Author: paperwing
Date: 2012-03-28 11:42:45 -0700 (Wed, 28 Mar 2012)
New Revision: 28682

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/MainGraphicsHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/constants/GraphicsConstants.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/processing/TableSelectionCytoscapeDataSubprocessor.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/data/GraphicsData.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DragMovementInputHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/KeyboardMonitor.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MouseMonitor.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/input/SelectionInputHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
Log:
fixes #833 First neighbors, invert node selection buttons now working, nodes no 
longer deselect upon clicking the window after using toolbar buttons. Networks 
created via "create network from selection" button are now centered. First 
neighbors and invert node bug fixed by network view requesting focus after work 
performed by toolbar buttons. All view-related toolbar buttons are now working.

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-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-28 18:42:45 UTC (rev 28682)
@@ -116,6 +116,10 @@
                
                cytoscapeDataProcessor = handler.getCytoscapeDataProcessor();
                lightingProcessor = handler.getLightingProcessor();
+               
+               if (handler instanceof MainGraphicsHandler) {
+                       ((WindNetworkView) 
graphicsData.getNetworkView()).setNetworkCamera(graphicsData.getCamera());
+               }
        }
        
        /** Attach the KeyboardMonitor and MouseMonitors, which are listeners,
@@ -133,6 +137,10 @@
                component.addFocusListener(keys);
                
                graphicsData.setContainer(component);
+               
+               if (handler instanceof MainGraphicsHandler) {
+                       ((WindNetworkView) 
graphicsData.getNetworkView()).setContainer(component);
+               }
        }
        
        public void setAnimatorControl(GLAnimatorControl animatorControl) {
@@ -262,7 +270,6 @@
                        
                        graphicsData.setAnimatorController(controller);
                        ((WindNetworkView) 
graphicsData.getNetworkView()).setAnimatorController(controller);
-                       ((WindNetworkView) 
graphicsData.getNetworkView()).setNetworkCamera(graphicsData.getCamera());
                }
        }
 

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-28 18:42:45 UTC (rev 28682)
@@ -15,6 +15,7 @@
 import org.cytoscape.paperwing.internal.coordinator.ViewingCoordinator;
 import 
org.cytoscape.paperwing.internal.cytoscape.processing.CytoscapeDataProcessor;
 import 
org.cytoscape.paperwing.internal.cytoscape.processing.MainCytoscapeDataProcessor;
+import org.cytoscape.paperwing.internal.cytoscape.view.WindNetworkView;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.data.LightingData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
      2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
      2012-03-28 18:42:45 UTC (rev 28682)
@@ -6,6 +6,8 @@
 import java.awt.Image;
 import java.awt.event.ContainerEvent;
 import java.awt.event.ContainerListener;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.awt.image.BufferedImage;
@@ -24,6 +26,7 @@
 import org.cytoscape.application.events.SetCurrentRenderingEngineEvent;
 import org.cytoscape.application.events.SetCurrentRenderingEngineListener;
 import org.cytoscape.model.CyNetwork;
+import org.cytoscape.paperwing.internal.constants.GraphicsConstants;
 import org.cytoscape.paperwing.internal.task.TaskFactoryListener;
 import org.cytoscape.service.util.CyServiceRegistrar;
 import org.cytoscape.view.model.CyNetworkView;
@@ -262,11 +265,6 @@
                // TODO Auto-generated method stub
                return null;
        }
-
-       @Override
-       public void setProperties(String key, String value) {
-               // TODO Auto-generated method stub
-       }
        
        @Override
        public Printable createPrintable() {
@@ -301,4 +299,9 @@
        @Override
        public void printCanvas(java.awt.Graphics printCanvas) {
        }
+       
+       @Override
+       public String getRenderingEngineID() {
+               return GraphicsConstants.RENDERING_ENGINE_ID;
+       }
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/constants/GraphicsConstants.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/constants/GraphicsConstants.java
      2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/constants/GraphicsConstants.java
      2012-03-28 18:42:45 UTC (rev 28682)
@@ -4,4 +4,13 @@
        
        /** A value representing that no valid display list is being 
referenced. */
        public static final int EMPTY_DISPLAY_LIST = -1;
+       
+       /** String id representing the renderer. */
+       public static final String RENDERING_ENGINE_ID = "wind";
+       
+       /** 
+        * The default scaling used to convert Cytoscape coordinates to 
renderer coordinates. Cytoscape coordinates
+        * are divided by this value to obtain renderer coordinates.
+        */
+       public static final float DEFAULT_DISTANCE_SCALE = 180.0f;
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/processing/TableSelectionCytoscapeDataSubprocessor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/processing/TableSelectionCytoscapeDataSubprocessor.java
     2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/processing/TableSelectionCytoscapeDataSubprocessor.java
     2012-03-28 18:42:45 UTC (rev 28682)
@@ -24,60 +24,8 @@
        
        @Override
        public void processCytoscapeData(GraphicsData graphicsData) {
-               
-               // Note: For the below method, Ding does not fill in selected 
states, so for now the 3d renderer will not do so either.
-               // initializeTableSelectionState(graphicsData);
-               
-               // Update CyTable with the currently selected set of nodes and 
edges
-               processSelectionData(graphicsData);
-               
-               processUpdateSelected(graphicsData);
        }
        
-       // Performs selection in Cytoscape data objects, such as CyTable
-       private void processSelectionData(GraphicsData graphicsData) {
-               
-               CyNetworkView networkView = graphicsData.getNetworkView();
-               GraphicsSelectionData selectionData = 
graphicsData.getSelectionData();
-               
-               Set<Integer> toBeDeselectedNodeIndices = 
selectionData.getToBeDeselectedNodeIndices();
-               Set<Integer> toBeDeselectedEdgeIndices = 
selectionData.getToBeDeselectedEdgeIndices();
-               
-               NetworkToolkit.deselectNodes(toBeDeselectedNodeIndices, 
networkView);
-               NetworkToolkit.deselectEdges(toBeDeselectedEdgeIndices, 
networkView);
-               toBeDeselectedNodeIndices.clear();
-               toBeDeselectedEdgeIndices.clear();
-               
-               // Select nodes
-               for (int index : selectionData.getSelectedNodeIndices()) {
-                       if (!NetworkToolkit.checkNodeSelected(index, 
networkView)) {
-                               NetworkToolkit.setNodeSelected(index, 
networkView, true);
-                       }
-               }
-               
-               // Select edges
-               for (int index : selectionData.getSelectedEdgeIndices()) {
-                       if (!NetworkToolkit.checkEdgeSelected(index, 
networkView)) {
-                               NetworkToolkit.setEdgeSelected(index, 
networkView, true);
-                       }
-               }
-       }
-       
-       // Checks if nodes and edges were made to be selected by other 
components of Cytoscape
-       private void processUpdateSelected(GraphicsData graphicsData) {
-               CyNetworkView networkView = graphicsData.getNetworkView();
-               
-               Set<Integer> selectedNodeIndices = 
graphicsData.getSelectionData().getSelectedNodeIndices();
-               Set<Integer> selectedEdgeIndices = 
graphicsData.getSelectionData().getSelectedEdgeIndices();
-               // selectedNodeIndices.clear();
-               
-               List<CyNode> tableSelectedNodes = 
CyTableUtil.getNodesInState(networkView.getModel(), "selected", true);
-               
-               for (CyNode node : tableSelectedNodes) {
-                       selectedNodeIndices.add(node.getIndex());
-               }
-       }
-       
        /**
         *  Fills in the missing "selected" boolean values in CyTable.
         *  

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-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/cytoscape/view/WindNetworkView.java
   2012-03-28 18:42:45 UTC (rev 28682)
@@ -1,5 +1,6 @@
 package org.cytoscape.paperwing.internal.cytoscape.view;
 
+import java.awt.Component;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -45,12 +46,27 @@
        private VisualMappingManager visualMappingManager;
        
        private AnimatorController animatorController;
+       
+       /**
+        * The camera associated with the main network viewing window used to
+        * perform operations such as fitting all nodes onto the screen
+        */
        private SimpleCamera networkCamera = null;
        
+       /**
+        * The container associated with the network view, used to request
+        * input focus after actions such as the user clicking a button on the 
+        * toolbar
+        */
+       private Component container = null;
+       
        // Assumes indices of nodes are unique
        private Map<Integer, View<CyNode>> nodeViews;
        private Map<Integer, View<CyEdge>> edgeViews;
        
+       /** A boolean that keeps track if fitContent() has been called to 
ensure the network has been centered at least once. */
+       private boolean networkCentered;
+       
        public WindNetworkView(CyNetwork network,
                        VisualLexicon visualLexicon,
                        VisualMappingManager visualMappingManager) {
@@ -78,6 +94,7 @@
                        edgeViews.put(edge.getIndex(), edgeView);
                }
                
+               networkCentered = false;
        }
        
        @Override
@@ -129,6 +146,7 @@
        public void fitContent() {
                if (networkCamera != null) {
                        NetworkToolkit.fitInView(networkCamera, 
nodeViews.values(), 180.0, 1.9, 2.0);
+                       networkCentered = true;
                }
                
                if (animatorController != null) {
@@ -167,9 +185,21 @@
                // Match the current network view to the currently applied 
visual style
 //             updateToMatchVisualStyle();
                
+               // Render at least 1 more frame to reflect changes in network
                if (animatorController != null) {
                        animatorController.startAnimator();
                }
+               
+               if (networkCamera != null && !networkCentered) {
+                       NetworkToolkit.fitInView(networkCamera, 
nodeViews.values(), 180.0, 1.9, 2.0);
+                       networkCentered = true;
+               }
+               
+               // Request focus after the network has been updated, such as 
via clicking a toolbar button,
+               // in order to be ready to receive keyboard and mouse input
+               if (container != null) {
+                       container.requestFocus();
+               }
        }
        
        // Checks if there is a discrepancy between number of nodes and 
nodeViews, attempts
@@ -328,6 +358,14 @@
        public SimpleCamera getNetworkCamera() {
                return networkCamera;
        }
+
+       public void setContainer(Component container) {
+               this.container = container;
+       }
+
+       public Component getContainer() {
+               return container;
+       }
        
 //     @Override
 //     public void handleEvent(AboutToRemoveNodesEvent e) {

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-28 18:42:45 UTC (rev 28682)
@@ -11,6 +11,7 @@
 
 import org.cytoscape.paperwing.internal.AnimatorController;
 import org.cytoscape.paperwing.internal.Graphics;
+import org.cytoscape.paperwing.internal.constants.GraphicsConstants;
 import org.cytoscape.paperwing.internal.coordinator.ViewingCoordinator;
 import org.cytoscape.paperwing.internal.cytoscape.edges.EdgeAnalyser;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
@@ -45,7 +46,7 @@
         * This value controls distance scaling when converting from Cytoscape
         * coordinates (such as from Ding) to the renderer's 3D coordinates
         */
-       private float distanceScale = 180.0f; 
+       private float distanceScale = GraphicsConstants.DEFAULT_DISTANCE_SCALE; 
 
        private float verticalFov = 45.0f;
        

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
 2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/CameraInputHandler.java
 2012-03-28 18:42:45 UTC (rev 28682)
@@ -1,8 +1,13 @@
 package org.cytoscape.paperwing.internal.input;
 
 import java.awt.event.KeyEvent;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Set;
 
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTableUtil;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.data.GraphicsSelectionData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
@@ -35,7 +40,7 @@
        
        private void processCameraZoom(MouseMonitor mouse, GraphicsData 
graphicsData) {
                SimpleCamera camera = graphicsData.getCamera();
-               Set<Integer> selectedNodeIndices = 
graphicsData.getSelectionData().getSelectedNodeIndices();
+               
                GraphicsSelectionData selectionData = 
graphicsData.getSelectionData();
                CyNetworkView networkView = graphicsData.getNetworkView();
                
@@ -44,9 +49,15 @@
 //                     camera.zoomOut((double) mouse.dWheel());
                        camera.moveForwardQuickly(-mouse.dWheel());
                        
-                       if (!selectedNodeIndices.isEmpty()) {
-                               // TODO: Check if this is a suitable place to 
put this, as
-                               // it helps to make node dragging smoother
+                       List<CyNode> selectedNodes = 
CyTableUtil.getNodesInState(networkView.getModel(), "selected", true);
+                       
+                       if (!selectedNodes.isEmpty()) {
+                               Set<Integer> selectedNodeIndices = new 
HashSet<Integer>();
+                               
+                               for (CyNode node : selectedNodes) {
+                                       
selectedNodeIndices.add(node.getIndex());
+                               }
+                               
                                Vector3 averagePosition = 
NetworkToolkit.findCenter(selectedNodeIndices, networkView, 
graphicsData.getDistanceScale());
                                
selectionData.setSelectProjectionDistance(averagePosition.distance(camera.getPosition()));
                        }
@@ -151,7 +162,8 @@
                
                // Reset camera
                if (held.contains(KeyEvent.VK_C)) {
-                       graphicsData.setCamera(new SimpleCamera());
+                       graphicsData.getCamera().set(new SimpleCamera());
+                       graphicsData.getNetworkView().updateView();
                }
        }
        

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DragMovementInputHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DragMovementInputHandler.java
   2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/DragMovementInputHandler.java
   2012-03-28 18:42:45 UTC (rev 28682)
@@ -41,8 +41,6 @@
                        selectedNodeViews.add(networkView.getNodeView(node));
                }
                
-               System.out.println("Selected node count: " + 
selectedNodes.size() + ", " + selectedNodeViews.size());
-               
                if (selectedNodeViews.isEmpty()) {
                        return;
                }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/KeyboardMonitor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/KeyboardMonitor.java
    2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/KeyboardMonitor.java
    2012-03-28 18:42:45 UTC (rev 28682)
@@ -101,7 +101,6 @@
 
        @Override
        public void focusGained(FocusEvent event) {
-               
        }
 
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MouseMonitor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MouseMonitor.java
       2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/MouseMonitor.java
       2012-03-28 18:42:45 UTC (rev 28682)
@@ -195,9 +195,9 @@
        }
 
        @Override
-       public void focusGained(FocusEvent event) {
+       public void focusGained(FocusEvent event) {     
        }
-
+       
        @Override
        public void focusLost(FocusEvent event) {
                // Release all keys
@@ -206,6 +206,4 @@
                ignoreNext = true;
                hasNew = true;
        }
-       
-
 }

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-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
  2012-03-28 18:42:45 UTC (rev 28682)
@@ -2,11 +2,13 @@
 
 import java.awt.event.KeyEvent;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyEdge.Type;
 import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTableUtil;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.tools.GeometryToolkit;
@@ -78,10 +80,10 @@
        }
        
        private static void processCreateEdge(Set<Integer> pressed, 
GraphicsData graphicsData) {
-               
-               Set<Integer> selectedNodeIndices = 
graphicsData.getSelectionData().getSelectedNodeIndices();
                CyNetworkView networkView = graphicsData.getNetworkView();
                
+               List<CyNode> selectedNodes = 
CyTableUtil.getNodesInState(networkView.getModel(), "selected", true);
+               
                // Create edges between nodes
                if (pressed.contains(KeyEvent.VK_J)) {
                        CyNode hoverNode = networkView.getModel().getNode(
@@ -89,9 +91,9 @@
 
                        if (hoverNode != null) {
 
-                               for (Integer index : selectedNodeIndices) {
+                               for (CyNode node : selectedNodes) {
                                        networkView.getModel().addEdge(
-                                                       
networkView.getModel().getNode(index),
+                                                       node,
                                                        hoverNode, false);
 
                                }
@@ -108,39 +110,26 @@
                Set<Integer> selectedEdgeIndices = 
graphicsData.getSelectionData().getSelectedEdgeIndices();
                CyNetworkView networkView = graphicsData.getNetworkView();
                
+               List<CyNode> selectedNodes = 
CyTableUtil.getNodesInState(networkView.getModel(), "selected", true);
+               List<CyEdge> selectedEdges = 
CyTableUtil.getEdgesInState(networkView.getModel(), "selected", true);
+               
                // Delete selected edges/nodes
                if (pressed.contains(KeyEvent.VK_DELETE)) {
                        Set<CyEdge> edgesToBeRemoved = new 
LinkedHashSet<CyEdge>();
                        Set<CyNode> nodesToBeRemoved = new 
LinkedHashSet<CyNode>();
                        
-                       // Remove nodes
-                       CyNode nodeToBeRemoved;
-                       
-                       for (Integer index : selectedNodeIndices) {
-                               nodeToBeRemoved = 
networkView.getModel().getNode(index);
-                               
-                               if (nodeToBeRemoved != null ) {
-                                       nodesToBeRemoved.add(nodeToBeRemoved);
-                                       
-                                       // TODO: Check if use of Type.ANY for 
any edge is correct
-                                       // TODO: Check if this addAll method 
properly skips adding
-                                       // edges already in the 
edgesToBeRemovedList
-                                       
edgesToBeRemoved.addAll(networkView.getModel()
-                                                       
.getAdjacentEdgeList(nodeToBeRemoved,
-                                                                       
Type.ANY));
-                               }
-                               
+                       // Prepare to remove nodes
+                       for (CyNode node : selectedNodes) {
+
+                               nodesToBeRemoved.add(node);
+                               edgesToBeRemoved.addAll(networkView.getModel()
+                                               .getAdjacentEdgeList(node,
+                                                               Type.ANY));
                        }
 
-                       // Remove edges
-                       CyEdge edgeToBeRemoved;
-                       
-                       for (Integer index : selectedEdgeIndices) {
-                               edgeToBeRemoved = 
networkView.getModel().getEdge(index);
-                               
-                               if (edgeToBeRemoved != null) {
-                                       edgesToBeRemoved.add(edgeToBeRemoved);
-                               }
+                       // Prepare to remove edges
+                       for (CyEdge edge : selectedEdges) {
+                               edgesToBeRemoved.add(edge);
                        }
                        
                        // Remove the node and edge entries from the CyTable

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/SelectionInputHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/SelectionInputHandler.java
      2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/SelectionInputHandler.java
      2012-03-28 18:42:45 UTC (rev 28682)
@@ -2,6 +2,7 @@
 
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseEvent;
+import java.util.List;
 import java.util.Set;
 
 import org.cytoscape.model.CyEdge;
@@ -9,6 +10,7 @@
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyRow;
 import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableUtil;
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.data.GraphicsSelectionData;
 import org.cytoscape.paperwing.internal.layouts.SphericalLayoutAlgorithmTask;
@@ -27,7 +29,7 @@
                GraphicsSelectionData selectionData = 
graphicsData.getSelectionData();
                
                //TODO: Check whether to have this method here or in 
MainCytoscapeDataProcessor
-               processClearToBeDeselected(selectionData);
+               // processClearToBeDeselected(selectionData);
                
                processDeselectOther(keys, mouse, graphicsData);
                processSingleSelection(keys, mouse, graphicsData);
@@ -44,6 +46,7 @@
        // Performs single selection, and deselection of previously selected 
objects
        private void processSingleSelection(KeyboardMonitor keys,
                        MouseMonitor mouse, GraphicsData graphicsData) {
+               CyNetworkView networkView = graphicsData.getNetworkView();
                int newHoverNodeIndex = 
graphicsData.getPickingData().getClosestPickedNodeIndex();
                int newHoverEdgeIndex = 
graphicsData.getPickingData().getClosestPickedEdgeIndex();
                
@@ -52,13 +55,6 @@
                selectionData.setHoverNodeIndex(newHoverNodeIndex);
                selectionData.setHoverEdgeIndex(newHoverEdgeIndex);
                
-               Set<Integer> selectedNodeIndices = 
selectionData.getSelectedNodeIndices();
-               Set<Integer> selectedEdgeIndices = 
selectionData.getSelectedEdgeIndices();
-       
-               // These are needed to keep track of to-be removed objects for 
faster Cytoscape data processing
-               Set<Integer> toBeDeselectedNodeIndices = 
selectionData.getToBeDeselectedNodeIndices();
-               Set<Integer> toBeDeselectedEdgeIndices = 
selectionData.getToBeDeselectedEdgeIndices();
-               
                if (!selectionData.isDragSelectMode()
                                && 
!keys.getHeld().contains(KeyEvent.VK_CONTROL)) {
                                
@@ -66,29 +62,22 @@
                                
                                if (newHoverNodeIndex != NO_INDEX) {
                                        
-                                       if 
(selectedNodeIndices.contains(newHoverNodeIndex)) {
-                                               
selectedNodeIndices.remove(newHoverNodeIndex);
-                                               
toBeDeselectedNodeIndices.add(newHoverNodeIndex);
-                                               
+                                       if 
(NetworkToolkit.checkNodeSelected(newHoverNodeIndex, networkView)) {
+                                               // Deselect the node if it was 
already selected
+                                               
NetworkToolkit.setNodeSelected(newHoverNodeIndex, networkView, false);
                                        } else {
-                                               
selectedNodeIndices.add(newHoverNodeIndex);
-                                               
-                                               // Debug: Find size of biggest 
clique containing this node
-                                               
-                                               /*
-                                               System.out.println("Size of 
clique: " + SphericalLayoutAlgorithmTask.findCliques(
-                                                               
graphicsData.getNetworkView().getModel()).get(
-                                                                               
graphicsData.getNetworkView().getModel().getNode(newHoverNodeIndex)).size());
-                                               */
+                                               // Select the node if it was 
not selected
+                                               
NetworkToolkit.setNodeSelected(newHoverNodeIndex, networkView, true);
                                        }
                                        
                                } else if (newHoverEdgeIndex != NO_INDEX) {
                
-                                       if 
(selectedEdgeIndices.contains(newHoverEdgeIndex)) {
-                                               
selectedEdgeIndices.remove(newHoverEdgeIndex);
-                                               
toBeDeselectedEdgeIndices.add(newHoverEdgeIndex);
+                                       if 
(NetworkToolkit.checkEdgeSelected(newHoverEdgeIndex, networkView)) {
+                                               // Deselect the edge if it was 
already selected
+                                               
NetworkToolkit.setEdgeSelected(newHoverEdgeIndex, networkView, false);
                                        } else {
-                                               
selectedEdgeIndices.add(newHoverEdgeIndex);
+                                               // Select the edge if it was 
not selected
+                                               
NetworkToolkit.setEdgeSelected(newHoverEdgeIndex, networkView, true);
                                        }
                                }
                        }
@@ -98,24 +87,25 @@
        private void processDeselectOther(KeyboardMonitor keys, MouseMonitor 
mouse,
                        GraphicsData graphicsData) {
                
+               CyNetworkView networkView = graphicsData.getNetworkView();
                GraphicsSelectionData selectionData = 
graphicsData.getSelectionData();
-               
-               Set<Integer> selectedNodeIndices = 
selectionData.getSelectedNodeIndices();
-               Set<Integer> selectedEdgeIndices = 
selectionData.getSelectedEdgeIndices();
-               
+
                if (mouse.getPressed().contains(MouseEvent.BUTTON1)) { 
                        if (!selectionData.isDragSelectMode() 
                                        && 
!keys.getHeld().contains(KeyEvent.VK_SHIFT)
                                        && 
!keys.getHeld().contains(KeyEvent.VK_CONTROL)) {
                                        
-                                       //&& 
graphicsData.getPickingData().getClosestPickedNodeIndex() == NO_INDEX
-                                       //&& 
graphicsData.getPickingData().getClosestPickedEdgeIndex() == NO_INDEX) {
-                               
-                               
selectionData.getToBeDeselectedNodeIndices().addAll(selectedNodeIndices);
-                               
selectionData.getToBeDeselectedEdgeIndices().addAll(selectedEdgeIndices);
-                               
-                               selectedNodeIndices.clear();
-                               selectedEdgeIndices.clear();
+                               // Deselect currently selected nodes
+                               List<CyNode> selectedNodes = 
CyTableUtil.getNodesInState(networkView.getModel(), "selected", true);
+                               for (CyNode node : selectedNodes) {
+                                       
NetworkToolkit.setNodeSelected(node.getIndex(), networkView, false);
+                               }
+
+                               // Deselect currently selected edges
+                               List<CyEdge> selectedEdges = 
CyTableUtil.getEdgesInState(networkView.getModel(), "selected", true);
+                               for (CyEdge edge : selectedEdges) {
+                                       
NetworkToolkit.setEdgeSelected(edge.getIndex(), networkView, false);
+                               }
                        }
                }
                
@@ -126,6 +116,7 @@
                        GraphicsData graphicsData) {
                
                GraphicsSelectionData selectionData = 
graphicsData.getSelectionData();
+               CyNetworkView networkView = graphicsData.getNetworkView();
                
                if (!keys.getHeld().contains(KeyEvent.VK_CONTROL)) {
                
@@ -156,10 +147,20 @@
                                selectionData.setDragSelectMode(false);
                                selectionData.setSelectTopLeftFound(false);
                                
+                               
+                               for (Integer index : 
graphicsData.getPickingData().getPickedNodeIndices()) {
+                                       NetworkToolkit.setNodeSelected(index, 
networkView, true);
+                               }
+                               
+                               for (Integer index : 
graphicsData.getPickingData().getPickedEdgeIndices()) {
+                                       NetworkToolkit.setEdgeSelected(index, 
networkView, true);
+                               }
+                               
+                               /*
                                
selectionData.getSelectedNodeIndices().addAll(graphicsData.getPickingData().getPickedNodeIndices());
                                
selectionData.getSelectedEdgeIndices().addAll(graphicsData.getPickingData().getPickedEdgeIndices());
+                               */
                                
-                               
                        }
                }
        }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
   2012-03-28 17:53:47 UTC (rev 28681)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodesProcedure.java
   2012-03-28 18:42:45 UTC (rev 28682)
@@ -143,9 +143,9 @@
                if 
(nodeView.getVisualProperty(BasicVisualLexicon.NODE_SELECTED)) {
                        
                        // Make selected nodes appear greener
-                       color.multiplyRed(0.7, 0, 0.7);
+                       color.multiplyRed(0.7, 0, 0.3);
                        color.multiplyGreen(1.5, 0.5, 1);
-                       color.multiplyBlue(0.7, 0, 0.7);
+                       color.multiplyBlue(0.7, 0, 0.3);
                } else if (nodeView.getModel().getIndex() == 
graphicsData.getSelectionData().getHoverNodeIndex()) {
                        // Make hovered nodes appear bluer
                        color.multiplyRed(0.7, 0, 0.7);

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