KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > SeriesShapeFactory


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  * SeriesShapeFactory.java
24  * -----------------------
25  * (C) Copyright 2002, 2003, by Jeremy Bowman.
26  *
27  * Original Author: Jeremy Bowman;
28  * Contributor(s): -;
29  *
30  * $Id: SeriesShapeFactory.java,v 1.4 2003/09/03 15:08:41 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 13-May-2002 : Version 1 (JB);
35  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
36  * 06-Aug-2003 : No longer required, so deprecated (DG);
37  *
38  */

39
40 package org.jfree.chart;
41
42 import java.awt.Polygon JavaDoc;
43 import java.awt.Shape JavaDoc;
44 import java.awt.geom.Ellipse2D JavaDoc;
45 import java.awt.geom.Rectangle2D JavaDoc;
46
47 /**
48  * Provider of shapes for indicating data points on a Plot. This one
49  * uses a distinct shape for each series, looping if it exhausts the
50  * possibilities.
51  *
52  * @deprecated No longer used. Shapes are supplied by the DrawingSupplier class.
53  *
54  * @author Jeremy Bowman
55  */

56 public class SeriesShapeFactory implements ShapeFactory {
57
58     /** The number of distinct shapes available */
59     private static final int SHAPE_COUNT = 11;
60
61     /**
62      * Returns a Shape that can be used in plotting data. Used in XYPlots.
63      *
64      * @param series the index of the series.
65      * @param item the index of the item.
66      * @param x x-coordinate of the item.
67      * @param y y-coordinate of the item.
68      * @param scale the size.
69      *
70      * @return a Shape that can be used in plotting data.
71      */

72     public Shape JavaDoc getShape(int series, int item, double x, double y, double scale) {
73
74         return getShape(series, null, x, y, scale);
75
76     }
77
78     /**
79      * Returns a Shape that can be used in plotting data. Used in CategoryPlots.
80      *
81      * @param series the index of the series.
82      * @param category the category.
83      * @param x x-coordinate of the category.
84      * @param y y-coordinate of the category.
85      * @param scale the size.
86      *
87      * @return a Shape that can be used in plotting data.
88      */

89     public Shape JavaDoc getShape(int series, Object JavaDoc category, double x, double y, double scale) {
90
91         double delta = 0.5 * scale;
92         int index = series % SHAPE_COUNT;
93         int[] xpoints = null;
94         int[] ypoints = null;
95         switch (index) {
96         case 0:
97             // Square
98
return new Rectangle2D.Double JavaDoc(x - delta, y - delta, scale, scale);
99         case 1:
100             // Circle
101
return new Ellipse2D.Double JavaDoc(x - delta, y - delta, scale, scale);
102         case 2:
103             // Up-pointing triangle
104
xpoints = intArray(x, x + delta, x - delta);
105             ypoints = intArray(y - delta, y + delta, y + delta);
106             return new Polygon JavaDoc(xpoints, ypoints, 3);
107         case 3:
108             // Diamond
109
xpoints = intArray(x, x + delta, x, x - delta);
110             ypoints = intArray(y - delta, y, y + delta, y);
111             return new Polygon JavaDoc(xpoints, ypoints, 4);
112         case 4:
113             // Horizontal rectangle
114
return new Rectangle2D.Double JavaDoc(x - delta, y - delta / 2, scale, scale / 2);
115         case 5:
116             // Down-pointing triangle
117
xpoints = intArray(x - delta, x + delta, x);
118             ypoints = intArray(y - delta, y - delta, y + delta);
119             return new Polygon JavaDoc(xpoints, ypoints, 3);
120         case 6:
121             // Horizontal ellipse
122
return new Ellipse2D.Double JavaDoc(x - delta, y - delta / 2, scale, scale / 2);
123         case 7:
124             // Right-pointing triangle
125
xpoints = intArray(x - delta, x + delta, x - delta);
126             ypoints = intArray(y - delta, y, y + delta);
127             return new Polygon JavaDoc(xpoints, ypoints, 3);
128         case 8:
129             // Vertical rectangle
130
return new Rectangle2D.Double JavaDoc(x - delta / 2, y - delta, scale / 2, scale);
131         case 9:
132             // Left-pointing triangle
133
xpoints = intArray(x - delta, x + delta, x + delta);
134             ypoints = intArray(y, y - delta, y + delta);
135             return new Polygon JavaDoc(xpoints, ypoints, 3);
136         default:
137             // Vertical ellipse
138
return new Ellipse2D.Double JavaDoc(x - delta / 2, y - delta, scale / 2, scale);
139         }
140
141     }
142
143     /**
144      * Helper method to avoid lots of explicit casts in getShape(). Returns
145      * an array containing the provided doubles cast to ints.
146      *
147      * @param a x
148      * @param b y
149      * @param c z
150      *
151      * @return int[3] with converted params.
152      */

153     private static int[] intArray(double a, double b, double c) {
154         return new int[] {(int) a, (int) b, (int) c};
155     }
156
157     /**
158      * Helper method to avoid lots of explicit casts in getShape(). Returns
159      * an array containing the provided doubles cast to ints.
160      *
161      * @param a x
162      * @param b y
163      * @param c z
164      * @param d t
165      *
166      * @return int[3] with converted params.
167      */

168     private static int[] intArray(double a, double b, double c, double d) {
169         return new int[] {(int) a, (int) b, (int) c, (int) d};
170     }
171
172 }
173
Popular Tags