Author: ruschein
Date: 2010-08-02 10:03:15 -0700 (Mon, 02 Aug 2010)
New Revision: 21118
Added:
cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesEdit.java
Modified:
cytoscape/trunk/src/main/java/cytoscape/actions/GinyUtils.java
cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesAction.java
Log:
Added undo for hide/show selected nodes.
Modified: cytoscape/trunk/src/main/java/cytoscape/actions/GinyUtils.java
===================================================================
--- cytoscape/trunk/src/main/java/cytoscape/actions/GinyUtils.java
2010-08-02 17:00:59 UTC (rev 21117)
+++ cytoscape/trunk/src/main/java/cytoscape/actions/GinyUtils.java
2010-08-02 17:03:15 UTC (rev 21118)
@@ -68,7 +68,7 @@
}
for (Iterator i = view.getSelectedNodes().iterator();
i.hasNext();) {
- NodeView nview = (NodeView) i.next();
+ final NodeView nview = (NodeView) i.next();
view.hideGraphObject(nview);
}
@@ -85,27 +85,34 @@
return;
}
- for (Iterator i = view.getSelectedNodes().iterator();
i.hasNext();) {
- NodeView nview = (NodeView) i.next();
- view.showGraphObject(nview);
+ for (Iterator i = view.getSelectedNodes().iterator();
i.hasNext(); /* Empty! */) {
+ final NodeView nodeView = (NodeView)i.next();
+ view.showGraphObject(nodeView);
- int[] na =
view.getGraphPerspective().neighborsArray(nview.getGraphPerspectiveIndex());
-
- for (int i2 = 0; i2 < na.length; ++i2) {
- int[] edges = view.getGraphPerspective()
-
.getEdgeIndicesArray(nview.getGraphPerspectiveIndex(), na[i2],
- true,
true);
-
- for (int j = 0; j < edges.length; ++j) {
-
view.showGraphObject(view.getEdgeView(edges[j]));
- }
- }
+ showEdges(view, nodeView);
}
view.updateView();
}
/**
+ * Shows all edges for "nodeView" found that are part of the network
associated with "view".
+ */
+ public static void showEdges(final GraphView view, final NodeView
nodeView) {
+ final int[] neighbours =
+
view.getGraphPerspective().neighborsArray(nodeView.getGraphPerspectiveIndex());
+
+ for (int n = 0; n < neighbours.length; ++n) {
+ final int[] edges =
+
view.getGraphPerspective().getEdgeIndicesArray(nodeView.getGraphPerspectiveIndex(),
+
neighbours[n], true, true);
+
+ for (int j = 0; j < edges.length; ++j)
+
view.showGraphObject(view.getEdgeView(edges[j]));
+ }
+ }
+
+ /**
* DOCUMENT ME!
*
* @param view DOCUMENT ME!
Modified:
cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesAction.java
===================================================================
---
cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesAction.java
2010-08-02 17:00:59 UTC (rev 21117)
+++
cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesAction.java
2010-08-02 17:03:15 UTC (rev 21118)
@@ -1,15 +1,8 @@
/*
File: HideSelectedNodesAction.java
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2010, 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,32 +27,25 @@
along with this library; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-
-//-------------------------------------------------------------------------
-// $Revision$
-// $Date$
-// $Author$
-//-------------------------------------------------------------------------
package cytoscape.actions;
-import cytoscape.Cytoscape;
+import cytoscape.Cytoscape;
import cytoscape.util.CytoscapeAction;
-
+import cytoscape.util.undo.CyUndo;
import cytoscape.view.CyNetworkView;
-//-------------------------------------------------------------------------
+import giny.view.NodeView;
+
import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import javax.swing.AbstractAction;
-
import javax.swing.event.MenuEvent;
-//-------------------------------------------------------------------------
-/**
- *
- */
public class HideSelectedNodesAction extends CytoscapeAction {
static public String MENU_LABEL = "Hide Node Selection";
@@ -74,20 +60,20 @@
/**
* Creates a new HideSelectedNodesAction object.
- *
- * @param label DOCUMENT ME!
*/
public HideSelectedNodesAction(boolean label) {
super();
}
- /**
- * DOCUMENT ME!
- *
- * @param e DOCUMENT ME!
- */
- public void actionPerformed(ActionEvent e) {
- GinyUtils.hideSelectedNodes(Cytoscape.getCurrentNetworkView());
+ public void actionPerformed(final ActionEvent e) {
+ final CyNetworkView view = Cytoscape.getCurrentNetworkView();
+
+ final List<NodeView> hiddenNodeViews = new
ArrayList<NodeView>();
+ for (Iterator i = view.getSelectedNodes().iterator();
i.hasNext(); /* Empty! */)
+ hiddenNodeViews.add((NodeView)i.next());
+ CyUndo.getUndoableEditSupport().postEdit(new
HideSelectedNodesEdit(view, hiddenNodeViews, this));
+
+ GinyUtils.hideSelectedNodes(view);
}
public void menuSelected(MenuEvent e) {
Added:
cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesEdit.java
===================================================================
--- cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesEdit.java
(rev 0)
+++ cytoscape/trunk/src/main/java/cytoscape/actions/HideSelectedNodesEdit.java
2010-08-02 17:03:15 UTC (rev 21118)
@@ -0,0 +1,91 @@
+/*
+ File: HideSelectedNodesEdit.java
+
+ Copyright (c) 2010, 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
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ 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 cytoscape.actions;
+
+
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import giny.view.NodeView;
+
+import cytoscape.Cytoscape;
+import cytoscape.view.CyNetworkView;
+import cytoscape.util.undo.CyAbstractEdit;
+
+
+/**
+ * An undoable edit that will undo and redo hiding of selected nodes.
+ */
+class HideSelectedNodesEdit extends CyAbstractEdit {
+ private static final long serialVersionUID = -1146181528012954334L;
+
+ private final CyNetworkView networkView;
+ private final List<NodeView> hiddenNodeViews;
+ private final HideSelectedNodesAction hideSelectedNodesAction;
+
+ HideSelectedNodesEdit(final CyNetworkView networkView, final
List<NodeView> hiddenNodeViews,
+ final HideSelectedNodesAction
hideSelectedNodesAction)
+ {
+ super(HideSelectedNodesAction.MENU_LABEL);
+
+ this.networkView = networkView;
+ this.hiddenNodeViews = hiddenNodeViews;
+ this.hideSelectedNodesAction = hideSelectedNodesAction;
+ }
+
+ public void redo() {
+ super.redo();
+
+ final CyNetworkView view = Cytoscape.getCurrentNetworkView();
+ final List<NodeView> hiddenNodeViews = new
ArrayList<NodeView>();
+ for (Iterator i = view.getSelectedNodes().iterator();
i.hasNext(); /* Empty! */)
+ hiddenNodeViews.add((NodeView)i.next());
+ GinyUtils.hideSelectedNodes(view);
+
+
+ hideSelectedNodesAction.setEnabled(false);
+ }
+
+ public void undo() {
+ super.undo();
+
+ for (final NodeView nodeView : hiddenNodeViews) {
+ networkView.showGraphObject(nodeView);
+ nodeView.setSelected(true);
+ GinyUtils.showEdges(networkView, nodeView);
+ }
+
+ networkView.updateView();
+
+ hideSelectedNodesAction.setEnabled(true);
+ }
+}
--
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.