Author: kono
Date: 2012-05-01 17:26:50 -0700 (Tue, 01 May 2012)
New Revision: 29070

Modified:
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/QuickStartStartup.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/SessionHandler.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/actions/RecentSessionManager.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/BookmarkDialogFactoryImpl.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/shutdown/ConfigDirPropertyWriter.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/BirdsEyeViewHandler.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkPanel.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolBarEnableUpdater.java
   
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolCytoPanelListener.java
Log:
refs #892 GUI related code sections in handleEvent() methods are called by 
invokeLater().

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/QuickStartStartup.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/QuickStartStartup.java
 2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/QuickStartStartup.java
 2012-05-02 00:26:50 UTC (rev 29070)
@@ -1,5 +1,7 @@
 package org.cytoscape.internal;
 
+import javax.swing.SwingUtilities;
+
 import org.cytoscape.application.events.CyStartEvent;
 import org.cytoscape.application.events.CyStartListener;
 import org.cytoscape.application.swing.CySwingApplication;
@@ -11,18 +13,27 @@
  */
 public class QuickStartStartup implements CyStartListener {
 
-       private TaskFactory quickStartTaskFactory;
-       private DialogTaskManager guiTaskManager;
-       private CySwingApplication swingApp;
-       
-       public QuickStartStartup(TaskFactory quickStartTaskFactory, 
DialogTaskManager guiTaskManager, CySwingApplication swingApp){     
+       private final TaskFactory quickStartTaskFactory;
+       private final DialogTaskManager guiTaskManager;
+       private final CySwingApplication swingApp;
+
+       public QuickStartStartup(final TaskFactory quickStartTaskFactory, final 
DialogTaskManager guiTaskManager,
+                       final CySwingApplication swingApp) {
                this.quickStartTaskFactory = quickStartTaskFactory;
                this.guiTaskManager = guiTaskManager;
                this.swingApp = swingApp;
        }
+
        
-       public void handleEvent(CyStartEvent e){
-               guiTaskManager.setExecutionContext(swingApp.getJFrame());
-               
guiTaskManager.execute(quickStartTaskFactory.createTaskIterator());
-       }       
+       @Override
+       public void handleEvent(CyStartEvent e) {
+               
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               
guiTaskManager.setExecutionContext(swingApp.getJFrame());
+                               
guiTaskManager.execute(quickStartTaskFactory.createTaskIterator());
+                       }
+               });
+       }
 }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/SessionHandler.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/SessionHandler.java
    2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/SessionHandler.java
    2012-05-02 00:26:50 UTC (rev 29070)
@@ -43,6 +43,7 @@
 
 import javax.swing.JInternalFrame;
 import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
 
 import org.cytoscape.application.events.CyShutdownEvent;
 import org.cytoscape.application.events.CyShutdownListener;
@@ -107,7 +108,7 @@
        }
 
        @Override
-       public void handleEvent(CyShutdownEvent e) {
+       public void handleEvent(final CyShutdownEvent e) {
                // If there are no networks, just quit.
                if (netMgr.getNetworkSet().size() == 0) 
                        return;
@@ -134,91 +135,106 @@
        }
 
        @Override
-       public void handleEvent(SessionAboutToBeSavedEvent e) {
+       public void handleEvent(final SessionAboutToBeSavedEvent e) {
+               // Do not use invokeLater() here!  It breaks session file.
+               prepareForSaving(e);
+       }
+       
+       private final void prepareForSaving(final SessionAboutToBeSavedEvent e) 
{
                final SessionState sessState = new SessionState();
-               
+
                // Network Frames
                final NetworkFrames netFrames = new NetworkFrames();
                sessState.setNetworkFrames(netFrames);
-               
+
                final JInternalFrame[] internalFrames = 
netViewMgr.getDesktopPane().getAllFrames();
-       
-       for (JInternalFrame iframe : internalFrames) {
-               final CyNetworkView view = netViewMgr.getNetworkView(iframe);
-               
-               if (view == null) {
+
+               for (JInternalFrame iframe : internalFrames) {
+                       final CyNetworkView view = 
netViewMgr.getNetworkView(iframe);
+
+                       if (view == null) {
                                logger.error("Cannot save position of network 
frame \"" + iframe.getTitle()
                                                + "\": Network View is null.");
-                       continue;
-               }
-               
-               final NetworkFrame nf = new NetworkFrame();
-            nf.setNetworkViewID(view.getSUID().toString());
-            nf.setX(BigInteger.valueOf(iframe.getX()));
-            nf.setY(BigInteger.valueOf(iframe.getY()));
-               
-            netFrames.getNetworkFrame().add(nf);
-       }
-               
-        // CytoPanels States
-       final Cytopanels cytopanels = new Cytopanels();
+                               continue;
+                       }
+
+                       final NetworkFrame nf = new NetworkFrame();
+                       nf.setNetworkViewID(view.getSUID().toString());
+                       nf.setX(BigInteger.valueOf(iframe.getX()));
+                       nf.setY(BigInteger.valueOf(iframe.getY()));
+
+                       netFrames.getNetworkFrame().add(nf);
+               }
+
+               // CytoPanels States
+               final Cytopanels cytopanels = new Cytopanels();
                sessState.setCytopanels(cytopanels);
-               
+
                for (Map.Entry<String, CytoPanelName> entry : 
CYTOPANEL_NAMES.entrySet()) {
                        final CytoPanel p = 
desktop.getCytoPanel(entry.getValue());
-                       
+
                        final Cytopanel cytopanel = new Cytopanel();
                        cytopanel.setId(entry.getKey());
                        cytopanel.setPanelState(p.getState().toString());
                        
cytopanel.setSelectedPanel(Integer.toString(p.getSelectedIndex()));
-                       
+
                        cytopanels.getCytopanel().add(cytopanel);
                }
-               
+
                // Create temp file
                File tmpFile = new File(System.getProperty("java.io.tmpdir"), 
SESSION_STATE_FILENAME);
                tmpFile.deleteOnExit();
-               
+
                // Write to the file
                sessionStateIO.write(sessState, tmpFile);
-               
+
                // Add it to the apps list
                List<File> fileList = new ArrayList<File>();
                fileList.add(tmpFile);
-               
+
                try {
                        e.addAppFiles(APP_NAME, fileList);
                } catch (Exception ex) {
-                       logger.error("Error adding "+SESSION_STATE_FILENAME+" 
file to be saved in the session.", ex);
+                       logger.error("Error adding " + SESSION_STATE_FILENAME + 
" file to be saved in the session.", ex);
                }
        }
 
        @Override
-       public void handleEvent(SessionLoadedEvent e) {
+       public void handleEvent(final SessionLoadedEvent e) {
                final CySession sess = e.getLoadedSession();
 
-               if (sess != null) {
-                       final Map<String, List<File>> filesMap = 
sess.getAppFileListMap();
+               if (sess == null)
+                       return;
+               
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               postLoading(sess);
+                       }
+               });
+       }
+       
+       private final void postLoading(final CySession sess) {
+               final Map<String, List<File>> filesMap = 
sess.getAppFileListMap();
 
-                       if (filesMap != null) {
-                               final List<File> files = filesMap.get(APP_NAME);
+               if (filesMap != null) {
+                       final List<File> files = filesMap.get(APP_NAME);
 
-                               if (files != null) {
-                                       SessionState sessState = null;
-                                       
-                                       for (File f : files) {
-                                               if 
(f.getName().endsWith(SESSION_STATE_FILENAME)) {
-                                                       // There should be only 
one file!
-                                                       sessState = 
sessionStateIO.read(f);
-                                                       break;
-                                               }
+                       if (files != null) {
+                               SessionState sessState = null;
+                               
+                               for (File f : files) {
+                                       if 
(f.getName().endsWith(SESSION_STATE_FILENAME)) {
+                                               // There should be only one 
file!
+                                               sessState = 
sessionStateIO.read(f);
+                                               break;
                                        }
-                                       
-                                       if (sessState != null) {
-                                               
setNetworkFrameLocations(sessState.getNetworkFrames(), sess);
-                                               
setCytoPanelStates(sessState.getCytopanels());
-                                       }
                                }
+                               
+                               if (sessState != null) {
+                                       
setNetworkFrameLocations(sessState.getNetworkFrames(), sess);
+                                       
setCytoPanelStates(sessState.getCytopanels());
+                               }
                        }
                }
        }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/actions/RecentSessionManager.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/actions/RecentSessionManager.java
      2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/actions/RecentSessionManager.java
      2012-05-02 00:26:50 UTC (rev 29070)
@@ -10,6 +10,8 @@
 import java.util.Properties;
 import java.util.Set;
 
+import javax.swing.SwingUtilities;
+
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.events.CyShutdownEvent;
 import org.cytoscape.application.events.CyShutdownListener;
@@ -22,6 +24,7 @@
 import org.cytoscape.session.CySessionManager;
 import org.cytoscape.session.events.SessionLoadedEvent;
 import org.cytoscape.session.events.SessionLoadedListener;
+import org.cytoscape.work.ServiceProperties;
 import org.cytoscape.work.TaskFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -64,7 +67,6 @@
        }
 
        private void updateMenuItems() {
-               
                // If there is no recent items, add dummy menu.
                if(tracker.getRecentlyOpenedURLs().size() == 0) {
                        registrar.registerService(factory, CyAction.class, new 
Properties());
@@ -82,9 +84,9 @@
 
                for (final URL url : urls) {
                        final Properties prop = new Properties();
-                       prop.put("preferredMenu", MENU_CATEGORY);
-                       prop.put("title", url.getFile());
-                       prop.put("menuGravity", "6.0");
+                       prop.put(ServiceProperties.PREFERRED_MENU, 
MENU_CATEGORY);
+                       prop.put(ServiceProperties.TITLE, url.getFile());
+                       prop.put(ServiceProperties.MENU_GRAVITY, "6.0");
                        final OpenRecentSessionTaskFactory factory = new 
OpenRecentSessionTaskFactory(sessionManager, readerManager, appManager, 
tracker, url);
                        registrar.registerService(factory, TaskFactory.class, 
prop);
 
@@ -96,6 +98,13 @@
        @Override
        public void handleEvent(SessionLoadedEvent e) {
                updateMenuItems();
+               
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               updateMenuItems();
+                       }
+               });
        }
        
        
@@ -127,7 +136,4 @@
                        throw new RuntimeException("Could not save recently 
opened session file list.", ex);
                }
        }
-       
-       
-
 }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/BookmarkDialogFactoryImpl.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/BookmarkDialogFactoryImpl.java
 2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/dialogs/BookmarkDialogFactoryImpl.java
 2012-05-02 00:26:50 UTC (rev 29070)
@@ -2,6 +2,8 @@
 
 import java.awt.Frame;
 
+import javax.swing.SwingUtilities;
+
 import org.cytoscape.property.CyProperty;
 import org.cytoscape.property.bookmark.Bookmarks;
 import org.cytoscape.property.bookmark.BookmarksUtil;
@@ -24,11 +26,18 @@
        }
        
        @Override
-       @SuppressWarnings("unchecked")
-       public void handleEvent(SessionLoadedEvent e) {
+       public void handleEvent(final SessionLoadedEvent e) {
+               
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               updateBookmarks(e.getLoadedSession());
+                       }
+               });
+       }
+       
+       private void updateBookmarks(final CySession sess) {
                // Update bookmarks
-               CySession sess = e.getLoadedSession();
-               
                if (sess != null) {
                        for (CyProperty<?> p : sess.getProperties()) {
                                if 
(Bookmarks.class.isAssignableFrom(p.getPropertyType())) {

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/shutdown/ConfigDirPropertyWriter.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/shutdown/ConfigDirPropertyWriter.java
  2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/shutdown/ConfigDirPropertyWriter.java
  2012-05-02 00:26:50 UTC (rev 29070)
@@ -43,7 +43,7 @@
                        
                        final File outputFile = new 
File(config.getConfigurationDirectoryLocation(), propertyFileName);
                        
-                       Properties props = (Properties) 
keyAndValue.getKey().getProperties();
+                       final Properties props = (Properties) 
keyAndValue.getKey().getProperties();
 
                        try {
                                FileOutputStream out = new 
FileOutputStream(outputFile);
@@ -53,9 +53,7 @@
                        catch(Exception e){
                                logger.error("Error in wring properties file!");
                        }
-                       
                }
-               
        }
 
        public void addCyProperty(final CyProperty newCyProperty, final Map 
properties) {

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
     2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/util/undo/UndoMonitor.java
     2012-05-02 00:26:50 UTC (rev 29070)
@@ -84,17 +84,19 @@
         return lim;
     }
 
+
        /**
-        * This method listens for changes to the current network and discards 
all edits
-        * when the network changes. 
-        *
+        * This method listens for changes to the current network and discards 
all
+        * edits when the network changes.
+        * 
         * @param e The change event.
         */
-    public void handleEvent(SetCurrentNetworkViewEvent e) {
-               if ( e.getNetworkView() != null )
+       public void handleEvent(final SetCurrentNetworkViewEvent e) {
+               if (e.getNetworkView() != null)
                        undo.getUndoManager().discardAllEdits();
-    }
+       }
 
+
     /**
         * This method listens for a network destroy event. If the network 
being destroyed 
         * is the only available network, it discards all of its edits. Hence, 
when more

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/BirdsEyeViewHandler.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/BirdsEyeViewHandler.java
  2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/BirdsEyeViewHandler.java
  2012-05-02 00:26:50 UTC (rev 29070)
@@ -44,18 +44,23 @@
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
 import java.awt.event.ComponentListener;
-import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
 
+import javax.help.CSH.Manager;
 import javax.swing.JDesktopPane;
 import javax.swing.JInternalFrame;
 import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
 
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.events.SetCurrentRenderingEngineEvent;
 import org.cytoscape.application.events.SetCurrentRenderingEngineListener;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.CyNetworkViewManager;
 import org.cytoscape.view.model.events.NetworkViewDestroyedEvent;
 import org.cytoscape.view.model.events.NetworkViewDestroyedListener;
 import org.cytoscape.view.presentation.RenderingEngine;
@@ -107,7 +112,7 @@
                this.networkViewManager = viewmgr;
                this.renderingEngineManager = renderingEngineManager;
                
-               presentationMap = new HashMap<CyNetworkView, JPanel>();
+               presentationMap = new WeakHashMap<CyNetworkView, JPanel>();
 
                this.bevPanel = new JPanel();
                this.bevPanel.setPreferredSize(DEF_PANEL_SIZE);
@@ -169,6 +174,16 @@
        @Override
        public void handleEvent(final SetCurrentRenderingEngineEvent e) {
                final RenderingEngine<CyNetwork> newEngine = 
e.getRenderingEngine();
+               
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               updateBEV(newEngine);
+                       }
+               });
+       }
+       
+       private final void updateBEV(final RenderingEngine<CyNetwork> 
newEngine) {
                final CyNetworkView newViewModel = (CyNetworkView) 
newEngine.getViewModel();
                
                // Remove it from the manager object.
@@ -192,17 +207,38 @@
                presentationPanel.setSize(currentPanelSize);
                presentationPanel.setPreferredSize(currentPanelSize);
                
+               // TODO: Update timing is not correct.
                bevPanel.add(presentationPanel, BorderLayout.CENTER);
                setFocus();
                
                presentationPanel.repaint();            
                bevPanel.repaint();
-               
-               //System.out.println("#10 of rendering engine ===> " + 
renderingEngineManager.getAllRenderingEngines().size());
        }
 
        @Override
-       public void handleEvent(NetworkViewDestroyedEvent e) {
+       public void handleEvent(final NetworkViewDestroyedEvent e) {
+               final CyNetworkViewManager manager = e.getSource();
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               removeView(manager);
+                       }
+               });
+       }
+       
+       private final void removeView(final CyNetworkViewManager manager) {
+               Set<CyNetworkView> toBeRemoved = new HashSet<CyNetworkView>();
+               for(CyNetworkView view: this.presentationMap.keySet()) {
+                       if(manager.getNetworkViewSet().contains(view) == false)
+                               toBeRemoved.add(view);
+               }
+               
+               for(CyNetworkView view: toBeRemoved)
+                       presentationMap.remove(view);
+
+               toBeRemoved.clear();
+               toBeRemoved = null;
+               
                // Cleanup the visualization container
                if (appManager.getCurrentNetworkView() == null) {
                        bevPanel.removeAll();

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
     2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/CytoscapeDesktop.java
     2012-05-02 00:26:50 UTC (rev 29070)
@@ -417,25 +417,40 @@
        // handle CytoscapeStartEvent
        @Override
        public void handleEvent(CyStartEvent e) {
-               this.setVisible(true);
-               this.toFront();
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               setVisible(true);
+                               toFront();
+                       }
+               });
        }
 
        @Override
        public void handleEvent(SessionLoadedEvent e) {
                // Update window title
                String sessionName = e.getLoadedFileName();
-               
                if (sessionName == null)
                        sessionName = NEW_SESSION_NAME;
+               final String title = TITLE_PREFIX_STRING + sessionName;
                
-               this.setTitle(TITLE_PREFIX_STRING + sessionName);
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               setTitle(title);
+                       }
+               });
        }
 
        @Override
        public void handleEvent(SessionSavedEvent e) {
                // Update window title
                final String sessionName = e.getSavedFileName();
-               this.setTitle(TITLE_PREFIX_STRING + sessionName);
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               setTitle(TITLE_PREFIX_STRING + sessionName);
+                       }
+               });
        }
 }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkPanel.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkPanel.java
 2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkPanel.java
 2012-05-02 00:26:50 UTC (rev 29070)
@@ -136,10 +136,12 @@
        private boolean ignoreTreeSelectionEvents;
 
        /**
-        * Constructor for the Network Panel.
-        * @param factoryProvisioner 
         * 
-        * @param desktop
+        * @param applicationManager
+        * @param netmgr
+        * @param networkViewManager
+        * @param bird
+        * @param taskManager
         */
        public NetworkPanel(final CyApplicationManager applicationManager, 
final CyNetworkManager netmgr,
                        final CyNetworkViewManager networkViewManager, final 
BirdsEyeViewHandler bird,
@@ -464,7 +466,7 @@
 
        @Override
        public void handleEvent(final NetworkViewAddedEvent nde) {
-               SwingUtilities.invokeLater( new Runnable() {
+               SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                                final CyNetworkView netView = 
nde.getNetworkView();
                                logger.debug("Network view added to 
NetworkPanel: " + netView.getModel().getSUID());

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
   2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/NetworkViewManager.java
   2012-05-02 00:26:50 UTC (rev 29070)
@@ -47,6 +47,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.WeakHashMap;
 
 import javax.swing.JDesktopPane;
 import javax.swing.JInternalFrame;
@@ -61,6 +62,7 @@
 import org.cytoscape.application.events.SetCurrentNetworkViewListener;
 import org.cytoscape.application.swing.CyHelpBroker;
 import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyTable;
 import org.cytoscape.model.events.RowSetRecord;
 import org.cytoscape.model.events.RowsSetEvent;
 import org.cytoscape.model.events.RowsSetListener;
@@ -124,12 +126,7 @@
        private final CyApplicationManager applicationManager;
        private final RenderingEngineManager renderingEngineManager;
 
-       /**
-        * Creates a new NetworkViewManager object.
-        * 
-        * @param desktop
-        *            DOCUMENT ME!
-        */
+       
        public NetworkViewManager(CyApplicationManager appMgr, 
CyNetworkViewManager netViewMgr,final RenderingEngineManager 
renderingEngineManager,
                        CyProperty<Properties> cyProps, CyHelpBroker help) {
 
@@ -151,9 +148,9 @@
                // add Help hooks
                help.getHelpBroker().enableHelp(desktopPane, 
"network-view-manager", null);
 
-               presentationContainerMap = new HashMap<CyNetworkView, 
JInternalFrame>();
-               presentationMap = new HashMap<CyNetworkView, 
RenderingEngine<CyNetwork>>();
-               iFrameMap = new HashMap<JInternalFrame, CyNetworkView>();
+               presentationContainerMap = new WeakHashMap<CyNetworkView, 
JInternalFrame>();
+               presentationMap = new WeakHashMap<CyNetworkView, 
RenderingEngine<CyNetwork>>();
+               iFrameMap = new WeakHashMap<JInternalFrame, CyNetworkView>();
                currentView = null;
        }
 
@@ -247,13 +244,16 @@
        // // Event Handlers ////
        @Override
        public void handleEvent(SetCurrentNetworkViewEvent e) {
-               if (e.getNetworkView() == null) {
+               final CyNetworkView view = e.getNetworkView();
+               if (view == null) {
                        logger.info("Attempting to set current network view 
model: null view ");
                        return;
                }
 
                logger.info("Attempting to set current network view model: View 
Model ID = " + e.getNetworkView().getSUID());
-               setFocus(e.getNetworkView());
+               
+               // Do not use invokeLater() here! It cause all kinds of 
threading problem.
+               setFocus(view);
        }
 
        @Override
@@ -268,14 +268,25 @@
                if(views.size() != 0)
                        view = views.iterator().next();
                
-               if (view != null)
-                       setFocus(view);
+               if (view == null)
+                       return;
+               
+               final CyNetworkView targetView = view;
+       
+               // Do not use invokeLater() here! It cause all kinds of 
threading problem.
+               setFocus(targetView);
        }
 
        @Override
        public void handleEvent(NetworkViewAboutToBeDestroyedEvent nvde) {
                logger.info("Network view destroyed: View ID = " + 
nvde.getNetworkView());
-               removeView(nvde.getNetworkView());
+               final CyNetworkView view = nvde.getNetworkView();
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               removeView(view);
+                       }
+               });
        }
 
        /**
@@ -320,16 +331,17 @@
                }
        }
 
-       protected void removeView(final CyNetworkView view) {
+       private final void removeView(final CyNetworkView view) {
                try {
-                       final JInternalFrame frame = 
presentationContainerMap.get(view);
+                       JInternalFrame frame = 
presentationContainerMap.get(view);
                        if (frame != null) {
                                RenderingEngine<CyNetwork> removed = 
this.presentationMap.remove(view);
-                               logger.debug("#### Removing rendering engine: " 
+ removed);
+                               logger.debug("Removing rendering engine: " + 
removed);
                                removed = null;
                                iFrameMap.remove(frame);
                                presentationContainerMap.remove(view);
                                frame.dispose();
+                               frame = null;
                        }
                } catch (Exception e) {
                        logger.error("Network View unable to be killed", e);
@@ -439,8 +451,18 @@
        }
        
        @Override
-       public void handleEvent(NetworkViewChangedEvent e) {
-               for ( ViewChangeRecord<CyNetwork> record : 
e.getPayloadCollection()) {
+       public void handleEvent(final NetworkViewChangedEvent e) {
+               final Collection<ViewChangeRecord<CyNetwork>> records = 
e.getPayloadCollection();
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               updateInternalFrame(records);
+                       }
+               });
+       }
+       
+       private final void updateInternalFrame(final 
Collection<ViewChangeRecord<CyNetwork>> records) {
+               for (final ViewChangeRecord<CyNetwork> record : records) {
                        CyNetworkView view = (CyNetworkView)(record.getView());
                        JInternalFrame iframe = 
presentationContainerMap.get(view);
                        if ( iframe == null )
@@ -532,21 +554,28 @@
        }
 
        @Override
-       public void handleEvent(RowsSetEvent e) {
-               
-               for ( RowSetRecord record :e.getPayloadCollection()) {
+       public void handleEvent(final RowsSetEvent e) {
+               final Collection<RowSetRecord> records = 
e.getPayloadCollection();
+               final CyTable source = e.getSource();
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               updateNetworkNameColumn(records, source);
+                       }
+               });
+       }
+       
+       private final void updateNetworkNameColumn(final 
Collection<RowSetRecord> records, final CyTable source) {
+               for (final RowSetRecord record : records) {
                        // assume payload collection is for same column
-                       if ( !record.getColumn().equals(CyNetwork.NAME))
+                       if (!record.getColumn().equals(CyNetwork.NAME))
                                break;
-                       for (JInternalFrame targetIF: iFrameMap.keySet()){
-                               
-                               if ( 
iFrameMap.get(targetIF).getModel().getDefaultNetworkTable().equals(e.getSource())){
+                       for (JInternalFrame targetIF : iFrameMap.keySet()) {
+                               if 
(iFrameMap.get(targetIF).getModel().getDefaultNetworkTable().equals(source)) {
                                        
targetIF.setTitle(record.getRow().get(CyNetwork.NAME, String.class));
-                                       return; //assuming just one row is set.
+                                       return; // assuming just one row is set.
                                }
-
                        }
-
                }
        }
 }

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolBarEnableUpdater.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolBarEnableUpdater.java
 2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolBarEnableUpdater.java
 2012-05-02 00:26:50 UTC (rev 29070)
@@ -109,7 +109,7 @@
        private void updateToolbar() {
                SwingUtilities.invokeLater( new Runnable() {
                        public void run() {
-                               for (CyAction action : 
toolbar.getAllToolBarActions())
+                               for (final CyAction action : 
toolbar.getAllToolBarActions())
                                        action.updateEnableState();
                        }
                });

Modified: 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolCytoPanelListener.java
===================================================================
--- 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolCytoPanelListener.java
        2012-05-01 23:20:48 UTC (rev 29069)
+++ 
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/view/ToolCytoPanelListener.java
        2012-05-02 00:26:50 UTC (rev 29070)
@@ -1,4 +1,3 @@
-
 /*
  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
 
@@ -32,49 +31,52 @@
  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.internal.view;
 
+import javax.swing.JLabel;
+import javax.swing.SwingUtilities;
+
 import org.cytoscape.application.swing.CytoPanel;
 import org.cytoscape.application.swing.CytoPanelState;
 import org.cytoscape.application.swing.events.CytoPanelStateChangedEvent;
 import org.cytoscape.application.swing.events.CytoPanelStateChangedListener;
 
-import javax.swing.JLabel;
-
-
 /**
  * This class handles the embedding of the Tools CytoPanel within the Control
- * CytoPanel. For all other cytopanels this is handled by CytoPanelAction,
- * but because tools panel is within another cytopanel, we have to handle 
things
+ * CytoPanel. For all other cytopanels this is handled by CytoPanelAction, but
+ * because tools panel is within another cytopanel, we have to handle things
  * separately.
  */
 public class ToolCytoPanelListener implements CytoPanelStateChangedListener {
 
-       BiModalJSplitPane split;
-       CytoPanel southWest;
-       CytoPanelImp west;
-       
+       private final BiModalJSplitPane split;
+       private final CytoPanel southWest;
+       private final CytoPanelImp west;
+
        public ToolCytoPanelListener(BiModalJSplitPane split, CytoPanelImp 
west, CytoPanel southWest) {
                this.split = split;
                this.west = west;
                this.southWest = southWest;
        }
 
-
-    public void handleEvent(CytoPanelStateChangedEvent e) {
-               if ( e.getCytoPanel() != southWest )
+       public void handleEvent(CytoPanelStateChangedEvent e) {
+               if (e.getCytoPanel() != southWest)
                        return;
 
-               CytoPanelState newState = e.getNewState();
+               final CytoPanelState newState = e.getNewState();
+               
+               SwingUtilities.invokeLater(new Runnable() {
+                       @Override
+                       public void run() {
+                               if (newState == CytoPanelState.DOCK)
+                                       west.addComponentToSouth(split);
+                               else
+                                       west.addComponentToSouth(new JLabel());
 
-               if (newState == CytoPanelState.DOCK) 
-                       west.addComponentToSouth(split);
-               else 
-                       // removeComponentAtSouth() doesn't work properly, so 
we do this...
-                       west.addComponentToSouth(new JLabel());
-
-               west.validate();
+                               west.validate();
+                       }
+               });
        }
 }

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