Author: ruschein
Date: 2010-06-14 18:49:56 -0700 (Mon, 14 Jun 2010)
New Revision: 20540

Added:
   cytoscape/trunk/src/cytoscape/view/OpenRecentAction.java
Modified:
   cytoscape/trunk/src/cytoscape/Cytoscape.java
   cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
   cytoscape/trunk/src/cytoscape/util/RecentlyOpenedTracker.java
   cytoscape/trunk/src/cytoscape/view/CyMenus.java
Log:
Added a "most recently opened" session list to the "File" menu.

Modified: cytoscape/trunk/src/cytoscape/Cytoscape.java
===================================================================
--- cytoscape/trunk/src/cytoscape/Cytoscape.java        2010-06-14 22:31:53 UTC 
(rev 20539)
+++ cytoscape/trunk/src/cytoscape/Cytoscape.java        2010-06-15 01:49:56 UTC 
(rev 20540)
@@ -85,6 +85,7 @@
 import cytoscape.layout.CyLayoutAlgorithm;
 import cytoscape.layout.CyLayouts;
 import cytoscape.util.FileUtil;
+import cytoscape.util.RecentlyOpenedTracker;
 import cytoscape.view.CyNetworkView;
 import cytoscape.view.CytoscapeDesktop;
 import cytoscape.visual.VisualMappingManager;
@@ -227,7 +228,7 @@
         * internet have been changed.
         */
        public static final String PROXY_MODIFIED = "PROXY_MODIFIED";
-       
+
        /**
         * Fired every time a nested network is assigned to a node.
         * This event contains the following values:
@@ -237,7 +238,7 @@
         * </ul>
         */
        public static final String NESTED_NETWORK_CREATED = 
"NESTED_NETWORK_CREATED";
-       
+
        /**
         * Fired every time a nested network is removed from a node.
         */
@@ -392,6 +393,11 @@
        private static Bookmarks bookmarks;
 
        /**
+        * Used by session reader.
+        */
+       private static RecentlyOpenedTracker recentlyOpenedSessions = null;
+
+       /**
         * A null CyNetwork to give when there is no Current Network
         */
        protected static CyNetwork nullNetwork = getRootGraph()
@@ -427,7 +433,7 @@
         * this from here.
         * Don't initialize this until it is to be used.
         */
-       protected static VisualMappingManager VMM = null; 
+       protected static VisualMappingManager VMM = null;
 
        protected static CyLogger logger = CyLogger.getLogger(Cytoscape.class);
 
@@ -482,8 +488,13 @@
                                    // Cytoscape to a new session:
                                    getDesktop().setVisible (false);
                                    // get rid of existing data:
-                                   Cytoscape.createNewSession ();
+                                   Cytoscape.createNewSession();
                                } else {
+                                       try {
+                                               
getRecentlyOpenedSessionTracker().writeOut();
+                                       } catch (final IOException e) {
+                                               System.err.println("failed to 
save recent session URLs!");
+                                       }
                                        System.exit(returnVal);
                                }
                        } else {
@@ -903,7 +914,7 @@
                        selectedNetworkViews.add(cv);
        }
 
-       
+
        /**
         * Returns the list of selected networks.
         */
@@ -917,7 +928,7 @@
                return (List<CyNetwork>) selectedNetworks.clone();
        }
 
-       
+
        /**
         * Sets the list of selected networks.
         */
@@ -961,7 +972,7 @@
                        //logger.info("- SUCCEED setting current network " + 
id);
                        currentNetworkID = id;
 
-                       // reset selected networks 
+                       // reset selected networks
                        selectedNetworks.clear();
                        selectedNetworks.add((CyNetwork) 
(getNetworkMap().get(id)));
                }
@@ -976,7 +987,7 @@
                        //logger.info("= SUCCEED setting current network VIEW " 
+ id);
                        currentNetworkViewID = id;
 
-                       // reset selected network views 
+                       // reset selected network views
                        selectedNetworkViews.clear();
                        selectedNetworkViews.add((CyNetworkView) 
(getNetworkViewMap().get(id)));
 
@@ -1111,7 +1122,7 @@
                }
 
                updateNestedNetworkNodes(network);
-               
+
                // theoretically this should not be set to null till after the 
events
                // firing is done
                network = null;
@@ -1122,8 +1133,8 @@
                if ((currentNetworkID != null) && (currentNetworkViewID == 
null))
                        getDesktop().setFocus(currentNetworkID);
        }
-       
-       
+
+
        private static void updateNestedNetworkNodes(final GraphPerspective 
destroyedNetwork) {
                for (final CyNode node: 
(List<CyNode>)Cytoscape.getRootGraph().nodesList()) {
                        if (node.getNestedNetwork() == destroyedNetwork) {
@@ -1140,14 +1151,14 @@
                        return;
 
                getSelectedNetworkViews().remove(view);
-               
+
                final String viewID = view.getIdentifier();
-               
+
                if (viewID.equals(currentNetworkViewID)) {
                        if (getNetworkViewMap().size() <= 0)
                                currentNetworkViewID = null;
                        else {
-                               // depending on which randomly chosen 
currentNetworkID we get, 
+                               // depending on which randomly chosen 
currentNetworkID we get,
                                // we may or may not have a view for it.
                                CyNetworkView newCurr = 
getNetworkViewMap().get(currentNetworkID);
 
@@ -1157,13 +1168,13 @@
                                        currentNetworkViewID = null;
                        }
                }
-               
+
                firePropertyChange(CytoscapeDesktop.NETWORK_VIEW_DESTROYED, 
null, view);
                // theoretically this should not be set to null till after the 
events
                // firing is done
                getNetworkViewMap().remove(viewID);
                view = null;
-               
+
                // so that a network will be selected.
                if (currentNetworkID != null)
                        getDesktop().setFocus(currentNetworkID);
@@ -1435,7 +1446,7 @@
                if (reader instanceof NestedNetworkReader) {
                        // This is a reader which creates multiple networks.
                        final List<CyNetwork> networks = 
((NestedNetworkReader)reader).getNetworks();
-                       
+
                        // Turn views off for performance
                        
Cytoscape.getDesktop().getNetworkViewManager().getDesktopPane().setVisible(false);
                        for (CyNetwork network : networks) {
@@ -1445,14 +1456,14 @@
                                }
                        }
                        
Cytoscape.getDesktop().getNetworkViewManager().getDesktopPane().setVisible(true);
-                       
+
                        return networks.get(0); // Root network.
                } else {
                        // get the RootGraph indices of the nodes and
                        // edges that were just created
                        final int[] nodes = reader.getNodeIndicesArray();
                        final int[] edges = reader.getEdgeIndicesArray();
-               
+
                        if (nodes == null) {
                                logger.warn("Network reader didn't return any 
nodes");
                        }
@@ -1733,7 +1744,7 @@
         * @param vs the VisualStyle in which to render this new network. If 
null,
         *           the default visual style will be used.
         */
-       public static CyNetworkView createNetworkView(CyNetwork network, String 
title, CyLayoutAlgorithm layout, VisualStyle vs) {                      
+       public static CyNetworkView createNetworkView(CyNetwork network, String 
title, CyLayoutAlgorithm layout, VisualStyle vs) {
                if (network == nullNetwork) {
                        return nullNetworkView;
                }
@@ -1744,7 +1755,7 @@
 
                final DingNetworkView view = new DingNetworkView(network, 
title);
                final VisualMappingManager vmm = 
Cytoscape.getVisualMappingManager();
-               
+
                view.setIdentifier(network.getIdentifier());
                view.setTitle(network.getTitle());
                getNetworkViewMap().put(network.getIdentifier(), view);
@@ -1760,13 +1771,13 @@
                if (layout == null) {
                        layout = CyLayouts.getDefaultLayout();
                }
-               
+
                vmm.setNetworkView(view);
                vmm.applyAppearances();
                layout.doLayout(view);
                view.setGraphLOD(new CyGraphLOD());
                
Cytoscape.firePropertyChange(cytoscape.view.CytoscapeDesktop.NETWORK_VIEW_CREATED,
 null, view);
-               
+
                return view;
        }
 
@@ -1900,21 +1911,21 @@
                final String[] nodeAttrNames = 
nodeAttributes.getAttributeNames();
                for (String name: nodeAttrNames)
                        nodeAttributes.deleteAttribute(name);
-               
+
                // Clear edge attributes
                final String[] edgeAttrNames = 
edgeAttributes.getAttributeNames();
                for (String name: edgeAttrNames)
                        edgeAttributes.deleteAttribute(name);
-               
+
                // Clear network attributes
                final String[] networkAttrNames = 
networkAttributes.getAttributeNames();
                for(String name: networkAttrNames)
                        networkAttributes.deleteAttribute(name);
-               
+
                // Reset Ontology Server
                buildOntologyServer();
                setOntologyRootID(null);
-               
+
                setCurrentSessionFileName(null);
                firePropertyChange(ATTRIBUTES_CHANGED, null, null);
                cytoscapeRootGraph = null;
@@ -1967,4 +1978,18 @@
        public static void setBookmarks(Bookmarks pBookmarks) {
                bookmarks = pBookmarks;
        }
+
+       public synchronized static RecentlyOpenedTracker 
getRecentlyOpenedSessionTracker() {
+               if (recentlyOpenedSessions == null) {
+                       final String trackerFileName = "sessions.tracker";
+                       try {
+                               recentlyOpenedSessions = new 
RecentlyOpenedTracker(trackerFileName);
+                       } catch (final IOException e) {
+                               System.err.println(e);
+                               logger.warn("Failed to load \"" + 
trackerFileName + "\"!");
+                       }
+               }
+
+               return recentlyOpenedSessions;
+       }
 }

Modified: cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java
===================================================================
--- cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-06-14 22:31:53 UTC (rev 20539)
+++ cytoscape/trunk/src/cytoscape/data/readers/CytoscapeSessionReader.java      
2010-06-15 01:49:56 UTC (rev 20540)
@@ -90,6 +90,7 @@
 import cytoscape.logger.CyLogger;
 import cytoscape.task.TaskMonitor;
 import cytoscape.util.PercentUtil;
+import cytoscape.util.RecentlyOpenedTracker;
 import cytoscape.util.URLUtil;
 import cytoscape.view.CyNetworkView;
 import cytoscape.visual.customgraphic.CustomGraphicsPool;
@@ -135,9 +136,9 @@
         *
         */
        public static final String CY_PROPS = "cytoscape.props";
-       
-       
 
+
+
        /**
         *
         */
@@ -157,7 +158,7 @@
        private Bookmarks bookmarks = null;
        private HashMap<String, List<File>> pluginFileListMap;
        private HashMap<String, List<String>> theURLstrMap = new 
HashMap<String, List<String>>();
-       
+
        private Map<String, URL> imageMap;
        private URL imagePropsURL;
 
@@ -200,6 +201,10 @@
                }
 
                this.logger = CyLogger.getLogger(CytoscapeSessionReader.class);
+
+               final RecentlyOpenedTracker sessionTracker = 
Cytoscape.getRecentlyOpenedSessionTracker();
+               if (sessionTracker != null)
+                       sessionTracker.add(sourceName);
        }
 
        /**
@@ -277,7 +282,7 @@
 
             while ((zen = zis.getNextEntry()) != null) {
                 entryName = zen.getName();
-                
+
                 if (entryName.contains("/plugins/")) {
                     extractPluginEntry(entryName);
                 } else if (entryName.endsWith(CYSESSION)) {
@@ -328,12 +333,12 @@
 
        private void extractPluginEntry(String entryName) {
                String[] items = entryName.split("/");
-               
+
                if (items.length < 3) {
                        // It's a directory name, not a file name
                        return;
                }
-               
+
                String pluginName = items[2];
                String URLstr = "jar:" + sourceURL.toString() + "!/" + 
entryName;
 
@@ -346,30 +351,30 @@
                        theURLstrMap.put(pluginName, theURLstrList);
                }
        }
-       
+
        private void restoreCustomGraphics(final String entryName, final URL 
imageURL) throws IOException {
                final String[] ent = 
entryName.split(System.getProperty("file.separator"));
                System.out.println("\n\n" + entryName + "\n\n");
                final String displayName = ent[ent.length-1];
                String name = displayName.split("\\.")[0];
-               
+
                imageMap.put(name, imageURL);
        }
-       
+
        private void createCustomGraphics() throws IOException {
                final Properties imageProps = new Properties();
                imageProps.load(URLUtil.getBasicInputStream(imagePropsURL));
-               
+
                final CustomGraphicsPool pool = 
Cytoscape.getVisualMappingManager().getCustomGraphicsPool();
                // Reset the pool
                pool.removeAll();
-               
+
                for(String hash :imageMap.keySet()) {
                        final CyCustomGraphics<?> graphics = new 
URLImageCustomGraphics(imageMap.get(hash).toString());
                        final String propEntry = imageProps.getProperty(hash);
                        String[] parts = propEntry.split(",");
                        graphics.setDisplayName(parts[parts.length-1]);
-                       
+
 //                     System.out.println("New Graphics Name ========>>>>> " + 
hash);
 //                     System.out.println("New Graphics Display Name 
========>>>>> " + graphics.getDisplayName());
                        pool.addGraphics(Integer.parseInt(hash), graphics);
@@ -387,7 +392,7 @@
 
                // All listeners should listen to this event to ignore 
unnecessary events!
                
Cytoscape.firePropertyChange(Integer.toString(Cytoscape.SESSION_OPENED), null, 
true);
-               
+
                Cytoscape.getDesktop().getVizMapperUI().initializeTableState();
 
                try {
@@ -409,7 +414,7 @@
                }
 
                //restoreNestedNetworkLinks();
-               
+
                // Send signal to others
                Cytoscape.firePropertyChange(Cytoscape.ATTRIBUTES_CHANGED, 
null, null);
                Cytoscape.firePropertyChange(Cytoscape.NETWORK_LOADED, null, 
null);
@@ -444,7 +449,7 @@
                logger.info("Session loaded in " + (System.currentTimeMillis() 
- start) + " msec.");
        }
 
-       
+
        /**
         * Restore nested network references.
         */
@@ -454,7 +459,7 @@
                // Do nothing if nested network does not exists in this session.
                if(!attrNames.contains(CyNode.NESTED_NETWORK_ID_ATTR))
                        return;
-               
+
                final Map<String, String> titleToIdMap = 
createNetworkTitleToIDMap();
                for (final CyNetwork network:Cytoscape.getNetworkSet()) {
                        for (final CyNode 
node:(List<CyNode>)network.nodesList()) {
@@ -465,11 +470,11 @@
                        }
                }
        }
-       
-       
+
+
        private Map<String, String> createNetworkTitleToIDMap() {
                final Map<String, String> titleToIdMap = new HashMap<String, 
String>();
-               
+
                Set<CyNetwork> networks = Cytoscape.getNetworkSet();
                for (CyNetwork network:networks) {
                        titleToIdMap.put(network.getTitle(), 
network.getIdentifier());
@@ -477,7 +482,7 @@
                return titleToIdMap;
        }
 
-       
+
        // Delete tmp files (the plugin state files) to cleanup
        private void deleteTmpPluginFiles() {
                if ((pluginFileListMap == null) || (pluginFileListMap.size() == 
0))
@@ -495,7 +500,7 @@
                        }
                }
        }
-       
+
        /**
         * Decompress session file
         *
@@ -513,7 +518,7 @@
                        IOException e = new IOException("Session file is broken 
or this is not a session file.");
                        throw e;
                }
-               
+
                if(imagePropsURL != null)
                        createCustomGraphics();
 
@@ -528,8 +533,8 @@
                }
 
                 /*
-                 * Even though cytoscapePropsURL is probably a local URL, 
error on the 
-                 * side of caution and use URLUtil to get the input stream 
(which 
+                 * Even though cytoscapePropsURL is probably a local URL, 
error on the
+                 * side of caution and use URLUtil to get the input stream 
(which
                  * handles proxy servers and cached pages):
                  */
                
CytoscapeInit.getProperties().load(URLUtil.getBasicInputStream(cytoscapePropsURL));
@@ -537,7 +542,7 @@
 
                // restore plugin state files
                restorePlugnStateFilesFromZip();
-               
+
                // Restore Nested Networks
                restoreNestedNetworkLinks();
        }
@@ -637,7 +642,7 @@
 
                try {
                        // InputStream is = pBookmarksFileURL.openStream();
-                       // Use URLUtil to get the InputStream since we might be 
using a proxy server 
+                       // Use URLUtil to get the InputStream since we might be 
using a proxy server
                        // and because pages may be cached:
                        final JAXBContext jaxbContext = 
JAXBContext.newInstance(BOOKMARK_PACKAGE_NAME,
                                                                                
this.getClass().getClassLoader());
@@ -664,8 +669,8 @@
 
                return theBookmark;
        }
-       
 
+
        private void loadCySession() throws JAXBException, IOException, 
Exception {
                // InputStream is = cysessionFileURL.openStream();
                // Even though cytoscapeFileURL is probably a local URL, error 
on the
@@ -685,7 +690,7 @@
                                is.close();
             }
                }
-               
+
                /*
                 * Session ID is the name of folder which contains everything 
for this
                 * session.
@@ -701,7 +706,7 @@
        }
 
        private void restoreDesktopState() {
-               
+
                // Restore Desktop size
                Cytoscape.getDesktop()
                         
.setSize(session.getSessionState().getDesktop().getDesktopSize().getWidth()

Modified: cytoscape/trunk/src/cytoscape/util/RecentlyOpenedTracker.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/RecentlyOpenedTracker.java       
2010-06-14 22:31:53 UTC (rev 20539)
+++ cytoscape/trunk/src/cytoscape/util/RecentlyOpenedTracker.java       
2010-06-15 01:49:56 UTC (rev 20540)
@@ -25,6 +25,9 @@
  along with this library; if not, write to the Free Software Foundation,
  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */
+package cytoscape.util;
+
+
 import cytoscape.CytoscapeInit;
 
 import java.io.BufferedReader;
@@ -33,17 +36,18 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.net.URL;
 import java.util.List;
 import java.util.LinkedList;
 
 
 /**
- *  A class to keep track of a short list of recently opened files.
+ *  A class to keep track of a short list of recently opened URLs.
  */
 public class RecentlyOpenedTracker {
        private static final int MAX_TRACK_COUNT = 5;
        private final String trackerFileName;
-       private final LinkedList<String> fileNames;
+       private final LinkedList<URL> trackerURLs;
 
        /**
         *  Creates a "recently opened" file tracker.
@@ -53,33 +57,37 @@
         */
        public RecentlyOpenedTracker(final String trackerFileName) throws 
IOException {
                this.trackerFileName = trackerFileName;
-               fileNames = new LinkedList<String>();
+               trackerURLs = new LinkedList<URL>();
+
                final File input = new 
File(CytoscapeInit.getConfigVersionDirectory(), trackerFileName);
+               if (!input.exists())
+                       input.createNewFile();
+
                final BufferedReader reader = new BufferedReader(new 
FileReader(input));
                String line;
-               while ((line = reader.readLine()) != null && fileNames.size() < 
MAX_TRACK_COUNT) {
-                       final String newFileName = line.trim();
-                       if (newFileName.length() > 0)
-                               fileNames.addLast(newFileName);
+               while ((line = reader.readLine()) != null && trackerURLs.size() 
< MAX_TRACK_COUNT) {
+                       final String newURL = line.trim();
+                       if (newURL.length() > 0)
+                               trackerURLs.addLast(new URL(newURL));
                }
        }
 
        /**
         *  @returns the current list of recently opened file names
         */
-       @SuppressWarnings("unchecked") public List<String> 
getRecentlyOpenedFiles() {
-                return (List<String>)fileNames.clone();
+       @SuppressWarnings("unchecked") public synchronized List<URL> 
getRecentlyOpenedURLs() {
+                return (List<URL>)trackerURLs.clone();
        }
 
        /**
-        *  Adds "newFileName" to the list of recently opened file names and 
trims the list if it has
+        *  Adds "newURL" to the list of recently opened file names and trims 
the list if it has
         *  exceeded its maximum length.
         */
-       public void addFileName(final String newFileName) {
-               fileNames.remove(newFileName);
-               if (fileNames.size() == MAX_TRACK_COUNT)
-                       fileNames.removeLast();
-               fileNames.addFirst(newFileName);
+       public synchronized void add(final URL newURL) {
+               trackerURLs.remove(newURL);
+               if (trackerURLs.size() == MAX_TRACK_COUNT)
+                       trackerURLs.removeLast();
+               trackerURLs.addFirst(newURL);
        }
 
        /**
@@ -87,8 +95,18 @@
         */
        public void writeOut() throws FileNotFoundException {
                final PrintWriter writer = new PrintWriter(new 
File(CytoscapeInit.getConfigVersionDirectory(), trackerFileName));
-               for (final String fileName : fileNames)
-                       writer.println(fileName);
+               for (final URL trackerURL : trackerURLs)
+                       writer.println(trackerURL.toString());
                writer.close();
        }
+
+       /**
+        *  @return the last addition or null if there are no URLs
+        */
+       public synchronized URL getMostRecentAddition() {
+               if (trackerURLs.isEmpty())
+                       return null;
+               else
+                       return trackerURLs.getFirst();
+       }
 }
\ No newline at end of file

Modified: cytoscape/trunk/src/cytoscape/view/CyMenus.java
===================================================================
--- cytoscape/trunk/src/cytoscape/view/CyMenus.java     2010-06-14 22:31:53 UTC 
(rev 20539)
+++ cytoscape/trunk/src/cytoscape/view/CyMenus.java     2010-06-15 01:49:56 UTC 
(rev 20540)
@@ -29,6 +29,7 @@
 */
 package cytoscape.view;
 
+
 import giny.view.GraphViewChangeEvent;
 import giny.view.GraphViewChangeListener;
 
@@ -38,7 +39,10 @@
 import java.awt.event.MouseWheelListener;
 import java.awt.event.ActionListener;
 import java.awt.event.ActionEvent;
-
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.net.URL;
+import java.util.List;
 import javax.help.CSH;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
@@ -46,6 +50,7 @@
 import javax.swing.JSeparator;
 import javax.swing.JOptionPane;
 import javax.swing.Action;
+import javax.swing.JMenuItem;
 
 import org.jdesktop.swingx.JXTitledSeparator;
 
@@ -56,6 +61,7 @@
 import cytoscape.util.CytoscapeAction;
 import cytoscape.util.CytoscapeMenuBar;
 import cytoscape.util.CytoscapeToolBar;
+import cytoscape.util.RecentlyOpenedTracker;
 import cytoscape.util.undo.RedoAction;
 import cytoscape.util.undo.UndoAction;
 import cytoscape.view.cytopanels.CytoPanelName;
@@ -69,8 +75,7 @@
  * writers can use this function to specify the location of the menu item.
  * </p>
  */
-public class CyMenus implements GraphViewChangeListener {
-
+public class CyMenus implements GraphViewChangeListener, 
PropertyChangeListener {
        boolean menusInitialized = false;
 
        CytoscapeMenuBar menuBar;
@@ -89,6 +94,7 @@
        JMenu vizMenu;
        JMenu helpMenu;
        JMenu opsMenu;
+       JMenu recentlyOpenedSubMenu;
 
        JButton openSessionButton;
        JButton saveButton;
@@ -104,10 +110,11 @@
        JButton vizButton;
 
        /**
-        * Creates a new CyMenus object. This will construct the basic bar 
objects, 
+        * Creates a new CyMenus object. This will construct the basic bar 
objects,
         * but won't fill them with menu items and associated action listeners.
         */
        public CyMenus() {
+               
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(this);
 
                toolBar = new CytoscapeToolBar();
 
@@ -118,6 +125,8 @@
                newSubMenu2 = menuBar.getMenu("File.New.Network");
                loadSubMenu = menuBar.getMenu("File.Import", 1);
                saveSubMenu = menuBar.getMenu("File.Export", 2);
+               recentlyOpenedSubMenu = menuBar.getMenu("File.Recently Opened", 
3);
+               initRecentlyOpenedSubMenu();
                editMenu = menuBar.getMenu("Edit");
                viewMenu = menuBar.getMenu("View");
                selectMenu = menuBar.getMenu("Select");
@@ -126,6 +135,16 @@
                helpMenu = menuBar.getMenu("Help");
        }
 
+       private void initRecentlyOpenedSubMenu() {
+               final RecentlyOpenedTracker sessionTracker = 
Cytoscape.getRecentlyOpenedSessionTracker();
+               if (sessionTracker == null)
+                       return;
+
+               final List<URL> recentlyOpenedSessions = 
sessionTracker.getRecentlyOpenedURLs();
+               for (final URL url : recentlyOpenedSessions)
+                       recentlyOpenedSubMenu.add(new JMenuItem(new 
OpenRecentAction(url)));
+       }
+
        /**
         * Returns the main menu bar constructed by this object.
         */
@@ -199,7 +218,7 @@
 
        /**
         * Returns the menu with items associated with plugins. Most plugins 
grab
-        * this menu and add their menu option. 
+        * this menu and add their menu option.
         */
        public JMenu getOperationsMenu() {
                return opsMenu;
@@ -220,7 +239,7 @@
        }
 
        /**
-        * Add the menu item. 
+        * Add the menu item.
         *
         * @param action
         */
@@ -285,7 +304,7 @@
 
        /**
         * We are not listening for any GraphViewChangeEvents.  MenuItems are 
responsible for
-        * updating their own state, which is generally accomplished by 
implementing the menuSelected() 
+        * updating their own state, which is generally accomplished by 
implementing the menuSelected()
         * method.
         *
         * @param e
@@ -294,14 +313,14 @@
 
        /**
         * Used to return the cytopanels menu.
-        * @deprecated Will be removed April 2008. Cytopanels no longer have a 
separate menu (they're in View). 
+        * @deprecated Will be removed April 2008. Cytopanels no longer have a 
separate menu (they're in View).
         */
        public JMenu getCytoPanelMenu() {
                return null;
        }
 
        /**
-        * Used to set up the CytoPanelMenu items. 
+        * Used to set up the CytoPanelMenu items.
         * @deprecated Will be removed April 2008. Cytopanels are initialized 
in the Display* actions. Do not use.
         */
        public void initCytoPanelMenus() { }
@@ -331,7 +350,7 @@
 
                //
                // File menu
-               // 
+               //
 
                // New submenu
                addAction(new NewSessionAction());
@@ -341,18 +360,18 @@
                addAction(new NewNetworkAction());
 
                addAction(new OpenSessionAction(),1);
-               
+
                addAction(new SaveSessionAction("Save"),2);
                addAction(new SaveSessionAsAction("Save as..."),3);
 
                fileMenu.add(new JSeparator(), 2);
                fileMenu.add(new JSeparator(), 5);
-               
-               
+
+
                // Import sub menu
                addAction(new ImportGraphFileAction(this));
                addAction(new WebServiceNetworkImportAction());
-               
+
                loadSubMenu.add(new JSeparator());
 
                addAction(new ImportNodeAttributesAction());
@@ -360,7 +379,7 @@
                addAction(new ImportExpressionMatrixAction());
 
                addAction(new ImportVizmapAction());
-               
+
                loadSubMenu.add(new JSeparator());
 
                // Save submenu
@@ -392,7 +411,7 @@
                editMenu.add(new JSeparator());
 
                addAction(new DeleteAction());
-               
+
                editMenu.add(new JSeparator());
 
                addAction(new PreferenceAction());
@@ -435,23 +454,23 @@
 
                //
                // View menu
-               // 
+               //
                addAction(new CytoPanelAction(CytoPanelName.WEST,true,null));
                addAction(new CytoPanelAction(CytoPanelName.SOUTH,true,null));
                addAction(new CytoPanelAction(CytoPanelName.EAST,false,null));
                addAction(new CytoPanelAction(CytoPanelName.SOUTH_WEST,false, 
CytoPanelName.WEST));
-               
+
                viewMenu.add(new JSeparator());
-               
+
                addAction(new ShowGraphicsDetailsAction());
-               
+
                viewMenu.add(new JSeparator());
                addAction(new SetVisualPropertiesAction());
                addAction(new ShowCustomGraphicsManagerAction());
                viewMenu.add(new JSeparator());
-               
+
                viewMenu.add(new ArrangeAction());
-               
+
                //
                // Layout menu
                //
@@ -468,7 +487,7 @@
 
                opsMenu.addSeparator();
 
-               // 
+               //
                // Help menu
                //
                addAction(new HelpContentsAction());
@@ -602,7 +621,7 @@
                toolBar.addSeparator();
 
                helpButton = new JButton();
-               helpButton.addActionListener( new ActionListener() { 
+               helpButton.addActionListener( new ActionListener() {
                        private CSH.DisplayHelpFromSource csh;
                        public void actionPerformed(ActionEvent e) {
                                if ( csh == null ) {
@@ -629,5 +648,20 @@
                                                    
.getResource("images/ximian/stock_file-with-objects.png")));
                vizButton.setToolTipText("Open VizMapper\u2122");
                vizButton.setBorderPainted(false);
-       } 
+       }
+
+       public void propertyChange(PropertyChangeEvent e) {
+               if 
(!e.getPropertyName().equals(Integer.toString(Cytoscape.SESSION_OPENED)))
+                       return;
+
+               final RecentlyOpenedTracker sessionTracker = 
Cytoscape.getRecentlyOpenedSessionTracker();
+               if (sessionTracker == null)
+                       return;
+
+               final URL mostRecentlyAddedSession = 
sessionTracker.getMostRecentAddition();
+               if (mostRecentlyAddedSession == null)
+                       return;
+
+               recentlyOpenedSubMenu.add(new JMenuItem(new 
OpenRecentAction(mostRecentlyAddedSession)));
+       }
 }

Added: cytoscape/trunk/src/cytoscape/view/OpenRecentAction.java
===================================================================
--- cytoscape/trunk/src/cytoscape/view/OpenRecentAction.java                    
        (rev 0)
+++ cytoscape/trunk/src/cytoscape/view/OpenRecentAction.java    2010-06-15 
01:49:56 UTC (rev 20540)
@@ -0,0 +1,77 @@
+/*
+ File: OpenRecentAction.java
+
+ Copyright (c) 2006, 2010, 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 cytoscape.view;
+
+
+import cytoscape.Cytoscape;
+import cytoscape.data.readers.CytoscapeSessionReader;
+import cytoscape.logger.CyLogger;
+
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.net.URL;
+import javax.swing.AbstractAction;
+
+
+class OpenRecentAction extends AbstractAction {
+       private URL sessionFileURL;
+       private CyLogger logger;
+
+       OpenRecentAction(final URL sessionFileURL) {
+               super(sessionFileURL.toString());
+
+               this.sessionFileURL = sessionFileURL;
+               this.logger = CyLogger.getLogger(OpenRecentAction.class);
+       }
+
+       public void actionPerformed(final ActionEvent e) {
+               try {
+                       final CytoscapeSessionReader reader = new 
CytoscapeSessionReader(sessionFileURL);
+                       if (reader == null) {
+                               logger.warn("Failed to load: " + 
sessionFileURL);
+                               return;
+                       }
+                       try {
+                               reader.read();
+                       } catch (final Exception ex1) {
+                               logger.warn("Failed to load: " + 
sessionFileURL);
+                               return;
+                       }
+
+                       final String sessionName = sessionFileURL.toString();
+                       Cytoscape.setCurrentSessionFileName(sessionName);
+                       Cytoscape.getDesktop().setTitle("Cytoscape Desktop 
(Session Name: " + sessionName + ")");
+
+               } catch (final IOException ex2) {
+                       logger.warn("Failed to open session: " + 
sessionFileURL);
+                       System.err.println(ex2);
+               }
+       }
+}

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