Author: ruschein
Date: 2011-07-11 12:31:17 -0700 (Mon, 11 Jul 2011)
New Revision: 26140
Removed:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/FileChooserFilter.java
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandlerFactory.java
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/SupportedFileTypesManager.java
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
core3/work-swing-impl/trunk/it/src/test/java/org/cytoscape/work/ServiceConfigurationTest.java
core3/work-swing-impl/trunk/pom.xml
Log:
Now we use FileUtil in FileHandler.
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
2011-07-11 19:31:17 UTC (rev 26140)
@@ -19,16 +19,17 @@
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
-import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.LayoutStyle;
+import javax.swing.SwingUtilities;
import org.cytoscape.io.DataCategory;
+import org.cytoscape.util.swing.FileChooserFilter;
+import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.work.Tunable;
-import org.cytoscape.work.internal.tunables.utils.FileChooserFilter;
import org.cytoscape.work.internal.tunables.utils.SupportedFileTypesManager;
import org.cytoscape.work.swing.AbstractGUITunableHandler;
@@ -39,14 +40,8 @@
* @author pasteur
*/
public class FileHandler extends AbstractGUITunableHandler {
- private static final String DEF_DIRECTORY =
System.getProperty("user.home");
- private static final String LAST_DIRECTORY = "directory.last";
+ private final FileUtil fileUtil;
- // Core Cytoscape props
- private final Properties props;
-
- private JFileChooser fileChooser;
-
private JButton chooseButton;
private JTextField fileTextField;
private ImageIcon image;
@@ -63,37 +58,36 @@
*
* It creates the GUI which displays the path of the current file in a
field, and provides
* access to a FileChooser with filtering parameters on
- * <i>network</i>,<i>attributes</i>, or <i>session</i> (parameters are
set in the <code>Tunable</code>'s annotations of the <code>File</code>)
+ * <i>network</i>,<i>attributes</i>, or <i>session</i> (parameters are
set in the
+ * <code>Tunable</code>'s annotations of the <code>File</code>)
*
- *
- * @param f field that has been annotated
- * @param o object contained in <code>f</code>
- * @param t tunable associated to <code>f</code>
+ * @param field the field that has been annotated
+ * @param obj object contained in <code>field</code>
+ * @param tunable the tunable associated to <code>field</code>
* @param fileTypesManager
*/
- public FileHandler(Field f, Object o, Tunable t,
+ public FileHandler(final Field field, final Object obj, final Tunable t,
final SupportedFileTypesManager fileTypesManager,
- final Properties props)
+ final FileUtil fileUtil)
{
- super(f, o, t);
+ super(field, obj, t);
this.fileTypesManager = fileTypesManager;
- this.props = props;
+ this.fileUtil = fileUtil;
init(fileTypesManager);
}
public FileHandler(final Method getter, final Method setter, final
Object instance,
final Tunable tunable,
final SupportedFileTypesManager fileTypesManager,
- final Properties props)
+ final FileUtil fileUtil)
{
super(getter, setter, instance, tunable);
this.fileTypesManager = fileTypesManager;
- this.props = props;
+ this.fileUtil = fileUtil;
init(fileTypesManager);
}
private void init(final SupportedFileTypesManager fileTypesManager) {
- fileChooser = new JFileChooser();
input = isInput();
final String fileCategory = getFileCategory();
@@ -141,27 +135,6 @@
final String fileCategory = getFileCategory();
fileTextField.setText("Please select a " +
fileCategory.toLowerCase() + " file...");
titleLabel.setText((input ? "Load " : "Save ") +
initialCaps(fileCategory) + " File");
-
- if (filters.isEmpty())
- return;
-
- fileChooser.setAcceptAllFileFilterUsed(input);
-
- int i = 0;
- FileChooserFilter defaultFilter = null;
- for (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;
-
- fileChooser.addChoosableFileFilter(filter);
- }
- fileChooser.setFileFilter(defaultFilter);
}
private String getFileCategory() {
@@ -179,7 +152,7 @@
return Character.toUpperCase(s.charAt(0)) +
s.substring(1).toLowerCase();
}
- //diplays the panel's component in a good view
+ // displays the panel's component in a good view
private void setLayout() {
layout = new GroupLayout(panel);
@@ -214,60 +187,16 @@
// Click on the "open" or "save" button action listener
private final class myFileActionListener implements ActionListener{
public void actionPerformed(ActionEvent ae) {
- File file = null;
- final String lastDir =
props.getProperty(LAST_DIRECTORY, DEF_DIRECTORY);
-
- File lastDirFile;
- try {
- lastDirFile = new File(lastDir);
- } catch (Exception e){
- lastDirFile = new File(DEF_DIRECTORY);
- }
-
- if (!lastDirFile.isDirectory())
- lastDirFile = new File(DEF_DIRECTORY);
-
- fileChooser.setCurrentDirectory(lastDirFile);
-
try_again: {
- int ret = JFileChooser.CANCEL_OPTION;
- if (ae.getActionCommand().equals("open"))
- ret = fileChooser.showOpenDialog(panel);
- else if (ae.getActionCommand().equals("save"))
- ret = fileChooser.showSaveDialog(panel);
-
- if (ret == JFileChooser.APPROVE_OPTION) {
- file = fileChooser.getSelectedFile();
- if (file != null) {
-/*
- // Make sure the user-supplied
file name has an extension:
- final String fileName =
file.getPath();
- if (getFileExtension(fileName)
== null) {
- final String extension =
-
filters.get(0).getExtensions()[0];
- final String
nameWithExtension =
-
addFileExtension(fileName, extension);
- file = new
File(nameWithExtension);
- }
-
- if
(ae.getActionCommand().equals("save") && file.exists()) {
- if
(JOptionPane.showConfirmDialog(
- panel,
- "The file you
selected already exists. "
- + "Are you sure
you want to overwrite it?",
- "Confirmation",
-
JOptionPane.YES_NO_OPTION)
- ==
JOptionPane.NO_OPTION)
- break try_again;
- }
-*/
- fileTextField.setFont(new
Font(null, Font.PLAIN, 10));
-
fileTextField.setText(file.getAbsolutePath());
-
fileTextField.removeMouseListener(mouseClick);
- }
+ final int load_or_save = input ? FileUtil.LOAD
: FileUtil.SAVE;
+ final File file =
fileUtil.getFile(SwingUtilities.getWindowAncestor(panel),
+
titleLabel.getText(), load_or_save, filters);
+ if (file != null) {
+ fileTextField.setFont(new Font(null,
Font.PLAIN, 10));
+
fileTextField.setText(file.getAbsolutePath());
+
fileTextField.removeMouseListener(mouseClick);
}
}
- props.put(LAST_DIRECTORY,
fileChooser.getCurrentDirectory().getAbsolutePath());
}
}
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandlerFactory.java
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandlerFactory.java
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandlerFactory.java
2011-07-11 19:31:17 UTC (rev 26140)
@@ -1,38 +1,39 @@
package org.cytoscape.work.internal.tunables;
+
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Properties;
-import org.cytoscape.property.CyProperty;
+import org.cytoscape.util.swing.FileUtil;
import org.cytoscape.work.Tunable;
import org.cytoscape.work.internal.tunables.utils.SupportedFileTypesManager;
import org.cytoscape.work.swing.GUITunableHandler;
import org.cytoscape.work.swing.GUITunableHandlerFactory;
-public class FileHandlerFactory implements GUITunableHandlerFactory {
- private SupportedFileTypesManager fileTypesManager;
- private Properties props;
+public final class FileHandlerFactory implements GUITunableHandlerFactory {
+ private final FileUtil fileUtil;
+ private final SupportedFileTypesManager fileTypesManager;
- public FileHandlerFactory(final CyProperty<Properties> p, final
SupportedFileTypesManager fileTypesManager) {
- this.props = p.getProperties();
+ public FileHandlerFactory(final FileUtil fileUtil, final
SupportedFileTypesManager fileTypesManager) {
+ this.fileUtil = fileUtil;
this.fileTypesManager = fileTypesManager;
}
public GUITunableHandler getHandler(Field field, Object instance,
Tunable tunable) {
- if ( field.getType() != File.class)
+ if (!File.class.isAssignableFrom(field.getType()))
return null;
- return new FileHandler(field, instance, tunable,
fileTypesManager, props);
+ return new FileHandler(field, instance, tunable,
fileTypesManager, fileUtil);
}
public GUITunableHandler getHandler(Method getter, Method setter,
Object instance, Tunable tunable) {
- if ( getter.getReturnType() != File.class)
+ if (!File.class.isAssignableFrom(getter.getReturnType()))
return null;
- return new FileHandler(getter, setter, instance, tunable,
fileTypesManager, props);
+ return new FileHandler(getter, setter, instance, tunable,
fileTypesManager, fileUtil);
}
}
Deleted:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/FileChooserFilter.java
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/FileChooserFilter.java
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/FileChooserFilter.java
2011-07-11 19:31:17 UTC (rev 26140)
@@ -1,88 +0,0 @@
-package org.cytoscape.work.internal.tunables.utils;
-
-
-import java.io.File;
-import java.util.Arrays;
-import javax.swing.filechooser.FileFilter;
-
-
-public class FileChooserFilter extends FileFilter {
- private final String description;
- private final String[] extensions;
-
- public FileChooserFilter(final String description, final String
extension) {
- super();
- this.description = description;
- this.extensions = new String[] { extension };
- }
-
- public FileChooserFilter(final String description, final String[]
extensions) {
- super();
- this.description = description;
- this.extensions = extensions;
- }
-
- //accept or not the file from jfilechooser
- public boolean accept(final File file) {
- if (file.isDirectory())
- return true;
-
- String fileName = file.getName().toLowerCase();
-
- if (extensions != null) {
- for(int i = 0; i < extensions.length; i++) {
- if (fileName.endsWith(extensions[i]))
- return true;
- }
-
- for(int i = 0; i < extensions.length; i++) {
- if (fileName.contains(extensions[i]))
- return true;
- }
- } else
- throw new IllegalArgumentException("No fileType
specified");
-
- return false;
- }
-
- public String getDescription(){
- return description;
- }
-
- public String[] getExtensions() {
- return extensions;
- }
-
- @Override
- public boolean equals(final Object other) {
- if (!(other instanceof FileChooserFilter))
- return false;
-
- final FileChooserFilter otherFilter = (FileChooserFilter)other;
- if (!otherFilter.description.equals(description))
- return false;
-
- if (otherFilter.extensions.length != extensions.length)
- return false;
-
- Arrays.sort(otherFilter.extensions);
- Arrays.sort(extensions);
-
- for (int i = 0; i < extensions.length; ++i) {
- if (!extensions[i].equals(otherFilter.extensions[i]))
- return false;
- }
-
- return true;
- }
-
- static String toString(final String[] strings) {
- final StringBuilder setAsString = new StringBuilder();
- setAsString.append('{');
- for (final String item : strings) {
- setAsString.append(item + " ");
- }
- setAsString.append('}');
- return setAsString.toString();
- }
-}
\ No newline at end of file
Modified:
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/SupportedFileTypesManager.java
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/SupportedFileTypesManager.java
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/utils/SupportedFileTypesManager.java
2011-07-11 19:31:17 UTC (rev 26140)
@@ -14,6 +14,7 @@
import org.cytoscape.io.CyFileFilterProvider;
import org.cytoscape.io.read.InputStreamTaskFactory;
import org.cytoscape.io.write.CyWriterFactory;
+import org.cytoscape.util.swing.FileChooserFilter;
/**
Modified:
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-07-11 19:31:17 UTC (rev 26140)
@@ -5,10 +5,10 @@
http://www.springframework.org/schema/osgi
http://www.springframework.org/schema/osgi/spring-osgi-1.0.xsd"
default-lazy-init="false">
+ <!-- Services imported by this bundle -->
+ <osgi:reference id="fileUtilRef"
interface="org.cytoscape.util.swing.FileUtil" />
+
<!-- Services provided by this bundle -->
-
- <osgi:reference id="cytoscapePropertiesServiceRef"
- interface="org.cytoscape.property.CyProperty"
filter="(cyPropertyName=coreSettings)" />
<osgi:service id="undoSupportService" ref="undoSupport"
interface="org.cytoscape.work.undo.UndoSupport">
Modified:
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
---
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
2011-07-11 19:31:17 UTC (rev 26140)
@@ -39,12 +39,12 @@
</bean>
<bean id="integerHandlerFactory"
class="org.cytoscape.work.swing.BasicGUITunableHandlerFactory">
<constructor-arg
value="org.cytoscape.work.internal.tunables.IntegerHandler" />
- <constructor-arg>
+ <constructor-arg>
<list>
<value>java.lang.Integer</value>
<util:constant
static-field="java.lang.Integer.TYPE"/>
</list>
- </constructor-arg>
+ </constructor-arg>
</bean>
<bean id="floatHandlerFactory"
class="org.cytoscape.work.swing.BasicGUITunableHandlerFactory">
<constructor-arg
value="org.cytoscape.work.internal.tunables.FloatHandler" />
@@ -53,7 +53,7 @@
<value>java.lang.Float</value>
<util:constant
static-field="java.lang.Float.TYPE"/>
</list>
- </constructor-arg>
+ </constructor-arg>
</bean>
<bean id="doubleHandlerFactory"
class="org.cytoscape.work.swing.BasicGUITunableHandlerFactory">
<constructor-arg
value="org.cytoscape.work.internal.tunables.DoubleHandler" />
@@ -62,7 +62,7 @@
<value>java.lang.Double</value>
<util:constant
static-field="java.lang.Double.TYPE"/>
</list>
- </constructor-arg>
+ </constructor-arg>
</bean>
<bean id="longHandlerFactory"
class="org.cytoscape.work.swing.BasicGUITunableHandlerFactory">
<constructor-arg
value="org.cytoscape.work.internal.tunables.LongHandler" />
@@ -71,7 +71,7 @@
<value>java.lang.Long</value>
<util:constant
static-field="java.lang.Long.TYPE"/>
</list>
- </constructor-arg>
+ </constructor-arg>
</bean>
<bean id="stringHandlerFactory"
class="org.cytoscape.work.swing.BasicGUITunableHandlerFactory">
<constructor-arg
value="org.cytoscape.work.internal.tunables.StringHandler" />
@@ -106,9 +106,7 @@
<constructor-arg ref="bookmarksUtilServiceRef" />
</bean>
<bean id="fileHandlerFactory"
class="org.cytoscape.work.internal.tunables.FileHandlerFactory">
- <constructor-arg ref="cytoscapePropertiesServiceRef"/>
+ <constructor-arg ref="fileUtilRef"/>
<constructor-arg ref="supportedFileTypesManager" />
</bean>
-
-
</beans>
Modified:
core3/work-swing-impl/trunk/it/src/test/java/org/cytoscape/work/ServiceConfigurationTest.java
===================================================================
---
core3/work-swing-impl/trunk/it/src/test/java/org/cytoscape/work/ServiceConfigurationTest.java
2011-07-11 18:56:34 UTC (rev 26139)
+++
core3/work-swing-impl/trunk/it/src/test/java/org/cytoscape/work/ServiceConfigurationTest.java
2011-07-11 19:31:17 UTC (rev 26140)
@@ -1,20 +1,22 @@
package org.cytoscape.work;
-import org.junit.Test;
-import org.junit.Before;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.MavenConfiguredJUnit4TestRunner;
+import java.util.Properties;
+
+import org.cytoscape.integration.ServiceTestSupport;
+import org.cytoscape.property.BasicCyProperty;
+import org.cytoscape.property.CyProperty;
+import org.cytoscape.property.bookmark.BookmarksUtil;
import org.cytoscape.work.swing.GUITaskManager;
import org.cytoscape.work.swing.GUITunableHandlerFactory;
import org.cytoscape.work.swing.GUITunableInterceptor;
import org.cytoscape.work.undo.UndoSupport;
-import org.cytoscape.integration.ServiceTestSupport;
-import org.cytoscape.property.CyProperty;
-import org.cytoscape.property.bookmark.BookmarksUtil;
+import org.junit.Test;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.MavenConfiguredJUnit4TestRunner;
-import java.util.Properties;
@RunWith(MavenConfiguredJUnit4TestRunner.class)
public class ServiceConfigurationTest extends ServiceTestSupport {
@@ -26,9 +28,10 @@
Properties p = new Properties();
p.setProperty("cyPropertyName","bookmarks");
-
- registerMockService(CyProperty.class, coreP);
- registerMockService(CyProperty.class, p);
+
+ CyProperty<Properties> cyProp = new BasicCyProperty(new
Properties(), CyProperty.SavePolicy.CONFIG_DIR);
+ registerMockService(CyProperty.class, cyProp, coreP);
+ registerMockService(CyProperty.class, cyProp, p);
registerMockService(BookmarksUtil.class);
}
Modified: core3/work-swing-impl/trunk/pom.xml
===================================================================
--- core3/work-swing-impl/trunk/pom.xml 2011-07-11 18:56:34 UTC (rev 26139)
+++ core3/work-swing-impl/trunk/pom.xml 2011-07-11 19:31:17 UTC (rev 26140)
@@ -75,6 +75,12 @@
<dependencies>
<dependency>
<groupId>org.cytoscape</groupId>
+ <artifactId>swing-util-api</artifactId>
+ <version>3.0.0-alpha3-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape</groupId>
<artifactId>work-api</artifactId>
<version>3.0.0-alpha4-SNAPSHOT</version>
<scope>provided</scope>
--
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.