KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > demos > StaticCollectorChart


1 /*
2  * StaticCollectorChart.java, utility test class for jchart2d.
3  * Copyright (C) Achim Westermann, created on 10.12.2004, 13:48:55
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  *
22  */

23 package info.monitorenter.gui.chart.demos;
24
25 import info.monitorenter.gui.chart.Chart2D;
26 import info.monitorenter.gui.chart.ITrace2D;
27 import info.monitorenter.gui.chart.io.AStaticDataCollector;
28 import info.monitorenter.gui.chart.io.PropertyFileStaticDataCollector;
29 import info.monitorenter.gui.chart.layout.ChartPanel;
30 import info.monitorenter.gui.chart.traces.Trace2DSimple;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.event.WindowAdapter JavaDoc;
34 import java.awt.event.WindowEvent JavaDoc;
35 import java.io.File JavaDoc;
36 import java.io.FileInputStream JavaDoc;
37 import java.io.IOException JavaDoc;
38 import java.io.InputStream JavaDoc;
39
40 import javax.swing.JFrame JavaDoc;
41 import javax.swing.JPanel JavaDoc;
42
43 /**
44  * A chart to test labels. This chart uses a
45  * <code>{@link info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber}</code>
46  * that formats to whole integer numbers. No same labels should appear.
47  * <p>
48  *
49  * @author Achim Westermann
50  *
51  * @version $Revision: 1.1 $
52  */

53 public class StaticCollectorChart extends JPanel JavaDoc {
54
55   /**
56    * Generated <code>serialVersionUID</code>.
57    */

58   private static final long serialVersionUID = 3689069555917797688L;
59
60   /**
61    * Shows the chart in a frame and fills it with the data file that is
62    * specified by the first command line argument.
63    * <p>
64    *
65    * @param args
66    * arg[0] has to be a file name of a data file in
67    * java.util.Properties format.
68    *
69    * @throws IOException
70    * if sth. goes wrong.
71    */

72   public static void main(final String JavaDoc[] args) throws IOException JavaDoc {
73     JFrame JavaDoc frame = new JFrame JavaDoc("SampleChart");
74     InputStream JavaDoc stream = new FileInputStream JavaDoc(new File JavaDoc(args[0]));
75     ITrace2D trace = new Trace2DSimple();
76     AStaticDataCollector collector = new PropertyFileStaticDataCollector(trace, stream);
77
78     frame.getContentPane().add(new StaticCollectorChart(collector));
79     frame.addWindowListener(new WindowAdapter JavaDoc() {
80       public void windowClosing(final WindowEvent JavaDoc e) {
81         System.exit(0);
82       }
83     });
84     frame.setSize(600, 600);
85     frame.setVisible(true);
86   }
87
88   /** The internal chart. */
89   private Chart2D m_chart;
90
91   /**
92    * Creates a chart that collects it's data from the given collector.
93    * <p>
94    *
95    * @param datacollector
96    * the data collector to use.
97    *
98    * @throws IOException
99    * if collecting data fails.
100    */

101   public StaticCollectorChart(final AStaticDataCollector datacollector) throws IOException JavaDoc {
102     this.setLayout(new BorderLayout JavaDoc());
103     this.m_chart = new Chart2D();
104
105     // Add all points, as it is static:
106
datacollector.collectData();
107     // Add the trace to the chart:
108
this.m_chart.addTrace(datacollector.getTrace());
109
110     // Make it visible:
111
this.add(new ChartPanel(this.m_chart), BorderLayout.CENTER);
112
113   }
114
115   /**
116    * Returns the chart.
117    * <p>
118    *
119    * @return Returns the chart.
120    */

121   public final Chart2D getChart() {
122     return this.m_chart;
123   }
124 }
125
Popular Tags