Author: mes
Date: 2011-04-29 15:43:31 -0700 (Fri, 29 Apr 2011)
New Revision: 24861

Added:
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
Removed:
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutAdapter.java
Modified:
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractGraphPartition.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractLayout.java
   core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/CyLayouts.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/EdgeWeighter.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutEdge.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutNode.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutTask.java
   
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
Log:
initial layout api cleanup

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractGraphPartition.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractGraphPartition.java
  2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractGraphPartition.java
  2011-04-29 22:43:31 UTC (rev 24861)
@@ -34,8 +34,7 @@
         */
        public AbstractGraphPartition(final CyNetworkView networkView, final 
String name,
                                      final boolean singlePartition,
-                                     final boolean selectedOnly, final 
Set<View<CyNode>> staticNodes)
-       {
+                                     final boolean selectedOnly, final 
Set<View<CyNode>> staticNodes) {
                super(networkView, name, selectedOnly, staticNodes);
                this.singlePartition = singlePartition;
        }
@@ -113,7 +112,7 @@
                        // We still use the partition abstraction, even if we're
                        // not partitioning.  This makes the code further down
                        // much cleaner
-                       LayoutPartition partition = new 
LayoutPartition(network, networkView, selectedOnly, edgeWeighter);
+                       LayoutPartition partition = new 
LayoutPartition(networkView, selectedOnly, edgeWeighter);
                        partition.setTaskMonitor(taskMonitor);
                        partitionList = new ArrayList(1);
                        partitionList.add(partition);
@@ -126,11 +125,11 @@
                                        unlockedNodes.add(node);
                                }
                        }
-                       LayoutPartition partition = new 
LayoutPartition(network, networkView, unlockedNodes, edgeWeighter);
+                       LayoutPartition partition = new 
LayoutPartition(networkView, unlockedNodes, edgeWeighter);
                        partitionList = new ArrayList(1);
                        partitionList.add(partition);
                } else {
-                       partitionList = LayoutPartition.partition(network, 
networkView, false, edgeWeighter);
+                       partitionList = PartitionUtil.partition(networkView, 
false, edgeWeighter);
                }
 
                total_nodes = network.getNodeCount();

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractLayout.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractLayout.java
  2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/AbstractLayout.java
  2011-04-29 22:43:31 UTC (rev 24861)
@@ -72,12 +72,17 @@
        protected String propertyPrefix = "abstract";
        protected UndoSupport undo;
 
+       private final String humanName;
+       private final String computerName;
+
        /**
         * The Constructor is null
         */
-       public AbstractLayout(UndoSupport undo) {
+       public AbstractLayout(UndoSupport undo, String computerName, String 
humanName) {
                this.staticNodes = new HashSet<View<CyNode>>();
                this.undo = undo;
+               this.computerName = computerName;
+               this.humanName = humanName;
        }
 
        @Override
@@ -89,13 +94,17 @@
         * getName is used to construct property strings
         * for this layout.
         */
-       public abstract String getName();
+       public String getName() {
+               return computerName;
+       }
 
        /**
         * toString is used to get the user-visible name
         * of the layout
         */
-       public abstract String toString();
+       public String toString() {
+               return humanName;
+       }
 
        /**
         * These methods should be overridden
@@ -193,7 +202,8 @@
        protected void initialize_local() {
        }
 
-       /** Descendents need to call this if they intend to use the 
"staticNodes" field.
+       /** 
+        * Descendents need to call this if they intend to use the 
"staticNodes" field.
         */
        public final void initStaticNodes() {
                staticNodes.clear();
@@ -204,6 +214,5 @@
                        if (!selectedNodes.contains(nodeView.getModel()))
                                staticNodes.add(nodeView);
                }
-                       
        }
 }

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/CyLayouts.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/CyLayouts.java   
    2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/CyLayouts.java   
    2011-04-29 22:43:31 UTC (rev 24861)
@@ -42,10 +42,6 @@
        String PREF_MENU_DEFAULT = "Cytoscape Layouts";
        String DEFAULT_LAYOUT_NAME = "grid";
 
-       void addLayout(CyLayoutAlgorithm layout, Map props);
-
-       void removeLayout(CyLayoutAlgorithm layout, Map props);
-
        CyLayoutAlgorithm getLayout(String name);
 
        Collection<CyLayoutAlgorithm> getAllLayouts(); 

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/EdgeWeighter.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/EdgeWeighter.java
    2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/EdgeWeighter.java
    2011-04-29 22:43:31 UTC (rev 24861)
@@ -51,41 +51,41 @@
  * The EdgeWeighter class.  This class is used as a container for information
  * about how to interpret weights in an weighted layout.
  */
-public class EdgeWeighter {
+public final class EdgeWeighter {
+
        @Tunable(description="How to interpret weight values", groups={"Edge 
Weight Settings"})
        public WeightTypes type = WeightTypes.GUESS;
+
        @Tunable(description="The minimum edge weight to consider", 
groups={"Edge Weight Settings"})
        public double minWeightCutoff = 0;
+
        @Tunable(description="The maximum edge weight to consider", 
groups={"Edge Weight Settings"})
        public double maxWeightCutoff = Double.MAX_VALUE;
-       final static double EPSILON = .001;
 
+       @Tunable(description="The edge attribute that contains the weights", 
groups={"Edge Weight Settings"})
+       public String weightAttribute = null;
+
+
+       private final static double EPSILON = .001;
+
        // Default normalization bounds
-       final static double LOWER_BOUND = .1f;
-       final static double UPPER_BOUND = .9f;
+       private final static double LOWER_BOUND = .1f;
+       private final static double UPPER_BOUND = .9f;
 
-       double lowerBounds = LOWER_BOUND;
-       double upperBounds = UPPER_BOUND;
+       private double lowerBounds = LOWER_BOUND;
+       private double upperBounds = UPPER_BOUND;
 
-       double maxWeight = -1000000;
-       double minWeight = 1000000;
-       double maxLogWeight = -1000000;
-       double minLogWeight = 1000000;
+       private double maxWeight = -1000000;
+       private double minWeight = 1000000;
+       private double maxLogWeight = -1000000;
+       private double minLogWeight = 1000000;
 
-       double logWeightCeiling = 1028;
-       boolean logOverflow = false;
+       private double logWeightCeiling = 1028;
+       private boolean logOverflow = false;
 
        // These are just here for efficiency reasons
-       double normalFactor = Double.MAX_VALUE;
+       private double normalFactor = Double.MAX_VALUE;
 
-       @Tunable(description="The edge attribute that contains the weights", 
groups={"Edge Weight Settings"})
-       public String weightAttribute = null;
-
-       static WeightTypes[] weightChoices = {WeightTypes.GUESS,
-                                             WeightTypes.LOG,
-                                             WeightTypes.DISTANCE,
-                                             WeightTypes.WEIGHT};
-
        public void reset() {
                maxWeight = -1000000;
                minWeight = 1000000;
@@ -174,7 +174,7 @@
                                weight = normalize(edge.getWeight());
                        }
                        break;
-         case LOG:
+               case LOG:
                        // System.out.print("Log: ");
                        weight = edge.getLogWeight();
                        // System.out.print("Log weight = "+weight);
@@ -183,12 +183,12 @@
                        weight = logNormalize(weight);
                        // System.out.println(" normalized weight = "+weight);
                        break;
-         case DISTANCE:
+               case DISTANCE:
                        // System.out.println("Distance");
                        weight = edge.getWeight();
                        weight = (lowerBounds + upperBounds) - 
normalize(weight);
                        break;
-         case WEIGHT:
+               case WEIGHT:
                        // System.out.println("Weight");
                        weight = normalize(edge.getWeight());
                        break;

Deleted: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutAdapter.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutAdapter.java
   2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutAdapter.java
   2011-04-29 22:43:31 UTC (rev 24861)
@@ -1,155 +0,0 @@
-/*
-  File: LayoutAdapter.java
-
-  Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
-  This library is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published
-  by the Free Software Foundation; either version 2.1 of the License, or
-  any later version.
-
-  This library is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
-  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
-  documentation provided hereunder is on an "as is" basis, and the
-  Institute for Systems Biology and the Whitehead Institute
-  have no obligations to provide maintenance, support,
-  updates, enhancements or modifications.  In no event shall the
-  Institute for Systems Biology and the Whitehead Institute
-  be liable to any party for direct, indirect, special,
-  incidental or consequential damages, including lost profits, arising
-  out of the use of this software and its documentation, even if the
-  Institute for Systems Biology and the Whitehead Institute
-  have been advised of the possibility of such damage.  See
-  the GNU Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with this library; if not, write to the Free Software Foundation,
-  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package org.cytoscape.view.layout;
-
-
-import org.cytoscape.work.TaskMonitor;
-import org.cytoscape.view.model.CyNetworkView;
-import org.cytoscape.view.model.View;
-import org.cytoscape.model.CyNode;
-
-import javax.swing.*;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
-
-
-/**
- * LayoutAdapter provides a *very* minimal interface to implement a layout
- * algorithm.  It is meant to be used by graph readers and plugins that provide
- * their own node placement and whose layout approach should not be made
- * available outside of the reader or plugin's context.
- */
-abstract public class LayoutAdapter implements CyLayoutAlgorithm {
-
-       /**
-        * This method performs the layout on the current network.
-        *
-        * @param networkView the CyNetworkView on which to perform the layout
-        */
-       public void doLayout(CyNetworkView networkView) {
-               doLayout(networkView, null);
-       }
-
-       /**
-        * This method performs the layout on the current network, but assumes
-        * that the layout is part of an existing monitored task
-        *
-        * @param networkView the CyNetworkView on which to perform the layout
-        * @param monitor the task monitor to use
-        */
-       public abstract void doLayout(CyNetworkView networkView, TaskMonitor 
monitor);
-
-       /**
-        * Get the name of this layout.
-        *
-        * @return String representing the name of the layout.
-        */
-       public String getName() {return "LayoutAdaptor";}
-
-       /**
-        * Tests to see if this layout supports doing a layout on a subset of 
the
-        * nodes in this network view.
-        *
-        * @return true if layout supports layouts on a subset of the nodes
-        */
-       public boolean supportsSelectedOnly() {return false;}
-
-       /**
-        * Sets the "selectedOnly" flag
-        *
-        * @param selectedOnly boolean value that tells the layout algorithm 
whether to
-        * only layout the selected nodes
-        */
-       public void setSelectedOnly(boolean selectedOnly) {}
-
-       /**
-        * Tests to see if this layout supports doing a layout based on node 
attributes.
-        *
-        * @return byte array of allowable attribute types or "null" if not 
supported.  If the
-        *              first type is "-1", all types are supported
-        */
-       public Set<Class<?>> supportsNodeAttributes() { return new 
HashSet<Class<?>>(); }
-
-       /**
-        * Tests to see if this layout supports doing a layout based on edge 
attributes.
-        *
-        * @return type array of allowable attribute types or "null" if not 
supported.  If the
-        *              first type is "-1", all types are supported
-        */
-       public Set<Class<?>> supportsEdgeAttributes() { return new 
HashSet<Class<?>>(); }
-
-       /**
-        * Sets the attribute to use for node- or edge- based attribute layouts
-        *
-        * @param attributeName String with the name of the attribute to use
-        */
-       public void setLayoutAttribute(String attributeName) {}
-
-       /**
-        * This returns a (possibly empty) List of Strings that is used for
-        * the attribute list in the menu for attribute-based layouts.  This
-        * allows layout algorithms to provide "special" attributes.  For 
example,
-        * a force directed layout might want to set the list to 
["(unweighted)"]
-        * to allow the user to perform an unweighted layout.  Note that this 
value
-        * will be set using setLayoutAttribute() just like other attributes, 
so the
-        * layout algorithm will need to check for it.
-        *
-        * @return List of Strings
-        */
-       public List<String> getInitialAttributeList() {return new 
ArrayList<String>();}
-
-       /**
-        *  DOCUMENT ME!
-        *
-        * @param nodes DOCUMENT ME!
-        */
-       public void lockNodes(View<CyNode>[] nodes) {}
-
-       /**
-        *  DOCUMENT ME!
-        *
-        * @param v DOCUMENT ME!
-        */
-       public void lockNode(View<CyNode> v) {}
-
-       /**
-        *  DOCUMENT ME!
-        *
-        * @param v DOCUMENT ME!
-        */
-       public void unlockNode(View<CyNode> v) {}
-
-       /**
-        *  DOCUMENT ME!
-        */
-       public void unlockAllNodes() {}
-}

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutEdge.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutEdge.java  
    2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutEdge.java  
    2011-04-29 22:43:31 UTC (rev 24861)
@@ -40,7 +40,7 @@
  * to information about the weights associated with edges, and pointers to the
  * LayoutNodes that are joined by this edge.
  */
-public class LayoutEdge {
+public final class LayoutEdge {
        // instance variables
        private LayoutNode v1;
        private LayoutNode v2;
@@ -49,12 +49,6 @@
        private CyEdge edge;
 
        /**
-        * An empty constructor
-        */
-       public LayoutEdge() {
-       }
-
-       /**
         * Create a LayoutEdge that will contain information about this edge.
         * Additional information must be filled in later.
         *

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutNode.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutNode.java  
    2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutNode.java  
    2011-04-29 22:43:31 UTC (rev 24861)
@@ -47,9 +47,8 @@
  * the methods of this class are wrappers for Node or View<CyNode> methods, and
  * these are often wrapped by LayoutPartition methods.
  */
-public class LayoutNode {
+public final class LayoutNode {
        // static (class) variables
-       private static int lockedNodes = 0;
        static final double EPSILON = 0.0000001D;
 
        // instance variables
@@ -66,12 +65,6 @@
        private ArrayList<LayoutNode> neighbors = null;
 
        /**
-          * Empty constructor
-          */
-       public LayoutNode() {
-       }
-
-       /**
         * The main constructor for a LayoutNode.
         *
         * @param nodeView The View<CyNode> of this node
@@ -197,7 +190,6 @@
         */
        public void lock() {
                this.isLocked = true;
-               lockedNodes += 1;
        }
 
        /**
@@ -207,7 +199,6 @@
         */
        public void unLock() {
                this.isLocked = false;
-               lockedNodes -= 1;
        }
 
        /**
@@ -407,16 +398,4 @@
 
                return ret;
        }
-
-       /**
-        * Returns the number of locked nodes.  This is a static that is 
incremented whenever
-        * lock() is called and decremented whenever unlock() is called.  It is 
useful for some
-        * algorithms that only want to get the number of unlocked nodes for 
the purposes of their
-        * layout loops.
-        *
-        * @return        the number of unlocked nodes.
-        */
-       public static int lockedNodeCount() {
-               return lockedNodes;
-       }
 }

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
 2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
 2011-04-29 22:43:31 UTC (rev 24861)
@@ -65,12 +65,10 @@
  * @author <a href="mailto:[email protected]";>Scooter Morris</a>
  * @version 0.9
  */
-public class LayoutPartition {
+public final class LayoutPartition {
        private ArrayList<LayoutNode> nodeList;
        private ArrayList<LayoutEdge> edgeList;
-       private static HashMap<CyNode, LayoutNode> nodeToLayoutNode = null;
-       private static Map<Integer,Integer> nodesSeenMap = null;
-       private static Map<Integer,Integer> edgesSeenMap = null;
+       private HashMap<CyNode, LayoutNode> nodeToLayoutNode; 
        private int nodeIndex = 0;
        private int partitionNumber = 0;
        private EdgeWeighter edgeWeighter = null;
@@ -110,10 +108,8 @@
        public LayoutPartition(int nodeCount, int edgeCount) {
                nodeList = new ArrayList<LayoutNode>(nodeCount);
                edgeList = new ArrayList<LayoutEdge>(edgeCount);
+               nodeToLayoutNode = new HashMap<CyNode,LayoutNode>(nodeCount);
                partitionNumber = 1;
-
-               if (nodeToLayoutNode == null)
-                       nodeToLayoutNode = new 
HashMap<CyNode,LayoutNode>(nodeCount);
        }
 
        /**
@@ -125,9 +121,9 @@
         * @param nodeSet the nodes to be considered
         * @param edgeWeighter the weighter to use for edge weighting
         */
-       public LayoutPartition(CyNetwork network, CyNetworkView networkView, 
Collection<CyNode>nodeSet,
+       public LayoutPartition(CyNetworkView networkView, 
Collection<CyNode>nodeSet,
                               EdgeWeighter edgeWeighter) {
-               initialize(network,networkView,nodeSet,edgeWeighter);
+               initialize(networkView,nodeSet,edgeWeighter);
        }
 
 
@@ -140,30 +136,28 @@
         * @param selectedOnly if true, only include selected nodes in the 
partition
         * @param edgeWeighter the weighter to use for edge weighting
         */
-       public LayoutPartition(CyNetwork network, CyNetworkView networkView, 
boolean selectedOnly,
+       public LayoutPartition(CyNetworkView networkView, boolean selectedOnly,
                               EdgeWeighter edgeWeighter) {
                if (selectedOnly) {
-                       
initialize(network,networkView,CyTableUtil.getNodesInState(network,"selected",true),edgeWeighter);
+                       
initialize(networkView,CyTableUtil.getNodesInState(networkView.getModel(),"selected",true),edgeWeighter);
                } else {
-                       
initialize(network,networkView,network.getNodeList(),edgeWeighter);
+                       
initialize(networkView,networkView.getModel().getNodeList(),edgeWeighter);
                }
        }
 
-       protected void initialize(CyNetwork network, CyNetworkView networkView, 
Collection<CyNode>nodeSet,
+       private void initialize(CyNetworkView networkView, 
Collection<CyNode>nodeSet,
                                  EdgeWeighter edgeWeighter) {
 
                this.edgeWeighter = edgeWeighter;
 
                // Initialize
-               nodeList = new ArrayList<LayoutNode>(network.getNodeCount());
-               edgeList = new ArrayList<LayoutEdge>(network.getEdgeCount());
+               nodeList = new 
ArrayList<LayoutNode>(networkView.getModel().getNodeCount());
+               edgeList = new 
ArrayList<LayoutEdge>(networkView.getModel().getEdgeCount());
+               nodeToLayoutNode = new 
HashMap<CyNode,LayoutNode>(networkView.getModel().getNodeCount());
 
-               if (nodeToLayoutNode == null)
-                       nodeToLayoutNode = new 
HashMap<CyNode,LayoutNode>(network.getNodeCount());
-
                // Now, walk the iterators and fill in the values
-               nodeListInitialize(network, networkView, nodeSet);
-               edgeListInitialize(network, networkView);
+               nodeListInitialize(networkView, nodeSet);
+               edgeListInitialize(networkView);
                trimToSize();
                partitionNumber = 1;
        }
@@ -196,8 +190,6 @@
                } else {
                        
updateMinMax(nv.getVisualProperty(MinimalVisualLexicon.NODE_X_LOCATION),
                                                 
nv.getVisualProperty(MinimalVisualLexicon.NODE_Y_LOCATION));
-                       // this.width += Math.sqrt(nv.getWidth());
-                       // this.height += Math.sqrt(nv.getHeight());
                        this.width += 
nv.getVisualProperty(MinimalVisualLexicon.NODE_WIDTH); 
                        this.height += 
nv.getVisualProperty(MinimalVisualLexicon.NODE_HEIGHT);
                }
@@ -283,8 +275,8 @@
 
                        if (nodeToLayoutNode.containsKey(source) && 
nodeToLayoutNode.containsKey(target)) {
                                // Add the connecting nodes
-                               lEdge.addNodes((LayoutNode) 
nodeToLayoutNode.get(source),
-                                              (LayoutNode) 
nodeToLayoutNode.get(target));
+                               lEdge.addNodes(nodeToLayoutNode.get(source),
+                                              nodeToLayoutNode.get(target));
                        }
                }
        }
@@ -514,13 +506,13 @@
        /**
         * Private routines
         */
-       private void nodeListInitialize(CyNetwork network, CyNetworkView 
networkView,
+       private void nodeListInitialize(CyNetworkView networkView,
                                        Collection<CyNode> nodeSet) {
                int nodeIndex = 0;
-               this.nodeList = new 
ArrayList<LayoutNode>(network.getNodeCount());
+               this.nodeList = new 
ArrayList<LayoutNode>(networkView.getModel().getNodeCount());
 
                for (View<CyNode>nv: networkView.getNodeViews()){
-                       CyNode node = (CyNode) nv.getModel();
+                       CyNode node = nv.getModel();
 
                        if (!nodeSet.contains(node)) {
                                addNode(nv, true);
@@ -530,20 +522,20 @@
                }
        }
 
-       private void edgeListInitialize(CyNetwork network, CyNetworkView 
networkView) {
+       private void edgeListInitialize(CyNetworkView networkView) {
                for (View<CyEdge>ev: networkView.getEdgeViews()){
                        CyEdge edge = ev.getModel();
                        // Make sure we clean up after any previous layouts
                        //ev.clearBends(); // FIXME: this will mean some 
cleanup in VisualProperty, right?
 
-                       CyNode source = (CyNode) edge.getSource();
-                       CyNode target = (CyNode) edge.getTarget();
+                       CyNode source = edge.getSource();
+                       CyNode target = edge.getTarget();
 
                        if (source == target)
                                continue;
 
-                       LayoutNode v1 = (LayoutNode) 
nodeToLayoutNode.get(source);
-                       LayoutNode v2 = (LayoutNode) 
nodeToLayoutNode.get(target);
+                       LayoutNode v1 = nodeToLayoutNode.get(source);
+                       LayoutNode v2 = nodeToLayoutNode.get(target);
 
                        // Do we care about this edge?
                        if (v1.isLocked() && v2.isLocked())
@@ -556,9 +548,9 @@
        /**
         * Space saving convenience function to trim the internal arrays to fit 
the
         * contained data.  Useful to call this after a partition has been 
created
-        * and filled.  This is used by the static method 
LayoutPartition.partition
+        * and filled.  This is used by the static method 
PartitionUtil.partition()
         */
-       private void trimToSize() {
+       void trimToSize() {
                nodeList.trimToSize();
                edgeList.trimToSize();
        }
@@ -579,169 +571,4 @@
 
                // System.out.println("Updating "+newEdge);
        }
-
-       // Static routines
-
-       /**
-        * Partition the graph -- this builds the LayoutEdge and LayoutNode
-        * arrays as a byproduct.  The algorithm for this was taken from
-        * algorithms/graphPartition/SGraphPartition.java.
-        *
-        * @param network the GraphPerspective containing the graph
-        * @param networkView the CyNetworkView representing the graph
-        * @param selectedOnly only consider selected nodes
-        * @param edgeWeighter the weighter to use for edge weighting
-        * @return a List of LayoutPartitions
-        */
-       public static List<LayoutPartition> partition(CyNetwork network, 
CyNetworkView networkView,
-                                    boolean selectedOnly, EdgeWeighter 
edgeWeighter) {
-
-               if (selectedOnly) {
-                       return partition(network,networkView, 
CyTableUtil.getNodesInState(network,"selected",true),edgeWeighter);
-               }
-
-               return 
partition(network,networkView,network.getNodeList(),edgeWeighter);
-
-       }
-
-       /**
-        * Partition the graph -- this builds the LayoutEdge and LayoutNode
-        * arrays as a byproduct.  The algorithm for this was taken from
-        * algorithms/graphPartition/SGraphPartition.java.
-        *
-        * @param network the GraphPerspective containing the graph
-        * @param networkView the CyNetworkView representing the graph
-        * @param nodeSet the set of nodes to consider
-        * @param edgeWeighter the weighter to use for edge weighting
-        * @return a List of LayoutPartitions
-        */
-       public static List<LayoutPartition> partition(CyNetwork network, 
CyNetworkView networkView,
-                                    Collection<CyNode> nodeSet, EdgeWeighter 
edgeWeighter) {
-               ArrayList<LayoutPartition> partitions = new 
ArrayList<LayoutPartition>();
-
-               nodesSeenMap = new HashMap<Integer,Integer>(); 
-               edgesSeenMap = new HashMap<Integer,Integer>(); 
-
-               Map<Integer,View<CyNode>> nodesToViews = new 
HashMap<Integer,View<CyNode>>(); 
-               nodeToLayoutNode = new 
HashMap<CyNode,LayoutNode>(network.getNodeCount());
-
-               // Initialize the maps
-               for (View<CyNode> nv: networkView.getNodeViews()){
-                       int node = nv.getModel().getIndex();
-                       nodesSeenMap.put(node, m_NODE_HAS_NOT_BEEN_SEEN);
-                       nodesToViews.put(node, nv);
-               }
-
-               for (CyEdge edge: network.getEdgeList()) {
-                       int edgeIndex = edge.getIndex();
-                       edgesSeenMap.put(edgeIndex, m_NODE_HAS_NOT_BEEN_SEEN);
-               }
-
-               // OK, now traverse the graph
-               for (CyNode node: nodeSet) {
-                       int nodeIndex = node.getIndex();
-
-                       // Have we seen this already?
-                       if (nodesSeenMap.get(nodeIndex) == m_NODE_HAS_BEEN_SEEN)
-                               continue;
-
-                       // Nope, first time
-                       LayoutPartition part = new 
LayoutPartition(network.getNodeCount(),
-                                                                  
network.getEdgeCount());
-                       // Set the edge weighter
-                       part.setEdgeWeighter(edgeWeighter);
-
-                       nodesSeenMap.put(nodeIndex, m_NODE_HAS_BEEN_SEEN);
-
-                       // Traverse through all connected nodes
-                       traverse(network, networkView, nodesToViews, node, 
part);
-
-                       // Done -- finalize the parition
-                       part.trimToSize();
-
-                       // Finally, now that we're sure we've touched all of our
-                       // nodes.  Fix up our edgeLayout list to have all of our
-                       // layoutNodes
-                       part.fixEdges();
-
-                       partitions.add(part);
-               }
-
-               // Now sort the partitions based on the partition's node count
-               LayoutPartition[] a = new LayoutPartition[1];
-               LayoutPartition[] parts = partitions.toArray(a);
-               Arrays.sort(parts,
-                           new Comparator<LayoutPartition>() {
-                               public int compare(LayoutPartition p1, 
LayoutPartition p2) {
-                                       return (p2.size() - p1.size());
-                               }
-
-                               public boolean equals(LayoutPartition obj) {
-                                       return false;
-                               }
-                       });
-
-               return Arrays.asList(parts);
-       }
-
-       /**
-         * This method traverses nodes connected to the specified node.
-         * @param network            The GraphPerspective we are laying out
-         * @param networkView        The CyNetworkView we are laying out
-         * @param nodesToViews       A map that maps between nodes and views
-         * @param node               The node to search for connected nodes.
-         * @param partition          The partition that we're laying out
-         */
-       private static void traverse(CyNetwork network, CyNetworkView 
networkView,
-                                    Map<Integer,View<CyNode>> nodesToViews, 
CyNode node,
-                                    LayoutPartition partition) {
-               int nodeIndex = node.getIndex();
-
-               // Get the View<CyNode>
-               View<CyNode> nv = nodesToViews.get(nodeIndex);
-
-               // Add this node to the partition
-               partition.addNode(nv, false);
-
-               // Iterate through each connected edge
-               for (CyEdge incidentEdge: network.getAdjacentEdgeList(node, 
CyEdge.Type.ANY)){
-
-                       int edgeIndex = incidentEdge.getIndex();
-
-                       // Have we already seen this edge?
-                       if (edgesSeenMap.get(edgeIndex) == 
m_NODE_HAS_BEEN_SEEN) {
-                               // Yes, continue since it means we *must* have 
seen both sides
-                               continue;
-                       }
-
-                       edgesSeenMap.put(edgeIndex, m_NODE_HAS_BEEN_SEEN);
-
-                       // Make sure we clean up after any previous layouts
-                       //View<CyEdge> ev = 
networkView.getEdgeView(incidentEdge);
-                       //ev.clearBends(); FIXME: punted
-
-                       // Add the edge to the partition
-                       partition.addEdge(incidentEdge);
-
-                       // Determine the node's index that is on the other side 
of the edge
-                       CyNode otherNode;
-
-                       if (incidentEdge.getSource() == node) {
-                               otherNode = incidentEdge.getTarget();
-                       } else {
-                               otherNode = incidentEdge.getSource();
-                       }
-
-                       int incidentNodeIndex = otherNode.getIndex();
-
-                       // Have we seen the connecting node yet?
-                       if (nodesSeenMap.get(incidentNodeIndex) == 
m_NODE_HAS_NOT_BEEN_SEEN) {
-                               // Mark it as having been seen
-                               nodesSeenMap.put(incidentNodeIndex, 
m_NODE_HAS_BEEN_SEEN);
-
-                               // Traverse through this one
-                               traverse(network, networkView, nodesToViews, 
otherNode, partition);
-                       }
-               }
-       }
 }

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutTask.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutTask.java  
    2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/LayoutTask.java  
    2011-04-29 22:43:31 UTC (rev 24861)
@@ -20,18 +20,16 @@
 
 public abstract class LayoutTask extends AbstractTask {
        
-       protected static final Logger logger = 
LoggerFactory.getLogger(LayoutTask.class);
-       
+       private static final Logger logger = 
LoggerFactory.getLogger(LayoutTask.class);
        protected static final String LAYOUT_ALGORITHM = "layoutAlgorithm";
 
        protected final CyNetworkView networkView;
-       private final String name;
        protected final boolean selectedOnly;
        protected final Set<View<CyNode>> staticNodes;
 
-       protected boolean cancelled = false;
+       private final String name;
 
-       public LayoutTask(final CyNetworkView networkView, final String name, 
final boolean selectedOnly,
+       public LayoutTask(final CyNetworkView networkView, final String name, 
boolean selectedOnly,
                          final Set<View<CyNode>> staticNodes)
        {
                super();
@@ -71,45 +69,10 @@
                logger.debug("Layout finished: " + 
(System.currentTimeMillis()-start) + " msec.");
        }
 
-       /**
-        * Lock these nodes (i.e. prevent them from moving).
-        *
-        * @param nodes An array of View<CyNode>'s to lock
-        */
-       public void lockNodes(View<CyNode>[] nodes) {
-               for (int i = 0; i < nodes.length; ++i) {
-                       staticNodes.add(nodes[i]);
-               }
-       }
 
-       /**
-        * Lock this node (i.e. prevent it from moving).
-        *
-        * @param v A View<CyNode> to lock
-        */
-       public void lockNode(View<CyNode> v) {
-               staticNodes.add(v);
-       }
-
-       /**
-        * Unlock this node
-        *
-        * @param v A View<CyNode> to unlock
-        */
-       public void unlockNode(View<CyNode> v) {
-               staticNodes.remove(v);
-       }
-
        protected boolean isLocked(View<CyNode> v) {
-               return (staticNodes.contains(v));
+               return ((staticNodes != null) && (staticNodes.contains(v)));
        }
 
-       /**
-        * Unlock all nodes
-        */
-       public void unlockAllNodes() {
-               staticNodes.clear();
-       }
-
        protected abstract void doLayout(final TaskMonitor taskMonitor, final 
CyNetwork network);
-}
\ No newline at end of file
+}

Added: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
                           (rev 0)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
   2011-04-29 22:43:31 UTC (rev 24861)
@@ -0,0 +1,229 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2006 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package org.cytoscape.view.layout;
+
+import org.cytoscape.model.CyTableUtil;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Random;
+
+import java.awt.Dimension;
+import org.cytoscape.work.TaskMonitor;
+
+
+/**
+ * This class also provides static methods that are used to partition a 
network. 
+ *
+ * @author <a href="mailto:[email protected]";>Scooter Morris</a>
+ */
+public final class PartitionUtil {
+
+       private static final int m_NODE_HAS_NOT_BEEN_SEEN = 0;
+       private static final int m_NODE_HAS_BEEN_SEEN = 1;
+
+       private PartitionUtil() {};
+
+
+       /**
+        * Partition the graph -- this builds the LayoutEdge and LayoutNode
+        * arrays as a byproduct.  The algorithm for this was taken from
+        * algorithms/graphPartition/SGraphPartition.java.
+        *
+        * @param network the GraphPerspective containing the graph
+        * @param networkView the CyNetworkView representing the graph
+        * @param selectedOnly only consider selected nodes
+        * @param edgeWeighter the weighter to use for edge weighting
+        * @return a List of LayoutPartitions
+        */
+       public static List<LayoutPartition> partition(CyNetworkView networkView,
+                                    boolean selectedOnly, EdgeWeighter 
edgeWeighter) {
+
+               if (selectedOnly)
+                       return partition(networkView, 
CyTableUtil.getNodesInState(networkView.getModel(),"selected",true),edgeWeighter);
+               else
+                       return 
partition(networkView,networkView.getModel().getNodeList(),edgeWeighter);
+       }
+
+       /**
+        * Partition the graph -- this builds the LayoutEdge and LayoutNode
+        * arrays as a byproduct.  The algorithm for this was taken from
+        * algorithms/graphPartition/SGraphPartition.java.
+        *
+        * @param network the GraphPerspective containing the graph
+        * @param networkView the CyNetworkView representing the graph
+        * @param nodeSet the set of nodes to consider
+        * @param edgeWeighter the weighter to use for edge weighting
+        * @return a List of LayoutPartitions
+        */
+       public static List<LayoutPartition> partition(CyNetworkView networkView,
+                                    Collection<CyNode> nodeSet, EdgeWeighter 
edgeWeighter) {
+               List<LayoutPartition> partitions = new 
ArrayList<LayoutPartition>();
+
+               final CyNetwork network = networkView.getModel();
+
+               Map<Integer,Integer> nodesSeenMap = new 
HashMap<Integer,Integer>(); 
+               Map<Integer,Integer> edgesSeenMap = new 
HashMap<Integer,Integer>(); 
+               Map<Integer,View<CyNode>> nodesToViews = new 
HashMap<Integer,View<CyNode>>(); 
+
+               // Initialize the maps
+               for (View<CyNode> nv: networkView.getNodeViews()){
+                       int node = nv.getModel().getIndex();
+                       nodesSeenMap.put(node, m_NODE_HAS_NOT_BEEN_SEEN);
+                       nodesToViews.put(node, nv);
+               }
+
+               for (CyEdge edge: network.getEdgeList()) {
+                       int edgeIndex = edge.getIndex();
+                       edgesSeenMap.put(edgeIndex, m_NODE_HAS_NOT_BEEN_SEEN);
+               }
+
+               // OK, now traverse the graph
+               for (CyNode node: nodeSet) {
+                       int nodeIndex = node.getIndex();
+
+                       // Have we seen this already?
+                       if (nodesSeenMap.get(nodeIndex) == m_NODE_HAS_BEEN_SEEN)
+                               continue;
+
+                       // Nope, first time
+                       LayoutPartition part = new 
LayoutPartition(network.getNodeCount(),
+                                                                  
network.getEdgeCount());
+                       // Set the edge weighter
+                       part.setEdgeWeighter(edgeWeighter);
+
+                       nodesSeenMap.put(nodeIndex, m_NODE_HAS_BEEN_SEEN);
+
+                       // Traverse through all connected nodes
+                       traverse(network, networkView, nodesToViews, node, 
part, nodesSeenMap, edgesSeenMap);
+
+                       // Done -- finalize the parition
+                       part.trimToSize();
+
+                       // Finally, now that we're sure we've touched all of our
+                       // nodes.  Fix up our edgeLayout list to have all of our
+                       // layoutNodes
+                       part.fixEdges();
+
+                       partitions.add(part);
+               }
+
+               // Now sort the partitions based on the partition's node count
+               Collections.sort(partitions,
+                       new Comparator<LayoutPartition>() {
+                               public int compare(LayoutPartition p1, 
LayoutPartition p2) {
+                                       return (p2.size() - p1.size());
+                               }
+
+                               public boolean equals(LayoutPartition obj) {
+                                       return false;
+                               }
+                       });
+
+               return partitions; 
+       }
+
+       /**
+         * This method traverses nodes connected to the specified node.
+         * @param network            The GraphPerspective we are laying out
+         * @param networkView        The CyNetworkView we are laying out
+         * @param nodesToViews       A map that maps between nodes and views
+         * @param node               The node to search for connected nodes.
+         * @param partition          The partition that we're laying out
+         * @param nodesSeenMap       A map of nodes already visited.
+         * @param edgesSeenMap       A map of edges already visited.
+         */
+       private static void traverse(CyNetwork network, CyNetworkView 
networkView,
+                                    Map<Integer,View<CyNode>> nodesToViews, 
CyNode node,
+                                    LayoutPartition partition, 
Map<Integer,Integer> nodesSeenMap, 
+                                                                
Map<Integer,Integer> edgesSeenMap ) {
+               int nodeIndex = node.getIndex();
+
+               // Get the View<CyNode>
+               View<CyNode> nv = nodesToViews.get(nodeIndex);
+
+               // Add this node to the partition
+               partition.addNode(nv, false);
+
+               // Iterate through each connected edge
+               for (CyEdge incidentEdge: network.getAdjacentEdgeList(node, 
CyEdge.Type.ANY)){
+
+                       int edgeIndex = incidentEdge.getIndex();
+
+                       // Have we already seen this edge?
+                       if (edgesSeenMap.get(edgeIndex) == 
m_NODE_HAS_BEEN_SEEN) {
+                               // Yes, continue since it means we *must* have 
seen both sides
+                               continue;
+                       }
+
+                       edgesSeenMap.put(edgeIndex, m_NODE_HAS_BEEN_SEEN);
+
+                       // Add the edge to the partition
+                       partition.addEdge(incidentEdge);
+
+                       // Determine the node's index that is on the other side 
of the edge
+                       CyNode otherNode;
+
+                       if (incidentEdge.getSource() == node) {
+                               otherNode = incidentEdge.getTarget();
+                       } else {
+                               otherNode = incidentEdge.getSource();
+                       }
+
+                       int incidentNodeIndex = otherNode.getIndex();
+
+                       // Have we seen the connecting node yet?
+                       if (nodesSeenMap.get(incidentNodeIndex) == 
m_NODE_HAS_NOT_BEEN_SEEN) {
+                               // Mark it as having been seen
+                               nodesSeenMap.put(incidentNodeIndex, 
m_NODE_HAS_BEEN_SEEN);
+
+                               // Traverse through this one
+                               traverse(network, networkView, nodesToViews, 
otherNode, partition, nodesSeenMap, edgesSeenMap);
+                       }
+               }
+       }
+}

Modified: 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
===================================================================
--- 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
      2011-04-29 22:33:35 UTC (rev 24860)
+++ 
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
      2011-04-29 22:43:31 UTC (rev 24861)
@@ -63,7 +63,7 @@
         * Creates a new GridNodeLayout object.
         */
        public GridNodeLayout(UndoSupport un) {
-               super(un);
+               super(un,CyLayouts.DEFAULT_LAYOUT_NAME,"Grid Layout");
        }
 
        public boolean tunablesAreValid(final Appendable errMsg) {
@@ -88,24 +88,6 @@
        }
 
        /**
-        *  DOCUMENT ME!
-        *
-        * @return  DOCUMENT ME!
-        */
-       public String getName() {
-               return CyLayouts.DEFAULT_LAYOUT_NAME;
-       }
-
-       /**
-        *  DOCUMENT ME!
-        *
-        * @return  DOCUMENT ME!
-        */
-       public String toString() {
-               return "Grid Layout";
-       }
-
-       /**
         * We do support selected only
         *
         * @return true

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