Frames | No Frames |
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: * NumberAxis3D.java 29: * ----------------- 30: * (C) Copyright 2001-2006, by Serge V. Grachov and Contributors. 31: * 32: * Original Author: Serge V. Grachov; 33: * Contributor(s): David Gilbert (for Object Refinery Limited); 34: * Jonathan Nash; 35: * Richard Atkinson; 36: * Tin Luu; 37: * 38: * $Id: NumberAxis3D.java,v 1.5.2.2 2006/01/18 11:03:02 mungady Exp $ 39: * 40: * Changes 41: * ------- 42: * 31-Oct-2001 : Version 1 contributed by Serge V. Grachov (DG); 43: * 23-Nov-2001 : Overhauled auto tick unit code for all axes (DG); 44: * 12-Dec-2001 : Minor change due to grid lines bug fix (DG); 45: * 08-Jan-2002 : Added flag allowing the axis to be 'inverted'. That is, run 46: * from positive to negative. Added default values to 47: * constructors (DG); 48: * 16-Jan-2002 : Added an optional crosshair, based on the implementation by 49: * Jonathan Nash (DG); 50: * 25-Feb-2002 : Updated constructors for new autoRangeStickyZero flag (DG); 51: * 19-Apr-2002 : drawVerticalString() is now drawRotatedString() in 52: * RefineryUtilities (DG); 53: * 25-Jun-2002 : Removed redundant import (DG); 54: * 25-Jul-2002 : Changed order of parameters in ValueAxis constructor (DG); 55: * 06-Aug-2002 : Modified draw method to not draw axis label if label is empty 56: * String (RA); 57: * 05-Sep-2002 : Updated constructor for changes in the Axis class, and changed 58: * draw method to observe tickMarkPaint (DG); 59: * 22-Sep-2002 : Fixed errors reported by Checkstyle (DG); 60: * 08-Nov-2002 : Moved to new package com.jrefinery.chart.axis (DG); 61: * 20-Jan-2003 : Removed unnecessary constructors (DG); 62: * 26-Mar-2003 : Implemented Serializable (DG); 63: * 13-May-2003 : Merged HorizontalNumberAxis3D and VerticalNumberAxis3D (DG); 64: * 21-Aug-2003 : Updated draw() method signature (DG); 65: * 07-Nov-2003 : Modified refreshTicks method signature (DG); 66: * 18-Jan-2006 : Fixed bug 1408904 (axis assumes CategoryPlot) (DG): 67: * 68: */ 69: 70: package org.jfree.chart.axis; 71: 72: import java.awt.Graphics2D; 73: import java.awt.geom.Rectangle2D; 74: import java.io.Serializable; 75: import java.util.List; 76: 77: import org.jfree.chart.Effect3D; 78: import org.jfree.chart.plot.CategoryPlot; 79: import org.jfree.chart.plot.Plot; 80: import org.jfree.chart.plot.PlotRenderingInfo; 81: import org.jfree.chart.renderer.category.CategoryItemRenderer; 82: import org.jfree.ui.RectangleEdge; 83: 84: /** 85: * A standard linear value axis with a 3D effect corresponding to the 86: * offset specified by some renderers. 87: */ 88: public class NumberAxis3D extends NumberAxis implements Serializable { 89: 90: /** For serialization. */ 91: private static final long serialVersionUID = -1790205852569123512L; 92: 93: /** 94: * Default constructor. 95: */ 96: public NumberAxis3D() { 97: this(null); 98: } 99: 100: /** 101: * Constructs a new axis. 102: * 103: * @param label the axis label (<code>null</code> permitted). 104: */ 105: public NumberAxis3D(String label) { 106: super(label); 107: setAxisLineVisible(false); 108: } 109: 110: /** 111: * Draws the axis on a Java 2D graphics device (such as the screen or a 112: * printer). 113: * 114: * @param g2 the graphics device. 115: * @param cursor the cursor. 116: * @param plotArea the area for drawing the axes and data. 117: * @param dataArea the area for drawing the data (a subset of the 118: * plotArea). 119: * @param edge the axis location. 120: * @param plotState collects information about the plot (<code>null</code> 121: * permitted). 122: * 123: * @return The updated cursor value. 124: */ 125: public AxisState draw(Graphics2D g2, double cursor, Rectangle2D plotArea, 126: Rectangle2D dataArea, 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 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: double xOffset = 0.0; 141: double yOffset = 0.0; 142: Plot plot = getPlot(); 143: if (plot instanceof CategoryPlot) { 144: CategoryPlot cp = (CategoryPlot) plot; 145: CategoryItemRenderer r = cp.getRenderer(); 146: if (r instanceof Effect3D) { 147: Effect3D e3D = (Effect3D) r; 148: xOffset = e3D.getXOffset(); 149: yOffset = e3D.getYOffset(); 150: } 151: } 152: 153: double adjustedX = dataArea.getMinX(); 154: double adjustedY = dataArea.getMinY(); 155: double adjustedW = dataArea.getWidth() - xOffset; 156: double adjustedH = dataArea.getHeight() - yOffset; 157: 158: if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) { 159: adjustedY += yOffset; 160: } 161: else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) { 162: adjustedX += xOffset; 163: } 164: Rectangle2D adjustedDataArea = new Rectangle2D.Double(adjustedX, 165: adjustedY, adjustedW, adjustedH); 166: 167: // draw the tick marks and labels... 168: AxisState info = drawTickMarksAndLabels(g2, cursor, plotArea, 169: adjustedDataArea, edge); 170: 171: // draw the axis label... 172: info = drawLabel(getLabel(), g2, plotArea, dataArea, edge, info); 173: 174: return info; 175: 176: } 177: 178: }