Author: kono
Date: 2012-03-09 16:36:07 -0800 (Fri, 09 Mar 2012)
New Revision: 28479
Added:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/Point.java
Modified:
core3/api/trunk/layout-api/pom.xml
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutAlgorithm.java
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualMappingFunctionFactory.java
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutFRAlgorithmTask.java
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutKKAlgorithmTask.java
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
Log:
refs #751 AWT/Swing dependency had been removed from layout-api.
Modified: core3/api/trunk/layout-api/pom.xml
===================================================================
--- core3/api/trunk/layout-api/pom.xml 2012-03-10 00:14:30 UTC (rev 28478)
+++ core3/api/trunk/layout-api/pom.xml 2012-03-10 00:36:07 UTC (rev 28479)
@@ -13,7 +13,6 @@
</properties>
<modelVersion>4.0.0</modelVersion>
- <groupId>org.cytoscape</groupId>
<artifactId>layout-api</artifactId>
<name>${bundle.symbolicName}</name>
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutAlgorithm.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutAlgorithm.java
2012-03-10 00:14:30 UTC (rev 28478)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractLayoutAlgorithm.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -30,23 +30,19 @@
package org.cytoscape.view.layout;
-import java.awt.Dimension;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.cytoscape.model.CyColumn;
import org.cytoscape.model.CyNetwork;
import org.cytoscape.model.CyNode;
-import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyTableUtil;
-import org.cytoscape.model.CyColumn;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
-import org.cytoscape.work.TaskMonitor;
-import org.cytoscape.work.undo.UndoSupport;
import org.cytoscape.work.Tunable;
+import org.cytoscape.work.undo.UndoSupport;
import org.cytoscape.work.util.ListSingleSelection;
@@ -54,101 +50,16 @@
* The AbstractLayoutAlgorithm provides a basic implementation of a layout
TaskFactory.
* @CyAPI.Abstract.Class
*/
-abstract public class AbstractLayoutAlgorithm implements CyLayoutAlgorithm {
+public abstract class AbstractLayoutAlgorithm implements CyLayoutAlgorithm {
- private ListSingleSelection<String> submenuDef;
-
private static final String ALL_NODES = " All Nodes";
private static final String SELECTED_NODES_ONLY = " Selected Nodes
Only";
private static final String NODE_PREFIX = "(Node) ";
private static final String EDGE_PREFIX = "(Edge) ";
-
- /**
- * Never use this method from within a layout to access the submenu
options,
- * instead call the configureLayoutFromSubmenuSelection() method to
configure
- * the layout based on menu selection.
- * @return The list single selection object that specifies the submenu
- * names to be used for generating selection submenus.
- */
- @Tunable(description="Apply to")
- public ListSingleSelection<String> getSubmenuOptions() {
-
- List<String> possibleValues = new ArrayList<String>();
-
- Set<Class<?>> nodeAttrTypes = supportsNodeAttributes();
- Set<Class<?>> edgeAttrTypes = supportsEdgeAttributes();
-
- if ( nodeAttrTypes != null && !nodeAttrTypes.isEmpty() ) {
- for (final CyColumn column :
network.getDefaultNodeTable().getColumns())
- if (nodeAttrTypes.contains(column.getType()))
- possibleValues.add(NODE_PREFIX +
column.getName());
- } else if ( edgeAttrTypes != null && !edgeAttrTypes.isEmpty() )
{
- for (final CyColumn column :
network.getDefaultEdgeTable().getColumns())
- if (edgeAttrTypes.contains(column.getType()))
- possibleValues.add(EDGE_PREFIX +
column.getName());
- }
+ private ListSingleSelection<String> submenuDef;
- int numSelected = CyTableUtil.getNodesInState(network,
CyNetwork.SELECTED, true).size();
- if (supportsSelectedOnly() && numSelected > 0) {
-
- if ( possibleValues.isEmpty() ) {
- possibleValues.add(ALL_NODES);
- possibleValues.add(SELECTED_NODES_ONLY);
- } else {
- List<String> newPossibleValues = new
ArrayList<String>();
- for ( String pv : possibleValues ) {
- newPossibleValues.add(pv + ALL_NODES);
- newPossibleValues.add(pv +
SELECTED_NODES_ONLY);
- }
- possibleValues = newPossibleValues;
- }
- }
-
-// if ( possibleValues.isEmpty() )
-// possibleValues.add( humanName );
-
- submenuDef = new ListSingleSelection<String>( possibleValues );
- if (possibleValues.size() > 0) {
- submenuDef.setSelectedValue(possibleValues.get(0));
- }
- return submenuDef;
- }
-
/**
- * This method is a no-op. Don't use it.
- */
- public void setSubmenuOptions(ListSingleSelection<String> opts) {
- // no-op
- }
-
- /**
- *
- */
- protected void configureLayoutFromSubmenuSelection() {
- String selectedMenu = submenuDef.getSelectedValue();
-
- if ( selectedMenu == null || selectedMenu == "" )
- return;
-
- setSelectedOnly( selectedMenu.endsWith(SELECTED_NODES_ONLY) );
-
- if ( selectedMenu.endsWith( ALL_NODES ) )
- selectedMenu = selectedMenu.replaceFirst( ALL_NODES, ""
);
- if ( selectedMenu.endsWith( SELECTED_NODES_ONLY ) )
- selectedMenu = selectedMenu.replaceFirst(
SELECTED_NODES_ONLY, "" );
-
-
- if ( selectedMenu.startsWith( NODE_PREFIX ) )
- selectedMenu = selectedMenu.replaceFirst( NODE_PREFIX,
"" );
- if ( selectedMenu.startsWith( EDGE_PREFIX ) )
- selectedMenu = selectedMenu.replaceFirst( EDGE_PREFIX,
"" );
-
- if ( selectedMenu.length() > 0 )
- setLayoutAttribute(selectedMenu);
- }
-
- /**
* The network view that the layout will be applied to.
*/
protected CyNetworkView networkView;
@@ -163,7 +74,6 @@
* The UndoSupport object use for allowing undo of layouts.
*/
protected final UndoSupport undo;
-// private ViewChangeEdit undoableEdit;
/**
* The set of nodes that are
@@ -176,12 +86,14 @@
protected boolean selectedOnly;
private final boolean supportsSelectedOnly;
- private String edgeAttribute = null;
- private String nodeAttribute = null;
- private Dimension currentSize = new Dimension(20, 20);
private final String humanName;
private final String computerName;
+
+ // TODO: are these necessary?
+ private String nodeAttribute;
+ private String edgeAttribute;
+
/**
* The Constructor.
* @param undo the UndoSupport object used for allowing undo of layouts.
@@ -207,7 +119,6 @@
double node_count = (double) network.getNodeCount();
node_count = Math.sqrt(node_count);
node_count *= 100;
- currentSize = new Dimension((int) node_count, (int) node_count);
}
/**
@@ -217,11 +128,10 @@
* @param attributeName The name of the attribute
*/
public void setLayoutAttribute(String attributeName) {
- if (supportsNodeAttributes().size() > 0) {
+ if (supportsNodeAttributes().size() > 0)
nodeAttribute = attributeName;
- } else if (supportsEdgeAttributes().size() > 0) {
+ else if (supportsEdgeAttributes().size() > 0)
edgeAttribute = attributeName;
- }
}
/**
@@ -267,6 +177,7 @@
* @return the list of supported attribute types, or null
* if node attributes are not supported
*/
+ @Override
public Set<Class<?>> supportsNodeAttributes() {
return new HashSet<Class<?>>();
}
@@ -279,6 +190,7 @@
* @return the list of supported attribute types, or null
* if edge attributes are not supported
*/
+ @Override
public Set<Class<?>> supportsEdgeAttributes() {
return new HashSet<Class<?>>();
}
@@ -292,6 +204,7 @@
*
* @return A (possibly empty) list of attributes
*/
+ @Override
public List<String> getInitialAttributeList() {
return new ArrayList<String>();
}
@@ -309,4 +222,75 @@
staticNodes.add(nodeView);
}
}
+
+
+ /**
+ * Never use this method from within a layout to access the submenu
options,
+ * instead call the configureLayoutFromSubmenuSelection() method to
configure
+ * the layout based on menu selection.
+ * @return The list single selection object that specifies the submenu
+ * names to be used for generating selection submenus.
+ */
+ @Tunable(description = "Apply to")
+ public ListSingleSelection<String> getSubmenuOptions() {
+
+ List<String> possibleValues = new ArrayList<String>();
+
+ Set<Class<?>> nodeAttrTypes = supportsNodeAttributes();
+ Set<Class<?>> edgeAttrTypes = supportsEdgeAttributes();
+
+ if (nodeAttrTypes != null && !nodeAttrTypes.isEmpty()) {
+ for (final CyColumn column :
network.getDefaultNodeTable().getColumns())
+ if (nodeAttrTypes.contains(column.getType()))
+ possibleValues.add(NODE_PREFIX +
column.getName());
+ } else if (edgeAttrTypes != null && !edgeAttrTypes.isEmpty()) {
+ for (final CyColumn column :
network.getDefaultEdgeTable().getColumns())
+ if (edgeAttrTypes.contains(column.getType()))
+ possibleValues.add(EDGE_PREFIX +
column.getName());
+ }
+
+ int numSelected = CyTableUtil.getNodesInState(network,
CyNetwork.SELECTED, true).size();
+ if (supportsSelectedOnly() && numSelected > 0) {
+
+ if (possibleValues.isEmpty()) {
+ possibleValues.add(ALL_NODES);
+ possibleValues.add(SELECTED_NODES_ONLY);
+ } else {
+ List<String> newPossibleValues = new
ArrayList<String>();
+ for (String pv : possibleValues) {
+ newPossibleValues.add(pv + ALL_NODES);
+ newPossibleValues.add(pv +
SELECTED_NODES_ONLY);
+ }
+ possibleValues = newPossibleValues;
+ }
+ }
+
+ submenuDef = new ListSingleSelection<String>(possibleValues);
+ if (possibleValues.size() > 0) {
+ submenuDef.setSelectedValue(possibleValues.get(0));
+ }
+ return submenuDef;
+ }
+
+ protected void configureLayoutFromSubmenuSelection() {
+ String selectedMenu = submenuDef.getSelectedValue();
+
+ if (selectedMenu == null || selectedMenu == "")
+ return;
+
+ setSelectedOnly(selectedMenu.endsWith(SELECTED_NODES_ONLY));
+
+ if (selectedMenu.endsWith(ALL_NODES))
+ selectedMenu = selectedMenu.replaceFirst(ALL_NODES, "");
+ if (selectedMenu.endsWith(SELECTED_NODES_ONLY))
+ selectedMenu =
selectedMenu.replaceFirst(SELECTED_NODES_ONLY, "");
+
+ if (selectedMenu.startsWith(NODE_PREFIX))
+ selectedMenu = selectedMenu.replaceFirst(NODE_PREFIX,
"");
+ if (selectedMenu.startsWith(EDGE_PREFIX))
+ selectedMenu = selectedMenu.replaceFirst(EDGE_PREFIX,
"");
+
+ if (selectedMenu.length() > 0)
+ setLayoutAttribute(selectedMenu);
+ }
}
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
2012-03-10 00:14:30 UTC (rev 28478)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -32,11 +32,11 @@
*/
package org.cytoscape.view.layout;
-import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.Map;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
@@ -65,9 +65,9 @@
*/
public final class LayoutPartition {
- private ArrayList<LayoutNode> nodeList;
- private ArrayList<LayoutEdge> edgeList;
- private HashMap<CyNode, LayoutNode> nodeToLayoutNode;
+ private List<LayoutNode> nodeList;
+ private List<LayoutEdge> edgeList;
+ private Map<CyNode, LayoutNode> nodeToLayoutNode;
private int nodeIndex = 0;
private int partitionNumber = 0;
private EdgeWeighter edgeWeighter = null;
@@ -448,18 +448,15 @@
return lockedNodes;
}
+
/**
* Return the average location of the nodes in this partition
*
* @return average location of the nodes as a Dimension
- * @see Dimension
*/
- public Dimension getAverageLocation() {
+ public Point getAverageLocation() {
int nodes = nodeCount() - lockedNodes;
- final Dimension result = new Dimension();
- result.setSize(averageX / nodes, averageY / nodes);
-
- return result;
+ return new Point(averageX / nodes, averageY / nodes);
}
/**
@@ -543,8 +540,8 @@
* and filled. This is used by the static method
PartitionUtil.partition()
*/
void trimToSize() {
- nodeList.trimToSize();
- edgeList.trimToSize();
+ ((ArrayList<LayoutNode>) nodeList).trimToSize();
+ ((ArrayList<LayoutEdge>) edgeList).trimToSize();
}
private void updateMinMax(double x, double y) {
Added:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/Point.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/Point.java
(rev 0)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/Point.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -0,0 +1,25 @@
+package org.cytoscape.view.layout;
+
+
+/**
+ * Simple immutable object which represents a point (x, y).
+ *
+ */
+public final class Point {
+ private final Double x;
+ private final Double y;
+
+ public Point(final Double x, final Double y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ public Double getX() {
+ return x;
+ }
+
+ public Double getY() {
+ return y;
+ }
+
+}
Modified:
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualMappingFunctionFactory.java
===================================================================
---
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualMappingFunctionFactory.java
2012-03-10 00:14:30 UTC (rev 28478)
+++
core3/api/trunk/vizmap-api/src/main/java/org/cytoscape/view/vizmap/VisualMappingFunctionFactory.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -14,7 +14,7 @@
* Create a new {@linkplain VisualMappingFunction}.
*
* @param <K> Data type of controlling attribute.
- * @param <V> Data type of {@linkplain VisualProperty}, such as
{@linkplain java.awt.Color}, {@linkplain String}, etc.
+ * @param <V> Data type of {@linkplain VisualProperty}, such as
{@linkplain Double}, {@linkplain String}, etc.
*
* @param attributeName Controlling attribute name. This is a name of
the column in a data table.
* @param attrValueType Data type of controlling attribute.
Modified:
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutFRAlgorithmTask.java
===================================================================
---
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutFRAlgorithmTask.java
2012-03-10 00:14:30 UTC (rev 28478)
+++
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutFRAlgorithmTask.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -1,7 +1,6 @@
package csapps.layout.algorithms.bioLayout;
-import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Set;
@@ -9,6 +8,7 @@
import org.cytoscape.view.layout.LayoutEdge;
import org.cytoscape.view.layout.LayoutNode;
import org.cytoscape.view.layout.LayoutPartition;
+import org.cytoscape.view.layout.Point;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
@@ -359,7 +359,7 @@
public void layoutPartion(LayoutPartition partition) {
this.partition = partition;
- Dimension initialLocation = null;
+ Point initialLocation = null;
/* Get all of our profiles */
/*
@@ -390,9 +390,8 @@
}
// Figure out our starting point
- if (selectedOnly) {
+ if (selectedOnly)
initialLocation = partition.getAverageLocation();
- }
// Randomize our points, if any points lie
// outside of our bounds
@@ -460,9 +459,9 @@
if (selectedOnly) {
double xDelta = 0.0;
double yDelta = 0.0;
- Dimension finalLocation =
partition.getAverageLocation();
- xDelta = finalLocation.getWidth() -
initialLocation.getWidth();
- yDelta = finalLocation.getHeight() -
initialLocation.getHeight();
+ final Point finalLocation =
partition.getAverageLocation();
+ xDelta = finalLocation.getX() - initialLocation.getX();
+ yDelta = finalLocation.getY() - initialLocation.getY();
for (LayoutNode v: partition.getNodeList()) {
if (!v.isLocked()) {
Modified:
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutKKAlgorithmTask.java
===================================================================
---
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutKKAlgorithmTask.java
2012-03-10 00:14:30 UTC (rev 28478)
+++
core3/impl/trunk/layout-cytoscape-impl/src/main/java/csapps/layout/algorithms/bioLayout/BioLayoutKKAlgorithmTask.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -1,7 +1,6 @@
package csapps.layout.algorithms.bioLayout;
-import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -13,6 +12,7 @@
import org.cytoscape.view.layout.LayoutEdge;
import org.cytoscape.view.layout.LayoutNode;
import org.cytoscape.view.layout.LayoutPartition;
+import org.cytoscape.view.layout.Point;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
@@ -279,7 +279,7 @@
* Perform a layout
*/
public void layoutPartion(LayoutPartition partition) {
- Dimension initialLocation = null;
+ Point initialLocation = null;
this.partition = partition;
// Initialize all of our values. This will create
// our internal objects and initialize them
@@ -454,9 +454,9 @@
if (selectedOnly) {
double xDelta = 0.0;
double yDelta = 0.0;
- Dimension finalLocation =
partition.getAverageLocation();
- xDelta = finalLocation.getWidth() -
initialLocation.getWidth();
- yDelta = finalLocation.getHeight() -
initialLocation.getHeight();
+ final Point finalLocation =
partition.getAverageLocation();
+ xDelta = finalLocation.getX() - initialLocation.getX();
+ yDelta = finalLocation.getY() - initialLocation.getY();
for (LayoutNode v: partition.getNodeList()) {
if (!v.isLocked()) {
v.decrement(xDelta, yDelta);
Modified:
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
===================================================================
---
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
2012-03-10 00:14:30 UTC (rev 28478)
+++
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
2012-03-10 00:36:07 UTC (rev 28479)
@@ -28,7 +28,6 @@
package org.cytoscape.prefuse.layouts.internal;
-import java.awt.Dimension;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -42,18 +41,14 @@
import org.cytoscape.view.layout.LayoutEdge;
import org.cytoscape.view.layout.LayoutNode;
import org.cytoscape.view.layout.LayoutPartition;
+import org.cytoscape.view.layout.Point;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
-import org.cytoscape.work.Tunable;
-import org.cytoscape.work.undo.UndoSupport;
import prefuse.util.force.DragForce;
-import prefuse.util.force.EulerIntegrator;
import prefuse.util.force.ForceItem;
import prefuse.util.force.ForceSimulator;
-import prefuse.util.force.Integrator;
import prefuse.util.force.NBodyForce;
-import prefuse.util.force.RungeKuttaIntegrator;
import prefuse.util.force.SpringForce;
@@ -124,7 +119,7 @@
public void layoutPartion(LayoutPartition part) {
- Dimension initialLocation = null;
+ Point initialLocation = null;
// System.out.println("layoutPartion:
"+part.getEdgeList().size()+" edges");
// Calculate our edge weights
part.calculateEdgeWeights();
@@ -164,9 +159,8 @@
}
// Figure out our starting point
- if (selectedOnly) {
+ if (selectedOnly)
initialLocation = part.getAverageLocation();
- }
// perform layout
long timestep = 1000L;
@@ -191,9 +185,9 @@
if (selectedOnly) {
double xDelta = 0.0;
double yDelta = 0.0;
- Dimension finalLocation = part.getAverageLocation();
- xDelta = finalLocation.getWidth() -
initialLocation.getWidth();
- yDelta = finalLocation.getHeight() -
initialLocation.getHeight();
+ final Point finalLocation = part.getAverageLocation();
+ xDelta = finalLocation.getX() - initialLocation.getX();
+ yDelta = finalLocation.getY() - initialLocation.getY();
for (LayoutNode v: part.getNodeList()) {
if (!v.isLocked()) {
v.decrement(xDelta, yDelta);
--
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.