linerenderer3d.java
来自「JfreeChart 常用图表例子」· Java 代码 · 共 614 行 · 第 1/2 页
JAVA
614 行
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * ------------------- * LineRenderer3D.java * ------------------- * (C) Copyright 2004, 2005, by Tobias Selb and Contributors. * * Original Author: Tobias Selb; * Contributor(s): David Gilbert (for Object Refinery Limited); * * $Id: LineRenderer3D.java,v 1.10 2005/05/19 14:01:46 mungady Exp $ * * Changes * ------- * 15-Oct-2004 : Version 1 (TS); * 05-Nov-2004 : Modified drawItem() signature (DG); * 11-Nov-2004 : Now uses ShapeUtilities class to translate shapes (DG); * 26-Jan-2005 : Update for changes in super class (DG); * 13-Apr-2005 : Check item visibility in drawItem() method (DG); * */package org.jfree.chart.renderer.category;import java.awt.AlphaComposite;import java.awt.Color;import java.awt.Composite;import java.awt.Graphics2D;import java.awt.Image;import java.awt.Paint;import java.awt.Shape;import java.awt.Stroke;import java.awt.geom.GeneralPath;import java.awt.geom.Line2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import org.jfree.chart.Effect3D;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.entity.CategoryItemEntity;import org.jfree.chart.entity.EntityCollection;import org.jfree.chart.event.RendererChangeEvent;import org.jfree.chart.labels.CategoryToolTipGenerator;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.Marker;import org.jfree.chart.plot.Plot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.plot.ValueMarker;import org.jfree.data.Range;import org.jfree.data.category.CategoryDataset;import org.jfree.util.ShapeUtilities;/** * A line renderer with a 3D effect. * * @author Tobias Selb (http://www.uepselon.com) */public class LineRenderer3D extends LineAndShapeRenderer implements Effect3D, Serializable { /** For serialization. */ private static final long serialVersionUID = 5467931468380928736L; /** The default x-offset for the 3D effect. */ public static final double DEFAULT_X_OFFSET = 12.0; /** The default y-offset for the 3D effect. */ public static final double DEFAULT_Y_OFFSET = 8.0; /** The default wall paint. */ public static final Paint DEFAULT_WALL_PAINT = new Color(0xDD, 0xDD, 0xDD); /** The size of x-offset for the 3D effect. */ private double xOffset; /** The size of y-offset for the 3D effect. */ private double yOffset; /** The paint used to shade the left and lower 3D wall. */ private transient Paint wallPaint; /** * Creates a new renderer. */ public LineRenderer3D() { super(true, false); //Create a line renderer only this.xOffset = DEFAULT_X_OFFSET; this.yOffset = DEFAULT_Y_OFFSET; this.wallPaint = DEFAULT_WALL_PAINT; } /** * Returns the x-offset for the 3D effect. * * @return The x-offset. */ public double getXOffset() { return this.xOffset; } /** * Returns the y-offset for the 3D effect. * * @return The y-offset. */ public double getYOffset() { return this.yOffset; } /** * Sets the x-offset. * * @param xOffset the x-offset. */ public void setxOffset(double xOffset) { this.xOffset = xOffset; notifyListeners(new RendererChangeEvent(this)); } /** * Sets the y-offset. * * @param yOffset the y-offset. */ public void setyOffset(double yOffset) { this.yOffset = yOffset; notifyListeners(new RendererChangeEvent(this)); } /** * Returns the paint used to highlight the left and bottom wall in the plot * background. * * @return The paint. */ public Paint getWallPaint() { return this.wallPaint; } /** * Sets the paint used to hightlight the left and bottom walls in the plot * background. * * @param paint the paint. */ public void setWallPaint(Paint paint) { this.wallPaint = paint; notifyListeners(new RendererChangeEvent(this)); } /** * Draws the background for the plot. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the area inside the axes. */ public void drawBackground(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) { float x0 = (float) dataArea.getX(); float x1 = x0 + (float) Math.abs(this.xOffset); float x3 = (float) dataArea.getMaxX(); float x2 = x3 - (float) Math.abs(this.xOffset); float y0 = (float) dataArea.getMaxY(); float y1 = y0 - (float) Math.abs(this.yOffset); float y3 = (float) dataArea.getMinY(); float y2 = y3 + (float) Math.abs(this.yOffset); GeneralPath clip = new GeneralPath(); clip.moveTo(x0, y0); clip.lineTo(x0, y2); clip.lineTo(x1, y3); clip.lineTo(x3, y3); clip.lineTo(x3, y1); clip.lineTo(x2, y0); clip.closePath(); // fill background... Paint backgroundPaint = plot.getBackgroundPaint(); if (backgroundPaint != null) { g2.setPaint(backgroundPaint); g2.fill(clip); } GeneralPath leftWall = new GeneralPath(); leftWall.moveTo(x0, y0); leftWall.lineTo(x0, y2); leftWall.lineTo(x1, y3); leftWall.lineTo(x1, y1); leftWall.closePath(); g2.setPaint(getWallPaint()); g2.fill(leftWall); GeneralPath bottomWall = new GeneralPath(); bottomWall.moveTo(x0, y0); bottomWall.lineTo(x1, y1); bottomWall.lineTo(x3, y1); bottomWall.lineTo(x2, y0); bottomWall.closePath(); g2.setPaint(getWallPaint()); g2.fill(bottomWall); // higlight the background corners... g2.setPaint(Color.lightGray); Line2D corner = new Line2D.Double(x0, y0, x1, y1); g2.draw(corner); corner.setLine(x1, y1, x1, y3); g2.draw(corner); corner.setLine(x1, y1, x3, y1); g2.draw(corner); // draw background image, if there is one... Image backgroundImage = plot.getBackgroundImage(); if (backgroundImage != null) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC, plot.getBackgroundAlpha()) ); g2.drawImage( backgroundImage, (int) x1, (int) y3, (int) (x3 - x1 + 1), (int) (y1 - y3 + 1), null ); g2.setComposite(originalComposite); } } /** * Draws the outline for the plot. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the area inside the axes. */ public void drawOutline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea) { float x0 = (float) dataArea.getX(); float x1 = x0 + (float) Math.abs(this.xOffset); float x3 = (float) dataArea.getMaxX(); float x2 = x3 - (float) Math.abs(this.xOffset); float y0 = (float) dataArea.getMaxY(); float y1 = y0 - (float) Math.abs(this.yOffset); float y3 = (float) dataArea.getMinY(); float y2 = y3 + (float) Math.abs(this.yOffset); GeneralPath clip = new GeneralPath(); clip.moveTo(x0, y0); clip.lineTo(x0, y2); clip.lineTo(x1, y3); clip.lineTo(x3, y3); clip.lineTo(x3, y1); clip.lineTo(x2, y0); clip.closePath(); // put an outline around the data area... Stroke outlineStroke = plot.getOutlineStroke(); Paint outlinePaint = plot.getOutlinePaint(); if ((outlineStroke != null) && (outlinePaint != null)) { g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(clip); } } /** * Draws a grid line against the domain axis. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the area for plotting data (not yet adjusted for any * 3D effect). * @param value the Java2D value at which the grid line should be drawn. * */ public void drawDomainGridline(Graphics2D g2, CategoryPlot plot,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?