Author: kono
Date: 2011-05-31 14:08:13 -0700 (Tue, 31 May 2011)
New Revision: 25604

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/GUITunableHandlerFactory.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
Log:
Last selected directory is managed in Core Property from this version.

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-05-31 19:49:59 UTC (rev 25603)
+++ 
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/FileHandler.java
        2011-05-31 21:08:13 UTC (rev 25604)
@@ -1,7 +1,9 @@
 package org.cytoscape.work.internal.tunables;
 
 
+import java.awt.FileDialog;
 import java.awt.Font;
+import java.awt.Frame;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.MouseAdapter;
@@ -11,6 +13,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.List;
+import java.util.Properties;
 
 import javax.swing.GroupLayout;
 import javax.swing.ImageIcon;
@@ -24,9 +27,9 @@
 
 import org.cytoscape.io.DataCategory;
 import org.cytoscape.work.Tunable;
-import org.cytoscape.work.swing.AbstractGUITunableHandler;
 import org.cytoscape.work.internal.tunables.utils.FileChooserFilter;
 import org.cytoscape.work.internal.tunables.utils.SupportedFileTypesManager;
+import org.cytoscape.work.swing.AbstractGUITunableHandler;
 
 
 /**
@@ -35,7 +38,16 @@
  * @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";
+       
+       // Core Cytoscape props
+       private final Properties props;
+       
        private JFileChooser fileChooser;
+       
        private JButton chooseButton;
        private JTextField fileTextField;
        private ImageIcon image;
@@ -58,15 +70,19 @@
         * @param t tunable associated to <code>f</code>
         * @param fileTypesManager 
         */
-       protected FileHandler(Field f, Object o, Tunable t, final 
SupportedFileTypesManager fileTypesManager) {
+       protected FileHandler(Field f, Object o, Tunable t, final 
SupportedFileTypesManager fileTypesManager,
+                       Properties props) {
                super(f, o, t);
                this.fileTypesManager = fileTypesManager;
+               this.props = props;
                init();
        }
 
-       protected FileHandler(final Method getter, final Method setter, final 
Object instance, final Tunable tunable, final SupportedFileTypesManager 
fileTypesManager) {
+       protected FileHandler(final Method getter, final Method setter, final 
Object instance, final Tunable tunable,
+                       final SupportedFileTypesManager fileTypesManager, 
Properties props) {
                super(getter, setter, instance, tunable);
                this.fileTypesManager = fileTypesManager;
+               this.props = props;
                init();
        }
 
@@ -115,7 +131,9 @@
                final String fileCategory = getFileCategory().toUpperCase();
                fileTextField.setText("Please select a " + 
fileCategory.toLowerCase() + " file...");
                titleLabel.setText("Import " + initialCaps(fileCategory) + " 
File");
-               List<FileChooserFilter> filters = 
fileTypesManager.getSupportedFileTypes(DataCategory.valueOf(fileCategory), 
input);
+               
+               final List<FileChooserFilter> filters = 
fileTypesManager.getSupportedFileTypes(
+                               DataCategory.valueOf(fileCategory), input);
                for (FileChooserFilter filter : filters)
                        fileChooser.addChoosableFileFilter(filter);
        }
@@ -167,30 +185,40 @@
                                                  .addContainerGap()));
        }
 
-       //Click on the "open" button actionlistener
-       private class myFileActionListener implements ActionListener{
+       //Click on the "open" button action listener
+       private final class myFileActionListener implements ActionListener{
                public void actionPerformed(ActionEvent ae) {
-                       if (ae.getActionCommand().equals("open")) {
-                               int ret = fileChooser.showOpenDialog(panel);
-                               if (ret == JFileChooser.APPROVE_OPTION) {
-                                       File file = 
fileChooser.getSelectedFile();
-                                       if (file != null) {
-                                               fileTextField.setFont(new 
Font(null, Font.PLAIN,10));
-                                               
fileTextField.setText(file.getAbsolutePath());
-                                               
fileTextField.removeMouseListener(mouseClick);
-                                       }
+                       
+                       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);
+                       
+                       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) {
+                                       fileTextField.setFont(new Font(null, 
Font.PLAIN, 10));
+                                       
fileTextField.setText(file.getAbsolutePath());
+                                       
fileTextField.removeMouseListener(mouseClick);
                                }
-                       } else if (ae.getActionCommand().equals("save")) {
-                               int ret = fileChooser.showSaveDialog(panel);
-                               if (ret == JFileChooser.APPROVE_OPTION) {
-                                       File file = 
fileChooser.getSelectedFile();
-                                       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/GUITunableHandlerFactory.java
===================================================================
--- 
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/GUITunableHandlerFactory.java
   2011-05-31 19:49:59 UTC (rev 25603)
+++ 
core3/work-swing-impl/trunk/impl/src/main/java/org/cytoscape/work/internal/tunables/GUITunableHandlerFactory.java
   2011-05-31 21:08:13 UTC (rev 25604)
@@ -6,6 +6,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.URL;
+import java.util.Properties;
 
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.property.bookmark.BookmarksUtil;
@@ -33,16 +34,26 @@
        private Bookmarks bookmarks;
        private BookmarksUtil bkUtil;
        private SupportedFileTypesManager fileTypesManager;
+       
+       private final Properties props;
 
        /**
         * creates a new GUITunableHandlerFactory object
-        * @param book  informations and properties of the 
<code>Bookmarks</code> registered
-        * @param bkUtil object that provides tools to manage the 
<code>Bookmarks</code>
+        * 
+        * @param book
+        *            informations and properties of the <code>Bookmarks</code>
+        *            registered
+        * @param bkUtil
+        *            object that provides tools to manage the
+        *            <code>Bookmarks</code>
         */
-       public GUITunableHandlerFactory(CyProperty<Bookmarks> book, 
BookmarksUtil bkUtil, SupportedFileTypesManager fileTypesManager) {
+       public GUITunableHandlerFactory(final CyProperty<Properties> coreProps, 
final CyProperty<Bookmarks> book,
+                       BookmarksUtil bkUtil, SupportedFileTypesManager 
fileTypesManager) {
                this.bookmarks = book.getProperties();
                this.bkUtil = bkUtil;
                this.fileTypesManager = fileTypesManager;
+               
+               this.props = coreProps.getProperties();
        }
 
        /**
@@ -82,7 +93,7 @@
                if (type == ListMultipleSelection.class)
                        return new ListMultipleHandler<String>(getter, setter, 
instance, tunable);
                if (type == File.class)
-                       return new FileHandler(getter, setter, instance, 
tunable, fileTypesManager);
+                       return new FileHandler(getter, setter, instance, 
tunable, fileTypesManager, props);
                if (type == URL.class)
                        return new URLHandler(getter, setter, instance, 
tunable, bookmarks, bkUtil);
                if (type == InputStream.class)
@@ -139,7 +150,7 @@
                if (type == ListMultipleSelection.class)
                        return new ListMultipleHandler<String>(field, instance, 
tunable);
                if (type == File.class)
-                       return new FileHandler(field, instance, tunable, 
fileTypesManager);
+                       return new FileHandler(field, instance, tunable, 
fileTypesManager, props);
                if (type == URL.class)
                        return new URLHandler(field, instance, tunable, 
bookmarks, bkUtil);
                if (type == InputStream.class)

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-05-31 19:49:59 UTC (rev 25603)
+++ 
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context-osgi.xml
 2011-05-31 21:08:13 UTC (rev 25604)
@@ -6,6 +6,9 @@
         default-lazy-init="false">
 
        <!-- 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-05-31 19:49:59 UTC (rev 25603)
+++ 
core3/work-swing-impl/trunk/impl/src/main/resources/META-INF/spring/bundle-context.xml
      2011-05-31 21:08:13 UTC (rev 25604)
@@ -25,6 +25,7 @@
        </bean>
 
        <bean id="guiHandlerFactory" 
class="org.cytoscape.work.internal.tunables.GUITunableHandlerFactory">
+               <constructor-arg ref="cytoscapePropertiesServiceRef"/>
                <constructor-arg ref="bookmarkServiceRef" />
                <constructor-arg ref="bookmarksUtilServiceRef" />
                <constructor-arg ref="supportedFileTypesManager" />

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-05-31 19:49:59 UTC (rev 25603)
+++ 
core3/work-swing-impl/trunk/it/src/test/java/org/cytoscape/work/ServiceConfigurationTest.java
       2011-05-31 21:08:13 UTC (rev 25604)
@@ -21,9 +21,14 @@
 
        @Before
        public void setup() {
+               Properties coreP = new Properties();
+               coreP.setProperty("cyPropertyName","coreSettings");
+               
                Properties p = new Properties();
                p.setProperty("cyPropertyName","bookmarks");
-               registerMockService(CyProperty.class,p);
+               
+               registerMockService(CyProperty.class, coreP);
+               registerMockService(CyProperty.class, p);
                registerMockService(BookmarksUtil.class);
        }
        

-- 
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.

Reply via email to