Author: kono
Date: 2009-12-03 13:54:54 -0800 (Thu, 03 Dec 2009)
New Revision: 18645
Modified:
cytoscape/trunk/src/cytoscape/CyNode.java
cytoscape/trunk/src/cytoscape/util/NestedNetworkViewUpdater.java
Log:
First working version of Nested Network feature including saving and loading
session.
Modified: cytoscape/trunk/src/cytoscape/CyNode.java
===================================================================
--- cytoscape/trunk/src/cytoscape/CyNode.java 2009-12-03 20:05:09 UTC (rev
18644)
+++ cytoscape/trunk/src/cytoscape/CyNode.java 2009-12-03 21:54:54 UTC (rev
18645)
@@ -36,17 +36,17 @@
*/
package cytoscape;
+import giny.model.GraphPerspective;
+import giny.model.RootGraph;
+
+import java.util.ArrayList;
+import java.util.List;
+
import cytoscape.giny.CytoscapeFingRootGraph;
-
import cytoscape.groups.CyGroup;
import cytoscape.groups.CyGroupManager;
-import giny.model.*;
-import java.util.ArrayList;
-import java.util.List;
-
-
/**
*
*/
@@ -60,9 +60,9 @@
int m_rootGraphIndex = 0;
String m_identifier = null;
ArrayList<CyGroup> groupList = null;
- GraphPerspective graphPerspective;
+
+ private GraphPerspective nestedNetwork;
-
/**
* Creates a new CyNode object.
*
@@ -73,6 +73,7 @@
this.m_rootGraph = (CytoscapeFingRootGraph) root;
this.m_rootGraphIndex = rootGraphIndex;
this.m_identifier = new Integer(m_rootGraphIndex).toString();
+ this.nestedNetwork = null;
}
@@ -242,17 +243,17 @@
*/
public void setNestedNetwork(final GraphPerspective graphPerspective) {
// Sanity check.
- if (graphPerspective == this.graphPerspective)
+ if (graphPerspective == this.nestedNetwork)
return;
// Let listeners know that the previous nested network was
removed
- if (this.graphPerspective != null) {
-
Cytoscape.getPropertyChangeSupport().firePropertyChange(Cytoscape.NESTED_NETWORK_DESTROYED,
this, this.graphPerspective);
+ if (this.nestedNetwork != null) {
+
Cytoscape.getPropertyChangeSupport().firePropertyChange(Cytoscape.NESTED_NETWORK_DESTROYED,
this, this.nestedNetwork);
}
// create a Node Attribute "nested.network.id" for this Node
- final String networkID = ((CyNetwork)(graphPerspective == null
? this.graphPerspective : graphPerspective)).getIdentifier();
- this.graphPerspective = graphPerspective;
+ final String networkID = ((CyNetwork)(graphPerspective == null
? this.nestedNetwork : graphPerspective)).getIdentifier();
+ this.nestedNetwork = graphPerspective;
Cytoscape.getNodeAttributes().setAttribute(this.getIdentifier(),
NESTED_NETWORK_ID_ATTR, networkID);
@@ -271,7 +272,7 @@
parentNodeList.add(this.getIdentifier());
} else {
parentNodeList = (List<String>)
Cytoscape.getNetworkAttributes().getListAttribute(networkID, PARENT_NODES_ATTR);
- if (this.graphPerspective != null) {
+ if (this.nestedNetwork != null) {
parentNodeList.add(this.getIdentifier());
} else {
parentNodeList.remove(this.getIdentifier());
@@ -287,7 +288,7 @@
}
// Let listeners know nested network was assigned to this node.
- if (this.graphPerspective != null) {
+ if (this.nestedNetwork != null) {
Cytoscape.getPropertyChangeSupport().firePropertyChange(Cytoscape.NESTED_NETWORK_CREATED,
this, graphPerspective);
}
}
@@ -299,6 +300,6 @@
* @return a network reference or null.
*/
public GraphPerspective getNestedNetwork() {
- return graphPerspective;
+ return nestedNetwork;
}
}
Modified: cytoscape/trunk/src/cytoscape/util/NestedNetworkViewUpdater.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/NestedNetworkViewUpdater.java
2009-12-03 20:05:09 UTC (rev 18644)
+++ cytoscape/trunk/src/cytoscape/util/NestedNetworkViewUpdater.java
2009-12-03 21:54:54 UTC (rev 18645)
@@ -4,6 +4,7 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -27,41 +28,88 @@
public class NestedNetworkViewUpdater implements PropertyChangeListener {
private static final String NESTED_NETWORK_VS_NAME = "Nested Network
Style";
+
+ private boolean ignoreNextEvent = false;
public NestedNetworkViewUpdater() {
-
//Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(this);
+
Cytoscape.getPropertyChangeSupport().addPropertyChangeListener(this);
Cytoscape.getSwingPropertyChangeSupport().addPropertyChangeListener(this);
}
- public void propertyChange(final PropertyChangeEvent evt) {
- System.out.println("------- Got Signal --------> " +
evt.getPropertyName() + ", " + evt.getSource());
+ public void propertyChange(final PropertyChangeEvent evt) {
if
(evt.getPropertyName().equals(CytoscapeDesktop.NETWORK_VIEW_CREATED) ||
evt.getPropertyName().equals(CytoscapeDesktop.NETWORK_VIEW_DESTROYED)) {
+ if (ignoreNextEvent) {
+ ignoreNextEvent = false;
+ return;
+ } else {
+ ignoreNextEvent = true;
+ }
+ final boolean created =
evt.getPropertyName().equals(CytoscapeDesktop.NETWORK_VIEW_CREATED);
- final boolean created =
evt.getPropertyName().equals(CytoscapeDesktop.NETWORK_VIEW_CREATED);
// "New value" always contains newly created/destroyed
CyNetworkView.
final CyNetworkView view = (CyNetworkView)
evt.getNewValue();
- final List<String> parents =
Cytoscape.getNetworkAttributes().getListAttribute(view.getNetwork().getIdentifier(),
CyNode.PARENT_NODES_ATTR);
+ if (created) {
+ updateNodeViews(view.getNetwork(), view);
+ }
+
+ final List<String> parents =
Cytoscape.getNetworkAttributes().getListAttribute(view.getNetwork().getIdentifier(),
+ CyNode.PARENT_NODES_ATTR);
if (parents == null || parents.isEmpty()) {
return; // Not a nested network.
}
+ setNestedNetworkViews(parents, created);
- // First, grab all the available network views.
- final Collection<CyNetworkView> networkViews =
Cytoscape.getNetworkViewMap().values();
- for (final CyNetworkView networkView: networkViews) {
- for (final String parentNode: parents) {
- // If this view contains a parentNode,
then update its nested network view.
- //TODO: When we load saved session with
nested network, the following can be null. WHY?
- final CyNode node =
Cytoscape.getCyNode(parentNode);
- final NodeView nodeView =
networkView.getNodeView(node);
- if (nodeView != null && node != null &&
node.getNestedNetwork() != null) {
- System.out.println("--------->
Nested = " + node.getNestedNetwork());
-
((DNodeView)nodeView).setNestedNetworkView(
- created ? (DGraphView)
Cytoscape.getNetworkView(((CyNetwork)nodeView.getNode().getNestedNetwork()).getIdentifier())
- : null);
+ } else if
(evt.getPropertyName().equals(Cytoscape.NESTED_NETWORK_CREATED)) {
+ final CyNode parentNode = (CyNode) evt.getOldValue();
+ final List<String> parents = new ArrayList<String>();
+ parents.add(parentNode.getIdentifier());
+ setNestedNetworkViews(parents, /* created = */ true);
+ } else if
(evt.getPropertyName().equals(Cytoscape.NESTED_NETWORK_DESTROYED)) {
+ final CyNode parentNode = (CyNode) evt.getOldValue();
+ final List<String> parents = new ArrayList<String>();
+ parents.add(parentNode.getIdentifier());
+ setNestedNetworkViews(parents, /* created = */ false);
+ }
+ }
+
+
+ private void setNestedNetworkViews(final List<String> parents, final
boolean created) {
+ final Collection<CyNetworkView> networkViews =
Cytoscape.getNetworkViewMap().values();
+ for (final CyNetworkView networkView: networkViews) {
+ for (final String parentNode: parents) {
+ // If this view contains a parentNode, then
update its nested network view.
+ final CyNode node =
Cytoscape.getCyNode(parentNode);
+ if (node == null) {
+ continue;
+ }
+ final NodeView nodeView =
networkView.getNodeView(node);
+
+ if (nodeView != null) {
+ final CyNetwork nestedNetwork =
(CyNetwork)nodeView.getNode().getNestedNetwork();
+ if (nestedNetwork != null) {
+ CyNetworkView nestedNetworkView
= Cytoscape.getNetworkView(nestedNetwork.getIdentifier());
+ if (nestedNetworkView ==
Cytoscape.getNullNetworkView()) {
+ nestedNetworkView =
null;
+ }
+
((DNodeView)nodeView).setNestedNetworkView(created ? (DGraphView)
nestedNetworkView : null);
}
}
}
}
}
+
+
+ private void updateNodeViews(final CyNetwork currentNetwork, final
CyNetworkView currentNetworkView) {
+ for (final CyNode node:
(List<CyNode>)currentNetwork.nodesList()) {
+ final CyNetwork nestedNetwork = (CyNetwork)
node.getNestedNetwork();
+ if (nestedNetwork != null) {
+ final CyNetworkView nestedNetworkView =
Cytoscape.getNetworkView(nestedNetwork.getIdentifier());
+ if
(!nestedNetworkView.equals(Cytoscape.getNullNetworkView())) {
+ final NodeView nodeView =
currentNetworkView.getNodeView(node);
+
((DNodeView)nodeView).setNestedNetworkView((DGraphView) nestedNetworkView);
+ }
+ }
+ }
+ }
}
--
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.