KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > graph > GraphSeriesPanel


1 /*
2  * Copyright 2002-2005 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
28 import java.awt.BorderLayout JavaDoc;
29 import java.awt.Dimension JavaDoc;
30
31 /**
32  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Mar 30, 2006
33  * @version $Revision: 570 $($Author: ghinkl $ / $Date: 2006-04-12 15:14:16 -0400 (Wed, 12 Apr 2006) $)
34  */

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 JavaDoc());
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 JavaDoc(450,250));
55     }
56
57
58     private class SeriesTableModel extends AbstractTableModel JavaDoc {
59
60
61         public int getRowCount() {
62             return timeSeriesCollection.getSeriesCount();
63         }
64
65         public int getColumnCount() {
66             return 3;
67         }
68
69         public String JavaDoc 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 JavaDoc<?> getColumnClass(int column) {
79             switch (column) {
80                 case 0: return String JavaDoc.class;
81                 case 1: return String JavaDoc.class;
82                 case 2: return Number JavaDoc.class;
83                 default: return Object JavaDoc.class;
84             }
85         }
86
87
88         public Object JavaDoc 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