Author: neildhruva
Date: 2012-05-30 03:55:14 -0700 (Wed, 30 May 2012)
New Revision: 29389
Added:
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/MyDialog.java
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTask.java
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTaskFactory.java
Log:
Changed the default node table display from console to JDialog and JPanel
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
===================================================================
---
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
2012-05-30 07:38:10 UTC (rev 29388)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CyActivator.java
2012-05-30 10:55:14 UTC (rev 29389)
@@ -1,6 +1,8 @@
package org.cytoscape.sample.internal;
import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.application.swing.CytoPanelComponent;
import org.cytoscape.service.util.AbstractCyActivator;
import org.cytoscape.work.TaskFactory;
@@ -18,14 +20,18 @@
public void start(BundleContext bc) {
CyApplicationManager cyApplicationManagerService =
getService(bc,CyApplicationManager.class);
- PrintTableTaskFactory printTableTaskFactory = new
PrintTableTaskFactory(cyApplicationManagerService);
+ CySwingApplication cySwingApplicationService =
getService(bc,CySwingApplication.class);
+ MyCytoPanel myCytoPanel = new MyCytoPanel();
+ PrintTableTaskFactory printTableTaskFactory = new
PrintTableTaskFactory(cyApplicationManagerService, cySwingApplicationService,
myCytoPanel);
+
Properties printTableTaskFactoryProps = new Properties();
printTableTaskFactoryProps.setProperty("preferredMenu","Apps");
printTableTaskFactoryProps.setProperty("menuGravity","11.0");
printTableTaskFactoryProps.setProperty("title","Print Table");
registerService(bc,printTableTaskFactory,TaskFactory.class,
printTableTaskFactoryProps);
+
+ registerService(bc,myCytoPanel,CytoPanelComponent.class, new
Properties());
}
}
-
Added:
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
(rev 0)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
2012-05-30 10:55:14 UTC (rev 29389)
@@ -0,0 +1,44 @@
+package org.cytoscape.sample.internal;
+
+import java.awt.Component;
+
+import javax.swing.Icon;
+import javax.swing.JPanel;
+
+import org.cytoscape.application.swing.CytoPanelComponent;
+import org.cytoscape.application.swing.CytoPanelName;
+
+public class MyCytoPanel extends JPanel implements CytoPanelComponent {
+
+ private static final long serialVersionUID = 8292806967891823933L;
+
+ public MyCytoPanel() {
+
+ this.setVisible(true);
+ }
+
+
+ public Component getComponent() {
+ return this;
+ }
+
+ /**
+ * @return CytoPanelName Location of the CytoPanel
+ */
+ public CytoPanelName getCytoPanelName() {
+ return CytoPanelName.SOUTH;
+ }
+
+ /**
+ * @return String Title of the CytoPanel
+ */
+ public String getTitle() {
+ return "Table View";
+ }
+
+ public Icon getIcon() {
+ return null;
+ }
+}
+
+
Added:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyDialog.java
===================================================================
---
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyDialog.java
(rev 0)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyDialog.java
2012-05-30 10:55:14 UTC (rev 29389)
@@ -0,0 +1,78 @@
+package org.cytoscape.sample.internal;
+
+import java.awt.BorderLayout;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+
+import javax.swing.JDialog;
+import javax.swing.JScrollPane;
+import javax.swing.JTable;
+
+public class MyDialog extends JDialog{
+
+ private static final long serialVersionUID = -265391392725279259L;
+ private JTable table;
+ private static boolean dialogAlreadyExists = false;
+
+ public MyDialog(JTable table){
+
+ if(!dialogAlreadyExists){
+
+ this.table = table;
+
+ createDialog();
+ addTable();
+
+ this.pack();
+ this.setVisible(true);
+
+ dialogAlreadyExists=true;
+ }
+
+ this.addWindowListener(new WindowListener() {
+
+ @Override
+ public void windowClosing(WindowEvent e) {
+ dialogAlreadyExists = false;
+ }
+
+ @Override
+ public void windowClosed(WindowEvent e) {
+ }
+ @Override
+ public void windowActivated(WindowEvent e) {}
+ @Override
+ public void windowDeactivated(WindowEvent e) {}
+ @Override
+ public void windowDeiconified(WindowEvent e) {}
+ @Override
+ public void windowIconified(WindowEvent e) {}
+ @Override
+ public void windowOpened(WindowEvent e) {}
+ });
+
+
+ }
+
+ /**
+ * Creates the JDialog UI
+ */
+ public void createDialog(){
+
+ this.setTitle("Table View");
+ this.setBounds(200, 200, 500, 500);
+ }
+
+ /**
+ * Adds the JTable to the JDialog
+ */
+ public void addTable(){
+
+ this.add(new JScrollPane(table), BorderLayout.NORTH);
+ }
+
+ public void windowClosed(WindowEvent e)
+ {
+ System.out.println("jdialog window closed event received");
+ }
+}
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTask.java
===================================================================
---
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTask.java
2012-05-30 07:38:10 UTC (rev 29388)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTask.java
2012-05-30 10:55:14 UTC (rev 29389)
@@ -2,14 +2,22 @@
import java.util.Collection;
import java.util.Map;
+import java.util.Vector;
+import javax.swing.JButton;
+import javax.swing.JTable;
+import javax.swing.JScrollPane;
+import javax.swing.table.DefaultTableModel;
+
import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.application.swing.CySwingApplication;
import org.cytoscape.model.CyTable;
import org.cytoscape.model.CyRow;
import org.cytoscape.model.CyColumn;
import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.TaskMonitor;
+
/**
* PrintTableTask extracts information from the table model and prints it in
the console.
* It prints all the table records in a row-column fashion.
@@ -17,15 +25,26 @@
public class PrintTableTask extends AbstractTask {
private CyApplicationManager manager;
+ private CySwingApplication desktopApp;
+ private CyTable cytable;
+ private MyCytoPanel myCytoPanel;
+ private JTable table, table2;
+
+ private static boolean tableAlreadyExists = false;
/**
* Class constructor invoked by the <code>PrintTableTaskFactory</code>
class
*
- * @param manager an instance of <code>CyApplicationManager</code>
that is used to manage the current network
+ * @param manager an instance of <code>CyApplicationManager</code> that
is used to manage the current network
*/
- public PrintTableTask(CyApplicationManager manager){
+ public PrintTableTask(CyApplicationManager manager, CySwingApplication
desktopApp, MyCytoPanel myCytoPanel){
+ this.manager=manager;
+ this.desktopApp=desktopApp;
- this.manager=manager;
+ this.myCytoPanel = myCytoPanel;
+ cytable = manager.getCurrentNetwork().getDefaultNodeTable();
// Node Table
+ //CyTable cytable =
manager.getCurrentNetwork().getDefaultNetworkTable(); // Network Table
+ //CyTable cytable =
manager.getCurrentNetwork().getDefaultEdgeTable(); // Edge Table
}
/**
@@ -34,29 +53,55 @@
@Override
public void run(TaskMonitor taskMonitor) {
- CyTable cytable =
manager.getCurrentNetwork().getDefaultNodeTable(); // Node Table
- //CyTable cytable =
manager.getCurrentNetwork().getDefaultNetworkTable(); // Network Table
- //CyTable cytable =
manager.getCurrentNetwork().getDefaultEdgeTable(); // Edge Table
+ setTableValues(getColumnVector(), cytable.getRowCount());
- if(cytable != null){
- //Collect all columns, get their column names, iterate
over these
- Collection<CyColumn> cycolumns = (Collection<CyColumn>)
cytable.getColumns();
- for(CyColumn cycolumn : cycolumns){
- System.out.print(cycolumn.getName()+"\t");
+ new MyDialog(table);
+ if(!tableAlreadyExists)
+ {
+ myCytoPanel.add(new JScrollPane(table2));
+ myCytoPanel.revalidate();
+ tableAlreadyExists = true;
+ }
+ }
+
+ /**
+ * 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 void setTableValues(Vector<String> v, int rowCount){
+ DefaultTableModel tablemodel = new DefaultTableModel(v,
rowCount);
+ table = new JTable(tablemodel);
+ table2 = 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){
+
table.getModel().setValueAt(cyrowmap.get(cyColumnName), rowIndex, columnIndex);
+
table2.getModel().setValueAt(cyrowmap.get(cyColumnName), rowIndex,
columnIndex++);
}
- System.out.println();
-
- //Get all table rows, go row by row, extract values in
each row using column names from above
- Collection<CyRow> cyrows = cytable.getAllRows();
- for(CyRow cyrow : cyrows){
- Map<String, Object> cyrowmap =
cyrow.getAllValues();
- for(CyColumn cycolumn : cycolumns){
-
System.out.print(cyrowmap.get(cycolumn.getName())+"\t");
- }
- System.out.println();
- }
- }else{
- System.out.println("Please import a network");
+ rowIndex++;
+ columnIndex=0;
}
- }
+ }
}
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTaskFactory.java
===================================================================
---
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTaskFactory.java
2012-05-30 07:38:10 UTC (rev 29388)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PrintTableTaskFactory.java
2012-05-30 10:55:14 UTC (rev 29389)
@@ -1,26 +1,48 @@
package org.cytoscape.sample.internal;
import org.cytoscape.application.CyApplicationManager;
+import org.cytoscape.application.swing.CySwingApplication;
+import org.cytoscape.application.swing.CytoPanel;
+import org.cytoscape.application.swing.CytoPanelName;
+import org.cytoscape.application.swing.CytoPanelState;
import org.cytoscape.work.AbstractTaskFactory;
import org.cytoscape.work.TaskIterator;
public class PrintTableTaskFactory extends AbstractTaskFactory {
private CyApplicationManager manager;
+ private CySwingApplication desktopApp;
+ private final CytoPanel cytoPanelSouth;
+ private MyCytoPanel myCytoPanel;
/**
* Class constructor invoked by the <code>CyActivator</code> class
*
* @param manager an instance of <code>CyApplicationManager</code>
that is used to manage the current network
*/
- public PrintTableTaskFactory(CyApplicationManager manager){
- this.manager=manager;
+ public PrintTableTaskFactory(CyApplicationManager manager,
CySwingApplication desktopApp, MyCytoPanel myCytoPanel){
+ this.manager = manager;
+ this.desktopApp = desktopApp;
+ this.cytoPanelSouth =
this.desktopApp.getCytoPanel(CytoPanelName.SOUTH);
+ this.myCytoPanel = myCytoPanel;
}
/**
* @see org.cytoscape.work.TaskFactory#createTaskIterator()
*/
public TaskIterator createTaskIterator(){
- return new TaskIterator(new PrintTableTask(manager));
+ // If the state of the cytoPanelSouth is HIDE, show it
+ if (cytoPanelSouth.getState() == CytoPanelState.HIDE) {
+ cytoPanelSouth.setState(CytoPanelState.DOCK);
+ }
+
+ // Select my panel
+ int index = cytoPanelSouth.indexOfComponent(myCytoPanel);
+ if (index == -1) {
+ return null;
+ }
+ cytoPanelSouth.setSelectedIndex(index);
+
+ return new TaskIterator(new PrintTableTask(manager, desktopApp,
myCytoPanel));
}
}
--
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.