Author: mes
Date: 2012-06-01 16:07:03 -0700 (Fri, 01 Jun 2012)
New Revision: 29428
Added:
core3/impl/trunk/swing-util-impl/
core3/impl/trunk/swing-util-impl/pom.xml
core3/impl/trunk/swing-util-impl/src/
core3/impl/trunk/swing-util-impl/src/main/
core3/impl/trunk/swing-util-impl/src/main/java/
core3/impl/trunk/swing-util-impl/src/main/java/org/
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/CyActivator.java
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/FileUtilImpl.java
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/OpenBrowserImpl.java
core3/impl/trunk/swing-util-impl/src/test/
core3/impl/trunk/swing-util-impl/src/test/java/
core3/impl/trunk/swing-util-impl/src/test/java/org/
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/CyActivatorTest.java
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/FileUtilImplTest.java
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/OpenBrowserImplTest.java
Removed:
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/internal/
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/internal/
Modified:
core3/api/trunk/swing-util-api/pom.xml
core3/gui-distribution/trunk/features/src/main/resources/features.xml
core3/impl/trunk/pom.xml
Log:
separated implementation parts out of swing-util-api and put them in
swing-util-impl
Modified: core3/api/trunk/swing-util-api/pom.xml
===================================================================
--- core3/api/trunk/swing-util-api/pom.xml 2012-06-01 22:51:32 UTC (rev
29427)
+++ core3/api/trunk/swing-util-api/pom.xml 2012-06-01 23:07:03 UTC (rev
29428)
@@ -72,7 +72,6 @@
<Bundle-Version>${project.version}</Bundle-Version>
<Export-Package>!${bundle.namespace}.internal.*,${bundle.namespace}.*;version="${project.version}"</Export-Package>
<Private-Package>${bundle.namespace}.internal.*</Private-Package>
-
<Bundle-Activator>${bundle.namespace}.internal.CyActivator</Bundle-Activator>
</instructions>
</configuration>
</plugin>
@@ -80,33 +79,6 @@
</build>
<dependencies>
<dependency>
- <groupId>org.cytoscape</groupId>
- <artifactId>property-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.cytoscape</groupId>
- <artifactId>service-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${osgi.api.version}</version>
- </dependency>
- <dependency>
- <groupId>org.cytoscape</groupId>
- <artifactId>model-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.cytoscape</groupId>
- <artifactId>application-api</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <!-- Testing -->
- <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
Modified: core3/gui-distribution/trunk/features/src/main/resources/features.xml
===================================================================
--- core3/gui-distribution/trunk/features/src/main/resources/features.xml
2012-06-01 22:51:32 UTC (rev 29427)
+++ core3/gui-distribution/trunk/features/src/main/resources/features.xml
2012-06-01 23:07:03 UTC (rev 29428)
@@ -83,6 +83,8 @@
<bundle
start-level="110">mvn:org.cytoscape/application-api/${cytoscape.api.version}</bundle>
<bundle
start-level="110">mvn:org.cytoscape/datasource-api/${cytoscape.api.version}</bundle>
<bundle
start-level="110">mvn:org.cytoscape/command-executor-api/${cytoscape.api.version}</bundle>
+ <bundle
start-level="110">mvn:org.cytoscape/swing-util-api/${cytoscape.api.version}</bundle>
+ <bundle
start-level="110">mvn:org.cytoscape/service-api/${cytoscape.api.version}</bundle>
<bundle
start-level="115">mvn:org.cytoscape.distribution/cmdline-impl/${project.version}</bundle>
<bundle
start-level="115">mvn:org.cytoscape/property-impl/${cytoscape.impl.version}</bundle>
@@ -90,15 +92,13 @@
<bundle
start-level="120">mvn:org.cytoscape/datasource-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="120">mvn:org.cytoscape/equations-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="120">mvn:org.cytoscape/event-impl/${cytoscape.impl.version}</bundle>
- <bundle
start-level="120">mvn:org.cytoscape/swing-util-api/${cytoscape.api.version}</bundle>
- <bundle
start-level="120">mvn:org.cytoscape/service-api/${cytoscape.api.version}</bundle>
+ <bundle
start-level="120">mvn:org.cytoscape/swing-util-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="125">mvn:org.cytoscape/model-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="125">mvn:org.cytoscape/group-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="125">mvn:org.cytoscape/work-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="125">mvn:org.cytoscape/work-swing-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="125">mvn:org.cytoscape/work-impl/${cytoscape.impl.version}</bundle>
-
<bundle
start-level="125">mvn:org.cytoscape/presentation-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="130">mvn:org.cytoscape/layout-impl/${cytoscape.impl.version}</bundle>
@@ -148,7 +148,6 @@
<bundle
start-level="175">mvn:org.cytoscape/app-impl/${cytoscape.impl.version}</bundle>
-
<bundle
start-level="180">mvn:org.cytoscape/scripting-impl/${cytoscape.impl.version}</bundle>
<bundle
start-level="185">mvn:org.cytoscape/gui-cmdline-parser-impl/${cytoscape.impl.version}</bundle>
Modified: core3/impl/trunk/pom.xml
===================================================================
--- core3/impl/trunk/pom.xml 2012-06-01 22:51:32 UTC (rev 29427)
+++ core3/impl/trunk/pom.xml 2012-06-01 23:07:03 UTC (rev 29428)
@@ -49,6 +49,7 @@
<module>search-impl</module>
<module>session-impl</module>
<module>help-impl</module>
+ <module>swing-util-impl</module>
<module>swing-application-impl</module>
<module>table-browser-impl</module>
<module>table-import-impl</module>
@@ -220,6 +221,8 @@
<artifactId>command-executor-api</artifactId>
<version>${cytoscape.api.version}</version>
</dependency>
+
+ <!-- test jars -->
<dependency>
<groupId>org.cytoscape</groupId>
<artifactId>core-task-api</artifactId>
Added: core3/impl/trunk/swing-util-impl/pom.xml
===================================================================
--- core3/impl/trunk/swing-util-impl/pom.xml (rev 0)
+++ core3/impl/trunk/swing-util-impl/pom.xml 2012-06-01 23:07:03 UTC (rev
29428)
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>impl-parent</artifactId>
+ <version>3.0.0-alpha9-SNAPSHOT</version>
+ </parent>
+
+ <properties>
+
<bundle.symbolicName>org.cytoscape.swing-util-impl</bundle.symbolicName>
+
<bundle.namespace>org.cytoscape.util.swing.internal</bundle.namespace>
+ </properties>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>swing-util-impl</artifactId>
+ <name>Cytoscape Swing Utility Impl (${project.artifactId})</name>
+ <packaging>bundle</packaging>
+
+ <repositories>
+ <!-- bootstrap for cytoscape dependencies, namely the parent
POM snapshots -->
+ <repository>
+ <id>cytoscape_snapshots</id>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <name>Cytoscape Snapshots</name>
+
<url>http://code.cytoscape.org/nexus/content/repositories/snapshots/</url>
+ </repository>
+ <!-- bootstrap for cytoscape dependencies, namely the parent
POM releases -->
+ <repository>
+ <id>cytoscape_releases</id>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <name>Cytoscape Releases</name>
+
<url>http://code.cytoscape.org/nexus/content/repositories/releases/</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
<version>${maven-bundle-plugin.version}</version>
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
+
<Bundle-Version>${project.version}</Bundle-Version>
+
<Export-Package>!${bundle.namespace}.*</Export-Package>
+
<Private-Package>${bundle.namespace}.*</Private-Package>
+
<Bundle-Activator>${bundle.namespace}.CyActivator</Bundle-Activator>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>swing-util-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>property-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>service-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>model-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
+ <artifactId>application-api</artifactId>
+ </dependency>
+
+ <!-- Testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added:
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/CyActivator.java
===================================================================
---
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/CyActivator.java
(rev 0)
+++
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/CyActivator.java
2012-06-01 23:07:03 UTC (rev 29428)
@@ -0,0 +1,28 @@
+package org.cytoscape.util.swing.internal;
+
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.util.swing.internal.FileUtilImpl;
+import org.cytoscape.util.swing.internal.OpenBrowserImpl;
+import org.cytoscape.util.swing.FileUtil;
+import org.cytoscape.util.swing.OpenBrowser;
+import org.osgi.framework.BundleContext;
+import org.cytoscape.service.util.AbstractCyActivator;
+import java.util.Properties;
+
+public class CyActivator extends AbstractCyActivator {
+ public CyActivator() {
+ super();
+ }
+
+ @Override
+ public void start(BundleContext bc) {
+
+ OpenBrowserImpl openBrowser = new OpenBrowserImpl();
+ registerService(bc, openBrowser, OpenBrowser.class, new
Properties());
+
+ CyProperty<Properties> cytoscapePropertiesServiceRef =
getService(bc, CyProperty.class,
+ "(cyPropertyName=cytoscape3.props)");
+ FileUtilImpl fileUtil = new
FileUtilImpl(cytoscapePropertiesServiceRef);
+ registerService(bc, fileUtil, FileUtil.class, new Properties());
+ }
+}
Added:
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/FileUtilImpl.java
===================================================================
---
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/FileUtilImpl.java
(rev 0)
+++
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/FileUtilImpl.java
2012-06-01 23:07:03 UTC (rev 29428)
@@ -0,0 +1,311 @@
+/*
+ File: FileUtil.java
+
+ Copyright (c) 2006, 2011, The Cytoscape Consortium (www.cytoscape.org)
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.util.swing.internal;
+
+
+import java.awt.Component;
+import java.awt.Dialog;
+import java.awt.FileDialog;
+import java.awt.Frame;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.swing.JComponent;
+import javax.swing.JFileChooser;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPopupMenu;
+
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.util.swing.FileChooserFilter;
+import org.cytoscape.util.swing.FileUtil;
+
+
+class FileUtilImpl implements FileUtil {
+
+ private final Properties coreProperties;
+
+ FileUtilImpl(final CyProperty<Properties> cyCoreProperty) {
+ coreProperties = cyCoreProperty.getProperties();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File getFile(final Component parent, final String title, final
int load_save_custom,
+ final Collection<FileChooserFilter> filters) {
+ return getFile(parent, title, load_save_custom, null, null,
filters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File getFile(final Component parent, final String title, final
int load_save_custom,
+ final String start_dir, final String
custom_approve_text,
+ final Collection<FileChooserFilter> filters)
+ {
+ File[] result = getFiles(parent, title, load_save_custom,
start_dir,
+ custom_approve_text, false, filters);
+
+ return ((result == null) || (result.length <= 0)) ? null :
result[0];
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File[] getFiles(final Component parent, final String title,
+ final int load_save_custom,
+ final Collection<FileChooserFilter> filters)
+ {
+ return getFiles(parent, title, load_save_custom, null, null,
true, filters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File[] getFiles(final Component parent, final String title,
+ final int load_save_custom, final String
start_dir,
+ final String custom_approve_text,
+ final Collection<FileChooserFilter> filters)
+ {
+ return getFiles(parent, title, load_save_custom, start_dir,
+ custom_approve_text, true, filters);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public File[] getFiles(final Component parent, final String title,
final int load_save_custom, String start_dir,
+ final String custom_approve_text, final boolean
multiselect, final Collection<FileChooserFilter> filters) {
+
+ if (parent == null)
+ throw new NullPointerException("\"parent\" must not be
null!");
+
+ if (start_dir == null)
+ start_dir =
coreProperties.getProperty(FileUtil.LAST_DIRECTORY,
System.getProperty("user.dir"));
+
+ final String osName = System.getProperty("os.name");
+
+ if (osName.startsWith("Mac")) {
+ // This is a Macintosh, use the AWT style file dialog
+
+ final String fileDialogForDirectories =
System.getProperty("apple.awt.fileDialogForDirectories");
+
System.setProperty("apple.awt.fileDialogForDirectories", "false");
+
+ try {
+ final FileDialog chooser;
+ if (parent instanceof Frame)
+ chooser = new FileDialog((Frame)
parent, title, load_save_custom);
+ else if (parent instanceof Dialog)
+ chooser = new FileDialog((Dialog)
parent, title, load_save_custom);
+ else if (parent instanceof JMenuItem) {
+ JComponent jcomponent = (JComponent)
((JPopupMenu)parent.getParent()).getInvoker();
+ chooser = new FileDialog((Frame)
jcomponent.getTopLevelAncestor(), title, load_save_custom);
+ } else {
+ throw new
IllegalArgumentException("Cannot (not implemented yet) create a dialog " +
+ "own by a parent
component of type: " + parent.getClass().getCanonicalName());
+ }
+
+ if (start_dir != null)
+ chooser.setDirectory(start_dir);
+
+ chooser.setModal(true);
+ chooser.setFilenameFilter(new
CombinedFilenameFilter(filters));
+ chooser.setLocationRelativeTo(parent);
+ chooser.setVisible(true);
+
+ if (chooser.getFile() != null) {
+ //TODO: how can we select multiple
files on Mac?
+ final File[] results = new File[1];
+ String newFileName = chooser.getFile();
+
+ //We need to do this check in the
writers/readers
+ //if (load_save_custom == SAVE)
+ // newFileName =
addFileExt(filters, newFileName);
+
+ results[0] = new
File(chooser.getDirectory() + File.separator + newFileName);
+
+ if (chooser.getDirectory() != null)
+
coreProperties.setProperty(FileUtil.LAST_DIRECTORY, chooser.getDirectory());
+
+ return results;
+ }
+ } finally {
+ if(fileDialogForDirectories != null)
+
System.setProperty("apple.awt.fileDialogForDirectories",
fileDialogForDirectories);
+ }
+
+ return null;
+ } else {
+ // this is not a Mac, use the Swing based file dialog
+ final File start = new File(start_dir);
+ final JFileChooser chooser = new JFileChooser(start);
+
+ // set multiple selection, if applicable
+ chooser.setMultiSelectionEnabled(multiselect);
+
+ // set the dialog title
+ chooser.setDialogTitle(title);
+ chooser.setAcceptAllFileFilterUsed(load_save_custom ==
LOAD);
+
+ int i = 0;
+ FileChooserFilter defaultFilter = null;
+ for (final FileChooserFilter filter : filters) {
+ // If we're down to the last filter and we
haven't yet selected a default,
+ // do it now!
+ if (++i == filters.size() && defaultFilter ==
null)
+ defaultFilter = filter;
+
+ // If we haven't yet selected a default and our
filter's description starts
+ // with "All ", make it the default.
+ else if (defaultFilter == null &&
filter.getDescription().startsWith("All "))
+ defaultFilter = filter;
+ chooser.addChoosableFileFilter(filter);
+ }
+
+ File[] results = null;
+ File tmp = null;
+
+ // set the dialog type
+ if (load_save_custom == LOAD) {
+ if (chooser.showOpenDialog(parent) ==
JFileChooser.APPROVE_OPTION) {
+ if (multiselect)
+ results =
chooser.getSelectedFiles();
+ else if ((tmp =
chooser.getSelectedFile()) != null) {
+ results = new File[1];
+ results[0] = tmp;
+ }
+ }
+ } else if (load_save_custom == SAVE) {
+ if (chooser.showSaveDialog(parent) ==
JFileChooser.APPROVE_OPTION) {
+ if (multiselect)
+ results =
chooser.getSelectedFiles();
+ else if ((tmp =
chooser.getSelectedFile()) != null) {
+ results = new File[1];
+ results[0] = tmp;
+ }
+
+ // FileDialog checks for overwrites,
but JFileChooser does
+ // not, so we need to do so ourselves:
+ for (int k = 0; k < results.length;
++k) {
+ if (results[k].exists()) {
+ int answer =
+
JOptionPane.showConfirmDialog(
+ chooser,
+ "The
file '"
+ +
results[k].getName()
+ + "'
already exists, are you sure you want to overwrite it?",
+ "File
exists",
+
JOptionPane.YES_NO_OPTION,
+
JOptionPane.WARNING_MESSAGE);
+ if (answer ==
JOptionPane.NO_OPTION){
+ return null;
+ }
+ }
+ }
+ }
+ } else {
+ if (chooser.showDialog(parent,
custom_approve_text) == JFileChooser.APPROVE_OPTION) {
+ if (multiselect)
+ results =
chooser.getSelectedFiles();
+ else if ((tmp =
chooser.getSelectedFile()) != null) {
+ results = new File[1];
+ results[0] = tmp;
+ }
+ }
+ }
+
+ if (results != null &&
chooser.getCurrentDirectory().getPath() != null)
+
coreProperties.setProperty(FileUtil.LAST_DIRECTORY,
+
chooser.getCurrentDirectory().getPath());
+
+ return results;
+ }
+ }
+
+ private String addFileExt(final Collection<FileChooserFilter> filters,
final String fileName) {
+ final Set<String> extSet = new HashSet<String>();
+ for(final FileChooserFilter filter: filters) {
+ final String[] exts = filter.getExtensions();
+ for(String ext:exts)
+ extSet.add(ext);
+ }
+
+ // Check file name has
+ final String upperName = fileName.toUpperCase();
+ for(String ext: extSet) {
+ if(upperName.endsWith("." + ext.toUpperCase()))
+ return fileName;
+ }
+
+
+ // Need to add ext
+ String fullFileName = fileName;
+ try {
+ fullFileName = fileName + "." +
extSet.iterator().next();
+ }
+ catch(Exception e){
+ //If the category is "UNSPECIFIED", we may get
null-pointer exception here
+ }
+
+ return fullFileName;
+ }
+
+ private static final class CombinedFilenameFilter implements
FilenameFilter {
+ private final Collection<FileChooserFilter> filters;
+
+ CombinedFilenameFilter(final Collection<FileChooserFilter>
filters) {
+ this.filters = filters;
+ }
+
+ @Override
+ public boolean accept(final File dir, final String name) {
+ if (filters.isEmpty())
+ return true;
+
+ final File path = new File(dir, name);
+ for (final FileChooserFilter filter : filters) {
+ if (filter.accept(path))
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
Added:
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/OpenBrowserImpl.java
===================================================================
---
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/OpenBrowserImpl.java
(rev 0)
+++
core3/impl/trunk/swing-util-impl/src/main/java/org/cytoscape/util/swing/internal/OpenBrowserImpl.java
2012-06-01 23:07:03 UTC (rev 29428)
@@ -0,0 +1,78 @@
+/*
+ File: OpenBrowserImpl.java
+
+ Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+//-------------------------------------------------------------------------
+// $Revision: 13206 $
+// $Date: 2008-02-26 16:37:29 -0800 (Tue, 26 Feb 2008) $
+// $Author: kono $
+//-------------------------------------------------------------------------
+package org.cytoscape.util.swing.internal;
+
+import java.awt.Desktop;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.cytoscape.util.swing.OpenBrowser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class OpenBrowserImpl implements OpenBrowser {
+
+ private final Logger logger =
LoggerFactory.getLogger(OpenBrowserImpl.class);
+
+ /**
+ * Opens the specified URL in the system default web browser.
+ *
+ * @return true if the URL opens successfully.
+ */
+ @Override
+ public boolean openURL(final String url) {
+ final Desktop desktop = Desktop.getDesktop();
+ try {
+ URI uri = new URI(url);
+ desktop.browse(uri);
+ } catch (IOException ioe) {
+ logger.warn("Could not open web browser: ", ioe);
+ return false;
+ } catch (URISyntaxException e) {
+ logger.warn("This URI is invalid: " + url, e);
+ return false;
+ }
+ return true;
+ }
+}
Added:
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/CyActivatorTest.java
===================================================================
---
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/CyActivatorTest.java
(rev 0)
+++
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/CyActivatorTest.java
2012-06-01 23:07:03 UTC (rev 29428)
@@ -0,0 +1,38 @@
+package org.cytoscape.util.swing.internal;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class CyActivatorTest {
+ @Mock BundleContext bc;
+ @Mock ServiceReference reference;
+
+ CyActivator activator;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ ServiceReference[] refs = new ServiceReference[]{reference};
+ when(bc.getServiceReferences(anyString(),
anyString())).thenReturn(refs);
+ activator = new CyActivator();
+ }
+
+
+ @Test
+ public void testCyActivator() {
+ assertNotNull(activator);
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void testStart() {
+ activator.start(bc);
+ }
+}
Added:
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/FileUtilImplTest.java
===================================================================
---
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/FileUtilImplTest.java
(rev 0)
+++
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/FileUtilImplTest.java
2012-06-01 23:07:03 UTC (rev 29428)
@@ -0,0 +1,65 @@
+package org.cytoscape.util.swing.internal;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.when;
+
+import java.util.Properties;
+
+import org.cytoscape.property.CyProperty;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+public class FileUtilImplTest {
+ private FileUtilImpl fileUtil;
+
+ @Mock private CyProperty<Properties> cyProperty;
+
+ private Properties props = new Properties();
+
+
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ when(cyProperty.getProperties()).thenReturn(props);
+
+ fileUtil = new FileUtilImpl(cyProperty);
+ }
+
+ @Test
+ public void testFileUtilImpl() {
+ assertNotNull(fileUtil);
+ }
+
+// @Test
+// public void
testGetFileComponentStringIntCollectionOfFileChooserFilter() {
+// Component parent = null;
+// String title = test;
+// int load_save_custom;
+// Collection<FileChooserFilter> filters;
+// fileUtil.getFile(parent, title, load_save_custom, filters);
+// }
+//
+// @Test
+// public void
testGetFileComponentStringIntStringStringCollectionOfFileChooserFilter() {
+// fail("Not yet implemented");
+// }
+//
+// @Test
+// public void
testGetFilesComponentStringIntCollectionOfFileChooserFilter() {
+// fail("Not yet implemented");
+// }
+//
+// @Test
+// public void
testGetFilesComponentStringIntStringStringCollectionOfFileChooserFilter() {
+// fail("Not yet implemented");
+// }
+//
+// @Test
+// public void
testGetFilesComponentStringIntStringStringBooleanCollectionOfFileChooserFilter()
{
+// fail("Not yet implemented");
+// }
+
+}
Added:
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/OpenBrowserImplTest.java
===================================================================
---
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/OpenBrowserImplTest.java
(rev 0)
+++
core3/impl/trunk/swing-util-impl/src/test/java/org/cytoscape/util/swing/internal/OpenBrowserImplTest.java
2012-06-01 23:07:03 UTC (rev 29428)
@@ -0,0 +1,27 @@
+package org.cytoscape.util.swing.internal;
+
+import static org.junit.Assert.assertFalse;
+
+import java.awt.Desktop;
+
+import org.cytoscape.util.swing.OpenBrowser;
+import org.junit.Assume;
+import org.junit.Test;
+
+public class OpenBrowserImplTest {
+
+ OpenBrowser openBrowser = new OpenBrowserImpl();
+
+
+ @Test
+ public void testOpenURL() {
+ Assume.assumeTrue(Desktop.isDesktopSupported());
+
+ // Invalid URL
+ assertFalse(openBrowser.openURL("123 @#$ ww ?* cyto"));
+
+ // Warning: This actually opens web browser!
+ //assertTrue(openBrowser.openURL("http://www.cytoscape.org/"));
+ }
+
+}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.