KickJava   Java API By Example, From Geeks To Geeks.

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


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  * GanttDemo1.java
24  * ---------------
25  * (C) Copyright 2002, 2003 by Object Refinery Limited.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: GanttDemo1.java,v 1.6 2003/11/28 10:57:36 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 06-Jun-2002 : Version 1 (DG);
35  * 10-Oct-2002 : Modified to use DemoDatasetFactory (DG);
36  * 10-Jan-2003 : Renamed GanttDemo --> GanttDemo1 (DG);
37  * 16-Oct-2003 : Shifted dataset from DemoDatasetFactory to this class (DG);
38  *
39  */

40
41 package org.jfree.chart.demo;
42
43 import java.util.Calendar JavaDoc;
44 import java.util.Date JavaDoc;
45
46 import org.jfree.chart.ChartFactory;
47 import org.jfree.chart.ChartPanel;
48 import org.jfree.chart.JFreeChart;
49 import org.jfree.data.IntervalCategoryDataset;
50 import org.jfree.data.gantt.Task;
51 import org.jfree.data.gantt.TaskSeries;
52 import org.jfree.data.gantt.TaskSeriesCollection;
53 import org.jfree.data.time.SimpleTimePeriod;
54 import org.jfree.ui.ApplicationFrame;
55 import org.jfree.ui.RefineryUtilities;
56
57 /**
58  * A simple demonstration application showing how to create a Gantt chart.
59  * <P>
60  * This demo is intended to show the conceptual approach rather than being a polished
61  * implementation.
62  *
63  * @author David Gilbert
64  *
65  */

66 public class GanttDemo1 extends ApplicationFrame {
67
68     /**
69      * Creates a new demo.
70      *
71      * @param title the frame title.
72      */

73     public GanttDemo1(String JavaDoc title) {
74
75         super(title);
76
77         IntervalCategoryDataset dataset = createDataset();
78         JFreeChart chart = createChart(dataset);
79
80         // add the chart to a panel...
81
ChartPanel chartPanel = new ChartPanel(chart);
82         chartPanel.setPreferredSize(new java.awt.Dimension JavaDoc(500, 270));
83         setContentPane(chartPanel);
84
85     }
86
87     // ****************************************************************************
88
// * COMMERCIAL SUPPORT / JFREECHART DEVELOPER GUIDE *
89
// * Please note that commercial support and documentation is available from: *
90
// * *
91
// * http://www.object-refinery.com/jfreechart/support.html *
92
// * *
93
// * This is not only a great service for developers, but is a VERY IMPORTANT *
94
// * source of funding for the JFreeChart project. Please support us so that *
95
// * we can continue developing free software. *
96
// ****************************************************************************
97

98     /**
99      * Creates a sample dataset for a Gantt chart.
100      *
101      * @return The dataset.
102      */

103     public static IntervalCategoryDataset createDataset() {
104
105         TaskSeries s1 = new TaskSeries("Scheduled");
106         s1.add(new Task("Write Proposal",
107                new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
108                                     date(5, Calendar.APRIL, 2001))));
109         s1.add(new Task("Obtain Approval",
110                new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
111                                     date(9, Calendar.APRIL, 2001))));
112         s1.add(new Task("Requirements Analysis",
113                new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
114                                     date(5, Calendar.MAY, 2001))));
115         s1.add(new Task("Design Phase",
116                new SimpleTimePeriod(date(6, Calendar.MAY, 2001),
117                                     date(30, Calendar.MAY, 2001))));
118         s1.add(new Task("Design Signoff",
119                new SimpleTimePeriod(date(2, Calendar.JUNE, 2001),
120                                     date(2, Calendar.JUNE, 2001))));
121         s1.add(new Task("Alpha Implementation",
122                new SimpleTimePeriod(date(3, Calendar.JUNE, 2001),
123                                     date(31, Calendar.JULY, 2001))));
124         s1.add(new Task("Design Review",
125                new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001),
126                                     date(8, Calendar.AUGUST, 2001))));
127         s1.add(new Task("Revised Design Signoff",
128                new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001),
129                                     date(10, Calendar.AUGUST, 2001))));
130         s1.add(new Task("Beta Implementation",
131                new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001),
132                                     date(12, Calendar.SEPTEMBER, 2001))));
133         s1.add(new Task("Testing",
134                new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001),
135                                     date(31, Calendar.OCTOBER, 2001))));
136         s1.add(new Task("Final Implementation",
137                new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001),
138                                     date(15, Calendar.NOVEMBER, 2001))));
139         s1.add(new Task("Signoff",
140                new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001),
141                                     date(30, Calendar.NOVEMBER, 2001))));
142
143         TaskSeries s2 = new TaskSeries("Actual");
144         s2.add(new Task("Write Proposal",
145                new SimpleTimePeriod(date(1, Calendar.APRIL, 2001),
146                                     date(5, Calendar.APRIL, 2001))));
147         s2.add(new Task("Obtain Approval",
148                new SimpleTimePeriod(date(9, Calendar.APRIL, 2001),
149                                     date(9, Calendar.APRIL, 2001))));
150         s2.add(new Task("Requirements Analysis",
151                new SimpleTimePeriod(date(10, Calendar.APRIL, 2001),
152                                     date(15, Calendar.MAY, 2001))));
153         s2.add(new Task("Design Phase",
154                new SimpleTimePeriod(date(15, Calendar.MAY, 2001),
155                                     date(17, Calendar.JUNE, 2001))));
156         s2.add(new Task("Design Signoff",
157                new SimpleTimePeriod(date(30, Calendar.JUNE, 2001),
158                                     date(30, Calendar.JUNE, 2001))));
159         s2.add(new Task("Alpha Implementation",
160                new SimpleTimePeriod(date(1, Calendar.JULY, 2001),
161                                     date(12, Calendar.SEPTEMBER, 2001))));
162         s2.add(new Task("Design Review",
163                new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001),
164                                     date(22, Calendar.SEPTEMBER, 2001))));
165         s2.add(new Task("Revised Design Signoff",
166                new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001),
167                                     date(27, Calendar.SEPTEMBER, 2001))));
168         s2.add(new Task("Beta Implementation",
169                new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001),
170                                     date(30, Calendar.OCTOBER, 2001))));
171         s2.add(new Task("Testing",
172                new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001),
173                                     date(17, Calendar.NOVEMBER, 2001))));
174         s2.add(new Task("Final Implementation",
175                new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001),
176                                     date(5, Calendar.DECEMBER, 2001))));
177         s2.add(new Task("Signoff",
178                new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001),
179                                     date(11, Calendar.DECEMBER, 2001))));
180
181         TaskSeriesCollection collection = new TaskSeriesCollection();
182         collection.add(s1);
183         collection.add(s2);
184
185         return collection;
186     }
187
188     /**
189      * Utility method for creating <code>Date</code> objects.
190      *
191      * @param day the date.
192      * @param month the month.
193      * @param year the year.
194      *
195      * @return a date.
196      */

197     private static Date JavaDoc date(int day, int month, int year) {
198
199         Calendar JavaDoc calendar = Calendar.getInstance();
200         calendar.set(year, month, day);
201         Date JavaDoc result = calendar.getTime();
202         return result;
203
204     }
205         
206     /**
207      * Creates a chart.
208      *
209      * @param dataset the dataset.
210      *
211      * @return The chart.
212      */

213     private JFreeChart createChart(IntervalCategoryDataset dataset) {
214         JFreeChart chart = ChartFactory.createGanttChart(
215             "Gantt Chart Demo", // chart title
216
"Task", // domain axis label
217
"Date", // range axis label
218
dataset, // data
219
true, // include legend
220
true, // tooltips
221
false // urls
222
);
223         return chart;
224     }
225     
226     /**
227      * Starting point for the demonstration application.
228      *
229      * @param args ignored.
230      */

231     public static void main(String JavaDoc[] args) {
232
233         GanttDemo1 demo = new GanttDemo1("Gantt Chart Demo 1");
234         demo.pack();
235         RefineryUtilities.centerFrameOnScreen(demo);
236         demo.setVisible(true);
237
238     }
239
240 }
241
Popular Tags