Author: neildhruva
Date: 2012-06-07 10:41:30 -0700 (Thu, 07 Jun 2012)
New Revision: 29497

Added:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
Removed:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CreateTable.java
Modified:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
Log:
Created MYTableModel by extending the AbstractTableModel class. No longer using 
DefaultTableModel.

Deleted: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CreateTable.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CreateTable.java
      2012-06-07 15:00:51 UTC (rev 29496)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CreateTable.java
      2012-06-07 17:41:30 UTC (rev 29497)
@@ -1,59 +0,0 @@
-package org.cytoscape.sample.internal;
-
-import java.util.Collection;
-import java.util.Map;
-import java.util.Vector;
-import javax.swing.JTable;
-import javax.swing.table.DefaultTableModel;
-import org.cytoscape.model.CyTable;
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyColumn;
-
-public class CreateTable {
-
-       private CyTable cytable;
-       
-       public CreateTable(CyTable cytable){                    
-               
-               this.cytable = cytable;
-       }
-       
-       /**
-        * Used to acquire the names of columns in the <code>CyTable</code> 
instance
-        *
-        * @return Vector<String> Vector of column names
-        */
-       public Vector<String> getColumnVector(){
-               Collection<CyColumn> cycolumns = (Collection<CyColumn>) 
cytable.getColumns(); 
-               Vector<String> v = new Vector<String>();
-               for(CyColumn cycolumn : cycolumns){
-                        v.add(cycolumn.getName());
-               }       
-               return v;
-       }
-       
-       /**
-        * Values corresponding to each cell in the table are acquired and set 
in the
-        * new JTable
-        *
-        * @param v A vector of column names
-        * @param rowCount Number of rows in the <code>CyTable</code> instance
-        */
-       
-       public JTable setTableValues(Vector<String> v, int rowCount){
-               DefaultTableModel tablemodel = new DefaultTableModel(v, 
rowCount);
-               JTable jtable = new JTable(tablemodel);
-               Collection<CyRow> cyrows = cytable.getAllRows();
-               int rowIndex=0;
-               int columnIndex=0;
-               for(CyRow cyrow : cyrows){
-                       Map<String, Object> cyrowmap = cyrow.getAllValues();
-                       for(String cyColumnName : v){
-                               
jtable.getModel().setValueAt(cyrowmap.get(cyColumnName), rowIndex, 
columnIndex++);
-                       }
-                       rowIndex++;
-                       columnIndex=0;
-               }
-               return jtable;
-       }       
-}

Added: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
                             (rev 0)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
     2012-06-07 17:41:30 UTC (rev 29497)
@@ -0,0 +1,96 @@
+package org.cytoscape.sample.internal;
+
+import java.util.Collection;
+import java.util.Map;
+
+import javax.swing.table.AbstractTableModel;
+
+import org.cytoscape.model.CyColumn;
+import org.cytoscape.model.CyRow;
+import org.cytoscape.model.CyTable;
+
+public class MyTableModel extends AbstractTableModel {
+
+       private static final long serialVersionUID = 4744686051219349710L;
+       
+       private CyTable cytable;
+       private String[] columnNames;
+       private Object[][] data;
+       private int columnLength;
+       
+       public MyTableModel(CyTable cytable){
+               this.cytable = cytable;
+               this.columnLength =cytable.getColumns().size();
+               this.columnNames = new String[this.columnLength];
+               this.data = new Object[cytable.getRowCount()][columnLength];
+               setColumnNames();
+               setDataValues();
+       }
+       
+       /**
+        * Sets the names of columns from the <code>CyTable</code>
+        *
+        */
+       public void setColumnNames() {
+               Collection<CyColumn> cycolumns = (Collection<CyColumn>) 
cytable.getColumns(); 
+               int count=0;
+               for(CyColumn cycolumn : cycolumns){
+                        columnNames[count] = cycolumn.getName();
+                        count++;
+               }       
+       }
+       
+       /**
+        * Stores all the data values from the <code>CyTable</code> in a 2D 
array
+        *
+        */
+       public void setDataValues() {
+               Collection<CyRow> cyrows = cytable.getAllRows();
+               int rowIndex=0;
+               Map<String, Object> cyrowmap;
+               for(CyRow cyrow : cyrows){
+                       cyrowmap = cyrow.getAllValues();
+                       for(int columnIndex=0; columnIndex < columnLength; 
columnIndex++){
+                               data[rowIndex][columnIndex] = 
cyrowmap.get(columnNames[columnIndex]); 
+                       }
+                       rowIndex++;                     
+               }
+       }
+       
+       @Override
+       public int getColumnCount() {
+               return this.columnLength;
+       }
+
+       @Override
+       public int getRowCount() {
+               return data.length;
+       }
+
+       @Override
+       public Object getValueAt(int rowIndex, int columnIndex) {
+               //the .toString() is temporary in order to display the JTable 
properly
+               return data[rowIndex][columnIndex].toString();
+       }
+       
+       @Override
+       public String getColumnName(int columnIndex) {
+               return columnNames[columnIndex];
+    }
+       
+       @Override
+       public Class getColumnClass(int columnIndex) {
+               return getValueAt(0, columnIndex).getClass();
+    }
+       
+       @Override
+       public boolean isCellEditable(int rowIndex, int columnIndex) {
+               return false;
+       }
+       /*
+       @Override
+       public void fireTableDataChanged(){
+               
+       }
+*/
+}

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
  2012-06-07 15:00:51 UTC (rev 29496)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
  2012-06-07 17:41:30 UTC (rev 29497)
@@ -13,7 +13,6 @@
        private MyCytoPanel myCytoPanel;
        private JTable table;
        private CyTable cytable;
-       private CreateTable createTable;
        private static HashMap<String, Serializable> panelComponentMap;
        private JCheckBox[] checkBoxArray;
        private PanelComponents panelComponents;
@@ -32,14 +31,14 @@
                cytable = e.getNetwork().getDefaultNodeTable();
                if(cytable!=null)
                {
-                       if(panelComponentMap.containsKey(cytable.getTitle())){  
+                       if(panelComponentMap.containsKey(cytable.getTitle())) { 
+                               
                                panelComponents = (PanelComponents) 
panelComponentMap.get(cytable.getTitle());
                                table = panelComponents.getTable();
                                checkBoxArray = 
panelComponents.getCheckBoxArray();
-                       }else{
+                       } else {
                                
-                               createTable = new CreateTable(cytable);
-                               table = 
createTable.setTableValues(createTable.getColumnVector(), 
cytable.getRowCount());
+                               table = new JTable(new MyTableModel(cytable));
                                panelComponents = new PanelComponents(table);
                                checkBoxArray = 
panelComponents.initialiseCheckBoxArray();
                                panelComponentMap.put(cytable.getTitle(), 
panelComponents);

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