Author: scooter
Date: 2010-08-04 11:18:06 -0700 (Wed, 04 Aug 2010)
New Revision: 21189

Added:
   csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/Columns.java
Modified:
   
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/CreateByAttributeDialog.java
   csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupTableModel.java
   csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupToolDialog.java
Log:
Additions for 2.8 network-specific groups


Added: csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/Columns.java
===================================================================
--- csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/Columns.java        
                        (rev 0)
+++ csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/Columns.java        
2010-08-04 18:18:06 UTC (rev 21189)
@@ -0,0 +1,76 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2006 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 groupTool.ui;
+
+// System imports
+import java.util.List;
+import java.util.ArrayList;
+
+public enum Columns {
+       NAME("Group Name", String.class),
+       NETWORK("Network", String.class),
+       NODES("Nodes", Integer.class),
+       INTERNAL("Internal Edges", Integer.class),
+       EXTERNAL("External Edges", Integer.class),
+       VIEWER("Viewer", String.class);
+
+       protected static List<Columns> columnList;
+
+       protected static void addColumn(Columns column) { 
+               if (columnList == null) columnList = new ArrayList<Columns>();
+               columnList.add(column); 
+       }
+
+       public static int columnCount() { return columnList.size(); }
+
+       public static String getColumnName(int col) { return 
columnList.get(col).toString(); }
+       public static Columns getColumn(int col) { return columnList.get(col); }
+       public static int getColumnNumber(Columns column) {
+               for (int i = 0; i < columnList.size(); i++) {
+                       if (columnList.get(i).equals(column)) return i;
+               }
+               return -1;
+       }
+
+       private String columnName = null;
+       private Class columnClass = null;
+
+       Columns(String name, Class classType) {
+               columnName = name;
+               columnClass = classType;
+               Columns.addColumn(this);
+       }
+
+       public String toString() {return columnName;}
+       public Class getColumnClass() { return columnClass; }
+}

Modified: 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/CreateByAttributeDialog.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/CreateByAttributeDialog.java
        2010-08-04 18:04:14 UTC (rev 21188)
+++ 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/CreateByAttributeDialog.java
        2010-08-04 18:18:06 UTC (rev 21189)
@@ -226,7 +226,7 @@
                                        CyGroupManager.removeGroup(group);
                                }
 
-                               group = CyGroupManager.createGroup(groupName, 
nodeList, viewer);
+                               group = CyGroupManager.createGroup(groupName, 
nodeList, viewer, network);
                                // nodeAttributes.setAttribute(groupName, 
attribute, groupName);
                                CyGroupViewer groupViewer = 
CyGroupManager.getGroupViewer(viewer);
                                groupViewer.groupCreated(group);

Modified: 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupTableModel.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupTableModel.java    
    2010-08-04 18:04:14 UTC (rev 21188)
+++ 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupTableModel.java    
    2010-08-04 18:18:06 UTC (rev 21189)
@@ -32,29 +32,18 @@
  */
 package groupTool.ui;
 
+import javax.swing.table.AbstractTableModel;
+
 // System imports
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.HashMap;
 
-import javax.swing.*;
-import javax.swing.table.*;
-import javax.swing.event.*;
-import javax.swing.text.Position;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.event.*;
-
 // Cytoscape imports
 import cytoscape.CyNetwork;
-import cytoscape.CyNode;
-import cytoscape.view.CyNetworkView;
-import cytoscape.groups.*;
+import cytoscape.groups.CyGroup;
+import cytoscape.groups.CyGroupManager;
 
+
 /**
  * The GroupTableModel class provides the table model used by the 
GroupToolDialog
  *
@@ -64,8 +53,6 @@
 public class GroupTableModel 
              extends AbstractTableModel {
 
-       private static final String[] columnNames = {"Group Name", "Nodes", 
"Internal Edges", "External Edges", "Viewer"};
-
        private GroupToolDialog groupDialog = null;
        private List<CyGroup> groupList = null;
 
@@ -93,7 +80,7 @@
         *
         * @return 5
         */
-       public int getColumnCount() { return columnNames.length; }
+       public int getColumnCount() { return Columns.columnCount(); }
 
        /**
         * Return the value at the requested row and column.  In our case
@@ -107,17 +94,28 @@
         */
        public Object getValueAt(int row, int col) {
                CyGroup group = groupList.get(row);
-               if (col == 0) {
+
+               Columns column = Columns.getColumn(col);
+               switch (column) {
+
+               case NAME:
                        return group.getGroupName();
-               } else if (col == 1) {
-                       return new Integer(group.getNodes().size());
-               } else if (col == 2) {
+               case NETWORK:
+                       CyNetwork net = group.getNetwork();
+                       if (net != null)
+                               return net.getTitle();
+                       return "Global";
+               case INTERNAL:
                        return new Integer(group.getInnerEdges().size());
-               } else if (col == 3) {
+               case EXTERNAL:
                        return new Integer(group.getOuterEdges().size());
-               } else if (col == 4) {
+               case NODES:
+                       return new Integer(group.getNodes().size());
+               case VIEWER:
                        return group.getViewer();
+
                }
+
                return null;
        }
 
@@ -129,7 +127,8 @@
         * @return false
         */
        public boolean isCellEditable(int row, int col) {
-               if (col == 4) 
+               Columns column = Columns.getColumn(col);
+               if (column == Columns.VIEWER || column == Columns.NETWORK) 
                        return true;
 
                return false;
@@ -142,7 +141,7 @@
         * @return column name as a String
         */
        public String getColumnName(int col) {
-               return columnNames[col];
+               return Columns.getColumnName(col);
        }
 
        /**
@@ -153,9 +152,7 @@
         * @return object Class of this column
         */
        public Class getColumnClass(int c) {
-               if (c == 0 || c == 4) return String.class;
-
-               return Integer.class;
+               return Columns.getColumn(c).getColumnClass();
        }
 
        public CyGroup getGroupAtRow(int row) {

Modified: 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupToolDialog.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupToolDialog.java    
    2010-08-04 18:04:14 UTC (rev 21188)
+++ 
csplugins/trunk/ucsf/scooter/groupTool/src/groupTool/ui/GroupToolDialog.java    
    2010-08-04 18:18:06 UTC (rev 21189)
@@ -35,8 +35,6 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Collection;
-import java.util.Iterator;
-import java.util.HashMap;
 
 import javax.swing.*;
 import javax.swing.tree.*;
@@ -53,7 +51,10 @@
 import java.awt.GridBagLayout;
 import java.awt.event.*;
 
-import cytoscape.groups.*;
+import cytoscape.groups.CyGroup;
+import cytoscape.groups.CyGroupChangeListener;
+import cytoscape.groups.CyGroupManager;
+import cytoscape.groups.CyGroupViewer;
 import cytoscape.Cytoscape;
 import cytoscape.CyNetwork;
 import cytoscape.CyNode;
@@ -115,7 +116,8 @@
                this.groupTable = new JTable(sorter);
                sorter.setTableHeader(groupTable.getTableHeader());
 
-               setUpViewerRenderer(groupTable, 
groupTable.getColumnModel().getColumn(4));
+               setUpViewerRenderer(groupTable);
+               setUpNetworkRenderer(groupTable);
                groupTable.setCellSelectionEnabled(true);
                ListSelectionModel lsm = groupTable.getSelectionModel();
                
lsm.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
@@ -189,13 +191,14 @@
                        List<CyGroup> groupList = CyGroupManager.getGroupList();
                        String groupName = JOptionPane.showInputDialog("Please 
enter a name for this group");
                        if (groupName == null) return;
-                       CyGroup group = CyGroupManager.createGroup(groupName, 
currentNodes, null);
+                       CyGroup group = CyGroupManager.createGroup(groupName, 
currentNodes, null, network);
                } else if ("delete".equals(e.getActionCommand())) {
                        // Don't listen until we're done
                        CyGroupManager.removeGroupChangeListener(this);
                        int rows[] = groupTable.getSelectedRows();
                        for (int row = 0; row < rows.length; row++) {
-                               String groupName = (String) 
groupTable.getValueAt(rows[row], 0);
+                               String groupName = (String) 
groupTable.getValueAt(rows[row], 
+                                                                               
  Columns.getColumnNumber(Columns.NAME));
                                CyGroup group = 
CyGroupManager.findGroup(groupName);
                                if (group == null) continue;
                                CyGroupManager.removeGroup(group);
@@ -214,7 +217,8 @@
                        if (rows == null) return;
                        int cols[] = groupTable.getSelectedColumns();
                        for (int row = 0; row < rows.length; row++) {
-                               String groupName = (String) 
groupTable.getValueAt(rows[row], 0);
+                               String groupName = (String) 
groupTable.getValueAt(rows[row], 
+                                                                               
  Columns.getColumnNumber(Columns.NAME));
                                CyGroup group = 
CyGroupManager.findGroup(groupName);
                                if (group == null) continue;
 
@@ -224,14 +228,30 @@
                                        if 
("clear".equals(e.getActionCommand())) 
                                                state = false;
 
-                                       if (cols[col] == 1 || cols[col] == 0) {
+                                       Columns column = 
Columns.getColumn(cols[col]);
+
+                                       switch (column) {
+                                       case NAME:
                                                
Cytoscape.getCurrentNetwork().setSelectedNodeState(group.getGroupNode(), state);
                                                
Cytoscape.getCurrentNetwork().setSelectedNodeState(group.getNodes(), state);
-                                       }
-                                       if (cols[col] == 2 || cols[col] == 0)
                                                
Cytoscape.getCurrentNetwork().setSelectedEdgeState(group.getInnerEdges(), 
state);
-                                       if (cols[col] == 3 || cols[col] == 0)
                                                
Cytoscape.getCurrentNetwork().setSelectedEdgeState(group.getOuterEdges(), 
state);
+                                               break;
+
+                                       case NODES:
+                                               
Cytoscape.getCurrentNetwork().setSelectedNodeState(group.getGroupNode(), state);
+                                               
Cytoscape.getCurrentNetwork().setSelectedNodeState(group.getNodes(), state);
+                                               break;
+
+                                       case INTERNAL:
+                                               
Cytoscape.getCurrentNetwork().setSelectedEdgeState(group.getInnerEdges(), 
state);
+                                               break;
+
+                                       case EXTERNAL:
+                                               
Cytoscape.getCurrentNetwork().setSelectedEdgeState(group.getOuterEdges(), 
state);
+                                               break;
+                                       }
+
                                }
                        }
                        Cytoscape.getCurrentNetworkView().updateView();
@@ -242,12 +262,12 @@
                }
        }
 
-       private void setUpViewerRenderer(JTable table, TableColumn 
viewerColumn) {
+       private void setUpViewerRenderer(JTable table) {
+               int viewerCol = Columns.getColumnNumber(Columns.VIEWER);
+               TableColumn viewerColumn = 
groupTable.getColumnModel().getColumn(viewerCol);
                JComboBox vBox = new JComboBox();
                Collection<CyGroupViewer> viewers = 
CyGroupManager.getGroupViewers();
-               Iterator <CyGroupViewer> vIter = viewers.iterator();
-               while (vIter.hasNext()) {
-                       CyGroupViewer gv = vIter.next();
+               for (CyGroupViewer gv: viewers) {
                        vBox.addItem(gv.getViewerName());
                }
                DefaultCellEditor editor = new DefaultCellEditor(vBox);
@@ -255,21 +275,65 @@
                viewerColumn.setCellEditor(editor);
        }
 
+       private void setUpNetworkRenderer(JTable table) {
+               int netCol = Columns.getColumnNumber(Columns.NETWORK);
+               TableColumn networkColumn = 
groupTable.getColumnModel().getColumn(netCol);
+               JComboBox vBox = new JComboBox();
+               // Get the list of networks
+               Collection<CyNetwork> networks = Cytoscape.getNetworkSet();
+               for (CyNetwork net: networks) {
+                       vBox.addItem(net.getTitle());
+               }
+               vBox.addItem("Global");
+               DefaultCellEditor editor = new DefaultCellEditor(vBox);
+               editor.addCellEditorListener(this);
+               networkColumn.setCellEditor(editor);
+       }
+
        public void editingCanceled(ChangeEvent e) { }
 
        public void editingStopped(ChangeEvent e) {
                int row = groupTable.getSelectedRow();
                int col = groupTable.getSelectedColumn();
-               if (row == -1 || col != 4) return;
+               if (row == -1) return;
 
+               Columns column = Columns.getColumn(col);
+               CyGroup group = tableModel.getGroupAtRow(row);
                DefaultCellEditor editor = (DefaultCellEditor)e.getSource();
-               String viewerName = (String) editor.getCellEditorValue();
-               String oldViewerName = (String)groupTable.getValueAt(row,col);
-               if (viewerName.equals(oldViewerName)) return;
-               CyGroup group = tableModel.getGroupAtRow(row);
 
-               // Set the new viewer
-               CyGroupManager.setGroupViewer(group, viewerName, 
Cytoscape.getCurrentNetworkView(), true);
+               switch (column) {
+                       case VIEWER:
+                               String viewerName = (String) 
editor.getCellEditorValue();
+                               String oldViewerName = 
(String)groupTable.getValueAt(row,col);
+                               if (viewerName.equals(oldViewerName)) return;
+
+                               // Set the new viewer
+                               CyGroupManager.setGroupViewer(group, 
viewerName, Cytoscape.getCurrentNetworkView(), true);
+                               break;
+
+                       case NETWORK:
+                               String networkName = (String) 
editor.getCellEditorValue();
+                               String oldNetworkName = 
(String)groupTable.getValueAt(row,col);
+                               if (networkName.equals(oldNetworkName)) return;
+
+                               // OK, update the network
+
+                               if (networkName.equals("Global")) {
+                                       group.setNetwork(null, true);
+                                       return;
+                               }
+
+                               Collection<CyNetwork> networks = 
Cytoscape.getNetworkSet();
+                               for (CyNetwork network: networks) {
+                                       if 
(network.getTitle().equals(networkName)) {
+                                               group.setNetwork(network, true);
+                                               return;
+                                       }
+                               }
+                               break;
+                               
+               }
+               return;
        }
 
        public void valueChanged (ListSelectionEvent e) {

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