KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > axis > NumberAxis3D


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -----------------
27  * NumberAxis3D.java
28  * -----------------
29  * (C) Copyright 2001-2004, by Serge V. Grachov and Contributors.
30  *
31  * Original Author: Serge V. Grachov;
32  * Contributor(s): David Gilbert (for Object Refinery Limited);
33  * Jonathan Nash;
34  * Richard Atkinson;
35  * Tin Luu;
36  *
37  * $Id: NumberAxis3D.java,v 1.5 2005/05/19 13:58:11 mungady Exp $
38  *
39  * Changes
40  * -------
41  * 31-Oct-2001 : Version 1 contributed by Serge V. Grachov (DG);
42  * 23-Nov-2001 : Overhauled auto tick unit code for all axes (DG);
43  * 12-Dec-2001 : Minor change due to grid lines bug fix (DG);
44  * 08-Jan-2002 : Added flag allowing the axis to be 'inverted'. That is, run
45  * from positive to negative. Added default values to
46  * constructors (DG);
47  * 16-Jan-2002 : Added an optional crosshair, based on the implementation by
48  * Jonathan Nash (DG);
49  * 25-Feb-2002 : Updated constructors for new autoRangeStickyZero flag (DG);
50  * 19-Apr-2002 : drawVerticalString() is now drawRotatedString() in
51  * RefineryUtilities (DG);
52  * 25-Jun-2002 : Removed redundant import (DG);
53  * 25-Jul-2002 : Changed order of parameters in ValueAxis constructor (DG);
54  * 06-Aug-2002 : Modified draw method to not draw axis label if label is empty
55  * String (RA);
56  * 05-Sep-2002 : Updated constructor for changes in the Axis class, and changed
57  * draw method to observe tickMarkPaint (DG);
58  * 22-Sep-2002 : Fixed errors reported by Checkstyle (DG);
59  * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG);
60  * 20-Jan-2003 : Removed unnecessary constructors (DG);
61  * 26-Mar-2003 : Implemented Serializable (DG);
62  * 13-May-2003 : Merged HorizontalNumberAxis3D and VerticalNumberAxis3D (DG);
63  * 21-Aug-2003 : Updated draw() method signature (DG);
64  * 07-Nov-2003 : Modified refreshTicks method signature (DG);
65  *
66  */

67
68 package org.jfree.chart.axis;
69
70 import java.awt.Graphics2D JavaDoc;
71 import java.awt.geom.Rectangle2D JavaDoc;
72 import java.io.Serializable JavaDoc;
73 import java.util.List JavaDoc;
74
75 import org.jfree.chart.Effect3D;
76 import org.jfree.chart.plot.CategoryPlot;
77 import org.jfree.chart.plot.PlotRenderingInfo;
78 import org.jfree.ui.RectangleEdge;
79
80 /**
81  * A standard linear value axis, for values displayed vertically.
82  *
83  * @author Serge V. Grachov
84  */

85 public class NumberAxis3D extends NumberAxis implements Serializable JavaDoc {
86
87     /** For serialization. */
88     private static final long serialVersionUID = -1790205852569123512L;
89     
90     /**
91      * Default constructor.
92      */

93     public NumberAxis3D() {
94         this(null);
95     }
96     
97     /**
98      * Constructs a new axis.
99      *
100      * @param label the axis label (<code>null</code> permitted).
101      */

102     public NumberAxis3D(String JavaDoc label) {
103         super(label);
104         setAxisLineVisible(false);
105     }
106
107     /**
108      * Draws the axis on a Java 2D graphics device (such as the screen or a
109      * printer).
110      *
111      * @param g2 the graphics device.
112      * @param cursor the cursor.
113      * @param plotArea the area for drawing the axes and data.
114      * @param dataArea the area for drawing the data (a subset of the
115      * plotArea).
116      * @param edge the axis location.
117      * @param plotState collects information about the plot (<code>null</code>
118      * permitted).
119      *
120      * @return The updated cursor value.
121      */

122     public AxisState draw(Graphics2D JavaDoc g2,
123                           double cursor,
124                           Rectangle2D JavaDoc plotArea,
125                           Rectangle2D JavaDoc dataArea,
126                           RectangleEdge edge,
127                           PlotRenderingInfo plotState) {
128
129         // if the axis is not visible, don't draw it...
130
if (!isVisible()) {
131             AxisState state = new AxisState(cursor);
132             // even though the axis is not visible, we need ticks for the
133
// gridlines...
134
List JavaDoc ticks = refreshTicks(g2, state, dataArea, edge);
135             state.setTicks(ticks);
136             return state;
137         }
138
139         // calculate the adjusted data area taking into account the 3D effect...
140
CategoryPlot plot = (CategoryPlot) getPlot();
141
142         Effect3D e3D = (Effect3D) plot.getRenderer();
143         double adjustedX = dataArea.getMinX();
144         double adjustedY = dataArea.getMinY();
145         double adjustedW = dataArea.getWidth() - e3D.getXOffset();
146         double adjustedH = dataArea.getHeight() - e3D.getYOffset();
147
148         if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
149             adjustedY += e3D.getYOffset();
150         }
151         else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
152             adjustedX += e3D.getXOffset();
153         }
154         Rectangle2D JavaDoc adjustedDataArea = new Rectangle2D.Double JavaDoc(
155             adjustedX, adjustedY, adjustedW, adjustedH
156         );
157
158         // draw the tick marks and labels...
159
AxisState info = drawTickMarksAndLabels(
160             g2, cursor, plotArea, adjustedDataArea, edge
161         );
162        
163         // draw the axis label...
164
info = drawLabel(getLabel(), g2, plotArea, dataArea, edge, info);
165
166         return info;
167         
168     }
169
170 }
171
Popular Tags