KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > renderer > xy > XYLine3DRenderer


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, 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  * XYLine3DRenderer.java
29  * ---------------------
30  * (C) Copyright 2005, by Object Refinery Limited.
31  *
32  * Original Author: Thomas Morgner;
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * $Id: XYLine3DRenderer.java,v 1.4.2.1 2005/10/25 20:56:21 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 14-Jan-2005 : Added standard header (DG);
40  */

41
42 package org.jfree.chart.renderer.xy;
43
44 import java.awt.Color JavaDoc;
45 import java.awt.Graphics2D JavaDoc;
46 import java.awt.Paint JavaDoc;
47 import java.awt.Shape JavaDoc;
48 import java.io.Serializable JavaDoc;
49
50 import org.jfree.chart.Effect3D;
51 import org.jfree.chart.event.RendererChangeEvent;
52
53 /**
54  * A XYLineAndShapeRenderer that adds a shadow line to the graph
55  * to emulate a 3D-effect.
56  */

57 public class XYLine3DRenderer extends XYLineAndShapeRenderer
58                               implements Effect3D, Serializable JavaDoc {
59
60     /** For serialization. */
61     private static final long serialVersionUID = 588933208243446087L;
62     
63     /** The default x-offset for the 3D effect. */
64     public static final double DEFAULT_X_OFFSET = 12.0;
65
66     /** The default y-offset for the 3D effect. */
67     public static final double DEFAULT_Y_OFFSET = 8.0;
68
69     /** The default wall paint. */
70     public static final Paint JavaDoc DEFAULT_WALL_PAINT = new Color JavaDoc(0xDD, 0xDD, 0xDD);
71
72     /** The size of x-offset for the 3D effect. */
73     private double xOffset;
74
75     /** The size of y-offset for the 3D effect. */
76     private double yOffset;
77
78     /** The paint used to shade the left and lower 3D wall. */
79     private transient Paint JavaDoc wallPaint;
80
81     /**
82      * Creates a new renderer.
83      */

84     public XYLine3DRenderer() {
85         this.wallPaint = DEFAULT_WALL_PAINT;
86         this.xOffset = DEFAULT_X_OFFSET;
87         this.yOffset = DEFAULT_Y_OFFSET;
88     }
89
90     /**
91      * Returns the x-offset for the 3D effect.
92      *
93      * @return The 3D effect.
94      */

95     public double getXOffset() {
96         return this.xOffset;
97     }
98
99     /**
100      * Returns the y-offset for the 3D effect.
101      *
102      * @return The 3D effect.
103      */

104     public double getYOffset() {
105         return this.yOffset;
106     }
107
108     /**
109      * Sets the x-offset and sends a {@link RendererChangeEvent} to all
110      * registered listeners.
111      *
112      * @param xOffset the x-offset.
113      */

114     public void setXOffset(double xOffset) {
115         this.xOffset = xOffset;
116         notifyListeners(new RendererChangeEvent(this));
117     }
118
119     /**
120      * Sets the y-offset and sends a {@link RendererChangeEvent} to all
121      * registered listeners.
122      *
123      * @param yOffset the y-offset.
124      */

125     public void setYOffset(double yOffset) {
126         this.yOffset = yOffset;
127         notifyListeners(new RendererChangeEvent(this));
128     }
129
130     /**
131      * Returns the paint used to highlight the left and bottom wall in the plot
132      * background.
133      *
134      * @return The paint.
135      */

136     public Paint JavaDoc getWallPaint() {
137         return this.wallPaint;
138     }
139
140     /**
141      * Sets the paint used to hightlight the left and bottom walls in the plot
142      * background.
143      *
144      * @param paint the paint.
145      */

146     public void setWallPaint(Paint JavaDoc paint) {
147         this.wallPaint = paint;
148         notifyListeners(new RendererChangeEvent(this));
149     }
150
151     /**
152      * Returns the number of passes through the data that the renderer requires
153      * in order to draw the chart. Most charts will require a single pass,
154      * but some require two passes.
155      *
156      * @return The pass count.
157      */

158     public int getPassCount() {
159         return 3;
160     }
161
162     /**
163      * Returns <code>true</code> if the specified pass involves drawing lines.
164      *
165      * @param pass the pass.
166      *
167      * @return A boolean.
168      */

169     protected boolean isLinePass(int pass) {
170         return pass == 0 || pass == 1;
171     }
172
173     /**
174      * Returns <code>true</code> if the specified pass involves drawing items.
175      *
176      * @param pass the pass.
177      *
178      * @return A boolean.
179      */

180     protected boolean isItemPass(int pass) {
181         return pass == 2;
182     }
183
184     /**
185      * Returns <code>true</code> if the specified pass involves drawing shadows.
186      *
187      * @param pass the pass.
188      *
189      * @return A boolean.
190      */

191     protected boolean isShadowPass (int pass) {
192         return pass == 0;
193     }
194
195     /**
196      * Overrides the method in the subclass to draw a shadow in the first pass.
197      *
198      * @param g2 the graphics device.
199      * @param pass the pass.
200      * @param series the series index (zero-based).
201      * @param item the item index (zero-based).
202      * @param shape the shape.
203      */

204     protected void drawFirstPassShape(Graphics2D JavaDoc g2,
205                                       int pass,
206                                       int series,
207                                       int item,
208                                       Shape JavaDoc shape) {
209         if (isShadowPass(pass)) {
210             if (getWallPaint() != null) {
211                 g2.setStroke(getItemStroke(series, item));
212                 g2.setPaint(getWallPaint());
213                 g2.translate(getXOffset(), getYOffset());
214                 g2.draw(shape);
215                 g2.translate(-getXOffset(), -getYOffset());
216             }
217         }
218         else {
219             // now draw the real shape
220
super.drawFirstPassShape(g2, pass, series, item, shape);
221         }
222     }
223
224 }
225
Popular Tags