KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > layout > demos > CoordinateViewChart


1 /*
2  * CoordinateViewChart.java of project jchart2d, a demo that uses
3  * a ChartCoordinateView to display the position of the mouse over the chart.
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.layout.demos;
23
24 import info.monitorenter.gui.chart.Chart2D;
25 import info.monitorenter.gui.chart.ITrace2D;
26 import info.monitorenter.gui.chart.io.AStaticDataCollector;
27 import info.monitorenter.gui.chart.io.PropertyFileStaticDataCollector;
28 import info.monitorenter.gui.chart.layout.ChartPanel;
29 import info.monitorenter.gui.chart.layout.LayoutFactory;
30 import info.monitorenter.gui.chart.layout.views.ChartCoordinateView;
31 import info.monitorenter.gui.chart.traces.Trace2DLtd;
32
33 import java.awt.Container JavaDoc;
34 import java.awt.Dimension JavaDoc;
35 import java.awt.GridBagConstraints JavaDoc;
36 import java.awt.GridBagLayout JavaDoc;
37 import java.awt.event.WindowAdapter JavaDoc;
38 import java.awt.event.WindowEvent JavaDoc;
39 import java.io.IOException JavaDoc;
40
41 import javax.swing.JFrame JavaDoc;
42
43
44 /**
45  * A demo that uses a {@link info.monitorenter.gui.chart.layout.views.ChartCoordinateView} to
46  * display the position of the mouse over the chart.
47  * <p>
48  *
49  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann</a>
50  * @version $Revision: 1.2 $
51  */

52 public class CoordinateViewChart extends JFrame JavaDoc {
53
54   /** The chart to display and query for coordinates. */
55   private Chart2D m_chart;
56
57   /**
58    * Creates an instance that displays the given chart and a
59    * {@link ChartCoordinateView} to show the coordinates of the mouse cursor
60    * over the chart.
61    * <p>
62    *
63    * @param chart
64    * the chart to display and sshow the coordinates of the mouse cursor
65    * over it.
66    */

67   public CoordinateViewChart(final Chart2D chart) {
68     super("View coordinates");
69     this.m_chart = chart;
70
71     ChartCoordinateView viewChartValue = new ChartCoordinateView(this.m_chart);
72     // listen for basic propery changes of the chart:
73
new LayoutFactory.BasicPropertyAdaptSupport(viewChartValue, this.m_chart);
74
75     Container JavaDoc contentPane = this.getContentPane();
76     contentPane.setLayout(new GridBagLayout JavaDoc());
77     new LayoutFactory.BasicPropertyAdaptSupport(contentPane, this.m_chart);
78
79     // chart: use space
80
GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
81     gbc.gridx = 0;
82     gbc.gridy = 0;
83     gbc.gridheight = 1;
84     gbc.gridwidth = 1;
85     gbc.weightx = 1;
86     gbc.weighty = 1.0;
87     gbc.insets.bottom = 8;
88     gbc.anchor = GridBagConstraints.NORTH;
89     gbc.fill = GridBagConstraints.BOTH;
90     contentPane.add(new ChartPanel(this.m_chart), gbc);
91
92     // coordinate view: stay small
93
gbc.gridy = 1;
94     gbc.weighty = 0.0;
95     gbc.insets.bottom = 0;
96     gbc.anchor = GridBagConstraints.NORTH;
97     gbc.fill = GridBagConstraints.NONE;
98     contentPane.add(viewChartValue, gbc);
99
100     this.addWindowListener(new WindowAdapter JavaDoc() {
101       public void windowClosing(final WindowEvent JavaDoc e) {
102         System.exit(0);
103       }
104     });
105
106     this.setSize(new Dimension JavaDoc(400, 300));
107     this.setVisible(true);
108
109   }
110
111   /**
112    * Demo application startup method.
113    * <p>
114    *
115    * @param args
116    * ignored.
117    * @throws IOException
118    * if loading data for the demo chart fails.
119    */

120   public static void main(final String JavaDoc[] args) throws IOException JavaDoc {
121     Chart2D chart = new Chart2D();
122
123     ITrace2D trace = new Trace2DLtd(400);
124     AStaticDataCollector collector = new PropertyFileStaticDataCollector(trace,
125         CoordinateViewChart.class.getResourceAsStream("data.properties"));
126     collector.collectData();
127     chart.addTrace(trace);
128     new CoordinateViewChart(chart);
129
130   }
131
132 }
133
Popular Tags