Author: ruschein
Date: 2011-07-29 13:25:05 -0700 (Fri, 29 Jul 2011)
New Revision: 26338
Added:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/LayoutEdit.java
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTaskFactory.java
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
Log:
Added undo/redo support for applying the preferred layout.
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
2011-07-29 20:10:21 UTC (rev 26337)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
2011-07-29 20:25:05 UTC (rev 26338)
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2010-2011, 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
@@ -24,37 +24,56 @@
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.task.internal.layout;
+
+import org.cytoscape.event.CyEventHelper;
import org.cytoscape.task.AbstractNetworkViewTask;
-import org.cytoscape.work.TaskMonitor;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
import org.cytoscape.view.layout.CyLayoutAlgorithm;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.undo.UndoSupport;
+
import java.util.Properties;
+
public class ApplyPreferredLayoutTask extends AbstractNetworkViewTask {
-
private static final String DEF_LAYOUT = "force-directed";
+ private final UndoSupport undoSupport;
+ private final CyEventHelper eventHelper;
private Properties props;
private final CyLayoutAlgorithmManager layouts;
- public ApplyPreferredLayoutTask(CyNetworkView v,
CyLayoutAlgorithmManager layouts, Properties props) {
+ public ApplyPreferredLayoutTask(final UndoSupport undoSupport,
+ final CyEventHelper eventHelper,
+ final CyNetworkView v,
+ final CyLayoutAlgorithmManager layouts,
+ final Properties props)
+ {
super(v);
- this.layouts = layouts;
- this.props = props;
+ this.undoSupport = undoSupport;
+ this.eventHelper = eventHelper;
+ this.layouts = layouts;
+ this.props = props;
}
- public ApplyPreferredLayoutTask(final CyNetworkView v, final
CyLayoutAlgorithmManager layouts) {
+ public ApplyPreferredLayoutTask(final CyNetworkView v,
+ final CyLayoutAlgorithmManager layouts)
+ {
super(v);
+ this.undoSupport = null;
+ this.eventHelper = null;
this.layouts = layouts;
}
public void run(TaskMonitor tm) {
-
+ if (undoSupport != null)
+ undoSupport.getUndoableEditSupport().postEdit(new
LayoutEdit(eventHelper,
+
view));
+
String pref = CyLayoutAlgorithmManager.DEFAULT_LAYOUT_NAME;
if(props != null)
pref = props.getProperty("preferredLayoutAlgorithm",
DEF_LAYOUT);
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTaskFactory.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTaskFactory.java
2011-07-29 20:10:21 UTC (rev 26337)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTaskFactory.java
2011-07-29 20:25:05 UTC (rev 26338)
@@ -1,23 +1,35 @@
package org.cytoscape.task.internal.layout;
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.property.CyProperty;
import org.cytoscape.task.AbstractNetworkViewTaskFactory;
+import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
import org.cytoscape.work.TaskIterator;
-import org.cytoscape.property.CyProperty;
-import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
+import org.cytoscape.work.undo.UndoSupport;
+
import java.util.Properties;
+
public class ApplyPreferredLayoutTaskFactory extends
AbstractNetworkViewTaskFactory {
-
+ private final UndoSupport undoSupport;
+ private final CyEventHelper eventHelper;
private final CyLayoutAlgorithmManager layouts;
private final Properties props;
- public ApplyPreferredLayoutTaskFactory(CyLayoutAlgorithmManager
layouts, CyProperty<Properties> p) {
- this.layouts = layouts;
- this.props = p.getProperties();
+ public ApplyPreferredLayoutTaskFactory(final UndoSupport undoSupport,
+ final CyEventHelper eventHelper,
+ final CyLayoutAlgorithmManager
layouts,
+ final CyProperty<Properties> p)
+ {
+ this.undoSupport = undoSupport;
+ this.eventHelper = eventHelper;
+ this.layouts = layouts;
+ this.props = p.getProperties();
}
public TaskIterator getTaskIterator() {
- return new TaskIterator(new ApplyPreferredLayoutTask(view,
layouts, props));
+ return new TaskIterator(new
ApplyPreferredLayoutTask(undoSupport, eventHelper, view,
+ layouts,
props));
}
}
Copied:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/LayoutEdit.java
(from rev 26328,
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/ZoomEdit.java)
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/LayoutEdit.java
(rev 0)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/layout/LayoutEdit.java
2011-07-29 20:25:05 UTC (rev 26338)
@@ -0,0 +1,97 @@
+package org.cytoscape.task.internal.layout;
+
+
+import static
org.cytoscape.view.presentation.property.MinimalVisualLexicon.NODE_X_LOCATION;
+import static
org.cytoscape.view.presentation.property.MinimalVisualLexicon.NODE_Y_LOCATION;
+import static
org.cytoscape.view.presentation.property.RichVisualLexicon.NODE_Z_LOCATION;
+import static
org.cytoscape.view.presentation.property.MinimalVisualLexicon.NETWORK_CENTER_X_LOCATION;
+import static
org.cytoscape.view.presentation.property.MinimalVisualLexicon.NETWORK_CENTER_Y_LOCATION;
+import static
org.cytoscape.view.presentation.property.RichVisualLexicon.NETWORK_CENTER_Z_LOCATION;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.util.swing.CyAbstractEdit;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+
+
+/** An undoable edit that will undo and redo the zooming of a network view. */
+final class LayoutEdit extends CyAbstractEdit {
+ private final CyEventHelper eventHelper;
+ private final CyNetworkView view;
+ private List<NodeViewAndLocations> nodeViewsAndLocations;
+ private double networkCenterX;
+ private double networkCenterY;
+ private double networkCenterZ;
+
+ LayoutEdit(final CyEventHelper eventHelper, final CyNetworkView view) {
+ super("Apply Preferred Layout");
+
+ this.eventHelper = eventHelper;
+ this.view = view;
+
+ saveNodeViewsAndLocations();
+ }
+
+ public void redo() {
+ super.redo();
+
+ saveAndRestore();
+ }
+
+ public void undo() {
+ super.undo();
+
+ saveAndRestore();
+ }
+
+ private void saveAndRestore() {
+ final List<NodeViewAndLocations> oldNodeViewsAndLocations =
nodeViewsAndLocations;
+ saveNodeViewsAndLocations();
+ for (final NodeViewAndLocations nodeViewAndLocation :
oldNodeViewsAndLocations)
+ nodeViewAndLocation.restoreLocations();
+
+ view.setVisualProperty(NETWORK_CENTER_X_LOCATION,
networkCenterX);
+ view.setVisualProperty(NETWORK_CENTER_Y_LOCATION,
networkCenterY);
+ view.setVisualProperty(NETWORK_CENTER_Z_LOCATION,
networkCenterZ);
+
+ eventHelper.flushPayloadEvents();
+ view.updateView();
+ }
+
+ private void saveNodeViewsAndLocations() {
+ networkCenterX =
view.getVisualProperty(NETWORK_CENTER_X_LOCATION);
+ networkCenterY =
view.getVisualProperty(NETWORK_CENTER_Y_LOCATION);
+ networkCenterZ =
view.getVisualProperty(NETWORK_CENTER_Z_LOCATION);
+
+ final Collection<View<CyNode>> nodeViews = view.getNodeViews();
+ nodeViewsAndLocations = new
ArrayList<NodeViewAndLocations>(nodeViews.size());
+ for (final View<CyNode> nodeView : nodeViews)
+ nodeViewsAndLocations.add(new
NodeViewAndLocations(nodeView));
+ }
+}
+
+
+final class NodeViewAndLocations {
+ private final View<CyNode> nodeView;
+ private final double xLocation;
+ private final double yLocation;
+ private final double zLocation;
+
+ NodeViewAndLocations(final View<CyNode> nodeView) {
+ this.nodeView = nodeView;
+ xLocation = nodeView.getVisualProperty(NODE_X_LOCATION);
+ yLocation = nodeView.getVisualProperty(NODE_Y_LOCATION);
+ zLocation = nodeView.getVisualProperty(NODE_Z_LOCATION);
+ }
+
+ void restoreLocations() {
+ nodeView.setVisualProperty(NODE_X_LOCATION, xLocation);
+ nodeView.setVisualProperty(NODE_Y_LOCATION, yLocation);
+ nodeView.setVisualProperty(NODE_Z_LOCATION, zLocation);
+ }
+}
Modified:
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
===================================================================
---
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-07-29 20:10:21 UTC (rev 26337)
+++
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
2011-07-29 20:25:05 UTC (rev 26338)
@@ -359,6 +359,8 @@
<bean id="applyPreferredLayoutTaskFactory"
class="org.cytoscape.task.internal.layout.ApplyPreferredLayoutTaskFactory">
+ <constructor-arg ref="undoSupportServiceRef" />
+ <constructor-arg ref="cyEventHelperRef" />
<constructor-arg ref="cyLayoutsServiceRef" />
<constructor-arg ref="cyPropertyServiceRef" />
</bean>
--
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.