Author: kono
Date: 2012-06-19 15:00:41 -0700 (Tue, 19 Jun 2012)
New Revision: 29623

Modified:
   
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutTask.java
   
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdit.java
Log:
fixes #1144 Individual edge bend values will be cleared when user apply layout. 
 Also, undo/redo function implemented for this.

Modified: 
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutTask.java
===================================================================
--- 
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutTask.java
  2012-06-19 21:42:22 UTC (rev 29622)
+++ 
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutTask.java
  2012-06-19 22:00:41 UTC (rev 29623)
@@ -1,10 +1,12 @@
 package org.cytoscape.view.layout;
 
 
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNetwork;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.model.CyRow;
@@ -107,6 +109,9 @@
                
                if ( undo != null )
                        undo.postEdit(new LayoutEdit(name,networkView));
+               
+               // Clear Edge Bends.
+               clearEdgeBends();
 
                // this is overridden by children and does the actual layout
                doLayout(taskMonitor);
@@ -123,6 +128,21 @@
 
                logger.debug("Layout finished in " + 
(System.currentTimeMillis() - start) + " msec.");
        }
+       
+       /**
+        * Clears edge bend values ASSIGNED TO EACH EDGE.
+        * Default Edge Bend value will not be cleared.
+        * 
+        * TODO: should we clear mapping, too?
+        */
+       private final void clearEdgeBends() {
+               final Collection<View<CyEdge>> edgeViews = 
networkView.getEdgeViews();
+               
+               for(final View<CyEdge> edgeView: edgeViews) {
+                       
edgeView.setVisualProperty(BasicVisualLexicon.EDGE_BEND, null);
+                       edgeView.clearValueLock(BasicVisualLexicon.EDGE_BEND);
+               }
+       }
 
        /**
         * This method is designed to actually encapsulate the layout 
algorithm. It will be

Modified: 
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdit.java
===================================================================
--- 
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdit.java
  2012-06-19 21:42:22 UTC (rev 29622)
+++ 
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdit.java
  2012-06-19 22:00:41 UTC (rev 29623)
@@ -8,14 +8,19 @@
 import static 
org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_CENTER_Y_LOCATION;
 import static 
org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_CENTER_Z_LOCATION;
 import static 
org.cytoscape.view.presentation.property.BasicVisualLexicon.NETWORK_SCALE_FACTOR;
+import static 
org.cytoscape.view.presentation.property.BasicVisualLexicon.EDGE_BEND;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
 
+import org.cytoscape.model.CyEdge;
 import org.cytoscape.model.CyNode;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
+import org.cytoscape.view.presentation.property.values.Bend;
 import org.cytoscape.work.undo.AbstractCyEdit;
 
 
@@ -25,6 +30,8 @@
 public final class LayoutEdit extends AbstractCyEdit {
        private final CyNetworkView view;
        private List<NodeViewAndLocations> nodeViewsAndLocations;
+       private Map<View<CyEdge>, Bend> bendMap;
+       
        private double networkScale;
        private double networkCenterX;
        private double networkCenterY;
@@ -32,15 +39,17 @@
 
        /**
         * Constructor.
-        * @param name The name that will appear in the undo menu.
-        * @param view The view whose current position will be tracked.
+        * 
+        * @param name
+        *            The name that will appear in the undo menu.
+        * @param view
+        *            The view whose current position will be tracked.
         */
        public LayoutEdit(String name, final CyNetworkView view) {
                super(name);
-
-               this.view        = view;
-
+               this.view = view;
                saveNodeViewsAndLocations();
+               saveEdgeViews();
        }
 
        @Override
@@ -59,9 +68,15 @@
                final double oldNetworkCenterX = networkCenterX;
                final double oldNetworkCenterY = networkCenterY;
                final double oldNetworkCenterZ = networkCenterZ;
+               final Map<View<CyEdge>, Bend> oldEdgeBends = bendMap;
+               
                saveNodeViewsAndLocations();
+               saveEdgeViews();
+               
                for (final NodeViewAndLocations nodeViewAndLocation : 
oldNodeViewsAndLocations)
                        nodeViewAndLocation.restoreLocations();
+               for(View<CyEdge> edgeView: oldEdgeBends.keySet())
+                       edgeView.setVisualProperty(EDGE_BEND, 
oldEdgeBends.get(edgeView));
 
                view.setVisualProperty(NETWORK_SCALE_FACTOR, oldNetworkScale);
                view.setVisualProperty(NETWORK_CENTER_X_LOCATION, 
oldNetworkCenterX);
@@ -82,6 +97,15 @@
                for (final View<CyNode> nodeView : nodeViews)
                        nodeViewsAndLocations.add(new 
NodeViewAndLocations(nodeView));
        }
+       
+       private void saveEdgeViews() {
+               this.bendMap = new WeakHashMap<View<CyEdge>, Bend>();
+               final Collection<View<CyEdge>> edgeViews = view.getEdgeViews();
+               for (final View<CyEdge> edgeView : edgeViews) {
+                       bendMap.put(edgeView, 
edgeView.getVisualProperty(EDGE_BEND));
+               }
+                       
+       }
 }
 
 

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