Source for org.jfree.chart.axis.NumberAxis3D

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