Author: neildhruva
Date: 2012-07-11 07:50:15 -0700 (Wed, 11 Jul 2012)
New Revision: 29826
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CytoChart.java
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
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/PanelComponents.java
Log:
Two example charts are added to CytoChart.java. A JComboBox is provided to the
user to switch between chart types. A new column is added to the custom
myCyTable attached to every network that contains the chart selected for that
particular network.
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CytoChart.java
===================================================================
---
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CytoChart.java
2012-07-11 00:04:16 UTC (rev 29825)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/CytoChart.java
2012-07-11 14:50:15 UTC (rev 29826)
@@ -1,20 +1,31 @@
package org.cytoscape.sample.internal;
+import java.util.Vector;
+
+import javax.swing.JTable;
+
import org.jfree.chart.ChartFactory;
-import org.jfree.chart.ChartPanel;
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 ChartPanel myChart;
private DefaultCategoryDataset dataset;
+ Vector<String> plottableColumns;
- public CytoChart() {
+ public CytoChart(JTable table) {
- dataset = new DefaultCategoryDataset();
+ //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));
+
+ }
}
/**
@@ -22,7 +33,60 @@
*
* @return The <code>ChartPanel</code> that contains the newly created
chart.
*/
- public ChartPanel createChart(){
+ 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");
@@ -31,8 +95,15 @@
chart = ChartFactory.createBarChart("Comparison between
Salesman",
"Salesman", "Profit", dataset, PlotOrientation.VERTICAL,
false, true, false);
- myChart = new ChartPanel(chart);
- myChart.setMouseWheelEnabled(true);
- return myChart;
+
+ return chart;
}
+
+ /**
+ *
+ * @return The current chart.
+ */
+ public JFreeChart getTheChart() {
+ return this.chart;
+ }
}
Modified:
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
===================================================================
---
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
2012-07-11 00:04:16 UTC (rev 29825)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/EventTableAdded.java
2012-07-11 14:50:15 UTC (rev 29826)
@@ -5,6 +5,7 @@
import java.util.Iterator;
import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
import javax.swing.JTable;
import org.cytoscape.application.events.SetCurrentNetworkEvent;
@@ -29,6 +30,7 @@
private CyTableFactory tableFactory;
private CyTableManager cyTableManager;
private CyNetworkTableManager cyNetworkTableMgr;
+ private JComboBox chartTypeComboBox;
EventTableAdded(MyCytoPanel myCytoPanel,
CyTableFactory tableFactory,
@@ -39,7 +41,7 @@
this.tableFactory = tableFactory;
this.cyNetworkTableMgr = cyNetworkTableMgr;
this.cyTableManager = cyTableManager;
- this.panelComponents = new PanelComponents();
+ this.panelComponents = new PanelComponents(myCytoPanel);
}
@@ -73,7 +75,7 @@
}
if(myCyTable!=null) {
- checkBoxArray =
panelComponents.initCheckBoxArray(myCyTable, cytable);
+ 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)
@@ -88,20 +90,24 @@
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);
- checkBoxArray =
panelComponents.initCheckBoxArray(myCyTable, cytable);
+ panelComponents.initCheckBoxArray(myCyTable, cytable);
}
+ chartTypeComboBox = panelComponents.getComboBox();
table = panelComponents.getTable();
- myCytoPanel.initComponents(table, checkBoxArray, columnCount);
+ checkBoxArray = panelComponents.getCheckBoxArray();
+ myCytoPanel.initComponents(table, checkBoxArray, columnCount,
chartTypeComboBox);
}
}
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-07-11 00:04:16 UTC (rev 29825)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/MyCytoPanel.java
2012-07-11 14:50:15 UTC (rev 29826)
@@ -1,12 +1,14 @@
package org.cytoscape.sample.internal;
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;
@@ -16,6 +18,7 @@
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 {
@@ -27,12 +30,15 @@
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);
+
}
/**
@@ -42,25 +48,37 @@
* @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){
+ public void initComponents(JTable table, JCheckBox[] checkBoxArray, int
tableColumnCount, JComboBox jComboBox1){
if(this.getComponents().length>0)
this.removeAll();
- cytoChart = new CytoChart();
- myChart = cytoChart.createChart();
+ this.setBounds(0, 0, 2000, 2000);
+ this.setPreferredSize(new Dimension(2000, 2000));
- this.checkBoxArray = checkBoxArray;
+ 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();
+
}
/**
@@ -74,18 +92,22 @@
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))
+ );
- layout.setHorizontalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE,
260, GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(checkBoxGroupHor)
- .addGap(16, 16, 16)
- .addComponent(myChart, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addGap(35, 35, 35))
- );
-
SequentialGroup checkBoxGroupVert = layout.createSequentialGroup();
checkBoxGroupVert.addContainerGap();
for(int i=0;i<tableColumnCount;i++){
@@ -96,14 +118,17 @@
}
layout.setVerticalGroup(
- layout.createParallelGroup(GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 304,
Short.MAX_VALUE)
+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
- .addComponent(myChart, GroupLayout.PREFERRED_SIZE,
GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
- .addGap(184, 184, 184))
- .addGroup(checkBoxGroupVert
- .addContainerGap())
- );
+
.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() {
@@ -130,4 +155,20 @@
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);
+ }
}
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-07-11 00:04:16 UTC (rev 29825)
+++
csplugins/trunk/soc/neildhruva/PrintTable/src/main/java/org/cytoscape/sample/internal/PanelComponents.java
2012-07-11 14:50:15 UTC (rev 29826)
@@ -1,11 +1,14 @@
package org.cytoscape.sample.internal;
+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;
@@ -21,19 +24,36 @@
private CyTable myCyTable;
private List<Boolean> checkBoxState;
private List<String> columnNamesList;
+ private JComboBox chartTypeComboBox;
+ private MyCytoPanel myCytoPanel;
+ private String chartType;
- public PanelComponents() {
-
+ 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.
*
- * @return JCheckBox[] Array of checkboxes initialized with column names
as titles
*/
- public JCheckBox[] initCheckBoxArray(CyTable myCyTable, CyTable cytable){
+ @SuppressWarnings("unchecked")
+ public void initCheckBoxArray(CyTable myCyTable, CyTable cytable){
this.myCyTable = myCyTable;
this.table = new JTable(new MyTableModel(cytable));
@@ -80,7 +100,23 @@
}
}
- return checkBoxArray;
+ //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));
+ }
}
/**
@@ -126,6 +162,15 @@
/**
*
+ * @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.
*/
@@ -135,6 +180,15 @@
/**
*
+ * @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(){
@@ -148,5 +202,13 @@
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.