Author: neildhruva
Date: 2012-07-18 11:00:53 -0700 (Wed, 18 Jul 2012)
New Revision: 29922

Added:
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/ChartAppFactory.java
   
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
   
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
Log:
directory changes

Added: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/ChartAppFactory.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/ChartAppFactory.java
                                (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/ChartAppFactory.java
        2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,18 @@
+package org.cytoscape.neildhruva.chartapp;
+
+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);
+
+}

Added: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
                            (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
    2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,47 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import org.cytoscape.application.events.SetCurrentNetworkListener;
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.model.CyNetworkTableManager;
+import org.cytoscape.model.CyTableFactory;
+import org.cytoscape.model.CyTableManager;
+import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
+import org.cytoscape.neildhruva.chartapp.impl.ChartAppFactoryImpl;
+import org.cytoscape.neildhruva.chartapp.impl.EventTableAdded;
+import org.cytoscape.neildhruva.chartapp.impl.EventTableDestroyed;
+import org.cytoscape.neildhruva.chartapp.impl.MyCytoPanel;
+import org.cytoscape.service.util.AbstractCyActivator;
+
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+
+public class CyActivator extends AbstractCyActivator {
+
+       public CyActivator() {
+               super();
+       }
+
+       public void start(BundleContext bc) {
+               
+               CyTableFactory cyDataTableFactoryServiceRef = 
getService(bc,CyTableFactory.class);
+               CyNetworkTableManager cyNetworkTableManagerServiceRef = 
getService(bc, CyNetworkTableManager.class);
+               CyTableManager cyTableManagerServiceRef = 
getService(bc,CyTableManager.class);
+               
+               MyCytoPanel myCytoPanel = new MyCytoPanel();
+               ChartAppFactoryImpl chartAppFactoryImpl = new 
ChartAppFactoryImpl(cyDataTableFactoryServiceRef, 
cyNetworkTableManagerServiceRef, cyTableManagerServiceRef); 
+               registerService(bc, chartAppFactoryImpl, ChartAppFactory.class, 
new Properties());
+               
+               ChartAppFactory chartAppFactory = getService(bc, 
ChartAppFactory.class);
+               
+               EventTableAdded eventTableAdded = new 
EventTableAdded(myCytoPanel, chartAppFactory);
+               EventTableDestroyed eventTableDestroyed = new 
EventTableDestroyed(myCytoPanel);
+               
+               registerService(bc,myCytoPanel,CytoPanelComponent.class, new 
Properties());
+               
registerService(bc,eventTableAdded,SetCurrentNetworkListener.class, new 
Properties());
+               
registerService(bc,eventTableDestroyed,NetworkAboutToBeDestroyedListener.class, 
new Properties());
+               
+               
+       }
+}

Added: 
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/ChartAppFactoryImpl.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/ChartAppFactoryImpl.java
       2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,101 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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.ChartAppFactory;
+
+import org.jfree.chart.ChartPanel;
+
+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(false);
+                               }
+                               
+                               //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);
+                       }       
+               
+                       //get all components and send them to the panel layout 
class.
+                       JComboBox chartTypeComboBox = 
panelComponents.getComboBox();
+                       table = panelComponents.getTable();
+                       JCheckBox[] checkBoxArray = 
panelComponents.getCheckBoxArray();
+                       ChartPanel myChartPanel = 
panelComponents.getChartPanel();
+                       jpanel = panelLayout.initLayout(table, 
tableColumnCount, checkBoxArray, chartTypeComboBox, myChartPanel);
+                       
+               } else {
+                       jpanel = panelLayout.nullJPanel();
+               }
+               
+               return jpanel;
+       }
+
+
+}

Added: 
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/CytoChart.java
                         (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/CytoChart.java
 2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,218 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.util.Vector;
+
+import javax.swing.JTable;
+
+import org.cytoscape.model.CyNetwork;
+import org.jfree.chart.ChartFactory;
+import org.jfree.chart.JFreeChart;
+import org.jfree.chart.axis.NumberAxis;
+import org.jfree.chart.plot.CategoryPlot;
+import org.jfree.chart.plot.PlotOrientation;
+import org.jfree.chart.renderer.category.LineAndShapeRenderer;
+import org.jfree.data.category.DefaultCategoryDataset;
+
+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() {
+               
+               
//System.out.println(cyTable.getAllRows().get(0).get(CyNetwork.NAME, 
String.class)+"-------");
+               // 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?
+               );
+               */
+               
+                 // row keys...
+        final String series1 = "First";
+        final String series2 = "Second";
+        final String series3 = "Third";
+
+        // column keys...
+        final String type1 = "Type 1";
+        final String type2 = "Type 2";
+        final String type3 = "Type 3";
+        final String type4 = "Type 4";
+        final String type5 = "Type 5";
+        final String type6 = "Type 6";
+        final String type7 = "Type 7";
+        final String type8 = "Type 8";
+
+        // create the dataset...
+        final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
+
+        dataset.addValue(1.0, series1, type1);
+        dataset.addValue(4.0, series1, type2);
+        dataset.addValue(3.0, series1, type3);
+        dataset.addValue(5.0, series1, type4);
+        dataset.addValue(5.0, series1, type5);
+        dataset.addValue(7.0, series1, type6);
+        dataset.addValue(7.0, series1, type7);
+        dataset.addValue(8.0, series1, type8);
+
+        dataset.addValue(5.0, series2, type1);
+        dataset.addValue(7.0, series2, type2);
+        dataset.addValue(6.0, series2, type3);
+        dataset.addValue(8.0, series2, type4);
+        dataset.addValue(4.0, series2, type5);
+        dataset.addValue(4.0, series2, type6);
+        dataset.addValue(2.0, series2, type7);
+        dataset.addValue(1.0, series2, type8);
+
+        dataset.addValue(4.0, series3, type1);
+        dataset.addValue(3.0, series3, type2);
+        dataset.addValue(2.0, series3, type3);
+        dataset.addValue(3.0, series3, type4);
+        dataset.addValue(6.0, series3, type5);
+        dataset.addValue(3.0, series3, type6);
+        dataset.addValue(4.0, series3, type7);
+        dataset.addValue(3.0, series3, type8);
+        
+        // create the chart...
+        chart = ChartFactory.createLineChart(
+            "Line Chart Demo 1",       // chart title
+            "Type",                    // domain axis label
+            "Value",                   // range axis label
+            dataset,                   // data
+            PlotOrientation.VERTICAL,  // orientation
+            true,                      // include legend
+            true,                      // tooltips
+            false                      // urls
+        );
+
+        // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
+//        final StandardLegend legend = (StandardLegend) chart.getLegend();
+  //      legend.setDisplaySeriesShapes(true);
+    //    legend.setShapeScaleX(1.5);
+      //  legend.setShapeScaleY(1.5);
+        //legend.setDisplaySeriesLines(true);
+
+        chart.setBackgroundPaint(Color.white);
+
+        final CategoryPlot plot = (CategoryPlot) chart.getPlot();
+        plot.setBackgroundPaint(Color.lightGray);
+        plot.setRangeGridlinePaint(Color.white);
+
+        // customise the range axis...
+        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
+        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
+        rangeAxis.setAutoRangeIncludesZero(true);
+
+        // 
****************************************************************************
+        // * JFREECHART DEVELOPER GUIDE                                        
       *
+        // * The JFreeChart Developer Guide, written by David Gilbert, is 
available   *
+        // * to purchase from Object Refinery Limited:                         
       *
+        // *                                                                   
       *
+        // * http://www.object-refinery.com/jfreechart/guide.html              
       *
+        // *                                                                   
       *
+        // * Sales are used to provide funding for the JFreeChart project - 
please    * 
+        // * support us so that we can continue developing free software.      
       *
+        // 
****************************************************************************
+        
+        // customise the renderer...
+        final LineAndShapeRenderer renderer = (LineAndShapeRenderer) 
plot.getRenderer();
+//        renderer.setDrawShapes(true);
+
+        renderer.setSeriesStroke(
+            0, new BasicStroke(
+                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
+                1.0f, new float[] {10.0f, 6.0f}, 0.0f
+            )
+        );
+        renderer.setSeriesStroke(
+            1, new BasicStroke(
+                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
+                1.0f, new float[] {6.0f, 6.0f}, 0.0f
+            )
+        );
+        renderer.setSeriesStroke(
+            2, new BasicStroke(
+                2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
+                1.0f, new float[] {2.0f, 6.0f}, 0.0f
+            )
+        );
+        // OPTIONAL CUSTOMISATION COMPLETED.
+        
+        
+               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;
+       }
+}

Added: 
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/EventTableAdded.java
                           (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableAdded.java
   2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,37 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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.ChartAppFactory;
+
+
+public class EventTableAdded implements SetCurrentNetworkListener{
+
+       private MyCytoPanel myCytoPanel; 
+       private ChartAppFactory chartAppFactory;
+       
+       public 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);
+       }
+}

Added: 
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/EventTableDestroyed.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/EventTableDestroyed.java
       2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,29 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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;
+       
+       public 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);
+               
+       }
+}

Added: 
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/MyCytoPanel.java
                               (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyCytoPanel.java
       2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,58 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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;
+       }
+       
+}

Added: 
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/MyTableModel.java
                              (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/MyTableModel.java
      2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,94 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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

Added: 
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/PanelComponents.java
                           (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/PanelComponents.java
   2012-07-18 18:00:53 UTC (rev 29922)
@@ -0,0 +1,208 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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;
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+
+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;
+       private CytoChart cytoChart;
+       private JFreeChart chart;
+       private ChartPanel myChartPanel;
+       
+       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.
+        */
+    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.refreshChartPanel(chartType);
+                       updateChartType(chartType);
+                   }
+               });
+               
+        } else {
+               
chartTypeComboBox.getModel().setSelectedItem(myCyTable.getAllRows().get(0).get("ChartType",
 String.class));
+        }
+        
+        //initialize the chart
+        this.cytoChart = new CytoChart(table);
+               this.chart = 
cytoChart.createChart(chartTypeComboBox.getSelectedItem().toString());
+               this.myChartPanel = new ChartPanel(chart);
+               myChartPanel.setMouseWheelEnabled(true);
+    }
+    
+    /**
+     * 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;
+       }
+       
+       /**
+        * @return The chart panel.
+        */
+       public ChartPanel getChartPanel(){
+               return this.myChartPanel;
+       }
+       
+}

Added: 
csplugins/trunk/soc/neildhruva/ChartApp/src/main/java/org/cytoscape/neildhruva/chartapp/impl/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 18:00:53 UTC (rev 29922)
@@ -0,0 +1,137 @@
+package org.cytoscape.neildhruva.chartapp.impl;
+
+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 myChartPanel;
+    private CytoChart cytoChart;
+    private JComboBox chartTypeComboBox;
+    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 chartTypeComboBox Used to select the type of chart.  
+        */
+       public JPanel initLayout(JTable table, int tableColumnCount, 
JCheckBox[] checkBoxArray, JComboBox chartTypeComboBox,
+                                                         ChartPanel 
myChartPanel){
+               
+               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;
+               this.myChartPanel = myChartPanel;
+               
+               table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+               
+               jScrollPane1 = new JScrollPane();
+               jScrollPane1.setViewportView(table);
+               
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+               jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane 
.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+               
+               this.chartTypeComboBox = chartTypeComboBox; 
+               
+               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(myChartPanel, 
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, 
GroupLayout.PREFERRED_SIZE)
+                    
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+                    .addGroup(checkBoxGroupHor
+                        .addComponent(chartTypeComboBox, 
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(myChartPanel, GroupLayout.PREFERRED_SIZE, 
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                        .addGroup(checkBoxGroupVert
+                        
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+                        .addComponent(chartTypeComboBox, 
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 refreshChartPanel(String chartType) {
+               chart = cytoChart.createChart(chartType);
+               myChartPanel.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