Author: paperwing
Date: 2012-03-27 09:02:46 -0700 (Tue, 27 Mar 2012)
New Revision: 28663

Modified:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/AnimatorController.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/coordinator/BirdsEyeCoordinatorProcessor.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/DefaultValueVault.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/input/DebugInputHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/NetworkToolkit.java
Log:
Renamed CyTableEntry references to CyIdentifiable, pressing C not only resets 
camera but now also resets node z-coordinates to default values, fitInView() 
method created in NetworkToolkit to allow the network view object to perform 
fitting operations used in the toolbar, camera reference added to 
WindNetworkView for taskbar zooming

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/AnimatorController.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/AnimatorController.java
       2012-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/AnimatorController.java
       2012-03-27 16:02:46 UTC (rev 28663)
@@ -116,7 +116,7 @@
                return coordinator;
        }
 
-       private void startAnimator() {
+       public void startAnimator() {
                animatorControl.start();
                
                if (coordinator.isBirdsEyeClaimed() && 
coordinator.getBirdsEyeAnimatorControl() != null) {
@@ -124,7 +124,7 @@
                }
        }
        
-       private void stopAnimator() {
+       public void stopAnimator() {
                animatorControl.stop();
                
                if (coordinator.isBirdsEyeClaimed() && 
coordinator.getBirdsEyeAnimatorControl() != null) {

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-27 16:02:46 UTC (rev 28663)
@@ -24,6 +24,7 @@
 import org.cytoscape.paperwing.internal.coordinator.CoordinatorProcessor;
 import org.cytoscape.paperwing.internal.coordinator.ViewingCoordinator;
 import 
org.cytoscape.paperwing.internal.cytoscape.processing.CytoscapeDataProcessor;
+import org.cytoscape.paperwing.internal.cytoscape.view.WindNetworkView;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.input.InputProcessor;
@@ -260,6 +261,7 @@
                        component.addMouseWheelListener(controller);
                        
                        graphicsData.setAnimatorController(controller);
+                       ((WindNetworkView) 
graphicsData.getNetworkView()).setAnimatorController(controller);
                }
        }
 

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/coordinator/BirdsEyeCoordinatorProcessor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/coordinator/BirdsEyeCoordinatorProcessor.java
 2012-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/coordinator/BirdsEyeCoordinatorProcessor.java
 2012-03-27 16:02:46 UTC (rev 28663)
@@ -1,10 +1,14 @@
 package org.cytoscape.paperwing.internal.coordinator;
 
+import java.util.Collection;
+
+import org.cytoscape.model.CyNode;
 import org.cytoscape.paperwing.internal.data.CoordinatorData;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.tools.NetworkToolkit;
 import org.cytoscape.paperwing.internal.tools.SimpleCamera;
+import org.cytoscape.view.model.View;
 
 public class BirdsEyeCoordinatorProcessor implements CoordinatorProcessor {
 
@@ -98,6 +102,8 @@
                // Update the birds eye view camera
                camera.set(mainCameraCopy);
                
+               /*
+       
                Vector3 networkCenter = 
NetworkToolkit.findNetworkCenter(graphicsData.getNetworkView(), 
graphicsData.getDistanceScale());
                Vector3 farthestNode = 
NetworkToolkit.findFarthestNodeFromCenter(graphicsData.getNetworkView(), 
networkCenter, graphicsData.getDistanceScale());
                
@@ -117,8 +123,14 @@
 
                camera.moveTo(networkCenter.plus(offset));
                camera.setDistance(newDistance);
+               
+               */
+               
+               NetworkToolkit.fitInView(camera, 
graphicsData.getNetworkView().getNodeViews(), graphicsData.getDistanceScale(), 
5.0);
        }
        
+
+       
        @Override
        public void unlinkCoordinator(ViewingCoordinator coordinator) {
                coordinator.unlinkBirdsEye();

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/DefaultValueVault.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/DefaultValueVault.java
 2012-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/DefaultValueVault.java
 2012-03-27 16:02:46 UTC (rev 28663)
@@ -7,9 +7,9 @@
 import java.util.Map.Entry;
 
 import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
-import org.cytoscape.model.CyTableEntry;
 import org.cytoscape.view.model.VisualLexicon;
 import org.cytoscape.view.model.VisualProperty;
 import org.cytoscape.view.presentation.property.BasicVisualLexicon;
@@ -21,7 +21,7 @@
        private Map<String, VisualPropertyValueHolder<?>> edgeDefaultValues;
        private Map<String, VisualPropertyValueHolder<?>> networkDefaultValues;
        
-       private Map<Class<? extends CyTableEntry>,
+       private Map<Class<? extends CyIdentifiable>,
                Map<String, VisualPropertyValueHolder<?>>> defaultValueSets;
        
        private VisualLexicon visualLexicon;
@@ -33,7 +33,7 @@
                edgeDefaultValues = new HashMap<String, 
VisualPropertyValueHolder<?>>();
                networkDefaultValues = new HashMap<String, 
VisualPropertyValueHolder<?>>();
                
-               defaultValueSets = new HashMap<Class<? extends CyTableEntry>, 
Map<String, VisualPropertyValueHolder<?>>>();
+               defaultValueSets = new HashMap<Class<? extends CyIdentifiable>, 
Map<String, VisualPropertyValueHolder<?>>>();
                defaultValueSets.put(CyNode.class, nodeDefaultValues);
                defaultValueSets.put(CyEdge.class, edgeDefaultValues);
                defaultValueSets.put(CyNetwork.class, networkDefaultValues);

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-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkView.java
   2012-03-27 16:02:46 UTC (rev 28663)
@@ -7,10 +7,12 @@
 import java.util.Map;
 import java.util.Set;
 
+import javax.media.opengl.GLAnimatorControl;
+
 import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyIdentifiable;
 import org.cytoscape.model.CyNetwork;
 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;
@@ -20,8 +22,10 @@
 import org.cytoscape.model.events.AddedEdgesListener;
 import org.cytoscape.model.events.AddedNodesEvent;
 import org.cytoscape.model.events.AddedNodesListener;
+import org.cytoscape.paperwing.internal.AnimatorController;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.tools.NetworkToolkit;
+import org.cytoscape.paperwing.internal.tools.SimpleCamera;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.model.VisualLexicon;
@@ -40,6 +44,9 @@
        private DefaultValueVault defaultValues;
        private VisualMappingManager visualMappingManager;
        
+       private AnimatorController animatorController;
+       private SimpleCamera networkCamera = null;
+       
        // Assumes indices of nodes are unique
        private Map<Integer, View<CyNode>> nodeViews;
        private Map<Integer, View<CyEdge>> edgeViews;
@@ -104,8 +111,8 @@
        }
 
        @Override
-       public Collection<View<? extends CyTableEntry>> getAllViews() {
-               Collection<View<? extends CyTableEntry>> views = new 
HashSet<View<? extends CyTableEntry>>();
+       public Collection<View<? extends CyIdentifiable>> getAllViews() {
+               Collection<View<? extends CyIdentifiable>> views = new 
HashSet<View<? extends CyIdentifiable>>();
                
                // Return views for Node, Edge, Network
                views.addAll(getNodeViews());
@@ -278,7 +285,7 @@
                // Update visual properties according to the current visual 
style
                VisualStyle visualStyle = 
visualMappingManager.getVisualStyle(this);
                
-               for (View<? extends CyTableEntry> view : getAllViews()) {
+               for (View<? extends CyIdentifiable> view : getAllViews()) {
                        for (VisualProperty<?> visualProperty : 
visualLexicon.getAllVisualProperties()) {
                                if (view.getVisualProperty(visualProperty) != 
null 
                                                && 
visualStyle.getDefaultValue(visualProperty) != null
@@ -309,6 +316,22 @@
                        return defaultValues.getDefaultValue(visualProperty);
                }
        }
+
+       public void setAnimatorController(AnimatorController 
animatorController) {
+               this.animatorController = animatorController;
+       }
+
+       public AnimatorController getAnimatorController() {
+               return animatorController;
+       }
+
+       public void setNetworkCamera(SimpleCamera networkCamera) {
+               this.networkCamera = networkCamera;
+       }
+
+       public SimpleCamera getNetworkCamera() {
+               return networkCamera;
+       }
        
 //     @Override
 //     public void handleEvent(AboutToRemoveNodesEvent e) {

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
  2012-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DebugInputHandler.java
  2012-03-27 16:02:46 UTC (rev 28663)
@@ -2,7 +2,10 @@
 
 import java.util.Set;
 
+import org.cytoscape.model.CyNode;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.presentation.property.BasicVisualLexicon;
 
 import com.jogamp.newt.event.KeyEvent;
 
@@ -26,9 +29,17 @@
                        graphicsData.setShowFPS(!graphicsData.getShowFPS());
                }
                
+               // Toggle displaying all node labels or only for the 
selected/hovered nodes
                if (pressed.contains(KeyEvent.VK_L)) {
                        
graphicsData.setShowAllNodeLabels(!graphicsData.getShowAllNodeLabels());
                }
+               
+               // Reset node z-coordinate values to default
+               if (pressed.contains(KeyEvent.VK_C)) {
+                       for (View<CyNode> nodeView : 
graphicsData.getNetworkView().getNodeViews()) {
+                               
nodeView.setVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION, 0.0);
+                       }
+               }
        }
 
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
     2012-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/layouts/SphericalLayoutAlgorithmTask.java
     2012-03-27 16:02:46 UTC (rev 28663)
@@ -11,6 +11,7 @@
 import org.cytoscape.model.CyEdge.Type;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.paperwing.internal.cytoscape.view.WindNetworkView;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.tools.NetworkToolkit;
 import org.cytoscape.view.layout.AbstractBasicLayoutTask;
@@ -60,6 +61,10 @@
                }
                
                arrangePartitions(partitions);
+               
+               if (networkView instanceof WindNetworkView) {
+                       ((WindNetworkView) 
networkView).getAnimatorController().startAnimator();
+               }
        }
        
        private void arrangePartitions(Collection<Collection<View<CyNode>>> 
partitions) {

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-03-27 01:12:23 UTC (rev 28662)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/NetworkToolkit.java
     2012-03-27 16:02:46 UTC (rev 28663)
@@ -1,5 +1,6 @@
 package org.cytoscape.paperwing.internal.tools;
 
+import java.util.Collection;
 import java.util.Set;
 
 import org.cytoscape.model.CyColumn;
@@ -17,6 +18,14 @@
 
        private static final String SELECTED_COLUMN_NAME = "selected";
        
+       /**
+        * Find the average position of a given set of nodes.
+        * 
+        * @param nodeIndices The indices of nodes whose average position is to 
be found
+        * @param networkView The network view containing the nodes
+        * @param distanceScale The distance scaling used to convert between 
Cytoscape and renderer coordinates.
+        * @return The average position
+        */
        public static Vector3 findCenter(Set<Integer> nodeIndices, 
CyNetworkView networkView, double distanceScale) {
                if (nodeIndices.isEmpty()) {
                        return null;
@@ -43,7 +52,70 @@
                
                return result;
        }
+       
+       /**
+        * Position the given camera as to fit all of the given nodes in the 
current view.
+        * 
+        * @param camera The camera to position
+        * @param nodeViews The node views to be fit into the current view
+        * @param distanceScale The distance scaling used to convert between 
Cytoscape and render coordinates. Cytoscape coordinates
+        * are divided by this scale to obtain renderer coordinates.
+        * @param minDistance The minimum distance between the camera and the 
average node position.
+        */
+       public static void fitInView(SimpleCamera camera, 
Collection<View<CyNode>> nodeViews, double distanceScale, double minDistance) {
+               Vector3 center = NetworkToolkit.findCenter(nodeViews, 
distanceScale);
+               Vector3 farthestNode = 
NetworkToolkit.findFarthestNodeFromCenter(nodeViews, center, distanceScale);
+               
+               double newDistance = farthestNode.distance(center);
+               
+               // Further increase the distance needed
+               newDistance *= 3;
+               
+               // Enforce minimum distance
+               newDistance = Math.max(newDistance, minDistance);
+               
+               Vector3 offset = camera.getDirection().multiply(-newDistance);
+               
+               camera.moveTo(center.plus(offset));
+               camera.setDistance(newDistance);
+       }
+       
+       /**
+        * Obtain the average position of a set of nodes.
+        * 
+        * @param nodeViews The node views whose average position is to be 
obtained
+        * @param distanceScale The distance scaling used to convert between 
Cytoscape and render coordinates. Cytoscape coordinates
+        * are divided by this scale to obtain renderer coordinates.
+        * @return The average position
+        */
+       public static Vector3 findCenter(Collection<View<CyNode>> nodeViews, 
double distanceScale) {
+               double x = 0, y = 0, z = 0;
+               int visitedCount = 0;
+               
+               for (View<CyNode> nodeView : nodeViews) {
+                       
+                       if (nodeView != null) {
+                               x += 
nodeView.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
+                               y += 
nodeView.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
+                               z += 
nodeView.getVisualProperty(BasicVisualLexicon.NODE_Z_LOCATION);
+                               visitedCount++;
+                       }
+               }
+               
+               Vector3 result = new Vector3(x, y, z);
+               result.divideLocal(distanceScale * visitedCount);
+               
+               return result;
+       }
 
+       /**
+        * Obtain the average position of nodes in a network.
+        *
+        * @param networkView The network to find the average position of
+        * @param distanceScale The distance scaling used to convert between 
Cytoscape and render coordinates. Cytoscape coordinates
+        * are divided by this scale to obtain renderer coordinates.
+        * @return The average position
+        */
        public static Vector3 findNetworkCenter(CyNetworkView networkView, 
double distanceScale) {
                double x = 0, y = 0, z = 0;
                int visitedCount = 0;
@@ -70,17 +142,23 @@
                return result;
        }
 
-       public static Vector3 findFarthestNodeFromCenter(CyNetworkView 
networkView, Vector3 networkCenter, double distanceScale) {
+       /**
+        * Find the position of the node that is farthest from a given position.
+        * 
+        * @param nodeViews The node views used to find the farthest node
+        * @param networkCenter The position used as the center, to determine 
the farthest node
+        * @param distanceScale The distance scaling used to convert between 
Cytoscape and render coordinates. Cytoscape coordinates
+        * are divided by this scale to obtain renderer coordinates.
+        * @return The position of the farthest node
+        */
+       public static Vector3 
findFarthestNodeFromCenter(Collection<View<CyNode>> nodeViews, Vector3 
networkCenter, double distanceScale) {
                double currentDistanceSquared;
                double maxDistanceSquared = 0;
                
                Vector3 currentPosition = new Vector3();
                Vector3 maxPosition = new Vector3();
                
-               View<CyNode> nodeView;
-               
-               for (CyNode node : networkView.getModel().getNodeList()) {
-                       nodeView = networkView.getNodeView(node);
+               for (View<CyNode> nodeView : nodeViews) {
                        
                        if (nodeView != null) {
                        
@@ -100,11 +178,23 @@
                
                return maxPosition;
        }
+       
+       public static Vector3 findFarthestNodeFromCenter(CyNetworkView 
networkView, Vector3 networkCenter, double distanceScale) {
+               return findFarthestNodeFromCenter(networkView.getNodeViews(), 
networkCenter, distanceScale);
+       }
 
        public static Vector3 findFarthestNodeFromCenter(CyNetworkView 
networkView, double distanceScale) {
                return findFarthestNodeFromCenter(networkView, 
findNetworkCenter(networkView, distanceScale), distanceScale);
        }
 
+       /**
+        * Moves all of a given set of nodes by an amount specified by a 
displacement vector.
+        * 
+        * @param nodeIndices The indices of nodes to move
+        * @param networkView The network view containing the nodes
+        * @param distanceScale The distance scaling used to convert between 
Cytoscape and renderer coordinates
+        * @param displacement The displacement vector
+        */
        public static void displaceNodes(Set<Integer> nodeIndices, 
CyNetworkView networkView, double distanceScale, Vector3 displacement) {
                View<CyNode> nodeView;
                

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