KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SampleXYDatasetThread.java
24  * --------------------------
25  * (C) Copyright 2001-2003, by Object Refinery Limited;
26  *
27  * Original Author: David Gilbert;
28  * Contributor(s): -;
29  *
30  * $Id: SampleXYDatasetThread.java,v 1.2 2003/05/29 15:23:34 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 22-Oct-2001 : Version 1 (DG);
35  * 07-Nov-2001 : Updated source header (DG);
36  *
37  */

38
39 package org.jfree.chart.demo;
40
41 /**
42  * Implements the runnable interface and updates the SampleXYDataset. This gives the event
43  * notification mechanism in JFreeChart a run to make sure it works.
44  *
45  * WARNING 1 : There are likely to be problems with accessing datasets from more than one thread,
46  * so don't use this code for anything other than the demo!
47  * <P>
48  * WARNING 2 : Updating the dataset this way 'animates' the chart - but JFreeChart is not designed
49  * for the production of animated charts. For fast animations, you need a chart that draws to
50  * a bitmap, in order to optimise the screen updates. But JFreeChart draws to an abstract
51  * drawing surface (Graphics2D), which brings many benefits, but also means that we cannot implement
52  * any performance tricks when the screen updates because we cannot guarantee which pixels are
53  * rendered by the Graphics2D pipeline...
54  *
55  * @author David Gilbert
56  */

57 public class SampleXYDatasetThread implements Runnable JavaDoc {
58
59     /** The data. */
60     private SampleXYDataset data;
61
62     /**
63      * Creates a new thread.
64      *
65      * @param data the dataset.
66      */

67     public SampleXYDatasetThread(SampleXYDataset data) {
68         this.data = data;
69     }
70
71     /**
72      * Runs the thread.
73      */

74     public void run() {
75         while (true) {
76             try {
77                 Thread.sleep(500);
78                 data.setTranslate(data.getTranslate() + 0.25);
79             }
80             catch (Exception JavaDoc e) {
81                 // ignore
82
}
83       }
84
85     }
86
87 }
88
Popular Tags