Author: clopes
Date: 2011-08-26 15:16:57 -0700 (Fri, 26 Aug 2011)
New Revision: 26640
Added:
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEDiscardResultAction.java
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/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/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/MCODEResultsPanel.java
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
Log:
Implemented closing all related result panels when networks are destroyed, and
reset some cached parameters when that happens.
Other fixes and improvements.
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-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/AbstractMCODEAction.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -17,7 +17,9 @@
protected final CySwingApplication swingApplication;
- public AbstractMCODEAction(String name, CyApplicationManager
applicationManager, CySwingApplication swingApplication) {
+ public AbstractMCODEAction(final String name,
+ final
CyApplicationManager applicationManager,
+ final
CySwingApplication swingApplication) {
super(name, applicationManager);
this.swingApplication = swingApplication;
}
@@ -67,6 +69,14 @@
return panels;
}
+ protected MCODEResultsPanel getResultPanel(final int resultId) {
+ for (MCODEResultsPanel panel : getResultPanels()) {
+ if (panel.getResultId() == resultId) return panel;
+ }
+
+ return null;
+ }
+
/**
* @return true if the plugin is opened and false otherwise
*/
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-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEAnalyzeAction.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -84,10 +84,7 @@
private final TaskManager taskManager;
private final MCODEUtil mcodeUtil;
- private MCODEResultsPanel resultPanel;
-
int analyze = FIRST_TIME;
- int resultId = 1;
public MCODEAnalyzeAction(final String title,
final
CyApplicationManager applicationManager,
@@ -164,6 +161,8 @@
analyze = FIRST_TIME;
}
+ final int resultId = mcodeUtil.getCurrentResultId();
+
// These statements determine which portion of the algorithm
needs to be conducted by
// testing which parameters have been modified compared to the
last saved parameters.
// Here we ensure that only relavant parameters are looked at.
For example, fluff density
@@ -172,7 +171,7 @@
if (currentParamsCopy.isIncludeLoops() !=
savedParamsCopy.isIncludeLoops() ||
currentParamsCopy.getDegreeCutoff() !=
savedParamsCopy.getDegreeCutoff() || analyze == FIRST_TIME) {
analyze = RESCORE;
- System.err.println("Analysis: score network, find
clusters");
+ System.out.println("Analysis: score network, find
clusters");
mcodeUtil.getCurrentParameters().setParams(currentParamsCopy, resultId,
network.getSUID());
} else if
(!currentParamsCopy.getScope().equals(savedParamsCopy.getScope()) ||
(!currentParamsCopy.getScope().equals(MCODEParameterSet.NETWORK) &&
currentParamsCopy
@@ -188,11 +187,11 @@
.isFluff() &&
currentParamsCopy.getFluffNodeDensityCutoff() != savedParamsCopy
.getFluffNodeDensityCutoff())))) {
analyze = REFIND;
- System.err.println("Analysis: find clusters");
+ System.out.println("Analysis: find clusters");
mcodeUtil.getCurrentParameters().setParams(currentParamsCopy, resultId,
network.getSUID());
} else {
analyze = INTERRUPTION;
- interruptedMessage = "The parameters you
specified\nhave not changed.";
+ interruptedMessage = "The parameters you specified have
not changed.";
mcodeUtil.getCurrentParameters().setParams(currentParamsCopy, resultId,
network.getSUID());
}
@@ -221,16 +220,26 @@
@Override
public void run() {
+ MCODEResultsPanel
resultPanel = null;
boolean resultFound =
false;
// Display clusters in
a new modal dialog box
if (e.isSuccessful()) {
- if
(e.getClusters().length > 0) {
+ if
(e.getClusters() != null && e.getClusters().length > 0) {
resultFound = true;
+
mcodeUtil.addNetworkResult(network.getSUID());
+
+
MCODEDiscardResultAction discardResultAction = new MCODEDiscardResultAction(
+
"Discard
Result",
+
resultId,
+
applicationManager,
+
swingApplication,
+
registrar,
+
mcodeUtil);
+
resultPanel = new MCODEResultsPanel(e.getClusters(), alg, mcodeUtil, network,
networkView,
e.getImageList(), resultId,
-
swingApplication, registrar);
-
resultId++;
+
swingApplication, discardResultAction);
registrar.registerService(resultPanel, CytoPanelComponent.class, new
Properties());
} else {
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-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODECloseAction.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -2,6 +2,7 @@
import java.awt.event.ActionEvent;
import java.util.Collection;
+import java.util.Set;
import javax.swing.JOptionPane;
@@ -14,12 +15,15 @@
import org.cytoscape.mcode.internal.util.MCODEUtil;
import org.cytoscape.mcode.internal.view.MCODEMainPanel;
import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
import org.cytoscape.service.util.CyServiceRegistrar;
/**
* Closes the plugin panels.
*/
-public class MCODECloseAction extends AbstractMCODEAction {
+public class MCODECloseAction extends AbstractMCODEAction implements
NetworkAboutToBeDestroyedListener {
private static final long serialVersionUID = -8309835257402089360L;
@@ -42,9 +46,7 @@
* @param event Menu Item Selected.
*/
@Override
- public void actionPerformed(ActionEvent event) {
- CytoPanel cytoPanel =
swingApplication.getCytoPanel(CytoPanelName.WEST);
-
+ public void actionPerformed(final ActionEvent event) {
//First we must make sure that the plugin is opened
if (isOpened()) {
Collection<MCODEResultsPanel> resultPanels =
getResultPanels();
@@ -60,12 +62,12 @@
null,
null);
if (result == JOptionPane.YES_OPTION) {
- for (MCODEResultsPanel p :
resultPanels) {
- int resultId = p.getResultId();
-
mcodeUtil.getCurrentParameters().removeResultParams(resultId);
- registrar.unregisterService(p,
CytoPanelComponent.class);
+ for (MCODEResultsPanel panel :
resultPanels) {
+ panel.discard(false);
}
+ CytoPanel cytoPanel =
swingApplication.getCytoPanel(CytoPanelName.WEST);
+
if
(cytoPanel.getCytoPanelComponentCount() == 0) {
cytoPanel.setState(CytoPanelState.HIDE);
}
@@ -86,4 +88,17 @@
public void updateEnableState() {
setEnabled(isOpened());
}
+
+ @Override
+ public void handleEvent(final NetworkAboutToBeDestroyedEvent e) {
+ if (isOpened()) {
+ CyNetwork network = e.getNetwork();
+ Set<Integer> resultIds =
mcodeUtil.getNetworkResults(network.getSUID());
+
+ for (int id : resultIds) {
+ MCODEResultsPanel panel = getResultPanel(id);
+ if (panel != null) panel.discard(false);
+ }
+ }
+ }
}
Added:
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEDiscardResultAction.java
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEDiscardResultAction.java
(rev 0)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/MCODEDiscardResultAction.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -0,0 +1,79 @@
+package org.cytoscape.mcode.internal;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.JOptionPane;
+
+import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.application.swing.CytoPanel;
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.application.swing.CytoPanelName;
+import org.cytoscape.application.swing.CytoPanelState;
+import org.cytoscape.mcode.internal.util.MCODEUtil;
+import org.cytoscape.mcode.internal.view.MCODEResultsPanel;
+import org.cytoscape.service.util.CyServiceRegistrar;
+
+public class MCODEDiscardResultAction extends AbstractMCODEAction {
+
+ private static final long serialVersionUID = 304724069977183435L;
+
+ public static final String REQUEST_USER_CONFIRMATION_COMMAND =
"requestUserConfirmation";
+
+ private final int resultId;
+ private final CyServiceRegistrar registrar;
+ private final MCODEUtil mcodeUtil;
+
+ public MCODEDiscardResultAction(final String name,
+ final
int resultId,
+ final
CyApplicationManager applicationManager,
+ final
CySwingApplication swingApplication,
+ final
CyServiceRegistrar registrar,
+ final
MCODEUtil mcodeUtil) {
+ super(name, applicationManager, swingApplication);
+ this.resultId = resultId;
+ this.registrar = registrar;
+ this.mcodeUtil = mcodeUtil;
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent event) {
+ MCODEResultsPanel panel = getResultPanel(resultId);
+
+ if (panel != null) {
+ int resultId = panel.getResultId();
+ Integer confirmed = JOptionPane.YES_OPTION;
+ boolean requestUserConfirmation = new
Boolean(getValue(REQUEST_USER_CONFIRMATION_COMMAND).toString());
+
+ if (requestUserConfirmation) {
+ // Must make sure the user wants to close this
results panel
+ String message = "You are about to dispose of
Result " + resultId + ".\nDo you wish to continue?";
+ confirmed =
JOptionPane.showOptionDialog(swingApplication.getJFrame(),
+
new Object[] { message },
+
"Confirm",
+
JOptionPane.YES_NO_OPTION,
+
JOptionPane.QUESTION_MESSAGE,
+
null,
+
null,
+
null);
+ }
+
+ if (confirmed == JOptionPane.YES_OPTION) {
+ registrar.unregisterService(panel,
CytoPanelComponent.class);
+ mcodeUtil.removeNetworkResult(resultId);
+ }
+ }
+
+ final CytoPanel cytoPanel =
swingApplication.getCytoPanel(CytoPanelName.EAST);
+
+ // If there are no more tabs in the cytopanel then we hide it
+ if (cytoPanel.getCytoPanelComponentCount() == 0) {
+ cytoPanel.setState(CytoPanelState.HIDE);
+ }
+
+ if (getResultPanels().size() == 0) {
+ // Reset the results cache
+ mcodeUtil.reset();
+ }
+ }
+}
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-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/task/MCODEAnalyzeTask.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -7,7 +7,6 @@
import org.cytoscape.mcode.internal.event.AnalysisCompletedListener;
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.util.MCODEUtil;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.work.Task;
@@ -62,7 +61,6 @@
private boolean interrupted;
private CyNetwork network;
- private MCODECluster[] clusters;
private Image imageList[];
/**
@@ -97,6 +95,7 @@
}
boolean success = false;
+ MCODECluster[] clusters = null;
try {
// Run MCODE scoring algorithm - node scores are saved
in the alg object
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-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/util/MCODEUtil.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -5,6 +5,7 @@
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
+import java.awt.Paint;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
@@ -21,6 +22,7 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
@@ -48,10 +50,16 @@
import org.cytoscape.view.presentation.RenderingEngine;
import org.cytoscape.view.presentation.RenderingEngineFactory;
import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
+import org.cytoscape.view.presentation.property.NodeShapeVisualProperty;
import org.cytoscape.view.presentation.property.RichVisualLexicon;
+import org.cytoscape.view.presentation.property.values.NodeShape;
+import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
import org.cytoscape.view.vizmap.VisualMappingManager;
import org.cytoscape.view.vizmap.VisualStyle;
import org.cytoscape.view.vizmap.VisualStyleFactory;
+import org.cytoscape.view.vizmap.mappings.BoundaryRangeValues;
+import org.cytoscape.view.vizmap.mappings.ContinuousMapping;
+import org.cytoscape.view.vizmap.mappings.DiscreteMapping;
/**
* * Copyright (c) 2004 Memorial Sloan-Kettering Cancer Center
@@ -104,14 +112,22 @@
private final VisualMappingManager visualMappingMgr;
private final CySwingApplication swingApplication;
private final CyEventHelper eventHelper;
+ private final VisualMappingFunctionFactory discreteMappingFactory;
+ private final VisualMappingFunctionFactory continuousMappingFactory;
+ private final VisualMappingFunctionFactory passthroughMappingFactory;
private boolean interrupted;
private Image placeHolderImage;
- private VisualStyle style; // visual style used by the MCODE plugin
+ private VisualStyle clusterStyle;
+ private VisualStyle pluginStyle;
private MCODECurrentParameters currentParameters;
- //Keeps track of networks (id is key) and their respective algorithms
+ // Keeps track of networks (id is key) and their respective algorithms
private Map<Long, MCODEAlgorithm> networkAlgorithms;
+ // Keeps track of networks (id is key) and their respective results
(list of result ids)
+ private Map<Long, Set<Integer>> networkResults;
+ private int currentResultId;
+
public MCODEUtil(final RenderingEngineFactory<CyNetwork>
renderingEngineFactory,
final CyNetworkViewFactory
networkViewFactory,
final CyRootNetworkFactory
rootNetworkFactory,
@@ -121,7 +137,10 @@
final VisualStyleFactory
visualStyleFactory,
final VisualMappingManager
visualMappingMgr,
final CySwingApplication
swingApplication,
- final CyEventHelper eventHelper) {
+ final CyEventHelper eventHelper,
+ final VisualMappingFunctionFactory
discreteMappingFactory,
+ final VisualMappingFunctionFactory
continuousMappingFactory,
+ final VisualMappingFunctionFactory
passthroughMappingFactory) {
this.renderingEngineFactory = renderingEngineFactory;
this.networkViewFactory = networkViewFactory;
this.rootNetworkFactory = rootNetworkFactory;
@@ -132,31 +151,91 @@
this.visualMappingMgr = visualMappingMgr;
this.swingApplication = swingApplication;
this.eventHelper = eventHelper;
+ this.discreteMappingFactory = discreteMappingFactory;
+ this.continuousMappingFactory = continuousMappingFactory;
+ this.passthroughMappingFactory = passthroughMappingFactory;
this.reset();
}
+ public int getCurrentResultId() {
+ return currentResultId;
+ }
+
public void reset() {
+ currentResultId = 1;
currentParameters = new MCODECurrentParameters();
networkAlgorithms = new HashMap<Long, MCODEAlgorithm>();
+ networkResults = new HashMap<Long, Set<Integer>>();
}
public MCODECurrentParameters getCurrentParameters() {
return currentParameters;
}
- public boolean containsNetworkAlgorithm(long suid) {
+ public boolean containsNetworkAlgorithm(final long suid) {
return networkAlgorithms.containsKey(suid);
}
-
- public MCODEAlgorithm getNetworkAlgorithm(long suid) {
+
+ public MCODEAlgorithm getNetworkAlgorithm(final long suid) {
return networkAlgorithms.get(suid);
}
-
- public void addNetworkAlgorithm(long suid, MCODEAlgorithm alg) {
+
+ public void addNetworkAlgorithm(final long suid, final MCODEAlgorithm
alg) {
networkAlgorithms.put(suid, alg);
}
+ public boolean containsNetworkResult(final long suid) {
+ return networkResults.containsKey(suid);
+ }
+
+ public Set<Integer> getNetworkResults(final long suid) {
+ Set<Integer> ids = networkResults.get(suid);
+
+ return ids != null ? ids : new HashSet<Integer>();
+ }
+
+ public synchronized void addNetworkResult(final long suid) {
+ Set<Integer> ids = networkResults.get(suid);
+
+ if (ids == null) {
+ ids = new HashSet<Integer>();
+ networkResults.put(suid, ids);
+ }
+
+ ids.add(currentResultId++);
+ }
+
+ public boolean removeNetworkResult(final int resultId) {
+ boolean removed = false;
+ Long networkToRemove = null;
+
+ for (Entry<Long, Set<Integer>> entries :
networkResults.entrySet()) {
+ Set<Integer> ids = entries.getValue();
+
+ if (ids.remove(resultId)) {
+ if (ids.isEmpty()) {
+ networkToRemove = entries.getKey();
+ }
+
+ removed = true;
+ break;
+ }
+ }
+
+ if (networkToRemove != null) {
+ removeNetworkResults(networkToRemove);
+ }
+
+ this.getCurrentParameters().removeResultParams(resultId);
+
+ return removed;
+ }
+
+ public Set<Integer> removeNetworkResults(final long suid) {
+ return networkResults.remove(suid);
+ }
+
/**
* Convert a network to an image. This is used by the
MCODEResultsPanel.
*
@@ -189,7 +268,7 @@
// keeps track of progress as a percent of the totalGoal
double progress = 0;
- final VisualStyle vs = getPluginStyle();
+ final VisualStyle vs = getClusterStyle();
final CyNetworkView clusterView =
createNetworkView(cluster.getNetwork(), vs);
clusterView.setVisualProperty(MinimalVisualLexicon.NETWORK_WIDTH, new
Double(width));
@@ -360,23 +439,23 @@
}
}
- public VisualStyle getPluginStyle() {
- if (style == null) {
- style = visualStyleFactory.getInstance("MCODE");
+ public VisualStyle getClusterStyle() {
+ if (clusterStyle == null) {
+ clusterStyle = visualStyleFactory.getInstance("MCODE
Cluster");
- style.setDefaultValue(MinimalVisualLexicon.NODE_SIZE,
40.0);
- style.setDefaultValue(MinimalVisualLexicon.NODE_WIDTH,
40.0);
- style.setDefaultValue(MinimalVisualLexicon.NODE_HEIGHT,
40.0);
- style.setDefaultValue(MinimalVisualLexicon.NODE_PAINT,
Color.RED);
-
style.setDefaultValue(MinimalVisualLexicon.NODE_FILL_COLOR, Color.RED);
-
style.setDefaultValue(RichVisualLexicon.NODE_BORDER_PAINT, Color.BLACK);
-
style.setDefaultValue(RichVisualLexicon.NODE_BORDER_WIDTH, 5.0);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_SIZE, 40.0);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_WIDTH, 40.0);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_HEIGHT, 40.0);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_PAINT, Color.RED);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.NODE_FILL_COLOR, Color.RED);
+
clusterStyle.setDefaultValue(RichVisualLexicon.NODE_BORDER_PAINT, Color.BLACK);
+
clusterStyle.setDefaultValue(RichVisualLexicon.NODE_BORDER_WIDTH, 5.0);
- style.setDefaultValue(MinimalVisualLexicon.EDGE_PAINT,
Color.BLUE);
-
style.setDefaultValue(RichVisualLexicon.EDGE_UNSELECTED_PAINT, Color.BLUE);
-
style.setDefaultValue(RichVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT,
Color.BLUE);
-
style.setDefaultValue(RichVisualLexicon.EDGE_SELECTED_PAINT, Color.BLUE);
-
style.setDefaultValue(RichVisualLexicon.EDGE_STROKE_SELECTED_PAINT, Color.BLUE);
+
clusterStyle.setDefaultValue(MinimalVisualLexicon.EDGE_PAINT, Color.BLUE);
+
clusterStyle.setDefaultValue(RichVisualLexicon.EDGE_UNSELECTED_PAINT,
Color.BLUE);
+
clusterStyle.setDefaultValue(RichVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT,
Color.BLUE);
+
clusterStyle.setDefaultValue(RichVisualLexicon.EDGE_SELECTED_PAINT, Color.BLUE);
+
clusterStyle.setDefaultValue(RichVisualLexicon.EDGE_STROKE_SELECTED_PAINT,
Color.BLUE);
// TODO
// if (cluster.getSeedNode().intValue() ==
nv.getRootGraphIndex()) {
@@ -388,54 +467,49 @@
// ev.setTargetEdgeEnd(EdgeView.BLACK_ARROW);
// ev.setTargetEdgeEndPaint(Color.CYAN);
// ev.setSourceEdgeEndPaint(Color.CYAN);
+ }
- // TODO: change original network style?
- // // Node Shape:
- // private void
createNodeShape(NodeAppearanceCalculator nac) {
- // DiscreteMapping discreteMapping = new
DiscreteMapping(RECT, "MCODE_Node_Status", ObjectMapping.NODE_MAPPING);
- // //Node shapes are determined by three
discrete classifications
- //
discreteMapping.putMapValue("Clustered", ELLIPSE);
- // discreteMapping.putMapValue("Seed",
RECT);
- //
discreteMapping.putMapValue("Unclustered", DIAMOND);
- //
- // Calculator nodeShapeCalculator = new
BasicCalculator("Seed and Cluster Status Calculator", discreteMapping,
VisualPropertyType.NODE_SHAPE);
- // nac.setCalculator(nodeShapeCalculator);
- //
- // // NodeColor:
- //
nac.getDefaultAppearance().set(VisualPropertyType.NODE_FILL_COLOR, Color.WHITE);
- // ContinuousMapping continuousMapping =
new ContinuousMapping(Color.WHITE, ObjectMapping.NODE_MAPPING);
- //
continuousMapping.setControllingAttributeName("MCODE_Score", null, false);
- //
- // Interpolator fInt = new
LinearNumberToColorInterpolator();
- // continuousMapping.setInterpolator(fInt);
- //
- // //Node color is based on the score, the
lower the score the darker the color
- // Color minColor = Color.BLACK;
- // Color maxColor = Color.RED;
- //
- // //Create two boundary conditions
- // //First we state that everything below
or equalling 0 (min) will be white, and everything above that will
- // //start from black and fade into the
next boundary color
- // BoundaryRangeValues bv0 = new
BoundaryRangeValues(Color.WHITE, Color.WHITE, minColor);
- // //Now we state that anything anything
below the max score will fade into red from the lower boundary color
- // //and everything equal or greater than
the max (never occurs since this is the upper boundary) will be red
- // BoundaryRangeValues bv2 = new
BoundaryRangeValues(maxColor, maxColor, maxColor);
- //
- // //Set Data Points
- // double minValue = 0.0;
- // //the max value is set by
MCODEVisualStyleAction based on the current result set's max score
- // continuousMapping.addPoint(minValue,
bv0);
- // continuousMapping.addPoint(maxValue,
bv2);
- //
- // Calculator nodeColorCalculator = new
BasicCalculator("MCODE Score Color Calculator", continuousMapping,
VisualPropertyType.NODE_FILL_COLOR);
- // nac.setCalculator(nodeColorCalculator);
- //
- // public void setMaxValue(double maxValue) {
- // this.maxValue = maxValue;
- // }
+ return clusterStyle;
+ }
+
+ public VisualStyle getPluginStyle(double maxScore) {
+ if (pluginStyle == null) {
+ pluginStyle = visualStyleFactory.getInstance("MCODE");
+
+ // Node Shape:
+ DiscreteMapping<String, NodeShape> nodeShapeDm =
(DiscreteMapping<String, NodeShape>) discreteMappingFactory
+
.createVisualMappingFunction("MCODE_Node_Status", String.class,
RichVisualLexicon.NODE_SHAPE);
+
+ nodeShapeDm.putMapValue("Clustered",
NodeShapeVisualProperty.ELLIPSE);
+ nodeShapeDm.putMapValue("Seed",
NodeShapeVisualProperty.RECTANGLE);
+ nodeShapeDm.putMapValue("Unclustered",
NodeShapeVisualProperty.DIAMOND);
+
+ pluginStyle.addVisualMappingFunction(nodeShapeDm);
+
+ // Node Color:
+ // The lower the score the darker the color
+
pluginStyle.setDefaultValue(MinimalVisualLexicon.NODE_FILL_COLOR, Color.WHITE);
+
+ ContinuousMapping<Double, Paint> nodeColorCm =
(ContinuousMapping<Double, Paint>) continuousMappingFactory
+
.createVisualMappingFunction("MCODE_Score", Double.class,
MinimalVisualLexicon.NODE_FILL_COLOR);
+
+ final Color MIN_COLOR = Color.BLACK;
+ final Color MAX_COLOR = Color.RED;
+
+ // First we state that everything below or equaling 0
(min) will be white, and everything above that will
+ // start from black and fade into the next boundary
color
+ nodeColorCm.addPoint(0.0, new
BoundaryRangeValues<Paint>(Color.WHITE, Color.WHITE, MIN_COLOR));
+ // Now we state that anything anything below the max
score will fade into red from the lower boundary color
+ // and everything equal or greater than the max (never
occurs since this is the upper boundary) will be red
+ // The max value is set by MCODEVisualStyleAction based
on the current result set's max score
+ nodeColorCm.addPoint(maxScore, new
BoundaryRangeValues<Paint>(MAX_COLOR, MAX_COLOR, MAX_COLOR));
+
+ // TODO: create one style per score and store in a map?
+
+ pluginStyle.addVisualMappingFunction(nodeColorCm);
}
- return style;
+ return pluginStyle;
}
public VisualStyle getNetworkViewStyle(CyNetworkView view) {
@@ -456,7 +530,7 @@
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/MCODEResultsPanel.java
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
2011-08-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/java/org/cytoscape/mcode/internal/view/MCODEResultsPanel.java
2011-08-26 22:16:57 UTC (rev 26640)
@@ -37,6 +37,7 @@
import javax.swing.JTextArea;
import javax.swing.JToolTip;
import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -50,6 +51,7 @@
import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.application.swing.CytoPanelName;
import org.cytoscape.application.swing.CytoPanelState;
+import org.cytoscape.mcode.internal.MCODEDiscardResultAction;
import org.cytoscape.mcode.internal.model.MCODEAlgorithm;
import org.cytoscape.mcode.internal.model.MCODECluster;
import org.cytoscape.mcode.internal.model.MCODECurrentParameters;
@@ -124,10 +126,11 @@
private CyNetworkView networkView; // Keep a record of this too, if it
exists
private MCODECollapsiblePanel explorePanel;
private JPanel[] exploreContent;
+ private JButton closeButton;
+
private MCODEParameterSet currentParamsCopy;
- private int enumerationSelection = 0; // Keep track of selected
attribute for
- // enumeration so it stays selected for all
- // cluster explorations
+ // Keep track of selected attribute for enumeration so it stays
selected for all cluster explorations
+ private int enumerationSelection = 0;
// Graphical classes
private GraphDrawer drawer;
@@ -135,7 +138,7 @@
private final MCODEUtil mcodeutil;
private final CySwingApplication swingApplication;
- private final CyServiceRegistrar registrar;
+ private final MCODEDiscardResultAction discardResultAction;
/**
* Constructor for the Results Panel which displays the clusters in a
@@ -155,7 +158,7 @@
Image[] imageList,
int resultId,
final
CySwingApplication swingApplication,
- final
CyServiceRegistrar registrar) {
+ final
MCODEDiscardResultAction discardResultAction) {
setLayout(new BorderLayout());
this.alg = alg;
@@ -166,7 +169,7 @@
// The view may not exist, but we only test for that when we
need to (in the TableRowSelectionHandler below)
this.networkView = networkView;
this.swingApplication = swingApplication;
- this.registrar = registrar;
+ this.discardResultAction = discardResultAction;
currentParamsCopy =
mcodeutil.getCurrentParameters().getResultParams(resultId);
@@ -207,6 +210,23 @@
return this.resultId;
}
+ public void discard(final boolean requestUserConfirmation) {
+ SwingUtilities.invokeLater(new Runnable() {
+
+ @Override
+ public void run() {
+ boolean oldRequestUserConfirmation = new
Boolean(discardResultAction
+
.getValue(MCODEDiscardResultAction.REQUEST_USER_CONFIRMATION_COMMAND).toString());
+
+
discardResultAction.putValue(MCODEDiscardResultAction.REQUEST_USER_CONFIRMATION_COMMAND,
+
requestUserConfirmation);
+ closeButton.doClick();
+
discardResultAction.putValue(MCODEDiscardResultAction.REQUEST_USER_CONFIRMATION_COMMAND,
+
oldRequestUserConfirmation);
+ }
+ });
+ }
+
/**
* Creates a panel that contains the browser table with a scroll bar.
*
@@ -263,8 +283,8 @@
exportButton.setToolTipText("Export result set to a text file");
// The close button
- JButton closeButton = new JButton("Discard Result");
- closeButton.addActionListener(new
MCODEResultsPanel.CloseAction(this));
+ closeButton = new JButton(discardResultAction);
+
discardResultAction.putValue(MCODEDiscardResultAction.REQUEST_USER_CONFIRMATION_COMMAND,
true);
buttonPanel.add(exportButton);
buttonPanel.add(closeButton);
@@ -382,7 +402,7 @@
private JPanel createBottomExplorePanel(int selectedRow) {
JPanel panel = new JPanel();
JButton createChildButton = new JButton("Create Sub-Network");
- createChildButton.addActionListener(new
MCODEResultsPanel.CreateChildAction(this, selectedRow));
+ createChildButton.addActionListener(new
MCODEResultsPanel.CreateSubNetworkAction(this, selectedRow));
panel.add(createChildButton);
return panel;
@@ -440,12 +460,14 @@
/**
* Handles the create child network press in the cluster exploration
panel
*/
- private class CreateChildAction extends AbstractAction {
+ private class CreateSubNetworkAction extends AbstractAction {
+ private static final long serialVersionUID =
-7055711916961537608L;
+
int selectedRow;
MCODEResultsPanel trigger;
- CreateChildAction(MCODEResultsPanel trigger, int selectedRow) {
+ CreateSubNetworkAction(MCODEResultsPanel trigger, int
selectedRow) {
this.selectedRow = selectedRow;
this.trigger = trigger;
}
@@ -459,10 +481,10 @@
final String title = trigger.getResultId() + ": " +
cluster.getClusterName() + " (Score: " +
nf.format(cluster.getClusterScore()) + ")";
// create the child network and view
- final SwingWorker worker = new SwingWorker() {
+ final SwingWorker<CyNetworkView, ?> worker = new
SwingWorker<CyNetworkView, Object>() {
@Override
- protected Object doInBackground() throws
Exception {
+ protected CyNetworkView doInBackground() throws
Exception {
CyNetwork newNetwork =
mcodeutil.createSubNetwork(clusterNetwork, clusterNetwork.getNodeList());
newNetwork.getCyRow().set(CyNetwork.NAME, title);
@@ -512,7 +534,7 @@
newNetworkView.fitContent();
newNetworkView.updateView();
- return null;
+ return newNetworkView;
}
};
@@ -800,42 +822,6 @@
}
/**
- * Handles the close press for this results panel
- */
- private class CloseAction extends AbstractAction {
-
- final MCODEResultsPanel trigger;
-
- CloseAction(final MCODEResultsPanel trigger) {
- this.trigger = trigger;
- }
-
- public void actionPerformed(ActionEvent e) {
- final CytoPanel cytoPanel =
swingApplication.getCytoPanel(CytoPanelName.EAST);
-
- // Must make sure the user wants to close this results
panel
- String message = "You are about to dispose of " +
resultId + ".\nDo you wish to continue?";
- int result =
JOptionPane.showOptionDialog(swingApplication.getJFrame(),
-
new Object[] { message },
-
"Confirm",
-
JOptionPane.YES_NO_OPTION,
-
JOptionPane.QUESTION_MESSAGE,
-
null,
-
null,
-
null);
- if (result == JOptionPane.YES_OPTION) {
- registrar.unregisterService(trigger,
CytoPanelComponent.class);
-
mcodeutil.getCurrentParameters().removeResultParams(getResultId());
- }
-
- // If there are no more tabs in the cytopanel then we
hide it
- if (cytoPanel.getCytoPanelComponentCount() == 0) {
- cytoPanel.setState(CytoPanelState.HIDE);
- }
- }
- }
-
- /**
* Handles the Export press for this panel (export results to a text
file)
*/
private class ExportAction extends AbstractAction {
Modified:
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
===================================================================
---
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-08-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context-osgi.xml
2011-08-26 22:16:57 UTC (rev 26640)
@@ -52,6 +52,18 @@
<osgi:reference id="visualMappingManagerServiceRef"
interface="org.cytoscape.view.vizmap.VisualMappingManager" />
+
+ <osgi:reference id="discreteMappingFactoryServiceRef"
+ interface="org.cytoscape.view.vizmap.VisualMappingFunctionFactory"
+ filter="(mapping.type=discrete)" />
+
+ <osgi:reference id="continuousMappingFactoryServiceRef"
+ interface="org.cytoscape.view.vizmap.VisualMappingFunctionFactory"
+ filter="(mapping.type=continuous)" />
+
+ <osgi:reference id="passthroughMappingFactoryServiceRef"
+ interface="org.cytoscape.view.vizmap.VisualMappingFunctionFactory"
+ filter="(mapping.type=passthrough)" />
<!-- ================= Export =========================== -->
@@ -61,8 +73,12 @@
<osgi:service id="openMenuActionService" ref="openAction"
interface="org.cytoscape.application.swing.CyAction" />
- <osgi:service id="closeMenuActionService" ref="closeAction"
- interface="org.cytoscape.application.swing.CyAction" />
+ <osgi:service id="closeMenuActionService" ref="closeAction">
+ <osgi:interfaces>
+ <value>org.cytoscape.application.swing.CyAction</value>
+
<value>org.cytoscape.model.events.NetworkAboutToBeDestroyedListener</value>
+ </osgi:interfaces>
+ </osgi:service>
<osgi:service id="helpMenuActionService" ref="helpAction"
interface="org.cytoscape.application.swing.CyAction" />
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-26 21:05:40 UTC (rev 26639)
+++
csplugins/trunk/toronto/clopes/mcode/src/main/resources/META-INF/spring/bundle-context.xml
2011-08-26 22:16:57 UTC (rev 26640)
@@ -60,6 +60,9 @@
<constructor-arg ref="visualMappingManagerServiceRef" />
<constructor-arg ref="cySwingApplicationServiceRef" />
<constructor-arg ref="cyEventHelperServiceRef" />
+ <constructor-arg ref="discreteMappingFactoryServiceRef" />
+ <constructor-arg ref="continuousMappingFactoryServiceRef" />
+ <constructor-arg ref="passthroughMappingFactoryServiceRef" />
</bean>
<!-- Other beans -->
--
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.