Author: clopes
Date: 2011-08-25 13:24:28 -0700 (Thu, 25 Aug 2011)
New Revision: 26636

Modified:
   csplugins/trunk/toronto/clopes/mcode/pom.xml
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/AbstractMCODEAction.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEAnalyzeAction.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODECurrentParameters.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEMainPanel.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
   
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
Log:
Closing the plugin now removes the related CytoPanels correctly.
Fixed most of the issues with node selection (had to remove workaround used for 
creating cluster images).

Modified: csplugins/trunk/toronto/clopes/mcode/pom.xml
===================================================================
--- csplugins/trunk/toronto/clopes/mcode/pom.xml        2011-08-24 23:35:48 UTC 
(rev 26635)
+++ csplugins/trunk/toronto/clopes/mcode/pom.xml        2011-08-25 20:24:28 UTC 
(rev 26636)
@@ -141,12 +141,6 @@
                        <version>4.8.2</version>
                        <scope>test</scope>
                </dependency>
-               <dependency>
-                       <groupId>org.cytoscape</groupId>
-                       <artifactId>test-support</artifactId>
-                       <version>3.0.0-alpha2</version>
-                       <scope>test</scope>
-               </dependency>
        </dependencies>
 
 </project>

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/AbstractMCODEAction.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/AbstractMCODEAction.java
    2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/AbstractMCODEAction.java
    2011-08-25 20:24:28 UTC (rev 26636)
@@ -1,5 +1,8 @@
 package org.cytoscape.mcode.internal;
 
+import java.util.ArrayList;
+import java.util.Collection;
+
 import org.cytoscape.application.CyApplicationManager;
 import org.cytoscape.application.swing.AbstractCyAction;
 import org.cytoscape.application.swing.CySwingApplication;
@@ -30,7 +33,7 @@
         * @return Cytoscape's results panel
         */
        protected CytoPanel getResultsCytoPanel() {
-               return swingApplication.getCytoPanel(CytoPanelName.WEST);
+               return swingApplication.getCytoPanel(CytoPanelName.EAST);
        }
 
        /**
@@ -49,18 +52,19 @@
        }
 
        /**
-        * @return The results panel of the plugin if it is opened, and null 
otherwise
+        * @return The result panels of the plugin if it is opened, or an empty 
collection otherwise
         */
-       protected MCODEResultsPanel getResultsPanel() {
+       protected Collection<MCODEResultsPanel> getResultPanels() {
+               Collection<MCODEResultsPanel> panels = new 
ArrayList<MCODEResultsPanel>();
                CytoPanel cytoPanel = getResultsCytoPanel();
                int count = cytoPanel.getCytoPanelComponentCount();
 
                for (int i = 0; i < count; i++) {
                        if (cytoPanel.getComponentAt(i) instanceof 
MCODEResultsPanel)
-                               return (MCODEResultsPanel) 
cytoPanel.getComponentAt(i);
+                               panels.add((MCODEResultsPanel) 
cytoPanel.getComponentAt(i));
                }
 
-               return null;
+               return panels;
        }
 
        /**

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEAnalyzeAction.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEAnalyzeAction.java
     2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEAnalyzeAction.java
     2011-08-25 20:24:28 UTC (rev 26636)
@@ -2,9 +2,7 @@
 
 import java.awt.event.ActionEvent;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Properties;
 
 import javax.swing.JOptionPane;
@@ -19,7 +17,6 @@
 import org.cytoscape.mcode.internal.event.AnalysisCompletedEvent;
 import org.cytoscape.mcode.internal.event.AnalysisCompletedListener;
 import org.cytoscape.mcode.internal.model.MCODEAlgorithm;
-import org.cytoscape.mcode.internal.model.MCODECurrentParameters;
 import org.cytoscape.mcode.internal.model.MCODEParameterSet;
 import org.cytoscape.mcode.internal.task.MCODEAnalyzeTaskFactory;
 import org.cytoscape.mcode.internal.util.MCODEUtil;
@@ -87,9 +84,6 @@
        private final TaskManager taskManager;
        private final MCODEUtil mcodeUtil;
 
-       //Keeps track of networks (id is key) and their respective algorithms
-       private Map<Long, MCODEAlgorithm> networkManager;
-
        private MCODEResultsPanel resultPanel;
 
        int analyze = FIRST_TIME;
@@ -107,7 +101,6 @@
                this.mcodeUtil = mcodeUtil;
 
                enableFor = "networkAndView";
-               networkManager = new HashMap<Long, MCODEAlgorithm>();
        }
 
        /**
@@ -160,14 +153,14 @@
                // of that network (so as to determine if rescoring/refinding 
is required for
                // this network without interference by parameters of other 
networks)
                // otherwise we construct a new alg class
-               if (networkManager.containsKey(network.getSUID())) {
-                       alg = networkManager.get(network.getSUID());
+               if (mcodeUtil.containsNetworkAlgorithm(network.getSUID())) {
+                       alg = mcodeUtil.getNetworkAlgorithm(network.getSUID());
                        // Get a copy of the last saved parameters for 
comparison with the current ones
-                       savedParamsCopy = 
MCODECurrentParameters.getInstance().getParamsCopy(network.getSUID());
+                       savedParamsCopy = 
mcodeUtil.getCurrentParameters().getParamsCopy(network.getSUID());
                } else {
                        alg = new MCODEAlgorithm(null, mcodeUtil);
-                       savedParamsCopy = 
MCODECurrentParameters.getInstance().getParamsCopy(null);
-                       networkManager.put(network.getSUID(), alg);
+                       savedParamsCopy = 
mcodeUtil.getCurrentParameters().getParamsCopy(null);
+                       mcodeUtil.addNetworkAlgorithm(network.getSUID(), alg);
                        analyze = FIRST_TIME;
                }
 
@@ -180,7 +173,7 @@
                        currentParamsCopy.getDegreeCutoff() != 
savedParamsCopy.getDegreeCutoff() || analyze == FIRST_TIME) {
                        analyze = RESCORE;
                        System.err.println("Analysis: score network, find 
clusters");
-                       
MCODECurrentParameters.getInstance().setParams(currentParamsCopy, resultId, 
network.getSUID());
+                       
mcodeUtil.getCurrentParameters().setParams(currentParamsCopy, resultId, 
network.getSUID());
                } else if 
(!currentParamsCopy.getScope().equals(savedParamsCopy.getScope()) ||
                                   
(!currentParamsCopy.getScope().equals(MCODEParameterSet.NETWORK) && 
currentParamsCopy
                                                   .getSelectedNodes() != 
savedParamsCopy.getSelectedNodes()) ||
@@ -196,11 +189,11 @@
                                                   
.getFluffNodeDensityCutoff())))) {
                        analyze = REFIND;
                        System.err.println("Analysis: find clusters");
-                       
MCODECurrentParameters.getInstance().setParams(currentParamsCopy, resultId, 
network.getSUID());
+                       
mcodeUtil.getCurrentParameters().setParams(currentParamsCopy, resultId, 
network.getSUID());
                } else {
                        analyze = INTERRUPTION;
                        interruptedMessage = "The parameters you 
specified\nhave not changed.";
-                       
MCODECurrentParameters.getInstance().setParams(currentParamsCopy, resultId, 
network.getSUID());
+                       
mcodeUtil.getCurrentParameters().setParams(currentParamsCopy, resultId, 
network.getSUID());
                }
 
                // Finally we save the current parameters

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
       2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
       2011-08-25 20:24:28 UTC (rev 26636)
@@ -1,6 +1,7 @@
 package org.cytoscape.mcode.internal;
 
 import java.awt.event.ActionEvent;
+import java.util.Collection;
 
 import javax.swing.JOptionPane;
 
@@ -10,7 +11,7 @@
 import org.cytoscape.application.swing.CytoPanelComponent;
 import org.cytoscape.application.swing.CytoPanelName;
 import org.cytoscape.application.swing.CytoPanelState;
-import org.cytoscape.mcode.internal.model.MCODECurrentParameters;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
 import org.cytoscape.mcode.internal.view.MCODEMainPanel;
 import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
 import org.cytoscape.service.util.CyServiceRegistrar;
@@ -23,13 +24,16 @@
        private static final long serialVersionUID = -8309835257402089360L;
 
        private final CyServiceRegistrar registrar;
+       private final MCODEUtil mcodeUtil;
 
        public MCODECloseAction(final String name,
                                                        final 
CyApplicationManager applicationManager,
                                                        final 
CySwingApplication swingApplication,
-                                                       final 
CyServiceRegistrar registrar) {
+                                                       final 
CyServiceRegistrar registrar,
+                                                       final MCODEUtil 
mcodeUtil) {
                super(name, applicationManager, swingApplication);
                this.registrar = registrar;
+               this.mcodeUtil = mcodeUtil;
                setPreferredMenu("Plugins.MCODE");
        }
 
@@ -43,9 +47,9 @@
 
                //First we must make sure that the plugin is opened
                if (isOpened()) {
-                       MCODEResultsPanel resultsPanel = getResultsPanel();
+                       Collection<MCODEResultsPanel> resultPanels = 
getResultPanels();
 
-                       if (resultsPanel != null) {
+                       if (resultPanels.size() > 0) {
                                String message = "You are about to close the 
MCODE plugin.\nDo you wish to continue?";
                                int result = 
JOptionPane.showOptionDialog(swingApplication.getJFrame(),
                                                                                
                                  new Object[] { message },
@@ -56,11 +60,12 @@
                                                                                
                                  null,
                                                                                
                                  null);
                                if (result == JOptionPane.YES_OPTION) {
-                                       int resultId = 
resultsPanel.getResultId();
-                                       
MCODECurrentParameters.removeResultParams(resultId);
+                                       for (MCODEResultsPanel p : 
resultPanels) {
+                                               int resultId = p.getResultId();
+                                               
mcodeUtil.getCurrentParameters().removeResultParams(resultId);
+                                               registrar.unregisterService(p, 
CytoPanelComponent.class);
+                                       }
 
-                                       
registrar.unregisterService(resultsPanel, CytoPanelComponent.class);
-
                                        if 
(cytoPanel.getCytoPanelComponentCount() == 0) {
                                                
cytoPanel.setState(CytoPanelState.HIDE);
                                        }
@@ -72,6 +77,8 @@
                        if (mainPanel != null) {
                                registrar.unregisterService(mainPanel, 
CytoPanelComponent.class);
                        }
+
+                       mcodeUtil.reset();
                }
        }
 

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
        2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEOpenAction.java
        2011-08-25 20:24:28 UTC (rev 26636)
@@ -7,6 +7,7 @@
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.application.swing.CytoPanel;
 import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
 import org.cytoscape.mcode.internal.view.MCODEMainPanel;
 import org.cytoscape.service.util.CyServiceRegistrar;
 
@@ -19,15 +20,18 @@
 
        private final CyServiceRegistrar registrar;
        private final MCODEAnalyzeAction analyzeAction;
+       private final MCODEUtil mcodeUtil;
 
        public MCODEOpenAction(final String name,
                                                   final CyApplicationManager 
applicationManager,
                                                   final CySwingApplication 
swingApplication,
                                                   final CyServiceRegistrar 
registrar,
-                                                  final MCODEAnalyzeAction 
analyzeAction) {
+                                                  final MCODEAnalyzeAction 
analyzeAction,
+                                                  final MCODEUtil mcodeUtil) {
                super(name, applicationManager, swingApplication);
                this.registrar = registrar;
                this.analyzeAction = analyzeAction;
+               this.mcodeUtil = mcodeUtil;
                setPreferredMenu("Plugins.MCODE");
        }
 
@@ -43,11 +47,10 @@
 
                        // First we must make sure that the plugin is not 
already open
                        if (!isOpened()) {
-                               mainPanel = new 
MCODEMainPanel(swingApplication);
+                               mainPanel = new 
MCODEMainPanel(swingApplication, mcodeUtil);
                                mainPanel.addAction(analyzeAction);
 
                                registrar.registerService(mainPanel, 
CytoPanelComponent.class, new Properties());
-                               
                                analyzeAction.updateEnableState();
                        } else {
                                mainPanel = getMainPanel();

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
   2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODEAlgorithm.java
   2011-08-25 20:24:28 UTC (rev 26636)
@@ -113,7 +113,7 @@
        public MCODEAlgorithm(final Long networkID, final MCODEUtil mcodeUtil) {
                this.mcodeUtil = mcodeUtil;
                //get current parameters
-               params = 
MCODECurrentParameters.getInstance().getParamsCopy(networkID);
+               params = 
mcodeUtil.getCurrentParameters().getParamsCopy(networkID);
        }
 
        public MCODEAlgorithm(final TaskMonitor taskMonitor, final Long 
networkID, final MCODEUtil mcodeUtil) {
@@ -122,7 +122,7 @@
        }
 
        public void setTaskMonitor(TaskMonitor taskMonitor, Long networkID) {
-               params = 
MCODECurrentParameters.getInstance().getParamsCopy(networkID);
+               params = 
mcodeUtil.getCurrentParameters().getParamsCopy(networkID);
                this.taskMonitor = taskMonitor;
        }
 
@@ -457,7 +457,7 @@
                // This method is similar to the finding method with the 
exception of the filtering so that the decrease of the cluster size
                // can produce a single node, also the use of the node seen 
hash map is differentially applied...
                Map<Integer, NodeInfo> nodeInfoHashMap = 
nodeInfoResultsMap.get(resultId);
-               MCODEParameterSet params = 
MCODECurrentParameters.getResultParams(cluster.getResultId());
+               MCODEParameterSet params = 
mcodeUtil.getCurrentParameters().getResultParams(cluster.getResultId());
                final Map<Integer, Boolean> nodeSeenHashMap;
 
                // If the size slider is below the set node score cutoff we use 
the node seen hash map so that clusters

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODECurrentParameters.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODECurrentParameters.java
   2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/model/MCODECurrentParameters.java
   2011-08-25 20:24:28 UTC (rev 26636)
@@ -46,20 +46,10 @@
  */
 public class MCODECurrentParameters {
 
-       private static MCODECurrentParameters ourInstance = new 
MCODECurrentParameters();
-       private static Map<Long, MCODEParameterSet> currentParams = new 
HashMap<Long, MCODEParameterSet>();
-       private static Map<Integer, MCODEParameterSet> resultParams = new 
HashMap<Integer, MCODEParameterSet>();
+       private Map<Long, MCODEParameterSet> currentParams = new HashMap<Long, 
MCODEParameterSet>();
+       private Map<Integer, MCODEParameterSet> resultParams = new 
HashMap<Integer, MCODEParameterSet>();
 
        /**
-        * Get the one instance of this singleton class that stores the current 
parameters internally.
-        * 
-        * @return ourInstance
-        */
-       public static MCODECurrentParameters getInstance() {
-               return ourInstance;
-       }
-
-       /**
         * Get a copy of the current parameters for a particular network. Only 
a copy of the current param object is
         * returned to avoid side effects.  The user should use the following 
code to get their
         * own copy of the current parameters:
@@ -116,11 +106,11 @@
                resultParams.put(resultId, resultParamSet);
        }
 
-       public static MCODEParameterSet getResultParams(int resultId) {
+       public MCODEParameterSet getResultParams(int resultId) {
                return resultParams.get(resultId).copy();
        }
 
-       public static void removeResultParams(int resultId) {
+       public void removeResultParams(int resultId) {
                resultParams.remove(resultId);
        }
 }

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
  2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
  2011-08-25 20:24:28 UTC (rev 26636)
@@ -130,20 +130,14 @@
                        // Also create all the images here for the clusters, 
since it can be a time consuming operation
                        clusters = mcodeUtil.sortClusters(clusters);
                        imageList = new Image[clusters.length];
-                       int imageSize = 
MCODECurrentParameters.getResultParams(resultId).getDefaultRowHeight();
+                       int imageSize = 
mcodeUtil.getCurrentParameters().getResultParams(resultId).getDefaultRowHeight();
 
                        for (int i = 0; i < clusters.length; i++) {
                                if (interrupted) {
                                        return;
                                }
 
-                               imageList[i] = 
mcodeUtil.convertNetworkToImage(network,
-                                                                               
                                           null,
-                                                                               
                                           clusters[i],
-                                                                               
                                           imageSize,
-                                                                               
                                           imageSize,
-                                                                               
                                           null,
-                                                                               
                                           true);
+                               imageList[i] = 
mcodeUtil.createClusterImage(clusters[i], imageSize, imageSize, null, true, 
null);
                                taskMonitor.setProgress((i * 100) / 
clusters.length);
                        }
 

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
 2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
 2011-08-25 20:24:28 UTC (rev 26636)
@@ -1,7 +1,6 @@
 package org.cytoscape.mcode.internal.util;
 
 import java.awt.Color;
-import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics2D;
@@ -13,14 +12,16 @@
 import java.io.IOException;
 import java.text.DateFormat;
 import java.text.NumberFormat;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Comparator;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Map;
 import java.util.Set;
 
-import javax.swing.JInternalFrame;
 import javax.swing.JOptionPane;
 import javax.swing.SwingUtilities;
 
@@ -29,6 +30,7 @@
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.mcode.internal.model.MCODEAlgorithm;
 import org.cytoscape.mcode.internal.model.MCODECluster;
+import org.cytoscape.mcode.internal.model.MCODECurrentParameters;
 import org.cytoscape.mcode.internal.view.MCODELoader;
 import org.cytoscape.mcode.internal.view.SpringEmbeddedLayouter;
 import org.cytoscape.model.CyEdge;
@@ -106,6 +108,9 @@
        private boolean interrupted;
        private Image placeHolderImage;
        private VisualStyle style; // visual style used by the MCODE plugin
+       private MCODECurrentParameters currentParameters;
+       //Keeps track of networks (id is key) and their respective algorithms
+       private Map<Long, MCODEAlgorithm> networkAlgorithms;
 
        public MCODEUtil(final RenderingEngineFactory<CyNetwork> 
renderingEngineFactory,
                                         final CyNetworkViewFactory 
networkViewFactory,
@@ -127,26 +132,48 @@
                this.visualMappingMgr = visualMappingMgr;
                this.swingApplication = swingApplication;
                this.eventHelper = eventHelper;
+
+               this.reset();
        }
 
+       public void reset() {
+               currentParameters = new MCODECurrentParameters();
+               networkAlgorithms = new HashMap<Long, MCODEAlgorithm>();
+       }
+
+       public MCODECurrentParameters getCurrentParameters() {
+               return currentParameters;
+       }
+
+       public boolean containsNetworkAlgorithm(long suid) {
+               return networkAlgorithms.containsKey(suid);
+       }
+       
+       public MCODEAlgorithm getNetworkAlgorithm(long suid) {
+               return networkAlgorithms.get(suid);
+       }
+       
+       public void addNetworkAlgorithm(long suid, MCODEAlgorithm alg) {
+               networkAlgorithms.put(suid, alg);
+       }
+
        /**
         * Convert a network to an image.  This is used by the 
MCODEResultsPanel.
-        *
-        * @param loader Graphic loader displaying progress and process
+        * 
         * @param cluster Input network to convert to an image
         * @param height  Height that the resulting image should be
         * @param width   Width that the resulting image should be
         * @param layouter Reference to the layout algorithm
         * @param layoutNecessary Determinant of cluster size growth or 
shrinkage, the former requires layout
+        * @param loader Graphic loader displaying progress and process
         * @return The resulting image
         */
-       public Image convertNetworkToImage(final CyNetwork network,
-                                                                          
final MCODELoader loader,
-                                                                          
final MCODECluster cluster,
-                                                                          
final int height,
-                                                                          
final int width,
-                                                                          
SpringEmbeddedLayouter layouter,
-                                                                          
boolean layoutNecessary) {
+       public Image createClusterImage(final MCODECluster cluster,
+                                                                       final 
int height,
+                                                                       final 
int width,
+                                                                       
SpringEmbeddedLayouter layouter,
+                                                                       boolean 
layoutNecessary,
+                                                                       final 
MCODELoader loader) {
                // Progress reporters.
                // There are three basic tasks, the progress of each is 
calculated and then combined
                // using the respective weighting to get an overall progress 
global progress
@@ -164,7 +191,7 @@
 
                final VisualStyle vs = getPluginStyle();
                final CyNetworkView clusterView = 
createNetworkView(cluster.getNetwork(), vs);
-               
+
                
clusterView.setVisualProperty(MinimalVisualLexicon.NETWORK_WIDTH, new 
Double(width));
                
clusterView.setVisualProperty(MinimalVisualLexicon.NETWORK_HEIGHT, new 
Double(height));
 
@@ -255,7 +282,8 @@
                        @Override
                        public void run() {
                                try {
-                                       displayNetworkView(clusterView);
+                                       // TODO: remove this workaround when 
possible to get image off-screen
+                                       //                                      
displayNetworkView(clusterView);
 
                                        // Apply style again:
                                        vs.apply(clusterView);
@@ -275,7 +303,8 @@
                                } catch (Exception ex) {
                                        throw new RuntimeException(ex);
                                } finally {
-                                       destroyNetworkViewAndModel(clusterView);
+                                       // TODO: remove this workaround when 
possible to get image off-screen
+                                       //                                      
destroyNetworkViewAndModel(clusterView);
                                }
                        }
                });
@@ -330,7 +359,7 @@
                        networkMgr.destroyNetwork(view.getModel());
                }
        }
-       
+
        public VisualStyle getPluginStyle() {
                if (style == null) {
                        style = visualStyleFactory.getInstance("MCODE");
@@ -413,15 +442,21 @@
                return view != null ? visualMappingMgr.getVisualStyle(view) : 
null;
        }
 
-       public void setSelected(final Collection<? extends CyTableEntry> 
objects, final boolean select, CyNetworkView view) {
-               for (final CyTableEntry nodeOrEdge : objects)
+       @SuppressWarnings("unchecked")
+       public void setSelected(final Collection<? extends CyTableEntry> 
elements, CyNetwork network, CyNetworkView view) {
+               Collection<? extends CyTableEntry> allElements = new 
ArrayList<CyTableEntry>(network.getNodeList());
+               allElements.addAll((Collection) network.getEdgeList());
+
+               for (final CyTableEntry nodeOrEdge : allElements) {
+                       boolean select = elements.contains(nodeOrEdge);
                        nodeOrEdge.getCyRow().set(CyNetwork.SELECTED, select);
+               }
 
                eventHelper.flushPayloadEvents();
-               
+
                if (view != null) {
                        view.updateView();
-                       eventHelper.flushPayloadEvents();
+//                     eventHelper.flushPayloadEvents();
                        swingApplication.getJFrame().repaint(); // TODO: remove 
this ugly hack!!!
                }
        }

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEMainPanel.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEMainPanel.java
    2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEMainPanel.java
    2011-08-25 20:24:28 UTC (rev 26636)
@@ -2,7 +2,6 @@
 
 import java.awt.BorderLayout;
 import java.awt.Component;
-import java.awt.Container;
 import java.awt.FlowLayout;
 import java.awt.GridLayout;
 import java.awt.event.ActionEvent;
@@ -34,9 +33,9 @@
 import org.cytoscape.application.swing.CySwingApplication;
 import org.cytoscape.application.swing.CytoPanelComponent;
 import org.cytoscape.application.swing.CytoPanelName;
-import org.cytoscape.mcode.internal.model.MCODECurrentParameters;
 import org.cytoscape.mcode.internal.model.MCODEParameterSet;
 import org.cytoscape.mcode.internal.util.MCODEResources;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
 import org.cytoscape.mcode.internal.util.MCODEResources.ImageName;
 
 /**
@@ -81,6 +80,7 @@
        private static final long serialVersionUID = 2655227790686546553L;
 
        private final CySwingApplication swingApplication;
+       private final MCODEUtil mcodeUtil;
        private final List<CyAction> actions;
 
        // Panels
@@ -126,22 +126,16 @@
 
        /**
         * The actual parameter change panel that builds the UI
-        *
-        * @param trigger A reference to the action that triggered the 
initiation of this class
-        * @param MCODEVS Reference to MCODE's visual style
         */
-       public MCODEMainPanel(final CySwingApplication swingApplication
-       /*MCODEMainPanelAction trigger, final MCODEVisualStyle MCODEVS*/) {
+       public MCODEMainPanel(final CySwingApplication swingApplication, final 
MCODEUtil mcodeUtil) {
                this.swingApplication = swingApplication;
-               
+               this.mcodeUtil = mcodeUtil;
                actions = new ArrayList<CyAction>();
-
-               //        this.trigger = trigger;
-               //        this.MCODEVS = MCODEVS;
+               
                setLayout(new BorderLayout());
 
                //get the current parameters
-               currentParamsCopy = 
MCODECurrentParameters.getInstance().getParamsCopy(null);
+               currentParamsCopy = 
mcodeUtil.getCurrentParameters().getParamsCopy(null);
                currentParamsCopy.setDefaultParams();
 
                decFormat = new DecimalFormat();
@@ -168,7 +162,7 @@
        public void addAction(CyAction action) {
                JButton bt = new JButton(action);
                getBottomPanel().add(bt);
-               
+
                this.actions.add(action);
        }
 
@@ -196,7 +190,7 @@
        public MCODEParameterSet getCurrentParamsCopy() {
                return currentParamsCopy;
        }
-       
+
        /**
         * Creates a JPanel containing scope radio buttons
         *

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
 2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
 2011-08-25 20:24:28 UTC (rev 26636)
@@ -168,7 +168,7 @@
                this.swingApplication = swingApplication;
                this.registrar = registrar;
 
-               currentParamsCopy = 
MCODECurrentParameters.getResultParams(resultId);
+               currentParamsCopy = 
mcodeutil.getCurrentParameters().getResultParams(resultId);
 
                JPanel clusterBrowserPanel = 
createClusterBrowserPanel(imageList);
                JPanel bottomPanel = createBottomPanel();
@@ -465,13 +465,13 @@
                                protected Object doInBackground() throws 
Exception {
                                        CyNetwork newNetwork = 
mcodeutil.createSubNetwork(clusterNetwork, clusterNetwork.getNodeList());
                                        
newNetwork.getCyRow().set(CyNetwork.NAME, title);
-                                       
+
                                        VisualStyle vs = 
mcodeutil.getNetworkViewStyle(networkView);
                                        CyNetworkView newNetworkView = 
mcodeutil.createNetworkView(newNetwork, vs);
-                                       
+
                                        
newNetworkView.setVisualProperty(MinimalVisualLexicon.NETWORK_CENTER_X_LOCATION,
 0.0);
                                        
newNetworkView.setVisualProperty(MinimalVisualLexicon.NETWORK_CENTER_Y_LOCATION,
 0.0);
-                                       
+
                                        
mcodeutil.displayNetworkView(newNetworkView);
 
                                        // Layout new cluster and fit it to 
window.
@@ -825,7 +825,7 @@
                                                                                
                          null);
                        if (result == JOptionPane.YES_OPTION) {
                                registrar.unregisterService(trigger, 
CytoPanelComponent.class);
-                               
MCODECurrentParameters.removeResultParams(getResultId());
+                               
mcodeutil.getCurrentParameters().removeResultParams(getResultId());
                        }
 
                        // If there are no more tabs in the cytopanel then we 
hide it
@@ -931,15 +931,15 @@
        /**
         * Selects a cluster in the view that is selected by the user in the 
browser table
         * 
-        * @param gpCluster Cluster to be selected
+        * @param custerNetwork Cluster to be selected
         */
-       public void selectCluster(final CyNetwork gpCluster) {
-               if (gpCluster != null) {
+       public void selectCluster(final CyNetwork custerNetwork) {
+               if (custerNetwork != null) {
                        // Only do this if a view has been created on this 
network
                        if (networkView != null) {
                                // start with no selected nodes
-                               
mcodeutil.setSelected(networkView.getModel().getNodeList(), false, networkView);
-                               mcodeutil.setSelected(gpCluster.getNodeList(), 
true, networkView);
+                               //                              
mcodeutil.setSelected(network.getNodeList(), false, networkView);
+                               
mcodeutil.setSelected(custerNetwork.getNodeList(), network, networkView);
 
                                // TODO: is it still necessary?
                                // We want the focus to switch to the 
appropriate network view but only if the cytopanel is docked
@@ -948,7 +948,6 @@
                                //                                      
                                //                                       
Cytoscape.getDesktop().setFocus(networkView.getSUID());
                                //                              }
-                               networkView.fitSelected();
                        } else {
                                // Warn user that nothing will happen in this 
case because there
                                // is no view to select nodes with
@@ -957,8 +956,8 @@
                                                                                
          "No Network View",
                                                                                
          JOptionPane.INFORMATION_MESSAGE);
                        }
-               } else if (networkView != null) {
-                       
mcodeutil.setSelected(networkView.getModel().getNodeList(), false, networkView);
+               } else {
+                       mcodeutil.setSelected(new ArrayList<CyNode>(), network, 
networkView); // deselect all
                }
        }
 
@@ -1181,13 +1180,12 @@
                                        // process was interrupted by the 
slider movement
                                        // In that case the drawing must occur 
for a new cluster using the drawGraph method
                                        if (drawGraph && !drawPlaceHolder) {
-                                               Image image = 
mcodeutil.convertNetworkToImage(network,
-                                                                               
                                                          loader,
-                                                                               
                                                          cluster,
-                                                                               
                                                          graphPicSize,
-                                                                               
                                                          graphPicSize,
-                                                                               
                                                          layouter,
-                                                                               
                                                          layoutNecessary);
+                                               Image image = 
mcodeutil.createClusterImage(cluster,
+                                                                               
                                                   graphPicSize,
+                                                                               
                                                   graphPicSize,
+                                                                               
                                                   layouter,
+                                                                               
                                                   layoutNecessary,
+                                                                               
                                                   loader);
                                                // If the drawing process was 
interrupted, a new cluster must have been found and
                                                // this will have returned 
null, the drawing will be recalled (with the new cluster)
                                                // However, if the graphing was 
successful, we update

Modified: 
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
--- 
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
  2011-08-24 23:35:48 UTC (rev 26635)
+++ 
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
  2011-08-25 20:24:28 UTC (rev 26636)
@@ -15,6 +15,7 @@
                <constructor-arg ref="cySwingApplicationServiceRef" />
                <constructor-arg ref="cyServiceRegistrarServiceRef" />
                <constructor-arg ref="analyzeAction" />
+               <constructor-arg ref="mcodeUtil" />
        </bean>
        
        <bean id="closeAction" 
class="org.cytoscape.mcode.internal.MCODECloseAction">
@@ -22,6 +23,7 @@
                <constructor-arg ref="cyApplicationManagerServiceRef" />
                <constructor-arg ref="cySwingApplicationServiceRef" />
                <constructor-arg ref="cyServiceRegistrarServiceRef" />
+               <constructor-arg ref="mcodeUtil" />
        </bean>
 
        <bean id="helpAction" 
class="org.cytoscape.mcode.internal.MCODEHelpAction">

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