Author: neildhruva
Date: 2012-07-14 03:39:32 -0700 (Sat, 14 Jul 2012)
New Revision: 29901

Added:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CytoChart.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableAdded.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableDestroyed.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyCytoPanel.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyTableModel.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/PanelComponents.java
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/impl/
Removed:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/chartapp/
Log:
changed directory structure

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
                          (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CyActivator.java
  2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,36 @@
+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.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();
+               EventTableAdded tableAddedEvent = new 
EventTableAdded(myCytoPanel, cyDataTableFactoryServiceRef, 
cyNetworkTableManagerServiceRef, cyTableManagerServiceRef);
+               EventTableDestroyed tableDestroyedEvent = new 
EventTableDestroyed(myCytoPanel);
+               
+               registerService(bc,myCytoPanel,CytoPanelComponent.class, new 
Properties());
+               
registerService(bc,tableAddedEvent,SetCurrentNetworkListener.class, new 
Properties());
+               
registerService(bc,tableDestroyedEvent,NetworkAboutToBeDestroyedListener.class, 
new Properties());
+               
+               
+       }
+}

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CytoChart.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CytoChart.java
                            (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/CytoChart.java
    2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,109 @@
+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) {
+               
+               //print all the columns that can be plotted on a graph
+               MyTableModel myTableModel = (MyTableModel) table.getModel();
+               this.plottableColumns = myTableModel.getPlottableColumns();
+               for(int i=0;i<plottableColumns.size();i++){
+                       System.out.println(plottableColumns.get(i));
+                       
+               }
+       }
+       
+       /**
+        * 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;
+       }
+}

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableAdded.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableAdded.java
                              (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableAdded.java
      2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,104 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Iterator;
+
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JTable;
+
+import org.cytoscape.application.events.SetCurrentNetworkEvent;
+import org.cytoscape.application.events.SetCurrentNetworkListener;
+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;
+
+public class EventTableAdded implements SetCurrentNetworkListener{
+
+       private MyCytoPanel myCytoPanel; 
+       private JTable table;
+       private JCheckBox[] checkBoxArray;
+       private PanelComponents panelComponents=null;
+       private int columnCount;
+       private List<Boolean> checkBoxState;
+       private List<String> columnNamesList;
+       private CyTableFactory tableFactory;
+       private CyTableManager cyTableManager;
+       private CyNetworkTableManager cyNetworkTableMgr;
+       private JComboBox chartTypeComboBox;
+       
+       EventTableAdded(MyCytoPanel myCytoPanel, 
+                                       CyTableFactory tableFactory,
+                                       CyNetworkTableManager cyNetworkTableMgr,
+                                       CyTableManager cyTableManager) {
+               
+               this.myCytoPanel = myCytoPanel;
+               this.tableFactory = tableFactory;
+               this.cyNetworkTableMgr = cyNetworkTableMgr;
+               this.cyTableManager = cyTableManager;
+               this.panelComponents = new PanelComponents(myCytoPanel);
+       }
+
+       
+       @Override
+       public void handleEvent(SetCurrentNetworkEvent e) {
+               
+               if(e.getNetwork() == null) 
+                       return;
+               
+               //cytable is the CyTable corresponding to the current node table
+               final CyTable cytable = e.getNetwork().getDefaultNodeTable();
+               if(cytable==null)
+                       return;
+               
+               final Long networkSUID = e.getNetwork().getSUID();
+               table = new JTable(new MyTableModel(cytable));
+               columnCount = table.getColumnCount();
+               
+               //myCyTable is the custom CyTable created for this app and 
associated with each network.
+               CyTable myCyTable=null;
+               
+               myCyTable = cyNetworkTableMgr.getTable(e.getNetwork(), 
CyNetwork.class, "PrintTable");
+               
+               if(myCyTable!=null) {
+                       panelComponents.initCheckBoxArray(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)
+                       checkBoxState = new ArrayList<Boolean>();
+                       columnNamesList = new ArrayList<String>();
+                       for(int i=0; i<columnCount; 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(e.getNetwork(), 
CyNetwork.class, "PrintTable", myCyTable);
+                       //add myCyTable to the CyTableManager in order to 
preserve it across sessions
+                       cyTableManager.addTable(myCyTable);
+                       
+                       panelComponents.initCheckBoxArray(myCyTable, cytable);
+               }       
+               
+               chartTypeComboBox = panelComponents.getComboBox();
+               table = panelComponents.getTable();
+               checkBoxArray = panelComponents.getCheckBoxArray();
+               myCytoPanel.initComponents(table, checkBoxArray, columnCount, 
chartTypeComboBox);               
+       }
+}

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableDestroyed.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableDestroyed.java
                          (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/EventTableDestroyed.java
  2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,29 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.awt.GridLayout;
+
+import javax.swing.JLabel;
+
+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) {
+               
+               //Clear the Table View Panel
+               myCytoPanel.removeAll();
+               JLabel label = new JLabel("Please select/import a network");
+               myCytoPanel.setLayout(new GridLayout());
+               myCytoPanel.add(label);
+               myCytoPanel.revalidate();
+       }
+}

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyCytoPanel.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyCytoPanel.java
                          (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyCytoPanel.java
  2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,174 @@
+package org.cytoscape.neildhruva.chartapp;
+
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.GridLayout;
+
+import javax.swing.GroupLayout;
+import javax.swing.GroupLayout.SequentialGroup;
+import javax.swing.Icon;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+import javax.swing.LayoutStyle;
+
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.application.swing.CytoPanelName;
+import org.jfree.chart.ChartPanel;
+import org.jfree.chart.JFreeChart;
+
+public class MyCytoPanel extends JPanel implements CytoPanelComponent {
+       
+       private static final long serialVersionUID = 8292806967891823933L;
+
+    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 MyCytoPanel() {
+       JLabel label = new JLabel("Please select/import a network");
+               this.setLayout(new GridLayout());
+               this.add(label);
+               this.setVisible(true);
+               
+       }
+
+       /**
+        * Initializes the <code>JTable</code> and the <code>JCheckBox</code>[] 
array to be added to this <code>JPanel</code> 
+        * 
+        * @param jtable The <code>JTable</code> to be displayed in this 
<code>JPanel</code>
+        * @param checkBoxArray The <code>JCheckBox</code>[] array to be 
displayed in this <code>JPanel</code>
+        * @param tableColumnCount The initial column count of the 
<code>JTable</code>
+        */
+       public void initComponents(JTable table, JCheckBox[] checkBoxArray, int 
tableColumnCount, JComboBox jComboBox1){
+               
+               if(this.getComponents().length>0)
+                       this.removeAll();
+               
+               this.setBounds(0, 0, 2000, 2000);
+               this.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(this);
+        this.setLayout(layout);
+        
+        initPanel();
+        this.revalidate();
+        
+       }
+       
+       /**
+        * Adds the <code>JTable</code> and the <code>JCheckBox</code>[] array 
to the layout of
+        * this <code>JPanel</code>.
+        * 
+        */
+       public void initPanel(){
+               
+               GroupLayout.ParallelGroup checkBoxGroupHor = 
layout.createParallelGroup(GroupLayout.Alignment.LEADING);
+               for(int i=0;i<tableColumnCount;i++) {
+               checkBoxGroupHor.addComponent(checkBoxArray[i]);
+        }
+               checkBoxGroupHor.addComponent(jComboBox1);
+               
+               layout.setHorizontalGroup(
+                
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                .addGroup(layout.createSequentialGroup()
+                    .addComponent(jScrollPane1, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE)
+                    .addGap(6, 6, 6)
+                    
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+                        .addGroup(layout.createSequentialGroup()
+                            .addGroup(checkBoxGroupHor)
+                            .addGap(81, 81, 81)
+                            .addComponent(myChart, GroupLayout.PREFERRED_SIZE, 
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
+                        .addComponent(jComboBox1, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                    .addGap(98, 98, 98))
+        );
+        
+        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.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
+                            .addGap(18, 18, 18)
+                            .addComponent(jComboBox1, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                        .addComponent(jScrollPane1, 
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 
javax.swing.GroupLayout.PREFERRED_SIZE))
+                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, 
Short.MAX_VALUE))
+        );
+        
+     }
+       
+       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;
+       }
+       
+       /**
+        * @return Instance of {@link CytoChart} used to get access to the 
current chart or create a new chart.
+        */
+       public CytoChart getCytoChart() {
+               return this.cytoChart;
+       }
+       
+       /**
+        * Sets the new chart within the {@link ChartPanel}.
+        * 
+        */
+       public void setChartPanel(String chartType) {
+               chart = cytoChart.createChart(chartType);
+               myChart.setChart(chart);
+       }
+}

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyTableModel.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyTableModel.java
                         (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/MyTableModel.java
 2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,103 @@
+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().isInterface()) {
+                                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().isInterface()){
+                               columnNameArray[count] = cycolumn.getName();
+                               count++;
+                       }
+               }
+               return columnNameArray; 
+       }
+       
+       /**
+        * Returns a vector of names of columns from the <code>CyTable</code> 
that are of the type Integer, Long or Double.
+        * 
+        * @return Vector containing names of columns that are of the type 
Integer, Long or Double.
+        */
+       public Vector<String> getPlottableColumns() {
+               Vector<String> v = new Vector<String>();
+               for(int columnIndex=0; columnIndex < columnLength; 
columnIndex++){
+                       if(getColumnClass(columnIndex).equals(Integer.class) || 
getColumnClass(columnIndex).equals(Double.class) || 
getColumnClass(columnIndex).equals(Long.class)) {
+                               v.add(columnNames[columnIndex]);
+                       }
+               }
+               return v;       
+       }
+}
\ No newline at end of file

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/PanelComponents.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/PanelComponents.java
                              (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/neildhruva/chartapp/PanelComponents.java
      2012-07-14 10:39:32 UTC (rev 29901)
@@ -0,0 +1,214 @@
+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 MyCytoPanel myCytoPanel;
+       private String chartType;
+       
+       public enum chartTypes {
+               BAR {
+                   public String toString() {
+                       return "Bar Chart";
+                   }
+               },
+                
+               Line {
+                   public String toString() {
+                       return "Line Chart";
+                   }
+               }
+       }
+       
+       public PanelComponents(MyCytoPanel myCytoPanel) {
+           this.myCytoPanel = myCytoPanel;
+    }
+       
+       /**
+     * 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.  
+     * 
+     */
+    @SuppressWarnings("unchecked")
+       public void initCheckBoxArray(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();
+                       myCytoPanel.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));
+               }
+        }
+    }
+       
+       /**
+        * 
+        * @param chartType
+        */
+       public void updateChartType(String chartType) {
+               myCyTable.getAllRows().get(0).set("ChartType", chartType);
+               this.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 initial column count of the table.
+        */
+       public int getTableColumnCount(){
+               return this.columnCount;
+       }
+       
+       /**
+        * 
+        * @return The modified JTable after some rows have been made invisible.
+        */
+       public JTable getTable(){
+               return this.table;
+       }
+       
+       /**
+        * 
+        * @return The Chart type string.
+        */
+       public String getChartType(){
+               return this.chartType;
+       }
+
+}

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