1 16 package org.mc4j.console.swing.graph; 17 18 import org.jdesktop.swingx.JXTable; 19 import org.jdesktop.swingx.decorator.HighlighterPipeline; 20 import org.jdesktop.swingx.decorator.Highlighter; 21 import org.jdesktop.swingx.decorator.AlternateRowHighlighter; 22 import org.jfree.data.time.TimeSeries; 23 import org.jfree.data.time.TimeSeriesCollection; 24 import org.mc4j.ems.connection.bean.attribute.EmsAttribute; 25 26 import javax.swing.*; 27 import javax.swing.table.AbstractTableModel ; 28 import java.awt.BorderLayout ; 29 import java.awt.Dimension ; 30 31 35 public class GraphSeriesPanel extends JPanel { 36 37 TimeSeriesCollection timeSeriesCollection; 38 39 public GraphSeriesPanel(TimeSeriesCollection timeSeriesCollection) { 40 this.timeSeriesCollection = timeSeriesCollection; 41 init(); 42 } 43 44 private void init() { 45 setLayout(new BorderLayout ()); 46 47 add(new JLabel("Currently graphed attributes"), BorderLayout.NORTH); 48 49 JXTable table = new JXTable(new SeriesTableModel()); 50 table.setHighlighters(new HighlighterPipeline(new Highlighter[] { new AlternateRowHighlighter() })); 51 table.setColumnControlVisible(true); 52 add(new JScrollPane(table), BorderLayout.CENTER); 53 setSize(450,250); 54 setPreferredSize(new Dimension (450,250)); 55 } 56 57 58 private class SeriesTableModel extends AbstractTableModel { 59 60 61 public int getRowCount() { 62 return timeSeriesCollection.getSeriesCount(); 63 } 64 65 public int getColumnCount() { 66 return 3; 67 } 68 69 public String getColumnName(int column) { 70 switch (column) { 71 case 0: return "Name"; 72 case 1: return "Description"; 73 case 2: return "Value"; 74 default: return ""; 75 } 76 } 77 78 public Class <?> getColumnClass(int column) { 79 switch (column) { 80 case 0: return String .class; 81 case 1: return String .class; 82 case 2: return Number .class; 83 default: return Object .class; 84 } 85 } 86 87 88 public Object getValueAt(int row, int column) { 89 TimeSeries s = timeSeriesCollection.getSeries(row); 90 EmsAttribute attribute = (EmsAttribute) s.getKey(); 91 switch (column) { 92 case 0: return attribute.getName(); 93 case 1: return attribute.getDescription(); 94 case 2: return attribute.getValue(); 95 case 3: return new JButton("Hi"); 96 default: return s; 97 } 98 } 99 } 100 101 } 102 103 104 | Popular Tags |