Author: ruschein
Date: 2011-07-20 16:34:11 -0700 (Wed, 20 Jul 2011)
New Revision: 26226

Added:
   
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentEdit.java
   
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentEditTest.java
Modified:
   
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTask.java
   
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTaskFactory.java
   
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
   
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskFactoryTest.java
   
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskTest.java
Log:
Added undo/redo capability to fit content.

Copied: 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentEdit.java
 (from rev 26211, 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/title/NetworkTitleEdit.java)
===================================================================
--- 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentEdit.java
                               (rev 0)
+++ 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentEdit.java
       2011-07-20 23:34:11 UTC (rev 26226)
@@ -0,0 +1,44 @@
+package org.cytoscape.task.internal.zoom;
+
+
+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.MinimalVisualLexicon.NETWORK_SCALE_FACTOR;
+
+import org.cytoscape.util.swing.CyAbstractEdit;
+import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.VisualProperty;
+
+
+/** An undoable edit that will undo and redo the fitting of the content of a 
network view. */ 
+final class FitContentEdit extends CyAbstractEdit {
+       private final CyNetworkView view;
+       private final double networkScaleFactor;
+       private final double networkCenterXLocation;
+       private final double networkCenterYLocation;
+
+       FitContentEdit(final CyNetworkView view) {
+               super("Fit Content");
+
+               this.view = view;
+               networkScaleFactor = 
view.getVisualProperty(NETWORK_SCALE_FACTOR);
+               networkCenterXLocation = 
view.getVisualProperty(NETWORK_CENTER_X_LOCATION);
+               networkCenterYLocation = 
view.getVisualProperty(NETWORK_CENTER_Y_LOCATION);
+       }
+
+       public void redo() {
+               super.redo();
+
+               view.fitContent();
+               view.updateView();
+       }
+
+       public void undo() {
+               super.undo();
+
+               view.setVisualProperty(NETWORK_SCALE_FACTOR, 
networkScaleFactor);
+               view.setVisualProperty(NETWORK_CENTER_X_LOCATION, 
networkCenterXLocation);
+               view.setVisualProperty(NETWORK_CENTER_Y_LOCATION, 
networkCenterYLocation);
+               view.updateView();
+       }
+}

Modified: 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTask.java
===================================================================
--- 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTask.java
       2011-07-20 22:29:57 UTC (rev 26225)
+++ 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTask.java
       2011-07-20 23:34:11 UTC (rev 26226)
@@ -1,15 +1,8 @@
 /*
   File: FitContentTask.java
 
-  Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+  Copyright (c) 2006, 2011, The Cytoscape Consortium (www.cytoscape.org)
 
-  The Cytoscape Consortium is:
-  - Institute for Systems Biology
-  - University of California San Diego
-  - Memorial Sloan-Kettering Cancer Center
-  - Institut Pasteur
-  - Agilent Technologies
-
   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
@@ -34,24 +27,26 @@
   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.zoom;
 
 
 import org.cytoscape.task.AbstractNetworkViewTask;
 import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.undo.UndoSupport;
 import org.cytoscape.view.model.CyNetworkView;
 
 
 public class FitContentTask extends AbstractNetworkViewTask {
+       private final UndoSupport undoSupport;
 
-       public FitContentTask(CyNetworkView v) {
+       public FitContentTask(final UndoSupport undoSupport, final 
CyNetworkView v) {
                super(v);
+               this.undoSupport = undoSupport;
        }
 
        public void run(TaskMonitor tm) {
-               // Call utility methods to fire events to redraw presentation.
+               undoSupport.getUndoableEditSupport().postEdit(new 
FitContentEdit(view));
+
                view.fitContent();
        }
-
 }

Modified: 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTaskFactory.java
===================================================================
--- 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTaskFactory.java
        2011-07-20 22:29:57 UTC (rev 26225)
+++ 
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/zoom/FitContentTaskFactory.java
        2011-07-20 23:34:11 UTC (rev 26226)
@@ -1,7 +1,7 @@
 /*
  File: FitContentTaskFactory.java
 
- 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
@@ -26,17 +26,23 @@
  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.zoom;  
 
 
 import org.cytoscape.task.AbstractNetworkViewTaskFactory;  
 import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.undo.UndoSupport;
 
 
 public class FitContentTaskFactory extends AbstractNetworkViewTaskFactory {
+       private final UndoSupport undoSupport;
 
+       public FitContentTaskFactory(final UndoSupport undoSupport) {
+               this.undoSupport = undoSupport;
+       }
+
        public TaskIterator getTaskIterator() {
-               return new TaskIterator(new FitContentTask(view));
+               return new TaskIterator(new FitContentTask(undoSupport, view));
        } 
 }

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-20 22:29:57 UTC (rev 26225)
+++ 
core3/core-task-impl/trunk/src/main/resources/META-INF/spring/bundle-context.xml
    2011-07-20 23:34:11 UTC (rev 26226)
@@ -259,6 +259,7 @@
        </bean>
 
        <bean id="fitContentTaskFactory" 
class="org.cytoscape.task.internal.zoom.FitContentTaskFactory">
+               <constructor-arg ref="undoSupportServiceRef" />
        </bean>
 
        <!-- session -->

Copied: 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentEditTest.java
 (from rev 26222, 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/ZoomEditTest.java)
===================================================================
--- 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentEditTest.java
                           (rev 0)
+++ 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentEditTest.java
   2011-07-20 23:34:11 UTC (rev 26226)
@@ -0,0 +1,37 @@
+package org.cytoscape.task.internal.zoom;
+
+
+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.MinimalVisualLexicon.NETWORK_SCALE_FACTOR;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.cytoscape.view.model.CyNetworkView;
+
+import org.junit.Test;
+
+
+public class FitContentEditTest {
+       @Test
+       public void runTest() {
+               final CyNetworkView view = mock(CyNetworkView.class);
+               
when(view.getVisualProperty(NETWORK_SCALE_FACTOR)).thenReturn(2.0);
+               
when(view.getVisualProperty(NETWORK_CENTER_X_LOCATION)).thenReturn(100.0);
+               
when(view.getVisualProperty(NETWORK_CENTER_Y_LOCATION)).thenReturn(400.0);
+
+               final FitContentEdit zoomEdit = new FitContentEdit(view);
+               
when(view.getVisualProperty(NETWORK_SCALE_FACTOR)).thenReturn(1.0);
+               
when(view.getVisualProperty(NETWORK_CENTER_X_LOCATION)).thenReturn(200.0);
+               
when(view.getVisualProperty(NETWORK_CENTER_Y_LOCATION)).thenReturn(300.0);
+               zoomEdit.undo();
+               verify(view, times(1)).setVisualProperty(NETWORK_SCALE_FACTOR, 
Double.valueOf(2.0));
+               verify(view, 
times(1)).setVisualProperty(NETWORK_CENTER_X_LOCATION, Double.valueOf(100.0));
+               verify(view, 
times(1)).setVisualProperty(NETWORK_CENTER_Y_LOCATION, Double.valueOf(400.0));
+               zoomEdit.redo();
+               verify(view, times(1)).fitContent();
+       }
+}

Modified: 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskFactoryTest.java
===================================================================
--- 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskFactoryTest.java
    2011-07-20 22:29:57 UTC (rev 26225)
+++ 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskFactoryTest.java
    2011-07-20 23:34:11 UTC (rev 26226)
@@ -1,22 +1,29 @@
 package org.cytoscape.task.internal.zoom;
 
+
+import javax.swing.undo.UndoableEditSupport;
+
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskFactory;
 import org.cytoscape.work.TaskIterator;
+import org.cytoscape.work.undo.UndoSupport;
 import org.cytoscape.task.internal.zoom.FitContentTaskFactory;
 import org.junit.Test;
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
+
 public class FitContentTaskFactoryTest {
-
        @Test
        public void testGetTaskIterator() {
-               
                CyNetworkView view = mock(CyNetworkView.class);
                
-               FitContentTaskFactory factory = new FitContentTaskFactory();
+               UndoableEditSupport undoableEditSupport = 
mock(UndoableEditSupport.class);
+               UndoSupport undoSupport = mock(UndoSupport.class);
+               
when(undoSupport.getUndoableEditSupport()).thenReturn(undoableEditSupport);
+
+               FitContentTaskFactory factory = new 
FitContentTaskFactory(undoSupport);
                factory.setNetworkView(view);
                
                TaskIterator ti = factory.getTaskIterator();
@@ -26,5 +33,4 @@
                Task t = ti.next();
                assertNotNull( t );             
        }
-       
 }

Modified: 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskTest.java
===================================================================
--- 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskTest.java
   2011-07-20 22:29:57 UTC (rev 26225)
+++ 
core3/core-task-impl/trunk/src/test/java/org/cytoscape/task/internal/zoom/FitContentTaskTest.java
   2011-07-20 23:34:11 UTC (rev 26226)
@@ -1,24 +1,39 @@
 package org.cytoscape.task.internal.zoom;
 
+
+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.MinimalVisualLexicon.NETWORK_SCALE_FACTOR;
+
+import javax.swing.undo.UndoableEditSupport;
+
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskFactory;
 import org.cytoscape.work.TaskIterator;
 import org.cytoscape.work.TaskMonitor;
+import org.cytoscape.work.undo.UndoSupport;
 import org.cytoscape.task.internal.zoom.FitContentTaskFactory;
 import org.junit.Test;
 
 import static org.mockito.Mockito.*;
 
+
 public class FitContentTaskTest {
-
        @Test
        public void testRun() throws Exception {
                CyNetworkView view = mock(CyNetworkView.class);
+               
when(view.getVisualProperty(NETWORK_SCALE_FACTOR)).thenReturn(Double.valueOf(1.0));
+               
when(view.getVisualProperty(NETWORK_CENTER_X_LOCATION)).thenReturn(Double.valueOf(2.0));
+               
when(view.getVisualProperty(NETWORK_CENTER_Y_LOCATION)).thenReturn(Double.valueOf(3.0));
                                
                TaskMonitor tm = mock(TaskMonitor.class);
                
-               FitContentTask t = new FitContentTask(view);
+               UndoableEditSupport undoableEditSupport = 
mock(UndoableEditSupport.class);
+               UndoSupport undoSupport = mock(UndoSupport.class);
+               
when(undoSupport.getUndoableEditSupport()).thenReturn(undoableEditSupport);
+                               
+               FitContentTask t = new FitContentTask(undoSupport, view);
                
                t.run(tm);
                
@@ -31,7 +46,11 @@
                                
                TaskMonitor tm = mock(TaskMonitor.class);
                
-               FitContentTask t = new FitContentTask(view);
+               UndoableEditSupport undoableEditSupport = 
mock(UndoableEditSupport.class);
+               UndoSupport undoSupport = mock(UndoSupport.class);
+               
when(undoSupport.getUndoableEditSupport()).thenReturn(undoableEditSupport);
+                               
+               FitContentTask t = new FitContentTask(undoSupport, view);
                
                t.run(tm);
        }

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