Author: paperwing
Date: 2012-01-11 11:43:13 -0800 (Wed, 11 Jan 2012)
New Revision: 27980
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkView.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkViewFactory.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderEdgesProcedure.java
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/NetworkToolkit.java
Log:
fixed issue with WindNetworkView not properly being able to keep track of
deleted/added nodes/edges
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
2012-01-11 18:51:25 UTC (rev 27979)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/CyActivator.java
2012-01-11 19:43:13 UTC (rev 27980)
@@ -36,7 +36,7 @@
// Wind NetworkView factory
WindNetworkViewFactory windNetworkViewFactory =
- new WindNetworkViewFactory(windVisualLexicon);
+ new WindNetworkViewFactory(cyServiceRegistrarRef,
windVisualLexicon);
Properties windNetworkViewFactoryProps = new Properties();
windNetworkViewFactoryProps.setProperty("serviceType",
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkView.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkView.java
2012-01-11 18:51:25 UTC (rev 27979)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkView.java
2012-01-11 19:43:13 UTC (rev 27980)
@@ -10,13 +10,20 @@
import org.cytoscape.model.CyNode;
import org.cytoscape.model.CyTableEntry;
import org.cytoscape.model.SUIDFactory;
+import org.cytoscape.model.events.AboutToRemoveEdgesEvent;
+import org.cytoscape.model.events.AboutToRemoveEdgesListener;
+import org.cytoscape.model.events.AboutToRemoveNodesEvent;
+import org.cytoscape.model.events.AboutToRemoveNodesListener;
+import org.cytoscape.model.events.AddedEdgesEvent;
+import org.cytoscape.model.events.AddedEdgesListener;
+import org.cytoscape.model.events.AddedNodesEvent;
+import org.cytoscape.model.events.AddedNodesListener;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
import org.cytoscape.view.model.VisualLexicon;
import org.cytoscape.view.model.VisualProperty;
-public class WindNetworkView extends VisualPropertyKeeper<CyNetwork>
- implements CyNetworkView {
+public class WindNetworkView extends VisualPropertyKeeper<CyNetwork>
implements CyNetworkView {
private long suid;
@@ -114,6 +121,16 @@
public void updateView() {
// TODO: Check if correct place to put this; below code should
ensure having a view
// for every node/edge in the network
+
+ matchNodes();
+ matchEdges();
+ }
+
+ // Checks if there is a discrepancy between number of nodes and
nodeViews, attempts
+ // to fix discrepancy by removing extra views and adding missing views
+ // TODO: Currently considers the set of views to be OK if node and
nodeView counts match,
+ // does not check if there is an actual 1:1 relationship
+ private void matchNodes() {
int nodeCountDifference = network.getNodeCount() -
nodeViews.size();
// Check if nodes have been added to the network
@@ -136,14 +153,73 @@
if (nodeCountDifference != 0) {
// TODO: Use exception
-
System.out.println("WindNetworkView.updateView(): node count mismatch by " +
nodeCountDifference);
+
System.out.println("WindNetworkView.matchNodes(): node count mismatch by " +
nodeCountDifference);
}
// Check if nodes have been removed from the network
} else if (nodeCountDifference < 0) {
+ int nodeIndex;
+ HashSet<Integer> toBeRemovedIndices = new
HashSet<Integer>();
+ for (View<CyNode> nodeView : nodeViews.values()) {
+
+ nodeIndex = nodeView.getModel().getIndex();
+
+ // TODO: Currently performs check by checking
if the view's node index is still valid
+ if (network.getNode(nodeIndex) == null) {
+ toBeRemovedIndices.add(nodeIndex);
+ }
+ }
+
+ for (int index : toBeRemovedIndices) {
+ nodeViews.remove(index);
+ }
}
+ }
+
+ private void matchEdges() {
+ int edgeCountDifference = network.getEdgeCount() -
edgeViews.size();
-
+ // Check if nodes have been added to the network
+ if (edgeCountDifference > 0) {
+ for (CyEdge edge : network.getEdgeList()) {
+
+ // Found a edge without a view?
+ if (edgeViews.get(edge.getIndex()) == null) {
+
+ WindEdgeView edgeView = new
WindEdgeView(edge, SUIDFactory.getNextSUID());
+ defaultValues.initializeEdge(edgeView);
+
+ edgeViews.put(edge.getIndex(),
edgeView);
+
+ edgeCountDifference--;
+ }
+ }
+
+ // Did we fail to match every edge with a edge view?
+ if (edgeCountDifference != 0) {
+
+ // TODO: Use exception
+
System.out.println("WindNetworkView.matchEdges(): edge count mismatch by " +
edgeCountDifference);
+ }
+ // Check if edges have been removed from the network
+ } else if (edgeCountDifference < 0) {
+ int edgeIndex;
+ HashSet<Integer> toBeRemovedIndices = new
HashSet<Integer>();
+
+ for (View<CyEdge> edgeView : edgeViews.values()) {
+
+ edgeIndex = edgeView.getModel().getIndex();
+
+ // TODO: Currently performs check by checking
if the view's edge index is still valid
+ if (network.getEdge(edgeIndex) == null) {
+ toBeRemovedIndices.add(edgeIndex);
+ }
+ }
+
+ for (int index : toBeRemovedIndices) {
+ edgeViews.remove(index);
+ }
+ }
}
@Override
@@ -153,4 +229,52 @@
defaultValues.modifyDefaultValue(visualProperty, defaultValue);
}
+// @Override
+// public void handleEvent(AboutToRemoveNodesEvent e) {
+// if (e.getSource() == network) {
+// for (CyNode node : e.getNodes()) {
+// nodeViews.remove(node.getIndex());
+// }
+// }
+// }
+//
+// @Override
+// public void handleEvent(AboutToRemoveEdgesEvent e) {
+// if (e.getSource() == network) {
+// for (CyEdge edge : e.getEdges()) {
+// edgeViews.remove(edge.getIndex());
+// }
+// }
+// }
+//
+// @Override
+// public void handleEvent(AddedNodesEvent e) {
+// if (e.getSource() == network) {
+// WindNodeView nodeView;
+//
+// for (CyNode node : e.getPayloadCollection()) {
+// nodeView = new WindNodeView(node,
SUIDFactory.getNextSUID());
+// defaultValues.initializeNode(nodeView);
+//
+// nodeViews.put(node.getIndex(), nodeView);
+// }
+// }
+// }
+//
+// @Override
+// public void handleEvent(AddedEdgesEvent e) {
+// if (e.getSource() == network) {
+// WindEdgeView edgeView;
+//
+// for (CyEdge edge : e.getPayloadCollection()) {
+// edgeView = new WindEdgeView(edge,
SUIDFactory.getNextSUID());
+// defaultValues.initializeEdge(edgeView);
+//
+// edgeViews.put(edge.getIndex(), edgeView);
+// }
+// }
+// }
+
+
+
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkViewFactory.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkViewFactory.java
2012-01-11 18:51:25 UTC (rev 27979)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkViewFactory.java
2012-01-11 19:43:13 UTC (rev 27980)
@@ -1,7 +1,14 @@
package org.cytoscape.paperwing.internal.cytoscape.view;
+import java.util.Properties;
+
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.SUIDFactory;
+import org.cytoscape.model.events.AboutToRemoveEdgesListener;
+import org.cytoscape.model.events.AboutToRemoveNodesListener;
+import org.cytoscape.model.events.AddedEdgesListener;
+import org.cytoscape.model.events.AddedNodesListener;
+import org.cytoscape.service.util.CyServiceRegistrar;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.CyNetworkViewFactory;
import org.cytoscape.view.model.VisualLexicon;
@@ -10,16 +17,35 @@
private VisualLexicon visualLexicon;
- public WindNetworkViewFactory(VisualLexicon visualLexicon) {
+ private CyServiceRegistrar serviceRegistrar;
+
+ public WindNetworkViewFactory(CyServiceRegistrar serviceRegistrar,
+ VisualLexicon visualLexicon) {
+ this.serviceRegistrar = serviceRegistrar;
this.visualLexicon = visualLexicon;
}
@Override
public CyNetworkView createNetworkView(CyNetwork network,
Boolean useThreshold) {
+
+ // TODO: Implement use of useThreshold parameter
+ WindNetworkView networkView = new WindNetworkView(network,
visualLexicon);
- // TODO: Implement use of useThreshold parameter
- return new WindNetworkView(network, visualLexicon);
+// serviceRegistrar.registerService(networkView,
AddedNodesListener.class,
+// new Properties());
+// serviceRegistrar.registerService(networkView,
AddedEdgesListener.class,
+// new Properties());
+//
+// serviceRegistrar.registerService(networkView,
AboutToRemoveNodesListener.class,
+// new Properties());
+// serviceRegistrar.registerService(networkView,
AboutToRemoveEdgesListener.class,
+// new Properties());
+
+ // TODO: Now that we've registered the service, we need to
unregister them once
+ // the NetworkView is removed from Cytoscape
+
+ return networkView;
}
@Override
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
2012-01-11 18:51:25 UTC (rev 27979)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
2012-01-11 19:43:13 UTC (rev 27980)
@@ -88,9 +88,10 @@
networkView.getModel().getNode(index),
hoverNode, false);
- // TODO: Not sure if this call is needed
- networkView.updateView();
}
+
+ // TODO: Not sure if this call is needed
+ networkView.updateView();
}
}
}
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderEdgesProcedure.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderEdgesProcedure.java
2012-01-11 18:51:25 UTC (rev 27979)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderEdgesProcedure.java
2012-01-11 19:43:13 UTC (rev 27980)
@@ -35,7 +35,7 @@
/** The default radius of the semi-cylindrical edges */
- private static final float EDGE_RADIUS = 0.11f; // 0.018f default as of
Dec 2011
+ private static final float EDGE_RADIUS = 0.06f; // 0.018f default as of
Dec 2011
/**
* A multiplicative factor for the width of the edges when reading from
the
@@ -53,10 +53,10 @@
* How many straight edge segments to use for approximating a curved
edge,
* this value does not have to be static
*/
- private static int QUADRATIC_EDGE_SEGMENTS = 5;
+ private static int QUADRATIC_EDGE_SEGMENTS = 3;
/** The slices detail level to use for drawing edges */
- private static int EDGE_SLICES_DETAIL = 4;
+ private static int EDGE_SLICES_DETAIL = 3;
/** The stacks detail level to use for drawing edges */
private static int EDGE_STACKS_DETAIL = 1;
Modified:
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/NetworkToolkit.java
===================================================================
---
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/NetworkToolkit.java
2012-01-11 18:51:25 UTC (rev 27979)
+++
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/NetworkToolkit.java
2012-01-11 19:43:13 UTC (rev 27980)
@@ -82,16 +82,19 @@
for (CyNode node : networkView.getModel().getNodeList()) {
nodeView = networkView.getNodeView(node);
-
currentPosition.set(nodeView.getVisualProperty(RichVisualLexicon.NODE_X_LOCATION),
-
nodeView.getVisualProperty(RichVisualLexicon.NODE_Y_LOCATION),
-
nodeView.getVisualProperty(RichVisualLexicon.NODE_Z_LOCATION));
- currentPosition.divideLocal(distanceScale);
+ if (nodeView != null) {
- currentDistanceSquared =
networkCenter.distanceSquared(currentPosition);
-
- if (currentDistanceSquared > maxDistanceSquared) {
- maxDistanceSquared = currentDistanceSquared;
- maxPosition.set(currentPosition);
+
currentPosition.set(nodeView.getVisualProperty(RichVisualLexicon.NODE_X_LOCATION),
+
nodeView.getVisualProperty(RichVisualLexicon.NODE_Y_LOCATION),
+
nodeView.getVisualProperty(RichVisualLexicon.NODE_Z_LOCATION));
+ currentPosition.divideLocal(distanceScale);
+
+ currentDistanceSquared =
networkCenter.distanceSquared(currentPosition);
+
+ if (currentDistanceSquared >
maxDistanceSquared) {
+ maxDistanceSquared =
currentDistanceSquared;
+ maxPosition.set(currentPosition);
+ }
}
}
--
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.