Author: ghuck
Date: 2009-07-31 10:04:43 -0700 (Fri, 31 Jul 2009)
New Revision: 17635

Modified:
   csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java
Log:
Added sopport for laying out only selected nodes.



Modified: csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java
===================================================================
--- csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java     2009-07-31 
15:08:34 UTC (rev 17634)
+++ csplugins/trunk/soc/ghuck/plugin/src/ForceDirected.java     2009-07-31 
17:04:43 UTC (rev 17635)
@@ -40,6 +40,7 @@
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
+import java.awt.Dimension;
 import java.awt.GridLayout;
 import java.awt.Rectangle;
 import java.util.Iterator;
@@ -101,7 +102,7 @@
      * This plugin supports laying out only selected nodes
      */
     public boolean supportsSelectedOnly() {
-               return false;
+               return true;
     }
 
     
@@ -120,7 +121,7 @@
 
        layoutProperties.add(new Tunable("CUDA_PATH", "CUDA instalation 
folder", Tunable.STRING , new String("/usr/local/cuda")));
        
-       layoutProperties.add(new Tunable("nodeSize", "Final node size", 
Tunable.DOUBLE , new Double(2.0)));
+       layoutProperties.add(new Tunable("nodeSize", "Final node size\n(0 for 
no change in size)", Tunable.DOUBLE , new Double(2.0)));
 
        // Initialize layout properties
        layoutProperties.initializeProperties();
@@ -238,7 +239,7 @@
        
     
     /**
-     * This function does the "heavy work", calling the native code
+     * This function does the "heavy work" of the layout process
      */
     public void layoutPartion (LayoutPartition part) {
 
@@ -258,6 +259,12 @@
        // Get node's list
        List<LayoutNode> nodeList = part.getNodeList();
 
+       // Figure out our starting point if we are only laying out selected 
nodes
+       Dimension initialLocation = null;
+       if (selectedOnly) {
+           initialLocation = part.getAverageLocation();
+       }
+
        // Allocate memory for storing graph edges information (to be used as 
arguments for JNI call)
        int[] AdjMatIndex = new int[numNodes + 1];
        int[] AdjMatVals  = new int[2 * numEdges];      
@@ -362,10 +369,6 @@
            }
        }
        catch (Exception exception){
-           /*String message4 = "Problem detected while loading Static 
Library\nCannot Produce Layout\n"
-                   + exception.getMessage();
-               JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message4);
-           */
        }
 
        // Check whether it has been canceled by the user
@@ -392,7 +395,7 @@
            return;
        
        // Update Node position
-       //part.resetNodes(); // reset the nodes so we get the new average 
location
+       part.resetNodes(); // reset the nodes so we get the new average location
 
        // Iterate over all nodes
        int currentNode = 0;
@@ -418,12 +421,29 @@
            part.moveNodeToLocation(node);
 
            // Change node's size
-           appearance.applyAppearance(node.getNodeView());
+           if (!node.isLocked() && nodeSize != 0.0)
+               appearance.applyAppearance(node.getNodeView());
 
            currentNode++;
        }
        
-       //return;
+       
+       // Not quite done, yet.  If we're only laying out selected nodes, we 
need
+       // to migrate the selected nodes back to their starting position
+       if (selectedOnly) {
+           double xDelta = 0.0;
+           double yDelta = 0.0;
+           Dimension finalLocation = part.getAverageLocation();
+           xDelta = finalLocation.getWidth() - initialLocation.getWidth();
+           yDelta = finalLocation.getHeight() - initialLocation.getHeight();
+           for (LayoutNode v: part.getNodeList()) {
+               if (!v.isLocked()) {
+                   v.decrement(xDelta, yDelta);
+                   part.moveNodeToLocation(v);
+               }
+           }
+       }
+
     }// layoutPartion(LayoutPartition part)
     
     


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