Author: kono
Date: 2012-11-08 12:23:51 -0800 (Thu, 08 Nov 2012)
New Revision: 30760
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
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTask.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTaskFactoryImpl.java
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayoutTask.java
Log:
refs #1553 FitContent() removed for performance.
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-11-08 01:26:16 UTC (rev 30759)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutTask.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -1,12 +1,10 @@
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;
@@ -21,18 +19,20 @@
import org.slf4j.LoggerFactory;
/**
- * This is a basic implementation of a LayoutAlgorithm Task that does
- * some bookkeeping, but primarily delegates to the doLayout() method.
- * Extensions of this class are meant to operate on the CyNetworkView
- * provided to the constructor (and is available as a protected member
- * variable).
- * @CyAPI.Abstract.Class
+ * This is a basic implementation of a LayoutAlgorithm Task that does some
+ * bookkeeping, but primarily delegates to the doLayout() method. Extensions of
+ * this class are meant to operate on the CyNetworkView provided to the
+ * constructor (and is available as a protected member variable).
+ *
+ * @CyAPI.Abstract.Class
*/
public abstract class AbstractLayoutTask extends AbstractTask {
-
+
private static final Logger logger =
LoggerFactory.getLogger(AbstractLayoutTask.class);
+
+ // Short name of this algorithm
private final String name;
-
+
/**
* The table column name that provides the layout algorithm name.
*/
@@ -42,40 +42,43 @@
* The network view that the layout will be applied to.
*/
protected final CyNetworkView networkView;
-
+
/**
* The node views that will be laid out by the algorithm.
*/
protected final Set<View<CyNode>> nodesToLayOut;
-
- /**
+
+ /**
* The attribute to be used for this layout. May be null and/or ignored.
*/
protected final String layoutAttribute;
-
+
/**
* Undo support for the task.
*/
protected final UndoSupport undo;
-
+
/**
* Determines whether the resulting set of nodes should be moved back to
- * their original centroid after being laid out.
+ * their original centroid after being laid out.
*/
protected boolean recenter = true;
-
+
/**
* Constructor.
- * @param name The name of the layout algorithm.
- * @param networkView The network view that the layout algorithm will
be applied to.
- * @param nodesToLayOut The set of nodes to be laid out.
- * @param layoutAttribute The name of the attribute to use for the
layout. May be null or empty.
+ *
+ * @param name
+ * The name of the layout algorithm.
+ * @param networkView
+ * The network view that the layout algorithm will be
applied to.
+ * @param nodesToLayOut
+ * The set of nodes to be laid out.
+ * @param layoutAttribute
+ * The name of the attribute to use for the layout. May be
null
+ * or empty.
*/
- public AbstractLayoutTask(String name,
- CyNetworkView networkView,
- Set<View<CyNode>> nodesToLayOut,
- String layoutAttribute,
- UndoSupport undo) {
+ public AbstractLayoutTask(final String name, final CyNetworkView
networkView,
+ final Set<View<CyNode>> nodesToLayOut, final String
layoutAttribute, final UndoSupport undo) {
super();
this.networkView = networkView;
@@ -84,10 +87,9 @@
if (nodesToLayOut.size() == 0) {
this.nodesToLayOut = new HashSet<View<CyNode>>();
- for (View<CyNode> view : networkView.getNodeViews()) {
- if
(view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE)) {
+ for (final View<CyNode> view :
networkView.getNodeViews()) {
+ if
(view.getVisualProperty(BasicVisualLexicon.NODE_VISIBLE))
this.nodesToLayOut.add(view);
- }
}
} else {
this.nodesToLayOut =
Collections.unmodifiableSet(nodesToLayOut);
@@ -95,7 +97,7 @@
this.layoutAttribute = layoutAttribute;
}
-
+
/**
* {@inheritDoc}
*/
@@ -109,21 +111,16 @@
return;
final CyNetwork network = networkView.getModel();
-
if (nodesToLayOut.size() == 0 &&
networkView.getNodeViews().size() == 0)
return;
-
- if ( undo != null )
- undo.postEdit(new LayoutEdit(name,networkView));
-
- // Clear Edge Bends.
- clearEdgeBends();
+ if (undo != null)
+ undo.postEdit(new LayoutEdit(name, networkView));
+
LayoutPoint centroid = null;
- if (recenter) {
+ if (recenter)
centroid = computeCentroid();
- }
-
+
// this is overridden by children and does the actual layout
doLayout(taskMonitor);
@@ -131,20 +128,19 @@
LayoutPoint newCentroid = computeCentroid();
translateNodes(new LayoutPoint(centroid.getX() -
newCentroid.getX(), centroid.getY() - newCentroid.getY()));
}
-
- // Fit Content method always redraw the presentation.
- networkView.fitContent();
// update the __layoutAlgorithm attribute
- final CyRow networkAttributes =
network.getRow(network,CyNetwork.HIDDEN_ATTRS);
+ final CyRow networkAttributes = network.getRow(network,
CyNetwork.HIDDEN_ATTRS);
final CyTable netAttrsTable = networkAttributes.getTable();
+
if (netAttrsTable.getColumn(LAYOUT_ALGORITHM) == null)
netAttrsTable.createColumn(LAYOUT_ALGORITHM,
String.class, true);
+
networkAttributes.set(LAYOUT_ALGORITHM, name);
logger.debug("Layout finished in " +
(System.currentTimeMillis() - start) + " msec.");
}
-
+
private void translateNodes(LayoutPoint translation) {
Collection<View<CyNode>> views;
if (nodesToLayOut.size() == 0) {
@@ -152,7 +148,7 @@
} else {
views = nodesToLayOut;
}
-
+
for (View<CyNode> view : views) {
double x =
view.getVisualProperty(BasicVisualLexicon.NODE_X_LOCATION);
double y =
view.getVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION);
@@ -168,7 +164,7 @@
} else {
views = nodesToLayOut;
}
-
+
double x = 0;
double y = 0;
double total = 0;
@@ -184,24 +180,11 @@
}
/**
- * Clears edge bend values ASSIGNED TO EACH EDGE.
- * Default Edge Bend value will not be cleared.
+ * This method is designed to actually encapsulate the layout
algorithm. It
+ * will be called from within the run() method of the task.
*
- * TODO: should we clear mapping, too?
+ * @param taskMonitor
+ * Provided to allow updates to the task status.
*/
- 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
- * called from within the run() method of the task.
- * @param taskMonitor Provided to allow updates to the task status.
- */
protected abstract void doLayout(final TaskMonitor taskMonitor);
}
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-11-08 01:26:16 UTC (rev 30759)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdit.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -1,6 +1,5 @@
package org.cytoscape.view.layout;
-
import static
org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_X_LOCATION;
import static
org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_Y_LOCATION;
import static
org.cytoscape.view.presentation.property.BasicVisualLexicon.NODE_Z_LOCATION;
@@ -23,15 +22,15 @@
import org.cytoscape.view.presentation.property.values.Bend;
import org.cytoscape.work.undo.AbstractCyEdit;
-
-/**
- * An undoable edit that will undo and redo of a layout algorithm applied to a
network view.
+/**
+ * An undoable edit that will undo and redo of a layout algorithm applied to a
+ * network view.
*/
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;
@@ -56,7 +55,7 @@
public void redo() {
saveAndRestore();
}
-
+
@Override
public void undo() {
saveAndRestore();
@@ -69,13 +68,13 @@
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())
+ for (View<CyEdge> edgeView : oldEdgeBends.keySet())
edgeView.setVisualProperty(EDGE_BEND,
oldEdgeBends.get(edgeView));
view.setVisualProperty(NETWORK_SCALE_FACTOR, oldNetworkScale);
@@ -97,18 +96,16 @@
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));
}
-
}
}
-
final class NodeViewAndLocations {
private final View<CyNode> nodeView;
private final double xLocation;
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTask.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTask.java
2012-11-08 01:26:16 UTC (rev 30759)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTask.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -100,11 +100,13 @@
taskMonitor.setTitle("Creating Network View");
taskMonitor.setStatusMessage("Creating network view...");
+ final VisualStyle style = vmm.getCurrentVisualStyle(); // get
the current style before registering the view!
+
int i = 0;
int viewCount = networks.size();
for (final CyNetwork n : networks) {
if (netViewMgr.getNetworkViews(n).isEmpty()) {
- createView(n);
+ createView(n, style);
taskMonitor.setStatusMessage("Network view
successfully created for: "
+
n.getRow(n).get(CyNetwork.NAME, String.class));
i++;
@@ -115,14 +117,12 @@
taskMonitor.setProgress(1.0);
}
- private final void createView(CyNetwork network) throws Exception {
+ private final void createView(final CyNetwork network, final
VisualStyle style) throws Exception {
final long start = System.currentTimeMillis();
try {
- // By calling this task, actual view will be created
even if it's a
- // large network.
+ // By calling this task, actual view will be created
even if it's a large network.
final CyNetworkView view =
viewFactory.createNetworkView(network);
- final VisualStyle style = vmm.getCurrentVisualStyle();
// get the current style before registering the view!
netViewMgr.addNetworkView(view);
// Apply visual style
@@ -133,17 +133,14 @@
// If a source view has been provided, use that to set
the X/Y positions of the
// nodes along with the visual style.
- if (sourceView != null)
+ if (sourceView != null) {
insertTasksAfterCurrentTask(new
CopyExistingViewTask(vmm, renderingEngineMgr, view, sourceView,
null, null, true));
-
- // Otherwise check if layouts have been provided.
- else if (layoutMgr != null) {
+ } else if (layoutMgr != null) {
final Set<CyNetworkView> views = new
HashSet<CyNetworkView>();
views.add(view);
insertTasksAfterCurrentTask(new
ApplyPreferredLayoutTask(views, layoutMgr));
}
-
} catch (Exception e) {
throw new Exception("Could not create network view for
network: "
+
network.getRow(network).get(CyNetwork.NAME, String.class), e);
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTaskFactoryImpl.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTaskFactoryImpl.java
2012-11-08 01:26:16 UTC (rev 30759)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/creation/CreateNetworkViewTaskFactoryImpl.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -26,10 +26,9 @@
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.creation;
-
import java.util.Collection;
import org.cytoscape.event.CyEventHelper;
@@ -44,9 +43,9 @@
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.undo.UndoSupport;
+public class CreateNetworkViewTaskFactoryImpl extends
AbstractNetworkCollectionTaskFactory implements
+ CreateNetworkViewTaskFactory {
-public class CreateNetworkViewTaskFactoryImpl extends
AbstractNetworkCollectionTaskFactory implements CreateNetworkViewTaskFactory {
-
private final UndoSupport undoSupport;
private final CyNetworkViewManager netViewMgr;
private final CyNetworkViewFactory viewFactory;
@@ -55,23 +54,19 @@
private final VisualMappingManager vmm;
private final RenderingEngineManager renderingEngineMgr;
- public CreateNetworkViewTaskFactoryImpl(final UndoSupport undoSupport,
-
final CyNetworkViewFactory viewFactory,
-
final CyNetworkViewManager netViewMgr,
-
final CyLayoutAlgorithmManager layoutMgr,
-
final CyEventHelper eventHelper,
-
final VisualMappingManager vmm,
-
final RenderingEngineManager renderingEngineMgr) {
- this.undoSupport = undoSupport;
- this.viewFactory = viewFactory;
- this.netViewMgr = netViewMgr;
- this.layoutMgr = layoutMgr;
- this.eventHelper = eventHelper;
- this.vmm = vmm;
+ public CreateNetworkViewTaskFactoryImpl(final UndoSupport undoSupport,
final CyNetworkViewFactory viewFactory,
+ final CyNetworkViewManager netViewMgr, final
CyLayoutAlgorithmManager layoutMgr,
+ final CyEventHelper eventHelper, final
VisualMappingManager vmm,
+ final RenderingEngineManager renderingEngineMgr) {
+ this.undoSupport = undoSupport;
+ this.viewFactory = viewFactory;
+ this.netViewMgr = netViewMgr;
+ this.layoutMgr = layoutMgr;
+ this.eventHelper = eventHelper;
+ this.vmm = vmm;
this.renderingEngineMgr = renderingEngineMgr;
}
-
@Override
public TaskIterator createTaskIterator(final Collection<CyNetwork>
networks) {
// Create visualization + layout (optional)
@@ -85,11 +80,11 @@
@Override
public boolean isReady(final Collection<CyNetwork> networks) {
- for (CyNetwork n : networks)
- if (!netViewMgr.getNetworkViews(n).isEmpty())
- return false;
-
- return true;
+ for (CyNetwork n : networks)
+ if (!netViewMgr.getNetworkViews(n).isEmpty())
+ return false;
+
+ return true;
}
}
Modified:
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
===================================================================
---
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
2012-11-08 01:26:16 UTC (rev 30759)
+++
core3/impl/trunk/core-task-impl/src/main/java/org/cytoscape/task/internal/layout/ApplyPreferredLayoutTask.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -30,10 +30,15 @@
import java.util.Collection;
import java.util.Properties;
+import org.cytoscape.model.CyEdge;
import org.cytoscape.task.AbstractNetworkViewCollectionTask;
import org.cytoscape.view.layout.CyLayoutAlgorithm;
import org.cytoscape.view.layout.CyLayoutAlgorithmManager;
import org.cytoscape.view.model.CyNetworkView;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.presentation.property.BasicVisualLexicon;
+import org.cytoscape.work.AbstractTask;
+import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.TaskMonitor;
public class ApplyPreferredLayoutTask extends
AbstractNetworkViewCollectionTask {
@@ -69,16 +74,57 @@
tm.setProgress(0.2d);
final CyLayoutAlgorithm layout =
layouts.getLayout(pref);
if (layout != null) {
-
insertTasksAfterCurrentTask(layout.createTaskIterator(view,
layout.getDefaultLayoutContext(),
-
CyLayoutAlgorithm.ALL_NODE_VIEWS, ""));
+ clearEdgeBends(view);
+ final TaskIterator itr =
layout.createTaskIterator(view, layout.getDefaultLayoutContext(),
+
CyLayoutAlgorithm.ALL_NODE_VIEWS, "");
+ insertTasksAfterCurrentTask(new
UpdateViewTask(view));
+ insertTasksAfterCurrentTask(itr);
+
} else {
throw new IllegalArgumentException("Couldn't
find layout algorithm: " + pref);
}
-
+
i++;
tm.setProgress((i / (double) viewCount));
}
-
+
tm.setProgress(1.0);
}
+
+ /**
+ * 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 CyNetworkView networkView) {
+ final Collection<View<CyEdge>> edgeViews =
networkView.getEdgeViews();
+ if (edgeViews.isEmpty())
+ return;
+
+ final View<CyEdge> first = edgeViews.iterator().next();
+ if (first.isSet(BasicVisualLexicon.EDGE_BEND) == false)
+ return;
+
+ for (final View<CyEdge> edgeView : edgeViews) {
+
edgeView.setVisualProperty(BasicVisualLexicon.EDGE_BEND, null);
+ edgeView.clearValueLock(BasicVisualLexicon.EDGE_BEND);
+ }
+ }
+
+ /**
+ * Simply updates the network view.
+ */
+ private final class UpdateViewTask extends AbstractTask {
+ private final CyNetworkView view;
+
+ UpdateViewTask(final CyNetworkView view) {
+ this.view = view;
+ }
+
+ @Override
+ public void run(TaskMonitor taskMonitor) throws Exception {
+ view.updateView();
+ }
+ }
}
Modified:
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
===================================================================
---
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
2012-11-08 01:26:16 UTC (rev 30759)
+++
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -26,10 +26,9 @@
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.view.layout.internal.algorithms;
-
import java.util.Set;
import org.cytoscape.model.CyNode;
@@ -40,30 +39,31 @@
import org.cytoscape.work.TaskIterator;
import org.cytoscape.work.undo.UndoSupport;
-
/**
- * The GridNodeLayout provides a very simple layout, suitable as
- * the default layout for Cytoscape data readers.
+ * The GridNodeLayout provides a very simple layout, suitable as the default
+ * layout for Cytoscape data readers.
*/
public class GridNodeLayout extends AbstractLayoutAlgorithm {
-
+
/**
* Creates a new GridNodeLayout object.
*/
public GridNodeLayout(UndoSupport undoSupport) {
- super(CyLayoutAlgorithmManager.DEFAULT_LAYOUT_NAME,"Grid
Layout", undoSupport);
+ super(CyLayoutAlgorithmManager.DEFAULT_LAYOUT_NAME, "Grid
Layout", undoSupport);
}
@Override
- public TaskIterator createTaskIterator(CyNetworkView networkView,
Object context, Set<View<CyNode>> nodesToLayOut, String attrName) {
- return new TaskIterator(new GridNodeLayoutTask(getName(),
networkView, nodesToLayOut, (GridNodeLayoutContext)context, attrName,
undoSupport));
+ public TaskIterator createTaskIterator(CyNetworkView networkView,
Object context, Set<View<CyNode>> nodesToLayOut,
+ String attrName) {
+ return new TaskIterator(new GridNodeLayoutTask(getName(),
networkView, nodesToLayOut,
+ (GridNodeLayoutContext) context, attrName,
undoSupport));
}
-
+
@Override
public Object createLayoutContext() {
return new GridNodeLayoutContext();
}
-
+
@Override
public boolean getSupportsSelectedOnly() {
return true;
Modified:
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayoutTask.java
===================================================================
---
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayoutTask.java
2012-11-08 01:26:16 UTC (rev 30759)
+++
core3/impl/trunk/layout-impl/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayoutTask.java
2012-11-08 20:23:51 UTC (rev 30760)
@@ -60,6 +60,7 @@
this.nodeVerticalSpacing = context.nodeVerticalSpacing;
this.nodeHorizontalSpacing = context.nodeHorizontalSpacing;
+ this.recenter = false;
}
/**
--
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.