Author: apico
Date: 2009-03-12 15:10:19 -0700 (Thu, 12 Mar 2009)
New Revision: 16249

Added:
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/GOLayout.java
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/MFNodeAppearanceCalculator.java
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionAlgorithm.java
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionNetworkVisualStyleFactory.java
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/RegionManager.java
Modified:
   
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
Log:
new project


Modified: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
       2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/CellAlgorithm.java
       2009-03-12 22:10:19 UTC (rev 16249)
@@ -71,7 +71,7 @@
                 * @return short-hand name
                 */
                public String getName() {
-                       return "go-layout";
+                       return "cell-layout";
                }
 
                /**
@@ -80,7 +80,7 @@
                 * @return user visible name
                 */
                public String toString() {
-                       return "GO Layout";
+                       return "Cell Layout";
                }
 
                /**
@@ -788,4 +788,5 @@
                                }
                        }
                        Cytoscape.getCurrentNetworkView().redrawGraph(true, 
true);
-               }
\ No newline at end of file
+               }
+       }
\ No newline at end of file

Added: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/GOLayout.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/GOLayout.java
    2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/GOLayout.java
    2009-03-12 22:10:19 UTC (rev 16249)
@@ -0,0 +1,173 @@
+package org.genmapp.golayout;
+
+import giny.model.Node;
+
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+import CellularLayoutPlugin.CellularLayoutAlgorithm;
+
+import cytoscape.CyNetwork;
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.data.CyAttributesUtils;
+import cytoscape.ding.CyGraphAllLOD;
+import cytoscape.ding.DingNetworkView;
+import cytoscape.groups.CyGroup;
+import cytoscape.groups.CyGroupManager;
+import cytoscape.layout.CyLayoutAlgorithm;
+import cytoscape.layout.CyLayouts;
+import cytoscape.plugin.CytoscapePlugin;
+import cytoscape.util.CytoscapeAction;
+import cytoscape.view.CyDesktopManager;
+import cytoscape.view.CyNetworkView;
+import cytoscape.visual.CalculatorCatalog;
+import cytoscape.visual.VisualMappingManager;
+import cytoscape.visual.VisualStyle;
+
+
+public class GOLayout extends CytoscapePlugin {
+       /**
+        * The constructor registers our layout algorithm. The CyLayouts 
mechanism
+        * will worry about how to get it in the right menu, etc.
+        */
+       public CellularLayoutPlugin() {
+               CyLayouts.addLayout(new GOLayoutAlgorithm(), "GO Layout: Run 
All");
+               CyLayouts.addLayout(new PartitionAlgorithm(), "GO Layout: 
Partition");
+               CyLayouts.addLayout(new CellAlgorithm(), "GO Layout: Cell 
Layout");
+       }
+
+public class GOLayoutAlgorithm() extends AbstractLayout {
+       double distanceBetweenNodes = 80.0d;
+       LayoutProperties layoutProperties = null;
+
+       /**
+        * Creates a new CellularLayoutAlgorithm object.
+        */
+       public CellAlgorithm() {
+               super();
+               layoutProperties = new LayoutProperties(getName());
+               layoutProperties.add(new Tunable("nodeSpacing",
+                               "Spacing between nodes", Tunable.DOUBLE, new 
Double(80.0)));
+
+               // We've now set all of our tunables, so we can read the 
property
+               // file now and adjust as appropriate
+               layoutProperties.initializeProperties();
+
+               // Finally, update everything. We need to do this to update
+               // any of our values based on what we read from the property 
file
+               updateSettings(true);
+
+       }
+
+       /**
+        * External interface to update our settings
+        */
+       public void updateSettings() {
+               updateSettings(true);
+       }
+
+       /**
+        * Signals that we want to update our internal settings
+        * 
+        * @param force
+        *            force the settings to be updated, if true
+        */
+       public void updateSettings(boolean force) {
+               layoutProperties.updateValues();
+               Tunable t = layoutProperties.get("nodeSpacing");
+               if ((t != null) && (t.valueChanged() || force))
+                       distanceBetweenNodes = ((Double) 
t.getValue()).doubleValue();
+       }
+
+       /**
+        * Reverts our settings back to the original.
+        */
+       public void revertSettings() {
+               layoutProperties.revertProperties();
+       }
+
+       public LayoutProperties getSettings() {
+               return layoutProperties;
+       }
+
+       /**
+        * Returns the short-hand name of this algorithm
+        * 
+        * @return short-hand name
+        */
+       public String getName() {
+               return "go-layout";
+       }
+
+       /**
+        * Returns the user-visible name of this layout
+        * 
+        * @return user visible name
+        */
+       public String toString() {
+               return "GO Layout";
+       }
+
+       /**
+        * Return true if we support performing our layout on a limited set of
+        * nodes
+        * 
+        * @return true if we support selected-only layout
+        */
+       public boolean supportsSelectedOnly() {
+               return false;
+       }
+
+       /**
+        * Returns the types of node attributes supported by this algorithm.
+        * 
+        * @return the list of supported attribute types, or null if node
+        *         attributes are not supported
+        */
+       public byte[] supportsNodeAttributes() {
+               return null;
+       }
+
+       /**
+        * Returns the types of edge attributes supported by this algorithm.
+        * 
+        * @return the list of supported attribute types, or null if edge
+        *         attributes are not supported
+        */
+       public byte[] supportsEdgeAttributes() {
+               return null;
+       }
+
+       /**
+        * Returns a JPanel to be used as part of the Settings dialog for this
+        * layout algorithm.
+        * 
+        */
+       public JPanel getSettingsPanel() {
+               JPanel panel = new JPanel(new GridLayout(0, 1));
+               panel.add(layoutProperties.getTunablePanel());
+
+               return panel;
+       }
+
+       /**
+        * The layout protocol...
+        */
+       public void construct() {
+               CyLayoutAlgorithm layout = CyLayouts
+               .getLayout("partition");
+layout.doLayout(new_view);
+       }
+}
+}

Added: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/MFNodeAppearanceCalculator.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/MFNodeAppearanceCalculator.java
  2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/MFNodeAppearanceCalculator.java
  2009-03-12 22:10:19 UTC (rev 16249)
@@ -0,0 +1,69 @@
+package cytoscape.partitionNetwork;
+
+
+import giny.model.Node;
+
+import java.awt.Color;
+
+
+import cytoscape.CyNetwork;
+import cytoscape.CyNode;
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.visual.NodeAppearance;
+import cytoscape.visual.NodeAppearanceCalculator;
+import cytoscape.visual.NodeShape;
+import cytoscape.visual.VisualPropertyType;
+
+public class MFNodeAppearanceCalculator extends NodeAppearanceCalculator {
+       
+       public static int FEATURE_NODE_WIDTH = 60;
+       public static int FEATURE_NODE_HEIGHT = 30;
+       
+       public MFNodeAppearanceCalculator() {
+               
+
+       }
+       
+       public void calculateNodeAppearance(NodeAppearance appr, Node node,
+                       CyNetwork network) {
+               super.calculateNodeAppearance(appr, node, network);
+               
+//             CyAttributes nodeAttribs = Cytoscape.getNodeAttributes();
+//             String feature_id = node.getIdentifier();
+               
+                       
+//                     //Node label
+//                     String label = 
nodeAttribs.getStringAttribute(feature_id, "label");
+//                     appr.set(VisualPropertyType.NODE_LABEL, label != null ? 
label : feature_id);
+//                     
+//                     //Node shape
+//                     setNodeSizeLocked(false);
+//                     appr.set(VisualPropertyType.NODE_SHAPE, NodeShape.RECT);
+//                     appr.set(VisualPropertyType.NODE_WIDTH, 
FEATURE_NODE_WIDTH);
+//                     appr.set(VisualPropertyType.NODE_HEIGHT, 
FEATURE_NODE_HEIGHT);
+                       
+//                     //Node colors
+//                     Color stroke = new Color(0,0,0);
+//                     if(stroke != null) {
+//                             appr.set(VisualPropertyType.NODE_BORDER_COLOR, 
stroke);
+//                     }
+//                     Color fill = new Color(255,255,255);
+//                     if(fill != null) {
+//                             appr.set(VisualPropertyType.NODE_FILL_COLOR, 
fill);
+//                     }
+                       
+               
+       }
+               
+//     public String calculateNodeLabel(Node node, CyNetwork network) {
+//             String feature_id = SpliceController.get_nodeId();
+//             CyNode feature = Cytoscape.getCyNode(feature_id);
+//             CyAttributes nodeAttribs = Cytoscape.getNodeAttributes();
+//             if(feature != null) {
+//                     String label = 
nodeAttribs.getStringAttribute(feature_id, "label");
+//                     return label;
+//             }
+//             return null;
+//     }
+}

Added: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionAlgorithm.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionAlgorithm.java
  2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionAlgorithm.java
  2009-03-12 22:10:19 UTC (rev 16249)
@@ -0,0 +1,407 @@
+import java.awt.GridLayout;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.swing.JPanel;
+import javax.swing.SwingUtilities;
+
+/**
+ * PartitionAlgorithm
+ */
+public class PartitionAlgorithm extends AbstractLayout {
+       double distanceBetweenNodes = 80.0d;
+       LayoutProperties layoutProperties = null;
+
+       private String layoutName = null;
+       private ArrayList<Object> nodeAttributeValues = new ArrayList();
+       private static final String attributeName = "annotation.GO 
BIOLOGICAL_PROCESS";
+       private HashMap<Object, List<Node>> attributeValueNodeMap = new 
HashMap<Object, List<Node>>();
+       private List<CyNetworkView> views = new ArrayList<CyNetworkView>();
+       private List<CyGroup> groups = new ArrayList<CyGroup>();
+       private List<Node> unconnectedNodes = new ArrayList<Node>();
+       private int networkViewThreshhold = 5; // necessary size to show network
+
+       // view in the tiling
+
+       /**
+        * Creates a new PartitionAlgorithm object.
+        */
+       public PartitionAlgorithm(String layout) {
+               super();
+
+               this.layoutName = layout;
+
+               layoutProperties = new LayoutProperties(getName());
+               layoutProperties.add(new Tunable("nodeSpacing",
+                               "Spacing between nodes", Tunable.DOUBLE, new 
Double(80.0)));
+               layoutProperties.add();
+               // We've now set all of our tunables, so we can read the 
property
+               // file now and adjust as appropriate
+               layoutProperties.initializeProperties();
+
+               // Finally, update everything. We need to do this to update
+               // any of our values based on what we read from the property 
file
+               updateSettings(true);
+
+       }
+
+       /**
+        * External interface to update our settings
+        */
+       public void updateSettings() {
+               updateSettings(true);
+       }
+
+       /**
+        * Signals that we want to update our internal settings
+        * 
+        * @param force
+        *            force the settings to be updated, if true
+        */
+       public void updateSettings(boolean force) {
+               layoutProperties.updateValues();
+               Tunable t = layoutProperties.get("nodeSpacing");
+               if ((t != null) && (t.valueChanged() || force))
+                       distanceBetweenNodes = ((Double) 
t.getValue()).doubleValue();
+       }
+
+       /**
+        * Reverts our settings back to the original.
+        */
+       public void revertSettings() {
+               layoutProperties.revertProperties();
+       }
+
+       public LayoutProperties getSettings() {
+               return layoutProperties;
+       }
+
+       /**
+        * Returns the short-hand name of this algorithm
+        * 
+        * @return short-hand name
+        */
+       public String getName() {
+               return "partition";
+       }
+
+       /**
+        * Returns the user-visible name of this layout
+        * 
+        * @return user visible name
+        */
+       public String toString() {
+               return "Partition";
+       }
+
+       /**
+        * Return true if we support performing our layout on a limited set of 
nodes
+        * 
+        * @return true if we support selected-only layout
+        */
+       public boolean supportsSelectedOnly() {
+               return false;
+       }
+
+       /**
+        * Returns the types of node attributes supported by this algorithm.
+        * 
+        * @return the list of supported attribute types, or null if node 
attributes
+        *         are not supported
+        */
+       public byte[] supportsNodeAttributes() {
+               return null;
+       }
+
+       /**
+        * Returns the types of edge attributes supported by this algorithm.
+        * 
+        * @return the list of supported attribute types, or null if edge 
attributes
+        *         are not supported
+        */
+       public byte[] supportsEdgeAttributes() {
+               return null;
+       }
+
+       /**
+        * Returns a JPanel to be used as part of the Settings dialog for this
+        * layout algorithm.
+        * 
+        */
+       public JPanel getSettingsPanel() {
+               JPanel panel = new JPanel(new GridLayout(0, 1));
+               panel.add(layoutProperties.getTunablePanel());
+
+               return panel;
+       }
+
+       /**
+        * 
+        */
+       public ArrayList<Object> setupNodeAttributeValues() {
+               CyAttributes attribs = Cytoscape.getNodeAttributes();
+               Map attrMap = CyAttributesUtils.getAttribute(attributeName, 
attribs);
+               Collection values = attrMap.values();
+               ArrayList<Object> uniqueValueList = new ArrayList<Object>();
+
+               // key will be a List attribute value, so we need to pull out 
individual
+               // list items
+               if (attribs.getType(attributeName) == 
CyAttributes.TYPE_SIMPLE_LIST) {
+                       for (Object o : values) {
+                               List oList = (List) o;
+                               for (int j = 0; j < oList.size(); j++) {
+                                       Object jObj = oList.get(j);
+                                       if (jObj != null) {
+                                               if 
(!uniqueValueList.contains(jObj)) {
+                                                       
uniqueValueList.add(jObj);
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               return uniqueValueList;
+       }
+
+       public void buildMetaNodeView(CyNetwork net) {
+               // create an 'uber' view of the network as group nodes
+               CyNetwork group_network = 
Cytoscape.createNetwork(net.nodesList(), net
+                               .edgesList(), "overView", net);
+               CyNetworkView group_view = 
Cytoscape.getNetworkView(group_network
+                               .getIdentifier());
+
+               for (Object val : attributeValueNodeMap.keySet()) {
+                       List<Node> memberNodes = attributeValueNodeMap.get(val);
+                       CyGroup group = 
CyGroupManager.createGroup(val.toString(),
+                                       memberNodes, null);
+                       groups.add(group);
+               }
+               // group unconnected nodes
+               CyGroup group = CyGroupManager.createGroup("unConnected",
+                               unconnectedNodes, null);
+               groups.add(group);
+
+               // now loop through all groups and set state to 'collapsed'
+               for (CyGroup g : groups) {
+                       g.setState(2);
+                       CyGroupManager.setGroupViewer(g, "metaNode", 
group_view, true); // set
+                                                                               
                                                                        // this
+                                                                               
                                                                        // false
+                                                                               
                                                                        // later
+                                                                               
                                                                        // for
+                                                                               
                                                                        // 
efficiency
+               }
+
+               CyLayoutAlgorithm layout = 
CyLayouts.getLayout("force-directed");
+               layout.doLayout(group_view);
+               Cytoscape.getVisualMappingManager().setVisualStyle(
+                               
PartitionNetworkVisualStyleFactory.PartitionNetwork_VS);
+
+       }
+
+       public void populateNodes(String attributeName) {
+
+               CyAttributes attribs = Cytoscape.getNodeAttributes();
+               Iterator<Node> it = 
Cytoscape.getCurrentNetwork().nodesIterator();
+               List<Node> selectedNodes = null;
+               List<Node> unassignedNodes = 
Cytoscape.getCurrentNetwork().nodesList();
+
+               boolean valueFound = false;
+
+               while (it.hasNext()) {
+
+                       valueFound = false;
+                       Node node = it.next();
+
+                       // assign unconnected nodes to a special category and 
move on
+                       int[] edges = Cytoscape.getCurrentNetwork()
+                                       
.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(),
+                                                       true, true, true);
+                       if (edges.length <= 0) {
+                               unconnectedNodes.add(node);
+                               continue;
+                       }
+
+                       String val = null;
+                       String terms[] = new String[1];
+                       // add support for parsing List type attributes
+                       if (attribs.getType(attributeName) == 
CyAttributes.TYPE_SIMPLE_LIST) {
+                               List valList = 
attribs.getListAttribute(node.getIdentifier(),
+                                               attributeName);
+                               // System.out.println ("Got values for node: " 
+ node + " = " +
+                               // valList);
+                               // iterate through all elements in the list
+                               if (valList != null && valList.size() > 0) {
+                                       terms = new String[valList.size()];
+                                       for (int i = 0; i < valList.size(); 
i++) {
+                                               Object o = valList.get(i);
+                                               terms[i] = o.toString();
+                                       }
+                               }
+                               val = join(terms);
+                       } else {
+                               String valCheck = 
attribs.getStringAttribute(node
+                                               .getIdentifier(), 
attributeName);
+                               if (valCheck != null && !valCheck.equals("")) {
+                                       val = valCheck;
+                               }
+                       }
+
+                       if ((!(val == null) && (!val.equals("null")) && 
(val.length() > 0))) {
+
+                               for (Object o : nodeAttributeValues) {
+                                       // System.out.println ("checking node 
value " + val +
+                                       // " against " + o.toString());
+                                       if (val.indexOf(o.toString()) >= 0) {
+                                               selectedNodes = 
attributeValueNodeMap.get(o);
+                                               if (selectedNodes == null) {
+                                                       selectedNodes = new 
ArrayList<Node>();
+                                               }
+                                               if 
(!selectedNodes.contains(node)) {
+                                                       selectedNodes.add(node);
+                                                       
attributeValueNodeMap.put(o.toString(),
+                                                                       
selectedNodes);
+                                                       valueFound = true;
+                                               }
+                                               // System.out.println 
("selected nodes for value: " +
+                                               // o.toString() + " = " +
+                                               // selectedNodes);
+                                       }
+                               }
+                       }
+                       if (!valueFound)
+                       // put this node in 'unassigned' category
+                       // but do we need to treat separately the case where 
there is a
+                       // value not in the template
+                       // from the case where there is no value?
+                       {
+                               selectedNodes = 
attributeValueNodeMap.get("unassigned");
+                               if (selectedNodes == null) {
+                                       selectedNodes = new ArrayList<Node>();
+                               }
+                               if (!selectedNodes.contains(node)) {
+                                       selectedNodes.add(node);
+                                       attributeValueNodeMap.put("unassigned", 
selectedNodes);
+                                       valueFound = true;
+                               }
+                       }
+               }
+       }
+
+       private String join(String values[]) {
+               StringBuffer buf = new StringBuffer();
+               for (int i = 0; i < values.length; i++) {
+                       buf.append(values[i]);
+                       if (i < values.length - 1) {
+                               buf.append(", ");
+                       }
+               }
+               return buf.toString();
+       }
+
+       /**
+        * build a subnetwork for selected nodes leverages from
+        * cytoscape.actions.NewWindowSelectedNodesOnlyAction
+        * 
+        * @param current_network
+        */
+       public void buildSubNetwork(CyNetwork current_network, String 
attributeValue) {
+
+               CyNetworkView current_network_view = null;
+
+               if (Cytoscape.viewExists(current_network.getIdentifier())) {
+                       current_network_view = 
Cytoscape.getNetworkView(current_network
+                                       .getIdentifier());
+               } // end of if ()
+
+               List nodes = attributeValueNodeMap.get(attributeValue);
+               // System.out.println("Got nodes for attributeValue: " + 
attributeValue
+               // + " = " + nodes);
+               if (nodes == null) {
+                       return;
+               }
+
+               CyNetwork new_network = Cytoscape.createNetwork(nodes, 
current_network
+                               .getConnectingEdges(new ArrayList(nodes)),
+               // CyNetworkNaming.getSuggestedSubnetworkTitle(current_network),
+                               attributeValue, // for network title
+                               current_network, (nodes.size() >= 
networkViewThreshhold)); // optional
+                                                                               
                                                                        // 
create
+                                                                               
                                                                        // 
network
+                                                                               
                                                                        // view
+
+               if (new_network.nodesList().size() >= networkViewThreshhold) {
+
+                       CyNetworkView new_view = 
Cytoscape.getNetworkView(new_network
+                                       .getIdentifier());
+
+                       if (new_view == Cytoscape.getNullNetworkView()) {
+                               return;
+                       }
+
+                       views.add(new_view);
+
+                       // apply layout
+                       if (current_network_view != 
Cytoscape.getNullNetworkView()) {
+
+                               // CyLayoutAlgorithm layout =
+                               // CyLayouts.getLayout("force-directed");
+                               System.out.println("Layout: " + 
new_view.getTitle());
+                               CyLayoutAlgorithm layout = CyLayouts
+                                               .getLayout(this.layoutName);
+                               layout.doLayout(new_view);
+
+                       }
+
+                       // set graphics level of detail
+                       ((DingNetworkView) new_view).setGraphLOD(new 
CyGraphAllLOD());
+
+                       Cytoscape.getVisualMappingManager().setVisualStyle(
+                                       
PartitionNetworkVisualStyleFactory.PartitionNetwork_VS);
+
+               }
+       }
+
+       /**
+        * layout the subnetwork views in a grid
+        */
+       public void tileNetworkViews() {
+               SwingUtilities.invokeLater(new Runnable() {
+                       public void run() {
+                               
CyDesktopManager.arrangeFrames(CyDesktopManager.Arrange.GRID);
+                               // finally loop through the network views and 
fitContent
+                               for (CyNetworkView view : views) {
+                                       
Cytoscape.setCurrentNetworkView(view.getIdentifier());
+                                       view.fitContent();
+                               }
+
+                       }
+               });
+       }
+
+       /**
+        * The layout protocol...
+        */
+       public void construct() {
+               nodeAttributeValues = setupNodeAttributeValues();
+               populateNodes(attributeName);
+
+               Set<Object> attributeValues = attributeValueNodeMap.keySet();
+               CyNetwork net = Cytoscape.getCurrentNetwork();
+               CyNetworkView view = 
Cytoscape.getNetworkView(net.getIdentifier());
+
+               //              
+               for (Object val : attributeValues) {
+                       buildSubNetwork(net, val.toString());
+               }
+
+               buildMetaNodeView(net);
+               tileNetworkViews(); // tile and fit content in each view
+
+       }
+}

Added: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionNetworkVisualStyleFactory.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionNetworkVisualStyleFactory.java
  2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/PartitionNetworkVisualStyleFactory.java
  2009-03-12 22:10:19 UTC (rev 16249)
@@ -0,0 +1,260 @@
+package cytoscape.partitionNetwork;
+
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import cytoscape.data.CyAttributesUtils;
+import cytoscape.view.CyNetworkView;
+import cytoscape.visual.CalculatorCatalog;
+import cytoscape.visual.GlobalAppearanceCalculator;
+import cytoscape.visual.LabelPosition;
+import cytoscape.visual.NodeAppearanceCalculator;
+import cytoscape.visual.NodeShape;
+import cytoscape.visual.VisualMappingManager;
+import cytoscape.visual.VisualPropertyType;
+import cytoscape.visual.VisualStyle;
+import cytoscape.visual.calculators.BasicCalculator;
+import cytoscape.visual.calculators.Calculator;
+import cytoscape.visual.mappings.DiscreteMapping;
+import cytoscape.visual.mappings.ObjectMapping;
+import cytoscape.visual.mappings.PassThroughMapping;
+
+public class PartitionNetworkVisualStyleFactory {
+
+       /**
+        * 
+        */
+       public static final String PartitionNetwork_VS = "MolecularFunction";
+       
+
+
+       public static VisualStyle createVisualStyle(CyNetworkView view) {
+               
+               VisualMappingManager vmm = Cytoscape.getVisualMappingManager();
+               CalculatorCatalog catalog = vmm.getCalculatorCatalog();
+               VisualStyle sgvStyle = 
catalog.getVisualStyle(PartitionNetwork_VS);
+               if (sgvStyle == null) { // Create the MF visual style
+                       try {
+                               sgvStyle = (VisualStyle) 
vmm.getVisualStyle().clone();
+                       } catch (CloneNotSupportedException e) {
+                               sgvStyle = new VisualStyle(PartitionNetwork_VS);
+                       }
+                       sgvStyle.setName(PartitionNetwork_VS);
+                       NodeAppearanceCalculator nac = new 
MFNodeAppearanceCalculator();
+                       nac.getDefaultAppearance().setNodeSizeLocked(false);
+                       
nac.getDefaultAppearance().set(VisualPropertyType.NODE_HEIGHT,
+                                       
MFNodeAppearanceCalculator.FEATURE_NODE_HEIGHT);
+                       
nac.getDefaultAppearance().set(VisualPropertyType.NODE_WIDTH,
+                                       
MFNodeAppearanceCalculator.FEATURE_NODE_WIDTH);
+                       
nac.getDefaultAppearance().set(VisualPropertyType.NODE_SHAPE,
+                                       NodeShape.RECT);
+                       nac.getDefaultAppearance().set(
+                                       VisualPropertyType.NODE_BORDER_COLOR, 
new Color(0, 0, 0));
+                       
nac.getDefaultAppearance().set(VisualPropertyType.NODE_FILL_COLOR,
+                                       new Color(255, 255, 255));
+                       
+                       
+                       final String attributeName = "annotation.GO 
MOLECULAR_FUNCTION";        
+                       CyAttributes attribs = Cytoscape.getNodeAttributes();
+                       Map attrMap = 
CyAttributesUtils.getAttribute(attributeName, attribs);
+                       Collection values = attrMap.values();
+                       List uniqueValueList = new ArrayList();
+                       
+                       // key will be a List attribute value, so we need to 
pull out individual list items
+                       if (attribs.getType(attributeName) == 
CyAttributes.TYPE_SIMPLE_LIST) {
+                               for (Object o : values)
+                               {
+                                       List oList = (List) o;
+                                       for (int j = 0; j < oList.size(); j++)
+                                       {
+                                               Object jObj = oList.get(j);
+                                               if (jObj != null)
+                                               {
+                                                       if 
(!uniqueValueList.contains(jObj))
+                                                       {
+                                                               
uniqueValueList.add(jObj);
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+                       PassThroughMapping passMappingLabel = new 
PassThroughMapping("", "canonicalName");
+                       Calculator labelCalculator = new 
BasicCalculator(PartitionNetwork_VS,
+                       passMappingLabel,
+                                       VisualPropertyType.NODE_LABEL);
+                       nac.setCalculator(labelCalculator);
+                       DiscreteMapping disMappingNodeW = new 
DiscreteMapping(MFNodeAppearanceCalculator.FEATURE_NODE_WIDTH, "register_node", 
ObjectMapping.NODE_MAPPING);
+                       disMappingNodeW.putMapValue(Boolean.TRUE, 0.1);
+                       Calculator widthCalculator = new 
BasicCalculator(PartitionNetwork_VS,
+                       disMappingNodeW,
+                                       VisualPropertyType.NODE_WIDTH);
+                       nac.setCalculator(widthCalculator);
+                       DiscreteMapping disMappingNodeH = new 
DiscreteMapping(MFNodeAppearanceCalculator.FEATURE_NODE_HEIGHT, 
"register_node", ObjectMapping.NODE_MAPPING);
+                       disMappingNodeH.putMapValue(Boolean.TRUE, 0.1);
+                       Calculator heightCalculator = new 
BasicCalculator(PartitionNetwork_VS,
+                       disMappingNodeH,
+                                       VisualPropertyType.NODE_HEIGHT);
+                       nac.setCalculator(heightCalculator);
+                       
+                       DiscreteMapping disMappingFont = new 
DiscreteMapping(12, "register_node", ObjectMapping.NODE_MAPPING);
+                       disMappingFont.putMapValue(Boolean.TRUE, 24);
+                       Calculator fontCalculator = new 
BasicCalculator(PartitionNetwork_VS,
+                                       disMappingFont,
+                                       VisualPropertyType.NODE_FONT_SIZE);
+                       nac.setCalculator(fontCalculator);
+                       LabelPosition lp = new LabelPosition();
+                       DiscreteMapping disMappingLabelPosition = new 
DiscreteMapping(lp, "register_node", ObjectMapping.NODE_MAPPING);
+                       lp.setOffsetX(120);
+                       lp.setOffsetY(15);
+                       lp.setJustify(1);
+                       disMappingLabelPosition.putMapValue(Boolean.TRUE, lp);
+                       Calculator posCalculator = new 
BasicCalculator(PartitionNetwork_VS,
+                                       disMappingLabelPosition,
+                                       VisualPropertyType.NODE_LABEL_POSITION);
+                       nac.setCalculator(posCalculator);
+                       
+                       DiscreteMapping disMappingNodeFill = new 
DiscreteMapping(Color.white,
+                       ObjectMapping.NODE_MAPPING);
+                       
disMappingNodeFill.setControllingAttributeName(attributeName, 
view.getNetwork(), false);
+                       /*
+                        * Create random colors
+                        */
+                       final float increment = 1f / ((Number) 
uniqueValueList.size()).floatValue();
+                       float hue = 0;
+                       float sat = 0;
+                       float br = 0;
+                       int i = 0;
+                       for (Object key : uniqueValueList) {
+                               hue = hue + increment;
+                               sat = (Math.abs(((Number) Math.cos((8 * i) / (2 
* Math.PI))).floatValue()) * 0.7f)
+                                     + 0.3f;
+                               br = (Math.abs(((Number) Math.sin(((i) / (2 * 
Math.PI)) + (Math.PI / 2)))
+                                              .floatValue()) * 0.7f) + 0.3f;
+                               disMappingNodeFill.putMapValue(key, new 
Color(Color.HSBtoRGB(hue, sat, br)));
+                               i++;
+                       }
+                       Calculator colorCalculator = new 
BasicCalculator(PartitionNetwork_VS,
+                       disMappingNodeFill,
+                                       VisualPropertyType.NODE_FILL_COLOR);
+                       
+                       nac.setCalculator(colorCalculator);
+
+                       sgvStyle.setNodeAppearanceCalculator(nac);
+                       
+                       GlobalAppearanceCalculator gac = 
sgvStyle.getGlobalAppearanceCalculator();
+                       // set edge opacity
+                       gac.setDefaultBackgroundColor(Color.white);
+//                     VisualStyle visualStyle = new 
VisualStyle(PartitionNetwork_VS, nodeAppCalc, edgeAppCalc, gac);
+                       VisualPropertyType type = 
VisualPropertyType.EDGE_OPACITY;
+                       type.setDefault(sgvStyle, new Integer(200));
+                       type = VisualPropertyType.NODE_SHAPE;
+                       type.setDefault(sgvStyle, NodeShape.ELLIPSE);
+                       sgvStyle.setGlobalAppearanceCalculator(gac);
+
+                       catalog.addVisualStyle(sgvStyle);
+               }
+               CyNetworkView myView = Cytoscape.getCurrentNetworkView();
+               vmm.setNetworkView(myView);
+               vmm.setVisualStyle(sgvStyle);
+               myView.setVisualStyle(PartitionNetwork_VS);
+
+               Cytoscape.getVisualMappingManager().setNetworkView(myView);
+               Cytoscape.getVisualMappingManager().applyAppearances();
+
+               
+
+               
+               return sgvStyle;
+               
+               
+//             VisualStyle clone = null;
+//             try {
+//                     clone = (VisualStyle) currentStyle.clone();
+//             } catch (CloneNotSupportedException exc) {
+//                     CyLogger.getLogger().warn("Clone not supported 
exception!");
+//             }
+
+               // ------------------------------ Set node color 
---------------------------//
+
+//             ContinuousMapping colorMapping = new 
ContinuousMapping(Color.GRAY, ObjectMapping.NODE_MAPPING);
+//             colorMapping.setControllingAttributeName(CUM_SPECTRA, network, 
false);
+//             
+//             colorMapping.addPoint (CUM_SPECTRA_LOW_POINT, 
+//                             new BoundaryRangeValues (LOW_COLOR, LOW_COLOR, 
LOW_COLOR));
+//             colorMapping.addPoint(CUM_SPECTRA_MID_POINT, 
+//                             new BoundaryRangeValues (MID_COLOR, MID_COLOR, 
MID_COLOR));
+//             colorMapping.addPoint(CUM_SPECTRA_HIGH_POINT, 
+//                             new BoundaryRangeValues (HIGH_COLOR, 
HIGH_COLOR, HIGH_COLOR));
+//             
+//             
+//             Calculator colorCalculator = new BasicCalculator("Spectrum Mill 
Color Calculator",
+//                                                                         
colorMapping,
+//     
+/*
+               ContinuousMapping colorMapping = new 
ContinuousMapping(Color.GRAY, ObjectMapping.NODE_MAPPING);
+               colorMapping.setControllingAttributeName(HEAT_NORMAL_RATIO, 
network, false);
+               
+               colorMapping.addPoint (HEAT_NORMAL_RATIO_LOW_POINT, 
+                               new BoundaryRangeValues (LOW_COLOR, LOW_COLOR, 
LOW_COLOR));
+               colorMapping.addPoint(HEAT_NORMAL_RATIO_MID_POINT, 
+                               new BoundaryRangeValues (MID_COLOR, MID_COLOR, 
MID_COLOR));
+               colorMapping.addPoint(HEAT_NORMAL_RATIO_HIGH_POINT, 
+                               new BoundaryRangeValues (HIGH_COLOR, 
HIGH_COLOR, HIGH_COLOR));
+               
+               
+               Calculator colorCalculator = new BasicCalculator("Scaffold 
Color Calculator",
+                                                                           
colorMapping,
+                                                                               
                                                        
VisualPropertyType.NODE_FILL_COLOR);
+               nodeAppCalc.setCalculator(colorCalculator);
+               */
+
+               //--------------------- Set the size of the nodes 
--------------------------//
+
+/*
+               ContinuousMapping sizeMapping = new ContinuousMapping(MID_SIZE, 
ObjectMapping.NODE_MAPPING);
+               sizeMapping.setControllingAttributeName(CUM_INTENSITY, network, 
false);
+               
+               sizeMapping.addPoint (CUM_INTENSITY_LOW_POINT, 
+                               new BoundaryRangeValues (LOW_SIZE, LOW_SIZE, 
LOW_SIZE));
+               sizeMapping.addPoint(CUM_INTENSITY_MID_POINT, 
+                               new BoundaryRangeValues (MID_SIZE, MID_SIZE, 
MID_SIZE));
+               sizeMapping.addPoint(CUM_INTENSITY_HIGH_POINT, 
+                               new BoundaryRangeValues (HIGH_SIZE, HIGH_SIZE, 
HIGH_SIZE));
+               
+               
+               Calculator sizeCalculator = new BasicCalculator("Spectrum Mill 
Node Size Calculator",
+                                                                           
sizeMapping,
+                                                                               
                                                        
VisualPropertyType.NODE_SIZE);
+               nodeAppCalc.setCalculator(sizeCalculator);
+
+*/
+               // ------------------------------ Set node shapes 
---------------------------//
+
+               /*
+               DiscreteMapping disMapping = new 
DiscreteMapping(NodeShape.ELLIPSE,
+                ObjectMapping.NODE_MAPPING);
+//             disMapping.setControllingAttributeName(MOLECULAR_SPECIES, 
network, false);
+       
+//             disMapping.putMapValue(PROTEIN, NodeShape.ELLIPSE);
+
+               Calculator shapeCalculator = new BasicCalculator("Node Shape 
Calculator",
+                           disMapping,
+                                                       
VisualPropertyType.NODE_SHAPE);
+               
+               nodeAppCalc.setCalculator(shapeCalculator);
+
+*/
+
+               //------------------------- Create a visual style 
-------------------------------//
+//             GlobalAppearanceCalculator gac = 
vmManager.getVisualStyle().getGlobalAppearanceCalculator();
+               // -------------------------- set node color to encoding of 
Molecular Function ------ //
+               
+
+       }       
+       
+}

Added: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java  
    2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/Region.java  
    2009-03-12 22:10:19 UTC (rev 16249)
@@ -0,0 +1,710 @@
+package org.genmapp.cellularlayout;
+
+import giny.model.Node;
+import giny.view.NodeView;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.swing.JComponent;
+
+import org.pathvisio.view.ShapeRegistry;
+
+import cytoscape.Cytoscape;
+import cytoscape.data.CyAttributes;
+import ding.view.DGraphView;
+import ding.view.InnerCanvas;
+import ding.view.ViewportChangeListener;
+
+public class Region extends JComponent implements ViewportChangeListener {
+
+       // shape and parameters from template
+       private String shape; // Line, Arc, Oval, Rectangle
+       private Color color;
+       private double centerX;
+       private double centerY;
+       private double width;
+       private double height;
+       private int zorder;
+       private double rotation;
+       private String attValue;
+
+       // additional parameters not from template
+       private String attName;
+       private List<String> nestedAttValues; // values represented by attValue
+       private List<NodeView> nodeViews;
+       private int nodeCount;
+       private int columns;
+       private int area;
+       private boolean visibleBorder;
+
+       // dimensions of free, non-overlapping space available for nodes
+       private double freeCenterX;
+       private double freeCenterY;
+       private double freeWidth;
+       private double freeHeight;
+       private List<Region> regionsOverlapped = new ArrayList<Region>();
+       private List<Region> overlappingRegions = new ArrayList<Region>();
+
+       // graphics
+       protected DGraphView dview = (DGraphView) 
Cytoscape.getCurrentNetworkView();
+       private static final int TRANSLUCENCY_LEVEL = (int) (255 * .10);
+
+       public Region(String shape, String color, double centerX, double 
centerY,
+                       double width, double height, int zorder, double 
rotation,
+                       String attValue) {
+               super();
+
+               this.shape = shape;
+               this.color = Color.decode(color); // decode hexadecimal string
+               this.centerX = centerX;
+               this.centerY = centerY;
+               this.width = width;
+               this.height = height;
+               if (width < 1) // handle extreme case
+                       this.width = 1;
+               if (height < 1) // handle extreme case
+                       this.height = 1;
+               this.area = (int) (width * height);
+               this.zorder = zorder;
+               this.rotation = rotation;
+               this.attValue = attValue;
+               RegionManager.addRegion(this.attValue, this);
+
+               // nested terms based on Nathan's GO tree analysis
+               if (this.attValue.equals("extracellular region"))
+                       nestedAttValues = Arrays.asList("extracellular region", 
"secreted");
+               else if (this.attValue.equals("plasma membrane"))
+                       nestedAttValues = Arrays.asList("plasma membrane", 
"cell wall");
+               else if (this.attValue.equals("cytoplasm"))
+                       nestedAttValues = Arrays.asList("cytoplasm", 
"intracellular");
+               else if (this.attValue.equals("nucleus"))
+                       nestedAttValues = Arrays.asList("nucleus", "nucleolus",
+                                       "nuclear membrane");
+               else
+                       nestedAttValues = Arrays.asList(this.attValue);
+
+               // additional parameters
+               this.attName = "BasicCellularComponents"; // hard-coded, for now
+
+               this.nodeViews = populateNodeViews();
+               this.nodeCount = this.nodeViews.size();
+               this.columns = (int) Math.sqrt(this.nodeCount);
+               this.freeCenterX = centerX;
+               this.freeCenterY = centerY;
+               this.freeWidth = width;
+               this.freeHeight = height;
+
+               // define free area inside of ovals
+               if (this.shape == "Oval") {
+                       Double x = 0.0d;
+                       Double y = 0.0d;
+                       Double a = 0.0d;
+                       Double b = 0.0d;
+
+                       if (width > height) {
+                               a = width / 2;
+                               b = height / 2;
+                       } else {
+                               a = height / 2;
+                               b = width / 2;
+                       }
+
+                       // TODO: adapt equations to handle rotation (phi)
+                       // x=h+a(cos t)(cos phi) - b(sin t)(sin phi)
+                       // y=k+b(sin t)(cos phi) +a(cos t)(sin phi)
+                       x = centerX + a * Math.cos(Math.PI / 4);
+                       y = centerY + b * Math.cos(Math.PI / 4);
+
+                       this.freeWidth = Math.abs(x - centerX) * 2;
+                       this.freeHeight = Math.abs(y - centerY) * 2;
+               }
+
+               // adjust area for line shapes
+               if (this.shape == "Line") {
+                       this.area = 0; // treat as 1D object
+                       // this will force lines shapes to top of drawing order
+               }
+
+               // graphics
+               setBounds(getVOutline().getBounds());
+               dview.addViewportChangeListener(this);
+
+       }
+
+       private List<NodeView> populateNodeViews() {
+               CyAttributes attribs = Cytoscape.getNodeAttributes();
+               Iterator it = Cytoscape.getCurrentNetwork().nodesIterator();
+               List<NodeView> nvList = new ArrayList<NodeView>();
+               while (it.hasNext()) {
+                       Node node = (Node) it.next();
+                       String val = null;
+                       String terms[] = new String[1];
+                       // add support for parsing List type attributes
+                       if (attribs.getType(attName) == 
CyAttributes.TYPE_SIMPLE_LIST) {
+                               List valList = 
attribs.getListAttribute(node.getIdentifier(),
+                                               attName);
+                               // iterate through all elements in the list
+                               if (valList != null && valList.size() > 0) {
+                                       terms = new String[valList.size()];
+                                       for (int i = 0; i < valList.size(); 
i++) {
+                                               Object o = valList.get(i);
+                                               terms[i] = o.toString();
+                                       }
+                               }
+                               val = join(terms);
+                       } else {
+                               String valCheck = 
attribs.getStringAttribute(node
+                                               .getIdentifier(), attName);
+                               if (valCheck != null && !valCheck.equals("")) {
+                                       val = valCheck;
+                               }
+                       }
+
+                       // loop through elements in array below and match
+                       if ((!(val == null) && (!val.equals("null")) && 
(val.length() > 0))) {
+                               for (Object o : nestedAttValues) {
+                                       if (val.indexOf(o.toString()) >= 0) {
+                                               
nvList.add(Cytoscape.getCurrentNetworkView()
+                                                               
.getNodeView(node));
+                                               break; // stop searching after 
first hit
+                                       }
+
+                               }
+                       } else if (nestedAttValues.get(0).equals("unassigned")) 
{
+                               
nvList.add(Cytoscape.getCurrentNetworkView().getNodeView(node));
+                       }
+
+               }
+               return nvList;
+       }
+
+       /**
+        * generates comma-separated list as a single string
+        * 
+        * @param values
+        *            array
+        * @return string
+        */
+       private static String join(String values[]) {
+               StringBuffer buf = new StringBuffer();
+               for (int i = 0; i < values.length; i++) {
+                       buf.append(values[i]);
+                       if (i < values.length - 1) {
+                               buf.append(", ");
+                       }
+               }
+               return buf.toString();
+       }
+
+       // graphics
+       public void setBounds(double x, double y, double width, double height) {
+               setBounds((int) x, (int) y, (int) width, (int) height);
+       }
+
+       public final void paint(Graphics g) {
+               Graphics2D g2d = (Graphics2D) g.create();
+               g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                               RenderingHints.VALUE_ANTIALIAS_ON);
+               g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
+                               RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+               doPaint(g2d);
+       }
+
+       protected java.awt.Shape relativeToBounds(java.awt.Shape s) {
+               Rectangle r = getBounds();
+               AffineTransform f = new AffineTransform();
+               f.translate(-r.x, -r.y);
+               return f.createTransformedShape(s);
+       }
+
+       protected java.awt.Shape viewportTransform(java.awt.Shape s) {
+               InnerCanvas canvas = dview.getCanvas();
+
+               AffineTransform f = canvas.getAffineTransform();
+               if (f != null)
+                       return f.createTransformedShape(s);
+               else
+                       return s;
+       }
+
+       public void viewportChanged(int w, int h, double newXCenter,
+                       double newYCenter, double newScaleFactor) {
+               InnerCanvas canvas = dview.getCanvas();
+
+               AffineTransform f = canvas.getAffineTransform();
+
+               if (f == null)
+                       return;
+
+               java.awt.Shape outline = getVOutline();
+
+               Rectangle b = outline.getBounds();
+               Point2D pstart = f.transform(new Point2D.Double(b.x, b.y), 
null);
+               setBounds(pstart.getX(), pstart.getY(), b.width * 
newScaleFactor,
+                               b.height * newScaleFactor);
+       }
+
+       public Rectangle2D.Double getVRectangle() {
+               return new Rectangle2D.Double(getRegionLeft(), getRegionTop(),
+                               (getRegionRight() - getRegionLeft()),
+                               (getRegionBottom() - getRegionTop()));
+       }
+
+       public java.awt.Shape getVOutline() {
+               Rectangle2D.Double r = getVRectangle();
+               r.width = r.width + 2;
+               r.height = r.height + 2;
+               AffineTransform f = new AffineTransform();
+               f.rotate(this.rotation, getCenterX(), getCenterY());
+               java.awt.Shape outline = f.createTransformedShape(r);
+               return outline;
+       }
+
+       public void doPaint(Graphics2D g2d) {
+
+               Rectangle b = 
relativeToBounds(viewportTransform(getVRectangle()))
+                               .getBounds();
+
+               Color fillcolor = Color.blue;
+               Color fillColor = new Color(fillcolor.getRed(), 
fillcolor.getGreen(),
+                               fillcolor.getBlue(), TRANSLUCENCY_LEVEL);
+               Color linecolor = this.color;
+
+               int sw = 1;
+               int x = b.x;
+               int y = b.y;
+               int w = b.width - sw - 1;
+               int h = b.height - sw - 1;
+               int cx = x + w / 2;
+               int cy = y + h / 2;
+
+
+               // TODO
+               // s = new Rectangle(x, y, w, h);
+               if (this.shape == "Line") {
+                       Point2D src = new Point2D.Double(this.centerX, 
this.centerY);
+                       Point2D trgt = new Point2D.Double(this.width, 
this.height);
+                       Point2D srcT = new Point2D.Double();
+                       Point2D trgtT = new Point2D.Double();
+                       
+                       AffineTransform t = new AffineTransform();
+                       t.transform(src, srcT);
+                       t.transform(trgt, trgtT);
+                       
+                       g2d.drawLine((int) srcT.getX(), (int) srcT.getY(),
+                                       (int) trgtT.getX(), (int)trgtT.getY());
+                       
+               } else { // Rectangle, Oval
+                       java.awt.Shape s = null;
+
+                       s = ShapeRegistry.getShape(this.shape, x, y, w, h);
+
+                       AffineTransform t = new AffineTransform();
+                       t.rotate(this.rotation, cx, cy);
+                       s = t.createTransformedShape(s);
+
+                       // TODO
+                       // g2d.setColor(fillcolor);
+                       // g2d.fill(s);
+
+                       g2d.setColor(linecolor);
+                       g2d.setStroke(new BasicStroke());
+                       g2d.draw(s);
+
+               }
+
+       }
+
+       /**
+        * identifies set of node views that overlap with provided region.
+        * 
+        * @param nodeViews
+        * @param from
+        * @return NodeViews within boundary of current region
+        */
+       public static List bounded(List<NodeView> nodeViews, Region r) {
+               List<NodeView> boundedNodeViews = new ArrayList<NodeView>();
+               double currentX;
+               double currentY;
+               // first calculate the min/max x and y for the list of 
*relevant*
+               // nodeviews
+               Iterator<NodeView> it = nodeViews.iterator();
+               while (it.hasNext()) {
+                       NodeView nv = it.next();
+                       currentX = nv.getXPosition();
+                       currentY = nv.getYPosition();
+                       if (currentX > r.getRegionLeft() && currentX < 
r.getRegionRight()
+                                       && currentY > r.getRegionTop()
+                                       && currentY < r.getRegionBottom()) {
+                               boundedNodeViews.add(nv);
+                       }
+               }
+
+               return boundedNodeViews;
+       }
+
+       /**
+        * @return the nodeViews
+        */
+       public List<NodeView> getNodeViews() {
+               return nodeViews;
+       }
+
+       /**
+        * @param nodeViews
+        *            the nodeViews to set
+        */
+       public void setNodeViews(List<NodeView> nodeViews) {
+               this.nodeViews = nodeViews;
+       }
+
+       /**
+        * @return the visibleBorder
+        */
+       public boolean isVisibleBorder() {
+               return visibleBorder;
+       }
+
+       /**
+        * @param visibleBorder
+        *            the visibleBorder to set
+        */
+       public void setVisibleBorder(boolean visibleBorder) {
+               this.visibleBorder = visibleBorder;
+       }
+
+       /**
+        * @return the centerX
+        */
+       public double getCenterX() {
+               return centerX;
+       }
+
+       /**
+        * @return the centerY
+        */
+       public double getCenterY() {
+               return centerY;
+       }
+
+       /**
+        * @param centerX
+        *            the centerX to set
+        */
+       public void setCenterX(double centerX) {
+               this.centerX = centerX;
+       }
+
+       /**
+        * @param centerY
+        *            the centerY to set
+        */
+       public void setCenterY(double centerY) {
+               this.centerY = centerY;
+       }
+
+       /**
+        * Note: for a Line, width == length, irrespective of orientation
+        * 
+        * @return the width
+        */
+       public double getRegionWidth() {
+               return width;
+       }
+
+       /**
+        * @return the height
+        */
+       public double getRegionHeight() {
+               return height;
+       }
+
+       /**
+        * Note: for a Line, width == length, irrespective of orientation
+        * 
+        * @param width
+        *            the width to set
+        */
+       public void setRegionWidth(double width) {
+               this.width = width;
+       }
+
+       /**
+        * @param height
+        *            the height to set
+        */
+       public void setRegionHeight(double height) {
+               this.height = height;
+       }
+
+       /**
+        * @return
+        */
+       public double getRegionLeft() {
+               if (this.shape == "Line") {
+                       return (Math.min(this.centerX, this.width));
+               } else { // Rectangle, Oval
+                       return (this.centerX - this.width / 2);
+               }
+       }
+
+       /**
+        * @return
+        */
+       public double getRegionTop() {
+               if (this.shape == "Line") {
+                       return (Math.min(this.centerY, this.height));
+               } else { // Rectangle, Oval
+                       return (this.centerY - this.height / 2);
+               }
+       }
+
+       /**
+        * @return
+        */
+       public double getRegionRight() {
+               if (this.shape == "Line") {
+                       return (Math.max(this.centerX, this.width));
+               } else { // Rectangle, Oval
+                       return (this.centerX + this.width / 2);
+               }
+       }
+
+       /**
+        * @return
+        */
+       public double getRegionBottom() {
+               if (this.shape == "Line") {
+                       return (Math.max(this.centerY, this.height));
+               } else { // Rectangle, Oval
+                       return (this.centerY + this.height / 2);
+               }
+       }
+
+       /**
+        * @return the area
+        */
+       public int getArea() {
+               return area;
+       }
+
+       /**
+        * @param area
+        *            the area to set
+        */
+       public void setArea(int area) {
+               this.area = area;
+       }
+
+       /**
+        * @return the zorder
+        */
+       public int getZorder() {
+               return zorder;
+       }
+
+       /**
+        * @return the attValue
+        */
+       public String getAttValue() {
+               return attValue;
+       }
+
+       /**
+        * @return the nodeCount
+        */
+       public int getNodeCount() {
+               return nodeCount;
+       }
+
+       /**
+        * @return the columns
+        */
+       public int getColumns() {
+               return columns;
+       }
+
+       /**
+        * @return the shape
+        */
+       public String getShape() {
+               return shape;
+       }
+
+       /**
+        * @return the freeCenterX
+        */
+       public double getFreeCenterX() {
+               return freeCenterX;
+       }
+
+       /**
+        * @param freeCenterX
+        *            the freeCenterX to set
+        */
+       public void setFreeCenterX(double freeCenterX) {
+               this.freeCenterX = freeCenterX;
+       }
+
+       /**
+        * @return the freeCenterY
+        */
+       public double getFreeCenterY() {
+               return freeCenterY;
+       }
+
+       /**
+        * @param freeCenterY
+        *            the freeCenterY to set
+        */
+       public void setFreeCenterY(double freeCenterY) {
+               this.freeCenterY = freeCenterY;
+       }
+
+       /**
+        * @return the freeWidth
+        */
+       public double getFreeWidth() {
+               return freeWidth;
+       }
+
+       /**
+        * @param freeWidth
+        *            the freeWidth to set
+        */
+       public void setFreeWidth(double freeWidth) {
+               this.freeWidth = freeWidth;
+       }
+
+       /**
+        * @return the freeHeight
+        */
+       public double getFreeHeight() {
+               return freeHeight;
+       }
+
+       /**
+        * @param freeHeight
+        *            the freeHeight to set
+        */
+       public void setFreeHeight(double freeHeight) {
+               this.freeHeight = freeHeight;
+       }
+
+       public double getFreeLeft() {
+               return (freeCenterX - freeWidth / 2);
+       }
+
+       public double getFreeRight() {
+               return (freeCenterX + freeWidth / 2);
+       }
+
+       public double getFreeTop() {
+               return (freeCenterY - freeHeight / 2);
+       }
+
+       public double getFreeBottom() {
+               return (freeCenterY + freeHeight / 2);
+       }
+
+       public double getLineLength() {
+               return (Math.sqrt(Math.pow((this.width - this.centerX), 2)
+                               + Math.pow((this.height - this.centerY), 2)));
+       }
+
+       public double getFreeLength() {
+               return (Math.sqrt(Math.pow((freeWidth - freeCenterX), 2)
+                               + Math.pow((freeHeight - freeCenterY), 2)));
+       }
+
+       public void setLineLength(Double l) {
+               Double oldLength = getLineLength();
+               Double halfDiff = (l - oldLength) / 2;
+               Double ratio = halfDiff / oldLength;
+               Double x = (this.width - this.centerX) * ratio;
+               Double y = (this.height - this.centerY) * ratio;
+               if (this.centerX < this.width) {
+                       setCenterX((this.centerX - x));
+                       setRegionWidth((this.width + x));
+               } else {
+                       setCenterX((this.centerX + x));
+                       setRegionWidth((this.width - x));
+               }
+               if (this.centerY < this.height) {
+                       setCenterY((this.centerY - y));
+                       setRegionHeight((this.height + y));
+               } else {
+                       setCenterY((this.centerY + y));
+                       setRegionHeight((this.height - y));
+               }
+       }
+
+       public void setFreeLength(Double l) {
+               Double oldLength = getFreeLength();
+               Double halfDiff = (l - oldLength) / 2;
+               Double ratio = halfDiff / oldLength;
+               Double x = (this.freeWidth - this.freeCenterX) * ratio;
+               Double y = (this.freeHeight - this.freeCenterY) * ratio;
+               if (this.freeCenterX < this.freeWidth) {
+                       setFreeCenterX((this.freeCenterX - x));
+                       setFreeWidth((this.freeWidth + x));
+               } else {
+                       setFreeCenterX((this.freeCenterX + x));
+                       setFreeWidth((this.freeWidth - x));
+               }
+               if (this.freeCenterY < this.freeHeight) {
+                       setFreeCenterY((this.freeCenterY - y));
+                       setFreeHeight((this.freeHeight + y));
+               } else {
+                       setFreeCenterY((this.freeCenterY + y));
+                       setFreeHeight((this.freeHeight - y));
+               }
+       }
+
+       /**
+        * returns list of regions that are overlapped by a given region
+        * 
+        * @return the regionsOverlapped
+        */
+       public List<Region> getRegionsOverlapped() {
+               return regionsOverlapped;
+       }
+
+       /**
+        * add to list of regions that are overlapped by a given region
+        * 
+        * @param regionsOverlapped
+        *            the regionsOverlapped to set
+        */
+       public void setRegionsOverlapped(Region r) {
+               this.regionsOverlapped.add(r);
+       }
+
+       /**
+        * @return the overlappingRegions
+        */
+       public List<Region> getOverlappingRegions() {
+               return overlappingRegions;
+       }
+
+       /**
+        * @param overlappingRegions
+        *            the overlappingRegions to set
+        */
+       public void setOverlappingRegions(Region r) {
+               this.overlappingRegions.add(r);
+       }
+
+}
\ No newline at end of file

Added: 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/RegionManager.java
===================================================================
--- 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/RegionManager.java
       2009-03-12 22:07:08 UTC (rev 16248)
+++ 
csplugins/trunk/ucsf/apico/CellularLayout/src/org/genmapp/golayout/RegionManager.java
       2009-03-12 22:10:19 UTC (rev 16249)
@@ -0,0 +1,138 @@
+package org.genmapp.cellularlayout;
+
+import giny.model.Node;
+import giny.view.NodeView;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.TreeMap;
+
+import cytoscape.Cytoscape;
+import ding.view.DGraphView;
+import ding.view.DingCanvas;
+
+/**
+ * This class maintains a hashmap of regions by attribute value, plus methods
+ * that operate over all regions.
+ * 
+ */
+public class RegionManager {
+
+       private static HashMap<String, Region> regionAttMap = new 
HashMap<String, Region>();
+       private static TreeMap<Integer, Region> sortedRegionMap = new 
TreeMap<Integer, Region>();
+
+       public static void addRegion(String attValue, Region region) {
+               regionAttMap.put(attValue, region);
+               checkForOverlap(region);
+       }
+
+       public static Region getRegionByAtt(String attValue) {
+               return regionAttMap.get(attValue);
+       }
+
+       public static Collection<Region> getAllRegions() {
+               return regionAttMap.values();
+       }
+
+       public static void clearAll() {
+               regionAttMap.clear();
+               sortedRegionMap.clear();
+               DGraphView dview = (DGraphView) 
Cytoscape.getCurrentNetworkView();
+               DingCanvas bCanvas = dview
+                               .getCanvas(DGraphView.Canvas.BACKGROUND_CANVAS);
+               bCanvas.removeAll();
+
+               // clean up copied nodes and edges
+               Iterator it = Cytoscape.getCurrentNetwork().nodesIterator();
+               while (it.hasNext()) {
+                       Node node = (Node) it.next();
+                       if (node.getIdentifier().contains("__")) {
+                               Cytoscape.getCurrentNetwork().removeNode(
+                                               node.getRootGraphIndex(), true);
+                       }
+               }
+
+       }
+
+       /**
+        * Checks each new region against existing regions for overlap. If
+        * overlapping, region is added to a sorted tree map.
+        * 
+        * Also hacks area values when found to be equivalent to an existing 
region.
+        * This helps make it sortable.
+        * 
+        * @param r
+        */
+       private static void checkForOverlap(Region newRegion) {
+               double newLeft = newRegion.getRegionLeft();
+               double newRight = newRegion.getRegionRight();
+               double newTop = newRegion.getRegionTop();
+               double newBottom = newRegion.getRegionBottom();
+
+               Region[] sra = getSortedRegionArray();
+               for (int i = sra.length - 1; i >= 0; i--) { // from largest to 
smallest
+                       if (i == -1) // if first region
+                               break;
+                       Region r = sra[i];
+                       if (newRegion.getShape() == "Line") {
+                               if (newRegion.getArea() == r.getArea()) {
+                                       newRegion.setArea(newRegion.getArea() - 
1);
+                               }
+                       } else { // ovals and rectangles
+                               if (newRegion.getArea() == r.getArea()) {
+                                       // if tie, then most elongated on top
+                                       int eRatio = (int) ((r.getRegionWidth() 
/ r
+                                                       .getRegionHeight()) / 
(newRegion.getRegionWidth() / newRegion
+                                                       .getRegionHeight()));
+                                       if (eRatio <= 1) { // tie break goes to 
newRegion
+                                               
newRegion.setArea(newRegion.getArea() - 1);
+                                       } else {
+                                               r.setArea(newRegion.getArea() - 
1);
+                                       }
+                               }
+                               if ((newLeft > r.getRegionLeft() && newLeft < r
+                                               .getRegionRight())
+                                               || (newRight > 
r.getRegionLeft() && newRight < r
+                                                               
.getRegionRight())
+                                               || newLeft < r.getRegionLeft()
+                                               && newRight > 
r.getRegionRight()) {
+                                       if ((newTop > r.getRegionTop() && 
newTop < r
+                                                       .getRegionBottom())
+                                                       || (newBottom > 
r.getRegionTop() && newBottom < r
+                                                                       
.getRegionBottom())
+                                                       || newTop < 
r.getRegionTop()
+                                                       && newBottom > 
r.getRegionBottom()) {
+                                               // If we got this far, it means 
one region is
+                                               // overlapping
+                                               // the other. Now we want to 
flag the smaller one so we
+                                               // know when and where to apply 
"oil & water" exclusion.
+                                               if (r.getArea() > 
newRegion.getArea()) {
+                                                       
newRegion.setRegionsOverlapped(r);
+                                                       
r.setOverlappingRegions(newRegion);
+                                               } else {
+                                                       
r.setRegionsOverlapped(newRegion);
+                                                       
newRegion.setOverlappingRegions(r);
+                                               }
+                                       }
+                               }
+                       }
+               }
+               sortedRegionMap.put(newRegion.getArea(), newRegion);
+       }
+
+       /**
+        * @return sra the sortedRegionArray
+        */
+       public static Region[] getSortedRegionArray() {
+               Region[] sra = new Region[sortedRegionMap.size()];
+               int i = 0;
+               for (Region r : sortedRegionMap.values()) {
+                       sra[i] = r;
+                       i++;
+               }
+               return sra;
+       }
+}
\ No newline at end of file


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