Author: ruschein
Date: 2010-07-26 12:47:23 -0700 (Mon, 26 Jul 2010)
New Revision: 21027
Modified:
cytoscape/trunk/src/cytoscape/CytoscapeInit.java
cytoscape/trunk/src/cytoscape/util/FileUtil.java
Log:
We now start looking for files to load in the user's home directory and
remember the last file-open location.
Modified: cytoscape/trunk/src/cytoscape/CytoscapeInit.java
===================================================================
--- cytoscape/trunk/src/cytoscape/CytoscapeInit.java 2010-07-26 18:17:31 UTC
(rev 21026)
+++ cytoscape/trunk/src/cytoscape/CytoscapeInit.java 2010-07-26 19:47:23 UTC
(rev 21027)
@@ -34,6 +34,7 @@
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -99,7 +100,7 @@
* @since Cytoscape 1.0
* @author Cytoscape Core Team
*/
-public class CytoscapeInit {
+public class CytoscapeInit implements PropertyChangeListener {
private static final String SPLASH_SCREEN_LOCATION =
"/cytoscape/images/CytoscapeSplashScreen.png";
private static Properties properties;
private static Properties visualProperties;
@@ -115,7 +116,7 @@
private static CyInitParams initParams;
// Most-Recently-Used directories and files
- private static File mrud;
+ private static Properties mrud;
private static File mruf;
// Error message
@@ -127,6 +128,7 @@
* Creates a new CytoscapeInit object.
*/
public CytoscapeInit() {
+
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(Cytoscape.CYTOSCAPE_EXIT,
this);
}
/**
@@ -265,10 +267,7 @@
* @return the most recently used directory
*/
public static File getMRUD() {
- if (mrud == null)
- mrud = new File(properties.getProperty("mrud",
System.getProperty("user.dir")));
-
- return mrud;
+ return new File(mrud.getProperty("fileOpenLocation",
System.getProperty("user.home")));
}
/**
@@ -281,8 +280,8 @@
/**
* @param mrud_new the most recently used directory
*/
- public static void setMRUD(File mrud_new) {
- mrud = mrud_new;
+ public static void setMRUD(final File mrud_new) {
+ mrud.setProperty("fileOpenLocation", mrud_new.toString());
}
/**
@@ -488,6 +487,19 @@
visualProperties = new Properties();
loadStaticProperties("vizmap.props", visualProperties);
}
+
+ if (mrud == null) {
+ mrud = new Properties();
+ final File propsFile = new
File(CytoscapeInit.getConfigVersionDirectory(),
"mostRecentlyUsedDirectory.props");
+ if (propsFile != null) {
+ try {
+ final FileInputStream inputStream = new
FileInputStream(propsFile);
+ mrud.load(inputStream);
+ } catch (final IOException e) {
+ // Intentionally empty!
+ }
+ }
+ }
}
private void setUpAttributesChangedListener() {
@@ -640,4 +652,16 @@
logger.error("Plugin system initialization error:
"+e.toString(),e);
}
}
+
+ public void propertyChange(final PropertyChangeEvent e) {
+ if (e.getPropertyName().equals(Cytoscape.CYTOSCAPE_EXIT)) {
+ final File propsFile = new
File(CytoscapeInit.getConfigVersionDirectory(),
"mostRecentlyUsedDirectory.props");
+ try {
+ mrud.store(new FileOutputStream(propsFile), "");
+ }
+ catch (final IOException ioe) {
+ System.err.println("Failed to save
\"mostRecentlyUsedDirectory.props\"!");
+ }
+ }
+ }
}
Modified: cytoscape/trunk/src/cytoscape/util/FileUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/FileUtil.java 2010-07-26 18:17:31 UTC
(rev 21026)
+++ cytoscape/trunk/src/cytoscape/util/FileUtil.java 2010-07-26 19:47:23 UTC
(rev 21027)
@@ -71,8 +71,11 @@
static class NoEditFileChooser extends JFileChooser {
public NoEditFileChooser(final File start) {
super(start);
-
+
final JList list = findFileList(this);
+ if (list == null)
+ return;
+
for (MouseListener l : list.getMouseListeners()) {
if (l.getClass().getName().indexOf("FilePane")
>= 0) {
list.removeMouseListener(l);
@@ -345,11 +348,14 @@
//logger.info( "Os name: "+osName );
if (osName.startsWith("Mac")) {
// this is a Macintosh, use the AWT style file dialog
- FileDialog chooser = new
FileDialog(Cytoscape.getDesktop(),title, load_save_custom);
+ FileDialog chooser = new
FileDialog(Cytoscape.getDesktop(), title, load_save_custom);
- if (!multiselect && selectedFiles != null){
- chooser.setFile(selectedFiles[0].toString());
- }
+ final File mostRecentlyUsedDirectory =
CytoscapeInit.getMRUD();
+ if (mostRecentlyUsedDirectory != null)
+
chooser.setDirectory(mostRecentlyUsedDirectory.toString());
+
+ if (!multiselect && selectedFiles != null)
+ chooser.setFile(selectedFiles[0].toString());
// we can only set the one filter; therefore, create a
special
// version of CyFileFilter that contains all extensions
@@ -357,10 +363,8 @@
for (int i = 0; i < filters.length; i++) {
Iterator iter;
-
- for (iter =
filters[i].getExtensionSet().iterator(); iter.hasNext();) {
+ for (iter =
filters[i].getExtensionSet().iterator(); iter.hasNext(); /* Empty! */)
fileFilter.addExtension((String)
iter.next());
- }
}
fileFilter.setDescription("All network files");
@@ -372,9 +376,8 @@
File[] result = new File[1];
result[0] = new File(chooser.getDirectory() +
"/" + chooser.getFile());
- if (chooser.getDirectory() != null) {
+ if (chooser.getDirectory() != null)
CytoscapeInit.setMRUD(new
File(chooser.getDirectory()));
- }
return result;
}
--
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.