Author: neildhruva
Date: 2012-07-18 10:56:34 -0700 (Wed, 18 Jul 2012)
New Revision: 29920

Added:
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableAdded.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableDestroyed.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyCytoPanel.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyTableModel.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
Removed:
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactory.java
Log:
directory changes

Deleted: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactory.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/ChartAppFactory.java
    2012-07-18 02:25:51 UTC (rev 29918)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactory.java
   2012-07-18 17:56:34 UTC (rev 29920)
@@ -1,18 +0,0 @@
-package org.cytoscape.neildhruva.chartapp.api;
-
-import javax.swing.JPanel;
-
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyTable;
-
-public interface ChartAppFactory {
-       
-       /**
-        * Creates a {@link JPanel} consisting of a JFreeChart, checkboxes with 
column names etc.
-        * @param currentNetwork The current {@link CyNetwork}.
-        * @param cyTable The {@link CyTable} that contains values to be 
plotted on the {@link JFreeChart}
-        * @return The {@link JPanel} consisting of the chart, checkboxes with 
column names etc.
-        */
-       JPanel createPanel(CyNetwork currentNetwork, CyTable cyTable);
-
-}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/ChartAppFactoryImpl.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
       2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,97 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.util.ArrayList;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JPanel;
+import javax.swing.JTable;
+
+import org.cytoscape.model.CyIdentifiable;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNetworkTableManager;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+import org.cytoscape.model.CyTableFactory;
+import org.cytoscape.model.CyTableManager;
+
+import org.cytoscape.neildhruva.chartapp.api.ChartAppFactory;
+
+public class ChartAppFactoryImpl implements ChartAppFactory {
+
+       private JPanel jpanel;
+       private int tableColumnCount;
+       private CyTableFactory tableFactory;
+       private CyNetworkTableManager cyNetworkTableMgr;
+       private CyTableManager cyTableManager;
+       private PanelComponents panelComponents;
+       private PanelLayout panelLayout;
+       
+       public ChartAppFactoryImpl(     CyTableFactory tableFactory,
+                                                               
CyNetworkTableManager cyNetworkTableMgr,
+                                                               CyTableManager 
cyTableManager) {
+
+               this.tableFactory = tableFactory;
+               this.cyNetworkTableMgr = cyNetworkTableMgr;
+               this.cyTableManager = cyTableManager;
+               this.panelLayout = new PanelLayout();
+               this.panelComponents = new PanelComponents(panelLayout);
+       }
+       
+       public JPanel createPanel(CyNetwork currentNetwork, CyTable cyTable) {
+               
+               final Long networkSUID = currentNetwork.getSUID();
+               JTable table = new JTable(new MyTableModel(cyTable));
+               tableColumnCount = table.getColumnCount();
+               
+               if(tableColumnCount>0) {
+                       
+                       //myCyTable is the custom CyTable created for this app 
and associated with each network.
+                       CyTable myCyTable=null;
+                       
+                       myCyTable = cyNetworkTableMgr.getTable(currentNetwork, 
CyNetwork.class, "PrintTable "+cyTable.getTitle());
+                       
+                       if(myCyTable!=null) {
+                               panelComponents.initComponents(myCyTable, 
cyTable);
+                       } else {
+                               //checkBoxState stores information on whether a 
given column of a network table is
+                               //hidden or visible depending on the associated 
boolean value (true for visible)
+                               ArrayList<Boolean> checkBoxState = new 
ArrayList<Boolean>();
+                               ArrayList<String> columnNamesList = new 
ArrayList<String>();
+                               for(int i=0; i<tableColumnCount; i++) {
+                                       
columnNamesList.add(table.getColumnName(i));
+                                       checkBoxState.add(true);
+                               }
+                               
+                               //if myCyTable is null, create a new CyTable 
and associate it with the current network.
+                               myCyTable = 
tableFactory.createTable("PrintTable "+cyTable.getTitle(), CyIdentifiable.SUID, 
Long.class, true, true);
+                               myCyTable.createListColumn("Names", 
String.class, true);
+                               myCyTable.createListColumn("States", 
Boolean.class, true);
+                               myCyTable.createColumn("ChartType", 
String.class, true);
+                       
+                               CyRow cyrow = myCyTable.getRow(networkSUID);
+                               cyrow.set("Names", columnNamesList);
+                               cyrow.set("States", checkBoxState);
+                               cyrow.set("ChartType", "Bar Chart"); //default 
value is "Bar Chart"
+                       
+                               //associate myCyTable with this network 
+                               cyNetworkTableMgr.setTable(currentNetwork, 
CyNetwork.class, "PrintTable "+cyTable.getTitle(), myCyTable);
+                               //add myCyTable to the CyTableManager in order 
to preserve it across sessions
+                               cyTableManager.addTable(myCyTable);
+                       
+                               panelComponents.initComponents(myCyTable, 
cyTable);
+                       }       
+               
+                       JComboBox chartTypeComboBox = 
panelComponents.getComboBox();
+                       table = panelComponents.getTable();
+                       JCheckBox[] checkBoxArray = 
panelComponents.getCheckBoxArray();
+                       jpanel = panelLayout.initLayout(table, 
tableColumnCount, checkBoxArray, chartTypeComboBox);
+               } else {
+                       jpanel = panelLayout.nullJPanel();
+               }
+               
+               return jpanel;
+       }
+
+
+}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/CytoChart.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
                         (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
 2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,102 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.util.Vector;
+
+import javax.swing.JTable;
+
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.data.category.DefaultCategoryDataset;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+
+public class CytoChart {
+
+       private JFreeChart chart;
+    private DefaultCategoryDataset dataset;
+    Vector<String> plottableColumns;
+    
+       public CytoChart(JTable table) {
+               
+       }
+       
+       /**
+        * Creates a chart/graph and puts it in a chart panel.
+        * 
+        * @return The <code>ChartPanel</code> that contains the newly created 
chart.
+        */
+       public JFreeChart createChart(String chartType){
+               
+               if(chartType.equals("Bar Chart")){
+                       return BarChart();
+               }
+                       
+               else{
+                       return XYChart();
+               }
+               
+       }
+       
+       /**
+        * Creates an XY Plot (Line Chart).
+        * @return Chart containing the XY plot.
+        */
+       public JFreeChart XYChart() {
+               
+               // Create a simple XY chart
+               XYSeries series = new XYSeries("XYGraph");
+               series.add(1, 1);
+               series.add(1, 2);
+               series.add(2, 1);
+               series.add(3, 9);
+               series.add(4, 10);
+               // Add the series to the data set
+               XYSeriesCollection dataset = new XYSeriesCollection();
+               dataset.addSeries(series);
+               
+               // Generate the graph
+               chart = ChartFactory.createXYLineChart(
+               "XY Chart", // Title
+               "x-axis", // x-axis Label
+               "y-axis", // y-axis Label
+               dataset, // Dataset
+               PlotOrientation.VERTICAL, // Plot Orientation
+               true, // Show Legend
+               true, // Use tooltips
+               false // Configure chart to generate URLs?
+               );
+               
+               
+               return chart;
+               
+       }
+       
+       /**
+        * Creates a Bar Chart.
+        * @return The bar chart.
+        */
+       public JFreeChart BarChart() {
+               
+               this.dataset = new DefaultCategoryDataset();
+               
+               dataset.setValue(6, "Profit", "Jane");
+               dataset.setValue(7, "Profit", "Tom");
+               dataset.setValue(8, "Profit", "Jill");
+               dataset.setValue(5, "Profit", "John");
+               dataset.setValue(12, "Profit", "Fred");
+               chart = ChartFactory.createBarChart("Comparison between 
Salesman",
+               "Salesman", "Profit", dataset, PlotOrientation.VERTICAL,
+               false, true, false);
+               
+               return chart;
+       }
+       
+       /**
+        * 
+        * @return The current chart.
+        */
+       public JFreeChart getTheChart() {
+               return this.chart;
+       }
+}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableAdded.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/EventTableAdded.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableAdded.java
                           (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableAdded.java
   2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,37 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import javax.swing.JPanel;
+
+import org.cytoscape.application.events.SetCurrentNetworkEvent;
+import org.cytoscape.application.events.SetCurrentNetworkListener;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyTable;
+
+import org.cytoscape.neildhruva.chartapp.api.ChartAppFactory;
+
+public class EventTableAdded implements SetCurrentNetworkListener{
+
+       private MyCytoPanel myCytoPanel; 
+       private ChartAppFactory chartAppFactory;
+       
+       EventTableAdded(MyCytoPanel myCytoPanel, ChartAppFactory 
chartAppFactory) {     
+               this.myCytoPanel = myCytoPanel;
+               this.chartAppFactory = chartAppFactory;
+       }
+
+       @Override
+       public void handleEvent(SetCurrentNetworkEvent e) {
+               
+               final CyNetwork cyNetwork = e.getNetwork();
+               if(cyNetwork == null) 
+                       return;
+               
+               //cyTable is the CyTable corresponding to the current node table
+               final CyTable cyTable = e.getNetwork().getDefaultNodeTable();
+               if(cyTable==null)
+                       return;
+               
+               JPanel jpanel = chartAppFactory.createPanel(cyNetwork, cyTable);
+               myCytoPanel.setJPanel(jpanel);
+       }
+}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableDestroyed.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/EventTableDestroyed.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableDestroyed.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableDestroyed.java
       2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,29 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.awt.GridLayout;
+
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
+
+public class EventTableDestroyed implements NetworkAboutToBeDestroyedListener{
+
+       private MyCytoPanel myCytoPanel;
+       
+       EventTableDestroyed(MyCytoPanel myCytoPanel){
+               this.myCytoPanel = myCytoPanel;
+       }
+       
+       @Override
+       public void handleEvent(NetworkAboutToBeDestroyedEvent e) {
+               
+               JLabel label = new JLabel("Please select/import a network");
+               JPanel jpanel=new JPanel();
+           jpanel.setLayout(new GridLayout());
+               jpanel.add(label);
+               myCytoPanel.setJPanel(jpanel);
+               
+       }
+}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyCytoPanel.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/MyCytoPanel.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyCytoPanel.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyCytoPanel.java
       2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,58 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.awt.Component;
+import java.awt.GridLayout;
+
+import javax.swing.Icon;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.application.swing.CytoPanelName;
+
+@SuppressWarnings("serial")
+public class MyCytoPanel extends JPanel implements CytoPanelComponent {
+       
+    public MyCytoPanel() {
+       JLabel label = new JLabel("Please select/import a network");
+       this.setLayout(new GridLayout());
+               this.add(label);
+               this.setVisible(true);
+       }
+    
+    /**
+     * Resets the JPanel contained in this CytoPanel.
+     * @param jpanel The new JPanel that contains the chart, checkboxes etc.
+     */
+    public void setJPanel(JPanel jpanel) {
+       this.removeAll();
+       this.add(jpanel);
+       this.revalidate();
+    }
+    
+       public Component getComponent() {
+               return this;
+       }
+       
+       /**
+        * @return Location of the CytoPanel
+        */
+       public CytoPanelName getCytoPanelName() {
+               return CytoPanelName.SOUTH;
+       }
+
+       /**
+        * @return Title of the CytoPanel
+        */
+       public String getTitle() {
+               return "Table View";
+       }
+
+       /**
+        * @return Icon
+        */
+       public Icon getIcon() {
+               return null;
+       }
+       
+}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyTableModel.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/MyTableModel.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyTableModel.java
                              (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyTableModel.java
      2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,94 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.util.Collection;
+import java.util.Vector;
+
+import javax.swing.table.AbstractTableModel;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyTable;
+
+public class MyTableModel extends AbstractTableModel {
+
+       private static final long serialVersionUID = 4744686051219349710L;
+       
+       private CyTable cytable;
+       private String[] columnNames;
+       private int columnLength;
+       
+       public MyTableModel(CyTable cytable){
+               this.cytable = cytable;
+               this.columnLength = setColumnCount();
+               this.columnNames = setColumnNames();
+       }
+       
+       @Override
+       public int getColumnCount() {
+               return this.columnLength;
+       }
+
+       @Override
+       public int getRowCount() {
+               return cytable.getRowCount();
+       }
+
+       @Override
+       public Object getValueAt(int rowIndex, int columnIndex) {
+               return 
cytable.getAllRows().get(rowIndex).get(getColumnName(columnIndex), 
getColumnClass(columnIndex));
+       }
+       
+       @Override
+       public String getColumnName(int columnIndex) {
+               return columnNames[columnIndex];
+    }
+       
+       @Override
+       public Class<?> getColumnClass(int columnIndex) {
+               return cytable.getColumn(getColumnName(columnIndex)).getType();
+    }
+       
+       @Override
+       public boolean isCellEditable(int rowIndex, int columnIndex) {
+               return false;
+       }
+       
+       /**
+        * Sets the count of columns from the <code>CyTable</code>, excluding 
the ones that 
+        * contain data in the form of a <code>List</code>.
+        *
+        */
+       public int setColumnCount() {
+               Collection<CyColumn> cycolumns = (Collection<CyColumn>) 
cytable.getColumns(); 
+               int count=0;
+               for(CyColumn cycolumn : cycolumns){
+                       if((cycolumn.getType().equals(Integer.class) || 
+                               cycolumn.getType().equals(Double.class)  || 
+                               cycolumn.getType().equals(Long.class))   &&
+                               !cycolumn.getName().equals("SUID")) {
+                                count++;
+                        }
+               }       
+               return count;
+       }
+       
+       /**
+        * Sets the names of columns from the <code>CyTable</code>. Only those 
columns that don't
+        * contain <code>List</code> data are added to the array.
+        *
+        */
+       public String[] setColumnNames() {
+               String[] columnNameArray = new String [this.columnLength];
+               Collection<CyColumn> cycolumns = (Collection<CyColumn>) 
cytable.getColumns(); 
+               int count=0;
+               for(CyColumn cycolumn : cycolumns){
+                       if((cycolumn.getType().equals(Integer.class) || 
+                               cycolumn.getType().equals(Double.class)  || 
+                               cycolumn.getType().equals(Long.class))   &&
+                               !cycolumn.getName().equals("SUID")) {
+                               columnNameArray[count++] = cycolumn.getName();
+                       }
+               }
+               return columnNameArray; 
+       }
+       
+}
\ No newline at end of file

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/PanelComponents.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
                           (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
   2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,193 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JTable;
+import javax.swing.table.TableColumn;
+import javax.swing.table.TableColumnModel;
+
+import org.cytoscape.model.CyTable;
+
+public class PanelComponents {
+
+    private JTable table;
+       private TableColumnModel tableColumnModel;
+       private JCheckBox[] checkBoxArray;
+       private int columnCount;
+       private CyTable myCyTable;
+       private List<Boolean> checkBoxState;
+       private List<String> columnNamesList;
+       private JComboBox chartTypeComboBox;
+       private PanelLayout panelLayout;
+       
+       public enum chartTypes {
+               BAR {
+                   public String toString() {
+                       return "Bar Chart";
+                   }
+               },
+                
+               LINE {
+                   public String toString() {
+                       return "Line Chart";
+                   }
+               }
+       }
+       
+       public PanelComponents(PanelLayout panelLayout) {
+           this.panelLayout = panelLayout;
+    }
+       
+       /**
+        * Initializes an array of checkboxes with column names of the table as 
titles and
+     * sets each checkbox checked/unchecked corresponding to the Boolean 
values in which track hidden columns.
+     * The checkboxes allows user to check/uncheck a particular column.
+        * @param myCyTable The custom CyTable that stores information about 
hidden columns, type of chart and column names.
+        * @param cytable The CyTable supplied by the user.
+        */
+    @SuppressWarnings("unchecked")
+       public void initComponents(CyTable myCyTable, CyTable cytable){
+               
+       this.myCyTable = myCyTable;
+       this.table = new JTable(new MyTableModel(cytable));
+       this.tableColumnModel = table.getColumnModel();
+       this.columnCount = table.getColumnCount();
+       
+       this.columnNamesList = new ArrayList<String>();
+               this.checkBoxState = new ArrayList<Boolean>();
+       checkBoxState = myCyTable.getAllRows().get(0).getList("States", 
Boolean.class);
+       columnNamesList = myCyTable.getAllRows().get(0).getList("Names", 
String.class);
+       
+       checkBoxArray = new JCheckBox[columnCount];
+       
+        for(int i=0;i<columnCount;i++){
+               checkBoxArray[i] = new JCheckBox();
+               checkBoxArray[i].setText(table.getColumnName(i));
+               checkBoxArray[i].setSelected(checkBoxState.get(i));
+               
+               final int j=i;
+               
+               /* 
+                * A listener is add to each checkbox so that when the 
corresponding
+                * checkbox is clicked, the hideColumn and showColumn methods 
can be
+                * invoked.
+                */
+               checkBoxArray[i].addItemListener(new ItemListener() {
+                               
+                       @Override
+                               public void itemStateChanged(ItemEvent arg0) {
+                                       if(!checkBoxArray[j].isSelected()){
+                                               
hideColumn(checkBoxArray[j].getText());
+                                       }else{
+                                               
showColumn(checkBoxArray[j].getText());
+                                       }
+                               }
+               });
+        }
+    
+        //hide all the columns that the user intends to hide in the JTable
+        for(int i=0;i<columnCount;i++){
+               if(!checkBoxState.get(i)) {
+                       TableColumn column = 
tableColumnModel.getColumn(tableColumnModel.getColumnIndex(checkBoxArray[i].getText()));
+                       tableColumnModel.removeColumn(column);
+               }
+        }
+        
+        //initialize the JComboBox which selects the type of chart to be 
displayed
+        //every time it is changed, the graph changes as well
+        if(chartTypeComboBox==null) {
+               chartTypeComboBox = new JComboBox(chartTypes.values());
+               chartTypeComboBox.setSelectedItem("Bar Chart"); //by default
+               
+               chartTypeComboBox.addActionListener(new ActionListener () {
+                   public void actionPerformed(ActionEvent e) {
+                       String chartType = ((JComboBox) 
e.getSource()).getSelectedItem().toString();
+                       panelLayout.setChartPanel(chartType);
+                       updateChartType(chartType);
+                   }
+               });
+               
+        } else {
+               
chartTypeComboBox.getModel().setSelectedItem(myCyTable.getAllRows().get(0).get("ChartType",
 String.class));
+        }
+    }
+    
+    /**
+     * Hides the column from the table view by removing it from the table 
column model.
+     * @param columnName Name of the column that has to be hidden.
+     */
+    public void hideColumn(String columnName) {
+        
+       int columnIndex = tableColumnModel.getColumnIndex(columnName);
+        TableColumn column = tableColumnModel.getColumn(columnIndex);
+        
+        columnIndex = columnNamesList.indexOf(columnName);
+        checkBoxState.set(columnIndex, false);
+        myCyTable.getAllRows().get(0).set("States", checkBoxState);
+        
+        tableColumnModel.removeColumn(column);
+        
+    }
+
+    /**
+     * Makes a column visible in the JTable.
+     * @param columnName Name of the column that has to be made visible.
+     */
+       public void showColumn(String columnName) {
+               
+               int columnIndex = columnNamesList.indexOf(columnName);
+               ((MyTableModel) table.getModel()).fireTableStructureChanged();
+               
+               checkBoxState.set(columnIndex, true);
+               
+               /* after calling fireTableStructureChanged(), the entire JTable 
is refreshed. This is done because
+                * table.getAutoCreateColumnsFromModel() is true. So now, all 
columns corresponding to unchecked 
+                * checkboxes need to be hidden.
+                */
+               for(int i=0;i<columnCount;i++) {
+               if(!checkBoxState.get(i)) {
+                       hideColumn(columnNamesList.get(i));
+               }
+        }
+    }
+       
+       /**
+        * Update the chart type in the custom CyTable attached to the network.
+        * @param chartType One of the types of charts listed in {@link 
chartTypes}.
+        */
+       public void updateChartType(String chartType) {
+               myCyTable.getAllRows().get(0).set("ChartType", chartType);
+       }
+       
+       /**
+        * @return The modified checkbox array after the user has 
selected/deselected
+        *                 some checkboxes.
+        */
+       public JCheckBox[] getCheckBoxArray(){
+               return this.checkBoxArray;
+       }
+       
+       /**
+        * @return The modified checkbox array after the user has 
selected/deselected
+        *                 some checkboxes.
+        */
+       public JComboBox getComboBox(){
+               return this.chartTypeComboBox;
+       }
+       
+       /**
+        * @return The modified JTable after some rows have been made invisible.
+        */
+       public JTable getTable(){
+               return this.table;
+       }
+       
+}

Copied: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
 (from rev 29919, 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/api/PanelLayout.java)
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelLayout.java
       2012-07-18 17:56:34 UTC (rev 29920)
@@ -0,0 +1,140 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.awt.Dimension;
+import java.awt.GridLayout;
+
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.SequentialGroup;
+import javax.swing.JComboBox;
+import javax.swing.JCheckBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.LayoutStyle;
+
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+
+public class PanelLayout {
+
+       private JPanel jpanel;
+       private JScrollPane jScrollPane1;
+    private JCheckBox[] checkBoxArray;
+    private GroupLayout layout;
+    private int tableColumnCount;
+    private ChartPanel myChart;
+    private CytoChart cytoChart;
+    private JComboBox jComboBox1;
+    private JFreeChart chart;
+       
+    public PanelLayout () {
+               this.jpanel = new JPanel();
+    }
+    
+    
+       /**
+        * Initializes the JTable and the JCheckBox[] array to be added to 
jpanel.
+        * @param jtable The JTable to be displayed in jpanel.
+        * @param tableColumnCount The initial column count of the JTable .
+        * @param checkBoxArray The JCheckBox[] array to be displayed in 
jpanel. 
+        * @param jComboBox1 Used to select the type of chart.  
+        */
+       public JPanel initLayout(JTable table, int tableColumnCount, 
JCheckBox[] checkBoxArray, JComboBox jComboBox1){
+               
+               if(jpanel.getComponents().length>0)
+                       jpanel.removeAll();
+               
+               jpanel.setBounds(0, 0, 2000, 2000);
+               jpanel.setPreferredSize(new Dimension(2000, 2000));
+               
+               this.checkBoxArray = checkBoxArray;
+               this.tableColumnCount =tableColumnCount;
+               
+               table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+               
+               cytoChart = new CytoChart(table);
+               chart = 
cytoChart.createChart(jComboBox1.getSelectedItem().toString());
+               myChart = new ChartPanel(chart);
+               myChart.setMouseWheelEnabled(true);
+               
+               jScrollPane1 = new JScrollPane();
+               jScrollPane1.setViewportView(table);
+               
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+               jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane 
.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+               
+               this.jComboBox1 = jComboBox1; 
+               
+               layout = new GroupLayout(jpanel);
+               jpanel.setLayout(layout);
+                       
+               initPanel();
+                       
+        return jpanel;
+        
+       }
+       
+       /**
+        * Adds the JTable and the JCheckBox[] array to the layout of jpanel.
+        */
+       public void initPanel(){
+               
+               GroupLayout.ParallelGroup checkBoxGroupHor = 
layout.createParallelGroup(GroupLayout.Alignment.LEADING);
+               for(int i=0;i<tableColumnCount;i++) {
+               checkBoxGroupHor.addComponent(checkBoxArray[i]);
+        }
+               
+        SequentialGroup checkBoxGroupVert = layout.createSequentialGroup();
+        checkBoxGroupVert.addContainerGap();
+        for(int i=0;i<tableColumnCount;i++){
+               checkBoxGroupVert.addComponent(checkBoxArray[i]);
+               if(i!=(tableColumnCount-1)) {
+                       
checkBoxGroupVert.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
+               }
+        }
+       
+        layout.setHorizontalGroup(
+                
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(layout.createSequentialGroup()
+                               .addComponent(myChart, 
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, 
GroupLayout.PREFERRED_SIZE)
+                    
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                    .addGroup(checkBoxGroupHor
+                        .addComponent(jComboBox1, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                    .addGap(443, 443, 443))
+        );
+        
+        layout.setVerticalGroup(
+                
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(layout.createSequentialGroup()
+                    
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                       .addComponent(myChart, GroupLayout.PREFERRED_SIZE, 
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                        .addGroup(checkBoxGroupVert
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(jComboBox1, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)))
+                    .addContainerGap(183, Short.MAX_VALUE))
+        );
+    }
+       
+       /**
+        * When there are no plottable columns, this method is invoked.
+        * @return <code>JPanel</code> containing a warning.
+        */
+       public JPanel nullJPanel() {
+               
+               if(jpanel.getComponents().length>0)
+                       jpanel.removeAll();
+               
+               JLabel label = new JLabel("No plottable columns. Please 
select/import another network");
+       jpanel.setLayout(new GridLayout());
+               jpanel.add(label);
+               return jpanel;
+       }
+       
+       /**
+        * Sets the new chart within the {@link ChartPanel}.
+        */
+       public void setChartPanel(String chartType) {
+               chart = cytoChart.createChart(chartType);
+               myChart.setChart(chart);
+       }
+}

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