Author: ghuck
Date: 2010-07-28 16:26:56 -0700 (Wed, 28 Jul 2010)
New Revision: 21065

Modified:
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelPartition.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/GroupAttributesLayout.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutAlgorithm.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutFRAlgorithm.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutKKAlgorithm.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/circularLayout/CircularLayoutAlgorithm.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AbstractGraphPartition.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AttributeCircleLayout.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
   
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/ISOMLayout.java
Log:


Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
      2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelNodeImpl.java
      2010-07-28 23:26:56 UTC (rev 21065)
@@ -85,16 +85,37 @@
            lp = parser.parseStringValue(labelPosition);
            // logger.info("ObjectPosition succesfully parsed!");
        }
-       
-//     logger.info("Parent node: " + parentNodeView.getNode().getIdentifier());
-//     logger.info("Offset = " + lp.getOffsetX() + ", " + lp.getOffsetY() );
 
-       this.setX(lp.getOffsetX() + parentNodeView.getXPosition());
-       this.setY(lp.getOffsetY() + parentNodeView.getYPosition());         
-       this.neighbors = new ArrayList<LayoutNode>();
-       this.index = index;
+       try {   
+           //  logger.info("Parent node: " + 
parentNodeView.getNode().getIdentifier());
+           //  logger.info("Offset = " + lp.getOffsetX() + ", " + 
lp.getOffsetY() );
+           
+           this.setX(lp.getOffsetX() + parentNodeView.getXPosition());
+           this.setY(lp.getOffsetY() + parentNodeView.getYPosition());     
+           this.neighbors = new ArrayList<LayoutNode>();
+           this.index = index;
 
-       // logger.info("Created " + this.getIdentifier() + "placed in: " + 
this.getX() + ", " + this.getY() );
+           // logger.info("Created " + this.getIdentifier() + "placed in: " + 
this.getX() + ", " + this.getY() );
+       }
+       catch(Exception e) {
+           // Log error
+           logger.warning("Error detected while creating LayoutLabelNodeImp: " 
+ e.toString() );
+
+           // Reset this attribute by eliminating it
+
+           if (nodeAtts.hasAttribute(parentNodeView.getNode().getIdentifier(), 
"node.labelPosition")) {
+               
nodeAtts.deleteAttribute(parentNodeView.getNode().getIdentifier(), 
"node.labelPosition");
+               logger.warning("Deleted 'node.labelPosition' attribute");
+           }
+ 
+           lp = new ObjectPositionImpl();
+           logger.warning("Created new ObjectPosition!");          
+
+           this.setX( parentNodeView.getXPosition() );
+           this.setY( parentNodeView.getYPosition() );     
+           this.neighbors = new ArrayList<LayoutNode>();
+           this.index = index;
+       }
     }
 
     /**
@@ -123,7 +144,8 @@
            nodeAtts.setAttribute(parentNodeView.getNode().getIdentifier(),
                                  "node.labelPosition", lp.shortString());
 
-           //      logger.info("Label node was moved!");
+//         logger.info("Label node was moved!, short string: " + 
lp.shortString());
+//         logger.info("full label string: " + lp.toString() );
        } 
     }
 

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelPartition.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelPartition.java
     2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutLabelPartition.java
     2010-07-28 23:26:56 UTC (rev 21065)
@@ -87,8 +87,7 @@
     public LayoutLabelPartition(LayoutPartition part, 
                                double weightCoefficient, 
                                boolean moveNodes, 
-                               boolean selectedOnly,
-                               boolean isWeighted) {
+                               boolean selectedOnly) {
 
        super(part.size(), part.getEdgeList().size());
 
@@ -197,32 +196,28 @@
        Double weight = null;
        
        // -- First set labelEdges weights --
-       if (this.isWeighted) {
-           // Calculate maximum preexisting weight
-           Double maxWeight = new Double(Double.MIN_VALUE);
 
-           ListIterator<LayoutEdge>iter = edgeList.listIterator();
+       // Calculate maximum preexisting weight
+       Double maxWeight = new Double(Double.MIN_VALUE);
 
-           while (iter.hasNext()) {
-               LayoutEdge edge = iter.next();
-           
-               // Only consider non label edges
-               if (labelToParentMap.keySet().contains(edge.getSource()) || 
-                   labelToParentMap.keySet().contains(edge.getTarget()) ) {
-                   continue;
-               }
+       ListIterator<LayoutEdge>iter = edgeList.listIterator();
 
-               if (  edge.getWeight() > maxWeight ) {
-                   maxWeight = edge.getWeight();
-               }
+       while (iter.hasNext()) {
+           LayoutEdge edge = iter.next();
+           
+           // Only consider non label edges
+           if (labelToParentMap.keySet().contains(edge.getSource()) || 
+               labelToParentMap.keySet().contains(edge.getTarget()) ) {
+               continue;
            }
 
-           // Value which will be used as weight for all label edges
-           weight = maxWeight *  weightCoefficient;
-       } 
-       else { // if (!this.isWeighted)
-           weight = weightCoefficient;
+           if (  edge.getWeight() > maxWeight ) {
+               maxWeight = edge.getWeight();
+           }
        }
+
+       // Value which will be used as weight for all label edges
+       weight = maxWeight *  weightCoefficient;
        
        // Set all labelEdge weights
        ListIterator<LayoutEdge>iter2 = edgeList.listIterator();
@@ -234,11 +229,7 @@
                labelToParentMap.keySet().contains(edge.getTarget()) ) {        
        
                // set label edges weights
                edge.setWeight(weight);         
-           } else{ // non label edge (normal one)
-               if (!this.isWeighted){
-                   edge.setWeight(1.0);
-               }
-           }
+           } 
        }
 
 

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
  2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/LayoutPartition.java
  2010-07-28 23:26:56 UTC (rev 21065)
@@ -313,7 +313,7 @@
                iter.remove();
 
            //logger.debug("Edge "+edge.getEdge().getIdentifier()+" now has 
weight "+edge.getWeight());
-           logger.info( edge.toString() + " now has weight "+edge.getWeight());
+           // logger.info( edge.toString() + " now has weight 
"+edge.getWeight());
        }
     }
 

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/GroupAttributesLayout.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/GroupAttributesLayout.java
 2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/GroupAttributesLayout.java
 2010-07-28 23:26:56 UTC (rev 21065)
@@ -286,7 +286,7 @@
        /**
         *  DOCUMENT ME!
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
                if (canceled) return;
 
                taskMonitor.setStatus("Initializing");

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutAlgorithm.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutAlgorithm.java
  2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutAlgorithm.java
  2010-07-28 23:26:56 UTC (rev 21065)
@@ -313,7 +313,7 @@
        /**
         * Main function that must be implemented by the child class.
         */
-       public abstract void layoutPartion(LayoutPartition partition);
+       public abstract void layoutPartition(LayoutPartition partition);
 
        protected void initialize_local() {
        }

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutFRAlgorithm.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutFRAlgorithm.java
        2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutFRAlgorithm.java
        2010-07-28 23:26:56 UTC (rev 21065)
@@ -509,7 +509,7 @@
        /**
         * Perform a layout
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
                this.partition = partition;
 
                Dimension initialLocation = null;

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutKKAlgorithm.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutKKAlgorithm.java
        2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/bioLayout/BioLayoutKKAlgorithm.java
        2010-07-28 23:26:56 UTC (rev 21065)
@@ -432,7 +432,7 @@
        /**
         * Perform a layout
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
                Iterator iter = null;
                Dimension initialLocation = null;
                this.partition = partition;

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/circularLayout/CircularLayoutAlgorithm.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/circularLayout/CircularLayoutAlgorithm.java
        2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/circularLayout/CircularLayoutAlgorithm.java
        2010-07-28 23:26:56 UTC (rev 21065)
@@ -132,7 +132,7 @@
         *
         * @param partition DOCUMENT ME!
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
                if (canceled)
                        return;
 

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
     2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/force/ForceDirectedLayout.java
     2010-07-28 23:26:56 UTC (rev 21065)
@@ -121,12 +121,12 @@
        }
 
 
-       public void layoutPartion(LayoutPartition part) {
+       public void layoutPartition(LayoutPartition part) {
                Dimension initialLocation = null;
-               // logger.debug("layoutPartion: "+part.getEdgeList().size()+" 
edges");
+               // logger.debug("layoutPartition: "+part.getEdgeList().size()+" 
edges");
                // Calculate our edge weights
                part.calculateEdgeWeights();
-               // logger.debug("layoutPartion: "+part.getEdgeList().size()+" 
edges after calculateEdgeWeights");
+               // logger.debug("layoutPartition: "+part.getEdgeList().size()+" 
edges after calculateEdgeWeights");
 
                m_fsim.clear();
 

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AbstractGraphPartition.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AbstractGraphPartition.java
 2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AbstractGraphPartition.java
 2010-07-28 23:26:56 UTC (rev 21065)
@@ -6,7 +6,9 @@
 import cern.colt.map.*;
 
 import csplugins.layout.LayoutNode;
+import csplugins.layout.LayoutLabelNodeImpl;
 import csplugins.layout.LayoutPartition;
+import csplugins.layout.LayoutLabelPartition;
 import csplugins.layout.EdgeWeighter;
 
 import cytoscape.CyNetwork;
@@ -14,6 +16,11 @@
 import cytoscape.CyNode;
 
 import cytoscape.layout.AbstractLayout;
+import cytoscape.layout.LayoutProperties;
+import cytoscape.layout.Tunable;
+
+import cytoscape.data.CyAttributes;
+
 import cytoscape.logger.CyLogger;
 
 import cytoscape.task.*;
@@ -28,203 +35,414 @@
 
 import javax.swing.JOptionPane;
 
+import java.awt.Dimension;
 
+
 /**
  * An abstract class that handles the partitioning of graphs so that
  * the partitions will be laid out individually.
  */
 public abstract class AbstractGraphPartition extends AbstractLayout {
-       double incr = 100;
-       protected List <LayoutPartition> partitionList = null;
-       protected EdgeWeighter edgeWeighter = null;
-       protected boolean singlePartition = false;
-       protected CyLogger logger = null;
+    double incr = 100;
+    protected List <LayoutPartition> partitionList = null;
+    protected EdgeWeighter edgeWeighter = null;
+    protected boolean singlePartition = false;
+    protected CyLogger logger = null;
 
-       // Information for taskMonitor
-       double current_start = 0;       // Starting node number
-       double  current_size = 0;               // Partition size
-       double  total_nodes = 0;                // Total number of nodes
+    /**
+     * Whether Labels should be repositioned in their default positions 
+     */
+    protected boolean resetPosition = false;
+    
+    /**
+     * Whether network nodes will be moved or not 
+     */
+    protected boolean moveNodes = false;
 
-       /**
-        * Creates a new AbstractGraphPartition object.
-        */
-       public AbstractGraphPartition() {
-               super();
-       }
+    /**
+     * Coefficient to determine label edge weights
+     */
+    protected double weightCoefficient = 10.0;
 
-       /**
-        * Override this method and layout the LayoutPartion just
-        * like you would a NetworkView.
-        *
-        * @param partition The LayoutPartion to be laid out. 
-        */
-       public abstract void layoutPartion(LayoutPartition partition);
 
-       /**
-        *  DOCUMENT ME!
-        *
-        * @return  DOCUMENT ME!
-        */
-       public boolean supportsSelectedOnly() {
-               return true;
-       }
 
-       /**
-        * Sets the singlePartition flag, which disables partitioning. This
-        * can be used by users who do not want to partition their graph for
-        * some reason.
-        *
-        * @param flag if false, no paritioning will be done
-        */
-       public void setPartition(boolean flag) {
-               if (flag)
-                       this.singlePartition = false;
-               else
-                       this.singlePartition = true;
+    // Information for taskMonitor
+    double current_start = 0;  // Starting node number
+    double     current_size = 0;               // Partition size
+    double     total_nodes = 0;                // Total number of nodes
+
+    /**
+     * Creates a new AbstractGraphPartition object.
+     */
+    public AbstractGraphPartition() {
+       super();
+    }
+
+    /**
+     * Override this method and layout the LayoutPartion just
+     * like you would a NetworkView.
+     *
+     * @param partition The LayoutPartion to be laid out. 
+     */
+    public abstract void layoutPartition(LayoutPartition partition);
+    
+    /**
+     *  DOCUMENT ME!
+     *
+     * @return  DOCUMENT ME!
+     */
+    public boolean supportsSelectedOnly() {
+       return true;
+    }
+
+    /**
+     * If overridden by a subclass to return true, before calling to 
+     * layoutPartition mathod, fake nodes will be created to represent label 
+     * positions, and labels will be placed acordingly. 
+     *
+     * It is an easy way of creating label layout algorithms.
+     *
+     * For this to work fine with labels, weights should be supported.
+     *
+     * @return Whether the layout algorithm supports label layout. 
+     */
+    public boolean supportsLabelLayout() {
+       return false;
+    }
+
+
+    /**
+     * Sets the singlePartition flag, which disables partitioning. This
+     * can be used by users who do not want to partition their graph for
+     * some reason.
+     *
+     * @param flag if false, no paritioning will be done
+     */
+    public void setPartition(boolean flag) {
+       if (flag)
+           this.singlePartition = false;
+       else
+           this.singlePartition = true;
+    }
+
+    /**
+     * Sets the singlePartition flag, which disables partitioning. This
+     * can be used by users who do not want to partition their graph for
+     * some reason.
+     *
+     * @param value if "false", no paritioning will be done
+     */
+    public void setPartition(String value) {
+       Boolean val = new Boolean(value);
+       setPartition(val.booleanValue());
+    }
+
+    /**
+     *  DOCUMENT ME!
+     *
+     * @param percent The percentage of completion for this partition
+     */
+    protected void setTaskStatus(int percent) {
+       if (taskMonitor != null) {
+           // Calculate the nodes done for this partition
+           double nodesDone = current_size*(double)percent/100.;
+           // Calculate the percent done overall
+           double pDone = ((nodesDone+current_start)/total_nodes)*100.;
+           taskMonitor.setPercentCompleted((int)pDone);
+           taskMonitor.setStatus("Completed " + (int)pDone + "%");
        }
+    }
 
-       /**
-        * Sets the singlePartition flag, which disables partitioning. This
-        * can be used by users who do not want to partition their graph for
-        * some reason.
-        *
-        * @param value if "false", no paritioning will be done
-        */
-       public void setPartition(String value) {
-               Boolean val = new Boolean(value);
-               setPartition(val.booleanValue());
+    /**
+     * AbstractGraphPartitionLayout implements the construct method
+     * and calls layoutPartition for each partition.
+     */
+    public void construct() {
+       initialize();
+
+       // Reset label positions if necessary
+       if (resetPosition) {
+           resetLabelPositions();
+           return;
        }
 
-       /**
-        *  DOCUMENT ME!
-        *
-        * @param percent The percentage of completion for this partition
-        */
-       protected void setTaskStatus(int percent) {
-               if (taskMonitor != null) {
-                       // Calculate the nodes done for this partition
-                       double nodesDone = current_size*(double)percent/100.;
-                       // Calculate the percent done overall
-                       double pDone = 
((nodesDone+current_start)/total_nodes)*100.;
-                       taskMonitor.setPercentCompleted((int)pDone);
-                       taskMonitor.setStatus("Completed " + (int)pDone + "%");
+       if (edgeWeighter != null) 
+           edgeWeighter.reset();
+
+       // Depending on whether we are partitioned or not,
+       // we use different initialization.  Note that if the user only wants
+       // to lay out selected nodes, partitioning becomes a very bad idea!
+       if (selectedOnly || singlePartition) {
+           // 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);
+           partitionList = new ArrayList(1);
+           partitionList.add(partition);
+       } else if (staticNodes != null && staticNodes.size() > 0) {
+           // Someone has programmatically locked a set of nodes -- construct
+           // the list of unlocked nodes
+           List<CyNode> unlockedNodes = new ArrayList();
+           for (CyNode node: (List<CyNode>)network.nodesList()) {
+               if 
(!isLocked(networkView.getNodeView(node.getRootGraphIndex()))) {
+                   unlockedNodes.add(node);
                }
+           }
+           LayoutPartition partition = new LayoutPartition(network, 
networkView, unlockedNodes, edgeWeighter);
+           partitionList = new ArrayList(1);
+           partitionList.add(partition);
+       } else {
+           partitionList = LayoutPartition.partition(network, networkView, 
false, edgeWeighter);
        }
 
-       /**
-        * AbstractGraphPartitionLayout implements the constuct method
-        * and calls layoutPartion for each partition.
-        */
-       public void construct() {
-               initialize();
+       total_nodes = network.getNodeCount();
+       current_start = 0;
 
-               if (edgeWeighter != null) 
-                       edgeWeighter.reset();
+       // Set up offsets -- we start with the overall min and max
+       double xStart = (partitionList.get(0)).getMinX();
+       double yStart = (partitionList.get(0)).getMinY();
 
-               // Depending on whether we are partitioned or not,
-               // we use different initialization.  Note that if the user only 
wants
-               // to lay out selected nodes, partitioning becomes a very bad 
idea!
-               if (selectedOnly || singlePartition) {
-                       // 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);
-                       partitionList = new ArrayList(1);
-                       partitionList.add(partition);
-               } else if (staticNodes != null && staticNodes.size() > 0) {
-                       // Someone has programmatically locked a set of nodes 
-- construct
-                       // the list of unlocked nodes
-                       List<CyNode> unlockedNodes = new ArrayList();
-                       for (CyNode node: (List<CyNode>)network.nodesList()) {
-                               if 
(!isLocked(networkView.getNodeView(node.getRootGraphIndex()))) {
-                                       unlockedNodes.add(node);
-                               }
-                       }
-                       LayoutPartition partition = new 
LayoutPartition(network, networkView, unlockedNodes, edgeWeighter);
-                       partitionList = new ArrayList(1);
-                       partitionList.add(partition);
-               } else {
-                       partitionList = LayoutPartition.partition(network, 
networkView, false, edgeWeighter);
+       for (LayoutPartition part: partitionList) {
+           xStart = Math.min(xStart, part.getMinX());
+           yStart = Math.min(yStart, part.getMinY());
+       }
+
+       double next_x_start = xStart;
+       double next_y_start = yStart;
+       double current_max_y = 0;
+
+       double max_dimensions = Math.sqrt((double) network.getNodeCount());
+       // give each node room
+       max_dimensions *= incr;
+       max_dimensions += xStart;
+
+       for (LayoutPartition partition: partitionList) {
+           if (canceled) break;
+           // get the partition
+           current_size = (double)partition.size();
+           // logger.debug("Partition #"+partition.getPartitionNumber()+" has 
"+current_size+" nodes");
+           setTaskStatus(1);
+
+           // Partitions Requiring Layout
+           if (partition.nodeCount() > 1) { // TODO: add case when nodeCount = 
1
+               try {
+                   layoutSinglePartition(partition);
+               } catch (OutOfMemoryError _e) {
+                   System.gc();
+                   logger.error("Layout algorithm failed: Out of memory");
+                   return;
+               } catch (Exception _e) {
+                   logger.error("Layout algorithm failed: ", (Throwable)_e);
+                   return;
                }
 
-               total_nodes = network.getNodeCount();
-               current_start = 0;
+               if (!selectedOnly && !singlePartition) {
+                   // logger.debug("Offsetting partition 
#"+partition.getPartitionNumber()+" to "+next_x_start+", "+next_y_start);
+                   // OFFSET
+                   partition.offset(next_x_start, next_y_start);
+               }
 
-               // Set up offsets -- we start with the overall min and max
-               double xStart = (partitionList.get(0)).getMinX();
-               double yStart = (partitionList.get(0)).getMinY();
+               // single nodes
+           } else if ( partition.nodeCount() == 1 ) {
+               // Reset our bounds
+               partition.resetNodes();
 
-               for (LayoutPartition part: partitionList) {
-                       xStart = Math.min(xStart, part.getMinX());
-                       yStart = Math.min(yStart, part.getMinY());
+               // Single node -- get it
+               LayoutNode node = (LayoutNode) partition.getNodeList().get(0);
+               node.setLocation(next_x_start, next_y_start);
+               partition.moveNodeToLocation(node);
+           } else {
+               continue;
+           }
+
+           double last_max_x = partition.getMaxX();
+           double last_max_y = partition.getMaxY();
+
+           if (last_max_y > current_max_y) {
+               current_max_y = last_max_y;
+           }
+
+           if (last_max_x > max_dimensions) {
+               next_x_start = xStart;
+               next_y_start = current_max_y;
+               next_y_start += incr;
+           } else {
+               next_x_start = last_max_x;
+               next_x_start += incr;
+           }
+
+           setTaskStatus( 100 );
+           current_start += current_size;
+       } 
+    }
+
+
+    /**
+     * 
+     */
+    protected void layoutSinglePartition(LayoutPartition partition){
+
+       if(supportsLabelLayout()) {
+
+           Dimension initialLocation = null;
+
+           if (canceled)
+               return;
+       
+           // Create new Label partition
+           LayoutLabelPartition newPartition = new 
LayoutLabelPartition(partition,
+                                                                        
weightCoefficient,
+                                                                        
moveNodes,
+                                                                        
selectedOnly);
+
+           //  logger.info("New partition succesfully created!");
+
+           // Figure out our starting point - This will be used when:
+           // 1- Laying out labels off all nodes
+           // - and- 
+           // 2- (normal) Nodes are not allowed to move
+           if (selectedOnly && moveNodes) {
+               newPartition.recalculateStatistics();
+               initialLocation = newPartition.getAverageLocation();
+           }
+
+           if (canceled)
+               return;
+
+           // Layout the new partition using the parent class layout algorithm
+           layoutPartition(newPartition);
+
+           if (canceled)
+               return;
+
+           // Not quite done, yet. We may need to migrate labels back to their 
starting position
+           // This will be necessary if:
+           // 1- Laying out only selected nodes
+           // - and - 
+           // 2- (normal) Nodes are allowed to move
+
+           taskMonitor.setStatus("Making final arrangements to partition...");
+
+           if (selectedOnly && moveNodes) {
+               // logger.info("moving back labels (and possibly nodes) to 
their location");
+
+               newPartition.recalculateStatistics();
+               Dimension finalLocation = newPartition.getAverageLocation();
+               double xDelta = 0.0;
+               double yDelta = 0.0;
+        
+               xDelta = finalLocation.getWidth() - initialLocation.getWidth();
+               yDelta = finalLocation.getHeight() - 
initialLocation.getHeight();
+
+               for (LayoutNode v: newPartition.getNodeList()) {
+                   if (!v.isLocked()) {
+                       v.decrement(xDelta, yDelta);
+                       newPartition.moveNodeToLocation(v);
+                   }
                }
+           }
 
-               double next_x_start = xStart;
-               double next_y_start = yStart;
-               double current_max_y = 0;
 
-               double max_dimensions = Math.sqrt((double) 
network.getNodeCount());
-               // give each node room
-               max_dimensions *= incr;
-               max_dimensions += xStart;
+           // make sure nodes are where they should be
+           for(LayoutNode node: newPartition.getLabelToParentMap().values() ) {
 
-               for (LayoutPartition partition: partitionList) {
-                       if (canceled) break;
-                       // get the partition
-                       current_size = (double)partition.size();
-                       // logger.debug("Partition 
#"+partition.getPartitionNumber()+" has "+current_size+" nodes");
-                       setTaskStatus(1);
+               if (canceled)
+                   return;
 
-                       // Partitions Requiring Layout
-                       if (partition.nodeCount() > 1) {
-                               try {
-                                       layoutPartion(partition);
-                               } catch (OutOfMemoryError _e) {
-                                       System.gc();
-                                       logger.error("Layout algorithm failed: 
Out of memory");
-                                       return;
-                               } catch (Exception _e) {
-                                       logger.error("Layout algorithm failed: 
", (Throwable)_e);
-                                       return;
-                               }
+               node.moveToLocation();
+               logger.info( node.toString() );
+           }
 
-                               if (!selectedOnly && !singlePartition) {
-                                       // logger.debug("Offsetting partition 
#"+partition.getPartitionNumber()+" to "+next_x_start+", "+next_y_start);
-                                       // OFFSET
-                                       partition.offset(next_x_start, 
next_y_start);
-                               }
+           // make sure that all labels are where they should be 
+           for(LayoutLabelNodeImpl node: newPartition.getLabelNodes() ) {      
 
-                       // single nodes
-                       } else if ( partition.nodeCount() == 1 ) {
-                               // Reset our bounds
-                               partition.resetNodes();
+               if (canceled)
+                   return;
 
-                               // Single node -- get it
-                               LayoutNode node = (LayoutNode) 
partition.getNodeList().get(0);
-                               node.setLocation(next_x_start, next_y_start);
-                               partition.moveNodeToLocation(node);
-                       } else {
-                               continue;
-                       }
+               node.moveToLocation();
+               logger.info( node.toString() );
+           }
 
-                       double last_max_x = partition.getMaxX();
-                       double last_max_y = partition.getMaxY();
+           taskMonitor.setStatus("Updating Display...");
 
-                       if (last_max_y > current_max_y) {
-                               current_max_y = last_max_y;
-                       }
+           // redraw the network so that the new label positions are visible
+           networkView.updateView();
+           networkView.redrawGraph(true, true);
 
-                       if (last_max_x > max_dimensions) {
-                               next_x_start = xStart;
-                               next_y_start = current_max_y;
-                               next_y_start += incr;
-                       } else {
-                               next_x_start = last_max_x;
-                               next_x_start += incr;
-                       }
 
-                       setTaskStatus( 100 );
-                       current_start += current_size;
-               } 
+
+       } else {
+           layoutPartition(partition);
        }
+
+    }
+
+    /**
+     * Adds the necessary tunables to control the label layout.
+     */
+    public void getLabelTunables(LayoutProperties layoutProperties) {
+
+       layoutProperties.add(new Tunable("labels_settings", 
+                                        "Label specific settings",
+                                        Tunable.GROUP, new Integer(3))); 
+
+       layoutProperties.add(new Tunable("resetPosition", 
+                                        "Reset label positions",
+                                        Tunable.BOOLEAN, new 
Boolean(resetPosition)));
+
+       layoutProperties.add(new Tunable("moveNodes", 
+                                        "Allow nodes to move",
+                                        Tunable.BOOLEAN, new 
Boolean(moveNodes)));
+
+       layoutProperties.add(new Tunable("weightCoefficient", 
+                                        "weightCoefficient",
+                                        Tunable.DOUBLE, new 
Double(weightCoefficient)));
+    }
+
+    /**
+     *  Update our tunable settings
+     *
+     * @param layoutProperties the LayoutProperties handler for this layout
+     * @param force whether or not to force the update
+     */
+    public void updateSettings(LayoutProperties layoutProperties, boolean 
force) {
+
+       Tunable t = layoutProperties.get("resetPosition");
+       if ((t != null) && (t.valueChanged() || force))
+           resetPosition = ((Boolean) t.getValue()).booleanValue();
+
+       t = layoutProperties.get("moveNodes");
+       if ((t != null) && (t.valueChanged() || force))
+           moveNodes = ((Boolean) t.getValue()).booleanValue();
+
+       t = layoutProperties.get("weightCoefficient");
+       if ((t != null) && (t.valueChanged() || force))
+           weightCoefficient = ((Double) t.getValue()).doubleValue();
+    }
+
+
+    /**
+     * Moves labels to the same position in which their parent nodes are
+     */
+    protected void resetLabelPositions() {
+
+       logger.info("Reseting labels position");
+
+       CyAttributes nodeAtts = Cytoscape.getNodeAttributes();
+
+       // Go through all nodes deleting the label position attribute
+       for (CyNode node: (List<CyNode>)network.nodesList()) {
+           if (!selectedOnly || 
!isLocked(networkView.getNodeView(node.getRootGraphIndex()))) {
+               if (nodeAtts.hasAttribute(node.getIdentifier(), 
"node.labelPosition")) {
+                   nodeAtts.deleteAttribute(node.getIdentifier(), 
"node.labelPosition");
+               }
+           }
+       }
+       
+       // redraw the network so that the new label positions are visible
+       networkView.updateView();
+       networkView.redrawGraph(true, true);
+    }
+
+
 }

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AttributeCircleLayout.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AttributeCircleLayout.java
  2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/AttributeCircleLayout.java
  2010-07-28 23:26:56 UTC (rev 21065)
@@ -242,7 +242,7 @@
         *
         * @param partition DOCUMENT ME!
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
                data = Cytoscape.getNodeAttributes();
 
                // just add the unlocked nodes

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
       2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/DegreeSortedCircleLayout.java
       2010-07-28 23:26:56 UTC (rev 21065)
@@ -57,7 +57,7 @@
         *
         * @param partition DOCUMENT ME!
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
 
     // just add the unlocked nodes
     List<LayoutNode> nodes = new ArrayList<LayoutNode>();

Modified: 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/ISOMLayout.java
===================================================================
--- 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/ISOMLayout.java
     2010-07-28 22:29:50 UTC (rev 21064)
+++ 
coreplugins/branches/labelLayout/AutomaticLayout/src/csplugins/layout/algorithms/graphPartition/ISOMLayout.java
     2010-07-28 23:26:56 UTC (rev 21065)
@@ -218,7 +218,7 @@
         *
         * @param partition DOCUMENT ME!
         */
-       public void layoutPartion(LayoutPartition partition) {
+       public void layoutPartition(LayoutPartition partition) {
                this.partition = partition;
 
                int nodeCount = partition.nodeCount();

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