Author: scooter
Date: 2010-11-29 10:11:12 -0800 (Mon, 29 Nov 2010)
New Revision: 23032

Modified:
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
   
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
Log:
Added NodeChart functionality


Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
   2010-11-29 17:23:25 UTC (rev 23031)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/MetaNodeGroupViewer.java
   2010-11-29 18:11:12 UTC (rev 23032)
@@ -79,6 +79,12 @@
        private static String NAMEDSELECTION = "namedselection";
        private static String NODECHARTS = "nodecharts";
 
+       /**
+        * Create a new group viewer for metanodes
+        *
+        * @param viewerName the name of the viewer
+        * @param logger our current logger
+        */
        public MetaNodeGroupViewer (String viewerName, CyLogger logger) {
                this.viewerName = viewerName;
                this.logger = logger;
@@ -104,10 +110,16 @@
                        return null;
        }
 
+       /**
+        * Return the settings dialog for this group viewer
+        */
        public MetanodeSettingsDialog getSettingsDialog() {
                return settingsDialog;
        }
 
+       /**
+        * Return our logger
+        */
        public CyLogger getLogger() {
                return this.logger;
        }
@@ -228,14 +240,12 @@
                } 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()) {
@@ -244,12 +254,22 @@
                }
        }
 
+       /**
+        * Returns true if the nodeChartPlugin is loaded, false otherwise
+        *
+        * @return 'true' if the nodeChartPlugin is loaded
+        */
        public boolean haveNodeCharts() {
                if (!haveNodeCharts)
                        haveNodeCharts = checkNodeCharts();
                return haveNodeCharts;
        }
 
+       /**
+        * Return the list of chart types the nodeChartPlugin supports
+        *
+        * @return a list of chart types (as Strings)
+        */
        public List<String> getChartTypes() {
                try {
                        Map<String,Object> args = new HashMap<String,Object>();
@@ -263,6 +283,9 @@
                return new ArrayList<String>();
        }
 
+       /**
+        * This routine checks to see if the nodeChartPlugin is loaded
+        */
        public boolean checkNodeCharts() {
                try {
                        CyCommandManager.getCommand(NODECHARTS, "clear");
@@ -303,6 +326,9 @@
                updateGroupPanel();
        }
 
+       /**
+        * Method to register ourselves with the group panel
+        */
        public void registerWithGroupPanel() {
                // First, see if the named selection plugin is loaded
                CyCommandHandler handler = null;

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
     2010-11-29 17:23:25 UTC (rev 23031)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/ui/MetanodeSettingsDialog.java
     2010-11-29 18:11:12 UTC (rev 23032)
@@ -50,6 +50,7 @@
 import cytoscape.CyNode;
 import cytoscape.Cytoscape;
 import cytoscape.data.CyAttributes;
+import cytoscape.data.CyAttributesUtils;
 import cytoscape.groups.CyGroup;
 import cytoscape.groups.CyGroupManager;
 import cytoscape.groups.CyGroupViewer;
@@ -110,6 +111,11 @@
        // Dialog components
        JPanel tunablePanel = null;
 
+       /**
+        * Create a new settings dialog
+        *
+        * @param viewer the group viewer
+        */
        public MetanodeSettingsDialog(MetaNodeGroupViewer viewer) {
                super(Cytoscape.getDesktop(), "Metanode Settings Dialog", 
false);
                metanodeProperties = new MetanodeProperties("metanode");
@@ -123,6 +129,9 @@
                pack();
        }
 
+       /**
+        * Initialize the dialog
+        */
        private void initialize() {
 
                JPanel mainPanel = new JPanel();
@@ -187,6 +196,10 @@
                setContentPane(mainPanel);
        }
 
+
+       /**
+        * Create all of our properties
+        */
        private void initializeProperties() {
                tunableEnablers = new ArrayList<Tunable>();
                nodeChartEnablers = new ArrayList<Tunable>();
@@ -395,24 +408,43 @@
                }
        }
 
+       /**
+        * Revert our settings
+        */
        public void revertSettings() {
                metanodeProperties.revertProperties();
                AttributeManager.revertSettings();
        }
 
+       /**
+        * Return our settings
+        *
+        * @return our properties
+        */
        public MetanodeProperties getSettings() {
                return metanodeProperties;
        }
 
+       /**
+        * Update all of our attribute manager override values
+        *
+        * @param network the network we're updating our override values for
+        */
        public void updateOverrides(CyNetwork network) {
                AttributeManager.loadHandlerMappings(network);
        }
 
+       /**
+        * Update the tunables that list attribute values
+        */
        public void updateAttributes() {
                attrList.setLowerBound(getAttributes());
                nodeChartAttrList.setLowerBound(getNodeAttributes());
        }
 
+       /**
+        * Update our list of node chart types
+        */
        public void updateNodeChartTypes() {
                if (groupViewer.checkNodeCharts()) {
                        enableNodeCharts(true);
@@ -421,6 +453,9 @@
                        enableNodeCharts(false);
        }
 
+       /**
+        * Return 'true' if we're supposed to use the nested network viewer
+        */
        public boolean getUseNestedNetworks() {
                updateSettings(false);
                String bv = 
(String)metanodeProperties.getProperties().get("useNestedNetworks");
@@ -428,6 +463,11 @@
                return useNestedNetworks;
        }
 
+       /**
+        * Return all of the node attributes as a string array
+        *
+        * @return array of node attributes
+        */
        private String[] getNodeAttributes() {
                CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
                List<String> attributeList = new ArrayList();
@@ -438,6 +478,11 @@
                return attributeArray;
        }
 
+       /**
+        * Return all of the attributes as a string array
+        *
+        * @return array of attributes
+        */
        private String[] getAttributes() {
                CyAttributes nodeAttributes = Cytoscape.getNodeAttributes();
                CyAttributes edgeAttributes = Cytoscape.getEdgeAttributes();
@@ -451,6 +496,11 @@
                return attributeArray;
        }
 
+       /**
+        * Return all of the chart types as a string array
+        *
+        * @return array of chart types
+        */
        private String[] getChartTypes() {
                String [] a = new String[1];
                List<String> viewerList = groupViewer.getChartTypes();
@@ -473,6 +523,9 @@
                }
        }
 
+       /**
+        * Methods to support the ComponentListener interface
+        */
        public void componentHidden(ComponentEvent e) {}
        public void componentShown(ComponentEvent e) {}
        public void componentMoved(ComponentEvent e) {}
@@ -481,6 +534,9 @@
                pack();
        }
 
+       /**
+        * This method is called when the user performs an action
+        */
        public void actionPerformed(ActionEvent e) {
                String command = e.getActionCommand();
 
@@ -496,6 +552,8 @@
                } else if (command.equals("clear")) {
                        AttributeManager.clearSettings();
                        tunableChanged(attrList);
+
+               // Apply the current settings to the selected metanodes
                } else if (command.equals("applySelected")) {
                        updateSettings(true);
                        // Get all selected nodes
@@ -507,6 +565,8 @@
                                }
                        }
                        setVisible(false);
+
+               // Apply the current settings to all metanodes
                } else if (command.equals("applyAll")) {
                        updateSettings(true);
                        // Get the list of groups
@@ -556,52 +616,10 @@
                        chartType = (String)getListValue(t);
                        MetaNodeManager.setChartTypeDefault(chartType);
                } else if (t.getName().equals("attributeList")) {
-                       CyAttributes attrs = null;
-
-                       // Get the attribute
                        String attributeWP = (String)getListValue(t);
-
                        if (attributeWP == null)
                                return;
-
-                       // Strip prefix
-                       String attribute = attributeWP.substring(5);
-
-                       if (attributeWP.startsWith("edge"))
-                               attrs = Cytoscape.getEdgeAttributes();
-                       else
-                               attrs = Cytoscape.getNodeAttributes();
-
-                       byte type = attrs.getType(attribute);
-
-                       // Get the list
-                       AttributeHandlingType[] hTypes = 
AttributeManager.getHandlingOptions(type);
-                       AttributeHandlingType[] handlingTypes = new 
AttributeHandlingType[hTypes.length+1];
-
-                       handlingTypes[0] = AttributeHandlingType.DEFAULT;
-                       for (int i = 0; i < hTypes.length; i++) {
-                               handlingTypes[i+1] = hTypes[i];
-                       }
-
-                       // Set the name
-                       typeString.setValue(attributeName(type));
-
-                       typeList.removeTunableValueListener(this);
-                       // Update the list
-                       typeList.setLowerBound(handlingTypes);
-
-                       // Do we already have a handler?
-                       AttributeHandler handler = 
AttributeManager.getHandler(attributeWP);
-                       if (handler != null) {
-                               // Yes, show the right one to the user
-                               for (int i = 0; i < handlingTypes.length; i++) {
-                                       if (handler.getHandlerType() == 
handlingTypes[i]) {
-                                               
typeList.setValue(Integer.valueOf(i));
-                                               break;
-                                       }
-                               }
-                       }
-                       typeList.addTunableValueListener(this);
+                       updateAttributeHandlers(attributeWP);
                } else if (t.getName().equals("aggregationType")) {
                        // Get the attribute
                        String attributeWP = (String)getListValue(attrList);
@@ -615,25 +633,48 @@
                repaint();
        }
 
-       private String attributeName(byte type) {
-               switch (type) {
-                       case CyAttributes.TYPE_BOOLEAN:
-                               return "Boolean";
-                       case CyAttributes.TYPE_INTEGER:
-                               return "Integer";
-                       case CyAttributes.TYPE_FLOATING:
-                               return "Floating-point";
-                       case CyAttributes.TYPE_STRING:
-                               return "String";
-                       case CyAttributes.TYPE_SIMPLE_LIST:
-                               return "Simple List";
-                       case CyAttributes.TYPE_SIMPLE_MAP:
-                               return "Simple Map";
-                       case CyAttributes.TYPE_COMPLEX:
-                               return "Complex type (unsupported)";
-                       default:
-                               return "Undefined";
+       private void updateAttributeHandlers(String attributeWP) {
+               CyAttributes attrs = null;
+
+               // Strip prefix
+               String attribute = attributeWP.substring(5);
+
+               if (attributeWP.startsWith("edge"))
+                       attrs = Cytoscape.getEdgeAttributes();
+               else
+                       attrs = Cytoscape.getNodeAttributes();
+
+               byte type = attrs.getType(attribute);
+
+               // Get the list
+               AttributeHandlingType[] hTypes = 
AttributeManager.getHandlingOptions(type);
+               AttributeHandlingType[] handlingTypes = new 
AttributeHandlingType[hTypes.length+1];
+
+               handlingTypes[0] = AttributeHandlingType.DEFAULT;
+               for (int i = 0; i < hTypes.length; i++) {
+                       handlingTypes[i+1] = hTypes[i];
                }
+
+               // Set the name
+               typeString.setValue(CyAttributesUtils.toString(type));
+
+               typeList.removeTunableValueListener(this);
+               // Update the list
+               typeList.setLowerBound(handlingTypes);
+
+               // Do we already have a handler?
+               AttributeHandler handler = 
AttributeManager.getHandler(attributeWP);
+               if (handler != null) {
+                       // Yes, show the right one to the user
+                       for (int i = 0; i < handlingTypes.length; i++) {
+                                       if (handler.getHandlerType() == 
handlingTypes[i]) {
+                                       typeList.setValue(Integer.valueOf(i));
+                                       break;
+                               }
+                       }
+               }
+               typeList.addTunableValueListener(this);
+               return;
        }
 
        private Object getListValue(Tunable t) {

Modified: 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
       2010-11-29 17:23:25 UTC (rev 23031)
+++ 
csplugins/trunk/ucsf/scooter/metaNodePlugin2/src/metaNodePlugin2/view/NodeCharts.java
       2010-11-29 18:11:12 UTC (rev 23032)
@@ -81,6 +81,13 @@
        private static String VALUELIST = "valuelist";
        private static String LABELLIST = "labellist";
        
+       /**
+        * This method calculates the values and labels and draws the 
+        * node chart on a metanode.
+        *
+        * @param mn the metanode we're drawing on
+        * @param logger the CyLogger we're using
+        */
        public static void updateNodeCharts(MetaNode mn, CyLogger logger) {
                // Get the attribute we're using
                String nodeChartAttribute = mn.getNodeChartAttribute();
@@ -103,10 +110,12 @@
                    attributeType == CyAttributes.TYPE_COMPLEX || attributeType 
== CyAttributes.TYPE_BOOLEAN)
                        return;
 
+               // Create our argument map
                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");
+
+               // Depending on the attribute type -- do the right thing
                switch (attributeType) {
                        case CyAttributes.TYPE_SIMPLE_LIST:
                                getHistogramLabelsAndValues(args, group, 
nodeAttributes, nodeChartAttribute, chartType);
@@ -123,14 +132,18 @@
                }
 
                try {
+                       // First, make sure we don't have any nodechart on the 
node
                        CyCommandResult result = 
CyCommandManager.execute("nodecharts", "clear", args);
+                       // Now, add the node chart
                        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());
                }
        }
 
+       /**
+        * This method is used to handle numeric attribute types
+        */
        private static void getNumericLabelsAndValues(Map<String,Object>args, 
CyGroup group, CyAttributes nodeAttributes,
                                                      String 
nodeChartAttribute, String chartType) {
                List<String> labels = new ArrayList<String>();
@@ -145,60 +158,57 @@
                args.put(LABELLIST, labels);
        }
 
+       /**
+        * This method is used to handle string attribute types
+        */
        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);
-                               }
+                               incrementHistogram(valueMap, v);
                        }
                }
 
-               // 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);
+               addHistoArgs(valueMap, args);
        }
 
+       /**
+        * This method is used to handle list attribute types
+        */
        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);
-                                       }
+                                       incrementHistogram(valueMap, label);
                                }
                        }
                }
+               addHistoArgs(valueMap, args);
+       }
 
+       private static void incrementHistogram(Map<String, Integer> map, String 
value) {
+               if (!map.containsKey(value))
+                       map.put(value, new Integer(1));
+               else {
+                       Integer count = map.get(value);
+                       map.put(value, count+1);
+               }
+       }
+
+       private static void addHistoArgs(Map<String, Integer> map, Map<String, 
Object> args) {
                // Now, we've got the histogram, create the appropriate arrays
-               List<String>labels = new ArrayList<String>(valueMap.keySet());
+               List<String>labels = new ArrayList<String>(map.keySet());
                List<Integer>values = new ArrayList<Integer>();
                for (String label: labels) {
-                       values.add(valueMap.get(label));
+                       values.add(map.get(label));
                }
-               System.out.println("Values: "+values);
                args.put(VALUELIST, values);
-               System.out.println("Labels: "+labels);
                args.put(LABELLIST, labels);
        }
 

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