Author: neildhruva
Date: 2012-06-13 01:26:27 -0700 (Wed, 13 Jun 2012)
New Revision: 29547

Modified:
   
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
   
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/PanelComponents.java
   
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/TableDestroyedEvent.java
Log:
To display as a JTable, data is directly read from CyTable and not stored in 
the form of a 2D array which was initially the case. Changes mainly made to 
MyTableModel.java

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
      2012-06-13 06:28:31 UTC (rev 29546)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
      2012-06-13 08:26:27 UTC (rev 29547)
@@ -51,7 +51,7 @@
         layout = new GroupLayout(this);
         this.setLayout(layout);
         
-        initPanel();                                    
+        initPanel();
         this.revalidate();
        }
        
@@ -63,7 +63,7 @@
        public void initPanel(){
                
                GroupLayout.ParallelGroup checkBoxGroupHor = 
layout.createParallelGroup(GroupLayout.Alignment.LEADING);
-        for(int i=0;i<tableColumnCount;i++){
+               for(int i=0;i<tableColumnCount;i++) {
                checkBoxGroupHor.addComponent(checkBoxArray[i]);
         }
         
@@ -80,7 +80,9 @@
         checkBoxGroupVert.addContainerGap();
         for(int i=0;i<tableColumnCount;i++){
                checkBoxGroupVert.addComponent(checkBoxArray[i]);
-               
checkBoxGroupVert.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
+               if(!(i==(tableColumnCount-1))) {
+                       
checkBoxGroupVert.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED);
+               }
         }
         checkBoxGroupVert.addContainerGap(192, Short.MAX_VALUE);
         

Modified: 
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
     2012-06-13 06:28:31 UTC (rev 29546)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyTableModel.java
     2012-06-13 08:26:27 UTC (rev 29547)
@@ -1,13 +1,11 @@
 package org.cytoscape.sample.internal;
 
 import java.util.Collection;
-import java.util.Map;
 import java.util.Vector;
 
 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 {
@@ -16,48 +14,15 @@
        
        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;
@@ -65,13 +30,12 @@
 
        @Override
        public int getRowCount() {
-               return data.length;
+               return cytable.getRowCount();
        }
 
        @Override
        public Object getValueAt(int rowIndex, int columnIndex) {
-               //the .toString() is temporary in order to display the JTable 
properly
-               return data[rowIndex][columnIndex].toString();
+               return 
cytable.getAllRows().get(rowIndex).get(getColumnName(columnIndex), 
getColumnClass(columnIndex));
        }
        
        @Override
@@ -80,8 +44,8 @@
     }
        
        @Override
-       public Class getColumnClass(int columnIndex) {
-               return getValueAt(0, columnIndex).getClass();
+       public Class<?> getColumnClass(int columnIndex) {
+               return cytable.getColumn(getColumnName(columnIndex)).getType();
     }
        
        @Override
@@ -90,6 +54,19 @@
        }
        
        /**
+        * 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++;
+               }       
+       }
+       
+       /**
         * 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.

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
  2012-06-13 06:28:31 UTC (rev 29546)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
  2012-06-13 08:26:27 UTC (rev 29547)
@@ -9,11 +9,9 @@
 import javax.swing.table.TableColumn;
 import javax.swing.table.TableColumnModel;
 
-public class PanelComponents extends javax.swing.JFrame {
+public class PanelComponents {
 
-    private static final long serialVersionUID = 7013054990224843833L;
-       
-       private JTable table;
+    private JTable table;
        private TableColumnModel tableColumnModel;
        private HashMap<String, Serializable> hiddenColumnsColumn;
     private HashMap<String, Serializable> hiddenColumnsIndex;

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-13 06:28:31 UTC (rev 29546)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableAddedEvent.java
  2012-06-13 08:26:27 UTC (rev 29547)
@@ -1,9 +1,9 @@
 package org.cytoscape.sample.internal;
 
-import java.io.Serializable;
 import java.util.HashMap;
 import javax.swing.JCheckBox;
 import javax.swing.JTable;
+
 import org.cytoscape.application.events.SetCurrentNetworkEvent;
 import org.cytoscape.application.events.SetCurrentNetworkListener;
 import org.cytoscape.model.CyTable;
@@ -13,7 +13,7 @@
        private MyCytoPanel myCytoPanel;
        private JTable table;
        private CyTable cytable;
-       private static HashMap<String, Serializable> panelComponentMap;
+       private static HashMap<String, Object> panelComponentMap;
        private JCheckBox[] checkBoxArray;
        private PanelComponents panelComponents;
        private int tableColumnCount;
@@ -21,7 +21,7 @@
        TableAddedEvent(MyCytoPanel myCytoPanel){
                
                this.myCytoPanel = myCytoPanel;
-               panelComponentMap = new HashMap<String, Serializable>();
+               panelComponentMap = new HashMap<String, Object>();
        }
 
        
@@ -50,7 +50,7 @@
                
        }
        
-       public static HashMap<String, Serializable> getPanelComponentMap(){
+       public static HashMap<String, Object> getPanelComponentMap(){
                return panelComponentMap;
        }
 }

Modified: 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
===================================================================
--- 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
      2012-06-13 06:28:31 UTC (rev 29546)
+++ 
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/TableDestroyedEvent.java
      2012-06-13 08:26:27 UTC (rev 29547)
@@ -1,17 +1,16 @@
 package org.cytoscape.sample.internal;
 
-import java.io.Serializable;
 import java.util.HashMap;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedEvent;
 import org.cytoscape.model.events.NetworkAboutToBeDestroyedListener;
 
 public class TableDestroyedEvent implements NetworkAboutToBeDestroyedListener{
 
-       private HashMap<String, Serializable> panelComponentMap;
+       private HashMap<String, Object> panelComponentMap;
        
        TableDestroyedEvent(){
                
-               panelComponentMap = new HashMap<String, Serializable>();
+               panelComponentMap = new HashMap<String, Object>();
        }
 
        @Override

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