Author: scooter
Date: 2010-11-22 22:28:44 -0800 (Mon, 22 Nov 2010)
New Revision: 22991

Added:
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
Modified:
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/ViewUtils.java
Log:
Added NodeChart functionality.  Not done, yet...


Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
   2010-11-23 00:23:56 UTC (rev 22990)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
   2010-11-23 06:28:44 UTC (rev 22991)
@@ -42,6 +42,7 @@
 import cytoscape.Cytoscape;
 import cytoscape.view.CyNetworkView;
 
+import cytoscape.command.CyCommandHandler;
 import cytoscape.command.CyCommandManager;
 import cytoscape.command.CyCommandResult;
 
@@ -60,6 +61,7 @@
 import metaNodePlugin2.model.MetanodeProperties;
 import metaNodePlugin2.ui.MetanodeMenuListener;
 import metaNodePlugin2.ui.MetanodeSettingsDialog;
+import metaNodePlugin2.view.NodeCharts;
 
 /**
  * 
@@ -72,8 +74,10 @@
        CyGroupViewer namedSelectionViewer = null;
        MetanodeSettingsDialog settingsDialog = null;
        boolean registeredWithGroupPanel = false;
+       boolean haveNodeCharts = false;
 
        private static String NAMEDSELECTION = "namedselection";
+       private static String NODECHARTS = "nodecharts";
 
        public MetaNodeGroupViewer (String viewerName, CyLogger logger) {
                this.viewerName = viewerName;
@@ -86,9 +90,6 @@
                } catch (Exception e) {
                        logger.error(e.getMessage(),e);
                }
-
-               // Tell the group panel we want to use it
-               registerWithGroupPanel();
        }
 
        /**
@@ -227,16 +228,50 @@
                } else if (change == CyGroupViewer.ChangeType.STATE_CHANGED) {
                        // Handle different representations here....
                        if (group.getState() == MetaNodePlugin2.COLLAPSED && 
!mn.isCollapsed()) {
+                               System.out.println("Collapsing");
                                // Actually collapse the group
                                mn.collapse(Cytoscape.getCurrentNetworkView());
                                // Handle our attributes
                                AttributeManager.updateAttributes(mn);
+                               if (haveNodeCharts) {
+                                       // Handle our node charts
+                                       System.out.println("Updating node 
charts");
+                                       NodeCharts.updateNodeCharts(mn, logger);
+                               }
                        } else if (group.getState() == MetaNodePlugin2.EXPANDED 
&& mn.isCollapsed()) {
                                mn.expand(Cytoscape.getCurrentNetworkView());
                        }
                }
        }
 
+       public boolean haveNodeCharts() {
+               if (!haveNodeCharts)
+                       haveNodeCharts = checkNodeCharts();
+               return haveNodeCharts;
+       }
+
+       public List<String> getChartTypes() {
+               try {
+                       Map<String,Object> args = new HashMap<String,Object>();
+                       CyCommandResult result = 
CyCommandManager.execute(NODECHARTS, "list", args);
+                       Object chartTypes = result.getResult("typeList");
+                       if (chartTypes instanceof List)
+                               return (List<String>)chartTypes;
+               } catch (Exception e) {
+                       logger.info(e.getMessage());
+               }
+               return new ArrayList<String>();
+       }
+
+       public boolean checkNodeCharts() {
+               try {
+                       CyCommandManager.getCommand(NODECHARTS, "clear");
+               } catch (RuntimeException e) {
+                       return false;
+               }
+               return true;
+       }
+
        private void updateGroupPanel() {
                if (!registeredWithGroupPanel) {
                        registerWithGroupPanel();
@@ -269,10 +304,20 @@
        }
 
        public void registerWithGroupPanel() {
+               // First, see if the named selection plugin is loaded
+               CyCommandHandler handler = null;
+
+               registeredWithGroupPanel = false; // probably redundant
                try {
+                       handler = CyCommandManager.getCommand(NAMEDSELECTION, 
"add viewer");
+               } catch (RuntimeException e) {
+                       return;
+               }
+
+               try {
                        Map<String,Object> args = new HashMap<String,Object>();
                        args.put("viewer",viewerName);
-                       CyCommandResult result = 
CyCommandManager.execute(NAMEDSELECTION, "add viewer", args);
+                       CyCommandResult result = handler.execute("add viewer", 
args);
                        if (result.getErrors() != null && 
result.getErrors().size() > 0) {
                                for (String error: result.getErrors())
                                        logger.warning(error);

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
       2010-11-23 00:23:56 UTC (rev 22990)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodePlugin2.java
       2010-11-23 06:28:44 UTC (rev 22991)
@@ -119,11 +119,8 @@
        public static final int EXPANDED = 1;
        public static final int COLLAPSED = 2;
 
-       private static boolean registeredWithGroupPanel = false;
-
        private static boolean addedGraphViewChangeListener = false;
 
-       private MetanodeSettingsDialog settingsDialog = null;
        private MetaNodeGroupViewer groupViewer = null;
 
        protected int descendents = 0;
@@ -132,6 +129,7 @@
         * The main constructor
         */
        public MetaNodePlugin2() {
+
                logger = CyLogger.getLogger(MetaNodePlugin2.class);
                // Register with CyGroup
                groupViewer = new MetaNodeGroupViewer(viewerName, logger);
@@ -146,6 +144,9 @@
                        Cytoscape.getDesktop().getSwingPropertyChangeSupport()
                                  .addPropertyChangeListener( 
CytoscapeDesktop.NETWORK_VIEW_FOCUSED, this);
 
+                       Cytoscape.getPropertyChangeSupport()
+                                 .addPropertyChangeListener( 
Cytoscape.CYTOSCAPE_INITIALIZED, this);
+
                        // Add our context menu
                        
Cytoscape.getCurrentNetworkView().addNodeContextMenuListener(this);
                        
Cytoscape.getCurrentNetworkView().addGraphViewChangeListener(this);
@@ -181,6 +182,11 @@
                        // Load the default aggregation values for this network
                        
groupViewer.getSettingsDialog().updateOverrides(Cytoscape.getCurrentNetwork());
                        // 
MetaNodeManager.newView(Cytoscape.getCurrentNetworkView());
+               } else if (e.getPropertyName() == 
Cytoscape.CYTOSCAPE_INITIALIZED) {
+                       // Handle interaction with other plugins
+                       groupViewer.registerWithGroupPanel();
+                       groupViewer.haveNodeCharts();
+                       groupViewer.getSettingsDialog().updateNodeChartTypes();
                }
        }
 

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
        2010-11-23 00:23:56 UTC (rev 22990)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNode.java
        2010-11-23 06:28:44 UTC (rev 22991)
@@ -85,6 +85,8 @@
        private boolean hideMetanode = true;
        private double metanodeOpacity = 0.;
        private boolean useNestedNetworks = false;
+       private String nodeChartAttribute = null;
+       private String chartType = null;
 
        private Map<CyEdge,CyEdge> metaEdges = new HashMap<CyEdge,CyEdge>();
        private Map<CyNode,CyEdge> membershipEdges = null;
@@ -340,6 +342,32 @@
        }
 
        /**
+        * Sets the attribute to use node charting
+        *
+        * @param attribute the attribute to use for node charting
+        */
+       public void setNodeChartAttribute(String nodeChartAttribute) {
+               this.nodeChartAttribute = nodeChartAttribute;
+       }
+
+       public String getNodeChartAttribute() {
+               return this.nodeChartAttribute;
+       }
+
+       /**
+        * Sets the node chart type
+        *
+        * @param chartType the chart type
+        */
+       public void setChartType(String chartType) {
+               this.chartType = chartType;
+       }
+
+       public String getChartType() {
+               return this.chartType;
+       }
+
+       /**
         * Sets whether or not we hide the metnode when we expand the
         * network.
         *

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
 2010-11-23 00:23:56 UTC (rev 22990)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/model/MetaNodeManager.java
 2010-11-23 06:28:44 UTC (rev 22991)
@@ -58,6 +58,8 @@
        protected static boolean hideMetanodeDefault = true;
        protected static double metanodeOpacityDefault = 255.;
        protected static boolean useNestedNetworksDefault = false;
+       protected static String chartTypeDefault = null;
+       protected static String nodeChartAttributeDefault = null;
 
        public static final String X_HINT_ATTR = "__metanodeHintX";
        public static final String Y_HINT_ATTR = "__metanodeHintY";
@@ -88,6 +90,8 @@
                mn.setUseNestedNetworks(useNestedNetworksDefault);
                mn.setHideMetaNode(hideMetanodeDefault);
                mn.setMetaNodeOpacity(metanodeOpacityDefault);
+               mn.setChartType(chartTypeDefault);
+               mn.setNodeChartAttribute(nodeChartAttributeDefault);
                if (metaGroup.getNetwork() == null) {
                        metaGroup.setNetwork(Cytoscape.getCurrentNetwork(), 
false);
                }
@@ -222,4 +226,40 @@
        static public boolean getUseNestedNetworksDefault() {
                return MetaNodeManager.useNestedNetworksDefault;
        }
+
+       /**
+        * Sets the attribute to use for node charting.
+        *
+        * @param nodeChartAttribute the attribute to use for node charts
+        */
+       static public void setNodeChartAttributeDefault(String 
nodeChartAttribute) {
+               MetaNodeManager.nodeChartAttributeDefault = nodeChartAttribute;
+       }
+
+       /**
+        * Gets the attribute to use for node charting.
+        *
+        * @return the attribute to use for node charts
+        */
+       static public String getNodeChartAttributeDefault() {
+               return MetaNodeManager.nodeChartAttributeDefault;
+       }
+
+       /**
+        * Sets the chart type to use for node charting.
+        *
+        * @param chartType the chart type to use for node charts
+        */
+       static public void setChartTypeDefault(String chartType) {
+               MetaNodeManager.chartTypeDefault = chartType;
+       }
+
+       /**
+        * Gets the node chart type.
+        *
+        * @return the node chart type
+        */
+       static public String getChartTypeDefault() {
+               return MetaNodeManager.chartTypeDefault;
+       }
 }

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
     2010-11-23 00:23:56 UTC (rev 22990)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
     2010-11-23 06:28:44 UTC (rev 22991)
@@ -38,6 +38,7 @@
 */
 package metaNodePlugin2.ui;
 
+import metaNodePlugin2.MetaNodeGroupViewer;
 import metaNodePlugin2.model.MetaNode;
 import metaNodePlugin2.model.MetaNodeManager;
 import metaNodePlugin2.model.MetanodeProperties;
@@ -92,18 +93,24 @@
        private Tunable typeString = null;
        private Tunable typeList = null;
        private Tunable attrList = null;
+       private Tunable nodeChartAttrList = null;
+       private Tunable nodeChartTypeList = null;
        private String[] attributeArray = null;
        private List<Tunable>tunableEnablers = null;
+       private List<Tunable>nodeChartEnablers = null;
        private boolean hideMetaNode = true;
   private boolean enableHandling = false;
   private boolean useNestedNetworks = false;
        private double metanodeOpacity = 255.0f;
-       private CyGroupViewer groupViewer = null;
+       private String chartType = null;
+       private String nodeChartAttribute = null;
+       private MetaNodeGroupViewer groupViewer = null;
+       private static String NONETYPE = "-- None --";
 
        // Dialog components
        JPanel tunablePanel = null;
 
-       public MetanodeSettingsDialog(CyGroupViewer viewer) {
+       public MetanodeSettingsDialog(MetaNodeGroupViewer viewer) {
                super(Cytoscape.getDesktop(), "Metanode Settings Dialog", 
false);
                metanodeProperties = new MetanodeProperties("metanode");
                this.groupViewer = viewer;
@@ -181,31 +188,34 @@
        }
 
        private void initializeProperties() {
-               tunableEnablers = new ArrayList();
+               tunableEnablers = new ArrayList<Tunable>();
+               nodeChartEnablers = new ArrayList<Tunable>();
 
                
                metanodeProperties.add(new Tunable("appearanceGroup", "Metanode 
Appearance",
                                                   Tunable.GROUP, new 
Integer(2),
                                                   new Boolean(true), null, 
Tunable.COLLAPSABLE));
                {
-                       Tunable t = new Tunable("useNestedNetworks",
-                                               "Create a nested network for 
collapsed metanodes",
-                                               Tunable.BOOLEAN, new 
Boolean(false), 0);
-                       t.addTunableValueListener(this);
-                       metanodeProperties.add(t);
-               }
+                       {
+                               Tunable t = new Tunable("useNestedNetworks",
+                                                       "Create a nested 
network for collapsed metanodes",
+                                                       Tunable.BOOLEAN, new 
Boolean(false), 0);
+                               t.addTunableValueListener(this);
+                               metanodeProperties.add(t);
+                       }
 
-               // Sliders always look better when grouped
-               metanodeProperties.add(new Tunable("opacityGroup", "Metanode 
Opacity",
-                                                  Tunable.GROUP, new 
Integer(1),
-                                                  null, null, 0));
+                       // Sliders always look better when grouped
+                       metanodeProperties.add(new Tunable("opacityGroup", 
"Metanode Opacity",
+                                                         Tunable.GROUP, new 
Integer(1),
+                                                         null, null, 0));
 
-               {
-                       Tunable t = new Tunable("metanodeOpacity",
-                                               "Percent opacity of collapsed 
metanodes",
-                                               Tunable.DOUBLE, new Double(0), 
new Double(0), new Double(100), Tunable.USESLIDER);
-                       t.addTunableValueListener(this);
-                       metanodeProperties.add(t);
+                       {
+                               Tunable t = new Tunable("metanodeOpacity",
+                                                       "Percent opacity of 
collapsed metanodes",
+                                                       Tunable.DOUBLE, new 
Double(0), new Double(0), new Double(100), Tunable.USESLIDER);
+                               t.addTunableValueListener(this);
+                               metanodeProperties.add(t);
+                       }
                }
 
                {
@@ -216,6 +226,32 @@
                        metanodeProperties.add(t);
                }
 
+               // If we have nodeCharts, provide chart options for aggregated 
attributes
+               {
+                       Tunable t = new Tunable("nodeChartsGroup", "Node Chart 
Options",
+                                               Tunable.GROUP, new Integer(2),
+                                         new Boolean(true), null, 
Tunable.COLLAPSABLE);
+                       metanodeProperties.add(t);
+
+                       {
+                               // Get the attribute to map
+                               nodeChartAttrList = new 
Tunable("nodeChartAttribute", "Attribute to use for node chart",
+                                                               Tunable.LIST, 
new Integer(0),
+                                                               
getNodeAttributes(), null, 0);
+                               nodeChartEnablers.add(nodeChartAttrList);
+                               metanodeProperties.add(nodeChartAttrList);
+                               nodeChartAttrList.addTunableValueListener(this);
+
+                               // Get the chart type (might change depending 
on the chart type)
+                               nodeChartTypeList = new Tunable("chartType", 
"Chart type",
+                                                               Tunable.LIST, 
new Integer(0),
+                                                               
getChartTypes(), null, 0);
+                               nodeChartEnablers.add(nodeChartTypeList);
+                               metanodeProperties.add(nodeChartTypeList);
+                               nodeChartTypeList.addTunableValueListener(this);
+                       }
+               }
+
                metanodeProperties.add(new Tunable("defaultsGroup", "Defaults",
                                                   Tunable.GROUP, new 
Integer(5),
                                                   new Boolean(true), null, 
Tunable.COLLAPSABLE));
@@ -316,7 +352,21 @@
                        metanodeProperties.setProperty(t.getName(), 
t.getValue().toString());
                }
 
+               t = metanodeProperties.get("nodeChartAttribute");
+               if ((t != null) && (t.valueChanged() || force)) {
+                       nodeChartAttribute = (String)getListValue(t);
+                       
MetaNodeManager.setNodeChartAttributeDefault(nodeChartAttribute);
+                       metanodeProperties.setProperty(t.getName(), 
t.getValue().toString());
+               }
 
+               t = metanodeProperties.get("chartType");
+               if ((t != null) && (t.valueChanged() || force)) {
+                       chartType = (String)getListValue(t);
+                       MetaNodeManager.setChartTypeDefault(chartType);
+                       metanodeProperties.setProperty(t.getName(), 
t.getValue().toString());
+               }
+
+
                // For each default value, get the default and set it
                t = metanodeProperties.get("stringDefaults");
                if ((t != null) && (t.valueChanged() || force)) {
@@ -360,8 +410,17 @@
 
        public void updateAttributes() {
                attrList.setLowerBound(getAttributes());
+               nodeChartAttrList.setLowerBound(getNodeAttributes());
        }
 
+       public void updateNodeChartTypes() {
+               if (groupViewer.checkNodeCharts()) {
+                       enableNodeCharts(true);
+                       nodeChartTypeList.setLowerBound(getChartTypes());
+               } else
+                       enableNodeCharts(false);
+       }
+
        public boolean getUseNestedNetworks() {
                updateSettings(false);
                String bv = 
(String)metanodeProperties.getProperties().get("useNestedNetworks");
@@ -369,6 +428,16 @@
                return useNestedNetworks;
        }
 
+       private String[] getNodeAttributes() {
+               CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
+               List<String> attributeList = new ArrayList();
+               makeAttributes(null, nodeAttributes, attributeList);
+               String [] a = new String[1];
+               attributeArray = attributeList.toArray(a);
+               Arrays.sort(attributeArray);
+               return attributeArray;
+       }
+
        private String[] getAttributes() {
                CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
                CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
@@ -382,13 +451,25 @@
                return attributeArray;
        }
 
+       private String[] getChartTypes() {
+               String [] a = new String[1];
+               List<String> viewerList = groupViewer.getChartTypes();
+               viewerList.add(NONETYPE);
+               String [] viewerArray = viewerList.toArray(a);
+               Arrays.sort(viewerArray);
+               return viewerArray;
+       }
+
        private void makeAttributes(String prefix, CyAttributes attrs, 
List<String>list) {
                // Build a list
                String[] names = attrs.getAttributeNames();
                for (int i = 0; i < names.length; i++) {
                        if (!attrs.getUserVisible(names[i]))
                                continue;
-                       list.add(prefix+"."+names[i]);
+                       if (prefix != null)
+                               list.add(prefix+"."+names[i]);
+                       else
+                               list.add(names[i]);
                }
        }
 
@@ -422,12 +503,7 @@
                        for (CyNode node: nodeList) {
                                MetaNode mn = MetaNodeManager.getMetaNode(node);
                                if (mn != null) {
-                                       
mn.setUseNestedNetworks(useNestedNetworks);
-                                       // 
mn.setSizeToBoundingBox(sizeToBoundingBox);
-                                       mn.setHideMetaNode(hideMetaNode);
-                                       
mn.setAggregateAttributes(enableHandling);
-                                       // System.out.println("setting opacity 
for "+mn+" to "+metanodeOpacity);
-                                       mn.setMetaNodeOpacity(metanodeOpacity);
+                                       updateMetaNodeSettings(mn);
                                }
                        }
                        setVisible(false);
@@ -440,12 +516,7 @@
                                for (CyGroup group: groupList)  {
                                        MetaNode mn = 
MetaNodeManager.getMetaNode(group);
                                        if (mn != null) {
-                                               
mn.setUseNestedNetworks(useNestedNetworks);
-                                               // 
mn.setSizeToBoundingBox(sizeToBoundingBox);
-                                               
mn.setHideMetaNode(hideMetaNode);
-                                               
mn.setAggregateAttributes(enableHandling);
-                                               // System.out.println("setting 
opacity for "+mn+" to "+metanodeOpacity);
-                                               
mn.setMetaNodeOpacity(metanodeOpacity);
+                                               updateMetaNodeSettings(mn);
                                        }
                                }
                        }
@@ -453,6 +524,17 @@
                }
        }
 
+       private void updateMetaNodeSettings(MetaNode mn) {
+               mn.setUseNestedNetworks(useNestedNetworks);
+               // mn.setSizeToBoundingBox(sizeToBoundingBox);
+               mn.setHideMetaNode(hideMetaNode);
+               mn.setAggregateAttributes(enableHandling);
+               // System.out.println("setting opacity for "+mn+" to 
"+metanodeOpacity);
+               mn.setMetaNodeOpacity(metanodeOpacity);
+               mn.setChartType(chartType);
+               mn.setNodeChartAttribute(nodeChartAttribute);
+       }
+
        public void tunableChanged(Tunable t) {
                if (t.getName().equals("hideMetanodes")) {
       hideMetaNode = ((Boolean) t.getValue()).booleanValue();
@@ -467,6 +549,12 @@
       enableHandling = ((Boolean) t.getValue()).booleanValue();
                        AttributeManager.setEnable(enableHandling);
                        enableTunables(enableHandling);
+               } else if (t.getName().equals("nodeChartAttribute")) {
+                       nodeChartAttribute = (String)getListValue(t);
+                       
MetaNodeManager.setNodeChartAttributeDefault(nodeChartAttribute);
+               } else if (t.getName().equals("chartType")) {
+                       chartType = (String)getListValue(t);
+                       MetaNodeManager.setChartTypeDefault(chartType);
                } else if (t.getName().equals("attributeList")) {
                        CyAttributes attrs = null;
 
@@ -569,6 +657,15 @@
                pack();
        }
 
+       private void enableNodeCharts(boolean enableHandling) {
+               for (Tunable t: nodeChartEnablers) {
+                       // System.out.println("Setting immutable for "+t+" to 
"+(!enableHandling));
+                       t.setImmutable(!enableHandling);
+               }
+               doLayout();
+               pack();
+       }
+
        private void modifyVizMap() {
                // Get the current Visual Style
                VisualStyle currentStyle = 
Cytoscape.getCurrentNetworkView().getVisualStyle();

Added: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
                               (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
       2010-11-23 06:28:44 UTC (rev 22991)
@@ -0,0 +1,205 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2007 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package metaNodePlugin2.view;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+// giny imports
+import giny.view.EdgeView;
+import giny.view.NodeView;
+
+// Cytoscape imports
+import cytoscape.Cytoscape;
+import cytoscape.CyNode;
+import cytoscape.CyNetwork;
+import cytoscape.command.CyCommandException;
+import cytoscape.command.CyCommandManager;
+import cytoscape.command.CyCommandResult;
+import cytoscape.logger.CyLogger;
+import cytoscape.view.CyNetworkView;
+import cytoscape.data.CyAttributes;
+
+import cytoscape.groups.CyGroup;
+
+// Metanode imports
+import metaNodePlugin2.model.MetaNode;
+
+
+/**
+ * The NodeCharts class provides several static methods that
+ * manage the interface to the nodechart plugin
+ *
+ * It would be nice to reuse the AttributeHandler implementations, but
+ * we interpret things differently for nodeCharts than we do for aggregated
+ * attributes...
+ *
+ * At this point, this handles the following types:
+ *     TYPE_INTEGER: labels are the names of the nodes and the values are the 
values
+ *     TYPE_FLOATING: labels are the names of the nodes and the values are the 
values
+ *     TYPE_STRING: labels are the names of the strings and the values are the 
number of times that string occurs
+ *     TYPE_BOOLEAN: labels are either "True" or "False" and the values are 
the number of times that condition occurs
+ *     TYPE_SIMPLE_LIST: results depend on type:
+ *             String: labels are the names of the strings and the values are 
the number of times that string occurs
+ *             Integer: ??
+ *             Double: ??
+ */
+public class NodeCharts {
+
+       private static String VALUELIST = "valuelist";
+       private static String LABELLIST = "labellist";
+       
+       public static void updateNodeCharts(MetaNode mn, CyLogger logger) {
+               // Get the attribute we're using
+               String nodeChartAttribute = mn.getNodeChartAttribute();
+
+               // Get the chart type
+               String chartType = mn.getChartType();
+
+               if (nodeChartAttribute == null || chartType == null) return;
+
+               // Get the values from all of our children
+               CyGroup group = mn.getCyGroup();
+               List<CyNode> nodeList = group.getNodes();
+               if (nodeList == null) return;
+
+               CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
+
+               // Make sure this is a type that makes sense for us
+               byte attributeType = nodeAttributes.getType(nodeChartAttribute);
+               if (attributeType == CyAttributes.TYPE_UNDEFINED || 
attributeType == CyAttributes.TYPE_SIMPLE_MAP ||
+                   attributeType == CyAttributes.TYPE_COMPLEX || attributeType 
== CyAttributes.TYPE_BOOLEAN)
+                       return;
+
+               Map<String, Object> args = new HashMap<String, Object>();
+               args.put("node", group.getGroupNode().getIdentifier());
+               System.out.println("Node: 
"+group.getGroupNode().getIdentifier());
+               args.put("colorlist", "contrasting");
+               switch (attributeType) {
+                       case CyAttributes.TYPE_SIMPLE_LIST:
+                               getHistogramLabelsAndValues(args, group, 
nodeAttributes, nodeChartAttribute, chartType);
+                               break;
+                       case CyAttributes.TYPE_INTEGER:
+                       case CyAttributes.TYPE_FLOATING:
+                               getNumericLabelsAndValues(args, group, 
nodeAttributes, nodeChartAttribute, chartType);
+                               break;
+                       case CyAttributes.TYPE_BOOLEAN:
+                       case CyAttributes.TYPE_STRING:
+                               getStringLabelsAndValues(args, group, 
nodeAttributes, nodeChartAttribute, chartType);
+                               break;
+                       default:
+               }
+
+               try {
+                       CyCommandResult result = 
CyCommandManager.execute("nodecharts", "clear", args);
+                       result = CyCommandManager.execute("nodecharts", 
chartType, args);
+               } catch (CyCommandException cce) {
+                       logger.warning("node chart command failed: 
"+cce.getMessage());
+                       System.out.println("node chart command failed: 
"+cce.getMessage());
+               }
+       }
+
+       private static void getNumericLabelsAndValues(Map<String,Object>args, 
CyGroup group, CyAttributes nodeAttributes,
+                                                     String 
nodeChartAttribute, String chartType) {
+               List<String> labels = new ArrayList<String>();
+               List<String> values = new ArrayList<String>();
+               for (CyNode node: group.getNodes()) {
+                       if (nodeAttributes.hasAttribute(node.getIdentifier(), 
nodeChartAttribute)) {
+                               labels.add(node.getIdentifier());
+                               
values.add(nodeAttributes.getAttribute(node.getIdentifier(), 
nodeChartAttribute).toString());
+                       }
+               }
+               args.put(VALUELIST, values);
+               args.put(LABELLIST, labels);
+       }
+
+       private static void getStringLabelsAndValues(Map<String,Object>args, 
CyGroup group, CyAttributes nodeAttributes,
+                                                     String 
nodeChartAttribute, String chartType) {
+               Map<String, Integer> valueMap = new HashMap<String, Integer>();
+               for (CyNode node: group.getNodes()) {
+                       if (nodeAttributes.hasAttribute(node.getIdentifier(), 
nodeChartAttribute)) {
+                               String v = 
nodeAttributes.getAttribute(node.getIdentifier(), 
nodeChartAttribute).toString();
+                               
+                               if (!valueMap.containsKey(v))
+                                       valueMap.put(v, new Integer(1));
+                               else {
+                                       Integer count = valueMap.get(v);
+                                       valueMap.put(v, count+1);
+                               }
+                       }
+               }
+
+               // Now, we've got the histogram, create the appropriate arrays
+               List<String>labels = new ArrayList<String>(valueMap.keySet());
+               List<Integer>values = new ArrayList<Integer>();
+               for (String label: labels) {
+                       values.add(valueMap.get(label));
+               }
+               args.put(VALUELIST, values);
+               args.put(LABELLIST, labels);
+       }
+
+       private static void getHistogramLabelsAndValues(Map<String,Object>args, 
CyGroup group, CyAttributes nodeAttributes,
+                                                     String 
nodeChartAttribute, String chartType) {
+               System.out.println("Getting histogram labels and values");
+               Map<String, Integer> valueMap = new HashMap<String, Integer>();
+               for (CyNode node: group.getNodes()) {
+                       if (nodeAttributes.hasAttribute(node.getIdentifier(), 
nodeChartAttribute)) {
+                               List l = 
nodeAttributes.getListAttribute(node.getIdentifier(), nodeChartAttribute);
+                               for (Object v: l) {
+                                       String label = v.toString();
+                                       if (!valueMap.containsKey(label))
+                                               valueMap.put(label, new 
Integer(1));
+                                       else {
+                                               Integer count = 
valueMap.get(label);
+                                               valueMap.put(label, count+1);
+                                       }
+                               }
+                       }
+               }
+
+               // Now, we've got the histogram, create the appropriate arrays
+               List<String>labels = new ArrayList<String>(valueMap.keySet());
+               List<Integer>values = new ArrayList<Integer>();
+               for (String label: labels) {
+                       values.add(valueMap.get(label));
+               }
+               System.out.println("Values: "+values);
+               args.put(VALUELIST, values);
+               System.out.println("Labels: "+labels);
+               args.put(LABELLIST, labels);
+       }
+
+}

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/ViewUtils.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/ViewUtils.java
        2010-11-23 00:23:56 UTC (rev 22990)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/ViewUtils.java
        2010-11-23 06:28:44 UTC (rev 22991)
@@ -206,7 +206,7 @@
                        Dimension offset = getAttributes(node, nodeAttributes);
                        // offset might be null if we've just added the node
                        if (offset != null) {
-                               System.out.println("Offset for 
"+node.toString()+" is "+offset.getWidth()+"x"+offset.getHeight());
+                               // System.out.println("Offset for 
"+node.toString()+" is "+offset.getWidth()+"x"+offset.getHeight());
                                net.restoreNode(node);
                                NodeView nView = view.getNodeView(node);
                                double nodeWidth = 0.0;

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