Author: jm
Date: 2012-01-05 15:14:25 -0800 (Thu, 05 Jan 2012)
New Revision: 27932
Added:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutEdit.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTask.java
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTaskFactory.java
Log:
Added more forgotten classes
Added:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutEdit.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutEdit.java
(rev 0)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/LayoutEdit.java
2012-01-05 23:14:25 UTC (rev 27932)
@@ -0,0 +1,101 @@
+package org.cytoscape.internal.layout.ui;
+
+
+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 static
org.cytoscape.view.presentation.property.MinimalVisualLexicon.NETWORK_SCALE_FACTOR;
+
+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.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+import org.cytoscape.work.undo.AbstractCyEdit;
+
+
+/** An undoable edit that will undo and redo the zooming of a network view. */
+final class LayoutEdit extends AbstractCyEdit {
+ private final CyEventHelper eventHelper;
+ private final CyNetworkView view;
+ private List<NodeViewAndLocations> nodeViewsAndLocations;
+ private double networkScale;
+ private double networkCenterX;
+ private double networkCenterY;
+ private double networkCenterZ;
+
+ LayoutEdit(String name, final CyEventHelper eventHelper, final
CyNetworkView view) {
+ super(name);
+
+ this.eventHelper = eventHelper;
+ this.view = view;
+
+ saveNodeViewsAndLocations();
+ }
+
+ public void redo() {
+ saveAndRestore();
+ }
+
+ public void undo() {
+ saveAndRestore();
+ }
+
+ private void saveAndRestore() {
+ final List<NodeViewAndLocations> oldNodeViewsAndLocations =
nodeViewsAndLocations;
+ final double oldNetworkScale = networkScale;
+ final double oldNetworkCenterX = networkCenterX;
+ final double oldNetworkCenterY = networkCenterY;
+ final double oldNetworkCenterZ = networkCenterZ;
+ saveNodeViewsAndLocations();
+ for (final NodeViewAndLocations nodeViewAndLocation :
oldNodeViewsAndLocations)
+ nodeViewAndLocation.restoreLocations();
+
+ view.setVisualProperty(NETWORK_SCALE_FACTOR, oldNetworkScale);
+ view.setVisualProperty(NETWORK_CENTER_X_LOCATION,
oldNetworkCenterX);
+ view.setVisualProperty(NETWORK_CENTER_Y_LOCATION,
oldNetworkCenterY);
+ view.setVisualProperty(NETWORK_CENTER_Z_LOCATION,
oldNetworkCenterZ);
+
+ eventHelper.flushPayloadEvents();
+ view.updateView();
+ }
+
+ private void saveNodeViewsAndLocations() {
+ networkScale = view.getVisualProperty(NETWORK_SCALE_FACTOR);
+ 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);
+ }
+}
Added:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTask.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTask.java
(rev 0)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTask.java
2012-01-05 23:14:25 UTC (rev 27932)
@@ -0,0 +1,31 @@
+package org.cytoscape.internal.layout.ui;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.undo.UndoSupport;
+
+public class UndoSupportTask implements Task {
+
+ private String name;
+ private UndoSupport undo;
+ private CyEventHelper eventHelper;
+ private CyNetworkView view;
+
+ public UndoSupportTask(String name, UndoSupport undo, CyEventHelper
eventHelper, CyNetworkView view) {
+ this.name = name;
+ this.undo = undo;
+ this.eventHelper = eventHelper;
+ this.view = view;
+ }
+
+ @Override
+ public void run(TaskMonitor taskMonitor) throws Exception {
+ undo.postEdit(new LayoutEdit(name, eventHelper, view));
+ }
+
+ @Override
+ public void cancel() {
+ }
+}
Added:
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTaskFactory.java
===================================================================
---
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTaskFactory.java
(rev 0)
+++
core3/impl/trunk/swing-application-impl/src/main/java/org/cytoscape/internal/layout/ui/UndoSupportTaskFactory.java
2012-01-05 23:14:25 UTC (rev 27932)
@@ -0,0 +1,42 @@
+package org.cytoscape.internal.layout.ui;
+
+import org.cytoscape.event.CyEventHelper;
+import org.cytoscape.task.NetworkViewTaskFactory;
+import org.cytoscape.view.layout.AbstractLayoutAlgorithm;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.work.Task;
+import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.undo.UndoSupport;
+
+public class UndoSupportTaskFactory extends AbstractLayoutAlgorithm {
+
+ private NetworkViewTaskFactory delegate;
+ private UndoSupport undo;
+ private CyEventHelper eventHelper;
+ private String name;
+
+ public UndoSupportTaskFactory(AbstractLayoutAlgorithm delegate,
UndoSupport undo, CyEventHelper eventHelper) {
+ super(undo, delegate.getName(), delegate.toString(),
delegate.supportsSelectedOnly());
+ this.name = delegate.toString();
+ this.undo = undo;
+ this.delegate = delegate;
+ this.eventHelper = eventHelper;
+ }
+
+ @Override
+ public TaskIterator createTaskIterator() {
+ TaskIterator source = delegate.createTaskIterator();
+ Task[] tasks = new Task[source.getNumTasks() + 1];
+ tasks[0] = new UndoSupportTask(name, undo, eventHelper,
networkView);
+ for (int i = 1; i < tasks.length; i++) {
+ tasks[i] = source.next();
+ }
+ return new TaskIterator(tasks.length, tasks);
+ }
+
+ @Override
+ public void setNetworkView(CyNetworkView netView) {
+ super.setNetworkView(netView);
+ delegate.setNetworkView(netView);
+ }
+}
--
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.