KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > xy > XYBarDataset


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -----------------
28  * XYBarDataset.java
29  * -----------------
30  * (C) Copyright 2004-2006, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: XYBarDataset.java,v 1.4.2.2 2006/08/03 16:22:40 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 02-Mar-2004 : Version 1 (DG);
40  * 05-May-2004 : Now extends AbstractIntervalXYDataset (DG);
41  * 15-Jul-2004 : Switched getX() with getXValue() and getY() with
42  * getYValue() (DG);
43  *
44  */

45
46 package org.jfree.data.xy;
47
48 import org.jfree.data.general.DatasetChangeEvent;
49 import org.jfree.data.general.DatasetChangeListener;
50
51 /**
52  * A dataset wrapper class that converts a standard {@link XYDataset} into an
53  * {@link IntervalXYDataset} suitable for use in creating XY bar charts.
54  */

55 public class XYBarDataset extends AbstractIntervalXYDataset
56                           implements IntervalXYDataset, DatasetChangeListener {
57     
58     /** The underlying dataset. */
59     private XYDataset underlying;
60     
61     /** The bar width. */
62     private double barWidth;
63     
64     /**
65      * Creates a new dataset.
66      *
67      * @param underlying the underlying dataset.
68      * @param barWidth the width of the bars.
69      */

70     public XYBarDataset(XYDataset underlying, double barWidth) {
71         this.underlying = underlying;
72         this.underlying.addChangeListener(this);
73         this.barWidth = barWidth;
74     }
75
76     /**
77      * Returns the number of series in the dataset.
78      *
79      * @return The series count.
80      */

81     public int getSeriesCount() {
82         return this.underlying.getSeriesCount();
83     }
84
85     /**
86      * Returns the key for a series.
87      *
88      * @param series the series index (in the range <code>0</code> to
89      * <code>getSeriesCount() - 1</code>).
90      *
91      * @return The series key.
92      */

93     public Comparable JavaDoc getSeriesKey(int series) {
94         return this.underlying.getSeriesKey(series);
95     }
96     
97     /**
98      * Returns the number of items in a series.
99      *
100      * @param series the series index (zero-based).
101      *
102      * @return The item count.
103      */

104     public int getItemCount(int series) {
105         return this.underlying.getItemCount(series);
106     }
107
108     /**
109      * Returns the x-value for an item within a series. The x-values may or
110      * may not be returned in ascending order, that is up to the class
111      * implementing the interface.
112      *
113      * @param series the series index (zero-based).
114      * @param item the item index (zero-based).
115      *
116      * @return The x-value.
117      */

118     public Number JavaDoc getX(int series, int item) {
119         return this.underlying.getX(series, item);
120     }
121
122     /**
123      * Returns the y-value for an item within a series.
124      *
125      * @param series the series index (zero-based).
126      * @param item the item index (zero-based).
127      *
128      * @return The y-value (possibly <code>null</code>).
129      */

130     public Number JavaDoc getY(int series, int item) {
131         return this.underlying.getY(series, item);
132     }
133
134     /**
135      * Returns the starting X value for the specified series and item.
136      *
137      * @param series the series index (zero-based).
138      * @param item the item index (zero-based).
139      *
140      * @return The value.
141      */

142     public Number JavaDoc getStartX(int series, int item) {
143         Number JavaDoc result = null;
144         Number JavaDoc xnum = this.underlying.getX(series, item);
145         if (xnum != null) {
146              result = new Double JavaDoc(xnum.doubleValue() - this.barWidth / 2.0);
147         }
148         return result;
149     }
150
151     /**
152      * Returns the ending X value for the specified series and item.
153      *
154      * @param series the series index (zero-based).
155      * @param item the item index (zero-based).
156      *
157      * @return The value.
158      */

159     public Number JavaDoc getEndX(int series, int item) {
160         Number JavaDoc result = null;
161         Number JavaDoc xnum = this.underlying.getX(series, item);
162         if (xnum != null) {
163              result = new Double JavaDoc(xnum.doubleValue() + this.barWidth / 2.0);
164         }
165         return result;
166     }
167
168     /**
169      * Returns the starting Y value for the specified series and item.
170      *
171      * @param series the series index (zero-based).
172      * @param item the item index (zero-based).
173      *
174      * @return The value.
175      */

176     public Number JavaDoc getStartY(int series, int item) {
177         return this.underlying.getY(series, item);
178     }
179
180     /**
181      * Returns the ending Y value for the specified series and item.
182      *
183      * @param series the series index (zero-based).
184      * @param item the item index (zero-based).
185      *
186      * @return The value.
187      */

188     public Number JavaDoc getEndY(int series, int item) {
189         return this.underlying.getY(series, item);
190     }
191
192     /**
193      * Receives notification of an dataset change event.
194      *
195      * @param event information about the event.
196      */

197     public void datasetChanged(DatasetChangeEvent event) {
198         this.notifyListeners(event);
199     }
200
201 }
202
Popular Tags