KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * SampleChart, a test for memory leak contributed by Martin Rojo.
3  * Copyright (C) 2002 Achim Westermann, Achim.Westermann@gmx.de
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 package info.monitorenter.gui.chart.demos;
23
24 import info.monitorenter.gui.chart.Chart2D;
25 import info.monitorenter.gui.chart.ITrace2D;
26 import info.monitorenter.gui.chart.io.ADataCollector;
27 import info.monitorenter.gui.chart.io.RandomDataCollectorOffset;
28 import info.monitorenter.gui.chart.layout.ChartPanel;
29 import info.monitorenter.gui.chart.traces.Trace2DLtdReplacing;
30
31 import java.awt.BorderLayout JavaDoc;
32 import java.awt.Color JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.event.WindowAdapter JavaDoc;
35 import java.awt.event.WindowEvent JavaDoc;
36
37 import javax.swing.JFrame JavaDoc;
38 import javax.swing.JPanel JavaDoc;
39
40
41 /**
42  * <p>
43  * Sample chart from Java 2D open source package.
44  * </p>
45  *
46  * <p>
47  * Copyright: sample code taken from http://jchart2d.sourceforge.net/usage.shtml
48  * </p>
49  *
50  * <p>
51  * Company: Infotility
52  * </p>
53  *
54  * @author Martin Rojo
55  *
56  * @author Achim Westermann (modified)
57  *
58  * @version $Revision: 1.1 $
59  */

60 public class SampleChart extends JPanel JavaDoc {
61   /**
62    * Generated <code>serialVersionUID</code>.
63    */

64   private static final long serialVersionUID = 3257009847668192306L;
65
66   /**
67    * Main entry.
68    * <p>
69    *
70    * @param args
71    * ignored.
72    * <p>
73    */

74   public static void main(final String JavaDoc[] args) {
75     for (int i = 0; i < 1; i++) {
76       JFrame JavaDoc frame = new JFrame JavaDoc("SampleChart");
77       frame.getContentPane().add(new SampleChart());
78       frame.addWindowListener(new WindowAdapter JavaDoc() {
79         public void windowClosing(final WindowEvent JavaDoc e) {
80           System.exit(0);
81         }
82       });
83       frame.setSize(600, 300);
84       frame.setLocation(i % 3 * 200, i / 3 * 100);
85       frame.setVisible(true);
86     }
87   }
88
89   /**
90    * Defcon.
91    * <p>
92    */

93   public SampleChart() {
94     this.setLayout(new BorderLayout JavaDoc());
95     this.setMaximumSize(new Dimension JavaDoc(600, 600));
96     this.setPreferredSize(new Dimension JavaDoc(500, 600));
97     Chart2D chart = new Chart2D();
98     // Create an ITrace:
99
// Note that dynamic charts need limited amount of values!!!
100
// ITrace2D trace = new Trace2DLtd(200);
101
// 3/11/-5 , let's try something else too:
102
ITrace2D trace = new Trace2DLtdReplacing(100);
103     trace.setColor(Color.RED);
104
105     // Add the trace to the chart:
106
chart.addTrace(trace);
107
108     // Make it visible:
109
this.add(new ChartPanel(chart), BorderLayout.CENTER);
110
111     /**
112      * ** removing this for now, potential memory leak ? 3/11/05
113      */

114
115     // Enable the termination button [cross on the upperright edge]:
116
// Every 50 milliseconds a new value is collected.
117
ADataCollector collector = new RandomDataCollectorOffset(trace, 100);
118     // Start a Thread that adds the values:
119
collector.start();
120     /** ********** potential memory leak ? 3/1//05 */
121   }
122 }
123
Popular Tags