KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > demo > InternalFrameDemo


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ----------------------
23  * InternalFrameDemo.java
24  * ----------------------
25  * (C) Copyright 2003, by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited).
28  * Contributor(s): -;
29  *
30  * $Id: InternalFrameDemo.java,v 1.3 2003/11/28 10:57:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 29-Jul-2003 : Version 1 (DG);
35  *
36  */

37 package org.jfree.chart.demo;
38
39 import java.awt.Dimension JavaDoc;
40
41 import javax.swing.JDesktopPane JavaDoc;
42 import javax.swing.JInternalFrame JavaDoc;
43
44 import org.jfree.chart.ChartFactory;
45 import org.jfree.chart.ChartPanel;
46 import org.jfree.chart.JFreeChart;
47 import org.jfree.chart.plot.PlotOrientation;
48 import org.jfree.data.DefaultCategoryDataset;
49 import org.jfree.data.XYDataset;
50 import org.jfree.data.time.Minute;
51 import org.jfree.data.time.RegularTimePeriod;
52 import org.jfree.data.time.TimeSeries;
53 import org.jfree.data.time.TimeSeriesCollection;
54 import org.jfree.ui.ApplicationFrame;
55 import org.jfree.ui.RefineryUtilities;
56
57 /**
58  * A simple internal frame demo.
59  *
60  * @author David Gilbert
61  */

62 public class InternalFrameDemo extends ApplicationFrame {
63
64     /**
65      * Creates a new instance of the demo.
66      *
67      * @param title the title.
68      */

69     public InternalFrameDemo(String JavaDoc title) {
70         super(title);
71         JDesktopPane JavaDoc desktopPane = new JDesktopPane JavaDoc();
72         desktopPane.setPreferredSize(new Dimension JavaDoc(600, 400));
73         JInternalFrame JavaDoc frame1 = createFrame1();
74         desktopPane.add(frame1);
75         frame1.pack();
76         frame1.setVisible(true);
77         JInternalFrame JavaDoc frame2 = createFrame2();
78         desktopPane.add(frame2);
79         frame2.pack();
80         frame2.setLocation(100, 200);
81         frame2.setVisible(true);
82         getContentPane().add(desktopPane);
83     }
84     
85     /**
86      * Creates an internal frame.
87      *
88      * @return An internal frame.
89      */

90     private JInternalFrame JavaDoc createFrame1() {
91         DefaultCategoryDataset dataset = new DefaultCategoryDataset();
92         dataset.addValue(34.0, "Series 1", "Category 1");
93         dataset.addValue(23.0, "Series 1", "Category 2");
94         dataset.addValue(54.0, "Series 1", "Category 3");
95         JFreeChart chart = ChartFactory.createBarChart(
96             "Bar Chart",
97             "Category",
98             "Series",
99             dataset,
100             PlotOrientation.VERTICAL,
101             true,
102             true,
103             false
104         );
105         ChartPanel chartPanel = new ChartPanel(chart);
106         chartPanel.setPreferredSize(new Dimension JavaDoc(200, 100));
107         JInternalFrame JavaDoc frame = new JInternalFrame JavaDoc("Frame 1", true);
108         frame.getContentPane().add(chartPanel);
109         return frame;
110         
111     }
112     
113     /**
114      * Creates an internal frame.
115      *
116      * @return An internal frame.
117      */

118     private JInternalFrame JavaDoc createFrame2() {
119         XYDataset dataset1 = createDataset("Series 1", 100.0, new Minute(), 200);
120         
121         JFreeChart chart = ChartFactory.createTimeSeriesChart(
122             "Time Series Chart",
123             "Time of Day",
124             "Value",
125             dataset1,
126             true,
127             true,
128             false
129         );
130         ChartPanel chartPanel = new ChartPanel(chart);
131         chartPanel.setPreferredSize(new Dimension JavaDoc(200, 100));
132         JInternalFrame JavaDoc frame = new JInternalFrame JavaDoc("Frame 2", true);
133         frame.getContentPane().add(chartPanel);
134         return frame;
135     }
136     
137     /**
138      * Creates a sample dataset.
139      *
140      * @param name the dataset name.
141      * @param base the starting value.
142      * @param start the starting period.
143      * @param count the number of values to generate.
144      *
145      * @return The dataset.
146      */

147     private XYDataset createDataset(String JavaDoc name, double base, RegularTimePeriod start, int count) {
148
149         TimeSeries series = new TimeSeries(name, start.getClass());
150         RegularTimePeriod period = start;
151         double value = base;
152         for (int i = 0; i < count; i++) {
153             series.add(period, value);
154             period = period.next();
155             value = value * (1 + (Math.random() - 0.495) / 10.0);
156         }
157
158         TimeSeriesCollection dataset = new TimeSeriesCollection();
159         dataset.addSeries(series);
160
161         return dataset;
162
163     }
164
165     // ****************************************************************************
166
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
167
// * Please note that commercial support and documentation is available from: *
168
// * *
169
// * http://www.object-refinery.com/jfreechart/support.html *
170
// * *
171
// * This is not only a great service for developers, but is a VERY IMPORTANT *
172
// * source of funding for the JFreeChart project. Please support us so that *
173
// * we can continue developing free software. *
174
// ****************************************************************************
175

176     /**
177      * The starting point for the demo.
178      *
179      * @param args ignored.
180      */

181     public static void main(String JavaDoc[] args) {
182         InternalFrameDemo demo = new InternalFrameDemo("Internal Frame Demo");
183         demo.pack();
184         RefineryUtilities.centerFrameOnScreen(demo);
185         demo.setVisible(true);
186         
187     }
188
189 }
190
Popular Tags