Author: pwang
Date: 2010-09-24 15:25:37 -0700 (Fri, 24 Sep 2010)
New Revision: 22052

Added:
   
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayoutTask.java
Modified:
   
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
Log:
Refactored

Modified: 
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
===================================================================
--- 
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
    2010-09-24 21:45:17 UTC (rev 22051)
+++ 
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
    2010-09-24 22:25:37 UTC (rev 22052)
@@ -1,8 +1,8 @@
 /* vim: set ts=2: */
 package csplugins.layout.algorithms.graphPartition;
 
-import static org.cytoscape.model.CyTableEntry.NODE;
 
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -13,20 +13,23 @@
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyTableManager;
 import org.cytoscape.view.layout.AbstractGraphPartition;
+import org.cytoscape.view.layout.AbstractLayout;
 import org.cytoscape.view.layout.LayoutNode;
 import org.cytoscape.view.layout.LayoutPartition;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.TunableValidator;
 import org.cytoscape.work.undo.UndoSupport;
 
 
 /**
  *
  */
-public class DegreeSortedCircleLayout extends AbstractGraphPartition {
+public class DegreeSortedCircleLayout extends AbstractLayout implements 
TunableValidator {
        
        private static final String DEGREE_ATTR_NAME = "degree";
-
        private CyTableManager tableMgr;
 
+
        /**
         * Creates a new DegreeSortedCircleLayout object.
         */
@@ -35,6 +38,16 @@
                this.tableMgr = tableMgr;
        }
 
+       // TODO
+       public boolean tunablesAreValid(final Appendable errMsg) {
+               return true;
+       }
+       
+       public TaskIterator getTaskIterator() {
+               return new TaskIterator(new 
DegreeSortedCircleLayoutTask(networkView, getName(), selectedOnly, staticNodes,
+                               DEGREE_ATTR_NAME, tableMgr));
+       }
+       
        /**
         *  DOCUMENT ME!
         *
@@ -52,69 +65,4 @@
        public String getName() {
                return "degree-circle";
        }
-
-       /**
-        *  DOCUMENT ME!
-        *
-        * @param partition DOCUMENT ME!
-        */
-       public void layoutPartion(LayoutPartition partition) {
-               // Create attribute
-               if(tableMgr.getTableMap(NODE, 
network).get(CyNetwork.DEFAULT_ATTRS).getUniqueColumns().contains(DEGREE_ATTR_NAME)
 == false) {
-                       tableMgr.getTableMap(NODE, 
network).get(CyNetwork.DEFAULT_ATTRS).createColumn(DEGREE_ATTR_NAME,
-                               Double.class, false);
-               }
-
-    // just add the unlocked nodes
-    List<LayoutNode> nodes = new ArrayList<LayoutNode>();
-    for ( LayoutNode ln : partition.getNodeList() ) {
-      if ( !ln.isLocked() ) {
-        nodes.add(ln);
-      }
-    }
-       
-               if (canceled)
-                       return;
-
-               // sort the Nodes based on the degree
-               Collections.sort(nodes,
-                           new Comparator<LayoutNode>() {
-                               public int compare(LayoutNode o1, LayoutNode 
o2) {
-                                       final CyNode node1 = o1.getNode();
-                                       final CyNode node2 = o2.getNode();
-                                       // FIXME: should allow parametrization 
of edge type? (expose as tunable)
-                                       final int d1 = 
network.getAdjacentEdgeList(node1, CyEdge.Type.ANY).size();
-                                       final int d2 = 
network.getAdjacentEdgeList(node2, CyEdge.Type.ANY).size();
-                                       
-                                       // Create Degree Attribute
-                                       node1.attrs().set(DEGREE_ATTR_NAME, 
(double)d1);
-                                       node2.attrs().set(DEGREE_ATTR_NAME, 
(double)d2);
-                                       
-                                       return (d2 - d1);
-                               }
-
-                               public boolean equals(Object o) {
-                                       return false;
-                               }
-                       });
-
-               if (canceled)
-                       return;
-
-               // place each Node in a circle
-               int r = 100 * (int) Math.sqrt(nodes.size());
-               double phi = (2 * Math.PI) / nodes.size();
-               partition.resetNodes(); // We want to figure out our mins & 
maxes anew
-
-               for (int i = 0; i < nodes.size(); i++) {
-                       LayoutNode node = nodes.get(i);
-                       node.setX(r + (r * Math.sin(i * phi)));
-                       node.setY(r + (r * Math.cos(i * phi)));
-                       partition.moveNodeToLocation(node);
-               }
-       }
-       
-       public void construct() {
-               super.construct();
-       }
 }

Added: 
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayoutTask.java
===================================================================
--- 
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayoutTask.java
                                (rev 0)
+++ 
core3/layout-cytoscape-impl/trunk/src/main/java/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayoutTask.java
        2010-09-24 22:25:37 UTC (rev 22052)
@@ -0,0 +1,106 @@
+package csplugins.layout.algorithms.graphPartition;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.CyTableManager;
+import org.cytoscape.view.layout.AbstractGraphPartition;
+import org.cytoscape.view.layout.LayoutNode;
+import org.cytoscape.view.layout.LayoutPartition;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+import org.cytoscape.model.CyTableEntry;
+
+public class DegreeSortedCircleLayoutTask extends AbstractGraphPartition {
+
+       private String DEGREE_ATTR_NAME = "degree";
+       private CyTableManager tableMgr;
+       CyNetwork network;
+
+       /**
+        * Creates a new GridNodeLayout object.
+        */
+       public DegreeSortedCircleLayoutTask(final CyNetworkView networkView, 
final String name,
+                                 final boolean selectedOnly, final 
Set<View<CyNode>> staticNodes,
+                                 final String DEGREE_ATTR_NAME, CyTableManager 
tableMgr)
+       {
+               super(networkView, name, selectedOnly, staticNodes);
+
+               this.DEGREE_ATTR_NAME= DEGREE_ATTR_NAME;
+               this.tableMgr = tableMgr;
+               this.network = networkView.getModel();
+       }
+
+
+       /**
+        *  DOCUMENT ME!
+        *
+        * @param partition DOCUMENT ME!
+        */
+       public void layoutPartion(LayoutPartition partition) {
+               // Create attribute
+               if(tableMgr.getTableMap(CyTableEntry.NODE, 
network).get(CyNetwork.DEFAULT_ATTRS).getUniqueColumns().contains(DEGREE_ATTR_NAME)
 == false) {
+                       tableMgr.getTableMap(CyTableEntry.NODE, 
network).get(CyNetwork.DEFAULT_ATTRS).createColumn(DEGREE_ATTR_NAME,
+                               Double.class, false);
+               }
+
+    // just add the unlocked nodes
+    List<LayoutNode> nodes = new ArrayList<LayoutNode>();
+    for ( LayoutNode ln : partition.getNodeList() ) {
+      if ( !ln.isLocked() ) {
+        nodes.add(ln);
+      }
+    }
+       
+               if (cancelled)
+                       return;
+
+               // sort the Nodes based on the degree
+               Collections.sort(nodes,
+                           new Comparator<LayoutNode>() {
+                               public int compare(LayoutNode o1, LayoutNode 
o2) {
+                                       final CyNode node1 = o1.getNode();
+                                       final CyNode node2 = o2.getNode();
+                                       // FIXME: should allow parametrization 
of edge type? (expose as tunable)
+                                       final int d1 = 
network.getAdjacentEdgeList(node1, CyEdge.Type.ANY).size();
+                                       final int d2 = 
network.getAdjacentEdgeList(node2, CyEdge.Type.ANY).size();
+                                       
+                                       // Create Degree Attribute
+                                       node1.attrs().set(DEGREE_ATTR_NAME, 
(double)d1);
+                                       node2.attrs().set(DEGREE_ATTR_NAME, 
(double)d2);
+                                       
+                                       return (d2 - d1);
+                               }
+
+                               public boolean equals(Object o) {
+                                       return false;
+                               }
+                       });
+
+               if (cancelled)
+                       return;
+
+               // place each Node in a circle
+               int r = 100 * (int) Math.sqrt(nodes.size());
+               double phi = (2 * Math.PI) / nodes.size();
+               partition.resetNodes(); // We want to figure out our mins & 
maxes anew
+
+               for (int i = 0; i < nodes.size(); i++) {
+                       LayoutNode node = nodes.get(i);
+                       node.setX(r + (r * Math.sin(i * phi)));
+                       node.setY(r + (r * Math.cos(i * phi)));
+                       partition.moveNodeToLocation(node);
+               }
+       }
+       
+       //public void construct() {
+       //      super.construct();
+       //}
+
+}

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