file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
DefaultShadowGenerator.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/util/DefaultShadowGenerator.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * DefaultShadowGenerator.java * --------------------------- * (C) Copyright 2009, 2011 by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 10-Jul-2009 : Version 1 (DG); * 29-Oct-2011 : Fixed Eclipse warnings (DG); * */ package org.jfree.chart.util; import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.io.Serializable; import org.jfree.chart.HashUtilities; /** * A default implementation of the {@link ShadowGenerator} interface, based on * code in a * <a href="http://www.jroller.com/gfx/entry/fast_or_good_drop_shadows">blog * post by Romain Guy</a>. * * @since 1.0.14 */ public class DefaultShadowGenerator implements ShadowGenerator, Serializable { private static final long serialVersionUID = 2732993885591386064L; /** The shadow size. */ private int shadowSize; /** The shadow color. */ private Color shadowColor; /** The shadow opacity. */ private float shadowOpacity; /** The shadow offset angle (in radians). */ private double angle; /** The shadow offset distance (in Java2D units). */ private int distance; /** * Creates a new instance with default attributes. */ public DefaultShadowGenerator() { this(5, Color.BLACK, 0.5f, 5, -Math.PI / 4); } /** * Creates a new instance with the specified attributes. * * @param size the shadow size. * @param color the shadow color. * @param opacity the shadow opacity. * @param distance the shadow offset distance. * @param angle the shadow offset angle (in radians). */ public DefaultShadowGenerator(int size, Color color, float opacity, int distance, double angle) { if (color == null) { throw new IllegalArgumentException("Null 'color' argument."); } this.shadowSize = size; this.shadowColor = color; this.shadowOpacity = opacity; this.distance = distance; this.angle = angle; } /** * Returns the shadow size. * * @return The shadow size. */ public int getShadowSize() { return this.shadowSize; } /** * Returns the shadow color. * * @return The shadow color (never <code>null</code>). */ public Color getShadowColor() { return this.shadowColor; } /** * Returns the shadow opacity. * * @return The shadow opacity. */ public float getShadowOpacity() { return this.shadowOpacity; } /** * Returns the shadow offset distance. * * @return The shadow offset distance (in Java2D units). */ public int getDistance() { return this.distance; } /** * Returns the shadow offset angle (in radians). * * @return The angle (in radians). */ public double getAngle() { return this.angle; } /** * Calculates the x-offset for drawing the shadow image relative to the * source. * * @return The x-offset. */ @Override public int calculateOffsetX() { return (int) (Math.cos(this.angle) * this.distance) - this.shadowSize; } /** * Calculates the y-offset for drawing the shadow image relative to the * source. * * @return The y-offset. */ @Override public int calculateOffsetY() { return -(int) (Math.sin(this.angle) * this.distance) - this.shadowSize; } /** * Creates and returns an image containing the drop shadow for the * specified source image. * * @param source the source image. * * @return A new image containing the shadow. */ @Override public BufferedImage createDropShadow(BufferedImage source) { BufferedImage subject = new BufferedImage( source.getWidth() + this.shadowSize * 2, source.getHeight() + this.shadowSize * 2, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = subject.createGraphics(); g2.drawImage(source, null, this.shadowSize, this.shadowSize); g2.dispose(); applyShadow(subject); return subject; } /** * Applies a shadow to the image. * * @param image the image. */ protected void applyShadow(BufferedImage image) { int dstWidth = image.getWidth(); int dstHeight = image.getHeight(); int left = (this.shadowSize - 1) >> 1; int right = this.shadowSize - left; int xStart = left; int xStop = dstWidth - right; int yStart = left; int yStop = dstHeight - right; int shadowRgb = this.shadowColor.getRGB() & 0x00FFFFFF; int[] aHistory = new int[this.shadowSize]; int historyIdx = 0; int aSum; int[] dataBuffer = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); int lastPixelOffset = right * dstWidth; float sumDivider = this.shadowOpacity / this.shadowSize; // horizontal pass for (int y = 0, bufferOffset = 0; y < dstHeight; y++, bufferOffset = y * dstWidth) { aSum = 0; historyIdx = 0; for (int x = 0; x < this.shadowSize; x++, bufferOffset++) { int a = dataBuffer[bufferOffset] >>> 24; aHistory[x] = a; aSum += a; } bufferOffset -= right; for (int x = xStart; x < xStop; x++, bufferOffset++) { int a = (int) (aSum * sumDivider); dataBuffer[bufferOffset] = a << 24 | shadowRgb; // substract the oldest pixel from the sum aSum -= aHistory[historyIdx]; // get the lastest pixel a = dataBuffer[bufferOffset + right] >>> 24; aHistory[historyIdx] = a; aSum += a; if (++historyIdx >= this.shadowSize) { historyIdx -= this.shadowSize; } } } // vertical pass for (int x = 0, bufferOffset = 0; x < dstWidth; x++, bufferOffset = x) { aSum = 0; historyIdx = 0; for (int y = 0; y < this.shadowSize; y++, bufferOffset += dstWidth) { int a = dataBuffer[bufferOffset] >>> 24; aHistory[y] = a; aSum += a; } bufferOffset -= lastPixelOffset; for (int y = yStart; y < yStop; y++, bufferOffset += dstWidth) { int a = (int) (aSum * sumDivider); dataBuffer[bufferOffset] = a << 24 | shadowRgb; // substract the oldest pixel from the sum aSum -= aHistory[historyIdx]; // get the lastest pixel a = dataBuffer[bufferOffset + lastPixelOffset] >>> 24; aHistory[historyIdx] = a; aSum += a; if (++historyIdx >= this.shadowSize) { historyIdx -= this.shadowSize; } } } } /** * Tests this object for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return The object. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DefaultShadowGenerator)) { return false; } DefaultShadowGenerator that = (DefaultShadowGenerator) obj; if (this.shadowSize != that.shadowSize) { return false; } if (!this.shadowColor.equals(that.shadowColor)) { return false; } if (this.shadowOpacity != that.shadowOpacity) { return false; } if (this.distance != that.distance) { return false; } if (this.angle != that.angle) { return false; } return true; } /** * Returns a hash code for this instance. * * @return The hash code. */ @Override public int hashCode() { int hash = HashUtilities.hashCode(17, this.shadowSize); hash = HashUtilities.hashCode(hash, this.shadowColor); hash = HashUtilities.hashCode(hash, this.shadowOpacity); hash = HashUtilities.hashCode(hash, this.distance); hash = HashUtilities.hashCode(hash, this.angle); return hash; } }
9,909
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ArrayUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/util/ArrayUtilities.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * ArrayUtilities.java * ------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * $Id: ArrayUtilities.java,v 1.7 2008/09/10 09:21:30 mungady Exp $ * * Changes * ------- * 21-Aug-2003 : Version 1 (DG); * 04-Oct-2004 : Renamed ArrayUtils --> ArrayUtilities (DG); * 16-Jun-2012 : Moved from JCommon to JFreeChart (DG); * */ package org.jfree.chart.util; import java.util.Arrays; /** * Utility methods for working with arrays. */ public class ArrayUtilities { /** * Private constructor prevents object creation. */ private ArrayUtilities() { } /** * Clones a two dimensional array of floats. * * @param array the array. * * @return A clone of the array. */ public static float[][] clone(final float[][] array) { if (array == null) { return null; } final float[][] result = new float[array.length][]; System.arraycopy(array, 0, result, 0, array.length); for (int i = 0; i < array.length; i++) { final float[] child = array[i]; final float[] copychild = new float[child.length]; System.arraycopy(child, 0, copychild, 0, child.length); result[i] = copychild; } return result; } /** * Returns <code>true</code> if all the references in <code>array1</code> * are equal to all the references in <code>array2</code> (two * <code>null</code> references are considered equal for this test). * * @param array1 the first array (<code>null</code> permitted). * @param array2 the second array (<code>null</code> permitted). * * @return A boolean. */ public static boolean equalReferencesInArrays(final Object[] array1, final Object[] array2) { if (array1 == null) { return (array2 == null); } if (array2 == null) { return false; } if (array1.length != array2.length) { return false; } for (int i = 0; i < array1.length; i++) { if (array1[i] == null) { if (array2[i] != null) { return false; } } if (array2[i] == null) { if (array1[i] != null) { return false; } } if (array1[i] != array2[i]) { return false; } } return true; } /** * Tests two float arrays for equality. * * @param array1 the first array (<code>null</code> permitted). * @param array2 the second arrray (<code>null</code> permitted). * * @return A boolean. */ public static boolean equal(final float[][] array1, final float[][] array2) { if (array1 == null) { return (array2 == null); } if (array2 == null) { return false; } if (array1.length != array2.length) { return false; } for (int i = 0; i < array1.length; i++) { if (!Arrays.equals(array1[i], array2[i])) { return false; } } return true; } /** * Returns <code>true</code> if any two items in the array are equal to * one another. Any <code>null</code> values in the array are ignored. * * @param array the array to check. * * @return A boolean. */ public static boolean hasDuplicateItems(final Object[] array) { for (int i = 0; i < array.length; i++) { for (int j = 0; j < i; j++) { final Object o1 = array[i]; final Object o2 = array[j]; if (o1 != null && o2 != null) { if (o1.equals(o2)) { return true; } } } } return false; } /** * Compares the initial elements of two arrays. * * @param a1 array 1. * @param a2 array 2. * * @return An integer showing the relative ordering. */ public static int compareVersionArrays (Comparable[] a1, Comparable[] a2) { int length = Math.min (a1.length, a2.length); for (int i = 0; i < length; i++) { Comparable o1 = a1[i]; Comparable o2 = a2[i]; if (o1 == null && o2 == null) { // cannot decide .. continue; } if (o1 == null) { return 1; } if (o2 == null) { return -1; } int retval = o1.compareTo(o2); if (retval != 0) { return retval; } } return 0; } }
6,189
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StringUtils.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/util/StringUtils.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * StringUtils.java * ---------------- * (C)opyright 2003-2012, by Thomas Morgner and Contributors. * * Original Author: Thomas Morgner; * Contributor(s): David Gilbert (for Object Refinery Limited); * * $Id: StringUtils.java,v 1.5 2005/10/18 13:24:19 mungady Exp $ * * Changes * ------------------------- * 21-Jun-2003 : Initial version (TM); * 17-Jun-2012 : Moved from JCommon to JFreeChart (DG); * */ package org.jfree.chart.util; /** * String utilities. */ public class StringUtils { /** * Private constructor prevents object creation. */ private StringUtils() { } /** * Helper functions to query a strings start portion. The comparison is case insensitive. * * @param base the base string. * @param start the starting text. * * @return true, if the string starts with the given starting text. */ public static boolean startsWithIgnoreCase(final String base, final String start) { if (base.length() < start.length()) { return false; } return base.regionMatches(true, 0, start, 0, start.length()); } /** * Helper functions to query a strings end portion. The comparison is case insensitive. * * @param base the base string. * @param end the ending text. * * @return true, if the string ends with the given ending text. */ public static boolean endsWithIgnoreCase(final String base, final String end) { if (base.length() < end.length()) { return false; } return base.regionMatches(true, base.length() - end.length(), end, 0, end.length()); } /** * Queries the system properties for the line separator. If access * to the System properties is forbidden, the UNIX default is returned. * * @return the line separator. */ public static String getLineSeparator() { try { return System.getProperty("line.separator", "\n"); } catch (Exception e) { return "\n"; } } }
3,319
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SerialUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/util/SerialUtilities.java
/* ======================================================================== * JCommon : a free general purpose class library for the Java(tm) platform * ======================================================================== * * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jcommon/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Java is a trademark or registered trademark of Sun Microsystems, Inc. * in the United States and other countries.] * * -------------------- * SerialUtilities.java * -------------------- * (C) Copyright 2000-2005, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Arik Levin; * * $Id: SerialUtilities.java,v 1.15 2011/10/11 12:45:02 matinh Exp $ * * Changes * ------- * 25-Mar-2003 : Version 1 (DG); * 18-Sep-2003 : Added capability to serialize GradientPaint (DG); * 26-Apr-2004 : Added read/writePoint2D() methods (DG); * 22-Feb-2005 : Added support for Arc2D - see patch 1147035 by Arik Levin (DG); * 29-Jul-2005 : Added support for AttributedString (DG); * 10-Oct-2011 : Added support for AlphaComposite instances (MH); * */ package org.jfree.chart.util; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.GradientPaint; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.Ellipse2D; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.AttributedCharacterIterator; import java.text.AttributedString; import java.text.CharacterIterator; import java.util.HashMap; import java.util.Map; /** * A class containing useful utility methods relating to serialization. * * @author David Gilbert */ public class SerialUtilities { /** * Private constructor prevents object creation. */ private SerialUtilities() { } /** * Returns <code>true</code> if a class implements <code>Serializable</code> * and <code>false</code> otherwise. * * @param c the class. * * @return A boolean. */ public static boolean isSerializable(final Class c) { /** final Class[] interfaces = c.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (interfaces[i].equals(Serializable.class)) { return true; } } Class cc = c.getSuperclass(); if (cc != null) { return isSerializable(cc); } */ return (Serializable.class.isAssignableFrom(c)); } /** * Reads a <code>Paint</code> object that has been serialised by the * {@link SerialUtilities#writePaint(Paint, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The paint object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ public static Paint readPaint(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Paint result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (isSerializable(c)) { result = (Paint) stream.readObject(); } else if (c.equals(GradientPaint.class)) { final float x1 = stream.readFloat(); final float y1 = stream.readFloat(); final Color c1 = (Color) stream.readObject(); final float x2 = stream.readFloat(); final float y2 = stream.readFloat(); final Color c2 = (Color) stream.readObject(); final boolean isCyclic = stream.readBoolean(); result = new GradientPaint(x1, y1, c1, x2, y2, c2, isCyclic); } } return result; } /** * Serialises a <code>Paint</code> object. * * @param paint the paint object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ public static void writePaint(final Paint paint, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (paint != null) { stream.writeBoolean(false); stream.writeObject(paint.getClass()); if (paint instanceof Serializable) { stream.writeObject(paint); } else if (paint instanceof GradientPaint) { final GradientPaint gp = (GradientPaint) paint; stream.writeFloat((float) gp.getPoint1().getX()); stream.writeFloat((float) gp.getPoint1().getY()); stream.writeObject(gp.getColor1()); stream.writeFloat((float) gp.getPoint2().getX()); stream.writeFloat((float) gp.getPoint2().getY()); stream.writeObject(gp.getColor2()); stream.writeBoolean(gp.isCyclic()); } } else { stream.writeBoolean(true); } } /** * Reads a <code>Stroke</code> object that has been serialised by the * {@link SerialUtilities#writeStroke(Stroke, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The stroke object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ public static Stroke readStroke(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Stroke result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (c.equals(BasicStroke.class)) { final float width = stream.readFloat(); final int cap = stream.readInt(); final int join = stream.readInt(); final float miterLimit = stream.readFloat(); final float[] dash = (float[]) stream.readObject(); final float dashPhase = stream.readFloat(); result = new BasicStroke( width, cap, join, miterLimit, dash, dashPhase ); } else { result = (Stroke) stream.readObject(); } } return result; } /** * Serialises a <code>Stroke</code> object. This code handles the * <code>BasicStroke</code> class which is the only <code>Stroke</code> * implementation provided by the JDK (and isn't directly * <code>Serializable</code>). * * @param stroke the stroke object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ public static void writeStroke(final Stroke stroke, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (stroke != null) { stream.writeBoolean(false); if (stroke instanceof BasicStroke) { final BasicStroke s = (BasicStroke) stroke; stream.writeObject(BasicStroke.class); stream.writeFloat(s.getLineWidth()); stream.writeInt(s.getEndCap()); stream.writeInt(s.getLineJoin()); stream.writeFloat(s.getMiterLimit()); stream.writeObject(s.getDashArray()); stream.writeFloat(s.getDashPhase()); } else { stream.writeObject(stroke.getClass()); stream.writeObject(stroke); } } else { stream.writeBoolean(true); } } /** * Reads a <code>Composite</code> object that has been serialised by the * {@link SerialUtilities#writeComposite(Composite, ObjectOutputStream)} * method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The composite object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. * * @since 1.0.17 */ public static Composite readComposite(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Composite result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (isSerializable(c)) { result = (Composite) stream.readObject(); } else if (c.equals(AlphaComposite.class)) { final int rule = stream.readInt(); final float alpha = stream.readFloat(); result = AlphaComposite.getInstance(rule, alpha); } } return result; } /** * Serialises a <code>Composite</code> object. * * @param composite the composite object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. * * @since 1.0.17 */ public static void writeComposite(final Composite composite, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (composite != null) { stream.writeBoolean(false); stream.writeObject(composite.getClass()); if (composite instanceof Serializable) { stream.writeObject(composite); } else if (composite instanceof AlphaComposite) { final AlphaComposite ac = (AlphaComposite) composite; stream.writeInt(ac.getRule()); stream.writeFloat(ac.getAlpha()); } } else { stream.writeBoolean(true); } } /** * Reads a <code>Shape</code> object that has been serialised by the * {@link #writeShape(Shape, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The shape object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ public static Shape readShape(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Shape result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (c.equals(Line2D.class)) { final double x1 = stream.readDouble(); final double y1 = stream.readDouble(); final double x2 = stream.readDouble(); final double y2 = stream.readDouble(); result = new Line2D.Double(x1, y1, x2, y2); } else if (c.equals(Rectangle2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); result = new Rectangle2D.Double(x, y, w, h); } else if (c.equals(Ellipse2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); result = new Ellipse2D.Double(x, y, w, h); } else if (c.equals(Arc2D.class)) { final double x = stream.readDouble(); final double y = stream.readDouble(); final double w = stream.readDouble(); final double h = stream.readDouble(); final double as = stream.readDouble(); // Angle Start final double ae = stream.readDouble(); // Angle Extent final int at = stream.readInt(); // Arc type result = new Arc2D.Double(x, y, w, h, as, ae, at); } else if (c.equals(GeneralPath.class)) { final GeneralPath gp = new GeneralPath(); final float[] args = new float[6]; boolean hasNext = stream.readBoolean(); while (!hasNext) { final int type = stream.readInt(); for (int i = 0; i < 6; i++) { args[i] = stream.readFloat(); } switch (type) { case PathIterator.SEG_MOVETO : gp.moveTo(args[0], args[1]); break; case PathIterator.SEG_LINETO : gp.lineTo(args[0], args[1]); break; case PathIterator.SEG_CUBICTO : gp.curveTo(args[0], args[1], args[2], args[3], args[4], args[5]); break; case PathIterator.SEG_QUADTO : gp.quadTo(args[0], args[1], args[2], args[3]); break; case PathIterator.SEG_CLOSE : gp.closePath(); break; default : throw new RuntimeException( "JFreeChart - No path exists"); } gp.setWindingRule(stream.readInt()); hasNext = stream.readBoolean(); } result = gp; } else { result = (Shape) stream.readObject(); } } return result; } /** * Serialises a <code>Shape</code> object. * * @param shape the shape object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ public static void writeShape(final Shape shape, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (shape != null) { stream.writeBoolean(false); if (shape instanceof Line2D) { final Line2D line = (Line2D) shape; stream.writeObject(Line2D.class); stream.writeDouble(line.getX1()); stream.writeDouble(line.getY1()); stream.writeDouble(line.getX2()); stream.writeDouble(line.getY2()); } else if (shape instanceof Rectangle2D) { final Rectangle2D rectangle = (Rectangle2D) shape; stream.writeObject(Rectangle2D.class); stream.writeDouble(rectangle.getX()); stream.writeDouble(rectangle.getY()); stream.writeDouble(rectangle.getWidth()); stream.writeDouble(rectangle.getHeight()); } else if (shape instanceof Ellipse2D) { final Ellipse2D ellipse = (Ellipse2D) shape; stream.writeObject(Ellipse2D.class); stream.writeDouble(ellipse.getX()); stream.writeDouble(ellipse.getY()); stream.writeDouble(ellipse.getWidth()); stream.writeDouble(ellipse.getHeight()); } else if (shape instanceof Arc2D) { final Arc2D arc = (Arc2D) shape; stream.writeObject(Arc2D.class); stream.writeDouble(arc.getX()); stream.writeDouble(arc.getY()); stream.writeDouble(arc.getWidth()); stream.writeDouble(arc.getHeight()); stream.writeDouble(arc.getAngleStart()); stream.writeDouble(arc.getAngleExtent()); stream.writeInt(arc.getArcType()); } else if (shape instanceof GeneralPath) { stream.writeObject(GeneralPath.class); final PathIterator pi = shape.getPathIterator(null); final float[] args = new float[6]; stream.writeBoolean(pi.isDone()); while (!pi.isDone()) { final int type = pi.currentSegment(args); stream.writeInt(type); // TODO: could write this to only stream the values // required for the segment type for (int i = 0; i < 6; i++) { stream.writeFloat(args[i]); } stream.writeInt(pi.getWindingRule()); pi.next(); stream.writeBoolean(pi.isDone()); } } else { stream.writeObject(shape.getClass()); stream.writeObject(shape); } } else { stream.writeBoolean(true); } } /** * Reads a <code>Point2D</code> object that has been serialised by the * {@link #writePoint2D(Point2D, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The point object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. */ public static Point2D readPoint2D(final ObjectInputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Point2D result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final double x = stream.readDouble(); final double y = stream.readDouble(); result = new Point2D.Double(x, y); } return result; } /** * Serialises a <code>Point2D</code> object. * * @param p the point object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ public static void writePoint2D(final Point2D p, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (p != null) { stream.writeBoolean(false); stream.writeDouble(p.getX()); stream.writeDouble(p.getY()); } else { stream.writeBoolean(true); } } /** * Reads a <code>AttributedString</code> object that has been serialised by * the {@link SerialUtilities#writeAttributedString(AttributedString, * ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The attributed string object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ public static AttributedString readAttributedString( ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } AttributedString result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { // read string and attributes then create result String plainStr = (String) stream.readObject(); result = new AttributedString(plainStr); char c = stream.readChar(); int start = 0; while (c != CharacterIterator.DONE) { int limit = stream.readInt(); Map<? extends AttributedCharacterIterator.Attribute, ?> atts = (Map<? extends AttributedCharacterIterator.Attribute, ?>) stream.readObject(); result.addAttributes(atts, start, limit); start = limit; c = stream.readChar(); } } return result; } /** * Serialises an <code>AttributedString</code> object. * * @param as the attributed string object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ public static void writeAttributedString(AttributedString as, ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (as != null) { stream.writeBoolean(false); AttributedCharacterIterator aci = as.getIterator(); // build a plain string from aci // then write the string StringBuffer plainStr = new StringBuffer(); char current = aci.first(); while (current != CharacterIterator.DONE) { plainStr = plainStr.append(current); current = aci.next(); } stream.writeObject(plainStr.toString()); // then write the attributes and limits for each run current = aci.first(); int begin = aci.getBeginIndex(); while (current != CharacterIterator.DONE) { // write the current character - when the reader sees that this // is not CharacterIterator.DONE, it will know to read the // run limits and attributes stream.writeChar(current); // now write the limit, adjusted as if beginIndex is zero int limit = aci.getRunLimit(); stream.writeInt(limit - begin); // now write the attribute set Map<AttributedCharacterIterator.Attribute, Object> atts = new HashMap<AttributedCharacterIterator.Attribute, Object>(aci.getAttributes()); stream.writeObject(atts); current = aci.setIndex(limit); } // write a character that signals to the reader that all runs // are done... stream.writeChar(CharacterIterator.DONE); } else { // write a flag that indicates a null stream.writeBoolean(true); } } }
25,095
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Rotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/util/Rotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * Rotation.java * ------------- * (C)opyright 2003-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 19-Aug-2003 : Version 1 (DG); * 20-Feb-2004 : Updated Javadocs (DG); * 17-Jun-2012 : Moved from JCommon to JFreeChart (DG); * */ package org.jfree.chart.util; /** * Represents a direction of rotation (<code>CLOCKWISE</code> or * <code>ANTICLOCKWISE</code>). */ public enum Rotation { /** Clockwise. */ CLOCKWISE("Rotation.CLOCKWISE", -1.0), /** The reverse order renders the primary dataset first. */ ANTICLOCKWISE("Rotation.ANTICLOCKWISE", 1.0); /** The name. */ private String name; /** * The factor (-1.0 for <code>CLOCKWISE</code> and 1.0 for * <code>ANTICLOCKWISE</code>). */ private double factor; /** * Private constructor. * * @param name the name. * @param factor the rotation factor. */ private Rotation(final String name, final double factor) { this.name = name; this.factor = factor; } /** * Returns a string representing the object. * * @return the string (never <code>null</code>). */ @Override public String toString() { return this.name; } /** * Returns the rotation factor, which is -1.0 for <code>CLOCKWISE</code> * and 1.0 for <code>ANTICLOCKWISE</code>. * * @return the rotation factor. */ public double getFactor() { return this.factor; } }
2,836
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/CategoryAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * CategoryAnnotation.java * ----------------------- * (C) Copyright 2003-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 02-Apr-2003 : Version 1 (DG); * 02-Jul-2003 : Eliminated Annotation base interface (DG); * 24-Jun-2009 : Now extends Annotation (see patch 2809117 by PK) (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.CategoryPlot; /** * The interface that must be supported by annotations that are to be added to * a {@link CategoryPlot}. */ public interface CategoryAnnotation extends Annotation { /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis); }
2,434
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/package-info.java
/** * A framework for adding annotations to charts. */ package org.jfree.chart.annotations;
94
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TextAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/TextAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * TextAnnotation.java * ------------------- * (C) Copyright 2002-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * Martin Hoeller; * * Changes: * -------- * 28-Aug-2002 : Version 1 (DG); * 07-Nov-2002 : Fixed errors reported by Checkstyle, added accessor * methods (DG); * 13-Jan-2003 : Reviewed Javadocs (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 02-Jun-2003 : Added anchor and rotation settings (DG); * 19-Aug-2003 : Added equals() method and implemented Cloneable (DG); * 29-Sep-2004 : Updated equals() method (DG); * 06-Jun-2005 : Fixed equals() method to work with GradientPaint (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 16-Jan-2007 : Added argument checks, fixed hashCode() method and updated * API docs (DG); * 24-Jun-2009 : Fire change events (see patch 2809117 by PK) (DG); * 28-Oct-2011 : Added missing argument check, Bug #3428870 (MH); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.Color; import java.awt.Font; import java.awt.Paint; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.SerialUtilities; /** * A base class for text annotations. This class records the content but not * the location of the annotation. */ public class TextAnnotation extends AbstractAnnotation implements Serializable { /** For serialization. */ private static final long serialVersionUID = 7008912287533127432L; /** The default font. */ public static final Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 10); /** The default paint. */ public static final Paint DEFAULT_PAINT = Color.BLACK; /** The default text anchor. */ public static final TextAnchor DEFAULT_TEXT_ANCHOR = TextAnchor.CENTER; /** The default rotation anchor. */ public static final TextAnchor DEFAULT_ROTATION_ANCHOR = TextAnchor.CENTER; /** The default rotation angle. */ public static final double DEFAULT_ROTATION_ANGLE = 0.0; /** The text. */ private String text; /** The font. */ private Font font; /** The paint. */ private transient Paint paint; /** The text anchor. */ private TextAnchor textAnchor; /** The rotation anchor. */ private TextAnchor rotationAnchor; /** The rotation angle. */ private double rotationAngle; /** * Creates a text annotation with default settings. * * @param text the text (<code>null</code> not permitted). */ protected TextAnnotation(String text) { super(); ParamChecks.nullNotPermitted(text, "text"); this.text = text; this.font = DEFAULT_FONT; this.paint = DEFAULT_PAINT; this.textAnchor = DEFAULT_TEXT_ANCHOR; this.rotationAnchor = DEFAULT_ROTATION_ANCHOR; this.rotationAngle = DEFAULT_ROTATION_ANGLE; } /** * Returns the text for the annotation. * * @return The text (never <code>null</code>). * * @see #setText(String) */ public String getText() { return this.text; } /** * Sets the text for the annotation. * * @param text the text (<code>null</code> not permitted). * * @see #getText() */ public void setText(String text) { ParamChecks.nullNotPermitted(text, "text"); this.text = text; fireAnnotationChanged(); } /** * Returns the font for the annotation. * * @return The font (never <code>null</code>). * * @see #setFont(Font) */ public Font getFont() { return this.font; } /** * Sets the font for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getFont() */ public void setFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.font = font; fireAnnotationChanged(); } /** * Returns the paint for the annotation. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { ParamChecks.nullNotPermitted(paint, "paint"); this.paint = paint; fireAnnotationChanged(); } /** * Returns the text anchor. * * @return The text anchor. * * @see #setTextAnchor(TextAnchor) */ public TextAnchor getTextAnchor() { return this.textAnchor; } /** * Sets the text anchor (the point on the text bounding rectangle that is * aligned to the (x, y) coordinate of the annotation) and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param anchor the anchor point (<code>null</code> not permitted). * * @see #getTextAnchor() */ public void setTextAnchor(TextAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.textAnchor = anchor; fireAnnotationChanged(); } /** * Returns the rotation anchor. * * @return The rotation anchor point (never <code>null</code>). * * @see #setRotationAnchor(TextAnchor) */ public TextAnchor getRotationAnchor() { return this.rotationAnchor; } /** * Sets the rotation anchor point and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getRotationAnchor() */ public void setRotationAnchor(TextAnchor anchor) { ParamChecks.nullNotPermitted(anchor, "anchor"); this.rotationAnchor = anchor; fireAnnotationChanged(); } /** * Returns the rotation angle in radians. * * @return The rotation angle. * * @see #setRotationAngle(double) */ public double getRotationAngle() { return this.rotationAngle; } /** * Sets the rotation angle and sends an {@link AnnotationChangeEvent} to * all registered listeners. The angle is measured clockwise in radians. * * @param angle the angle (in radians). * * @see #getRotationAngle() */ public void setRotationAngle(double angle) { this.rotationAngle = angle; fireAnnotationChanged(); } /** * Tests this object for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } // now try to reject equality... if (!(obj instanceof TextAnnotation)) { return false; } TextAnnotation that = (TextAnnotation) obj; if (!ObjectUtilities.equal(this.text, that.getText())) { return false; } if (!ObjectUtilities.equal(this.font, that.getFont())) { return false; } if (!PaintUtilities.equal(this.paint, that.getPaint())) { return false; } if (!ObjectUtilities.equal(this.textAnchor, that.getTextAnchor())) { return false; } if (!ObjectUtilities.equal(this.rotationAnchor, that.getRotationAnchor())) { return false; } if (this.rotationAngle != that.getRotationAngle()) { return false; } // seem to be the same... return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = 37 * result + this.font.hashCode(); result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); result = 37 * result + this.rotationAnchor.hashCode(); long temp = Double.doubleToLongBits(this.rotationAngle); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = 37 * result + this.text.hashCode(); result = 37 * result + this.textAnchor.hashCode(); return result; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); } }
11,219
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryPointerAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/CategoryPointerAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * CategoryPointerAnnotation.java * ------------------------------ * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 02-Oct-2006 : Version 1 (DG); * 06-Mar-2007 : Implemented hashCode() (DG); * 24-Jun-2009 : Fire change events (see patch 2809117 by PK) (DG); * 30-Mar-2010 : Correct calculation of pointer line (see patch 2954302) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.category.CategoryDataset; /** * An arrow and label that can be placed on a {@link CategoryPlot}. The arrow * is drawn at a user-definable angle so that it points towards the (category, * value) location for the annotation. * <p> * The arrow length (and its offset from the (category, value) location) is * controlled by the tip radius and the base radius attributes. Imagine two * circles around the (category, value) coordinate: the inner circle defined by * the tip radius, and the outer circle defined by the base radius. Now, draw * the arrow starting at some point on the outer circle (the point is * determined by the angle), with the arrow tip being drawn at a corresponding * point on the inner circle. * * @since 1.0.3 */ public class CategoryPointerAnnotation extends CategoryTextAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -4031161445009858551L; /** The default tip radius (in Java2D units). */ public static final double DEFAULT_TIP_RADIUS = 10.0; /** The default base radius (in Java2D units). */ public static final double DEFAULT_BASE_RADIUS = 30.0; /** The default label offset (in Java2D units). */ public static final double DEFAULT_LABEL_OFFSET = 3.0; /** The default arrow length (in Java2D units). */ public static final double DEFAULT_ARROW_LENGTH = 5.0; /** The default arrow width (in Java2D units). */ public static final double DEFAULT_ARROW_WIDTH = 3.0; /** The angle of the arrow's line (in radians). */ private double angle; /** * The radius from the (x, y) point to the tip of the arrow (in Java2D * units). */ private double tipRadius; /** * The radius from the (x, y) point to the start of the arrow line (in * Java2D units). */ private double baseRadius; /** The length of the arrow head (in Java2D units). */ private double arrowLength; /** The arrow width (in Java2D units, per side). */ private double arrowWidth; /** The arrow stroke. */ private transient Stroke arrowStroke; /** The arrow paint. */ private transient Paint arrowPaint; /** The radius from the base point to the anchor point for the label. */ private double labelOffset; /** * Creates a new label and arrow annotation. * * @param label the label (<code>null</code> permitted). * @param key the category key. * @param value the y-value (measured against the chart's range axis). * @param angle the angle of the arrow's line (in radians). */ public CategoryPointerAnnotation(String label, Comparable key, double value, double angle) { super(label, key, value); this.angle = angle; this.tipRadius = DEFAULT_TIP_RADIUS; this.baseRadius = DEFAULT_BASE_RADIUS; this.arrowLength = DEFAULT_ARROW_LENGTH; this.arrowWidth = DEFAULT_ARROW_WIDTH; this.labelOffset = DEFAULT_LABEL_OFFSET; this.arrowStroke = new BasicStroke(1.0f); this.arrowPaint = Color.BLACK; } /** * Returns the angle of the arrow. * * @return The angle (in radians). * * @see #setAngle(double) */ public double getAngle() { return this.angle; } /** * Sets the angle of the arrow and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param angle the angle (in radians). * * @see #getAngle() */ public void setAngle(double angle) { this.angle = angle; fireAnnotationChanged(); } /** * Returns the tip radius. * * @return The tip radius (in Java2D units). * * @see #setTipRadius(double) */ public double getTipRadius() { return this.tipRadius; } /** * Sets the tip radius and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param radius the radius (in Java2D units). * * @see #getTipRadius() */ public void setTipRadius(double radius) { this.tipRadius = radius; fireAnnotationChanged(); } /** * Returns the base radius. * * @return The base radius (in Java2D units). * * @see #setBaseRadius(double) */ public double getBaseRadius() { return this.baseRadius; } /** * Sets the base radius and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param radius the radius (in Java2D units). * * @see #getBaseRadius() */ public void setBaseRadius(double radius) { this.baseRadius = radius; fireAnnotationChanged(); } /** * Returns the label offset. * * @return The label offset (in Java2D units). * * @see #setLabelOffset(double) */ public double getLabelOffset() { return this.labelOffset; } /** * Sets the label offset (from the arrow base, continuing in a straight * line, in Java2D units) and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param offset the offset (in Java2D units). * * @see #getLabelOffset() */ public void setLabelOffset(double offset) { this.labelOffset = offset; fireAnnotationChanged(); } /** * Returns the arrow length. * * @return The arrow length. * * @see #setArrowLength(double) */ public double getArrowLength() { return this.arrowLength; } /** * Sets the arrow length and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param length the length. * * @see #getArrowLength() */ public void setArrowLength(double length) { this.arrowLength = length; fireAnnotationChanged(); } /** * Returns the arrow width. * * @return The arrow width (in Java2D units). * * @see #setArrowWidth(double) */ public double getArrowWidth() { return this.arrowWidth; } /** * Sets the arrow width and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param width the width (in Java2D units). * * @see #getArrowWidth() */ public void setArrowWidth(double width) { this.arrowWidth = width; fireAnnotationChanged(); } /** * Returns the stroke used to draw the arrow line. * * @return The arrow stroke (never <code>null</code>). * * @see #setArrowStroke(Stroke) */ public Stroke getArrowStroke() { return this.arrowStroke; } /** * Sets the stroke used to draw the arrow line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getArrowStroke() */ public void setArrowStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.arrowStroke = stroke; fireAnnotationChanged(); } /** * Returns the paint used for the arrow. * * @return The arrow paint (never <code>null</code>). * * @see #setArrowPaint(Paint) */ public Paint getArrowPaint() { return this.arrowPaint; } /** * Sets the paint used for the arrow and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the arrow paint (<code>null</code> not permitted). * * @see #getArrowPaint() */ public void setArrowPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.arrowPaint = paint; fireAnnotationChanged(); } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ @Override public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); CategoryDataset dataset = plot.getDataset(); int catIndex = dataset.getColumnIndex(getCategory()); int catCount = dataset.getColumnCount(); double j2DX = domainAxis.getCategoryMiddle(catIndex, catCount, dataArea, domainEdge); double j2DY = rangeAxis.valueToJava2D(getValue(), dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { double temp = j2DX; j2DX = j2DY; j2DY = temp; } double startX = j2DX + Math.cos(this.angle) * this.baseRadius; double startY = j2DY + Math.sin(this.angle) * this.baseRadius; double endX = j2DX + Math.cos(this.angle) * this.tipRadius; double endY = j2DY + Math.sin(this.angle) * this.tipRadius; double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength; double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength; double arrowLeftX = arrowBaseX + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth; double arrowLeftY = arrowBaseY + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth; double arrowRightX = arrowBaseX - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth; double arrowRightY = arrowBaseY - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth; GeneralPath arrow = new GeneralPath(); arrow.moveTo((float) endX, (float) endY); arrow.lineTo((float) arrowLeftX, (float) arrowLeftY); arrow.lineTo((float) arrowRightX, (float) arrowRightY); arrow.closePath(); g2.setStroke(this.arrowStroke); g2.setPaint(this.arrowPaint); Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY); g2.draw(line); g2.fill(arrow); // draw the label g2.setFont(getFont()); g2.setPaint(getPaint()); double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius + this.labelOffset); double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius + this.labelOffset); /* Rectangle2D hotspot = */ TextUtilities.drawAlignedString(getText(), g2, (float) labelX, (float) labelY, getTextAnchor()); // TODO: implement the entity for the annotation } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CategoryPointerAnnotation)) { return false; } if (!super.equals(obj)) { return false; } CategoryPointerAnnotation that = (CategoryPointerAnnotation) obj; if (this.angle != that.angle) { return false; } if (this.tipRadius != that.tipRadius) { return false; } if (this.baseRadius != that.baseRadius) { return false; } if (this.arrowLength != that.arrowLength) { return false; } if (this.arrowWidth != that.arrowWidth) { return false; } if (!this.arrowPaint.equals(that.arrowPaint)) { return false; } if (!ObjectUtilities.equal(this.arrowStroke, that.arrowStroke)) { return false; } if (this.labelOffset != that.labelOffset) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; long temp = Double.doubleToLongBits(this.angle); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.tipRadius); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.baseRadius); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.arrowLength); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.arrowWidth); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = 37 * result + HashUtilities.hashCodeForPaint(this.arrowPaint); result = 37 * result + this.arrowStroke.hashCode(); temp = Double.doubleToLongBits(this.labelOffset); result = 37 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.arrowPaint, stream); SerialUtilities.writeStroke(this.arrowStroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.arrowPaint = SerialUtilities.readPaint(stream); this.arrowStroke = SerialUtilities.readStroke(stream); } }
17,348
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYLineAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYLineAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * XYLineAnnotation.java * --------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (see patch 2809117); * * Changes: * -------- * 02-Apr-2003 : Version 1 (DG); * 19-Aug-2003 : Added equals method, implemented Cloneable, and applied * serialization fixes (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 14-Apr-2004 : Fixed draw() method to handle plot orientation correctly (DG); * 29-Sep-2004 : Added support for tool tips and URLS, now extends * AbstractXYAnnotation (DG); * 04-Oct-2004 : Renamed ShapeUtils --> ShapeUtilities (DG); * 08-Jun-2005 : Fixed equals() method to handle GradientPaint() (DG); * 05-Nov-2008 : Added workaround for JRE bug 6574155, see JFreeChart bug * 2221495 (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.util.LineUtilities; import org.jfree.chart.util.SerialUtilities; /** * A simple line annotation that can be placed on an {@link XYPlot}. */ public class XYLineAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -80535465244091334L; /** The x-coordinate. */ private double x1; /** The y-coordinate. */ private double y1; /** The x-coordinate. */ private double x2; /** The y-coordinate. */ private double y2; /** The line stroke. */ private transient Stroke stroke; /** The line color. */ private transient Paint paint; /** * Creates a new annotation that draws a line from (x1, y1) to (x2, y2) * where the coordinates are measured in data space (that is, against the * plot's axes). * * @param x1 the x-coordinate for the start of the line. * @param y1 the y-coordinate for the start of the line. * @param x2 the x-coordinate for the end of the line. * @param y2 the y-coordinate for the end of the line. */ public XYLineAnnotation(double x1, double y1, double x2, double y2) { this(x1, y1, x2, y2, new BasicStroke(1.0f), Color.BLACK); } /** * Creates a new annotation that draws a line from (x1, y1) to (x2, y2) * where the coordinates are measured in data space (that is, against the * plot's axes). * * @param x1 the x-coordinate for the start of the line. * @param y1 the y-coordinate for the start of the line. * @param x2 the x-coordinate for the end of the line. * @param y2 the y-coordinate for the end of the line. * @param stroke the line stroke (<code>null</code> not permitted). * @param paint the line color (<code>null</code> not permitted). */ public XYLineAnnotation(double x1, double y1, double x2, double y2, Stroke stroke, Paint paint) { super(); if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; this.stroke = stroke; this.paint = paint; } /** * Draws the annotation. This method is called by the {@link XYPlot} * class, you won't normally need to call it yourself. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float j2DX1 = 0.0f; float j2DX2 = 0.0f; float j2DY1 = 0.0f; float j2DY2 = 0.0f; if (orientation == PlotOrientation.VERTICAL) { j2DX1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); j2DY1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); j2DX2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge); j2DY2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.HORIZONTAL) { j2DY1 = (float) domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); j2DX1 = (float) rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); j2DY2 = (float) domainAxis.valueToJava2D(this.x2, dataArea, domainEdge); j2DX2 = (float) rangeAxis.valueToJava2D(this.y2, dataArea, rangeEdge); } g2.setPaint(this.paint); g2.setStroke(this.stroke); Line2D line = new Line2D.Float(j2DX1, j2DY1, j2DX2, j2DY2); // line is clipped to avoid JRE bug 6574155, for more info // see JFreeChart bug 2221495 boolean visible = LineUtilities.clipLine(line, dataArea); if (visible) { g2.draw(line); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, ShapeUtilities.createLineRegion(line, 1.0f), rendererIndex, toolTip, url); } } /** * Tests this object for equality with an arbitrary object. * * @param obj the object to test against (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof XYLineAnnotation)) { return false; } XYLineAnnotation that = (XYLineAnnotation) obj; if (this.x1 != that.x1) { return false; } if (this.y1 != that.y1) { return false; } if (this.x2 != that.x2) { return false; } if (this.y2 != that.y2) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } // seems to be the same... return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(this.x1); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.x2); result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y1); result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y2); result = 29 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writeStroke(this.stroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.stroke = SerialUtilities.readStroke(stream); } }
11,079
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractXYAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/AbstractXYAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * AbstractXYAnnotation.java * ------------------------- * (C) Copyright 2004-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 29-Sep-2004 : Version 1 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Mar-2007 : Implemented hashCode() (DG); * 24-Jun-2009 : Now extends AbstractAnnotation (see patch 2809117 by PK) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.geom.Rectangle2D; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.XYAnnotationEntity; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; /** * The interface that must be supported by annotations that are to be added to * an {@link XYPlot}. */ public abstract class AbstractXYAnnotation extends AbstractAnnotation implements XYAnnotation { /** The tool tip text. */ private String toolTipText; /** The URL. */ private String url; /** * Creates a new instance that has no tool tip or URL specified. */ protected AbstractXYAnnotation() { super(); this.toolTipText = null; this.url = null; } /** * Returns the tool tip text for the annotation. This will be displayed in * a {@link org.jfree.chart.ChartPanel} when the mouse pointer hovers over * the annotation. * * @return The tool tip text (possibly <code>null</code>). * * @see #setToolTipText(String) */ public String getToolTipText() { return this.toolTipText; } /** * Sets the tool tip text for the annotation. * * @param text the tool tip text (<code>null</code> permitted). * * @see #getToolTipText() */ public void setToolTipText(String text) { this.toolTipText = text; fireAnnotationChanged(); } /** * Returns the URL for the annotation. This URL will be used to provide * hyperlinks when an HTML image map is created for the chart. * * @return The URL (possibly <code>null</code>). * * @see #setURL(String) */ public String getURL() { return this.url; } /** * Sets the URL for the annotation. * * @param url the URL (<code>null</code> permitted). * * @see #getURL() */ public void setURL(String url) { this.url = url; fireAnnotationChanged(); } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public abstract void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info); /** * A utility method for adding an {@link XYAnnotationEntity} to * a {@link PlotRenderingInfo} instance. * * @param info the plot rendering info (<code>null</code> permitted). * @param hotspot the hotspot area. * @param rendererIndex the renderer index. * @param toolTipText the tool tip text. * @param urlText the URL text. */ protected void addEntity(PlotRenderingInfo info, Shape hotspot, int rendererIndex, String toolTipText, String urlText) { if (info == null) { return; } EntityCollection entities = info.getOwner().getEntityCollection(); if (entities == null) { return; } XYAnnotationEntity entity = new XYAnnotationEntity(hotspot, rendererIndex, toolTipText, urlText); entities.add(entity); } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof AbstractXYAnnotation)) { return false; } AbstractXYAnnotation that = (AbstractXYAnnotation) obj; if (!ObjectUtilities.equal(this.toolTipText, that.toolTipText)) { return false; } if (!ObjectUtilities.equal(this.url, that.url)) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; if (this.toolTipText != null) { result = 37 * result + this.toolTipText.hashCode(); } if (this.url != null) { result = 37 * result + this.url.hashCode(); } return result; } }
6,565
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * XYAnnotation.java * ----------------- * (C) Copyright 2002-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 28-Aug-2002 : Version 1 (DG); * 07-Nov-2002 : Fixed errors reported by Checkstyle (DG); * 13-Jan-2003 : Reviewed Javadocs (DG); * 09-May-2003 : Added plot to draw() method (DG); * 02-Jul-2003 : Eliminated the Annotation base interface (DG); * 29-Sep-2004 : Added 'rendererIndex' and 'info' parameter to draw() method * to support chart entities (tool tips etc) (DG); * 24-Jun-2009 : Now extends Annotation (see patch 2809117 by PK) (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; /** * The interface that must be supported by annotations that are to be added to * an {@link XYPlot}. */ public interface XYAnnotation extends Annotation{ /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info); }
2,988
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/AbstractAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * AbstractAnnotation.java * ----------------------- * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: Peter Kolb (see patch 2809117); * Contributor(s): ; * * Changes: * -------- * 20-Jun-2009 : Version 1 (PK); * */ package org.jfree.chart.annotations; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.EventListener; import java.util.List; import javax.swing.event.EventListenerList; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.event.AnnotationChangeListener; /** * An abstract implementation of the {@link Annotation} interface, containing a * mechanism for registering change listeners. * * @since 1.0.14 */ public abstract class AbstractAnnotation implements Annotation, Cloneable, Serializable { /** Storage for registered change listeners. */ private transient EventListenerList listenerList; /** * A flag that indicates whether listeners should be notified * about changes of the annotation. */ private boolean notify = true; /** * Constructs an annotation. */ protected AbstractAnnotation() { this.listenerList = new EventListenerList(); } /** * Registers an object to receive notification of changes to the * annotation. * * @param listener the object to register. * * @see #removeChangeListener(AnnotationChangeListener) */ @Override public void addChangeListener(AnnotationChangeListener listener) { this.listenerList.add(AnnotationChangeListener.class, listener); } /** * Deregisters an object so that it no longer receives notification of * changes to the annotation. * * @param listener the object to deregister. * * @see #addChangeListener(AnnotationChangeListener) */ @Override public void removeChangeListener(AnnotationChangeListener listener) { this.listenerList.remove(AnnotationChangeListener.class, listener); } /** * Returns <code>true</code> if the specified object is registered with * the annotation as a listener. Most applications won't need to call this * method, it exists mainly for use by unit testing code. * * @param listener the listener. * * @return A boolean. * * @see #addChangeListener(AnnotationChangeListener) * @see #removeChangeListener(AnnotationChangeListener) */ public boolean hasListener(EventListener listener) { List<Object> list = Arrays.asList(this.listenerList.getListenerList()); return list.contains(listener); } /** * Notifies all registered listeners that the annotation has changed. * * @see #addChangeListener(AnnotationChangeListener) */ protected void fireAnnotationChanged() { if (notify) { notifyListeners(new AnnotationChangeEvent(this, this)); } } /** * Notifies all registered listeners that the annotation has changed. * * @param event contains information about the event that triggered the * notification. * * @see #addChangeListener(AnnotationChangeListener) * @see #removeChangeListener(AnnotationChangeListener) */ protected void notifyListeners(AnnotationChangeEvent event) { Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == AnnotationChangeListener.class) { ((AnnotationChangeListener) listeners[i + 1]).annotationChanged( event); } } } /** * Returns a flag that indicates whether listeners should be * notified about changes to the annotation. * * @return the flag. * * @see #setNotify(boolean) */ public boolean getNotify(){ return this.notify; } /** * Sets a flag that indicates whether listeners should be notified about * changes of an annotation. * * @param flag the flag * * @see #getNotify() */ public void setNotify(boolean flag){ this.notify = flag; if (notify) { fireAnnotationChanged(); } } /** * Returns a clone of the annotation. The cloned annotation will NOT * include the {@link AnnotationChangeListener} references that have been * registered with this annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation does not support * cloning. */ @Override public Object clone() throws CloneNotSupportedException { AbstractAnnotation clone = (AbstractAnnotation) super.clone(); clone.listenerList = new EventListenerList(); return clone; } /** * Handles serialization. * * @param stream the output stream. * * @throws IOException if there is an I/O problem. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); } /** * Restores a serialized object. * * @param stream the input stream. * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.listenerList = new EventListenerList(); } }
6,988
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYPointerAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYPointerAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * XYPointerAnnotation.java * ------------------------ * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 21-May-2003 : Version 1 (DG); * 10-Jun-2003 : Changed BoundsAnchor to TextAnchor (DG); * 02-Jul-2003 : Added accessor methods and simplified constructor (DG); * 19-Aug-2003 : Implemented Cloneable (DG); * 13-Oct-2003 : Fixed bug where arrow paint is not set correctly (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 29-Sep-2004 : Changes to draw() method signature (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 20-Feb-2006 : Correction for equals() method (fixes bug 1435160) (DG); * 12-Jul-2006 : Fix drawing for PlotOrientation.HORIZONTAL, thanks to * Skunk (DG); * 12-Feb-2009 : Added support for rotated label, plus background and * outline (DG); * 18-May-2009 : Fixed typo in hashCode() method (DG); * 24-Jun-2009 : Fire change events (see patch 2809117 by PK) (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; 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.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.SerialUtilities; /** * An arrow and label that can be placed on an {@link XYPlot}. The arrow is * drawn at a user-definable angle so that it points towards the (x, y) * location for the annotation. * <p> * The arrow length (and its offset from the (x, y) location) is controlled by * the tip radius and the base radius attributes. Imagine two circles around * the (x, y) coordinate: the inner circle defined by the tip radius, and the * outer circle defined by the base radius. Now, draw the arrow starting at * some point on the outer circle (the point is determined by the angle), with * the arrow tip being drawn at a corresponding point on the inner circle. * */ public class XYPointerAnnotation extends XYTextAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -4031161445009858551L; /** The default tip radius (in Java2D units). */ public static final double DEFAULT_TIP_RADIUS = 10.0; /** The default base radius (in Java2D units). */ public static final double DEFAULT_BASE_RADIUS = 30.0; /** The default label offset (in Java2D units). */ public static final double DEFAULT_LABEL_OFFSET = 3.0; /** The default arrow length (in Java2D units). */ public static final double DEFAULT_ARROW_LENGTH = 5.0; /** The default arrow width (in Java2D units). */ public static final double DEFAULT_ARROW_WIDTH = 3.0; /** The angle of the arrow's line (in radians). */ private double angle; /** * The radius from the (x, y) point to the tip of the arrow (in Java2D * units). */ private double tipRadius; /** * The radius from the (x, y) point to the start of the arrow line (in * Java2D units). */ private double baseRadius; /** The length of the arrow head (in Java2D units). */ private double arrowLength; /** The arrow width (in Java2D units, per side). */ private double arrowWidth; /** The arrow stroke. */ private transient Stroke arrowStroke; /** The arrow paint. */ private transient Paint arrowPaint; /** The radius from the base point to the anchor point for the label. */ private double labelOffset; /** * Creates a new label and arrow annotation. * * @param label the label (<code>null</code> permitted). * @param x the x-coordinate (measured against the chart's domain axis). * @param y the y-coordinate (measured against the chart's range axis). * @param angle the angle of the arrow's line (in radians). */ public XYPointerAnnotation(String label, double x, double y, double angle) { super(label, x, y); this.angle = angle; this.tipRadius = DEFAULT_TIP_RADIUS; this.baseRadius = DEFAULT_BASE_RADIUS; this.arrowLength = DEFAULT_ARROW_LENGTH; this.arrowWidth = DEFAULT_ARROW_WIDTH; this.labelOffset = DEFAULT_LABEL_OFFSET; this.arrowStroke = new BasicStroke(1.0f); this.arrowPaint = Color.BLACK; } /** * Returns the angle of the arrow. * * @return The angle (in radians). * * @see #setAngle(double) */ public double getAngle() { return this.angle; } /** * Sets the angle of the arrow and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param angle the angle (in radians). * * @see #getAngle() */ public void setAngle(double angle) { this.angle = angle; fireAnnotationChanged(); } /** * Returns the tip radius. * * @return The tip radius (in Java2D units). * * @see #setTipRadius(double) */ public double getTipRadius() { return this.tipRadius; } /** * Sets the tip radius and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param radius the radius (in Java2D units). * * @see #getTipRadius() */ public void setTipRadius(double radius) { this.tipRadius = radius; fireAnnotationChanged(); } /** * Returns the base radius. * * @return The base radius (in Java2D units). * * @see #setBaseRadius(double) */ public double getBaseRadius() { return this.baseRadius; } /** * Sets the base radius and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param radius the radius (in Java2D units). * * @see #getBaseRadius() */ public void setBaseRadius(double radius) { this.baseRadius = radius; fireAnnotationChanged(); } /** * Returns the label offset. * * @return The label offset (in Java2D units). * * @see #setLabelOffset(double) */ public double getLabelOffset() { return this.labelOffset; } /** * Sets the label offset (from the arrow base, continuing in a straight * line, in Java2D units) and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param offset the offset (in Java2D units). * * @see #getLabelOffset() */ public void setLabelOffset(double offset) { this.labelOffset = offset; fireAnnotationChanged(); } /** * Returns the arrow length. * * @return The arrow length. * * @see #setArrowLength(double) */ public double getArrowLength() { return this.arrowLength; } /** * Sets the arrow length and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param length the length. * * @see #getArrowLength() */ public void setArrowLength(double length) { this.arrowLength = length; fireAnnotationChanged(); } /** * Returns the arrow width. * * @return The arrow width (in Java2D units). * * @see #setArrowWidth(double) */ public double getArrowWidth() { return this.arrowWidth; } /** * Sets the arrow width and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param width the width (in Java2D units). * * @see #getArrowWidth() */ public void setArrowWidth(double width) { this.arrowWidth = width; fireAnnotationChanged(); } /** * Returns the stroke used to draw the arrow line. * * @return The arrow stroke (never <code>null</code>). * * @see #setArrowStroke(Stroke) */ public Stroke getArrowStroke() { return this.arrowStroke; } /** * Sets the stroke used to draw the arrow line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getArrowStroke() */ public void setArrowStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' not permitted."); } this.arrowStroke = stroke; fireAnnotationChanged(); } /** * Returns the paint used for the arrow. * * @return The arrow paint (never <code>null</code>). * * @see #setArrowPaint(Paint) */ public Paint getArrowPaint() { return this.arrowPaint; } /** * Sets the paint used for the arrow and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the arrow paint (<code>null</code> not permitted). * * @see #getArrowPaint() */ public void setArrowPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.arrowPaint = paint; fireAnnotationChanged(); } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info the plot rendering info. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); double j2DX = domainAxis.valueToJava2D(getX(), dataArea, domainEdge); double j2DY = rangeAxis.valueToJava2D(getY(), dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { double temp = j2DX; j2DX = j2DY; j2DY = temp; } double startX = j2DX + Math.cos(this.angle) * this.baseRadius; double startY = j2DY + Math.sin(this.angle) * this.baseRadius; double endX = j2DX + Math.cos(this.angle) * this.tipRadius; double endY = j2DY + Math.sin(this.angle) * this.tipRadius; double arrowBaseX = endX + Math.cos(this.angle) * this.arrowLength; double arrowBaseY = endY + Math.sin(this.angle) * this.arrowLength; double arrowLeftX = arrowBaseX + Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth; double arrowLeftY = arrowBaseY + Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth; double arrowRightX = arrowBaseX - Math.cos(this.angle + Math.PI / 2.0) * this.arrowWidth; double arrowRightY = arrowBaseY - Math.sin(this.angle + Math.PI / 2.0) * this.arrowWidth; GeneralPath arrow = new GeneralPath(); arrow.moveTo((float) endX, (float) endY); arrow.lineTo((float) arrowLeftX, (float) arrowLeftY); arrow.lineTo((float) arrowRightX, (float) arrowRightY); arrow.closePath(); g2.setStroke(this.arrowStroke); g2.setPaint(this.arrowPaint); Line2D line = new Line2D.Double(startX, startY, arrowBaseX, arrowBaseY); g2.draw(line); g2.fill(arrow); // draw the label double labelX = j2DX + Math.cos(this.angle) * (this.baseRadius + this.labelOffset); double labelY = j2DY + Math.sin(this.angle) * (this.baseRadius + this.labelOffset); g2.setFont(getFont()); Shape hotspot = TextUtilities.calculateRotatedStringBounds( getText(), g2, (float) labelX, (float) labelY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (getBackgroundPaint() != null) { g2.setPaint(getBackgroundPaint()); g2.fill(hotspot); } g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, (float) labelX, (float) labelY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (isOutlineVisible()) { g2.setStroke(getOutlineStroke()); g2.setPaint(getOutlinePaint()); g2.draw(hotspot); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, hotspot, rendererIndex, toolTip, url); } } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYPointerAnnotation)) { return false; } XYPointerAnnotation that = (XYPointerAnnotation) obj; if (this.angle != that.angle) { return false; } if (this.tipRadius != that.tipRadius) { return false; } if (this.baseRadius != that.baseRadius) { return false; } if (this.arrowLength != that.arrowLength) { return false; } if (this.arrowWidth != that.arrowWidth) { return false; } if (!this.arrowPaint.equals(that.arrowPaint)) { return false; } if (!ObjectUtilities.equal(this.arrowStroke, that.arrowStroke)) { return false; } if (this.labelOffset != that.labelOffset) { return false; } return super.equals(obj); } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = super.hashCode(); long temp = Double.doubleToLongBits(this.angle); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.tipRadius); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.baseRadius); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.arrowLength); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.arrowWidth); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = result * 37 + HashUtilities.hashCodeForPaint(this.arrowPaint); result = result * 37 + this.arrowStroke.hashCode(); temp = Double.doubleToLongBits(this.labelOffset); result = 37 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.arrowPaint, stream); SerialUtilities.writeStroke(this.arrowStroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.arrowPaint = SerialUtilities.readPaint(stream); this.arrowStroke = SerialUtilities.readStroke(stream); } }
18,531
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDrawableAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYDrawableAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * XYDrawableAnnotation.java * ------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 21-May-2003 : Version 1 (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 30-Sep-2004 : Added support for tool tips and URLs (DG); * 18-Jun-2008 : Added scaling factor (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.Serializable; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.Drawable; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; /** * A general annotation that can be placed on an {@link XYPlot}. */ public class XYDrawableAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -6540812859722691020L; /** The scaling factor. */ private double drawScaleFactor; /** The x-coordinate. */ private double x; /** The y-coordinate. */ private double y; /** The width. */ private double displayWidth; /** The height. */ private double displayHeight; /** The drawable object. */ private Drawable drawable; /** * Creates a new annotation to be displayed within the given area. * * @param x the x-coordinate for the area. * @param y the y-coordinate for the area. * @param width the width of the area. * @param height the height of the area. * @param drawable the drawable object (<code>null</code> not permitted). */ public XYDrawableAnnotation(double x, double y, double width, double height, Drawable drawable) { this(x, y, width, height, 1.0, drawable); } /** * Creates a new annotation to be displayed within the given area. If you * specify a <code>drawScaleFactor</code> of 2.0, the <code>drawable</code> * will be drawn at twice the requested display size then scaled down to * fit the space. * * @param x the x-coordinate for the area. * @param y the y-coordinate for the area. * @param displayWidth the width of the area. * @param displayHeight the height of the area. * @param drawScaleFactor the scaling factor for drawing. * @param drawable the drawable object (<code>null</code> not permitted). * * @since 1.0.11 */ public XYDrawableAnnotation(double x, double y, double displayWidth, double displayHeight, double drawScaleFactor, Drawable drawable) { super(); if (drawable == null) { throw new IllegalArgumentException("Null 'drawable' argument."); } this.x = x; this.y = y; this.displayWidth = displayWidth; this.displayHeight = displayHeight; this.drawScaleFactor = drawScaleFactor; this.drawable = drawable; } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); Rectangle2D displayArea = new Rectangle2D.Double( j2DX - this.displayWidth / 2.0, j2DY - this.displayHeight / 2.0, this.displayWidth, this.displayHeight); // here we change the AffineTransform so we can draw the annotation // to a larger area and scale it down into the display area // afterwards, the original transform is restored AffineTransform savedTransform = g2.getTransform(); Rectangle2D drawArea = new Rectangle2D.Double(0.0, 0.0, this.displayWidth * this.drawScaleFactor, this.displayHeight * this.drawScaleFactor); g2.scale(1 / this.drawScaleFactor, 1 / this.drawScaleFactor); g2.translate((j2DX - this.displayWidth / 2.0) * this.drawScaleFactor, (j2DY - this.displayHeight / 2.0) * this.drawScaleFactor); this.drawable.draw(g2, drawArea); g2.setTransform(savedTransform); String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, displayArea, rendererIndex, toolTip, url); } } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object to test against. * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { // simple case return true; } // now try to reject equality... if (!super.equals(obj)) { return false; } if (!(obj instanceof XYDrawableAnnotation)) { return false; } XYDrawableAnnotation that = (XYDrawableAnnotation) obj; if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } if (this.displayWidth != that.displayWidth) { return false; } if (this.displayHeight != that.displayHeight) { return false; } if (this.drawScaleFactor != that.drawScaleFactor) { return false; } if (!ObjectUtilities.equal(this.drawable, that.drawable)) { return false; } // seem to be the same... return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(this.x); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y); result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.displayWidth); result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.displayHeight); result = 29 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } }
9,071
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDataImageAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYDataImageAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * XYDataImageAnnotation.java * -------------------------- * (C) Copyright 2008-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 17-Sep-2008 : Version 1, based on XYImageAnnotation (DG); * 10-Mar-2009 : Implemented XYAnnotationBoundsInfo (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.data.Range; /** * An annotation that allows an image to be placed within a rectangle specified * in data coordinates on an {@link XYPlot}. Note that this annotation * is not currently serializable, so don't use it if you plan on serializing * your chart(s). * * @since 1.0.11 */ public class XYDataImageAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, XYAnnotationBoundsInfo { /** The image. */ private transient Image image; /** * The x-coordinate (in data space). */ private double x; /** * The y-coordinate (in data space). */ private double y; /** * The image display area width in data coordinates. */ private double w; /** * The image display area height in data coordinates. */ private double h; /** * A flag indicating whether or not the annotation should contribute to * the data range for a plot/renderer. * * @since 1.0.13 */ private boolean includeInDataBounds; /** * Creates a new annotation to be displayed within the specified rectangle. * * @param image the image (<code>null</code> not permitted). * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param w the image display area width. * @param h the image display area height. */ public XYDataImageAnnotation(Image image, double x, double y, double w, double h) { this(image, x, y, w, h, false); } /** * Creates a new annotation to be displayed within the specified rectangle. * * @param image the image (<code>null</code> not permitted). * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param w the image display area width. * @param h the image display area height. * @param includeInDataBounds a flag that controls whether or not the * annotation is included in the data bounds for the axis autoRange. * * @since 1.0.13 */ public XYDataImageAnnotation(Image image, double x, double y, double w, double h, boolean includeInDataBounds) { super(); if (image == null) { throw new IllegalArgumentException("Null 'image' argument."); } this.image = image; this.x = x; this.y = y; this.w = w; this.h = h; this.includeInDataBounds = includeInDataBounds; } /** * Returns the image for the annotation. * * @return The image. */ public Image getImage() { return this.image; } /** * Returns the x-coordinate (in data space) for the annotation. * * @return The x-coordinate. */ public double getX() { return this.x; } /** * Returns the y-coordinate (in data space) for the annotation. * * @return The y-coordinate. */ public double getY() { return this.y; } /** * Returns the width (in data space) of the data rectangle into which the * image will be drawn. * * @return The width. */ public double getWidth() { return this.w; } /** * Returns the height (in data space) of the data rectangle into which the * image will be drawn. * * @return The height. */ public double getHeight() { return this.h; } /** * Returns the flag that controls whether or not the annotation should * contribute to the autoRange for the axis it is plotted against. * * @return A boolean. * * @since 1.0.13 */ @Override public boolean getIncludeInDataBounds() { return this.includeInDataBounds; } /** * Returns the x-range for the annotation. * * @return The range. * * @since 1.0.13 */ @Override public Range getXRange() { return new Range(this.x, this.x + this.w); } /** * Returns the y-range for the annotation. * * @return The range. * * @since 1.0.13 */ @Override public Range getYRange() { return new Range(this.y, this.y + this.h); } /** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation xAxisLocation = plot.getDomainAxisLocation(); AxisLocation yAxisLocation = plot.getRangeAxisLocation(); RectangleEdge xEdge = Plot.resolveDomainAxisLocation(xAxisLocation, orientation); RectangleEdge yEdge = Plot.resolveRangeAxisLocation(yAxisLocation, orientation); float j2DX0 = (float) domainAxis.valueToJava2D(this.x, dataArea, xEdge); float j2DY0 = (float) rangeAxis.valueToJava2D(this.y, dataArea, yEdge); float j2DX1 = (float) domainAxis.valueToJava2D(this.x + this.w, dataArea, xEdge); float j2DY1 = (float) rangeAxis.valueToJava2D(this.y + this.h, dataArea, yEdge); float xx0 = 0.0f; float yy0 = 0.0f; float xx1 = 0.0f; float yy1 = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx0 = j2DY0; xx1 = j2DY1; yy0 = j2DX0; yy1 = j2DX1; } else if (orientation == PlotOrientation.VERTICAL) { xx0 = j2DX0; xx1 = j2DX1; yy0 = j2DY0; yy1 = j2DY1; } // TODO: rotate the image when drawn with horizontal orientation? g2.drawImage(this.image, (int) xx0, (int) Math.min(yy0, yy1), (int) (xx1 - xx0), (int) Math.abs(yy1 - yy0), null); String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx0, yy0, (xx1 - xx0), (yy1 - yy0)), rendererIndex, toolTip, url); } } /** * Tests this object for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } // now try to reject equality... if (!super.equals(obj)) { return false; } if (!(obj instanceof XYDataImageAnnotation)) { return false; } XYDataImageAnnotation that = (XYDataImageAnnotation) obj; if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } if (this.w != that.w) { return false; } if (this.h != that.h) { return false; } if (this.includeInDataBounds != that.includeInDataBounds) { return false; } if (!ObjectUtilities.equal(this.image, that.image)) { return false; } // seems to be the same... return true; } /** * Returns a hash code for this object. * * @return A hash code. */ @Override public int hashCode() { return this.image.hashCode(); } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); // FIXME //SerialUtilities.writeImage(this.image, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); // FIXME //this.image = SerialUtilities.readImage(stream); } }
11,474
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Annotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/Annotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * Annotation.java * --------------- * (C) Copyright 2009-2013 by Object Refinery Limited and Contributors. * * Original Author: Peter Kolb (see patch 2809117); * Contributor(s): ; * * Changes: * -------- * 20-Jun-2009 : Version 1 (PK); * */ package org.jfree.chart.annotations; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.event.AnnotationChangeListener; /** * The base interface for annotations. All annotations should support the * {@link AnnotationChangeEvent} mechanism by allowing listeners to register * and receive notification of any changes to the annotation. */ public interface Annotation { /** * Registers an object for notification of changes to the annotation. * * @param listener the object to register. */ public void addChangeListener(AnnotationChangeListener listener); /** * Deregisters an object for notification of changes to the annotation. * * @param listener the object to deregister. */ public void removeChangeListener(AnnotationChangeListener listener); }
2,340
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYImageAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYImageAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * XYImageAnnotation.java * ---------------------- * (C) Copyright 2003-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Mike Harris; * Peter Kolb (patch 2809117); * * Changes: * -------- * 01-Dec-2003 : Version 1 (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 18-May-2004 : Fixed bug with plot orientation (DG); * 29-Sep-2004 : Now extends AbstractXYAnnotation, with modified draw() * method signature and updated equals() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 01-Dec-2006 : Added anchor attribute (see patch 1584860 from * Mike Harris) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.Image; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; /** * An annotation that allows an image to be placed at some location on * an {@link XYPlot}. * * TODO: implement serialization properly (image is not serializable). */ public class XYImageAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -4364694501921559958L; /** The x-coordinate (in data space). */ private double x; /** The y-coordinate (in data space). */ private double y; /** The image. */ private transient Image image; /** * The image anchor point. * * @since 1.0.4 */ private RectangleAnchor anchor; /** * Creates a new annotation to be displayed at the specified (x, y) * location. * * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param image the image (<code>null</code> not permitted). */ public XYImageAnnotation(double x, double y, Image image) { this(x, y, image, RectangleAnchor.CENTER); } /** * Creates a new annotation to be displayed at the specified (x, y) * location. * * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param image the image (<code>null</code> not permitted). * @param anchor the image anchor (<code>null</code> not permitted). * * @since 1.0.4 */ public XYImageAnnotation(double x, double y, Image image, RectangleAnchor anchor) { super(); if (image == null) { throw new IllegalArgumentException("Null 'image' argument."); } if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.x = x; this.y = y; this.image = image; this.anchor = anchor; } /** * Returns the x-coordinate (in data space) for the annotation. * * @return The x-coordinate. * * @since 1.0.4 */ public double getX() { return this.x; } /** * Returns the y-coordinate (in data space) for the annotation. * * @return The y-coordinate. * * @since 1.0.4 */ public double getY() { return this.y; } /** * Returns the image for the annotation. * * @return The image. * * @since 1.0.4 */ public Image getImage() { return this.image; } /** * Returns the image anchor for the annotation. * * @return The image anchor. * * @since 1.0.4 */ public RectangleAnchor getImageAnchor() { return this.anchor; } /** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); float j2DX = (float) domainAxis.valueToJava2D(this.x, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } int w = this.image.getWidth(null); int h = this.image.getHeight(null); Rectangle2D imageRect = new Rectangle2D.Double(0, 0, w, h); Point2D anchorPoint = RectangleAnchor.coordinates(imageRect, this.anchor); xx = xx - (float) anchorPoint.getX(); yy = yy - (float) anchorPoint.getY(); g2.drawImage(this.image, (int) xx, (int) yy, null); String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx, yy, w, h), rendererIndex, toolTip, url); } } /** * Tests this object for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } // now try to reject equality... if (!super.equals(obj)) { return false; } if (!(obj instanceof XYImageAnnotation)) { return false; } XYImageAnnotation that = (XYImageAnnotation) obj; if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } if (!ObjectUtilities.equal(this.image, that.image)) { return false; } if (!this.anchor.equals(that.anchor)) { return false; } // seems to be the same... return true; } /** * Returns a hash code for this object. * * @return A hash code. */ @Override public int hashCode() { return this.image.hashCode(); } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); //SerialUtilities.writeImage(this.image, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); //this.image = SerialUtilities.readImage(stream); } }
10,070
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryTextAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/CategoryTextAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * CategoryTextAnnotation.java * --------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 02-Apr-2003 : Version 1 (DG); * 02-Jul-2003 : Added new text alignment and rotation options (DG); * 04-Jul-2003 : Added a category anchor option (DG); * 19-Aug-2003 : Added equals() method and implemented Cloneable (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 30-Sep-2004 : Moved drawRotatedString() from RefineryUtilities * --> TextUtilities (DG); * ------------- JFREECHART 1.0.x ------------------------------------------- * 06-Mar-2007 : Implemented hashCode() (DG); * 23-Apr-2008 : Implemented PublicCloneable (DG); * 24-Jun-2009 : Fire change events (see patch 2809117 by PK) (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import org.jfree.chart.axis.CategoryAnchor; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.data.category.CategoryDataset; /** * A text annotation that can be placed on a {@link CategoryPlot}. */ public class CategoryTextAnnotation extends TextAnnotation implements CategoryAnnotation, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 3333360090781320147L; /** The category. */ private Comparable category; /** The category anchor (START, MIDDLE, or END). */ private CategoryAnchor categoryAnchor; /** The value. */ private double value; /** * Creates a new annotation to be displayed at the given location. * * @param text the text (<code>null</code> not permitted). * @param category the category (<code>null</code> not permitted). * @param value the value. */ public CategoryTextAnnotation(String text, Comparable category, double value) { super(text); ParamChecks.nullNotPermitted(category, "category"); this.category = category; this.value = value; this.categoryAnchor = CategoryAnchor.MIDDLE; } /** * Returns the category. * * @return The category (never <code>null</code>). * * @see #setCategory(Comparable) */ public Comparable getCategory() { return this.category; } /** * Sets the category that the annotation attaches to and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param category the category (<code>null</code> not permitted). * * @see #getCategory() */ public void setCategory(Comparable category) { if (category == null) { throw new IllegalArgumentException("Null 'category' argument."); } this.category = category; fireAnnotationChanged(); } /** * Returns the category anchor point. * * @return The category anchor point. * * @see #setCategoryAnchor(CategoryAnchor) */ public CategoryAnchor getCategoryAnchor() { return this.categoryAnchor; } /** * Sets the category anchor point and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param anchor the anchor point (<code>null</code> not permitted). * * @see #getCategoryAnchor() */ public void setCategoryAnchor(CategoryAnchor anchor) { ParamChecks.nullNotPermitted(anchor, "anchor"); this.categoryAnchor = anchor; fireAnnotationChanged(); } /** * Returns the value that the annotation attaches to. * * @return The value. * * @see #setValue(double) */ public double getValue() { return this.value; } /** * Sets the value and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param value the value. * * @see #getValue() */ public void setValue(double value) { this.value = value; fireAnnotationChanged(); } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ @Override public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) { CategoryDataset dataset = plot.getDataset(); int catIndex = dataset.getColumnIndex(this.category); int catCount = dataset.getColumnCount(); float anchorX = 0.0f; float anchorY = 0.0f; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); if (orientation == PlotOrientation.HORIZONTAL) { anchorY = (float) domainAxis.getCategoryJava2DCoordinate( this.categoryAnchor, catIndex, catCount, dataArea, domainEdge); anchorX = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge); } else if (orientation == PlotOrientation.VERTICAL) { anchorX = (float) domainAxis.getCategoryJava2DCoordinate( this.categoryAnchor, catIndex, catCount, dataArea, domainEdge); anchorY = (float) rangeAxis.valueToJava2D(this.value, dataArea, rangeEdge); } g2.setFont(getFont()); g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); } /** * Tests this object for equality with another. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CategoryTextAnnotation)) { return false; } CategoryTextAnnotation that = (CategoryTextAnnotation) obj; if (!super.equals(obj)) { return false; } if (!this.category.equals(that.getCategory())) { return false; } if (!this.categoryAnchor.equals(that.getCategoryAnchor())) { return false; } if (this.value != that.getValue()) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = super.hashCode(); result = 37 * result + this.category.hashCode(); result = 37 * result + this.categoryAnchor.hashCode(); long temp = Double.doubleToLongBits(this.value); result = 37 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } }
9,431
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYPolygonAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYPolygonAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * XYPolygonAnnotation.java * ------------------------ * (C) Copyright 2005-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 09-Feb-2005 : Version 1 (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.GeneralPath; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.util.SerialUtilities; /** * A polygon annotation that can be placed on an {@link XYPlot}. The * polygon coordinates are specified in data space. */ public class XYPolygonAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -6984203651995900036L; /** The polygon. */ private double[] polygon; /** The stroke used to draw the box outline. */ private transient Stroke stroke; /** The paint used to draw the box outline. */ private transient Paint outlinePaint; /** The paint used to fill the box. */ private transient Paint fillPaint; /** * Creates a new annotation (where, by default, the polygon is drawn * with a black outline). The array of polygon coordinates must contain * an even number of coordinates (each pair is an (x, y) location on the * plot) and the last point is automatically joined back to the first point. * * @param polygon the coordinates of the polygon's vertices * (<code>null</code> not permitted). */ public XYPolygonAnnotation(double[] polygon) { this(polygon, new BasicStroke(1.0f), Color.BLACK); } /** * Creates a new annotation where the box is drawn as an outline using * the specified <code>stroke</code> and <code>outlinePaint</code>. * The array of polygon coordinates must contain an even number of * coordinates (each pair is an (x, y) location on the plot) and the last * point is automatically joined back to the first point. * * @param polygon the coordinates of the polygon's vertices * (<code>null</code> not permitted). * @param stroke the shape stroke (<code>null</code> permitted). * @param outlinePaint the shape color (<code>null</code> permitted). */ public XYPolygonAnnotation(double[] polygon, Stroke stroke, Paint outlinePaint) { this(polygon, stroke, outlinePaint, null); } /** * Creates a new annotation. The array of polygon coordinates must * contain an even number of coordinates (each pair is an (x, y) location * on the plot) and the last point is automatically joined back to the * first point. * * @param polygon the coordinates of the polygon's vertices * (<code>null</code> not permitted). * @param stroke the shape stroke (<code>null</code> permitted). * @param outlinePaint the shape color (<code>null</code> permitted). * @param fillPaint the paint used to fill the shape (<code>null</code> * permitted). */ public XYPolygonAnnotation(double[] polygon, Stroke stroke, Paint outlinePaint, Paint fillPaint) { super(); if (polygon == null) { throw new IllegalArgumentException("Null 'polygon' argument."); } if (polygon.length % 2 != 0) { throw new IllegalArgumentException("The 'polygon' array must " + "contain an even number of items."); } this.polygon = polygon.clone(); this.stroke = stroke; this.outlinePaint = outlinePaint; this.fillPaint = fillPaint; } /** * Returns the coordinates of the polygon's vertices. The returned array * is a copy, so it is safe to modify without altering the annotation's * state. * * @return The coordinates of the polygon's vertices. * * @since 1.0.2 */ public double[] getPolygonCoordinates() { return this.polygon.clone(); } /** * Returns the fill paint. * * @return The fill paint (possibly <code>null</code>). * * @since 1.0.2 */ public Paint getFillPaint() { return this.fillPaint; } /** * Returns the outline stroke. * * @return The outline stroke (possibly <code>null</code>). * * @since 1.0.2 */ public Stroke getOutlineStroke() { return this.stroke; } /** * Returns the outline paint. * * @return The outline paint (possibly <code>null</code>). * * @since 1.0.2 */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Draws the annotation. This method is usually called by the * {@link XYPlot} class, you shouldn't need to call it directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info the plot rendering info. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { // if we don't have at least 2 (x, y) coordinates, just return if (this.polygon.length < 4) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); GeneralPath area = new GeneralPath(); double x = domainAxis.valueToJava2D(this.polygon[0], dataArea, domainEdge); double y = rangeAxis.valueToJava2D(this.polygon[1], dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { area.moveTo((float) y, (float) x); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) y, (float) x); } area.closePath(); } else if (orientation == PlotOrientation.VERTICAL) { area.moveTo((float) x, (float) y); for (int i = 2; i < this.polygon.length; i += 2) { x = domainAxis.valueToJava2D(this.polygon[i], dataArea, domainEdge); y = rangeAxis.valueToJava2D(this.polygon[i + 1], dataArea, rangeEdge); area.lineTo((float) x, (float) y); } area.closePath(); } if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(area); } if (this.stroke != null && this.outlinePaint != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(area); } addEntity(info, area, rendererIndex, getToolTipText(), getURL()); } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } // now try to reject equality if (!super.equals(obj)) { return false; } if (!(obj instanceof XYPolygonAnnotation)) { return false; } XYPolygonAnnotation that = (XYPolygonAnnotation) obj; if (!Arrays.equals(this.polygon, that.polygon)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!PaintUtilities.equal(this.fillPaint, that.fillPaint)) { return false; } // seem to be the same return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = 37 * result + HashUtilities.hashCodeForDoubleArray( this.polygon); result = 37 * result + HashUtilities.hashCodeForPaint(this.fillPaint); result = 37 * result + HashUtilities.hashCodeForPaint( this.outlinePaint); if (this.stroke != null) { result = 37 * result + this.stroke.hashCode(); } return result; } /** * Returns a clone. * * @return A clone. * * @throws CloneNotSupportedException not thrown by this class, but may be * by subclasses. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.stroke, stream); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writePaint(this.fillPaint, stream); } /** * Provides serialization support. * * @param stream the input stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.stroke = SerialUtilities.readStroke(stream); this.outlinePaint = SerialUtilities.readPaint(stream); this.fillPaint = SerialUtilities.readPaint(stream); } }
12,584
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYTitleAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYTitleAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * XYTitleAnnotation.java * ---------------------- * (C) Copyright 2007-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Andrew Mickish; * Peter Kolb (patch 2809117); * * Changes: * -------- * 02-Feb-2007 : Version 1 (DG); * 30-Apr-2007 : Fixed equals() method (DG); * 26-Feb-2008 : Fixed NullPointerException when drawing chart with a null * ChartRenderingInfo - see patch 1901599 by Andrew Mickish (DG); * 03-Sep-2008 : Moved from experimental to main (DG); * 24-Jun-2009 : Fire change events (see patch 2809117 by PK) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); */ package org.jfree.chart.annotations; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.block.BlockParams; import org.jfree.chart.block.EntityBlockResult; import org.jfree.chart.block.RectangleConstraint; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.title.Title; import org.jfree.chart.util.XYCoordinateType; import org.jfree.data.Range; /** * An annotation that allows any {@link Title} to be placed at a location on * an {@link XYPlot}. * * @since 1.0.11 */ public class XYTitleAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -4364694501921559958L; /** The coordinate type. */ private XYCoordinateType coordinateType; /** The x-coordinate (in data space). */ private double x; /** The y-coordinate (in data space). */ private double y; /** The maximum width. */ private double maxWidth; /** The maximum height. */ private double maxHeight; /** The title. */ private Title title; /** * The title anchor point. */ private RectangleAnchor anchor; /** * Creates a new annotation to be displayed at the specified (x, y) * location. * * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param title the title (<code>null</code> not permitted). */ public XYTitleAnnotation(double x, double y, Title title) { this(x, y, title, RectangleAnchor.CENTER); } /** * Creates a new annotation to be displayed at the specified (x, y) * location. * * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). * @param title the title (<code>null</code> not permitted). * @param anchor the title anchor (<code>null</code> not permitted). */ public XYTitleAnnotation(double x, double y, Title title, RectangleAnchor anchor) { super(); if (title == null) { throw new IllegalArgumentException("Null 'title' argument."); } if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.coordinateType = XYCoordinateType.RELATIVE; this.x = x; this.y = y; this.maxWidth = 0.0; this.maxHeight = 0.0; this.title = title; this.anchor = anchor; } /** * Returns the coordinate type (set in the constructor). * * @return The coordinate type (never <code>null</code>). */ public XYCoordinateType getCoordinateType() { return this.coordinateType; } /** * Returns the x-coordinate for the annotation. * * @return The x-coordinate. */ public double getX() { return this.x; } /** * Returns the y-coordinate for the annotation. * * @return The y-coordinate. */ public double getY() { return this.y; } /** * Returns the title for the annotation. * * @return The title. */ public Title getTitle() { return this.title; } /** * Returns the title anchor for the annotation. * * @return The title anchor. */ public RectangleAnchor getTitleAnchor() { return this.anchor; } /** * Returns the maximum width. * * @return The maximum width. */ public double getMaxWidth() { return this.maxWidth; } /** * Sets the maximum width and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param max the maximum width (0.0 or less means no maximum). */ public void setMaxWidth(double max) { this.maxWidth = max; fireAnnotationChanged(); } /** * Returns the maximum height. * * @return The maximum height. */ public double getMaxHeight() { return this.maxHeight; } /** * Sets the maximum height and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param max the maximum height. */ public void setMaxHeight(double max) { this.maxHeight = max; fireAnnotationChanged(); } /** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( rangeAxisLocation, orientation); Range xRange = domainAxis.getRange(); Range yRange = rangeAxis.getRange(); double anchorX = 0.0; double anchorY = 0.0; if (this.coordinateType == XYCoordinateType.RELATIVE) { anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); } else { anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); } float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } double maxW = dataArea.getWidth(); double maxH = dataArea.getHeight(); if (this.coordinateType == XYCoordinateType.RELATIVE) { if (this.maxWidth > 0.0) { maxW = maxW * this.maxWidth; } if (this.maxHeight > 0.0) { maxH = maxH * this.maxHeight; } } if (this.coordinateType == XYCoordinateType.DATA) { maxW = this.maxWidth; maxH = this.maxHeight; } RectangleConstraint rc = new RectangleConstraint( new Range(0, maxW), new Range(0, maxH)); Size2D size = this.title.arrange(g2, rc); Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height); Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor); xx = xx - (float) anchorPoint.getX(); yy = yy - (float) anchorPoint.getY(); titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); BlockParams p = new BlockParams(); if (info != null) { if (info.getOwner().getEntityCollection() != null) { p.setGenerateEntities(true); } } Object result = this.title.draw(g2, titleRect, p); if (info != null) { if (result instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) result; info.getOwner().getEntityCollection().addAll( ebr.getEntityCollection()); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url); } } } /** * Tests this object for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYTitleAnnotation)) { return false; } XYTitleAnnotation that = (XYTitleAnnotation) obj; if (this.coordinateType != that.coordinateType) { return false; } if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } if (this.maxWidth != that.maxWidth) { return false; } if (this.maxHeight != that.maxHeight) { return false; } if (!ObjectUtilities.equal(this.title, that.title)) { return false; } if (!this.anchor.equals(that.anchor)) { return false; } return super.equals(obj); } /** * Returns a hash code for this object. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = HashUtilities.hashCode(result, this.anchor); result = HashUtilities.hashCode(result, this.coordinateType); result = HashUtilities.hashCode(result, this.x); result = HashUtilities.hashCode(result, this.y); result = HashUtilities.hashCode(result, this.maxWidth); result = HashUtilities.hashCode(result, this.maxHeight); result = HashUtilities.hashCode(result, this.title); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } }
13,072
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYBoxAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYBoxAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * XYBoxAnnotation.java * -------------------- * (C) Copyright 2005-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (see patch 2809117); * * Changes: * -------- * 19-Jan-2005 : Version 1 (DG); * 06-Jun-2005 : Fixed equals() method to handle GradientPaint (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.util.SerialUtilities; /** * A box annotation that can be placed on an {@link XYPlot}. The * box coordinates are specified in data space. */ public class XYBoxAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 6764703772526757457L; /** The lower x-coordinate. */ private double x0; /** The lower y-coordinate. */ private double y0; /** The upper x-coordinate. */ private double x1; /** The upper y-coordinate. */ private double y1; /** The stroke used to draw the box outline. */ private transient Stroke stroke; /** The paint used to draw the box outline. */ private transient Paint outlinePaint; /** The paint used to fill the box. */ private transient Paint fillPaint; /** * Creates a new annotation (where, by default, the box is drawn * with a black outline). * * @param x0 the lower x-coordinate of the box (in data space). * @param y0 the lower y-coordinate of the box (in data space). * @param x1 the upper x-coordinate of the box (in data space). * @param y1 the upper y-coordinate of the box (in data space). */ public XYBoxAnnotation(double x0, double y0, double x1, double y1) { this(x0, y0, x1, y1, new BasicStroke(1.0f), Color.BLACK); } /** * Creates a new annotation where the box is drawn as an outline using * the specified <code>stroke</code> and <code>outlinePaint</code>. * * @param x0 the lower x-coordinate of the box (in data space). * @param y0 the lower y-coordinate of the box (in data space). * @param x1 the upper x-coordinate of the box (in data space). * @param y1 the upper y-coordinate of the box (in data space). * @param stroke the shape stroke (<code>null</code> permitted). * @param outlinePaint the shape color (<code>null</code> permitted). */ public XYBoxAnnotation(double x0, double y0, double x1, double y1, Stroke stroke, Paint outlinePaint) { this(x0, y0, x1, y1, stroke, outlinePaint, null); } /** * Creates a new annotation. * * @param x0 the lower x-coordinate of the box (in data space). * @param y0 the lower y-coordinate of the box (in data space). * @param x1 the upper x-coordinate of the box (in data space). * @param y1 the upper y-coordinate of the box (in data space). * @param stroke the shape stroke (<code>null</code> permitted). * @param outlinePaint the shape color (<code>null</code> permitted). * @param fillPaint the paint used to fill the shape (<code>null</code> * permitted). */ public XYBoxAnnotation(double x0, double y0, double x1, double y1, Stroke stroke, Paint outlinePaint, Paint fillPaint) { super(); this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1; this.stroke = stroke; this.outlinePaint = outlinePaint; this.fillPaint = fillPaint; } /** * Draws the annotation. This method is usually called by the * {@link XYPlot} class, you shouldn't need to call it directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info the plot rendering info. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); double transX0 = domainAxis.valueToJava2D(this.x0, dataArea, domainEdge); double transY0 = rangeAxis.valueToJava2D(this.y0, dataArea, rangeEdge); double transX1 = domainAxis.valueToJava2D(this.x1, dataArea, domainEdge); double transY1 = rangeAxis.valueToJava2D(this.y1, dataArea, rangeEdge); Rectangle2D box = null; if (orientation == PlotOrientation.HORIZONTAL) { box = new Rectangle2D.Double(transY0, transX1, transY1 - transY0, transX0 - transX1); } else if (orientation == PlotOrientation.VERTICAL) { box = new Rectangle2D.Double(transX0, transY1, transX1 - transX0, transY0 - transY1); } if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(box); } if (this.stroke != null && this.outlinePaint != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(box); } addEntity(info, box, rendererIndex, getToolTipText(), getURL()); } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } // now try to reject equality if (!super.equals(obj)) { return false; } if (!(obj instanceof XYBoxAnnotation)) { return false; } XYBoxAnnotation that = (XYBoxAnnotation) obj; if (!(this.x0 == that.x0)) { return false; } if (!(this.y0 == that.y0)) { return false; } if (!(this.x1 == that.x1)) { return false; } if (!(this.y1 == that.y1)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!PaintUtilities.equal(this.fillPaint, that.fillPaint)) { return false; } // seem to be the same return true; } /** * Returns a hash code. * * @return A hash code. */ @Override public int hashCode() { int result; long temp; temp = Double.doubleToLongBits(this.x0); result = (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.x1); result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y0); result = 29 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y1); result = 29 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone. * * @return A clone. * * @throws CloneNotSupportedException not thrown by this class, but may be * by subclasses. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.stroke, stream); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writePaint(this.fillPaint, stream); } /** * Provides serialization support. * * @param stream the input stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.stroke = SerialUtilities.readStroke(stream); this.outlinePaint = SerialUtilities.readPaint(stream); this.fillPaint = SerialUtilities.readPaint(stream); } }
10,950
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryLineAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/CategoryLineAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * CategoryLineAnnotation.java * --------------------------- * (C) Copyright 2005-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 29-Jul-2005 : Version 1, based on CategoryTextAnnotation (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Mar-2007 : Reimplemented hashCode() (DG); * 23-Apr-2008 : Implemented PublicCloneable (DG); * 24-Jun-2009 : Now extends AbstractAnnotation (see patch 2809117 by PK) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.CategoryAnchor; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.category.CategoryDataset; /** * A line annotation that can be placed on a {@link CategoryPlot}. */ public class CategoryLineAnnotation extends AbstractAnnotation implements CategoryAnnotation, Cloneable, PublicCloneable, Serializable { /** For serialization. */ static final long serialVersionUID = 3477740483341587984L; /** The category for the start of the line. */ private Comparable category1; /** The value for the start of the line. */ private double value1; /** The category for the end of the line. */ private Comparable category2; /** The value for the end of the line. */ private double value2; /** The line color. */ private transient Paint paint = Color.BLACK; /** The line stroke. */ private transient Stroke stroke = new BasicStroke(1.0f); /** * Creates a new annotation that draws a line between (category1, value1) * and (category2, value2). * * @param category1 the category (<code>null</code> not permitted). * @param value1 the value. * @param category2 the category (<code>null</code> not permitted). * @param value2 the value. * @param paint the line color (<code>null</code> not permitted). * @param stroke the line stroke (<code>null</code> not permitted). */ public CategoryLineAnnotation(Comparable category1, double value1, Comparable category2, double value2, Paint paint, Stroke stroke) { super(); ParamChecks.nullNotPermitted(category1, "category1"); ParamChecks.nullNotPermitted(category2, "category2"); ParamChecks.nullNotPermitted(paint, "paint"); ParamChecks.nullNotPermitted(stroke, "stroke"); this.category1 = category1; this.value1 = value1; this.category2 = category2; this.value2 = value2; this.paint = paint; this.stroke = stroke; } /** * Returns the category for the start of the line. * * @return The category for the start of the line (never <code>null</code>). * * @see #setCategory1(Comparable) */ public Comparable getCategory1() { return this.category1; } /** * Sets the category for the start of the line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param category the category (<code>null</code> not permitted). * * @see #getCategory1() */ public void setCategory1(Comparable category) { if (category == null) { throw new IllegalArgumentException("Null 'category' argument."); } this.category1 = category; fireAnnotationChanged(); } /** * Returns the y-value for the start of the line. * * @return The y-value for the start of the line. * * @see #setValue1(double) */ public double getValue1() { return this.value1; } /** * Sets the y-value for the start of the line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param value the value. * * @see #getValue1() */ public void setValue1(double value) { this.value1 = value; fireAnnotationChanged(); } /** * Returns the category for the end of the line. * * @return The category for the end of the line (never <code>null</code>). * * @see #setCategory2(Comparable) */ public Comparable getCategory2() { return this.category2; } /** * Sets the category for the end of the line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param category the category (<code>null</code> not permitted). * * @see #getCategory2() */ public void setCategory2(Comparable category) { ParamChecks.nullNotPermitted(category, "category"); this.category2 = category; fireAnnotationChanged(); } /** * Returns the y-value for the end of the line. * * @return The y-value for the end of the line. * * @see #setValue2(double) */ public double getValue2() { return this.value2; } /** * Sets the y-value for the end of the line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param value the value. * * @see #getValue2() */ public void setValue2(double value) { this.value2 = value; fireAnnotationChanged(); } /** * Returns the paint used to draw the connecting line. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint used to draw the connecting line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; fireAnnotationChanged(); } /** * Returns the stroke used to draw the connecting line. * * @return The stroke (never <code>null</code>). * * @see #setStroke(Stroke) */ public Stroke getStroke() { return this.stroke; } /** * Sets the stroke used to draw the connecting line and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke() */ public void setStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.stroke = stroke; fireAnnotationChanged(); } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. */ @Override public void draw(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, CategoryAxis domainAxis, ValueAxis rangeAxis) { CategoryDataset dataset = plot.getDataset(); int catIndex1 = dataset.getColumnIndex(this.category1); int catIndex2 = dataset.getColumnIndex(this.category2); int catCount = dataset.getColumnCount(); double lineX1 = 0.0f; double lineY1 = 0.0f; double lineX2 = 0.0f; double lineY2 = 0.0f; PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); if (orientation == PlotOrientation.HORIZONTAL) { lineY1 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge); lineX1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge); lineY2 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge); lineX2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge); } else if (orientation == PlotOrientation.VERTICAL) { lineX1 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex1, catCount, dataArea, domainEdge); lineY1 = rangeAxis.valueToJava2D(this.value1, dataArea, rangeEdge); lineX2 = domainAxis.getCategoryJava2DCoordinate( CategoryAnchor.MIDDLE, catIndex2, catCount, dataArea, domainEdge); lineY2 = rangeAxis.valueToJava2D(this.value2, dataArea, rangeEdge); } g2.setPaint(this.paint); g2.setStroke(this.stroke); g2.drawLine((int) lineX1, (int) lineY1, (int) lineX2, (int) lineY2); } /** * Tests this object for equality with another. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CategoryLineAnnotation)) { return false; } CategoryLineAnnotation that = (CategoryLineAnnotation) obj; if (!this.category1.equals(that.getCategory1())) { return false; } if (this.value1 != that.getValue1()) { return false; } if (!this.category2.equals(that.getCategory2())) { return false; } if (this.value2 != that.getValue2()) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = 37 * result + this.category1.hashCode(); long temp = Double.doubleToLongBits(this.value1); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = 37 * result + this.category2.hashCode(); temp = Double.doubleToLongBits(this.value2); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); result = 37 * result + this.stroke.hashCode(); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writeStroke(this.stroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.stroke = SerialUtilities.readStroke(stream); } }
14,112
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYShapeAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYShapeAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * XYShapeAnnotation.java * ---------------------- * (C) Copyright 2003-2012, by Ondax, Inc. and Contributors. * * Original Author: Greg Steckman (for Ondax, Inc.); * Contributor(s): David Gilbert (for Object Refinery Limited); * Peter Kolb (patch 2809117); * * Changes: * -------- * 15-Aug-2003 : Version 1, adapted from * org.jfree.chart.annotations.XYLineAnnotation (GS); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 20-Apr-2004 : Added new constructor and fixed bug 934258 (DG); * 29-Sep-2004 : Added 'fillPaint' to allow for colored shapes, now extends * AbstractXYAnnotation to add tool tip and URL support, and * implemented equals() and Cloneable (DG); * 21-Jan-2005 : Modified constructor for consistency with other * constructors (DG); * 06-Jun-2005 : Fixed equals() method to handle GradientPaint (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 24-Oct-2006 : Calculate AffineTransform on shape's bounding rectangle * rather than sample points (0, 0) and (1, 1) (DG); * 06-Mar-2007 : Implemented hashCode() (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.AffineTransform; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.util.SerialUtilities; /** * A simple <code>Shape</code> annotation that can be placed on an * {@link XYPlot}. The shape coordinates are specified in data space. */ public class XYShapeAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -8553218317600684041L; /** The shape. */ private transient Shape shape; /** The stroke used to draw the shape's outline. */ private transient Stroke stroke; /** The paint used to draw the shape's outline. */ private transient Paint outlinePaint; /** The paint used to fill the shape. */ private transient Paint fillPaint; /** * Creates a new annotation (where, by default, the shape is drawn * with a black outline). * * @param shape the shape (coordinates in data space, <code>null</code> * not permitted). */ public XYShapeAnnotation(Shape shape) { this(shape, new BasicStroke(1.0f), Color.BLACK); } /** * Creates a new annotation where the shape is drawn as an outline using * the specified <code>stroke</code> and <code>outlinePaint</code>. * * @param shape the shape (<code>null</code> not permitted). * @param stroke the shape stroke (<code>null</code> permitted). * @param outlinePaint the shape color (<code>null</code> permitted). */ public XYShapeAnnotation(Shape shape, Stroke stroke, Paint outlinePaint) { this(shape, stroke, outlinePaint, null); } /** * Creates a new annotation. * * @param shape the shape (<code>null</code> not permitted). * @param stroke the shape stroke (<code>null</code> permitted). * @param outlinePaint the shape color (<code>null</code> permitted). * @param fillPaint the paint used to fill the shape (<code>null</code> * permitted. */ public XYShapeAnnotation(Shape shape, Stroke stroke, Paint outlinePaint, Paint fillPaint) { super(); if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } this.shape = shape; this.stroke = stroke; this.outlinePaint = outlinePaint; this.fillPaint = fillPaint; } /** * Draws the annotation. This method is usually called by the * {@link XYPlot} class, you shouldn't need to call it directly. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info the plot rendering info. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); // compute transform matrix elements via sample points. Assume no // rotation or shear. Rectangle2D bounds = this.shape.getBounds2D(); double x0 = bounds.getMinX(); double x1 = bounds.getMaxX(); double xx0 = domainAxis.valueToJava2D(x0, dataArea, domainEdge); double xx1 = domainAxis.valueToJava2D(x1, dataArea, domainEdge); double m00 = (xx1 - xx0) / (x1 - x0); double m02 = xx0 - x0 * m00; double y0 = bounds.getMaxY(); double y1 = bounds.getMinY(); double yy0 = rangeAxis.valueToJava2D(y0, dataArea, rangeEdge); double yy1 = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge); double m11 = (yy1 - yy0) / (y1 - y0); double m12 = yy0 - m11 * y0; // create transform & transform shape Shape s = null; if (orientation == PlotOrientation.HORIZONTAL) { AffineTransform t1 = new AffineTransform(0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f); AffineTransform t2 = new AffineTransform(m11, 0.0f, 0.0f, m00, m12, m02); s = t1.createTransformedShape(this.shape); s = t2.createTransformedShape(s); } else if (orientation == PlotOrientation.VERTICAL) { AffineTransform t = new AffineTransform(m00, 0, 0, m11, m02, m12); s = t.createTransformedShape(this.shape); } if (this.fillPaint != null) { g2.setPaint(this.fillPaint); g2.fill(s); } if (this.stroke != null && this.outlinePaint != null) { g2.setPaint(this.outlinePaint); g2.setStroke(this.stroke); g2.draw(s); } addEntity(info, s, rendererIndex, getToolTipText(), getURL()); } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } // now try to reject equality if (!super.equals(obj)) { return false; } if (!(obj instanceof XYShapeAnnotation)) { return false; } XYShapeAnnotation that = (XYShapeAnnotation) obj; if (!this.shape.equals(that.shape)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!PaintUtilities.equal(this.fillPaint, that.fillPaint)) { return false; } // seem to be the same return true; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = 37 * result + this.shape.hashCode(); if (this.stroke != null) { result = 37 * result + this.stroke.hashCode(); } result = 37 * result + HashUtilities.hashCodeForPaint( this.outlinePaint); result = 37 * result + HashUtilities.hashCodeForPaint(this.fillPaint); return result; } /** * Returns a clone. * * @return A clone. * * @throws CloneNotSupportedException ???. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeShape(this.shape, stream); SerialUtilities.writeStroke(this.stroke, stream); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writePaint(this.fillPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.shape = SerialUtilities.readShape(stream); this.stroke = SerialUtilities.readStroke(stream); this.outlinePaint = SerialUtilities.readPaint(stream); this.fillPaint = SerialUtilities.readPaint(stream); } }
11,410
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYAnnotationBoundsInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYAnnotationBoundsInfo.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * XYAnnotationBoundsInfo.java * --------------------------- * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 10-Mar-2009 : Version 1 (DG); * */ package org.jfree.chart.annotations; import org.jfree.data.Range; /** * An interface that supplies information about the bounds of the annotation. * * @since 1.0.13 */ public interface XYAnnotationBoundsInfo { /** * Returns a flag that determines whether or not the annotation's * bounds should be taken into account for auto-range calculations on * the axes that the annotation is plotted against. * * @return A boolean. */ public boolean getIncludeInDataBounds(); /** * Returns the range of x-values (in data space) that the annotation * uses. * * @return The x-range. */ public Range getXRange(); /** * Returns the range of y-values (in data space) that the annotation * uses. * * @return The y-range. */ public Range getYRange(); }
2,396
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYTextAnnotation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/annotations/XYTextAnnotation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * XYTextAnnotation.java * --------------------- * (C) Copyright 2002-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Peter Kolb (patch 2809117); * * Changes: * -------- * 28-Aug-2002 : Version 1 (DG); * 07-Nov-2002 : Fixed errors reported by Checkstyle (DG); * 13-Jan-2003 : Reviewed Javadocs (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 02-Jul-2003 : Added new text alignment and rotation options (DG); * 19-Aug-2003 : Implemented Cloneable (DG); * 17-Jan-2003 : Added fix for bug 878706, where the annotation is placed * incorrectly for a plot with horizontal orientation (thanks to * Ed Yu for the fix) (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 26-Jan-2006 : Fixed equals() method (bug 1415480) (DG); * 06-Mar-2007 : Added argument checks, re-implemented hashCode() method (DG); * 12-Feb-2009 : Added background paint and outline paint/stroke (DG); * 01-Apr-2009 : Fixed bug in hotspot calculation (DG); * 24-Jun-2009 : Fire change events (see patch 2809117) (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.annotations; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.plot.Plot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.PlotRenderingInfo; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.SerialUtilities; /** * A text annotation that can be placed at a particular (x, y) location on an * {@link XYPlot}. */ public class XYTextAnnotation extends AbstractXYAnnotation implements Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -2946063342782506328L; /** The default font. */ public static final Font DEFAULT_FONT = new Font("SansSerif", Font.PLAIN, 10); /** The default paint. */ public static final Paint DEFAULT_PAINT = Color.BLACK; /** The default text anchor. */ public static final TextAnchor DEFAULT_TEXT_ANCHOR = TextAnchor.CENTER; /** The default rotation anchor. */ public static final TextAnchor DEFAULT_ROTATION_ANCHOR = TextAnchor.CENTER; /** The default rotation angle. */ public static final double DEFAULT_ROTATION_ANGLE = 0.0; /** The text. */ private String text; /** The font. */ private Font font; /** The paint. */ private transient Paint paint; /** The x-coordinate. */ private double x; /** The y-coordinate. */ private double y; /** The text anchor (to be aligned with (x, y)). */ private TextAnchor textAnchor; /** The rotation anchor. */ private TextAnchor rotationAnchor; /** The rotation angle. */ private double rotationAngle; /** * The background paint (possibly null). * * @since 1.0.13 */ private transient Paint backgroundPaint; /** * The flag that controls the visibility of the outline. * * @since 1.0.13 */ private boolean outlineVisible; /** * The outline paint (never null). * * @since 1.0.13 */ private transient Paint outlinePaint; /** * The outline stroke (never null). * * @since 1.0.13 */ private transient Stroke outlineStroke; /** * Creates a new annotation to be displayed at the given coordinates. The * coordinates are specified in data space (they will be converted to * Java2D space for display). * * @param text the text (<code>null</code> not permitted). * @param x the x-coordinate (in data space). * @param y the y-coordinate (in data space). */ public XYTextAnnotation(String text, double x, double y) { super(); if (text == null) { throw new IllegalArgumentException("Null 'text' argument."); } this.text = text; this.font = DEFAULT_FONT; this.paint = DEFAULT_PAINT; this.x = x; this.y = y; this.textAnchor = DEFAULT_TEXT_ANCHOR; this.rotationAnchor = DEFAULT_ROTATION_ANCHOR; this.rotationAngle = DEFAULT_ROTATION_ANGLE; // by default the outline and background won't be visible this.backgroundPaint = null; this.outlineVisible = false; this.outlinePaint = Color.BLACK; this.outlineStroke = new BasicStroke(0.5f); } /** * Returns the text for the annotation. * * @return The text (never <code>null</code>). * * @see #setText(String) */ public String getText() { return this.text; } /** * Sets the text for the annotation. * * @param text the text (<code>null</code> not permitted). * * @see #getText() */ public void setText(String text) { if (text == null) { throw new IllegalArgumentException("Null 'text' argument."); } this.text = text; } /** * Returns the font for the annotation. * * @return The font (never <code>null</code>). * * @see #setFont(Font) */ public Font getFont() { return this.font; } /** * Sets the font for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getFont() */ public void setFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.font = font; fireAnnotationChanged(); } /** * Returns the paint for the annotation. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; fireAnnotationChanged(); } /** * Returns the text anchor. * * @return The text anchor (never <code>null</code>). * * @see #setTextAnchor(TextAnchor) */ public TextAnchor getTextAnchor() { return this.textAnchor; } /** * Sets the text anchor (the point on the text bounding rectangle that is * aligned to the (x, y) coordinate of the annotation) and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param anchor the anchor point (<code>null</code> not permitted). * * @see #getTextAnchor() */ public void setTextAnchor(TextAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.textAnchor = anchor; fireAnnotationChanged(); } /** * Returns the rotation anchor. * * @return The rotation anchor point (never <code>null</code>). * * @see #setRotationAnchor(TextAnchor) */ public TextAnchor getRotationAnchor() { return this.rotationAnchor; } /** * Sets the rotation anchor point and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getRotationAnchor() */ public void setRotationAnchor(TextAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.rotationAnchor = anchor; fireAnnotationChanged(); } /** * Returns the rotation angle. * * @return The rotation angle. * * @see #setRotationAngle(double) */ public double getRotationAngle() { return this.rotationAngle; } /** * Sets the rotation angle and sends an {@link AnnotationChangeEvent} to * all registered listeners. The angle is measured clockwise in radians. * * @param angle the angle (in radians). * * @see #getRotationAngle() */ public void setRotationAngle(double angle) { this.rotationAngle = angle; fireAnnotationChanged(); } /** * Returns the x coordinate for the text anchor point (measured against the * domain axis). * * @return The x coordinate (in data space). * * @see #setX(double) */ public double getX() { return this.x; } /** * Sets the x coordinate for the text anchor point (measured against the * domain axis) and sends an {@link AnnotationChangeEvent} to all * registered listeners. * * @param x the x coordinate (in data space). * * @see #getX() */ public void setX(double x) { this.x = x; fireAnnotationChanged(); } /** * Returns the y coordinate for the text anchor point (measured against the * range axis). * * @return The y coordinate (in data space). * * @see #setY(double) */ public double getY() { return this.y; } /** * Sets the y coordinate for the text anchor point (measured against the * range axis) and sends an {@link AnnotationChangeEvent} to all registered * listeners. * * @param y the y coordinate. * * @see #getY() */ public void setY(double y) { this.y = y; fireAnnotationChanged(); } /** * Returns the background paint for the annotation. * * @return The background paint (possibly <code>null</code>). * * @see #setBackgroundPaint(Paint) * * @since 1.0.13 */ public Paint getBackgroundPaint() { return this.backgroundPaint; } /** * Sets the background paint for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getBackgroundPaint() * * @since 1.0.13 */ public void setBackgroundPaint(Paint paint) { this.backgroundPaint = paint; fireAnnotationChanged(); } /** * Returns the outline paint for the annotation. * * @return The outline paint (never <code>null</code>). * * @see #setOutlinePaint(Paint) * * @since 1.0.13 */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Sets the outline paint for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getOutlinePaint() * * @since 1.0.13 */ public void setOutlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.outlinePaint = paint; fireAnnotationChanged(); } /** * Returns the outline stroke for the annotation. * * @return The outline stroke (never <code>null</code>). * * @see #setOutlineStroke(Stroke) * * @since 1.0.13 */ public Stroke getOutlineStroke() { return this.outlineStroke; } /** * Sets the outline stroke for the annotation and sends an * {@link AnnotationChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getOutlineStroke() * * @since 1.0.13 */ public void setOutlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.outlineStroke = stroke; fireAnnotationChanged(); } /** * Returns the flag that controls whether or not the outline is drawn. * * @return A boolean. * * @since 1.0.13 */ public boolean isOutlineVisible() { return this.outlineVisible; } /** * Sets the flag that controls whether or not the outline is drawn and * sends an {@link AnnotationChangeEvent} to all registered listeners. * * @param visible the new flag value. * * @since 1.0.13 */ public void setOutlineVisible(boolean visible) { this.outlineVisible = visible; fireAnnotationChanged(); } /** * Draws the annotation. * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info an optional info object that will be populated with * entity information. */ @Override public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( plot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation( plot.getRangeAxisLocation(), orientation); float anchorX = (float) domainAxis.valueToJava2D( this.x, dataArea, domainEdge); float anchorY = (float) rangeAxis.valueToJava2D( this.y, dataArea, rangeEdge); if (orientation == PlotOrientation.HORIZONTAL) { float tempAnchor = anchorX; anchorX = anchorY; anchorY = tempAnchor; } g2.setFont(getFont()); Shape hotspot = TextUtilities.calculateRotatedStringBounds( getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.backgroundPaint != null) { g2.setPaint(this.backgroundPaint); g2.fill(hotspot); } g2.setPaint(getPaint()); TextUtilities.drawRotatedString(getText(), g2, anchorX, anchorY, getTextAnchor(), getRotationAngle(), getRotationAnchor()); if (this.outlineVisible) { g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(hotspot); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, hotspot, rendererIndex, toolTip, url); } } /** * Tests this annotation for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYTextAnnotation)) { return false; } XYTextAnnotation that = (XYTextAnnotation) obj; if (!this.text.equals(that.text)) { return false; } if (this.x != that.x) { return false; } if (this.y != that.y) { return false; } if (!this.font.equals(that.font)) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!this.rotationAnchor.equals(that.rotationAnchor)) { return false; } if (this.rotationAngle != that.rotationAngle) { return false; } if (!this.textAnchor.equals(that.textAnchor)) { return false; } if (this.outlineVisible != that.outlineVisible) { return false; } if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!(this.outlineStroke.equals(that.outlineStroke))) { return false; } return super.equals(obj); } /** * Returns a hash code for the object. * * @return A hash code. */ @Override public int hashCode() { int result = 193; result = 37 * this.text.hashCode(); result = 37 * this.font.hashCode(); result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); long temp = Double.doubleToLongBits(this.x); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.y); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = 37 * result + this.textAnchor.hashCode(); result = 37 * result + this.rotationAnchor.hashCode(); temp = Double.doubleToLongBits(this.rotationAngle); result = 37 * result + (int) (temp ^ (temp >>> 32)); return result; } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException if the annotation can't be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writePaint(this.backgroundPaint, stream); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writeStroke(this.outlineStroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.backgroundPaint = SerialUtilities.readPaint(stream); this.outlinePaint = SerialUtilities.readPaint(stream); this.outlineStroke = SerialUtilities.readStroke(stream); } }
20,851
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BlockFrame.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/BlockFrame.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * BlockFrame.java * --------------- * (C) Copyright 2007-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 16-Mar-2007 : Version 1 (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.PublicCloneable; /** * A block frame is a type of border that can be drawn around the outside of * any {@link AbstractBlock}. Classes that implement this interface should * implement {@link PublicCloneable} OR be immutable. * * @since 1.0.5 */ public interface BlockFrame { /** * Returns the space reserved for the border. * * @return The space (never <code>null</code>). */ public RectangleInsets getInsets(); /** * Draws the border by filling in the reserved space (in black). * * @param g2 the graphics device. * @param area the area. */ public void draw(Graphics2D g2, Rectangle2D area); }
2,384
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/package-info.java
/** * Blocks and layout classes used extensively by the {@link org.jfree.chart.title.LegendTitle} class. */ package org.jfree.chart.block;
141
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Block.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/Block.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------- * Block.java * ---------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 08-Feb-2005 : Added ID (DG); * 20-Apr-2005 : Added a new draw() method that can accept params * and return results (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import org.jfree.chart.ui.Drawable; import org.jfree.chart.ui.Size2D; /** * A block is an arbitrary item that can be drawn (in Java2D space) within a * rectangular area, has a preferred size, and can be arranged by an * {@link Arrangement} manager. */ public interface Block extends Drawable { /** * Returns an ID for the block. * * @return An ID. */ public String getID(); /** * Sets the ID for the block. * * @param id the ID. */ public void setID(String id); /** * Arranges the contents of the block, with no constraints, and returns * the block size. * * @param g2 the graphics device. * * @return The size of the block. */ public Size2D arrange(Graphics2D g2); /** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ public Size2D arrange(Graphics2D g2, RectangleConstraint constraint); /** * Returns the current bounds of the block. * * @return The bounds. */ public Rectangle2D getBounds(); /** * Sets the bounds of the block. * * @param bounds the bounds. */ public void setBounds(Rectangle2D bounds); /** * Draws the block within the specified area. Refer to the documentation * for the implementing class for information about the <code>params</code> * and return value supported. * * @param g2 the graphics device. * @param area the area. * @param params optional parameters (<code>null</code> permitted). * * @return An optional return value (possibly <code>null</code>). */ public Object draw(Graphics2D g2, Rectangle2D area, Object params); }
3,735
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
EntityBlockResult.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/EntityBlockResult.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * EntityBlockResult.java * ---------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 19-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart.block; import org.jfree.chart.entity.EntityCollection; /** * Provides access to the {@link EntityCollection} generated when a block is * drawn. */ public interface EntityBlockResult { /** * Returns the entity collection. * * @return An entity collection (possibly <code>null</code>). */ public EntityCollection getEntityCollection(); }
1,914
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractBlock.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/AbstractBlock.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * AbstractBlock.java * ------------------ * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 02-Feb-2005 : Added accessor methods for margin (DG); * 04-Feb-2005 : Added equals() method and implemented Serializable (DG); * 03-May-2005 : Added null argument checks (DG); * 06-May-2005 : Added convenience methods for setting margin, border and * padding (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 16-Mar-2007 : Changed border from BlockBorder to BlockFrame, updated * equals(), and implemented Cloneable (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.Range; /** * A convenience class for creating new classes that implement * the {@link Block} interface. */ public class AbstractBlock implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 7689852412141274563L; /** The id for the block. */ private String id; /** The margin around the outside of the block. */ private RectangleInsets margin; /** The frame (or border) for the block. */ private BlockFrame frame; /** The padding between the block content and the border. */ private RectangleInsets padding; /** * The natural width of the block (may be overridden if there are * constraints in sizing). */ private double width; /** * The natural height of the block (may be overridden if there are * constraints in sizing). */ private double height; /** * The current bounds for the block (position of the block in Java2D space). */ private transient Rectangle2D bounds; /** * Creates a new block. */ protected AbstractBlock() { this.id = null; this.width = 0.0; this.height = 0.0; this.bounds = new Rectangle2D.Float(); this.margin = RectangleInsets.ZERO_INSETS; this.frame = BlockBorder.NONE; this.padding = RectangleInsets.ZERO_INSETS; } /** * Returns the id. * * @return The id (possibly <code>null</code>). * * @see #setID(String) */ public String getID() { return this.id; } /** * Sets the id for the block. * * @param id the id (<code>null</code> permitted). * * @see #getID() */ public void setID(String id) { this.id = id; } /** * Returns the natural width of the block, if this is known in advance. * The actual width of the block may be overridden if layout constraints * make this necessary. * * @return The width. * * @see #setWidth(double) */ public double getWidth() { return this.width; } /** * Sets the natural width of the block, if this is known in advance. * * @param width the width (in Java2D units) * * @see #getWidth() */ public void setWidth(double width) { this.width = width; } /** * Returns the natural height of the block, if this is known in advance. * The actual height of the block may be overridden if layout constraints * make this necessary. * * @return The height. * * @see #setHeight(double) */ public double getHeight() { return this.height; } /** * Sets the natural width of the block, if this is known in advance. * * @param height the width (in Java2D units) * * @see #getHeight() */ public void setHeight(double height) { this.height = height; } /** * Returns the margin. * * @return The margin (never <code>null</code>). * * @see #getMargin() */ public RectangleInsets getMargin() { return this.margin; } /** * Sets the margin (use {@link RectangleInsets#ZERO_INSETS} for no * padding). * * @param margin the margin (<code>null</code> not permitted). * * @see #getMargin() */ public void setMargin(RectangleInsets margin) { if (margin == null) { throw new IllegalArgumentException("Null 'margin' argument."); } this.margin = margin; } /** * Sets the margin. * * @param top the top margin. * @param left the left margin. * @param bottom the bottom margin. * @param right the right margin. * * @see #getMargin() */ public void setMargin(double top, double left, double bottom, double right) { setMargin(new RectangleInsets(top, left, bottom, right)); } /** * Sets a black border with the specified line widths. * * @param top the top border line width. * @param left the left border line width. * @param bottom the bottom border line width. * @param right the right border line width. */ public void setBorder(double top, double left, double bottom, double right) { setFrame(new BlockBorder(top, left, bottom, right)); } /** * Returns the current frame (border). * * @return The frame. * * @since 1.0.5 * @see #setFrame(BlockFrame) */ public BlockFrame getFrame() { return this.frame; } /** * Sets the frame (or border). * * @param frame the frame (<code>null</code> not permitted). * * @since 1.0.5 * @see #getFrame() */ public void setFrame(BlockFrame frame) { if (frame == null) { throw new IllegalArgumentException("Null 'frame' argument."); } this.frame = frame; } /** * Returns the padding. * * @return The padding (never <code>null</code>). * * @see #setPadding(RectangleInsets) */ public RectangleInsets getPadding() { return this.padding; } /** * Sets the padding (use {@link RectangleInsets#ZERO_INSETS} for no * padding). * * @param padding the padding (<code>null</code> not permitted). * * @see #getPadding() */ public void setPadding(RectangleInsets padding) { if (padding == null) { throw new IllegalArgumentException("Null 'padding' argument."); } this.padding = padding; } /** * Sets the padding. * * @param top the top padding. * @param left the left padding. * @param bottom the bottom padding. * @param right the right padding. */ public void setPadding(double top, double left, double bottom, double right) { setPadding(new RectangleInsets(top, left, bottom, right)); } /** * Returns the x-offset for the content within the block. * * @return The x-offset. * * @see #getContentYOffset() */ public double getContentXOffset() { return this.margin.getLeft() + this.frame.getInsets().getLeft() + this.padding.getLeft(); } /** * Returns the y-offset for the content within the block. * * @return The y-offset. * * @see #getContentXOffset() */ public double getContentYOffset() { return this.margin.getTop() + this.frame.getInsets().getTop() + this.padding.getTop(); } /** * Arranges the contents of the block, with no constraints, and returns * the block size. * * @param g2 the graphics device. * * @return The block size (in Java2D units, never <code>null</code>). */ public Size2D arrange(Graphics2D g2) { return arrange(g2, RectangleConstraint.NONE); } /** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { Size2D base = new Size2D(getWidth(), getHeight()); return constraint.calculateConstrainedSize(base); } /** * Returns the current bounds of the block. * * @return The bounds. * * @see #setBounds(Rectangle2D) */ public Rectangle2D getBounds() { return this.bounds; } /** * Sets the bounds of the block. * * @param bounds the bounds (<code>null</code> not permitted). * * @see #getBounds() */ public void setBounds(Rectangle2D bounds) { if (bounds == null) { throw new IllegalArgumentException("Null 'bounds' argument."); } this.bounds = bounds; } /** * Calculate the width available for content after subtracting * the margin, border and padding space from the specified fixed * width. * * @param fixedWidth the fixed width. * * @return The available space. * * @see #trimToContentHeight(double) */ protected double trimToContentWidth(double fixedWidth) { double result = this.margin.trimWidth(fixedWidth); result = this.frame.getInsets().trimWidth(result); result = this.padding.trimWidth(result); return Math.max(result, 0.0); } /** * Calculate the height available for content after subtracting * the margin, border and padding space from the specified fixed * height. * * @param fixedHeight the fixed height. * * @return The available space. * * @see #trimToContentWidth(double) */ protected double trimToContentHeight(double fixedHeight) { double result = this.margin.trimHeight(fixedHeight); result = this.frame.getInsets().trimHeight(result); result = this.padding.trimHeight(result); return Math.max(result, 0.0); } /** * Returns a constraint for the content of this block that will result in * the bounds of the block matching the specified constraint. * * @param c the outer constraint (<code>null</code> not permitted). * * @return The content constraint. */ protected RectangleConstraint toContentConstraint(RectangleConstraint c) { if (c == null) { throw new IllegalArgumentException("Null 'c' argument."); } if (c.equals(RectangleConstraint.NONE)) { return c; } double w = c.getWidth(); Range wr = c.getWidthRange(); double h = c.getHeight(); Range hr = c.getHeightRange(); double ww = trimToContentWidth(w); double hh = trimToContentHeight(h); Range wwr = trimToContentWidth(wr); Range hhr = trimToContentHeight(hr); return new RectangleConstraint( ww, wwr, c.getWidthConstraintType(), hh, hhr, c.getHeightConstraintType() ); } private Range trimToContentWidth(Range r) { if (r == null) { return null; } double lowerBound = 0.0; double upperBound = Double.POSITIVE_INFINITY; if (r.getLowerBound() > 0.0) { lowerBound = trimToContentWidth(r.getLowerBound()); } if (r.getUpperBound() < Double.POSITIVE_INFINITY) { upperBound = trimToContentWidth(r.getUpperBound()); } return new Range(lowerBound, upperBound); } private Range trimToContentHeight(Range r) { if (r == null) { return null; } double lowerBound = 0.0; double upperBound = Double.POSITIVE_INFINITY; if (r.getLowerBound() > 0.0) { lowerBound = trimToContentHeight(r.getLowerBound()); } if (r.getUpperBound() < Double.POSITIVE_INFINITY) { upperBound = trimToContentHeight(r.getUpperBound()); } return new Range(lowerBound, upperBound); } /** * Adds the margin, border and padding to the specified content width. * * @param contentWidth the content width. * * @return The adjusted width. */ protected double calculateTotalWidth(double contentWidth) { double result = contentWidth; result = this.padding.extendWidth(result); result = this.frame.getInsets().extendWidth(result); result = this.margin.extendWidth(result); return result; } /** * Adds the margin, border and padding to the specified content height. * * @param contentHeight the content height. * * @return The adjusted height. */ protected double calculateTotalHeight(double contentHeight) { double result = contentHeight; result = this.padding.extendHeight(result); result = this.frame.getInsets().extendHeight(result); result = this.margin.extendHeight(result); return result; } /** * Reduces the specified area by the amount of space consumed * by the margin. * * @param area the area (<code>null</code> not permitted). * * @return The trimmed area. */ protected Rectangle2D trimMargin(Rectangle2D area) { // defer argument checking... this.margin.trim(area); return area; } /** * Reduces the specified area by the amount of space consumed * by the border. * * @param area the area (<code>null</code> not permitted). * * @return The trimmed area. */ protected Rectangle2D trimBorder(Rectangle2D area) { // defer argument checking... this.frame.getInsets().trim(area); return area; } /** * Reduces the specified area by the amount of space consumed * by the padding. * * @param area the area (<code>null</code> not permitted). * * @return The trimmed area. */ protected Rectangle2D trimPadding(Rectangle2D area) { // defer argument checking... this.padding.trim(area); return area; } /** * Draws the border around the perimeter of the specified area. * * @param g2 the graphics device. * @param area the area. */ protected void drawBorder(Graphics2D g2, Rectangle2D area) { this.frame.draw(g2, area); } /** * Tests this block for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof AbstractBlock)) { return false; } AbstractBlock that = (AbstractBlock) obj; if (!ObjectUtilities.equal(this.id, that.id)) { return false; } if (!this.frame.equals(that.frame)) { return false; } if (!this.bounds.equals(that.bounds)) { return false; } if (!this.margin.equals(that.margin)) { return false; } if (!this.padding.equals(that.padding)) { return false; } if (this.height != that.height) { return false; } if (this.width != that.width) { return false; } return true; } /** * Returns a clone of this block. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem creating the * clone. */ @Override public Object clone() throws CloneNotSupportedException { AbstractBlock clone = (AbstractBlock) super.clone(); clone.bounds = (Rectangle2D) ShapeUtilities.clone(this.bounds); if (this.frame instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) this.frame; clone.frame = (BlockFrame) pc.clone(); } return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeShape(this.bounds, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.bounds = (Rectangle2D) SerialUtilities.readShape(stream); } }
18,713
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BlockContainer.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/BlockContainer.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * BlockContainer.java * ------------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 02-Feb-2005 : Added isEmpty() method (DG); * 04-Feb-2005 : Added equals(), clone() and implemented Serializable (DG); * 08-Feb-2005 : Updated for changes in RectangleConstraint (DG); * 20-Apr-2005 : Added new draw() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 20-Jul-2006 : Perform translation directly on drawing area, not via * Graphics2D (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.StandardEntityCollection; /** * A container for a collection of {@link Block} objects. The container uses * an {@link Arrangement} object to handle the position of each block. */ public class BlockContainer extends AbstractBlock implements Block, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 8199508075695195293L; /** The blocks within the container. */ private List<Block> blocks; /** The object responsible for laying out the blocks. */ private Arrangement arrangement; /** * Creates a new instance with default settings. */ public BlockContainer() { this(new BorderArrangement()); } /** * Creates a new instance with the specified arrangement. * * @param arrangement the arrangement manager (<code>null</code> not * permitted). */ public BlockContainer(Arrangement arrangement) { if (arrangement == null) { throw new IllegalArgumentException("Null 'arrangement' argument."); } this.arrangement = arrangement; this.blocks = new ArrayList<Block>(); } /** * Returns the arrangement (layout) manager for the container. * * @return The arrangement manager (never <code>null</code>). */ public Arrangement getArrangement() { return this.arrangement; } /** * Sets the arrangement (layout) manager. * * @param arrangement the arrangement (<code>null</code> not permitted). */ public void setArrangement(Arrangement arrangement) { if (arrangement == null) { throw new IllegalArgumentException("Null 'arrangement' argument."); } this.arrangement = arrangement; } /** * Returns <code>true</code> if there are no blocks in the container, and * <code>false</code> otherwise. * * @return A boolean. */ public boolean isEmpty() { return this.blocks.isEmpty(); } /** * Returns an unmodifiable list of the {@link Block} objects managed by * this arrangement. * * @return A list of blocks. */ public List<Block> getBlocks() { return Collections.unmodifiableList(this.blocks); } /** * Adds a block to the container. * * @param block the block (<code>null</code> permitted). */ public void add(Block block) { add(block, null); } /** * Adds a block to the container. * * @param block the block (<code>null</code> permitted). * @param key the key (<code>null</code> permitted). */ public void add(Block block, Object key) { this.blocks.add(block); this.arrangement.add(block, key); } /** * Clears all the blocks from the container. */ public void clear() { this.blocks.clear(); this.arrangement.clear(); } /** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { return this.arrangement.arrange(this, g2, constraint); } /** * Draws the container and all the blocks within it. * * @param g2 the graphics device. * @param area the area. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null); } /** * Draws the block within the specified area. * * @param g2 the graphics device. * @param area the area. * @param params passed on to blocks within the container * (<code>null</code> permitted). * * @return An instance of {@link EntityBlockResult}, or <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { // check if we need to collect chart entities from the container EntityBlockParams ebp; StandardEntityCollection sec = null; if (params instanceof EntityBlockParams) { ebp = (EntityBlockParams) params; if (ebp.getGenerateEntities()) { sec = new StandardEntityCollection(); } } Rectangle2D contentArea = (Rectangle2D) area.clone(); contentArea = trimMargin(contentArea); drawBorder(g2, contentArea); contentArea = trimBorder(contentArea); contentArea = trimPadding(contentArea); for (Block block : this.blocks) { Rectangle2D bounds = block.getBounds(); Rectangle2D drawArea = new Rectangle2D.Double(bounds.getX() + area.getX(), bounds.getY() + area.getY(), bounds.getWidth(), bounds.getHeight()); Object r = block.draw(g2, drawArea, params); if (sec != null) { if (r instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) r; EntityCollection ec = ebr.getEntityCollection(); sec.addAll(ec); } } } BlockResult result = null; if (sec != null) { result = new BlockResult(); result.setEntityCollection(sec); } return result; } /** * Tests this container for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BlockContainer)) { return false; } if (!super.equals(obj)) { return false; } BlockContainer that = (BlockContainer) obj; if (!this.arrangement.equals(that.arrangement)) { return false; } if (!this.blocks.equals(that.blocks)) { return false; } return true; } /** * Returns a clone of the container. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { BlockContainer clone = (BlockContainer) super.clone(); // TODO : complete this return clone; } }
9,012
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Arrangement.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/Arrangement.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * Arrangement.java * ---------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 11-Feb-2005 : Modified arrange() method to return Size2D (DG); * 22-Apr-2005 : Reordered arguments in arrange() method (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import org.jfree.chart.ui.Size2D; /** * An object that is responsible for arranging a collection of {@link Block}s * within a {@link BlockContainer}. */ public interface Arrangement { /** * Adds a block and a key which can be used to determine the position of * the block in the arrangement. This method is called by the container * (you don't need to call this method directly) and gives the arrangement * an opportunity to record the details if they are required. * * @param block the block. * @param key the key (<code>null</code> permitted). */ public void add(Block block, Object key); /** * Arranges the blocks within the specified container, subject to the given * constraint. * * @param container the container (<code>null</code> not permitted). * @param g2 the graphics device. * @param constraint the constraint. * * @return The container size after the arrangement. */ public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint); /** * Clears any cached layout information retained by the arrangement. */ public void clear(); }
3,002
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LineBorder.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/LineBorder.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * LineBorder.java * --------------- * (C) Copyright 2007-2012, by Christo Zietsman and Contributors. * * Original Author: Christo Zietsman; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes: * -------- * 16-Mar-2007 : Version 1, contributed by Christo Zietsman with * modifications by DG (DG); * 13-Jun-2007 : Don't draw if area doesn't have positive dimensions (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.SerialUtilities; /** * A line border for any {@link AbstractBlock}. * * @since 1.0.5 */ public class LineBorder implements BlockFrame, Serializable { /** For serialization. */ static final long serialVersionUID = 4630356736707233924L; /** The line color. */ private transient Paint paint; /** The line stroke. */ private transient Stroke stroke; /** The insets. */ private RectangleInsets insets; /** * Creates a default border. */ public LineBorder() { this(Color.BLACK, new BasicStroke(1.0f), new RectangleInsets(1.0, 1.0, 1.0, 1.0)); } /** * Creates a new border with the specified color. * * @param paint the color (<code>null</code> not permitted). * @param stroke the border stroke (<code>null</code> not permitted). * @param insets the insets (<code>null</code> not permitted). */ public LineBorder(Paint paint, Stroke stroke, RectangleInsets insets) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } if (insets == null) { throw new IllegalArgumentException("Null 'insets' argument."); } this.paint = paint; this.stroke = stroke; this.insets = insets; } /** * Returns the paint. * * @return The paint (never <code>null</code>). */ public Paint getPaint() { return this.paint; } /** * Returns the insets. * * @return The insets (never <code>null</code>). */ @Override public RectangleInsets getInsets() { return this.insets; } /** * Returns the stroke. * * @return The stroke (never <code>null</code>). */ public Stroke getStroke() { return this.stroke; } /** * Draws the border by filling in the reserved space (in black). * * @param g2 the graphics device. * @param area the area. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { double w = area.getWidth(); double h = area.getHeight(); // if the area has zero height or width, we shouldn't draw anything if (w <= 0.0 || h <= 0.0) { return; } double t = this.insets.calculateTopInset(h); double b = this.insets.calculateBottomInset(h); double l = this.insets.calculateLeftInset(w); double r = this.insets.calculateRightInset(w); double x = area.getX(); double y = area.getY(); double x0 = x + l / 2.0; double x1 = x + w - r / 2.0; double y0 = y + h - b / 2.0; double y1 = y + t / 2.0; g2.setPaint(getPaint()); g2.setStroke(getStroke()); Line2D line = new Line2D.Double(); if (t > 0.0) { line.setLine(x0, y1, x1, y1); g2.draw(line); } if (b > 0.0) { line.setLine(x0, y0, x1, y0); g2.draw(line); } if (l > 0.0) { line.setLine(x0, y0, x0, y1); g2.draw(line); } if (r > 0.0) { line.setLine(x1, y0, x1, y1); g2.draw(line); } } /** * Tests this border for equality with an arbitrary instance. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof LineBorder)) { return false; } LineBorder that = (LineBorder) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } if (!this.insets.equals(that.insets)) { return false; } return true; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writeStroke(this.stroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.stroke = SerialUtilities.readStroke(stream); } }
7,216
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CenterArrangement.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/CenterArrangement.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * CenterArrangement.java * ---------------------- * (C) Copyright 2005-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 08-Mar-2005 : Version 1 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 20-Jul-2006 : Set bounds of contained block when arranging (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.List; import org.jfree.chart.ui.Size2D; /** * Arranges a block in the center of its container. This class is immutable. */ public class CenterArrangement implements Arrangement, Serializable { /** For serialization. */ private static final long serialVersionUID = -353308149220382047L; /** * Creates a new instance. */ public CenterArrangement() { } /** * Adds a block to be managed by this instance. This method is usually * called by the {@link BlockContainer}, you shouldn't need to call it * directly. * * @param block the block. * @param key a key that controls the position of the block. */ @Override public void add(Block block, Object key) { // since the flow layout is relatively straightforward, // no information needs to be recorded here } /** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters. * * @param container the container whose items are being arranged. * @param g2 the graphics device. * @param constraint the size constraint. * * @return The size of the container after arrangement of the contents. */ @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { LengthConstraintType w = constraint.getWidthConstraintType(); LengthConstraintType h = constraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) { return arrangeNN(container, g2); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.FIXED) { if (h == LengthConstraintType.NONE) { return arrangeFN(container, g2, constraint); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.RANGE) { if (h == LengthConstraintType.NONE) { return arrangeRN(container, g2, constraint); } else if (h == LengthConstraintType.FIXED) { return arrangeRF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { return arrangeRR(container, g2, constraint); } } throw new IllegalArgumentException("Unknown LengthConstraintType."); } /** * Arranges the blocks in the container with a fixed width and no height * constraint. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size. */ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { List<Block> blocks = container.getBlocks(); Block b = blocks.get(0); Size2D s = b.arrange(g2, RectangleConstraint.NONE); double width = constraint.getWidth(); Rectangle2D bounds = new Rectangle2D.Double((width - s.width) / 2.0, 0.0, s.width, s.height); b.setBounds(bounds); return new Size2D((width - s.width) / 2.0, s.height); } /** * Arranges the blocks in the container with a fixed with and a range * constraint on the height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size following the arrangement. */ protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D s = arrangeFN(container, g2, constraint); if (constraint.getHeightRange().contains(s.height)) { return s; } else { RectangleConstraint c = constraint.toFixedHeight( constraint.getHeightRange().constrain(s.getHeight())); return arrangeFF(container, g2, c); } } /** * Arranges the blocks in the container with the overall height and width * specified as fixed constraints. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size following the arrangement. */ protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // TODO: implement this properly return arrangeFN(container, g2, constraint); } /** * Arranges the blocks with the overall width and height to fit within * specified ranges. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size after the arrangement. */ protected Size2D arrangeRR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, and see if this fits within // the required ranges... Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; // TODO: we didn't check the height yet } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().getUpperBound()); return arrangeFR(container, g2, c); } } /** * Arranges the blocks in the container with a range constraint on the * width and a fixed height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size following the arrangement. */ protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D s = arrangeNF(container, g2, constraint); if (constraint.getWidthRange().contains(s.width)) { return s; } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().constrain(s.getWidth())); return arrangeFF(container, g2, c); } } /** * Arranges the block with a range constraint on the width, and no * constraint on the height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size following the arrangement. */ protected Size2D arrangeRN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, then see if the width fits // within the required range...if not, call arrangeFN() at max width Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().getUpperBound()); return arrangeFN(container, g2, c); } } /** * Arranges the blocks without any constraints. This puts all blocks * into a single row. * * @param container the container. * @param g2 the graphics device. * * @return The size after the arrangement. */ protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) { List<Block> blocks = container.getBlocks(); Block b = blocks.get(0); Size2D s = b.arrange(g2, RectangleConstraint.NONE); b.setBounds(new Rectangle2D.Double(0.0, 0.0, s.width, s.height)); return new Size2D(s.width, s.height); } /** * Arranges the blocks with no width constraint and a fixed height * constraint. This puts all blocks into a single row. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size after the arrangement. */ protected Size2D arrangeNF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // TODO: for now we are ignoring the height constraint return arrangeNN(container, g2); } /** * Clears any cached information. */ @Override public void clear() { // no action required. } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CenterArrangement)) { return false; } return true; } }
11,550
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BlockResult.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/BlockResult.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * BlockResult.java * ---------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 19-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart.block; import org.jfree.chart.entity.EntityCollection; /** * Used to return results from the draw() method in the {@link Block} * class. */ public class BlockResult implements EntityBlockResult { /** The entities from the block. */ private EntityCollection entities; /** * Creates a new result instance. */ public BlockResult() { this.entities = null; } /** * Returns the collection of entities from the block. * * @return The entities. */ @Override public EntityCollection getEntityCollection() { return this.entities; } /** * Sets the entities for the block. * * @param entities the entities. */ public void setEntityCollection(EntityCollection entities) { this.entities = entities; } }
2,346
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
GridArrangement.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/GridArrangement.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * GridArrangement.java * -------------------- * (C) Copyright 2005-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 08-Feb-2005 : Version 1 (DG); * 03-Dec-2008 : Implemented missing methods, and fixed bugs reported in * patch 2370487 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.List; import org.jfree.chart.ui.Size2D; /** * Arranges blocks in a grid within their container. */ public class GridArrangement implements Arrangement, Serializable { /** For serialization. */ private static final long serialVersionUID = -2563758090144655938L; /** The rows. */ private int rows; /** The columns. */ private int columns; /** * Creates a new grid arrangement. * * @param rows the row count. * @param columns the column count. */ public GridArrangement(int rows, int columns) { this.rows = rows; this.columns = columns; } /** * Adds a block and a key which can be used to determine the position of * the block in the arrangement. This method is called by the container * (you don't need to call this method directly) and gives the arrangement * an opportunity to record the details if they are required. * * @param block the block. * @param key the key (<code>null</code> permitted). */ @Override public void add(Block block, Object key) { // can safely ignore } /** * Arranges the blocks within the specified container, subject to the given * constraint. * * @param container the container (<code>null</code> not permitted). * @param constraint the constraint. * @param g2 the graphics device. * * @return The size following the arrangement. */ @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { LengthConstraintType w = constraint.getWidthConstraintType(); LengthConstraintType h = constraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) { return arrangeNN(container, g2); } else if (h == LengthConstraintType.FIXED) { return arrangeNF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { // find optimum height, then map to range return arrangeNR(container, g2, constraint); } } else if (w == LengthConstraintType.FIXED) { if (h == LengthConstraintType.NONE) { // find optimum height return arrangeFN(container, g2, constraint); } else if (h == LengthConstraintType.FIXED) { return arrangeFF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { // find optimum height and map to range return arrangeFR(container, g2, constraint); } } else if (w == LengthConstraintType.RANGE) { // find optimum width and map to range if (h == LengthConstraintType.NONE) { // find optimum height return arrangeRN(container, g2, constraint); } else if (h == LengthConstraintType.FIXED) { // fixed width return arrangeRF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { return arrangeRR(container, g2, constraint); } } throw new RuntimeException("Should never get to here!"); } /** * Arranges the container with no constraint on the width or height. * * @param container the container (<code>null</code> not permitted). * @param g2 the graphics device. * * @return The size. */ protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) { double maxW = 0.0; double maxH = 0.0; List<Block> blocks = container.getBlocks(); for (Block b : blocks) { if (b != null) { Size2D s = b.arrange(g2, RectangleConstraint.NONE); maxW = Math.max(maxW, s.width); maxH = Math.max(maxH, s.height); } } double width = this.columns * maxW; double height = this.rows * maxH; RectangleConstraint c = new RectangleConstraint(width, height); return arrangeFF(container, g2, c); } /** * Arranges the container with a fixed overall width and height. * * @param container the container (<code>null</code> not permitted). * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The size following the arrangement. */ protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { double width = constraint.getWidth() / this.columns; double height = constraint.getHeight() / this.rows; List<Block> blocks = container.getBlocks(); for (int c = 0; c < this.columns; c++) { for (int r = 0; r < this.rows; r++) { int index = r * this.columns + c; if (index >= blocks.size()) { break; } Block b = blocks.get(index); if (b != null) { b.setBounds(new Rectangle2D.Double(c * width, r * height, width, height)); } } } return new Size2D(this.columns * width, this.rows * height); } /** * Arrange with a fixed width and a height within a given range. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedHeight(); Size2D size1 = arrange(container, g2, c1); if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; } else { double h = constraint.getHeightRange().constrain(size1.getHeight()); RectangleConstraint c2 = constraint.toFixedHeight(h); return arrange(container, g2, c2); } } /** * Arrange with a fixed height and a width within a given range. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedWidth(); Size2D size1 = arrange(container, g2, c1); if (constraint.getWidthRange().contains(size1.getWidth())) { return size1; } else { double w = constraint.getWidthRange().constrain(size1.getWidth()); RectangleConstraint c2 = constraint.toFixedWidth(w); return arrange(container, g2, c2); } } /** * Arrange with a fixed width and no height constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeRN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedWidth(); Size2D size1 = arrange(container, g2, c1); if (constraint.getWidthRange().contains(size1.getWidth())) { return size1; } else { double w = constraint.getWidthRange().constrain(size1.getWidth()); RectangleConstraint c2 = constraint.toFixedWidth(w); return arrange(container, g2, c2); } } /** * Arrange with a fixed height and no width constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeNR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint c1 = constraint.toUnconstrainedHeight(); Size2D size1 = arrange(container, g2, c1); if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; } else { double h = constraint.getHeightRange().constrain(size1.getHeight()); RectangleConstraint c2 = constraint.toFixedHeight(h); return arrange(container, g2, c2); } } /** * Arrange with ranges for both the width and height constraints. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size of the arrangement. */ protected Size2D arrangeRR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D size1 = arrange(container, g2, RectangleConstraint.NONE); if (constraint.getWidthRange().contains(size1.getWidth())) { if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; } else { // width is OK, but height must be constrained double h = constraint.getHeightRange().constrain( size1.getHeight()); RectangleConstraint cc = new RectangleConstraint( size1.getWidth(), h); return arrangeFF(container, g2, cc); } } else { if (constraint.getHeightRange().contains(size1.getHeight())) { // height is OK, but width must be constrained double w = constraint.getWidthRange().constrain( size1.getWidth()); RectangleConstraint cc = new RectangleConstraint(w, size1.getHeight()); return arrangeFF(container, g2, cc); } else { double w = constraint.getWidthRange().constrain( size1.getWidth()); double h = constraint.getHeightRange().constrain( size1.getHeight()); RectangleConstraint cc = new RectangleConstraint(w, h); return arrangeFF(container, g2, cc); } } } /** * Arrange with a fixed width and a height within a given range. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size of the arrangement. */ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { double width = constraint.getWidth() / this.columns; RectangleConstraint bc = constraint.toFixedWidth(width); List<Block> blocks = container.getBlocks(); double maxH = 0.0; for (int r = 0; r < this.rows; r++) { for (int c = 0; c < this.columns; c++) { int index = r * this.columns + c; if (index >= blocks.size()) { break; } Block b = blocks.get(index); if (b != null) { Size2D s = b.arrange(g2, bc); maxH = Math.max(maxH, s.getHeight()); } } } RectangleConstraint cc = constraint.toFixedHeight(maxH * this.rows); return arrange(container, g2, cc); } /** * Arrange with a fixed height and no constraint for the width. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size of the arrangement. */ protected Size2D arrangeNF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { double height = constraint.getHeight() / this.rows; RectangleConstraint bc = constraint.toFixedHeight(height); List<Block> blocks = container.getBlocks(); double maxW = 0.0; for (int r = 0; r < this.rows; r++) { for (int c = 0; c < this.columns; c++) { int index = r * this.columns + c; if (index >= blocks.size()) { break; } Block b = blocks.get(index); if (b != null) { Size2D s = b.arrange(g2, bc); maxW = Math.max(maxW, s.getWidth()); } } } RectangleConstraint cc = constraint.toFixedWidth(maxW * this.columns); return arrange(container, g2, cc); } /** * Clears any cached layout information retained by the arrangement. */ @Override public void clear() { // nothing to clear } /** * Compares this layout manager for equality with an arbitrary object. * * @param obj the object. * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof GridArrangement)) { return false; } GridArrangement that = (GridArrangement) obj; if (this.columns != that.columns) { return false; } if (this.rows != that.rows) { return false; } return true; } }
15,772
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BlockBorder.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/BlockBorder.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * BlockBorder.java * ---------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 04-Feb-2005 : Added equals() and implemented Serializable (DG); * 23-Feb-2005 : Added attribute for border color (DG); * 06-May-2005 : Added new convenience constructors (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 16-Mar-2007 : Implemented BlockFrame (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.SerialUtilities; /** * A border for a block. This class is immutable. */ public class BlockBorder implements BlockFrame, Serializable { /** For serialization. */ private static final long serialVersionUID = 4961579220410228283L; /** An empty border. */ public static final BlockBorder NONE = new BlockBorder( RectangleInsets.ZERO_INSETS, Color.WHITE); /** The space reserved for the border. */ private RectangleInsets insets; /** The border color. */ private transient Paint paint; /** * Creates a default border. */ public BlockBorder() { this(Color.BLACK); } /** * Creates a new border with the specified color. * * @param paint the color (<code>null</code> not permitted). */ public BlockBorder(Paint paint) { this(new RectangleInsets(1, 1, 1, 1), paint); } /** * Creates a new border with the specified line widths (in black). * * @param top the width of the top border. * @param left the width of the left border. * @param bottom the width of the bottom border. * @param right the width of the right border. */ public BlockBorder(double top, double left, double bottom, double right) { this(new RectangleInsets(top, left, bottom, right), Color.BLACK); } /** * Creates a new border with the specified line widths (in black). * * @param top the width of the top border. * @param left the width of the left border. * @param bottom the width of the bottom border. * @param right the width of the right border. * @param paint the border paint (<code>null</code> not permitted). */ public BlockBorder(double top, double left, double bottom, double right, Paint paint) { this(new RectangleInsets(top, left, bottom, right), paint); } /** * Creates a new border. * * @param insets the border insets (<code>null</code> not permitted). * @param paint the paint (<code>null</code> not permitted). */ public BlockBorder(RectangleInsets insets, Paint paint) { if (insets == null) { throw new IllegalArgumentException("Null 'insets' argument."); } if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.insets = insets; this.paint = paint; } /** * Returns the space reserved for the border. * * @return The space (never <code>null</code>). */ @Override public RectangleInsets getInsets() { return this.insets; } /** * Returns the paint used to draw the border. * * @return The paint (never <code>null</code>). */ public Paint getPaint() { return this.paint; } /** * Draws the border by filling in the reserved space. * * @param g2 the graphics device. * @param area the area. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { // this default implementation will just fill the available // border space with a single color double t = this.insets.calculateTopInset(area.getHeight()); double b = this.insets.calculateBottomInset(area.getHeight()); double l = this.insets.calculateLeftInset(area.getWidth()); double r = this.insets.calculateRightInset(area.getWidth()); double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); g2.setPaint(this.paint); Rectangle2D rect = new Rectangle2D.Double(); if (t > 0.0) { rect.setRect(x, y, w, t); g2.fill(rect); } if (b > 0.0) { rect.setRect(x, y + h - b, w, b); g2.fill(rect); } if (l > 0.0) { rect.setRect(x, y, l, h); g2.fill(rect); } if (r > 0.0) { rect.setRect(x + w - r, y, r, h); g2.fill(rect); } } /** * Tests this border for equality with an arbitrary instance. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BlockBorder)) { return false; } BlockBorder that = (BlockBorder) obj; if (!this.insets.equals(that.insets)) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return true; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); } }
7,764
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
RectangleConstraint.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/RectangleConstraint.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * RectangleConstraint.java * ------------------------ * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 02-Feb-2005 : Added toString() method (DG); * 08-Feb-2005 : Separated height and width constraints (DG); * 13-May-2005 : Added convenience constructor and new methods for * transforming constraints (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import org.jfree.chart.ui.Size2D; import org.jfree.data.Range; /** * A description of a constraint for resizing a rectangle. Constraints are * immutable. */ public class RectangleConstraint { /** * An instance representing no constraint. */ public static final RectangleConstraint NONE = new RectangleConstraint( 0.0, null, LengthConstraintType.NONE, 0.0, null, LengthConstraintType.NONE); /** The width. */ private double width; /** The width range. */ private Range widthRange; /** The width constraint type. */ private LengthConstraintType widthConstraintType; /** The fixed or maximum height. */ private double height; private Range heightRange; /** The constraint type. */ private LengthConstraintType heightConstraintType; /** * Creates a new "fixed width and height" instance. * * @param w the fixed width. * @param h the fixed height. */ public RectangleConstraint(double w, double h) { this(w, null, LengthConstraintType.FIXED, h, null, LengthConstraintType.FIXED); } /** * Creates a new "range width and height" instance. * * @param w the width range. * @param h the height range. */ public RectangleConstraint(Range w, Range h) { this(0.0, w, LengthConstraintType.RANGE, 0.0, h, LengthConstraintType.RANGE); } /** * Creates a new constraint with a range for the width and a * fixed height. * * @param w the width range. * @param h the fixed height. */ public RectangleConstraint(Range w, double h) { this(0.0, w, LengthConstraintType.RANGE, h, null, LengthConstraintType.FIXED); } /** * Creates a new constraint with a fixed width and a range for * the height. * * @param w the fixed width. * @param h the height range. */ public RectangleConstraint(double w, Range h) { this(w, null, LengthConstraintType.FIXED, 0.0, h, LengthConstraintType.RANGE); } /** * Creates a new constraint. * * @param w the fixed or maximum width. * @param widthRange the width range. * @param widthConstraintType the width type. * @param h the fixed or maximum height. * @param heightRange the height range. * @param heightConstraintType the height type. */ public RectangleConstraint(double w, Range widthRange, LengthConstraintType widthConstraintType, double h, Range heightRange, LengthConstraintType heightConstraintType) { if (widthConstraintType == null) { throw new IllegalArgumentException("Null 'widthType' argument."); } if (heightConstraintType == null) { throw new IllegalArgumentException("Null 'heightType' argument."); } this.width = w; this.widthRange = widthRange; this.widthConstraintType = widthConstraintType; this.height = h; this.heightRange = heightRange; this.heightConstraintType = heightConstraintType; } /** * Returns the fixed width. * * @return The width. */ public double getWidth() { return this.width; } /** * Returns the width range. * * @return The range (possibly <code>null</code>). */ public Range getWidthRange() { return this.widthRange; } /** * Returns the constraint type. * * @return The constraint type (never <code>null</code>). */ public LengthConstraintType getWidthConstraintType() { return this.widthConstraintType; } /** * Returns the fixed height. * * @return The height. */ public double getHeight() { return this.height; } /** * Returns the width range. * * @return The range (possibly <code>null</code>). */ public Range getHeightRange() { return this.heightRange; } /** * Returns the constraint type. * * @return The constraint type (never <code>null</code>). */ public LengthConstraintType getHeightConstraintType() { return this.heightConstraintType; } /** * Returns a constraint that matches this one on the height attributes, * but has no width constraint. * * @return A new constraint. */ public RectangleConstraint toUnconstrainedWidth() { if (this.widthConstraintType == LengthConstraintType.NONE) { return this; } else { return new RectangleConstraint(this.width, this.widthRange, LengthConstraintType.NONE, this.height, this.heightRange, this.heightConstraintType); } } /** * Returns a constraint that matches this one on the width attributes, * but has no height constraint. * * @return A new constraint. */ public RectangleConstraint toUnconstrainedHeight() { if (this.heightConstraintType == LengthConstraintType.NONE) { return this; } else { return new RectangleConstraint(this.width, this.widthRange, this.widthConstraintType, 0.0, this.heightRange, LengthConstraintType.NONE); } } /** * Returns a constraint that matches this one on the height attributes, * but has a fixed width constraint. * * @param width the fixed width. * * @return A new constraint. */ public RectangleConstraint toFixedWidth(double width) { return new RectangleConstraint(width, this.widthRange, LengthConstraintType.FIXED, this.height, this.heightRange, this.heightConstraintType); } /** * Returns a constraint that matches this one on the width attributes, * but has a fixed height constraint. * * @param height the fixed height. * * @return A new constraint. */ public RectangleConstraint toFixedHeight(double height) { return new RectangleConstraint(this.width, this.widthRange, this.widthConstraintType, height, this.heightRange, LengthConstraintType.FIXED); } /** * Returns a constraint that matches this one on the height attributes, * but has a range width constraint. * * @param range the width range (<code>null</code> not permitted). * * @return A new constraint. */ public RectangleConstraint toRangeWidth(Range range) { if (range == null) { throw new IllegalArgumentException("Null 'range' argument."); } return new RectangleConstraint(range.getUpperBound(), range, LengthConstraintType.RANGE, this.height, this.heightRange, this.heightConstraintType); } /** * Returns a constraint that matches this one on the width attributes, * but has a range height constraint. * * @param range the height range (<code>null</code> not permitted). * * @return A new constraint. */ public RectangleConstraint toRangeHeight(Range range) { if (range == null) { throw new IllegalArgumentException("Null 'range' argument."); } return new RectangleConstraint(this.width, this.widthRange, this.widthConstraintType, range.getUpperBound(), range, LengthConstraintType.RANGE); } /** * Returns a string representation of this instance, mostly used for * debugging purposes. * * @return A string. */ @Override public String toString() { return "RectangleConstraint[" + this.widthConstraintType.toString() + ": width=" + this.width + ", height=" + this.height + "]"; } /** * Returns the new size that reflects the constraints defined by this * instance. * * @param base the base size. * * @return The constrained size. */ public Size2D calculateConstrainedSize(Size2D base) { Size2D result = new Size2D(); if (this.widthConstraintType == LengthConstraintType.NONE) { result.width = base.width; if (this.heightConstraintType == LengthConstraintType.NONE) { result.height = base.height; } else if (this.heightConstraintType == LengthConstraintType.RANGE) { result.height = this.heightRange.constrain(base.height); } else if (this.heightConstraintType == LengthConstraintType.FIXED) { result.height = this.height; } } else if (this.widthConstraintType == LengthConstraintType.RANGE) { result.width = this.widthRange.constrain(base.width); if (this.heightConstraintType == LengthConstraintType.NONE) { result.height = base.height; } else if (this.heightConstraintType == LengthConstraintType.RANGE) { result.height = this.heightRange.constrain(base.height); } else if (this.heightConstraintType == LengthConstraintType.FIXED) { result.height = this.height; } } else if (this.widthConstraintType == LengthConstraintType.FIXED) { result.width = this.width; if (this.heightConstraintType == LengthConstraintType.NONE) { result.height = base.height; } else if (this.heightConstraintType == LengthConstraintType.RANGE) { result.height = this.heightRange.constrain(base.height); } else if (this.heightConstraintType == LengthConstraintType.FIXED) { result.height = this.height; } } return result; } }
11,883
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
EntityBlockParams.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/EntityBlockParams.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * EntityBlockParams.java * ---------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 19-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart.block; /** * An interface that is used by the draw() method of some {@link Block} * implementations to determine whether or not to generate entities for the * items within the block. */ public interface EntityBlockParams { /** * Returns a flag that controls whether or not the block should return * entities for the items it draws. * * @return A boolean. */ public boolean getGenerateEntities(); }
1,981
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BlockParams.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/BlockParams.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * BlockParams.java * ---------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 19-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart.block; /** * A standard parameter object that can be passed to the draw() method defined * by the {@link Block} class. */ public class BlockParams implements EntityBlockParams { /** * A flag that controls whether or not the block should generate and * return chart entities for the items it draws. */ private boolean generateEntities; /** * The x-translation (used to enable chart entities to use global * coordinates rather than coordinates that are local to the container * they are within). */ private double translateX; /** * The y-translation (used to enable chart entities to use global * coordinates rather than coordinates that are local to the container * they are within). */ private double translateY; /** * Creates a new instance. */ public BlockParams() { this.translateX = 0.0; this.translateY = 0.0; this.generateEntities = false; } /** * Returns the flag that controls whether or not chart entities are * generated. * * @return A boolean. */ @Override public boolean getGenerateEntities() { return this.generateEntities; } /** * Sets the flag that controls whether or not chart entities are generated. * * @param generate the flag. */ public void setGenerateEntities(boolean generate) { this.generateEntities = generate; } /** * Returns the translation required to convert local x-coordinates back to * the coordinate space of the container. * * @return The x-translation amount. */ public double getTranslateX() { return this.translateX; } /** * Sets the translation required to convert local x-coordinates into the * coordinate space of the container. * * @param x the x-translation amount. */ public void setTranslateX(double x) { this.translateX = x; } /** * Returns the translation required to convert local y-coordinates back to * the coordinate space of the container. * * @return The y-translation amount. */ public double getTranslateY() { return this.translateY; } /** * Sets the translation required to convert local y-coordinates into the * coordinate space of the container. * * @param y the y-translation amount. */ public void setTranslateY(double y) { this.translateY = y; } }
4,045
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ColumnArrangement.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/ColumnArrangement.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * ColumnArrangement.java * ---------------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 04-Feb-2005 : Added equals() and implemented Serializable (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.jfree.chart.ui.HorizontalAlignment; import org.jfree.chart.ui.Size2D; import org.jfree.chart.ui.VerticalAlignment; /** * Arranges blocks in a column layout. This class is immutable. */ public class ColumnArrangement implements Arrangement, Serializable { /** For serialization. */ private static final long serialVersionUID = -5315388482898581555L; /** The horizontal alignment of blocks. */ private HorizontalAlignment horizontalAlignment; /** The vertical alignment of blocks within each row. */ private VerticalAlignment verticalAlignment; /** The horizontal gap between columns. */ private double horizontalGap; /** The vertical gap between items in a column. */ private double verticalGap; /** * Creates a new instance. */ public ColumnArrangement() { } /** * Creates a new instance. * * @param hAlign the horizontal alignment (currently ignored). * @param vAlign the vertical alignment (currently ignored). * @param hGap the horizontal gap. * @param vGap the vertical gap. */ public ColumnArrangement(HorizontalAlignment hAlign, VerticalAlignment vAlign, double hGap, double vGap) { this.horizontalAlignment = hAlign; this.verticalAlignment = vAlign; this.horizontalGap = hGap; this.verticalGap = vGap; } /** * Adds a block to be managed by this instance. This method is usually * called by the {@link BlockContainer}, you shouldn't need to call it * directly. * * @param block the block. * @param key a key that controls the position of the block. */ @Override public void add(Block block, Object key) { // since the flow layout is relatively straightforward, no information // needs to be recorded here } /** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters. * * @param container the container whose items are being arranged. * @param g2 the graphics device. * @param constraint the size constraint. * * @return The size of the container after arrangement of the contents. */ @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { LengthConstraintType w = constraint.getWidthConstraintType(); LengthConstraintType h = constraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) { return arrangeNN(container, g2); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.FIXED) { if (h == LengthConstraintType.NONE) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.FIXED) { return arrangeFF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.RANGE) { if (h == LengthConstraintType.NONE) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.FIXED) { return arrangeRF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { return arrangeRR(container, g2, constraint); } } return new Size2D(); // TODO: complete this } /** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters. * * @param container the container whose items are being arranged. * @param g2 the graphics device. * @param constraint the size constraint. * * @return The container size after the arrangement. */ protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // TODO: implement properly return arrangeNF(container, g2, constraint); } /** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters. * * @param container the container whose items are being arranged. * @param constraint the size constraint. * @param g2 the graphics device. * * @return The container size after the arrangement. */ protected Size2D arrangeNF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { List<Block> blocks = container.getBlocks(); double height = constraint.getHeight(); if (height <= 0.0) { height = Double.POSITIVE_INFINITY; } double x = 0.0; double y = 0.0; double maxWidth = 0.0; List<Block> itemsInColumn = new ArrayList<Block>(); for (Block block : blocks) { Size2D size = block.arrange(g2, RectangleConstraint.NONE); if (y + size.height <= height) { itemsInColumn.add(block); block.setBounds( new Rectangle2D.Double(x, y, size.width, size.height) ); y = y + size.height + this.verticalGap; maxWidth = Math.max(maxWidth, size.width); } else { if (itemsInColumn.isEmpty()) { // place in this column (truncated) anyway block.setBounds( new Rectangle2D.Double( x, y, size.width, Math.min(size.height, height - y) ) ); y = 0.0; x = x + size.width + this.horizontalGap; } else { // start new column itemsInColumn.clear(); x = x + maxWidth + this.horizontalGap; y = 0.0; maxWidth = size.width; block.setBounds( new Rectangle2D.Double( x, y, size.width, Math.min(size.height, height) ) ); y = size.height + this.verticalGap; itemsInColumn.add(block); } } } return new Size2D(x + maxWidth, constraint.getHeight()); } /** * Arranges a container with range constraints for both the horizontal * and vertical. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size of the container. */ protected Size2D arrangeRR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, and see if this fits within // the required ranges... Size2D s1 = arrangeNN(container, g2); if (constraint.getHeightRange().contains(s1.height)) { return s1; // TODO: we didn't check the width yet } else { RectangleConstraint c = constraint.toFixedHeight( constraint.getHeightRange().getUpperBound() ); return arrangeRF(container, g2, c); } } /** * Arranges the blocks in the container using a fixed height and a * range for the width. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The size of the container after arrangement. */ protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D s = arrangeNF(container, g2, constraint); if (constraint.getWidthRange().contains(s.width)) { return s; } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().constrain(s.getWidth()) ); return arrangeFF(container, g2, c); } } /** * Arranges the blocks without any constraints. This puts all blocks * into a single column. * * @param container the container. * @param g2 the graphics device. * * @return The size after the arrangement. */ protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) { double y = 0.0; double height = 0.0; double maxWidth = 0.0; List<Block> blocks = container.getBlocks(); int blockCount = blocks.size(); if (blockCount > 0) { Size2D[] sizes = new Size2D[blocks.size()]; for (int i = 0; i < blocks.size(); i++) { Block block = blocks.get(i); sizes[i] = block.arrange(g2, RectangleConstraint.NONE); height = height + sizes[i].getHeight(); maxWidth = Math.max(sizes[i].width, maxWidth); block.setBounds( new Rectangle2D.Double( 0.0, y, sizes[i].width, sizes[i].height ) ); y = y + sizes[i].height + this.verticalGap; } if (blockCount > 1) { height = height + this.verticalGap * (blockCount - 1); } if (this.horizontalAlignment != HorizontalAlignment.LEFT) { for (Block block : blocks) { //Block b = (Block) blocks.get(i); if (this.horizontalAlignment == HorizontalAlignment.CENTER) { //TODO: shift block right by half } else if (this.horizontalAlignment == HorizontalAlignment.RIGHT) { //TODO: shift block over to right } } } } return new Size2D(maxWidth, height); } /** * Clears any cached information. */ @Override public void clear() { // no action required. } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColumnArrangement)) { return false; } ColumnArrangement that = (ColumnArrangement) obj; if (this.horizontalAlignment != that.horizontalAlignment) { return false; } if (this.verticalAlignment != that.verticalAlignment) { return false; } if (this.horizontalGap != that.horizontalGap) { return false; } if (this.verticalGap != that.verticalGap) { return false; } return true; } }
13,849
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BorderArrangement.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/BorderArrangement.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * BorderArrangement.java * ---------------------- * (C) Copyright 2004-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 08-Feb-2005 : Updated for changes in RectangleConstraint (DG); * 24-Feb-2005 : Improved arrangeRR() method (DG); * 03-May-2005 : Implemented Serializable and added equals() method (DG); * 13-May-2005 : Fixed bugs in the arrange() method (DG); * 08-Apr-2008 : Fixed bug in arrangeFF() method where width is too small for * left and right blocks (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.ObjectUtilities; import org.jfree.data.Range; /** * An arrangement manager that lays out blocks in a similar way to * Swing's BorderLayout class. */ public class BorderArrangement implements Arrangement, Serializable { /** For serialization. */ private static final long serialVersionUID = 506071142274883745L; /** The block (if any) at the center of the layout. */ private Block centerBlock; /** The block (if any) at the top of the layout. */ private Block topBlock; /** The block (if any) at the bottom of the layout. */ private Block bottomBlock; /** The block (if any) at the left of the layout. */ private Block leftBlock; /** The block (if any) at the right of the layout. */ private Block rightBlock; /** * Creates a new instance. */ public BorderArrangement() { } /** * Adds a block to the arrangement manager at the specified edge. * If the key is not an instance of {@link RectangleEdge} the block will * be added in the center. * * @param block the block (<code>null</code> permitted). * @param key the edge (an instance of {@link RectangleEdge}) or * <code>null</code> for the center block. */ @Override public void add(Block block, Object key) { if (!(key instanceof RectangleEdge)) { // catches null also this.centerBlock = block; } else { RectangleEdge edge = (RectangleEdge) key; if (edge == RectangleEdge.TOP) { this.topBlock = block; } else if (edge == RectangleEdge.BOTTOM) { this.bottomBlock = block; } else if (edge == RectangleEdge.LEFT) { this.leftBlock = block; } else if (edge == RectangleEdge.RIGHT) { this.rightBlock = block; } } } /** * Arranges the items in the specified container, subject to the given * constraint. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The block size. */ @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { RectangleConstraint contentConstraint = container.toContentConstraint(constraint); Size2D contentSize = null; LengthConstraintType w = contentConstraint.getWidthConstraintType(); LengthConstraintType h = contentConstraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) { contentSize = arrangeNN(container, g2); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.FIXED) { if (h == LengthConstraintType.NONE) { contentSize = arrangeFN(container, g2, constraint.getWidth()); } else if (h == LengthConstraintType.FIXED) { contentSize = arrangeFF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { contentSize = arrangeFR(container, g2, constraint); } } else if (w == LengthConstraintType.RANGE) { if (h == LengthConstraintType.NONE) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.FIXED) { throw new RuntimeException("Not implemented."); } else if (h == LengthConstraintType.RANGE) { contentSize = arrangeRR(container, constraint.getWidthRange(), constraint.getHeightRange(), g2); } } return new Size2D(container.calculateTotalWidth(contentSize.getWidth()), container.calculateTotalHeight(contentSize.getHeight())); } /** * Performs an arrangement without constraints. * * @param container the container. * @param g2 the graphics device. * * @return The container size after the arrangement. */ protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) { double[] w = new double[5]; double[] h = new double[5]; if (this.topBlock != null) { Size2D size = this.topBlock.arrange(g2, RectangleConstraint.NONE); w[0] = size.width; h[0] = size.height; } if (this.bottomBlock != null) { Size2D size = this.bottomBlock.arrange(g2, RectangleConstraint.NONE); w[1] = size.width; h[1] = size.height; } if (this.leftBlock != null) { Size2D size = this.leftBlock.arrange(g2, RectangleConstraint.NONE); w[2] = size.width; h[2] = size.height; } if (this.rightBlock != null) { Size2D size = this.rightBlock.arrange(g2, RectangleConstraint.NONE); w[3] = size.width; h[3] = size.height; } h[2] = Math.max(h[2], h[3]); h[3] = h[2]; if (this.centerBlock != null) { Size2D size = this.centerBlock.arrange(g2, RectangleConstraint.NONE); w[4] = size.width; h[4] = size.height; } double width = Math.max(w[0], Math.max(w[1], w[2] + w[4] + w[3])); double centerHeight = Math.max(h[2], Math.max(h[3], h[4])); double height = h[0] + h[1] + centerHeight; if (this.topBlock != null) { this.topBlock.setBounds(new Rectangle2D.Double(0.0, 0.0, width, h[0])); } if (this.bottomBlock != null) { this.bottomBlock.setBounds(new Rectangle2D.Double(0.0, height - h[1], width, h[1])); } if (this.leftBlock != null) { this.leftBlock.setBounds(new Rectangle2D.Double(0.0, h[0], w[2], centerHeight)); } if (this.rightBlock != null) { this.rightBlock.setBounds(new Rectangle2D.Double(width - w[3], h[0], w[3], centerHeight)); } if (this.centerBlock != null) { this.centerBlock.setBounds(new Rectangle2D.Double(w[2], h[0], width - w[2] - w[3], centerHeight)); } return new Size2D(width, height); } /** * Performs an arrangement with a fixed width and a range for the height. * * @param container the container. * @param g2 the graphics device. * @param constraint the constraint. * * @return The container size after the arrangement. */ protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D size1 = arrangeFN(container, g2, constraint.getWidth()); if (constraint.getHeightRange().contains(size1.getHeight())) { return size1; } else { double h = constraint.getHeightRange().constrain(size1.getHeight()); RectangleConstraint c2 = constraint.toFixedHeight(h); return arrange(container, g2, c2); } } /** * Arranges the container width a fixed width and no constraint on the * height. * * @param container the container. * @param g2 the graphics device. * @param width the fixed width. * * @return The container size after arranging the contents. */ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, double width) { double[] w = new double[5]; double[] h = new double[5]; RectangleConstraint c1 = new RectangleConstraint(width, null, LengthConstraintType.FIXED, 0.0, null, LengthConstraintType.NONE); if (this.topBlock != null) { Size2D size = this.topBlock.arrange(g2, c1); w[0] = size.width; h[0] = size.height; } if (this.bottomBlock != null) { Size2D size = this.bottomBlock.arrange(g2, c1); w[1] = size.width; h[1] = size.height; } RectangleConstraint c2 = new RectangleConstraint(0.0, new Range(0.0, width), LengthConstraintType.RANGE, 0.0, null, LengthConstraintType.NONE); if (this.leftBlock != null) { Size2D size = this.leftBlock.arrange(g2, c2); w[2] = size.width; h[2] = size.height; } if (this.rightBlock != null) { double maxW = Math.max(width - w[2], 0.0); RectangleConstraint c3 = new RectangleConstraint(0.0, new Range(Math.min(w[2], maxW), maxW), LengthConstraintType.RANGE, 0.0, null, LengthConstraintType.NONE); Size2D size = this.rightBlock.arrange(g2, c3); w[3] = size.width; h[3] = size.height; } h[2] = Math.max(h[2], h[3]); h[3] = h[2]; if (this.centerBlock != null) { RectangleConstraint c4 = new RectangleConstraint(width - w[2] - w[3], null, LengthConstraintType.FIXED, 0.0, null, LengthConstraintType.NONE); Size2D size = this.centerBlock.arrange(g2, c4); w[4] = size.width; h[4] = size.height; } double height = h[0] + h[1] + Math.max(h[2], Math.max(h[3], h[4])); return arrange(container, g2, new RectangleConstraint(width, height)); } /** * Performs an arrangement with range constraints on both the vertical * and horizontal sides. * * @param container the container. * @param widthRange the allowable range for the container width. * @param heightRange the allowable range for the container height. * @param g2 the graphics device. * * @return The container size. */ protected Size2D arrangeRR(BlockContainer container, Range widthRange, Range heightRange, Graphics2D g2) { double[] w = new double[5]; double[] h = new double[5]; if (this.topBlock != null) { RectangleConstraint c1 = new RectangleConstraint(widthRange, heightRange); Size2D size = this.topBlock.arrange(g2, c1); w[0] = size.width; h[0] = size.height; } if (this.bottomBlock != null) { Range heightRange2 = Range.shift(heightRange, -h[0], false); RectangleConstraint c2 = new RectangleConstraint(widthRange, heightRange2); Size2D size = this.bottomBlock.arrange(g2, c2); w[1] = size.width; h[1] = size.height; } Range heightRange3 = Range.shift(heightRange, -(h[0] + h[1])); if (this.leftBlock != null) { RectangleConstraint c3 = new RectangleConstraint(widthRange, heightRange3); Size2D size = this.leftBlock.arrange(g2, c3); w[2] = size.width; h[2] = size.height; } Range widthRange2 = Range.shift(widthRange, -w[2], false); if (this.rightBlock != null) { RectangleConstraint c4 = new RectangleConstraint(widthRange2, heightRange3); Size2D size = this.rightBlock.arrange(g2, c4); w[3] = size.width; h[3] = size.height; } h[2] = Math.max(h[2], h[3]); h[3] = h[2]; Range widthRange3 = Range.shift(widthRange, -(w[2] + w[3]), false); if (this.centerBlock != null) { RectangleConstraint c5 = new RectangleConstraint(widthRange3, heightRange3); Size2D size = this.centerBlock.arrange(g2, c5); w[4] = size.width; h[4] = size.height; } double width = Math.max(w[0], Math.max(w[1], w[2] + w[4] + w[3])); double height = h[0] + h[1] + Math.max(h[2], Math.max(h[3], h[4])); if (this.topBlock != null) { this.topBlock.setBounds(new Rectangle2D.Double(0.0, 0.0, width, h[0])); } if (this.bottomBlock != null) { this.bottomBlock.setBounds(new Rectangle2D.Double(0.0, height - h[1], width, h[1])); } if (this.leftBlock != null) { this.leftBlock.setBounds(new Rectangle2D.Double(0.0, h[0], w[2], h[2])); } if (this.rightBlock != null) { this.rightBlock.setBounds(new Rectangle2D.Double(width - w[3], h[0], w[3], h[3])); } if (this.centerBlock != null) { this.centerBlock.setBounds(new Rectangle2D.Double(w[2], h[0], width - w[2] - w[3], height - h[0] - h[1])); } return new Size2D(width, height); } /** * Arranges the items within a container. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The container size after the arrangement. */ protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { double[] w = new double[5]; double[] h = new double[5]; w[0] = constraint.getWidth(); if (this.topBlock != null) { RectangleConstraint c1 = new RectangleConstraint(w[0], null, LengthConstraintType.FIXED, 0.0, new Range(0.0, constraint.getHeight()), LengthConstraintType.RANGE); Size2D size = this.topBlock.arrange(g2, c1); h[0] = size.height; } w[1] = w[0]; if (this.bottomBlock != null) { RectangleConstraint c2 = new RectangleConstraint(w[0], null, LengthConstraintType.FIXED, 0.0, new Range(0.0, constraint.getHeight() - h[0]), LengthConstraintType.RANGE); Size2D size = this.bottomBlock.arrange(g2, c2); h[1] = size.height; } h[2] = constraint.getHeight() - h[1] - h[0]; if (this.leftBlock != null) { RectangleConstraint c3 = new RectangleConstraint(0.0, new Range(0.0, constraint.getWidth()), LengthConstraintType.RANGE, h[2], null, LengthConstraintType.FIXED); Size2D size = this.leftBlock.arrange(g2, c3); w[2] = size.width; } h[3] = h[2]; if (this.rightBlock != null) { RectangleConstraint c4 = new RectangleConstraint(0.0, new Range(0.0, Math.max(constraint.getWidth() - w[2], 0.0)), LengthConstraintType.RANGE, h[2], null, LengthConstraintType.FIXED); Size2D size = this.rightBlock.arrange(g2, c4); w[3] = size.width; } h[4] = h[2]; w[4] = constraint.getWidth() - w[3] - w[2]; RectangleConstraint c5 = new RectangleConstraint(w[4], h[4]); if (this.centerBlock != null) { this.centerBlock.arrange(g2, c5); } if (this.topBlock != null) { this.topBlock.setBounds(new Rectangle2D.Double(0.0, 0.0, w[0], h[0])); } if (this.bottomBlock != null) { this.bottomBlock.setBounds(new Rectangle2D.Double(0.0, h[0] + h[2], w[1], h[1])); } if (this.leftBlock != null) { this.leftBlock.setBounds(new Rectangle2D.Double(0.0, h[0], w[2], h[2])); } if (this.rightBlock != null) { this.rightBlock.setBounds(new Rectangle2D.Double(w[2] + w[4], h[0], w[3], h[3])); } if (this.centerBlock != null) { this.centerBlock.setBounds(new Rectangle2D.Double(w[2], h[0], w[4], h[4])); } return new Size2D(constraint.getWidth(), constraint.getHeight()); } /** * Clears the layout. */ @Override public void clear() { this.centerBlock = null; this.topBlock = null; this.bottomBlock = null; this.leftBlock = null; this.rightBlock = null; } /** * Tests this arrangement for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof BorderArrangement)) { return false; } BorderArrangement that = (BorderArrangement) obj; if (!ObjectUtilities.equal(this.topBlock, that.topBlock)) { return false; } if (!ObjectUtilities.equal(this.bottomBlock, that.bottomBlock)) { return false; } if (!ObjectUtilities.equal(this.leftBlock, that.leftBlock)) { return false; } if (!ObjectUtilities.equal(this.rightBlock, that.rightBlock)) { return false; } if (!ObjectUtilities.equal(this.centerBlock, that.centerBlock)) { return false; } return true; } }
20,034
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LabelBlock.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/LabelBlock.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * LabelBlock.java * --------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Pierre-Marie Le Biot; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 19-Apr-2005 : Added optional tooltip and URL text items, * draw() method now returns entities if * requested (DG); * 13-May-2005 : Added methods to set the font (DG); * 01-Sep-2005 : Added paint management (PMLB); * Implemented equals() and clone() (PublicCloneable) (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 20-Jul-2006 : Fixed entity area in draw() method (DG); * 16-Mar-2007 : Fixed serialization when using GradientPaint (DG); * 10-Feb-2009 : Added alignment fields (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.entity.ChartEntity; import org.jfree.chart.entity.StandardEntityCollection; import org.jfree.chart.text.TextBlock; import org.jfree.chart.text.TextBlockAnchor; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.SerialUtilities; /** * A block containing a label. */ public class LabelBlock extends AbstractBlock implements Block, PublicCloneable { /** For serialization. */ static final long serialVersionUID = 249626098864178017L; /** * The text for the label - retained in case the label needs * regenerating (for example, to change the font). */ private String text; /** The label. */ private TextBlock label; /** The font. */ private Font font; /** The tool tip text (can be <code>null</code>). */ private String toolTipText; /** The URL text (can be <code>null</code>). */ private String urlText; /** The default color. */ public static final Paint DEFAULT_PAINT = Color.BLACK; /** The paint. */ private transient Paint paint; /** * The content alignment point. * * @since 1.0.13 */ private TextBlockAnchor contentAlignmentPoint; /** * The anchor point for the text. * * @since 1.0.13 */ private RectangleAnchor textAnchor; /** * Creates a new label block. * * @param label the label (<code>null</code> not permitted). */ public LabelBlock(String label) { this(label, new Font("SansSerif", Font.PLAIN, 10), DEFAULT_PAINT); } /** * Creates a new label block. * * @param text the text for the label (<code>null</code> not permitted). * @param font the font (<code>null</code> not permitted). */ public LabelBlock(String text, Font font) { this(text, font, DEFAULT_PAINT); } /** * Creates a new label block. * * @param text the text for the label (<code>null</code> not permitted). * @param font the font (<code>null</code> not permitted). * @param paint the paint (<code>null</code> not permitted). */ public LabelBlock(String text, Font font, Paint paint) { this.text = text; this.paint = paint; this.label = TextUtilities.createTextBlock(text, font, this.paint); this.font = font; this.toolTipText = null; this.urlText = null; this.contentAlignmentPoint = TextBlockAnchor.CENTER; this.textAnchor = RectangleAnchor.CENTER; } /** * Returns the font. * * @return The font (never <code>null</code>). * * @see #setFont(Font) */ public Font getFont() { return this.font; } /** * Sets the font and regenerates the label. * * @param font the font (<code>null</code> not permitted). * * @see #getFont() */ public void setFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.font = font; this.label = TextUtilities.createTextBlock(this.text, font, this.paint); } /** * Returns the paint. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint and regenerates the label. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; this.label = TextUtilities.createTextBlock(this.text, this.font, this.paint); } /** * Returns the tool tip text. * * @return The tool tip text (possibly <code>null</code>). * * @see #setToolTipText(String) */ public String getToolTipText() { return this.toolTipText; } /** * Sets the tool tip text. * * @param text the text (<code>null</code> permitted). * * @see #getToolTipText() */ public void setToolTipText(String text) { this.toolTipText = text; } /** * Returns the URL text. * * @return The URL text (possibly <code>null</code>). * * @see #setURLText(String) */ public String getURLText() { return this.urlText; } /** * Sets the URL text. * * @param text the text (<code>null</code> permitted). * * @see #getURLText() */ public void setURLText(String text) { this.urlText = text; } /** * Returns the content alignment point. * * @return The content alignment point (never <code>null</code>). * * @since 1.0.13 */ public TextBlockAnchor getContentAlignmentPoint() { return this.contentAlignmentPoint; } /** * Sets the content alignment point. * * @param anchor the anchor used to determine the alignment point (never * <code>null</code>). * * @since 1.0.13 */ public void setContentAlignmentPoint(TextBlockAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.contentAlignmentPoint = anchor; } /** * Returns the text anchor (never <code>null</code>). * * @return The text anchor. * * @since 1.0.13 */ public RectangleAnchor getTextAnchor() { return this.textAnchor; } /** * Sets the text anchor. * * @param anchor the anchor (<code>null</code> not permitted). * * @since 1.0.13 */ public void setTextAnchor(RectangleAnchor anchor) { this.textAnchor = anchor; } /** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { g2.setFont(this.font); Size2D s = this.label.calculateDimensions(g2); return new Size2D(calculateTotalWidth(s.getWidth()), calculateTotalHeight(s.getHeight())); } /** * Draws the block. * * @param g2 the graphics device. * @param area the area. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null); } /** * Draws the block within the specified area. * * @param g2 the graphics device. * @param area the area. * @param params ignored (<code>null</code> permitted). * * @return Always <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { area = trimMargin(area); drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); // check if we need to collect chart entities from the container EntityBlockParams ebp = null; StandardEntityCollection sec = null; Shape entityArea = null; if (params instanceof EntityBlockParams) { ebp = (EntityBlockParams) params; if (ebp.getGenerateEntities()) { sec = new StandardEntityCollection(); entityArea = (Shape) area.clone(); } } g2.setPaint(this.paint); g2.setFont(this.font); Point2D pt = RectangleAnchor.coordinates(area, this.textAnchor); this.label.draw(g2, (float) pt.getX(), (float) pt.getY(), this.contentAlignmentPoint); BlockResult result = null; if (ebp != null && sec != null) { if (this.toolTipText != null || this.urlText != null) { ChartEntity entity = new ChartEntity(entityArea, this.toolTipText, this.urlText); sec.add(entity); result = new BlockResult(); result.setEntityCollection(sec); } } return result; } /** * Tests this <code>LabelBlock</code> for equality with an arbitrary * object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (!(obj instanceof LabelBlock)) { return false; } LabelBlock that = (LabelBlock) obj; if (!this.text.equals(that.text)) { return false; } if (!this.font.equals(that.font)) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!ObjectUtilities.equal(this.toolTipText, that.toolTipText)) { return false; } if (!ObjectUtilities.equal(this.urlText, that.urlText)) { return false; } if (!this.contentAlignmentPoint.equals(that.contentAlignmentPoint)) { return false; } if (!this.textAnchor.equals(that.textAnchor)) { return false; } return super.equals(obj); } /** * Returns a clone of this <code>LabelBlock</code> instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); } }
13,228
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LengthConstraintType.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/LengthConstraintType.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * LengthConstraintType.java * ------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 08-Feb-2004 : Version 1 (DG); * */ package org.jfree.chart.block; /** * Defines tokens used to indicate a length constraint type. */ public enum LengthConstraintType { /** NONE. */ NONE("LengthConstraintType.NONE"), /** Range. */ RANGE("RectangleConstraintType.RANGE"), /** FIXED. */ FIXED("LengthConstraintType.FIXED"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private LengthConstraintType(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,232
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
EmptyBlock.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/EmptyBlock.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * EmptyBlock.java * --------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 04-Feb-2005 : Now cloneable and serializable (DG); * 20-Apr-2005 : Added new draw() method (DG); * 08-Apr-2008 : Added support for margin and border (DG); * 08-May-2008 : Updated arrange() method to recognise incoming constraint (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.PublicCloneable; /** * An empty block with a fixed size. */ public class EmptyBlock extends AbstractBlock implements Block, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -4083197869412648579L; /** * Creates a new block with the specified width and height. * * @param width the width. * @param height the height. */ public EmptyBlock(double width, double height) { setWidth(width); setHeight(height); } /** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { Size2D base = new Size2D(calculateTotalWidth(getWidth()), calculateTotalHeight(getHeight())); return constraint.calculateConstrainedSize(base); } /** * Draws the block. Since the block is empty, there is nothing to draw * except the optional border. * * @param g2 the graphics device. * @param area the area. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { draw(g2, area, null); } /** * Draws the block within the specified area. Since the block is empty, * there is nothing to draw except the optional border. * * @param g2 the graphics device. * @param area the area. * @param params ignored (<code>null</code> permitted). * * @return Always <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { area = trimMargin(area); drawBorder(g2, area); return null; } /** * Returns a clone of the block. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } }
4,227
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ColorBlock.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/ColorBlock.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * ColorBlock.java * --------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 20-Apr-2005 : Added new draw() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 16-Mar-2007 : Implemented equals() and fixed serialization (DG); * 08-Apr-2008 : Added code for margin, border and padding in draw() * method (DG); * 12-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import org.jfree.chart.ui.Size2D; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.SerialUtilities; /** * A block that is filled with a single color. */ public class ColorBlock extends AbstractBlock implements Block { /** For serialization. */ static final long serialVersionUID = 3383866145634010865L; /** The paint. */ private transient Paint paint; /** * Creates a new block. * * @param paint the paint (<code>null</code> not permitted). * @param width the width. * @param height the height. */ public ColorBlock(Paint paint, double width, double height) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; setWidth(width); setHeight(height); } /** * Returns the paint. * * @return The paint (never <code>null</code>). * * @since 1.0.5 */ public Paint getPaint() { return this.paint; } /** * Arranges the contents of the block, within the given constraints, and * returns the block size. * * @param g2 the graphics device. * @param constraint the constraint (<code>null</code> not permitted). * * @return The block size (in Java2D units, never <code>null</code>). */ @Override public Size2D arrange(Graphics2D g2, RectangleConstraint constraint) { return new Size2D(calculateTotalWidth(getWidth()), calculateTotalHeight(getHeight())); } /** * Draws the block. * * @param g2 the graphics device. * @param area the area. */ @Override public void draw(Graphics2D g2, Rectangle2D area) { area = trimMargin(area); drawBorder(g2, area); area = trimBorder(area); area = trimPadding(area); g2.setPaint(this.paint); g2.fill(area); } /** * Draws the block within the specified area. * * @param g2 the graphics device. * @param area the area. * @param params ignored (<code>null</code> permitted). * * @return Always <code>null</code>. */ @Override public Object draw(Graphics2D g2, Rectangle2D area, Object params) { draw(g2, area); return null; } /** * Tests this block for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ColorBlock)) { return false; } ColorBlock that = (ColorBlock) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } return super.equals(obj); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); } }
5,740
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
FlowArrangement.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/block/FlowArrangement.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * FlowArrangement.java * -------------------- * (C) Copyright 2004-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 22-Oct-2004 : Version 1 (DG); * 04-Feb-2005 : Implemented equals() and made serializable (DG); * 08-Feb-2005 : Updated for changes in RectangleConstraint (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.block; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.jfree.chart.ui.HorizontalAlignment; import org.jfree.chart.ui.Size2D; import org.jfree.chart.ui.VerticalAlignment; /** * Arranges blocks in a flow layout. This class is immutable. */ public class FlowArrangement implements Arrangement, Serializable { /** For serialization. */ private static final long serialVersionUID = 4543632485478613800L; /** The horizontal alignment of blocks. */ private HorizontalAlignment horizontalAlignment; /** The vertical alignment of blocks within each row. */ private VerticalAlignment verticalAlignment; /** The horizontal gap between items within rows. */ private double horizontalGap; /** The vertical gap between rows. */ private double verticalGap; /** * Creates a new instance. */ public FlowArrangement() { this(HorizontalAlignment.CENTER, VerticalAlignment.CENTER, 2.0, 2.0); } /** * Creates a new instance. * * @param hAlign the horizontal alignment (currently ignored). * @param vAlign the vertical alignment (currently ignored). * @param hGap the horizontal gap. * @param vGap the vertical gap. */ public FlowArrangement(HorizontalAlignment hAlign, VerticalAlignment vAlign, double hGap, double vGap) { this.horizontalAlignment = hAlign; this.verticalAlignment = vAlign; this.horizontalGap = hGap; this.verticalGap = vGap; } /** * Adds a block to be managed by this instance. This method is usually * called by the {@link BlockContainer}, you shouldn't need to call it * directly. * * @param block the block. * @param key a key that controls the position of the block. */ @Override public void add(Block block, Object key) { // since the flow layout is relatively straightforward, // no information needs to be recorded here } /** * Calculates and sets the bounds of all the items in the specified * container, subject to the given constraint. The <code>Graphics2D</code> * can be used by some items (particularly items containing text) to * calculate sizing parameters. * * @param container the container whose items are being arranged. * @param constraint the size constraint. * @param g2 the graphics device. * * @return The size of the container after arrangement of the contents. */ @Override public Size2D arrange(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { LengthConstraintType w = constraint.getWidthConstraintType(); LengthConstraintType h = constraint.getHeightConstraintType(); if (w == LengthConstraintType.NONE) { if (h == LengthConstraintType.NONE) { return arrangeNN(container, g2); } else if (h == LengthConstraintType.FIXED) { return arrangeNF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { throw new RuntimeException("Not implemented."); } } else if (w == LengthConstraintType.FIXED) { if (h == LengthConstraintType.NONE) { return arrangeFN(container, g2, constraint); } else if (h == LengthConstraintType.FIXED) { return arrangeFF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { return arrangeFR(container, g2, constraint); } } else if (w == LengthConstraintType.RANGE) { if (h == LengthConstraintType.NONE) { return arrangeRN(container, g2, constraint); } else if (h == LengthConstraintType.FIXED) { return arrangeRF(container, g2, constraint); } else if (h == LengthConstraintType.RANGE) { return arrangeRR(container, g2, constraint); } } throw new RuntimeException("Unrecognised constraint type."); } /** * Arranges the blocks in the container with a fixed width and no height * constraint. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size. */ protected Size2D arrangeFN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { List<Block> blocks = container.getBlocks(); double width = constraint.getWidth(); double x = 0.0; double y = 0.0; double maxHeight = 0.0; List<Block> itemsInRow = new ArrayList<Block>(); for (Block block : blocks) { Size2D size = block.arrange(g2, RectangleConstraint.NONE); if (x + size.width <= width) { itemsInRow.add(block); block.setBounds( new Rectangle2D.Double(x, y, size.width, size.height) ); x = x + size.width + this.horizontalGap; maxHeight = Math.max(maxHeight, size.height); } else { if (itemsInRow.isEmpty()) { // place in this row (truncated) anyway block.setBounds( new Rectangle2D.Double( x, y, Math.min(size.width, width - x), size.height ) ); x = 0.0; y = y + size.height + this.verticalGap; } else { // start new row itemsInRow.clear(); x = 0.0; y = y + maxHeight + this.verticalGap; maxHeight = size.height; block.setBounds( new Rectangle2D.Double( x, y, Math.min(size.width, width), size.height ) ); x = size.width + this.horizontalGap; itemsInRow.add(block); } } } return new Size2D(constraint.getWidth(), y + maxHeight); } /** * Arranges the blocks in the container with a fixed width and a range * constraint on the height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size following the arrangement. */ protected Size2D arrangeFR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D s = arrangeFN(container, g2, constraint); if (constraint.getHeightRange().contains(s.height)) { return s; } else { RectangleConstraint c = constraint.toFixedHeight( constraint.getHeightRange().constrain(s.getHeight()) ); return arrangeFF(container, g2, c); } } /** * Arranges the blocks in the container with the overall height and width * specified as fixed constraints. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size following the arrangement. */ protected Size2D arrangeFF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // TODO: implement this properly return arrangeFN(container, g2, constraint); } /** * Arranges the blocks with the overall width and height to fit within * specified ranges. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size after the arrangement. */ protected Size2D arrangeRR(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, and see if this fits within // the required ranges... Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; // TODO: we didn't check the height yet } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().getUpperBound() ); return arrangeFR(container, g2, c); } } /** * Arranges the blocks in the container with a range constraint on the * width and a fixed height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size following the arrangement. */ protected Size2D arrangeRF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { Size2D s = arrangeNF(container, g2, constraint); if (constraint.getWidthRange().contains(s.width)) { return s; } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().constrain(s.getWidth()) ); return arrangeFF(container, g2, c); } } /** * Arranges the block with a range constraint on the width, and no * constraint on the height. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size following the arrangement. */ protected Size2D arrangeRN(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // first arrange without constraints, then see if the width fits // within the required range...if not, call arrangeFN() at max width Size2D s1 = arrangeNN(container, g2); if (constraint.getWidthRange().contains(s1.width)) { return s1; } else { RectangleConstraint c = constraint.toFixedWidth( constraint.getWidthRange().getUpperBound() ); return arrangeFN(container, g2, c); } } /** * Arranges the blocks without any constraints. This puts all blocks * into a single row. * * @param container the container. * @param g2 the graphics device. * * @return The size after the arrangement. */ protected Size2D arrangeNN(BlockContainer container, Graphics2D g2) { double x = 0.0; double width = 0.0; double maxHeight = 0.0; List<Block> blocks = container.getBlocks(); int blockCount = blocks.size(); if (blockCount > 0) { Size2D[] sizes = new Size2D[blocks.size()]; for (int i = 0; i < blocks.size(); i++) { Block block = blocks.get(i); sizes[i] = block.arrange(g2, RectangleConstraint.NONE); width = width + sizes[i].getWidth(); maxHeight = Math.max(sizes[i].height, maxHeight); block.setBounds( new Rectangle2D.Double( x, 0.0, sizes[i].width, sizes[i].height ) ); x = x + sizes[i].width + this.horizontalGap; } if (blockCount > 1) { width = width + this.horizontalGap * (blockCount - 1); } if (this.verticalAlignment != VerticalAlignment.TOP) { for (Block block : blocks) { //Block b = (Block) blocks.get(i); if (this.verticalAlignment == VerticalAlignment.CENTER) { //TODO: shift block down by half } else if (this.verticalAlignment == VerticalAlignment.BOTTOM) { //TODO: shift block down to bottom } } } } return new Size2D(width, maxHeight); } /** * Arranges the blocks with no width constraint and a fixed height * constraint. This puts all blocks into a single row. * * @param container the container. * @param constraint the constraint. * @param g2 the graphics device. * * @return The size after the arrangement. */ protected Size2D arrangeNF(BlockContainer container, Graphics2D g2, RectangleConstraint constraint) { // TODO: for now we are ignoring the height constraint return arrangeNN(container, g2); } /** * Clears any cached information. */ @Override public void clear() { // no action required. } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof FlowArrangement)) { return false; } FlowArrangement that = (FlowArrangement) obj; if (this.horizontalAlignment != that.horizontalAlignment) { return false; } if (this.verticalAlignment != that.verticalAlignment) { return false; } if (this.horizontalGap != that.horizontalGap) { return false; } if (this.verticalGap != that.verticalGap) { return false; } return true; } }
15,733
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CategoryPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * CategoryPlot.java * ----------------- * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Jeremy Bowman; * Arnaud Lelievre; * Richard West, Advanced Micro Devices, Inc.; * Ulrich Voigt - patch 2686040; * Peter Kolb - patches 2603321 and 2809117; * * Changes * ------- * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG); * 21-Aug-2001 : Added standard header. Fixed DOS encoding problem (DG); * 18-Sep-2001 : Updated header (DG); * 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 23-Oct-2001 : Changed intro and trail gaps on bar plots to use percentage of * available space rather than a fixed number of units (DG); * 12-Dec-2001 : Changed constructors to protected (DG); * 13-Dec-2001 : Added tooltips (DG); * 16-Jan-2002 : Increased maximum intro and trail gap percents, plus added * some argument checking code. Thanks to Taoufik Romdhane for * suggesting this (DG); * 05-Feb-2002 : Added accessor methods for the tooltip generator, incorporated * alpha-transparency for Plot and subclasses (DG); * 06-Mar-2002 : Updated import statements (DG); * 14-Mar-2002 : Renamed BarPlot.java --> CategoryPlot.java, and changed code * to use the CategoryItemRenderer interface (DG); * 22-Mar-2002 : Dropped the getCategories() method (DG); * 23-Apr-2002 : Moved the dataset from the JFreeChart class to the Plot * class (DG); * 29-Apr-2002 : New methods to support printing values at the end of bars, * contributed by Jeremy Bowman (DG); * 11-May-2002 : New methods for label visibility and overlaid plot support, * contributed by Jeremy Bowman (DG); * 06-Jun-2002 : Removed the tooltip generator, this is now stored with the * renderer. Moved constants into the CategoryPlotConstants * interface. Updated Javadoc comments (DG); * 10-Jun-2002 : Overridden datasetChanged() method to update the upper and * lower bound on the range axis (if necessary), updated * Javadocs (DG); * 25-Jun-2002 : Removed redundant imports (DG); * 20-Aug-2002 : Changed the constructor for Marker (DG); * 28-Aug-2002 : Added listener notification to setDomainAxis() and * setRangeAxis() (DG); * 23-Sep-2002 : Added getLegendItems() method and fixed errors reported by * Checkstyle (DG); * 28-Oct-2002 : Changes to the CategoryDataset interface (DG); * 05-Nov-2002 : Base dataset is now TableDataset not CategoryDataset (DG); * 07-Nov-2002 : Renamed labelXXX as valueLabelXXX (DG); * 18-Nov-2002 : Added grid settings for both domain and range axis (previously * these were set in the axes) (DG); * 19-Nov-2002 : Added axis location parameters to constructor (DG); * 17-Jan-2003 : Moved to com.jrefinery.chart.plot package (DG); * 14-Feb-2003 : Fixed bug in auto-range calculation for secondary axis (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 02-May-2003 : Moved render() method up from subclasses. Added secondary * range markers. Added an attribute to control the dataset * rendering order. Added a drawAnnotations() method. Changed * the axis location from an int to an AxisLocation (DG); * 07-May-2003 : Merged HorizontalCategoryPlot and VerticalCategoryPlot into * this class (DG); * 02-Jun-2003 : Removed check for range axis compatibility (DG); * 04-Jul-2003 : Added a domain gridline position attribute (DG); * 21-Jul-2003 : Moved DrawingSupplier to Plot superclass (DG); * 19-Aug-2003 : Added equals() method and implemented Cloneable (DG); * 01-Sep-2003 : Fixed bug 797466 (no change event when secondary dataset * changes) (DG); * 02-Sep-2003 : Fixed bug 795209 (wrong dataset checked in render2 method) and * 790407 (initialise method) (DG); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 08-Sep-2003 : Fixed bug (wrong secondary range axis being used). Changed * ValueAxis API (DG); * 10-Sep-2003 : Fixed bug in setRangeAxis() method (DG); * 15-Sep-2003 : Fixed two bugs in serialization, implemented * PublicCloneable (DG); * 23-Oct-2003 : Added event notification for changes to renderer (DG); * 26-Nov-2003 : Fixed bug (849645) in clearRangeMarkers() method (DG); * 03-Dec-2003 : Modified draw method to accept anchor (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 10-Mar-2004 : Fixed bug in axis range calculation when secondary renderer is * stacked (DG); * 12-May-2004 : Added fixed legend items (DG); * 19-May-2004 : Added check for null legend item from renderer (DG); * 02-Jun-2004 : Updated the DatasetRenderingOrder class (DG); * 05-Nov-2004 : Renamed getDatasetsMappedToRangeAxis() * --> datasetsMappedToRangeAxis(), and ensured that returned * list doesn't contain null datasets (DG); * 12-Nov-2004 : Implemented new Zoomable interface (DG); * 07-Jan-2005 : Renamed getRangeExtent() --> findRangeBounds() in * CategoryItemRenderer (DG); * 04-May-2005 : Fixed serialization of range markers (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 20-May-2005 : Added setDomainAxes() and setRangeAxes() methods, as per * RFE 1183100 (DG); * 01-Jun-2005 : Upon deserialization, register plot as a listener with its * axes, dataset(s) and renderer(s) - see patch 1209475 (DG); * 02-Jun-2005 : Added support for domain markers (DG); * 06-Jun-2005 : Fixed equals() method for use with GradientPaint (DG); * 09-Jun-2005 : Added setRenderers(), as per RFE 1183100 (DG); * 16-Jun-2005 : Added getDomainAxisCount() and getRangeAxisCount() methods, to * match XYPlot (see RFE 1220495) (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 11-Jan-2006 : Added configureRangeAxes() to rendererChanged(), since the * renderer might influence the axis range (DG); * 27-Jan-2006 : Added various null argument checks (DG); * 18-Aug-2006 : Added getDatasetCount() method, plus a fix for bug drawing * category labels, thanks to Adriaan Joubert (1277726) (DG); * 05-Sep-2006 : Added MarkerChangeEvent support (DG); * 30-Oct-2006 : Added getDomainAxisIndex(), datasetsMappedToDomainAxis() and * getCategoriesForAxis() methods (DG); * 22-Nov-2006 : Fire PlotChangeEvent from setColumnRenderingOrder() and * setRowRenderingOrder() (DG); * 29-Nov-2006 : Fix for bug 1605207 (IntervalMarker exceeds bounds of data * area) (DG); * 26-Feb-2007 : Fix for bug 1669218 (setDomainAxisLocation() notify argument * ignored) (DG); * 13-Mar-2007 : Added null argument checks for setRangeCrosshairPaint() and * setRangeCrosshairStroke(), fixed clipping for * annotations (DG); * 07-Jun-2007 : Override drawBackground() for new GradientPaint handling (DG); * 10-Jul-2007 : Added getRangeAxisIndex(ValueAxis) method (DG); * 24-Sep-2007 : Implemented new zoom methods (DG); * 25-Oct-2007 : Added some argument checks (DG); * 05-Nov-2007 : Applied patch 1823697, by Richard West, for removal of domain * and range markers (DG); * 14-Nov-2007 : Added missing event notifications (DG); * 25-Mar-2008 : Added new methods with optional notification - see patch * 1913751 (DG); * 07-Apr-2008 : Fixed NPE in removeDomainMarker() and * removeRangeMarker() (DG); * 23-Apr-2008 : Fixed equals() and clone() methods (DG); * 26-Jun-2008 : Fixed crosshair support (DG); * 10-Jul-2008 : Fixed outline visibility for 3D renderers (DG); * 12-Aug-2008 : Added rendererCount() method (DG); * 25-Nov-2008 : Added facility to map datasets to multiples axes (DG); * 15-Dec-2008 : Cleaned up grid drawing methods (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 21-Jan-2009 : Added rangeMinorGridlinesVisible flag (DG); * 18-Mar-2009 : Modified anchored zoom behaviour (DG); * 19-Mar-2009 : Implemented Pannable interface - see patch 2686040 (DG); * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * 24-Jun-2009 : Implemented AnnotationChangeListener (see patch 2809117 by * PK) (DG); * 06-Jul-2009 : Fix for cloning of renderers - see bug 2817504 (DG) * 10-Jul-2009 : Added optional drop shadow generator (DG); * 27-Sep-2011 : Fixed annotation import (DG); * 18-Oct-2011 : Fixed tooltip offset with shadow generator (DG); * 20-Nov-2011 : Initialise shadow generator as null (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection class (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.Set; import java.util.TreeMap; import org.jfree.chart.LegendItem; import org.jfree.chart.annotations.Annotation; import org.jfree.chart.annotations.CategoryAnnotation; import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.AxisCollection; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.CategoryAnchor; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.TickType; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.axis.ValueTick; import org.jfree.chart.ui.Layer; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectList; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.SortOrder; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.event.AnnotationChangeListener; import org.jfree.chart.event.ChartChangeEventType; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; import org.jfree.chart.event.RendererChangeListener; import org.jfree.chart.renderer.category.AbstractCategoryItemRenderer; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.CategoryItemRendererState; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.chart.util.ShadowGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; /** * A general plotting class that uses data from a {@link CategoryDataset} and * renders each data item using a {@link CategoryItemRenderer}. */ public class CategoryPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable, AnnotationChangeListener, RendererChangeListener, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -3537691700434728188L; /** * The default visibility of the grid lines plotted against the domain * axis. */ public static final boolean DEFAULT_DOMAIN_GRIDLINES_VISIBLE = false; /** * The default visibility of the grid lines plotted against the range * axis. */ public static final boolean DEFAULT_RANGE_GRIDLINES_VISIBLE = true; /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] {2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.LIGHT_GRAY; /** The default value label font. */ public static final Font DEFAULT_VALUE_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); /** * The default crosshair visibility. * * @since 1.0.5 */ public static final boolean DEFAULT_CROSSHAIR_VISIBLE = false; /** * The default crosshair stroke. * * @since 1.0.5 */ public static final Stroke DEFAULT_CROSSHAIR_STROKE = DEFAULT_GRIDLINE_STROKE; /** * The default crosshair paint. * * @since 1.0.5 */ public static final Paint DEFAULT_CROSSHAIR_PAINT = Color.BLUE; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** The plot orientation. */ private PlotOrientation orientation; /** The offset between the data area and the axes. */ private RectangleInsets axisOffset; /** Storage for the domain axes. */ private ObjectList<CategoryAxis> domainAxes; /** Storage for the domain axis locations. */ private ObjectList<AxisLocation> domainAxisLocations; /** * A flag that controls whether or not the shared domain axis is drawn * (only relevant when the plot is being used as a subplot). */ private boolean drawSharedDomainAxis; /** Storage for the range axes. */ private ObjectList<ValueAxis> rangeAxes; /** Storage for the range axis locations. */ private ObjectList<AxisLocation> rangeAxisLocations; /** Storage for the datasets. */ private ObjectList<CategoryDataset> datasets; /** Storage for keys that map datasets to domain axes. */ private TreeMap<Integer, List<Integer>> datasetToDomainAxesMap; /** Storage for keys that map datasets to range axes. */ private TreeMap<Integer, List<Integer>> datasetToRangeAxesMap; /** Storage for the renderers. */ private ObjectList<CategoryItemRenderer> renderers; /** The dataset rendering order. */ private DatasetRenderingOrder renderingOrder = DatasetRenderingOrder.REVERSE; /** * Controls the order in which the columns are traversed when rendering the * data items. */ private SortOrder columnRenderingOrder = SortOrder.ASCENDING; /** * Controls the order in which the rows are traversed when rendering the * data items. */ private SortOrder rowRenderingOrder = SortOrder.ASCENDING; /** * A flag that controls whether the grid-lines for the domain axis are * visible. */ private boolean domainGridlinesVisible; /** The position of the domain gridlines relative to the category. */ private CategoryAnchor domainGridlinePosition; /** The stroke used to draw the domain grid-lines. */ private transient Stroke domainGridlineStroke; /** The paint used to draw the domain grid-lines. */ private transient Paint domainGridlinePaint; /** * A flag that controls whether or not the zero baseline against the range * axis is visible. * * @since 1.0.13 */ private boolean rangeZeroBaselineVisible; /** * The stroke used for the zero baseline against the range axis. * * @since 1.0.13 */ private transient Stroke rangeZeroBaselineStroke; /** * The paint used for the zero baseline against the range axis. * * @since 1.0.13 */ private transient Paint rangeZeroBaselinePaint; /** * A flag that controls whether the grid-lines for the range axis are * visible. */ private boolean rangeGridlinesVisible; /** The stroke used to draw the range axis grid-lines. */ private transient Stroke rangeGridlineStroke; /** The paint used to draw the range axis grid-lines. */ private transient Paint rangeGridlinePaint; /** * A flag that controls whether or not gridlines are shown for the minor * tick values on the primary range axis. * * @since 1.0.13 */ private boolean rangeMinorGridlinesVisible; /** * The stroke used to draw the range minor grid-lines. * * @since 1.0.13 */ private transient Stroke rangeMinorGridlineStroke; /** * The paint used to draw the range minor grid-lines. * * @since 1.0.13 */ private transient Paint rangeMinorGridlinePaint; /** The anchor value. */ private double anchorValue; /** * The index for the dataset that the crosshairs are linked to (this * determines which axes the crosshairs are plotted against). * * @since 1.0.11 */ private int crosshairDatasetIndex; /** * A flag that controls the visibility of the domain crosshair. * * @since 1.0.11 */ private boolean domainCrosshairVisible; /** * The row key for the crosshair point. * * @since 1.0.11 */ private Comparable domainCrosshairRowKey; /** * The column key for the crosshair point. * * @since 1.0.11 */ private Comparable domainCrosshairColumnKey; /** * The stroke used to draw the domain crosshair if it is visible. * * @since 1.0.11 */ private transient Stroke domainCrosshairStroke; /** * The paint used to draw the domain crosshair if it is visible. * * @since 1.0.11 */ private transient Paint domainCrosshairPaint; /** A flag that controls whether or not a range crosshair is drawn. */ private boolean rangeCrosshairVisible; /** The range crosshair value. */ private double rangeCrosshairValue; /** The pen/brush used to draw the crosshair (if any). */ private transient Stroke rangeCrosshairStroke; /** The color used to draw the crosshair (if any). */ private transient Paint rangeCrosshairPaint; /** * A flag that controls whether or not the crosshair locks onto actual * data points. */ private boolean rangeCrosshairLockedOnData = true; /** A map containing lists of markers for the domain axes. */ private Map<Integer, Collection<Marker>> foregroundDomainMarkers; /** A map containing lists of markers for the domain axes. */ private Map<Integer, Collection<Marker>> backgroundDomainMarkers; /** A map containing lists of markers for the range axes. */ private Map<Integer, Collection<Marker>> foregroundRangeMarkers; /** A map containing lists of markers for the range axes. */ private Map<Integer, Collection<Marker>> backgroundRangeMarkers; /** * A (possibly empty) list of annotations for the plot. The list should * be initialised in the constructor and never allowed to be * <code>null</code>. */ private List<CategoryAnnotation> annotations; /** * The weight for the plot (only relevant when the plot is used as a subplot * within a combined plot). */ private int weight; /** The fixed space for the domain axis. */ private AxisSpace fixedDomainAxisSpace; /** The fixed space for the range axis. */ private AxisSpace fixedRangeAxisSpace; /** * An optional collection of legend items that can be returned by the * getLegendItems() method. */ private List<LegendItem> fixedLegendItems; /** * A flag that controls whether or not panning is enabled for the * range axis/axes. * * @since 1.0.13 */ private boolean rangePannable; /** * The shadow generator for the plot (<code>null</code> permitted). * * @since 1.0.14 */ private ShadowGenerator shadowGenerator; /** * Default constructor. */ public CategoryPlot() { this(null, null, null, null); } /** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). * @param domainAxis the domain axis (<code>null</code> permitted). * @param rangeAxis the range axis (<code>null</code> permitted). * @param renderer the item renderer (<code>null</code> permitted). * */ public CategoryPlot(CategoryDataset dataset, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryItemRenderer renderer) { super(); this.orientation = PlotOrientation.VERTICAL; // allocate storage for dataset, axes and renderers this.domainAxes = new ObjectList<CategoryAxis>(); this.domainAxisLocations = new ObjectList<AxisLocation>(); this.rangeAxes = new ObjectList<ValueAxis>(); this.rangeAxisLocations = new ObjectList<AxisLocation>(); this.datasetToDomainAxesMap = new TreeMap<Integer, List<Integer>>(); this.datasetToRangeAxesMap = new TreeMap<Integer, List<Integer>>(); this.renderers = new ObjectList<CategoryItemRenderer>(); this.datasets = new ObjectList<CategoryDataset>(); this.datasets.set(0, dataset); if (dataset != null) { dataset.addChangeListener(this); } this.axisOffset = RectangleInsets.ZERO_INSETS; setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT, false); setRangeAxisLocation(AxisLocation.TOP_OR_LEFT, false); this.renderers.set(0, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } this.domainAxes.set(0, domainAxis); this.mapDatasetToDomainAxis(0, 0); if (domainAxis != null) { domainAxis.setPlot(this); domainAxis.addChangeListener(this); } this.drawSharedDomainAxis = false; this.rangeAxes.set(0, rangeAxis); this.mapDatasetToRangeAxis(0, 0); if (rangeAxis != null) { rangeAxis.setPlot(this); rangeAxis.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); this.domainGridlinesVisible = DEFAULT_DOMAIN_GRIDLINES_VISIBLE; this.domainGridlinePosition = CategoryAnchor.MIDDLE; this.domainGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.domainGridlinePaint = DEFAULT_GRIDLINE_PAINT; this.rangeZeroBaselineVisible = false; this.rangeZeroBaselinePaint = Color.BLACK; this.rangeZeroBaselineStroke = new BasicStroke(0.5f); this.rangeGridlinesVisible = DEFAULT_RANGE_GRIDLINES_VISIBLE; this.rangeGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.rangeGridlinePaint = DEFAULT_GRIDLINE_PAINT; this.rangeMinorGridlinesVisible = false; this.rangeMinorGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.rangeMinorGridlinePaint = Color.WHITE; this.foregroundDomainMarkers = new HashMap<Integer, Collection<Marker>>(); this.backgroundDomainMarkers = new HashMap<Integer, Collection<Marker>>(); this.foregroundRangeMarkers = new HashMap<Integer, Collection<Marker>>(); this.backgroundRangeMarkers = new HashMap<Integer, Collection<Marker>>(); this.anchorValue = 0.0; this.domainCrosshairVisible = false; this.domainCrosshairStroke = DEFAULT_CROSSHAIR_STROKE; this.domainCrosshairPaint = DEFAULT_CROSSHAIR_PAINT; this.rangeCrosshairVisible = DEFAULT_CROSSHAIR_VISIBLE; this.rangeCrosshairValue = 0.0; this.rangeCrosshairStroke = DEFAULT_CROSSHAIR_STROKE; this.rangeCrosshairPaint = DEFAULT_CROSSHAIR_PAINT; this.annotations = new java.util.ArrayList<CategoryAnnotation>(); this.rangePannable = false; this.shadowGenerator = null; } /** * Returns a string describing the type of plot. * * @return The type. */ @Override public String getPlotType() { return localizationResources.getString("Category_Plot"); } /** * Returns the orientation of the plot. * * @return The orientation of the plot (never <code>null</code>). * * @see #setOrientation(PlotOrientation) */ @Override public PlotOrientation getOrientation() { return this.orientation; } /** * Sets the orientation for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param orientation the orientation (<code>null</code> not permitted). * * @see #getOrientation() */ public void setOrientation(PlotOrientation orientation) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } this.orientation = orientation; fireChangeEvent(); } /** * Returns the axis offset. * * @return The axis offset (never <code>null</code>). * * @see #setAxisOffset(RectangleInsets) */ public RectangleInsets getAxisOffset() { return this.axisOffset; } /** * Sets the axis offsets (gap between the data area and the axes) and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param offset the offset (<code>null</code> not permitted). * * @see #getAxisOffset() */ public void setAxisOffset(RectangleInsets offset) { if (offset == null) { throw new IllegalArgumentException("Null 'offset' argument."); } this.axisOffset = offset; fireChangeEvent(); } /** * Returns the domain axis for the plot. If the domain axis for this plot * is <code>null</code>, then the method will return the parent plot's * domain axis (if there is a parent plot). * * @return The domain axis (<code>null</code> permitted). * * @see #setDomainAxis(CategoryAxis) */ public CategoryAxis getDomainAxis() { return getDomainAxis(0); } /** * Returns a domain axis. * * @param index the axis index. * * @return The axis (<code>null</code> possible). * * @see #setDomainAxis(int, CategoryAxis) */ public CategoryAxis getDomainAxis(int index) { CategoryAxis result = null; if (index < this.domainAxes.size()) { result = this.domainAxes.get(index); } if (result == null) { Plot parent = getParent(); if (parent instanceof CategoryPlot) { CategoryPlot cp = (CategoryPlot) parent; result = cp.getDomainAxis(index); } } return result; } /** * Sets the domain axis for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param axis the axis (<code>null</code> permitted). * * @see #getDomainAxis() */ public void setDomainAxis(CategoryAxis axis) { setDomainAxis(0, axis); } /** * Sets a domain axis and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * * @see #getDomainAxis(int) */ public void setDomainAxis(int index, CategoryAxis axis) { setDomainAxis(index, axis, true); } /** * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * @param notify notify listeners? */ public void setDomainAxis(int index, CategoryAxis axis, boolean notify) { CategoryAxis existing = this.domainAxes.get(index); if (existing != null) { existing.removeChangeListener(this); } if (axis != null) { axis.setPlot(this); } this.domainAxes.set(index, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } if (notify) { fireChangeEvent(); } } /** * Sets the domain axes for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axes the axes (<code>null</code> not permitted). * * @see #setRangeAxes(ValueAxis[]) */ public void setDomainAxes(CategoryAxis[] axes) { for (int i = 0; i < axes.length; i++) { setDomainAxis(i, axes[i], false); } fireChangeEvent(); } /** * Returns the index of the specified axis, or <code>-1</code> if the axis * is not assigned to the plot. * * @param axis the axis (<code>null</code> not permitted). * * @return The axis index. * * @see #getDomainAxis(int) * @see #getRangeAxisIndex(ValueAxis) * * @since 1.0.3 */ public int getDomainAxisIndex(CategoryAxis axis) { if (axis == null) { throw new IllegalArgumentException("Null 'axis' argument."); } return this.domainAxes.indexOf(axis); } /** * Returns the domain axis location for the primary domain axis. * * @return The location (never <code>null</code>). * * @see #getRangeAxisLocation() */ public AxisLocation getDomainAxisLocation() { return getDomainAxisLocation(0); } /** * Returns the location for a domain axis. * * @param index the axis index. * * @return The location. * * @see #setDomainAxisLocation(int, AxisLocation) */ public AxisLocation getDomainAxisLocation(int index) { AxisLocation result = null; if (index < this.domainAxisLocations.size()) { result = this.domainAxisLocations.get(index); } if (result == null) { result = AxisLocation.getOpposite(getDomainAxisLocation(0)); } return result; } /** * Sets the location of the domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param location the axis location (<code>null</code> not permitted). * * @see #getDomainAxisLocation() * @see #setDomainAxisLocation(int, AxisLocation) */ public void setDomainAxisLocation(AxisLocation location) { // delegate... setDomainAxisLocation(0, location, true); } /** * Sets the location of the domain axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the axis location (<code>null</code> not permitted). * @param notify a flag that controls whether listeners are notified. */ public void setDomainAxisLocation(AxisLocation location, boolean notify) { // delegate... setDomainAxisLocation(0, location, notify); } /** * Sets the location for a domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * * @see #getDomainAxisLocation(int) * @see #setRangeAxisLocation(int, AxisLocation) */ public void setDomainAxisLocation(int index, AxisLocation location) { // delegate... setDomainAxisLocation(index, location, true); } /** * Sets the location for a domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * @param notify notify listeners? * * @since 1.0.5 * * @see #getDomainAxisLocation(int) * @see #setRangeAxisLocation(int, AxisLocation, boolean) */ public void setDomainAxisLocation(int index, AxisLocation location, boolean notify) { if (index == 0 && location == null) { throw new IllegalArgumentException( "Null 'location' for index 0 not permitted."); } this.domainAxisLocations.set(index, location); if (notify) { fireChangeEvent(); } } /** * Returns the domain axis edge. This is derived from the axis location * and the plot orientation. * * @return The edge (never <code>null</code>). */ public RectangleEdge getDomainAxisEdge() { return getDomainAxisEdge(0); } /** * Returns the edge for a domain axis. * * @param index the axis index. * * @return The edge (never <code>null</code>). */ public RectangleEdge getDomainAxisEdge(int index) { RectangleEdge result; AxisLocation location = getDomainAxisLocation(index); if (location != null) { result = Plot.resolveDomainAxisLocation(location, this.orientation); } else { result = RectangleEdge.opposite(getDomainAxisEdge(0)); } return result; } /** * Returns the number of domain axes. * * @return The axis count. */ public int getDomainAxisCount() { return this.domainAxes.size(); } /** * Clears the domain axes from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. */ public void clearDomainAxes() { for (int i = 0; i < this.domainAxes.size(); i++) { CategoryAxis axis = this.domainAxes.get(i); if (axis != null) { axis.removeChangeListener(this); } } this.domainAxes.clear(); fireChangeEvent(); } /** * Configures the domain axes. */ public void configureDomainAxes() { for (int i = 0; i < this.domainAxes.size(); i++) { CategoryAxis axis = this.domainAxes.get(i); if (axis != null) { axis.configure(); } } } /** * Returns the range axis for the plot. If the range axis for this plot is * null, then the method will return the parent plot's range axis (if there * is a parent plot). * * @return The range axis (possibly <code>null</code>). */ public ValueAxis getRangeAxis() { return getRangeAxis(0); } /** * Returns a range axis. * * @param index the axis index. * * @return The axis (<code>null</code> possible). */ public ValueAxis getRangeAxis(int index) { ValueAxis result = null; if (index < this.rangeAxes.size()) { result = this.rangeAxes.get(index); } if (result == null) { Plot parent = getParent(); if (parent instanceof CategoryPlot) { CategoryPlot cp = (CategoryPlot) parent; result = cp.getRangeAxis(index); } } return result; } /** * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param axis the axis (<code>null</code> permitted). */ public void setRangeAxis(ValueAxis axis) { setRangeAxis(0, axis); } /** * Sets a range axis and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param index the axis index. * @param axis the axis. */ public void setRangeAxis(int index, ValueAxis axis) { setRangeAxis(index, axis, true); } /** * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param index the axis index. * @param axis the axis. * @param notify notify listeners? */ public void setRangeAxis(int index, ValueAxis axis, boolean notify) { ValueAxis existing = this.rangeAxes.get(index); if (existing != null) { existing.removeChangeListener(this); } if (axis != null) { axis.setPlot(this); } this.rangeAxes.set(index, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } if (notify) { fireChangeEvent(); } } /** * Sets the range axes for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axes the axes (<code>null</code> not permitted). * * @see #setDomainAxes(CategoryAxis[]) */ public void setRangeAxes(ValueAxis[] axes) { for (int i = 0; i < axes.length; i++) { setRangeAxis(i, axes[i], false); } fireChangeEvent(); } /** * Returns the index of the specified axis, or <code>-1</code> if the axis * is not assigned to the plot. * * @param axis the axis (<code>null</code> not permitted). * * @return The axis index. * * @see #getRangeAxis(int) * @see #getDomainAxisIndex(CategoryAxis) * * @since 1.0.7 */ public int getRangeAxisIndex(ValueAxis axis) { if (axis == null) { throw new IllegalArgumentException("Null 'axis' argument."); } int result = this.rangeAxes.indexOf(axis); if (result < 0) { // try the parent plot Plot parent = getParent(); if (parent instanceof CategoryPlot) { CategoryPlot p = (CategoryPlot) parent; result = p.getRangeAxisIndex(axis); } } return result; } /** * Returns the range axis location. * * @return The location (never <code>null</code>). */ public AxisLocation getRangeAxisLocation() { return getRangeAxisLocation(0); } /** * Returns the location for a range axis. * * @param index the axis index. * * @return The location. * * @see #setRangeAxisLocation(int, AxisLocation) */ public AxisLocation getRangeAxisLocation(int index) { AxisLocation result = null; if (index < this.rangeAxisLocations.size()) { result = this.rangeAxisLocations.get(index); } if (result == null) { result = AxisLocation.getOpposite(getRangeAxisLocation(0)); } return result; } /** * Sets the location of the range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param location the location (<code>null</code> not permitted). * * @see #setRangeAxisLocation(AxisLocation, boolean) * @see #setDomainAxisLocation(AxisLocation) */ public void setRangeAxisLocation(AxisLocation location) { // defer argument checking... setRangeAxisLocation(location, true); } /** * Sets the location of the range axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? * * @see #setDomainAxisLocation(AxisLocation, boolean) */ public void setRangeAxisLocation(AxisLocation location, boolean notify) { setRangeAxisLocation(0, location, notify); } /** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * * @see #getRangeAxisLocation(int) * @see #setRangeAxisLocation(int, AxisLocation, boolean) */ public void setRangeAxisLocation(int index, AxisLocation location) { setRangeAxisLocation(index, location, true); } /** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location. * @param notify notify listeners? * * @see #getRangeAxisLocation(int) * @see #setDomainAxisLocation(int, AxisLocation, boolean) */ public void setRangeAxisLocation(int index, AxisLocation location, boolean notify) { if (index == 0 && location == null) { throw new IllegalArgumentException( "Null 'location' for index 0 not permitted."); } this.rangeAxisLocations.set(index, location); if (notify) { fireChangeEvent(); } } /** * Returns the edge where the primary range axis is located. * * @return The edge (never <code>null</code>). */ public RectangleEdge getRangeAxisEdge() { return getRangeAxisEdge(0); } /** * Returns the edge for a range axis. * * @param index the axis index. * * @return The edge. */ public RectangleEdge getRangeAxisEdge(int index) { AxisLocation location = getRangeAxisLocation(index); return Plot.resolveRangeAxisLocation(location, this.orientation); } /** * Returns the number of range axes. * * @return The axis count. */ public int getRangeAxisCount() { return this.rangeAxes.size(); } /** * Clears the range axes from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. */ public void clearRangeAxes() { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = this.rangeAxes.get(i); if (axis != null) { axis.removeChangeListener(this); } } this.rangeAxes.clear(); fireChangeEvent(); } /** * Configures the range axes. */ public void configureRangeAxes() { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = this.rangeAxes.get(i); if (axis != null) { axis.configure(); } } } /** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). * * @see #setDataset(CategoryDataset) */ public CategoryDataset getDataset() { return getDataset(0); } /** * Returns the dataset at the given index. * * @param index the dataset index. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(int, CategoryDataset) */ public CategoryDataset getDataset(int index) { CategoryDataset result = null; if (this.datasets.size() > index) { result = this.datasets.get(index); } return result; } /** * Sets the dataset for the plot, replacing the existing dataset, if there * is one. This method also calls the * {@link #datasetChanged(DatasetChangeEvent)} method, which adjusts the * axis ranges if necessary and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() */ public void setDataset(CategoryDataset dataset) { setDataset(0, dataset); } /** * Sets a dataset for the plot. * * @param index the dataset index. * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset(int) */ public void setDataset(int index, CategoryDataset dataset) { CategoryDataset existing = this.datasets.get(index); if (existing != null) { existing.removeChangeListener(this); } this.datasets.set(index, dataset); if (dataset != null) { dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns the number of datasets. * * @return The number of datasets. * * @since 1.0.2 */ public int getDatasetCount() { return this.datasets.size(); } /** * Returns the index of the specified dataset, or <code>-1</code> if the * dataset does not belong to the plot. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The index. * * @since 1.0.11 */ public int indexOf(CategoryDataset dataset) { int result = -1; for (int i = 0; i < this.datasets.size(); i++) { if (dataset == this.datasets.get(i)) { result = i; break; } } return result; } /** * Maps a dataset to a particular domain axis. * * @param index the dataset index (zero-based). * @param axisIndex the axis index (zero-based). * * @see #getDomainAxisForDataset(int) */ public void mapDatasetToDomainAxis(int index, int axisIndex) { List<Integer> axisIndices = new java.util.ArrayList<Integer>(1); axisIndices.add(axisIndex); mapDatasetToDomainAxes(index, axisIndices); } /** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices (<code>null</code> permitted). * * @since 1.0.12 */ public void mapDatasetToDomainAxes(int index, List<Integer> axisIndices) { if (index < 0) { throw new IllegalArgumentException("Requires 'index' >= 0."); } checkAxisIndices(axisIndices); this.datasetToDomainAxesMap.put(index, new ArrayList<Integer>(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * This method is used to perform argument checking on the list of * axis indices passed to mapDatasetToDomainAxes() and * mapDatasetToRangeAxes(). * * @param indices the list of indices (<code>null</code> permitted). */ private void checkAxisIndices(List<Integer> indices) { // axisIndices can be: // 1. null; // 2. non-empty, containing only Integer objects that are unique. if (indices == null) { return; // OK } int count = indices.size(); if (count == 0) { throw new IllegalArgumentException("Empty list not permitted."); } HashSet<Integer> set = new HashSet<Integer>(); for (Integer item : indices) { if (set.contains(item)) { throw new IllegalArgumentException("Indices must be unique."); } set.add(item); } } /** * Returns the domain axis for a dataset. You can change the axis for a * dataset using the {@link #mapDatasetToDomainAxis(int, int)} method. * * @param index the dataset index. * * @return The domain axis. * * @see #mapDatasetToDomainAxis(int, int) */ public CategoryAxis getDomainAxisForDataset(int index) { if (index < 0) { throw new IllegalArgumentException("Negative 'index'."); } CategoryAxis axis; List<Integer> axisIndices = this.datasetToDomainAxesMap.get( Integer.valueOf(index)); if (axisIndices != null) { // the first axis in the list is used for data <--> Java2D Integer axisIndex = axisIndices.get(0); axis = getDomainAxis(axisIndex); } else { axis = getDomainAxis(0); } return axis; } /** * Maps a dataset to a particular range axis. * * @param index the dataset index (zero-based). * @param axisIndex the axis index (zero-based). * * @see #getRangeAxisForDataset(int) */ public void mapDatasetToRangeAxis(int index, int axisIndex) { List<Integer> axisIndices = new java.util.ArrayList<Integer>(1); axisIndices.add(axisIndex); mapDatasetToRangeAxes(index, axisIndices); } /** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices (<code>null</code> permitted). * * @since 1.0.12 */ public void mapDatasetToRangeAxes(int index, List<Integer> axisIndices) { if (index < 0) { throw new IllegalArgumentException("Requires 'index' >= 0."); } checkAxisIndices(axisIndices); Integer key = index; this.datasetToRangeAxesMap.put(key, new ArrayList<Integer>(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * Returns the range axis for a dataset. You can change the axis for a * dataset using the {@link #mapDatasetToRangeAxis(int, int)} method. * * @param index the dataset index. * * @return The range axis. * * @see #mapDatasetToRangeAxis(int, int) */ public ValueAxis getRangeAxisForDataset(int index) { if (index < 0) { throw new IllegalArgumentException("Negative 'index'."); } ValueAxis axis; List<Integer> axisIndices = this.datasetToRangeAxesMap.get( Integer.valueOf(index)); if (axisIndices != null) { // the first axis in the list is used for data <--> Java2D Integer axisIndex = axisIndices.get(0); axis = getRangeAxis(axisIndex); } else { axis = getRangeAxis(0); } return axis; } /** * Returns the number of renderer slots for this plot. * * @return The number of renderer slots. * * @since 1.0.11 */ public int getRendererCount() { return this.renderers.size(); } /** * Returns a reference to the renderer for the plot. * * @return The renderer. * * @see #setRenderer(CategoryItemRenderer) */ public CategoryItemRenderer getRenderer() { return getRenderer(0); } /** * Returns the renderer at the given index. * * @param index the renderer index. * * @return The renderer (possibly <code>null</code>). * * @see #setRenderer(int, CategoryItemRenderer) */ public CategoryItemRenderer getRenderer(int index) { CategoryItemRenderer result = null; if (this.renderers.size() > index) { result = this.renderers.get(index); } return result; } /** * Sets the renderer at index 0 (sometimes referred to as the "primary" * renderer) and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param renderer the renderer (<code>null</code> permitted. * * @see #getRenderer() */ public void setRenderer(CategoryItemRenderer renderer) { setRenderer(0, renderer, true); } /** * Sets the renderer at index 0 (sometimes referred to as the "primary" * renderer) and, if requested, sends a {@link PlotChangeEvent} to all * registered listeners. * <p> * You can set the renderer to <code>null</code>, but this is not * recommended because: * <ul> * <li>no data will be displayed;</li> * <li>the plot background will not be painted;</li> * </ul> * * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? * * @see #getRenderer() */ public void setRenderer(CategoryItemRenderer renderer, boolean notify) { setRenderer(0, renderer, notify); } /** * Sets the renderer at the specified index and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). * * @see #getRenderer(int) * @see #setRenderer(int, CategoryItemRenderer, boolean) */ public void setRenderer(int index, CategoryItemRenderer renderer) { setRenderer(index, renderer, true); } /** * Sets a renderer. A {@link PlotChangeEvent} is sent to all registered * listeners. * * @param index the index. * @param renderer the renderer (<code>null</code> permitted). * @param notify notify listeners? * * @see #getRenderer(int) */ public void setRenderer(int index, CategoryItemRenderer renderer, boolean notify) { // stop listening to the existing renderer... CategoryItemRenderer existing = this.renderers.get(index); if (existing != null) { existing.removeChangeListener(this); } // register the new renderer... this.renderers.set(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { fireChangeEvent(); } } /** * Sets the renderers for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param renderers the renderers. */ public void setRenderers(CategoryItemRenderer[] renderers) { for (int i = 0; i < renderers.length; i++) { setRenderer(i, renderers[i], false); } fireChangeEvent(); } /** * Returns the renderer for the specified dataset. If the dataset doesn't * belong to the plot, this method will return <code>null</code>. * * @param dataset the dataset (<code>null</code> permitted). * * @return The renderer (possibly <code>null</code>). */ public CategoryItemRenderer getRendererForDataset(CategoryDataset dataset) { CategoryItemRenderer result = null; for (int i = 0; i < this.datasets.size(); i++) { if (this.datasets.get(i) == dataset) { result = this.renderers.get(i); break; } } return result; } /** * Returns the index of the specified renderer, or <code>-1</code> if the * renderer is not assigned to this plot. * * @param renderer the renderer (<code>null</code> permitted). * * @return The renderer index. */ public int getIndexOf(CategoryItemRenderer renderer) { return this.renderers.indexOf(renderer); } /** * Returns the dataset rendering order. * * @return The order (never <code>null</code>). * * @see #setDatasetRenderingOrder(DatasetRenderingOrder) */ public DatasetRenderingOrder getDatasetRenderingOrder() { return this.renderingOrder; } /** * Sets the rendering order and sends a {@link PlotChangeEvent} to all * registered listeners. By default, the plot renders the primary dataset * last (so that the primary dataset overlays the secondary datasets). You * can reverse this if you want to. * * @param order the rendering order (<code>null</code> not permitted). * * @see #getDatasetRenderingOrder() */ public void setDatasetRenderingOrder(DatasetRenderingOrder order) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } this.renderingOrder = order; fireChangeEvent(); } /** * Returns the order in which the columns are rendered. The default value * is <code>SortOrder.ASCENDING</code>. * * @return The column rendering order (never <code>null</code). * * @see #setColumnRenderingOrder(SortOrder) */ public SortOrder getColumnRenderingOrder() { return this.columnRenderingOrder; } /** * Sets the column order in which the items in each dataset should be * rendered and sends a {@link PlotChangeEvent} to all registered * listeners. Note that this affects the order in which items are drawn, * NOT their position in the chart. * * @param order the order (<code>null</code> not permitted). * * @see #getColumnRenderingOrder() * @see #setRowRenderingOrder(SortOrder) */ public void setColumnRenderingOrder(SortOrder order) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } this.columnRenderingOrder = order; fireChangeEvent(); } /** * Returns the order in which the rows should be rendered. The default * value is <code>SortOrder.ASCENDING</code>. * * @return The order (never <code>null</code>). * * @see #setRowRenderingOrder(SortOrder) */ public SortOrder getRowRenderingOrder() { return this.rowRenderingOrder; } /** * Sets the row order in which the items in each dataset should be * rendered and sends a {@link PlotChangeEvent} to all registered * listeners. Note that this affects the order in which items are drawn, * NOT their position in the chart. * * @param order the order (<code>null</code> not permitted). * * @see #getRowRenderingOrder() * @see #setColumnRenderingOrder(SortOrder) */ public void setRowRenderingOrder(SortOrder order) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } this.rowRenderingOrder = order; fireChangeEvent(); } /** * Returns the flag that controls whether the domain grid-lines are visible. * * @return The <code>true</code> or <code>false</code>. * * @see #setDomainGridlinesVisible(boolean) */ public boolean isDomainGridlinesVisible() { return this.domainGridlinesVisible; } /** * Sets the flag that controls whether or not grid-lines are drawn against * the domain axis. * <p> * If the flag value changes, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isDomainGridlinesVisible() */ public void setDomainGridlinesVisible(boolean visible) { if (this.domainGridlinesVisible != visible) { this.domainGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the position used for the domain gridlines. * * @return The gridline position (never <code>null</code>). * * @see #setDomainGridlinePosition(CategoryAnchor) */ public CategoryAnchor getDomainGridlinePosition() { return this.domainGridlinePosition; } /** * Sets the position used for the domain gridlines and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param position the position (<code>null</code> not permitted). * * @see #getDomainGridlinePosition() */ public void setDomainGridlinePosition(CategoryAnchor position) { if (position == null) { throw new IllegalArgumentException("Null 'position' argument."); } this.domainGridlinePosition = position; fireChangeEvent(); } /** * Returns the stroke used to draw grid-lines against the domain axis. * * @return The stroke (never <code>null</code>). * * @see #setDomainGridlineStroke(Stroke) */ public Stroke getDomainGridlineStroke() { return this.domainGridlineStroke; } /** * Sets the stroke used to draw grid-lines against the domain axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getDomainGridlineStroke() */ public void setDomainGridlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' not permitted."); } this.domainGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint used to draw grid-lines against the domain axis. * * @return The paint (never <code>null</code>). * * @see #setDomainGridlinePaint(Paint) */ public Paint getDomainGridlinePaint() { return this.domainGridlinePaint; } /** * Sets the paint used to draw the grid-lines (if any) against the domain * axis and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getDomainGridlinePaint() */ public void setDomainGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.domainGridlinePaint = paint; fireChangeEvent(); } /** * Returns a flag that controls whether or not a zero baseline is * displayed for the range axis. * * @return A boolean. * * @see #setRangeZeroBaselineVisible(boolean) * * @since 1.0.13 */ public boolean isRangeZeroBaselineVisible() { return this.rangeZeroBaselineVisible; } /** * Sets the flag that controls whether or not the zero baseline is * displayed for the range axis, and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param visible the flag. * * @see #isRangeZeroBaselineVisible() * * @since 1.0.13 */ public void setRangeZeroBaselineVisible(boolean visible) { this.rangeZeroBaselineVisible = visible; fireChangeEvent(); } /** * Returns the stroke used for the zero baseline against the range axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeZeroBaselineStroke(Stroke) * * @since 1.0.13 */ public Stroke getRangeZeroBaselineStroke() { return this.rangeZeroBaselineStroke; } /** * Sets the stroke for the zero baseline for the range axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getRangeZeroBaselineStroke() * * @since 1.0.13 */ public void setRangeZeroBaselineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.rangeZeroBaselineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the zero baseline (if any) plotted against the * range axis. * * @return The paint (never <code>null</code>). * * @see #setRangeZeroBaselinePaint(Paint) * * @since 1.0.13 */ public Paint getRangeZeroBaselinePaint() { return this.rangeZeroBaselinePaint; } /** * Sets the paint for the zero baseline plotted against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeZeroBaselinePaint() * * @since 1.0.13 */ public void setRangeZeroBaselinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeZeroBaselinePaint = paint; fireChangeEvent(); } /** * Returns the flag that controls whether the range grid-lines are visible. * * @return The flag. * * @see #setRangeGridlinesVisible(boolean) */ public boolean isRangeGridlinesVisible() { return this.rangeGridlinesVisible; } /** * Sets the flag that controls whether or not grid-lines are drawn against * the range axis. If the flag changes value, a {@link PlotChangeEvent} is * sent to all registered listeners. * * @param visible the new value of the flag. * * @see #isRangeGridlinesVisible() */ public void setRangeGridlinesVisible(boolean visible) { if (this.rangeGridlinesVisible != visible) { this.rangeGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke used to draw the grid-lines against the range axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeGridlineStroke(Stroke) */ public Stroke getRangeGridlineStroke() { return this.rangeGridlineStroke; } /** * Sets the stroke used to draw the grid-lines against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getRangeGridlineStroke() */ public void setRangeGridlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.rangeGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint used to draw the grid-lines against the range axis. * * @return The paint (never <code>null</code>). * * @see #setRangeGridlinePaint(Paint) */ public Paint getRangeGridlinePaint() { return this.rangeGridlinePaint; } /** * Sets the paint used to draw the grid lines against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeGridlinePaint() */ public void setRangeGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeGridlinePaint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the range axis minor grid is visible, and * <code>false</code> otherwise. * * @return A boolean. * * @see #setRangeMinorGridlinesVisible(boolean) * * @since 1.0.13 */ public boolean isRangeMinorGridlinesVisible() { return this.rangeMinorGridlinesVisible; } /** * Sets the flag that controls whether or not the range axis minor grid * lines are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isRangeMinorGridlinesVisible() * * @since 1.0.13 */ public void setRangeMinorGridlinesVisible(boolean visible) { if (this.rangeMinorGridlinesVisible != visible) { this.rangeMinorGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the minor grid lines (if any) plotted against the * range axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeMinorGridlineStroke(Stroke) * * @since 1.0.13 */ public Stroke getRangeMinorGridlineStroke() { return this.rangeMinorGridlineStroke; } /** * Sets the stroke for the minor grid lines plotted against the range axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getRangeMinorGridlineStroke() * * @since 1.0.13 */ public void setRangeMinorGridlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.rangeMinorGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the minor grid lines (if any) plotted against the * range axis. * * @return The paint (never <code>null</code>). * * @see #setRangeMinorGridlinePaint(Paint) * * @since 1.0.13 */ public Paint getRangeMinorGridlinePaint() { return this.rangeMinorGridlinePaint; } /** * Sets the paint for the minor grid lines plotted against the range axis * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeMinorGridlinePaint() * * @since 1.0.13 */ public void setRangeMinorGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeMinorGridlinePaint = paint; fireChangeEvent(); } /** * Returns the fixed legend items, if any. * * @return The legend items (possibly <code>null</code>). * * @see #setFixedLegendItems(LegendItemCollection) */ public List<LegendItem> getFixedLegendItems() { return this.fixedLegendItems; } /** * Sets the fixed legend items for the plot. Leave this set to * <code>null</code> if you prefer the legend items to be created * automatically. * * @param items the legend items (<code>null</code> permitted). * * @see #getFixedLegendItems() */ public void setFixedLegendItems(List<LegendItem> items) { this.fixedLegendItems = items; fireChangeEvent(); } /** * Returns the legend items for the plot. By default, this method creates * a legend item for each series in each of the datasets. You can change * this behaviour by overriding this method. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { if (this.fixedLegendItems != null) { return this.fixedLegendItems; } List<LegendItem> result = new ArrayList<LegendItem>(); // get the legend items for the datasets... int count = this.datasets.size(); for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) { CategoryDataset dataset = getDataset(datasetIndex); if (dataset != null) { CategoryItemRenderer renderer = getRenderer(datasetIndex); if (renderer != null) { result.addAll(renderer.getLegendItems()); } } } return result; } /** * Handles a 'click' on the plot by updating the anchor value. * * @param x x-coordinate of the click (in Java2D space). * @param y y-coordinate of the click (in Java2D space). * @param info information about the plot's dimensions. * */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { // set the anchor value for the range axis... double java2D = 0.0; if (this.orientation == PlotOrientation.HORIZONTAL) { java2D = x; } else if (this.orientation == PlotOrientation.VERTICAL) { java2D = y; } RectangleEdge edge = Plot.resolveRangeAxisLocation( getRangeAxisLocation(), this.orientation); double value = getRangeAxis().java2DToValue( java2D, info.getDataArea(), edge); setAnchorValue(value); setRangeCrosshairValue(value); } } /** * Zooms (in or out) on the plot's value axis. * <p> * If the value 0.0 is passed in as the zoom percent, the auto-range * calculation for the axis is restored (which sets the range to include * the minimum and maximum data values, thus displaying all the data). * * @param percent the zoom amount. */ @Override public void zoom(double percent) { if (percent > 0.0) { double range = getRangeAxis().getRange().getLength(); double scaledRange = range * percent; getRangeAxis().setRange(this.anchorValue - scaledRange / 2.0, this.anchorValue + scaledRange / 2.0); } else { getRangeAxis().setAutoRange(true); } } /** * Receives notification of a change to an {@link Annotation} added to * this plot. * * @param event information about the event (not used here). * * @since 1.0.14 */ @Override public void annotationChanged(AnnotationChangeEvent event) { if (getParent() != null) { getParent().annotationChanged(event); } else { PlotChangeEvent e = new PlotChangeEvent(this); notifyListeners(e); } } /** * Receives notification of a change to the plot's dataset. * <P> * The range axis bounds will be recalculated if necessary. * * @param event information about the event (not used here). */ @Override public void datasetChanged(DatasetChangeEvent event) { int count = this.rangeAxes.size(); for (int axisIndex = 0; axisIndex < count; axisIndex++) { ValueAxis yAxis = getRangeAxis(axisIndex); if (yAxis != null) { yAxis.configure(); } } if (getParent() != null) { getParent().datasetChanged(event); } else { PlotChangeEvent e = new PlotChangeEvent(this); e.setType(ChartChangeEventType.DATASET_UPDATED); notifyListeners(e); } } /** * Receives notification of a renderer change event. * * @param event the event. */ @Override public void rendererChanged(RendererChangeEvent event) { Plot parent = getParent(); if (parent != null) { if (parent instanceof RendererChangeListener) { RendererChangeListener rcl = (RendererChangeListener) parent; rcl.rendererChanged(event); } else { // this should never happen with the existing code, but throw // an exception in case future changes make it possible... throw new RuntimeException( "The renderer has changed and I don't know what to do!"); } } else { configureRangeAxes(); PlotChangeEvent e = new PlotChangeEvent(this); notifyListeners(e); } } /** * Adds a marker for display (in the foreground) against the domain axis and * sends a {@link PlotChangeEvent} to all registered listeners. Typically a * marker will be drawn by the renderer as a line perpendicular to the * domain axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * * @see #removeDomainMarker(Marker) */ public void addDomainMarker(CategoryMarker marker) { addDomainMarker(marker, Layer.FOREGROUND); } /** * Adds a marker for display against the domain axis and sends a * {@link PlotChangeEvent} to all registered listeners. Typically a marker * will be drawn by the renderer as a line perpendicular to the domain * axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background) (<code>null</code> * not permitted). * * @see #removeDomainMarker(Marker, Layer) */ public void addDomainMarker(CategoryMarker marker, Layer layer) { addDomainMarker(0, marker, layer); } /** * Adds a marker for display by a particular renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to a domain axis, however this is entirely up to the renderer. * * @param index the renderer index. * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (<code>null</code> not permitted). * * @see #removeDomainMarker(int, Marker, Layer) */ public void addDomainMarker(int index, CategoryMarker marker, Layer layer) { addDomainMarker(index, marker, layer, true); } /** * Adds a marker for display by a particular renderer and, if requested, * sends a {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to a domain axis, however this is entirely up to the renderer. * * @param index the renderer index. * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (<code>null</code> not permitted). * @param notify notify listeners? * * @since 1.0.10 * * @see #removeDomainMarker(int, Marker, Layer, boolean) */ public void addDomainMarker(int index, CategoryMarker marker, Layer layer, boolean notify) { if (marker == null) { throw new IllegalArgumentException("Null 'marker' not permitted."); } if (layer == null) { throw new IllegalArgumentException("Null 'layer' not permitted."); } Collection<Marker> markers; if (layer == Layer.FOREGROUND) { markers = this.foregroundDomainMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.foregroundDomainMarkers.put(index, markers); } markers.add(marker); } else if (layer == Layer.BACKGROUND) { markers = this.backgroundDomainMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.backgroundDomainMarkers.put(index, markers); } markers.add(marker); } marker.addChangeListener(this); if (notify) { fireChangeEvent(); } } /** * Clears all the domain markers for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @see #clearRangeMarkers() */ public void clearDomainMarkers() { if (this.backgroundDomainMarkers != null) { Set<Integer> keys = this.backgroundDomainMarkers.keySet(); for (Integer key : keys) { clearDomainMarkers(key); } this.backgroundDomainMarkers.clear(); } if (this.foregroundDomainMarkers != null) { Set<Integer> keys = this.foregroundDomainMarkers.keySet(); for (Integer key : keys) { clearDomainMarkers(key); } this.foregroundDomainMarkers.clear(); } fireChangeEvent(); } /** * Returns the list of domain markers (read only) for the specified layer. * * @param layer the layer (foreground or background). * * @return The list of domain markers. */ public Collection<Marker> getDomainMarkers(Layer layer) { return getDomainMarkers(0, layer); } /** * Returns a collection of domain markers for a particular renderer and * layer. * * @param index the renderer index. * @param layer the layer. * * @return A collection of markers (possibly <code>null</code>). */ public Collection<Marker> getDomainMarkers(int index, Layer layer) { Collection<Marker> result = null; if (layer == Layer.FOREGROUND) { result = this.foregroundDomainMarkers.get(index); } else if (layer == Layer.BACKGROUND) { result = this.backgroundDomainMarkers.get(index); } if (result != null) { result = Collections.unmodifiableCollection(result); } return result; } /** * Clears all the domain markers for the specified renderer. * * @param index the renderer index. * * @see #clearRangeMarkers(int) */ public void clearDomainMarkers(int index) { if (this.backgroundDomainMarkers != null) { Collection<Marker> markers = this.backgroundDomainMarkers.get(index); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } if (this.foregroundDomainMarkers != null) { Collection<Marker> markers = this.foregroundDomainMarkers.get(index); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } fireChangeEvent(); } /** * Removes a marker for the domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param marker the marker. * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeDomainMarker(Marker marker) { return removeDomainMarker(marker, Layer.FOREGROUND); } /** * Removes a marker for the domain axis in the specified layer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeDomainMarker(Marker marker, Layer layer) { return removeDomainMarker(0, marker, layer); } /** * Removes a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeDomainMarker(int index, Marker marker, Layer layer) { return removeDomainMarker(index, marker, layer, true); } /** * Removes a marker for a specific dataset/renderer and, if requested, * sends a {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * @param notify notify listeners? * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.10 */ public boolean removeDomainMarker(int index, Marker marker, Layer layer, boolean notify) { Collection<Marker> markers; if (layer == Layer.FOREGROUND) { markers = this.foregroundDomainMarkers.get(index); } else { markers = this.backgroundDomainMarkers.get(index); } if (markers == null) { return false; } boolean removed = markers.remove(marker); if (removed && notify) { fireChangeEvent(); } return removed; } /** * Adds a marker for display (in the foreground) against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. Typically a * marker will be drawn by the renderer as a line perpendicular to the * range axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * * @see #removeRangeMarker(Marker) */ public void addRangeMarker(Marker marker) { addRangeMarker(marker, Layer.FOREGROUND); } /** * Adds a marker for display against the range axis and sends a * {@link PlotChangeEvent} to all registered listeners. Typically a marker * will be drawn by the renderer as a line perpendicular to the range axis, * however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background) (<code>null</code> * not permitted). * * @see #removeRangeMarker(Marker, Layer) */ public void addRangeMarker(Marker marker, Layer layer) { addRangeMarker(0, marker, layer); } /** * Adds a marker for display by a particular renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to a range axis, however this is entirely up to the renderer. * * @param index the renderer index. * @param marker the marker. * @param layer the layer. * * @see #removeRangeMarker(int, Marker, Layer) */ public void addRangeMarker(int index, Marker marker, Layer layer) { addRangeMarker(index, marker, layer, true); } /** * Adds a marker for display by a particular renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to a range axis, however this is entirely up to the renderer. * * @param index the renderer index. * @param marker the marker. * @param layer the layer. * @param notify notify listeners? * * @since 1.0.10 * * @see #removeRangeMarker(int, Marker, Layer, boolean) */ public void addRangeMarker(int index, Marker marker, Layer layer, boolean notify) { Collection<Marker> markers; if (layer == Layer.FOREGROUND) { markers = this.foregroundRangeMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.foregroundRangeMarkers.put(index, markers); } markers.add(marker); } else if (layer == Layer.BACKGROUND) { markers = this.backgroundRangeMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.backgroundRangeMarkers.put(index, markers); } markers.add(marker); } marker.addChangeListener(this); if (notify) { fireChangeEvent(); } } /** * Clears all the range markers for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @see #clearDomainMarkers() */ public void clearRangeMarkers() { if (this.backgroundRangeMarkers != null) { Set<Integer> keys = this.backgroundRangeMarkers.keySet(); for (Integer key : keys) { clearRangeMarkers(key); } this.backgroundRangeMarkers.clear(); } if (this.foregroundRangeMarkers != null) { Set<Integer> keys = this.foregroundRangeMarkers.keySet(); for (Integer key : keys) { clearRangeMarkers(key); } this.foregroundRangeMarkers.clear(); } fireChangeEvent(); } /** * Returns the list of range markers (read only) for the specified layer. * * @param layer the layer (foreground or background). * * @return The list of range markers. * * @see #getRangeMarkers(int, Layer) */ public Collection<Marker> getRangeMarkers(Layer layer) { return getRangeMarkers(0, layer); } /** * Returns a collection of range markers for a particular renderer and * layer. * * @param index the renderer index. * @param layer the layer. * * @return A collection of markers (possibly <code>null</code>). */ public Collection<Marker> getRangeMarkers(int index, Layer layer) { Collection<Marker> result = null; Integer key = index; if (layer == Layer.FOREGROUND) { result = this.foregroundRangeMarkers.get(key); } else if (layer == Layer.BACKGROUND) { result = this.backgroundRangeMarkers.get(key); } if (result != null) { result = Collections.unmodifiableCollection(result); } return result; } /** * Clears all the range markers for the specified renderer. * * @param index the renderer index. * * @see #clearDomainMarkers(int) */ public void clearRangeMarkers(int index) { Integer key = index; if (this.backgroundRangeMarkers != null) { Collection<Marker> markers = this.backgroundRangeMarkers.get(key); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } if (this.foregroundRangeMarkers != null) { Collection<Marker> markers = this.foregroundRangeMarkers.get(key); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } fireChangeEvent(); } /** * Removes a marker for the range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param marker the marker. * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 * * @see #addRangeMarker(Marker) */ public boolean removeRangeMarker(Marker marker) { return removeRangeMarker(marker, Layer.FOREGROUND); } /** * Removes a marker for the range axis in the specified layer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 * * @see #addRangeMarker(Marker, Layer) */ public boolean removeRangeMarker(Marker marker, Layer layer) { return removeRangeMarker(0, marker, layer); } /** * Removes a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 * * @see #addRangeMarker(int, Marker, Layer) */ public boolean removeRangeMarker(int index, Marker marker, Layer layer) { return removeRangeMarker(index, marker, layer, true); } /** * Removes a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * @param notify notify listeners. * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.10 * * @see #addRangeMarker(int, Marker, Layer, boolean) */ public boolean removeRangeMarker(int index, Marker marker, Layer layer, boolean notify) { if (marker == null) { throw new IllegalArgumentException("Null 'marker' argument."); } Collection<Marker> markers; if (layer == Layer.FOREGROUND) { markers = this.foregroundRangeMarkers.get(index); } else { markers = this.backgroundRangeMarkers.get(index); } if (markers == null) { return false; } boolean removed = markers.remove(marker); if (removed && notify) { fireChangeEvent(); } return removed; } /** * Returns the flag that controls whether or not the domain crosshair is * displayed by the plot. * * @return A boolean. * * @since 1.0.11 * * @see #setDomainCrosshairVisible(boolean) */ public boolean isDomainCrosshairVisible() { return this.domainCrosshairVisible; } /** * Sets the flag that controls whether or not the domain crosshair is * displayed by the plot, and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param flag the new flag value. * * @since 1.0.11 * * @see #isDomainCrosshairVisible() * @see #setRangeCrosshairVisible(boolean) */ public void setDomainCrosshairVisible(boolean flag) { if (this.domainCrosshairVisible != flag) { this.domainCrosshairVisible = flag; fireChangeEvent(); } } /** * Returns the row key for the domain crosshair. * * @return The row key. * * @since 1.0.11 */ public Comparable getDomainCrosshairRowKey() { return this.domainCrosshairRowKey; } /** * Sets the row key for the domain crosshair and sends a * {PlotChangeEvent} to all registered listeners. * * @param key the key. * * @since 1.0.11 */ public void setDomainCrosshairRowKey(Comparable key) { setDomainCrosshairRowKey(key, true); } /** * Sets the row key for the domain crosshair and, if requested, sends a * {PlotChangeEvent} to all registered listeners. * * @param key the key. * @param notify notify listeners? * * @since 1.0.11 */ public void setDomainCrosshairRowKey(Comparable key, boolean notify) { this.domainCrosshairRowKey = key; if (notify) { fireChangeEvent(); } } /** * Returns the column key for the domain crosshair. * * @return The column key. * * @since 1.0.11 */ public Comparable getDomainCrosshairColumnKey() { return this.domainCrosshairColumnKey; } /** * Sets the column key for the domain crosshair and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param key the key. * * @since 1.0.11 */ public void setDomainCrosshairColumnKey(Comparable key) { setDomainCrosshairColumnKey(key, true); } /** * Sets the column key for the domain crosshair and, if requested, sends * a {@link PlotChangeEvent} to all registered listeners. * * @param key the key. * @param notify notify listeners? * * @since 1.0.11 */ public void setDomainCrosshairColumnKey(Comparable key, boolean notify) { this.domainCrosshairColumnKey = key; if (notify) { fireChangeEvent(); } } /** * Returns the dataset index for the crosshair. * * @return The dataset index. * * @since 1.0.11 */ public int getCrosshairDatasetIndex() { return this.crosshairDatasetIndex; } /** * Sets the dataset index for the crosshair and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the index. * * @since 1.0.11 */ public void setCrosshairDatasetIndex(int index) { setCrosshairDatasetIndex(index, true); } /** * Sets the dataset index for the crosshair and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the index. * @param notify notify listeners? * * @since 1.0.11 */ public void setCrosshairDatasetIndex(int index, boolean notify) { this.crosshairDatasetIndex = index; if (notify) { fireChangeEvent(); } } /** * Returns the paint used to draw the domain crosshair. * * @return The paint (never <code>null</code>). * * @since 1.0.11 * * @see #setDomainCrosshairPaint(Paint) * @see #getDomainCrosshairStroke() */ public Paint getDomainCrosshairPaint() { return this.domainCrosshairPaint; } /** * Sets the paint used to draw the domain crosshair. * * @param paint the paint (<code>null</code> not permitted). * * @since 1.0.11 * * @see #getDomainCrosshairPaint() */ public void setDomainCrosshairPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.domainCrosshairPaint = paint; fireChangeEvent(); } /** * Returns the stroke used to draw the domain crosshair. * * @return The stroke (never <code>null</code>). * * @since 1.0.11 * * @see #setDomainCrosshairStroke(Stroke) * @see #getDomainCrosshairPaint() */ public Stroke getDomainCrosshairStroke() { return this.domainCrosshairStroke; } /** * Sets the stroke used to draw the domain crosshair, and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @since 1.0.11 * * @see #getDomainCrosshairStroke() */ public void setDomainCrosshairStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.domainCrosshairStroke = stroke; } /** * Returns a flag indicating whether or not the range crosshair is visible. * * @return The flag. * * @see #setRangeCrosshairVisible(boolean) */ public boolean isRangeCrosshairVisible() { return this.rangeCrosshairVisible; } /** * Sets the flag indicating whether or not the range crosshair is visible. * * @param flag the new value of the flag. * * @see #isRangeCrosshairVisible() */ public void setRangeCrosshairVisible(boolean flag) { if (this.rangeCrosshairVisible != flag) { this.rangeCrosshairVisible = flag; fireChangeEvent(); } } /** * Returns a flag indicating whether or not the crosshair should "lock-on" * to actual data values. * * @return The flag. * * @see #setRangeCrosshairLockedOnData(boolean) */ public boolean isRangeCrosshairLockedOnData() { return this.rangeCrosshairLockedOnData; } /** * Sets the flag indicating whether or not the range crosshair should * "lock-on" to actual data values, and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param flag the flag. * * @see #isRangeCrosshairLockedOnData() */ public void setRangeCrosshairLockedOnData(boolean flag) { if (this.rangeCrosshairLockedOnData != flag) { this.rangeCrosshairLockedOnData = flag; fireChangeEvent(); } } /** * Returns the range crosshair value. * * @return The value. * * @see #setRangeCrosshairValue(double) */ public double getRangeCrosshairValue() { return this.rangeCrosshairValue; } /** * Sets the range crosshair value and, if the crosshair is visible, sends * a {@link PlotChangeEvent} to all registered listeners. * * @param value the new value. * * @see #getRangeCrosshairValue() */ public void setRangeCrosshairValue(double value) { setRangeCrosshairValue(value, true); } /** * Sets the range crosshair value and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners (but only if the * crosshair is visible). * * @param value the new value. * @param notify a flag that controls whether or not listeners are * notified. * * @see #getRangeCrosshairValue() */ public void setRangeCrosshairValue(double value, boolean notify) { this.rangeCrosshairValue = value; if (isRangeCrosshairVisible() && notify) { fireChangeEvent(); } } /** * Returns the pen-style (<code>Stroke</code>) used to draw the crosshair * (if visible). * * @return The crosshair stroke (never <code>null</code>). * * @see #setRangeCrosshairStroke(Stroke) * @see #isRangeCrosshairVisible() * @see #getRangeCrosshairPaint() */ public Stroke getRangeCrosshairStroke() { return this.rangeCrosshairStroke; } /** * Sets the pen-style (<code>Stroke</code>) used to draw the range * crosshair (if visible), and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param stroke the new crosshair stroke (<code>null</code> not * permitted). * * @see #getRangeCrosshairStroke() */ public void setRangeCrosshairStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.rangeCrosshairStroke = stroke; fireChangeEvent(); } /** * Returns the paint used to draw the range crosshair. * * @return The paint (never <code>null</code>). * * @see #setRangeCrosshairPaint(Paint) * @see #isRangeCrosshairVisible() * @see #getRangeCrosshairStroke() */ public Paint getRangeCrosshairPaint() { return this.rangeCrosshairPaint; } /** * Sets the paint used to draw the range crosshair (if visible) and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeCrosshairPaint() */ public void setRangeCrosshairPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeCrosshairPaint = paint; fireChangeEvent(); } /** * Returns the list of annotations. * * @return The list of annotations (never <code>null</code>). * * @see #addAnnotation(CategoryAnnotation) * @see #clearAnnotations() */ public List<CategoryAnnotation> getAnnotations() { return this.annotations; } /** * Adds an annotation to the plot and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * * @see #removeAnnotation(CategoryAnnotation) */ public void addAnnotation(CategoryAnnotation annotation) { addAnnotation(annotation, true); } /** * Adds an annotation to the plot and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * @param notify notify listeners? * * @since 1.0.10 */ public void addAnnotation(CategoryAnnotation annotation, boolean notify) { if (annotation == null) { throw new IllegalArgumentException("Null 'annotation' argument."); } this.annotations.add(annotation); annotation.addChangeListener(this); if (notify) { fireChangeEvent(); } } /** * Removes an annotation from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * * @return A boolean (indicates whether or not the annotation was removed). * * @see #addAnnotation(CategoryAnnotation) */ public boolean removeAnnotation(CategoryAnnotation annotation) { return removeAnnotation(annotation, true); } /** * Removes an annotation from the plot and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * @param notify notify listeners? * * @return A boolean (indicates whether or not the annotation was removed). * * @since 1.0.10 */ public boolean removeAnnotation(CategoryAnnotation annotation, boolean notify) { if (annotation == null) { throw new IllegalArgumentException("Null 'annotation' argument."); } boolean removed = this.annotations.remove(annotation); annotation.removeChangeListener(this); if (removed && notify) { fireChangeEvent(); } return removed; } /** * Clears all the annotations and sends a {@link PlotChangeEvent} to all * registered listeners. */ public void clearAnnotations() { for (CategoryAnnotation annotation : this.annotations) { annotation.removeChangeListener(this); } this.annotations.clear(); fireChangeEvent(); } /** * Returns the shadow generator for the plot, if any. * * @return The shadow generator (possibly <code>null</code>). * * @since 1.0.14 */ public ShadowGenerator getShadowGenerator() { return this.shadowGenerator; } /** * Sets the shadow generator for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @since 1.0.14 */ public void setShadowGenerator(ShadowGenerator generator) { this.shadowGenerator = generator; fireChangeEvent(); } /** * Calculates the space required for the domain axis/axes. * * @param g2 the graphics device. * @param plotArea the plot area. * @param space a carrier for the result (<code>null</code> permitted). * * @return The required space. */ protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) { if (space == null) { space = new AxisSpace(); } // reserve some space for the domain axis... if (this.fixedDomainAxisSpace != null) { if (this.orientation == PlotOrientation.HORIZONTAL) { space.ensureAtLeast( this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT); space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT); } else if (this.orientation == PlotOrientation.VERTICAL) { space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP); space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM); } } else { // reserve space for the primary domain axis... RectangleEdge domainEdge = Plot.resolveDomainAxisLocation( getDomainAxisLocation(), this.orientation); if (this.drawSharedDomainAxis) { space = getDomainAxis().reserveSpace(g2, this, plotArea, domainEdge, space); } // reserve space for any domain axes... for (int i = 0; i < this.domainAxes.size(); i++) { Axis xAxis = this.domainAxes.get(i); if (xAxis != null) { RectangleEdge edge = getDomainAxisEdge(i); space = xAxis.reserveSpace(g2, this, plotArea, edge, space); } } } return space; } /** * Calculates the space required for the range axis/axes. * * @param g2 the graphics device. * @param plotArea the plot area. * @param space a carrier for the result (<code>null</code> permitted). * * @return The required space. */ protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) { if (space == null) { space = new AxisSpace(); } // reserve some space for the range axis... if (this.fixedRangeAxisSpace != null) { if (this.orientation == PlotOrientation.HORIZONTAL) { space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP); space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM); } else if (this.orientation == PlotOrientation.VERTICAL) { space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT); space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT); } } else { // reserve space for the range axes (if any)... for (int i = 0; i < this.rangeAxes.size(); i++) { Axis yAxis = this.rangeAxes.get(i); if (yAxis != null) { RectangleEdge edge = getRangeAxisEdge(i); space = yAxis.reserveSpace(g2, this, plotArea, edge, space); } } } return space; } /** * Trims a rectangle to integer coordinates. * * @param rect the incoming rectangle. * * @return A rectangle with integer coordinates. */ private Rectangle integerise(Rectangle2D rect) { int x0 = (int) Math.ceil(rect.getMinX()); int y0 = (int) Math.ceil(rect.getMinY()); int x1 = (int) Math.floor(rect.getMaxX()); int y1 = (int) Math.floor(rect.getMaxY()); return new Rectangle(x0, y0, (x1 - x0), (y1 - y0)); } /** * Calculates the space required for the axes. * * @param g2 the graphics device. * @param plotArea the plot area. * * @return The space required for the axes. */ protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); space = calculateRangeAxisSpace(g2, plotArea, space); space = calculateDomainAxisSpace(g2, plotArea, space); return space; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * <P> * At your option, you may supply an instance of {@link PlotRenderingInfo}. * If you do, it will be populated with information about the drawing, * including various plot dimensions and tooltip info. * * @param g2 the graphics device. * @param area the area within which the plot (including axes) should * be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param state collects info as the chart is drawn (possibly * <code>null</code>). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo state) { // if the plot area is too small, just return... boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; } // record the plot area... if (state == null) { // if the incoming state is null, no information will be passed // back to the caller - but we create a temporary state to record // the plot area, since that is used later by the axes state = new PlotRenderingInfo(null); } state.setPlotArea(area); // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); // calculate the data area... AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); this.axisOffset.trim(dataArea); dataArea = integerise(dataArea); if (dataArea.isEmpty()) { return; } state.setDataArea(dataArea); createAndAddEntity((Rectangle2D) dataArea.clone(), state, null, null); // if there is a renderer, it draws the background, otherwise use the // default background... if (getRenderer() != null) { getRenderer().drawBackground(g2, this, dataArea); } else { drawBackground(g2, dataArea); } Map<Axis, AxisState> axisStateMap = drawAxes(g2, area, dataArea, state); // the anchor point is typically the point where the mouse last // clicked - the crosshairs will be driven off this point... if (anchor != null && !dataArea.contains(anchor)) { anchor = ShapeUtilities.getPointInRectangle(anchor.getX(), anchor.getY(), dataArea); } CategoryCrosshairState crosshairState = new CategoryCrosshairState(); crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY); crosshairState.setAnchor(anchor); // specify the anchor X and Y coordinates in Java2D space, for the // cases where these are not updated during rendering (i.e. no lock // on data) crosshairState.setAnchorX(Double.NaN); crosshairState.setAnchorY(Double.NaN); if (anchor != null) { ValueAxis rangeAxis = getRangeAxis(); if (rangeAxis != null) { double y; if (getOrientation() == PlotOrientation.VERTICAL) { y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge()); } else { y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge()); } crosshairState.setAnchorY(y); } } crosshairState.setRowKey(getDomainCrosshairRowKey()); crosshairState.setColumnKey(getDomainCrosshairColumnKey()); crosshairState.setCrosshairY(getRangeCrosshairValue()); // don't let anyone draw outside the data area Shape savedClip = g2.getClip(); g2.clip(dataArea); drawDomainGridlines(g2, dataArea); AxisState rangeAxisState = axisStateMap.get(getRangeAxis()); if (rangeAxisState == null) { if (parentState != null) { rangeAxisState = parentState.getSharedAxisStates() .get(getRangeAxis()); } } if (rangeAxisState != null) { drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); drawZeroRangeBaseline(g2, dataArea); } Graphics2D savedG2 = g2; BufferedImage dataImage = null; if (this.shadowGenerator != null) { dataImage = new BufferedImage((int) dataArea.getWidth(), (int)dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB); g2 = dataImage.createGraphics(); g2.translate(-dataArea.getX(), -dataArea.getY()); g2.setRenderingHints(savedG2.getRenderingHints()); } // draw the markers... for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND); } // now render data items... boolean foundData = false; // set up the alpha-transparency... Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, getForegroundAlpha())); DatasetRenderingOrder order = getDatasetRenderingOrder(); if (order == DatasetRenderingOrder.FORWARD) { for (int i = 0; i < this.datasets.size(); i++) { foundData = render(g2, dataArea, i, state, crosshairState) || foundData; } } else { // DatasetRenderingOrder.REVERSE for (int i = this.datasets.size() - 1; i >= 0; i--) { foundData = render(g2, dataArea, i, state, crosshairState) || foundData; } } // draw the foreground markers... for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND); } // draw the annotations (if any)... drawAnnotations(g2, dataArea); if (this.shadowGenerator != null) { BufferedImage shadowImage = this.shadowGenerator.createDropShadow( dataImage); g2 = savedG2; g2.drawImage(shadowImage, (int) dataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) dataArea.getY() + this.shadowGenerator.calculateOffsetY(), null); g2.drawImage(dataImage, (int) dataArea.getX(), (int) dataArea.getY(), null); } g2.setClip(savedClip); g2.setComposite(originalComposite); if (!foundData) { drawNoDataMessage(g2, dataArea); } int datasetIndex = crosshairState.getDatasetIndex(); setCrosshairDatasetIndex(datasetIndex, false); // draw domain crosshair if required... Comparable rowKey = crosshairState.getRowKey(); Comparable columnKey = crosshairState.getColumnKey(); setDomainCrosshairRowKey(rowKey, false); setDomainCrosshairColumnKey(columnKey, false); if (isDomainCrosshairVisible() && columnKey != null) { Paint paint = getDomainCrosshairPaint(); Stroke stroke = getDomainCrosshairStroke(); drawDomainCrosshair(g2, dataArea, this.orientation, datasetIndex, rowKey, columnKey, stroke, paint); } // draw range crosshair if required... ValueAxis yAxis = getRangeAxisForDataset(datasetIndex); RectangleEdge yAxisEdge = getRangeAxisEdge(); if (!this.rangeCrosshairLockedOnData && anchor != null) { double yy; if (getOrientation() == PlotOrientation.VERTICAL) { yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge); } else { yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge); } crosshairState.setCrosshairY(yy); } setRangeCrosshairValue(crosshairState.getCrosshairY(), false); if (isRangeCrosshairVisible()) { double y = getRangeCrosshairValue(); Paint paint = getRangeCrosshairPaint(); Stroke stroke = getRangeCrosshairStroke(); drawRangeCrosshair(g2, dataArea, getOrientation(), y, yAxis, stroke, paint); } // draw an outline around the plot area... if (isOutlineVisible()) { if (getRenderer() != null) { getRenderer().drawOutline(g2, this, dataArea); } else { drawOutline(g2, dataArea); } } } /** * Draws the plot background (the background color and/or image). * <P> * This method will be called during the chart drawing process and is * declared public so that it can be accessed by the renderers used by * certain subclasses. You shouldn't need to call this method directly. * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. */ @Override public void drawBackground(Graphics2D g2, Rectangle2D area) { fillBackground(g2, area, this.orientation); drawBackgroundImage(g2, area); } /** * A utility method for drawing the plot's axes. * * @param g2 the graphics device. * @param plotArea the plot area. * @param dataArea the data area. * @param plotState collects information about the plot (<code>null</code> * permitted). * * @return A map containing the axis states. */ protected Map<Axis, AxisState> drawAxes(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, PlotRenderingInfo plotState) { AxisCollection axisCollection = new AxisCollection(); // add domain axes to lists... for (int index = 0; index < this.domainAxes.size(); index++) { CategoryAxis xAxis = this.domainAxes.get(index); if (xAxis != null) { axisCollection.add(xAxis, getDomainAxisEdge(index)); } } // add range axes to lists... for (int index = 0; index < this.rangeAxes.size(); index++) { ValueAxis yAxis = this.rangeAxes.get(index); if (yAxis != null) { axisCollection.add(yAxis, getRangeAxisEdge(index)); } } Map<Axis, AxisState> axisStateMap = new HashMap<Axis, AxisState>(); // draw the top axes double cursor = dataArea.getMinY() - this.axisOffset.calculateTopOutset( dataArea.getHeight()); for (Axis axis : axisCollection.getAxesAtTop()) { if (axis != null) { AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.TOP, plotState); cursor = axisState.getCursor(); axisStateMap.put(axis, axisState); } } // draw the bottom axes cursor = dataArea.getMaxY() + this.axisOffset.calculateBottomOutset(dataArea.getHeight()); for (Axis axis : axisCollection.getAxesAtBottom()) { if (axis != null) { AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM, plotState); cursor = axisState.getCursor(); axisStateMap.put(axis, axisState); } } // draw the left axes cursor = dataArea.getMinX() - this.axisOffset.calculateLeftOutset(dataArea.getWidth()); for (Axis axis : axisCollection.getAxesAtLeft()) { if (axis != null) { AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT, plotState); cursor = axisState.getCursor(); axisStateMap.put(axis, axisState); } } // draw the right axes cursor = dataArea.getMaxX() + this.axisOffset.calculateRightOutset(dataArea.getWidth()); for (Axis axis : axisCollection.getAxesAtRight()) { if (axis != null) { AxisState axisState = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.RIGHT, plotState); cursor = axisState.getCursor(); axisStateMap.put(axis, axisState); } } return axisStateMap; } /** * Draws a representation of a dataset within the dataArea region using the * appropriate renderer. * * @param g2 the graphics device. * @param dataArea the region in which the data is to be drawn. * @param index the dataset and renderer index. * @param info an optional object for collection dimension information. * @param crosshairState a state object for tracking crosshair info * (<code>null</code> permitted). * * @return A boolean that indicates whether or not real data was found. * * @since 1.0.11 */ public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CategoryCrosshairState crosshairState) { boolean foundData = false; CategoryDataset currentDataset = getDataset(index); CategoryItemRenderer renderer = getRenderer(index); CategoryAxis domainAxis = getDomainAxisForDataset(index); ValueAxis rangeAxis = getRangeAxisForDataset(index); boolean hasData = !DatasetUtilities.isEmptyOrNull(currentDataset); if (hasData && renderer != null) { foundData = true; CategoryItemRendererState state = renderer.initialise(g2, dataArea, this, index, info); state.setCrosshairState(crosshairState); int columnCount = currentDataset.getColumnCount(); int rowCount = currentDataset.getRowCount(); int passCount = renderer.getPassCount(); for (int pass = 0; pass < passCount; pass++) { if (this.columnRenderingOrder == SortOrder.ASCENDING) { for (int column = 0; column < columnCount; column++) { if (this.rowRenderingOrder == SortOrder.ASCENDING) { for (int row = 0; row < rowCount; row++) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass); } } else { for (int row = rowCount - 1; row >= 0; row--) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass); } } } } else { for (int column = columnCount - 1; column >= 0; column--) { if (this.rowRenderingOrder == SortOrder.ASCENDING) { for (int row = 0; row < rowCount; row++) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass); } } else { for (int row = rowCount - 1; row >= 0; row--) { renderer.drawItem(g2, state, dataArea, this, domainAxis, rangeAxis, currentDataset, row, column, pass); } } } } } } return foundData; } /** * Draws the domain gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List) */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea) { if (!isDomainGridlinesVisible()) { return; } CategoryAnchor anchor = getDomainGridlinePosition(); RectangleEdge domainAxisEdge = getDomainAxisEdge(); CategoryDataset dataset = getDataset(); if (dataset == null) { return; } CategoryAxis axis = getDomainAxis(); if (axis != null) { int columnCount = dataset.getColumnCount(); for (int c = 0; c < columnCount; c++) { double xx = axis.getCategoryJava2DCoordinate(anchor, c, columnCount, dataArea, domainAxisEdge); CategoryItemRenderer renderer1 = getRenderer(); if (renderer1 != null) { renderer1.drawDomainGridline(g2, this, dataArea, xx); } } } } /** * Draws the range gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the area inside the axes. * @param ticks the ticks. * * @see #drawDomainGridlines(Graphics2D, Rectangle2D) */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // draw the range grid lines, if any... if (!isRangeGridlinesVisible() && !isRangeMinorGridlinesVisible()) { return; } // no axis, no gridlines... ValueAxis axis = getRangeAxis(); if (axis == null) { return; } // no renderer, no gridlines... CategoryItemRenderer r = getRenderer(); if (r == null) { return; } Stroke gridStroke = null; Paint gridPaint = null; boolean paintLine; for (ValueTick tick : ticks) { paintLine = false; if ((tick.getTickType() == TickType.MINOR) && isRangeMinorGridlinesVisible()) { gridStroke = getRangeMinorGridlineStroke(); gridPaint = getRangeMinorGridlinePaint(); paintLine = true; } else if ((tick.getTickType() == TickType.MAJOR) && isRangeGridlinesVisible()) { gridStroke = getRangeGridlineStroke(); gridPaint = getRangeGridlinePaint(); paintLine = true; } if (((tick.getValue() != 0.0) || !isRangeZeroBaselineVisible()) && paintLine) { // the method we want isn't in the CategoryItemRenderer // interface... if (r instanceof AbstractCategoryItemRenderer) { AbstractCategoryItemRenderer aci = (AbstractCategoryItemRenderer) r; aci.drawRangeGridline(g2, this, axis, dataArea, tick.getValue(), gridPaint, gridStroke); } else { // we'll have to use the method in the interface, but // this doesn't have the paint and stroke settings... r.drawRangeGridline(g2, this, axis, dataArea, tick.getValue()); } } } } /** * Draws a base line across the chart at value zero on the range axis. * * @param g2 the graphics device. * @param area the data area. * * @see #setRangeZeroBaselineVisible(boolean) * * @since 1.0.13 */ protected void drawZeroRangeBaseline(Graphics2D g2, Rectangle2D area) { if (!isRangeZeroBaselineVisible()) { return; } CategoryItemRenderer r = getRenderer(); if (r instanceof AbstractCategoryItemRenderer) { AbstractCategoryItemRenderer aci = (AbstractCategoryItemRenderer) r; aci.drawRangeGridline(g2, this, getRangeAxis(), area, 0.0, this.rangeZeroBaselinePaint, this.rangeZeroBaselineStroke); } else { r.drawRangeGridline(g2, this, getRangeAxis(), area, 0.0); } } /** * Draws the annotations. * * @param g2 the graphics device. * @param dataArea the data area. */ protected void drawAnnotations(Graphics2D g2, Rectangle2D dataArea) { if (getAnnotations() != null) { for (CategoryAnnotation annotation : getAnnotations()) { annotation.draw(g2, this, dataArea, getDomainAxis(), getRangeAxis()); } } } /** * Draws the domain markers (if any) for an axis and layer. This method is * typically called from within the draw() method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). * * @see #drawRangeMarkers(Graphics2D, Rectangle2D, int, Layer) */ protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { CategoryItemRenderer r = getRenderer(index); if (r == null) { return; } Collection<Marker> markers = getDomainMarkers(index, layer); CategoryAxis axis = getDomainAxisForDataset(index); if (markers != null && axis != null) { for (Marker marker1 : markers) { CategoryMarker marker = (CategoryMarker) marker1; r.drawDomainMarker(g2, this, axis, marker, dataArea); } } } /** * Draws the range markers (if any) for an axis and layer. This method is * typically called from within the draw() method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). * * @see #drawDomainMarkers(Graphics2D, Rectangle2D, int, Layer) */ protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { CategoryItemRenderer r = getRenderer(index); if (r == null) { return; } Collection<Marker> markers = getRangeMarkers(index, layer); ValueAxis axis = getRangeAxisForDataset(index); if (markers != null && axis != null) { for (Marker marker : markers) { r.drawRangeMarker(g2, this, axis, marker, dataArea); } } } /** * Utility method for drawing a line perpendicular to the range axis (used * for crosshairs). * * @param g2 the graphics device. * @param dataArea the area defined by the axes. * @param value the data value. * @param stroke the line stroke (<code>null</code> not permitted). * @param paint the line paint (<code>null</code> not permitted). */ protected void drawRangeLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { double java2D = getRangeAxis().valueToJava2D(value, dataArea, getRangeAxisEdge()); Line2D line = null; if (this.orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(java2D, dataArea.getMinY(), java2D, dataArea.getMaxY()); } else if (this.orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(dataArea.getMinX(), java2D, dataArea.getMaxX(), java2D); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } /** * Draws a domain crosshair. * * @param g2 the graphics target. * @param dataArea the data area. * @param orientation the plot orientation. * @param datasetIndex the dataset index. * @param rowKey the row key. * @param columnKey the column key. * @param stroke the stroke used to draw the crosshair line. * @param paint the paint used to draw the crosshair line. * * @see #drawRangeCrosshair(Graphics2D, Rectangle2D, PlotOrientation, * double, ValueAxis, Stroke, Paint) * * @since 1.0.11 */ protected void drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea, PlotOrientation orientation, int datasetIndex, Comparable rowKey, Comparable columnKey, Stroke stroke, Paint paint) { CategoryDataset dataset = getDataset(datasetIndex); CategoryAxis axis = getDomainAxisForDataset(datasetIndex); CategoryItemRenderer renderer = getRenderer(datasetIndex); Line2D line; if (orientation == PlotOrientation.VERTICAL) { double xx = renderer.getItemMiddle(rowKey, columnKey, dataset, axis, dataArea, RectangleEdge.BOTTOM); line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); } else { double yy = renderer.getItemMiddle(rowKey, columnKey, dataset, axis, dataArea, RectangleEdge.LEFT); line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } /** * Draws a range crosshair. * * @param g2 the graphics target. * @param dataArea the data area. * @param orientation the plot orientation. * @param value the crosshair value. * @param axis the axis against which the value is measured. * @param stroke the stroke used to draw the crosshair line. * @param paint the paint used to draw the crosshair line. * * @see #drawDomainCrosshair(Graphics2D, Rectangle2D, PlotOrientation, int, * Comparable, Comparable, Stroke, Paint) * * @since 1.0.5 */ protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, PlotOrientation orientation, double value, ValueAxis axis, Stroke stroke, Paint paint) { if (!axis.getRange().contains(value)) { return; } Line2D line; if (orientation == PlotOrientation.HORIZONTAL) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); } else { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } /** * Returns the range of data values that will be plotted against the range * axis. If the dataset is <code>null</code>, this method returns * <code>null</code>. * * @param axis the axis. * * @return The data range. */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; List<CategoryDataset> mappedDatasets = new ArrayList<CategoryDataset>(); int rangeIndex = this.rangeAxes.indexOf(axis); if (rangeIndex >= 0) { mappedDatasets.addAll(datasetsMappedToRangeAxis(rangeIndex)); } else if (axis == getRangeAxis()) { mappedDatasets.addAll(datasetsMappedToRangeAxis(0)); } // iterate through the datasets that map to the axis and get the union // of the ranges. for (CategoryDataset d : mappedDatasets) { CategoryItemRenderer r = getRendererForDataset(d); if (r != null) { result = Range.combine(result, r.findRangeBounds(d)); } } return result; } /** * Returns a list of the datasets that are mapped to the axis with the * specified index. * * @param axisIndex the axis index. * * @return The list (possibly empty, but never <code>null</code>). * * @since 1.0.3 */ private List<CategoryDataset> datasetsMappedToDomainAxis(int axisIndex) { Integer key = axisIndex; List<CategoryDataset> result = new ArrayList<CategoryDataset>(); for (int i = 0; i < this.datasets.size(); i++) { List<Integer> mappedAxes = this.datasetToDomainAxesMap.get( Integer.valueOf(i)); CategoryDataset dataset = this.datasets.get(i); if (mappedAxes == null) { if (key.equals(ZERO)) { if (dataset != null) { result.add(dataset); } } } else { if (mappedAxes.contains(key)) { if (dataset != null) { result.add(dataset); } } } } return result; } /** * A utility method that returns a list of datasets that are mapped to a * given range axis. * * @param index the axis index. * * @return A list of datasets. */ private List<CategoryDataset> datasetsMappedToRangeAxis(int index) { Integer key = index; List<CategoryDataset> result = new ArrayList<CategoryDataset>(); for (int i = 0; i < this.datasets.size(); i++) { List<Integer> mappedAxes = this.datasetToRangeAxesMap.get( Integer.valueOf(i)); if (mappedAxes == null) { if (key.equals(ZERO)) { result.add(this.datasets.get(i)); } } else { if (mappedAxes.contains(key)) { result.add(this.datasets.get(i)); } } } return result; } /** * Returns the weight for this plot when it is used as a subplot within a * combined plot. * * @return The weight. * * @see #setWeight(int) */ public int getWeight() { return this.weight; } /** * Sets the weight for the plot and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param weight the weight. * * @see #getWeight() */ public void setWeight(int weight) { this.weight = weight; fireChangeEvent(); } /** * Returns the fixed domain axis space. * * @return The fixed domain axis space (possibly <code>null</code>). * * @see #setFixedDomainAxisSpace(AxisSpace) */ public AxisSpace getFixedDomainAxisSpace() { return this.fixedDomainAxisSpace; } /** * Sets the fixed domain axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). * * @see #getFixedDomainAxisSpace() */ public void setFixedDomainAxisSpace(AxisSpace space) { setFixedDomainAxisSpace(space, true); } /** * Sets the fixed domain axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). * @param notify notify listeners? * * @see #getFixedDomainAxisSpace() * * @since 1.0.7 */ public void setFixedDomainAxisSpace(AxisSpace space, boolean notify) { this.fixedDomainAxisSpace = space; if (notify) { fireChangeEvent(); } } /** * Returns the fixed range axis space. * * @return The fixed range axis space (possibly <code>null</code>). * * @see #setFixedRangeAxisSpace(AxisSpace) */ public AxisSpace getFixedRangeAxisSpace() { return this.fixedRangeAxisSpace; } /** * Sets the fixed range axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). * * @see #getFixedRangeAxisSpace() */ public void setFixedRangeAxisSpace(AxisSpace space) { setFixedRangeAxisSpace(space, true); } /** * Sets the fixed range axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). * @param notify notify listeners? * * @see #getFixedRangeAxisSpace() * * @since 1.0.7 */ public void setFixedRangeAxisSpace(AxisSpace space, boolean notify) { this.fixedRangeAxisSpace = space; if (notify) { fireChangeEvent(); } } /** * Returns a list of the categories in the plot's primary dataset. * * @return A list of the categories in the plot's primary dataset. * * @see #getCategoriesForAxis(CategoryAxis) */ public List<Comparable> getCategories() { List<Comparable> result = null; if (getDataset() != null) { result = Collections.unmodifiableList(getDataset().getColumnKeys()); } return result; } /** * Returns a list of the categories that should be displayed for the * specified axis. * * @param axis the axis (<code>null</code> not permitted) * * @return The categories. * * @since 1.0.3 */ public List<Comparable> getCategoriesForAxis(CategoryAxis axis) { List<Comparable> result = new ArrayList<Comparable>(); int axisIndex = this.domainAxes.indexOf(axis); List<CategoryDataset> mappedDatasets = datasetsMappedToDomainAxis(axisIndex); for (CategoryDataset dataset : mappedDatasets) { // add the unique categories from this dataset for (int i = 0; i < dataset.getColumnCount(); i++) { Comparable category = dataset.getColumnKey(i); if (!result.contains(category)) { result.add(category); } } } return result; } /** * Returns the flag that controls whether or not the shared domain axis is * drawn for each subplot. * * @return A boolean. * * @see #setDrawSharedDomainAxis(boolean) */ public boolean getDrawSharedDomainAxis() { return this.drawSharedDomainAxis; } /** * Sets the flag that controls whether the shared domain axis is drawn when * this plot is being used as a subplot. * * @param draw a boolean. * * @see #getDrawSharedDomainAxis() */ public void setDrawSharedDomainAxis(boolean draw) { this.drawSharedDomainAxis = draw; fireChangeEvent(); } /** * Returns <code>false</code> always, because the plot cannot be panned * along the domain axis/axes. * * @return A boolean. * * @see #isRangePannable() * * @since 1.0.13 */ @Override public boolean isDomainPannable() { return false; } /** * Returns <code>true</code> if panning is enabled for the range axes, * and <code>false</code> otherwise. * * @return A boolean. * * @see #setRangePannable(boolean) * @see #isDomainPannable() * * @since 1.0.13 */ @Override public boolean isRangePannable() { return this.rangePannable; } /** * Sets the flag that enables or disables panning of the plot along * the range axes. * * @param pannable the new flag value. * * @see #isRangePannable() * * @since 1.0.13 */ public void setRangePannable(boolean pannable) { this.rangePannable = pannable; } /** * Pans the domain axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.13 */ @Override public void panDomainAxes(double percent, PlotRenderingInfo info, Point2D source) { // do nothing, because the plot is not pannable along the domain axes } /** * Pans the range axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.13 */ @Override public void panRangeAxes(double percent, PlotRenderingInfo info, Point2D source) { if (!isRangePannable()) { return; } int rangeAxisCount = getRangeAxisCount(); for (int i = 0; i < rangeAxisCount; i++) { ValueAxis axis = getRangeAxis(i); if (axis == null) { continue; } double length = axis.getRange().getLength(); double adj = percent * length; if (axis.isInverted()) { adj = -adj; } axis.setRange(axis.getLowerBound() + adj, axis.getUpperBound() + adj); } } /** * Returns <code>false</code> to indicate that the domain axes are not * zoomable. * * @return A boolean. * * @see #isRangeZoomable() */ @Override public boolean isDomainZoomable() { return false; } /** * Returns <code>true</code> to indicate that the range axes are zoomable. * * @return A boolean. * * @see #isDomainZoomable() */ @Override public boolean isRangeZoomable() { return true; } /** * This method does nothing, because <code>CategoryPlot</code> doesn't * support zooming on the domain. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D space) for the zoom. */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source) { // can't zoom domain axis } /** * This method does nothing, because <code>CategoryPlot</code> doesn't * support zooming on the domain. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param state the plot state. * @param source the source point (in Java2D space) for the zoom. */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source) { // can't zoom domain axis } /** * This method does nothing, because <code>CategoryPlot</code> doesn't * support zooming on the domain. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // can't zoom domain axis } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D space) for the zoom. */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source) { // delegate to other method zoomRangeAxes(factor, state, source, false); } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. * @param useAnchor a flag that controls whether or not the source point * is used for the zoom anchor. * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // perform the zoom on each range axis for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = this.rangeAxes.get(i); if (rangeAxis != null) { if (useAnchor) { // get the relevant source coordinate given the plot // orientation double sourceY = source.getY(); if (this.orientation == PlotOrientation.HORIZONTAL) { sourceY = source.getX(); } double anchorY = rangeAxis.java2DToValue(sourceY, info.getDataArea(), getRangeAxisEdge()); rangeAxis.resizeRange2(factor, anchorY); } else { rangeAxis.resizeRange(factor); } } } } /** * Zooms in on the range axes. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param state the plot state. * @param source the source point (in Java2D space) for the zoom. */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source) { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = this.rangeAxes.get(i); if (rangeAxis != null) { rangeAxis.zoomRange(lowerPercent, upperPercent); } } } /** * Returns the anchor value. * * @return The anchor value. * * @see #setAnchorValue(double) */ public double getAnchorValue() { return this.anchorValue; } /** * Sets the anchor value and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param value the anchor value. * * @see #getAnchorValue() */ public void setAnchorValue(double value) { setAnchorValue(value, true); } /** * Sets the anchor value and, if requested, sends a {@link PlotChangeEvent} * to all registered listeners. * * @param value the value. * @param notify notify listeners? * * @see #getAnchorValue() */ public void setAnchorValue(double value, boolean notify) { this.anchorValue = value; if (notify) { fireChangeEvent(); } } /** * Tests the plot for equality with an arbitrary object. * * @param obj the object to test against (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CategoryPlot)) { return false; } CategoryPlot that = (CategoryPlot) obj; if (this.orientation != that.orientation) { return false; } if (!ObjectUtilities.equal(this.axisOffset, that.axisOffset)) { return false; } if (!this.domainAxes.equals(that.domainAxes)) { return false; } if (!this.domainAxisLocations.equals(that.domainAxisLocations)) { return false; } if (this.drawSharedDomainAxis != that.drawSharedDomainAxis) { return false; } if (!this.rangeAxes.equals(that.rangeAxes)) { return false; } if (!this.rangeAxisLocations.equals(that.rangeAxisLocations)) { return false; } if (!ObjectUtilities.equal(this.datasetToDomainAxesMap, that.datasetToDomainAxesMap)) { return false; } if (!ObjectUtilities.equal(this.datasetToRangeAxesMap, that.datasetToRangeAxesMap)) { return false; } if (!ObjectUtilities.equal(this.renderers, that.renderers)) { return false; } if (this.renderingOrder != that.renderingOrder) { return false; } if (this.columnRenderingOrder != that.columnRenderingOrder) { return false; } if (this.rowRenderingOrder != that.rowRenderingOrder) { return false; } if (this.domainGridlinesVisible != that.domainGridlinesVisible) { return false; } if (this.domainGridlinePosition != that.domainGridlinePosition) { return false; } if (!ObjectUtilities.equal(this.domainGridlineStroke, that.domainGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.domainGridlinePaint, that.domainGridlinePaint)) { return false; } if (this.rangeGridlinesVisible != that.rangeGridlinesVisible) { return false; } if (!ObjectUtilities.equal(this.rangeGridlineStroke, that.rangeGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.rangeGridlinePaint, that.rangeGridlinePaint)) { return false; } if (this.anchorValue != that.anchorValue) { return false; } if (this.rangeCrosshairVisible != that.rangeCrosshairVisible) { return false; } if (this.rangeCrosshairValue != that.rangeCrosshairValue) { return false; } if (!ObjectUtilities.equal(this.rangeCrosshairStroke, that.rangeCrosshairStroke)) { return false; } if (!PaintUtilities.equal(this.rangeCrosshairPaint, that.rangeCrosshairPaint)) { return false; } if (this.rangeCrosshairLockedOnData != that.rangeCrosshairLockedOnData) { return false; } if (!ObjectUtilities.equal(this.foregroundDomainMarkers, that.foregroundDomainMarkers)) { return false; } if (!ObjectUtilities.equal(this.backgroundDomainMarkers, that.backgroundDomainMarkers)) { return false; } if (!ObjectUtilities.equal(this.foregroundRangeMarkers, that.foregroundRangeMarkers)) { return false; } if (!ObjectUtilities.equal(this.backgroundRangeMarkers, that.backgroundRangeMarkers)) { return false; } if (!ObjectUtilities.equal(this.annotations, that.annotations)) { return false; } if (this.weight != that.weight) { return false; } if (!ObjectUtilities.equal(this.fixedDomainAxisSpace, that.fixedDomainAxisSpace)) { return false; } if (!ObjectUtilities.equal(this.fixedRangeAxisSpace, that.fixedRangeAxisSpace)) { return false; } if (!ObjectUtilities.equal(this.fixedLegendItems, that.fixedLegendItems)) { return false; } if (this.domainCrosshairVisible != that.domainCrosshairVisible) { return false; } if (this.crosshairDatasetIndex != that.crosshairDatasetIndex) { return false; } if (!ObjectUtilities.equal(this.domainCrosshairColumnKey, that.domainCrosshairColumnKey)) { return false; } if (!ObjectUtilities.equal(this.domainCrosshairRowKey, that.domainCrosshairRowKey)) { return false; } if (!PaintUtilities.equal(this.domainCrosshairPaint, that.domainCrosshairPaint)) { return false; } if (!ObjectUtilities.equal(this.domainCrosshairStroke, that.domainCrosshairStroke)) { return false; } if (this.rangeMinorGridlinesVisible != that.rangeMinorGridlinesVisible) { return false; } if (!PaintUtilities.equal(this.rangeMinorGridlinePaint, that.rangeMinorGridlinePaint)) { return false; } if (!ObjectUtilities.equal(this.rangeMinorGridlineStroke, that.rangeMinorGridlineStroke)) { return false; } if (this.rangeZeroBaselineVisible != that.rangeZeroBaselineVisible) { return false; } if (!PaintUtilities.equal(this.rangeZeroBaselinePaint, that.rangeZeroBaselinePaint)) { return false; } if (!ObjectUtilities.equal(this.rangeZeroBaselineStroke, that.rangeZeroBaselineStroke)) { return false; } if (!ObjectUtilities.equal(this.shadowGenerator, that.shadowGenerator)) { return false; } return super.equals(obj); } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException if the cloning is not supported. */ @Override public Object clone() throws CloneNotSupportedException { CategoryPlot clone = (CategoryPlot) super.clone(); clone.domainAxes = new ObjectList<CategoryAxis>(); for (int i = 0; i < this.domainAxes.size(); i++) { CategoryAxis xAxis = this.domainAxes.get(i); if (xAxis != null) { CategoryAxis clonedAxis = (CategoryAxis) xAxis.clone(); clone.setDomainAxis(i, clonedAxis); } } clone.domainAxisLocations = (ObjectList<AxisLocation>) this.domainAxisLocations.clone(); clone.rangeAxes = new ObjectList<ValueAxis>(); for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis yAxis = this.rangeAxes.get(i); if (yAxis != null) { ValueAxis clonedAxis = (ValueAxis) yAxis.clone(); clone.setRangeAxis(i, clonedAxis); } } clone.rangeAxisLocations = (ObjectList<AxisLocation>) this.rangeAxisLocations.clone(); clone.datasets = (ObjectList<CategoryDataset>) this.datasets.clone(); for (int i = 0; i < clone.datasets.size(); i++) { CategoryDataset dataset = clone.getDataset(i); if (dataset != null) { dataset.addChangeListener(clone); } } clone.datasetToDomainAxesMap = new TreeMap<Integer, List<Integer>>(); clone.datasetToDomainAxesMap.putAll(this.datasetToDomainAxesMap); clone.datasetToRangeAxesMap = new TreeMap<Integer, List<Integer>>(); clone.datasetToRangeAxesMap.putAll(this.datasetToRangeAxesMap); clone.renderers = (ObjectList<CategoryItemRenderer>) this.renderers.clone(); for (int i = 0; i < this.renderers.size(); i++) { CategoryItemRenderer renderer2 = this.renderers.get(i); if (renderer2 instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) renderer2; CategoryItemRenderer rc = (CategoryItemRenderer) pc.clone(); clone.renderers.set(i, rc); rc.setPlot(clone); rc.addChangeListener(clone); } } if (this.fixedDomainAxisSpace != null) { clone.fixedDomainAxisSpace = ObjectUtilities.clone( this.fixedDomainAxisSpace); } if (this.fixedRangeAxisSpace != null) { clone.fixedRangeAxisSpace = ObjectUtilities.clone( this.fixedRangeAxisSpace); } clone.annotations = ObjectUtilities.deepClone(this.annotations); clone.foregroundDomainMarkers = cloneMarkerMap( this.foregroundDomainMarkers); clone.backgroundDomainMarkers = cloneMarkerMap( this.backgroundDomainMarkers); clone.foregroundRangeMarkers = cloneMarkerMap( this.foregroundRangeMarkers); clone.backgroundRangeMarkers = cloneMarkerMap( this.backgroundRangeMarkers); if (this.fixedLegendItems != null) { clone.fixedLegendItems = ObjectUtilities.deepClone(this.fixedLegendItems); } return clone; } /** * A utility method to clone the marker maps. * * @param map the map to clone. * * @return A clone of the map. * * @throws CloneNotSupportedException if there is some problem cloning the * map. */ private Map<Integer, Collection<Marker>> cloneMarkerMap(Map<Integer, Collection<Marker>> map) throws CloneNotSupportedException { Map<Integer, Collection<Marker>> clone = new HashMap<Integer, Collection<Marker>>(); Set<Integer> keys = map.keySet(); for (Integer key : keys) { Collection<Marker> entry = map.get(key); Collection<Marker> toAdd = ObjectUtilities.<Marker, Collection<Marker>>deepClone(entry); clone.put(key, toAdd); } return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.domainGridlineStroke, stream); SerialUtilities.writePaint(this.domainGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeGridlineStroke, stream); SerialUtilities.writePaint(this.rangeGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeCrosshairStroke, stream); SerialUtilities.writePaint(this.rangeCrosshairPaint, stream); SerialUtilities.writeStroke(this.domainCrosshairStroke, stream); SerialUtilities.writePaint(this.domainCrosshairPaint, stream); SerialUtilities.writeStroke(this.rangeMinorGridlineStroke, stream); SerialUtilities.writePaint(this.rangeMinorGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeZeroBaselineStroke, stream); SerialUtilities.writePaint(this.rangeZeroBaselinePaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.domainGridlineStroke = SerialUtilities.readStroke(stream); this.domainGridlinePaint = SerialUtilities.readPaint(stream); this.rangeGridlineStroke = SerialUtilities.readStroke(stream); this.rangeGridlinePaint = SerialUtilities.readPaint(stream); this.rangeCrosshairStroke = SerialUtilities.readStroke(stream); this.rangeCrosshairPaint = SerialUtilities.readPaint(stream); this.domainCrosshairStroke = SerialUtilities.readStroke(stream); this.domainCrosshairPaint = SerialUtilities.readPaint(stream); this.rangeMinorGridlineStroke = SerialUtilities.readStroke(stream); this.rangeMinorGridlinePaint = SerialUtilities.readPaint(stream); this.rangeZeroBaselineStroke = SerialUtilities.readStroke(stream); this.rangeZeroBaselinePaint = SerialUtilities.readPaint(stream); for (int i = 0; i < this.domainAxes.size(); i++) { CategoryAxis xAxis = this.domainAxes.get(i); if (xAxis != null) { xAxis.setPlot(this); xAxis.addChangeListener(this); } } for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis yAxis = this.rangeAxes.get(i); if (yAxis != null) { yAxis.setPlot(this); yAxis.addChangeListener(this); } } int datasetCount = this.datasets.size(); for (int i = 0; i < datasetCount; i++) { Dataset dataset = this.datasets.get(i); if (dataset != null) { dataset.addChangeListener(this); } } int rendererCount = this.renderers.size(); for (int i = 0; i < rendererCount; i++) { CategoryItemRenderer renderer = this.renderers.get(i); if (renderer != null) { renderer.addChangeListener(this); } } } }
172,439
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MeterPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/MeterPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * MeterPlot.java * -------------- * (C) Copyright 2000-2014, by Hari and Contributors. * * Original Author: Hari ([email protected]); * Contributor(s): David Gilbert (for Object Refinery Limited); * Bob Orchard; * Arnaud Lelievre; * Nicolas Brodu; * David Bastend; * * Changes * ------- * 01-Apr-2002 : Version 1, contributed by Hari (DG); * 23-Apr-2002 : Moved dataset from JFreeChart to Plot (DG); * 22-Aug-2002 : Added changes suggest by Bob Orchard, changed Color to Paint * for consistency, plus added Javadoc comments (DG); * 01-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 23-Jan-2003 : Removed one constructor (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 20-Aug-2003 : Changed dataset from MeterDataset --> ValueDataset, added * equals() method, * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * implemented Cloneable, and various other changes (DG); * 08-Sep-2003 : Added serialization methods (NB); * 11-Sep-2003 : Added cloning support (NB); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 25-Sep-2003 : Fix useless cloning. Correct dataset listener registration in * constructor. (NB) * 29-Oct-2003 : Added workaround for font alignment in PDF output (DG); * 17-Jan-2004 : Changed to allow dialBackgroundPaint to be set to null - see * bug 823628 (DG); * 07-Apr-2004 : Changed string bounds calculation (DG); * 12-May-2004 : Added tickLabelFormat attribute - see RFE 949566. Also * updated the equals() method (DG); * 02-Nov-2004 : Added sanity checks for range, and only draw the needle if the * value is contained within the overall range - see bug report * 1056047 (DG); * 11-Jan-2005 : Removed deprecated code in preparation for the 1.0.0 * release (DG); * 02-Feb-2005 : Added optional background paint for each region (DG); * 22-Mar-2005 : Removed 'normal', 'warning' and 'critical' regions and put in * facility to define an arbitrary number of MeterIntervals, * based on a contribution by David Bastend (DG); * 20-Apr-2005 : Small update for change to LegendItem constructors (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 08-Jun-2005 : Fixed equals() method to handle GradientPaint (DG); * 10-Nov-2005 : Added tickPaint, tickSize and valuePaint attributes, and * put value label drawing code into a separate method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Mar-2007 : Restore clip region correctly (see bug 1667750) (DG); * 18-May-2007 : Set dataset for LegendItem (DG); * 29-Nov-2007 : Fixed serialization bug with dialOutlinePaint (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Polygon; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.ResourceBundle; import org.jfree.chart.LegendItem; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.Range; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.ValueDataset; /** * A plot that displays a single value in the form of a needle on a dial. * Defined ranges (for example, 'normal', 'warning' and 'critical') can be * highlighted on the dial. */ public class MeterPlot extends Plot implements Serializable, Cloneable { /** For serialization. */ private static final long serialVersionUID = 2987472457734470962L; /** The default background paint. */ static final Paint DEFAULT_DIAL_BACKGROUND_PAINT = Color.BLACK; /** The default needle paint. */ static final Paint DEFAULT_NEEDLE_PAINT = Color.GREEN; /** The default value font. */ static final Font DEFAULT_VALUE_FONT = new Font("SansSerif", Font.BOLD, 12); /** The default value paint. */ static final Paint DEFAULT_VALUE_PAINT = Color.YELLOW; /** The default meter angle. */ public static final int DEFAULT_METER_ANGLE = 270; /** The default border size. */ public static final float DEFAULT_BORDER_SIZE = 3f; /** The default circle size. */ public static final float DEFAULT_CIRCLE_SIZE = 10f; /** The default label font. */ public static final Font DEFAULT_LABEL_FONT = new Font("SansSerif", Font.BOLD, 10); /** The dataset (contains a single value). */ private ValueDataset dataset; /** The dial shape (background shape). */ private DialShape shape; /** The dial extent (measured in degrees). */ private int meterAngle; /** The overall range of data values on the dial. */ private Range range; /** The tick size. */ private double tickSize; /** The paint used to draw the ticks. */ private transient Paint tickPaint; /** The units displayed on the dial. */ private String units; /** The font for the value displayed in the center of the dial. */ private Font valueFont; /** The paint for the value displayed in the center of the dial. */ private transient Paint valuePaint; /** A flag that controls whether or not the border is drawn. */ private boolean drawBorder; /** The outline paint. */ private transient Paint dialOutlinePaint; /** The paint for the dial background. */ private transient Paint dialBackgroundPaint; /** The paint for the needle. */ private transient Paint needlePaint; /** A flag that controls whether or not the tick labels are visible. */ private boolean tickLabelsVisible; /** The tick label font. */ private Font tickLabelFont; /** The tick label paint. */ private transient Paint tickLabelPaint; /** The tick label format. */ private NumberFormat tickLabelFormat; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** * A (possibly empty) list of the {@link MeterInterval}s to be highlighted * on the dial. */ private List<MeterInterval> intervals; /** * Creates a new plot with a default range of <code>0</code> to * <code>100</code> and no value to display. */ public MeterPlot() { this(null); } /** * Creates a new plot that displays the value from the supplied dataset. * * @param dataset the dataset (<code>null</code> permitted). */ public MeterPlot(ValueDataset dataset) { super(); this.shape = DialShape.CIRCLE; this.meterAngle = DEFAULT_METER_ANGLE; this.range = new Range(0.0, 100.0); this.tickSize = 10.0; this.tickPaint = Color.WHITE; this.units = "Units"; this.needlePaint = MeterPlot.DEFAULT_NEEDLE_PAINT; this.tickLabelsVisible = true; this.tickLabelFont = MeterPlot.DEFAULT_LABEL_FONT; this.tickLabelPaint = Color.BLACK; this.tickLabelFormat = NumberFormat.getInstance(); this.valueFont = MeterPlot.DEFAULT_VALUE_FONT; this.valuePaint = MeterPlot.DEFAULT_VALUE_PAINT; this.dialBackgroundPaint = MeterPlot.DEFAULT_DIAL_BACKGROUND_PAINT; this.intervals = new java.util.ArrayList<MeterInterval>(); setDataset(dataset); } /** * Returns the dial shape. The default is {@link DialShape#CIRCLE}). * * @return The dial shape (never <code>null</code>). * * @see #setDialShape(DialShape) */ public DialShape getDialShape() { return this.shape; } /** * Sets the dial shape and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param shape the shape (<code>null</code> not permitted). * * @see #getDialShape() */ public void setDialShape(DialShape shape) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } this.shape = shape; fireChangeEvent(); } /** * Returns the meter angle in degrees. This defines, in part, the shape * of the dial. The default is 270 degrees. * * @return The meter angle (in degrees). * * @see #setMeterAngle(int) */ public int getMeterAngle() { return this.meterAngle; } /** * Sets the angle (in degrees) for the whole range of the dial and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param angle the angle (in degrees, in the range 1-360). * * @see #getMeterAngle() */ public void setMeterAngle(int angle) { if (angle < 1 || angle > 360) { throw new IllegalArgumentException("Invalid 'angle' (" + angle + ")"); } this.meterAngle = angle; fireChangeEvent(); } /** * Returns the overall range for the dial. * * @return The overall range (never <code>null</code>). * * @see #setRange(Range) */ public Range getRange() { return this.range; } /** * Sets the range for the dial and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param range the range (<code>null</code> not permitted and zero-length * ranges not permitted). * * @see #getRange() */ public void setRange(Range range) { if (range == null) { throw new IllegalArgumentException("Null 'range' argument."); } if (!(range.getLength() > 0.0)) { throw new IllegalArgumentException( "Range length must be positive."); } this.range = range; fireChangeEvent(); } /** * Returns the tick size (the interval between ticks on the dial). * * @return The tick size. * * @see #setTickSize(double) */ public double getTickSize() { return this.tickSize; } /** * Sets the tick size and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param size the tick size (must be > 0). * * @see #getTickSize() */ public void setTickSize(double size) { if (size <= 0) { throw new IllegalArgumentException("Requires 'size' > 0."); } this.tickSize = size; fireChangeEvent(); } /** * Returns the paint used to draw the ticks around the dial. * * @return The paint used to draw the ticks around the dial (never * <code>null</code>). * * @see #setTickPaint(Paint) */ public Paint getTickPaint() { return this.tickPaint; } /** * Sets the paint used to draw the tick labels around the dial and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getTickPaint() */ public void setTickPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.tickPaint = paint; fireChangeEvent(); } /** * Returns a string describing the units for the dial. * * @return The units (possibly <code>null</code>). * * @see #setUnits(String) */ public String getUnits() { return this.units; } /** * Sets the units for the dial and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param units the units (<code>null</code> permitted). * * @see #getUnits() */ public void setUnits(String units) { this.units = units; fireChangeEvent(); } /** * Returns the paint for the needle. * * @return The paint (never <code>null</code>). * * @see #setNeedlePaint(Paint) */ public Paint getNeedlePaint() { return this.needlePaint; } /** * Sets the paint used to display the needle and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getNeedlePaint() */ public void setNeedlePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.needlePaint = paint; fireChangeEvent(); } /** * Returns the flag that determines whether or not tick labels are visible. * * @return The flag. * * @see #setTickLabelsVisible(boolean) */ public boolean getTickLabelsVisible() { return this.tickLabelsVisible; } /** * Sets the flag that controls whether or not the tick labels are visible * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param visible the flag. * * @see #getTickLabelsVisible() */ public void setTickLabelsVisible(boolean visible) { if (this.tickLabelsVisible != visible) { this.tickLabelsVisible = visible; fireChangeEvent(); } } /** * Returns the tick label font. * * @return The font (never <code>null</code>). * * @see #setTickLabelFont(Font) */ public Font getTickLabelFont() { return this.tickLabelFont; } /** * Sets the tick label font and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getTickLabelFont() */ public void setTickLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } if (!this.tickLabelFont.equals(font)) { this.tickLabelFont = font; fireChangeEvent(); } } /** * Returns the tick label paint. * * @return The paint (never <code>null</code>). * * @see #setTickLabelPaint(Paint) */ public Paint getTickLabelPaint() { return this.tickLabelPaint; } /** * Sets the tick label paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getTickLabelPaint() */ public void setTickLabelPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } if (!this.tickLabelPaint.equals(paint)) { this.tickLabelPaint = paint; fireChangeEvent(); } } /** * Returns the tick label format. * * @return The tick label format (never <code>null</code>). * * @see #setTickLabelFormat(NumberFormat) */ public NumberFormat getTickLabelFormat() { return this.tickLabelFormat; } /** * Sets the format for the tick labels and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param format the format (<code>null</code> not permitted). * * @see #getTickLabelFormat() */ public void setTickLabelFormat(NumberFormat format) { if (format == null) { throw new IllegalArgumentException("Null 'format' argument."); } this.tickLabelFormat = format; fireChangeEvent(); } /** * Returns the font for the value label. * * @return The font (never <code>null</code>). * * @see #setValueFont(Font) */ public Font getValueFont() { return this.valueFont; } /** * Sets the font used to display the value label and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getValueFont() */ public void setValueFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.valueFont = font; fireChangeEvent(); } /** * Returns the paint for the value label. * * @return The paint (never <code>null</code>). * * @see #setValuePaint(Paint) */ public Paint getValuePaint() { return this.valuePaint; } /** * Sets the paint used to display the value label and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getValuePaint() */ public void setValuePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.valuePaint = paint; fireChangeEvent(); } /** * Returns the paint for the dial background. * * @return The paint (possibly <code>null</code>). * * @see #setDialBackgroundPaint(Paint) */ public Paint getDialBackgroundPaint() { return this.dialBackgroundPaint; } /** * Sets the paint used to fill the dial background. Set this to * <code>null</code> for no background. * * @param paint the paint (<code>null</code> permitted). * * @see #getDialBackgroundPaint() */ public void setDialBackgroundPaint(Paint paint) { this.dialBackgroundPaint = paint; fireChangeEvent(); } /** * Returns a flag that controls whether or not a rectangular border is * drawn around the plot area. * * @return A flag. * * @see #setDrawBorder(boolean) */ public boolean getDrawBorder() { return this.drawBorder; } /** * Sets the flag that controls whether or not a rectangular border is drawn * around the plot area and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param draw the flag. * * @see #getDrawBorder() */ public void setDrawBorder(boolean draw) { // TODO: fix output when this flag is set to true this.drawBorder = draw; fireChangeEvent(); } /** * Returns the dial outline paint. * * @return The paint. * * @see #setDialOutlinePaint(Paint) */ public Paint getDialOutlinePaint() { return this.dialOutlinePaint; } /** * Sets the dial outline paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint. * * @see #getDialOutlinePaint() */ public void setDialOutlinePaint(Paint paint) { this.dialOutlinePaint = paint; fireChangeEvent(); } /** * Returns the dataset for the plot. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(ValueDataset) */ public ValueDataset getDataset() { return this.dataset; } /** * Sets the dataset for the plot, replacing the existing dataset if there * is one, and triggers a {@link PlotChangeEvent}. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() */ public void setDataset(ValueDataset dataset) { // if there is an existing dataset, remove the plot from the list of // change listeners... ValueDataset existing = this.dataset; if (existing != null) { existing.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns an unmodifiable list of the intervals for the plot. * * @return A list. * * @see #addInterval(MeterInterval) */ public List<MeterInterval> getIntervals() { return Collections.unmodifiableList(this.intervals); } /** * Adds an interval and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param interval the interval (<code>null</code> not permitted). * * @see #getIntervals() * @see #clearIntervals() */ public void addInterval(MeterInterval interval) { if (interval == null) { throw new IllegalArgumentException("Null 'interval' argument."); } this.intervals.add(interval); fireChangeEvent(); } /** * Clears the intervals for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @see #addInterval(MeterInterval) */ public void clearIntervals() { this.intervals.clear(); fireChangeEvent(); } /** * Returns an item for each interval. * * @return A collection of legend items. */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = new ArrayList<LegendItem>(); for (MeterInterval mi : this.intervals) { Paint color = mi.getBackgroundPaint(); if (color == null) { color = mi.getOutlinePaint(); } LegendItem item = new LegendItem(mi.getLabel(), mi.getLabel(), null, null, new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0), color); item.setDataset(getDataset()); result.add(item); } return result; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); area.setRect(area.getX() + 4, area.getY() + 4, area.getWidth() - 8, area.getHeight() - 8); // draw the background if (this.drawBorder) { drawBackground(g2, area); } // adjust the plot area by the interior spacing value double gapHorizontal = (2 * DEFAULT_BORDER_SIZE); double gapVertical = (2 * DEFAULT_BORDER_SIZE); double meterX = area.getX() + gapHorizontal / 2; double meterY = area.getY() + gapVertical / 2; double meterW = area.getWidth() - gapHorizontal; double meterH = area.getHeight() - gapVertical + ((this.meterAngle <= 180) && (this.shape != DialShape.CIRCLE) ? area.getHeight() / 1.25 : 0); double min = Math.min(meterW, meterH) / 2; meterX = (meterX + meterX + meterW) / 2 - min; meterY = (meterY + meterY + meterH) / 2 - min; meterW = 2 * min; meterH = 2 * min; Rectangle2D meterArea = new Rectangle2D.Double(meterX, meterY, meterW, meterH); Rectangle2D.Double originalArea = new Rectangle2D.Double( meterArea.getX() - 4, meterArea.getY() - 4, meterArea.getWidth() + 8, meterArea.getHeight() + 8); double meterMiddleX = meterArea.getCenterX(); double meterMiddleY = meterArea.getCenterY(); // plot the data (unless the dataset is null)... ValueDataset data = getDataset(); if (data != null) { double dataMin = this.range.getLowerBound(); double dataMax = this.range.getUpperBound(); Shape savedClip = g2.getClip(); g2.clip(originalArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (this.dialBackgroundPaint != null) { fillArc(g2, originalArea, dataMin, dataMax, this.dialBackgroundPaint, true); } drawTicks(g2, meterArea, dataMin, dataMax); drawArcForInterval(g2, meterArea, new MeterInterval("", this.range, this.dialOutlinePaint, new BasicStroke(1.0f), null)); for (MeterInterval interval : this.intervals) { drawArcForInterval(g2, meterArea, interval); } Number n = data.getValue(); if (n != null) { double value = n.doubleValue(); drawValueLabel(g2, meterArea); if (this.range.contains(value)) { g2.setPaint(this.needlePaint); g2.setStroke(new BasicStroke(2.0f)); double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE + 15; double valueAngle = valueToAngle(value); double valueP1 = meterMiddleX + (radius * Math.cos(Math.PI * (valueAngle / 180))); double valueP2 = meterMiddleY - (radius * Math.sin(Math.PI * (valueAngle / 180))); Polygon arrow = new Polygon(); if ((valueAngle > 135 && valueAngle < 225) || (valueAngle < 45 && valueAngle > -45)) { double valueP3 = (meterMiddleY - DEFAULT_CIRCLE_SIZE / 4); double valueP4 = (meterMiddleY + DEFAULT_CIRCLE_SIZE / 4); arrow.addPoint((int) meterMiddleX, (int) valueP3); arrow.addPoint((int) meterMiddleX, (int) valueP4); } else { arrow.addPoint((int) (meterMiddleX - DEFAULT_CIRCLE_SIZE / 4), (int) meterMiddleY); arrow.addPoint((int) (meterMiddleX + DEFAULT_CIRCLE_SIZE / 4), (int) meterMiddleY); } arrow.addPoint((int) valueP1, (int) valueP2); g2.fill(arrow); Ellipse2D circle = new Ellipse2D.Double(meterMiddleX - DEFAULT_CIRCLE_SIZE / 2, meterMiddleY - DEFAULT_CIRCLE_SIZE / 2, DEFAULT_CIRCLE_SIZE, DEFAULT_CIRCLE_SIZE); g2.fill(circle); } } g2.setClip(savedClip); g2.setComposite(originalComposite); } if (this.drawBorder) { drawOutline(g2, area); } } /** * Draws the arc to represent an interval. * * @param g2 the graphics device. * @param meterArea the drawing area. * @param interval the interval. */ protected void drawArcForInterval(Graphics2D g2, Rectangle2D meterArea, MeterInterval interval) { double minValue = interval.getRange().getLowerBound(); double maxValue = interval.getRange().getUpperBound(); Paint outlinePaint = interval.getOutlinePaint(); Stroke outlineStroke = interval.getOutlineStroke(); Paint backgroundPaint = interval.getBackgroundPaint(); if (backgroundPaint != null) { fillArc(g2, meterArea, minValue, maxValue, backgroundPaint, false); } if (outlinePaint != null) { if (outlineStroke != null) { drawArc(g2, meterArea, minValue, maxValue, outlinePaint, outlineStroke); } drawTick(g2, meterArea, minValue, true); drawTick(g2, meterArea, maxValue, true); } } /** * Draws an arc. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum value. * @param maxValue the maximum value. * @param paint the paint. * @param stroke the stroke. */ protected void drawArc(Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, Stroke stroke) { double startAngle = valueToAngle(maxValue); double endAngle = valueToAngle(minValue); double extent = endAngle - startAngle; double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); g2.setPaint(paint); g2.setStroke(stroke); if (paint != null && stroke != null) { Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, Arc2D.OPEN); g2.setPaint(paint); g2.setStroke(stroke); g2.draw(arc); } } /** * Fills an arc on the dial between the given values. * * @param g2 the graphics device. * @param area the plot area. * @param minValue the minimum data value. * @param maxValue the maximum data value. * @param paint the background paint (<code>null</code> not permitted). * @param dial a flag that indicates whether the arc represents the whole * dial. */ protected void fillArc(Graphics2D g2, Rectangle2D area, double minValue, double maxValue, Paint paint, boolean dial) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument"); } double startAngle = valueToAngle(maxValue); double endAngle = valueToAngle(minValue); double extent = endAngle - startAngle; double x = area.getX(); double y = area.getY(); double w = area.getWidth(); double h = area.getHeight(); int joinType; if (this.shape == DialShape.PIE) { joinType = Arc2D.PIE; } else if (this.shape == DialShape.CHORD) { if (dial && this.meterAngle > 180) { joinType = Arc2D.CHORD; } else { joinType = Arc2D.PIE; } } else if (this.shape == DialShape.CIRCLE) { joinType = Arc2D.PIE; if (dial) { extent = 360; } } else { throw new IllegalStateException("DialShape not recognised."); } g2.setPaint(paint); Arc2D.Double arc = new Arc2D.Double(x, y, w, h, startAngle, extent, joinType); g2.fill(arc); } /** * Translates a data value to an angle on the dial. * * @param value the value. * * @return The angle on the dial. */ public double valueToAngle(double value) { value = value - this.range.getLowerBound(); double baseAngle = 180 + ((this.meterAngle - 180) / 2); return baseAngle - ((value / this.range.getLength()) * this.meterAngle); } /** * Draws the ticks that subdivide the overall range. * * @param g2 the graphics device. * @param meterArea the meter area. * @param minValue the minimum value. * @param maxValue the maximum value. */ protected void drawTicks(Graphics2D g2, Rectangle2D meterArea, double minValue, double maxValue) { for (double v = minValue; v <= maxValue; v += this.tickSize) { drawTick(g2, meterArea, v); } } /** * Draws a tick. * * @param g2 the graphics device. * @param meterArea the meter area. * @param value the value. */ protected void drawTick(Graphics2D g2, Rectangle2D meterArea, double value) { drawTick(g2, meterArea, value, false); } /** * Draws a tick on the dial. * * @param g2 the graphics device. * @param meterArea the meter area. * @param value the tick value. * @param label a flag that controls whether or not a value label is drawn. */ protected void drawTick(Graphics2D g2, Rectangle2D meterArea, double value, boolean label) { double valueAngle = valueToAngle(value); double meterMiddleX = meterArea.getCenterX(); double meterMiddleY = meterArea.getCenterY(); g2.setPaint(this.tickPaint); g2.setStroke(new BasicStroke(2.0f)); double valueP2X; double valueP2Y; double radius = (meterArea.getWidth() / 2) + DEFAULT_BORDER_SIZE; double radius1 = radius - 15; double valueP1X = meterMiddleX + (radius * Math.cos(Math.PI * (valueAngle / 180))); double valueP1Y = meterMiddleY - (radius * Math.sin(Math.PI * (valueAngle / 180))); valueP2X = meterMiddleX + (radius1 * Math.cos(Math.PI * (valueAngle / 180))); valueP2Y = meterMiddleY - (radius1 * Math.sin(Math.PI * (valueAngle / 180))); Line2D.Double line = new Line2D.Double(valueP1X, valueP1Y, valueP2X, valueP2Y); g2.draw(line); if (this.tickLabelsVisible && label) { String tickLabel = this.tickLabelFormat.format(value); g2.setFont(this.tickLabelFont); g2.setPaint(this.tickLabelPaint); FontMetrics fm = g2.getFontMetrics(); Rectangle2D tickLabelBounds = TextUtilities.getTextBounds(tickLabel, g2, fm); double x = valueP2X; double y = valueP2Y; if (valueAngle == 90 || valueAngle == 270) { x = x - tickLabelBounds.getWidth() / 2; } else if (valueAngle < 90 || valueAngle > 270) { x = x - tickLabelBounds.getWidth(); } if ((valueAngle > 135 && valueAngle < 225) || valueAngle > 315 || valueAngle < 45) { y = y - tickLabelBounds.getHeight() / 2; } else { y = y + tickLabelBounds.getHeight() / 2; } g2.drawString(tickLabel, (float) x, (float) y); } } /** * Draws the value label just below the center of the dial. * * @param g2 the graphics device. * @param area the plot area. */ protected void drawValueLabel(Graphics2D g2, Rectangle2D area) { g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); String valueStr = "No value"; if (this.dataset != null) { Number n = this.dataset.getValue(); if (n != null) { valueStr = this.tickLabelFormat.format(n.doubleValue()) + " " + this.units; } } float x = (float) area.getCenterX(); float y = (float) area.getCenterY() + DEFAULT_CIRCLE_SIZE; TextUtilities.drawAlignedString(valueStr, g2, x, y, TextAnchor.TOP_CENTER); } /** * Returns a short string describing the type of plot. * * @return A string describing the type of plot. */ @Override public String getPlotType() { return localizationResources.getString("Meter_Plot"); } /** * A zoom method that does nothing. Plots are required to support the * zoom operation. In the case of a meter plot, it doesn't make sense to * zoom in or out, so the method is empty. * * @param percent The zoom percentage. */ @Override public void zoom(double percent) { // intentionally blank } /** * Tests the plot for equality with an arbitrary object. Note that the * dataset is ignored for the purposes of testing equality. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof MeterPlot)) { return false; } if (!super.equals(obj)) { return false; } MeterPlot that = (MeterPlot) obj; if (!ObjectUtilities.equal(this.units, that.units)) { return false; } if (!ObjectUtilities.equal(this.range, that.range)) { return false; } if (!ObjectUtilities.equal(this.intervals, that.intervals)) { return false; } if (!PaintUtilities.equal(this.dialOutlinePaint, that.dialOutlinePaint)) { return false; } if (this.shape != that.shape) { return false; } if (!PaintUtilities.equal(this.dialBackgroundPaint, that.dialBackgroundPaint)) { return false; } if (!PaintUtilities.equal(this.needlePaint, that.needlePaint)) { return false; } if (!ObjectUtilities.equal(this.valueFont, that.valueFont)) { return false; } if (!PaintUtilities.equal(this.valuePaint, that.valuePaint)) { return false; } if (!PaintUtilities.equal(this.tickPaint, that.tickPaint)) { return false; } if (this.tickSize != that.tickSize) { return false; } if (this.tickLabelsVisible != that.tickLabelsVisible) { return false; } if (!ObjectUtilities.equal(this.tickLabelFont, that.tickLabelFont)) { return false; } if (!PaintUtilities.equal(this.tickLabelPaint, that.tickLabelPaint)) { return false; } if (!ObjectUtilities.equal(this.tickLabelFormat, that.tickLabelFormat)) { return false; } if (this.drawBorder != that.drawBorder) { return false; } if (this.meterAngle != that.meterAngle) { return false; } return true; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.dialBackgroundPaint, stream); SerialUtilities.writePaint(this.dialOutlinePaint, stream); SerialUtilities.writePaint(this.needlePaint, stream); SerialUtilities.writePaint(this.valuePaint, stream); SerialUtilities.writePaint(this.tickPaint, stream); SerialUtilities.writePaint(this.tickLabelPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.dialBackgroundPaint = SerialUtilities.readPaint(stream); this.dialOutlinePaint = SerialUtilities.readPaint(stream); this.needlePaint = SerialUtilities.readPaint(stream); this.valuePaint = SerialUtilities.readPaint(stream); this.tickPaint = SerialUtilities.readPaint(stream); this.tickLabelPaint = SerialUtilities.readPaint(stream); if (this.dataset != null) { this.dataset.addChangeListener(this); } } /** * Returns an independent copy (clone) of the plot. The dataset is NOT * cloned - both the original and the clone will have a reference to the * same dataset. * * @return A clone. * * @throws CloneNotSupportedException if some component of the plot cannot * be cloned. */ @Override public Object clone() throws CloneNotSupportedException { MeterPlot clone = (MeterPlot) super.clone(); clone.tickLabelFormat = (NumberFormat) this.tickLabelFormat.clone(); // the following relies on the fact that the intervals are immutable clone.intervals = new java.util.ArrayList<MeterInterval>(this.intervals); if (clone.dataset != null) { clone.dataset.addChangeListener(clone); } return clone; } }
43,482
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ThermometerPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/ThermometerPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * ThermometerPlot.java * -------------------- * * (C) Copyright 2000-2014, by Bryan Scott and Contributors. * * Original Author: Bryan Scott (based on MeterPlot by Hari). * Contributor(s): David Gilbert (for Object Refinery Limited). * Arnaud Lelievre; * Julien Henry (see patch 1769088) (DG); * * Changes * ------- * 11-Apr-2002 : Version 1, contributed by Bryan Scott; * 15-Apr-2002 : Changed to implement VerticalValuePlot; * 29-Apr-2002 : Added getVerticalValueAxis() method (DG); * 25-Jun-2002 : Removed redundant imports (DG); * 17-Sep-2002 : Reviewed with Checkstyle utility (DG); * 18-Sep-2002 : Extensive changes made to API, to iron out bugs and * inconsistencies (DG); * 13-Oct-2002 : Corrected error datasetChanged which would generate exceptions * when value set to null (BRS). * 23-Jan-2003 : Removed one constructor (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 02-Jun-2003 : Removed test for compatible range axis (DG); * 01-Jul-2003 : Added additional check in draw method to ensure value not * null (BRS); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 29-Sep-2003 : Updated draw to set value of cursor to non-zero and allow * painting of axis. An incomplete fix and needs to be set for * left or right drawing (BRS); * 19-Nov-2003 : Added support for value labels to be displayed left of the * thermometer * 19-Nov-2003 : Improved axis drawing (now default axis does not draw axis line * and is closer to the bulb). Added support for the positioning * of the axis to the left or right of the bulb. (BRS); * 03-Dec-2003 : Directly mapped deprecated setData()/getData() method to * get/setDataset() (TM); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 07-Apr-2004 : Changed string width calculation (DG); * 12-Nov-2004 : Implemented the new Zoomable interface (DG); * 06-Jan-2004 : Added getOrientation() method (DG); * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); * 29-Mar-2005 : Fixed equals() method (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 09-Jun-2005 : Fixed more bugs in equals() method (DG); * 10-Jun-2005 : Fixed minor bug in setDisplayRange() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 14-Nov-2006 : Fixed margin when drawing (DG); * 03-May-2007 : Fixed datasetChanged() to handle null dataset, added null * argument check and event notification to setRangeAxis(), * added null argument check to setPadding(), setValueFont(), * setValuePaint(), setValueFormat() and setMercuryPaint(), * deprecated get/setShowValueLines(), deprecated * getMinimum/MaximumVerticalDataValue(), and fixed serialization * bug (DG); * 24-Sep-2007 : Implemented new methods in Zoomable interface (DG); * 08-Oct-2007 : Added attributes for thermometer dimensions - see patch 1769088 * by Julien Henry (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Stroke; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.UnitType; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.Range; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DefaultValueDataset; import org.jfree.data.general.ValueDataset; /** * A plot that displays a single value (from a {@link ValueDataset}) in a * thermometer type display. * <p> * This plot supports a number of options: * <ol> * <li>three sub-ranges which could be viewed as 'Normal', 'Warning' * and 'Critical' ranges.</li> * <li>the thermometer can be run in two modes: * <ul> * <li>fixed range, or</li> * <li>range adjusts to current sub-range.</li> * </ul> * </li> * <li>settable units to be displayed.</li> * <li>settable display location for the value text.</li> * </ol> */ public class ThermometerPlot extends Plot implements ValueAxisPlot, Zoomable, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 4087093313147984390L; /** A constant for unit type 'None'. */ public static final int UNITS_NONE = 0; /** A constant for unit type 'Fahrenheit'. */ public static final int UNITS_FAHRENHEIT = 1; /** A constant for unit type 'Celcius'. */ public static final int UNITS_CELCIUS = 2; /** A constant for unit type 'Kelvin'. */ public static final int UNITS_KELVIN = 3; /** A constant for the value label position (no label). */ public static final int NONE = 0; /** A constant for the value label position (right of the thermometer). */ public static final int RIGHT = 1; /** A constant for the value label position (left of the thermometer). */ public static final int LEFT = 2; /** A constant for the value label position (in the thermometer bulb). */ public static final int BULB = 3; /** A constant for the 'normal' range. */ public static final int NORMAL = 0; /** A constant for the 'warning' range. */ public static final int WARNING = 1; /** A constant for the 'critical' range. */ public static final int CRITICAL = 2; /** The axis gap. */ protected static final int AXIS_GAP = 10; /** The unit strings. */ protected static final String[] UNITS = {"", "\u00B0F", "\u00B0C", "\u00B0K"}; /** Index for low value in subrangeInfo matrix. */ protected static final int RANGE_LOW = 0; /** Index for high value in subrangeInfo matrix. */ protected static final int RANGE_HIGH = 1; /** Index for display low value in subrangeInfo matrix. */ protected static final int DISPLAY_LOW = 2; /** Index for display high value in subrangeInfo matrix. */ protected static final int DISPLAY_HIGH = 3; /** The default lower bound. */ protected static final double DEFAULT_LOWER_BOUND = 0.0; /** The default upper bound. */ protected static final double DEFAULT_UPPER_BOUND = 100.0; /** * The default bulb radius. * * @since 1.0.7 */ protected static final int DEFAULT_BULB_RADIUS = 40; /** * The default column radius. * * @since 1.0.7 */ protected static final int DEFAULT_COLUMN_RADIUS = 20; /** * The default gap between the outlines representing the thermometer. * * @since 1.0.7 */ protected static final int DEFAULT_GAP = 5; /** The dataset for the plot. */ private ValueDataset dataset; /** The range axis. */ private ValueAxis rangeAxis; /** The lower bound for the thermometer. */ private double lowerBound = DEFAULT_LOWER_BOUND; /** The upper bound for the thermometer. */ private double upperBound = DEFAULT_UPPER_BOUND; /** * The value label position. * * @since 1.0.7 */ private int bulbRadius = DEFAULT_BULB_RADIUS; /** * The column radius. * * @since 1.0.7 */ private int columnRadius = DEFAULT_COLUMN_RADIUS; /** * The gap between the two outlines the represent the thermometer. * * @since 1.0.7 */ private int gap = DEFAULT_GAP; /** * Blank space inside the plot area around the outside of the thermometer. */ private RectangleInsets padding; /** Stroke for drawing the thermometer */ private transient Stroke thermometerStroke = new BasicStroke(1.0f); /** Paint for drawing the thermometer */ private transient Paint thermometerPaint = Color.BLACK; /** The display units */ private int units = UNITS_CELCIUS; /** The value label position. */ private int valueLocation = BULB; /** The position of the axis **/ private int axisLocation = LEFT; /** The font to write the value in */ private Font valueFont = new Font("SansSerif", Font.BOLD, 16); /** Colour that the value is written in */ private transient Paint valuePaint = Color.WHITE; /** Number format for the value */ private NumberFormat valueFormat = new DecimalFormat(); /** The default paint for the mercury in the thermometer. */ private transient Paint mercuryPaint = Color.LIGHT_GRAY; /** A flag that controls whether value lines are drawn. */ private boolean showValueLines = false; /** The display sub-range. */ private int subrange = -1; /** The start and end values for the subranges. */ private double[][] subrangeInfo = { {0.0, 50.0, 0.0, 50.0}, {50.0, 75.0, 50.0, 75.0}, {75.0, 100.0, 75.0, 100.0} }; /** * A flag that controls whether or not the axis range adjusts to the * sub-ranges. */ private boolean followDataInSubranges = false; /** * A flag that controls whether or not the mercury paint changes with * the subranges. */ private boolean useSubrangePaint = true; /** Paint for each range */ private transient Paint[] subrangePaint = {Color.GREEN, Color.ORANGE, Color.RED}; /** A flag that controls whether the sub-range indicators are visible. */ private boolean subrangeIndicatorsVisible = true; /** The stroke for the sub-range indicators. */ private transient Stroke subrangeIndicatorStroke = new BasicStroke(2.0f); /** The range indicator stroke. */ private transient Stroke rangeIndicatorStroke = new BasicStroke(3.0f); /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** * Creates a new thermometer plot. */ public ThermometerPlot() { this(new DefaultValueDataset()); } /** * Creates a new thermometer plot, using default attributes where necessary. * * @param dataset the data set. */ public ThermometerPlot(ValueDataset dataset) { super(); this.padding = new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05, 0.05); this.dataset = dataset; if (dataset != null) { dataset.addChangeListener(this); } NumberAxis axis = new NumberAxis(null); axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); axis.setAxisLineVisible(false); axis.setPlot(this); axis.addChangeListener(this); this.rangeAxis = axis; setAxisRange(); } /** * Returns the dataset for the plot. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(ValueDataset) */ public ValueDataset getDataset() { return this.dataset; } /** * Sets the dataset for the plot, replacing the existing dataset if there * is one, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() */ public void setDataset(ValueDataset dataset) { // if there is an existing dataset, remove the plot from the list // of change listeners... ValueDataset existing = this.dataset; if (existing != null) { existing.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns the range axis. * * @return The range axis (never <code>null</code>). * * @see #setRangeAxis(ValueAxis) */ public ValueAxis getRangeAxis() { return this.rangeAxis; } /** * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param axis the new axis (<code>null</code> not permitted). * * @see #getRangeAxis() */ public void setRangeAxis(ValueAxis axis) { if (axis == null) { throw new IllegalArgumentException("Null 'axis' argument."); } // plot is registered as a listener with the existing axis... this.rangeAxis.removeChangeListener(this); axis.setPlot(this); axis.addChangeListener(this); this.rangeAxis = axis; fireChangeEvent(); } /** * Returns the lower bound for the thermometer. The data value can be set * lower than this, but it will not be shown in the thermometer. * * @return The lower bound. * * @see #setLowerBound(double) */ public double getLowerBound() { return this.lowerBound; } /** * Sets the lower bound for the thermometer. * * @param lower the lower bound. * * @see #getLowerBound() */ public void setLowerBound(double lower) { this.lowerBound = lower; setAxisRange(); } /** * Returns the upper bound for the thermometer. The data value can be set * higher than this, but it will not be shown in the thermometer. * * @return The upper bound. * * @see #setUpperBound(double) */ public double getUpperBound() { return this.upperBound; } /** * Sets the upper bound for the thermometer. * * @param upper the upper bound. * * @see #getUpperBound() */ public void setUpperBound(double upper) { this.upperBound = upper; setAxisRange(); } /** * Sets the lower and upper bounds for the thermometer. * * @param lower the lower bound. * @param upper the upper bound. */ public void setRange(double lower, double upper) { this.lowerBound = lower; this.upperBound = upper; setAxisRange(); } /** * Returns the padding for the thermometer. This is the space inside the * plot area. * * @return The padding (never <code>null</code>). * * @see #setPadding(RectangleInsets) */ public RectangleInsets getPadding() { return this.padding; } /** * Sets the padding for the thermometer and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param padding the padding (<code>null</code> not permitted). * * @see #getPadding() */ public void setPadding(RectangleInsets padding) { if (padding == null) { throw new IllegalArgumentException("Null 'padding' argument."); } this.padding = padding; fireChangeEvent(); } /** * Returns the stroke used to draw the thermometer outline. * * @return The stroke (never <code>null</code>). * * @see #setThermometerStroke(Stroke) * @see #getThermometerPaint() */ public Stroke getThermometerStroke() { return this.thermometerStroke; } /** * Sets the stroke used to draw the thermometer outline and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param s the new stroke (<code>null</code> ignored). * * @see #getThermometerStroke() */ public void setThermometerStroke(Stroke s) { if (s != null) { this.thermometerStroke = s; fireChangeEvent(); } } /** * Returns the paint used to draw the thermometer outline. * * @return The paint (never <code>null</code>). * * @see #setThermometerPaint(Paint) * @see #getThermometerStroke() */ public Paint getThermometerPaint() { return this.thermometerPaint; } /** * Sets the paint used to draw the thermometer outline and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the new paint (<code>null</code> ignored). * * @see #getThermometerPaint() */ public void setThermometerPaint(Paint paint) { if (paint != null) { this.thermometerPaint = paint; fireChangeEvent(); } } /** * Returns a code indicating the unit display type. This is one of * {@link #UNITS_NONE}, {@link #UNITS_FAHRENHEIT}, {@link #UNITS_CELCIUS} * and {@link #UNITS_KELVIN}. * * @return The units type. * * @see #setUnits(int) */ public int getUnits() { return this.units; } /** * Sets the units to be displayed in the thermometer. Use one of the * following constants: * * <ul> * <li>UNITS_NONE : no units displayed.</li> * <li>UNITS_FAHRENHEIT : units displayed in Fahrenheit.</li> * <li>UNITS_CELCIUS : units displayed in Celcius.</li> * <li>UNITS_KELVIN : units displayed in Kelvin.</li> * </ul> * * @param u the new unit type. * * @see #getUnits() */ public void setUnits(int u) { if ((u >= 0) && (u < UNITS.length)) { if (this.units != u) { this.units = u; fireChangeEvent(); } } } /** * Returns a code indicating the location at which the value label is * displayed. * * @return The location (one of {@link #NONE}, {@link #RIGHT}, * {@link #LEFT} and {@link #BULB}.). */ public int getValueLocation() { return this.valueLocation; } /** * Sets the location at which the current value is displayed and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * The location can be one of the constants: * <code>NONE</code>, * <code>RIGHT</code> * <code>LEFT</code> and * <code>BULB</code>. * * @param location the location. */ public void setValueLocation(int location) { if ((location >= 0) && (location < 4)) { this.valueLocation = location; fireChangeEvent(); } else { throw new IllegalArgumentException("Location not recognised."); } } /** * Returns the axis location. * * @return The location (one of {@link #NONE}, {@link #LEFT} and * {@link #RIGHT}). * * @see #setAxisLocation(int) */ public int getAxisLocation() { return this.axisLocation; } /** * Sets the location at which the axis is displayed relative to the * thermometer, and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param location the location (one of {@link #NONE}, {@link #LEFT} and * {@link #RIGHT}). * * @see #getAxisLocation() */ public void setAxisLocation(int location) { if ((location >= 0) && (location < 3)) { this.axisLocation = location; fireChangeEvent(); } else { throw new IllegalArgumentException("Location not recognised."); } } /** * Gets the font used to display the current value. * * @return The font. * * @see #setValueFont(Font) */ public Font getValueFont() { return this.valueFont; } /** * Sets the font used to display the current value. * * @param f the new font (<code>null</code> not permitted). * * @see #getValueFont() */ public void setValueFont(Font f) { if (f == null) { throw new IllegalArgumentException("Null 'font' argument."); } if (!this.valueFont.equals(f)) { this.valueFont = f; fireChangeEvent(); } } /** * Gets the paint used to display the current value. * * @return The paint. * * @see #setValuePaint(Paint) */ public Paint getValuePaint() { return this.valuePaint; } /** * Sets the paint used to display the current value and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the new paint (<code>null</code> not permitted). * * @see #getValuePaint() */ public void setValuePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } if (!this.valuePaint.equals(paint)) { this.valuePaint = paint; fireChangeEvent(); } } // FIXME: No getValueFormat() method? /** * Sets the formatter for the value label and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param formatter the new formatter (<code>null</code> not permitted). */ public void setValueFormat(NumberFormat formatter) { if (formatter == null) { throw new IllegalArgumentException("Null 'formatter' argument."); } this.valueFormat = formatter; fireChangeEvent(); } /** * Returns the default mercury paint. * * @return The paint (never <code>null</code>). * * @see #setMercuryPaint(Paint) */ public Paint getMercuryPaint() { return this.mercuryPaint; } /** * Sets the default mercury paint and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param paint the new paint (<code>null</code> not permitted). * * @see #getMercuryPaint() */ public void setMercuryPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.mercuryPaint = paint; fireChangeEvent(); } /** * Sets information for a particular range. * * @param range the range to specify information about. * @param low the low value for the range * @param hi the high value for the range */ public void setSubrangeInfo(int range, double low, double hi) { setSubrangeInfo(range, low, hi, low, hi); } /** * Sets the subrangeInfo attribute of the ThermometerPlot object * * @param range the new rangeInfo value. * @param rangeLow the new rangeInfo value * @param rangeHigh the new rangeInfo value * @param displayLow the new rangeInfo value * @param displayHigh the new rangeInfo value */ public void setSubrangeInfo(int range, double rangeLow, double rangeHigh, double displayLow, double displayHigh) { if ((range >= 0) && (range < 3)) { setSubrange(range, rangeLow, rangeHigh); setDisplayRange(range, displayLow, displayHigh); setAxisRange(); fireChangeEvent(); } } /** * Sets the bounds for a subrange. * * @param range the range type. * @param low the low value. * @param high the high value. */ public void setSubrange(int range, double low, double high) { if ((range >= 0) && (range < 3)) { this.subrangeInfo[range][RANGE_HIGH] = high; this.subrangeInfo[range][RANGE_LOW] = low; } } /** * Sets the displayed bounds for a sub range. * * @param range the range type. * @param low the low value. * @param high the high value. */ public void setDisplayRange(int range, double low, double high) { if ((range >= 0) && (range < this.subrangeInfo.length) && isValidNumber(high) && isValidNumber(low)) { if (high > low) { this.subrangeInfo[range][DISPLAY_HIGH] = high; this.subrangeInfo[range][DISPLAY_LOW] = low; } else { this.subrangeInfo[range][DISPLAY_HIGH] = low; this.subrangeInfo[range][DISPLAY_LOW] = high; } } } /** * Gets the paint used for a particular subrange. * * @param range the range (. * * @return The paint. * * @see #setSubrangePaint(int, Paint) */ public Paint getSubrangePaint(int range) { if ((range >= 0) && (range < this.subrangePaint.length)) { return this.subrangePaint[range]; } else { return this.mercuryPaint; } } /** * Sets the paint to be used for a subrange and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param range the range (0, 1 or 2). * @param paint the paint to be applied (<code>null</code> not permitted). * * @see #getSubrangePaint(int) */ public void setSubrangePaint(int range, Paint paint) { if ((range >= 0) && (range < this.subrangePaint.length) && (paint != null)) { this.subrangePaint[range] = paint; fireChangeEvent(); } } /** * Returns a flag that controls whether or not the thermometer axis zooms * to display the subrange within which the data value falls. * * @return The flag. */ public boolean getFollowDataInSubranges() { return this.followDataInSubranges; } /** * Sets the flag that controls whether or not the thermometer axis zooms * to display the subrange within which the data value falls. * * @param flag the flag. */ public void setFollowDataInSubranges(boolean flag) { this.followDataInSubranges = flag; fireChangeEvent(); } /** * Returns a flag that controls whether or not the mercury color changes * for each subrange. * * @return The flag. * * @see #setUseSubrangePaint(boolean) */ public boolean getUseSubrangePaint() { return this.useSubrangePaint; } /** * Sets the range colour change option. * * @param flag the new range colour change option * * @see #getUseSubrangePaint() */ public void setUseSubrangePaint(boolean flag) { this.useSubrangePaint = flag; fireChangeEvent(); } /** * Returns the bulb radius, in Java2D units. * @return The bulb radius. * * @since 1.0.7 */ public int getBulbRadius() { return this.bulbRadius; } /** * Sets the bulb radius (in Java2D units) and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param r the new radius (in Java2D units). * * @see #getBulbRadius() * * @since 1.0.7 */ public void setBulbRadius(int r) { this.bulbRadius = r; fireChangeEvent(); } /** * Returns the bulb diameter, which is always twice the value returned * by {@link #getBulbRadius()}. * * @return The bulb diameter. * * @since 1.0.7 */ public int getBulbDiameter() { return getBulbRadius() * 2; } /** * Returns the column radius, in Java2D units. * * @return The column radius. * * @see #setColumnRadius(int) * * @since 1.0.7 */ public int getColumnRadius() { return this.columnRadius; } /** * Sets the column radius (in Java2D units) and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param r the new radius. * * @see #getColumnRadius() * * @since 1.0.7 */ public void setColumnRadius(int r) { this.columnRadius = r; fireChangeEvent(); } /** * Returns the column diameter, which is always twice the value returned * by {@link #getColumnRadius()}. * * @return The column diameter. * * @since 1.0.7 */ public int getColumnDiameter() { return getColumnRadius() * 2; } /** * Returns the gap, in Java2D units, between the two outlines that * represent the thermometer. * * @return The gap. * * @see #setGap(int) * * @since 1.0.7 */ public int getGap() { return this.gap; } /** * Sets the gap (in Java2D units) between the two outlines that represent * the thermometer, and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param gap the new gap. * * @see #getGap() * * @since 1.0.7 */ public void setGap(int gap) { this.gap = gap; fireChangeEvent(); } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { RoundRectangle2D outerStem = new RoundRectangle2D.Double(); RoundRectangle2D innerStem = new RoundRectangle2D.Double(); RoundRectangle2D mercuryStem = new RoundRectangle2D.Double(); Ellipse2D outerBulb = new Ellipse2D.Double(); Ellipse2D innerBulb = new Ellipse2D.Double(); String temp = null; FontMetrics metrics = null; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); // adjust for padding... Rectangle2D interior = (Rectangle2D) area.clone(); this.padding.trim(interior); int midX = (int) (interior.getX() + (interior.getWidth() / 2)); int midY = (int) (interior.getY() + (interior.getHeight() / 2)); int stemTop = (int) (interior.getMinY() + getBulbRadius()); int stemBottom = (int) (interior.getMaxY() - getBulbDiameter()); Rectangle2D dataArea = new Rectangle2D.Double(midX - getColumnRadius(), stemTop, getColumnRadius(), stemBottom - stemTop); outerBulb.setFrame(midX - getBulbRadius(), stemBottom, getBulbDiameter(), getBulbDiameter()); outerStem.setRoundRect(midX - getColumnRadius(), interior.getMinY(), getColumnDiameter(), stemBottom + getBulbDiameter() - stemTop, getColumnDiameter(), getColumnDiameter()); Area outerThermometer = new Area(outerBulb); Area tempArea = new Area(outerStem); outerThermometer.add(tempArea); innerBulb.setFrame(midX - getBulbRadius() + getGap(), stemBottom + getGap(), getBulbDiameter() - getGap() * 2, getBulbDiameter() - getGap() * 2); innerStem.setRoundRect(midX - getColumnRadius() + getGap(), interior.getMinY() + getGap(), getColumnDiameter() - getGap() * 2, stemBottom + getBulbDiameter() - getGap() * 2 - stemTop, getColumnDiameter() - getGap() * 2, getColumnDiameter() - getGap() * 2); Area innerThermometer = new Area(innerBulb); tempArea = new Area(innerStem); innerThermometer.add(tempArea); if ((this.dataset != null) && (this.dataset.getValue() != null)) { double current = this.dataset.getValue().doubleValue(); double ds = this.rangeAxis.valueToJava2D(current, dataArea, RectangleEdge.LEFT); int i = getColumnDiameter() - getGap() * 2; // already calculated int j = getColumnRadius() - getGap(); // already calculated int l = (i / 2); int k = (int) Math.round(ds); if (k < (getGap() + interior.getMinY())) { k = (int) (getGap() + interior.getMinY()); l = getBulbRadius(); } Area mercury = new Area(innerBulb); if (k < (stemBottom + getBulbRadius())) { mercuryStem.setRoundRect(midX - j, k, i, (stemBottom + getBulbRadius()) - k, l, l); tempArea = new Area(mercuryStem); mercury.add(tempArea); } g2.setPaint(getCurrentPaint()); g2.fill(mercury); // draw range indicators... if (this.subrangeIndicatorsVisible) { g2.setStroke(this.subrangeIndicatorStroke); Range range = this.rangeAxis.getRange(); // draw start of normal range double value = this.subrangeInfo[NORMAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[NORMAL]); g2.draw(line); } // draw start of warning range value = this.subrangeInfo[WARNING][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[WARNING]); g2.draw(line); } // draw start of critical range value = this.subrangeInfo[CRITICAL][RANGE_LOW]; if (range.contains(value)) { double x = midX + getColumnRadius() + 2; double y = this.rangeAxis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(x, y, x + 10, y); g2.setPaint(this.subrangePaint[CRITICAL]); g2.draw(line); } } // draw the axis... if ((this.rangeAxis != null) && (this.axisLocation != NONE)) { int drawWidth = AXIS_GAP; if (this.showValueLines) { drawWidth += getColumnDiameter(); } Rectangle2D drawArea; double cursor = 0; switch (this.axisLocation) { case RIGHT: cursor = midX + getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.RIGHT, null); break; case LEFT: default: //cursor = midX - COLUMN_RADIUS - AXIS_GAP; cursor = midX - getColumnRadius(); drawArea = new Rectangle2D.Double(cursor, stemTop, drawWidth, (stemBottom - stemTop + 1)); this.rangeAxis.draw(g2, cursor, area, drawArea, RectangleEdge.LEFT, null); break; } } // draw text value on screen g2.setFont(this.valueFont); g2.setPaint(this.valuePaint); metrics = g2.getFontMetrics(); switch (this.valueLocation) { case RIGHT: g2.drawString(this.valueFormat.format(current), midX + getColumnRadius() + getGap(), midY); break; case LEFT: String valueString = this.valueFormat.format(current); int stringWidth = metrics.stringWidth(valueString); g2.drawString(valueString, midX - getColumnRadius() - getGap() - stringWidth, midY); break; case BULB: temp = this.valueFormat.format(current); i = metrics.stringWidth(temp) / 2; g2.drawString(temp, midX - i, stemBottom + getBulbRadius() + getGap()); break; default: } /***/ } g2.setPaint(this.thermometerPaint); g2.setFont(this.valueFont); // draw units indicator metrics = g2.getFontMetrics(); int tickX1 = midX - getColumnRadius() - getGap() * 2 - metrics.stringWidth(UNITS[this.units]); if (tickX1 > area.getMinX()) { g2.drawString(UNITS[this.units], tickX1, (int) (area.getMinY() + 20)); } // draw thermometer outline g2.setStroke(this.thermometerStroke); g2.draw(outerThermometer); g2.draw(innerThermometer); drawOutline(g2, area); } /** * A zoom method that does nothing. Plots are required to support the * zoom operation. In the case of a thermometer chart, it doesn't make * sense to zoom in or out, so the method is empty. * * @param percent the zoom percentage. */ @Override public void zoom(double percent) { // intentionally blank } /** * Returns a short string describing the type of plot. * * @return A short string describing the type of plot. */ @Override public String getPlotType() { return localizationResources.getString("Thermometer_Plot"); } /** * Checks to see if a new value means the axis range needs adjusting. * * @param event the dataset change event. */ @Override public void datasetChanged(DatasetChangeEvent event) { if (this.dataset != null) { Number vn = this.dataset.getValue(); if (vn != null) { double value = vn.doubleValue(); if (inSubrange(NORMAL, value)) { this.subrange = NORMAL; } else if (inSubrange(WARNING, value)) { this.subrange = WARNING; } else if (inSubrange(CRITICAL, value)) { this.subrange = CRITICAL; } else { this.subrange = -1; } setAxisRange(); } } super.datasetChanged(event); } /** * Returns the data range. * * @param axis the axis. * * @return The range of data displayed. */ @Override public Range getDataRange(ValueAxis axis) { return new Range(this.lowerBound, this.upperBound); } /** * Sets the axis range to the current values in the rangeInfo array. */ protected void setAxisRange() { if ((this.subrange >= 0) && (this.followDataInSubranges)) { this.rangeAxis.setRange( new Range(this.subrangeInfo[this.subrange][DISPLAY_LOW], this.subrangeInfo[this.subrange][DISPLAY_HIGH])); } else { this.rangeAxis.setRange(this.lowerBound, this.upperBound); } } /** * Returns the legend items for the plot. In this case, the method * returns an empty list because the plot has no legend. * * @return An empty list. */ @Override public List<LegendItem> getLegendItems() { return new ArrayList<LegendItem>(0); } /** * Returns the orientation of the plot. * * @return The orientation (always {@link PlotOrientation#VERTICAL}). */ @Override public PlotOrientation getOrientation() { return PlotOrientation.VERTICAL; } /** * Determine whether a number is valid and finite. * * @param d the number to be tested. * * @return <code>true</code> if the number is valid and finite, and * <code>false</code> otherwise. */ protected static boolean isValidNumber(double d) { return (!(Double.isNaN(d) || Double.isInfinite(d))); } /** * Returns true if the value is in the specified range, and false otherwise. * * @param subrange the subrange. * @param value the value to check. * * @return A boolean. */ private boolean inSubrange(int subrange, double value) { return (value > this.subrangeInfo[subrange][RANGE_LOW] && value <= this.subrangeInfo[subrange][RANGE_HIGH]); } /** * Returns the mercury paint corresponding to the current data value. * Called from the {@link #draw(Graphics2D, Rectangle2D, Point2D, * PlotState, PlotRenderingInfo)} method. * * @return The paint (never <code>null</code>). */ private Paint getCurrentPaint() { Paint result = this.mercuryPaint; if (this.useSubrangePaint) { double value = this.dataset.getValue().doubleValue(); if (inSubrange(NORMAL, value)) { result = this.subrangePaint[NORMAL]; } else if (inSubrange(WARNING, value)) { result = this.subrangePaint[WARNING]; } else if (inSubrange(CRITICAL, value)) { result = this.subrangePaint[CRITICAL]; } } return result; } /** * Tests this plot for equality with another object. The plot's dataset * is not considered in the test. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ThermometerPlot)) { return false; } ThermometerPlot that = (ThermometerPlot) obj; if (!super.equals(obj)) { return false; } if (!ObjectUtilities.equal(this.rangeAxis, that.rangeAxis)) { return false; } if (this.axisLocation != that.axisLocation) { return false; } if (this.lowerBound != that.lowerBound) { return false; } if (this.upperBound != that.upperBound) { return false; } if (!ObjectUtilities.equal(this.padding, that.padding)) { return false; } if (!ObjectUtilities.equal(this.thermometerStroke, that.thermometerStroke)) { return false; } if (!PaintUtilities.equal(this.thermometerPaint, that.thermometerPaint)) { return false; } if (this.units != that.units) { return false; } if (this.valueLocation != that.valueLocation) { return false; } if (!ObjectUtilities.equal(this.valueFont, that.valueFont)) { return false; } if (!PaintUtilities.equal(this.valuePaint, that.valuePaint)) { return false; } if (!ObjectUtilities.equal(this.valueFormat, that.valueFormat)) { return false; } if (!PaintUtilities.equal(this.mercuryPaint, that.mercuryPaint)) { return false; } if (this.showValueLines != that.showValueLines) { return false; } if (this.subrange != that.subrange) { return false; } if (this.followDataInSubranges != that.followDataInSubranges) { return false; } if (!equal(this.subrangeInfo, that.subrangeInfo)) { return false; } if (this.useSubrangePaint != that.useSubrangePaint) { return false; } if (this.bulbRadius != that.bulbRadius) { return false; } if (this.columnRadius != that.columnRadius) { return false; } if (this.gap != that.gap) { return false; } for (int i = 0; i < this.subrangePaint.length; i++) { if (!PaintUtilities.equal(this.subrangePaint[i], that.subrangePaint[i])) { return false; } } return true; } /** * Tests two double[][] arrays for equality. * * @param array1 the first array (<code>null</code> permitted). * @param array2 the second arrray (<code>null</code> permitted). * * @return A boolean. */ private static boolean equal(double[][] array1, double[][] array2) { if (array1 == null) { return (array2 == null); } if (array2 == null) { return false; } if (array1.length != array2.length) { return false; } for (int i = 0; i < array1.length; i++) { if (!Arrays.equals(array1[i], array2[i])) { return false; } } return true; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException if the plot cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { ThermometerPlot clone = (ThermometerPlot) super.clone(); if (clone.dataset != null) { clone.dataset.addChangeListener(clone); } clone.rangeAxis = ObjectUtilities.clone(this.rangeAxis); if (clone.rangeAxis != null) { clone.rangeAxis.setPlot(clone); clone.rangeAxis.addChangeListener(clone); } clone.valueFormat = (NumberFormat) this.valueFormat.clone(); clone.subrangePaint = this.subrangePaint.clone(); return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.thermometerStroke, stream); SerialUtilities.writePaint(this.thermometerPaint, stream); SerialUtilities.writePaint(this.valuePaint, stream); SerialUtilities.writePaint(this.mercuryPaint, stream); SerialUtilities.writeStroke(this.subrangeIndicatorStroke, stream); SerialUtilities.writeStroke(this.rangeIndicatorStroke, stream); for (int i = 0; i < 3; i++) { SerialUtilities.writePaint(this.subrangePaint[i], stream); } } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.thermometerStroke = SerialUtilities.readStroke(stream); this.thermometerPaint = SerialUtilities.readPaint(stream); this.valuePaint = SerialUtilities.readPaint(stream); this.mercuryPaint = SerialUtilities.readPaint(stream); this.subrangeIndicatorStroke = SerialUtilities.readStroke(stream); this.rangeIndicatorStroke = SerialUtilities.readStroke(stream); this.subrangePaint = new Paint[3]; for (int i = 0; i < 3; i++) { this.subrangePaint[i] = SerialUtilities.readPaint(stream); } if (this.rangeAxis != null) { this.rangeAxis.addChangeListener(this); } } /** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point. */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source) { // no domain axis to zoom } /** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point. * @param useAnchor a flag that controls whether or not the source point * is used for the zoom anchor. * * @since 1.0.7 */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor) { // no domain axis to zoom } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point. */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source) { this.rangeAxis.resizeRange(factor); } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point. * @param useAnchor a flag that controls whether or not the source point * is used for the zoom anchor. * * @since 1.0.7 */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor) { double anchorY = this.getRangeAxis().java2DToValue(source.getY(), state.getDataArea(), RectangleEdge.LEFT); this.rangeAxis.resizeRange(factor, anchorY); } /** * This method does nothing. * * @param lowerPercent the lower percent. * @param upperPercent the upper percent. * @param state the plot state. * @param source the source point. */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source) { // no domain axis to zoom } /** * Zooms the range axes. * * @param lowerPercent the lower percent. * @param upperPercent the upper percent. * @param state the plot state. * @param source the source point. */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source) { this.rangeAxis.zoomRange(lowerPercent, upperPercent); } /** * Returns <code>false</code>. * * @return A boolean. */ @Override public boolean isDomainZoomable() { return false; } /** * Returns <code>true</code>. * * @return A boolean. */ @Override public boolean isRangeZoomable() { return true; } }
54,121
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieLabelLinkStyle.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PieLabelLinkStyle.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * PieLabelLinkStyle.java * ---------------------- * (C) Copyright 2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 31-Mar-2008 : Version 1 (DG); * */ package org.jfree.chart.plot; /** * Used to indicate the style for the lines linking pie sections to their * corresponding labels. * * @since 1.0.10 */ public enum PieLabelLinkStyle { /** STANDARD. */ STANDARD("PieLabelLinkStyle.STANDARD"), /** QUAD_CURVE. */ QUAD_CURVE("PieLabelLinkStyle.QUAD_CURVE"), /** CUBIC_CURVE. */ CUBIC_CURVE("PieLabelLinkStyle.CUBIC_CURVE"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private PieLabelLinkStyle(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,299
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/package-info.java
/** * Plot classes and related interfaces. */ package org.jfree.chart.plot;
78
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ValueMarker.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/ValueMarker.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * ValueMarker.java * ---------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 09-Feb-2004 : Version 1 (DG); * 16-Feb-2005 : Added new constructor (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Sep-2006 : Added setValue() method (DG); * 08-Oct-2007 : Fixed bug 1808376, constructor calling super with incorrect * values (DG); * */ package org.jfree.chart.plot; import java.awt.Paint; import java.awt.Stroke; import org.jfree.chart.event.MarkerChangeEvent; /** * A marker that represents a single value. Markers can be added to plots to * highlight specific values. */ public class ValueMarker extends Marker { /** The value. */ private double value; /** * Creates a new marker. * * @param value the value. */ public ValueMarker(double value) { super(); this.value = value; } /** * Creates a new marker. * * @param value the value. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). */ public ValueMarker(double value, Paint paint, Stroke stroke) { this(value, paint, stroke, paint, stroke, 1.0f); } /** * Creates a new value marker. * * @param value the value. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * @param outlinePaint the outline paint (<code>null</code> permitted). * @param outlineStroke the outline stroke (<code>null</code> permitted). * @param alpha the alpha transparency (in the range 0.0f to 1.0f). */ public ValueMarker(double value, Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { super(paint, stroke, outlinePaint, outlineStroke, alpha); this.value = value; } /** * Returns the value. * * @return The value. * * @see #setValue(double) */ public double getValue() { return this.value; } /** * Sets the value for the marker and sends a {@link MarkerChangeEvent} to * all registered listeners. * * @param value the value. * * @see #getValue() * * @since 1.0.3 */ public void setValue(double value) { this.value = value; notifyListeners(new MarkerChangeEvent(this)); } /** * Tests this marker for equality with an arbitrary object. This method * returns <code>true</code> if: * * <ul> * <li><code>obj</code> is not <code>null</code>;</li> * <li><code>obj</code> is an instance of <code>ValueMarker</code>;</li> * <li><code>obj</code> has the same value as this marker;</li> * <li><code>super.equals(obj)</code> returns <code>true</code>.</li> * </ul> * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof ValueMarker)) { return false; } ValueMarker that = (ValueMarker) obj; if (this.value != that.value) { return false; } return true; } }
4,826
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYCrosshairState.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/XYCrosshairState.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * XYCrosshairState.java * --------------------- * (C) Copyright 2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 26-Jun-2008 : Version 1 (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.renderer.xy.XYItemRenderer; /** * Crosshair state information for the {@link XYPlot} and {@link XYItemRenderer} * classes. */ public class XYCrosshairState extends CrosshairState { /** * Creates a new instance. */ public XYCrosshairState() { } }
1,838
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
FastScatterPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/FastScatterPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * FastScatterPlot.java * -------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Arnaud Lelievre; * * Changes * ------- * 29-Oct-2002 : Added standard header (DG); * 07-Nov-2002 : Fixed errors reported by Checkstyle (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 19-Aug-2003 : Implemented Cloneable (DG); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 12-Nov-2003 : Implemented zooming (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 26-Jan-2004 : Added domain and range grid lines (DG); * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG); * 29-Sep-2004 : Removed hard-coded color (DG); * 04-Oct-2004 : Reworked equals() method and renamed ArrayUtils * --> ArrayUtilities (DG); * 12-Nov-2004 : Implemented the new Zoomable interface (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 16-Jun-2005 : Added get/setData() methods (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 10-Nov-2006 : Fixed bug 1593150, by not allowing null axes, and added * setDomainAxis() and setRangeAxis() methods (DG); * 24-Sep-2007 : Implemented new zooming methods (DG); * 25-Mar-2008 : Make use of new fireChangeEvent() method (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 26-Mar-2009 : Implemented Pannable, and fixed bug in zooming (DG); * 15-Jun-2012 : Remove JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.List; import java.util.ResourceBundle; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.axis.ValueTick; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ArrayUtilities; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.Range; /** * A fast scatter plot. */ public class FastScatterPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 7871545897358563521L; /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] {2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.LIGHT_GRAY; /** The data. */ private float[][] data; /** The x data range. */ private Range xDataRange; /** The y data range. */ private Range yDataRange; /** The domain axis (used for the x-values). */ private ValueAxis domainAxis; /** The range axis (used for the y-values). */ private ValueAxis rangeAxis; /** The paint used to plot data points. */ private transient Paint paint; /** A flag that controls whether the domain grid-lines are visible. */ private boolean domainGridlinesVisible; /** The stroke used to draw the domain grid-lines. */ private transient Stroke domainGridlineStroke; /** The paint used to draw the domain grid-lines. */ private transient Paint domainGridlinePaint; /** A flag that controls whether the range grid-lines are visible. */ private boolean rangeGridlinesVisible; /** The stroke used to draw the range grid-lines. */ private transient Stroke rangeGridlineStroke; /** The paint used to draw the range grid-lines. */ private transient Paint rangeGridlinePaint; /** * A flag that controls whether or not panning is enabled for the domain * axis. * * @since 1.0.13 */ private boolean domainPannable; /** * A flag that controls whether or not panning is enabled for the range * axis. * * @since 1.0.13 */ private boolean rangePannable; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** * Creates a new instance of <code>FastScatterPlot</code> with default * axes. */ public FastScatterPlot() { this(null, new NumberAxis("X"), new NumberAxis("Y")); } /** * Creates a new fast scatter plot. * <p> * The data is an array of x, y values: data[0][i] = x, data[1][i] = y. * * @param data the data (<code>null</code> permitted). * @param domainAxis the domain (x) axis (<code>null</code> not permitted). * @param rangeAxis the range (y) axis (<code>null</code> not permitted). */ public FastScatterPlot(float[][] data, ValueAxis domainAxis, ValueAxis rangeAxis) { super(); if (domainAxis == null) { throw new IllegalArgumentException("Null 'domainAxis' argument."); } if (rangeAxis == null) { throw new IllegalArgumentException("Null 'rangeAxis' argument."); } this.data = data; this.xDataRange = calculateXDataRange(data); this.yDataRange = calculateYDataRange(data); this.domainAxis = domainAxis; this.domainAxis.setPlot(this); this.domainAxis.addChangeListener(this); this.rangeAxis = rangeAxis; this.rangeAxis.setPlot(this); this.rangeAxis.addChangeListener(this); this.paint = Color.RED; this.domainGridlinesVisible = true; this.domainGridlinePaint = FastScatterPlot.DEFAULT_GRIDLINE_PAINT; this.domainGridlineStroke = FastScatterPlot.DEFAULT_GRIDLINE_STROKE; this.rangeGridlinesVisible = true; this.rangeGridlinePaint = FastScatterPlot.DEFAULT_GRIDLINE_PAINT; this.rangeGridlineStroke = FastScatterPlot.DEFAULT_GRIDLINE_STROKE; } /** * Returns a short string describing the plot type. * * @return A short string describing the plot type. */ @Override public String getPlotType() { return localizationResources.getString("Fast_Scatter_Plot"); } /** * Returns the data array used by the plot. * * @return The data array (possibly <code>null</code>). * * @see #setData(float[][]) */ public float[][] getData() { return this.data; } /** * Sets the data array used by the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param data the data array (<code>null</code> permitted). * * @see #getData() */ public void setData(float[][] data) { this.data = data; fireChangeEvent(); } /** * Returns the orientation of the plot. * * @return The orientation (always {@link PlotOrientation#VERTICAL}). */ @Override public PlotOrientation getOrientation() { return PlotOrientation.VERTICAL; } /** * Returns the domain axis for the plot. * * @return The domain axis (never <code>null</code>). * * @see #setDomainAxis(ValueAxis) */ public ValueAxis getDomainAxis() { return this.domainAxis; } /** * Sets the domain axis and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param axis the axis (<code>null</code> not permitted). * * @since 1.0.3 * * @see #getDomainAxis() */ public void setDomainAxis(ValueAxis axis) { if (axis == null) { throw new IllegalArgumentException("Null 'axis' argument."); } this.domainAxis = axis; fireChangeEvent(); } /** * Returns the range axis for the plot. * * @return The range axis (never <code>null</code>). * * @see #setRangeAxis(ValueAxis) */ public ValueAxis getRangeAxis() { return this.rangeAxis; } /** * Sets the range axis and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param axis the axis (<code>null</code> not permitted). * * @since 1.0.3 * * @see #getRangeAxis() */ public void setRangeAxis(ValueAxis axis) { if (axis == null) { throw new IllegalArgumentException("Null 'axis' argument."); } this.rangeAxis = axis; fireChangeEvent(); } /** * Returns the paint used to plot data points. The default is * <code>Color.RED</code>. * * @return The paint. * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the color for the data points and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the domain gridlines are visible, and * <code>false</code> otherwise. * * @return <code>true</code> or <code>false</code>. * * @see #setDomainGridlinesVisible(boolean) * @see #setDomainGridlinePaint(Paint) */ public boolean isDomainGridlinesVisible() { return this.domainGridlinesVisible; } /** * Sets the flag that controls whether or not the domain grid-lines are * visible. If the flag value is changed, a {@link PlotChangeEvent} is * sent to all registered listeners. * * @param visible the new value of the flag. * * @see #getDomainGridlinePaint() */ public void setDomainGridlinesVisible(boolean visible) { if (this.domainGridlinesVisible != visible) { this.domainGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the grid-lines (if any) plotted against the * domain axis. * * @return The stroke (never <code>null</code>). * * @see #setDomainGridlineStroke(Stroke) */ public Stroke getDomainGridlineStroke() { return this.domainGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the domain axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getDomainGridlineStroke() */ public void setDomainGridlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.domainGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the grid lines (if any) plotted against the domain * axis. * * @return The paint (never <code>null</code>). * * @see #setDomainGridlinePaint(Paint) */ public Paint getDomainGridlinePaint() { return this.domainGridlinePaint; } /** * Sets the paint for the grid lines plotted against the domain axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getDomainGridlinePaint() */ public void setDomainGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.domainGridlinePaint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the range axis grid is visible, and * <code>false</code> otherwise. * * @return <code>true</code> or <code>false</code>. * * @see #setRangeGridlinesVisible(boolean) */ public boolean isRangeGridlinesVisible() { return this.rangeGridlinesVisible; } /** * Sets the flag that controls whether or not the range axis grid lines are * visible. If the flag value is changed, a {@link PlotChangeEvent} is * sent to all registered listeners. * * @param visible the new value of the flag. * * @see #isRangeGridlinesVisible() */ public void setRangeGridlinesVisible(boolean visible) { if (this.rangeGridlinesVisible != visible) { this.rangeGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the grid lines (if any) plotted against the range * axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeGridlineStroke(Stroke) */ public Stroke getRangeGridlineStroke() { return this.rangeGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> permitted). * * @see #getRangeGridlineStroke() */ public void setRangeGridlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.rangeGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the grid lines (if any) plotted against the range * axis. * * @return The paint (never <code>null</code>). * * @see #setRangeGridlinePaint(Paint) */ public Paint getRangeGridlinePaint() { return this.rangeGridlinePaint; } /** * Sets the paint for the grid lines plotted against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeGridlinePaint() */ public void setRangeGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeGridlinePaint = paint; fireChangeEvent(); } /** * Draws the fast scatter plot on a Java 2D graphics device (such as the * screen or a printer). * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot (ignored). * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = new AxisSpace(); space = this.domainAxis.reserveSpace(g2, this, area, RectangleEdge.BOTTOM, space); space = this.rangeAxis.reserveSpace(g2, this, area, RectangleEdge.LEFT, space); Rectangle2D dataArea = space.shrink(area, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); AxisState domainAxisState = this.domainAxis.draw(g2, dataArea.getMaxY(), area, dataArea, RectangleEdge.BOTTOM, info); AxisState rangeAxisState = this.rangeAxis.draw(g2, dataArea.getMinX(), area, dataArea, RectangleEdge.LEFT, info); drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); render(g2, dataArea, info, null); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); } /** * Draws a representation of the data within the dataArea region. The * <code>info</code> and <code>crosshairState</code> arguments may be * <code>null</code>. * * @param g2 the graphics device. * @param dataArea the region in which the data is to be drawn. * @param info an optional object for collection dimension information. * @param crosshairState collects crosshair information (<code>null</code> * permitted). */ public void render(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, CrosshairState crosshairState) { //long start = System.currentTimeMillis(); //System.out.println("Start: " + start); g2.setPaint(this.paint); // if the axes use a linear scale, you can uncomment the code below and // switch to the alternative transX/transY calculation inside the loop // that follows - it is a little bit faster then. // // int xx = (int) dataArea.getMinX(); // int ww = (int) dataArea.getWidth(); // int yy = (int) dataArea.getMaxY(); // int hh = (int) dataArea.getHeight(); // double domainMin = this.domainAxis.getLowerBound(); // double domainLength = this.domainAxis.getUpperBound() - domainMin; // double rangeMin = this.rangeAxis.getLowerBound(); // double rangeLength = this.rangeAxis.getUpperBound() - rangeMin; if (this.data != null) { for (int i = 0; i < this.data[0].length; i++) { float x = this.data[0][i]; float y = this.data[1][i]; //int transX = (int) (xx + ww * (x - domainMin) / domainLength); //int transY = (int) (yy - hh * (y - rangeMin) / rangeLength); int transX = (int) this.domainAxis.valueToJava2D(x, dataArea, RectangleEdge.BOTTOM); int transY = (int) this.rangeAxis.valueToJava2D(y, dataArea, RectangleEdge.LEFT); g2.fillRect(transX, transY, 1, 1); } } //long finish = System.currentTimeMillis(); //System.out.println("Finish: " + finish); //System.out.println("Time: " + (finish - start)); } /** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // draw the domain grid lines, if the flag says they're visible... if (isDomainGridlinesVisible()) { for (ValueTick tick : ticks) { double v = this.domainAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(v, dataArea.getMinY(), v, dataArea.getMaxY()); g2.setPaint(getDomainGridlinePaint()); g2.setStroke(getDomainGridlineStroke()); g2.draw(line); } } } /** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // draw the range grid lines, if the flag says they're visible... if (isRangeGridlinesVisible()) { for (ValueTick tick : ticks) { double v = this.rangeAxis.valueToJava2D(tick.getValue(), dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), v, dataArea.getMaxX(), v); g2.setPaint(getRangeGridlinePaint()); g2.setStroke(getRangeGridlineStroke()); g2.draw(line); } } } /** * Returns the range of data values to be plotted along the axis, or * <code>null</code> if the specified axis isn't the domain axis or the * range axis for the plot. * * @param axis the axis (<code>null</code> permitted). * * @return The range (possibly <code>null</code>). */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; if (axis == this.domainAxis) { result = this.xDataRange; } else if (axis == this.rangeAxis) { result = this.yDataRange; } return result; } /** * Calculates the X data range. * * @param data the data (<code>null</code> permitted). * * @return The range. */ private Range calculateXDataRange(float[][] data) { Range result = null; if (data != null) { float lowest = Float.POSITIVE_INFINITY; float highest = Float.NEGATIVE_INFINITY; for (int i = 0; i < data[0].length; i++) { float v = data[0][i]; if (v < lowest) { lowest = v; } if (v > highest) { highest = v; } } if (lowest <= highest) { result = new Range(lowest, highest); } } return result; } /** * Calculates the Y data range. * * @param data the data (<code>null</code> permitted). * * @return The range. */ private Range calculateYDataRange(float[][] data) { Range result = null; if (data != null) { float lowest = Float.POSITIVE_INFINITY; float highest = Float.NEGATIVE_INFINITY; for (int i = 0; i < data[0].length; i++) { float v = data[1][i]; if (v < lowest) { lowest = v; } if (v > highest) { highest = v; } } if (lowest <= highest) { result = new Range(lowest, highest); } } return result; } /** * Multiplies the range on the domain axis by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source) { this.domainAxis.resizeRange(factor); } /** * Multiplies the range on the domain axis by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { if (useAnchor) { // get the source coordinate - this plot has always a VERTICAL // orientation double sourceX = source.getX(); double anchorX = this.domainAxis.java2DToValue(sourceX, info.getDataArea(), RectangleEdge.BOTTOM); this.domainAxis.resizeRange2(factor, anchorX); } else { this.domainAxis.resizeRange(factor); } } /** * Zooms in on the domain axes. * * @param lowerPercent the new lower bound as a percentage of the current * range. * @param upperPercent the new upper bound as a percentage of the current * range. * @param info the plot rendering info. * @param source the source point. */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { this.domainAxis.zoomRange(lowerPercent, upperPercent); } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source) { this.rangeAxis.resizeRange(factor); } /** * Multiplies the range on the range axis by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { if (useAnchor) { // get the source coordinate - this plot has always a VERTICAL // orientation double sourceY = source.getY(); double anchorY = this.rangeAxis.java2DToValue(sourceY, info.getDataArea(), RectangleEdge.LEFT); this.rangeAxis.resizeRange2(factor, anchorY); } else { this.rangeAxis.resizeRange(factor); } } /** * Zooms in on the range axes. * * @param lowerPercent the new lower bound as a percentage of the current * range. * @param upperPercent the new upper bound as a percentage of the current * range. * @param info the plot rendering info. * @param source the source point. */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { this.rangeAxis.zoomRange(lowerPercent, upperPercent); } /** * Returns <code>true</code>. * * @return A boolean. */ @Override public boolean isDomainZoomable() { return true; } /** * Returns <code>true</code>. * * @return A boolean. */ @Override public boolean isRangeZoomable() { return true; } /** * Returns <code>true</code> if panning is enabled for the domain axes, * and <code>false</code> otherwise. * * @return A boolean. * * @since 1.0.13 */ @Override public boolean isDomainPannable() { return this.domainPannable; } /** * Sets the flag that enables or disables panning of the plot along the * domain axes. * * @param pannable the new flag value. * * @since 1.0.13 */ public void setDomainPannable(boolean pannable) { this.domainPannable = pannable; } /** * Returns <code>true</code> if panning is enabled for the range axes, * and <code>false</code> otherwise. * * @return A boolean. * * @since 1.0.13 */ @Override public boolean isRangePannable() { return this.rangePannable; } /** * Sets the flag that enables or disables panning of the plot along * the range axes. * * @param pannable the new flag value. * * @since 1.0.13 */ public void setRangePannable(boolean pannable) { this.rangePannable = pannable; } /** * Pans the domain axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.13 */ @Override public void panDomainAxes(double percent, PlotRenderingInfo info, Point2D source) { if (!isDomainPannable() || this.domainAxis == null) { return; } double length = this.domainAxis.getRange().getLength(); double adj = -percent * length; if (this.domainAxis.isInverted()) { adj = -adj; } this.domainAxis.setRange(this.domainAxis.getLowerBound() + adj, this.domainAxis.getUpperBound() + adj); } /** * Pans the range axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.13 */ @Override public void panRangeAxes(double percent, PlotRenderingInfo info, Point2D source) { if (!isRangePannable() || this.rangeAxis == null) { return; } double length = this.rangeAxis.getRange().getLength(); double adj = percent * length; if (this.rangeAxis.isInverted()) { adj = -adj; } this.rangeAxis.setRange(this.rangeAxis.getLowerBound() + adj, this.rangeAxis.getUpperBound() + adj); } /** * Tests an arbitrary object for equality with this plot. Note that * <code>FastScatterPlot</code> carries its data around with it (rather * than referencing a dataset), and the data is included in the * equality test. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!super.equals(obj)) { return false; } if (!(obj instanceof FastScatterPlot)) { return false; } FastScatterPlot that = (FastScatterPlot) obj; if (this.domainPannable != that.domainPannable) { return false; } if (this.rangePannable != that.rangePannable) { return false; } if (!ArrayUtilities.equal(this.data, that.data)) { return false; } if (!ObjectUtilities.equal(this.domainAxis, that.domainAxis)) { return false; } if (!ObjectUtilities.equal(this.rangeAxis, that.rangeAxis)) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (this.domainGridlinesVisible != that.domainGridlinesVisible) { return false; } if (!PaintUtilities.equal(this.domainGridlinePaint, that.domainGridlinePaint)) { return false; } if (!ObjectUtilities.equal(this.domainGridlineStroke, that.domainGridlineStroke)) { return false; } if (!this.rangeGridlinesVisible == that.rangeGridlinesVisible) { return false; } if (!PaintUtilities.equal(this.rangeGridlinePaint, that.rangeGridlinePaint)) { return false; } if (!ObjectUtilities.equal(this.rangeGridlineStroke, that.rangeGridlineStroke)) { return false; } return true; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException if some component of the plot does * not support cloning. */ @Override public Object clone() throws CloneNotSupportedException { FastScatterPlot clone = (FastScatterPlot) super.clone(); if (this.data != null) { clone.data = ArrayUtilities.clone(this.data); } if (this.domainAxis != null) { clone.domainAxis = (ValueAxis) this.domainAxis.clone(); clone.domainAxis.setPlot(clone); clone.domainAxis.addChangeListener(clone); } if (this.rangeAxis != null) { clone.rangeAxis = (ValueAxis) this.rangeAxis.clone(); clone.rangeAxis.setPlot(clone); clone.rangeAxis.addChangeListener(clone); } return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writeStroke(this.domainGridlineStroke, stream); SerialUtilities.writePaint(this.domainGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeGridlineStroke, stream); SerialUtilities.writePaint(this.rangeGridlinePaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.domainGridlineStroke = SerialUtilities.readStroke(stream); this.domainGridlinePaint = SerialUtilities.readPaint(stream); this.rangeGridlineStroke = SerialUtilities.readStroke(stream); this.rangeGridlinePaint = SerialUtilities.readPaint(stream); if (this.domainAxis != null) { this.domainAxis.addChangeListener(this); } if (this.rangeAxis != null) { this.rangeAxis.addChangeListener(this); } } }
36,755
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialShape.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/DialShape.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * DialShape.java * -------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 20-Aug-2003 : Version 1 (DG); * 12-Nov-2007 : Implemented hashCode() (DG); * */ package org.jfree.chart.plot; /** * Used to indicate the background shape for a * {@link org.jfree.chart.plot.MeterPlot}. */ public enum DialShape { /** Circle. */ CIRCLE("DialShape.CIRCLE"), /** Chord. */ CHORD("DialShape.CHORD"), /** Pie. */ PIE("DialShape.PIE"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private DialShape(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,215
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractPieLabelDistributor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/AbstractPieLabelDistributor.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * AbstractPieLabelDistributor.java * -------------------------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 14-Jun-2007 : Version 1 (DG); * */ package org.jfree.chart.plot; import java.io.Serializable; import java.util.List; /** * A base class for handling the distribution of pie section labels. Create * your own subclass and set it using the * {@link PiePlot#setLabelDistributor(AbstractPieLabelDistributor)} method * if you want to customise the label distribution. */ public abstract class AbstractPieLabelDistributor implements Serializable { /** The label records. */ protected List<PieLabelRecord> labels; /** * Creates a new instance. */ public AbstractPieLabelDistributor() { this.labels = new java.util.ArrayList<PieLabelRecord>(); } /** * Returns a label record from the list. * * @param index the index. * * @return The label record. */ public PieLabelRecord getPieLabelRecord(int index) { return this.labels.get(index); } /** * Adds a label record. * * @param record the label record (<code>null</code> not permitted). */ public void addPieLabelRecord(PieLabelRecord record) { if (record == null) { throw new IllegalArgumentException("Null 'record' argument."); } this.labels.add(record); } /** * Returns the number of items in the list. * * @return The item count. */ public int getItemCount() { return this.labels.size(); } /** * Clears the list of labels. */ public void clear() { this.labels.clear(); } /** * Called by the {@link PiePlot} class. Implementations should distribute * the labels in this.labels then return. * * @param minY the y-coordinate for the top of the label area. * @param height the height of the label area. */ public abstract void distributeLabels(double minY, double height); }
3,428
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/XYPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------- * XYPlot.java * ----------- * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Craig MacFarlane; * Mark Watson (www.markwatson.com); * Jonathan Nash; * Gideon Krause; * Klaus Rheinwald; * Xavier Poinsard; * Richard Atkinson; * Arnaud Lelievre; * Nicolas Brodu; * Eduardo Ramalho; * Sergei Ivanov; * Richard West, Advanced Micro Devices, Inc.; * Ulrich Voigt - patches 1997549 and 2686040; * Peter Kolb - patches 1934255, 2603321 and 2809117; * Andrew Mickish - patch 1868749; * * Changes (from 21-Jun-2001) * -------------------------- * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG); * 18-Sep-2001 : Updated header and fixed DOS encoding problem (DG); * 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG); * 19-Oct-2001 : Removed the code for drawing the visual representation of each * data point into a separate class StandardXYItemRenderer. * This will make it easier to add variations to the way the * charts are drawn. Based on code contributed by Mark * Watson (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 20-Nov-2001 : Fixed clipping bug that shows up when chart is displayed * inside JScrollPane (DG); * 12-Dec-2001 : Removed unnecessary 'throws' clauses from constructor (DG); * 13-Dec-2001 : Added skeleton code for tooltips. Added new constructor. (DG); * 16-Jan-2002 : Renamed the tooltips class (DG); * 22-Jan-2002 : Added DrawInfo class, incorporating tooltips and crosshairs. * Crosshairs based on code by Jonathan Nash (DG); * 05-Feb-2002 : Added alpha-transparency setting based on code by Sylvain * Vieujot (DG); * 26-Feb-2002 : Updated getMinimumXXX() and getMaximumXXX() methods to handle * special case when chart is null (DG); * 28-Feb-2002 : Renamed Datasets.java --> DatasetUtilities.java (DG); * 28-Mar-2002 : The plot now registers with the renderer as a property change * listener. Also added a new constructor (DG); * 09-Apr-2002 : Removed the transRangeZero from the renderer.drawItem() * method. Moved the tooltip generator into the renderer (DG); * 23-Apr-2002 : Fixed bug in methods for drawing horizontal and vertical * lines (DG); * 13-May-2002 : Small change to the draw() method so that it works for * OverlaidXYPlot also (DG); * 25-Jun-2002 : Removed redundant import (DG); * 20-Aug-2002 : Renamed getItemRenderer() --> getRenderer(), and * setXYItemRenderer() --> setRenderer() (DG); * 28-Aug-2002 : Added mechanism for (optional) plot annotations (DG); * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 18-Nov-2002 : Added grid settings for both domain and range axis (previously * these were set in the axes) (DG); * 09-Jan-2003 : Further additions to the grid settings, plus integrated plot * border bug fix contributed by Gideon Krause (DG); * 22-Jan-2003 : Removed monolithic constructor (DG); * 04-Mar-2003 : Added 'no data' message, see bug report 691634. Added * secondary range markers using code contributed by Klaus * Rheinwald (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 03-Apr-2003 : Added setDomainAxisLocation() method (DG); * 30-Apr-2003 : Moved annotation drawing into a separate method (DG); * 01-May-2003 : Added multi-pass mechanism for renderers (DG); * 02-May-2003 : Changed axis locations from int to AxisLocation (DG); * 15-May-2003 : Added an orientation attribute (DG); * 02-Jun-2003 : Removed range axis compatibility test (DG); * 05-Jun-2003 : Added domain and range grid bands (sponsored by Focus Computer * Services Ltd) (DG); * 26-Jun-2003 : Fixed bug (757303) in getDataRange() method (DG); * 02-Jul-2003 : Added patch from bug report 698646 (secondary axes for * overlaid plots) (DG); * 23-Jul-2003 : Added support for multiple secondary datasets, axes and * renderers (DG); * 27-Jul-2003 : Added support for stacked XY area charts (RA); * 19-Aug-2003 : Implemented Cloneable (DG); * 01-Sep-2003 : Fixed bug where change to secondary datasets didn't generate * change event (797466) (DG) * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 08-Sep-2003 : Changed ValueAxis API (DG); * 08-Sep-2003 : Fixes for serialization (NB); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 17-Sep-2003 : Fixed zooming to include secondary domain axes (DG); * 18-Sep-2003 : Added getSecondaryDomainAxisCount() and * getSecondaryRangeAxisCount() methods suggested by Eduardo * Ramalho (RFE 808548) (DG); * 23-Sep-2003 : Split domain and range markers into foreground and * background (DG); * 06-Oct-2003 : Fixed bug in clearDomainMarkers() and clearRangeMarkers() * methods. Fixed bug (815876) in addSecondaryRangeMarker() * method. Added new addSecondaryDomainMarker methods (see bug * id 815869) (DG); * 10-Nov-2003 : Added getSecondaryDomain/RangeAxisMappedToDataset() methods * requested by Eduardo Ramalho (DG); * 24-Nov-2003 : Removed unnecessary notification when updating axis anchor * values (DG); * 21-Jan-2004 : Update for renamed method in ValueAxis (DG); * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG); * 12-Mar-2004 : Fixed bug where primary renderer is always used to determine * range type (DG); * 22-Mar-2004 : Fixed cloning bug (DG); * 23-Mar-2004 : Fixed more cloning bugs (DG); * 07-Apr-2004 : Fixed problem with axis range when the secondary renderer is * stacked, see this post in the forum: * http://www.jfree.org/phpBB2/viewtopic.php?t=8204 (DG); * 07-Apr-2004 : Added get/setDatasetRenderingOrder() methods (DG); * 26-Apr-2004 : Added option to fill quadrant areas in the background of the * plot (DG); * 27-Apr-2004 : Removed major distinction between primary and secondary * datasets, renderers and axes (DG); * 30-Apr-2004 : Modified to make use of the new getRangeExtent() method in the * renderer interface (DG); * 13-May-2004 : Added optional fixedLegendItems attribute (DG); * 19-May-2004 : Added indexOf() method (DG); * 03-Jun-2004 : Fixed zooming bug (DG); * 18-Aug-2004 : Added removedAnnotation() method (by tkram01) (DG); * 05-Oct-2004 : Modified storage type for dataset-to-axis maps (DG); * 06-Oct-2004 : Modified getDataRange() method to use renderer to determine * the x-value range (now matches behaviour for y-values). Added * getDomainAxisIndex() method (DG); * 12-Nov-2004 : Implemented new Zoomable interface (DG); * 25-Nov-2004 : Small update to clone() implementation (DG); * 22-Feb-2005 : Changed axis offsets from Spacer --> RectangleInsets (DG); * 24-Feb-2005 : Added indexOf(XYItemRenderer) method (DG); * 21-Mar-2005 : Register plot as change listener in setRenderer() method (DG); * 21-Apr-2005 : Added get/setSeriesRenderingOrder() methods (ET); * 26-Apr-2005 : Removed LOGGER (DG); * 04-May-2005 : Fixed serialization of domain and range markers (DG); * 05-May-2005 : Removed unused draw() method (DG); * 20-May-2005 : Added setDomainAxes() and setRangeAxes() methods, as per * RFE 1183100 (DG); * 01-Jun-2005 : Upon deserialization, register plot as a listener with its * axes, dataset(s) and renderer(s) - see patch 1209475 (DG); * 01-Jun-2005 : Added clearDomainMarkers(int) method to match * clearRangeMarkers(int) (DG); * 06-Jun-2005 : Fixed equals() method to handle GradientPaint (DG); * 09-Jun-2005 : Added setRenderers(), as per RFE 1183100 (DG); * 06-Jul-2005 : Fixed crosshair bug (id = 1233336) (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 26-Jan-2006 : Added getAnnotations() method (DG); * 05-Sep-2006 : Added MarkerChangeEvent support (DG); * 13-Oct-2006 : Fixed initialisation of CrosshairState - see bug report * 1565168 (DG); * 22-Nov-2006 : Fixed equals() and cloning() for quadrant attributes, plus * API doc updates (DG); * 29-Nov-2006 : Added argument checks (DG); * 15-Jan-2007 : Fixed bug in drawRangeMarkers() (DG); * 07-Feb-2007 : Fixed bug 1654215, renderer with no dataset (DG); * 26-Feb-2007 : Added missing setDomainAxisLocation() and * setRangeAxisLocation() methods (DG); * 02-Mar-2007 : Fix for crosshair positioning with horizontal orientation * (see patch 1671648 by Sergei Ivanov) (DG); * 13-Mar-2007 : Added null argument checks for crosshair attributes (DG); * 23-Mar-2007 : Added domain zero base line facility (DG); * 04-May-2007 : Render only visible data items if possible (DG); * 24-May-2007 : Fixed bug in render method for an empty series (DG); * 07-Jun-2007 : Modified drawBackground() to pass orientation to * fillBackground() for handling GradientPaint (DG); * 24-Sep-2007 : Added new zoom methods (DG); * 26-Sep-2007 : Include index value in IllegalArgumentExceptions (DG); * 05-Nov-2007 : Applied patch 1823697, by Richard West, for removal of domain * and range markers (DG); * 12-Nov-2007 : Fixed bug in equals() method for domain and range tick * band paint attributes (DG); * 27-Nov-2007 : Added new setFixedDomain/RangeAxisSpace() methods (DG); * 04-Jan-2008 : Fix for quadrant painting error - see patch 1849564 (DG); * 25-Mar-2008 : Added new methods with optional notification - see patch * 1913751 (DG); * 07-Apr-2008 : Fixed NPE in removeDomainMarker() and * removeRangeMarker() (DG); * 22-May-2008 : Modified calculateAxisSpace() to process range axes first, * then adjust the plot area before calculating the space * for the domain axes (DG); * 09-Jul-2008 : Added renderer state notification when series pass begins * and ends - see patch 1997549 by Ulrich Voigt (DG); * 25-Jul-2008 : Fixed NullPointerException for plots with no axes (DG); * 15-Aug-2008 : Added getRendererCount() method (DG); * 25-Sep-2008 : Added minor tick support, see patch 1934255 by Peter Kolb (DG); * 25-Nov-2008 : Allow datasets to be mapped to multiple axes - based on patch * 1868749 by Andrew Mickish (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 10-Mar-2009 : Allow some annotations to contribute to axis autoRange (DG); * 18-Mar-2009 : Modified anchored zoom behaviour and fixed bug in * "process visible range" rendering (DG); * 19-Mar-2009 : Added panning support based on patch 2686040 by Ulrich * Voigt (DG); * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * 30-Mar-2009 : Delegate panning to axes (DG); * 10-May-2009 : Added check for fixedLegendItems in equals(), and code to * handle cloning (DG); * 24-Jun-2009 : Added support for annotation events - see patch 2809117 * by PK (DG); * 06-Jul-2009 : Fix for cloning of renderers - see bug 2817504 (DG) * 10-Jul-2009 : Added optional drop shadow generator (DG); * 18-Oct-2011 : Fix tooltip offset with shadow renderer (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.Set; import java.util.TreeMap; import org.jfree.chart.LegendItem; import org.jfree.chart.annotations.Annotation; import org.jfree.chart.annotations.XYAnnotation; import org.jfree.chart.annotations.XYAnnotationBoundsInfo; import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.AxisCollection; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.TickType; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.axis.ValueTick; import org.jfree.chart.ui.Layer; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectList; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.event.ChartChangeEventType; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; import org.jfree.chart.event.RendererChangeListener; import org.jfree.chart.renderer.RendererUtilities; import org.jfree.chart.renderer.xy.AbstractXYItemRenderer; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.renderer.xy.XYItemRendererState; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.chart.util.ShadowGenerator; import org.jfree.data.Range; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.xy.XYDataset; /** * A general class for plotting data in the form of (x, y) pairs. This plot can * use data from any class that implements the {@link XYDataset} interface. * <P> * <code>XYPlot</code> makes use of an {@link XYItemRenderer} to draw each point * on the plot. By using different renderers, various chart types can be * produced. * <p> * The {@link org.jfree.chart.ChartFactory} class contains static methods for * creating pre-configured charts. */ public class XYPlot extends Plot implements ValueAxisPlot, Pannable, Zoomable, RendererChangeListener, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 7044148245716569264L; /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] {2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.LIGHT_GRAY; /** The default crosshair visibility. */ public static final boolean DEFAULT_CROSSHAIR_VISIBLE = false; /** The default crosshair stroke. */ public static final Stroke DEFAULT_CROSSHAIR_STROKE = DEFAULT_GRIDLINE_STROKE; /** The default crosshair paint. */ public static final Paint DEFAULT_CROSSHAIR_PAINT = Color.BLUE; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** The plot orientation. */ private PlotOrientation orientation; /** The offset between the data area and the axes. */ private RectangleInsets axisOffset; /** The domain axis / axes (used for the x-values). */ private ObjectList<ValueAxis> domainAxes; /** The domain axis locations. */ private ObjectList<AxisLocation> domainAxisLocations; /** The range axis (used for the y-values). */ private ObjectList<ValueAxis> rangeAxes; /** The range axis location. */ private ObjectList<AxisLocation> rangeAxisLocations; /** Storage for the datasets. */ private ObjectList<XYDataset> datasets; /** Storage for the renderers. */ private ObjectList<XYItemRenderer> renderers; /** * Storage for the mapping between datasets/renderers and domain axes. The * keys in the map are Integer objects, corresponding to the dataset * index. The values in the map are List objects containing Integer * objects (corresponding to the axis indices). If the map contains no * entry for a dataset, it is assumed to map to the primary domain axis * (index = 0). */ private Map<Integer, List<Integer>> datasetToDomainAxesMap; /** * Storage for the mapping between datasets/renderers and range axes. The * keys in the map are Integer objects, corresponding to the dataset * index. The values in the map are List objects containing Integer * objects (corresponding to the axis indices). If the map contains no * entry for a dataset, it is assumed to map to the primary domain axis * (index = 0). */ private Map<Integer, List<Integer>> datasetToRangeAxesMap; /** The origin point for the quadrants (if drawn). */ private transient Point2D quadrantOrigin = new Point2D.Double(0.0, 0.0); /** The paint used for each quadrant. */ private transient Paint[] quadrantPaint = new Paint[] {null, null, null, null}; /** A flag that controls whether the domain grid-lines are visible. */ private boolean domainGridlinesVisible; /** The stroke used to draw the domain grid-lines. */ private transient Stroke domainGridlineStroke; /** The paint used to draw the domain grid-lines. */ private transient Paint domainGridlinePaint; /** A flag that controls whether the range grid-lines are visible. */ private boolean rangeGridlinesVisible; /** The stroke used to draw the range grid-lines. */ private transient Stroke rangeGridlineStroke; /** The paint used to draw the range grid-lines. */ private transient Paint rangeGridlinePaint; /** * A flag that controls whether the domain minor grid-lines are visible. * * @since 1.0.12 */ private boolean domainMinorGridlinesVisible; /** * The stroke used to draw the domain minor grid-lines. * * @since 1.0.12 */ private transient Stroke domainMinorGridlineStroke; /** * The paint used to draw the domain minor grid-lines. * * @since 1.0.12 */ private transient Paint domainMinorGridlinePaint; /** * A flag that controls whether the range minor grid-lines are visible. * * @since 1.0.12 */ private boolean rangeMinorGridlinesVisible; /** * The stroke used to draw the range minor grid-lines. * * @since 1.0.12 */ private transient Stroke rangeMinorGridlineStroke; /** * The paint used to draw the range minor grid-lines. * * @since 1.0.12 */ private transient Paint rangeMinorGridlinePaint; /** * A flag that controls whether or not the zero baseline against the domain * axis is visible. * * @since 1.0.5 */ private boolean domainZeroBaselineVisible; /** * The stroke used for the zero baseline against the domain axis. * * @since 1.0.5 */ private transient Stroke domainZeroBaselineStroke; /** * The paint used for the zero baseline against the domain axis. * * @since 1.0.5 */ private transient Paint domainZeroBaselinePaint; /** * A flag that controls whether or not the zero baseline against the range * axis is visible. */ private boolean rangeZeroBaselineVisible; /** The stroke used for the zero baseline against the range axis. */ private transient Stroke rangeZeroBaselineStroke; /** The paint used for the zero baseline against the range axis. */ private transient Paint rangeZeroBaselinePaint; /** A flag that controls whether or not a domain crosshair is drawn..*/ private boolean domainCrosshairVisible; /** The domain crosshair value. */ private double domainCrosshairValue; /** The pen/brush used to draw the crosshair (if any). */ private transient Stroke domainCrosshairStroke; /** The color used to draw the crosshair (if any). */ private transient Paint domainCrosshairPaint; /** * A flag that controls whether or not the crosshair locks onto actual * data points. */ private boolean domainCrosshairLockedOnData = true; /** A flag that controls whether or not a range crosshair is drawn..*/ private boolean rangeCrosshairVisible; /** The range crosshair value. */ private double rangeCrosshairValue; /** The pen/brush used to draw the crosshair (if any). */ private transient Stroke rangeCrosshairStroke; /** The color used to draw the crosshair (if any). */ private transient Paint rangeCrosshairPaint; /** * A flag that controls whether or not the crosshair locks onto actual * data points. */ private boolean rangeCrosshairLockedOnData = true; /** A map of lists of foreground markers (optional) for the domain axes. */ private Map<Integer, Collection<Marker>> foregroundDomainMarkers; /** A map of lists of background markers (optional) for the domain axes. */ private Map<Integer, Collection<Marker>> backgroundDomainMarkers; /** A map of lists of foreground markers (optional) for the range axes. */ private Map<Integer, Collection<Marker>> foregroundRangeMarkers; /** A map of lists of background markers (optional) for the range axes. */ private Map<Integer, Collection<Marker>> backgroundRangeMarkers; /** * A (possibly empty) list of annotations for the plot. The list should * be initialised in the constructor and never allowed to be * <code>null</code>. */ private List<XYAnnotation> annotations; /** The paint used for the domain tick bands (if any). */ private transient Paint domainTickBandPaint; /** The paint used for the range tick bands (if any). */ private transient Paint rangeTickBandPaint; /** The fixed domain axis space. */ private AxisSpace fixedDomainAxisSpace; /** The fixed range axis space. */ private AxisSpace fixedRangeAxisSpace; /** * The order of the dataset rendering (REVERSE draws the primary dataset * last so that it appears to be on top). */ private DatasetRenderingOrder datasetRenderingOrder = DatasetRenderingOrder.REVERSE; /** * The order of the series rendering (REVERSE draws the primary series * last so that it appears to be on top). */ private SeriesRenderingOrder seriesRenderingOrder = SeriesRenderingOrder.REVERSE; /** * The weight for this plot (only relevant if this is a subplot in a * combined plot). */ private int weight; /** * An optional collection of legend items that can be returned by the * getLegendItems() method. */ private List<LegendItem> fixedLegendItems; /** * A flag that controls whether or not panning is enabled for the domain * axis/axes. * * @since 1.0.13 */ private boolean domainPannable; /** * A flag that controls whether or not panning is enabled for the range * axis/axes. * * @since 1.0.13 */ private boolean rangePannable; /** * The shadow generator (<code>null</code> permitted). * * @since 1.0.14 */ private ShadowGenerator shadowGenerator; /** * Creates a new <code>XYPlot</code> instance with no dataset, no axes and * no renderer. You should specify these items before using the plot. */ public XYPlot() { this(null, null, null, null); } /** * Creates a new plot with the specified dataset, axes and renderer. Any * of the arguments can be <code>null</code>, but in that case you should * take care to specify the value before using the plot (otherwise a * <code>NullPointerException</code> may be thrown). * * @param dataset the dataset (<code>null</code> permitted). * @param domainAxis the domain axis (<code>null</code> permitted). * @param rangeAxis the range axis (<code>null</code> permitted). * @param renderer the renderer (<code>null</code> permitted). */ public XYPlot(XYDataset dataset, ValueAxis domainAxis, ValueAxis rangeAxis, XYItemRenderer renderer) { super(); this.orientation = PlotOrientation.VERTICAL; this.weight = 1; // only relevant when this is a subplot this.axisOffset = RectangleInsets.ZERO_INSETS; // allocate storage for datasets, axes and renderers (all optional) this.domainAxes = new ObjectList<ValueAxis>(); this.domainAxisLocations = new ObjectList<AxisLocation>(); this.foregroundDomainMarkers = new HashMap<Integer, Collection<Marker>>(); this.backgroundDomainMarkers = new HashMap<Integer, Collection<Marker>>(); this.rangeAxes = new ObjectList<ValueAxis>(); this.rangeAxisLocations = new ObjectList<AxisLocation>(); this.foregroundRangeMarkers = new HashMap<Integer, Collection<Marker>>(); this.backgroundRangeMarkers = new HashMap<Integer, Collection<Marker>>(); this.datasets = new ObjectList<XYDataset>(); this.renderers = new ObjectList<XYItemRenderer>(); this.datasetToDomainAxesMap = new TreeMap<Integer, List<Integer>>(); this.datasetToRangeAxesMap = new TreeMap<Integer, List<Integer>>(); this.annotations = new java.util.ArrayList<XYAnnotation>(); this.datasets.set(0, dataset); if (dataset != null) { dataset.addChangeListener(this); } this.renderers.set(0, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } this.domainAxes.set(0, domainAxis); this.mapDatasetToDomainAxis(0, 0); if (domainAxis != null) { domainAxis.setPlot(this); domainAxis.addChangeListener(this); } this.domainAxisLocations.set(0, AxisLocation.BOTTOM_OR_LEFT); this.rangeAxes.set(0, rangeAxis); this.mapDatasetToRangeAxis(0, 0); if (rangeAxis != null) { rangeAxis.setPlot(this); rangeAxis.addChangeListener(this); } this.rangeAxisLocations.set(0, AxisLocation.BOTTOM_OR_LEFT); configureDomainAxes(); configureRangeAxes(); this.domainGridlinesVisible = true; this.domainGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.domainGridlinePaint = DEFAULT_GRIDLINE_PAINT; this.domainMinorGridlinesVisible = false; this.domainMinorGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.domainMinorGridlinePaint = Color.WHITE; this.domainZeroBaselineVisible = false; this.domainZeroBaselinePaint = Color.BLACK; this.domainZeroBaselineStroke = new BasicStroke(0.5f); this.rangeGridlinesVisible = true; this.rangeGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.rangeGridlinePaint = DEFAULT_GRIDLINE_PAINT; this.rangeMinorGridlinesVisible = false; this.rangeMinorGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.rangeMinorGridlinePaint = Color.WHITE; this.rangeZeroBaselineVisible = false; this.rangeZeroBaselinePaint = Color.BLACK; this.rangeZeroBaselineStroke = new BasicStroke(0.5f); this.domainCrosshairVisible = false; this.domainCrosshairValue = 0.0; this.domainCrosshairStroke = DEFAULT_CROSSHAIR_STROKE; this.domainCrosshairPaint = DEFAULT_CROSSHAIR_PAINT; this.rangeCrosshairVisible = false; this.rangeCrosshairValue = 0.0; this.rangeCrosshairStroke = DEFAULT_CROSSHAIR_STROKE; this.rangeCrosshairPaint = DEFAULT_CROSSHAIR_PAINT; this.shadowGenerator = null; } /** * Returns the plot type as a string. * * @return A short string describing the type of plot. */ @Override public String getPlotType() { return localizationResources.getString("XY_Plot"); } /** * Returns the orientation of the plot. * * @return The orientation (never <code>null</code>). * * @see #setOrientation(PlotOrientation) */ @Override public PlotOrientation getOrientation() { return this.orientation; } /** * Sets the orientation for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param orientation the orientation (<code>null</code> not allowed). * * @see #getOrientation() */ public void setOrientation(PlotOrientation orientation) { ParamChecks.nullNotPermitted(orientation, "orientation"); if (orientation != this.orientation) { this.orientation = orientation; fireChangeEvent(); } } /** * Returns the axis offset. * * @return The axis offset (never <code>null</code>). * * @see #setAxisOffset(RectangleInsets) */ public RectangleInsets getAxisOffset() { return this.axisOffset; } /** * Sets the axis offsets (gap between the data area and the axes) and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param offset the offset (<code>null</code> not permitted). * * @see #getAxisOffset() */ public void setAxisOffset(RectangleInsets offset) { if (offset == null) { throw new IllegalArgumentException("Null 'offset' argument."); } this.axisOffset = offset; fireChangeEvent(); } /** * Returns the domain axis with index 0. If the domain axis for this plot * is <code>null</code>, then the method will return the parent plot's * domain axis (if there is a parent plot). * * @return The domain axis (possibly <code>null</code>). * * @see #getDomainAxis(int) * @see #setDomainAxis(ValueAxis) */ public ValueAxis getDomainAxis() { return getDomainAxis(0); } /** * Returns the domain axis with the specified index, or <code>null</code>. * * @param index the axis index. * * @return The axis (<code>null</code> possible). * * @see #setDomainAxis(int, ValueAxis) */ public ValueAxis getDomainAxis(int index) { ValueAxis result = null; if (index < this.domainAxes.size()) { result = this.domainAxes.get(index); } if (result == null) { Plot parent = getParent(); if (parent instanceof XYPlot) { XYPlot xy = (XYPlot) parent; result = xy.getDomainAxis(index); } } return result; } /** * Sets the domain axis for the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axis the new axis (<code>null</code> permitted). * * @see #getDomainAxis() * @see #setDomainAxis(int, ValueAxis) */ public void setDomainAxis(ValueAxis axis) { setDomainAxis(0, axis); } /** * Sets a domain axis and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * * @see #getDomainAxis(int) * @see #setRangeAxis(int, ValueAxis) */ public void setDomainAxis(int index, ValueAxis axis) { setDomainAxis(index, axis, true); } /** * Sets a domain axis and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param index the axis index. * @param axis the axis. * @param notify notify listeners? * * @see #getDomainAxis(int) */ public void setDomainAxis(int index, ValueAxis axis, boolean notify) { ValueAxis existing = getDomainAxis(index); if (existing != null) { existing.removeChangeListener(this); } if (axis != null) { axis.setPlot(this); } this.domainAxes.set(index, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } if (notify) { fireChangeEvent(); } } /** * Sets the domain axes for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axes the axes (<code>null</code> not permitted). * * @see #setRangeAxes(ValueAxis[]) */ public void setDomainAxes(ValueAxis[] axes) { for (int i = 0; i < axes.length; i++) { setDomainAxis(i, axes[i], false); } fireChangeEvent(); } /** * Returns the location of the primary domain axis. * * @return The location (never <code>null</code>). * * @see #setDomainAxisLocation(AxisLocation) */ public AxisLocation getDomainAxisLocation() { return this.domainAxisLocations.get(0); } /** * Sets the location of the primary domain axis and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * * @see #getDomainAxisLocation() */ public void setDomainAxisLocation(AxisLocation location) { // delegate... setDomainAxisLocation(0, location, true); } /** * Sets the location of the domain axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? * * @see #getDomainAxisLocation() */ public void setDomainAxisLocation(AxisLocation location, boolean notify) { // delegate... setDomainAxisLocation(0, location, notify); } /** * Returns the edge for the primary domain axis (taking into account the * plot's orientation). * * @return The edge. * * @see #getDomainAxisLocation() * @see #getOrientation() */ public RectangleEdge getDomainAxisEdge() { return Plot.resolveDomainAxisLocation(getDomainAxisLocation(), this.orientation); } /** * Returns the number of domain axes. * * @return The axis count. * * @see #getRangeAxisCount() */ public int getDomainAxisCount() { return this.domainAxes.size(); } /** * Clears the domain axes from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @see #clearRangeAxes() */ public void clearDomainAxes() { for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis axis = this.domainAxes.get(i); if (axis != null) { axis.removeChangeListener(this); } } this.domainAxes.clear(); fireChangeEvent(); } /** * Configures the domain axes. */ public void configureDomainAxes() { for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis axis = this.domainAxes.get(i); if (axis != null) { axis.configure(); } } } /** * Returns the location for a domain axis. If this hasn't been set * explicitly, the method returns the location that is opposite to the * primary domain axis location. * * @param index the axis index. * * @return The location (never <code>null</code>). * * @see #setDomainAxisLocation(int, AxisLocation) */ public AxisLocation getDomainAxisLocation(int index) { AxisLocation result = null; if (index < this.domainAxisLocations.size()) { result = this.domainAxisLocations.get(index); } if (result == null) { result = AxisLocation.getOpposite(getDomainAxisLocation()); } return result; } /** * Sets the location for a domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location (<code>null</code> not permitted for index * 0). * * @see #getDomainAxisLocation(int) */ public void setDomainAxisLocation(int index, AxisLocation location) { // delegate... setDomainAxisLocation(index, location, true); } /** * Sets the axis location for a domain axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the axis index. * @param location the location (<code>null</code> not permitted for * index 0). * @param notify notify listeners? * * @since 1.0.5 * * @see #getDomainAxisLocation(int) * @see #setRangeAxisLocation(int, AxisLocation, boolean) */ public void setDomainAxisLocation(int index, AxisLocation location, boolean notify) { if (index == 0 && location == null) { throw new IllegalArgumentException( "Null 'location' for index 0 not permitted."); } this.domainAxisLocations.set(index, location); if (notify) { fireChangeEvent(); } } /** * Returns the edge for a domain axis. * * @param index the axis index. * * @return The edge. * * @see #getRangeAxisEdge(int) */ public RectangleEdge getDomainAxisEdge(int index) { AxisLocation location = getDomainAxisLocation(index); return Plot.resolveDomainAxisLocation(location, this.orientation); } /** * Returns the range axis for the plot. If the range axis for this plot is * <code>null</code>, then the method will return the parent plot's range * axis (if there is a parent plot). * * @return The range axis. * * @see #getRangeAxis(int) * @see #setRangeAxis(ValueAxis) */ public ValueAxis getRangeAxis() { return getRangeAxis(0); } /** * Sets the range axis for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param axis the axis (<code>null</code> permitted). * * @see #getRangeAxis() * @see #setRangeAxis(int, ValueAxis) */ public void setRangeAxis(ValueAxis axis) { if (axis != null) { axis.setPlot(this); } // plot is likely registered as a listener with the existing axis... ValueAxis existing = getRangeAxis(); if (existing != null) { existing.removeChangeListener(this); } this.rangeAxes.set(0, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } fireChangeEvent(); } /** * Returns the location of the primary range axis. * * @return The location (never <code>null</code>). * * @see #setRangeAxisLocation(AxisLocation) */ public AxisLocation getRangeAxisLocation() { return this.rangeAxisLocations.get(0); } /** * Sets the location of the primary range axis and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * * @see #getRangeAxisLocation() */ public void setRangeAxisLocation(AxisLocation location) { // delegate... setRangeAxisLocation(0, location, true); } /** * Sets the location of the primary range axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? * * @see #getRangeAxisLocation() */ public void setRangeAxisLocation(AxisLocation location, boolean notify) { // delegate... setRangeAxisLocation(0, location, notify); } /** * Returns the edge for the primary range axis. * * @return The range axis edge. * * @see #getRangeAxisLocation() * @see #getOrientation() */ public RectangleEdge getRangeAxisEdge() { return Plot.resolveRangeAxisLocation(getRangeAxisLocation(), this.orientation); } /** * Returns a range axis. * * @param index the axis index. * * @return The axis (<code>null</code> possible). * * @see #setRangeAxis(int, ValueAxis) */ public ValueAxis getRangeAxis(int index) { ValueAxis result = null; if (index < this.rangeAxes.size()) { result = this.rangeAxes.get(index); } if (result == null) { Plot parent = getParent(); if (parent instanceof XYPlot) { XYPlot xy = (XYPlot) parent; result = xy.getRangeAxis(index); } } return result; } /** * Sets a range axis and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * * @see #getRangeAxis(int) */ public void setRangeAxis(int index, ValueAxis axis) { setRangeAxis(index, axis, true); } /** * Sets a range axis and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * @param notify notify listeners? * * @see #getRangeAxis(int) */ public void setRangeAxis(int index, ValueAxis axis, boolean notify) { ValueAxis existing = getRangeAxis(index); if (existing != null) { existing.removeChangeListener(this); } if (axis != null) { axis.setPlot(this); } this.rangeAxes.set(index, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } if (notify) { fireChangeEvent(); } } /** * Sets the range axes for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axes the axes (<code>null</code> not permitted). * * @see #setDomainAxes(ValueAxis[]) */ public void setRangeAxes(ValueAxis[] axes) { for (int i = 0; i < axes.length; i++) { setRangeAxis(i, axes[i], false); } fireChangeEvent(); } /** * Returns the number of range axes. * * @return The axis count. * * @see #getDomainAxisCount() */ public int getRangeAxisCount() { return this.rangeAxes.size(); } /** * Clears the range axes from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @see #clearDomainAxes() */ public void clearRangeAxes() { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = this.rangeAxes.get(i); if (axis != null) { axis.removeChangeListener(this); } } this.rangeAxes.clear(); fireChangeEvent(); } /** * Configures the range axes. * * @see #configureDomainAxes() */ public void configureRangeAxes() { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = this.rangeAxes.get(i); if (axis != null) { axis.configure(); } } } /** * Returns the location for a range axis. If this hasn't been set * explicitly, the method returns the location that is opposite to the * primary range axis location. * * @param index the axis index. * * @return The location (never <code>null</code>). * * @see #setRangeAxisLocation(int, AxisLocation) */ public AxisLocation getRangeAxisLocation(int index) { AxisLocation result = null; if (index < this.rangeAxisLocations.size()) { result = this.rangeAxisLocations.get(index); } if (result == null) { result = AxisLocation.getOpposite(getRangeAxisLocation()); } return result; } /** * Sets the location for a range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location (<code>null</code> permitted). * * @see #getRangeAxisLocation(int) */ public void setRangeAxisLocation(int index, AxisLocation location) { // delegate... setRangeAxisLocation(index, location, true); } /** * Sets the axis location for a domain axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the axis index. * @param location the location (<code>null</code> not permitted for * index 0). * @param notify notify listeners? * * @since 1.0.5 * * @see #getRangeAxisLocation(int) * @see #setDomainAxisLocation(int, AxisLocation, boolean) */ public void setRangeAxisLocation(int index, AxisLocation location, boolean notify) { if (index == 0 && location == null) { throw new IllegalArgumentException( "Null 'location' for index 0 not permitted."); } this.rangeAxisLocations.set(index, location); if (notify) { fireChangeEvent(); } } /** * Returns the edge for a range axis. * * @param index the axis index. * * @return The edge. * * @see #getRangeAxisLocation(int) * @see #getOrientation() */ public RectangleEdge getRangeAxisEdge(int index) { AxisLocation location = getRangeAxisLocation(index); return Plot.resolveRangeAxisLocation(location, this.orientation); } /** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). * * @see #getDataset(int) * @see #setDataset(XYDataset) */ public XYDataset getDataset() { return getDataset(0); } /** * Returns a dataset. * * @param index the dataset index. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(int, XYDataset) */ public XYDataset getDataset(int index) { XYDataset result = null; if (this.datasets.size() > index) { result = this.datasets.get(index); } return result; } /** * Sets the primary dataset for the plot, replacing the existing dataset if * there is one. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() * @see #setDataset(int, XYDataset) */ public void setDataset(XYDataset dataset) { setDataset(0, dataset); } /** * Sets a dataset for the plot. * * @param index the dataset index. * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset(int) */ public void setDataset(int index, XYDataset dataset) { XYDataset existing = getDataset(index); if (existing != null) { existing.removeChangeListener(this); } this.datasets.set(index, dataset); if (dataset != null) { dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns the number of datasets. * * @return The number of datasets. */ public int getDatasetCount() { return this.datasets.size(); } /** * Returns the index of the specified dataset, or <code>-1</code> if the * dataset does not belong to the plot. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The index. */ public int indexOf(XYDataset dataset) { int result = -1; for (int i = 0; i < this.datasets.size(); i++) { if (dataset == this.datasets.get(i)) { result = i; break; } } return result; } /** * Maps a dataset to a particular domain axis. All data will be plotted * against axis zero by default, no mapping is required for this case. * * @param index the dataset index (zero-based). * @param axisIndex the axis index. * * @see #mapDatasetToRangeAxis(int, int) */ public void mapDatasetToDomainAxis(int index, int axisIndex) { List<Integer> axisIndices = new java.util.ArrayList<Integer>(1); axisIndices.add(axisIndex); mapDatasetToDomainAxes(index, axisIndices); } /** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices (<code>null</code> permitted). * * @since 1.0.12 */ public void mapDatasetToDomainAxes(int index, List<Integer> axisIndices) { if (index < 0) { throw new IllegalArgumentException("Requires 'index' >= 0."); } checkAxisIndices(axisIndices); Integer key = index; this.datasetToDomainAxesMap.put(key, new ArrayList<Integer>(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * Maps a dataset to a particular range axis. All data will be plotted * against axis zero by default, no mapping is required for this case. * * @param index the dataset index (zero-based). * @param axisIndex the axis index. * * @see #mapDatasetToDomainAxis(int, int) */ public void mapDatasetToRangeAxis(int index, int axisIndex) { List<Integer> axisIndices = new java.util.ArrayList<Integer>(1); axisIndices.add(axisIndex); mapDatasetToRangeAxes(index, axisIndices); } /** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices (<code>null</code> permitted). * * @since 1.0.12 */ public void mapDatasetToRangeAxes(int index, List<Integer> axisIndices) { if (index < 0) { throw new IllegalArgumentException("Requires 'index' >= 0."); } checkAxisIndices(axisIndices); Integer key = index; this.datasetToRangeAxesMap.put(key, new ArrayList<Integer>(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * This method is used to perform argument checking on the list of * axis indices passed to mapDatasetToDomainAxes() and * mapDatasetToRangeAxes(). * * @param indices the list of indices (<code>null</code> permitted). */ private void checkAxisIndices(List<Integer> indices) { // axisIndices can be: // 1. null; // 2. non-empty, containing only Integer objects that are unique. if (indices == null) { return; // OK } int count = indices.size(); if (count == 0) { throw new IllegalArgumentException("Empty list not permitted."); } Set<Integer> set = new HashSet<Integer>(); for (Integer item : indices) { if (set.contains(item)) { throw new IllegalArgumentException("Indices must be unique."); } set.add(item); } } /** * Returns the number of renderer slots for this plot. * * @return The number of renderer slots. * * @since 1.0.11 */ public int getRendererCount() { return this.renderers.size(); } /** * Returns the renderer for the primary dataset. * * @return The item renderer (possibly <code>null</code>). * * @see #setRenderer(XYItemRenderer) */ public XYItemRenderer getRenderer() { return getRenderer(0); } /** * Returns the renderer for a dataset, or <code>null</code>. * * @param index the renderer index. * * @return The renderer (possibly <code>null</code>). * * @see #setRenderer(int, XYItemRenderer) */ public XYItemRenderer getRenderer(int index) { XYItemRenderer result = null; if (this.renderers.size() > index) { result = this.renderers.get(index); } return result; } /** * Sets the renderer for the primary dataset and sends a * {@link PlotChangeEvent} to all registered listeners. If the renderer * is set to <code>null</code>, no data will be displayed. * * @param renderer the renderer (<code>null</code> permitted). * * @see #getRenderer() */ public void setRenderer(XYItemRenderer renderer) { setRenderer(0, renderer); } /** * Sets a renderer and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the index. * @param renderer the renderer. * * @see #getRenderer(int) */ public void setRenderer(int index, XYItemRenderer renderer) { setRenderer(index, renderer, true); } /** * Sets a renderer and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the index. * @param renderer the renderer. * @param notify notify listeners? * * @see #getRenderer(int) */ public void setRenderer(int index, XYItemRenderer renderer, boolean notify) { XYItemRenderer existing = getRenderer(index); if (existing != null) { existing.removeChangeListener(this); } this.renderers.set(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } configureDomainAxes(); configureRangeAxes(); if (notify) { fireChangeEvent(); } } /** * Sets the renderers for this plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param renderers the renderers (<code>null</code> not permitted). */ public void setRenderers(XYItemRenderer[] renderers) { for (int i = 0; i < renderers.length; i++) { setRenderer(i, renderers[i], false); } fireChangeEvent(); } /** * Returns the dataset rendering order. * * @return The order (never <code>null</code>). * * @see #setDatasetRenderingOrder(DatasetRenderingOrder) */ public DatasetRenderingOrder getDatasetRenderingOrder() { return this.datasetRenderingOrder; } /** * Sets the rendering order and sends a {@link PlotChangeEvent} to all * registered listeners. By default, the plot renders the primary dataset * last (so that the primary dataset overlays the secondary datasets). * You can reverse this if you want to. * * @param order the rendering order (<code>null</code> not permitted). * * @see #getDatasetRenderingOrder() */ public void setDatasetRenderingOrder(DatasetRenderingOrder order) { ParamChecks.nullNotPermitted(order, "order"); this.datasetRenderingOrder = order; fireChangeEvent(); } /** * Returns the series rendering order. * * @return the order (never <code>null</code>). * * @see #setSeriesRenderingOrder(SeriesRenderingOrder) */ public SeriesRenderingOrder getSeriesRenderingOrder() { return this.seriesRenderingOrder; } /** * Sets the series order and sends a {@link PlotChangeEvent} to all * registered listeners. By default, the plot renders the primary series * last (so that the primary series appears to be on top). * You can reverse this if you want to. * * @param order the rendering order (<code>null</code> not permitted). * * @see #getSeriesRenderingOrder() */ public void setSeriesRenderingOrder(SeriesRenderingOrder order) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument."); } this.seriesRenderingOrder = order; fireChangeEvent(); } /** * Returns the index of the specified renderer, or <code>-1</code> if the * renderer is not assigned to this plot. * * @param renderer the renderer (<code>null</code> permitted). * * @return The renderer index. */ public int getIndexOf(XYItemRenderer renderer) { return this.renderers.indexOf(renderer); } /** * Returns the renderer for the specified dataset. The code first * determines the index of the dataset, then checks if there is a * renderer with the same index (if not, the method returns renderer(0). * * @param dataset the dataset (<code>null</code> permitted). * * @return The renderer (possibly <code>null</code>). */ public XYItemRenderer getRendererForDataset(XYDataset dataset) { XYItemRenderer result = null; for (int i = 0; i < this.datasets.size(); i++) { if (this.datasets.get(i) == dataset) { result = this.renderers.get(i); if (result == null) { result = getRenderer(); } break; } } return result; } /** * Returns the weight for this plot when it is used as a subplot within a * combined plot. * * @return The weight. * * @see #setWeight(int) */ public int getWeight() { return this.weight; } /** * Sets the weight for the plot and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param weight the weight. * * @see #getWeight() */ public void setWeight(int weight) { this.weight = weight; fireChangeEvent(); } /** * Returns <code>true</code> if the domain gridlines are visible, and * <code>false</code> otherwise. * * @return <code>true</code> or <code>false</code>. * * @see #setDomainGridlinesVisible(boolean) */ public boolean isDomainGridlinesVisible() { return this.domainGridlinesVisible; } /** * Sets the flag that controls whether or not the domain grid-lines are * visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isDomainGridlinesVisible() */ public void setDomainGridlinesVisible(boolean visible) { if (this.domainGridlinesVisible != visible) { this.domainGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns <code>true</code> if the domain minor gridlines are visible, and * <code>false</code> otherwise. * * @return <code>true</code> or <code>false</code>. * * @see #setDomainMinorGridlinesVisible(boolean) * * @since 1.0.12 */ public boolean isDomainMinorGridlinesVisible() { return this.domainMinorGridlinesVisible; } /** * Sets the flag that controls whether or not the domain minor grid-lines * are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isDomainMinorGridlinesVisible() * * @since 1.0.12 */ public void setDomainMinorGridlinesVisible(boolean visible) { if (this.domainMinorGridlinesVisible != visible) { this.domainMinorGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the grid-lines (if any) plotted against the * domain axis. * * @return The stroke (never <code>null</code>). * * @see #setDomainGridlineStroke(Stroke) */ public Stroke getDomainGridlineStroke() { return this.domainGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the domain axis, and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>stroke</code> is * <code>null</code>. * * @see #getDomainGridlineStroke() */ public void setDomainGridlineStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.domainGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the stroke for the minor grid-lines (if any) plotted against the * domain axis. * * @return The stroke (never <code>null</code>). * * @see #setDomainMinorGridlineStroke(Stroke) * * @since 1.0.12 */ public Stroke getDomainMinorGridlineStroke() { return this.domainMinorGridlineStroke; } /** * Sets the stroke for the minor grid lines plotted against the domain * axis, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>stroke</code> is * <code>null</code>. * * @see #getDomainMinorGridlineStroke() * * @since 1.0.12 */ public void setDomainMinorGridlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.domainMinorGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the grid lines (if any) plotted against the domain * axis. * * @return The paint (never <code>null</code>). * * @see #setDomainGridlinePaint(Paint) */ public Paint getDomainGridlinePaint() { return this.domainGridlinePaint; } /** * Sets the paint for the grid lines plotted against the domain axis, and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>paint</code> is * <code>null</code>. * * @see #getDomainGridlinePaint() */ public void setDomainGridlinePaint(Paint paint) { ParamChecks.nullNotPermitted(paint, "paint"); this.domainGridlinePaint = paint; fireChangeEvent(); } /** * Returns the paint for the minor grid lines (if any) plotted against the * domain axis. * * @return The paint (never <code>null</code>). * * @see #setDomainMinorGridlinePaint(Paint) * * @since 1.0.12 */ public Paint getDomainMinorGridlinePaint() { return this.domainMinorGridlinePaint; } /** * Sets the paint for the minor grid lines plotted against the domain axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>paint</code> is * <code>null</code>. * * @see #getDomainMinorGridlinePaint() * * @since 1.0.12 */ public void setDomainMinorGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.domainMinorGridlinePaint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the range axis grid is visible, and * <code>false</code> otherwise. * * @return A boolean. * * @see #setRangeGridlinesVisible(boolean) */ public boolean isRangeGridlinesVisible() { return this.rangeGridlinesVisible; } /** * Sets the flag that controls whether or not the range axis grid lines * are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isRangeGridlinesVisible() */ public void setRangeGridlinesVisible(boolean visible) { if (this.rangeGridlinesVisible != visible) { this.rangeGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the grid lines (if any) plotted against the * range axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeGridlineStroke(Stroke) */ public Stroke getRangeGridlineStroke() { return this.rangeGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the range axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getRangeGridlineStroke() */ public void setRangeGridlineStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.rangeGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the grid lines (if any) plotted against the range * axis. * * @return The paint (never <code>null</code>). * * @see #setRangeGridlinePaint(Paint) */ public Paint getRangeGridlinePaint() { return this.rangeGridlinePaint; } /** * Sets the paint for the grid lines plotted against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeGridlinePaint() */ public void setRangeGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeGridlinePaint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the range axis minor grid is visible, and * <code>false</code> otherwise. * * @return A boolean. * * @see #setRangeMinorGridlinesVisible(boolean) * * @since 1.0.12 */ public boolean isRangeMinorGridlinesVisible() { return this.rangeMinorGridlinesVisible; } /** * Sets the flag that controls whether or not the range axis minor grid * lines are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isRangeMinorGridlinesVisible() * * @since 1.0.12 */ public void setRangeMinorGridlinesVisible(boolean visible) { if (this.rangeMinorGridlinesVisible != visible) { this.rangeMinorGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the minor grid lines (if any) plotted against the * range axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeMinorGridlineStroke(Stroke) * * @since 1.0.12 */ public Stroke getRangeMinorGridlineStroke() { return this.rangeMinorGridlineStroke; } /** * Sets the stroke for the minor grid lines plotted against the range axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getRangeMinorGridlineStroke() * * @since 1.0.12 */ public void setRangeMinorGridlineStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.rangeMinorGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the minor grid lines (if any) plotted against the * range axis. * * @return The paint (never <code>null</code>). * * @see #setRangeMinorGridlinePaint(Paint) * * @since 1.0.12 */ public Paint getRangeMinorGridlinePaint() { return this.rangeMinorGridlinePaint; } /** * Sets the paint for the minor grid lines plotted against the range axis * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeMinorGridlinePaint() * * @since 1.0.12 */ public void setRangeMinorGridlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeMinorGridlinePaint = paint; fireChangeEvent(); } /** * Returns a flag that controls whether or not a zero baseline is * displayed for the domain axis. * * @return A boolean. * * @since 1.0.5 * * @see #setDomainZeroBaselineVisible(boolean) */ public boolean isDomainZeroBaselineVisible() { return this.domainZeroBaselineVisible; } /** * Sets the flag that controls whether or not the zero baseline is * displayed for the domain axis, and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param visible the flag. * * @since 1.0.5 * * @see #isDomainZeroBaselineVisible() */ public void setDomainZeroBaselineVisible(boolean visible) { this.domainZeroBaselineVisible = visible; fireChangeEvent(); } /** * Returns the stroke used for the zero baseline against the domain axis. * * @return The stroke (never <code>null</code>). * * @since 1.0.5 * * @see #setDomainZeroBaselineStroke(Stroke) */ public Stroke getDomainZeroBaselineStroke() { return this.domainZeroBaselineStroke; } /** * Sets the stroke for the zero baseline for the domain axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @since 1.0.5 * * @see #getRangeZeroBaselineStroke() */ public void setDomainZeroBaselineStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.domainZeroBaselineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the zero baseline (if any) plotted against the * domain axis. * * @since 1.0.5 * * @return The paint (never <code>null</code>). * * @see #setDomainZeroBaselinePaint(Paint) */ public Paint getDomainZeroBaselinePaint() { return this.domainZeroBaselinePaint; } /** * Sets the paint for the zero baseline plotted against the domain axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @since 1.0.5 * * @see #getDomainZeroBaselinePaint() */ public void setDomainZeroBaselinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.domainZeroBaselinePaint = paint; fireChangeEvent(); } /** * Returns a flag that controls whether or not a zero baseline is * displayed for the range axis. * * @return A boolean. * * @see #setRangeZeroBaselineVisible(boolean) */ public boolean isRangeZeroBaselineVisible() { return this.rangeZeroBaselineVisible; } /** * Sets the flag that controls whether or not the zero baseline is * displayed for the range axis, and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param visible the flag. * * @see #isRangeZeroBaselineVisible() */ public void setRangeZeroBaselineVisible(boolean visible) { this.rangeZeroBaselineVisible = visible; fireChangeEvent(); } /** * Returns the stroke used for the zero baseline against the range axis. * * @return The stroke (never <code>null</code>). * * @see #setRangeZeroBaselineStroke(Stroke) */ public Stroke getRangeZeroBaselineStroke() { return this.rangeZeroBaselineStroke; } /** * Sets the stroke for the zero baseline for the range axis, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getRangeZeroBaselineStroke() */ public void setRangeZeroBaselineStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.rangeZeroBaselineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the zero baseline (if any) plotted against the * range axis. * * @return The paint (never <code>null</code>). * * @see #setRangeZeroBaselinePaint(Paint) */ public Paint getRangeZeroBaselinePaint() { return this.rangeZeroBaselinePaint; } /** * Sets the paint for the zero baseline plotted against the range axis and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRangeZeroBaselinePaint() */ public void setRangeZeroBaselinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeZeroBaselinePaint = paint; fireChangeEvent(); } /** * Returns the paint used for the domain tick bands. If this is * <code>null</code>, no tick bands will be drawn. * * @return The paint (possibly <code>null</code>). * * @see #setDomainTickBandPaint(Paint) */ public Paint getDomainTickBandPaint() { return this.domainTickBandPaint; } /** * Sets the paint for the domain tick bands. * * @param paint the paint (<code>null</code> permitted). * * @see #getDomainTickBandPaint() */ public void setDomainTickBandPaint(Paint paint) { this.domainTickBandPaint = paint; fireChangeEvent(); } /** * Returns the paint used for the range tick bands. If this is * <code>null</code>, no tick bands will be drawn. * * @return The paint (possibly <code>null</code>). * * @see #setRangeTickBandPaint(Paint) */ public Paint getRangeTickBandPaint() { return this.rangeTickBandPaint; } /** * Sets the paint for the range tick bands. * * @param paint the paint (<code>null</code> permitted). * * @see #getRangeTickBandPaint() */ public void setRangeTickBandPaint(Paint paint) { this.rangeTickBandPaint = paint; fireChangeEvent(); } /** * Returns the origin for the quadrants that can be displayed on the plot. * This defaults to (0, 0). * * @return The origin point (never <code>null</code>). * * @see #setQuadrantOrigin(Point2D) */ public Point2D getQuadrantOrigin() { return this.quadrantOrigin; } /** * Sets the quadrant origin and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param origin the origin (<code>null</code> not permitted). * * @see #getQuadrantOrigin() */ public void setQuadrantOrigin(Point2D origin) { ParamChecks.nullNotPermitted(origin, "origin"); this.quadrantOrigin = origin; fireChangeEvent(); } /** * Returns the paint used for the specified quadrant. * * @param index the quadrant index (0-3). * * @return The paint (possibly <code>null</code>). * * @see #setQuadrantPaint(int, Paint) */ public Paint getQuadrantPaint(int index) { if (index < 0 || index > 3) { throw new IllegalArgumentException("The index value (" + index + ") should be in the range 0 to 3."); } return this.quadrantPaint[index]; } /** * Sets the paint used for the specified quadrant and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the quadrant index (0-3). * @param paint the paint (<code>null</code> permitted). * * @see #getQuadrantPaint(int) */ public void setQuadrantPaint(int index, Paint paint) { if (index < 0 || index > 3) { throw new IllegalArgumentException("The index value (" + index + ") should be in the range 0 to 3."); } this.quadrantPaint[index] = paint; fireChangeEvent(); } /** * Adds a marker for the domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the domain axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * * @see #addDomainMarker(Marker, Layer) * @see #clearDomainMarkers() */ public void addDomainMarker(Marker marker) { // defer argument checking... addDomainMarker(marker, Layer.FOREGROUND); } /** * Adds a marker for the domain axis in the specified layer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the domain axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @see #addDomainMarker(int, Marker, Layer) */ public void addDomainMarker(Marker marker, Layer layer) { addDomainMarker(0, marker, layer); } /** * Clears all the (foreground and background) domain markers and sends a * {@link PlotChangeEvent} to all registered listeners. * * @see #addDomainMarker(int, Marker, Layer) */ public void clearDomainMarkers() { if (this.backgroundDomainMarkers != null) { Set<Integer> keys = this.backgroundDomainMarkers.keySet(); for (Integer key : keys) { clearDomainMarkers(key); } this.backgroundDomainMarkers.clear(); } if (this.foregroundDomainMarkers != null) { Set<Integer> keys = this.foregroundDomainMarkers.keySet(); for (Integer key : keys) { clearDomainMarkers(key); } this.foregroundDomainMarkers.clear(); } fireChangeEvent(); } /** * Clears the (foreground and background) domain markers for a particular * renderer and sends a {@link PlotChangeEvent} to all registered listeners. * * @param key the renderer index. * * @see #clearRangeMarkers(int) */ public void clearDomainMarkers(int key) { if (this.backgroundDomainMarkers != null) { Collection<Marker> markers = this.backgroundDomainMarkers.get(key); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } if (this.foregroundRangeMarkers != null) { Collection<Marker> markers = this.foregroundDomainMarkers.get(key); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } fireChangeEvent(); } /** * Adds a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the domain axis (that the renderer is mapped to), however this is * entirely up to the renderer. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * * @see #clearDomainMarkers(int) * @see #addRangeMarker(int, Marker, Layer) */ public void addDomainMarker(int index, Marker marker, Layer layer) { addDomainMarker(index, marker, layer, true); } /** * Adds a marker for a specific dataset/renderer and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the domain axis (that the renderer is mapped to), however this is * entirely up to the renderer. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * @param notify notify listeners? * * @since 1.0.10 */ public void addDomainMarker(int index, Marker marker, Layer layer, boolean notify) { ParamChecks.nullNotPermitted(marker, "marker"); ParamChecks.nullNotPermitted(layer, "layer"); Collection<Marker> markers; if (layer == Layer.FOREGROUND) { markers = this.foregroundDomainMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.foregroundDomainMarkers.put(index, markers); } markers.add(marker); } else if (layer == Layer.BACKGROUND) { markers = this.backgroundDomainMarkers.get(index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.backgroundDomainMarkers.put(index, markers); } markers.add(marker); } marker.addChangeListener(this); if (notify) { fireChangeEvent(); } } /** * Removes a marker for the domain axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param marker the marker. * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeDomainMarker(Marker marker) { return removeDomainMarker(marker, Layer.FOREGROUND); } /** * Removes a marker for the domain axis in the specified layer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeDomainMarker(Marker marker, Layer layer) { return removeDomainMarker(0, marker, layer); } /** * Removes a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeDomainMarker(int index, Marker marker, Layer layer) { return removeDomainMarker(index, marker, layer, true); } /** * Removes a marker for a specific dataset/renderer and, if requested, * sends a {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * @param notify notify listeners? * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.10 */ public boolean removeDomainMarker(int index, Marker marker, Layer layer, boolean notify) { ArrayList markers; if (layer == Layer.FOREGROUND) { markers = (ArrayList) this.foregroundDomainMarkers.get( index); } else { markers = (ArrayList) this.backgroundDomainMarkers.get( index); } if (markers == null) { return false; } boolean removed = markers.remove(marker); if (removed && notify) { fireChangeEvent(); } return removed; } /** * Adds a marker for the range axis and sends a {@link PlotChangeEvent} to * all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the range axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * * @see #addRangeMarker(Marker, Layer) */ public void addRangeMarker(Marker marker) { addRangeMarker(marker, Layer.FOREGROUND); } /** * Adds a marker for the range axis in the specified layer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the range axis, however this is entirely up to the renderer. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @see #addRangeMarker(int, Marker, Layer) */ public void addRangeMarker(Marker marker, Layer layer) { addRangeMarker(0, marker, layer); } /** * Clears all the range markers and sends a {@link PlotChangeEvent} to all * registered listeners. * * @see #clearRangeMarkers() */ public void clearRangeMarkers() { if (this.backgroundRangeMarkers != null) { Set<Integer> keys = this.backgroundRangeMarkers.keySet(); for (Integer key : keys) { clearRangeMarkers(key); } this.backgroundRangeMarkers.clear(); } if (this.foregroundRangeMarkers != null) { Set<Integer> keys = this.foregroundRangeMarkers.keySet(); for (Integer key : keys) { clearRangeMarkers(key); } this.foregroundRangeMarkers.clear(); } fireChangeEvent(); } /** * Adds a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the range axis, however this is entirely up to the renderer. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * * @see #clearRangeMarkers(int) * @see #addDomainMarker(int, Marker, Layer) */ public void addRangeMarker(int index, Marker marker, Layer layer) { addRangeMarker(index, marker, layer, true); } /** * Adds a marker for a specific dataset/renderer and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * Typically a marker will be drawn by the renderer as a line perpendicular * to the range axis, however this is entirely up to the renderer. * * @param index the dataset/renderer index. * @param marker the marker. * @param layer the layer (foreground or background). * @param notify notify listeners? * * @since 1.0.10 */ public void addRangeMarker(int index, Marker marker, Layer layer, boolean notify) { Collection<Marker> markers; if (layer == Layer.FOREGROUND) { markers = this.foregroundRangeMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.foregroundRangeMarkers.put(index, markers); } markers.add(marker); } else if (layer == Layer.BACKGROUND) { markers = this.backgroundRangeMarkers.get( index); if (markers == null) { markers = new java.util.ArrayList<Marker>(); this.backgroundRangeMarkers.put(index, markers); } markers.add(marker); } marker.addChangeListener(this); if (notify) { fireChangeEvent(); } } /** * Clears the (foreground and background) range markers for a particular * renderer. * * @param key the renderer index. */ public void clearRangeMarkers(int key) { if (this.backgroundRangeMarkers != null) { Collection<Marker> markers = this.backgroundRangeMarkers.get(key); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } if (this.foregroundRangeMarkers != null) { Collection<Marker> markers = this.foregroundRangeMarkers.get(key); if (markers != null) { for (Marker m : markers) { m.removeChangeListener(this); } markers.clear(); } } fireChangeEvent(); } /** * Removes a marker for the range axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param marker the marker. * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeRangeMarker(Marker marker) { return removeRangeMarker(marker, Layer.FOREGROUND); } /** * Removes a marker for the range axis in the specified layer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeRangeMarker(Marker marker, Layer layer) { return removeRangeMarker(0, marker, layer); } /** * Removes a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background). * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.7 */ public boolean removeRangeMarker(int index, Marker marker, Layer layer) { return removeRangeMarker(index, marker, layer, true); } /** * Removes a marker for a specific dataset/renderer and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the dataset/renderer index. * @param marker the marker (<code>null</code> not permitted). * @param layer the layer (foreground or background) (<code>null</code> not permitted). * @param notify notify listeners? * * @return A boolean indicating whether or not the marker was actually * removed. * * @since 1.0.10 */ public boolean removeRangeMarker(int index, Marker marker, Layer layer, boolean notify) { ParamChecks.nullNotPermitted(marker, "marker"); ParamChecks.nullNotPermitted(layer, "layer"); List markers; if (layer == Layer.FOREGROUND) { markers = (List) this.foregroundRangeMarkers.get( index); } else { markers = (List) this.backgroundRangeMarkers.get( index); } if (markers == null) { return false; } boolean removed = markers.remove(marker); if (removed && notify) { fireChangeEvent(); } return removed; } /** * Adds an annotation to the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * * @see #getAnnotations() * @see #removeAnnotation(XYAnnotation) */ public void addAnnotation(XYAnnotation annotation) { addAnnotation(annotation, true); } /** * Adds an annotation to the plot and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * @param notify notify listeners? * * @since 1.0.10 */ public void addAnnotation(XYAnnotation annotation, boolean notify) { ParamChecks.nullNotPermitted(annotation, "annotation"); this.annotations.add(annotation); annotation.addChangeListener(this); if (notify) { fireChangeEvent(); } } /** * Removes an annotation from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * * @return A boolean (indicates whether or not the annotation was removed). * * @see #addAnnotation(XYAnnotation) * @see #getAnnotations() */ public boolean removeAnnotation(XYAnnotation annotation) { return removeAnnotation(annotation, true); } /** * Removes an annotation from the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param annotation the annotation (<code>null</code> not permitted). * @param notify notify listeners? * * @return A boolean (indicates whether or not the annotation was removed). * * @since 1.0.10 */ public boolean removeAnnotation(XYAnnotation annotation, boolean notify) { ParamChecks.nullNotPermitted(annotation, "annotation"); boolean removed = this.annotations.remove(annotation); annotation.removeChangeListener(this); if (removed && notify) { fireChangeEvent(); } return removed; } /** * Returns the list of annotations. * * @return The list of annotations. * * @since 1.0.1 * * @see #addAnnotation(XYAnnotation) */ public List<XYAnnotation> getAnnotations() { return new ArrayList<XYAnnotation>(this.annotations); } /** * Clears all the annotations and sends a {@link PlotChangeEvent} to all * registered listeners. * * @see #addAnnotation(XYAnnotation) */ public void clearAnnotations() { for (XYAnnotation annotation : this.annotations) { annotation.removeChangeListener(this); } this.annotations.clear(); fireChangeEvent(); } /** * Returns the shadow generator for the plot, if any. * * @return The shadow generator (possibly <code>null</code>). * * @since 1.0.14 */ public ShadowGenerator getShadowGenerator() { return this.shadowGenerator; } /** * Sets the shadow generator for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @since 1.0.14 */ public void setShadowGenerator(ShadowGenerator generator) { this.shadowGenerator = generator; fireChangeEvent(); } /** * Calculates the space required for all the axes in the plot. * * @param g2 the graphics device. * @param plotArea the plot area. * * @return The required space. */ protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); space = calculateRangeAxisSpace(g2, plotArea, space); Rectangle2D revPlotArea = space.shrink(plotArea, null); space = calculateDomainAxisSpace(g2, revPlotArea, space); return space; } /** * Calculates the space required for the domain axis/axes. * * @param g2 the graphics device. * @param plotArea the plot area. * @param space a carrier for the result (<code>null</code> permitted). * * @return The required space. */ protected AxisSpace calculateDomainAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) { if (space == null) { space = new AxisSpace(); } // reserve some space for the domain axis... if (this.fixedDomainAxisSpace != null) { if (this.orientation == PlotOrientation.HORIZONTAL) { space.ensureAtLeast(this.fixedDomainAxisSpace.getLeft(), RectangleEdge.LEFT); space.ensureAtLeast(this.fixedDomainAxisSpace.getRight(), RectangleEdge.RIGHT); } else if (this.orientation == PlotOrientation.VERTICAL) { space.ensureAtLeast(this.fixedDomainAxisSpace.getTop(), RectangleEdge.TOP); space.ensureAtLeast(this.fixedDomainAxisSpace.getBottom(), RectangleEdge.BOTTOM); } } else { // reserve space for the domain axes... for (int i = 0; i < this.domainAxes.size(); i++) { Axis axis = this.domainAxes.get(i); if (axis != null) { RectangleEdge edge = getDomainAxisEdge(i); space = axis.reserveSpace(g2, this, plotArea, edge, space); } } } return space; } /** * Calculates the space required for the range axis/axes. * * @param g2 the graphics device. * @param plotArea the plot area. * @param space a carrier for the result (<code>null</code> permitted). * * @return The required space. */ protected AxisSpace calculateRangeAxisSpace(Graphics2D g2, Rectangle2D plotArea, AxisSpace space) { if (space == null) { space = new AxisSpace(); } // reserve some space for the range axis... if (this.fixedRangeAxisSpace != null) { if (this.orientation == PlotOrientation.HORIZONTAL) { space.ensureAtLeast(this.fixedRangeAxisSpace.getTop(), RectangleEdge.TOP); space.ensureAtLeast(this.fixedRangeAxisSpace.getBottom(), RectangleEdge.BOTTOM); } else if (this.orientation == PlotOrientation.VERTICAL) { space.ensureAtLeast(this.fixedRangeAxisSpace.getLeft(), RectangleEdge.LEFT); space.ensureAtLeast(this.fixedRangeAxisSpace.getRight(), RectangleEdge.RIGHT); } } else { // reserve space for the range axes... for (int i = 0; i < this.rangeAxes.size(); i++) { Axis axis = this.rangeAxes.get(i); if (axis != null) { RectangleEdge edge = getRangeAxisEdge(i); space = axis.reserveSpace(g2, this, plotArea, edge, space); } } } return space; } /** * Trims a rectangle to integer coordinates. * * @param rect the incoming rectangle. * * @return A rectangle with integer coordinates. */ private Rectangle integerise(Rectangle2D rect) { int x0 = (int) Math.ceil(rect.getMinX()); int y0 = (int) Math.ceil(rect.getMinY()); int x1 = (int) Math.floor(rect.getMaxX()); int y1 = (int) Math.floor(rect.getMaxY()); return new Rectangle(x0, y0, (x1 - x0), (y1 - y0)); } /** * Draws the plot within the specified area on a graphics device. * * @param g2 the graphics device. * @param area the plot area (in Java2D space). * @param anchor an anchor point in Java2D space (<code>null</code> * permitted). * @param parentState the state from the parent plot, if there is one * (<code>null</code> permitted). * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // if the plot area is too small, just return... boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; } // record the plot area... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); this.axisOffset.trim(dataArea); dataArea = integerise(dataArea); if (dataArea.isEmpty()) { return; } createAndAddEntity((Rectangle2D) dataArea.clone(), info, null, null); if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); Map<Axis, AxisState> axisStateMap = drawAxes(g2, area, dataArea, info); PlotOrientation orient = getOrientation(); // the anchor point is typically the point where the mouse last // clicked - the crosshairs will be driven off this point... if (anchor != null && !dataArea.contains(anchor)) { anchor = null; } CrosshairState crosshairState = new CrosshairState(); crosshairState.setCrosshairDistance(Double.POSITIVE_INFINITY); crosshairState.setAnchor(anchor); crosshairState.setAnchorX(Double.NaN); crosshairState.setAnchorY(Double.NaN); if (anchor != null) { ValueAxis domainAxis = getDomainAxis(); if (domainAxis != null) { double x; if (orient == PlotOrientation.VERTICAL) { x = domainAxis.java2DToValue(anchor.getX(), dataArea, getDomainAxisEdge()); } else { x = domainAxis.java2DToValue(anchor.getY(), dataArea, getDomainAxisEdge()); } crosshairState.setAnchorX(x); } ValueAxis rangeAxis = getRangeAxis(); if (rangeAxis != null) { double y; if (orient == PlotOrientation.VERTICAL) { y = rangeAxis.java2DToValue(anchor.getY(), dataArea, getRangeAxisEdge()); } else { y = rangeAxis.java2DToValue(anchor.getX(), dataArea, getRangeAxisEdge()); } crosshairState.setAnchorY(y); } } crosshairState.setCrosshairX(getDomainCrosshairValue()); crosshairState.setCrosshairY(getRangeCrosshairValue()); Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); AxisState domainAxisState = axisStateMap.get( getDomainAxis()); if (domainAxisState == null) { if (parentState != null) { domainAxisState = parentState.getSharedAxisStates() .get(getDomainAxis()); } } AxisState rangeAxisState = axisStateMap.get(getRangeAxis()); if (rangeAxisState == null) { if (parentState != null) { rangeAxisState = parentState.getSharedAxisStates() .get(getRangeAxis()); } } if (domainAxisState != null) { drawDomainTickBands(g2, dataArea, domainAxisState.getTicks()); } if (rangeAxisState != null) { drawRangeTickBands(g2, dataArea, rangeAxisState.getTicks()); } if (domainAxisState != null) { drawDomainGridlines(g2, dataArea, domainAxisState.getTicks()); drawZeroDomainBaseline(g2, dataArea); } if (rangeAxisState != null) { drawRangeGridlines(g2, dataArea, rangeAxisState.getTicks()); drawZeroRangeBaseline(g2, dataArea); } Graphics2D savedG2 = g2; BufferedImage dataImage = null; if (this.shadowGenerator != null) { dataImage = new BufferedImage((int) dataArea.getWidth(), (int)dataArea.getHeight(), BufferedImage.TYPE_INT_ARGB); g2 = dataImage.createGraphics(); g2.translate(-dataArea.getX(), -dataArea.getY()); g2.setRenderingHints(savedG2.getRenderingHints()); } // draw the markers that are associated with a specific renderer... for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.BACKGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.BACKGROUND); } // now draw annotations and render data items... boolean foundData = false; DatasetRenderingOrder order = getDatasetRenderingOrder(); if (order == DatasetRenderingOrder.FORWARD) { // draw background annotations int rendererCount = this.renderers.size(); for (int i = 0; i < rendererCount; i++) { XYItemRenderer r = getRenderer(i); if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info); } } // render data items... for (int i = 0; i < getDatasetCount(); i++) { foundData = render(g2, dataArea, i, info, crosshairState) || foundData; } // draw foreground annotations for (int i = 0; i < rendererCount; i++) { XYItemRenderer r = getRenderer(i); if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info); } } } else if (order == DatasetRenderingOrder.REVERSE) { // draw background annotations int rendererCount = this.renderers.size(); for (int i = rendererCount - 1; i >= 0; i--) { XYItemRenderer r = getRenderer(i); if (i >= getDatasetCount()) { // we need the dataset to make continue; // a link to the axes } if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.BACKGROUND, info); } } for (int i = getDatasetCount() - 1; i >= 0; i--) { foundData = render(g2, dataArea, i, info, crosshairState) || foundData; } // draw foreground annotations for (int i = rendererCount - 1; i >= 0; i--) { XYItemRenderer r = getRenderer(i); if (i >= getDatasetCount()) { // we need the dataset to make continue; // a link to the axes } if (r != null) { ValueAxis domainAxis = getDomainAxisForDataset(i); ValueAxis rangeAxis = getRangeAxisForDataset(i); r.drawAnnotations(g2, dataArea, domainAxis, rangeAxis, Layer.FOREGROUND, info); } } } // draw domain crosshair if required... int datasetIndex = crosshairState.getDatasetIndex(); ValueAxis xAxis = this.getDomainAxisForDataset(datasetIndex); RectangleEdge xAxisEdge = getDomainAxisEdge(getDomainAxisIndex(xAxis)); if (!this.domainCrosshairLockedOnData && anchor != null) { double xx; if (orient == PlotOrientation.VERTICAL) { xx = xAxis.java2DToValue(anchor.getX(), dataArea, xAxisEdge); } else { xx = xAxis.java2DToValue(anchor.getY(), dataArea, xAxisEdge); } crosshairState.setCrosshairX(xx); } setDomainCrosshairValue(crosshairState.getCrosshairX(), false); if (isDomainCrosshairVisible()) { double x = getDomainCrosshairValue(); Paint paint = getDomainCrosshairPaint(); Stroke stroke = getDomainCrosshairStroke(); drawDomainCrosshair(g2, dataArea, orient, x, xAxis, stroke, paint); } // draw range crosshair if required... ValueAxis yAxis = getRangeAxisForDataset(datasetIndex); RectangleEdge yAxisEdge = getRangeAxisEdge(getRangeAxisIndex(yAxis)); if (!this.rangeCrosshairLockedOnData && anchor != null) { double yy; if (orient == PlotOrientation.VERTICAL) { yy = yAxis.java2DToValue(anchor.getY(), dataArea, yAxisEdge); } else { yy = yAxis.java2DToValue(anchor.getX(), dataArea, yAxisEdge); } crosshairState.setCrosshairY(yy); } setRangeCrosshairValue(crosshairState.getCrosshairY(), false); if (isRangeCrosshairVisible()) { double y = getRangeCrosshairValue(); Paint paint = getRangeCrosshairPaint(); Stroke stroke = getRangeCrosshairStroke(); drawRangeCrosshair(g2, dataArea, orient, y, yAxis, stroke, paint); } if (!foundData) { drawNoDataMessage(g2, dataArea); } for (int i = 0; i < this.renderers.size(); i++) { drawDomainMarkers(g2, dataArea, i, Layer.FOREGROUND); } for (int i = 0; i < this.renderers.size(); i++) { drawRangeMarkers(g2, dataArea, i, Layer.FOREGROUND); } drawAnnotations(g2, dataArea, info); if (this.shadowGenerator != null) { BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage); g2 = savedG2; g2.drawImage(shadowImage, (int) dataArea.getX() + this.shadowGenerator.calculateOffsetX(), (int) dataArea.getY() + this.shadowGenerator.calculateOffsetY(), null); g2.drawImage(dataImage, (int) dataArea.getX(), (int) dataArea.getY(), null); } g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); } /** * Draws the background for the plot. * * @param g2 the graphics device. * @param area the area. */ @Override public void drawBackground(Graphics2D g2, Rectangle2D area) { fillBackground(g2, area, this.orientation); drawQuadrants(g2, area); drawBackgroundImage(g2, area); } /** * Draws the quadrants. * * @param g2 the graphics device. * @param area the area. * * @see #setQuadrantOrigin(Point2D) * @see #setQuadrantPaint(int, Paint) */ protected void drawQuadrants(Graphics2D g2, Rectangle2D area) { // 0 | 1 // --+-- // 2 | 3 boolean somethingToDraw = false; ValueAxis xAxis = getDomainAxis(); if (xAxis == null) { // we can't draw quadrants without a valid x-axis return; } double x = xAxis.getRange().constrain(this.quadrantOrigin.getX()); double xx = xAxis.valueToJava2D(x, area, getDomainAxisEdge()); ValueAxis yAxis = getRangeAxis(); if (yAxis == null) { // we can't draw quadrants without a valid y-axis return; } double y = yAxis.getRange().constrain(this.quadrantOrigin.getY()); double yy = yAxis.valueToJava2D(y, area, getRangeAxisEdge()); double xmin = xAxis.getLowerBound(); double xxmin = xAxis.valueToJava2D(xmin, area, getDomainAxisEdge()); double xmax = xAxis.getUpperBound(); double xxmax = xAxis.valueToJava2D(xmax, area, getDomainAxisEdge()); double ymin = yAxis.getLowerBound(); double yymin = yAxis.valueToJava2D(ymin, area, getRangeAxisEdge()); double ymax = yAxis.getUpperBound(); double yymax = yAxis.valueToJava2D(ymax, area, getRangeAxisEdge()); Rectangle2D[] r = new Rectangle2D[] {null, null, null, null}; if (this.quadrantPaint[0] != null) { if (x > xmin && y < ymax) { if (this.orientation == PlotOrientation.HORIZONTAL) { r[0] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmin, xx), Math.abs(yy - yymax), Math.abs(xx - xxmin)); } else { // PlotOrientation.VERTICAL r[0] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymax, yy), Math.abs(xx - xxmin), Math.abs(yy - yymax)); } somethingToDraw = true; } } if (this.quadrantPaint[1] != null) { if (x < xmax && y < ymax) { if (this.orientation == PlotOrientation.HORIZONTAL) { r[1] = new Rectangle2D.Double(Math.min(yymax, yy), Math.min(xxmax, xx), Math.abs(yy - yymax), Math.abs(xx - xxmax)); } else { // PlotOrientation.VERTICAL r[1] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymax, yy), Math.abs(xx - xxmax), Math.abs(yy - yymax)); } somethingToDraw = true; } } if (this.quadrantPaint[2] != null) { if (x > xmin && y > ymin) { if (this.orientation == PlotOrientation.HORIZONTAL) { r[2] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmin, xx), Math.abs(yy - yymin), Math.abs(xx - xxmin)); } else { // PlotOrientation.VERTICAL r[2] = new Rectangle2D.Double(Math.min(xxmin, xx), Math.min(yymin, yy), Math.abs(xx - xxmin), Math.abs(yy - yymin)); } somethingToDraw = true; } } if (this.quadrantPaint[3] != null) { if (x < xmax && y > ymin) { if (this.orientation == PlotOrientation.HORIZONTAL) { r[3] = new Rectangle2D.Double(Math.min(yymin, yy), Math.min(xxmax, xx), Math.abs(yy - yymin), Math.abs(xx - xxmax)); } else { // PlotOrientation.VERTICAL r[3] = new Rectangle2D.Double(Math.min(xx, xxmax), Math.min(yymin, yy), Math.abs(xx - xxmax), Math.abs(yy - yymin)); } somethingToDraw = true; } } if (somethingToDraw) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getBackgroundAlpha())); for (int i = 0; i < 4; i++) { if (this.quadrantPaint[i] != null && r[i] != null) { g2.setPaint(this.quadrantPaint[i]); g2.fill(r[i]); } } g2.setComposite(originalComposite); } } /** * Draws the domain tick bands, if any. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. * * @see #setDomainTickBandPaint(Paint) */ public void drawDomainTickBands(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { Paint bandPaint = getDomainTickBandPaint(); if (bandPaint != null) { boolean fillBand = false; ValueAxis xAxis = getDomainAxis(); double previous = xAxis.getLowerBound(); for (ValueTick tick : ticks) { double current = tick.getValue(); if (fillBand) { getRenderer().fillDomainGridBand(g2, this, xAxis, dataArea, previous, current); } previous = current; fillBand = !fillBand; } double end = xAxis.getUpperBound(); if (fillBand) { getRenderer().fillDomainGridBand(g2, this, xAxis, dataArea, previous, end); } } } /** * Draws the range tick bands, if any. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. * * @see #setRangeTickBandPaint(Paint) */ public void drawRangeTickBands(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { Paint bandPaint = getRangeTickBandPaint(); if (bandPaint != null) { boolean fillBand = false; ValueAxis axis = getRangeAxis(); double previous = axis.getLowerBound(); for (ValueTick tick : ticks) { double current = tick.getValue(); if (fillBand) { getRenderer().fillRangeGridBand(g2, this, axis, dataArea, previous, current); } previous = current; fillBand = !fillBand; } double end = axis.getUpperBound(); if (fillBand) { getRenderer().fillRangeGridBand(g2, this, axis, dataArea, previous, end); } } } /** * A utility method for drawing the axes. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plotArea the plot area (<code>null</code> not permitted). * @param dataArea the data area (<code>null</code> not permitted). * @param plotState collects information about the plot (<code>null</code> * permitted). * * @return A map containing the state for each axis drawn. */ protected Map<Axis, AxisState> drawAxes(Graphics2D g2, Rectangle2D plotArea, Rectangle2D dataArea, PlotRenderingInfo plotState) { AxisCollection axisCollection = new AxisCollection(); // add domain axes to lists... for (int index = 0; index < this.domainAxes.size(); index++) { ValueAxis axis = this.domainAxes.get(index); if (axis != null) { axisCollection.add(axis, getDomainAxisEdge(index)); } } // add range axes to lists... for (int index = 0; index < this.rangeAxes.size(); index++) { ValueAxis yAxis = this.rangeAxes.get(index); if (yAxis != null) { axisCollection.add(yAxis, getRangeAxisEdge(index)); } } Map<Axis, AxisState> axisStateMap = new HashMap<Axis, AxisState>(); // draw the top axes double cursor = dataArea.getMinY() - this.axisOffset.calculateTopOutset( dataArea.getHeight()); for (Axis axis1 : axisCollection.getAxesAtTop()) { ValueAxis axis = (ValueAxis) axis1; AxisState info = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.TOP, plotState); cursor = info.getCursor(); axisStateMap.put(axis, info); } // draw the bottom axes cursor = dataArea.getMaxY() + this.axisOffset.calculateBottomOutset(dataArea.getHeight()); for (Axis axis1 : axisCollection.getAxesAtBottom()) { ValueAxis axis = (ValueAxis) axis1; AxisState info = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.BOTTOM, plotState); cursor = info.getCursor(); axisStateMap.put(axis, info); } // draw the left axes cursor = dataArea.getMinX() - this.axisOffset.calculateLeftOutset(dataArea.getWidth()); for (Axis axis1 : axisCollection.getAxesAtLeft()) { ValueAxis axis = (ValueAxis) axis1; AxisState info = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.LEFT, plotState); cursor = info.getCursor(); axisStateMap.put(axis, info); } // draw the right axes cursor = dataArea.getMaxX() + this.axisOffset.calculateRightOutset(dataArea.getWidth()); for (Axis axis1 : axisCollection.getAxesAtRight()) { ValueAxis axis = (ValueAxis) axis1; AxisState info = axis.draw(g2, cursor, plotArea, dataArea, RectangleEdge.RIGHT, plotState); cursor = info.getCursor(); axisStateMap.put(axis, info); } return axisStateMap; } /** * Draws a representation of the data within the dataArea region, using the * current renderer. * <P> * The <code>info</code> and <code>crosshairState</code> arguments may be * <code>null</code>. * * @param g2 the graphics device. * @param dataArea the region in which the data is to be drawn. * @param index the dataset index. * @param info an optional object for collection dimension information. * @param crosshairState collects crosshair information * (<code>null</code> permitted). * * @return A flag that indicates whether any data was actually rendered. */ public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info, CrosshairState crosshairState) { boolean foundData = false; XYDataset dataset = getDataset(index); if (!DatasetUtilities.isEmptyOrNull(dataset)) { foundData = true; ValueAxis xAxis = getDomainAxisForDataset(index); ValueAxis yAxis = getRangeAxisForDataset(index); if (xAxis == null || yAxis == null) { return foundData; // can't render anything without axes } XYItemRenderer renderer = getRenderer(index); if (renderer == null) { renderer = getRenderer(); if (renderer == null) { // no default renderer available return foundData; } } XYItemRendererState state = renderer.initialise(g2, dataArea, this, dataset, info); int passCount = renderer.getPassCount(); SeriesRenderingOrder seriesOrder = getSeriesRenderingOrder(); if (seriesOrder == SeriesRenderingOrder.REVERSE) { //render series in reverse order for (int pass = 0; pass < passCount; pass++) { int seriesCount = dataset.getSeriesCount(); for (int series = seriesCount - 1; series >= 0; series--) { int firstItem = 0; int lastItem = dataset.getItemCount(series) - 1; if (lastItem == -1) { continue; } if (state.getProcessVisibleItemsOnly()) { int[] itemBounds = RendererUtilities.findLiveItems( dataset, series, xAxis.getLowerBound(), xAxis.getUpperBound()); firstItem = Math.max(itemBounds[0] - 1, 0); lastItem = Math.min(itemBounds[1] + 1, lastItem); } state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); for (int item = firstItem; item <= lastItem; item++) { renderer.drawItem(g2, state, dataArea, info, this, xAxis, yAxis, dataset, series, item, crosshairState, pass); } state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); } } } else { //render series in forward order for (int pass = 0; pass < passCount; pass++) { int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { int firstItem = 0; int lastItem = dataset.getItemCount(series) - 1; if (state.getProcessVisibleItemsOnly()) { int[] itemBounds = RendererUtilities.findLiveItems( dataset, series, xAxis.getLowerBound(), xAxis.getUpperBound()); firstItem = Math.max(itemBounds[0] - 1, 0); lastItem = Math.min(itemBounds[1] + 1, lastItem); } state.startSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); for (int item = firstItem; item <= lastItem; item++) { renderer.drawItem(g2, state, dataArea, info, this, xAxis, yAxis, dataset, series, item, crosshairState, pass); } state.endSeriesPass(dataset, series, firstItem, lastItem, pass, passCount); } } } } return foundData; } /** * Returns the domain axis for a dataset. * * @param index the dataset index. * * @return The axis. */ public ValueAxis getDomainAxisForDataset(int index) { int upper = Math.max(getDatasetCount(), getRendererCount()); if (index < 0 || index >= upper) { throw new IllegalArgumentException("Index " + index + " out of bounds."); } ValueAxis valueAxis; List<Integer> axisIndices = this.datasetToDomainAxesMap.get( index); if (axisIndices != null) { // the first axis in the list is used for data <--> Java2D Integer axisIndex = axisIndices.get(0); valueAxis = getDomainAxis(axisIndex); } else { valueAxis = getDomainAxis(0); } return valueAxis; } /** * Returns the range axis for a dataset. * * @param index the dataset index. * * @return The axis. */ public ValueAxis getRangeAxisForDataset(int index) { int upper = Math.max(getDatasetCount(), getRendererCount()); if (index < 0 || index >= upper) { throw new IllegalArgumentException("Index " + index + " out of bounds."); } ValueAxis valueAxis; List<Integer> axisIndices = this.datasetToRangeAxesMap.get( index); if (axisIndices != null) { // the first axis in the list is used for data <--> Java2D Integer axisIndex = axisIndices.get(0); valueAxis = getRangeAxis(axisIndex); } else { valueAxis = getRangeAxis(0); } return valueAxis; } /** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the data area. * @param ticks the ticks. * * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List) */ protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> ticks) { // no renderer, no gridlines... if (getRenderer() == null) { return; } // draw the domain grid lines, if any... if (isDomainGridlinesVisible() || isDomainMinorGridlinesVisible()) { Stroke gridStroke = null; Paint gridPaint = null; boolean paintLine; for (ValueTick tick : ticks) { paintLine = false; if ((tick.getTickType() == TickType.MINOR) && isDomainMinorGridlinesVisible()) { gridStroke = getDomainMinorGridlineStroke(); gridPaint = getDomainMinorGridlinePaint(); paintLine = true; } else if ((tick.getTickType() == TickType.MAJOR) && isDomainGridlinesVisible()) { gridStroke = getDomainGridlineStroke(); gridPaint = getDomainGridlinePaint(); paintLine = true; } XYItemRenderer r = getRenderer(); if ((r instanceof AbstractXYItemRenderer) && paintLine) { ((AbstractXYItemRenderer) r).drawDomainLine(g2, this, getDomainAxis(), dataArea, tick.getValue(), gridPaint, gridStroke); } } } } /** * Draws the gridlines for the plot's primary range axis, if they are * visible. * * @param g2 the graphics device. * @param area the data area. * @param ticks the ticks. * * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List) */ protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List<ValueTick> ticks) { // no renderer, no gridlines... if (getRenderer() == null) { return; } // draw the range grid lines, if any... if (isRangeGridlinesVisible() || isRangeMinorGridlinesVisible()) { Stroke gridStroke = null; Paint gridPaint = null; ValueAxis axis = getRangeAxis(); if (axis != null) { boolean paintLine; for (ValueTick tick : ticks) { paintLine = false; if ((tick.getTickType() == TickType.MINOR) && isRangeMinorGridlinesVisible()) { gridStroke = getRangeMinorGridlineStroke(); gridPaint = getRangeMinorGridlinePaint(); paintLine = true; } else if ((tick.getTickType() == TickType.MAJOR) && isRangeGridlinesVisible()) { gridStroke = getRangeGridlineStroke(); gridPaint = getRangeGridlinePaint(); paintLine = true; } if ((tick.getValue() != 0.0 || !isRangeZeroBaselineVisible()) && paintLine) { getRenderer().drawRangeGridline(g2, this, getRangeAxis(), area, tick.getValue(), gridPaint, gridStroke); } } } } } /** * Draws a base line across the chart at value zero on the domain axis. * * @param g2 the graphics device. * @param area the data area. * * @see #setDomainZeroBaselineVisible(boolean) * * @since 1.0.5 */ protected void drawZeroDomainBaseline(Graphics2D g2, Rectangle2D area) { if (isDomainZeroBaselineVisible()) { XYItemRenderer r = getRenderer(); // FIXME: the renderer interface doesn't have the drawDomainLine() // method, so we have to rely on the renderer being a subclass of // AbstractXYItemRenderer (which is lame) if (r instanceof AbstractXYItemRenderer) { AbstractXYItemRenderer renderer = (AbstractXYItemRenderer) r; renderer.drawDomainLine(g2, this, getDomainAxis(), area, 0.0, this.domainZeroBaselinePaint, this.domainZeroBaselineStroke); } } } /** * Draws a base line across the chart at value zero on the range axis. * * @param g2 the graphics device. * @param area the data area. * * @see #setRangeZeroBaselineVisible(boolean) */ protected void drawZeroRangeBaseline(Graphics2D g2, Rectangle2D area) { if (isRangeZeroBaselineVisible()) { getRenderer().drawRangeGridline(g2, this, getRangeAxis(), area, 0.0, this.rangeZeroBaselinePaint, this.rangeZeroBaselineStroke); } } /** * Draws the annotations for the plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param info the chart rendering info. */ public void drawAnnotations(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info) { ValueAxis xAxis = getDomainAxis(); ValueAxis yAxis = getRangeAxis(); for (XYAnnotation annotation : this.annotations) { annotation.draw(g2, this, dataArea, xAxis, yAxis, 0, info); } } /** * Draws the domain markers (if any) for an axis and layer. This method is * typically called from within the draw() method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). */ protected void drawDomainMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { XYItemRenderer r = getRenderer(index); if (r == null) { return; } // check that the renderer has a corresponding dataset (it doesn't // matter if the dataset is null) if (index >= getDatasetCount()) { return; } Collection<Marker> markers = getDomainMarkers(index, layer); ValueAxis axis = getDomainAxisForDataset(index); if (markers != null && axis != null) { for (Marker marker : markers) { r.drawDomainMarker(g2, this, axis, marker, dataArea); } } } /** * Draws the range markers (if any) for a renderer and layer. This method * is typically called from within the draw() method. * * @param g2 the graphics device. * @param dataArea the data area. * @param index the renderer index. * @param layer the layer (foreground or background). */ protected void drawRangeMarkers(Graphics2D g2, Rectangle2D dataArea, int index, Layer layer) { XYItemRenderer r = getRenderer(index); if (r == null) { return; } // check that the renderer has a corresponding dataset (it doesn't // matter if the dataset is null) if (index >= getDatasetCount()) { return; } Collection<Marker> markers = getRangeMarkers(index, layer); ValueAxis axis = getRangeAxisForDataset(index); if (markers != null && axis != null) { for (Marker marker : markers) { r.drawRangeMarker(g2, this, axis, marker, dataArea); } } } /** * Returns the list of domain markers (read only) for the specified layer. * * @param layer the layer (foreground or background). * * @return The list of domain markers. * * @see #getRangeMarkers(Layer) */ public Collection<Marker> getDomainMarkers(Layer layer) { return getDomainMarkers(0, layer); } /** * Returns the list of range markers (read only) for the specified layer. * * @param layer the layer (foreground or background). * * @return The list of range markers. * * @see #getDomainMarkers(Layer) */ public Collection<Marker> getRangeMarkers(Layer layer) { return getRangeMarkers(0, layer); } /** * Returns a collection of domain markers for a particular renderer and * layer. * * @param index the renderer index. * @param layer the layer. * * @return A collection of markers (possibly <code>null</code>). * * @see #getRangeMarkers(int, Layer) */ public Collection<Marker> getDomainMarkers(int index, Layer layer) { Collection<Marker> result = null; Integer key = index; if (layer == Layer.FOREGROUND) { result = this.foregroundDomainMarkers.get(key); } else if (layer == Layer.BACKGROUND) { result = this.backgroundDomainMarkers.get(key); } if (result != null) { result = Collections.unmodifiableCollection(result); } return result; } /** * Returns a collection of range markers for a particular renderer and * layer. * * @param index the renderer index. * @param layer the layer. * * @return A collection of markers (possibly <code>null</code>). * * @see #getDomainMarkers(int, Layer) */ public Collection<Marker> getRangeMarkers(int index, Layer layer) { Collection<Marker> result = null; Integer key = index; if (layer == Layer.FOREGROUND) { result = this.foregroundRangeMarkers.get(key); } else if (layer == Layer.BACKGROUND) { result = this.backgroundRangeMarkers.get(key); } if (result != null) { result = Collections.unmodifiableCollection(result); } return result; } /** * Utility method for drawing a horizontal line across the data area of the * plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawHorizontalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getRangeAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getDomainAxis(); } if (axis.getRange().contains(value)) { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } } /** * Draws a domain crosshair. * * @param g2 the graphics target. * @param dataArea the data area. * @param orientation the plot orientation. * @param value the crosshair value. * @param axis the axis against which the value is measured. * @param stroke the stroke used to draw the crosshair line. * @param paint the paint used to draw the crosshair line. * * @since 1.0.4 */ protected void drawDomainCrosshair(Graphics2D g2, Rectangle2D dataArea, PlotOrientation orientation, double value, ValueAxis axis, Stroke stroke, Paint paint) { if (axis.getRange().contains(value)) { Line2D line; if (orientation == PlotOrientation.VERTICAL) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); } else { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } } /** * Utility method for drawing a vertical line on the data area of the plot. * * @param g2 the graphics device. * @param dataArea the data area. * @param value the coordinate, where to draw the line. * @param stroke the stroke to use. * @param paint the paint to use. */ protected void drawVerticalLine(Graphics2D g2, Rectangle2D dataArea, double value, Stroke stroke, Paint paint) { ValueAxis axis = getDomainAxis(); if (getOrientation() == PlotOrientation.HORIZONTAL) { axis = getRangeAxis(); } if (axis.getRange().contains(value)) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); Line2D line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } } /** * Draws a range crosshair. * * @param g2 the graphics target. * @param dataArea the data area. * @param orientation the plot orientation. * @param value the crosshair value. * @param axis the axis against which the value is measured. * @param stroke the stroke used to draw the crosshair line. * @param paint the paint used to draw the crosshair line. * * @since 1.0.4 */ protected void drawRangeCrosshair(Graphics2D g2, Rectangle2D dataArea, PlotOrientation orientation, double value, ValueAxis axis, Stroke stroke, Paint paint) { if (axis.getRange().contains(value)) { Line2D line; if (orientation == PlotOrientation.HORIZONTAL) { double xx = axis.valueToJava2D(value, dataArea, RectangleEdge.BOTTOM); line = new Line2D.Double(xx, dataArea.getMinY(), xx, dataArea.getMaxY()); } else { double yy = axis.valueToJava2D(value, dataArea, RectangleEdge.LEFT); line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); } g2.setStroke(stroke); g2.setPaint(paint); g2.draw(line); } } /** * Handles a 'click' on the plot by updating the anchor values. * * @param x the x-coordinate, where the click occurred, in Java2D space. * @param y the y-coordinate, where the click occurred, in Java2D space. * @param info object containing information about the plot dimensions. */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { // set the anchor value for the horizontal axis... ValueAxis xaxis = getDomainAxis(); if (xaxis != null) { double hvalue = xaxis.java2DToValue(x, info.getDataArea(), getDomainAxisEdge()); setDomainCrosshairValue(hvalue); } // set the anchor value for the vertical axis... ValueAxis yaxis = getRangeAxis(); if (yaxis != null) { double vvalue = yaxis.java2DToValue(y, info.getDataArea(), getRangeAxisEdge()); setRangeCrosshairValue(vvalue); } } } /** * A utility method that returns a list of datasets that are mapped to a * particular axis. * * @param axisIndex the axis index (<code>null</code> not permitted). * * @return A list of datasets. */ private List<XYDataset> getDatasetsMappedToDomainAxis(Integer axisIndex) { ParamChecks.nullNotPermitted(axisIndex, "axisIndex"); List<XYDataset> result = new ArrayList<XYDataset>(); for (int i = 0; i < this.datasets.size(); i++) { List<Integer> mappedAxes = this.datasetToDomainAxesMap.get( i); if (mappedAxes == null) { if (axisIndex.equals(ZERO)) { result.add(this.datasets.get(i)); } } else { if (mappedAxes.contains(axisIndex)) { result.add(this.datasets.get(i)); } } } return result; } /** * A utility method that returns a list of datasets that are mapped to a * particular axis. * * @param axisIndex the axis index (<code>null</code> not permitted). * * @return A list of datasets. */ private List<XYDataset> getDatasetsMappedToRangeAxis(Integer axisIndex) { ParamChecks.nullNotPermitted(axisIndex, "axisIndex"); List<XYDataset> result = new ArrayList<XYDataset>(); for (int i = 0; i < this.datasets.size(); i++) { List<Integer> mappedAxes = this.datasetToRangeAxesMap.get( i); if (mappedAxes == null) { if (axisIndex.equals(ZERO)) { result.add(this.datasets.get(i)); } } else { if (mappedAxes.contains(axisIndex)) { result.add(this.datasets.get(i)); } } } return result; } /** * Returns the index of the given domain axis. * * @param axis the axis. * * @return The axis index. * * @see #getRangeAxisIndex(ValueAxis) */ public int getDomainAxisIndex(ValueAxis axis) { int result = this.domainAxes.indexOf(axis); if (result < 0) { // try the parent plot Plot parent = getParent(); if (parent instanceof XYPlot) { XYPlot p = (XYPlot) parent; result = p.getDomainAxisIndex(axis); } } return result; } /** * Returns the index of the given range axis. * * @param axis the axis. * * @return The axis index. * * @see #getDomainAxisIndex(ValueAxis) */ public int getRangeAxisIndex(ValueAxis axis) { int result = this.rangeAxes.indexOf(axis); if (result < 0) { // try the parent plot Plot parent = getParent(); if (parent instanceof XYPlot) { XYPlot p = (XYPlot) parent; result = p.getRangeAxisIndex(axis); } } return result; } /** * Returns the range for the specified axis. * * @param axis the axis. * * @return The range. */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; List<XYDataset> mappedDatasets = new ArrayList<XYDataset>(); List<XYAnnotation> includedAnnotations = new ArrayList<XYAnnotation>(); boolean isDomainAxis = true; // is it a domain axis? int domainIndex = getDomainAxisIndex(axis); if (domainIndex >= 0) { isDomainAxis = true; mappedDatasets.addAll(getDatasetsMappedToDomainAxis( domainIndex)); if (domainIndex == 0) { // grab the plot's annotations for (XYAnnotation annotation : this.annotations) { if (annotation instanceof XYAnnotationBoundsInfo) { includedAnnotations.add(annotation); } } } } // or is it a range axis? int rangeIndex = getRangeAxisIndex(axis); if (rangeIndex >= 0) { isDomainAxis = false; mappedDatasets.addAll(getDatasetsMappedToRangeAxis( rangeIndex)); if (rangeIndex == 0) { for (XYAnnotation annotation : this.annotations) { if (annotation instanceof XYAnnotationBoundsInfo) { includedAnnotations.add(annotation); } } } } // iterate through the datasets that map to the axis and get the union // of the ranges. for (XYDataset d : mappedDatasets) { if (d != null) { XYItemRenderer r = getRendererForDataset(d); if (r != null) { if (isDomainAxis) { result = Range.combine(result, r.findDomainBounds(d)); } else { result = Range.combine(result, r.findRangeBounds(d)); } Collection<XYAnnotation> c = r.getAnnotations(); for (XYAnnotation a : c) { if (a instanceof XYAnnotationBoundsInfo) { includedAnnotations.add(a); } } } else { // renderer is null if (isDomainAxis) { result = Range.combine(result, DatasetUtilities.findDomainBounds(d)); } else { result = Range.combine(result, DatasetUtilities.findRangeBounds(d)); } } } } for (XYAnnotation includedAnnotation : includedAnnotations) { XYAnnotationBoundsInfo xyabi = (XYAnnotationBoundsInfo) includedAnnotation; if (xyabi.getIncludeInDataBounds()) { if (isDomainAxis) { result = Range.combine(result, xyabi.getXRange()); } else { result = Range.combine(result, xyabi.getYRange()); } } } return result; } /** * Receives notification of a change to an {@link Annotation} added to * this plot. * * @param event information about the event (not used here). * * @since 1.0.14 */ @Override public void annotationChanged(AnnotationChangeEvent event) { if (getParent() != null) { getParent().annotationChanged(event); } else { PlotChangeEvent e = new PlotChangeEvent(this); notifyListeners(e); } } /** * Receives notification of a change to the plot's dataset. * <P> * The axis ranges are updated if necessary. * * @param event information about the event (not used here). */ @Override public void datasetChanged(DatasetChangeEvent event) { configureDomainAxes(); configureRangeAxes(); if (getParent() != null) { getParent().datasetChanged(event); } else { PlotChangeEvent e = new PlotChangeEvent(this); e.setType(ChartChangeEventType.DATASET_UPDATED); notifyListeners(e); } } /** * Receives notification of a renderer change event. * * @param event the event. */ @Override public void rendererChanged(RendererChangeEvent event) { // if the event was caused by a change to series visibility, then // the axis ranges might need updating... if (event.getSeriesVisibilityChanged()) { configureDomainAxes(); configureRangeAxes(); } fireChangeEvent(); } /** * Returns a flag indicating whether or not the domain crosshair is visible. * * @return The flag. * * @see #setDomainCrosshairVisible(boolean) */ public boolean isDomainCrosshairVisible() { return this.domainCrosshairVisible; } /** * Sets the flag indicating whether or not the domain crosshair is visible * and, if the flag changes, sends a {@link PlotChangeEvent} to all * registered listeners. * * @param flag the new value of the flag. * * @see #isDomainCrosshairVisible() */ public void setDomainCrosshairVisible(boolean flag) { if (this.domainCrosshairVisible != flag) { this.domainCrosshairVisible = flag; fireChangeEvent(); } } /** * Returns a flag indicating whether or not the crosshair should "lock-on" * to actual data values. * * @return The flag. * * @see #setDomainCrosshairLockedOnData(boolean) */ public boolean isDomainCrosshairLockedOnData() { return this.domainCrosshairLockedOnData; } /** * Sets the flag indicating whether or not the domain crosshair should * "lock-on" to actual data values. If the flag value changes, this * method sends a {@link PlotChangeEvent} to all registered listeners. * * @param flag the flag. * * @see #isDomainCrosshairLockedOnData() */ public void setDomainCrosshairLockedOnData(boolean flag) { if (this.domainCrosshairLockedOnData != flag) { this.domainCrosshairLockedOnData = flag; fireChangeEvent(); } } /** * Returns the domain crosshair value. * * @return The value. * * @see #setDomainCrosshairValue(double) */ public double getDomainCrosshairValue() { return this.domainCrosshairValue; } /** * Sets the domain crosshair value and sends a {@link PlotChangeEvent} to * all registered listeners (provided that the domain crosshair is visible). * * @param value the value. * * @see #getDomainCrosshairValue() */ public void setDomainCrosshairValue(double value) { setDomainCrosshairValue(value, true); } /** * Sets the domain crosshair value and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners (provided that the * domain crosshair is visible). * * @param value the new value. * @param notify notify listeners? * * @see #getDomainCrosshairValue() */ public void setDomainCrosshairValue(double value, boolean notify) { this.domainCrosshairValue = value; if (isDomainCrosshairVisible() && notify) { fireChangeEvent(); } } /** * Returns the {@link Stroke} used to draw the crosshair (if visible). * * @return The crosshair stroke (never <code>null</code>). * * @see #setDomainCrosshairStroke(Stroke) * @see #isDomainCrosshairVisible() * @see #getDomainCrosshairPaint() */ public Stroke getDomainCrosshairStroke() { return this.domainCrosshairStroke; } /** * Sets the Stroke used to draw the crosshairs (if visible) and notifies * registered listeners that the axis has been modified. * * @param stroke the new crosshair stroke (<code>null</code> not * permitted). * * @see #getDomainCrosshairStroke() */ public void setDomainCrosshairStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.domainCrosshairStroke = stroke; fireChangeEvent(); } /** * Returns the domain crosshair paint. * * @return The crosshair paint (never <code>null</code>). * * @see #setDomainCrosshairPaint(Paint) * @see #isDomainCrosshairVisible() * @see #getDomainCrosshairStroke() */ public Paint getDomainCrosshairPaint() { return this.domainCrosshairPaint; } /** * Sets the paint used to draw the crosshairs (if visible) and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the new crosshair paint (<code>null</code> not permitted). * * @see #getDomainCrosshairPaint() */ public void setDomainCrosshairPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.domainCrosshairPaint = paint; fireChangeEvent(); } /** * Returns a flag indicating whether or not the range crosshair is visible. * * @return The flag. * * @see #setRangeCrosshairVisible(boolean) * @see #isDomainCrosshairVisible() */ public boolean isRangeCrosshairVisible() { return this.rangeCrosshairVisible; } /** * Sets the flag indicating whether or not the range crosshair is visible. * If the flag value changes, this method sends a {@link PlotChangeEvent} * to all registered listeners. * * @param flag the new value of the flag. * * @see #isRangeCrosshairVisible() */ public void setRangeCrosshairVisible(boolean flag) { if (this.rangeCrosshairVisible != flag) { this.rangeCrosshairVisible = flag; fireChangeEvent(); } } /** * Returns a flag indicating whether or not the crosshair should "lock-on" * to actual data values. * * @return The flag. * * @see #setRangeCrosshairLockedOnData(boolean) */ public boolean isRangeCrosshairLockedOnData() { return this.rangeCrosshairLockedOnData; } /** * Sets the flag indicating whether or not the range crosshair should * "lock-on" to actual data values. If the flag value changes, this method * sends a {@link PlotChangeEvent} to all registered listeners. * * @param flag the flag. * * @see #isRangeCrosshairLockedOnData() */ public void setRangeCrosshairLockedOnData(boolean flag) { if (this.rangeCrosshairLockedOnData != flag) { this.rangeCrosshairLockedOnData = flag; fireChangeEvent(); } } /** * Returns the range crosshair value. * * @return The value. * * @see #setRangeCrosshairValue(double) */ public double getRangeCrosshairValue() { return this.rangeCrosshairValue; } /** * Sets the range crosshair value. * <P> * Registered listeners are notified that the plot has been modified, but * only if the crosshair is visible. * * @param value the new value. * * @see #getRangeCrosshairValue() */ public void setRangeCrosshairValue(double value) { setRangeCrosshairValue(value, true); } /** * Sets the range crosshair value and sends a {@link PlotChangeEvent} to * all registered listeners, but only if the crosshair is visible. * * @param value the new value. * @param notify a flag that controls whether or not listeners are * notified. * * @see #getRangeCrosshairValue() */ public void setRangeCrosshairValue(double value, boolean notify) { this.rangeCrosshairValue = value; if (isRangeCrosshairVisible() && notify) { fireChangeEvent(); } } /** * Returns the stroke used to draw the crosshair (if visible). * * @return The crosshair stroke (never <code>null</code>). * * @see #setRangeCrosshairStroke(Stroke) * @see #isRangeCrosshairVisible() * @see #getRangeCrosshairPaint() */ public Stroke getRangeCrosshairStroke() { return this.rangeCrosshairStroke; } /** * Sets the stroke used to draw the crosshairs (if visible) and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param stroke the new crosshair stroke (<code>null</code> not * permitted). * * @see #getRangeCrosshairStroke() */ public void setRangeCrosshairStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.rangeCrosshairStroke = stroke; fireChangeEvent(); } /** * Returns the range crosshair paint. * * @return The crosshair paint (never <code>null</code>). * * @see #setRangeCrosshairPaint(Paint) * @see #isRangeCrosshairVisible() * @see #getRangeCrosshairStroke() */ public Paint getRangeCrosshairPaint() { return this.rangeCrosshairPaint; } /** * Sets the paint used to color the crosshairs (if visible) and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the new crosshair paint (<code>null</code> not permitted). * * @see #getRangeCrosshairPaint() */ public void setRangeCrosshairPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rangeCrosshairPaint = paint; fireChangeEvent(); } /** * Returns the fixed domain axis space. * * @return The fixed domain axis space (possibly <code>null</code>). * * @see #setFixedDomainAxisSpace(AxisSpace) */ public AxisSpace getFixedDomainAxisSpace() { return this.fixedDomainAxisSpace; } /** * Sets the fixed domain axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). * * @see #getFixedDomainAxisSpace() */ public void setFixedDomainAxisSpace(AxisSpace space) { setFixedDomainAxisSpace(space, true); } /** * Sets the fixed domain axis space and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param space the space (<code>null</code> permitted). * @param notify notify listeners? * * @see #getFixedDomainAxisSpace() * * @since 1.0.9 */ public void setFixedDomainAxisSpace(AxisSpace space, boolean notify) { this.fixedDomainAxisSpace = space; if (notify) { fireChangeEvent(); } } /** * Returns the fixed range axis space. * * @return The fixed range axis space (possibly <code>null</code>). * * @see #setFixedRangeAxisSpace(AxisSpace) */ public AxisSpace getFixedRangeAxisSpace() { return this.fixedRangeAxisSpace; } /** * Sets the fixed range axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). * * @see #getFixedRangeAxisSpace() */ public void setFixedRangeAxisSpace(AxisSpace space) { setFixedRangeAxisSpace(space, true); } /** * Sets the fixed range axis space and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param space the space (<code>null</code> permitted). * @param notify notify listeners? * * @see #getFixedRangeAxisSpace() * * @since 1.0.9 */ public void setFixedRangeAxisSpace(AxisSpace space, boolean notify) { this.fixedRangeAxisSpace = space; if (notify) { fireChangeEvent(); } } /** * Returns <code>true</code> if panning is enabled for the domain axes, * and <code>false</code> otherwise. * * @return A boolean. * * @since 1.0.13 */ @Override public boolean isDomainPannable() { return this.domainPannable; } /** * Sets the flag that enables or disables panning of the plot along the * domain axes. * * @param pannable the new flag value. * * @since 1.0.13 */ public void setDomainPannable(boolean pannable) { this.domainPannable = pannable; } /** * Returns <code>true</code> if panning is enabled for the range axes, * and <code>false</code> otherwise. * * @return A boolean. * * @since 1.0.13 */ @Override public boolean isRangePannable() { return this.rangePannable; } /** * Sets the flag that enables or disables panning of the plot along * the range axes. * * @param pannable the new flag value. * * @since 1.0.13 */ public void setRangePannable(boolean pannable) { this.rangePannable = pannable; } /** * Pans the domain axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.13 */ @Override public void panDomainAxes(double percent, PlotRenderingInfo info, Point2D source) { if (!isDomainPannable()) { return; } int domainAxisCount = getDomainAxisCount(); for (int i = 0; i < domainAxisCount; i++) { ValueAxis axis = getDomainAxis(i); if (axis == null) { continue; } if (axis.isInverted()) { percent = -percent; } axis.pan(percent); } } /** * Pans the range axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.13 */ @Override public void panRangeAxes(double percent, PlotRenderingInfo info, Point2D source) { if (!isRangePannable()) { return; } int rangeAxisCount = getRangeAxisCount(); for (int i = 0; i < rangeAxisCount; i++) { ValueAxis axis = getRangeAxis(i); if (axis == null) { continue; } if (axis.isInverted()) { percent = -percent; } axis.pan(percent); } } /** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point (in Java2D space). * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D) */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source) { // delegate to other method zoomDomainAxes(factor, info, source, false); } /** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // perform the zoom on each domain axis for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis domainAxis = this.domainAxes.get(i); if (domainAxis != null) { if (useAnchor) { // get the relevant source coordinate given the plot // orientation double sourceX = source.getX(); if (this.orientation == PlotOrientation.HORIZONTAL) { sourceX = source.getY(); } double anchorX = domainAxis.java2DToValue(sourceX, info.getDataArea(), getDomainAxisEdge()); domainAxis.resizeRange2(factor, anchorX); } else { domainAxis.resizeRange(factor); } } } } /** * Zooms in on the domain axis/axes. The new lower and upper bounds are * specified as percentages of the current axis range, where 0 percent is * the current lower bound and 100 percent is the current upper bound. * * @param lowerPercent a percentage that determines the new lower bound * for the axis (e.g. 0.20 is twenty percent). * @param upperPercent a percentage that determines the new upper bound * for the axis (e.g. 0.80 is eighty percent). * @param info the plot rendering info. * @param source the source point (ignored). * * @see #zoomRangeAxes(double, double, PlotRenderingInfo, Point2D) */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis domainAxis = this.domainAxes.get(i); if (domainAxis != null) { domainAxis.zoomRange(lowerPercent, upperPercent); } } } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source) { // delegate to other method zoomRangeAxes(factor, info, source, false); } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point. * @param useAnchor a flag that controls whether or not the source point * is used for the zoom anchor. * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // perform the zoom on each range axis for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = this.rangeAxes.get(i); if (rangeAxis != null) { if (useAnchor) { // get the relevant source coordinate given the plot // orientation double sourceY = source.getY(); if (this.orientation == PlotOrientation.HORIZONTAL) { sourceY = source.getX(); } double anchorY = rangeAxis.java2DToValue(sourceY, info.getDataArea(), getRangeAxisEdge()); rangeAxis.resizeRange2(factor, anchorY); } else { rangeAxis.resizeRange(factor); } } } } /** * Zooms in on the range axes. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param info the plot rendering info. * @param source the source point. * * @see #zoomDomainAxes(double, double, PlotRenderingInfo, Point2D) */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis rangeAxis = this.rangeAxes.get(i); if (rangeAxis != null) { rangeAxis.zoomRange(lowerPercent, upperPercent); } } } /** * Returns <code>true</code>, indicating that the domain axis/axes for this * plot are zoomable. * * @return A boolean. * * @see #isRangeZoomable() */ @Override public boolean isDomainZoomable() { return true; } /** * Returns <code>true</code>, indicating that the range axis/axes for this * plot are zoomable. * * @return A boolean. * * @see #isDomainZoomable() */ @Override public boolean isRangeZoomable() { return true; } /** * Returns the number of series in the primary dataset for this plot. If * the dataset is <code>null</code>, the method returns 0. * * @return The series count. */ public int getSeriesCount() { int result = 0; XYDataset dataset = getDataset(); if (dataset != null) { result = dataset.getSeriesCount(); } return result; } /** * Returns the fixed legend items, if any. * * @return The legend items (possibly <code>null</code>). * * @see #setFixedLegendItems(LegendItemCollection) */ public List<LegendItem> getFixedLegendItems() { return this.fixedLegendItems; } /** * Sets the fixed legend items for the plot. Leave this set to * <code>null</code> if you prefer the legend items to be created * automatically. * * @param items the legend items (<code>null</code> permitted). * * @see #getFixedLegendItems() */ public void setFixedLegendItems(List<LegendItem> items) { this.fixedLegendItems = items; fireChangeEvent(); } /** * Returns the legend items for the plot. Each legend item is generated by * the plot's renderer, since the renderer is responsible for the visual * representation of the data. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { if (this.fixedLegendItems != null) { return this.fixedLegendItems; } List<LegendItem> result = new ArrayList<LegendItem>(); int count = this.datasets.size(); for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) { XYDataset dataset = getDataset(datasetIndex); if (dataset != null) { XYItemRenderer renderer = getRenderer(datasetIndex); if (renderer == null) { renderer = getRenderer(0); } if (renderer != null) { int seriesCount = dataset.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { if (renderer.isSeriesVisible(i) && renderer.isSeriesVisibleInLegend(i)) { LegendItem item = renderer.getLegendItem( datasetIndex, i); if (item != null) { result.add(item); } } } } } } return result; } /** * Tests this plot for equality with another object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof XYPlot)) { return false; } XYPlot that = (XYPlot) obj; if (this.weight != that.weight) { return false; } if (this.orientation != that.orientation) { return false; } if (!this.domainAxes.equals(that.domainAxes)) { return false; } if (!this.domainAxisLocations.equals(that.domainAxisLocations)) { return false; } if (this.rangeCrosshairLockedOnData != that.rangeCrosshairLockedOnData) { return false; } if (this.domainGridlinesVisible != that.domainGridlinesVisible) { return false; } if (this.rangeGridlinesVisible != that.rangeGridlinesVisible) { return false; } if (this.domainMinorGridlinesVisible != that.domainMinorGridlinesVisible) { return false; } if (this.rangeMinorGridlinesVisible != that.rangeMinorGridlinesVisible) { return false; } if (this.domainZeroBaselineVisible != that.domainZeroBaselineVisible) { return false; } if (this.rangeZeroBaselineVisible != that.rangeZeroBaselineVisible) { return false; } if (this.domainCrosshairVisible != that.domainCrosshairVisible) { return false; } if (this.domainCrosshairValue != that.domainCrosshairValue) { return false; } if (this.domainCrosshairLockedOnData != that.domainCrosshairLockedOnData) { return false; } if (this.rangeCrosshairVisible != that.rangeCrosshairVisible) { return false; } if (this.rangeCrosshairValue != that.rangeCrosshairValue) { return false; } if (!ObjectUtilities.equal(this.axisOffset, that.axisOffset)) { return false; } if (!ObjectUtilities.equal(this.renderers, that.renderers)) { return false; } if (!ObjectUtilities.equal(this.rangeAxes, that.rangeAxes)) { return false; } if (!this.rangeAxisLocations.equals(that.rangeAxisLocations)) { return false; } if (!ObjectUtilities.equal(this.datasetToDomainAxesMap, that.datasetToDomainAxesMap)) { return false; } if (!ObjectUtilities.equal(this.datasetToRangeAxesMap, that.datasetToRangeAxesMap)) { return false; } if (!ObjectUtilities.equal(this.domainGridlineStroke, that.domainGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.domainGridlinePaint, that.domainGridlinePaint)) { return false; } if (!ObjectUtilities.equal(this.rangeGridlineStroke, that.rangeGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.rangeGridlinePaint, that.rangeGridlinePaint)) { return false; } if (!ObjectUtilities.equal(this.domainMinorGridlineStroke, that.domainMinorGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.domainMinorGridlinePaint, that.domainMinorGridlinePaint)) { return false; } if (!ObjectUtilities.equal(this.rangeMinorGridlineStroke, that.rangeMinorGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.rangeMinorGridlinePaint, that.rangeMinorGridlinePaint)) { return false; } if (!PaintUtilities.equal(this.domainZeroBaselinePaint, that.domainZeroBaselinePaint)) { return false; } if (!ObjectUtilities.equal(this.domainZeroBaselineStroke, that.domainZeroBaselineStroke)) { return false; } if (!PaintUtilities.equal(this.rangeZeroBaselinePaint, that.rangeZeroBaselinePaint)) { return false; } if (!ObjectUtilities.equal(this.rangeZeroBaselineStroke, that.rangeZeroBaselineStroke)) { return false; } if (!ObjectUtilities.equal(this.domainCrosshairStroke, that.domainCrosshairStroke)) { return false; } if (!PaintUtilities.equal(this.domainCrosshairPaint, that.domainCrosshairPaint)) { return false; } if (!ObjectUtilities.equal(this.rangeCrosshairStroke, that.rangeCrosshairStroke)) { return false; } if (!PaintUtilities.equal(this.rangeCrosshairPaint, that.rangeCrosshairPaint)) { return false; } if (!ObjectUtilities.equal(this.foregroundDomainMarkers, that.foregroundDomainMarkers)) { return false; } if (!ObjectUtilities.equal(this.backgroundDomainMarkers, that.backgroundDomainMarkers)) { return false; } if (!ObjectUtilities.equal(this.foregroundRangeMarkers, that.foregroundRangeMarkers)) { return false; } if (!ObjectUtilities.equal(this.backgroundRangeMarkers, that.backgroundRangeMarkers)) { return false; } if (!ObjectUtilities.equal(this.foregroundDomainMarkers, that.foregroundDomainMarkers)) { return false; } if (!ObjectUtilities.equal(this.backgroundDomainMarkers, that.backgroundDomainMarkers)) { return false; } if (!ObjectUtilities.equal(this.foregroundRangeMarkers, that.foregroundRangeMarkers)) { return false; } if (!ObjectUtilities.equal(this.backgroundRangeMarkers, that.backgroundRangeMarkers)) { return false; } if (!ObjectUtilities.equal(this.annotations, that.annotations)) { return false; } if (!ObjectUtilities.equal(this.fixedLegendItems, that.fixedLegendItems)) { return false; } if (!PaintUtilities.equal(this.domainTickBandPaint, that.domainTickBandPaint)) { return false; } if (!PaintUtilities.equal(this.rangeTickBandPaint, that.rangeTickBandPaint)) { return false; } if (!this.quadrantOrigin.equals(that.quadrantOrigin)) { return false; } for (int i = 0; i < 4; i++) { if (!PaintUtilities.equal(this.quadrantPaint[i], that.quadrantPaint[i])) { return false; } } if (!ObjectUtilities.equal(this.shadowGenerator, that.shadowGenerator)) { return false; } return super.equals(obj); } /** * Returns dLeft/dRight value of selection interval (timestamp) * * @param rect the selection rectangle * @param info the plot rendering info. * @param select 0 - dLeft, 1 - dRight * @return A double. * */ public double getJava2dToValue(Rectangle2D rect, PlotRenderingInfo info, int select) { double temp = 0; for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis domainAxis = (ValueAxis) this.domainAxes.get(i); temp = domainAxis.java2DToValue( (select == 0 ? rect.getMinX() : rect.getMaxX()), info.getDataArea(), getDomainAxisEdge()); } return temp; } /** * Returns dLeft/dRight value of selection interval (in Java2D) * * @param dValue the selection rectangle * @param info the plot rendering info. * @return A double. * */ public double getValueToJava2d(double dValue, PlotRenderingInfo info) { double temp = 0; for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis domainAxis = (ValueAxis) this.domainAxes.get(i); temp = domainAxis.valueToJava2D( dValue, info.getDataArea(), getDomainAxisEdge()); } return temp; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this can occur if some component of * the plot cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { XYPlot clone = (XYPlot) super.clone(); clone.domainAxes = ObjectUtilities.clone(this.domainAxes); for (int i = 0; i < this.domainAxes.size(); i++) { ValueAxis axis = this.domainAxes.get(i); if (axis != null) { ValueAxis clonedAxis = (ValueAxis) axis.clone(); clone.domainAxes.set(i, clonedAxis); clonedAxis.setPlot(clone); clonedAxis.addChangeListener(clone); } } clone.domainAxisLocations = (ObjectList<AxisLocation>) this.domainAxisLocations.clone(); clone.rangeAxes = ObjectUtilities.clone(this.rangeAxes); for (int i = 0; i < this.rangeAxes.size(); i++) { ValueAxis axis = this.rangeAxes.get(i); if (axis != null) { ValueAxis clonedAxis = (ValueAxis) axis.clone(); clone.rangeAxes.set(i, clonedAxis); clonedAxis.setPlot(clone); clonedAxis.addChangeListener(clone); } } clone.rangeAxisLocations = ObjectUtilities.clone( this.rangeAxisLocations); // the datasets are not cloned, but listeners need to be added... clone.datasets = ObjectUtilities.clone(this.datasets); for (int i = 0; i < clone.datasets.size(); ++i) { XYDataset d = getDataset(i); if (d != null) { d.addChangeListener(clone); } } clone.datasetToDomainAxesMap = new TreeMap<Integer, List<Integer>>(); clone.datasetToDomainAxesMap.putAll(this.datasetToDomainAxesMap); clone.datasetToRangeAxesMap = new TreeMap<Integer, List<Integer>>(); clone.datasetToRangeAxesMap.putAll(this.datasetToRangeAxesMap); clone.renderers = ObjectUtilities.clone(this.renderers); for (int i = 0; i < this.renderers.size(); i++) { XYItemRenderer renderer2 = this.renderers.get(i); if (renderer2 instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) renderer2; XYItemRenderer rc = (XYItemRenderer) pc.clone(); clone.renderers.set(i, rc); rc.setPlot(clone); rc.addChangeListener(clone); } } clone.foregroundDomainMarkers = ObjectUtilities.clone( this.foregroundDomainMarkers); clone.backgroundDomainMarkers = ObjectUtilities.clone( this.backgroundDomainMarkers); clone.foregroundRangeMarkers = ObjectUtilities.clone( this.foregroundRangeMarkers); clone.backgroundRangeMarkers = ObjectUtilities.clone( this.backgroundRangeMarkers); clone.annotations = ObjectUtilities.deepClone(this.annotations); if (this.fixedDomainAxisSpace != null) { clone.fixedDomainAxisSpace = ObjectUtilities.clone( this.fixedDomainAxisSpace); } if (this.fixedRangeAxisSpace != null) { clone.fixedRangeAxisSpace = ObjectUtilities.clone( this.fixedRangeAxisSpace); } if (this.fixedLegendItems != null) { clone.fixedLegendItems = ObjectUtilities.deepClone(this.fixedLegendItems); } clone.quadrantOrigin = ObjectUtilities.clone( this.quadrantOrigin); clone.quadrantPaint = this.quadrantPaint.clone(); return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.domainGridlineStroke, stream); SerialUtilities.writePaint(this.domainGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeGridlineStroke, stream); SerialUtilities.writePaint(this.rangeGridlinePaint, stream); SerialUtilities.writeStroke(this.domainMinorGridlineStroke, stream); SerialUtilities.writePaint(this.domainMinorGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeMinorGridlineStroke, stream); SerialUtilities.writePaint(this.rangeMinorGridlinePaint, stream); SerialUtilities.writeStroke(this.rangeZeroBaselineStroke, stream); SerialUtilities.writePaint(this.rangeZeroBaselinePaint, stream); SerialUtilities.writeStroke(this.domainCrosshairStroke, stream); SerialUtilities.writePaint(this.domainCrosshairPaint, stream); SerialUtilities.writeStroke(this.rangeCrosshairStroke, stream); SerialUtilities.writePaint(this.rangeCrosshairPaint, stream); SerialUtilities.writePaint(this.domainTickBandPaint, stream); SerialUtilities.writePaint(this.rangeTickBandPaint, stream); SerialUtilities.writePoint2D(this.quadrantOrigin, stream); for (int i = 0; i < 4; i++) { SerialUtilities.writePaint(this.quadrantPaint[i], stream); } SerialUtilities.writeStroke(this.domainZeroBaselineStroke, stream); SerialUtilities.writePaint(this.domainZeroBaselinePaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.domainGridlineStroke = SerialUtilities.readStroke(stream); this.domainGridlinePaint = SerialUtilities.readPaint(stream); this.rangeGridlineStroke = SerialUtilities.readStroke(stream); this.rangeGridlinePaint = SerialUtilities.readPaint(stream); this.domainMinorGridlineStroke = SerialUtilities.readStroke(stream); this.domainMinorGridlinePaint = SerialUtilities.readPaint(stream); this.rangeMinorGridlineStroke = SerialUtilities.readStroke(stream); this.rangeMinorGridlinePaint = SerialUtilities.readPaint(stream); this.rangeZeroBaselineStroke = SerialUtilities.readStroke(stream); this.rangeZeroBaselinePaint = SerialUtilities.readPaint(stream); this.domainCrosshairStroke = SerialUtilities.readStroke(stream); this.domainCrosshairPaint = SerialUtilities.readPaint(stream); this.rangeCrosshairStroke = SerialUtilities.readStroke(stream); this.rangeCrosshairPaint = SerialUtilities.readPaint(stream); this.domainTickBandPaint = SerialUtilities.readPaint(stream); this.rangeTickBandPaint = SerialUtilities.readPaint(stream); this.quadrantOrigin = SerialUtilities.readPoint2D(stream); this.quadrantPaint = new Paint[4]; for (int i = 0; i < 4; i++) { this.quadrantPaint[i] = SerialUtilities.readPaint(stream); } this.domainZeroBaselineStroke = SerialUtilities.readStroke(stream); this.domainZeroBaselinePaint = SerialUtilities.readPaint(stream); // register the plot as a listener with its axes, datasets, and // renderers... int domainAxisCount = this.domainAxes.size(); for (int i = 0; i < domainAxisCount; i++) { Axis axis = this.domainAxes.get(i); if (axis != null) { axis.setPlot(this); axis.addChangeListener(this); } } int rangeAxisCount = this.rangeAxes.size(); for (int i = 0; i < rangeAxisCount; i++) { Axis axis = this.rangeAxes.get(i); if (axis != null) { axis.setPlot(this); axis.addChangeListener(this); } } int datasetCount = this.datasets.size(); for (int i = 0; i < datasetCount; i++) { Dataset dataset = this.datasets.get(i); if (dataset != null) { dataset.addChangeListener(this); } } int rendererCount = this.renderers.size(); for (int i = 0; i < rendererCount; i++) { XYItemRenderer renderer = this.renderers.get(i); if (renderer != null) { renderer.addChangeListener(this); } } } }
198,838
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DrawingSupplier.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/DrawingSupplier.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * DrawingSupplier.java * -------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Jan-2003 : Version 1 (DG); * 17-Jan-2003 : Renamed PaintSupplier --> DrawingSupplier (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 13-Jun-2007 : Added getNextOutlinePaint() method. * */ package org.jfree.chart.plot; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; /** * A supplier of <code>Paint</code>, <code>Stroke</code> and <code>Shape</code> * objects for use by plots and renderers. By providing a central place for * obtaining these items, we can ensure that duplication is avoided. * <p> * To support the cloning of charts, classes that implement this interface * should also implement <code>PublicCloneable</code>. */ public interface DrawingSupplier { /** * Returns the next paint in a sequence maintained by the supplier. * * @return The paint. */ public Paint getNextPaint(); /** * Returns the next outline paint in a sequence maintained by the supplier. * * @return The paint. */ public Paint getNextOutlinePaint(); /** * Returns the next fill paint in a sequence maintained by the supplier. * * @return The paint. * * @since 1.0.6 */ public Paint getNextFillPaint(); /** * Returns the next <code>Stroke</code> object in a sequence maintained by * the supplier. * * @return The stroke. */ public Stroke getNextStroke(); /** * Returns the next <code>Stroke</code> object in a sequence maintained by * the supplier. * * @return The stroke. */ public Stroke getNextOutlineStroke(); /** * Returns the next <code>Shape</code> object in a sequence maintained by * the supplier. * * @return The shape. */ public Shape getNextShape(); }
3,297
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CombinedRangeXYPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CombinedRangeXYPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * CombinedRangeXYPlot.java * ------------------------ * (C) Copyright 2001-2014, by Bill Kelemen and Contributors. * * Original Author: Bill Kelemen; * Contributor(s): David Gilbert (for Object Refinery Limited); * Anthony Boulestreau; * David Basten; * Kevin Frechette (for ISTI); * Arnaud Lelievre; * Nicolas Brodu; * Petr Kubanek (bug 1606205); * * Changes: * -------- * 06-Dec-2001 : Version 1 (BK); * 12-Dec-2001 : Removed unnecessary 'throws' clause from constructor (DG); * 18-Dec-2001 : Added plotArea attribute and get/set methods (BK); * 22-Dec-2001 : Fixed bug in chartChanged with multiple combinations of * CombinedPlots (BK); * 08-Jan-2002 : Moved to new package com.jrefinery.chart.combination (DG); * 25-Feb-2002 : Updated import statements (DG); * 28-Feb-2002 : Readded "this.plotArea = plotArea" that was deleted from * draw() method (BK); * 26-Mar-2002 : Added an empty zoom method (this method needs to be written * so that combined plots will support zooming (DG); * 29-Mar-2002 : Changed the method createCombinedAxis adding the creation of * OverlaidSymbolicAxis and CombinedSymbolicAxis(AB); * 23-Apr-2002 : Renamed CombinedPlot-->MultiXYPlot, and simplified the * structure (DG); * 23-May-2002 : Renamed (again) MultiXYPlot-->CombinedXYPlot (DG); * 19-Jun-2002 : Added get/setGap() methods suggested by David Basten (DG); * 25-Jun-2002 : Removed redundant imports (DG); * 16-Jul-2002 : Draws shared axis after subplots (to fix missing gridlines), * added overrides of 'setSeriesPaint()' and 'setXYItemRenderer()' * that pass changes down to subplots (KF); * 09-Oct-2002 : Added add(XYPlot) method (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 16-May-2003 : Renamed CombinedXYPlot --> CombinedRangeXYPlot (DG); * 26-Jun-2003 : Fixed bug 755547 (DG); * 16-Jul-2003 : Removed getSubPlots() method (duplicate of getSubplots()) (DG); * 08-Aug-2003 : Adjusted totalWeight in remove() method (DG); * 21-Aug-2003 : Implemented Cloneable (DG); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 11-Sep-2003 : Fix cloning support (subplots) (NB); * 15-Sep-2003 : Fixed error in cloning (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 17-Sep-2003 : Updated handling of 'clicks' (DG); * 12-Nov-2004 : Implements the new Zoomable interface (DG); * 25-Nov-2004 : Small update to clone() implementation (DG); * 21-Feb-2005 : The getLegendItems() method now returns the fixed legend * items if set (DG); * 05-May-2005 : Removed unused draw() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 13-Sep-2006 : Updated API docs (DG); * 06-Feb-2007 : Fixed bug 1606205, draw shared axis after subplots (DG); * 23-Mar-2007 : Reverted previous patch (DG); * 17-Apr-2007 : Added null argument checks to findSubplot() (DG); * 18-Jul-2007 : Fixed bug in removeSubplot (DG); * 27-Nov-2007 : Modified setFixedDomainAxisSpaceForSubplots() so as not to * trigger change events in subplots (DG); * 27-Mar-2008 : Add documentation for getDataRange() method (DG); * 31-Mar-2008 : Updated getSubplots() to return EMPTY_LIST for null * subplots, as suggested by Richard West (DG); * 28-Apr-2008 : Fixed zooming problem (see bug 1950037) (DG); * 11-Aug-2008 : Don't store totalWeight of subplots, calculate it as * required (DG); * 21-Dec-2011 : Apply patch 3447161 by Ulrich Voigt and Martin Hoeller (MH); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.ShadowGenerator; import org.jfree.data.Range; /** * An extension of {@link XYPlot} that contains multiple subplots that share a * common range axis. */ public class CombinedRangeXYPlot extends XYPlot implements PlotChangeListener { /** For serialization. */ private static final long serialVersionUID = -5177814085082031168L; /** Storage for the subplot references. */ private List<XYPlot> subplots; /** The gap between subplots. */ private double gap = 5.0; /** Temporary storage for the subplot areas. */ private transient Rectangle2D[] subplotAreas; /** * Default constructor. */ public CombinedRangeXYPlot() { this(new NumberAxis()); } /** * Creates a new plot. * * @param rangeAxis the shared axis. */ public CombinedRangeXYPlot(ValueAxis rangeAxis) { super(null, // no data in the parent plot null, rangeAxis, null); this.subplots = new java.util.ArrayList<XYPlot>(); } /** * Returns a string describing the type of plot. * * @return The type of plot. */ @Override public String getPlotType() { return localizationResources.getString("Combined_Range_XYPlot"); } /** * Returns the space between subplots. * * @return The gap. * * @see #setGap(double) */ public double getGap() { return this.gap; } /** * Sets the amount of space between subplots. * * @param gap the gap between subplots. * * @see #getGap() */ public void setGap(double gap) { this.gap = gap; } /** * Adds a subplot, with a default 'weight' of 1. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to <code>null</code>. * * @param subplot the subplot. */ public void add(XYPlot subplot) { add(subplot, 1); } /** * Adds a subplot with a particular weight (greater than or equal to one). * The weight determines how much space is allocated to the subplot * relative to all the other subplots. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to <code>null</code>. * * @param subplot the subplot (<code>null</code> not permitted). * @param weight the weight (must be 1 or greater). */ public void add(XYPlot subplot, int weight) { ParamChecks.nullNotPermitted(subplot, "subplot"); if (weight <= 0) { String msg = "The 'weight' must be positive."; throw new IllegalArgumentException(msg); } // store the plot and its weight subplot.setParent(this); subplot.setWeight(weight); subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); subplot.setRangeAxis(null); subplot.addChangeListener(this); this.subplots.add(subplot); configureRangeAxes(); fireChangeEvent(); } /** * Removes a subplot from the combined chart. * * @param subplot the subplot (<code>null</code> not permitted). */ public void remove(XYPlot subplot) { ParamChecks.nullNotPermitted(subplot, "subplot"); int position = -1; int size = this.subplots.size(); int i = 0; while (position == -1 && i < size) { if (this.subplots.get(i) == subplot) { position = i; } i++; } if (position != -1) { this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); configureRangeAxes(); fireChangeEvent(); } } /** * Returns the list of subplots. The returned list may be empty, but is * never <code>null</code>. * * @return An unmodifiable list of subplots. */ public List<XYPlot> getSubplots() { if (this.subplots != null) { return Collections.unmodifiableList(this.subplots); } else { return Collections.EMPTY_LIST; } } /** * Calculates the space required for the axes. * * @param g2 the graphics device. * @param plotArea the plot area. * * @return The space required for the axes. */ @Override protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); PlotOrientation orientation = getOrientation(); // work out the space required by the domain axis... AxisSpace fixed = getFixedRangeAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.VERTICAL) { space.setLeft(fixed.getLeft()); space.setRight(fixed.getRight()); } else if (orientation == PlotOrientation.HORIZONTAL) { space.setTop(fixed.getTop()); space.setBottom(fixed.getBottom()); } } else { ValueAxis valueAxis = getRangeAxis(); RectangleEdge valueEdge = Plot.resolveRangeAxisLocation( getRangeAxisLocation(), orientation ); if (valueAxis != null) { space = valueAxis.reserveSpace(g2, this, plotArea, valueEdge, space); } } Rectangle2D adjustedPlotArea = space.shrink(plotArea, null); // work out the maximum height or width of the non-shared axes... int n = this.subplots.size(); int totalWeight = 0; for (XYPlot sub : this.subplots) { totalWeight += sub.getWeight(); } // calculate plotAreas of all sub-plots, maximum vertical/horizontal // axis width/height this.subplotAreas = new Rectangle2D[n]; double x = adjustedPlotArea.getX(); double y = adjustedPlotArea.getY(); double usableSize = 0.0; if (orientation == PlotOrientation.VERTICAL) { usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1); } else if (orientation == PlotOrientation.HORIZONTAL) { usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1); } for (int i = 0; i < n; i++) { XYPlot plot = this.subplots.get(i); // calculate sub-plot area if (orientation == PlotOrientation.VERTICAL) { double w = usableSize * plot.getWeight() / totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight()); x = x + w + this.gap; } else if (orientation == PlotOrientation.HORIZONTAL) { double h = usableSize * plot.getWeight() / totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h); y = y + h + this.gap; } AxisSpace subSpace = plot.calculateDomainAxisSpace(g2, this.subplotAreas[i], null); space.ensureAtLeast(subSpace); } return space; } /** * Draws the plot within the specified area on a graphics device. * * @param g2 the graphics device. * @param area the plot area (in Java2D space). * @param anchor an anchor point in Java2D space (<code>null</code> * permitted). * @param parentState the state from the parent plot, if there is one * (<code>null</code> permitted). * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); //this.axisOffset.trim(dataArea); // set the width and height of non-shared axis of all sub-plots setFixedDomainAxisSpaceForSubplots(space); // draw the shared axis ValueAxis axis = getRangeAxis(); RectangleEdge edge = getRangeAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, edge); AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info); if (parentState == null) { parentState = new PlotState(); } parentState.getSharedAxisStates().put(axis, axisState); // draw all the charts for (int i = 0; i < this.subplots.size(); i++) { XYPlot plot = this.subplots.get(i); PlotRenderingInfo subplotInfo = null; if (info != null) { subplotInfo = new PlotRenderingInfo(info.getOwner()); info.addSubplotInfo(subplotInfo); } plot.draw(g2, this.subplotAreas[i], anchor, parentState, subplotInfo); } if (info != null) { info.setDataArea(dataArea); } } /** * Returns a collection of legend items for the plot. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = getFixedLegendItems(); if (result != null) { return result; } result = new ArrayList<LegendItem>(); if (this.subplots != null) { for (XYPlot subplot : subplots) { List<LegendItem> more = subplot.getLegendItems(); result.addAll(more); } } return result; } /** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source) { zoomDomainAxes(factor, info, source, false); } /** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). * @param useAnchor zoom about the anchor point? */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // delegate 'info' and 'source' argument checks... XYPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomDomainAxes(factor, info, source, useAnchor); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... for (XYPlot innerSubplot : getSubplots()) { innerSubplot.zoomDomainAxes(factor, info, source, useAnchor); } } } /** * Zooms in on the domain axes. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { // delegate 'info' and 'source' argument checks... XYPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomDomainAxes(lowerPercent, upperPercent, info, source); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... for (XYPlot innerSubplot : getSubplots()) { innerSubplot.zoomDomainAxes(lowerPercent, upperPercent, info, source); } } } /** * Pans all domain axes by the specified percentage. * * @param panRange the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.15 */ @Override public void panDomainAxes(double panRange, PlotRenderingInfo info, Point2D source) { // if the isDomainPannable flag is set for the combined plot, we should // pan for all the subplots, otherwise just the one under the mouse // pointer List<XYPlot> plotsToPan = new ArrayList<XYPlot>(); if (isDomainPannable()) { plotsToPan.addAll(this.subplots); } else { plotsToPan.add(findSubplot(info, source)); } for (XYPlot subplot : plotsToPan) { if (subplot == null) { continue; } if (isDomainPannable() || subplot.isDomainPannable()) { for (int i = 0; i < subplot.getDomainAxisCount(); i++) { ValueAxis domainAxis = subplot.getDomainAxis(i); domainAxis.pan(panRange); } } } } /** * Returns the subplot (if any) that contains the (x, y) point (specified * in Java2D space). * * @param info the chart rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). * * @return A subplot (possibly <code>null</code>). */ public XYPlot findSubplot(PlotRenderingInfo info, Point2D source) { ParamChecks.nullNotPermitted(info, "info"); ParamChecks.nullNotPermitted(source, "source"); XYPlot result = null; int subplotIndex = info.getSubplotIndex(source); if (subplotIndex >= 0) { result = this.subplots.get(subplotIndex); } return result; } /** * Sets the item renderer FOR ALL SUBPLOTS. Registered listeners are * notified that the plot has been modified. * <P> * Note: usually you will want to set the renderer independently for each * subplot, which is NOT what this method does. * * @param renderer the new renderer. */ @Override public void setRenderer(XYItemRenderer renderer) { super.setRenderer(renderer); // not strictly necessary, since the // renderer set for the // parent plot is not used for (XYPlot subplot : this.subplots) { subplot.setRenderer(renderer); } } /** * Sets the orientation for the plot (and all its subplots). * * @param orientation the orientation (<code>null</code> not permitted). */ @Override public void setOrientation(PlotOrientation orientation) { super.setOrientation(orientation); for (XYPlot subplot : this.subplots) { subplot.setOrientation(orientation); } } /** * Sets the shadow generator for the plot (and all subplots) and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param generator the new generator (<code>null</code> permitted). */ @Override public void setShadowGenerator(ShadowGenerator generator) { setNotify(false); super.setShadowGenerator(generator); for (XYPlot subplot : this.subplots) { subplot.setShadowGenerator(generator); } setNotify(true); } /** * Returns a range representing the extent of the data values in this plot * (obtained from the subplots) that will be rendered against the specified * axis. NOTE: This method is intended for internal JFreeChart use, and * is public only so that code in the axis classes can call it. Since * only the range axis is shared between subplots, the JFreeChart code * will only call this method for the range values (although this is not * checked/enforced). * * @param axis the axis. * * @return The range. */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; if (this.subplots != null) { for (XYPlot subplot : this.subplots) { result = Range.combine(result, subplot.getDataRange(axis)); } } return result; } /** * Sets the space (width or height, depending on the orientation of the * plot) for the domain axis of each subplot. * * @param space the space. */ protected void setFixedDomainAxisSpaceForSubplots(AxisSpace space) { for (XYPlot subplot : this.subplots) { subplot.setFixedDomainAxisSpace(space, false); } } /** * Handles a 'click' on the plot by updating the anchor values... * * @param x x-coordinate, where the click occurred. * @param y y-coordinate, where the click occurred. * @param info object containing information about the plot dimensions. */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { for (int i = 0; i < this.subplots.size(); i++) { XYPlot subplot = this.subplots.get(i); PlotRenderingInfo subplotInfo = info.getSubplotInfo(i); subplot.handleClick(x, y, subplotInfo); } } } /** * Receives a {@link PlotChangeEvent} and responds by notifying all * listeners. * * @param event the event. */ @Override public void plotChanged(PlotChangeEvent event) { notifyListeners(event); } /** * Tests this plot for equality with another object. * * @param obj the other object. * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CombinedRangeXYPlot)) { return false; } CombinedRangeXYPlot that = (CombinedRangeXYPlot) obj; if (this.gap != that.gap) { return false; } if (!ObjectUtilities.equal(this.subplots, that.subplots)) { return false; } return super.equals(obj); } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { CombinedRangeXYPlot result = (CombinedRangeXYPlot) super.clone(); result.subplots = (List<XYPlot>) ObjectUtilities.deepClone(this.subplots); for (XYPlot subplot : result.subplots) { subplot.setParent(result); } // after setting up all the subplots, the shared range axis may need // reconfiguring ValueAxis rangeAxis = result.getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } return result; } }
25,933
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PiePlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PiePlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------ * PiePlot.java * ------------ * (C) Copyright 2000-2014, by Andrzej Porebski and Contributors. * * Original Author: Andrzej Porebski; * Contributor(s): David Gilbert (for Object Refinery Limited); * Martin Cordova (percentages in labels); * Richard Atkinson (URL support for image maps); * Christian W. Zuckschwerdt; * Arnaud Lelievre; * Martin Hilpert (patch 1891849); * Andreas Schroeder (very minor); * Christoph Beck (bug 2121818); * * Changes * ------- * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG); * 18-Sep-2001 : Updated header (DG); * 15-Oct-2001 : Data source classes moved to com.jrefinery.data.* (DG); * 19-Oct-2001 : Moved series paint and stroke methods from JFreeChart.java to * Plot.java (DG); * 22-Oct-2001 : Renamed DataSource.java --> Dataset.java etc. (DG); * 13-Nov-2001 : Modified plot subclasses so that null axes are possible for * pie plot (DG); * 17-Nov-2001 : Added PieDataset interface and amended this class accordingly, * and completed removal of BlankAxis class as it is no longer * required (DG); * 19-Nov-2001 : Changed 'drawCircle' property to 'circular' property (DG); * 21-Nov-2001 : Added options for exploding pie sections and filled out range * of properties (DG); * Added option for percentages in chart labels, based on code * by Martin Cordova (DG); * 30-Nov-2001 : Changed default font from "Arial" --> "SansSerif" (DG); * 12-Dec-2001 : Removed unnecessary 'throws' clause in constructor (DG); * 13-Dec-2001 : Added tooltips (DG); * 16-Jan-2002 : Renamed tooltips class (DG); * 22-Jan-2002 : Fixed bug correlating legend labels with pie data (DG); * 05-Feb-2002 : Added alpha-transparency to plot class, and updated * constructors accordingly (DG); * 06-Feb-2002 : Added optional background image and alpha-transparency to Plot * and subclasses. Clipped drawing within plot area (DG); * 26-Mar-2002 : Added an empty zoom method (DG); * 18-Apr-2002 : PieDataset is no longer sorted (oldman); * 23-Apr-2002 : Moved dataset from JFreeChart to Plot. Added * getLegendItemLabels() method (DG); * 19-Jun-2002 : Added attributes to control starting angle and direction * (default is now clockwise) (DG); * 25-Jun-2002 : Removed redundant imports (DG); * 02-Jul-2002 : Fixed sign of percentage bug introduced in 0.9.2 (DG); * 16-Jul-2002 : Added check for null dataset in getLegendItemLabels() (DG); * 30-Jul-2002 : Moved summation code to DatasetUtilities (DG); * 05-Aug-2002 : Added URL support for image maps - new member variable for * urlGenerator, modified constructor and minor change to the * draw method (RA); * 18-Sep-2002 : Modified the percent label creation and added setters for the * formatters (AS); * 24-Sep-2002 : Added getLegendItems() method (DG); * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 09-Oct-2002 : Added check for null entity collection (DG); * 30-Oct-2002 : Changed PieDataset interface (DG); * 18-Nov-2002 : Changed CategoryDataset to TableDataset (DG); * 02-Jan-2003 : Fixed "no data" message (DG); * 23-Jan-2003 : Modified to extract data from rows OR columns in * CategoryDataset (DG); * 14-Feb-2003 : Fixed label drawing so that foreground alpha does not apply * (bug id 685536) (DG); * 07-Mar-2003 : Modified to pass pieIndex on to PieSectionEntity and tooltip * and URL generators (DG); * 21-Mar-2003 : Added a minimum angle for drawing arcs * (see bug id 620031) (DG); * 24-Apr-2003 : Switched around PieDataset and KeyedValuesDataset (DG); * 02-Jun-2003 : Fixed bug 721733 (DG); * 30-Jul-2003 : Modified entity constructor (CZ); * 19-Aug-2003 : Implemented Cloneable (DG); * 29-Aug-2003 : Fixed bug 796936 (null pointer on setOutlinePaint()) (DG); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 29-Oct-2003 : Added workaround for font alignment in PDF output (DG); * 05-Nov-2003 : Fixed missing legend bug (DG); * 10-Nov-2003 : Re-added the DatasetChangeListener to constructors (CZ); * 29-Jan-2004 : Fixed clipping bug in draw() method (DG); * 11-Mar-2004 : Major overhaul to improve labelling (DG); * 31-Mar-2004 : Made an adjustment for the plot area when the label generator * is null. Fixed null pointer exception when the label * generator returns null for a label (DG); * 06-Apr-2004 : Added getter, setter, serialization and draw support for * labelBackgroundPaint (AS); * 08-Apr-2004 : Added flag to control whether null values are ignored or * not (DG); * 15-Apr-2004 : Fixed some minor warnings from Eclipse (DG); * 26-Apr-2004 : Added attributes for label outline and shadow (DG); * 04-Oct-2004 : Renamed ShapeUtils --> ShapeUtilities (DG); * 04-Nov-2004 : Fixed null pointer exception with new LegendTitle class (DG); * 09-Nov-2004 : Added user definable legend item shape (DG); * 25-Nov-2004 : Added new legend label generator (DG); * 20-Apr-2005 : Added a tool tip generator for legend labels (DG); * 26-Apr-2005 : Removed LOGGER (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 10-May-2005 : Added flag to control visibility of label linking lines, plus * another flag to control the handling of zero values (DG); * 08-Jun-2005 : Fixed bug in getLegendItems() method (not respecting flags * for ignoring null and zero values), and fixed equals() method * to handle GradientPaint (DG); * 15-Jul-2005 : Added sectionOutlinesVisible attribute (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 09-Jan-2006 : Fixed bug 1400442, inconsistent treatment of null and zero * values in dataset (DG); * 28-Feb-2006 : Fixed bug 1440415, bad distribution of pie section * labels (DG); * 27-Sep-2006 : Initialised baseSectionPaint correctly, added lookup methods * for section paint, outline paint and outline stroke (DG); * 27-Sep-2006 : Refactored paint and stroke methods to use keys rather than * section indices (DG); * 03-Oct-2006 : Replaced call to JRE 1.5 method (DG); * 23-Nov-2006 : Added support for URLs for the legend items (DG); * 24-Nov-2006 : Cloning fixes (DG); * 17-Apr-2007 : Check for null label in legend items (DG); * 19-Apr-2007 : Deprecated override settings (DG); * 18-May-2007 : Set dataset for LegendItem (DG); * 14-Jun-2007 : Added label distributor attribute (DG); * 18-Jul-2007 : Added simple label option (DG); * 21-Nov-2007 : Fixed labelling bugs, added debug code, restored default * white background (DG); * 19-Mar-2008 : Fixed IllegalArgumentException when drawing with null * dataset (DG); * 31-Mar-2008 : Adjust the label area for the interiorGap (DG); * 31-Mar-2008 : Added quad and cubic curve label link lines - see patch * 1891849 by Martin Hilpert (DG); * 02-Jul-2008 : Added autoPopulate flags (DG); * 15-Aug-2008 : Added methods to clear section attributes (DG); * 15-Aug-2008 : Fixed bug 2051168 - problem with LegendItemEntity * generation (DG); * 23-Sep-2008 : Added getLabelLinkDepth() method - see bug 2121818 reported * by Christoph Beck (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 10-Jul-2009 : Added optional drop shadow generator (DG); * 03-Sep-2009 : Fixed bug where sinmpleLabelOffset is ignored (DG); * 04-Nov-2009 : Add mouse wheel rotation support (DG); * 18-Oct-2011 : Fixed tooltip offset with shadow generator (DG); * 20-Nov-2011 : Initialise shadow generator as null (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * 01-Jul-2012 : Removed deprecated code (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.CubicCurve2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.QuadCurve2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.TreeMap; import org.jfree.chart.LegendItem; import org.jfree.chart.PaintMap; import org.jfree.chart.StrokeMap; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.PieSectionEntity; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.labels.PieSectionLabelGenerator; import org.jfree.chart.labels.PieToolTipGenerator; import org.jfree.chart.labels.StandardPieSectionLabelGenerator; import org.jfree.chart.text.G2TextMeasurer; import org.jfree.chart.text.TextBlock; import org.jfree.chart.text.TextBox; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.urls.PieURLGenerator; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.Rotation; import org.jfree.chart.util.SerialUtilities; import org.jfree.chart.util.ShadowGenerator; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.UnitType; import org.jfree.data.DefaultKeyedValues; import org.jfree.data.KeyedValues; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.general.PieDataset; /** * A plot that displays data in the form of a pie chart, using data from any * class that implements the {@link PieDataset} interface. * The example shown here is generated by the <code>PieChartDemo2.java</code> * program included in the JFreeChart Demo Collection: * <br><br> * <img src="../../../../images/PiePlotSample.png" * alt="PiePlotSample.png" /> * <P> * Special notes: * <ol> * <li>the default starting point is 12 o'clock and the pie sections proceed * in a clockwise direction, but these settings can be changed;</li> * <li>negative values in the dataset are ignored;</li> * <li>there are utility methods for creating a {@link PieDataset} from a * {@link org.jfree.data.category.CategoryDataset};</li> * </ol> * * @see Plot * @see PieDataset */ public class PiePlot extends Plot implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -795612466005590431L; /** The default interior gap. */ public static final double DEFAULT_INTERIOR_GAP = 0.08; /** The maximum interior gap (currently 40%). */ public static final double MAX_INTERIOR_GAP = 0.40; /** The default starting angle for the pie chart. */ public static final double DEFAULT_START_ANGLE = 90.0; /** The default section label font. */ public static final Font DEFAULT_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); /** The default section label paint. */ public static final Paint DEFAULT_LABEL_PAINT = Color.BLACK; /** The default section label background paint. */ public static final Paint DEFAULT_LABEL_BACKGROUND_PAINT = new Color(255, 255, 192); /** The default section label outline paint. */ public static final Paint DEFAULT_LABEL_OUTLINE_PAINT = Color.BLACK; /** The default section label outline stroke. */ public static final Stroke DEFAULT_LABEL_OUTLINE_STROKE = new BasicStroke( 0.5f); /** The default section label shadow paint. */ public static final Paint DEFAULT_LABEL_SHADOW_PAINT = new Color(151, 151, 151, 128); /** The default minimum arc angle to draw. */ public static final double DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW = 0.00001; /** The dataset for the pie chart. */ private PieDataset dataset; /** The pie index (used by the {@link MultiplePiePlot} class). */ private int pieIndex; /** * The amount of space left around the outside of the pie plot, expressed * as a percentage of the plot area width and height. */ private double interiorGap; /** Flag determining whether to draw an ellipse or a perfect circle. */ private boolean circular; /** The starting angle. */ private double startAngle; /** The direction for the pie segments. */ private Rotation direction; /** The section paint map. */ private PaintMap sectionPaintMap; /** The base section paint (fallback). */ private transient Paint baseSectionPaint; /** * A flag that controls whether or not the section paint is auto-populated * from the drawing supplier. * * @since 1.0.11 */ private boolean autoPopulateSectionPaint; /** * A flag that controls whether or not an outline is drawn for each * section in the plot. */ private boolean sectionOutlinesVisible; /** The section outline paint map. */ private PaintMap sectionOutlinePaintMap; /** The base section outline paint (fallback). */ private transient Paint baseSectionOutlinePaint; /** * A flag that controls whether or not the section outline paint is * auto-populated from the drawing supplier. * * @since 1.0.11 */ private boolean autoPopulateSectionOutlinePaint; /** The section outline stroke map. */ private StrokeMap sectionOutlineStrokeMap; /** The base section outline stroke (fallback). */ private transient Stroke baseSectionOutlineStroke; /** * A flag that controls whether or not the section outline stroke is * auto-populated from the drawing supplier. * * @since 1.0.11 */ private boolean autoPopulateSectionOutlineStroke; /** The shadow paint. */ private transient Paint shadowPaint = Color.GRAY; /** The x-offset for the shadow effect. */ private double shadowXOffset = 4.0f; /** The y-offset for the shadow effect. */ private double shadowYOffset = 4.0f; /** The percentage amount to explode each pie section. */ private Map<Comparable, Number> explodePercentages; /** The section label generator. */ private PieSectionLabelGenerator labelGenerator; /** The font used to display the section labels. */ private Font labelFont; /** The color used to draw the section labels. */ private transient Paint labelPaint; /** * The color used to draw the background of the section labels. If this * is <code>null</code>, the background is not filled. */ private transient Paint labelBackgroundPaint; /** * The paint used to draw the outline of the section labels * (<code>null</code> permitted). */ private transient Paint labelOutlinePaint; /** * The stroke used to draw the outline of the section labels * (<code>null</code> permitted). */ private transient Stroke labelOutlineStroke; /** * The paint used to draw the shadow for the section labels * (<code>null</code> permitted). */ private transient Paint labelShadowPaint; /** * A flag that controls whether simple or extended labels are used. * * @since 1.0.7 */ private boolean simpleLabels = true; /** * The padding between the labels and the label outlines. This is not * allowed to be <code>null</code>. * * @since 1.0.7 */ private RectangleInsets labelPadding; /** * The simple label offset. * * @since 1.0.7 */ private RectangleInsets simpleLabelOffset; /** The maximum label width as a percentage of the plot width. */ private double maximumLabelWidth = 0.14; /** * The gap between the labels and the link corner, as a percentage of the * plot width. */ private double labelGap = 0.025; /** A flag that controls whether or not the label links are drawn. */ private boolean labelLinksVisible; /** * The label link style. * * @since 1.0.10 */ private PieLabelLinkStyle labelLinkStyle = PieLabelLinkStyle.STANDARD; /** The link margin. */ private double labelLinkMargin = 0.025; /** The paint used for the label linking lines. */ private transient Paint labelLinkPaint = Color.BLACK; /** The stroke used for the label linking lines. */ private transient Stroke labelLinkStroke = new BasicStroke(0.5f); /** * The pie section label distributor. * * @since 1.0.6 */ private AbstractPieLabelDistributor labelDistributor; /** The tooltip generator. */ private PieToolTipGenerator toolTipGenerator; /** The URL generator. */ private PieURLGenerator urlGenerator; /** The legend label generator. */ private PieSectionLabelGenerator legendLabelGenerator; /** A tool tip generator for the legend. */ private PieSectionLabelGenerator legendLabelToolTipGenerator; /** * A URL generator for the legend items (optional). * * @since 1.0.4. */ private PieURLGenerator legendLabelURLGenerator; /** * A flag that controls whether <code>null</code> values are ignored. */ private boolean ignoreNullValues; /** * A flag that controls whether zero values are ignored. */ private boolean ignoreZeroValues; /** The legend item shape. */ private transient Shape legendItemShape; /** * The smallest arc angle that will get drawn (this is to avoid a bug in * various Java implementations that causes the JVM to crash). See this * link for details: * * http://www.jfree.org/phpBB2/viewtopic.php?t=2707 * * ...and this bug report in the Java Bug Parade: * * http://developer.java.sun.com/developer/bugParade/bugs/4836495.html */ private double minimumArcAngleToDraw; /** * The shadow generator for the plot (<code>null</code> permitted). * * @since 1.0.14 */ private ShadowGenerator shadowGenerator; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** * This debug flag controls whether or not an outline is drawn showing the * interior of the plot region. This is drawn as a lightGray rectangle * showing the padding provided by the 'interiorGap' setting. */ static final boolean DEBUG_DRAW_INTERIOR = false; /** * This debug flag controls whether or not an outline is drawn showing the * link area (in blue) and link ellipse (in yellow). This controls where * the label links have 'elbow' points. */ static final boolean DEBUG_DRAW_LINK_AREA = false; /** * This debug flag controls whether or not an outline is drawn showing * the pie area (in green). */ static final boolean DEBUG_DRAW_PIE_AREA = false; /** * Creates a new plot. The dataset is initially set to <code>null</code>. */ public PiePlot() { this(null); } /** * Creates a plot that will draw a pie chart for the specified dataset. * * @param dataset the dataset (<code>null</code> permitted). */ public PiePlot(PieDataset dataset) { super(); this.dataset = dataset; if (dataset != null) { dataset.addChangeListener(this); } this.pieIndex = 0; this.interiorGap = DEFAULT_INTERIOR_GAP; this.circular = true; this.startAngle = DEFAULT_START_ANGLE; this.direction = Rotation.CLOCKWISE; this.minimumArcAngleToDraw = DEFAULT_MINIMUM_ARC_ANGLE_TO_DRAW; this.sectionPaintMap = new PaintMap(); this.baseSectionPaint = Color.GRAY; this.autoPopulateSectionPaint = true; this.sectionOutlinesVisible = true; this.sectionOutlinePaintMap = new PaintMap(); this.baseSectionOutlinePaint = DEFAULT_OUTLINE_PAINT; this.autoPopulateSectionOutlinePaint = false; this.sectionOutlineStrokeMap = new StrokeMap(); this.baseSectionOutlineStroke = DEFAULT_OUTLINE_STROKE; this.autoPopulateSectionOutlineStroke = false; this.explodePercentages = new TreeMap<Comparable, Number>(); this.labelGenerator = new StandardPieSectionLabelGenerator(); this.labelFont = DEFAULT_LABEL_FONT; this.labelPaint = DEFAULT_LABEL_PAINT; this.labelBackgroundPaint = DEFAULT_LABEL_BACKGROUND_PAINT; this.labelOutlinePaint = DEFAULT_LABEL_OUTLINE_PAINT; this.labelOutlineStroke = DEFAULT_LABEL_OUTLINE_STROKE; this.labelShadowPaint = DEFAULT_LABEL_SHADOW_PAINT; this.labelLinksVisible = true; this.labelDistributor = new PieLabelDistributor(0); this.simpleLabels = false; this.simpleLabelOffset = new RectangleInsets(UnitType.RELATIVE, 0.18, 0.18, 0.18, 0.18); this.labelPadding = new RectangleInsets(2, 2, 2, 2); this.toolTipGenerator = null; this.urlGenerator = null; this.legendLabelGenerator = new StandardPieSectionLabelGenerator(); this.legendLabelToolTipGenerator = null; this.legendLabelURLGenerator = null; this.legendItemShape = Plot.DEFAULT_LEGEND_ITEM_CIRCLE; this.ignoreNullValues = false; this.ignoreZeroValues = false; this.shadowGenerator = null; } /** * Returns the dataset. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(PieDataset) */ public PieDataset getDataset() { return this.dataset; } /** * Sets the dataset and sends a {@link DatasetChangeEvent} to 'this'. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() */ public void setDataset(PieDataset dataset) { // if there is an existing dataset, remove the plot from the list of // change listeners... PieDataset existing = this.dataset; if (existing != null) { existing.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns the pie index (this is used by the {@link MultiplePiePlot} class * to track subplots). * * @return The pie index. * * @see #setPieIndex(int) */ public int getPieIndex() { return this.pieIndex; } /** * Sets the pie index (this is used by the {@link MultiplePiePlot} class to * track subplots). * * @param index the index. * * @see #getPieIndex() */ public void setPieIndex(int index) { this.pieIndex = index; } /** * Returns the start angle for the first pie section. This is measured in * degrees starting from 3 o'clock and measuring anti-clockwise. * * @return The start angle. * * @see #setStartAngle(double) */ public double getStartAngle() { return this.startAngle; } /** * Sets the starting angle and sends a {@link PlotChangeEvent} to all * registered listeners. The initial default value is 90 degrees, which * corresponds to 12 o'clock. A value of zero corresponds to 3 o'clock... * this is the encoding used by Java's Arc2D class. * * @param angle the angle (in degrees). * * @see #getStartAngle() */ public void setStartAngle(double angle) { this.startAngle = angle; fireChangeEvent(); } /** * Returns the direction in which the pie sections are drawn (clockwise or * anti-clockwise). * * @return The direction (never <code>null</code>). * * @see #setDirection(Rotation) */ public Rotation getDirection() { return this.direction; } /** * Sets the direction in which the pie sections are drawn and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param direction the direction (<code>null</code> not permitted). * * @see #getDirection() */ public void setDirection(Rotation direction) { if (direction == null) { throw new IllegalArgumentException("Null 'direction' argument."); } this.direction = direction; fireChangeEvent(); } /** * Returns the interior gap, measured as a percentage of the available * drawing space. * * @return The gap (as a percentage of the available drawing space). * * @see #setInteriorGap(double) */ public double getInteriorGap() { return this.interiorGap; } /** * Sets the interior gap and sends a {@link PlotChangeEvent} to all * registered listeners. This controls the space between the edges of the * pie plot and the plot area itself (the region where the section labels * appear). * * @param percent the gap (as a percentage of the available drawing space). * * @see #getInteriorGap() */ public void setInteriorGap(double percent) { if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) { throw new IllegalArgumentException( "Invalid 'percent' (" + percent + ") argument."); } if (this.interiorGap != percent) { this.interiorGap = percent; fireChangeEvent(); } } /** * Returns a flag indicating whether the pie chart is circular, or * stretched into an elliptical shape. * * @return A flag indicating whether the pie chart is circular. * * @see #setCircular(boolean) */ public boolean isCircular() { return this.circular; } /** * A flag indicating whether the pie chart is circular, or stretched into * an elliptical shape. * * @param flag the new value. * * @see #isCircular() */ public void setCircular(boolean flag) { setCircular(flag, true); } /** * Sets the circular attribute and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param circular the new value of the flag. * @param notify notify listeners? * * @see #isCircular() */ public void setCircular(boolean circular, boolean notify) { this.circular = circular; if (notify) { fireChangeEvent(); } } /** * Returns the flag that controls whether <code>null</code> values in the * dataset are ignored. * * @return A boolean. * * @see #setIgnoreNullValues(boolean) */ public boolean getIgnoreNullValues() { return this.ignoreNullValues; } /** * Sets a flag that controls whether <code>null</code> values are ignored, * and sends a {@link PlotChangeEvent} to all registered listeners. At * present, this only affects whether or not the key is presented in the * legend. * * @param flag the flag. * * @see #getIgnoreNullValues() * @see #setIgnoreZeroValues(boolean) */ public void setIgnoreNullValues(boolean flag) { this.ignoreNullValues = flag; fireChangeEvent(); } /** * Returns the flag that controls whether zero values in the * dataset are ignored. * * @return A boolean. * * @see #setIgnoreZeroValues(boolean) */ public boolean getIgnoreZeroValues() { return this.ignoreZeroValues; } /** * Sets a flag that controls whether zero values are ignored, * and sends a {@link PlotChangeEvent} to all registered listeners. This * only affects whether or not a label appears for the non-visible * pie section. * * @param flag the flag. * * @see #getIgnoreZeroValues() * @see #setIgnoreNullValues(boolean) */ public void setIgnoreZeroValues(boolean flag) { this.ignoreZeroValues = flag; fireChangeEvent(); } //// SECTION PAINT //////////////////////////////////////////////////////// /** * Returns the paint for the specified section. This is equivalent to * <code>lookupSectionPaint(section, getAutoPopulateSectionPaint())</code>. * * @param key the section key. * * @return The paint for the specified section. * * @since 1.0.3 * * @see #lookupSectionPaint(Comparable, boolean) */ protected Paint lookupSectionPaint(Comparable key) { return lookupSectionPaint(key, getAutoPopulateSectionPaint()); } /** * Returns the paint for the specified section. The lookup involves these * steps: * <ul> * <li>if {@link #getSectionPaint()} is non-<code>null</code>, return * it;</li> * <li>if {@link #getSectionPaint(int)} is non-<code>null</code> return * it;</li> * <li>if {@link #getSectionPaint(int)} is <code>null</code> but * <code>autoPopulate</code> is <code>true</code>, attempt to fetch * a new paint from the drawing supplier * ({@link #getDrawingSupplier()}); * <li>if all else fails, return {@link #getBaseSectionPaint()}. * </ul> * * @param key the section key. * @param autoPopulate a flag that controls whether the drawing supplier * is used to auto-populate the section paint settings. * * @return The paint. * * @since 1.0.3 */ protected Paint lookupSectionPaint(Comparable key, boolean autoPopulate) { // check if there is a paint defined for the specified key Paint result = this.sectionPaintMap.getPaint(key); if (result != null) { return result; } // nothing defined - do we autoPopulate? if (autoPopulate) { DrawingSupplier ds = getDrawingSupplier(); if (ds != null) { result = ds.getNextPaint(); this.sectionPaintMap.put(key, result); } else { result = this.baseSectionPaint; } } else { result = this.baseSectionPaint; } return result; } /** * Returns a key for the specified section. If there is no such section * in the dataset, we generate a key. This is to provide some backward * compatibility for the (now deprecated) methods that get/set attributes * based on section indices. The preferred way of doing this now is to * link the attributes directly to the section key (there are new methods * for this, starting from version 1.0.3). * * @param section the section index. * * @return The key. * * @since 1.0.3 */ protected Comparable getSectionKey(int section) { Comparable key = null; if (this.dataset != null) { if (section >= 0 && section < this.dataset.getItemCount()) { key = this.dataset.getKey(section); } } if (key == null) { key = section; } return key; } /** * Returns the paint associated with the specified key, or * <code>null</code> if there is no paint associated with the key. * * @param key the key (<code>null</code> not permitted). * * @return The paint associated with the specified key, or * <code>null</code>. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @see #setSectionPaint(Comparable, Paint) * * @since 1.0.3 */ public Paint getSectionPaint(Comparable key) { // null argument check delegated... return this.sectionPaintMap.getPaint(key); } /** * Sets the paint associated with the specified key, and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param key the key (<code>null</code> not permitted). * @param paint the paint. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @see #getSectionPaint(Comparable) * * @since 1.0.3 */ public void setSectionPaint(Comparable key, Paint paint) { // null argument check delegated... this.sectionPaintMap.put(key, paint); fireChangeEvent(); } /** * Clears the section paint settings for this plot and, if requested, sends * a {@link PlotChangeEvent} to all registered listeners. Be aware that * if the <code>autoPopulateSectionPaint</code> flag is set, the section * paints may be repopulated using the same colours as before. * * @param notify notify listeners? * * @since 1.0.11 * * @see #autoPopulateSectionPaint */ public void clearSectionPaints(boolean notify) { this.sectionPaintMap.clear(); if (notify) { fireChangeEvent(); } } /** * Returns the base section paint. This is used when no other paint is * defined, which is rare. The default value is <code>Color.GRAY</code>. * * @return The paint (never <code>null</code>). * * @see #setBaseSectionPaint(Paint) */ public Paint getBaseSectionPaint() { return this.baseSectionPaint; } /** * Sets the base section paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getBaseSectionPaint() */ public void setBaseSectionPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.baseSectionPaint = paint; fireChangeEvent(); } /** * Returns the flag that controls whether or not the section paint is * auto-populated by the {@link #lookupSectionPaint(Comparable)} method. * * @return A boolean. * * @since 1.0.11 */ public boolean getAutoPopulateSectionPaint() { return this.autoPopulateSectionPaint; } /** * Sets the flag that controls whether or not the section paint is * auto-populated by the {@link #lookupSectionPaint(Comparable)} method, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param auto auto-populate? * * @since 1.0.11 */ public void setAutoPopulateSectionPaint(boolean auto) { this.autoPopulateSectionPaint = auto; fireChangeEvent(); } //// SECTION OUTLINE PAINT //////////////////////////////////////////////// /** * Returns the flag that controls whether or not the outline is drawn for * each pie section. * * @return The flag that controls whether or not the outline is drawn for * each pie section. * * @see #setSectionOutlinesVisible(boolean) */ public boolean getSectionOutlinesVisible() { return this.sectionOutlinesVisible; } /** * Sets the flag that controls whether or not the outline is drawn for * each pie section, and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param visible the flag. * * @see #getSectionOutlinesVisible() */ public void setSectionOutlinesVisible(boolean visible) { this.sectionOutlinesVisible = visible; fireChangeEvent(); } /** * Returns the outline paint for the specified section. This is equivalent * to <code>lookupSectionPaint(section, * getAutoPopulateSectionOutlinePaint())</code>. * * @param key the section key. * * @return The paint for the specified section. * * @since 1.0.3 * * @see #lookupSectionOutlinePaint(Comparable, boolean) */ protected Paint lookupSectionOutlinePaint(Comparable key) { return lookupSectionOutlinePaint(key, getAutoPopulateSectionOutlinePaint()); } /** * Returns the outline paint for the specified section. The lookup * involves these steps: * <ul> * <li>if {@link #getSectionOutlinePaint()} is non-<code>null</code>, * return it;</li> * <li>otherwise, if {@link #getSectionOutlinePaint(int)} is * non-<code>null</code> return it;</li> * <li>if {@link #getSectionOutlinePaint(int)} is <code>null</code> but * <code>autoPopulate</code> is <code>true</code>, attempt to fetch * a new outline paint from the drawing supplier * ({@link #getDrawingSupplier()}); * <li>if all else fails, return {@link #getBaseSectionOutlinePaint()}. * </ul> * * @param key the section key. * @param autoPopulate a flag that controls whether the drawing supplier * is used to auto-populate the section outline paint settings. * * @return The paint. * * @since 1.0.3 */ protected Paint lookupSectionOutlinePaint(Comparable key, boolean autoPopulate) { // check if there is a paint defined for the specified key Paint result = this.sectionOutlinePaintMap.getPaint(key); if (result != null) { return result; } // nothing defined - do we autoPopulate? if (autoPopulate) { DrawingSupplier ds = getDrawingSupplier(); if (ds != null) { result = ds.getNextOutlinePaint(); this.sectionOutlinePaintMap.put(key, result); } else { result = this.baseSectionOutlinePaint; } } else { result = this.baseSectionOutlinePaint; } return result; } /** * Returns the outline paint associated with the specified key, or * <code>null</code> if there is no paint associated with the key. * * @param key the key (<code>null</code> not permitted). * * @return The paint associated with the specified key, or * <code>null</code>. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @see #setSectionOutlinePaint(Comparable, Paint) * * @since 1.0.3 */ public Paint getSectionOutlinePaint(Comparable key) { // null argument check delegated... return this.sectionOutlinePaintMap.getPaint(key); } /** * Sets the outline paint associated with the specified key, and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param key the key (<code>null</code> not permitted). * @param paint the paint. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @see #getSectionOutlinePaint(Comparable) * * @since 1.0.3 */ public void setSectionOutlinePaint(Comparable key, Paint paint) { // null argument check delegated... this.sectionOutlinePaintMap.put(key, paint); fireChangeEvent(); } /** * Clears the section outline paint settings for this plot and, if * requested, sends a {@link PlotChangeEvent} to all registered listeners. * Be aware that if the <code>autoPopulateSectionPaint</code> flag is set, * the section paints may be repopulated using the same colours as before. * * @param notify notify listeners? * * @since 1.0.11 * * @see #autoPopulateSectionOutlinePaint */ public void clearSectionOutlinePaints(boolean notify) { this.sectionOutlinePaintMap.clear(); if (notify) { fireChangeEvent(); } } /** * Returns the base section paint. This is used when no other paint is * available. * * @return The paint (never <code>null</code>). * * @see #setBaseSectionOutlinePaint(Paint) */ public Paint getBaseSectionOutlinePaint() { return this.baseSectionOutlinePaint; } /** * Sets the base section paint. * * @param paint the paint (<code>null</code> not permitted). * * @see #getBaseSectionOutlinePaint() */ public void setBaseSectionOutlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.baseSectionOutlinePaint = paint; fireChangeEvent(); } /** * Returns the flag that controls whether or not the section outline paint * is auto-populated by the {@link #lookupSectionOutlinePaint(Comparable)} * method. * * @return A boolean. * * @since 1.0.11 */ public boolean getAutoPopulateSectionOutlinePaint() { return this.autoPopulateSectionOutlinePaint; } /** * Sets the flag that controls whether or not the section outline paint is * auto-populated by the {@link #lookupSectionOutlinePaint(Comparable)} * method, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param auto auto-populate? * * @since 1.0.11 */ public void setAutoPopulateSectionOutlinePaint(boolean auto) { this.autoPopulateSectionOutlinePaint = auto; fireChangeEvent(); } //// SECTION OUTLINE STROKE /////////////////////////////////////////////// /** * Returns the outline stroke for the specified section. This is * equivalent to <code>lookupSectionOutlineStroke(section, * getAutoPopulateSectionOutlineStroke())</code>. * * @param key the section key. * * @return The stroke for the specified section. * * @since 1.0.3 * * @see #lookupSectionOutlineStroke(Comparable, boolean) */ protected Stroke lookupSectionOutlineStroke(Comparable key) { return lookupSectionOutlineStroke(key, getAutoPopulateSectionOutlineStroke()); } /** * Returns the outline stroke for the specified section. The lookup * involves these steps: * <ul> * <li>if {@link #getSectionOutlineStroke()} is non-<code>null</code>, * return it;</li> * <li>otherwise, if {@link #getSectionOutlineStroke(int)} is * non-<code>null</code> return it;</li> * <li>if {@link #getSectionOutlineStroke(int)} is <code>null</code> but * <code>autoPopulate</code> is <code>true</code>, attempt to fetch * a new outline stroke from the drawing supplier * ({@link #getDrawingSupplier()}); * <li>if all else fails, return {@link #getBaseSectionOutlineStroke()}. * </ul> * * @param key the section key. * @param autoPopulate a flag that controls whether the drawing supplier * is used to auto-populate the section outline stroke settings. * * @return The stroke. * * @since 1.0.3 */ protected Stroke lookupSectionOutlineStroke(Comparable key, boolean autoPopulate) { // check if there is a stroke defined for the specified key Stroke result = this.sectionOutlineStrokeMap.getStroke(key); if (result != null) { return result; } // nothing defined - do we autoPopulate? if (autoPopulate) { DrawingSupplier ds = getDrawingSupplier(); if (ds != null) { result = ds.getNextOutlineStroke(); this.sectionOutlineStrokeMap.put(key, result); } else { result = this.baseSectionOutlineStroke; } } else { result = this.baseSectionOutlineStroke; } return result; } /** * Returns the outline stroke associated with the specified key, or * <code>null</code> if there is no stroke associated with the key. * * @param key the key (<code>null</code> not permitted). * * @return The stroke associated with the specified key, or * <code>null</code>. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @see #setSectionOutlineStroke(Comparable, Stroke) * * @since 1.0.3 */ public Stroke getSectionOutlineStroke(Comparable key) { // null argument check delegated... return this.sectionOutlineStrokeMap.getStroke(key); } /** * Sets the outline stroke associated with the specified key, and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param key the key (<code>null</code> not permitted). * @param stroke the stroke. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @see #getSectionOutlineStroke(Comparable) * * @since 1.0.3 */ public void setSectionOutlineStroke(Comparable key, Stroke stroke) { // null argument check delegated... this.sectionOutlineStrokeMap.put(key, stroke); fireChangeEvent(); } /** * Clears the section outline stroke settings for this plot and, if * requested, sends a {@link PlotChangeEvent} to all registered listeners. * Be aware that if the <code>autoPopulateSectionPaint</code> flag is set, * the section paints may be repopulated using the same colours as before. * * @param notify notify listeners? * * @since 1.0.11 * * @see #autoPopulateSectionOutlineStroke */ public void clearSectionOutlineStrokes(boolean notify) { this.sectionOutlineStrokeMap.clear(); if (notify) { fireChangeEvent(); } } /** * Returns the base section stroke. This is used when no other stroke is * available. * * @return The stroke (never <code>null</code>). * * @see #setBaseSectionOutlineStroke(Stroke) */ public Stroke getBaseSectionOutlineStroke() { return this.baseSectionOutlineStroke; } /** * Sets the base section stroke. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getBaseSectionOutlineStroke() */ public void setBaseSectionOutlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.baseSectionOutlineStroke = stroke; fireChangeEvent(); } /** * Returns the flag that controls whether or not the section outline stroke * is auto-populated by the {@link #lookupSectionOutlinePaint(Comparable)} * method. * * @return A boolean. * * @since 1.0.11 */ public boolean getAutoPopulateSectionOutlineStroke() { return this.autoPopulateSectionOutlineStroke; } /** * Sets the flag that controls whether or not the section outline stroke is * auto-populated by the {@link #lookupSectionOutlineStroke(Comparable)} * method, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param auto auto-populate? * * @since 1.0.11 */ public void setAutoPopulateSectionOutlineStroke(boolean auto) { this.autoPopulateSectionOutlineStroke = auto; fireChangeEvent(); } /** * Returns the shadow paint. * * @return The paint (possibly <code>null</code>). * * @see #setShadowPaint(Paint) */ public Paint getShadowPaint() { return this.shadowPaint; } /** * Sets the shadow paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getShadowPaint() */ public void setShadowPaint(Paint paint) { this.shadowPaint = paint; fireChangeEvent(); } /** * Returns the x-offset for the shadow effect. * * @return The offset (in Java2D units). * * @see #setShadowXOffset(double) */ public double getShadowXOffset() { return this.shadowXOffset; } /** * Sets the x-offset for the shadow effect and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param offset the offset (in Java2D units). * * @see #getShadowXOffset() */ public void setShadowXOffset(double offset) { this.shadowXOffset = offset; fireChangeEvent(); } /** * Returns the y-offset for the shadow effect. * * @return The offset (in Java2D units). * * @see #setShadowYOffset(double) */ public double getShadowYOffset() { return this.shadowYOffset; } /** * Sets the y-offset for the shadow effect and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param offset the offset (in Java2D units). * * @see #getShadowYOffset() */ public void setShadowYOffset(double offset) { this.shadowYOffset = offset; fireChangeEvent(); } /** * Returns the amount that the section with the specified key should be * exploded. * * @param key the key (<code>null</code> not permitted). * * @return The amount that the section with the specified key should be * exploded. * * @throws IllegalArgumentException if <code>key</code> is * <code>null</code>. * * @since 1.0.3 * * @see #setExplodePercent(Comparable, double) */ public double getExplodePercent(Comparable key) { double result = 0.0; if (this.explodePercentages != null) { Number percent = this.explodePercentages.get(key); if (percent != null) { result = percent.doubleValue(); } } return result; } /** * Sets the amount that a pie section should be exploded and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param key the section key (<code>null</code> not permitted). * @param percent the explode percentage (0.30 = 30 percent). * * @since 1.0.3 * * @see #getExplodePercent(Comparable) */ public void setExplodePercent(Comparable key, double percent) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } if (this.explodePercentages == null) { this.explodePercentages = new TreeMap<Comparable, Number>(); } this.explodePercentages.put(key, percent); fireChangeEvent(); } /** * Returns the maximum explode percent. * * @return The percent. */ public double getMaximumExplodePercent() { if (this.dataset == null) { return 0.0; } double result = 0.0; for (Comparable key : this.dataset.getKeys()) { Number explode = this.explodePercentages.get(key); if (explode != null) { result = Math.max(result, explode.doubleValue()); } } return result; } /** * Returns the section label generator. * * @return The generator (possibly <code>null</code>). * * @see #setLabelGenerator(PieSectionLabelGenerator) */ public PieSectionLabelGenerator getLabelGenerator() { return this.labelGenerator; } /** * Sets the section label generator and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @see #getLabelGenerator() */ public void setLabelGenerator(PieSectionLabelGenerator generator) { this.labelGenerator = generator; fireChangeEvent(); } /** * Returns the gap between the edge of the pie and the labels, expressed as * a percentage of the plot width. * * @return The gap (a percentage, where 0.05 = five percent). * * @see #setLabelGap(double) */ public double getLabelGap() { return this.labelGap; } /** * Sets the gap between the edge of the pie and the labels (expressed as a * percentage of the plot width) and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param gap the gap (a percentage, where 0.05 = five percent). * * @see #getLabelGap() */ public void setLabelGap(double gap) { this.labelGap = gap; fireChangeEvent(); } /** * Returns the maximum label width as a percentage of the plot width. * * @return The width (a percentage, where 0.20 = 20 percent). * * @see #setMaximumLabelWidth(double) */ public double getMaximumLabelWidth() { return this.maximumLabelWidth; } /** * Sets the maximum label width as a percentage of the plot width and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param width the width (a percentage, where 0.20 = 20 percent). * * @see #getMaximumLabelWidth() */ public void setMaximumLabelWidth(double width) { this.maximumLabelWidth = width; fireChangeEvent(); } /** * Returns the flag that controls whether or not label linking lines are * visible. * * @return A boolean. * * @see #setLabelLinksVisible(boolean) */ public boolean getLabelLinksVisible() { return this.labelLinksVisible; } /** * Sets the flag that controls whether or not label linking lines are * visible and sends a {@link PlotChangeEvent} to all registered listeners. * Please take care when hiding the linking lines - depending on the data * values, the labels can be displayed some distance away from the * corresponding pie section. * * @param visible the flag. * * @see #getLabelLinksVisible() */ public void setLabelLinksVisible(boolean visible) { this.labelLinksVisible = visible; fireChangeEvent(); } /** * Returns the label link style. * * @return The label link style (never <code>null</code>). * * @see #setLabelLinkStyle(PieLabelLinkStyle) * * @since 1.0.10 */ public PieLabelLinkStyle getLabelLinkStyle() { return this.labelLinkStyle; } /** * Sets the label link style and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param style the new style (<code>null</code> not permitted). * * @see #getLabelLinkStyle() * * @since 1.0.10 */ public void setLabelLinkStyle(PieLabelLinkStyle style) { if (style == null) { throw new IllegalArgumentException("Null 'style' argument."); } this.labelLinkStyle = style; fireChangeEvent(); } /** * Returns the margin (expressed as a percentage of the width or height) * between the edge of the pie and the link point. * * @return The link margin (as a percentage, where 0.05 is five percent). * * @see #setLabelLinkMargin(double) */ public double getLabelLinkMargin() { return this.labelLinkMargin; } /** * Sets the link margin and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param margin the margin. * * @see #getLabelLinkMargin() */ public void setLabelLinkMargin(double margin) { this.labelLinkMargin = margin; fireChangeEvent(); } /** * Returns the paint used for the lines that connect pie sections to their * corresponding labels. * * @return The paint (never <code>null</code>). * * @see #setLabelLinkPaint(Paint) */ public Paint getLabelLinkPaint() { return this.labelLinkPaint; } /** * Sets the paint used for the lines that connect pie sections to their * corresponding labels, and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getLabelLinkPaint() */ public void setLabelLinkPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.labelLinkPaint = paint; fireChangeEvent(); } /** * Returns the stroke used for the label linking lines. * * @return The stroke. * * @see #setLabelLinkStroke(Stroke) */ public Stroke getLabelLinkStroke() { return this.labelLinkStroke; } /** * Sets the link stroke and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param stroke the stroke. * * @see #getLabelLinkStroke() */ public void setLabelLinkStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.labelLinkStroke = stroke; fireChangeEvent(); } /** * Returns the distance that the end of the label link is embedded into * the plot, expressed as a percentage of the plot's radius. * <br><br> * This method is overridden in the {@link RingPlot} class to resolve * bug 2121818. * * @return <code>0.10</code>. * * @since 1.0.12 */ protected double getLabelLinkDepth() { return 0.1; } /** * Returns the section label font. * * @return The font (never <code>null</code>). * * @see #setLabelFont(Font) */ public Font getLabelFont() { return this.labelFont; } /** * Sets the section label font and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getLabelFont() */ public void setLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.labelFont = font; fireChangeEvent(); } /** * Returns the section label paint. * * @return The paint (never <code>null</code>). * * @see #setLabelPaint(Paint) */ public Paint getLabelPaint() { return this.labelPaint; } /** * Sets the section label paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getLabelPaint() */ public void setLabelPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.labelPaint = paint; fireChangeEvent(); } /** * Returns the section label background paint. * * @return The paint (possibly <code>null</code>). * * @see #setLabelBackgroundPaint(Paint) */ public Paint getLabelBackgroundPaint() { return this.labelBackgroundPaint; } /** * Sets the section label background paint and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getLabelBackgroundPaint() */ public void setLabelBackgroundPaint(Paint paint) { this.labelBackgroundPaint = paint; fireChangeEvent(); } /** * Returns the section label outline paint. * * @return The paint (possibly <code>null</code>). * * @see #setLabelOutlinePaint(Paint) */ public Paint getLabelOutlinePaint() { return this.labelOutlinePaint; } /** * Sets the section label outline paint and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getLabelOutlinePaint() */ public void setLabelOutlinePaint(Paint paint) { this.labelOutlinePaint = paint; fireChangeEvent(); } /** * Returns the section label outline stroke. * * @return The stroke (possibly <code>null</code>). * * @see #setLabelOutlineStroke(Stroke) */ public Stroke getLabelOutlineStroke() { return this.labelOutlineStroke; } /** * Sets the section label outline stroke and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> permitted). * * @see #getLabelOutlineStroke() */ public void setLabelOutlineStroke(Stroke stroke) { this.labelOutlineStroke = stroke; fireChangeEvent(); } /** * Returns the section label shadow paint. * * @return The paint (possibly <code>null</code>). * * @see #setLabelShadowPaint(Paint) */ public Paint getLabelShadowPaint() { return this.labelShadowPaint; } /** * Sets the section label shadow paint and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getLabelShadowPaint() */ public void setLabelShadowPaint(Paint paint) { this.labelShadowPaint = paint; fireChangeEvent(); } /** * Returns the label padding. * * @return The label padding (never <code>null</code>). * * @since 1.0.7 * * @see #setLabelPadding(RectangleInsets) */ public RectangleInsets getLabelPadding() { return this.labelPadding; } /** * Sets the padding between each label and its outline and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param padding the padding (<code>null</code> not permitted). * * @since 1.0.7 * * @see #getLabelPadding() */ public void setLabelPadding(RectangleInsets padding) { if (padding == null) { throw new IllegalArgumentException("Null 'padding' argument."); } this.labelPadding = padding; fireChangeEvent(); } /** * Returns the flag that controls whether simple or extended labels are * displayed on the plot. * * @return A boolean. * * @since 1.0.7 */ public boolean getSimpleLabels() { return this.simpleLabels; } /** * Sets the flag that controls whether simple or extended labels are * displayed on the plot, and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param simple the new flag value. * * @since 1.0.7 */ public void setSimpleLabels(boolean simple) { this.simpleLabels = simple; fireChangeEvent(); } /** * Returns the offset used for the simple labels, if they are displayed. * * @return The offset (never <code>null</code>). * * @since 1.0.7 * * @see #setSimpleLabelOffset(RectangleInsets) */ public RectangleInsets getSimpleLabelOffset() { return this.simpleLabelOffset; } /** * Sets the offset for the simple labels and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param offset the offset (<code>null</code> not permitted). * * @since 1.0.7 * * @see #getSimpleLabelOffset() */ public void setSimpleLabelOffset(RectangleInsets offset) { if (offset == null) { throw new IllegalArgumentException("Null 'offset' argument."); } this.simpleLabelOffset = offset; fireChangeEvent(); } /** * Returns the object responsible for the vertical layout of the pie * section labels. * * @return The label distributor (never <code>null</code>). * * @since 1.0.6 */ public AbstractPieLabelDistributor getLabelDistributor() { return this.labelDistributor; } /** * Sets the label distributor and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param distributor the distributor (<code>null</code> not permitted). * * @since 1.0.6 */ public void setLabelDistributor(AbstractPieLabelDistributor distributor) { if (distributor == null) { throw new IllegalArgumentException("Null 'distributor' argument."); } this.labelDistributor = distributor; fireChangeEvent(); } /** * Returns the tool tip generator, an object that is responsible for * generating the text items used for tool tips by the plot. If the * generator is <code>null</code>, no tool tips will be created. * * @return The generator (possibly <code>null</code>). * * @see #setToolTipGenerator(PieToolTipGenerator) */ public PieToolTipGenerator getToolTipGenerator() { return this.toolTipGenerator; } /** * Sets the tool tip generator and sends a {@link PlotChangeEvent} to all * registered listeners. Set the generator to <code>null</code> if you * don't want any tool tips. * * @param generator the generator (<code>null</code> permitted). * * @see #getToolTipGenerator() */ public void setToolTipGenerator(PieToolTipGenerator generator) { this.toolTipGenerator = generator; fireChangeEvent(); } /** * Returns the URL generator. * * @return The generator (possibly <code>null</code>). * * @see #setURLGenerator(PieURLGenerator) */ public PieURLGenerator getURLGenerator() { return this.urlGenerator; } /** * Sets the URL generator and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @see #getURLGenerator() */ public void setURLGenerator(PieURLGenerator generator) { this.urlGenerator = generator; fireChangeEvent(); } /** * Returns the minimum arc angle that will be drawn. Pie sections for an * angle smaller than this are not drawn, to avoid a JDK bug. * * @return The minimum angle. * * @see #setMinimumArcAngleToDraw(double) */ public double getMinimumArcAngleToDraw() { return this.minimumArcAngleToDraw; } /** * Sets the minimum arc angle that will be drawn. Pie sections for an * angle smaller than this are not drawn, to avoid a JDK bug. See this * link for details: * <br><br> * <a href="http://www.jfree.org/phpBB2/viewtopic.php?t=2707"> * http://www.jfree.org/phpBB2/viewtopic.php?t=2707</a> * <br><br> * ...and this bug report in the Java Bug Parade: * <br><br> * <a href= * "http://developer.java.sun.com/developer/bugParade/bugs/4836495.html"> * http://developer.java.sun.com/developer/bugParade/bugs/4836495.html</a> * * @param angle the minimum angle. * * @see #getMinimumArcAngleToDraw() */ public void setMinimumArcAngleToDraw(double angle) { this.minimumArcAngleToDraw = angle; } /** * Returns the shape used for legend items. * * @return The shape (never <code>null</code>). * * @see #setLegendItemShape(Shape) */ public Shape getLegendItemShape() { return this.legendItemShape; } /** * Sets the shape used for legend items and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param shape the shape (<code>null</code> not permitted). * * @see #getLegendItemShape() */ public void setLegendItemShape(Shape shape) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } this.legendItemShape = shape; fireChangeEvent(); } /** * Returns the legend label generator. * * @return The legend label generator (never <code>null</code>). * * @see #setLegendLabelGenerator(PieSectionLabelGenerator) */ public PieSectionLabelGenerator getLegendLabelGenerator() { return this.legendLabelGenerator; } /** * Sets the legend label generator and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param generator the generator (<code>null</code> not permitted). * * @see #getLegendLabelGenerator() */ public void setLegendLabelGenerator(PieSectionLabelGenerator generator) { if (generator == null) { throw new IllegalArgumentException("Null 'generator' argument."); } this.legendLabelGenerator = generator; fireChangeEvent(); } /** * Returns the legend label tool tip generator. * * @return The legend label tool tip generator (possibly <code>null</code>). * * @see #setLegendLabelToolTipGenerator(PieSectionLabelGenerator) */ public PieSectionLabelGenerator getLegendLabelToolTipGenerator() { return this.legendLabelToolTipGenerator; } /** * Sets the legend label tool tip generator and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @see #getLegendLabelToolTipGenerator() */ public void setLegendLabelToolTipGenerator( PieSectionLabelGenerator generator) { this.legendLabelToolTipGenerator = generator; fireChangeEvent(); } /** * Returns the legend label URL generator. * * @return The legend label URL generator (possibly <code>null</code>). * * @see #setLegendLabelURLGenerator(PieURLGenerator) * * @since 1.0.4 */ public PieURLGenerator getLegendLabelURLGenerator() { return this.legendLabelURLGenerator; } /** * Sets the legend label URL generator and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @see #getLegendLabelURLGenerator() * * @since 1.0.4 */ public void setLegendLabelURLGenerator(PieURLGenerator generator) { this.legendLabelURLGenerator = generator; fireChangeEvent(); } /** * Returns the shadow generator for the plot, if any. * * @return The shadow generator (possibly <code>null</code>). * * @since 1.0.14 */ public ShadowGenerator getShadowGenerator() { return this.shadowGenerator; } /** * Sets the shadow generator for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. Note that this is * a bitmap drop-shadow generation facility and is separate from the * vector based show option that is controlled via the * {@link #setShadowPaint(java.awt.Paint)} method. * * @param generator the generator (<code>null</code> permitted). * * @since 1.0.14 */ public void setShadowGenerator(ShadowGenerator generator) { this.shadowGenerator = generator; fireChangeEvent(); } /** * Handles a mouse wheel rotation (this method is intended for use by the * {@link org.jfree.chart.MouseWheelHandler} class). * * @param rotateClicks the number of rotate clicks on the the mouse wheel. * * @since 1.0.14 */ public void handleMouseWheelRotation(int rotateClicks) { setStartAngle(this.startAngle + rotateClicks * 4.0); } /** * Initialises the drawing procedure. This method will be called before * the first item is rendered, giving the plot an opportunity to initialise * any state information it wants to maintain. * * @param g2 the graphics device. * @param plotArea the plot area (<code>null</code> not permitted). * @param plot the plot. * @param index the secondary index (<code>null</code> for primary * renderer). * @param info collects chart rendering information for return to caller. * * @return A state object (maintains state information relevant to one * chart drawing). */ public PiePlotState initialise(Graphics2D g2, Rectangle2D plotArea, PiePlot plot, Integer index, PlotRenderingInfo info) { PiePlotState state = new PiePlotState(info); state.setPassesRequired(2); if (this.dataset != null) { state.setTotal(DatasetUtilities.calculatePieDatasetTotal( plot.getDataset())); } state.setLatestAngle(plot.getStartAngle()); return state; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing * (<code>null</code> permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { Graphics2D savedG2 = g2; BufferedImage dataImage = null; if (this.shadowGenerator != null) { dataImage = new BufferedImage((int) area.getWidth(), (int) area.getHeight(), BufferedImage.TYPE_INT_ARGB); g2 = dataImage.createGraphics(); g2.translate(-area.getX(), -area.getY()); g2.setRenderingHints(savedG2.getRenderingHints()); } drawPie(g2, area, info); if (this.shadowGenerator != null) { BufferedImage shadowImage = this.shadowGenerator.createDropShadow(dataImage); g2 = savedG2; g2.drawImage(shadowImage, (int) area.getX() + this.shadowGenerator.calculateOffsetX(), (int) area.getY() + this.shadowGenerator.calculateOffsetY(), null); g2.drawImage(dataImage, (int) area.getX(), (int) area.getY(), null); } } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, area); } /** * Draws the pie. * * @param g2 the graphics device. * @param plotArea the plot area. * @param info chart rendering info. */ protected void drawPie(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info) { PiePlotState state = initialise(g2, plotArea, this, null, info); // adjust the plot area for interior spacing and labels... double labelReserve = 0.0; if (this.labelGenerator != null && !this.simpleLabels) { labelReserve = this.labelGap + this.maximumLabelWidth; } double gapHorizontal = plotArea.getWidth() * (this.interiorGap + labelReserve) * 2.0; double gapVertical = plotArea.getHeight() * this.interiorGap * 2.0; if (DEBUG_DRAW_INTERIOR) { double hGap = plotArea.getWidth() * this.interiorGap; double vGap = plotArea.getHeight() * this.interiorGap; double igx1 = plotArea.getX() + hGap; double igx2 = plotArea.getMaxX() - hGap; double igy1 = plotArea.getY() + vGap; double igy2 = plotArea.getMaxY() - vGap; g2.setPaint(Color.GRAY); g2.draw(new Rectangle2D.Double(igx1, igy1, igx2 - igx1, igy2 - igy1)); } double linkX = plotArea.getX() + gapHorizontal / 2; double linkY = plotArea.getY() + gapVertical / 2; double linkW = plotArea.getWidth() - gapHorizontal; double linkH = plotArea.getHeight() - gapVertical; // make the link area a square if the pie chart is to be circular... if (this.circular) { double min = Math.min(linkW, linkH) / 2; linkX = (linkX + linkX + linkW) / 2 - min; linkY = (linkY + linkY + linkH) / 2 - min; linkW = 2 * min; linkH = 2 * min; } // the link area defines the dog leg points for the linking lines to // the labels Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW, linkH); state.setLinkArea(linkArea); if (DEBUG_DRAW_LINK_AREA) { g2.setPaint(Color.BLUE); g2.draw(linkArea); g2.setPaint(Color.YELLOW); g2.draw(new Ellipse2D.Double(linkArea.getX(), linkArea.getY(), linkArea.getWidth(), linkArea.getHeight())); } // the explode area defines the max circle/ellipse for the exploded // pie sections. it is defined by shrinking the linkArea by the // linkMargin factor. double lm = 0.0; if (!this.simpleLabels) { lm = this.labelLinkMargin; } double hh = linkArea.getWidth() * lm * 2.0; double vv = linkArea.getHeight() * lm * 2.0; Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0, linkY + vv / 2.0, linkW - hh, linkH - vv); state.setExplodedPieArea(explodeArea); // the pie area defines the circle/ellipse for regular pie sections. // it is defined by shrinking the explodeArea by the explodeMargin // factor. double maximumExplodePercent = getMaximumExplodePercent(); double percent = maximumExplodePercent / (1.0 + maximumExplodePercent); double h1 = explodeArea.getWidth() * percent; double v1 = explodeArea.getHeight() * percent; Rectangle2D pieArea = new Rectangle2D.Double(explodeArea.getX() + h1 / 2.0, explodeArea.getY() + v1 / 2.0, explodeArea.getWidth() - h1, explodeArea.getHeight() - v1); if (DEBUG_DRAW_PIE_AREA) { g2.setPaint(Color.GREEN); g2.draw(pieArea); } state.setPieArea(pieArea); state.setPieCenterX(pieArea.getCenterX()); state.setPieCenterY(pieArea.getCenterY()); state.setPieWRadius(pieArea.getWidth() / 2.0); state.setPieHRadius(pieArea.getHeight() / 2.0); // plot the data (unless the dataset is null)... if ((this.dataset != null) && (this.dataset.getKeys().size() > 0)) { List<Comparable> keys = this.dataset.getKeys(); double totalValue = DatasetUtilities.calculatePieDatasetTotal( this.dataset); int passesRequired = state.getPassesRequired(); for (int pass = 0; pass < passesRequired; pass++) { double runningTotal = 0.0; for (int section = 0; section < keys.size(); section++) { Number n = this.dataset.getValue(section); if (n != null) { double value = n.doubleValue(); if (value > 0.0) { runningTotal += value; drawItem(g2, section, explodeArea, state, pass); } } } } if (this.simpleLabels) { drawSimpleLabels(g2, keys, totalValue, plotArea, linkArea, state); } else { drawLabels(g2, keys, totalValue, plotArea, linkArea, state); } } else { drawNoDataMessage(g2, plotArea); } } /** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { Number n = this.dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; if (this.direction == Rotation.CLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 - value / state.getTotal() * 360.0; } else if (this.direction == Rotation.ANTICLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 + value / state.getTotal() * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(this.getSectionKey(section)) / mep; } Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.PIE); if (currentPass == 0) { if (this.shadowPaint != null && this.shadowGenerator == null) { Shape shadowArc = ShapeUtilities.createTranslatedShape( arc, (float) this.shadowXOffset, (float) this.shadowYOffset); g2.setPaint(this.shadowPaint); g2.fill(shadowArc); } } else if (currentPass == 1) { Comparable key = getSectionKey(section); Paint paint = lookupSectionPaint(key, state); g2.setPaint(paint); g2.fill(arc); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); if (this.sectionOutlinesVisible) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); } // update the linking line target for later // add an entity for the pie section if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip( this.dataset, key); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, key, this.pieIndex); } PieSectionEntity entity = new PieSectionEntity( arc, this.dataset, this.pieIndex, section, key, tip, url); entities.add(entity); } } } } state.setLatestAngle(angle2); } /** * Draws the pie section labels in the simple form. * * @param g2 the graphics device. * @param keys the section keys. * @param totalValue the total value for all sections in the pie. * @param plotArea the plot area. * @param pieArea the area containing the pie. * @param state the plot state. * * @since 1.0.7 */ protected void drawSimpleLabels(Graphics2D g2, List<Comparable> keys, double totalValue, Rectangle2D plotArea, Rectangle2D pieArea, PiePlotState state) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); Rectangle2D labelsArea = this.simpleLabelOffset.createInsetRectangle( pieArea); double runningTotal = 0.0; for (Comparable key : keys) { boolean include; double v = 0.0; Number n = getDataset().getValue(key); if (n == null) { include = !getIgnoreNullValues(); } else { v = n.doubleValue(); include = getIgnoreZeroValues() ? v > 0.0 : v >= 0.0; } if (include) { runningTotal = runningTotal + v; // work out the mid angle (0 - 90 and 270 - 360) = right, // otherwise left double mid = getStartAngle() + (getDirection().getFactor() * ((runningTotal - v / 2.0) * 360) / totalValue); Arc2D arc = new Arc2D.Double(labelsArea, getStartAngle(), mid - getStartAngle(), Arc2D.OPEN); int x = (int) arc.getEndPoint().getX(); int y = (int) arc.getEndPoint().getY(); PieSectionLabelGenerator myLabelGenerator = getLabelGenerator(); if (myLabelGenerator == null) { continue; } String label = myLabelGenerator.generateSectionLabel( this.dataset, key); if (label == null) { continue; } g2.setFont(this.labelFont); FontMetrics fm = g2.getFontMetrics(); Rectangle2D bounds = TextUtilities.getTextBounds(label, g2, fm); Rectangle2D out = this.labelPadding.createOutsetRectangle( bounds); Shape bg = ShapeUtilities.createTranslatedShape(out, x - bounds.getCenterX(), y - bounds.getCenterY()); if (this.labelShadowPaint != null && this.shadowGenerator == null) { Shape shadow = ShapeUtilities.createTranslatedShape(bg, this.shadowXOffset, this.shadowYOffset); g2.setPaint(this.labelShadowPaint); g2.fill(shadow); } if (this.labelBackgroundPaint != null) { g2.setPaint(this.labelBackgroundPaint); g2.fill(bg); } if (this.labelOutlinePaint != null && this.labelOutlineStroke != null) { g2.setPaint(this.labelOutlinePaint); g2.setStroke(this.labelOutlineStroke); g2.draw(bg); } g2.setPaint(this.labelPaint); g2.setFont(this.labelFont); TextUtilities.drawAlignedString(label, g2, x, y, TextAnchor.CENTER); } } g2.setComposite(originalComposite); } /** * Draws the labels for the pie sections. * * @param g2 the graphics device. * @param keys the keys. * @param totalValue the total value. * @param plotArea the plot area. * @param linkArea the link area. * @param state the state. */ protected void drawLabels(Graphics2D g2, List<Comparable> keys, double totalValue, Rectangle2D plotArea, Rectangle2D linkArea, PiePlotState state) { Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); // classify the keys according to which side the label will appear... DefaultKeyedValues leftKeys = new DefaultKeyedValues(); DefaultKeyedValues rightKeys = new DefaultKeyedValues(); double runningTotal = 0.0; for (Comparable key : keys) { boolean include; double v = 0.0; Number n = this.dataset.getValue(key); if (n == null) { include = !this.ignoreNullValues; } else { v = n.doubleValue(); include = this.ignoreZeroValues ? v > 0.0 : v >= 0.0; } if (include) { runningTotal = runningTotal + v; // work out the mid angle (0 - 90 and 270 - 360) = right, // otherwise left double mid = this.startAngle + (this.direction.getFactor() * ((runningTotal - v / 2.0) * 360) / totalValue); if (Math.cos(Math.toRadians(mid)) < 0.0) { leftKeys.addValue(key, new Double(mid)); } else { rightKeys.addValue(key, new Double(mid)); } } } g2.setFont(getLabelFont()); // calculate the max label width from the plot dimensions, because // a circular pie can leave a lot more room for labels... double marginX = plotArea.getX() + this.interiorGap * plotArea.getWidth(); double gap = plotArea.getWidth() * this.labelGap; double ww = linkArea.getX() - gap - marginX; float labelWidth = (float) this.labelPadding.trimWidth(ww); // draw the labels... if (this.labelGenerator != null) { drawLeftLabels(leftKeys, g2, plotArea, linkArea, labelWidth, state); drawRightLabels(rightKeys, g2, plotArea, linkArea, labelWidth, state); } g2.setComposite(originalComposite); } /** * Draws the left labels. * * @param leftKeys a collection of keys and angles (to the middle of the * section, in degrees) for the sections on the left side of the * plot. * @param g2 the graphics device. * @param plotArea the plot area. * @param linkArea the link area. * @param maxLabelWidth the maximum label width. * @param state the state. */ protected void drawLeftLabels(KeyedValues leftKeys, Graphics2D g2, Rectangle2D plotArea, Rectangle2D linkArea, float maxLabelWidth, PiePlotState state) { this.labelDistributor.clear(); double lGap = plotArea.getWidth() * this.labelGap; double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0; for (int i = 0; i < leftKeys.getItemCount(); i++) { String label = this.labelGenerator.generateSectionLabel( this.dataset, leftKeys.getKey(i)); if (label != null) { TextBlock block = TextUtilities.createTextBlock(label, this.labelFont, this.labelPaint, maxLabelWidth, new G2TextMeasurer(g2)); TextBox labelBox = new TextBox(block); labelBox.setBackgroundPaint(this.labelBackgroundPaint); labelBox.setOutlinePaint(this.labelOutlinePaint); labelBox.setOutlineStroke(this.labelOutlineStroke); if (this.shadowGenerator == null) { labelBox.setShadowPaint(this.labelShadowPaint); } else { labelBox.setShadowPaint(null); } labelBox.setInteriorGap(this.labelPadding); double theta = Math.toRadians( leftKeys.getValue(i).doubleValue()); double baseY = state.getPieCenterY() - Math.sin(theta) * verticalLinkRadius; double hh = labelBox.getHeight(g2); this.labelDistributor.addPieLabelRecord(new PieLabelRecord( leftKeys.getKey(i), theta, baseY, labelBox, hh, lGap / 2.0 + lGap / 2.0 * -Math.cos(theta), 1.0 - getLabelLinkDepth() + getExplodePercent(leftKeys.getKey(i)))); } } double hh = plotArea.getHeight(); double gap = hh * getInteriorGap(); this.labelDistributor.distributeLabels(plotArea.getMinY() + gap, hh - 2 * gap); for (int i = 0; i < this.labelDistributor.getItemCount(); i++) { drawLeftLabel(g2, state, this.labelDistributor.getPieLabelRecord(i)); } } /** * Draws the right labels. * * @param keys the keys. * @param g2 the graphics device. * @param plotArea the plot area. * @param linkArea the link area. * @param maxLabelWidth the maximum label width. * @param state the state. */ protected void drawRightLabels(KeyedValues keys, Graphics2D g2, Rectangle2D plotArea, Rectangle2D linkArea, float maxLabelWidth, PiePlotState state) { // draw the right labels... this.labelDistributor.clear(); double lGap = plotArea.getWidth() * this.labelGap; double verticalLinkRadius = state.getLinkArea().getHeight() / 2.0; for (int i = 0; i < keys.getItemCount(); i++) { String label = this.labelGenerator.generateSectionLabel( this.dataset, keys.getKey(i)); if (label != null) { TextBlock block = TextUtilities.createTextBlock(label, this.labelFont, this.labelPaint, maxLabelWidth, new G2TextMeasurer(g2)); TextBox labelBox = new TextBox(block); labelBox.setBackgroundPaint(this.labelBackgroundPaint); labelBox.setOutlinePaint(this.labelOutlinePaint); labelBox.setOutlineStroke(this.labelOutlineStroke); if (this.shadowGenerator == null) { labelBox.setShadowPaint(this.labelShadowPaint); } else { labelBox.setShadowPaint(null); } labelBox.setInteriorGap(this.labelPadding); double theta = Math.toRadians(keys.getValue(i).doubleValue()); double baseY = state.getPieCenterY() - Math.sin(theta) * verticalLinkRadius; double hh = labelBox.getHeight(g2); this.labelDistributor.addPieLabelRecord(new PieLabelRecord( keys.getKey(i), theta, baseY, labelBox, hh, lGap / 2.0 + lGap / 2.0 * Math.cos(theta), 1.0 - getLabelLinkDepth() + getExplodePercent(keys.getKey(i)))); } } double hh = plotArea.getHeight(); double gap = hh * getInteriorGap(); this.labelDistributor.distributeLabels(plotArea.getMinY() + gap, hh - 2 * gap); for (int i = 0; i < this.labelDistributor.getItemCount(); i++) { drawRightLabel(g2, state, this.labelDistributor.getPieLabelRecord(i)); } } /** * Returns a collection of legend items for the pie chart. * * @return The legend items (never <code>null</code>). */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = new ArrayList<LegendItem>(); if (this.dataset == null) { return result; } List<Comparable> keys = this.dataset.getKeys(); int section = 0; Shape shape = getLegendItemShape(); for (Comparable key : keys) { Number n = this.dataset.getValue(key); boolean include; if (n == null) { include = !this.ignoreNullValues; } else { double v = n.doubleValue(); if (v == 0.0) { include = !this.ignoreZeroValues; } else { include = v > 0.0; } } if (include) { String label = this.legendLabelGenerator.generateSectionLabel( this.dataset, key); if (label != null) { String description = label; String toolTipText = null; if (this.legendLabelToolTipGenerator != null) { toolTipText = this.legendLabelToolTipGenerator .generateSectionLabel(this.dataset, key); } String urlText = null; if (this.legendLabelURLGenerator != null) { urlText = this.legendLabelURLGenerator.generateURL( this.dataset, key, this.pieIndex); } Paint paint = lookupSectionPaint(key); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); LegendItem item = new LegendItem(label, description, toolTipText, urlText, true, shape, true, paint, true, outlinePaint, outlineStroke, false, // line not visible new Line2D.Float(), new BasicStroke(), Color.BLACK); item.setDataset(getDataset()); item.setSeriesIndex(this.dataset.getIndex(key)); item.setSeriesKey(key); result.add(item); } section++; } else { section++; } } return result; } /** * Returns a short string describing the type of plot. * * @return The plot type. */ @Override public String getPlotType() { return localizationResources.getString("Pie_Plot"); } /** * Returns a rectangle that can be used to create a pie section (taking * into account the amount by which the pie section is 'exploded'). * * @param unexploded the area inside which the unexploded pie sections are * drawn. * @param exploded the area inside which the exploded pie sections are * drawn. * @param angle the start angle. * @param extent the extent of the arc. * @param explodePercent the amount by which the pie section is exploded. * * @return A rectangle that can be used to create a pie section. */ protected Rectangle2D getArcBounds(Rectangle2D unexploded, Rectangle2D exploded, double angle, double extent, double explodePercent) { if (explodePercent == 0.0) { return unexploded; } Arc2D arc1 = new Arc2D.Double(unexploded, angle, extent / 2, Arc2D.OPEN); Point2D point1 = arc1.getEndPoint(); Arc2D.Double arc2 = new Arc2D.Double(exploded, angle, extent / 2, Arc2D.OPEN); Point2D point2 = arc2.getEndPoint(); double deltaX = (point1.getX() - point2.getX()) * explodePercent; double deltaY = (point1.getY() - point2.getY()) * explodePercent; return new Rectangle2D.Double(unexploded.getX() - deltaX, unexploded.getY() - deltaY, unexploded.getWidth(), unexploded.getHeight()); } /** * Draws a section label on the left side of the pie chart. * * @param g2 the graphics device. * @param state the state. * @param record the label record. */ protected void drawLeftLabel(Graphics2D g2, PiePlotState state, PieLabelRecord record) { double anchorX = state.getLinkArea().getMinX(); double targetX = anchorX - record.getGap(); double targetY = record.getAllocatedY(); if (this.labelLinksVisible) { double theta = record.getAngle(); double linkX = state.getPieCenterX() + Math.cos(theta) * state.getPieWRadius() * record.getLinkPercent(); double linkY = state.getPieCenterY() - Math.sin(theta) * state.getPieHRadius() * record.getLinkPercent(); double elbowX = state.getPieCenterX() + Math.cos(theta) * state.getLinkArea().getWidth() / 2.0; double elbowY = state.getPieCenterY() - Math.sin(theta) * state.getLinkArea().getHeight() / 2.0; double anchorY = elbowY; g2.setPaint(this.labelLinkPaint); g2.setStroke(this.labelLinkStroke); PieLabelLinkStyle style = getLabelLinkStyle(); if (style.equals(PieLabelLinkStyle.STANDARD)) { g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY)); g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY)); g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY)); } else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) { QuadCurve2D q = new QuadCurve2D.Float(); q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY); g2.draw(q); g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY)); } else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) { CubicCurve2D c = new CubicCurve2D .Float(); c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY, linkX, linkY); g2.draw(c); } } TextBox tb = record.getLabel(); tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.RIGHT); } /** * Draws a section label on the right side of the pie chart. * * @param g2 the graphics device. * @param state the state. * @param record the label record. */ protected void drawRightLabel(Graphics2D g2, PiePlotState state, PieLabelRecord record) { double anchorX = state.getLinkArea().getMaxX(); double targetX = anchorX + record.getGap(); double targetY = record.getAllocatedY(); if (this.labelLinksVisible) { double theta = record.getAngle(); double linkX = state.getPieCenterX() + Math.cos(theta) * state.getPieWRadius() * record.getLinkPercent(); double linkY = state.getPieCenterY() - Math.sin(theta) * state.getPieHRadius() * record.getLinkPercent(); double elbowX = state.getPieCenterX() + Math.cos(theta) * state.getLinkArea().getWidth() / 2.0; double elbowY = state.getPieCenterY() - Math.sin(theta) * state.getLinkArea().getHeight() / 2.0; double anchorY = elbowY; g2.setPaint(this.labelLinkPaint); g2.setStroke(this.labelLinkStroke); PieLabelLinkStyle style = getLabelLinkStyle(); if (style.equals(PieLabelLinkStyle.STANDARD)) { g2.draw(new Line2D.Double(linkX, linkY, elbowX, elbowY)); g2.draw(new Line2D.Double(anchorX, anchorY, elbowX, elbowY)); g2.draw(new Line2D.Double(anchorX, anchorY, targetX, targetY)); } else if (style.equals(PieLabelLinkStyle.QUAD_CURVE)) { QuadCurve2D q = new QuadCurve2D.Float(); q.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY); g2.draw(q); g2.draw(new Line2D.Double(elbowX, elbowY, linkX, linkY)); } else if (style.equals(PieLabelLinkStyle.CUBIC_CURVE)) { CubicCurve2D c = new CubicCurve2D .Float(); c.setCurve(targetX, targetY, anchorX, anchorY, elbowX, elbowY, linkX, linkY); g2.draw(c); } } TextBox tb = record.getLabel(); tb.draw(g2, (float) targetX, (float) targetY, RectangleAnchor.LEFT); } /** * Returns the center for the specified section. * Checks to see if the section is exploded and recalculates the * new center if so. * * @param state PiePlotState * @param key section key. * * @return The center for the specified section. * * @since 1.0.14 */ protected Point2D getArcCenter(PiePlotState state, Comparable key) { Point2D center = new Point2D.Double(state.getPieCenterX(), state .getPieCenterY()); double ep = getExplodePercent(key); double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = ep / mep; } if (ep != 0) { Rectangle2D pieArea = state.getPieArea(); Rectangle2D expPieArea = state.getExplodedPieArea(); double angle1, angle2; Number n = this.dataset.getValue(key); double value = n.doubleValue(); if (this.direction == Rotation.CLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 - value / state.getTotal() * 360.0; } else if (this.direction == Rotation.ANTICLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 + value / state.getTotal() * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); Arc2D arc1 = new Arc2D.Double(pieArea, angle1, angle / 2, Arc2D.OPEN); Point2D point1 = arc1.getEndPoint(); Arc2D.Double arc2 = new Arc2D.Double(expPieArea, angle1, angle / 2, Arc2D.OPEN); Point2D point2 = arc2.getEndPoint(); double deltaX = (point1.getX() - point2.getX()) * ep; double deltaY = (point1.getY() - point2.getY()) * ep; center = new Point2D.Double(state.getPieCenterX() - deltaX, state.getPieCenterY() - deltaY); } return center; } /** * Returns the paint for the specified section. This is equivalent to * <code>lookupSectionPaint(section)</code>. * Checks to see if the user set the Paint to be of type RadialGradientPaint * If so it adjusts the center and radius to match the Pie * * @param key the section key. * @param state PiePlotState. * * @return The paint for the specified section. * * @since 1.0.14 */ protected Paint lookupSectionPaint(Comparable key, PiePlotState state) { Paint paint = lookupSectionPaint(key, getAutoPopulateSectionPaint()); // If using JDK 1.6 or later the passed Paint Object can be a RadialGradientPaint // We need to adjust the radius and center for this object to match the Pie. try { // FIXME : we are using JDK1.6 now, don't need reflection here Class c = Class.forName("java.awt.RadialGradientPaint"); Constructor cc = c.getConstructor(new Class[] { Point2D.class, float.class, float[].class, Color[].class}); if (c.isInstance(paint)) { // User did pass a RadialGradientPaint object Method m = c.getMethod("getFractions", new Class[] {}); Object fractions = m.invoke(paint, new Object[] {}); m = c.getMethod("getColors", new Class[] {}); Object clrs = m.invoke(paint, new Object[] {}); Point2D center = getArcCenter(state, key); float radius = (float) state.getPieHRadius(); Paint radialPaint = (Paint) cc.newInstance(new Object[] { center, radius, fractions, clrs}); // return the new RadialGradientPaint return radialPaint; } } catch (Exception e) { } // Return whatever it was return paint; } /** * Tests this plot for equality with an arbitrary object. Note that the * plot's dataset is NOT included in the test for equality. * * @param obj the object to test against (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PiePlot)) { return false; } if (!super.equals(obj)) { return false; } PiePlot that = (PiePlot) obj; if (this.pieIndex != that.pieIndex) { return false; } if (this.interiorGap != that.interiorGap) { return false; } if (this.circular != that.circular) { return false; } if (this.startAngle != that.startAngle) { return false; } if (this.direction != that.direction) { return false; } if (this.ignoreZeroValues != that.ignoreZeroValues) { return false; } if (this.ignoreNullValues != that.ignoreNullValues) { return false; } if (!ObjectUtilities.equal(this.sectionPaintMap, that.sectionPaintMap)) { return false; } if (!PaintUtilities.equal(this.baseSectionPaint, that.baseSectionPaint)) { return false; } if (this.sectionOutlinesVisible != that.sectionOutlinesVisible) { return false; } if (!ObjectUtilities.equal(this.sectionOutlinePaintMap, that.sectionOutlinePaintMap)) { return false; } if (!PaintUtilities.equal(this.baseSectionOutlinePaint, that.baseSectionOutlinePaint)) { return false; } if (!ObjectUtilities.equal(this.sectionOutlineStrokeMap, that.sectionOutlineStrokeMap)) { return false; } if (!ObjectUtilities.equal(this.baseSectionOutlineStroke, that.baseSectionOutlineStroke)) { return false; } if (!PaintUtilities.equal(this.shadowPaint, that.shadowPaint)) { return false; } if (!(this.shadowXOffset == that.shadowXOffset)) { return false; } if (!(this.shadowYOffset == that.shadowYOffset)) { return false; } if (!ObjectUtilities.equal(this.explodePercentages, that.explodePercentages)) { return false; } if (!ObjectUtilities.equal(this.labelGenerator, that.labelGenerator)) { return false; } if (!ObjectUtilities.equal(this.labelFont, that.labelFont)) { return false; } if (!PaintUtilities.equal(this.labelPaint, that.labelPaint)) { return false; } if (!PaintUtilities.equal(this.labelBackgroundPaint, that.labelBackgroundPaint)) { return false; } if (!PaintUtilities.equal(this.labelOutlinePaint, that.labelOutlinePaint)) { return false; } if (!ObjectUtilities.equal(this.labelOutlineStroke, that.labelOutlineStroke)) { return false; } if (!PaintUtilities.equal(this.labelShadowPaint, that.labelShadowPaint)) { return false; } if (this.simpleLabels != that.simpleLabels) { return false; } if (!this.simpleLabelOffset.equals(that.simpleLabelOffset)) { return false; } if (!this.labelPadding.equals(that.labelPadding)) { return false; } if (!(this.maximumLabelWidth == that.maximumLabelWidth)) { return false; } if (!(this.labelGap == that.labelGap)) { return false; } if (!(this.labelLinkMargin == that.labelLinkMargin)) { return false; } if (this.labelLinksVisible != that.labelLinksVisible) { return false; } if (!this.labelLinkStyle.equals(that.labelLinkStyle)) { return false; } if (!PaintUtilities.equal(this.labelLinkPaint, that.labelLinkPaint)) { return false; } if (!ObjectUtilities.equal(this.labelLinkStroke, that.labelLinkStroke)) { return false; } if (!ObjectUtilities.equal(this.toolTipGenerator, that.toolTipGenerator)) { return false; } if (!ObjectUtilities.equal(this.urlGenerator, that.urlGenerator)) { return false; } if (!(this.minimumArcAngleToDraw == that.minimumArcAngleToDraw)) { return false; } if (!ShapeUtilities.equal(this.legendItemShape, that.legendItemShape)) { return false; } if (!ObjectUtilities.equal(this.legendLabelGenerator, that.legendLabelGenerator)) { return false; } if (!ObjectUtilities.equal(this.legendLabelToolTipGenerator, that.legendLabelToolTipGenerator)) { return false; } if (!ObjectUtilities.equal(this.legendLabelURLGenerator, that.legendLabelURLGenerator)) { return false; } if (this.autoPopulateSectionPaint != that.autoPopulateSectionPaint) { return false; } if (this.autoPopulateSectionOutlinePaint != that.autoPopulateSectionOutlinePaint) { return false; } if (this.autoPopulateSectionOutlineStroke != that.autoPopulateSectionOutlineStroke) { return false; } if (!ObjectUtilities.equal(this.shadowGenerator, that.shadowGenerator)) { return false; } // can't find any difference... return true; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException if some component of the plot does * not support cloning. */ @Override public Object clone() throws CloneNotSupportedException { PiePlot clone = (PiePlot) super.clone(); if (clone.dataset != null) { clone.dataset.addChangeListener(clone); } if (this.urlGenerator instanceof PublicCloneable) { clone.urlGenerator = ObjectUtilities.clone( this.urlGenerator); } clone.legendItemShape = ShapeUtilities.clone(this.legendItemShape); if (this.legendLabelGenerator != null) { clone.legendLabelGenerator = ObjectUtilities.clone(this.legendLabelGenerator); } if (this.legendLabelToolTipGenerator != null) { clone.legendLabelToolTipGenerator = ObjectUtilities.clone(this.legendLabelToolTipGenerator); } if (this.legendLabelURLGenerator instanceof PublicCloneable) { clone.legendLabelURLGenerator = ObjectUtilities.clone(this.legendLabelURLGenerator); } return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.baseSectionPaint, stream); SerialUtilities.writePaint(this.baseSectionOutlinePaint, stream); SerialUtilities.writeStroke(this.baseSectionOutlineStroke, stream); SerialUtilities.writePaint(this.shadowPaint, stream); SerialUtilities.writePaint(this.labelPaint, stream); SerialUtilities.writePaint(this.labelBackgroundPaint, stream); SerialUtilities.writePaint(this.labelOutlinePaint, stream); SerialUtilities.writeStroke(this.labelOutlineStroke, stream); SerialUtilities.writePaint(this.labelShadowPaint, stream); SerialUtilities.writePaint(this.labelLinkPaint, stream); SerialUtilities.writeStroke(this.labelLinkStroke, stream); SerialUtilities.writeShape(this.legendItemShape, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.baseSectionPaint = SerialUtilities.readPaint(stream); this.baseSectionOutlinePaint = SerialUtilities.readPaint(stream); this.baseSectionOutlineStroke = SerialUtilities.readStroke(stream); this.shadowPaint = SerialUtilities.readPaint(stream); this.labelPaint = SerialUtilities.readPaint(stream); this.labelBackgroundPaint = SerialUtilities.readPaint(stream); this.labelOutlinePaint = SerialUtilities.readPaint(stream); this.labelOutlineStroke = SerialUtilities.readStroke(stream); this.labelShadowPaint = SerialUtilities.readPaint(stream); this.labelLinkPaint = SerialUtilities.readPaint(stream); this.labelLinkStroke = SerialUtilities.readStroke(stream); this.legendItemShape = SerialUtilities.readShape(stream); } }
121,796
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Marker.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/Marker.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------- * Marker.java * ----------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Nicolas Brodu; * * Changes * ------- * 02-Jul-2002 : Added extra constructor, standard header and Javadoc * comments (DG); * 20-Aug-2002 : Added the outline stroke attribute (DG); * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 16-Oct-2002 : Added new constructor (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 21-May-2003 : Added labels (DG); * 11-Sep-2003 : Implemented Cloneable (NB); * 05-Nov-2003 : Added checks to ensure some attributes are never null (DG); * 11-Feb-2003 : Moved to org.jfree.chart.plot package, plus significant API * changes to support IntervalMarker in plots (DG); * 14-Jun-2004 : Updated equals() method (DG); * 21-Jan-2005 : Added settings to control direction of horizontal and * vertical label offsets (DG); * 01-Jun-2005 : Modified to use only one label offset type - this will be * applied to the domain or range axis as appropriate (DG); * 06-Jun-2005 : Fix equals() method to handle GradientPaint (DG); * 19-Aug-2005 : Changed constructor from public --> protected (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Sep-2006 : Added MarkerChangeListener support (DG); * 26-Sep-2007 : Fix for serialization bug 1802195 (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Paint; import java.awt.Stroke; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.EventListener; import javax.swing.event.EventListenerList; import org.jfree.chart.ui.LengthAdjustmentType; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.event.MarkerChangeEvent; import org.jfree.chart.event.MarkerChangeListener; import org.jfree.chart.util.SerialUtilities; /** * The base class for markers that can be added to plots to highlight a value * or range of values. * <br><br> * An event notification mechanism was added to this class in JFreeChart * version 1.0.3. */ public abstract class Marker implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -734389651405327166L; /** The paint (null is not allowed). */ private transient Paint paint; /** The stroke (null is not allowed). */ private transient Stroke stroke; /** The outline paint. */ private transient Paint outlinePaint; /** The outline stroke. */ private transient Stroke outlineStroke; /** The alpha transparency. */ private float alpha; /** The label. */ private String label = null; /** The label font. */ private Font labelFont; /** The label paint. */ private transient Paint labelPaint; /** The label position. */ private RectangleAnchor labelAnchor; /** The text anchor for the label. */ private TextAnchor labelTextAnchor; /** The label offset from the marker rectangle. */ private RectangleInsets labelOffset; /** * The offset type for the domain or range axis (never <code>null</code>). */ private LengthAdjustmentType labelOffsetType; /** Storage for registered change listeners. */ private transient EventListenerList listenerList; /** * Creates a new marker with default attributes. */ protected Marker() { this(Color.GRAY); } /** * Constructs a new marker. * * @param paint the paint (<code>null</code> not permitted). */ protected Marker(Paint paint) { this(paint, new BasicStroke(0.5f), Color.GRAY, new BasicStroke(0.5f), 0.80f); } /** * Constructs a new marker. * * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * @param outlinePaint the outline paint (<code>null</code> permitted). * @param outlineStroke the outline stroke (<code>null</code> permitted). * @param alpha the alpha transparency (must be in the range 0.0f to * 1.0f). * * @throws IllegalArgumentException if <code>paint</code> or * <code>stroke</code> is <code>null</code>, or <code>alpha</code> is * not in the specified range. */ protected Marker(Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } if (alpha < 0.0f || alpha > 1.0f) { throw new IllegalArgumentException( "The 'alpha' value must be in the range 0.0f to 1.0f"); } this.paint = paint; this.stroke = stroke; this.outlinePaint = outlinePaint; this.outlineStroke = outlineStroke; this.alpha = alpha; this.labelFont = new Font("SansSerif", Font.PLAIN, 9); this.labelPaint = Color.BLACK; this.labelAnchor = RectangleAnchor.TOP_LEFT; this.labelOffset = new RectangleInsets(3.0, 3.0, 3.0, 3.0); this.labelOffsetType = LengthAdjustmentType.CONTRACT; this.labelTextAnchor = TextAnchor.CENTER; this.listenerList = new EventListenerList(); } /** * Returns the paint. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint and sends a {@link MarkerChangeEvent} to all registered * listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the stroke. * * @return The stroke (never <code>null</code>). * * @see #setStroke(Stroke) */ public Stroke getStroke() { return this.stroke; } /** * Sets the stroke and sends a {@link MarkerChangeEvent} to all registered * listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke() */ public void setStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.stroke = stroke; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the outline paint. * * @return The outline paint (possibly <code>null</code>). * * @see #setOutlinePaint(Paint) */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Sets the outline paint and sends a {@link MarkerChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getOutlinePaint() */ public void setOutlinePaint(Paint paint) { this.outlinePaint = paint; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the outline stroke. * * @return The outline stroke (possibly <code>null</code>). * * @see #setOutlineStroke(Stroke) */ public Stroke getOutlineStroke() { return this.outlineStroke; } /** * Sets the outline stroke and sends a {@link MarkerChangeEvent} to all * registered listeners. * * @param stroke the stroke (<code>null</code> permitted). * * @see #getOutlineStroke() */ public void setOutlineStroke(Stroke stroke) { this.outlineStroke = stroke; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the alpha transparency. * * @return The alpha transparency. * * @see #setAlpha(float) */ public float getAlpha() { return this.alpha; } /** * Sets the alpha transparency that should be used when drawing the * marker, and sends a {@link MarkerChangeEvent} to all registered * listeners. The alpha transparency is a value in the range 0.0f * (completely transparent) to 1.0f (completely opaque). * * @param alpha the alpha transparency (must be in the range 0.0f to * 1.0f). * * @throws IllegalArgumentException if <code>alpha</code> is not in the * specified range. * * @see #getAlpha() */ public void setAlpha(float alpha) { if (alpha < 0.0f || alpha > 1.0f) { throw new IllegalArgumentException( "The 'alpha' value must be in the range 0.0f to 1.0f"); } this.alpha = alpha; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label (if <code>null</code> no label is displayed). * * @return The label (possibly <code>null</code>). * * @see #setLabel(String) */ public String getLabel() { return this.label; } /** * Sets the label (if <code>null</code> no label is displayed) and sends a * {@link MarkerChangeEvent} to all registered listeners. * * @param label the label (<code>null</code> permitted). * * @see #getLabel() */ public void setLabel(String label) { this.label = label; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label font. * * @return The label font (never <code>null</code>). * * @see #setLabelFont(Font) */ public Font getLabelFont() { return this.labelFont; } /** * Sets the label font and sends a {@link MarkerChangeEvent} to all * registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getLabelFont() */ public void setLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.labelFont = font; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label paint. * * @return The label paint (never </code>null</code>). * * @see #setLabelPaint(Paint) */ public Paint getLabelPaint() { return this.labelPaint; } /** * Sets the label paint and sends a {@link MarkerChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getLabelPaint() */ public void setLabelPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.labelPaint = paint; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label anchor. This defines the position of the label * anchor, relative to the bounds of the marker. * * @return The label anchor (never <code>null</code>). * * @see #setLabelAnchor(RectangleAnchor) */ public RectangleAnchor getLabelAnchor() { return this.labelAnchor; } /** * Sets the label anchor and sends a {@link MarkerChangeEvent} to all * registered listeners. The anchor defines the position of the label * anchor, relative to the bounds of the marker. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getLabelAnchor() */ public void setLabelAnchor(RectangleAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.labelAnchor = anchor; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label offset. * * @return The label offset (never <code>null</code>). * * @see #setLabelOffset(RectangleInsets) */ public RectangleInsets getLabelOffset() { return this.labelOffset; } /** * Sets the label offset and sends a {@link MarkerChangeEvent} to all * registered listeners. * * @param offset the label offset (<code>null</code> not permitted). * * @see #getLabelOffset() */ public void setLabelOffset(RectangleInsets offset) { if (offset == null) { throw new IllegalArgumentException("Null 'offset' argument."); } this.labelOffset = offset; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label offset type. * * @return The type (never <code>null</code>). * * @see #setLabelOffsetType(LengthAdjustmentType) */ public LengthAdjustmentType getLabelOffsetType() { return this.labelOffsetType; } /** * Sets the label offset type and sends a {@link MarkerChangeEvent} to all * registered listeners. * * @param adj the type (<code>null</code> not permitted). * * @see #getLabelOffsetType() */ public void setLabelOffsetType(LengthAdjustmentType adj) { if (adj == null) { throw new IllegalArgumentException("Null 'adj' argument."); } this.labelOffsetType = adj; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the label text anchor. * * @return The label text anchor (never <code>null</code>). * * @see #setLabelTextAnchor(TextAnchor) */ public TextAnchor getLabelTextAnchor() { return this.labelTextAnchor; } /** * Sets the label text anchor and sends a {@link MarkerChangeEvent} to * all registered listeners. * * @param anchor the label text anchor (<code>null</code> not permitted). * * @see #getLabelTextAnchor() */ public void setLabelTextAnchor(TextAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.labelTextAnchor = anchor; notifyListeners(new MarkerChangeEvent(this)); } /** * Registers an object for notification of changes to the marker. * * @param listener the object to be registered. * * @see #removeChangeListener(MarkerChangeListener) * * @since 1.0.3 */ public void addChangeListener(MarkerChangeListener listener) { this.listenerList.add(MarkerChangeListener.class, listener); } /** * Unregisters an object for notification of changes to the marker. * * @param listener the object to be unregistered. * * @see #addChangeListener(MarkerChangeListener) * * @since 1.0.3 */ public void removeChangeListener(MarkerChangeListener listener) { this.listenerList.remove(MarkerChangeListener.class, listener); } /** * Notifies all registered listeners that the marker has been modified. * * @param event information about the change event. * * @since 1.0.3 */ public void notifyListeners(MarkerChangeEvent event) { Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == MarkerChangeListener.class) { ((MarkerChangeListener) listeners[i + 1]).markerChanged(event); } } } /** * Returns an array containing all the listeners of the specified type. * * @param listenerType the listener type. * * @return The array of listeners. * * @since 1.0.3 */ public EventListener[] getListeners(Class listenerType) { return this.listenerList.getListeners(listenerType); } /** * Tests the marker for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Marker)) { return false; } Marker that = (Marker) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!ObjectUtilities.equal(this.stroke, that.stroke)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) { return false; } if (this.alpha != that.alpha) { return false; } if (!ObjectUtilities.equal(this.label, that.label)) { return false; } if (!ObjectUtilities.equal(this.labelFont, that.labelFont)) { return false; } if (!PaintUtilities.equal(this.labelPaint, that.labelPaint)) { return false; } if (this.labelAnchor != that.labelAnchor) { return false; } if (this.labelTextAnchor != that.labelTextAnchor) { return false; } if (!ObjectUtilities.equal(this.labelOffset, that.labelOffset)) { return false; } if (!this.labelOffsetType.equals(that.labelOffsetType)) { return false; } return true; } /** * Creates a clone of the marker. * * @return A clone. * * @throws CloneNotSupportedException never. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writeStroke(this.stroke, stream); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writeStroke(this.outlineStroke, stream); SerialUtilities.writePaint(this.labelPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.stroke = SerialUtilities.readStroke(stream); this.outlinePaint = SerialUtilities.readPaint(stream); this.outlineStroke = SerialUtilities.readStroke(stream); this.labelPaint = SerialUtilities.readPaint(stream); this.listenerList = new EventListenerList(); } }
20,916
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryMarker.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CategoryMarker.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * CategoryMarker.java * ------------------- * (C) Copyright 2005-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Nicolas Brodu; * * Changes * ------- * 20-May-2005 : Version 1 (DG); * 19-Aug-2005 : Implemented equals(), fixed bug in constructor (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Sep-2006 : Added MarkerChangeListener support (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Paint; import java.awt.Stroke; import java.io.Serializable; import org.jfree.chart.ui.LengthAdjustmentType; import org.jfree.chart.event.MarkerChangeEvent; /** * A marker for a category. * <br><br> * Note that for serialization to work correctly, the category key must be an * instance of a serializable class. * * @see CategoryPlot#addDomainMarker(CategoryMarker) */ public class CategoryMarker extends Marker implements Cloneable, Serializable { /** The category key. */ private Comparable key; /** * A hint that the marker should be drawn as a line rather than a region. */ private boolean drawAsLine = false; /** * Creates a new category marker for the specified category. * * @param key the category key. */ public CategoryMarker(Comparable key) { this(key, Color.GRAY, new BasicStroke(1.0f)); } /** * Creates a new category marker. * * @param key the key. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). */ public CategoryMarker(Comparable key, Paint paint, Stroke stroke) { this(key, paint, stroke, paint, stroke, 1.0f); } /** * Creates a new category marker. * * @param key the key. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * @param outlinePaint the outline paint (<code>null</code> permitted). * @param outlineStroke the outline stroke (<code>null</code> permitted). * @param alpha the alpha transparency. */ public CategoryMarker(Comparable key, Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { super(paint, stroke, outlinePaint, outlineStroke, alpha); this.key = key; setLabelOffsetType(LengthAdjustmentType.EXPAND); } /** * Returns the key. * * @return The key. */ public Comparable getKey() { return this.key; } /** * Sets the key and sends a {@link MarkerChangeEvent} to all registered * listeners. * * @param key the key (<code>null</code> not permitted). * * @since 1.0.3 */ public void setKey(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } this.key = key; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the flag that controls whether the marker is drawn as a region * or a line. * * @return A line. */ public boolean getDrawAsLine() { return this.drawAsLine; } /** * Sets the flag that controls whether the marker is drawn as a region or * as a line, and sends a {@link MarkerChangeEvent} to all registered * listeners. * * @param drawAsLine the flag. */ public void setDrawAsLine(boolean drawAsLine) { this.drawAsLine = drawAsLine; notifyListeners(new MarkerChangeEvent(this)); } /** * Tests the marker for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof CategoryMarker)) { return false; } if (!super.equals(obj)) { return false; } CategoryMarker that = (CategoryMarker) obj; if (!this.key.equals(that.key)) { return false; } if (this.drawAsLine != that.drawAsLine) { return false; } return true; } }
5,745
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PlotUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PlotUtilities.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * PlotUtilities.java * ------------------ * (C) Copyright 2007, 2008, by Sergei Ivanov and Contributors. * * Original Author: Sergei Ivanov; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 26-Sep-2007 : Version 1, contributed by Sergei Ivanov (see patch * 1772932) (DG); * */ package org.jfree.chart.plot; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.xy.XYDataset; /** * Some utility methods related to the plot classes. * * @since 1.0.7 */ public class PlotUtilities { /** * Returns <code>true</code> if all the datasets belonging to the specified * plot are empty or <code>null</code>, and <code>false</code> otherwise. * * @param plot the plot (<code>null</code> permitted). * * @return A boolean. * * @since 1.0.7 */ public static boolean isEmptyOrNull(XYPlot plot) { if (plot != null) { for (int i = 0, n = plot.getDatasetCount(); i < n; i++) { final XYDataset dataset = plot.getDataset(i); if (!DatasetUtilities.isEmptyOrNull(dataset)) { return false; } } } return true; } }
2,504
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Zoomable.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/Zoomable.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * Zoomable.java * ------------- * * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Rune Fauske; * * Changes * ------- * 12-Nov-2004 : Version 1 (DG); * 26-Jan-2004 : Added getOrientation() method (DG); * 04-Sep-2006 : Added credit for Rune Fauske, see patch 1050659 (DG); * 21-Sep-2007 : Added new zooming methods with 'useAnchor' flag. This breaks * the API, but is the cleanest way I can think of to fix a * long-standing bug (DG); * */ package org.jfree.chart.plot; import java.awt.geom.Point2D; import org.jfree.chart.ChartPanel; /** * A plot that is zoomable must implement this interface to provide a * mechanism for the {@link ChartPanel} to control the zooming. */ public interface Zoomable { /** * Returns <code>true</code> if the plot's domain is zoomable, and * <code>false</code> otherwise. * * @return A boolean. * * @see #isRangeZoomable() */ public boolean isDomainZoomable(); /** * Returns <code>true</code> if the plot's range is zoomable, and * <code>false</code> otherwise. * * @return A boolean. * * @see #isDomainZoomable() */ public boolean isRangeZoomable(); /** * Returns the orientation of the plot. * * @return The orientation. */ public PlotOrientation getOrientation(); /** * Multiplies the range on the domain axis/axes by the specified factor. * The <code>source</code> point can be used in some cases to identify a * subplot, or to determine the center of zooming (refer to the * documentation of the implementing class for details). * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D) */ public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source); /** * Multiplies the range on the domain axis/axes by the specified factor. * The <code>source</code> point can be used in some cases to identify a * subplot, or to determine the center of zooming (refer to the * documentation of the implementing class for details). * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). * @param useAnchor use source point as zoom anchor? * * @see #zoomRangeAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor); /** * Zooms in on the domain axes. The <code>source</code> point can be used * in some cases to identify a subplot for zooming. * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. * @param source the source point (in Java2D coordinates). * * @see #zoomRangeAxes(double, double, PlotRenderingInfo, Point2D) */ public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source); /** * Multiplies the range on the range axis/axes by the specified factor. * The <code>source</code> point can be used in some cases to identify a * subplot, or to determine the center of zooming (refer to the * documentation of the implementing class for details). * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D) */ public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source); /** * Multiplies the range on the range axis/axes by the specified factor. * The <code>source</code> point can be used in some cases to identify a * subplot, or to determine the center of zooming (refer to the * documentation of the implementing class for details). * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). * @param useAnchor use source point as zoom anchor? * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D) * * @since 1.0.7 */ public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor); /** * Zooms in on the range axes. The <code>source</code> point can be used * in some cases to identify a subplot for zooming. * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. * @param source the source point (in Java2D coordinates). * * @see #zoomDomainAxes(double, double, PlotRenderingInfo, Point2D) */ public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source); }
6,642
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WaferMapPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/WaferMapPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * WaferMapPlot.java * ----------------- * * (C) Copyright 2003-2014, by Robert Redburn and Contributors. * * Original Author: Robert Redburn; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 25-Nov-2003 : Version 1 contributed by Robert Redburn (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 10-Jun-2005 : Changed private --> protected for drawChipGrid(), * drawWaferEdge() and getWafterEdge() (DG); * 16-Jun-2005 : Added default constructor and setDataset() method (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.Serializable; import java.util.List; import java.util.ResourceBundle; import org.jfree.chart.LegendItem; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; import org.jfree.chart.event.RendererChangeListener; import org.jfree.chart.renderer.WaferMapRenderer; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.WaferMapDataset; /** * A wafer map plot. */ public class WaferMapPlot extends Plot implements RendererChangeListener, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 4668320403707308155L; /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] {2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.LIGHT_GRAY; /** The default crosshair visibility. */ public static final boolean DEFAULT_CROSSHAIR_VISIBLE = false; /** The default crosshair stroke. */ public static final Stroke DEFAULT_CROSSHAIR_STROKE = DEFAULT_GRIDLINE_STROKE; /** The default crosshair paint. */ public static final Paint DEFAULT_CROSSHAIR_PAINT = Color.BLUE; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** The plot orientation. * vertical = notch down * horizontal = notch right */ private PlotOrientation orientation; /** The dataset. */ private WaferMapDataset dataset; /** * Object responsible for drawing the visual representation of each point * on the plot. */ private WaferMapRenderer renderer; /** * Creates a new plot with no dataset. */ public WaferMapPlot() { this(null); } /** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). */ public WaferMapPlot(WaferMapDataset dataset) { this(dataset, null); } /** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). * @param renderer the renderer (<code>null</code> permitted). */ public WaferMapPlot(WaferMapDataset dataset, WaferMapRenderer renderer) { super(); this.orientation = PlotOrientation.VERTICAL; this.dataset = dataset; if (dataset != null) { dataset.addChangeListener(this); } this.renderer = renderer; if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } } /** * Returns the plot type as a string. * * @return A short string describing the type of plot. */ @Override public String getPlotType() { return ("WMAP_Plot"); } /** * Returns the dataset * * @return The dataset (possibly <code>null</code>). */ public WaferMapDataset getDataset() { return this.dataset; } /** * Sets the dataset used by the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param dataset the dataset (<code>null</code> permitted). */ public void setDataset(WaferMapDataset dataset) { // if there is an existing dataset, remove the plot from the list of // change listeners... if (this.dataset != null) { this.dataset.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self to trigger plot change event datasetChanged(new DatasetChangeEvent(this, dataset)); } /** * Sets the item renderer, and notifies all listeners of a change to the * plot. If the renderer is set to <code>null</code>, no chart will be * drawn. * * @param renderer the new renderer (<code>null</code> permitted). */ public void setRenderer(WaferMapRenderer renderer) { if (this.renderer != null) { this.renderer.removeChangeListener(this); } this.renderer = renderer; if (renderer != null) { renderer.setPlot(this); } fireChangeEvent(); } /** * Draws the wafermap view. * * @param g2 the graphics device. * @param area the plot area. * @param anchor the anchor point (<code>null</code> permitted). * @param state the plot state. * @param info the plot rendering info. */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState state, PlotRenderingInfo info) { // if the plot area is too small, just return... boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; } // record the plot area... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); drawChipGrid(g2, area); drawWaferEdge(g2, area); } /** * Calculates and draws the chip locations on the wafer. * * @param g2 the graphics device. * @param plotArea the plot area. */ protected void drawChipGrid(Graphics2D g2, Rectangle2D plotArea) { Shape savedClip = g2.getClip(); g2.setClip(getWaferEdge(plotArea)); Rectangle2D chip = new Rectangle2D.Double(); int xchips = 35; int ychips = 20; double space = 1d; if (this.dataset != null) { xchips = this.dataset.getMaxChipX() + 2; ychips = this.dataset.getMaxChipY() + 2; space = this.dataset.getChipSpace(); } double startX = plotArea.getX(); double startY = plotArea.getY(); double chipWidth = 1d; double chipHeight = 1d; if (plotArea.getWidth() != plotArea.getHeight()) { double major, minor; if (plotArea.getWidth() > plotArea.getHeight()) { major = plotArea.getWidth(); minor = plotArea.getHeight(); } else { major = plotArea.getHeight(); minor = plotArea.getWidth(); } //set upperLeft point if (plotArea.getWidth() == minor) { // x is minor startY += (major - minor) / 2; chipWidth = (plotArea.getWidth() - (space * xchips - 1)) / xchips; chipHeight = (plotArea.getWidth() - (space * ychips - 1)) / ychips; } else { // y is minor startX += (major - minor) / 2; chipWidth = (plotArea.getHeight() - (space * xchips - 1)) / xchips; chipHeight = (plotArea.getHeight() - (space * ychips - 1)) / ychips; } } for (int x = 1; x <= xchips; x++) { double upperLeftX = (startX - chipWidth) + (chipWidth * x) + (space * (x - 1)); for (int y = 1; y <= ychips; y++) { double upperLeftY = (startY - chipHeight) + (chipHeight * y) + (space * (y - 1)); chip.setFrame(upperLeftX, upperLeftY, chipWidth, chipHeight); g2.setColor(Color.WHITE); if (this.dataset.getChipValue(x - 1, ychips - y - 1) != null) { g2.setPaint( this.renderer.getChipColor( this.dataset.getChipValue(x - 1, ychips - y - 1) ) ); } g2.fill(chip); g2.setColor(Color.LIGHT_GRAY); g2.draw(chip); } } g2.setClip(savedClip); } /** * Calculates the location of the waferedge. * * @param plotArea the plot area. * * @return The wafer edge. */ protected Ellipse2D getWaferEdge(Rectangle2D plotArea) { Ellipse2D edge = new Ellipse2D.Double(); double diameter = plotArea.getWidth(); double upperLeftX = plotArea.getX(); double upperLeftY = plotArea.getY(); //get major dimension if (plotArea.getWidth() != plotArea.getHeight()) { double major, minor; if (plotArea.getWidth() > plotArea.getHeight()) { major = plotArea.getWidth(); minor = plotArea.getHeight(); } else { major = plotArea.getHeight(); minor = plotArea.getWidth(); } //ellipse diameter is the minor dimension diameter = minor; //set upperLeft point if (plotArea.getWidth() == minor) { // x is minor upperLeftY = plotArea.getY() + (major - minor) / 2; } else { // y is minor upperLeftX = plotArea.getX() + (major - minor) / 2; } } edge.setFrame(upperLeftX, upperLeftY, diameter, diameter); return edge; } /** * Draws the waferedge, including the notch. * * @param g2 the graphics device. * @param plotArea the plot area. */ protected void drawWaferEdge(Graphics2D g2, Rectangle2D plotArea) { // draw the wafer Ellipse2D waferEdge = getWaferEdge(plotArea); g2.setColor(Color.BLACK); g2.draw(waferEdge); // calculate and draw the notch // horizontal orientation is considered notch right // vertical orientation is considered notch down Arc2D notch; Rectangle2D waferFrame = waferEdge.getFrame(); double notchDiameter = waferFrame.getWidth() * 0.04; if (this.orientation == PlotOrientation.HORIZONTAL) { Rectangle2D notchFrame = new Rectangle2D.Double( waferFrame.getX() + waferFrame.getWidth() - (notchDiameter / 2), waferFrame.getY() + (waferFrame.getHeight() / 2) - (notchDiameter / 2), notchDiameter, notchDiameter ); notch = new Arc2D.Double(notchFrame, 90d, 180d, Arc2D.OPEN); } else { Rectangle2D notchFrame = new Rectangle2D.Double( waferFrame.getX() + (waferFrame.getWidth() / 2) - (notchDiameter / 2), waferFrame.getY() + waferFrame.getHeight() - (notchDiameter / 2), notchDiameter, notchDiameter ); notch = new Arc2D.Double(notchFrame, 0d, 180d, Arc2D.OPEN); } g2.setColor(Color.WHITE); g2.fill(notch); g2.setColor(Color.BLACK); g2.draw(notch); } /** * Return the legend items from the renderer. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { return this.renderer.getLegendCollection(); } /** * Notifies all registered listeners of a renderer change. * * @param event the event. */ @Override public void rendererChanged(RendererChangeEvent event) { fireChangeEvent(); } }
14,374
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
IntervalMarker.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/IntervalMarker.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * IntervalMarker.java * ------------------- * (C) Copyright 2002-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Aug-2002 : Added stroke to constructor in Marker class (DG); * 02-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 26-Mar-2003 : Implemented Serializable (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Sep-2006 : Added MarkerChangeEvent notification (DG); * 18-Dec-2007 : Added new constructor (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Paint; import java.awt.Stroke; import java.io.Serializable; import org.jfree.chart.ui.GradientPaintTransformer; import org.jfree.chart.ui.LengthAdjustmentType; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.event.MarkerChangeEvent; /** * Represents an interval to be highlighted in some way. */ public class IntervalMarker extends Marker implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -1762344775267627916L; /** The start value. */ private double startValue; /** The end value. */ private double endValue; /** The gradient paint transformer (optional). */ private GradientPaintTransformer gradientPaintTransformer; /** * Constructs an interval marker. * * @param start the start of the interval. * @param end the end of the interval. */ public IntervalMarker(double start, double end) { this(start, end, Color.GRAY, new BasicStroke(0.5f), Color.GRAY, new BasicStroke(0.5f), 0.8f); } /** * Creates a new interval marker with the specified range and fill paint. * The outline paint and stroke default to <code>null</code>. * * @param start the lower bound of the interval. * @param end the upper bound of the interval. * @param paint the fill paint (<code>null</code> not permitted). * * @since 1.0.9 */ public IntervalMarker(double start, double end, Paint paint) { this(start, end, paint, new BasicStroke(0.5f), null, null, 0.8f); } /** * Constructs an interval marker. * * @param start the start of the interval. * @param end the end of the interval. * @param paint the paint (<code>null</code> not permitted). * @param stroke the stroke (<code>null</code> not permitted). * @param outlinePaint the outline paint. * @param outlineStroke the outline stroke. * @param alpha the alpha transparency. */ public IntervalMarker(double start, double end, Paint paint, Stroke stroke, Paint outlinePaint, Stroke outlineStroke, float alpha) { super(paint, stroke, outlinePaint, outlineStroke, alpha); this.startValue = start; this.endValue = end; this.gradientPaintTransformer = null; setLabelOffsetType(LengthAdjustmentType.CONTRACT); } /** * Returns the start value for the interval. * * @return The start value. */ public double getStartValue() { return this.startValue; } /** * Sets the start value for the marker and sends a * {@link MarkerChangeEvent} to all registered listeners. * * @param value the value. * * @since 1.0.3 */ public void setStartValue(double value) { this.startValue = value; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the end value for the interval. * * @return The end value. */ public double getEndValue() { return this.endValue; } /** * Sets the end value for the marker and sends a * {@link MarkerChangeEvent} to all registered listeners. * * @param value the value. * * @since 1.0.3 */ public void setEndValue(double value) { this.endValue = value; notifyListeners(new MarkerChangeEvent(this)); } /** * Returns the gradient paint transformer. * * @return The gradient paint transformer (possibly <code>null</code>). */ public GradientPaintTransformer getGradientPaintTransformer() { return this.gradientPaintTransformer; } /** * Sets the gradient paint transformer and sends a * {@link MarkerChangeEvent} to all registered listeners. * * @param transformer the transformer (<code>null</code> permitted). */ public void setGradientPaintTransformer( GradientPaintTransformer transformer) { this.gradientPaintTransformer = transformer; notifyListeners(new MarkerChangeEvent(this)); } /** * Tests the marker for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof IntervalMarker)) { return false; } if (!super.equals(obj)) { return false; } IntervalMarker that = (IntervalMarker) obj; if (this.startValue != that.startValue) { return false; } if (this.endValue != that.endValue) { return false; } if (!ObjectUtilities.equal(this.gradientPaintTransformer, that.gradientPaintTransformer)) { return false; } return true; } /** * Returns a clone of the marker. * * @return A clone. * * @throws CloneNotSupportedException Not thrown by this class, but the * exception is declared for the use of subclasses. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } }
7,369
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieLabelDistributor.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PieLabelDistributor.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * PieLabelDistributor.java * ------------------------ * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Mar-2004 : Version 1 (DG); * 18-Apr-2005 : Use StringBuffer (DG); * 14-Jun-2007 : Now extends AbstractPieLabelDistributor (DG); * 31-Mar-2008 : Fix bugs in label distribution (DG); * */ package org.jfree.chart.plot; import java.util.Collections; /** * This class distributes the section labels for one side of a pie chart so * that they do not overlap. */ public class PieLabelDistributor extends AbstractPieLabelDistributor { /** The minimum gap. */ private double minGap = 4.0; /** * Creates a new distributor. * * @param labelCount the number of labels (ignored). */ public PieLabelDistributor(int labelCount) { super(); } /** * Distributes the labels. * * @param minY the minimum y-coordinate in Java2D-space. * @param height the available height (in Java2D units). */ @Override public void distributeLabels(double minY, double height) { sort(); // sorts the label records into ascending order by baseY // if (isOverlap()) { // adjustInwards(); // } // if still overlapping, do something else... if (isOverlap()) { adjustDownwards(minY, height); } if (isOverlap()) { adjustUpwards(minY, height); } if (isOverlap()) { spreadEvenly(minY, height); } } /** * Returns <code>true</code> if there are overlapping labels in the list, * and <code>false</code> otherwise. * * @return A boolean. */ private boolean isOverlap() { double y = 0.0; for (int i = 0; i < this.labels.size(); i++) { PieLabelRecord plr = getPieLabelRecord(i); if (y > plr.getLowerY()) { return true; } y = plr.getUpperY(); } return false; } /** * Adjusts the y-coordinate for the labels in towards the center in an * attempt to fix overlapping. */ protected void adjustInwards() { int lower = 0; int upper = this.labels.size() - 1; while (upper > lower) { if (lower < upper - 1) { PieLabelRecord r0 = getPieLabelRecord(lower); PieLabelRecord r1 = getPieLabelRecord(lower + 1); if (r1.getLowerY() < r0.getUpperY()) { double adjust = r0.getUpperY() - r1.getLowerY() + this.minGap; r1.setAllocatedY(r1.getAllocatedY() + adjust); } } PieLabelRecord r2 = getPieLabelRecord(upper - 1); PieLabelRecord r3 = getPieLabelRecord(upper); if (r2.getUpperY() > r3.getLowerY()) { double adjust = (r2.getUpperY() - r3.getLowerY()) + this.minGap; r3.setAllocatedY(r3.getAllocatedY() + adjust); } lower++; upper--; } } /** * Any labels that are overlapping are moved down in an attempt to * eliminate the overlaps. * * @param minY the minimum y value (in Java2D coordinate space). * @param height the height available for all labels. */ protected void adjustDownwards(double minY, double height) { for (int i = 0; i < this.labels.size() - 1; i++) { PieLabelRecord record0 = getPieLabelRecord(i); PieLabelRecord record1 = getPieLabelRecord(i + 1); if (record1.getLowerY() < record0.getUpperY()) { record1.setAllocatedY(Math.min(minY + height - record1.getLabelHeight() / 2.0, record0.getUpperY() + this.minGap + record1.getLabelHeight() / 2.0)); } } } /** * Any labels that are overlapping are moved up in an attempt to eliminate * the overlaps. * * @param minY the minimum y value (in Java2D coordinate space). * @param height the height available for all labels. */ protected void adjustUpwards(double minY, double height) { for (int i = this.labels.size() - 1; i > 0; i--) { PieLabelRecord record0 = getPieLabelRecord(i); PieLabelRecord record1 = getPieLabelRecord(i - 1); if (record1.getUpperY() > record0.getLowerY()) { record1.setAllocatedY(Math.max(minY + record1.getLabelHeight() / 2.0, record0.getLowerY() - this.minGap - record1.getLabelHeight() / 2.0)); } } } /** * Labels are spaced evenly in the available space in an attempt to * eliminate the overlaps. * * @param minY the minimum y value (in Java2D coordinate space). * @param height the height available for all labels. */ protected void spreadEvenly(double minY, double height) { double y = minY; double sumOfLabelHeights = 0.0; for (int i = 0; i < this.labels.size(); i++) { sumOfLabelHeights += getPieLabelRecord(i).getLabelHeight(); } double gap = height - sumOfLabelHeights; if (this.labels.size() > 1) { gap = gap / (this.labels.size() - 1); } for (int i = 0; i < this.labels.size(); i++) { PieLabelRecord record = getPieLabelRecord(i); y = y + record.getLabelHeight() / 2.0; record.setAllocatedY(y); y = y + record.getLabelHeight() / 2.0 + gap; } } /** * Sorts the label records into ascending order by y-value. */ public void sort() { Collections.sort(this.labels); } /** * Returns a string containing a description of the object for * debugging purposes. * * @return A string. */ @Override public String toString() { StringBuilder result = new StringBuilder(); for (int i = 0; i < this.labels.size(); i++) { result.append(getPieLabelRecord(i).toString()).append("\n"); } return result.toString(); } }
7,603
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Crosshair.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/Crosshair.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * Crosshair.java * -------------- * (C) Copyright 2009-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 13-Feb-2009 : Version 1 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Paint; import java.awt.Stroke; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.labels.CrosshairLabelGenerator; import org.jfree.chart.labels.StandardCrosshairLabelGenerator; import org.jfree.chart.util.SerialUtilities; /** * A crosshair for display on a plot. * * @since 1.0.13 */ public class Crosshair implements Cloneable, PublicCloneable, Serializable { /** Flag controlling visibility. */ private boolean visible; /** The crosshair value. */ private double value; /** The paint for the crosshair line. */ private transient Paint paint; /** The stroke for the crosshair line. */ private transient Stroke stroke; /** * A flag that controls whether or not the crosshair has a label * visible. */ private boolean labelVisible; /** * The label anchor. */ private RectangleAnchor labelAnchor; /** A label generator. */ private CrosshairLabelGenerator labelGenerator; /** * The x-offset in Java2D units. */ private double labelXOffset; /** * The y-offset in Java2D units. */ private double labelYOffset; /** * The label font. */ private Font labelFont; /** * The label paint. */ private transient Paint labelPaint; /** * The label background paint. */ private transient Paint labelBackgroundPaint; /** A flag that controls the visibility of the label outline. */ private boolean labelOutlineVisible; /** The label outline stroke. */ private transient Stroke labelOutlineStroke; /** The label outline paint. */ private transient Paint labelOutlinePaint; /** Property change support. */ private transient PropertyChangeSupport pcs; /** * Creates a new crosshair with value 0.0. */ public Crosshair() { this(0.0); } /** * Creates a new crosshair with the specified value. * * @param value the value. */ public Crosshair(double value) { this(value, Color.BLACK, new BasicStroke(1.0f)); } /** * Creates a new crosshair value with the specified value and line style. * * @param value the value. * @param paint the line paint (<code>null</code> not permitted). * @param stroke the line stroke (<code>null</code> not permitted). */ public Crosshair(double value, Paint paint, Stroke stroke) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.visible = true; this.value = value; this.paint = paint; this.stroke = stroke; this.labelVisible = false; this.labelGenerator = new StandardCrosshairLabelGenerator(); this.labelAnchor = RectangleAnchor.BOTTOM_LEFT; this.labelXOffset = 3.0; this.labelYOffset = 3.0; this.labelFont = new Font("Tahoma", Font.PLAIN, 12); this.labelPaint = Color.BLACK; this.labelBackgroundPaint = new Color(0, 0, 255, 63); this.labelOutlineVisible = true; this.labelOutlinePaint = Color.BLACK; this.labelOutlineStroke = new BasicStroke(0.5f); this.pcs = new PropertyChangeSupport(this); } /** * Returns the flag that indicates whether or not the crosshair is * currently visible. * * @return A boolean. * * @see #setVisible(boolean) */ public boolean isVisible() { return this.visible; } /** * Sets the flag that controls the visibility of the crosshair and sends * a proerty change event (with the name 'visible') to all registered * listeners. * * @param visible the new flag value. * * @see #isVisible() */ public void setVisible(boolean visible) { boolean old = this.visible; this.visible = visible; this.pcs.firePropertyChange("visible", old, visible); } /** * Returns the crosshair value. * * @return The crosshair value. * * @see #setValue(double) */ public double getValue() { return this.value; } /** * Sets the crosshair value and sends a property change event with the name * 'value' to all registered listeners. * * @param value the value. * * @see #getValue() */ public void setValue(double value) { Double oldValue = this.value; this.value = value; this.pcs.firePropertyChange("value", oldValue, value); } /** * Returns the paint for the crosshair line. * * @return The paint (never <code>null</code>). * * @see #setPaint(java.awt.Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint for the crosshair line and sends a property change event * with the name "paint" to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { Paint old = this.paint; this.paint = paint; this.pcs.firePropertyChange("paint", old, paint); } /** * Returns the stroke for the crosshair line. * * @return The stroke (never <code>null</code>). * * @see #setStroke(java.awt.Stroke) */ public Stroke getStroke() { return this.stroke; } /** * Sets the stroke for the crosshair line and sends a property change event * with the name "stroke" to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke() */ public void setStroke(Stroke stroke) { Stroke old = this.stroke; this.stroke = stroke; this.pcs.firePropertyChange("stroke", old, stroke); } /** * Returns the flag that controls whether or not a label is drawn for * this crosshair. * * @return A boolean. * * @see #setLabelVisible(boolean) */ public boolean isLabelVisible() { return this.labelVisible; } /** * Sets the flag that controls whether or not a label is drawn for the * crosshair and sends a property change event (with the name * 'labelVisible') to all registered listeners. * * @param visible the new flag value. * * @see #isLabelVisible() */ public void setLabelVisible(boolean visible) { boolean old = this.labelVisible; this.labelVisible = visible; this.pcs.firePropertyChange("labelVisible", old, visible); } /** * Returns the crosshair label generator. * * @return The label crosshair generator (never <code>null</code>). * * @see #setLabelGenerator(org.jfree.chart.labels.CrosshairLabelGenerator) */ public CrosshairLabelGenerator getLabelGenerator() { return this.labelGenerator; } /** * Sets the crosshair label generator and sends a property change event * (with the name 'labelGenerator') to all registered listeners. * * @param generator the new generator (<code>null</code> not permitted). * * @see #getLabelGenerator() */ public void setLabelGenerator(CrosshairLabelGenerator generator) { if (generator == null) { throw new IllegalArgumentException("Null 'generator' argument."); } CrosshairLabelGenerator old = this.labelGenerator; this.labelGenerator = generator; this.pcs.firePropertyChange("labelGenerator", old, generator); } /** * Returns the label anchor point. * * @return the label anchor point (never <code>null</code>. * * @see #setLabelAnchor(org.jfree.ui.RectangleAnchor) */ public RectangleAnchor getLabelAnchor() { return this.labelAnchor; } /** * Sets the label anchor point and sends a property change event (with the * name 'labelAnchor') to all registered listeners. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getLabelAnchor() */ public void setLabelAnchor(RectangleAnchor anchor) { RectangleAnchor old = this.labelAnchor; this.labelAnchor = anchor; this.pcs.firePropertyChange("labelAnchor", old, anchor); } /** * Returns the x-offset for the label (in Java2D units). * * @return The x-offset. * * @see #setLabelXOffset(double) */ public double getLabelXOffset() { return this.labelXOffset; } /** * Sets the x-offset and sends a property change event (with the name * 'labelXOffset') to all registered listeners. * * @param offset the new offset. * * @see #getLabelXOffset() */ public void setLabelXOffset(double offset) { Double old = this.labelXOffset; this.labelXOffset = offset; this.pcs.firePropertyChange("labelXOffset", old, offset); } /** * Returns the y-offset for the label (in Java2D units). * * @return The y-offset. * * @see #setLabelYOffset(double) */ public double getLabelYOffset() { return this.labelYOffset; } /** * Sets the y-offset and sends a property change event (with the name * 'labelYOffset') to all registered listeners. * * @param offset the new offset. * * @see #getLabelYOffset() */ public void setLabelYOffset(double offset) { Double old = this.labelYOffset; this.labelYOffset = offset; this.pcs.firePropertyChange("labelYOffset", old, offset); } /** * Returns the label font. * * @return The label font (never <code>null</code>). * * @see #setLabelFont(java.awt.Font) */ public Font getLabelFont() { return this.labelFont; } /** * Sets the label font and sends a property change event (with the name * 'labelFont') to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getLabelFont() */ public void setLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } Font old = this.labelFont; this.labelFont = font; this.pcs.firePropertyChange("labelFont", old, font); } /** * Returns the label paint. * * @return The label paint (never <code>null</code>). * * @see #setLabelPaint */ public Paint getLabelPaint() { return this.labelPaint; } /** * Sets the label paint and sends a property change event (with the name * 'labelPaint') to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getLabelPaint() */ public void setLabelPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } Paint old = this.labelPaint; this.labelPaint = paint; this.pcs.firePropertyChange("labelPaint", old, paint); } /** * Returns the label background paint. * * @return The label background paint (possibly <code>null</code>). * * @see #setLabelBackgroundPaint(java.awt.Paint) */ public Paint getLabelBackgroundPaint() { return this.labelBackgroundPaint; } /** * Sets the label background paint and sends a property change event with * the name 'labelBackgroundPaint') to all registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getLabelBackgroundPaint() */ public void setLabelBackgroundPaint(Paint paint) { Paint old = this.labelBackgroundPaint; this.labelBackgroundPaint = paint; this.pcs.firePropertyChange("labelBackgroundPaint", old, paint); } /** * Returns the flag that controls the visibility of the label outline. * * @return A boolean. * * @see #setLabelOutlineVisible(boolean) */ public boolean isLabelOutlineVisible() { return this.labelOutlineVisible; } /** * Sets the flag that controls the visibility of the label outlines and * sends a property change event (with the name "labelOutlineVisible") to * all registered listeners. * * @param visible the new flag value. * * @see #isLabelOutlineVisible() */ public void setLabelOutlineVisible(boolean visible) { boolean old = this.labelOutlineVisible; this.labelOutlineVisible = visible; this.pcs.firePropertyChange("labelOutlineVisible", old, visible); } /** * Returns the label outline paint. * * @return The label outline paint (never <code>null</code>). * * @see #setLabelOutlinePaint(java.awt.Paint) */ public Paint getLabelOutlinePaint() { return this.labelOutlinePaint; } /** * Sets the label outline paint and sends a property change event (with the * name "labelOutlinePaint") to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getLabelOutlinePaint() */ public void setLabelOutlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } Paint old = this.labelOutlinePaint; this.labelOutlinePaint = paint; this.pcs.firePropertyChange("labelOutlinePaint", old, paint); } /** * Returns the label outline stroke. * * @return The label outline stroke (never <code>null</code>). * * @see #setLabelOutlineStroke(java.awt.Stroke) */ public Stroke getLabelOutlineStroke() { return this.labelOutlineStroke; } /** * Sets the label outline stroke and sends a property change event (with * the name 'labelOutlineStroke') to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getLabelOutlineStroke() */ public void setLabelOutlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } Stroke old = this.labelOutlineStroke; this.labelOutlineStroke = stroke; this.pcs.firePropertyChange("labelOutlineStroke", old, stroke); } /** * Tests this crosshair for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Crosshair)) { return false; } Crosshair that = (Crosshair) obj; if (this.visible != that.visible) { return false; } if (this.value != that.value) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!this.stroke.equals(that.stroke)) { return false; } if (this.labelVisible != that.labelVisible) { return false; } if (!this.labelGenerator.equals(that.labelGenerator)) { return false; } if (!this.labelAnchor.equals(that.labelAnchor)) { return false; } if (this.labelXOffset != that.labelXOffset) { return false; } if (this.labelYOffset != that.labelYOffset) { return false; } if (!this.labelFont.equals(that.labelFont)) { return false; } if (!PaintUtilities.equal(this.labelPaint, that.labelPaint)) { return false; } if (!PaintUtilities.equal(this.labelBackgroundPaint, that.labelBackgroundPaint)) { return false; } if (this.labelOutlineVisible != that.labelOutlineVisible) { return false; } if (!PaintUtilities.equal(this.labelOutlinePaint, that.labelOutlinePaint)) { return false; } if (!this.labelOutlineStroke.equals(that.labelOutlineStroke)) { return false; } return true; // can't find any difference } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int hash = 7; hash = HashUtilities.hashCode(hash, this.visible); hash = HashUtilities.hashCode(hash, this.value); hash = HashUtilities.hashCode(hash, this.paint); hash = HashUtilities.hashCode(hash, this.stroke); hash = HashUtilities.hashCode(hash, this.labelVisible); hash = HashUtilities.hashCode(hash, this.labelAnchor); hash = HashUtilities.hashCode(hash, this.labelGenerator); hash = HashUtilities.hashCode(hash, this.labelXOffset); hash = HashUtilities.hashCode(hash, this.labelYOffset); hash = HashUtilities.hashCode(hash, this.labelFont); hash = HashUtilities.hashCode(hash, this.labelPaint); hash = HashUtilities.hashCode(hash, this.labelBackgroundPaint); hash = HashUtilities.hashCode(hash, this.labelOutlineVisible); hash = HashUtilities.hashCode(hash, this.labelOutlineStroke); hash = HashUtilities.hashCode(hash, this.labelOutlinePaint); return hash; } /** * Returns an independent copy of this instance. * * @return An independent copy of this instance. * * @throws java.lang.CloneNotSupportedException */ @Override public Object clone() throws CloneNotSupportedException { // FIXME: clone generator return super.clone(); } /** * Adds a property change listener. * * @param l the listener. * * @see #removePropertyChangeListener(java.beans.PropertyChangeListener) */ public void addPropertyChangeListener(PropertyChangeListener l) { this.pcs.addPropertyChangeListener(l); } /** * Removes a property change listener. * * @param l the listener. * * @see #addPropertyChangeListener(java.beans.PropertyChangeListener) */ public void removePropertyChangeListener(PropertyChangeListener l) { this.pcs.removePropertyChangeListener(l); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writeStroke(this.stroke, stream); SerialUtilities.writePaint(this.labelPaint, stream); SerialUtilities.writePaint(this.labelBackgroundPaint, stream); SerialUtilities.writeStroke(this.labelOutlineStroke, stream); SerialUtilities.writePaint(this.labelOutlinePaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.stroke = SerialUtilities.readStroke(stream); this.labelPaint = SerialUtilities.readPaint(stream); this.labelBackgroundPaint = SerialUtilities.readPaint(stream); this.labelOutlineStroke = SerialUtilities.readStroke(stream); this.labelOutlinePaint = SerialUtilities.readPaint(stream); this.pcs = new PropertyChangeSupport(this); } }
22,273
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CombinedRangeCategoryPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CombinedRangeCategoryPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * CombinedRangeCategoryPlot.java * ------------------------------ * (C) Copyright 2003-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Nicolas Brodu; * * Changes: * -------- * 16-May-2003 : Version 1 (DG); * 08-Aug-2003 : Adjusted totalWeight in remove() method (DG); * 19-Aug-2003 : Implemented Cloneable (DG); * 11-Sep-2003 : Fix cloning support (subplots) (NB); * 15-Sep-2003 : Implemented PublicCloneable. Fixed errors in cloning and * serialization (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 17-Sep-2003 : Updated handling of 'clicks' (DG); * 04-May-2004 : Added getter/setter methods for 'gap' attributes (DG); * 12-Nov-2004 : Implements the new Zoomable interface (DG); * 25-Nov-2004 : Small update to clone() implementation (DG); * 21-Feb-2005 : Fixed bug in remove() method (id = 1121172) (DG); * 21-Feb-2005 : The getLegendItems() method now returns the fixed legend * items if set (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 14-Nov-2007 : Updated setFixedDomainAxisSpaceForSubplots() method (DG); * 27-Mar-2008 : Add documentation for getDataRange() method (DG); * 31-Mar-2008 : Updated getSubplots() to return EMPTY_LIST for null * subplots, as suggested by Richard West (DG); * 26-Jun-2008 : Fixed crosshair support (DG); * 11-Aug-2008 : Don't store totalWeight of subplots, calculate it as * required (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.ShadowGenerator; import org.jfree.data.Range; /** * A combined category plot where the range axis is shared. */ public class CombinedRangeCategoryPlot extends CategoryPlot implements PlotChangeListener { /** For serialization. */ private static final long serialVersionUID = 7260210007554504515L; /** Storage for the subplot references. */ private List<CategoryPlot> subplots; /** The gap between subplots. */ private double gap; /** Temporary storage for the subplot areas. */ private transient Rectangle2D[] subplotArea; // TODO: move to plot state /** * Default constructor. */ public CombinedRangeCategoryPlot() { this(new NumberAxis()); } /** * Creates a new plot. * * @param rangeAxis the shared range axis. */ public CombinedRangeCategoryPlot(ValueAxis rangeAxis) { super(null, null, rangeAxis, null); this.subplots = new java.util.ArrayList<CategoryPlot>(); this.gap = 5.0; } /** * Returns the space between subplots. * * @return The gap (in Java2D units). */ public double getGap() { return this.gap; } /** * Sets the amount of space between subplots and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param gap the gap between subplots (in Java2D units). */ public void setGap(double gap) { this.gap = gap; fireChangeEvent(); } /** * Adds a subplot (with a default 'weight' of 1) and sends a * {@link PlotChangeEvent} to all registered listeners. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to <code>null</code>. * * @param subplot the subplot (<code>null</code> not permitted). */ public void add(CategoryPlot subplot) { // defer argument checking add(subplot, 1); } /** * Adds a subplot and sends a {@link PlotChangeEvent} to all registered * listeners. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to <code>null</code>. * * @param subplot the subplot (<code>null</code> not permitted). * @param weight the weight (must be >= 1). */ public void add(CategoryPlot subplot, int weight) { ParamChecks.nullNotPermitted(subplot, "subplot"); if (weight <= 0) { throw new IllegalArgumentException("Require weight >= 1."); } // store the plot and its weight subplot.setParent(this); subplot.setWeight(weight); subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); subplot.setRangeAxis(null); subplot.setOrientation(getOrientation()); subplot.addChangeListener(this); this.subplots.add(subplot); // configure the range axis... ValueAxis axis = getRangeAxis(); if (axis != null) { axis.configure(); } fireChangeEvent(); } /** * Removes a subplot from the combined chart. * * @param subplot the subplot (<code>null</code> not permitted). */ public void remove(CategoryPlot subplot) { ParamChecks.nullNotPermitted(subplot, "subplot"); int position = -1; int size = this.subplots.size(); int i = 0; while (position == -1 && i < size) { if (this.subplots.get(i) == subplot) { position = i; } i++; } if (position != -1) { this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); ValueAxis range = getRangeAxis(); if (range != null) { range.configure(); } ValueAxis range2 = getRangeAxis(1); if (range2 != null) { range2.configure(); } fireChangeEvent(); } } /** * Returns the list of subplots. The returned list may be empty, but is * never <code>null</code>. * * @return An unmodifiable list of subplots. */ public List<CategoryPlot> getSubplots() { if (this.subplots != null) { return Collections.unmodifiableList(this.subplots); } else { return Collections.EMPTY_LIST; } } /** * Calculates the space required for the axes. * * @param g2 the graphics device. * @param plotArea the plot area. * * @return The space required for the axes. */ @Override protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); PlotOrientation orientation = getOrientation(); // work out the space required by the domain axis... AxisSpace fixed = getFixedRangeAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.VERTICAL) { space.setLeft(fixed.getLeft()); space.setRight(fixed.getRight()); } else if (orientation == PlotOrientation.HORIZONTAL) { space.setTop(fixed.getTop()); space.setBottom(fixed.getBottom()); } } else { ValueAxis valueAxis = getRangeAxis(); RectangleEdge valueEdge = Plot.resolveRangeAxisLocation( getRangeAxisLocation(), orientation); if (valueAxis != null) { space = valueAxis.reserveSpace(g2, this, plotArea, valueEdge, space); } } Rectangle2D adjustedPlotArea = space.shrink(plotArea, null); // work out the maximum height or width of the non-shared axes... int n = this.subplots.size(); int totalWeight = 0; for (CategoryPlot sub : this.subplots) { totalWeight += sub.getWeight(); } // calculate plotAreas of all sub-plots, maximum vertical/horizontal // axis width/height this.subplotArea = new Rectangle2D[n]; double x = adjustedPlotArea.getX(); double y = adjustedPlotArea.getY(); double usableSize = 0.0; if (orientation == PlotOrientation.VERTICAL) { usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1); } else if (orientation == PlotOrientation.HORIZONTAL) { usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1); } for (int i = 0; i < n; i++) { CategoryPlot plot = this.subplots.get(i); // calculate sub-plot area if (orientation == PlotOrientation.VERTICAL) { double w = usableSize * plot.getWeight() / totalWeight; this.subplotArea[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight()); x = x + w + this.gap; } else if (orientation == PlotOrientation.HORIZONTAL) { double h = usableSize * plot.getWeight() / totalWeight; this.subplotArea[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h); y = y + h + this.gap; } AxisSpace subSpace = plot.calculateDomainAxisSpace(g2, this.subplotArea[i], null); space.ensureAtLeast(subSpace); } return space; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). Will perform all the placement calculations for each * sub-plots and then tell these to draw themselves. * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the parent state. * @param info collects information about the drawing (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); // calculate the data area... AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); // set the width and height of non-shared axis of all sub-plots setFixedDomainAxisSpaceForSubplots(space); // draw the shared axis ValueAxis axis = getRangeAxis(); RectangleEdge rangeEdge = getRangeAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, rangeEdge); AxisState state = axis.draw(g2, cursor, area, dataArea, rangeEdge, info); if (parentState == null) { parentState = new PlotState(); } parentState.getSharedAxisStates().put(axis, state); // draw all the charts for (int i = 0; i < this.subplots.size(); i++) { CategoryPlot plot = this.subplots.get(i); PlotRenderingInfo subplotInfo = null; if (info != null) { subplotInfo = new PlotRenderingInfo(info.getOwner()); info.addSubplotInfo(subplotInfo); } Point2D subAnchor = null; if (anchor != null && this.subplotArea[i].contains(anchor)) { subAnchor = anchor; } plot.draw(g2, this.subplotArea[i], subAnchor, parentState, subplotInfo); } if (info != null) { info.setDataArea(dataArea); } } /** * Sets the orientation for the plot (and all the subplots). * * @param orientation the orientation (<code>null</code> not permitted). */ @Override public void setOrientation(PlotOrientation orientation) { super.setOrientation(orientation); for (CategoryPlot plot : this.subplots) { plot.setOrientation(orientation); } } /** * Sets the shadow generator for the plot (and all subplots) and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param generator the new generator (<code>null</code> permitted). */ @Override public void setShadowGenerator(ShadowGenerator generator) { setNotify(false); super.setShadowGenerator(generator); for (CategoryPlot plot : this.subplots) { plot.setShadowGenerator(generator); } setNotify(true); } /** * Returns a range representing the extent of the data values in this plot * (obtained from the subplots) that will be rendered against the specified * axis. NOTE: This method is intended for internal JFreeChart use, and * is public only so that code in the axis classes can call it. Since * only the range axis is shared between subplots, the JFreeChart code * will only call this method for the range values (although this is not * checked/enforced). * * @param axis the axis. * * @return The range. */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; if (this.subplots != null) { for (CategoryPlot subplot : this.subplots) { result = Range.combine(result, subplot.getDataRange(axis)); } } return result; } /** * Returns a collection of legend items for the plot. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = getFixedLegendItems(); if (result == null) { result = new ArrayList<LegendItem>(); if (this.subplots != null) { for (CategoryPlot plot : this.subplots) { List<LegendItem> more = plot.getLegendItems(); result.addAll(more); } } } return result; } /** * Sets the size (width or height, depending on the orientation of the * plot) for the domain axis of each subplot. * * @param space the space. */ protected void setFixedDomainAxisSpaceForSubplots(AxisSpace space) { for (CategoryPlot plot : this.subplots) { plot.setFixedDomainAxisSpace(space, false); } } /** * Handles a 'click' on the plot by updating the anchor value. * * @param x x-coordinate of the click. * @param y y-coordinate of the click. * @param info information about the plot's dimensions. * */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { for (int i = 0; i < this.subplots.size(); i++) { CategoryPlot subplot = this.subplots.get(i); PlotRenderingInfo subplotInfo = info.getSubplotInfo(i); subplot.handleClick(x, y, subplotInfo); } } } /** * Receives a {@link PlotChangeEvent} and responds by notifying all * listeners. * * @param event the event. */ @Override public void plotChanged(PlotChangeEvent event) { notifyListeners(event); } /** * Tests the plot for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CombinedRangeCategoryPlot)) { return false; } CombinedRangeCategoryPlot that = (CombinedRangeCategoryPlot) obj; if (this.gap != that.gap) { return false; } if (!ObjectUtilities.equal(this.subplots, that.subplots)) { return false; } return super.equals(obj); } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { CombinedRangeCategoryPlot result = (CombinedRangeCategoryPlot) super.clone(); result.subplots = (List) ObjectUtilities.deepClone(this.subplots); for (CategoryPlot subplot : result.subplots) { Plot child = subplot; child.setParent(result); } // after setting up all the subplots, the shared range axis may need // reconfiguring ValueAxis rangeAxis = result.getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } return result; } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); // the range axis is deserialized before the subplots, so its value // range is likely to be incorrect... ValueAxis rangeAxis = getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } } }
19,696
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SeriesRenderingOrder.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/SeriesRenderingOrder.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * SeriesRenderingOrder.java * -------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: Eric Thomas (www.isti.com); * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes: * -------- * 21-Apr-2005 : Version 1 contributed by Eric Thomas (ET); * 21-Nov-2007 : Implemented hashCode() (DG); * */ package org.jfree.chart.plot; /** * Defines the tokens that indicate the rendering order for series in a * {@link org.jfree.chart.plot.XYPlot}. */ public enum SeriesRenderingOrder { /** * Render series in the order 0, 1, 2, ..., N-1, where N is the number * of series. */ FORWARD("SeriesRenderingOrder.FORWARD"), /** * Render series in the order N-1, N-2, ..., 2, 1, 0, where N is the * number of series. */ REVERSE("SeriesRenderingOrder.REVERSE"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private SeriesRenderingOrder(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string (never <code>null</code>). */ @Override public String toString() { return this.name; } }
2,543
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultDrawingSupplier.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/DefaultDrawingSupplier.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * DefaultDrawingSupplier.java * --------------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Jeremy Bowman; * * Changes * ------- * 16-Jan-2003 : Version 1 (DG); * 17-Jan-2003 : Added stroke method, renamed DefaultPaintSupplier * --> DefaultDrawingSupplier (DG) * 27-Jan-2003 : Incorporated code from SeriesShapeFactory, originally * contributed by Jeremy Bowman (DG); * 25-Mar-2003 : Implemented Serializable (DG); * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 13-Jun-2007 : Added fillPaintSequence (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Paint; import java.awt.Polygon; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import org.jfree.chart.ChartColor; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.SerialUtilities; /** * A default implementation of the {@link DrawingSupplier} interface. All * {@link Plot} instances have a new instance of this class installed by * default. */ public class DefaultDrawingSupplier implements DrawingSupplier, Cloneable, PublicCloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -7339847061039422538L; /** The default fill paint sequence. */ public static final Paint[] DEFAULT_PAINT_SEQUENCE = ChartColor.createDefaultPaintArray(); /** The default outline paint sequence. */ public static final Paint[] DEFAULT_OUTLINE_PAINT_SEQUENCE = new Paint[] { Color.LIGHT_GRAY}; /** The default fill paint sequence. */ public static final Paint[] DEFAULT_FILL_PAINT_SEQUENCE = new Paint[] { Color.WHITE}; /** The default stroke sequence. */ public static final Stroke[] DEFAULT_STROKE_SEQUENCE = new Stroke[] { new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)}; /** The default outline stroke sequence. */ public static final Stroke[] DEFAULT_OUTLINE_STROKE_SEQUENCE = new Stroke[] {new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL)}; /** The default shape sequence. */ public static final Shape[] DEFAULT_SHAPE_SEQUENCE = createStandardSeriesShapes(); /** The paint sequence. */ private transient Paint[] paintSequence; /** The current paint index. */ private int paintIndex; /** The outline paint sequence. */ private transient Paint[] outlinePaintSequence; /** The current outline paint index. */ private int outlinePaintIndex; /** The fill paint sequence. */ private transient Paint[] fillPaintSequence; /** The current fill paint index. */ private int fillPaintIndex; /** The stroke sequence. */ private transient Stroke[] strokeSequence; /** The current stroke index. */ private int strokeIndex; /** The outline stroke sequence. */ private transient Stroke[] outlineStrokeSequence; /** The current outline stroke index. */ private int outlineStrokeIndex; /** The shape sequence. */ private transient Shape[] shapeSequence; /** The current shape index. */ private int shapeIndex; /** * Creates a new supplier, with default sequences for fill paint, outline * paint, stroke and shapes. */ public DefaultDrawingSupplier() { this(DEFAULT_PAINT_SEQUENCE, DEFAULT_FILL_PAINT_SEQUENCE, DEFAULT_OUTLINE_PAINT_SEQUENCE, DEFAULT_STROKE_SEQUENCE, DEFAULT_OUTLINE_STROKE_SEQUENCE, DEFAULT_SHAPE_SEQUENCE); } /** * Creates a new supplier. * * @param paintSequence the fill paint sequence. * @param outlinePaintSequence the outline paint sequence. * @param strokeSequence the stroke sequence. * @param outlineStrokeSequence the outline stroke sequence. * @param shapeSequence the shape sequence. */ public DefaultDrawingSupplier(Paint[] paintSequence, Paint[] outlinePaintSequence, Stroke[] strokeSequence, Stroke[] outlineStrokeSequence, Shape[] shapeSequence) { this.paintSequence = paintSequence; this.fillPaintSequence = DEFAULT_FILL_PAINT_SEQUENCE; this.outlinePaintSequence = outlinePaintSequence; this.strokeSequence = strokeSequence; this.outlineStrokeSequence = outlineStrokeSequence; this.shapeSequence = shapeSequence; } /** * Creates a new supplier. * * @param paintSequence the paint sequence. * @param fillPaintSequence the fill paint sequence. * @param outlinePaintSequence the outline paint sequence. * @param strokeSequence the stroke sequence. * @param outlineStrokeSequence the outline stroke sequence. * @param shapeSequence the shape sequence. * * @since 1.0.6 */ public DefaultDrawingSupplier(Paint[] paintSequence, Paint[] fillPaintSequence, Paint[] outlinePaintSequence, Stroke[] strokeSequence, Stroke[] outlineStrokeSequence, Shape[] shapeSequence) { this.paintSequence = paintSequence; this.fillPaintSequence = fillPaintSequence; this.outlinePaintSequence = outlinePaintSequence; this.strokeSequence = strokeSequence; this.outlineStrokeSequence = outlineStrokeSequence; this.shapeSequence = shapeSequence; } /** * Returns the next paint in the sequence. * * @return The paint. */ @Override public Paint getNextPaint() { Paint result = this.paintSequence[this.paintIndex % this.paintSequence.length]; this.paintIndex++; return result; } /** * Returns the next outline paint in the sequence. * * @return The paint. */ @Override public Paint getNextOutlinePaint() { Paint result = this.outlinePaintSequence[ this.outlinePaintIndex % this.outlinePaintSequence.length]; this.outlinePaintIndex++; return result; } /** * Returns the next fill paint in the sequence. * * @return The paint. * * @since 1.0.6 */ @Override public Paint getNextFillPaint() { Paint result = this.fillPaintSequence[this.fillPaintIndex % this.fillPaintSequence.length]; this.fillPaintIndex++; return result; } /** * Returns the next stroke in the sequence. * * @return The stroke. */ @Override public Stroke getNextStroke() { Stroke result = this.strokeSequence[ this.strokeIndex % this.strokeSequence.length]; this.strokeIndex++; return result; } /** * Returns the next outline stroke in the sequence. * * @return The stroke. */ @Override public Stroke getNextOutlineStroke() { Stroke result = this.outlineStrokeSequence[ this.outlineStrokeIndex % this.outlineStrokeSequence.length]; this.outlineStrokeIndex++; return result; } /** * Returns the next shape in the sequence. * * @return The shape. */ @Override public Shape getNextShape() { Shape result = this.shapeSequence[ this.shapeIndex % this.shapeSequence.length]; this.shapeIndex++; return result; } /** * Creates an array of standard shapes to display for the items in series * on charts. * * @return The array of shapes. */ public static Shape[] createStandardSeriesShapes() { Shape[] result = new Shape[10]; double size = 6.0; double delta = size / 2.0; int[] xpoints = null; int[] ypoints = null; // square result[0] = new Rectangle2D.Double(-delta, -delta, size, size); // circle result[1] = new Ellipse2D.Double(-delta, -delta, size, size); // up-pointing triangle xpoints = intArray(0.0, delta, -delta); ypoints = intArray(-delta, delta, delta); result[2] = new Polygon(xpoints, ypoints, 3); // diamond xpoints = intArray(0.0, delta, 0.0, -delta); ypoints = intArray(-delta, 0.0, delta, 0.0); result[3] = new Polygon(xpoints, ypoints, 4); // horizontal rectangle result[4] = new Rectangle2D.Double(-delta, -delta / 2, size, size / 2); // down-pointing triangle xpoints = intArray(-delta, +delta, 0.0); ypoints = intArray(-delta, -delta, delta); result[5] = new Polygon(xpoints, ypoints, 3); // horizontal ellipse result[6] = new Ellipse2D.Double(-delta, -delta / 2, size, size / 2); // right-pointing triangle xpoints = intArray(-delta, delta, -delta); ypoints = intArray(-delta, 0.0, delta); result[7] = new Polygon(xpoints, ypoints, 3); // vertical rectangle result[8] = new Rectangle2D.Double(-delta / 2, -delta, size / 2, size); // left-pointing triangle xpoints = intArray(-delta, delta, delta); ypoints = intArray(0.0, -delta, +delta); result[9] = new Polygon(xpoints, ypoints, 3); return result; } /** * Tests this object for equality with another object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DefaultDrawingSupplier)) { return false; } DefaultDrawingSupplier that = (DefaultDrawingSupplier) obj; if (!Arrays.equals(this.paintSequence, that.paintSequence)) { return false; } if (this.paintIndex != that.paintIndex) { return false; } if (!Arrays.equals(this.outlinePaintSequence, that.outlinePaintSequence)) { return false; } if (this.outlinePaintIndex != that.outlinePaintIndex) { return false; } if (!Arrays.equals(this.strokeSequence, that.strokeSequence)) { return false; } if (this.strokeIndex != that.strokeIndex) { return false; } if (!Arrays.equals(this.outlineStrokeSequence, that.outlineStrokeSequence)) { return false; } if (this.outlineStrokeIndex != that.outlineStrokeIndex) { return false; } if (!equalShapes(this.shapeSequence, that.shapeSequence)) { return false; } if (this.shapeIndex != that.shapeIndex) { return false; } return true; } /** * A utility method for testing the equality of two arrays of shapes. * * @param s1 the first array (<code>null</code> permitted). * @param s2 the second array (<code>null</code> permitted). * * @return A boolean. */ private boolean equalShapes(Shape[] s1, Shape[] s2) { if (s1 == null) { return s2 == null; } if (s2 == null) { return false; } if (s1.length != s2.length) { return false; } for (int i = 0; i < s1.length; i++) { if (!ShapeUtilities.equal(s1[i], s2[i])) { return false; } } return true; } /** * Handles serialization. * * @param stream the output stream. * * @throws IOException if there is an I/O problem. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); int paintCount = this.paintSequence.length; stream.writeInt(paintCount); for (Paint aPaintSequence : this.paintSequence) { SerialUtilities.writePaint(aPaintSequence, stream); } int outlinePaintCount = this.outlinePaintSequence.length; stream.writeInt(outlinePaintCount); for (Paint anOutlinePaintSequence : this.outlinePaintSequence) { SerialUtilities.writePaint(anOutlinePaintSequence, stream); } int strokeCount = this.strokeSequence.length; stream.writeInt(strokeCount); for (Stroke aStrokeSequence : this.strokeSequence) { SerialUtilities.writeStroke(aStrokeSequence, stream); } int outlineStrokeCount = this.outlineStrokeSequence.length; stream.writeInt(outlineStrokeCount); for (Stroke anOutlineStrokeSequence : this.outlineStrokeSequence) { SerialUtilities.writeStroke(anOutlineStrokeSequence, stream); } int shapeCount = this.shapeSequence.length; stream.writeInt(shapeCount); for (Shape aShapeSequence : this.shapeSequence) { SerialUtilities.writeShape(aShapeSequence, stream); } } /** * Restores a serialized object. * * @param stream the input stream. * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); int paintCount = stream.readInt(); this.paintSequence = new Paint[paintCount]; for (int i = 0; i < paintCount; i++) { this.paintSequence[i] = SerialUtilities.readPaint(stream); } int outlinePaintCount = stream.readInt(); this.outlinePaintSequence = new Paint[outlinePaintCount]; for (int i = 0; i < outlinePaintCount; i++) { this.outlinePaintSequence[i] = SerialUtilities.readPaint(stream); } int strokeCount = stream.readInt(); this.strokeSequence = new Stroke[strokeCount]; for (int i = 0; i < strokeCount; i++) { this.strokeSequence[i] = SerialUtilities.readStroke(stream); } int outlineStrokeCount = stream.readInt(); this.outlineStrokeSequence = new Stroke[outlineStrokeCount]; for (int i = 0; i < outlineStrokeCount; i++) { this.outlineStrokeSequence[i] = SerialUtilities.readStroke(stream); } int shapeCount = stream.readInt(); this.shapeSequence = new Shape[shapeCount]; for (int i = 0; i < shapeCount; i++) { this.shapeSequence[i] = SerialUtilities.readShape(stream); } } /** * Helper method to avoid lots of explicit casts in getShape(). Returns * an array containing the provided doubles cast to ints. * * @param a x * @param b y * @param c z * * @return int[3] with converted params. */ private static int[] intArray(double a, double b, double c) { return new int[] {(int) a, (int) b, (int) c}; } /** * Helper method to avoid lots of explicit casts in getShape(). Returns * an array containing the provided doubles cast to ints. * * @param a x * @param b y * @param c z * @param d t * * @return int[4] with converted params. */ private static int[] intArray(double a, double b, double c, double d) { return new int[] {(int) a, (int) b, (int) c, (int) d}; } /** * Returns a clone. * * @return A clone. * * @throws CloneNotSupportedException if a component of the supplier does * not support cloning. */ @Override public Object clone() throws CloneNotSupportedException { DefaultDrawingSupplier clone = (DefaultDrawingSupplier) super.clone(); return clone; } }
17,757
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CombinedDomainCategoryPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CombinedDomainCategoryPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------- * CombinedDomainCategoryPlot.java * ------------------------------- * (C) Copyright 2003-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Nicolas Brodu; * * Changes: * -------- * 16-May-2003 : Version 1 (DG); * 08-Aug-2003 : Adjusted totalWeight in remove() method (DG); * 19-Aug-2003 : Added equals() method, implemented Cloneable and * Serializable (DG); * 11-Sep-2003 : Fix cloning support (subplots) (NB); * 15-Sep-2003 : Implemented PublicCloneable (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 17-Sep-2003 : Updated handling of 'clicks' (DG); * 04-May-2004 : Added getter/setter methods for 'gap' attribute (DG); * 12-Nov-2004 : Implemented the Zoomable interface (DG); * 25-Nov-2004 : Small update to clone() implementation (DG); * 21-Feb-2005 : The getLegendItems() method now returns the fixed legend * items if set (DG); * 05-May-2005 : Updated draw() method parameters (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 13-Sep-2006 : Updated API docs (DG); * 30-Oct-2006 : Added new getCategoriesForAxis() override (DG); * 17-Apr-2007 : Added null argument checks to findSubplot() (DG); * 14-Nov-2007 : Updated setFixedRangeAxisSpaceForSubplots() method (DG); * 27-Mar-2008 : Add documentation for getDataRange() method (DG); * 31-Mar-2008 : Updated getSubplots() to return EMPTY_LIST for null * subplots, as suggested by Richard West (DG); * 28-Apr-2008 : Fixed zooming problem (see bug 1950037) (DG); * 26-Jun-2008 : Fixed crosshair support (DG); * 11-Aug-2008 : Don't store totalWeight of subplots, calculate it as * required (DG); * 12-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.CategoryAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.ShadowGenerator; import org.jfree.data.Range; /** * A combined category plot where the domain axis is shared. */ public class CombinedDomainCategoryPlot extends CategoryPlot implements PlotChangeListener { /** For serialization. */ private static final long serialVersionUID = 8207194522653701572L; /** Storage for the subplot references. */ private List<CategoryPlot> subplots; /** The gap between subplots. */ private double gap; /** Temporary storage for the subplot areas. */ private transient Rectangle2D[] subplotAreas; // TODO: move the above to the plot state /** * Default constructor. */ public CombinedDomainCategoryPlot() { this(new CategoryAxis()); } /** * Creates a new plot. * * @param domainAxis the shared domain axis (<code>null</code> not * permitted). */ public CombinedDomainCategoryPlot(CategoryAxis domainAxis) { super(null, domainAxis, null, null); this.subplots = new java.util.ArrayList<CategoryPlot>(); this.gap = 5.0; } /** * Returns the space between subplots. The default value is 5.0. * * @return The gap (in Java2D units). * * @see #setGap(double) */ public double getGap() { return this.gap; } /** * Sets the amount of space between subplots and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param gap the gap between subplots (in Java2D units). * * @see #getGap() */ public void setGap(double gap) { this.gap = gap; fireChangeEvent(); } /** * Adds a subplot to the combined chart and sends a {@link PlotChangeEvent} * to all registered listeners. * <br><br> * The domain axis for the subplot will be set to <code>null</code>. You * must ensure that the subplot has a non-null range axis. * * @param subplot the subplot (<code>null</code> not permitted). */ public void add(CategoryPlot subplot) { add(subplot, 1); } /** * Adds a subplot to the combined chart and sends a {@link PlotChangeEvent} * to all registered listeners. * <br><br> * The domain axis for the subplot will be set to <code>null</code>. You * must ensure that the subplot has a non-null range axis. * * @param subplot the subplot (<code>null</code> not permitted). * @param weight the weight (must be >= 1). */ public void add(CategoryPlot subplot, int weight) { ParamChecks.nullNotPermitted(subplot, "subplot"); if (weight < 1) { throw new IllegalArgumentException("Require weight >= 1."); } subplot.setParent(this); subplot.setWeight(weight); subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); subplot.setDomainAxis(null); subplot.setOrientation(getOrientation()); subplot.addChangeListener(this); this.subplots.add(subplot); CategoryAxis axis = getDomainAxis(); if (axis != null) { axis.configure(); } fireChangeEvent(); } /** * Removes a subplot from the combined chart. Potentially, this removes * some unique categories from the overall union of the datasets...so the * domain axis is reconfigured, then a {@link PlotChangeEvent} is sent to * all registered listeners. * * @param subplot the subplot (<code>null</code> not permitted). */ public void remove(CategoryPlot subplot) { ParamChecks.nullNotPermitted(subplot, "subplot"); int position = -1; int size = this.subplots.size(); int i = 0; while (position == -1 && i < size) { if (this.subplots.get(i) == subplot) { position = i; } i++; } if (position != -1) { this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); CategoryAxis domain = getDomainAxis(); if (domain != null) { domain.configure(); } fireChangeEvent(); } } /** * Returns the list of subplots. The returned list may be empty, but is * never <code>null</code>. * * @return An unmodifiable list of subplots. */ public List<CategoryPlot> getSubplots() { if (this.subplots != null) { return Collections.unmodifiableList(this.subplots); } else { return Collections.EMPTY_LIST; } } /** * Returns the subplot (if any) that contains the (x, y) point (specified * in Java2D space). * * @param info the chart rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). * * @return A subplot (possibly <code>null</code>). */ public CategoryPlot findSubplot(PlotRenderingInfo info, Point2D source) { ParamChecks.nullNotPermitted(info, "info"); ParamChecks.nullNotPermitted(source, "source"); CategoryPlot result = null; int subplotIndex = info.getSubplotIndex(source); if (subplotIndex >= 0) { result = this.subplots.get(subplotIndex); } return result; } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source) { zoomRangeAxes(factor, info, source, false); } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). * @param useAnchor zoom about the anchor point? */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // delegate 'info' and 'source' argument checks... CategoryPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomRangeAxes(factor, info, source, useAnchor); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... for (CategoryPlot categoryPlot : getSubplots()) { subplot = categoryPlot; subplot.zoomRangeAxes(factor, info, source, useAnchor); } } } /** * Zooms in on the range axes. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { // delegate 'info' and 'source' argument checks... CategoryPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomRangeAxes(lowerPercent, upperPercent, info, source); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... for (CategoryPlot categoryPlot : getSubplots()) { subplot = categoryPlot; subplot.zoomRangeAxes(lowerPercent, upperPercent, info, source); } } } /** * Calculates the space required for the axes. * * @param g2 the graphics device. * @param plotArea the plot area. * * @return The space required for the axes. */ @Override protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); PlotOrientation orientation = getOrientation(); // work out the space required by the domain axis... AxisSpace fixed = getFixedDomainAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.HORIZONTAL) { space.setLeft(fixed.getLeft()); space.setRight(fixed.getRight()); } else if (orientation == PlotOrientation.VERTICAL) { space.setTop(fixed.getTop()); space.setBottom(fixed.getBottom()); } } else { CategoryAxis categoryAxis = getDomainAxis(); RectangleEdge categoryEdge = Plot.resolveDomainAxisLocation( getDomainAxisLocation(), orientation); if (categoryAxis != null) { space = categoryAxis.reserveSpace(g2, this, plotArea, categoryEdge, space); } else { if (getDrawSharedDomainAxis()) { space = getDomainAxis().reserveSpace(g2, this, plotArea, categoryEdge, space); } } } Rectangle2D adjustedPlotArea = space.shrink(plotArea, null); // work out the maximum height or width of the non-shared axes... int n = this.subplots.size(); int totalWeight = 0; for (CategoryPlot sub : this.subplots) { totalWeight += sub.getWeight(); } this.subplotAreas = new Rectangle2D[n]; double x = adjustedPlotArea.getX(); double y = adjustedPlotArea.getY(); double usableSize = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1); } else if (orientation == PlotOrientation.VERTICAL) { usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1); } for (int i = 0; i < n; i++) { CategoryPlot plot = this.subplots.get(i); // calculate sub-plot area if (orientation == PlotOrientation.HORIZONTAL) { double w = usableSize * plot.getWeight() / totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight()); x = x + w + this.gap; } else if (orientation == PlotOrientation.VERTICAL) { double h = usableSize * plot.getWeight() / totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h); y = y + h + this.gap; } AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null); space.ensureAtLeast(subSpace); } return space; } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). Will perform all the placement calculations for each of the * sub-plots and then tell these to draw themselves. * * @param g2 the graphics device. * @param area the area within which the plot (including axis labels) * should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects information about the drawing (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); area.setRect(area.getX() + insets.getLeft(), area.getY() + insets.getTop(), area.getWidth() - insets.getLeft() - insets.getRight(), area.getHeight() - insets.getTop() - insets.getBottom()); // calculate the data area... setFixedRangeAxisSpaceForSubplots(null); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); // set the width and height of non-shared axis of all sub-plots setFixedRangeAxisSpaceForSubplots(space); // draw the shared axis CategoryAxis axis = getDomainAxis(); RectangleEdge domainEdge = getDomainAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, domainEdge); AxisState axisState = axis.draw(g2, cursor, area, dataArea, domainEdge, info); if (parentState == null) { parentState = new PlotState(); } parentState.getSharedAxisStates().put(axis, axisState); // draw all the subplots for (int i = 0; i < this.subplots.size(); i++) { CategoryPlot plot = this.subplots.get(i); PlotRenderingInfo subplotInfo = null; if (info != null) { subplotInfo = new PlotRenderingInfo(info.getOwner()); info.addSubplotInfo(subplotInfo); } Point2D subAnchor = null; if (anchor != null && this.subplotAreas[i].contains(anchor)) { subAnchor = anchor; } plot.draw(g2, this.subplotAreas[i], subAnchor, parentState, subplotInfo); } if (info != null) { info.setDataArea(dataArea); } } /** * Sets the size (width or height, depending on the orientation of the * plot) for the range axis of each subplot. * * @param space the space (<code>null</code> permitted). */ protected void setFixedRangeAxisSpaceForSubplots(AxisSpace space) { for (CategoryPlot plot : this.subplots) { plot.setFixedRangeAxisSpace(space, false); } } /** * Sets the orientation of the plot (and all subplots). * * @param orientation the orientation (<code>null</code> not permitted). */ @Override public void setOrientation(PlotOrientation orientation) { super.setOrientation(orientation); for (CategoryPlot plot : this.subplots) { plot.setOrientation(orientation); } } /** * Sets the shadow generator for the plot (and all subplots) and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param generator the new generator (<code>null</code> permitted). */ @Override public void setShadowGenerator(ShadowGenerator generator) { setNotify(false); super.setShadowGenerator(generator); for (CategoryPlot plot : this.subplots) { plot.setShadowGenerator(generator); } setNotify(true); } /** * Returns a range representing the extent of the data values in this plot * (obtained from the subplots) that will be rendered against the specified * axis. NOTE: This method is intended for internal JFreeChart use, and * is public only so that code in the axis classes can call it. Since, * for this class, the domain axis is a {@link CategoryAxis} * (not a <code>ValueAxis</code}) and subplots have independent range axes, * the JFreeChart code will never call this method (although this is not * checked/enforced). * * @param axis the axis. * * @return The range. */ @Override public Range getDataRange(ValueAxis axis) { // override is only for documentation purposes return super.getDataRange(axis); } /** * Returns a collection of legend items for the plot. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = getFixedLegendItems(); if (result == null) { result = new ArrayList<LegendItem>(); if (this.subplots != null) { for (CategoryPlot plot : this.subplots) { List<LegendItem> more = plot.getLegendItems(); result.addAll(more); } } } return result; } /** * Returns an unmodifiable list of the categories contained in all the * subplots. * * @return The list. */ @Override public List<Comparable> getCategories() { List<Comparable> result = new java.util.ArrayList<Comparable>(); if (this.subplots != null) { for (CategoryPlot plot : this.subplots) { List<Comparable> more = plot.getCategories(); for (Comparable category : more) { if (!result.contains(category)) { result.add(category); } } } } return Collections.unmodifiableList(result); } /** * Overridden to return the categories in the subplots. * * @param axis ignored. * * @return A list of the categories in the subplots. * * @since 1.0.3 */ @Override public List<Comparable> getCategoriesForAxis(CategoryAxis axis) { // FIXME: this code means that it is not possible to use more than // one domain axis for the combined plots... return getCategories(); } /** * Handles a 'click' on the plot. * * @param x x-coordinate of the click. * @param y y-coordinate of the click. * @param info information about the plot's dimensions. */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { for (int i = 0; i < this.subplots.size(); i++) { CategoryPlot subplot = this.subplots.get(i); PlotRenderingInfo subplotInfo = info.getSubplotInfo(i); subplot.handleClick(x, y, subplotInfo); } } } /** * Receives a {@link PlotChangeEvent} and responds by notifying all * listeners. * * @param event the event. */ @Override public void plotChanged(PlotChangeEvent event) { notifyListeners(event); } /** * Tests the plot for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CombinedDomainCategoryPlot)) { return false; } CombinedDomainCategoryPlot that = (CombinedDomainCategoryPlot) obj; if (this.gap != that.gap) { return false; } if (!ObjectUtilities.equal(this.subplots, that.subplots)) { return false; } return super.equals(obj); } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { CombinedDomainCategoryPlot result = (CombinedDomainCategoryPlot) super.clone(); result.subplots = ObjectUtilities.deepClone(this.subplots); for (CategoryPlot child : this.subplots) { child.setParent(result); } return result; } }
23,966
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CrosshairState.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CrosshairState.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * CrosshairState.java * ------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 24-Jan-2002 : Version 1 (DG); * 05-Mar-2002 : Added Javadoc comments (DG); * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG); * 19-Sep-2003 : Modified crosshair distance calculation (DG); * 04-Dec-2003 : Crosshair anchor point now stored outside chart since it is * dependent on the display target (DG); * 25-Feb-2004 : Replaced CrosshairInfo --> CrosshairState (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 13-Oct-2006 : Fixed initialisation of CrosshairState - see bug report * 1565168 (DG); * 06-Feb-2007 : Added new fields and methods to fix bug 1086307 (DG); * 26-Jun-2008 : Now tracks dataset index (DG); * */ package org.jfree.chart.plot; import java.awt.geom.Point2D; /** * Maintains state information about crosshairs on a plot between successive * calls to the renderer's draw method. This class is used internally by * JFreeChart - it is not intended for external use. */ public class CrosshairState { /** * A flag that controls whether the distance is calculated in data space * or Java2D space. */ private boolean calculateDistanceInDataSpace = false; /** The x-value (in data space) for the anchor point. */ private double anchorX; /** The y-value (in data space) for the anchor point. */ private double anchorY; /** The anchor point in Java2D space - if null, don't update crosshair. */ private Point2D anchor; /** The x-value for the current crosshair point. */ private double crosshairX; /** The y-value for the current crosshair point. */ private double crosshairY; /** * The dataset index that the crosshair point relates to (this determines * the axes that the crosshairs will be plotted against). * * @since 1.0.11 */ private int datasetIndex; /** * The index of the domain axis that the crosshair x-value is measured * against. * * @since 1.0.4 */ private int domainAxisIndex; /** * The index of the range axis that the crosshair y-value is measured * against. * * @since 1.0.4 */ private int rangeAxisIndex; /** * The smallest distance (so far) between the anchor point and a data * point. */ private double distance; /** * Creates a new <code>CrosshairState</code> instance that calculates * distance in Java2D space. */ public CrosshairState() { this(false); } /** * Creates a new <code>CrosshairState</code> instance. * * @param calculateDistanceInDataSpace a flag that controls whether the * distance is calculated in data * space or Java2D space. */ public CrosshairState(boolean calculateDistanceInDataSpace) { this.calculateDistanceInDataSpace = calculateDistanceInDataSpace; } /** * Returns the distance between the anchor point and the current crosshair * point. * * @return The distance. * * @see #setCrosshairDistance(double) * @since 1.0.3 */ public double getCrosshairDistance() { return this.distance; } /** * Sets the distance between the anchor point and the current crosshair * point. As each data point is processed, its distance to the anchor * point is compared with this value and, if it is closer, the data point * becomes the new crosshair point. * * @param distance the distance. * * @see #getCrosshairDistance() */ public void setCrosshairDistance(double distance) { this.distance = distance; } /** * Evaluates a data point and if it is the closest to the anchor point it * becomes the new crosshair point. * <P> * To understand this method, you need to know the context in which it will * be called. An instance of this class is passed to an * {@link org.jfree.chart.renderer.xy.XYItemRenderer} as * each data point is plotted. As the point is plotted, it is passed to * this method to see if it should be the new crosshair point. * * @param x x coordinate (measured against the domain axis). * @param y y coordinate (measured against the range axis). * @param domainAxisIndex the index of the domain axis for this point. * @param rangeAxisIndex the index of the range axis for this point. * @param transX x translated into Java2D space. * @param transY y translated into Java2D space. * @param orientation the plot orientation. * * @since 1.0.4 */ public void updateCrosshairPoint(double x, double y, int domainAxisIndex, int rangeAxisIndex, double transX, double transY, PlotOrientation orientation) { if (this.anchor != null) { double d = 0.0; if (this.calculateDistanceInDataSpace) { d = (x - this.anchorX) * (x - this.anchorX) + (y - this.anchorY) * (y - this.anchorY); } else { double xx = this.anchor.getX(); double yy = this.anchor.getY(); if (orientation == PlotOrientation.HORIZONTAL) { double temp = yy; yy = xx; xx = temp; } d = (transX - xx) * (transX - xx) + (transY - yy) * (transY - yy); } if (d < this.distance) { this.crosshairX = x; this.crosshairY = y; this.domainAxisIndex = domainAxisIndex; this.rangeAxisIndex = rangeAxisIndex; this.distance = d; } } } /** * Evaluates an x-value and if it is the closest to the anchor x-value it * becomes the new crosshair value. * <P> * Used in cases where only the x-axis is numerical. * * @param candidateX x position of the candidate for the new crosshair * point. * @param domainAxisIndex the index of the domain axis for this x-value. * * @since 1.0.4 */ public void updateCrosshairX(double candidateX, int domainAxisIndex) { double d = Math.abs(candidateX - this.anchorX); if (d < this.distance) { this.crosshairX = candidateX; this.domainAxisIndex = domainAxisIndex; this.distance = d; } } /** * Evaluates a y-value and if it is the closest to the anchor y-value it * becomes the new crosshair value. * <P> * Used in cases where only the y-axis is numerical. * * @param candidateY y position of the candidate for the new crosshair * point. * @param rangeAxisIndex the index of the range axis for this y-value. * * @since 1.0.4 */ public void updateCrosshairY(double candidateY, int rangeAxisIndex) { double d = Math.abs(candidateY - this.anchorY); if (d < this.distance) { this.crosshairY = candidateY; this.rangeAxisIndex = rangeAxisIndex; this.distance = d; } } /** * Returns the anchor point. * * @return The anchor point. * * @see #setAnchor(Point2D) * * @since 1.0.3 */ public Point2D getAnchor() { return this.anchor; } /** * Sets the anchor point. This is usually the mouse click point in a chart * panel, and the crosshair point will often be the data item that is * closest to the anchor point. * <br><br> * Note that the x and y coordinates (in data space) are not updated by * this method - the caller is responsible for ensuring that this happens * in sync. * * @param anchor the anchor point (<code>null</code> permitted). * * @see #getAnchor() */ public void setAnchor(Point2D anchor) { this.anchor = anchor; } /** * Returns the x-coordinate (in data space) for the anchor point. * * @return The x-coordinate of the anchor point. * * @since 1.0.3 */ public double getAnchorX() { return this.anchorX; } /** * Sets the x-coordinate (in data space) for the anchor point. Note that * this does NOT update the anchor itself - the caller is responsible for * ensuring this is done in sync. * * @param x the x-coordinate. * * @since 1.0.3 */ public void setAnchorX(double x) { this.anchorX = x; } /** * Returns the y-coordinate (in data space) for the anchor point. * * @return The y-coordinate of teh anchor point. * * @since 1.0.3 */ public double getAnchorY() { return this.anchorY; } /** * Sets the y-coordinate (in data space) for the anchor point. Note that * this does NOT update the anchor itself - the caller is responsible for * ensuring this is done in sync. * * @param y the y-coordinate. * * @since 1.0.3 */ public void setAnchorY(double y) { this.anchorY = y; } /** * Get the x-value for the crosshair point. * * @return The x position of the crosshair point. * * @see #setCrosshairX(double) */ public double getCrosshairX() { return this.crosshairX; } /** * Sets the x coordinate for the crosshair. This is the coordinate in data * space measured against the domain axis. * * @param x the coordinate. * * @see #getCrosshairX() * @see #setCrosshairY(double) * @see #updateCrosshairPoint(double, double, double, double, * PlotOrientation) */ public void setCrosshairX(double x) { this.crosshairX = x; } /** * Get the y-value for the crosshair point. This is the coordinate in data * space measured against the range axis. * * @return The y position of the crosshair point. * * @see #setCrosshairY(double) */ public double getCrosshairY() { return this.crosshairY; } /** * Sets the y coordinate for the crosshair. * * @param y the y coordinate. * * @see #getCrosshairY() * @see #setCrosshairX(double) * @see #updateCrosshairPoint(double, double, double, double, * PlotOrientation) */ public void setCrosshairY(double y) { this.crosshairY = y; } /** * Returns the dataset index that the crosshair values relate to. The * dataset is mapped to specific axes, and this is how the crosshairs are * mapped also. * * @return The dataset index. * * @see #setDatasetIndex(int) * * @since 1.0.11 */ public int getDatasetIndex() { return this.datasetIndex; } /** * Sets the dataset index that the current crosshair values relate to. * * @param index the dataset index. * * @see #getDatasetIndex() * * @since 1.0.11 */ public void setDatasetIndex(int index) { this.datasetIndex = index; } }
12,739
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PlotRenderingInfo.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PlotRenderingInfo.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * PlotRenderingInfo.java * ---------------------- * (C) Copyright 2003-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Sep-2003 : Version 1 (DG); * 23-Sep-2003 : Added Javadocs (DG); * 12-Nov-2004 : Added getSubplotCount() and findSubplot() methods (DG); * 01-Nov-2005 : Made 'owner' non-transient to fix bug 1344048 (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 01-Dec-2006 : Implemented clone() method properly (DG); * 17-Apr-2007 : Fixed bug 1698965 (NPE in CombinedDomainXYPlot) (DG); * 17-Jun-2012 : Removed from JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.List; import org.jfree.chart.ChartRenderingInfo; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.SerialUtilities; /** * Stores information about the dimensions of a plot and its subplots. */ public class PlotRenderingInfo implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 8446720134379617220L; /** The owner of this info. */ private ChartRenderingInfo owner; /** The plot area. */ private transient Rectangle2D plotArea; /** The data area. */ private transient Rectangle2D dataArea; /** * Storage for the plot rendering info objects belonging to the subplots. */ private List<PlotRenderingInfo> subplotInfo; /** * Creates a new instance. * * @param owner the owner (<code>null</code> permitted). */ public PlotRenderingInfo(ChartRenderingInfo owner) { this.owner = owner; this.dataArea = new Rectangle2D.Double(); this.subplotInfo = new java.util.ArrayList<PlotRenderingInfo>(); } /** * Returns the owner (as specified in the constructor). * * @return The owner (possibly <code>null</code>). */ public ChartRenderingInfo getOwner() { return this.owner; } /** * Returns the plot area (in Java2D space). * * @return The plot area (possibly <code>null</code>). * * @see #setPlotArea(Rectangle2D) */ public Rectangle2D getPlotArea() { return this.plotArea; } /** * Sets the plot area. * * @param area the plot area (in Java2D space, <code>null</code> * permitted but discouraged) * * @see #getPlotArea() */ public void setPlotArea(Rectangle2D area) { this.plotArea = area; } /** * Returns the plot's data area (in Java2D space). * * @return The data area (possibly <code>null</code>). * * @see #setDataArea(Rectangle2D) */ public Rectangle2D getDataArea() { return this.dataArea; } /** * Sets the data area. * * @param area the data area (in Java2D space, <code>null</code> permitted * but discouraged). * * @see #getDataArea() */ public void setDataArea(Rectangle2D area) { this.dataArea = area; } /** * Returns the number of subplots (possibly zero). * * @return The subplot count. */ public int getSubplotCount() { return this.subplotInfo.size(); } /** * Adds the info for a subplot. * * @param info the subplot info. * * @see #getSubplotInfo(int) */ public void addSubplotInfo(PlotRenderingInfo info) { this.subplotInfo.add(info); } /** * Returns the info for a subplot. * * @param index the subplot index. * * @return The info. * * @see #addSubplotInfo(PlotRenderingInfo) */ public PlotRenderingInfo getSubplotInfo(int index) { return this.subplotInfo.get(index); } /** * Returns the index of the subplot that contains the specified * (x, y) point (the "source" point). The source point will usually * come from a mouse click on a {@link org.jfree.chart.ChartPanel}, * and this method is then used to determine the subplot that * contains the source point. * * @param source the source point (in Java2D space, <code>null</code> not * permitted). * * @return The subplot index (or -1 if no subplot contains * <code>source</code>). */ public int getSubplotIndex(Point2D source) { if (source == null) { throw new IllegalArgumentException("Null 'source' argument."); } int subplotCount = getSubplotCount(); for (int i = 0; i < subplotCount; i++) { PlotRenderingInfo info = getSubplotInfo(i); Rectangle2D area = info.getDataArea(); if (area.contains(source)) { return i; } } return -1; } /** * Tests this instance for equality against an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof PlotRenderingInfo)) { return false; } PlotRenderingInfo that = (PlotRenderingInfo) obj; if (!ObjectUtilities.equal(this.dataArea, that.dataArea)) { return false; } if (!ObjectUtilities.equal(this.plotArea, that.plotArea)) { return false; } if (!ObjectUtilities.equal(this.subplotInfo, that.subplotInfo)) { return false; } return true; } /** * Returns a clone of this object. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning. */ @Override public Object clone() throws CloneNotSupportedException { PlotRenderingInfo clone = (PlotRenderingInfo) super.clone(); if (this.plotArea != null) { clone.plotArea = (Rectangle2D) this.plotArea.clone(); } if (this.dataArea != null) { clone.dataArea = (Rectangle2D) this.dataArea.clone(); } clone.subplotInfo = new java.util.ArrayList<PlotRenderingInfo>(this.subplotInfo.size()); for (int i = 0; i < this.subplotInfo.size(); i++) { PlotRenderingInfo info = this.subplotInfo.get(i); clone.subplotInfo.add((PlotRenderingInfo)info.clone()); } return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeShape(this.dataArea, stream); SerialUtilities.writeShape(this.plotArea, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.dataArea = (Rectangle2D) SerialUtilities.readShape(stream); this.plotArea = (Rectangle2D) SerialUtilities.readShape(stream); } }
8,929
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PlotState.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PlotState.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * PlotState.java * -------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Oct-2003 : Version 1 (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.AxisState; import java.util.HashMap; import java.util.Map; /** * Records information about the state of a plot during the drawing process. */ public class PlotState { /** The shared axis states. */ private Map<Axis, AxisState> sharedAxisStates; /** * Creates a new state object. */ public PlotState() { this.sharedAxisStates = new HashMap<Axis, AxisState>(); } /** * Returns a map containing the shared axis states. * * @return A map. */ public Map<Axis, AxisState> getSharedAxisStates() { return this.sharedAxisStates; } }
2,196
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Plot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/Plot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------- * Plot.java * --------- * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Sylvain Vieujot; * Jeremy Bowman; * Andreas Schneider; * Gideon Krause; * Nicolas Brodu; * Michal Krause; * Richard West, Advanced Micro Devices, Inc.; * Peter Kolb - patches 2603321, 2809117; * * Changes * ------- * 21-Jun-2001 : Removed redundant JFreeChart parameter from constructors (DG); * 18-Sep-2001 : Updated header info and fixed DOS encoding problem (DG); * 19-Oct-2001 : Moved series paint and stroke methods from JFreeChart * class (DG); * 23-Oct-2001 : Created renderer for LinePlot class (DG); * 07-Nov-2001 : Changed type names for ChartChangeEvent (DG); * Tidied up some Javadoc comments (DG); * 13-Nov-2001 : Changes to allow for null axes on plots such as PiePlot (DG); * Added plot/axis compatibility checks (DG); * 12-Dec-2001 : Changed constructors to protected, and removed unnecessary * 'throws' clauses (DG); * 13-Dec-2001 : Added tooltips (DG); * 22-Jan-2002 : Added handleClick() method, as part of implementation for * crosshairs (DG); * Moved tooltips reference into ChartInfo class (DG); * 23-Jan-2002 : Added test for null axes in chartChanged() method, thanks * to Barry Evans for the bug report (number 506979 on * SourceForge) (DG); * Added a zoom() method (DG); * 05-Feb-2002 : Updated setBackgroundPaint(), setOutlineStroke() and * setOutlinePaint() to better handle null values, as suggested * by Sylvain Vieujot (DG); * 06-Feb-2002 : Added background image, plus alpha transparency for background * and foreground (DG); * 06-Mar-2002 : Added AxisConstants interface (DG); * 26-Mar-2002 : Changed zoom method from empty to abstract (DG); * 23-Apr-2002 : Moved dataset from JFreeChart class (DG); * 11-May-2002 : Added ShapeFactory interface for getShape() methods, * contributed by Jeremy Bowman (DG); * 28-May-2002 : Fixed bug in setSeriesPaint(int, Paint) for subplots (AS); * 25-Jun-2002 : Removed redundant imports (DG); * 30-Jul-2002 : Added 'no data' message for charts with null or empty * datasets (DG); * 21-Aug-2002 : Added code to extend series array if necessary (refer to * SourceForge bug id 594547 for details) (DG); * 17-Sep-2002 : Fixed bug in getSeriesOutlineStroke() method, reported by * Andreas Schroeder (DG); * 23-Sep-2002 : Added getLegendItems() abstract method (DG); * 24-Sep-2002 : Removed firstSeriesIndex, subplots now use their own paint * settings, there is a new mechanism for the legend to collect * the legend items (DG); * 27-Sep-2002 : Added dataset group (DG); * 14-Oct-2002 : Moved listener storage into EventListenerList. Changed some * abstract methods to empty implementations (DG); * 28-Oct-2002 : Added a getBackgroundImage() method (DG); * 21-Nov-2002 : Added a plot index for identifying subplots in combined and * overlaid charts (DG); * 22-Nov-2002 : Changed all attributes from 'protected' to 'private'. Added * dataAreaRatio attribute from David M O'Donnell's code (DG); * 09-Jan-2003 : Integrated fix for plot border contributed by Gideon * Krause (DG); * 17-Jan-2003 : Moved to com.jrefinery.chart.plot (DG); * 23-Jan-2003 : Removed one constructor (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 14-Jul-2003 : Moved the dataset and secondaryDataset attributes to the * CategoryPlot and XYPlot classes (DG); * 21-Jul-2003 : Moved DrawingSupplier from CategoryPlot and XYPlot up to this * class (DG); * 20-Aug-2003 : Implemented Cloneable (DG); * 11-Sep-2003 : Listeners and clone (NB); * 29-Oct-2003 : Added workaround for font alignment in PDF output (DG); * 03-Dec-2003 : Modified draw method to accept anchor (DG); * 12-Mar-2004 : Fixed clipping bug in drawNoDataMessage() method (DG); * 07-Apr-2004 : Modified string bounds calculation (DG); * 04-Nov-2004 : Added default shapes for legend items (DG); * 25-Nov-2004 : Some changes to the clone() method implementation (DG); * 23-Feb-2005 : Implemented new LegendItemSource interface (and also * PublicCloneable) (DG); * 21-Apr-2005 : Replaced Insets with RectangleInsets (DG); * 05-May-2005 : Removed unused draw() method (DG); * 06-Jun-2005 : Fixed bugs in equals() method (DG); * 01-Sep-2005 : Moved dataAreaRatio from here to ContourPlot (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 30-Jun-2006 : Added background image alpha - see bug report 1514904 (DG); * 05-Sep-2006 : Implemented the MarkerChangeListener interface (DG); * 11-Jan-2007 : Added some argument checks, event notifications, and many * API doc updates (DG); * 03-Apr-2007 : Made drawBackgroundImage() public (DG); * 07-Jun-2007 : Added new fillBackground() method to handle GradientPaint * taking into account orientation (DG); * 25-Mar-2008 : Added fireChangeEvent() method - see patch 1914411 (DG); * 15-Aug-2008 : Added setDrawingSupplier() method with notify flag (DG); * 13-Jan-2009 : Added notify flag (DG); * 19-Mar-2009 : Added entity support - see patch 2603321 by Peter Kolb (DG); * 24-Jun-2009 : Implemented AnnotationChangeListener (see patch 2809117 by * PK) (DG); * 13-Jul-2009 : Plot background image should be clipped if necessary (DG); * 10-Mar-2014 : Remove LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.swing.event.EventListenerList; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; import org.jfree.chart.LegendItemSource; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.PlotEntity; import org.jfree.chart.event.AnnotationChangeEvent; import org.jfree.chart.event.AnnotationChangeListener; import org.jfree.chart.event.AxisChangeEvent; import org.jfree.chart.event.AxisChangeListener; import org.jfree.chart.event.ChartChangeEventType; import org.jfree.chart.event.MarkerChangeEvent; import org.jfree.chart.event.MarkerChangeListener; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.jfree.chart.text.G2TextMeasurer; import org.jfree.chart.text.TextBlock; import org.jfree.chart.text.TextBlockAnchor; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.ui.Align; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.general.DatasetGroup; import org.jfree.data.general.LabelChangeEvent; import org.jfree.data.general.LabelChangeListener; import org.jfree.data.general.SelectionChangeEvent; import org.jfree.data.general.SelectionChangeListener; /** * The base class for all plots in JFreeChart. The {@link JFreeChart} class * delegates the drawing of axes and data to the plot. This base class * provides facilities common to most plot types. */ public abstract class Plot implements AxisChangeListener, DatasetChangeListener, SelectionChangeListener, LabelChangeListener, AnnotationChangeListener, MarkerChangeListener, LegendItemSource, PublicCloneable, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -8831571430103671324L; /** Useful constant representing zero. */ public static final Number ZERO = 0; /** The default insets. */ public static final RectangleInsets DEFAULT_INSETS = new RectangleInsets(4.0, 8.0, 4.0, 8.0); /** The default outline stroke. */ public static final Stroke DEFAULT_OUTLINE_STROKE = new BasicStroke(0.5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND); /** The default outline color. */ public static final Paint DEFAULT_OUTLINE_PAINT = Color.GRAY; /** The default foreground alpha transparency. */ public static final float DEFAULT_FOREGROUND_ALPHA = 1.0f; /** The default background alpha transparency. */ public static final float DEFAULT_BACKGROUND_ALPHA = 1.0f; /** The default background color. */ public static final Paint DEFAULT_BACKGROUND_PAINT = Color.WHITE; /** The minimum width at which the plot should be drawn. */ public static final int MINIMUM_WIDTH_TO_DRAW = 10; /** The minimum height at which the plot should be drawn. */ public static final int MINIMUM_HEIGHT_TO_DRAW = 10; /** A default box shape for legend items. */ public static final Shape DEFAULT_LEGEND_ITEM_BOX = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0); /** A default circle shape for legend items. */ public static final Shape DEFAULT_LEGEND_ITEM_CIRCLE = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0); /** The parent plot (<code>null</code> if this is the root plot). */ private Plot parent; /** The dataset group (to be used for thread synchronisation). */ private DatasetGroup datasetGroup; /** The message to display if no data is available. */ private String noDataMessage; /** The font used to display the 'no data' message. */ private Font noDataMessageFont; /** The paint used to draw the 'no data' message. */ private transient Paint noDataMessagePaint; /** Amount of blank space around the plot area. */ private RectangleInsets insets; /** * A flag that controls whether or not the plot outline is drawn. * * @since 1.0.6 */ private boolean outlineVisible; /** The Stroke used to draw an outline around the plot. */ private transient Stroke outlineStroke; /** The Paint used to draw an outline around the plot. */ private transient Paint outlinePaint; /** An optional color used to fill the plot background. */ private transient Paint backgroundPaint; /** An optional image for the plot background. */ private transient Image backgroundImage; // not currently serialized /** The alignment for the background image. */ private int backgroundImageAlignment = Align.FIT; /** The alpha value used to draw the background image. */ private float backgroundImageAlpha = 0.5f; /** The alpha-transparency for the plot. */ private float foregroundAlpha; /** The alpha transparency for the background paint. */ private float backgroundAlpha; /** The drawing supplier. */ private DrawingSupplier drawingSupplier; /** Storage for registered change listeners. */ private transient EventListenerList listenerList; /** * A flag that controls whether or not the plot will notify listeners * of changes (defaults to true, but sometimes it is useful to disable * this). * * @since 1.0.13 */ private boolean notify; /** * Creates a new plot. */ protected Plot() { this.parent = null; this.insets = DEFAULT_INSETS; this.backgroundPaint = DEFAULT_BACKGROUND_PAINT; this.backgroundAlpha = DEFAULT_BACKGROUND_ALPHA; this.backgroundImage = null; this.outlineVisible = true; this.outlineStroke = DEFAULT_OUTLINE_STROKE; this.outlinePaint = DEFAULT_OUTLINE_PAINT; this.foregroundAlpha = DEFAULT_FOREGROUND_ALPHA; this.noDataMessage = null; this.noDataMessageFont = new Font("SansSerif", Font.PLAIN, 12); this.noDataMessagePaint = Color.BLACK; this.drawingSupplier = new DefaultDrawingSupplier(); this.notify = true; this.listenerList = new EventListenerList(); } /** * Returns the dataset group for the plot (not currently used). * * @return The dataset group. * * @see #setDatasetGroup(DatasetGroup) */ public DatasetGroup getDatasetGroup() { return this.datasetGroup; } /** * Sets the dataset group (not currently used). * * @param group the dataset group (<code>null</code> permitted). * * @see #getDatasetGroup() */ protected void setDatasetGroup(DatasetGroup group) { this.datasetGroup = group; } /** * Returns the string that is displayed when the dataset is empty or * <code>null</code>. * * @return The 'no data' message (<code>null</code> possible). * * @see #setNoDataMessage(String) * @see #getNoDataMessageFont() * @see #getNoDataMessagePaint() */ public String getNoDataMessage() { return this.noDataMessage; } /** * Sets the message that is displayed when the dataset is empty or * <code>null</code>, and sends a {@link PlotChangeEvent} to all registered * listeners. * * @param message the message (<code>null</code> permitted). * * @see #getNoDataMessage() */ public void setNoDataMessage(String message) { this.noDataMessage = message; fireChangeEvent(); } /** * Returns the font used to display the 'no data' message. * * @return The font (never <code>null</code>). * * @see #setNoDataMessageFont(Font) * @see #getNoDataMessage() */ public Font getNoDataMessageFont() { return this.noDataMessageFont; } /** * Sets the font used to display the 'no data' message and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getNoDataMessageFont() */ public void setNoDataMessageFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.noDataMessageFont = font; fireChangeEvent(); } /** * Returns the paint used to display the 'no data' message. * * @return The paint (never <code>null</code>). * * @see #setNoDataMessagePaint(Paint) * @see #getNoDataMessage() */ public Paint getNoDataMessagePaint() { return this.noDataMessagePaint; } /** * Sets the paint used to display the 'no data' message and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getNoDataMessagePaint() */ public void setNoDataMessagePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.noDataMessagePaint = paint; fireChangeEvent(); } /** * Returns a short string describing the plot type. * <P> * Note: this gets used in the chart property editing user interface, * but there needs to be a better mechanism for identifying the plot type. * * @return A short string describing the plot type (never * <code>null</code>). */ public abstract String getPlotType(); /** * Returns the parent plot (or <code>null</code> if this plot is not part * of a combined plot). * * @return The parent plot. * * @see #setParent(Plot) * @see #getRootPlot() */ public Plot getParent() { return this.parent; } /** * Sets the parent plot. This method is intended for internal use, you * shouldn't need to call it directly. * * @param parent the parent plot (<code>null</code> permitted). * * @see #getParent() */ public void setParent(Plot parent) { this.parent = parent; } /** * Returns the root plot. * * @return The root plot. * * @see #getParent() */ public Plot getRootPlot() { Plot p = getParent(); if (p == null) { return this; } return p.getRootPlot(); } /** * Returns <code>true</code> if this plot is part of a combined plot * structure (that is, {@link #getParent()} returns a non-<code>null</code> * value), and <code>false</code> otherwise. * * @return <code>true</code> if this plot is part of a combined plot * structure. * * @see #getParent() */ public boolean isSubplot() { return (getParent() != null); } /** * Returns the insets for the plot area. * * @return The insets (never <code>null</code>). * * @see #setInsets(RectangleInsets) */ public RectangleInsets getInsets() { return this.insets; } /** * Sets the insets for the plot and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param insets the new insets (<code>null</code> not permitted). * * @see #getInsets() * @see #setInsets(RectangleInsets, boolean) */ public void setInsets(RectangleInsets insets) { setInsets(insets, true); } /** * Sets the insets for the plot and, if requested, and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param insets the new insets (<code>null</code> not permitted). * @param notify a flag that controls whether the registered listeners are * notified. * * @see #getInsets() * @see #setInsets(RectangleInsets) */ public void setInsets(RectangleInsets insets, boolean notify) { if (insets == null) { throw new IllegalArgumentException("Null 'insets' argument."); } if (!this.insets.equals(insets)) { this.insets = insets; if (notify) { fireChangeEvent(); } } } /** * Returns the background color of the plot area. * * @return The paint (possibly <code>null</code>). * * @see #setBackgroundPaint(Paint) */ public Paint getBackgroundPaint() { return this.backgroundPaint; } /** * Sets the background color of the plot area and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> permitted). * * @see #getBackgroundPaint() */ public void setBackgroundPaint(Paint paint) { if (paint == null) { if (this.backgroundPaint != null) { this.backgroundPaint = null; fireChangeEvent(); } } else { if (this.backgroundPaint != null) { if (this.backgroundPaint.equals(paint)) { return; // nothing to do } } this.backgroundPaint = paint; fireChangeEvent(); } } /** * Returns the alpha transparency of the plot area background. * * @return The alpha transparency. * * @see #setBackgroundAlpha(float) */ public float getBackgroundAlpha() { return this.backgroundAlpha; } /** * Sets the alpha transparency of the plot area background, and notifies * registered listeners that the plot has been modified. * * @param alpha the new alpha value (in the range 0.0f to 1.0f). * * @see #getBackgroundAlpha() */ public void setBackgroundAlpha(float alpha) { if (this.backgroundAlpha != alpha) { this.backgroundAlpha = alpha; fireChangeEvent(); } } /** * Returns the drawing supplier for the plot. * * @return The drawing supplier (possibly <code>null</code>). * * @see #setDrawingSupplier(DrawingSupplier) */ public DrawingSupplier getDrawingSupplier() { DrawingSupplier result = null; Plot p = getParent(); if (p != null) { result = p.getDrawingSupplier(); } else { result = this.drawingSupplier; } return result; } /** * Sets the drawing supplier for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. The drawing * supplier is responsible for supplying a limitless (possibly repeating) * sequence of <code>Paint</code>, <code>Stroke</code> and * <code>Shape</code> objects that the plot's renderer(s) can use to * populate its (their) tables. * * @param supplier the new supplier. * * @see #getDrawingSupplier() */ public void setDrawingSupplier(DrawingSupplier supplier) { this.drawingSupplier = supplier; fireChangeEvent(); } /** * Sets the drawing supplier for the plot and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. The drawing * supplier is responsible for supplying a limitless (possibly repeating) * sequence of <code>Paint</code>, <code>Stroke</code> and * <code>Shape</code> objects that the plot's renderer(s) can use to * populate its (their) tables. * * @param supplier the new supplier. * @param notify notify listeners? * * @see #getDrawingSupplier() * * @since 1.0.11 */ public void setDrawingSupplier(DrawingSupplier supplier, boolean notify) { this.drawingSupplier = supplier; if (notify) { fireChangeEvent(); } } /** * Returns the background image that is used to fill the plot's background * area. * * @return The image (possibly <code>null</code>). * * @see #setBackgroundImage(Image) */ public Image getBackgroundImage() { return this.backgroundImage; } /** * Sets the background image for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param image the image (<code>null</code> permitted). * * @see #getBackgroundImage() */ public void setBackgroundImage(Image image) { this.backgroundImage = image; fireChangeEvent(); } /** * Returns the background image alignment. Alignment constants are defined * in the <code>org.jfree.ui.Align</code> class in the JCommon class * library. * * @return The alignment. * * @see #setBackgroundImageAlignment(int) */ public int getBackgroundImageAlignment() { return this.backgroundImageAlignment; } /** * Sets the alignment for the background image and sends a * {@link PlotChangeEvent} to all registered listeners. Alignment options * are defined by the {@link org.jfree.ui.Align} class in the JCommon * class library. * * @param alignment the alignment. * * @see #getBackgroundImageAlignment() */ public void setBackgroundImageAlignment(int alignment) { if (this.backgroundImageAlignment != alignment) { this.backgroundImageAlignment = alignment; fireChangeEvent(); } } /** * Returns the alpha transparency used to draw the background image. This * is a value in the range 0.0f to 1.0f, where 0.0f is fully transparent * and 1.0f is fully opaque. * * @return The alpha transparency. * * @see #setBackgroundImageAlpha(float) */ public float getBackgroundImageAlpha() { return this.backgroundImageAlpha; } /** * Sets the alpha transparency used when drawing the background image. * * @param alpha the alpha transparency (in the range 0.0f to 1.0f, where * 0.0f is fully transparent, and 1.0f is fully opaque). * * @throws IllegalArgumentException if <code>alpha</code> is not within * the specified range. * * @see #getBackgroundImageAlpha() */ public void setBackgroundImageAlpha(float alpha) { if (alpha < 0.0f || alpha > 1.0f) { throw new IllegalArgumentException( "The 'alpha' value must be in the range 0.0f to 1.0f."); } if (this.backgroundImageAlpha != alpha) { this.backgroundImageAlpha = alpha; fireChangeEvent(); } } /** * Returns the flag that controls whether or not the plot outline is * drawn. The default value is <code>true</code>. Note that for * historical reasons, the plot's outline paint and stroke can take on * <code>null</code> values, in which case the outline will not be drawn * even if this flag is set to <code>true</code>. * * @return The outline visibility flag. * * @since 1.0.6 * * @see #setOutlineVisible(boolean) */ public boolean isOutlineVisible() { return this.outlineVisible; } /** * Sets the flag that controls whether or not the plot's outline is * drawn, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param visible the new flag value. * * @since 1.0.6 * * @see #isOutlineVisible() */ public void setOutlineVisible(boolean visible) { this.outlineVisible = visible; fireChangeEvent(); } /** * Returns the stroke used to outline the plot area. * * @return The stroke (possibly <code>null</code>). * * @see #setOutlineStroke(Stroke) */ public Stroke getOutlineStroke() { return this.outlineStroke; } /** * Sets the stroke used to outline the plot area and sends a * {@link PlotChangeEvent} to all registered listeners. If you set this * attribute to <code>null</code>, no outline will be drawn. * * @param stroke the stroke (<code>null</code> permitted). * * @see #getOutlineStroke() */ public void setOutlineStroke(Stroke stroke) { if (stroke == null) { if (this.outlineStroke != null) { this.outlineStroke = null; fireChangeEvent(); } } else { if (this.outlineStroke != null) { if (this.outlineStroke.equals(stroke)) { return; // nothing to do } } this.outlineStroke = stroke; fireChangeEvent(); } } /** * Returns the color used to draw the outline of the plot area. * * @return The color (possibly <code>null</code>). * * @see #setOutlinePaint(Paint) */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Sets the paint used to draw the outline of the plot area and sends a * {@link PlotChangeEvent} to all registered listeners. If you set this * attribute to <code>null</code>, no outline will be drawn. * * @param paint the paint (<code>null</code> permitted). * * @see #getOutlinePaint() */ public void setOutlinePaint(Paint paint) { if (paint == null) { if (this.outlinePaint != null) { this.outlinePaint = null; fireChangeEvent(); } } else { if (this.outlinePaint != null) { if (this.outlinePaint.equals(paint)) { return; // nothing to do } } this.outlinePaint = paint; fireChangeEvent(); } } /** * Returns the alpha-transparency for the plot foreground. * * @return The alpha-transparency. * * @see #setForegroundAlpha(float) */ public float getForegroundAlpha() { return this.foregroundAlpha; } /** * Sets the alpha-transparency for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param alpha the new alpha transparency. * * @see #getForegroundAlpha() */ public void setForegroundAlpha(float alpha) { if (this.foregroundAlpha != alpha) { this.foregroundAlpha = alpha; fireChangeEvent(); } } /** * Returns the legend items for the plot. By default, this method returns * <code>null</code>. Subclasses should override to return a list of * legend items for the plot. * * @return The legend items for the plot (possibly empty, but never * <code>null</code>). */ @Override public List<LegendItem> getLegendItems() { return new ArrayList<LegendItem>(); } /** * Returns a flag that controls whether or not change events are sent to * registered listeners. * * @return A boolean. * * @see #setNotify(boolean) * * @since 1.0.13 */ public boolean isNotify() { return this.notify; } /** * Sets a flag that controls whether or not listeners receive * {@link PlotChangeEvent} notifications. * * @param notify a boolean. * * @see #isNotify() * * @since 1.0.13 */ public void setNotify(boolean notify) { this.notify = notify; // if the flag is being set to true, there may be queued up changes... if (notify) { notifyListeners(new PlotChangeEvent(this)); } } /** * Registers an object for notification of changes to the plot. * * @param listener the object to be registered. * * @see #removeChangeListener(PlotChangeListener) */ public void addChangeListener(PlotChangeListener listener) { this.listenerList.add(PlotChangeListener.class, listener); } /** * Unregisters an object for notification of changes to the plot. * * @param listener the object to be unregistered. * * @see #addChangeListener(PlotChangeListener) */ public void removeChangeListener(PlotChangeListener listener) { this.listenerList.remove(PlotChangeListener.class, listener); } /** * Notifies all registered listeners that the plot has been modified. * * @param event information about the change event. */ public void notifyListeners(PlotChangeEvent event) { // if the 'notify' flag has been switched to false, we don't notify // the listeners if (!this.notify) { return; } Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == PlotChangeListener.class) { ((PlotChangeListener) listeners[i + 1]).plotChanged(event); } } } /** * Sends a {@link PlotChangeEvent} to all registered listeners. * * @since 1.0.10 */ protected void fireChangeEvent() { notifyListeners(new PlotChangeEvent(this)); } /** * Draws the plot within the specified area. The anchor is a point on the * chart that is specified externally (for instance, it may be the last * point of the last mouse click performed by the user) - plots can use or * ignore this value as they see fit. * <br><br> * Subclasses need to provide an implementation of this method, obviously. * * @param g2 the graphics device. * @param area the plot area. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the parent state (if any). * @param info carries back plot rendering info. */ public abstract void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info); /** * Draws the plot background (the background color and/or image). * <P> * This method will be called during the chart drawing process and is * declared public so that it can be accessed by the renderers used by * certain subclasses. You shouldn't need to call this method directly. * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. */ public void drawBackground(Graphics2D g2, Rectangle2D area) { // some subclasses override this method completely, so don't put // anything here that *must* be done fillBackground(g2, area); drawBackgroundImage(g2, area); } /** * Fills the specified area with the background paint. * * @param g2 the graphics device. * @param area the area. * * @see #getBackgroundPaint() * @see #getBackgroundAlpha() * @see #fillBackground(Graphics2D, Rectangle2D, PlotOrientation) */ protected void fillBackground(Graphics2D g2, Rectangle2D area) { fillBackground(g2, area, PlotOrientation.VERTICAL); } /** * Fills the specified area with the background paint. If the background * paint is an instance of <code>GradientPaint</code>, the gradient will * run in the direction suggested by the plot's orientation. * * @param g2 the graphics target. * @param area the plot area. * @param orientation the plot orientation (<code>null</code> not * permitted). * * @since 1.0.6 */ protected void fillBackground(Graphics2D g2, Rectangle2D area, PlotOrientation orientation) { if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } if (this.backgroundPaint == null) { return; } Paint p = this.backgroundPaint; if (p instanceof GradientPaint) { GradientPaint gp = (GradientPaint) p; if (orientation == PlotOrientation.VERTICAL) { p = new GradientPaint((float) area.getCenterX(), (float) area.getMaxY(), gp.getColor1(), (float) area.getCenterX(), (float) area.getMinY(), gp.getColor2()); } else if (orientation == PlotOrientation.HORIZONTAL) { p = new GradientPaint((float) area.getMinX(), (float) area.getCenterY(), gp.getColor1(), (float) area.getMaxX(), (float) area.getCenterY(), gp.getColor2()); } } Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundAlpha)); g2.setPaint(p); g2.fill(area); g2.setComposite(originalComposite); } /** * Draws the background image (if there is one) aligned within the * specified area. * * @param g2 the graphics device. * @param area the area. * * @see #getBackgroundImage() * @see #getBackgroundImageAlignment() * @see #getBackgroundImageAlpha() */ public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) { if (this.backgroundImage == null) { return; // nothing to do } Composite savedComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, this.backgroundImageAlpha)); Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0, this.backgroundImage.getWidth(null), this.backgroundImage.getHeight(null)); Align.align(dest, area, this.backgroundImageAlignment); Shape savedClip = g2.getClip(); g2.clip(area); g2.drawImage(this.backgroundImage, (int) dest.getX(), (int) dest.getY(), (int) dest.getWidth() + 1, (int) dest.getHeight() + 1, null); g2.setClip(savedClip); g2.setComposite(savedComposite); } /** * Draws the plot outline. This method will be called during the chart * drawing process and is declared public so that it can be accessed by the * renderers used by certain subclasses. You shouldn't need to call this * method directly. * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. */ public void drawOutline(Graphics2D g2, Rectangle2D area) { if (!this.outlineVisible) { return; } if ((this.outlineStroke != null) && (this.outlinePaint != null)) { g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(area); } } /** * Draws a message to state that there is no data to plot. * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. */ protected void drawNoDataMessage(Graphics2D g2, Rectangle2D area) { Shape savedClip = g2.getClip(); g2.clip(area); String message = this.noDataMessage; if (message != null) { g2.setFont(this.noDataMessageFont); g2.setPaint(this.noDataMessagePaint); TextBlock block = TextUtilities.createTextBlock( this.noDataMessage, this.noDataMessageFont, this.noDataMessagePaint, 0.9f * (float) area.getWidth(), new G2TextMeasurer(g2)); block.draw(g2, (float) area.getCenterX(), (float) area.getCenterY(), TextBlockAnchor.CENTER); } g2.setClip(savedClip); } /** * Creates a plot entity that contains a reference to the plot and the * data area as shape. * * @param dataArea the data area used as hot spot for the entity. * @param plotState the plot rendering info containing a reference to the * EntityCollection. * @param toolTip the tool tip (defined in the respective Plot * subclass) (<code>null</code> permitted). * @param urlText the url (defined in the respective Plot subclass) * (<code>null</code> permitted). * * @since 1.0.13 */ protected void createAndAddEntity(Rectangle2D dataArea, PlotRenderingInfo plotState, String toolTip, String urlText) { if (plotState != null && plotState.getOwner() != null) { EntityCollection e = plotState.getOwner().getEntityCollection(); if (e != null) { e.add(new PlotEntity(dataArea, this, toolTip, urlText)); } } } /** * Handles a 'click' on the plot. Since the plot does not maintain any * information about where it has been drawn, the plot rendering info is * supplied as an argument so that the plot dimensions can be determined. * * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param info an object containing information about the dimensions of * the plot. */ public void handleClick(int x, int y, PlotRenderingInfo info) { // provides a 'no action' default } /** * Performs a zoom on the plot. Subclasses should override if zooming is * appropriate for the type of plot. * * @param percent the zoom percentage. */ public void zoom(double percent) { // do nothing by default. } /** * Receives notification of a change to an {@link Annotation} added to * this plot. * * @param event information about the event (not used here). * * @since 1.0.14 */ @Override public void annotationChanged(AnnotationChangeEvent event) { fireChangeEvent(); } /** * Receives notification of a change to one of the plot's axes. * * @param event information about the event (not used here). */ @Override public void axisChanged(AxisChangeEvent event) { fireChangeEvent(); } /** * Receives notification of a change to the plot's dataset. * <P> * The plot reacts by passing on a plot change event to all registered * listeners. * * @param event information about the event (not used here). */ @Override public void datasetChanged(DatasetChangeEvent event) { PlotChangeEvent newEvent = new PlotChangeEvent(this); newEvent.setType(ChartChangeEventType.DATASET_UPDATED); notifyListeners(newEvent); } /** * Receives notification of a change to the selection state of the plot's data * <P> * The plot reacts by passing on a plot change event to all registered * listeners. * * @param event information about the event (not used here). */ @Override public void selectionChanged(SelectionChangeEvent event) { //could be typed but would require typing Plot and its decendents with a DatasetCursor PlotChangeEvent newEvent = new PlotChangeEvent(this); newEvent.setType(ChartChangeEventType.GENERAL); notifyListeners(newEvent); } /** * Receives notification of a change to the label information of the plot's data * <P> * The plot reacts by passing on a plot change event to all registered * listeners. * * @param event information about the event (not used here). */ @Override public void labelChanged(LabelChangeEvent event) { //could be typed but would require typing Plot and its decendents with a DatasetCursor PlotChangeEvent newEvent = new PlotChangeEvent(this); newEvent.setType(ChartChangeEventType.GENERAL); notifyListeners(newEvent); } /** * Receives notification of a change to a marker that is assigned to the * plot. * * @param event the event. * * @since 1.0.3 */ @Override public void markerChanged(MarkerChangeEvent event) { fireChangeEvent(); } /** * Adjusts the supplied x-value. * * @param x the x-value. * @param w1 width 1. * @param w2 width 2. * @param edge the edge (left or right). * * @return The adjusted x-value. */ protected double getRectX(double x, double w1, double w2, RectangleEdge edge) { double result = x; if (edge == RectangleEdge.LEFT) { result = result + w1; } else if (edge == RectangleEdge.RIGHT) { result = result + w2; } return result; } /** * Adjusts the supplied y-value. * * @param y the x-value. * @param h1 height 1. * @param h2 height 2. * @param edge the edge (top or bottom). * * @return The adjusted y-value. */ protected double getRectY(double y, double h1, double h2, RectangleEdge edge) { double result = y; if (edge == RectangleEdge.TOP) { result = result + h1; } else if (edge == RectangleEdge.BOTTOM) { result = result + h2; } return result; } /** * Tests this plot for equality with another object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof Plot)) { return false; } Plot that = (Plot) obj; if (!ObjectUtilities.equal(this.noDataMessage, that.noDataMessage)) { return false; } if (!ObjectUtilities.equal( this.noDataMessageFont, that.noDataMessageFont )) { return false; } if (!PaintUtilities.equal(this.noDataMessagePaint, that.noDataMessagePaint)) { return false; } if (!ObjectUtilities.equal(this.insets, that.insets)) { return false; } if (this.outlineVisible != that.outlineVisible) { return false; } if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { return false; } if (!ObjectUtilities.equal(this.backgroundImage, that.backgroundImage)) { return false; } if (this.backgroundImageAlignment != that.backgroundImageAlignment) { return false; } if (this.backgroundImageAlpha != that.backgroundImageAlpha) { return false; } if (this.foregroundAlpha != that.foregroundAlpha) { return false; } if (this.backgroundAlpha != that.backgroundAlpha) { return false; } if (!this.drawingSupplier.equals(that.drawingSupplier)) { return false; } if (this.notify != that.notify) { return false; } return true; } /** * Creates a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException if some component of the plot does not * support cloning. */ @Override public Object clone() throws CloneNotSupportedException { Plot clone = (Plot) super.clone(); // private Plot parent <-- don't clone the parent plot, but take care // childs in combined plots instead if (this.datasetGroup != null) { clone.datasetGroup = ObjectUtilities.clone(this.datasetGroup); } clone.drawingSupplier = ObjectUtilities.clone(this.drawingSupplier); clone.listenerList = new EventListenerList(); return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.noDataMessagePaint, stream); SerialUtilities.writeStroke(this.outlineStroke, stream); SerialUtilities.writePaint(this.outlinePaint, stream); // backgroundImage SerialUtilities.writePaint(this.backgroundPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.noDataMessagePaint = SerialUtilities.readPaint(stream); this.outlineStroke = SerialUtilities.readStroke(stream); this.outlinePaint = SerialUtilities.readPaint(stream); // backgroundImage this.backgroundPaint = SerialUtilities.readPaint(stream); this.listenerList = new EventListenerList(); } /** * Resolves a domain axis location for a given plot orientation. * * @param location the location (<code>null</code> not permitted). * @param orientation the orientation (<code>null</code> not permitted). * * @return The edge (never <code>null</code>). */ public static RectangleEdge resolveDomainAxisLocation( AxisLocation location, PlotOrientation orientation) { if (location == null) { throw new IllegalArgumentException("Null 'location' argument."); } if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } RectangleEdge result = null; if (location == AxisLocation.TOP_OR_RIGHT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.RIGHT; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.TOP; } } else if (location == AxisLocation.TOP_OR_LEFT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.LEFT; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.TOP; } } else if (location == AxisLocation.BOTTOM_OR_RIGHT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.RIGHT; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.BOTTOM; } } else if (location == AxisLocation.BOTTOM_OR_LEFT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.LEFT; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.BOTTOM; } } // the above should cover all the options... if (result == null) { throw new IllegalStateException("resolveDomainAxisLocation()"); } return result; } /** * Resolves a range axis location for a given plot orientation. * * @param location the location (<code>null</code> not permitted). * @param orientation the orientation (<code>null</code> not permitted). * * @return The edge (never <code>null</code>). */ public static RectangleEdge resolveRangeAxisLocation( AxisLocation location, PlotOrientation orientation) { if (location == null) { throw new IllegalArgumentException("Null 'location' argument."); } if (orientation == null) { throw new IllegalArgumentException("Null 'orientation' argument."); } RectangleEdge result = null; if (location == AxisLocation.TOP_OR_RIGHT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.TOP; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.RIGHT; } } else if (location == AxisLocation.TOP_OR_LEFT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.TOP; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.LEFT; } } else if (location == AxisLocation.BOTTOM_OR_RIGHT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.BOTTOM; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.RIGHT; } } else if (location == AxisLocation.BOTTOM_OR_LEFT) { if (orientation == PlotOrientation.HORIZONTAL) { result = RectangleEdge.BOTTOM; } else if (orientation == PlotOrientation.VERTICAL) { result = RectangleEdge.LEFT; } } // the above should cover all the options... if (result == null) { throw new IllegalStateException("resolveRangeAxisLocation()"); } return result; } }
53,887
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CombinedDomainXYPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CombinedDomainXYPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * CombinedDomainXYPlot.java * ------------------------- * (C) Copyright 2001-2014, by Bill Kelemen and Contributors. * * Original Author: Bill Kelemen; * Contributor(s): David Gilbert (for Object Refinery Limited); * Anthony Boulestreau; * David Basten; * Kevin Frechette (for ISTI); * Nicolas Brodu; * Petr Kubanek (bug 1606205); * * Changes: * -------- * 06-Dec-2001 : Version 1 (BK); * 12-Dec-2001 : Removed unnecessary 'throws' clause from constructor (DG); * 18-Dec-2001 : Added plotArea attribute and get/set methods (BK); * 22-Dec-2001 : Fixed bug in chartChanged with multiple combinations of * CombinedPlots (BK); * 08-Jan-2002 : Moved to new package com.jrefinery.chart.combination (DG); * 25-Feb-2002 : Updated import statements (DG); * 28-Feb-2002 : Readded "this.plotArea = plotArea" that was deleted from * draw() method (BK); * 26-Mar-2002 : Added an empty zoom method (this method needs to be written so * that combined plots will support zooming (DG); * 29-Mar-2002 : Changed the method createCombinedAxis adding the creation of * OverlaidSymbolicAxis and CombinedSymbolicAxis(AB); * 23-Apr-2002 : Renamed CombinedPlot-->MultiXYPlot, and simplified the * structure (DG); * 23-May-2002 : Renamed (again) MultiXYPlot-->CombinedXYPlot (DG); * 19-Jun-2002 : Added get/setGap() methods suggested by David Basten (DG); * 25-Jun-2002 : Removed redundant imports (DG); * 16-Jul-2002 : Draws shared axis after subplots (to fix missing gridlines), * added overrides of 'setSeriesPaint()' and 'setXYItemRenderer()' * that pass changes down to subplots (KF); * 09-Oct-2002 : Added add(XYPlot) method (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 16-May-2003 : Renamed CombinedXYPlot --> CombinedDomainXYPlot (DG); * 04-Aug-2003 : Removed leftover code that was causing domain axis drawing * problem (DG); * 08-Aug-2003 : Adjusted totalWeight in remove() method (DG); * 21-Aug-2003 : Implemented Cloneable (DG); * 11-Sep-2003 : Fix cloning support (subplots) (NB); * 15-Sep-2003 : Fixed error in cloning (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 17-Sep-2003 : Updated handling of 'clicks' (DG); * 12-Nov-2004 : Implemented the new Zoomable interface (DG); * 25-Nov-2004 : Small update to clone() implementation (DG); * 21-Feb-2005 : The getLegendItems() method now returns the fixed legend * items if set (DG); * 05-May-2005 : Removed unused draw() method (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 23-Aug-2006 : Override setFixedRangeAxisSpace() to update subplots (DG); * 06-Feb-2007 : Fixed bug 1606205, draw shared axis after subplots (DG); * 23-Mar-2007 : Reverted previous patch (bug fix 1606205) (DG); * 17-Apr-2007 : Added null argument checks to findSubplot() (DG); * 27-Nov-2007 : Modified setFixedRangeAxisSpaceForSubplots() so as not to * trigger change event in subplots (DG); * 28-Jan-2008 : Reset fixed range axis space in subplots for each call to * draw() (DG); * 27-Mar-2008 : Add documentation for getDataRange() method (DG); * 31-Mar-2008 : Updated getSubplots() to return EMPTY_LIST for null * subplots, as suggested by Richard West (DG); * 28-Apr-2008 : Fixed zooming problem (see bug 1950037) (DG); * 11-Aug-2008 : Don't store totalWeight of subplots, calculate it as * required (DG); * 21-Dec-2011 : Apply patch 3447161 by Ulrich Voigt and Martin Hoeller (MH); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.Graphics2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.AxisSpace; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.PlotChangeListener; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.ShadowGenerator; import org.jfree.data.Range; /** * An extension of {@link XYPlot} that contains multiple subplots that share a * common domain axis. */ public class CombinedDomainXYPlot extends XYPlot implements PlotChangeListener { /** For serialization. */ private static final long serialVersionUID = -7765545541261907383L; /** Storage for the subplot references. */ private List<XYPlot> subplots; /** The gap between subplots. */ private double gap = 5.0; /** Temporary storage for the subplot areas. */ private transient Rectangle2D[] subplotAreas; // TODO: the subplot areas needs to be moved out of the plot into the plot // state /** * Default constructor. */ public CombinedDomainXYPlot() { this(new NumberAxis()); } /** * Creates a new combined plot that shares a domain axis among multiple * subplots. * * @param domainAxis the shared axis. */ public CombinedDomainXYPlot(ValueAxis domainAxis) { super(null, // no data in the parent plot domainAxis, null, // no range axis null); // no rendereer this.subplots = new java.util.ArrayList<XYPlot>(); } /** * Returns a string describing the type of plot. * * @return The type of plot. */ @Override public String getPlotType() { return "Combined_Domain_XYPlot"; } /** * Sets the orientation for the plot (also changes the orientation for all * the subplots to match). * * @param orientation the orientation (<code>null</code> not allowed). */ @Override public void setOrientation(PlotOrientation orientation) { super.setOrientation(orientation); for (XYPlot subplot : this.subplots) { subplot.setOrientation(orientation); } } /** * Sets the shadow generator for the plot (and all subplots) and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param generator the new generator (<code>null</code> permitted). */ @Override public void setShadowGenerator(ShadowGenerator generator) { setNotify(false); super.setShadowGenerator(generator); for (XYPlot plot : this.subplots) { plot.setShadowGenerator(generator); } setNotify(true); } /** * Returns a range representing the extent of the data values in this plot * (obtained from the subplots) that will be rendered against the specified * axis. NOTE: This method is intended for internal JFreeChart use, and * is public only so that code in the axis classes can call it. Since * only the domain axis is shared between subplots, the JFreeChart code * will only call this method for the domain values (although this is not * checked/enforced). * * @param axis the axis. * * @return The range (possibly <code>null</code>). */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; if (this.subplots != null) { for (XYPlot subplot : this.subplots) { result = Range.combine(result, subplot.getDataRange(axis)); } } return result; } /** * Returns the gap between subplots, measured in Java2D units. * * @return The gap (in Java2D units). * * @see #setGap(double) */ public double getGap() { return this.gap; } /** * Sets the amount of space between subplots and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param gap the gap between subplots (in Java2D units). * * @see #getGap() */ public void setGap(double gap) { this.gap = gap; fireChangeEvent(); } /** * Adds a subplot (with a default 'weight' of 1) and sends a * {@link PlotChangeEvent} to all registered listeners. * <P> * The domain axis for the subplot will be set to <code>null</code>. You * must ensure that the subplot has a non-null range axis. * * @param subplot the subplot (<code>null</code> not permitted). */ public void add(XYPlot subplot) { // defer argument checking add(subplot, 1); } /** * Adds a subplot with the specified weight and sends a * {@link PlotChangeEvent} to all registered listeners. The weight * determines how much space is allocated to the subplot relative to all * the other subplots. * <P> * The domain axis for the subplot will be set to <code>null</code>. You * must ensure that the subplot has a non-null range axis. * * @param subplot the subplot (<code>null</code> not permitted). * @param weight the weight (must be >= 1). */ public void add(XYPlot subplot, int weight) { ParamChecks.nullNotPermitted(subplot, "subplot"); if (weight <= 0) { throw new IllegalArgumentException("Require weight >= 1."); } // store the plot and its weight subplot.setParent(this); subplot.setWeight(weight); subplot.setInsets(RectangleInsets.ZERO_INSETS, false); subplot.setDomainAxis(null); subplot.addChangeListener(this); this.subplots.add(subplot); ValueAxis axis = getDomainAxis(); if (axis != null) { axis.configure(); } fireChangeEvent(); } /** * Removes a subplot from the combined chart and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param subplot the subplot (<code>null</code> not permitted). */ public void remove(XYPlot subplot) { ParamChecks.nullNotPermitted(subplot, "subplot"); int position = -1; int size = this.subplots.size(); int i = 0; while (position == -1 && i < size) { if (this.subplots.get(i) == subplot) { position = i; } i++; } if (position != -1) { this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); ValueAxis domain = getDomainAxis(); if (domain != null) { domain.configure(); } fireChangeEvent(); } } /** * Returns the list of subplots. The returned list may be empty, but is * never <code>null</code>. * * @return An unmodifiable list of subplots. */ public List<XYPlot> getSubplots() { if (this.subplots != null) { return Collections.unmodifiableList(this.subplots); } else { return Collections.EMPTY_LIST; } } /** * Calculates the axis space required. * * @param g2 the graphics device. * @param plotArea the plot area. * * @return The space. */ @Override protected AxisSpace calculateAxisSpace(Graphics2D g2, Rectangle2D plotArea) { AxisSpace space = new AxisSpace(); PlotOrientation orientation = getOrientation(); // work out the space required by the domain axis... AxisSpace fixed = getFixedDomainAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.HORIZONTAL) { space.setLeft(fixed.getLeft()); space.setRight(fixed.getRight()); } else if (orientation == PlotOrientation.VERTICAL) { space.setTop(fixed.getTop()); space.setBottom(fixed.getBottom()); } } else { ValueAxis xAxis = getDomainAxis(); RectangleEdge xEdge = Plot.resolveDomainAxisLocation( getDomainAxisLocation(), orientation); if (xAxis != null) { space = xAxis.reserveSpace(g2, this, plotArea, xEdge, space); } } Rectangle2D adjustedPlotArea = space.shrink(plotArea, null); // work out the maximum height or width of the non-shared axes... int n = this.subplots.size(); int totalWeight = 0; for (XYPlot sub : this.subplots) { totalWeight += sub.getWeight(); } this.subplotAreas = new Rectangle2D[n]; double x = adjustedPlotArea.getX(); double y = adjustedPlotArea.getY(); double usableSize = 0.0; if (orientation == PlotOrientation.HORIZONTAL) { usableSize = adjustedPlotArea.getWidth() - this.gap * (n - 1); } else if (orientation == PlotOrientation.VERTICAL) { usableSize = adjustedPlotArea.getHeight() - this.gap * (n - 1); } for (int i = 0; i < n; i++) { XYPlot plot = this.subplots.get(i); // calculate sub-plot area if (orientation == PlotOrientation.HORIZONTAL) { double w = usableSize * plot.getWeight() / totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, w, adjustedPlotArea.getHeight()); x = x + w + this.gap; } else if (orientation == PlotOrientation.VERTICAL) { double h = usableSize * plot.getWeight() / totalWeight; this.subplotAreas[i] = new Rectangle2D.Double(x, y, adjustedPlotArea.getWidth(), h); y = y + h + this.gap; } AxisSpace subSpace = plot.calculateRangeAxisSpace(g2, this.subplotAreas[i], null); space.ensureAtLeast(subSpace); } return space; } /** * Draws the plot within the specified area on a graphics device. * * @param g2 the graphics device. * @param area the plot area (in Java2D space). * @param anchor an anchor point in Java2D space (<code>null</code> * permitted). * @param parentState the state from the parent plot, if there is one * (<code>null</code> permitted). * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // set up info collection... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); setFixedRangeAxisSpaceForSubplots(null); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); // set the width and height of non-shared axis of all sub-plots setFixedRangeAxisSpaceForSubplots(space); // draw the shared axis ValueAxis axis = getDomainAxis(); RectangleEdge edge = getDomainAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, edge); AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info); if (parentState == null) { parentState = new PlotState(); } parentState.getSharedAxisStates().put(axis, axisState); // draw all the subplots for (int i = 0; i < this.subplots.size(); i++) { XYPlot plot = this.subplots.get(i); PlotRenderingInfo subplotInfo = null; if (info != null) { subplotInfo = new PlotRenderingInfo(info.getOwner()); info.addSubplotInfo(subplotInfo); } plot.draw(g2, this.subplotAreas[i], anchor, parentState, subplotInfo); } if (info != null) { info.setDataArea(dataArea); } } /** * Returns a collection of legend items for the plot. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = getFixedLegendItems(); if (result == null) { result = new ArrayList<LegendItem>(); if (this.subplots != null) { for (XYPlot plot : this.subplots) { List<LegendItem> more = plot.getLegendItems(); result.addAll(more); } } } return result; } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source) { zoomRangeAxes(factor, info, source, false); } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). * @param useAnchor use source point as zoom anchor? */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor) { // delegate 'state' and 'source' argument checks... XYPlot subplot = findSubplot(state, source); if (subplot != null) { subplot.zoomRangeAxes(factor, state, source, useAnchor); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... for (XYPlot subPlot : getSubplots()) { subplot.zoomRangeAxes(factor, state, source, useAnchor); } } } /** * Zooms in on the range axes. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { // delegate 'info' and 'source' argument checks... XYPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomRangeAxes(lowerPercent, upperPercent, info, source); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... for (XYPlot sp : getSubplots()) { sp.zoomRangeAxes(lowerPercent, upperPercent, info, source); } } } /** * Pans the range axis (or axes) of the plot under the mouse pointer by the * specified percentage. * * @param panRange the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. * * @since 1.0.15 */ @Override public void panRangeAxes(double panRange, PlotRenderingInfo info, Point2D source) { // if the isRangePannable flag is set for the combined plot, we should // pan for all the subplots, otherwise just the one under the mouse // pointer List<XYPlot> plotsToPan = new ArrayList<XYPlot>(); if (isRangePannable()) { plotsToPan.addAll(this.subplots); } else { plotsToPan.add(findSubplot(info, source)); } for (XYPlot subplot : plotsToPan) { if (subplot == null) { continue; } if (isRangePannable() || subplot.isRangePannable()) { for (int i = 0; i < subplot.getRangeAxisCount(); i++) { ValueAxis rangeAxis = subplot.getRangeAxis(i); rangeAxis.pan(panRange); } } } } /** * Returns the subplot (if any) that contains the (x, y) point (specified * in Java2D space). * * @param info the chart rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). * * @return A subplot (possibly <code>null</code>). */ public XYPlot findSubplot(PlotRenderingInfo info, Point2D source) { ParamChecks.nullNotPermitted(info, "info"); ParamChecks.nullNotPermitted(source, "source"); XYPlot result = null; int subplotIndex = info.getSubplotIndex(source); if (subplotIndex >= 0) { result = this.subplots.get(subplotIndex); } return result; } /** * Sets the item renderer FOR ALL SUBPLOTS. Registered listeners are * notified that the plot has been modified. * <P> * Note: usually you will want to set the renderer independently for each * subplot, which is NOT what this method does. * * @param renderer the new renderer. */ @Override public void setRenderer(XYItemRenderer renderer) { super.setRenderer(renderer); // not strictly necessary, since the // renderer set for the // parent plot is not used for (XYPlot subplot : this.subplots) { subplot.setRenderer(renderer); } } /** * Sets the fixed range axis space and sends a {@link PlotChangeEvent} to * all registered listeners. * * @param space the space (<code>null</code> permitted). */ @Override public void setFixedRangeAxisSpace(AxisSpace space) { super.setFixedRangeAxisSpace(space); setFixedRangeAxisSpaceForSubplots(space); fireChangeEvent(); } /** * Sets the size (width or height, depending on the orientation of the * plot) for the domain axis of each subplot. * * @param space the space (<code>null</code> permitted). */ protected void setFixedRangeAxisSpaceForSubplots(AxisSpace space) { for (XYPlot subplot : this.subplots) { subplot.setFixedRangeAxisSpace(space, false); } } /** * Handles a 'click' on the plot by updating the anchor values. * * @param x x-coordinate, where the click occured. * @param y y-coordinate, where the click occured. * @param info object containing information about the plot dimensions. */ @Override public void handleClick(int x, int y, PlotRenderingInfo info) { Rectangle2D dataArea = info.getDataArea(); if (dataArea.contains(x, y)) { for (int i = 0; i < this.subplots.size(); i++) { XYPlot subplot = this.subplots.get(i); PlotRenderingInfo subplotInfo = info.getSubplotInfo(i); subplot.handleClick(x, y, subplotInfo); } } } /** * Receives a {@link PlotChangeEvent} and responds by notifying all * listeners. * * @param event the event. */ @Override public void plotChanged(PlotChangeEvent event) { notifyListeners(event); } /** * Tests this plot for equality with another object. * * @param obj the other object. * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CombinedDomainXYPlot)) { return false; } CombinedDomainXYPlot that = (CombinedDomainXYPlot) obj; if (this.gap != that.gap) { return false; } if (!ObjectUtilities.equal(this.subplots, that.subplots)) { return false; } return super.equals(obj); } /** * Returns a clone of the annotation. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { CombinedDomainXYPlot result = (CombinedDomainXYPlot) super.clone(); result.subplots = (List<XYPlot>) ObjectUtilities.deepClone(this.subplots); for (XYPlot p : result.subplots) { p.setParent(result); } // after setting up all the subplots, the shared domain axis may need // reconfiguring ValueAxis domainAxis = result.getDomainAxis(); if (domainAxis != null) { domainAxis.configure(); } return result; } }
26,825
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SpiderWebPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/SpiderWebPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * SpiderWebPlot.java * ------------------ * (C) Copyright 2005-2014, by Heaps of Flavour Pty Ltd and Contributors. * * Company Info: http://www.i4-talent.com * * Original Author: Don Elliott; * Contributor(s): David Gilbert (for Object Refinery Limited); * Nina Jeliazkova; * * Changes * ------- * 28-Jan-2005 : First cut - missing a few features - still to do: * - needs tooltips/URL/label generator functions * - ticks on axes / background grid? * 31-Jan-2005 : Renamed SpiderWebPlot, added label generator support, and * reformatted for consistency with other source files in * JFreeChart (DG); * 20-Apr-2005 : Renamed CategoryLabelGenerator * --> CategoryItemLabelGenerator (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 10-Jun-2005 : Added equals() method and fixed serialization (DG); * 16-Jun-2005 : Added default constructor and get/setDataset() * methods (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 05-Apr-2006 : Fixed bug preventing the display of zero values - see patch * 1462727 (DG); * 05-Apr-2006 : Added support for mouse clicks, tool tips and URLs - see patch * 1463455 (DG); * 01-Jun-2006 : Fix bug 1493199, NullPointerException when drawing with null * info (DG); * 05-Feb-2007 : Added attributes for axis stroke and paint, while fixing * bug 1651277, and implemented clone() properly (DG); * 06-Feb-2007 : Changed getPlotValue() to protected, as suggested in bug * 1605202 (DG); * 05-Mar-2007 : Restore clip region correctly (see bug 1667750) (DG); * 18-May-2007 : Set dataset for LegendItem (DG); * 02-Jun-2008 : Fixed bug with chart entities using TableOrder.BY_COLUMN (DG); * 02-Jun-2008 : Fixed bug with null dataset (DG); * 01-Jun-2009 : Set series key in getLegendItems() (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Polygon; import java.awt.Rectangle; import java.awt.Shape; import java.awt.Stroke; import java.awt.font.FontRenderContext; import java.awt.font.LineMetrics; import java.awt.geom.Arc2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.jfree.chart.LegendItem; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintList; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.Rotation; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.StrokeList; import org.jfree.chart.util.TableOrder; import org.jfree.chart.entity.CategoryItemEntity; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.labels.CategoryItemLabelGenerator; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; /** * A plot that displays data from a {@link CategoryDataset} in the form of a * "spider web". Multiple series can be plotted on the same axis to allow * easy comparison. This plot doesn't support negative values at present. */ public class SpiderWebPlot extends Plot implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -5376340422031599463L; /** The default head radius percent (currently 1%). */ public static final double DEFAULT_HEAD = 0.01; /** The default axis label gap (currently 10%). */ public static final double DEFAULT_AXIS_LABEL_GAP = 0.10; /** The default interior gap. */ public static final double DEFAULT_INTERIOR_GAP = 0.25; /** The maximum interior gap (currently 40%). */ public static final double MAX_INTERIOR_GAP = 0.40; /** The default starting angle for the radar chart axes. */ public static final double DEFAULT_START_ANGLE = 90.0; /** The default series label font. */ public static final Font DEFAULT_LABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); /** The default series label paint. */ public static final Paint DEFAULT_LABEL_PAINT = Color.BLACK; /** The default series label background paint. */ public static final Paint DEFAULT_LABEL_BACKGROUND_PAINT = new Color(255, 255, 192); /** The default series label outline paint. */ public static final Paint DEFAULT_LABEL_OUTLINE_PAINT = Color.BLACK; /** The default series label outline stroke. */ public static final Stroke DEFAULT_LABEL_OUTLINE_STROKE = new BasicStroke(0.5f); /** The default series label shadow paint. */ public static final Paint DEFAULT_LABEL_SHADOW_PAINT = Color.LIGHT_GRAY; /** * The default maximum value plotted - forces the plot to evaluate * the maximum from the data passed in */ public static final double DEFAULT_MAX_VALUE = -1.0; /** The head radius as a percentage of the available drawing area. */ protected double headPercent; /** The space left around the outside of the plot as a percentage. */ private double interiorGap; /** The gap between the labels and the axes as a %age of the radius. */ private double axisLabelGap; /** * The paint used to draw the axis lines. * * @since 1.0.4 */ private transient Paint axisLinePaint; /** * The stroke used to draw the axis lines. * * @since 1.0.4 */ private transient Stroke axisLineStroke; /** The dataset. */ private CategoryDataset dataset; /** The maximum value we are plotting against on each category axis */ private double maxValue; /** * The data extract order (BY_ROW or BY_COLUMN). This denotes whether * the data series are stored in rows (in which case the category names are * derived from the column keys) or in columns (in which case the category * names are derived from the row keys). */ private TableOrder dataExtractOrder; /** The starting angle. */ private double startAngle; /** The direction for drawing the radar axis & plots. */ private Rotation direction; /** The legend item shape. */ private transient Shape legendItemShape; /** The paint for ALL series (overrides list). */ private transient Paint seriesPaint; /** The series paint list. */ private PaintList seriesPaintList; /** The base series paint (fallback). */ private transient Paint baseSeriesPaint; /** The outline paint for ALL series (overrides list). */ private transient Paint seriesOutlinePaint; /** The series outline paint list. */ private PaintList seriesOutlinePaintList; /** The base series outline paint (fallback). */ private transient Paint baseSeriesOutlinePaint; /** The outline stroke for ALL series (overrides list). */ private transient Stroke seriesOutlineStroke; /** The series outline stroke list. */ private StrokeList seriesOutlineStrokeList; /** The base series outline stroke (fallback). */ private transient Stroke baseSeriesOutlineStroke; /** The font used to display the category labels. */ private Font labelFont; /** The color used to draw the category labels. */ private transient Paint labelPaint; /** The label generator. */ private CategoryItemLabelGenerator labelGenerator; /** controls if the web polygons are filled or not */ private boolean webFilled = true; /** A tooltip generator for the plot (<code>null</code> permitted). */ private CategoryToolTipGenerator toolTipGenerator; /** A URL generator for the plot (<code>null</code> permitted). */ private CategoryURLGenerator urlGenerator; /** * Creates a default plot with no dataset. */ public SpiderWebPlot() { this(null); } /** * Creates a new spider web plot with the given dataset, with each row * representing a series. * * @param dataset the dataset (<code>null</code> permitted). */ public SpiderWebPlot(CategoryDataset dataset) { this(dataset, TableOrder.BY_ROW); } /** * Creates a new spider web plot with the given dataset. * * @param dataset the dataset. * @param extract controls how data is extracted ({@link TableOrder#BY_ROW} * or {@link TableOrder#BY_COLUMN}). */ public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) { super(); if (extract == null) { throw new IllegalArgumentException("Null 'extract' argument."); } this.dataset = dataset; if (dataset != null) { dataset.addChangeListener(this); } this.dataExtractOrder = extract; this.headPercent = DEFAULT_HEAD; this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP; this.axisLinePaint = Color.BLACK; this.axisLineStroke = new BasicStroke(1.0f); this.interiorGap = DEFAULT_INTERIOR_GAP; this.startAngle = DEFAULT_START_ANGLE; this.direction = Rotation.CLOCKWISE; this.maxValue = DEFAULT_MAX_VALUE; this.seriesPaint = null; this.seriesPaintList = new PaintList(); this.baseSeriesPaint = null; this.seriesOutlinePaint = null; this.seriesOutlinePaintList = new PaintList(); this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT; this.seriesOutlineStroke = null; this.seriesOutlineStrokeList = new StrokeList(); this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE; this.labelFont = DEFAULT_LABEL_FONT; this.labelPaint = DEFAULT_LABEL_PAINT; this.labelGenerator = new StandardCategoryItemLabelGenerator(); this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE; } /** * Returns a short string describing the type of plot. * * @return The plot type. */ @Override public String getPlotType() { // return localizationResources.getString("Radar_Plot"); return ("Spider Web Plot"); } /** * Returns the dataset. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(CategoryDataset) */ public CategoryDataset getDataset() { return this.dataset; } /** * Sets the dataset used by the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() */ public void setDataset(CategoryDataset dataset) { // if there is an existing dataset, remove the plot from the list of // change listeners... if (this.dataset != null) { this.dataset.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self to trigger plot change event datasetChanged(new DatasetChangeEvent(this, dataset)); } /** * Method to determine if the web chart is to be filled. * * @return A boolean. * * @see #setWebFilled(boolean) */ public boolean isWebFilled() { return this.webFilled; } /** * Sets the webFilled flag and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param flag the flag. * * @see #isWebFilled() */ public void setWebFilled(boolean flag) { this.webFilled = flag; fireChangeEvent(); } /** * Returns the data extract order (by row or by column). * * @return The data extract order (never <code>null</code>). * * @see #setDataExtractOrder(TableOrder) */ public TableOrder getDataExtractOrder() { return this.dataExtractOrder; } /** * Sets the data extract order (by row or by column) and sends a * {@link PlotChangeEvent}to all registered listeners. * * @param order the order (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>order</code> is * <code>null</code>. * * @see #getDataExtractOrder() */ public void setDataExtractOrder(TableOrder order) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument"); } this.dataExtractOrder = order; fireChangeEvent(); } /** * Returns the head percent. * * @return The head percent. * * @see #setHeadPercent(double) */ public double getHeadPercent() { return this.headPercent; } /** * Sets the head percent and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param percent the percent. * * @see #getHeadPercent() */ public void setHeadPercent(double percent) { this.headPercent = percent; fireChangeEvent(); } /** * Returns the start angle for the first radar axis. * <BR> * This is measured in degrees starting from 3 o'clock (Java Arc2D default) * and measuring anti-clockwise. * * @return The start angle. * * @see #setStartAngle(double) */ public double getStartAngle() { return this.startAngle; } /** * Sets the starting angle and sends a {@link PlotChangeEvent} to all * registered listeners. * <P> * The initial default value is 90 degrees, which corresponds to 12 o'clock. * A value of zero corresponds to 3 o'clock... this is the encoding used by * Java's Arc2D class. * * @param angle the angle (in degrees). * * @see #getStartAngle() */ public void setStartAngle(double angle) { this.startAngle = angle; fireChangeEvent(); } /** * Returns the maximum value any category axis can take. * * @return The maximum value. * * @see #setMaxValue(double) */ public double getMaxValue() { return this.maxValue; } /** * Sets the maximum value any category axis can take and sends * a {@link PlotChangeEvent} to all registered listeners. * * @param value the maximum value. * * @see #getMaxValue() */ public void setMaxValue(double value) { this.maxValue = value; fireChangeEvent(); } /** * Returns the direction in which the radar axes are drawn * (clockwise or anti-clockwise). * * @return The direction (never <code>null</code>). * * @see #setDirection(Rotation) */ public Rotation getDirection() { return this.direction; } /** * Sets the direction in which the radar axes are drawn and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param direction the direction (<code>null</code> not permitted). * * @see #getDirection() */ public void setDirection(Rotation direction) { if (direction == null) { throw new IllegalArgumentException("Null 'direction' argument."); } this.direction = direction; fireChangeEvent(); } /** * Returns the interior gap, measured as a percentage of the available * drawing space. * * @return The gap (as a percentage of the available drawing space). * * @see #setInteriorGap(double) */ public double getInteriorGap() { return this.interiorGap; } /** * Sets the interior gap and sends a {@link PlotChangeEvent} to all * registered listeners. This controls the space between the edges of the * plot and the plot area itself (the region where the axis labels appear). * * @param percent the gap (as a percentage of the available drawing space). * * @see #getInteriorGap() */ public void setInteriorGap(double percent) { if ((percent < 0.0) || (percent > MAX_INTERIOR_GAP)) { throw new IllegalArgumentException( "Percentage outside valid range."); } if (this.interiorGap != percent) { this.interiorGap = percent; fireChangeEvent(); } } /** * Returns the axis label gap. * * @return The axis label gap. * * @see #setAxisLabelGap(double) */ public double getAxisLabelGap() { return this.axisLabelGap; } /** * Sets the axis label gap and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param gap the gap. * * @see #getAxisLabelGap() */ public void setAxisLabelGap(double gap) { this.axisLabelGap = gap; fireChangeEvent(); } /** * Returns the paint used to draw the axis lines. * * @return The paint used to draw the axis lines (never <code>null</code>). * * @see #setAxisLinePaint(Paint) * @see #getAxisLineStroke() * @since 1.0.4 */ public Paint getAxisLinePaint() { return this.axisLinePaint; } /** * Sets the paint used to draw the axis lines and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getAxisLinePaint() * @since 1.0.4 */ public void setAxisLinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.axisLinePaint = paint; fireChangeEvent(); } /** * Returns the stroke used to draw the axis lines. * * @return The stroke used to draw the axis lines (never <code>null</code>). * * @see #setAxisLineStroke(Stroke) * @see #getAxisLinePaint() * @since 1.0.4 */ public Stroke getAxisLineStroke() { return this.axisLineStroke; } /** * Sets the stroke used to draw the axis lines and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getAxisLineStroke() * @since 1.0.4 */ public void setAxisLineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.axisLineStroke = stroke; fireChangeEvent(); } //// SERIES PAINT ///////////////////////// /** * Returns the paint for ALL series in the plot. * * @return The paint (possibly <code>null</code>). * * @see #setSeriesPaint(Paint) */ public Paint getSeriesPaint() { return this.seriesPaint; } /** * Sets the paint for ALL series in the plot. If this is set to</code> null * </code>, then a list of paints is used instead (to allow different colors * to be used for each series of the radar group). * * @param paint the paint (<code>null</code> permitted). * * @see #getSeriesPaint() */ public void setSeriesPaint(Paint paint) { this.seriesPaint = paint; fireChangeEvent(); } /** * Returns the paint for the specified series. * * @param series the series index (zero-based). * * @return The paint (never <code>null</code>). * * @see #setSeriesPaint(int, Paint) */ public Paint getSeriesPaint(int series) { // return the override, if there is one... if (this.seriesPaint != null) { return this.seriesPaint; } // otherwise look up the paint list Paint result = this.seriesPaintList.getPaint(series); if (result == null) { DrawingSupplier supplier = getDrawingSupplier(); if (supplier != null) { Paint p = supplier.getNextPaint(); this.seriesPaintList.setPaint(series, p); result = p; } else { result = this.baseSeriesPaint; } } return result; } /** * Sets the paint used to fill a series of the radar and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param paint the paint (<code>null</code> permitted). * * @see #getSeriesPaint(int) */ public void setSeriesPaint(int series, Paint paint) { this.seriesPaintList.setPaint(series, paint); fireChangeEvent(); } /** * Returns the base series paint. This is used when no other paint is * available. * * @return The paint (never <code>null</code>). * * @see #setBaseSeriesPaint(Paint) */ public Paint getBaseSeriesPaint() { return this.baseSeriesPaint; } /** * Sets the base series paint. * * @param paint the paint (<code>null</code> not permitted). * * @see #getBaseSeriesPaint() */ public void setBaseSeriesPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.baseSeriesPaint = paint; fireChangeEvent(); } //// SERIES OUTLINE PAINT //////////////////////////// /** * Returns the outline paint for ALL series in the plot. * * @return The paint (possibly <code>null</code>). */ public Paint getSeriesOutlinePaint() { return this.seriesOutlinePaint; } /** * Sets the outline paint for ALL series in the plot. If this is set to * </code> null</code>, then a list of paints is used instead (to allow * different colors to be used for each series). * * @param paint the paint (<code>null</code> permitted). */ public void setSeriesOutlinePaint(Paint paint) { this.seriesOutlinePaint = paint; fireChangeEvent(); } /** * Returns the paint for the specified series. * * @param series the series index (zero-based). * * @return The paint (never <code>null</code>). */ public Paint getSeriesOutlinePaint(int series) { // return the override, if there is one... if (this.seriesOutlinePaint != null) { return this.seriesOutlinePaint; } // otherwise look up the paint list Paint result = this.seriesOutlinePaintList.getPaint(series); if (result == null) { result = this.baseSeriesOutlinePaint; } return result; } /** * Sets the paint used to fill a series of the radar and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param paint the paint (<code>null</code> permitted). */ public void setSeriesOutlinePaint(int series, Paint paint) { this.seriesOutlinePaintList.setPaint(series, paint); fireChangeEvent(); } /** * Returns the base series paint. This is used when no other paint is * available. * * @return The paint (never <code>null</code>). */ public Paint getBaseSeriesOutlinePaint() { return this.baseSeriesOutlinePaint; } /** * Sets the base series paint. * * @param paint the paint (<code>null</code> not permitted). */ public void setBaseSeriesOutlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.baseSeriesOutlinePaint = paint; fireChangeEvent(); } //// SERIES OUTLINE STROKE ///////////////////// /** * Returns the outline stroke for ALL series in the plot. * * @return The stroke (possibly <code>null</code>). */ public Stroke getSeriesOutlineStroke() { return this.seriesOutlineStroke; } /** * Sets the outline stroke for ALL series in the plot. If this is set to * </code> null</code>, then a list of paints is used instead (to allow * different colors to be used for each series). * * @param stroke the stroke (<code>null</code> permitted). */ public void setSeriesOutlineStroke(Stroke stroke) { this.seriesOutlineStroke = stroke; fireChangeEvent(); } /** * Returns the stroke for the specified series. * * @param series the series index (zero-based). * * @return The stroke (never <code>null</code>). */ public Stroke getSeriesOutlineStroke(int series) { // return the override, if there is one... if (this.seriesOutlineStroke != null) { return this.seriesOutlineStroke; } // otherwise look up the paint list Stroke result = this.seriesOutlineStrokeList.getStroke(series); if (result == null) { result = this.baseSeriesOutlineStroke; } return result; } /** * Sets the stroke used to fill a series of the radar and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param series the series index (zero-based). * @param stroke the stroke (<code>null</code> permitted). */ public void setSeriesOutlineStroke(int series, Stroke stroke) { this.seriesOutlineStrokeList.setStroke(series, stroke); fireChangeEvent(); } /** * Returns the base series stroke. This is used when no other stroke is * available. * * @return The stroke (never <code>null</code>). */ public Stroke getBaseSeriesOutlineStroke() { return this.baseSeriesOutlineStroke; } /** * Sets the base series stroke. * * @param stroke the stroke (<code>null</code> not permitted). */ public void setBaseSeriesOutlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.baseSeriesOutlineStroke = stroke; fireChangeEvent(); } /** * Returns the shape used for legend items. * * @return The shape (never <code>null</code>). * * @see #setLegendItemShape(Shape) */ public Shape getLegendItemShape() { return this.legendItemShape; } /** * Sets the shape used for legend items and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param shape the shape (<code>null</code> not permitted). * * @see #getLegendItemShape() */ public void setLegendItemShape(Shape shape) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } this.legendItemShape = shape; fireChangeEvent(); } /** * Returns the series label font. * * @return The font (never <code>null</code>). * * @see #setLabelFont(Font) */ public Font getLabelFont() { return this.labelFont; } /** * Sets the series label font and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getLabelFont() */ public void setLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.labelFont = font; fireChangeEvent(); } /** * Returns the series label paint. * * @return The paint (never <code>null</code>). * * @see #setLabelPaint(Paint) */ public Paint getLabelPaint() { return this.labelPaint; } /** * Sets the series label paint and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getLabelPaint() */ public void setLabelPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.labelPaint = paint; fireChangeEvent(); } /** * Returns the label generator. * * @return The label generator (never <code>null</code>). * * @see #setLabelGenerator(CategoryItemLabelGenerator) */ public CategoryItemLabelGenerator getLabelGenerator() { return this.labelGenerator; } /** * Sets the label generator and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param generator the generator (<code>null</code> not permitted). * * @see #getLabelGenerator() */ public void setLabelGenerator(CategoryItemLabelGenerator generator) { if (generator == null) { throw new IllegalArgumentException("Null 'generator' argument."); } this.labelGenerator = generator; } /** * Returns the tool tip generator for the plot. * * @return The tool tip generator (possibly <code>null</code>). * * @see #setToolTipGenerator(CategoryToolTipGenerator) * * @since 1.0.2 */ public CategoryToolTipGenerator getToolTipGenerator() { return this.toolTipGenerator; } /** * Sets the tool tip generator for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @see #getToolTipGenerator() * * @since 1.0.2 */ public void setToolTipGenerator(CategoryToolTipGenerator generator) { this.toolTipGenerator = generator; fireChangeEvent(); } /** * Returns the URL generator for the plot. * * @return The URL generator (possibly <code>null</code>). * * @see #setURLGenerator(CategoryURLGenerator) * * @since 1.0.2 */ public CategoryURLGenerator getURLGenerator() { return this.urlGenerator; } /** * Sets the URL generator for the plot and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param generator the generator (<code>null</code> permitted). * * @see #getURLGenerator() * * @since 1.0.2 */ public void setURLGenerator(CategoryURLGenerator generator) { this.urlGenerator = generator; fireChangeEvent(); } /** * Returns a collection of legend items for the spider web chart. * * @return The legend items (never <code>null</code>). */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = new ArrayList<LegendItem>(); if (getDataset() == null) { return result; } // TODO : support for fixed legend items List<Comparable> keys = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { keys = this.dataset.getRowKeys(); } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) { keys = this.dataset.getColumnKeys(); } if (keys == null) { return result; } int series = 0; Shape shape = getLegendItemShape(); for (Comparable key : keys) { String label = key.toString(); String description = label; Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke stroke = getSeriesOutlineStroke(series); LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint); item.setDataset(getDataset()); item.setSeriesKey(key); item.setSeriesIndex(series); result.add(item); series++; } return result; } /** * Returns a cartesian point from a polar angle, length and bounding box * * @param bounds the area inside which the point needs to be. * @param angle the polar angle, in degrees. * @param length the relative length. Given in percent of maximum extend. * * @return The cartesian point. */ protected Point2D getWebPoint(Rectangle2D bounds, double angle, double length) { double angrad = Math.toRadians(angle); double x = Math.cos(angrad) * length * bounds.getWidth() / 2; double y = -Math.sin(angrad) * length * bounds.getHeight() / 2; return new Point2D.Double(bounds.getX() + x + bounds.getWidth() / 2, bounds.getY() + y + bounds.getHeight() / 2); } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); if (info != null) { info.setPlotArea(area); info.setDataArea(area); } drawBackground(g2, area); drawOutline(g2, area); Shape savedClip = g2.getClip(); g2.clip(area); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); if (!DatasetUtilities.isEmptyOrNull(this.dataset)) { int seriesCount, catCount; if (this.dataExtractOrder == TableOrder.BY_ROW) { seriesCount = this.dataset.getRowCount(); catCount = this.dataset.getColumnCount(); } else { seriesCount = this.dataset.getColumnCount(); catCount = this.dataset.getRowCount(); } // ensure we have a maximum value to use on the axes if (this.maxValue == DEFAULT_MAX_VALUE) { calculateMaxValue(seriesCount, catCount); } // Next, setup the plot area // adjust the plot area by the interior spacing value double gapHorizontal = area.getWidth() * getInteriorGap(); double gapVertical = area.getHeight() * getInteriorGap(); double X = area.getX() + gapHorizontal / 2; double Y = area.getY() + gapVertical / 2; double W = area.getWidth() - gapHorizontal; double H = area.getHeight() - gapVertical; double headW = area.getWidth() * this.headPercent; double headH = area.getHeight() * this.headPercent; // make the chart area a square double min = Math.min(W, H) / 2; X = (X + X + W) / 2 - min; Y = (Y + Y + H) / 2 - min; W = 2 * min; H = 2 * min; Point2D centre = new Point2D.Double(X + W / 2, Y + H / 2); Rectangle2D radarArea = new Rectangle2D.Double(X, Y, W, H); // draw the axis and category label for (int cat = 0; cat < catCount; cat++) { double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); Point2D endPoint = getWebPoint(radarArea, angle, 1); // 1 = end of axis Line2D line = new Line2D.Double(centre, endPoint); g2.setPaint(this.axisLinePaint); g2.setStroke(this.axisLineStroke); g2.draw(line); drawLabel(g2, radarArea, 0.0, cat, angle, 360.0 / catCount); } // Now actually plot each of the series polygons.. for (int series = 0; series < seriesCount; series++) { drawRadarPoly(g2, radarArea, centre, info, series, catCount, headH, headW); } } else { drawNoDataMessage(g2, area); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, area); } /** * loop through each of the series to get the maximum value * on each category axis * * @param seriesCount the number of series * @param catCount the number of categories */ private void calculateMaxValue(int seriesCount, int catCount) { double v; Number nV; for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) { for (int catIndex = 0; catIndex < catCount; catIndex++) { nV = getPlotValue(seriesIndex, catIndex); if (nV != null) { v = nV.doubleValue(); if (v > this.maxValue) { this.maxValue = v; } } } } } /** * Draws a radar plot polygon. * * @param g2 the graphics device. * @param plotArea the area we are plotting in (already adjusted). * @param centre the centre point of the radar axes * @param info chart rendering info. * @param series the series within the dataset we are plotting * @param catCount the number of categories per radar plot * @param headH the data point height * @param headW the data point width */ protected void drawRadarPoly(Graphics2D g2, Rectangle2D plotArea, Point2D centre, PlotRenderingInfo info, int series, int catCount, double headH, double headW) { Polygon polygon = new Polygon(); EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } // plot the data... for (int cat = 0; cat < catCount; cat++) { Number dataValue = getPlotValue(series, cat); if (dataValue != null) { double value = dataValue.doubleValue(); if (value >= 0) { // draw the polygon series... // Finds our starting angle from the centre for this axis double angle = getStartAngle() + (getDirection().getFactor() * cat * 360 / catCount); // The following angle calc will ensure there isn't a top // vertical axis - this may be useful if you don't want any // given criteria to 'appear' move important than the // others.. // + (getDirection().getFactor() // * (cat + 0.5) * 360 / catCount); // find the point at the appropriate distance end point // along the axis/angle identified above and add it to the // polygon Point2D point = getWebPoint(plotArea, angle, value / this.maxValue); polygon.addPoint((int) point.getX(), (int) point.getY()); // put an elipse at the point being plotted.. Paint paint = getSeriesPaint(series); Paint outlinePaint = getSeriesOutlinePaint(series); Stroke outlineStroke = getSeriesOutlineStroke(series); Ellipse2D head = new Ellipse2D.Double(point.getX() - headW / 2, point.getY() - headH / 2, headW, headH); g2.setPaint(paint); g2.fill(head); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(head); if (entities != null) { int row; int col; if (this.dataExtractOrder == TableOrder.BY_ROW) { row = series; col = cat; } else { row = cat; col = series; } String tip = null; if (this.toolTipGenerator != null) { tip = this.toolTipGenerator.generateToolTip( this.dataset, row, col); } String url = null; if (this.urlGenerator != null) { url = this.urlGenerator.generateURL(this.dataset, row, col); } Shape area = new Rectangle( (int) (point.getX() - headW), (int) (point.getY() - headH), (int) (headW * 2), (int) (headH * 2)); CategoryItemEntity entity = new CategoryItemEntity( area, tip, url, this.dataset, this.dataset.getRowKey(row), this.dataset.getColumnKey(col)); entities.add(entity); } } } } // Plot the polygon Paint paint = getSeriesPaint(series); g2.setPaint(paint); g2.setStroke(getSeriesOutlineStroke(series)); g2.draw(polygon); // Lastly, fill the web polygon if this is required if (this.webFilled) { g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); g2.fill(polygon); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); } } /** * Returns the value to be plotted at the interseries of the * series and the category. This allows us to plot * <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just * reversing the definition of the categories and data series being * plotted. * * @param series the series to be plotted. * @param cat the category within the series to be plotted. * * @return The value to be plotted (possibly <code>null</code>). * * @see #getDataExtractOrder() */ protected Number getPlotValue(int series, int cat) { Number value = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { value = this.dataset.getValue(series, cat); } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) { value = this.dataset.getValue(cat, series); } return value; } /** * Draws the label for one axis. * * @param g2 the graphics device. * @param plotArea the plot area * @param value the value of the label (ignored). * @param cat the category (zero-based index). * @param startAngle the starting angle. * @param extent the extent of the arc. */ protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value, int cat, double startAngle, double extent) { FontRenderContext frc = g2.getFontRenderContext(); String label = null; if (this.dataExtractOrder == TableOrder.BY_ROW) { // if series are in rows, then the categories are the column keys label = this.labelGenerator.generateColumnLabel(this.dataset, cat); } else { // if series are in columns, then the categories are the row keys label = this.labelGenerator.generateRowLabel(this.dataset, cat); } Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc); LineMetrics lm = getLabelFont().getLineMetrics(label, frc); double ascent = lm.getAscent(); Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, plotArea, startAngle); Composite saveComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.setPaint(getLabelPaint()); g2.setFont(getLabelFont()); g2.drawString(label, (float) labelLocation.getX(), (float) labelLocation.getY()); g2.setComposite(saveComposite); } /** * Returns the location for a label * * @param labelBounds the label bounds. * @param ascent the ascent (height of font). * @param plotArea the plot area * @param startAngle the start angle for the pie series. * * @return The location for a label. */ protected Point2D calculateLabelLocation(Rectangle2D labelBounds, double ascent, Rectangle2D plotArea, double startAngle) { Arc2D arc1 = new Arc2D.Double(plotArea, startAngle, 0, Arc2D.OPEN); Point2D point1 = arc1.getEndPoint(); double deltaX = -(point1.getX() - plotArea.getCenterX()) * this.axisLabelGap; double deltaY = -(point1.getY() - plotArea.getCenterY()) * this.axisLabelGap; double labelX = point1.getX() - deltaX; double labelY = point1.getY() - deltaY; if (labelX < plotArea.getCenterX()) { labelX -= labelBounds.getWidth(); } if (labelX == plotArea.getCenterX()) { labelX -= labelBounds.getWidth() / 2; } if (labelY > plotArea.getCenterY()) { labelY += ascent; } return new Point2D.Double(labelX, labelY); } /** * Tests this plot for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof SpiderWebPlot)) { return false; } if (!super.equals(obj)) { return false; } SpiderWebPlot that = (SpiderWebPlot) obj; if (!this.dataExtractOrder.equals(that.dataExtractOrder)) { return false; } if (this.headPercent != that.headPercent) { return false; } if (this.interiorGap != that.interiorGap) { return false; } if (this.startAngle != that.startAngle) { return false; } if (!this.direction.equals(that.direction)) { return false; } if (this.maxValue != that.maxValue) { return false; } if (this.webFilled != that.webFilled) { return false; } if (this.axisLabelGap != that.axisLabelGap) { return false; } if (!PaintUtilities.equal(this.axisLinePaint, that.axisLinePaint)) { return false; } if (!this.axisLineStroke.equals(that.axisLineStroke)) { return false; } if (!ShapeUtilities.equal(this.legendItemShape, that.legendItemShape)) { return false; } if (!PaintUtilities.equal(this.seriesPaint, that.seriesPaint)) { return false; } if (!this.seriesPaintList.equals(that.seriesPaintList)) { return false; } if (!PaintUtilities.equal(this.baseSeriesPaint, that.baseSeriesPaint)) { return false; } if (!PaintUtilities.equal(this.seriesOutlinePaint, that.seriesOutlinePaint)) { return false; } if (!this.seriesOutlinePaintList.equals(that.seriesOutlinePaintList)) { return false; } if (!PaintUtilities.equal(this.baseSeriesOutlinePaint, that.baseSeriesOutlinePaint)) { return false; } if (!ObjectUtilities.equal(this.seriesOutlineStroke, that.seriesOutlineStroke)) { return false; } if (!this.seriesOutlineStrokeList.equals( that.seriesOutlineStrokeList)) { return false; } if (!this.baseSeriesOutlineStroke.equals( that.baseSeriesOutlineStroke)) { return false; } if (!this.labelFont.equals(that.labelFont)) { return false; } if (!PaintUtilities.equal(this.labelPaint, that.labelPaint)) { return false; } if (!this.labelGenerator.equals(that.labelGenerator)) { return false; } if (!ObjectUtilities.equal(this.toolTipGenerator, that.toolTipGenerator)) { return false; } if (!ObjectUtilities.equal(this.urlGenerator, that.urlGenerator)) { return false; } return true; } /** * Returns a clone of this plot. * * @return A clone of this plot. * * @throws CloneNotSupportedException if the plot cannot be cloned for * any reason. */ @Override public Object clone() throws CloneNotSupportedException { SpiderWebPlot clone = (SpiderWebPlot) super.clone(); clone.legendItemShape = ShapeUtilities.clone(this.legendItemShape); clone.seriesPaintList = (PaintList) this.seriesPaintList.clone(); clone.seriesOutlinePaintList = (PaintList) this.seriesOutlinePaintList.clone(); clone.seriesOutlineStrokeList = (StrokeList) this.seriesOutlineStrokeList.clone(); return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeShape(this.legendItemShape, stream); SerialUtilities.writePaint(this.seriesPaint, stream); SerialUtilities.writePaint(this.baseSeriesPaint, stream); SerialUtilities.writePaint(this.seriesOutlinePaint, stream); SerialUtilities.writePaint(this.baseSeriesOutlinePaint, stream); SerialUtilities.writeStroke(this.seriesOutlineStroke, stream); SerialUtilities.writeStroke(this.baseSeriesOutlineStroke, stream); SerialUtilities.writePaint(this.labelPaint, stream); SerialUtilities.writePaint(this.axisLinePaint, stream); SerialUtilities.writeStroke(this.axisLineStroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.legendItemShape = SerialUtilities.readShape(stream); this.seriesPaint = SerialUtilities.readPaint(stream); this.baseSeriesPaint = SerialUtilities.readPaint(stream); this.seriesOutlinePaint = SerialUtilities.readPaint(stream); this.baseSeriesOutlinePaint = SerialUtilities.readPaint(stream); this.seriesOutlineStroke = SerialUtilities.readStroke(stream); this.baseSeriesOutlineStroke = SerialUtilities.readStroke(stream); this.labelPaint = SerialUtilities.readPaint(stream); this.axisLinePaint = SerialUtilities.readPaint(stream); this.axisLineStroke = SerialUtilities.readStroke(stream); if (this.dataset != null) { this.dataset.addChangeListener(this); } } }
54,653
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CompassPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CompassPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * CompassPlot.java * ---------------- * (C) Copyright 2002-2014, by the Australian Antarctic Division and * Contributors. * * Original Author: Bryan Scott (for the Australian Antarctic Division); * Contributor(s): David Gilbert (for Object Refinery Limited); * Arnaud Lelievre; * Martin Hoeller; * * Changes: * -------- * 25-Sep-2002 : Version 1, contributed by Bryan Scott (DG); * 23-Jan-2003 : Removed one constructor (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 27-Mar-2003 : Changed MeterDataset to ValueDataset (DG); * 21-Aug-2003 : Implemented Cloneable (DG); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 09-Sep-2003 : Changed Color --> Paint (DG); * 15-Sep-2003 : Added null data value check (bug report 805009) (DG); * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG); * 16-Mar-2004 : Added support for revolutionDistance to enable support for * other units than degrees. * 16-Mar-2004 : Enabled LongNeedle to rotate about center. * 11-Jan-2005 : Removed deprecated code in preparation for 1.0.0 release (DG); * 17-Apr-2005 : Fixed bug in clone() method (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 08-Jun-2005 : Fixed equals() method to handle GradientPaint (DG); * 16-Jun-2005 : Renamed getData() --> getDatasets() and * addData() --> addDataset() (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 20-Mar-2007 : Fixed serialization (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 10-Oct-2011 : localization fix: bug #3353913 (MH); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Polygon; import java.awt.Stroke; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; import java.util.List; import java.util.ResourceBundle; import org.jfree.chart.LegendItem; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.needle.ArrowNeedle; import org.jfree.chart.needle.LineNeedle; import org.jfree.chart.needle.LongNeedle; import org.jfree.chart.needle.MeterNeedle; import org.jfree.chart.needle.MiddlePinNeedle; import org.jfree.chart.needle.PinNeedle; import org.jfree.chart.needle.PlumNeedle; import org.jfree.chart.needle.PointerNeedle; import org.jfree.chart.needle.ShipNeedle; import org.jfree.chart.needle.WindNeedle; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.general.DefaultValueDataset; import org.jfree.data.general.ValueDataset; /** * A specialised plot that draws a compass to indicate a direction based on the * value from a {@link ValueDataset}. */ public class CompassPlot extends Plot implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 6924382802125527395L; /** The default label font. */ public static final Font DEFAULT_LABEL_FONT = new Font("SansSerif", Font.BOLD, 10); /** A constant for the label type. */ public static final int NO_LABELS = 0; /** A constant for the label type. */ public static final int VALUE_LABELS = 1; /** The label type (NO_LABELS, VALUE_LABELS). */ private int labelType; /** The label font. */ private Font labelFont; /** A flag that controls whether or not a border is drawn. */ private boolean drawBorder = false; /** The rose highlight paint. */ private transient Paint roseHighlightPaint = Color.BLACK; /** The rose paint. */ private transient Paint rosePaint = Color.YELLOW; /** The rose center paint. */ private transient Paint roseCenterPaint = Color.WHITE; /** The compass font. */ private Font compassFont = new Font("Arial", Font.PLAIN, 10); /** A working shape. */ private transient Ellipse2D circle1; /** A working shape. */ private transient Ellipse2D circle2; /** A working area. */ private transient Area a1; /** A working area. */ private transient Area a2; /** A working shape. */ private transient Rectangle2D rect1; /** An array of value datasets. */ private ValueDataset[] datasets = new ValueDataset[1]; /** An array of needles. */ private MeterNeedle[] seriesNeedle = new MeterNeedle[1]; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** * The count to complete one revolution. Can be arbitrarily set * For degrees (the default) it is 360, for radians this is 2*Pi, etc */ protected double revolutionDistance = 360; /** * Default constructor. */ public CompassPlot() { this(new DefaultValueDataset()); } /** * Constructs a new compass plot. * * @param dataset the dataset for the plot (<code>null</code> permitted). */ public CompassPlot(ValueDataset dataset) { super(); if (dataset != null) { this.datasets[0] = dataset; dataset.addChangeListener(this); } this.circle1 = new Ellipse2D.Double(); this.circle2 = new Ellipse2D.Double(); this.rect1 = new Rectangle2D.Double(); setSeriesNeedle(0); } /** * Returns the label type. Defined by the constants: {@link #NO_LABELS} * and {@link #VALUE_LABELS}. * * @return The label type. * * @see #setLabelType(int) */ public int getLabelType() { // FIXME: this attribute is never used - deprecate? return this.labelType; } /** * Sets the label type (either {@link #NO_LABELS} or {@link #VALUE_LABELS}. * * @param type the type. * * @see #getLabelType() */ public void setLabelType(int type) { // FIXME: this attribute is never used - deprecate? if ((type != NO_LABELS) && (type != VALUE_LABELS)) { throw new IllegalArgumentException( "MeterPlot.setLabelType(int): unrecognised type."); } if (this.labelType != type) { this.labelType = type; fireChangeEvent(); } } /** * Returns the label font. * * @return The label font. * * @see #setLabelFont(Font) */ public Font getLabelFont() { // FIXME: this attribute is not used - deprecate? return this.labelFont; } /** * Sets the label font and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param font the new label font. * * @see #getLabelFont() */ public void setLabelFont(Font font) { // FIXME: this attribute is not used - deprecate? if (font == null) { throw new IllegalArgumentException("Null 'font' not allowed."); } this.labelFont = font; fireChangeEvent(); } /** * Returns the paint used to fill the outer circle of the compass. * * @return The paint (never <code>null</code>). * * @see #setRosePaint(Paint) */ public Paint getRosePaint() { return this.rosePaint; } /** * Sets the paint used to fill the outer circle of the compass, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRosePaint() */ public void setRosePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.rosePaint = paint; fireChangeEvent(); } /** * Returns the paint used to fill the inner background area of the * compass. * * @return The paint (never <code>null</code>). * * @see #setRoseCenterPaint(Paint) */ public Paint getRoseCenterPaint() { return this.roseCenterPaint; } /** * Sets the paint used to fill the inner background area of the compass, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRoseCenterPaint() */ public void setRoseCenterPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.roseCenterPaint = paint; fireChangeEvent(); } /** * Returns the paint used to draw the circles, symbols and labels on the * compass. * * @return The paint (never <code>null</code>). * * @see #setRoseHighlightPaint(Paint) */ public Paint getRoseHighlightPaint() { return this.roseHighlightPaint; } /** * Sets the paint used to draw the circles, symbols and labels of the * compass, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getRoseHighlightPaint() */ public void setRoseHighlightPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.roseHighlightPaint = paint; fireChangeEvent(); } /** * Returns a flag that controls whether or not a border is drawn. * * @return The flag. * * @see #setDrawBorder(boolean) */ public boolean getDrawBorder() { return this.drawBorder; } /** * Sets a flag that controls whether or not a border is drawn. * * @param status the flag status. * * @see #getDrawBorder() */ public void setDrawBorder(boolean status) { this.drawBorder = status; fireChangeEvent(); } /** * Sets the series paint. * * @param series the series index. * @param paint the paint. * * @see #setSeriesOutlinePaint(int, Paint) */ public void setSeriesPaint(int series, Paint paint) { // super.setSeriesPaint(series, paint); if ((series >= 0) && (series < this.seriesNeedle.length)) { this.seriesNeedle[series].setFillPaint(paint); } } /** * Sets the series outline paint. * * @param series the series index. * @param p the paint. * * @see #setSeriesPaint(int, Paint) */ public void setSeriesOutlinePaint(int series, Paint p) { if ((series >= 0) && (series < this.seriesNeedle.length)) { this.seriesNeedle[series].setOutlinePaint(p); } } /** * Sets the series outline stroke. * * @param series the series index. * @param stroke the stroke. * * @see #setSeriesOutlinePaint(int, Paint) */ public void setSeriesOutlineStroke(int series, Stroke stroke) { if ((series >= 0) && (series < this.seriesNeedle.length)) { this.seriesNeedle[series].setOutlineStroke(stroke); } } /** * Sets the needle type. * * @param type the type. * * @see #setSeriesNeedle(int, int) */ public void setSeriesNeedle(int type) { setSeriesNeedle(0, type); } /** * Sets the needle for a series. The needle type is one of the following: * <ul> * <li>0 = {@link ArrowNeedle};</li> * <li>1 = {@link LineNeedle};</li> * <li>2 = {@link LongNeedle};</li> * <li>3 = {@link PinNeedle};</li> * <li>4 = {@link PlumNeedle};</li> * <li>5 = {@link PointerNeedle};</li> * <li>6 = {@link ShipNeedle};</li> * <li>7 = {@link WindNeedle};</li> * <li>8 = {@link ArrowNeedle};</li> * <li>9 = {@link MiddlePinNeedle};</li> * </ul> * @param index the series index. * @param type the needle type. * * @see #setSeriesNeedle(int) */ public void setSeriesNeedle(int index, int type) { switch (type) { case 0: setSeriesNeedle(index, new ArrowNeedle(true)); setSeriesPaint(index, Color.RED); this.seriesNeedle[index].setHighlightPaint(Color.WHITE); break; case 1: setSeriesNeedle(index, new LineNeedle()); break; case 2: MeterNeedle longNeedle = new LongNeedle(); longNeedle.setRotateY(0.5); setSeriesNeedle(index, longNeedle); break; case 3: setSeriesNeedle(index, new PinNeedle()); break; case 4: setSeriesNeedle(index, new PlumNeedle()); break; case 5: setSeriesNeedle(index, new PointerNeedle()); break; case 6: setSeriesPaint(index, null); setSeriesOutlineStroke(index, new BasicStroke(3)); setSeriesNeedle(index, new ShipNeedle()); break; case 7: setSeriesPaint(index, Color.BLUE); setSeriesNeedle(index, new WindNeedle()); break; case 8: setSeriesNeedle(index, new ArrowNeedle(true)); break; case 9: setSeriesNeedle(index, new MiddlePinNeedle()); break; default: throw new IllegalArgumentException("Unrecognised type."); } } /** * Sets the needle for a series and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the series index. * @param needle the needle. */ public void setSeriesNeedle(int index, MeterNeedle needle) { if ((needle != null) && (index < this.seriesNeedle.length)) { this.seriesNeedle[index] = needle; } fireChangeEvent(); } /** * Returns an array of dataset references for the plot. * * @return The dataset for the plot, cast as a ValueDataset. * * @see #addDataset(ValueDataset) */ public ValueDataset[] getDatasets() { return this.datasets; } /** * Adds a dataset to the compass. * * @param dataset the new dataset (<code>null</code> ignored). * * @see #addDataset(ValueDataset, MeterNeedle) */ public void addDataset(ValueDataset dataset) { addDataset(dataset, null); } /** * Adds a dataset to the compass. * * @param dataset the new dataset (<code>null</code> ignored). * @param needle the needle (<code>null</code> permitted). */ public void addDataset(ValueDataset dataset, MeterNeedle needle) { if (dataset != null) { int i = this.datasets.length + 1; ValueDataset[] t = new ValueDataset[i]; MeterNeedle[] p = new MeterNeedle[i]; i = i - 2; for (; i >= 0; --i) { t[i] = this.datasets[i]; p[i] = this.seriesNeedle[i]; } i = this.datasets.length; t[i] = dataset; p[i] = ((needle != null) ? needle : p[i - 1]); ValueDataset[] a = this.datasets; MeterNeedle[] b = this.seriesNeedle; this.datasets = t; this.seriesNeedle = p; for (--i; i >= 0; --i) { a[i] = null; b[i] = null; } dataset.addChangeListener(this); } } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { int outerRadius = 0; int innerRadius = 0; int x1, y1, x2, y2; double a; if (info != null) { info.setPlotArea(area); } // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(area); // draw the background if (this.drawBorder) { drawBackground(g2, area); } int midX = (int) (area.getWidth() / 2); int midY = (int) (area.getHeight() / 2); int radius = midX; if (midY < midX) { radius = midY; } --radius; int diameter = 2 * radius; midX += (int) area.getMinX(); midY += (int) area.getMinY(); this.circle1.setFrame(midX - radius, midY - radius, diameter, diameter); this.circle2.setFrame( midX - radius + 15, midY - radius + 15, diameter - 30, diameter - 30 ); g2.setPaint(this.rosePaint); this.a1 = new Area(this.circle1); this.a2 = new Area(this.circle2); this.a1.subtract(this.a2); g2.fill(this.a1); g2.setPaint(this.roseCenterPaint); x1 = diameter - 30; g2.fillOval(midX - radius + 15, midY - radius + 15, x1, x1); g2.setPaint(this.roseHighlightPaint); g2.drawOval(midX - radius, midY - radius, diameter, diameter); x1 = diameter - 20; g2.drawOval(midX - radius + 10, midY - radius + 10, x1, x1); x1 = diameter - 30; g2.drawOval(midX - radius + 15, midY - radius + 15, x1, x1); x1 = diameter - 80; g2.drawOval(midX - radius + 40, midY - radius + 40, x1, x1); outerRadius = radius - 20; innerRadius = radius - 32; for (int w = 0; w < 360; w += 15) { a = Math.toRadians(w); x1 = midX - ((int) (Math.sin(a) * innerRadius)); x2 = midX - ((int) (Math.sin(a) * outerRadius)); y1 = midY - ((int) (Math.cos(a) * innerRadius)); y2 = midY - ((int) (Math.cos(a) * outerRadius)); g2.drawLine(x1, y1, x2, y2); } g2.setPaint(this.roseHighlightPaint); innerRadius = radius - 26; outerRadius = 7; for (int w = 45; w < 360; w += 90) { a = Math.toRadians(w); x1 = midX - ((int) (Math.sin(a) * innerRadius)); y1 = midY - ((int) (Math.cos(a) * innerRadius)); g2.fillOval(x1 - outerRadius, y1 - outerRadius, 2 * outerRadius, 2 * outerRadius); } /// Squares for (int w = 0; w < 360; w += 90) { a = Math.toRadians(w); x1 = midX - ((int) (Math.sin(a) * innerRadius)); y1 = midY - ((int) (Math.cos(a) * innerRadius)); Polygon p = new Polygon(); p.addPoint(x1 - outerRadius, y1); p.addPoint(x1, y1 + outerRadius); p.addPoint(x1 + outerRadius, y1); p.addPoint(x1, y1 - outerRadius); g2.fillPolygon(p); } /// Draw N, S, E, W innerRadius = radius - 42; Font f = getCompassFont(radius); g2.setFont(f); g2.drawString(localizationResources.getString("N"), midX - 5, midY - innerRadius + f.getSize()); g2.drawString(localizationResources.getString("S"), midX - 5, midY + innerRadius - 5); g2.drawString(localizationResources.getString("W"), midX - innerRadius + 5, midY + 5); g2.drawString(localizationResources.getString("E"), midX + innerRadius - f.getSize(), midY + 5); // plot the data (unless the dataset is null)... y1 = radius / 2; x1 = radius / 6; Rectangle2D needleArea = new Rectangle2D.Double( (midX - x1), (midY - y1), (2 * x1), (2 * y1) ); int x = this.seriesNeedle.length; int current = 0; double value = 0; int i = (this.datasets.length - 1); for (; i >= 0; --i) { ValueDataset data = this.datasets[i]; if (data != null && data.getValue() != null) { value = (data.getValue().doubleValue()) % this.revolutionDistance; value = value / this.revolutionDistance * 360; current = i % x; this.seriesNeedle[current].draw(g2, needleArea, value); } } if (this.drawBorder) { drawOutline(g2, area); } } /** * Returns a short string describing the type of plot. * * @return A string describing the plot. */ @Override public String getPlotType() { return localizationResources.getString("Compass_Plot"); } /** * Returns the legend items for the plot. For now, no legend is available * - this method returns null. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { return null; } /** * No zooming is implemented for compass plot, so this method is empty. * * @param percent the zoom amount. */ @Override public void zoom(double percent) { // no zooming possible } /** * Returns the font for the compass, adjusted for the size of the plot. * * @param radius the radius. * * @return The font. */ protected Font getCompassFont(int radius) { float fontSize = radius / 10.0f; if (fontSize < 8) { fontSize = 8; } Font newFont = this.compassFont.deriveFont(fontSize); return newFont; } /** * Tests an object for equality with this plot. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof CompassPlot)) { return false; } if (!super.equals(obj)) { return false; } CompassPlot that = (CompassPlot) obj; if (this.labelType != that.labelType) { return false; } if (!ObjectUtilities.equal(this.labelFont, that.labelFont)) { return false; } if (this.drawBorder != that.drawBorder) { return false; } if (!PaintUtilities.equal(this.roseHighlightPaint, that.roseHighlightPaint)) { return false; } if (!PaintUtilities.equal(this.rosePaint, that.rosePaint)) { return false; } if (!PaintUtilities.equal(this.roseCenterPaint, that.roseCenterPaint)) { return false; } if (!ObjectUtilities.equal(this.compassFont, that.compassFont)) { return false; } if (!Arrays.equals(this.seriesNeedle, that.seriesNeedle)) { return false; } if (getRevolutionDistance() != that.getRevolutionDistance()) { return false; } return true; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { CompassPlot clone = (CompassPlot) super.clone(); if (this.circle1 != null) { clone.circle1 = (Ellipse2D) this.circle1.clone(); } if (this.circle2 != null) { clone.circle2 = (Ellipse2D) this.circle2.clone(); } if (this.a1 != null) { clone.a1 = (Area) this.a1.clone(); } if (this.a2 != null) { clone.a2 = (Area) this.a2.clone(); } if (this.rect1 != null) { clone.rect1 = (Rectangle2D) this.rect1.clone(); } clone.datasets = this.datasets.clone(); clone.seriesNeedle = this.seriesNeedle.clone(); // clone share data sets => add the clone as listener to the dataset for (int i = 0; i < this.datasets.length; ++i) { if (clone.datasets[i] != null) { clone.datasets[i].addChangeListener(clone); } } return clone; } /** * Sets the count to complete one revolution. Can be arbitrarily set * For degrees (the default) it is 360, for radians this is 2*Pi, etc * * @param size the count to complete one revolution. * * @see #getRevolutionDistance() */ public void setRevolutionDistance(double size) { if (size > 0) { this.revolutionDistance = size; } } /** * Gets the count to complete one revolution. * * @return The count to complete one revolution. * * @see #setRevolutionDistance(double) */ public double getRevolutionDistance() { return this.revolutionDistance; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.rosePaint, stream); SerialUtilities.writePaint(this.roseCenterPaint, stream); SerialUtilities.writePaint(this.roseHighlightPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.rosePaint = SerialUtilities.readPaint(stream); this.roseCenterPaint = SerialUtilities.readPaint(stream); this.roseHighlightPaint = SerialUtilities.readPaint(stream); } }
28,229
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PiePlot3D.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PiePlot3D.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * PiePlot3D.java * -------------- * (C) Copyright 2000-2012, by Object Refinery and Contributors. * * Original Author: Tomer Peretz; * Contributor(s): Richard Atkinson; * David Gilbert (for Object Refinery Limited); * Xun Kang; * Christian W. Zuckschwerdt; * Arnaud Lelievre; * Dave Crane; * Martin Hoeller; * * Changes * ------- * 21-Jun-2002 : Version 1; * 31-Jul-2002 : Modified to use startAngle and direction, drawing modified so * that charts render with foreground alpha < 1.0 (DG); * 05-Aug-2002 : Small modification to draw method to support URLs for HTML * image maps (RA); * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG); * 18-Oct-2002 : Added drawing bug fix sent in by Xun Kang, and made a couple * of other related fixes (DG); * 30-Oct-2002 : Changed the PieDataset interface. Fixed another drawing * bug (DG); * 12-Nov-2002 : Fixed null pointer exception for zero or negative values (DG); * 07-Mar-2003 : Modified to pass pieIndex on to PieSectionEntity (DG); * 21-Mar-2003 : Added workaround for bug id 620031 (DG); * 26-Mar-2003 : Implemented Serializable (DG); * 30-Jul-2003 : Modified entity constructor (CZ); * 29-Aug-2003 : Small changes for API updates in PiePlot class (DG); * 02-Sep-2003 : Fixed bug where the 'no data' message is not displayed (DG); * 08-Sep-2003 : Added internationalization via use of properties * resourceBundle (RFE 690236) (AL); * 29-Oct-2003 : Added workaround for font alignment in PDF output (DG); * 20-Nov-2003 : Fixed bug 845289 (sides not showing) (DG); * 25-Nov-2003 : Added patch (845095) to fix outline paint issues (DG); * 10-Mar-2004 : Numerous changes to enhance labelling (DG); * 31-Mar-2004 : Adjusted plot area when label generator is null (DG); * 08-Apr-2004 : Added flag to PiePlot class to control the treatment of null * values (DG); * Added pieIndex to PieSectionEntity (DG); * 15-Nov-2004 : Removed creation of default tool tip generator (DG); * 16-Jun-2005 : Added default constructor (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 27-Sep-2006 : Updated draw() method for new lookup methods (DG); * 22-Mar-2007 : Added equals() override (DG); * 18-Jun-2007 : Added handling for simple label option (DG); * 04-Oct-2007 : Added option to darken sides of plot - thanks to Alex Moots * (see patch 1805262) (DG); * 21-Nov-2007 : Changed default depth factor, fixed labelling bugs and added * debug code - see debug flags in PiePlot class (DG); * 20-Mar-2008 : Fixed bug 1920854 - multiple redraws of the section * labels (DG); * 19-May-2009 : Fixed FindBugs warnings, patch by Michal Wozniak (DG); * 10-Jul-2009 : Added drop shaow support (DG); * 10-Oct-2011 : Localization fix: bug #3353913 (MH); * 18-Oct-2011 : Fix tooltip offset with shadow generator (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Polygon; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.PieSectionEntity; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.labels.PieToolTipGenerator; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.general.PieDataset; /** * A plot that displays data in the form of a 3D pie chart, using data from * any class that implements the {@link PieDataset} interface. * <P> * Although this class extends {@link PiePlot}, it does not currently support * exploded sections. */ public class PiePlot3D extends PiePlot implements Serializable { /** For serialization. */ private static final long serialVersionUID = 3408984188945161432L; /** The factor of the depth of the pie from the plot height */ private double depthFactor = 0.12; /** * A flag that controls whether or not the sides of the pie chart * are rendered using a darker colour. * * @since 1.0.7. */ private boolean darkerSides = false; // default preserves previous // behaviour /** * Creates a new instance with no dataset. */ public PiePlot3D() { this(null); } /** * Creates a pie chart with a three dimensional effect using the specified * dataset. * * @param dataset the dataset (<code>null</code> permitted). */ public PiePlot3D(PieDataset dataset) { super(dataset); setCircular(false, false); } /** * Returns the depth factor for the chart. * * @return The depth factor. * * @see #setDepthFactor(double) */ public double getDepthFactor() { return this.depthFactor; } /** * Sets the pie depth as a percentage of the height of the plot area, and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param factor the depth factor (for example, 0.20 is twenty percent). * * @see #getDepthFactor() */ public void setDepthFactor(double factor) { this.depthFactor = factor; fireChangeEvent(); } /** * Returns a flag that controls whether or not the sides of the pie chart * are rendered using a darker colour. This is only applied if the * section colour is an instance of {@link java.awt.Color}. * * @return A boolean. * * @see #setDarkerSides(boolean) * * @since 1.0.7 */ public boolean getDarkerSides() { return this.darkerSides; } /** * Sets a flag that controls whether or not the sides of the pie chart * are rendered using a darker colour, and sends a {@link PlotChangeEvent} * to all registered listeners. This is only applied if the * section colour is an instance of {@link java.awt.Color}. * * @param darker true to darken the sides, false to use the default * behaviour. * * @see #getDarkerSides() * * @since 1.0.7. */ public void setDarkerSides(boolean darker) { this.darkerSides = darker; fireChangeEvent(); } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). This method is called by the * {@link org.jfree.chart.JFreeChart} class, you don't normally need * to call it yourself. * * @param g2 the graphics device. * @param plotArea the area within which the plot should be drawn. * @param anchor the anchor point. * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing * (<code>null</code> permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D plotArea, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust for insets... RectangleInsets insets = getInsets(); insets.trim(plotArea); Rectangle2D originalPlotArea = (Rectangle2D) plotArea.clone(); if (info != null) { info.setPlotArea(plotArea); info.setDataArea(plotArea); } drawBackground(g2, plotArea); Shape savedClip = g2.getClip(); g2.clip(plotArea); Graphics2D savedG2 = g2; BufferedImage dataImage = null; if (getShadowGenerator() != null) { dataImage = new BufferedImage((int) plotArea.getWidth(), (int) plotArea.getHeight(), BufferedImage.TYPE_INT_ARGB); g2 = dataImage.createGraphics(); g2.translate(-plotArea.getX(), -plotArea.getY()); g2.setRenderingHints(savedG2.getRenderingHints()); originalPlotArea = (Rectangle2D) plotArea.clone(); } // adjust the plot area by the interior spacing value double gapPercent = getInteriorGap(); double labelPercent = 0.0; if (getLabelGenerator() != null) { labelPercent = getLabelGap() + getMaximumLabelWidth(); } double gapHorizontal = plotArea.getWidth() * (gapPercent + labelPercent) * 2.0; double gapVertical = plotArea.getHeight() * gapPercent * 2.0; if (DEBUG_DRAW_INTERIOR) { double hGap = plotArea.getWidth() * getInteriorGap(); double vGap = plotArea.getHeight() * getInteriorGap(); double igx1 = plotArea.getX() + hGap; double igx2 = plotArea.getMaxX() - hGap; double igy1 = plotArea.getY() + vGap; double igy2 = plotArea.getMaxY() - vGap; g2.setPaint(Color.LIGHT_GRAY); g2.draw(new Rectangle2D.Double(igx1, igy1, igx2 - igx1, igy2 - igy1)); } double linkX = plotArea.getX() + gapHorizontal / 2; double linkY = plotArea.getY() + gapVertical / 2; double linkW = plotArea.getWidth() - gapHorizontal; double linkH = plotArea.getHeight() - gapVertical; // make the link area a square if the pie chart is to be circular... if (isCircular()) { // is circular? double min = Math.min(linkW, linkH) / 2; linkX = (linkX + linkX + linkW) / 2 - min; linkY = (linkY + linkY + linkH) / 2 - min; linkW = 2 * min; linkH = 2 * min; } PiePlotState state = initialise(g2, plotArea, this, null, info); // the link area defines the dog leg points for the linking lines to // the labels Rectangle2D linkAreaXX = new Rectangle2D.Double(linkX, linkY, linkW, linkH * (1 - this.depthFactor)); state.setLinkArea(linkAreaXX); if (DEBUG_DRAW_LINK_AREA) { g2.setPaint(Color.BLUE); g2.draw(linkAreaXX); g2.setPaint(Color.YELLOW); g2.draw(new Ellipse2D.Double(linkAreaXX.getX(), linkAreaXX.getY(), linkAreaXX.getWidth(), linkAreaXX.getHeight())); } // the explode area defines the max circle/ellipse for the exploded pie // sections. // it is defined by shrinking the linkArea by the linkMargin factor. double hh = linkW * getLabelLinkMargin(); double vv = linkH * getLabelLinkMargin(); Rectangle2D explodeArea = new Rectangle2D.Double(linkX + hh / 2.0, linkY + vv / 2.0, linkW - hh, linkH - vv); state.setExplodedPieArea(explodeArea); // the pie area defines the circle/ellipse for regular pie sections. // it is defined by shrinking the explodeArea by the explodeMargin // factor. double maximumExplodePercent = getMaximumExplodePercent(); double percent = maximumExplodePercent / (1.0 + maximumExplodePercent); double h1 = explodeArea.getWidth() * percent; double v1 = explodeArea.getHeight() * percent; Rectangle2D pieArea = new Rectangle2D.Double(explodeArea.getX() + h1 / 2.0, explodeArea.getY() + v1 / 2.0, explodeArea.getWidth() - h1, explodeArea.getHeight() - v1); // the link area defines the dog-leg point for the linking lines to // the labels int depth = (int) (pieArea.getHeight() * this.depthFactor); Rectangle2D linkArea = new Rectangle2D.Double(linkX, linkY, linkW, linkH - depth); state.setLinkArea(linkArea); state.setPieArea(pieArea); state.setPieCenterX(pieArea.getCenterX()); state.setPieCenterY(pieArea.getCenterY() - depth / 2.0); state.setPieWRadius(pieArea.getWidth() / 2.0); state.setPieHRadius((pieArea.getHeight() - depth) / 2.0); // get the data source - return if null; PieDataset dataset = getDataset(); if (DatasetUtilities.isEmptyOrNull(getDataset())) { drawNoDataMessage(g2, plotArea); g2.setClip(savedClip); drawOutline(g2, plotArea); return; } // if too any elements if (dataset.getKeys().size() > plotArea.getWidth()) { String text = localizationResources.getString("Too_many_elements"); Font sfont = new Font("dialog", Font.BOLD, 10); g2.setFont(sfont); FontMetrics fm = g2.getFontMetrics(sfont); int stringWidth = fm.stringWidth(text); g2.drawString(text, (int) (plotArea.getX() + (plotArea.getWidth() - stringWidth) / 2), (int) (plotArea.getY() + (plotArea.getHeight() / 2))); return; } // if we are drawing a perfect circle, we need to readjust the top left // coordinates of the drawing area for the arcs to arrive at this // effect. if (isCircular()) { double min = Math.min(plotArea.getWidth(), plotArea.getHeight()) / 2; plotArea = new Rectangle2D.Double(plotArea.getCenterX() - min, plotArea.getCenterY() - min, 2 * min, 2 * min); } // get a list of keys... List<Comparable> sectionKeys = dataset.getKeys(); if (sectionKeys.isEmpty()) { return; } // establish the coordinates of the top left corner of the drawing area double arcX = pieArea.getX(); double arcY = pieArea.getY(); //g2.clip(clipArea); Composite originalComposite = g2.getComposite(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); double totalValue = DatasetUtilities.calculatePieDatasetTotal(dataset); double runningTotal = 0; if (depth < 0) { return; // if depth is negative don't draw anything } ArrayList<Arc2D.Double> arcList = new ArrayList<Arc2D.Double>(); Arc2D.Double arc; Paint paint; Paint outlinePaint; Stroke outlineStroke; for (Comparable currentKey : sectionKeys) { Number dataValue = dataset.getValue(currentKey); if (dataValue == null) { arcList.add(null); continue; } double value = dataValue.doubleValue(); if (value <= 0) { arcList.add(null); continue; } double startAngle = getStartAngle(); double direction = getDirection().getFactor(); double angle1 = startAngle + (direction * (runningTotal * 360)) / totalValue; double angle2 = startAngle + (direction * (runningTotal + value) * 360) / totalValue; if (Math.abs(angle2 - angle1) > getMinimumArcAngleToDraw()) { arcList.add(new Arc2D.Double(arcX, arcY + depth, pieArea.getWidth(), pieArea.getHeight() - depth, angle1, angle2 - angle1, Arc2D.PIE)); } else { arcList.add(null); } runningTotal += value; } Shape oldClip = g2.getClip(); Ellipse2D top = new Ellipse2D.Double(pieArea.getX(), pieArea.getY(), pieArea.getWidth(), pieArea.getHeight() - depth); Ellipse2D bottom = new Ellipse2D.Double(pieArea.getX(), pieArea.getY() + depth, pieArea.getWidth(), pieArea.getHeight() - depth); Rectangle2D lower = new Rectangle2D.Double(top.getX(), top.getCenterY(), pieArea.getWidth(), bottom.getMaxY() - top.getCenterY()); Rectangle2D upper = new Rectangle2D.Double(pieArea.getX(), top.getY(), pieArea.getWidth(), bottom.getCenterY() - top.getY()); Area a = new Area(top); a.add(new Area(lower)); Area b = new Area(bottom); b.add(new Area(upper)); Area pie = new Area(a); pie.intersect(b); Area front = new Area(pie); front.subtract(new Area(top)); Area back = new Area(pie); back.subtract(new Area(bottom)); // draw the bottom circle int[] xs; int[] ys; int categoryCount = arcList.size(); for (int categoryIndex = 0; categoryIndex < categoryCount; categoryIndex++) { arc = arcList.get(categoryIndex); if (arc == null) { continue; } Comparable key = getSectionKey(categoryIndex); paint = lookupSectionPaint(key); outlinePaint = lookupSectionOutlinePaint(key); outlineStroke = lookupSectionOutlineStroke(key); g2.setPaint(paint); g2.fill(arc); g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(arc); g2.setPaint(paint); Point2D p1 = arc.getStartPoint(); // draw the height xs = new int[] {(int) arc.getCenterX(), (int) arc.getCenterX(), (int) p1.getX(), (int) p1.getX()}; ys = new int[] {(int) arc.getCenterY(), (int) arc.getCenterY() - depth, (int) p1.getY() - depth, (int) p1.getY()}; Polygon polygon = new Polygon(xs, ys, 4); g2.setPaint(java.awt.Color.LIGHT_GRAY); g2.fill(polygon); g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(polygon); g2.setPaint(paint); } g2.setPaint(Color.GRAY); g2.fill(back); g2.fill(front); // cycle through once drawing only the sides at the back... int cat = 0; for (Arc2D.Double segment : arcList) { if (segment != null) { Comparable key = getSectionKey(cat); paint = lookupSectionPaint(key); outlinePaint = lookupSectionOutlinePaint(key); outlineStroke = lookupSectionOutlineStroke(key); drawSide(g2, pieArea, segment, front, back, paint, outlinePaint, outlineStroke, false, true); } cat++; } // cycle through again drawing only the sides at the front... cat = 0; for (Arc2D.Double segment : arcList) { if (segment != null) { Comparable key = getSectionKey(cat); paint = lookupSectionPaint(key); outlinePaint = lookupSectionOutlinePaint(key); outlineStroke = lookupSectionOutlineStroke(key); drawSide(g2, pieArea, segment, front, back, paint, outlinePaint, outlineStroke, true, false); } cat++; } g2.setClip(oldClip); // draw the sections at the top of the pie (and set up tooltips)... Arc2D upperArc; for (int sectionIndex = 0; sectionIndex < categoryCount; sectionIndex++) { arc = arcList.get(sectionIndex); if (arc == null) { continue; } upperArc = new Arc2D.Double(arcX, arcY, pieArea.getWidth(), pieArea.getHeight() - depth, arc.getAngleStart(), arc.getAngleExtent(), Arc2D.PIE); Comparable currentKey = sectionKeys.get(sectionIndex); paint = lookupSectionPaint(currentKey, true); outlinePaint = lookupSectionOutlinePaint(currentKey); outlineStroke = lookupSectionOutlineStroke(currentKey); g2.setPaint(paint); g2.fill(upperArc); g2.setStroke(outlineStroke); g2.setPaint(outlinePaint); g2.draw(upperArc); // add a tooltip for the section... if (info != null) { EntityCollection entities = info.getOwner().getEntityCollection(); if (entities != null) { String tip = null; PieToolTipGenerator tipster = getToolTipGenerator(); if (tipster != null) { // @mgs: using the method's return value was missing tip = tipster.generateToolTip(dataset, currentKey); } String url = null; if (getURLGenerator() != null) { url = getURLGenerator().generateURL(dataset, currentKey, getPieIndex()); } PieSectionEntity entity = new PieSectionEntity( upperArc, dataset, getPieIndex(), sectionIndex, currentKey, tip, url); entities.add(entity); } } } List<Comparable> keys = dataset.getKeys(); Rectangle2D adjustedPlotArea = new Rectangle2D.Double( originalPlotArea.getX(), originalPlotArea.getY(), originalPlotArea.getWidth(), originalPlotArea.getHeight() - depth); if (getSimpleLabels()) { drawSimpleLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state); } else { drawLabels(g2, keys, totalValue, adjustedPlotArea, linkArea, state); } if (getShadowGenerator() != null) { BufferedImage shadowImage = getShadowGenerator().createDropShadow(dataImage); g2 = savedG2; g2.drawImage(shadowImage, (int) plotArea.getX() + getShadowGenerator().calculateOffsetX(), (int) plotArea.getY() + getShadowGenerator().calculateOffsetY(), null); g2.drawImage(dataImage, (int) plotArea.getX(), (int) plotArea.getY(), null); } g2.setClip(savedClip); g2.setComposite(originalComposite); drawOutline(g2, originalPlotArea); } /** * Draws the side of a pie section. * * @param g2 the graphics device. * @param plotArea the plot area. * @param arc the arc. * @param front the front of the pie. * @param back the back of the pie. * @param paint the color. * @param outlinePaint the outline paint. * @param outlineStroke the outline stroke. * @param drawFront draw the front? * @param drawBack draw the back? */ protected void drawSide(Graphics2D g2, Rectangle2D plotArea, Arc2D arc, Area front, Area back, Paint paint, Paint outlinePaint, Stroke outlineStroke, boolean drawFront, boolean drawBack) { if (getDarkerSides()) { if (paint instanceof Color) { Color c = (Color) paint; c = c.darker(); paint = c; } } double start = arc.getAngleStart(); double extent = arc.getAngleExtent(); double end = start + extent; g2.setStroke(outlineStroke); // for CLOCKWISE charts, the extent will be negative... if (extent < 0.0) { if (isAngleAtFront(start)) { // start at front if (!isAngleAtBack(end)) { if (extent > -180.0) { // the segment is entirely at the // front of the chart if (drawFront) { Area side = new Area(new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), arc.getStartPoint().getX() - arc.getEndPoint().getX(), plotArea.getHeight())); side.intersect(front); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // the segment starts at the front, and wraps all // the way around // the back and finishes at the front again Area side1 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getStartPoint().getX() - plotArea.getX(), plotArea.getHeight())); side1.intersect(front); Area side2 = new Area(new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight())); side2.intersect(front); g2.setPaint(paint); if (drawFront) { g2.fill(side1); g2.fill(side2); } if (drawBack) { g2.fill(back); } g2.setPaint(outlinePaint); if (drawFront) { g2.draw(side1); g2.draw(side2); } if (drawBack) { g2.draw(back); } } } else { // starts at the front, finishes at the back (going // around the left side) if (drawBack) { Area side2 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight())); side2.intersect(back); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } if (drawFront) { Area side1 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getStartPoint().getX() - plotArea.getX(), plotArea.getHeight())); side1.intersect(front); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } } } else { // the segment starts at the back (still extending // CLOCKWISE) if (!isAngleAtFront(end)) { if (extent > -180.0) { // whole segment stays at the back if (drawBack) { Area side = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), arc.getEndPoint().getX() - arc.getStartPoint().getX(), plotArea.getHeight())); side.intersect(back); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // starts at the back, wraps around front, and // finishes at back again Area side1 = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight())); side1.intersect(back); Area side2 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight())); side2.intersect(back); g2.setPaint(paint); if (drawBack) { g2.fill(side1); g2.fill(side2); } if (drawFront) { g2.fill(front); } g2.setPaint(outlinePaint); if (drawBack) { g2.draw(side1); g2.draw(side2); } if (drawFront) { g2.draw(front); } } } else { // starts at back, finishes at front (CLOCKWISE) if (drawBack) { Area side1 = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight())); side1.intersect(back); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } if (drawFront) { Area side2 = new Area(new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight())); side2.intersect(front); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } } } } else if (extent > 0.0) { // the pie sections are arranged ANTICLOCKWISE if (isAngleAtFront(start)) { // segment starts at the front if (!isAngleAtBack(end)) { // and finishes at the front if (extent < 180.0) { // segment only occupies the front if (drawFront) { Area side = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), arc.getEndPoint().getX() - arc.getStartPoint().getX(), plotArea.getHeight())); side.intersect(front); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // segments wraps right around the back... Area side1 = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight())); side1.intersect(front); Area side2 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight())); side2.intersect(front); g2.setPaint(paint); if (drawFront) { g2.fill(side1); g2.fill(side2); } if (drawBack) { g2.fill(back); } g2.setPaint(outlinePaint); if (drawFront) { g2.draw(side1); g2.draw(side2); } if (drawBack) { g2.draw(back); } } } else { // segments starts at front and finishes at back... if (drawBack) { Area side2 = new Area(new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight())); side2.intersect(back); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } if (drawFront) { Area side1 = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getStartPoint().getX(), plotArea.getHeight())); side1.intersect(front); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } } } else { // segment starts at back if (!isAngleAtFront(end)) { if (extent < 180.0) { // and finishes at back if (drawBack) { Area side = new Area(new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), arc.getStartPoint().getX() - arc.getEndPoint().getX(), plotArea.getHeight())); side.intersect(back); g2.setPaint(paint); g2.fill(side); g2.setPaint(outlinePaint); g2.draw(side); } } else { // starts at back and wraps right around to the // back again Area side1 = new Area(new Rectangle2D.Double( arc.getStartPoint().getX(), plotArea.getY(), plotArea.getX() - arc.getStartPoint().getX(), plotArea.getHeight())); side1.intersect(back); Area side2 = new Area(new Rectangle2D.Double( arc.getEndPoint().getX(), plotArea.getY(), plotArea.getMaxX() - arc.getEndPoint().getX(), plotArea.getHeight())); side2.intersect(back); g2.setPaint(paint); if (drawBack) { g2.fill(side1); g2.fill(side2); } if (drawFront) { g2.fill(front); } g2.setPaint(outlinePaint); if (drawBack) { g2.draw(side1); g2.draw(side2); } if (drawFront) { g2.draw(front); } } } else { // starts at the back and finishes at the front // (wrapping the left side) if (drawBack) { Area side1 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getStartPoint().getX() - plotArea.getX(), plotArea.getHeight())); side1.intersect(back); g2.setPaint(paint); g2.fill(side1); g2.setPaint(outlinePaint); g2.draw(side1); } if (drawFront) { Area side2 = new Area(new Rectangle2D.Double( plotArea.getX(), plotArea.getY(), arc.getEndPoint().getX() - plotArea.getX(), plotArea.getHeight())); side2.intersect(front); g2.setPaint(paint); g2.fill(side2); g2.setPaint(outlinePaint); g2.draw(side2); } } } } } /** * Returns a short string describing the type of plot. * * @return <i>Pie 3D Plot</i>. */ @Override public String getPlotType() { return localizationResources.getString("Pie_3D_Plot"); } /** * A utility method that returns true if the angle represents a point at * the front of the 3D pie chart. 0 - 180 degrees is the back, 180 - 360 * is the front. * * @param angle the angle. * * @return A boolean. */ private boolean isAngleAtFront(double angle) { return (Math.sin(Math.toRadians(angle)) < 0.0); } /** * A utility method that returns true if the angle represents a point at * the back of the 3D pie chart. 0 - 180 degrees is the back, 180 - 360 * is the front. * * @param angle the angle. * * @return <code>true</code> if the angle is at the back of the pie. */ private boolean isAngleAtBack(double angle) { return (Math.sin(Math.toRadians(angle)) > 0.0); } /** * Tests this plot for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PiePlot3D)) { return false; } PiePlot3D that = (PiePlot3D) obj; if (this.depthFactor != that.depthFactor) { return false; } if (this.darkerSides != that.darkerSides) { return false; } return super.equals(obj); } }
41,424
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PolarAxisLocation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PolarAxisLocation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * PolarAxisLocation.java * ---------------------- * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 25-Nov-2009 : Version 1 (DG); * */ package org.jfree.chart.plot; /** * Used to indicate the location of an axis on a {@link PolarPlot}. * * @since 1.0.14 */ public enum PolarAxisLocation { /** Axis left of north. */ NORTH_LEFT("PolarAxisLocation.NORTH_LEFT"), /** Axis right of north. */ NORTH_RIGHT("PolarAxisLocation.NORTH_RIGHT"), /** Axis left of south. */ SOUTH_LEFT("PolarAxisLocation.SOUTH_LEFT"), /** Axis right of south. */ SOUTH_RIGHT("PolarAxisLocation.SOUTH_RIGHT"), /** Axis above east. */ EAST_ABOVE("PolarAxisLocation.EAST_ABOVE"), /** Axis below east. */ EAST_BELOW("PolarAxisLocation.EAST_BELOW"), /** Axis above west. */ WEST_ABOVE("PolarAxisLocation.WEST_ABOVE"), /** Axis below west. */ WEST_BELOW("PolarAxisLocation.WEST_BELOW"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private PolarAxisLocation(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,709
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryCrosshairState.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CategoryCrosshairState.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * CategoryCrosshairState.java * --------------------------- * (C) Copyright 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 26-Jun-2008 : Version 1 (DG); * */ package org.jfree.chart.plot; import java.awt.geom.Point2D; import org.jfree.chart.renderer.category.CategoryItemRenderer; /** * Represents state information for the crosshairs in a {@link CategoryPlot}. * An instance of this class is created at the start of the rendering process, * and updated as each data item is rendered. At the end of the rendering * process, this class holds the row key, column key and value for the * crosshair location. * * @since 1.0.11 */ public class CategoryCrosshairState extends CrosshairState { /** * The row key for the crosshair point. */ private Comparable rowKey; /** * The column key for the crosshair point. */ private Comparable columnKey; /** * Creates a new instance. */ public CategoryCrosshairState() { this.rowKey = null; this.columnKey = null; } /** * Returns the row key. * * @return The row key. */ public Comparable getRowKey() { return this.rowKey; } /** * Sets the row key. * * @param key the row key. */ public void setRowKey(Comparable key) { this.rowKey = key; } /** * Returns the column key. * * @return The column key. */ public Comparable getColumnKey() { return this.columnKey; } /** * Sets the column key. * * @param key the key. */ public void setColumnKey(Comparable key) { this.columnKey = key; } /** * Evaluates a data point from a {@link CategoryItemRenderer} and if it is * the closest to the anchor point it becomes the new crosshair point. * * @param rowKey the row key. * @param columnKey the column key. * @param value y coordinate (measured against the range axis). * @param datasetIndex the dataset index for this point. * @param transX x translated into Java2D space. * @param transY y translated into Java2D space. * @param orientation the plot orientation. */ public void updateCrosshairPoint(Comparable rowKey, Comparable columnKey, double value, int datasetIndex, double transX, double transY, PlotOrientation orientation) { Point2D anchor = getAnchor(); if (anchor != null) { double xx = anchor.getX(); double yy = anchor.getY(); if (orientation == PlotOrientation.HORIZONTAL) { double temp = yy; yy = xx; xx = temp; } double d = (transX - xx) * (transX - xx) + (transY - yy) * (transY - yy); if (d < getCrosshairDistance()) { this.rowKey = rowKey; this.columnKey = columnKey; setCrosshairY(value); setDatasetIndex(datasetIndex); setCrosshairDistance(d); } } } /** * Updates only the crosshair row and column keys (this is for the case * where the range crosshair does NOT lock onto the nearest data value). * * @param rowKey the row key. * @param columnKey the column key. * @param datasetIndex the dataset axis index. * @param transX the translated x-value. * @param orientation the plot orientation. */ public void updateCrosshairX(Comparable rowKey, Comparable columnKey, int datasetIndex, double transX, PlotOrientation orientation) { Point2D anchor = getAnchor(); if (anchor != null) { double anchorX = anchor.getX(); if (orientation == PlotOrientation.HORIZONTAL) { anchorX = anchor.getY(); } double d = Math.abs(transX - anchorX); if (d < getCrosshairDistance()) { this.rowKey = rowKey; this.columnKey = columnKey; setDatasetIndex(datasetIndex); setCrosshairDistance(d); } } } }
5,576
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ValueAxisPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/ValueAxisPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * ValueAxisPlot.java * ------------------ * * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 07-May-2003 : Version 1 (DG); * 11-Nov-2004 : Changed Horizontal --> Domain and Vertical --> Range (DG); * 12-Nov-2004 : Moved zooming methods to new Zoomable interface (DG); * */ package org.jfree.chart.plot; import org.jfree.chart.axis.ValueAxis; import org.jfree.data.Range; /** * An interface that is implemented by plots that use a {@link ValueAxis}, * providing a standard method to find the current data range. */ public interface ValueAxisPlot { /** * Returns the data range that should apply for the specified axis. * * @param axis the axis. * * @return The data range. */ public Range getDataRange(ValueAxis axis); }
2,165
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PolarPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PolarPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * PolarPlot.java * -------------- * (C) Copyright 2004-2014, by Solution Engineering, Inc. and Contributors. * * Original Author: Daniel Bridenbecker, Solution Engineering, Inc.; * Contributor(s): David Gilbert (for Object Refinery Limited); * Martin Hoeller (patches 1871902 and 2850344); * * Changes * ------- * 19-Jan-2004 : Version 1, contributed by DB with minor changes by DG (DG); * 07-Apr-2004 : Changed text bounds calculation (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 09-Jun-2005 : Fixed getDataRange() and equals() methods (DG); * 25-Oct-2005 : Implemented Zoomable (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 07-Feb-2007 : Fixed bug 1599761, data value less than axis minimum (DG); * 21-Mar-2007 : Fixed serialization bug (DG); * 24-Sep-2007 : Implemented new zooming methods (DG); * 17-Feb-2007 : Added angle tick unit attribute (see patch 1871902 by * Martin Hoeller) (DG); * 18-Dec-2008 : Use ResourceBundleWrapper - see patch 1607918 by * Jess Thrysoee (DG); * 03-Sep-2009 : Applied patch 2850344 by Martin Hoeller (DG); * 27-Nov-2009 : Added support for multiple datasets, renderers and axes (DG); * 09-Dec-2009 : Extended getLegendItems() to handle multiple datasets (DG); * 25-Jun-2010 : Better support for multiple axes (MH); * 03-Oct-2011 : Added support for angleOffset and direction (MH); * 12-Nov-2011 : Fixed bug 3432721, log-axis doesn't work (MH); * 12-Dec-2011 : Added support for radiusMinorGridilnesVisible (MH); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Composite; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Point; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.ResourceBundle; import java.util.Set; import java.util.TreeMap; import org.jfree.chart.LegendItem; import org.jfree.chart.axis.Axis; import org.jfree.chart.axis.AxisState; import org.jfree.chart.axis.NumberTick; import org.jfree.chart.axis.NumberTickUnit; import org.jfree.chart.axis.TickType; import org.jfree.chart.axis.TickUnit; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.axis.ValueTick; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.util.ObjectList; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.event.RendererChangeEvent; import org.jfree.chart.event.RendererChangeListener; import org.jfree.chart.renderer.PolarItemRenderer; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.ResourceBundleWrapper; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.Range; import org.jfree.data.general.Dataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.xy.XYDataset; /** * Plots data that is in (theta, radius) pairs where * theta equal to zero is due north and increases clockwise. */ public class PolarPlot extends Plot implements ValueAxisPlot, Zoomable, RendererChangeListener, Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 3794383185924179525L; /** The default margin. */ private static final int DEFAULT_MARGIN = 20; /** The annotation margin. */ private static final double ANNOTATION_MARGIN = 7.0; /** * The default angle tick unit size. * * @since 1.0.10 */ public static final double DEFAULT_ANGLE_TICK_UNIT_SIZE = 45.0; /** * The default angle offset. * * @since 1.0.14 */ public static final double DEFAULT_ANGLE_OFFSET = -90.0; /** The default grid line stroke. */ public static final Stroke DEFAULT_GRIDLINE_STROKE = new BasicStroke( 0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[]{2.0f, 2.0f}, 0.0f); /** The default grid line paint. */ public static final Paint DEFAULT_GRIDLINE_PAINT = Color.GRAY; /** The resourceBundle for the localization. */ protected static ResourceBundle localizationResources = ResourceBundleWrapper.getBundle( "org.jfree.chart.plot.LocalizationBundle"); /** The angles that are marked with gridlines. */ private List<ValueTick> angleTicks; /** The range axis (used for the y-values). */ private ObjectList<ValueAxis> axes; /** The axis locations. */ private ObjectList<PolarAxisLocation> axisLocations; /** Storage for the datasets. */ private ObjectList<Dataset> datasets; /** Storage for the renderers. */ private ObjectList<PolarItemRenderer> renderers; /** * The tick unit that controls the spacing between the angular grid lines. * * @since 1.0.10 */ private TickUnit angleTickUnit; /** * An offset for the angles, to start with 0 degrees at north, east, south * or west. * * @since 1.0.14 */ private double angleOffset; /** * A flag indicating if the angles increase counterclockwise or clockwise. * * @since 1.0.14 */ private boolean counterClockwise; /** A flag that controls whether or not the angle labels are visible. */ private boolean angleLabelsVisible = true; /** The font used to display the angle labels - never null. */ private Font angleLabelFont = new Font("SansSerif", Font.PLAIN, 12); /** The paint used to display the angle labels. */ private transient Paint angleLabelPaint = Color.BLACK; /** A flag that controls whether the angular grid-lines are visible. */ private boolean angleGridlinesVisible; /** The stroke used to draw the angular grid-lines. */ private transient Stroke angleGridlineStroke; /** The paint used to draw the angular grid-lines. */ private transient Paint angleGridlinePaint; /** A flag that controls whether the radius grid-lines are visible. */ private boolean radiusGridlinesVisible; /** The stroke used to draw the radius grid-lines. */ private transient Stroke radiusGridlineStroke; /** The paint used to draw the radius grid-lines. */ private transient Paint radiusGridlinePaint; /** * A flag that controls whether the radial minor grid-lines are visible. * @since 1.0.15 */ private boolean radiusMinorGridlinesVisible; /** The annotations for the plot. */ private List<String> cornerTextItems = new ArrayList<String>(); /** * The actual margin in pixels. * * @since 1.0.14 */ private int margin; /** * An optional collection of legend items that can be returned by the * getLegendItems() method. */ private List<LegendItem> fixedLegendItems; /** * Storage for the mapping between datasets/renderers and range axes. The * keys in the map are Integer objects, corresponding to the dataset * index. The values in the map are List objects containing Integer * objects (corresponding to the axis indices). If the map contains no * entry for a dataset, it is assumed to map to the primary domain axis * (index = 0). */ private Map<Integer, List<Integer>> datasetToAxesMap; /** * Default constructor. */ public PolarPlot() { this(null, null, null); } /** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). * @param radiusAxis the radius axis (<code>null</code> permitted). * @param renderer the renderer (<code>null</code> permitted). */ public PolarPlot(XYDataset dataset, ValueAxis radiusAxis, PolarItemRenderer renderer) { super(); this.datasets = new ObjectList<Dataset>(); this.datasets.set(0, dataset); if (dataset != null) { dataset.addChangeListener(this); } this.angleTickUnit = new NumberTickUnit(DEFAULT_ANGLE_TICK_UNIT_SIZE); this.axes = new ObjectList<ValueAxis>(); this.datasetToAxesMap = new TreeMap<Integer, List<Integer>>(); this.axes.set(0, radiusAxis); if (radiusAxis != null) { radiusAxis.setPlot(this); radiusAxis.addChangeListener(this); } // define the default locations for up to 8 axes... this.axisLocations = new ObjectList<PolarAxisLocation>(); this.axisLocations.set(0, PolarAxisLocation.EAST_ABOVE); this.axisLocations.set(1, PolarAxisLocation.NORTH_LEFT); this.axisLocations.set(2, PolarAxisLocation.WEST_BELOW); this.axisLocations.set(3, PolarAxisLocation.SOUTH_RIGHT); this.axisLocations.set(4, PolarAxisLocation.EAST_BELOW); this.axisLocations.set(5, PolarAxisLocation.NORTH_RIGHT); this.axisLocations.set(6, PolarAxisLocation.WEST_ABOVE); this.axisLocations.set(7, PolarAxisLocation.SOUTH_LEFT); this.renderers = new ObjectList<PolarItemRenderer>(); this.renderers.set(0, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } this.angleOffset = DEFAULT_ANGLE_OFFSET; this.counterClockwise = false; this.angleGridlinesVisible = true; this.angleGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.angleGridlinePaint = DEFAULT_GRIDLINE_PAINT; this.radiusGridlinesVisible = true; this.radiusMinorGridlinesVisible = true; this.radiusGridlineStroke = DEFAULT_GRIDLINE_STROKE; this.radiusGridlinePaint = DEFAULT_GRIDLINE_PAINT; this.margin = DEFAULT_MARGIN; } /** * Returns the plot type as a string. * * @return A short string describing the type of plot. */ @Override public String getPlotType() { return PolarPlot.localizationResources.getString("Polar_Plot"); } /** * Returns the primary axis for the plot. * * @return The primary axis (possibly <code>null</code>). * * @see #setAxis(ValueAxis) */ public ValueAxis getAxis() { return getAxis(0); } /** * Returns an axis for the plot. * * @param index the axis index. * * @return The axis (<code>null</code> possible). * * @see #setAxis(int, ValueAxis) * * @since 1.0.14 */ public ValueAxis getAxis(int index) { ValueAxis result = null; if (index < this.axes.size()) { result = this.axes.get(index); } return result; } /** * Sets the primary axis for the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param axis the new primary axis (<code>null</code> permitted). */ public void setAxis(ValueAxis axis) { setAxis(0, axis); } /** * Sets an axis for the plot and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * * @see #getAxis(int) * * @since 1.0.14 */ public void setAxis(int index, ValueAxis axis) { setAxis(index, axis, true); } /** * Sets an axis for the plot and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the axis index. * @param axis the axis (<code>null</code> permitted). * @param notify notify listeners? * * @see #getAxis(int) * * @since 1.0.14 */ public void setAxis(int index, ValueAxis axis, boolean notify) { ValueAxis existing = getAxis(index); if (existing != null) { existing.removeChangeListener(this); } if (axis != null) { axis.setPlot(this); } this.axes.set(index, axis); if (axis != null) { axis.configure(); axis.addChangeListener(this); } if (notify) { fireChangeEvent(); } } /** * Returns the location of the primary axis. * * @return The location (never <code>null</code>). * * @see #setAxisLocation(PolarAxisLocation) * * @since 1.0.14 */ public PolarAxisLocation getAxisLocation() { return getAxisLocation(0); } /** * Returns the location for an axis. * * @param index the axis index. * * @return The location (never <code>null</code>). * * @see #setAxisLocation(int, PolarAxisLocation) * * @since 1.0.14 */ public PolarAxisLocation getAxisLocation(int index) { PolarAxisLocation result = null; if (index < this.axisLocations.size()) { result = this.axisLocations.get(index); } return result; } /** * Sets the location of the primary axis and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * * @see #getAxisLocation() * * @since 1.0.14 */ public void setAxisLocation(PolarAxisLocation location) { // delegate... setAxisLocation(0, location, true); } /** * Sets the location of the primary axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? * * @see #getAxisLocation() * * @since 1.0.14 */ public void setAxisLocation(PolarAxisLocation location, boolean notify) { // delegate... setAxisLocation(0, location, notify); } /** * Sets the location for an axis and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param index the axis index. * @param location the location (<code>null</code> not permitted). * * @see #getAxisLocation(int) * * @since 1.0.14 */ public void setAxisLocation(int index, PolarAxisLocation location) { // delegate... setAxisLocation(index, location, true); } /** * Sets the axis location for an axis and, if requested, sends a * {@link PlotChangeEvent} to all registered listeners. * * @param index the axis index. * @param location the location (<code>null</code> not permitted). * @param notify notify listeners? * * @since 1.0.14 */ public void setAxisLocation(int index, PolarAxisLocation location, boolean notify) { ParamChecks.nullNotPermitted(location, "location"); this.axisLocations.set(index, location); if (notify) { fireChangeEvent(); } } /** * Returns the number of domain axes. * * @return The axis count. * * @since 1.0.14 **/ public int getAxisCount() { return this.axes.size(); } /** * Returns the primary dataset for the plot. * * @return The primary dataset (possibly <code>null</code>). * * @see #setDataset(XYDataset) */ public XYDataset getDataset() { return getDataset(0); } /** * Returns the dataset with the specified index, if any. * * @param index the dataset index. * * @return The dataset (possibly <code>null</code>). * * @see #setDataset(int, XYDataset) * * @since 1.0.14 */ public XYDataset getDataset(int index) { XYDataset result = null; if (index < this.datasets.size()) { result = (XYDataset) this.datasets.get(index); } return result; } /** * Sets the primary dataset for the plot, replacing the existing dataset * if there is one, and sends a {@code link PlotChangeEvent} to all * registered listeners. * * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset() */ public void setDataset(XYDataset dataset) { setDataset(0, dataset); } /** * Sets a dataset for the plot, replacing the existing dataset at the same * index if there is one, and sends a {@code link PlotChangeEvent} to all * registered listeners. * * @param index the dataset index. * @param dataset the dataset (<code>null</code> permitted). * * @see #getDataset(int) * * @since 1.0.14 */ public void setDataset(int index, XYDataset dataset) { XYDataset existing = getDataset(index); if (existing != null) { existing.removeChangeListener(this); } this.datasets.set(index, dataset); if (dataset != null) { dataset.addChangeListener(this); } // send a dataset change event to self... DatasetChangeEvent event = new DatasetChangeEvent(this, dataset); datasetChanged(event); } /** * Returns the number of datasets. * * @return The number of datasets. * * @since 1.0.14 */ public int getDatasetCount() { return this.datasets.size(); } /** * Returns the index of the specified dataset, or <code>-1</code> if the * dataset does not belong to the plot. * * @param dataset the dataset (<code>null</code> not permitted). * * @return The index. * * @since 1.0.14 */ public int indexOf(XYDataset dataset) { int result = -1; for (int i = 0; i < this.datasets.size(); i++) { if (dataset == this.datasets.get(i)) { result = i; break; } } return result; } /** * Returns the primary renderer. * * @return The renderer (possibly <code>null</code>). * * @see #setRenderer(PolarItemRenderer) */ public PolarItemRenderer getRenderer() { return getRenderer(0); } /** * Returns the renderer at the specified index, if there is one. * * @param index the renderer index. * * @return The renderer (possibly <code>null</code>). * * @see #setRenderer(int, PolarItemRenderer) * * @since 1.0.14 */ public PolarItemRenderer getRenderer(int index) { PolarItemRenderer result = null; if (index < this.renderers.size()) { result = this.renderers.get(index); } return result; } /** * Sets the primary renderer, and notifies all listeners of a change to the * plot. If the renderer is set to <code>null</code>, no data items will * be drawn for the corresponding dataset. * * @param renderer the new renderer (<code>null</code> permitted). * * @see #getRenderer() */ public void setRenderer(PolarItemRenderer renderer) { setRenderer(0, renderer); } /** * Sets a renderer and sends a {@link PlotChangeEvent} to all * registered listeners. * * @param index the index. * @param renderer the renderer. * * @see #getRenderer(int) * * @since 1.0.14 */ public void setRenderer(int index, PolarItemRenderer renderer) { setRenderer(index, renderer, true); } /** * Sets a renderer and, if requested, sends a {@link PlotChangeEvent} to * all registered listeners. * * @param index the index. * @param renderer the renderer. * @param notify notify listeners? * * @see #getRenderer(int) * * @since 1.0.14 */ public void setRenderer(int index, PolarItemRenderer renderer, boolean notify) { PolarItemRenderer existing = getRenderer(index); if (existing != null) { existing.removeChangeListener(this); } this.renderers.set(index, renderer); if (renderer != null) { renderer.setPlot(this); renderer.addChangeListener(this); } if (notify) { fireChangeEvent(); } } /** * Returns the tick unit that controls the spacing of the angular grid * lines. * * @return The tick unit (never <code>null</code>). * * @since 1.0.10 */ public TickUnit getAngleTickUnit() { return this.angleTickUnit; } /** * Sets the tick unit that controls the spacing of the angular grid * lines, and sends a {@link PlotChangeEvent} to all registered listeners. * * @param unit the tick unit (<code>null</code> not permitted). * * @since 1.0.10 */ public void setAngleTickUnit(TickUnit unit) { ParamChecks.nullNotPermitted(unit, "unit"); this.angleTickUnit = unit; fireChangeEvent(); } /** * Returns the offset that is used for all angles. * * @return The offset for the angles. * @since 1.0.14 */ public double getAngleOffset() { return this.angleOffset; } /** * Sets the offset that is used for all angles and sends a * {@link PlotChangeEvent} to all registered listeners. * * This is useful to let 0 degrees be at the north, east, south or west * side of the chart. * * @param offset The offset * @since 1.0.14 */ public void setAngleOffset(double offset) { this.angleOffset = offset; fireChangeEvent(); } /** * Get the direction for growing angle degrees. * * @return <code>true</code> if angle increases counterclockwise, * <code>false</code> otherwise. * @since 1.0.14 */ public boolean isCounterClockwise() { return this.counterClockwise; } /** * Sets the flag for increasing angle degrees direction. * * <code>true</code> for counterclockwise, <code>false</code> for * clockwise. * * @param counterClockwise The flag. * @since 1.0.14 */ public void setCounterClockwise(boolean counterClockwise) { this.counterClockwise = counterClockwise; } /** * Returns a flag that controls whether or not the angle labels are visible. * * @return A boolean. * * @see #setAngleLabelsVisible(boolean) */ public boolean isAngleLabelsVisible() { return this.angleLabelsVisible; } /** * Sets the flag that controls whether or not the angle labels are visible, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param visible the flag. * * @see #isAngleLabelsVisible() */ public void setAngleLabelsVisible(boolean visible) { if (this.angleLabelsVisible != visible) { this.angleLabelsVisible = visible; fireChangeEvent(); } } /** * Returns the font used to display the angle labels. * * @return A font (never <code>null</code>). * * @see #setAngleLabelFont(Font) */ public Font getAngleLabelFont() { return this.angleLabelFont; } /** * Sets the font used to display the angle labels and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @see #getAngleLabelFont() */ public void setAngleLabelFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.angleLabelFont = font; fireChangeEvent(); } /** * Returns the paint used to display the angle labels. * * @return A paint (never <code>null</code>). * * @see #setAngleLabelPaint(Paint) */ public Paint getAngleLabelPaint() { return this.angleLabelPaint; } /** * Sets the paint used to display the angle labels and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). */ public void setAngleLabelPaint(Paint paint) { ParamChecks.nullNotPermitted(paint, "paint"); this.angleLabelPaint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the angular gridlines are visible, and * <code>false</code> otherwise. * * @return <code>true</code> or <code>false</code>. * * @see #setAngleGridlinesVisible(boolean) */ public boolean isAngleGridlinesVisible() { return this.angleGridlinesVisible; } /** * Sets the flag that controls whether or not the angular grid-lines are * visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isAngleGridlinesVisible() */ public void setAngleGridlinesVisible(boolean visible) { if (this.angleGridlinesVisible != visible) { this.angleGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the grid-lines (if any) plotted against the * angular axis. * * @return The stroke (possibly <code>null</code>). * * @see #setAngleGridlineStroke(Stroke) */ public Stroke getAngleGridlineStroke() { return this.angleGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the angular axis and * sends a {@link PlotChangeEvent} to all registered listeners. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param stroke the stroke (<code>null</code> permitted). * * @see #getAngleGridlineStroke() */ public void setAngleGridlineStroke(Stroke stroke) { this.angleGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the grid lines (if any) plotted against the * angular axis. * * @return The paint (possibly <code>null</code>). * * @see #setAngleGridlinePaint(Paint) */ public Paint getAngleGridlinePaint() { return this.angleGridlinePaint; } /** * Sets the paint for the grid lines plotted against the angular axis. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param paint the paint (<code>null</code> permitted). * * @see #getAngleGridlinePaint() */ public void setAngleGridlinePaint(Paint paint) { this.angleGridlinePaint = paint; fireChangeEvent(); } /** * Returns <code>true</code> if the radius axis grid is visible, and * <code>false</code> otherwise. * * @return <code>true</code> or <code>false</code>. * * @see #setRadiusGridlinesVisible(boolean) */ public boolean isRadiusGridlinesVisible() { return this.radiusGridlinesVisible; } /** * Sets the flag that controls whether or not the radius axis grid lines * are visible. * <p> * If the flag value is changed, a {@link PlotChangeEvent} is sent to all * registered listeners. * * @param visible the new value of the flag. * * @see #isRadiusGridlinesVisible() */ public void setRadiusGridlinesVisible(boolean visible) { if (this.radiusGridlinesVisible != visible) { this.radiusGridlinesVisible = visible; fireChangeEvent(); } } /** * Returns the stroke for the grid lines (if any) plotted against the * radius axis. * * @return The stroke (possibly <code>null</code>). * * @see #setRadiusGridlineStroke(Stroke) */ public Stroke getRadiusGridlineStroke() { return this.radiusGridlineStroke; } /** * Sets the stroke for the grid lines plotted against the radius axis and * sends a {@link PlotChangeEvent} to all registered listeners. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param stroke the stroke (<code>null</code> permitted). * * @see #getRadiusGridlineStroke() */ public void setRadiusGridlineStroke(Stroke stroke) { this.radiusGridlineStroke = stroke; fireChangeEvent(); } /** * Returns the paint for the grid lines (if any) plotted against the radius * axis. * * @return The paint (possibly <code>null</code>). * * @see #setRadiusGridlinePaint(Paint) */ public Paint getRadiusGridlinePaint() { return this.radiusGridlinePaint; } /** * Sets the paint for the grid lines plotted against the radius axis and * sends a {@link PlotChangeEvent} to all registered listeners. * <p> * If you set this to <code>null</code>, no grid lines will be drawn. * * @param paint the paint (<code>null</code> permitted). * * @see #getRadiusGridlinePaint() */ public void setRadiusGridlinePaint(Paint paint) { this.radiusGridlinePaint = paint; fireChangeEvent(); } /** * Return the current value of the flag indicating if radial minor * grid-lines will be drawn or not. * * @return Returns <code>true</code> if radial minor grid-lines are drawn. * @since 1.0.15 */ public boolean isRadiusMinorGridlinesVisible() { return this.radiusMinorGridlinesVisible; } /** * Set the flag that determines if radial minor grid-lines will be drawn, * and sends a {@link PlotChangeEvent} to all registered listeners. * * @param flag <code>true</code> to draw the radial minor grid-lines, * <code>false</code> to hide them. * @since 1.0.15 */ public void setRadiusMinorGridlinesVisible(boolean flag) { this.radiusMinorGridlinesVisible = flag; fireChangeEvent(); } /** * Returns the margin around the plot area. * * @return The actual margin in pixels. * * @since 1.0.14 */ public int getMargin() { return this.margin; } /** * Set the margin around the plot area and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param margin The new margin in pixels. * * @since 1.0.14 */ public void setMargin(int margin) { this.margin = margin; fireChangeEvent(); } /** * Returns the fixed legend items, if any. The default value is * <code>null</code>. * * @return The legend items (possibly <code>null</code>). * * @see #setFixedLegendItems(LegendItemCollection) */ public List<LegendItem> getFixedLegendItems() { return this.fixedLegendItems; } /** * Sets the fixed legend items for the plot and sends a change event to all * registered listeners. Leave this set to <code>null</code> if you prefer * the legend items to be created automatically. * * @param items the legend items (<code>null</code> permitted). * * @see #getFixedLegendItems() */ public void setFixedLegendItems(List<LegendItem> items) { this.fixedLegendItems = items; fireChangeEvent(); } /** * Add text to be displayed in the lower right hand corner and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param text the text to display (<code>null</code> not permitted). * * @see #removeCornerTextItem(String) */ public void addCornerTextItem(String text) { if (text == null) { throw new IllegalArgumentException("Null 'text' argument."); } this.cornerTextItems.add(text); fireChangeEvent(); } /** * Remove the given text from the list of corner text items and * sends a {@link PlotChangeEvent} to all registered listeners. * * @param text the text to remove (<code>null</code> ignored). * * @see #addCornerTextItem(String) */ public void removeCornerTextItem(String text) { boolean removed = this.cornerTextItems.remove(text); if (removed) { fireChangeEvent(); } } /** * Clear the list of corner text items and sends a {@link PlotChangeEvent} * to all registered listeners. * * @see #addCornerTextItem(String) * @see #removeCornerTextItem(String) */ public void clearCornerTextItems() { if (this.cornerTextItems.size() > 0) { this.cornerTextItems.clear(); fireChangeEvent(); } } /** * Generates a list of tick values for the angular tick marks. * * @return A list of {@link NumberTick} instances. * * @since 1.0.10 */ protected List<ValueTick> refreshAngleTicks() { List<ValueTick> ticks = new ArrayList<ValueTick>(); for (double currentTickVal = 0.0; currentTickVal < 360.0; currentTickVal += this.angleTickUnit.getSize()) { TextAnchor ta = calculateTextAnchor(currentTickVal); NumberTick tick = new NumberTick(currentTickVal, this.angleTickUnit.valueToString(currentTickVal), ta, TextAnchor.CENTER, 0.0); ticks.add(tick); } return ticks; } /** * Calculate the text position for the given degrees. * * @param angleDegrees the angle in degrees. * * @return The optimal text anchor. * @since 1.0.14 */ protected TextAnchor calculateTextAnchor(double angleDegrees) { TextAnchor ta = TextAnchor.CENTER; // normalize angle double offset = this.angleOffset; while (offset < 0.0) { offset += 360.0; } double normalizedAngle = (((this.counterClockwise ? -1 : 1) * angleDegrees) + offset) % 360; while (this.counterClockwise && (normalizedAngle < 0.0)) { normalizedAngle += 360.0; } if (normalizedAngle == 0.0) { ta = TextAnchor.CENTER_LEFT; } else if (normalizedAngle > 0.0 && normalizedAngle < 90.0) { ta = TextAnchor.TOP_LEFT; } else if (normalizedAngle == 90.0) { ta = TextAnchor.TOP_CENTER; } else if (normalizedAngle > 90.0 && normalizedAngle < 180.0) { ta = TextAnchor.TOP_RIGHT; } else if (normalizedAngle == 180) { ta = TextAnchor.CENTER_RIGHT; } else if (normalizedAngle > 180.0 && normalizedAngle < 270.0) { ta = TextAnchor.BOTTOM_RIGHT; } else if (normalizedAngle == 270) { ta = TextAnchor.BOTTOM_CENTER; } else if (normalizedAngle > 270.0 && normalizedAngle < 360.0) { ta = TextAnchor.BOTTOM_LEFT; } return ta; } /** * Maps a dataset to a particular axis. All data will be plotted * against axis zero by default, no mapping is required for this case. * * @param index the dataset index (zero-based). * @param axisIndex the axis index. * * @since 1.0.14 */ public void mapDatasetToAxis(int index, int axisIndex) { List<Integer> axisIndices = new java.util.ArrayList<Integer>(1); axisIndices.add(axisIndex); mapDatasetToAxes(index, axisIndices); } /** * Maps the specified dataset to the axes in the list. Note that the * conversion of data values into Java2D space is always performed using * the first axis in the list. * * @param index the dataset index (zero-based). * @param axisIndices the axis indices (<code>null</code> permitted). * * @since 1.0.14 */ public void mapDatasetToAxes(int index, List<Integer> axisIndices) { if (index < 0) { throw new IllegalArgumentException("Requires 'index' >= 0."); } checkAxisIndices(axisIndices); Integer key = index; this.datasetToAxesMap.put(key, new ArrayList<Integer>(axisIndices)); // fake a dataset change event to update axes... datasetChanged(new DatasetChangeEvent(this, getDataset(index))); } /** * This method is used to perform argument checking on the list of * axis indices passed to mapDatasetToAxes(). * * @param indices the list of indices (<code>null</code> permitted). */ private void checkAxisIndices(List<Integer> indices) { // axisIndices can be: // 1. null; // 2. non-empty, containing only Integer objects that are unique. if (indices == null) { return; // OK } int count = indices.size(); if (count == 0) { throw new IllegalArgumentException("Empty list not permitted."); } Set<Integer> set = new HashSet<Integer>(); for (Integer i : indices) { if (set.contains(i)) { throw new IllegalArgumentException("Indices must be unique."); } set.add(i); } } /** * Returns the axis for a dataset. * * @param index the dataset index. * * @return The axis. * * @since 1.0.14 */ public ValueAxis getAxisForDataset(int index) { ValueAxis valueAxis; List<Integer> axisIndices = this.datasetToAxesMap.get( index); if (axisIndices != null) { // the first axis in the list is used for data <--> Java2D Integer axisIndex = axisIndices.get(0); valueAxis = getAxis(axisIndex); } else { valueAxis = getAxis(0); } return valueAxis; } /** * Returns the index of the given axis. * * @param axis the axis. * * @return The axis index or -1 if axis is not used in this plot. * * @since 1.0.14 */ public int getAxisIndex(ValueAxis axis) { int result = this.axes.indexOf(axis); if (result < 0) { // try the parent plot Plot parent = getParent(); if (parent instanceof PolarPlot) { PolarPlot p = (PolarPlot) parent; result = p.getAxisIndex(axis); } } return result; } /** * Returns the index of the specified renderer, or <code>-1</code> if the * renderer is not assigned to this plot. * * @param renderer the renderer (<code>null</code> permitted). * * @return The renderer index. * * @since 1.0.14 */ public int getIndexOf(PolarItemRenderer renderer) { return this.renderers.indexOf(renderer); } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * <P> * This plot relies on a {@link PolarItemRenderer} to draw each * item in the plot. This allows the visual representation of the data to * be changed easily. * <P> * The optional info argument collects information about the rendering of * the plot (dimensions, tooltip information etc). Just pass in * <code>null</code> if you do not need this information. * * @param g2 the graphics device. * @param area the area within which the plot (including axes and * labels) should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState ignored. * @param info collects chart drawing information (<code>null</code> * permitted). */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // if the plot area is too small, just return... boolean b1 = (area.getWidth() <= MINIMUM_WIDTH_TO_DRAW); boolean b2 = (area.getHeight() <= MINIMUM_HEIGHT_TO_DRAW); if (b1 || b2) { return; } // record the plot area... if (info != null) { info.setPlotArea(area); } // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); Rectangle2D dataArea = area; if (info != null) { info.setDataArea(dataArea); } // draw the plot background and axes... drawBackground(g2, dataArea); int axisCount = this.axes.size(); AxisState state = null; for (int i = 0; i < axisCount; i++) { ValueAxis axis = getAxis(i); if (axis != null) { PolarAxisLocation location = this.axisLocations.get(i); AxisState s = this.drawAxis(axis, location, g2, dataArea); if (i == 0) { state = s; } } } // now for each dataset, get the renderer and the appropriate axis // and render the dataset... Shape originalClip = g2.getClip(); Composite originalComposite = g2.getComposite(); g2.clip(dataArea); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getForegroundAlpha())); this.angleTicks = refreshAngleTicks(); drawGridlines(g2, dataArea, this.angleTicks, state.getTicks()); render(g2, dataArea, info); g2.setClip(originalClip); g2.setComposite(originalComposite); drawOutline(g2, dataArea); drawCornerTextItems(g2, dataArea); } /** * Draws the corner text items. * * @param g2 the drawing surface. * @param area the area. */ protected void drawCornerTextItems(Graphics2D g2, Rectangle2D area) { if (this.cornerTextItems.isEmpty()) { return; } g2.setColor(Color.BLACK); double width = 0.0; double height = 0.0; for (String s : this.cornerTextItems) { FontMetrics fm = g2.getFontMetrics(); Rectangle2D bounds = TextUtilities.getTextBounds(s, g2, fm); width = Math.max(width, bounds.getWidth()); height += bounds.getHeight(); } double xadj = ANNOTATION_MARGIN * 2.0; double yadj = ANNOTATION_MARGIN; width += xadj; height += yadj; double x = area.getMaxX() - width; double y = area.getMaxY() - height; g2.drawRect((int) x, (int) y, (int) width, (int) height); x += ANNOTATION_MARGIN; for (String s : this.cornerTextItems) { Rectangle2D bounds = TextUtilities.getTextBounds(s, g2, g2.getFontMetrics()); y += bounds.getHeight(); g2.drawString(s, (int) x, (int) y); } } /** * Draws the axis with the specified index. * * @param axis the axis. * @param location the axis location. * @param g2 the graphics target. * @param plotArea the plot area. * * @return The axis state. * * @since 1.0.14 */ protected AxisState drawAxis(ValueAxis axis, PolarAxisLocation location, Graphics2D g2, Rectangle2D plotArea) { double centerX = plotArea.getCenterX(); double centerY = plotArea.getCenterY(); double r = Math.min(plotArea.getWidth() / 2.0, plotArea.getHeight() / 2.0) - this.margin; double x = centerX - r; double y = centerY - r; Rectangle2D dataArea; AxisState result = null; if (location == PolarAxisLocation.NORTH_RIGHT) { dataArea = new Rectangle2D.Double(x, y, r, r); result = axis.draw(g2, centerX, plotArea, dataArea, RectangleEdge.RIGHT, null); } else if (location == PolarAxisLocation.NORTH_LEFT) { dataArea = new Rectangle2D.Double(centerX, y, r, r); result = axis.draw(g2, centerX, plotArea, dataArea, RectangleEdge.LEFT, null); } else if (location == PolarAxisLocation.SOUTH_LEFT) { dataArea = new Rectangle2D.Double(centerX, centerY, r, r); result = axis.draw(g2, centerX, plotArea, dataArea, RectangleEdge.LEFT, null); } else if (location == PolarAxisLocation.SOUTH_RIGHT) { dataArea = new Rectangle2D.Double(x, centerY, r, r); result = axis.draw(g2, centerX, plotArea, dataArea, RectangleEdge.RIGHT, null); } else if (location == PolarAxisLocation.EAST_ABOVE) { dataArea = new Rectangle2D.Double(centerX, centerY, r, r); result = axis.draw(g2, centerY, plotArea, dataArea, RectangleEdge.TOP, null); } else if (location == PolarAxisLocation.EAST_BELOW) { dataArea = new Rectangle2D.Double(centerX, y, r, r); result = axis.draw(g2, centerY, plotArea, dataArea, RectangleEdge.BOTTOM, null); } else if (location == PolarAxisLocation.WEST_ABOVE) { dataArea = new Rectangle2D.Double(x, centerY, r, r); result = axis.draw(g2, centerY, plotArea, dataArea, RectangleEdge.TOP, null); } else if (location == PolarAxisLocation.WEST_BELOW) { dataArea = new Rectangle2D.Double(x, y, r, r); result = axis.draw(g2, centerY, plotArea, dataArea, RectangleEdge.BOTTOM, null); } return result; } /** * Draws a representation of the data within the dataArea region, using the * current m_Renderer. * * @param g2 the graphics device. * @param dataArea the region in which the data is to be drawn. * @param info an optional object for collection dimension * information (<code>null</code> permitted). */ protected void render(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info) { // now get the data and plot it (the visual representation will depend // on the m_Renderer that has been set)... boolean hasData = false; int datasetCount = this.datasets.size(); for (int i = datasetCount - 1; i >= 0; i--) { XYDataset dataset = getDataset(i); if (dataset == null) { continue; } PolarItemRenderer renderer = getRenderer(i); if (renderer == null) { continue; } if (!DatasetUtilities.isEmptyOrNull(dataset)) { hasData = true; int seriesCount = dataset.getSeriesCount(); for (int series = 0; series < seriesCount; series++) { renderer.drawSeries(g2, dataArea, info, this, dataset, series); } } } if (!hasData) { drawNoDataMessage(g2, dataArea); } } /** * Draws the gridlines for the plot, if they are visible. * * @param g2 the graphics device. * @param dataArea the data area. * @param angularTicks the ticks for the angular axis. * @param radialTicks the ticks for the radial axis. */ protected void drawGridlines(Graphics2D g2, Rectangle2D dataArea, List<ValueTick> angularTicks, List<ValueTick> radialTicks) { PolarItemRenderer renderer = getRenderer(); // no renderer, no gridlines... if (renderer == null) { return; } // draw the domain grid lines, if any... if (isAngleGridlinesVisible()) { Stroke gridStroke = getAngleGridlineStroke(); Paint gridPaint = getAngleGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { renderer.drawAngularGridLines(g2, this, angularTicks, dataArea); } } // draw the radius grid lines, if any... if (isRadiusGridlinesVisible()) { Stroke gridStroke = getRadiusGridlineStroke(); Paint gridPaint = getRadiusGridlinePaint(); if ((gridStroke != null) && (gridPaint != null)) { List<ValueTick> ticks = buildRadialTicks(radialTicks); renderer.drawRadialGridLines(g2, this, getAxis(), ticks, dataArea); } } } /** * Create a list of ticks based on the given list and plot properties. * Only ticks of a specific type may be in the result list. * * @param allTicks A list of all available ticks for the primary axis. * <code>null</code> not permitted. * @return Ticks to use for radial gridlines. * @since 1.0.15 */ protected List<ValueTick> buildRadialTicks(List<ValueTick> allTicks) { List<ValueTick> ticks = new ArrayList<ValueTick>(); for (ValueTick tick : allTicks) { if (isRadiusMinorGridlinesVisible() || TickType.MAJOR.equals(tick.getTickType())) { ticks.add(tick); } } return ticks; } /** * Zooms the axis ranges by the specified percentage about the anchor point. * * @param percent the amount of the zoom. */ @Override public void zoom(double percent) { for (int axisIdx = 0; axisIdx < getAxisCount(); axisIdx++) { final ValueAxis axis = getAxis(axisIdx); if (axis != null) { if (percent > 0.0) { double radius = axis.getUpperBound(); double scaledRadius = radius * percent; axis.setUpperBound(scaledRadius); axis.setAutoRange(false); } else { axis.setAutoRange(true); } } } } /** * A utility method that returns a list of datasets that are mapped to a * particular axis. * * @param axisIndex the axis index (<code>null</code> not permitted). * * @return A list of datasets. * * @since 1.0.14 */ private List<Dataset> getDatasetsMappedToAxis(Integer axisIndex) { if (axisIndex == null) { throw new IllegalArgumentException("Null 'axisIndex' argument."); } List<Dataset> result = new ArrayList<Dataset>(); for (int i = 0; i < this.datasets.size(); i++) { List<Integer> mappedAxes = this.datasetToAxesMap.get(i); if (mappedAxes == null) { if (axisIndex.equals(ZERO)) { result.add(this.datasets.get(i)); } } else { if (mappedAxes.contains(axisIndex)) { result.add(this.datasets.get(i)); } } } return result; } /** * Returns the range for the specified axis. * * @param axis the axis. * * @return The range. */ @Override public Range getDataRange(ValueAxis axis) { Range result = null; int axisIdx = getAxisIndex(axis); List<Dataset> mappedDatasets = new ArrayList<Dataset>(); if (axisIdx >= 0) { mappedDatasets = getDatasetsMappedToAxis(axisIdx); } // iterate through the datasets that map to the axis and get the union // of the ranges. for (Dataset mappedDataset : mappedDatasets) { XYDataset d = (XYDataset) mappedDataset; if (d != null) { // FIXME better ask the renderer instead of DatasetUtilities result = Range.combine(result, DatasetUtilities.findRangeBounds(d)); } } return result; } /** * Receives notification of a change to the plot's m_Dataset. * <P> * The axis ranges are updated if necessary. * * @param event information about the event (not used here). */ @Override public void datasetChanged(DatasetChangeEvent event) { for (int i = 0; i < this.axes.size(); i++) { final ValueAxis axis = this.axes.get(i); if (axis != null) { axis.configure(); } } if (getParent() != null) { getParent().datasetChanged(event); } else { super.datasetChanged(event); } } /** * Notifies all registered listeners of a property change. * <P> * One source of property change events is the plot's m_Renderer. * * @param event information about the property change. */ @Override public void rendererChanged(RendererChangeEvent event) { fireChangeEvent(); } /** * Returns the legend items for the plot. Each legend item is generated by * the plot's m_Renderer, since the m_Renderer is responsible for the visual * representation of the data. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { if (this.fixedLegendItems != null) { return new ArrayList<LegendItem>(this.fixedLegendItems); } List<LegendItem> result = new ArrayList<LegendItem>(); int count = this.datasets.size(); for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) { XYDataset dataset = getDataset(datasetIndex); PolarItemRenderer renderer = getRenderer(datasetIndex); if (dataset != null && renderer != null) { int seriesCount = dataset.getSeriesCount(); for (int i = 0; i < seriesCount; i++) { LegendItem item = renderer.getLegendItem(i); result.add(item); } } } return result; } /** * Tests this plot for equality with another object. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> or <code>false</code>. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PolarPlot)) { return false; } PolarPlot that = (PolarPlot) obj; if (!this.axes.equals(that.axes)) { return false; } if (!this.axisLocations.equals(that.axisLocations)) { return false; } if (!this.renderers.equals(that.renderers)) { return false; } if (!this.angleTickUnit.equals(that.angleTickUnit)) { return false; } if (this.angleGridlinesVisible != that.angleGridlinesVisible) { return false; } if (this.angleOffset != that.angleOffset) { return false; } if (this.counterClockwise != that.counterClockwise) { return false; } if (this.angleLabelsVisible != that.angleLabelsVisible) { return false; } if (!this.angleLabelFont.equals(that.angleLabelFont)) { return false; } if (!PaintUtilities.equal(this.angleLabelPaint, that.angleLabelPaint)) { return false; } if (!ObjectUtilities.equal(this.angleGridlineStroke, that.angleGridlineStroke)) { return false; } if (!PaintUtilities.equal( this.angleGridlinePaint, that.angleGridlinePaint )) { return false; } if (this.radiusGridlinesVisible != that.radiusGridlinesVisible) { return false; } if (!ObjectUtilities.equal(this.radiusGridlineStroke, that.radiusGridlineStroke)) { return false; } if (!PaintUtilities.equal(this.radiusGridlinePaint, that.radiusGridlinePaint)) { return false; } if (this.radiusMinorGridlinesVisible != that.radiusMinorGridlinesVisible) { return false; } if (!this.cornerTextItems.equals(that.cornerTextItems)) { return false; } if (this.margin != that.margin) { return false; } if (!ObjectUtilities.equal(this.fixedLegendItems, that.fixedLegendItems)) { return false; } return super.equals(obj); } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this can occur if some component of * the plot cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { PolarPlot clone = (PolarPlot) super.clone(); clone.axes = ObjectUtilities.clone(this.axes); for (int i = 0; i < this.axes.size(); i++) { ValueAxis axis = this.axes.get(i); if (axis != null) { ValueAxis clonedAxis = (ValueAxis) axis.clone(); clone.axes.set(i, clonedAxis); clonedAxis.setPlot(clone); clonedAxis.addChangeListener(clone); } } // the datasets are not cloned, but listeners need to be added... clone.datasets = ObjectUtilities.clone(this.datasets); for (int i = 0; i < clone.datasets.size(); ++i) { XYDataset d = getDataset(i); if (d != null) { d.addChangeListener(clone); } } clone.renderers = ObjectUtilities.clone(this.renderers); for (int i = 0; i < this.renderers.size(); i++) { PolarItemRenderer renderer2 = this.renderers.get(i); if (renderer2 instanceof PublicCloneable) { PublicCloneable pc = (PublicCloneable) renderer2; PolarItemRenderer rc = (PolarItemRenderer) pc.clone(); clone.renderers.set(i, rc); rc.setPlot(clone); rc.addChangeListener(clone); } } clone.cornerTextItems = new ArrayList<String>(this.cornerTextItems); // FIXME : after cloning, the old items won't be in the clone return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.angleGridlineStroke, stream); SerialUtilities.writePaint(this.angleGridlinePaint, stream); SerialUtilities.writeStroke(this.radiusGridlineStroke, stream); SerialUtilities.writePaint(this.radiusGridlinePaint, stream); SerialUtilities.writePaint(this.angleLabelPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.angleGridlineStroke = SerialUtilities.readStroke(stream); this.angleGridlinePaint = SerialUtilities.readPaint(stream); this.radiusGridlineStroke = SerialUtilities.readStroke(stream); this.radiusGridlinePaint = SerialUtilities.readPaint(stream); this.angleLabelPaint = SerialUtilities.readPaint(stream); int rangeAxisCount = this.axes.size(); for (int i = 0; i < rangeAxisCount; i++) { Axis axis = this.axes.get(i); if (axis != null) { axis.setPlot(this); axis.addChangeListener(this); } } int datasetCount = this.datasets.size(); for (int i = 0; i < datasetCount; i++) { Dataset dataset = this.datasets.get(i); if (dataset != null) { dataset.addChangeListener(this); } } int rendererCount = this.renderers.size(); for (int i = 0; i < rendererCount; i++) { PolarItemRenderer renderer = this.renderers.get(i); if (renderer != null) { renderer.addChangeListener(this); } } } /** * This method is required by the {@link Zoomable} interface, but since * the plot does not have any domain axes, it does nothing. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source) { // do nothing } /** * This method is required by the {@link Zoomable} interface, but since * the plot does not have any domain axes, it does nothing. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). * @param useAnchor use source point as zoom anchor? * * @since 1.0.7 */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo state, Point2D source, boolean useAnchor) { // do nothing } /** * This method is required by the {@link Zoomable} interface, but since * the plot does not have any domain axes, it does nothing. * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. * @param source the source point (in Java2D coordinates). */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source) { // do nothing } /** * Multiplies the range on the range axis/axes by the specified factor. * * @param factor the zoom factor. * @param state the plot state. * @param source the source point (in Java2D coordinates). */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo state, Point2D source) { zoom(factor); } /** * Multiplies the range on the range axis by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info. * @param source the source point (in Java2D space). * @param useAnchor use source point as zoom anchor? * * @see #zoomDomainAxes(double, PlotRenderingInfo, Point2D, boolean) * * @since 1.0.7 */ @Override public void zoomRangeAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // get the source coordinate - this plot has always a VERTICAL // orientation final double sourceX = source.getX(); for (int axisIdx = 0; axisIdx < getAxisCount(); axisIdx++) { final ValueAxis axis = getAxis(axisIdx); if (axis != null) { if (useAnchor) { double anchorX = axis.java2DToValue(sourceX, info.getDataArea(), RectangleEdge.BOTTOM); axis.resizeRange(factor, anchorX); } else { axis.resizeRange(factor); } } } } /** * Zooms in on the range axes. * * @param lowerPercent the new lower bound. * @param upperPercent the new upper bound. * @param state the plot state. * @param source the source point (in Java2D coordinates). */ @Override public void zoomRangeAxes(double lowerPercent, double upperPercent, PlotRenderingInfo state, Point2D source) { zoom((upperPercent + lowerPercent) / 2.0); } /** * Returns <code>false</code> always. * * @return <code>false</code> always. */ @Override public boolean isDomainZoomable() { return false; } /** * Returns <code>true</code> to indicate that the range axis is zoomable. * * @return <code>true</code>. */ @Override public boolean isRangeZoomable() { return true; } /** * Returns the orientation of the plot. * * @return The orientation. */ @Override public PlotOrientation getOrientation() { return PlotOrientation.HORIZONTAL; } /** * Translates a (theta, radius) pair into Java2D coordinates. If * <code>radius</code> is less than the lower bound of the axis, then * this method returns the centre point. * * @param angleDegrees the angle in degrees. * @param radius the radius. * @param axis the axis. * @param dataArea the data area. * * @return A point in Java2D space. * * @since 1.0.14 */ public Point translateToJava2D(double angleDegrees, double radius, ValueAxis axis, Rectangle2D dataArea) { if (counterClockwise) { angleDegrees = -angleDegrees; } double radians = Math.toRadians(angleDegrees + this.angleOffset); double minx = dataArea.getMinX() + this.margin; double maxx = dataArea.getMaxX() - this.margin; double miny = dataArea.getMinY() + this.margin; double maxy = dataArea.getMaxY() - this.margin; double halfWidth = (maxx - minx) / 2.0; double halfHeight = (maxy - miny) / 2.0; double midX = minx + halfWidth; double midY = miny + halfHeight; double l = Math.min(halfWidth, halfHeight); Rectangle2D quadrant = new Rectangle2D.Double(midX, midY, l, l); double axisMin = axis.getLowerBound(); double adjustedRadius = Math.max(radius, axisMin); double length = axis.valueToJava2D(adjustedRadius, quadrant, RectangleEdge.BOTTOM) - midX; float x = (float) (midX + Math.cos(radians) * length); float y = (float) (midY + Math.sin(radians) * length); int ix = Math.round(x); int iy = Math.round(y); Point p = new Point(ix, iy); return p; } }
68,710
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MeterInterval.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/MeterInterval.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * MeterInterval.java * ------------------ * (C) Copyright 2005-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 22-Mar-2005 : Version 1 (DG); * 29-Mar-2005 : Fixed serialization (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Paint; import java.awt.Stroke; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.Range; /** * An interval to be highlighted on a {@link MeterPlot}. Instances of this * class are immutable. */ public class MeterInterval implements Serializable { /** For serialization. */ private static final long serialVersionUID = 1530982090622488257L; /** The interval label. */ private String label; /** The interval range. */ private Range range; /** The outline paint (used for the arc marking the interval). */ private transient Paint outlinePaint; /** The outline stroke (used for the arc marking the interval). */ private transient Stroke outlineStroke; /** The background paint for the interval. */ private transient Paint backgroundPaint; /** * Creates a new interval. * * @param label the label (<code>null</code> not permitted). * @param range the range (<code>null</code> not permitted). */ public MeterInterval(String label, Range range) { this(label, range, Color.YELLOW, new BasicStroke(2.0f), null); } /** * Creates a new interval. * * @param label the label (<code>null</code> not permitted). * @param range the range (<code>null</code> not permitted). * @param outlinePaint the outline paint (<code>null</code> permitted). * @param outlineStroke the outline stroke (<code>null</code> permitted). * @param backgroundPaint the background paint (<code>null</code> * permitted). */ public MeterInterval(String label, Range range, Paint outlinePaint, Stroke outlineStroke, Paint backgroundPaint) { if (label == null) { throw new IllegalArgumentException("Null 'label' argument."); } if (range == null) { throw new IllegalArgumentException("Null 'range' argument."); } this.label = label; this.range = range; this.outlinePaint = outlinePaint; this.outlineStroke = outlineStroke; this.backgroundPaint = backgroundPaint; } /** * Returns the label. * * @return The label (never <code>null</code>). */ public String getLabel() { return this.label; } /** * Returns the range. * * @return The range (never <code>null</code>). */ public Range getRange() { return this.range; } /** * Returns the background paint. If <code>null</code>, the background * should remain unfilled. * * @return The background paint (possibly <code>null</code>). */ public Paint getBackgroundPaint() { return this.backgroundPaint; } /** * Returns the outline paint. * * @return The outline paint (possibly <code>null</code>). */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Returns the outline stroke. * * @return The outline stroke (possibly <code>null</code>). */ public Stroke getOutlineStroke() { return this.outlineStroke; } /** * Checks this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof MeterInterval)) { return false; } MeterInterval that = (MeterInterval) obj; if (!this.label.equals(that.label)) { return false; } if (!this.range.equals(that.range)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!ObjectUtilities.equal(this.outlineStroke, that.outlineStroke)) { return false; } if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { return false; } return true; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writeStroke(this.outlineStroke, stream); SerialUtilities.writePaint(this.backgroundPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.outlinePaint = SerialUtilities.readPaint(stream); this.outlineStroke = SerialUtilities.readStroke(stream); this.backgroundPaint = SerialUtilities.readPaint(stream); } }
7,120
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DatasetRenderingOrder.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/DatasetRenderingOrder.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * DatasetRenderingOrder.java * -------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 02-May-2003 : Version 1 (DG); * 02-Jun-2004 : Changed 'STANDARD' --> 'FORWARD' (DG); * 21-Nov-2007 : Implemented hashCode() (DG); * */ package org.jfree.chart.plot; /** * Defines the tokens that indicate the rendering order for datasets in a * {@link org.jfree.chart.plot.CategoryPlot} or an * {@link org.jfree.chart.plot.XYPlot}. */ public enum DatasetRenderingOrder { /** * Render datasets in the order 0, 1, 2, ..., N-1, where N is the number * of datasets. */ FORWARD("DatasetRenderingOrder.FORWARD"), /** * Render datasets in the order N-1, N-2, ..., 2, 1, 0, where N is the * number of datasets. */ REVERSE("DatasetRenderingOrder.REVERSE"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private DatasetRenderingOrder(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string (never <code>null</code>). */ @Override public String toString() { return this.name; } }
2,613
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
Pannable.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/Pannable.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * Pannable.java * ------------- * * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: Ulrich Voigt - patch 2686040; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 19-Mar-2009 : Version 1, with modifications from patch by UV (DG); * */ package org.jfree.chart.plot; import java.awt.geom.Point2D; import org.jfree.chart.ChartPanel; /** * An interface that the {@link ChartPanel} class uses to communicate with * plots that support panning. * * @since 1.0.13 */ public interface Pannable { /** * Returns the orientation of the plot. * * @return The orientation (never <code>null</code>). */ public PlotOrientation getOrientation(); /** * Evaluates if the domain axis can be panned. * * @return <code>true</code> if the domain axis is pannable. */ public boolean isDomainPannable(); /** * Evaluates if the range axis can be panned. * * @return <code>true</code> if the range axis is pannable. */ public boolean isRangePannable(); /** * Pans the domain axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. */ public void panDomainAxes(double percent, PlotRenderingInfo info, Point2D source); /** * Pans the range axes by the specified percentage. * * @param percent the distance to pan (as a percentage of the axis length). * @param info the plot info * @param source the source point where the pan action started. */ public void panRangeAxes(double percent, PlotRenderingInfo info, Point2D source); }
3,080
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CenterTextMode.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/CenterTextMode.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * CenterTextMode.java * ------------------- * (C) Copyright 2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-Feb-2014 : Version 1 (DG); * */ package org.jfree.chart.plot; /** * The mode for the center text on a {@link RingPlot}. * * @since 1.0.18 */ public enum CenterTextMode { /** A fixed text item */ FIXED, /** A value item (taken from the first item in the dataset). */ VALUE, /** No center text. */ NONE }
1,824
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieLabelRecord.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PieLabelRecord.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * PieLabelRecord.java * ------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Mar-2004 : Version 1 (DG); * 14-Jun-2007 : Implemented Serializable, updated API docs (DG); * 21-Nov-2007 : Implemented equals() to shut up FindBugs (DG); * */ package org.jfree.chart.plot; import java.io.Serializable; import org.jfree.chart.text.TextBox; /** * A structure that retains information about the label for a section in a pie * chart. */ public class PieLabelRecord implements Comparable, Serializable { /** The section key. */ private Comparable key; /** The angle of the centre of the section (in radians). */ private double angle; /** The base y-coordinate. */ private double baseY; /** The allocated y-coordinate. */ private double allocatedY; /** The label. */ private TextBox label; /** The label height. */ private double labelHeight; /** The gap. */ private double gap; /** The link percent. */ private double linkPercent; /** * Creates a new record. * * @param key the section key. * @param angle the angle to the middle of the section (in radians). * @param baseY the base y-coordinate. * @param label the section label. * @param labelHeight the label height (in Java2D units). * @param gap the offset to the left. * @param linkPercent the link percent. */ public PieLabelRecord(Comparable key, double angle, double baseY, TextBox label, double labelHeight, double gap, double linkPercent) { this.key = key; this.angle = angle; this.baseY = baseY; this.allocatedY = baseY; this.label = label; this.labelHeight = labelHeight; this.gap = gap; this.linkPercent = linkPercent; } /** * Returns the base y-coordinate. This is where the label will appear if * there is no overlapping of labels. * * @return The base y-coordinate. */ public double getBaseY() { return this.baseY; } /** * Sets the base y-coordinate. * * @param base the base y-coordinate. */ public void setBaseY(double base) { this.baseY = base; } /** * Returns the lower bound of the label. * * @return The lower bound. */ public double getLowerY() { return this.allocatedY - this.labelHeight / 2.0; } /** * Returns the upper bound of the label. * * @return The upper bound. */ public double getUpperY() { return this.allocatedY + this.labelHeight / 2.0; } /** * Returns the angle of the middle of the section, in radians. * * @return The angle, in radians. */ public double getAngle() { return this.angle; } /** * Returns the key for the section that the label applies to. * * @return The key. */ public Comparable getKey() { return this.key; } /** * Returns the label. * * @return The label. */ public TextBox getLabel() { return this.label; } /** * Returns the label height (you could derive this from the label itself, * but we cache the value so it can be retrieved quickly). * * @return The label height (in Java2D units). */ public double getLabelHeight() { return this.labelHeight; } /** * Returns the allocated y-coordinate. * * @return The allocated y-coordinate. */ public double getAllocatedY() { return this.allocatedY; } /** * Sets the allocated y-coordinate. * * @param y the y-coordinate. */ public void setAllocatedY(double y) { this.allocatedY = y; } /** * Returns the gap. * * @return The gap. */ public double getGap() { return this.gap; } /** * Returns the link percent. * * @return The link percent. */ public double getLinkPercent() { return this.linkPercent; } /** * Compares this object to an arbitrary object. * * @param obj the object to compare against. * * @return An integer that specifies the relative order of the two objects. */ @Override public int compareTo(Object obj) { int result = 0; if (obj instanceof PieLabelRecord) { PieLabelRecord plr = (PieLabelRecord) obj; if (this.baseY < plr.baseY) { result = -1; } else if (this.baseY > plr.baseY) { result = 1; } } return result; } /** * Tests this record for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof PieLabelRecord)) { return false; } PieLabelRecord that = (PieLabelRecord) obj; if (!this.key.equals(that.key)) { return false; } if (this.angle != that.angle) { return false; } if (this.gap != that.gap) { return false; } if (this.allocatedY != that.allocatedY) { return false; } if (this.baseY != that.baseY) { return false; } if (this.labelHeight != that.labelHeight) { return false; } if (this.linkPercent != that.linkPercent) { return false; } if (!this.label.equals(that.label)) { return false; } return true; } /** * Returns a string describing the object. This is used for debugging only. * * @return A string. */ @Override public String toString() { return this.baseY + ", " + this.key.toString(); } }
7,479
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PlotOrientation.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PlotOrientation.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * PlotOrientation.java * -------------------- * (C) Copyright 2003-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 02-May-2003 : Version 1 (DG); * 17-Jul-2003 : Added readResolve() method (DG); * 21-Nov-2007 : Implemented hashCode() (DG); * */ package org.jfree.chart.plot; /** * Used to indicate the orientation (horizontal or vertical) of a 2D plot. */ public enum PlotOrientation { /** For a plot where the range axis is horizontal. */ HORIZONTAL("PlotOrientation.HORIZONTAL"), /** For a plot where the range axis is vertical. */ VERTICAL("PlotOrientation.VERTICAL"); /** The name. */ private String name; /** * Private constructor. * * @param name the name. */ private PlotOrientation(String name) { this.name = name; } /** * Returns a string representing the object. * * @return The string. */ @Override public String toString() { return this.name; } }
2,339
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MultiplePiePlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/MultiplePiePlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * MultiplePiePlot.java * -------------------- * (C) Copyright 2004-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Brian Cabana (patch 1943021); * * Changes * ------- * 29-Jan-2004 : Version 1 (DG); * 31-Mar-2004 : Added setPieIndex() call during drawing (DG); * 20-Apr-2005 : Small change for update to LegendItem constructors (DG); * 05-May-2005 : Updated draw() method parameters (DG); * 16-Jun-2005 : Added get/setDataset() and equals() methods (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 06-Apr-2006 : Fixed bug 1190647 - legend and section colors not consistent * when aggregation limit is specified (DG); * 27-Sep-2006 : Updated draw() method for deprecated code (DG); * 17-Jan-2007 : Updated prefetchSectionPaints() to check settings in * underlying PiePlot (DG); * 17-May-2007 : Added argument check to setPieChart() (DG); * 18-May-2007 : Set dataset for LegendItem (DG); * 18-Apr-2008 : In the constructor, register the plot as a dataset listener - * see patch 1943021 from Brian Cabana (DG); * 30-Dec-2008 : Added legendItemShape field, and fixed cloning bug (DG); * 09-Jan-2009 : See ignoreNullValues to true for sub-chart (DG); * 01-Jun-2009 : Set series key in getLegendItems() (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * 10-Mar-2014 : Removed LegendItemCollection (DG); * */ package org.jfree.chart.plot; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jfree.chart.ChartRenderingInfo; import org.jfree.chart.JFreeChart; import org.jfree.chart.LegendItem; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.TableOrder; import org.jfree.chart.event.PlotChangeEvent; import org.jfree.chart.title.TextTitle; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.category.CategoryDataset; import org.jfree.data.category.CategoryToPieDataset; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetUtilities; import org.jfree.data.general.PieDataset; /** * A plot that displays multiple pie plots using data from a * {@link CategoryDataset}. */ public class MultiplePiePlot extends Plot implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = -355377800470807389L; /** The chart object that draws the individual pie charts. */ private JFreeChart pieChart; /** The dataset. */ private CategoryDataset dataset; /** The data extract order (by row or by column). */ private TableOrder dataExtractOrder; /** The pie section limit percentage. */ private double limit = 0.0; /** * The key for the aggregated items. * * @since 1.0.2 */ private Comparable aggregatedItemsKey; /** * The paint for the aggregated items. * * @since 1.0.2 */ private transient Paint aggregatedItemsPaint; /** * The colors to use for each section. * * @since 1.0.2 */ private transient Map<Comparable, Paint> sectionPaints; /** * The legend item shape (never null). * * @since 1.0.12 */ private transient Shape legendItemShape; /** * Creates a new plot with no data. */ public MultiplePiePlot() { this(null); } /** * Creates a new plot. * * @param dataset the dataset (<code>null</code> permitted). */ public MultiplePiePlot(CategoryDataset dataset) { super(); setDataset(dataset); PiePlot piePlot = new PiePlot(null); piePlot.setIgnoreNullValues(true); this.pieChart = new JFreeChart(piePlot); this.pieChart.removeLegend(); this.dataExtractOrder = TableOrder.BY_COLUMN; this.pieChart.setBackgroundPaint(null); TextTitle seriesTitle = new TextTitle("Series Title", new Font("SansSerif", Font.BOLD, 12)); seriesTitle.setPosition(RectangleEdge.BOTTOM); this.pieChart.setTitle(seriesTitle); this.aggregatedItemsKey = "Other"; this.aggregatedItemsPaint = Color.LIGHT_GRAY; this.sectionPaints = new HashMap<Comparable, Paint>(); this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0); } /** * Returns the dataset used by the plot. * * @return The dataset (possibly <code>null</code>). */ public CategoryDataset getDataset() { return this.dataset; } /** * Sets the dataset used by the plot and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param dataset the dataset (<code>null</code> permitted). */ public void setDataset(CategoryDataset dataset) { // if there is an existing dataset, remove the plot from the list of // change listeners... if (this.dataset != null) { this.dataset.removeChangeListener(this); } // set the new dataset, and register the chart as a change listener... this.dataset = dataset; if (dataset != null) { setDatasetGroup(dataset.getGroup()); dataset.addChangeListener(this); } // send a dataset change event to self to trigger plot change event datasetChanged(new DatasetChangeEvent(this, dataset)); } /** * Returns the pie chart that is used to draw the individual pie plots. * Note that there are some attributes on this chart instance that will * be ignored at rendering time (for example, legend item settings). * * @return The pie chart (never <code>null</code>). * * @see #setPieChart(JFreeChart) */ public JFreeChart getPieChart() { return this.pieChart; } /** * Sets the chart that is used to draw the individual pie plots. The * chart's plot must be an instance of {@link PiePlot}. * * @param pieChart the pie chart (<code>null</code> not permitted). * * @see #getPieChart() */ public void setPieChart(JFreeChart pieChart) { if (pieChart == null) { throw new IllegalArgumentException("Null 'pieChart' argument."); } if (!(pieChart.getPlot() instanceof PiePlot)) { throw new IllegalArgumentException("The 'pieChart' argument must " + "be a chart based on a PiePlot."); } this.pieChart = pieChart; fireChangeEvent(); } /** * Returns the data extract order (by row or by column). * * @return The data extract order (never <code>null</code>). */ public TableOrder getDataExtractOrder() { return this.dataExtractOrder; } /** * Sets the data extract order (by row or by column) and sends a * {@link PlotChangeEvent} to all registered listeners. * * @param order the order (<code>null</code> not permitted). */ public void setDataExtractOrder(TableOrder order) { if (order == null) { throw new IllegalArgumentException("Null 'order' argument"); } this.dataExtractOrder = order; fireChangeEvent(); } /** * Returns the limit (as a percentage) below which small pie sections are * aggregated. * * @return The limit percentage. */ public double getLimit() { return this.limit; } /** * Sets the limit below which pie sections are aggregated. * Set this to 0.0 if you don't want any aggregation to occur. * * @param limit the limit percent. */ public void setLimit(double limit) { this.limit = limit; fireChangeEvent(); } /** * Returns the key for aggregated items in the pie plots, if there are any. * The default value is "Other". * * @return The aggregated items key. * * @since 1.0.2 */ public Comparable getAggregatedItemsKey() { return this.aggregatedItemsKey; } /** * Sets the key for aggregated items in the pie plots. You must ensure * that this doesn't clash with any keys in the dataset. * * @param key the key (<code>null</code> not permitted). * * @since 1.0.2 */ public void setAggregatedItemsKey(Comparable key) { if (key == null) { throw new IllegalArgumentException("Null 'key' argument."); } this.aggregatedItemsKey = key; fireChangeEvent(); } /** * Returns the paint used to draw the pie section representing the * aggregated items. The default value is <code>Color.LIGHT_GRAY</code>. * * @return The paint. * * @since 1.0.2 */ public Paint getAggregatedItemsPaint() { return this.aggregatedItemsPaint; } /** * Sets the paint used to draw the pie section representing the aggregated * items and sends a {@link PlotChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @since 1.0.2 */ public void setAggregatedItemsPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.aggregatedItemsPaint = paint; fireChangeEvent(); } /** * Returns a short string describing the type of plot. * * @return The plot type. */ @Override public String getPlotType() { return "Multiple Pie Plot"; // TODO: need to fetch this from localised resources } /** * Returns the shape used for legend items. * * @return The shape (never <code>null</code>). * * @see #setLegendItemShape(Shape) * * @since 1.0.12 */ public Shape getLegendItemShape() { return this.legendItemShape; } /** * Sets the shape used for legend items and sends a {@link PlotChangeEvent} * to all registered listeners. * * @param shape the shape (<code>null</code> not permitted). * * @see #getLegendItemShape() * * @since 1.0.12 */ public void setLegendItemShape(Shape shape) { if (shape == null) { throw new IllegalArgumentException("Null 'shape' argument."); } this.legendItemShape = shape; fireChangeEvent(); } /** * Draws the plot on a Java 2D graphics device (such as the screen or a * printer). * * @param g2 the graphics device. * @param area the area within which the plot should be drawn. * @param anchor the anchor point (<code>null</code> permitted). * @param parentState the state from the parent plot, if there is one. * @param info collects info about the drawing. */ @Override public void draw(Graphics2D g2, Rectangle2D area, Point2D anchor, PlotState parentState, PlotRenderingInfo info) { // adjust the drawing area for the plot insets (if any)... RectangleInsets insets = getInsets(); insets.trim(area); drawBackground(g2, area); drawOutline(g2, area); // check that there is some data to display... if (DatasetUtilities.isEmptyOrNull(this.dataset)) { drawNoDataMessage(g2, area); return; } int pieCount; if (this.dataExtractOrder == TableOrder.BY_ROW) { pieCount = this.dataset.getRowCount(); } else { pieCount = this.dataset.getColumnCount(); } // the columns variable is always >= rows int displayCols = (int) Math.ceil(Math.sqrt(pieCount)); int displayRows = (int) Math.ceil((double) pieCount / (double) displayCols); // swap rows and columns to match plotArea shape if (displayCols > displayRows && area.getWidth() < area.getHeight()) { int temp = displayCols; displayCols = displayRows; displayRows = temp; } prefetchSectionPaints(); int x = (int) area.getX(); int y = (int) area.getY(); int width = ((int) area.getWidth()) / displayCols; int height = ((int) area.getHeight()) / displayRows; int row = 0; int column = 0; int diff = (displayRows * displayCols) - pieCount; int xoffset = 0; Rectangle rect = new Rectangle(); for (int pieIndex = 0; pieIndex < pieCount; pieIndex++) { rect.setBounds(x + xoffset + (width * column), y + (height * row), width, height); String title; if (this.dataExtractOrder == TableOrder.BY_ROW) { title = this.dataset.getRowKey(pieIndex).toString(); } else { title = this.dataset.getColumnKey(pieIndex).toString(); } this.pieChart.setTitle(title); PieDataset piedataset; PieDataset dd = new CategoryToPieDataset(this.dataset, this.dataExtractOrder, pieIndex); if (this.limit > 0.0) { piedataset = DatasetUtilities.createConsolidatedPieDataset( dd, this.aggregatedItemsKey, this.limit); } else { piedataset = dd; } PiePlot piePlot = (PiePlot) this.pieChart.getPlot(); piePlot.setDataset(piedataset); piePlot.setPieIndex(pieIndex); // update the section colors to match the global colors... for (int i = 0; i < piedataset.getItemCount(); i++) { Comparable key = piedataset.getKey(i); Paint p; if (key.equals(this.aggregatedItemsKey)) { p = this.aggregatedItemsPaint; } else { p = this.sectionPaints.get(key); } piePlot.setSectionPaint(key, p); } ChartRenderingInfo subinfo = null; if (info != null) { subinfo = new ChartRenderingInfo(); } this.pieChart.draw(g2, rect, subinfo); if (info != null) { info.getOwner().getEntityCollection().addAll( subinfo.getEntityCollection()); info.addSubplotInfo(subinfo.getPlotInfo()); } ++column; if (column == displayCols) { column = 0; ++row; if (row == displayRows - 1 && diff != 0) { xoffset = (diff * width) / 2; } } } } /** * For each key in the dataset, check the <code>sectionPaints</code> * cache to see if a paint is associated with that key and, if not, * fetch one from the drawing supplier. These colors are cached so that * the legend and all the subplots use consistent colors. */ private void prefetchSectionPaints() { // pre-fetch the colors for each key...this is because the subplots // may not display every key, but we need the coloring to be // consistent... PiePlot piePlot = (PiePlot) getPieChart().getPlot(); if (this.dataExtractOrder == TableOrder.BY_ROW) { // column keys provide potential keys for individual pies for (int c = 0; c < this.dataset.getColumnCount(); c++) { Comparable key = this.dataset.getColumnKey(c); Paint p = piePlot.getSectionPaint(key); if (p == null) { p = this.sectionPaints.get(key); if (p == null) { p = getDrawingSupplier().getNextPaint(); } } this.sectionPaints.put(key, p); } } else { // row keys provide potential keys for individual pies for (int r = 0; r < this.dataset.getRowCount(); r++) { Comparable key = this.dataset.getRowKey(r); Paint p = piePlot.getSectionPaint(key); if (p == null) { p = this.sectionPaints.get(key); if (p == null) { p = getDrawingSupplier().getNextPaint(); } } this.sectionPaints.put(key, p); } } } /** * Returns a collection of legend items for the pie chart. * * @return The legend items. */ @Override public List<LegendItem> getLegendItems() { List<LegendItem> result = new ArrayList<LegendItem>(); if (this.dataset == null) { return result; } List<Comparable> keys = null; prefetchSectionPaints(); if (this.dataExtractOrder == TableOrder.BY_ROW) { keys = this.dataset.getColumnKeys(); } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) { keys = this.dataset.getRowKeys(); } if (keys == null) { return result; } int section = 0; for (Comparable key : keys) { String label = key.toString(); // TODO: use a generator here String description = label; Paint paint = this.sectionPaints.get(key); LegendItem item = new LegendItem(label, description, null, null, getLegendItemShape(), paint, Plot.DEFAULT_OUTLINE_STROKE, paint); item.setSeriesKey(key); item.setSeriesIndex(section); item.setDataset(getDataset()); result.add(item); section++; } if (this.limit > 0.0) { LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(), this.aggregatedItemsKey.toString(), null, null, getLegendItemShape(), this.aggregatedItemsPaint, Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint); result.add(a); } return result; } /** * Tests this plot for equality with an arbitrary object. Note that the * plot's dataset is not considered in the equality test. * * @param obj the object (<code>null</code> permitted). * * @return <code>true</code> if this plot is equal to <code>obj</code>, and * <code>false</code> otherwise. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof MultiplePiePlot)) { return false; } MultiplePiePlot that = (MultiplePiePlot) obj; if (this.dataExtractOrder != that.dataExtractOrder) { return false; } if (this.limit != that.limit) { return false; } if (!this.aggregatedItemsKey.equals(that.aggregatedItemsKey)) { return false; } if (!PaintUtilities.equal(this.aggregatedItemsPaint, that.aggregatedItemsPaint)) { return false; } if (!ObjectUtilities.equal(this.pieChart, that.pieChart)) { return false; } if (!ShapeUtilities.equal(this.legendItemShape, that.legendItemShape)) { return false; } if (!super.equals(obj)) { return false; } return true; } /** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException if some component of the plot does * not support cloning. */ @Override public Object clone() throws CloneNotSupportedException { MultiplePiePlot clone = (MultiplePiePlot) super.clone(); clone.pieChart = (JFreeChart) this.pieChart.clone(); clone.sectionPaints = new HashMap<Comparable, Paint>(this.sectionPaints); clone.legendItemShape = ShapeUtilities.clone(this.legendItemShape); return clone; } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.aggregatedItemsPaint, stream); SerialUtilities.writeShape(this.legendItemShape, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.aggregatedItemsPaint = SerialUtilities.readPaint(stream); this.legendItemShape = SerialUtilities.readShape(stream); this.sectionPaints = new HashMap<Comparable, Paint>(); } }
23,083
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
RingPlot.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/RingPlot.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * RingPlot.java * ------------- * (C) Copyright 2004-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limtied); * Contributor(s): Christoph Beck (bug 2121818); * * Changes * ------- * 08-Nov-2004 : Version 1 (DG); * 22-Feb-2005 : Renamed DonutPlot --> RingPlot (DG); * 06-Jun-2005 : Added default constructor and fixed equals() method to handle * GradientPaint (DG); * ------------- JFREECHART 1.0.x --------------------------------------------- * 20-Dec-2005 : Fixed problem with entity shape (bug 1386328) (DG); * 27-Sep-2006 : Updated drawItem() method for new lookup methods (DG); * 12-Oct-2006 : Added configurable section depth (DG); * 14-Feb-2007 : Added notification in setSectionDepth() method (DG); * 23-Sep-2008 : Fix for bug 2121818 by Christoph Beck (DG); * 13-Jul-2009 : Added support for shadow generator (DG); * 11-Oct-2011 : Check sectionOutlineVisible - bug 3237879 (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * 28-Feb-2014 : Add center text feature (DG); * */ package org.jfree.chart.plot; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.GeneralPath; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.DecimalFormat; import java.text.Format; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.Rotation; import org.jfree.chart.util.ShapeUtilities; import org.jfree.chart.util.UnitType; import org.jfree.chart.entity.EntityCollection; import org.jfree.chart.entity.PieSectionEntity; import org.jfree.chart.labels.PieToolTipGenerator; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.urls.PieURLGenerator; import org.jfree.chart.util.LineUtilities; import org.jfree.chart.util.ParamChecks; import org.jfree.chart.util.SerialUtilities; import org.jfree.data.general.PieDataset; /** * A customised pie plot that leaves a hole in the middle. */ public class RingPlot extends PiePlot implements Cloneable, Serializable { /** For serialization. */ private static final long serialVersionUID = 1556064784129676620L; /** The center text mode. */ private CenterTextMode centerTextMode = CenterTextMode.NONE; /** * Text to display in the middle of the chart (used for * CenterTextMode.FIXED). */ private String centerText; /** * The formatter used when displaying the first data value from the * dataset (CenterTextMode.VALUE). */ private Format centerTextFormatter = new DecimalFormat("0.00"); /** The font used to display the center text. */ private Font centerTextFont; /** The color used to display the center text. */ private Color centerTextColor; /** * A flag that controls whether or not separators are drawn between the * sections of the chart. */ private boolean separatorsVisible; /** The stroke used to draw separators. */ private transient Stroke separatorStroke; /** The paint used to draw separators. */ private transient Paint separatorPaint; /** * The length of the inner separator extension (as a percentage of the * depth of the sections). */ private double innerSeparatorExtension; /** * The length of the outer separator extension (as a percentage of the * depth of the sections). */ private double outerSeparatorExtension; /** * The depth of the section as a percentage of the diameter. */ private double sectionDepth; /** * Creates a new plot with a <code>null</code> dataset. */ public RingPlot() { this(null); } /** * Creates a new plot for the specified dataset. * * @param dataset the dataset (<code>null</code> permitted). */ public RingPlot(PieDataset dataset) { super(dataset); this.centerTextMode = CenterTextMode.NONE; this.centerText = null; this.centerTextFormatter = new DecimalFormat("0.00"); this.centerTextFont = DEFAULT_LABEL_FONT; this.centerTextColor = Color.BLACK; this.separatorsVisible = true; this.separatorStroke = new BasicStroke(0.5f); this.separatorPaint = Color.GRAY; this.innerSeparatorExtension = 0.20; // 20% this.outerSeparatorExtension = 0.20; // 20% this.sectionDepth = 0.20; // 20% } /** * Returns the mode for displaying text in the center of the plot. The * default value is {@link CenterTextMode#NONE} therefore no text * will be displayed by default. * * @return The mode (never <code>null</code>). * * @since 1.0.18 */ public CenterTextMode getCenterTextMode() { return this.centerTextMode; } /** * Sets the mode for displaying text in the center of the plot and sends * a change event to all registered listeners. For * {@link CenterTextMode#FIXED}, the display text will come from the * <code>centerText</code> attribute (see {@link #getCenterText()}). * For {@link CenterTextMode#VALUE}, the center text will be the value from * the first section in the dataset. * * @param mode the mode (<code>null</code> not permitted). * * @since 1.0.18 */ public void setCenterTextMode(CenterTextMode mode) { ParamChecks.nullNotPermitted(mode, "mode"); this.centerTextMode = mode; fireChangeEvent(); } /** * Returns the text to display in the center of the plot when the mode * is {@link CenterTextMode#FIXED}. * * @return The text (possibly <code>null</code>). * * @since 1.0.18. */ public String getCenterText() { return this.centerText; } /** * Sets the text to display in the center of the plot and sends a * change event to all registered listeners. If the text is set to * <code>null</code>, no text will be displayed. * * @param text the text (<code>null</code> permitted). * * @since 1.0.18 */ public void setCenterText(String text) { this.centerText = text; fireChangeEvent(); } /** * Returns the formatter used to format the center text value for the mode * {@link CenterTextMode#VALUE}. The default value is * <code>DecimalFormat("0.00");</code>. * * @return The formatter (never <code>null</code>). * * @since 1.0.18 */ public Format getCenterTextFormatter() { return this.centerTextFormatter; } /** * Sets the formatter used to format the center text value and sends a * change event to all registered listeners. * * @param formatter the formatter (<code>null</code> not permitted). * * @since 1.0.18 */ public void setCenterTextFormatter(Format formatter) { ParamChecks.nullNotPermitted(formatter, "formatter"); this.centerTextFormatter = formatter; } /** * Returns the font used to display the center text. The default value * is {@link PiePlot#DEFAULT_LABEL_FONT}. * * @return The font (never <code>null</code>). * * @since 1.0.18 */ public Font getCenterTextFont() { return this.centerTextFont; } /** * Sets the font used to display the center text and sends a change event * to all registered listeners. * * @param font the font (<code>null</code> not permitted). * * @since 1.0.18 */ public void setCenterTextFont(Font font) { ParamChecks.nullNotPermitted(font, "font"); this.centerTextFont = font; fireChangeEvent(); } /** * Returns the color for the center text. The default value is * <code>Color.BLACK</code>. * * @return The color (never <code>null</code>). * * @since 1.0.18 */ public Color getCenterTextColor() { return this.centerTextColor; } /** * Sets the color for the center text and sends a change event to all * registered listeners. * * @param color the color (<code>null</code> not permitted). * * @since 1.0.18 */ public void setCenterTextColor(Color color) { ParamChecks.nullNotPermitted(color, "color"); this.centerTextColor = color; fireChangeEvent(); } /** * Returns a flag that indicates whether or not separators are drawn between * the sections in the chart. * * @return A boolean. * * @see #setSeparatorsVisible(boolean) */ public boolean getSeparatorsVisible() { return this.separatorsVisible; } /** * Sets the flag that controls whether or not separators are drawn between * the sections in the chart, and sends a change event to all registered * listeners. * * @param visible the flag. * * @see #getSeparatorsVisible() */ public void setSeparatorsVisible(boolean visible) { this.separatorsVisible = visible; fireChangeEvent(); } /** * Returns the separator stroke. * * @return The stroke (never <code>null</code>). * * @see #setSeparatorStroke(Stroke) */ public Stroke getSeparatorStroke() { return this.separatorStroke; } /** * Sets the stroke used to draw the separator between sections and sends * a change event to all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getSeparatorStroke() */ public void setSeparatorStroke(Stroke stroke) { ParamChecks.nullNotPermitted(stroke, "stroke"); this.separatorStroke = stroke; fireChangeEvent(); } /** * Returns the separator paint. * * @return The paint (never <code>null</code>). * * @see #setSeparatorPaint(Paint) */ public Paint getSeparatorPaint() { return this.separatorPaint; } /** * Sets the paint used to draw the separator between sections and sends a * change event to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getSeparatorPaint() */ public void setSeparatorPaint(Paint paint) { ParamChecks.nullNotPermitted(paint, "paint"); this.separatorPaint = paint; fireChangeEvent(); } /** * Returns the length of the inner extension of the separator line that * is drawn between sections, expressed as a percentage of the depth of * the section. * * @return The inner separator extension (as a percentage). * * @see #setInnerSeparatorExtension(double) */ public double getInnerSeparatorExtension() { return this.innerSeparatorExtension; } /** * Sets the length of the inner extension of the separator line that is * drawn between sections, as a percentage of the depth of the * sections, and sends a change event to all registered listeners. * * @param percent the percentage. * * @see #getInnerSeparatorExtension() * @see #setOuterSeparatorExtension(double) */ public void setInnerSeparatorExtension(double percent) { this.innerSeparatorExtension = percent; fireChangeEvent(); } /** * Returns the length of the outer extension of the separator line that * is drawn between sections, expressed as a percentage of the depth of * the section. * * @return The outer separator extension (as a percentage). * * @see #setOuterSeparatorExtension(double) */ public double getOuterSeparatorExtension() { return this.outerSeparatorExtension; } /** * Sets the length of the outer extension of the separator line that is * drawn between sections, as a percentage of the depth of the * sections, and sends a change event to all registered listeners. * * @param percent the percentage. * * @see #getOuterSeparatorExtension() */ public void setOuterSeparatorExtension(double percent) { this.outerSeparatorExtension = percent; fireChangeEvent(); } /** * Returns the depth of each section, expressed as a percentage of the * plot radius. * * @return The depth of each section. * * @see #setSectionDepth(double) * @since 1.0.3 */ public double getSectionDepth() { return this.sectionDepth; } /** * The section depth is given as percentage of the plot radius. * Specifying 1.0 results in a straightforward pie chart. * * @param sectionDepth the section depth. * * @see #getSectionDepth() * @since 1.0.3 */ public void setSectionDepth(double sectionDepth) { this.sectionDepth = sectionDepth; fireChangeEvent(); } /** * Initialises the plot state (which will store the total of all dataset * values, among other things). This method is called once at the * beginning of each drawing. * * @param g2 the graphics device. * @param plotArea the plot area (<code>null</code> not permitted). * @param plot the plot. * @param index the secondary index (<code>null</code> for primary * renderer). * @param info collects chart rendering information for return to caller. * * @return A state object (maintains state information relevant to one * chart drawing). */ @Override public PiePlotState initialise(Graphics2D g2, Rectangle2D plotArea, PiePlot plot, Integer index, PlotRenderingInfo info) { PiePlotState state = super.initialise(g2, plotArea, plot, index, info); state.setPassesRequired(3); return state; } /** * Draws a single data item. * * @param g2 the graphics device (<code>null</code> not permitted). * @param section the section index. * @param dataArea the data plot area. * @param state state information for one chart. * @param currentPass the current pass index. */ @Override protected void drawItem(Graphics2D g2, int section, Rectangle2D dataArea, PiePlotState state, int currentPass) { PieDataset dataset = getDataset(); Number n = dataset.getValue(section); if (n == null) { return; } double value = n.doubleValue(); double angle1 = 0.0; double angle2 = 0.0; Rotation direction = getDirection(); if (direction == Rotation.CLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 - value / state.getTotal() * 360.0; } else if (direction == Rotation.ANTICLOCKWISE) { angle1 = state.getLatestAngle(); angle2 = angle1 + value / state.getTotal() * 360.0; } else { throw new IllegalStateException("Rotation type not recognised."); } double angle = (angle2 - angle1); if (Math.abs(angle) > getMinimumArcAngleToDraw()) { Comparable key = getSectionKey(section); double ep = 0.0; double mep = getMaximumExplodePercent(); if (mep > 0.0) { ep = getExplodePercent(key) / mep; } Rectangle2D arcBounds = getArcBounds(state.getPieArea(), state.getExplodedPieArea(), angle1, angle, ep); Arc2D.Double arc = new Arc2D.Double(arcBounds, angle1, angle, Arc2D.OPEN); // create the bounds for the inner arc double depth = this.sectionDepth / 2.0; RectangleInsets s = new RectangleInsets(UnitType.RELATIVE, depth, depth, depth, depth); Rectangle2D innerArcBounds = new Rectangle2D.Double(); innerArcBounds.setRect(arcBounds); s.trim(innerArcBounds); // calculate inner arc in reverse direction, for later // GeneralPath construction Arc2D.Double arc2 = new Arc2D.Double(innerArcBounds, angle1 + angle, -angle, Arc2D.OPEN); GeneralPath path = new GeneralPath(); path.moveTo((float) arc.getStartPoint().getX(), (float) arc.getStartPoint().getY()); path.append(arc.getPathIterator(null), false); path.append(arc2.getPathIterator(null), true); path.closePath(); Line2D separator = new Line2D.Double(arc2.getEndPoint(), arc.getStartPoint()); if (currentPass == 0) { Paint shadowPaint = getShadowPaint(); double shadowXOffset = getShadowXOffset(); double shadowYOffset = getShadowYOffset(); if (shadowPaint != null && getShadowGenerator() == null) { Shape shadowArc = ShapeUtilities.createTranslatedShape( path, (float) shadowXOffset, (float) shadowYOffset); g2.setPaint(shadowPaint); g2.fill(shadowArc); } } else if (currentPass == 1) { Paint paint = lookupSectionPaint(key); g2.setPaint(paint); g2.fill(path); Paint outlinePaint = lookupSectionOutlinePaint(key); Stroke outlineStroke = lookupSectionOutlineStroke(key); if (getSectionOutlinesVisible() && outlinePaint != null && outlineStroke != null) { g2.setPaint(outlinePaint); g2.setStroke(outlineStroke); g2.draw(path); } if (section == 0) { String nstr = null; if (this.centerTextMode.equals(CenterTextMode.VALUE)) { nstr = this.centerTextFormatter.format(n); } else if (this.centerTextMode.equals(CenterTextMode.FIXED)) { nstr = this.centerText; } if (nstr != null) { g2.setFont(this.centerTextFont); g2.setPaint(this.centerTextColor); TextUtilities.drawAlignedString(nstr, g2, (float) dataArea.getCenterX(), (float) dataArea.getCenterY(), TextAnchor.CENTER); } } // add an entity for the pie section if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { String tip = null; PieToolTipGenerator toolTipGenerator = getToolTipGenerator(); if (toolTipGenerator != null) { tip = toolTipGenerator.generateToolTip(dataset, key); } String url = null; PieURLGenerator urlGenerator = getURLGenerator(); if (urlGenerator != null) { url = urlGenerator.generateURL(dataset, key, getPieIndex()); } PieSectionEntity entity = new PieSectionEntity(path, dataset, getPieIndex(), section, key, tip, url); entities.add(entity); } } } else if (currentPass == 2) { if (this.separatorsVisible) { Line2D extendedSeparator = LineUtilities.extendLine( separator, this.innerSeparatorExtension, this.outerSeparatorExtension); g2.setStroke(this.separatorStroke); g2.setPaint(this.separatorPaint); g2.draw(extendedSeparator); } } } state.setLatestAngle(angle2); } /** * This method overrides the default value for cases where the ring plot * is very thin. This fixes bug 2121818. * * @return The label link depth, as a percentage of the plot's radius. */ @Override protected double getLabelLinkDepth() { return Math.min(super.getLabelLinkDepth(), getSectionDepth() / 2); } /** * Tests this plot for equality with an arbitrary object. * * @param obj the object to test against (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof RingPlot)) { return false; } RingPlot that = (RingPlot) obj; if (!this.centerTextMode.equals(that.centerTextMode)) { return false; } if (!ObjectUtilities.equal(this.centerText, that.centerText)) { return false; } if (!this.centerTextFormatter.equals(that.centerTextFormatter)) { return false; } if (!this.centerTextFont.equals(that.centerTextFont)) { return false; } if (!this.centerTextColor.equals(that.centerTextColor)) { return false; } if (this.separatorsVisible != that.separatorsVisible) { return false; } if (!ObjectUtilities.equal(this.separatorStroke, that.separatorStroke)) { return false; } if (!PaintUtilities.equal(this.separatorPaint, that.separatorPaint)) { return false; } if (this.innerSeparatorExtension != that.innerSeparatorExtension) { return false; } if (this.outerSeparatorExtension != that.outerSeparatorExtension) { return false; } if (this.sectionDepth != that.sectionDepth) { return false; } return super.equals(obj); } /** * Creates a new line by extending an existing line. * * @param line the line (<code>null</code> not permitted). * @param startPercent the amount to extend the line at the start point * end. * @param endPercent the amount to extend the line at the end point end. * * @return A new line. */ private Line2D extendLine(Line2D line, double startPercent, double endPercent) { ParamChecks.nullNotPermitted(line, "line"); double x1 = line.getX1(); double x2 = line.getX2(); double deltaX = x2 - x1; double y1 = line.getY1(); double y2 = line.getY2(); double deltaY = y2 - y1; x1 = x1 - (startPercent * deltaX); y1 = y1 - (startPercent * deltaY); x2 = x2 + (endPercent * deltaX); y2 = y2 + (endPercent * deltaY); return new Line2D.Double(x1, y1, x2, y2); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writeStroke(this.separatorStroke, stream); SerialUtilities.writePaint(this.separatorPaint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.separatorStroke = SerialUtilities.readStroke(stream); this.separatorPaint = SerialUtilities.readPaint(stream); } }
26,007
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PiePlotState.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/PiePlotState.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * PiePlotState.java * ----------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 06-Mar-2004 : Version 1 (DG); * */ package org.jfree.chart.plot; import java.awt.geom.Rectangle2D; import org.jfree.chart.renderer.RendererState; /** * A renderer state. */ public class PiePlotState extends RendererState { /** The number of passes required by the renderer. */ private int passesRequired; /** The total of the values in the dataset. */ private double total; /** The latest angle. */ private double latestAngle; /** The exploded pie area. */ private Rectangle2D explodedPieArea; /** The pie area. */ private Rectangle2D pieArea; /** The center of the pie in Java 2D coordinates. */ private double pieCenterX; /** The center of the pie in Java 2D coordinates. */ private double pieCenterY; /** The vertical pie radius. */ private double pieHRadius; /** The horizontal pie radius. */ private double pieWRadius; /** The link area. */ private Rectangle2D linkArea; /** * Creates a new object for recording temporary state information for a * renderer. * * @param info the plot rendering info. */ public PiePlotState(PlotRenderingInfo info) { super(info); this.passesRequired = 1; this.total = 0.0; } /** * Returns the number of passes required by the renderer. * * @return The number of passes. */ public int getPassesRequired() { return this.passesRequired; } /** * Sets the number of passes required by the renderer. * * @param passes the passes. */ public void setPassesRequired(int passes) { this.passesRequired = passes; } /** * Returns the total of the values in the dataset. * * @return The total. */ public double getTotal() { return this.total; } /** * Sets the total. * * @param total the total. */ public void setTotal(double total) { this.total = total; } /** * Returns the latest angle. * * @return The latest angle. */ public double getLatestAngle() { return this.latestAngle; } /** * Sets the latest angle. * * @param angle the angle. */ public void setLatestAngle(double angle) { this.latestAngle = angle; } /** * Returns the pie area. * * @return The pie area. */ public Rectangle2D getPieArea() { return this.pieArea; } /** * Sets the pie area. * * @param area the area. */ public void setPieArea(Rectangle2D area) { this.pieArea = area; } /** * Returns the exploded pie area. * * @return The exploded pie area. */ public Rectangle2D getExplodedPieArea() { return this.explodedPieArea; } /** * Sets the exploded pie area. * * @param area the area. */ public void setExplodedPieArea(Rectangle2D area) { this.explodedPieArea = area; } /** * Returns the x-coordinate of the center of the pie chart. * * @return The x-coordinate (in Java2D space). */ public double getPieCenterX() { return this.pieCenterX; } /** * Sets the x-coordinate of the center of the pie chart. * * @param x the x-coordinate (in Java2D space). */ public void setPieCenterX(double x) { this.pieCenterX = x; } /** * Returns the y-coordinate (in Java2D space) of the center of the pie * chart. For the {@link PiePlot3D} class, we derive this from the top of * the pie. * * @return The y-coordinate (in Java2D space). */ public double getPieCenterY() { return this.pieCenterY; } /** * Sets the y-coordinate of the center of the pie chart. This method is * used by the plot and typically is not called directly by applications. * * @param y the y-coordinate (in Java2D space). */ public void setPieCenterY(double y) { this.pieCenterY = y; } /** * Returns the link area. This defines the "dog-leg" point for the label * linking lines. * * @return The link area. */ public Rectangle2D getLinkArea() { return this.linkArea; } /** * Sets the label link area. This defines the "dog-leg" point for the * label linking lines. * * @param area the area. */ public void setLinkArea(Rectangle2D area) { this.linkArea = area; } /** * Returns the vertical pie radius. * * @return The radius. */ public double getPieHRadius() { return this.pieHRadius; } /** * Sets the vertical pie radius. * * @param radius the radius. */ public void setPieHRadius(double radius) { this.pieHRadius = radius; } /** * Returns the horizontal pie radius. * * @return The radius. */ public double getPieWRadius() { return this.pieWRadius; } /** * Sets the horizontal pie radius. * * @param radius the radius. */ public void setPieWRadius(double radius) { this.pieWRadius = radius; } }
6,728
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialBackground.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/dial/DialBackground.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * DialBackground.java * ------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 16-Oct-2007 : The equals() method needs to call super.equals() (DG); * 15-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot.dial; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.ui.GradientPaintTransformer; import org.jfree.chart.ui.StandardGradientPaintTransformer; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.SerialUtilities; /** * A regular dial layer that can be used to draw the background for a dial. * * @since 1.0.7 */ public class DialBackground extends AbstractDialLayer implements DialLayer, Cloneable, PublicCloneable, Serializable { /** For serialization. */ static final long serialVersionUID = -9019069533317612375L; /** * The background paint. This field is transient because serialization * requires special handling. */ private transient Paint paint; /** * The transformer used when the background paint is an instance of * <code>GradientPaint</code>. */ private GradientPaintTransformer gradientPaintTransformer; /** * Creates a new instance of <code>DialBackground</code>. The * default background paint is <code>Color.WHITE</code>. */ public DialBackground() { this(Color.WHITE); } /** * Creates a new instance of <code>DialBackground</code>. The * * @param paint the paint (<code>null</code> not permitted). * * @throws IllegalArgumentException if <code>paint</code> is * <code>null</code>. */ public DialBackground(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; this.gradientPaintTransformer = new StandardGradientPaintTransformer(); } /** * Returns the paint used to fill the background. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint for the dial background and sends a * {@link DialLayerChangeEvent} to all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the transformer used to adjust the coordinates of any * <code>GradientPaint</code> instance used for the background paint. * * @return The transformer (never <code>null</code>). * * @see #setGradientPaintTransformer(GradientPaintTransformer) */ public GradientPaintTransformer getGradientPaintTransformer() { return this.gradientPaintTransformer; } /** * Sets the transformer used to adjust the coordinates of any * <code>GradientPaint</code> instance used for the background paint, and * sends a {@link DialLayerChangeEvent} to all registered listeners. * * @param t the transformer (<code>null</code> not permitted). * * @see #getGradientPaintTransformer() */ public void setGradientPaintTransformer(GradientPaintTransformer t) { if (t == null) { throw new IllegalArgumentException("Null 't' argument."); } this.gradientPaintTransformer = t; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns <code>true</code> to indicate that this layer should be * clipped within the dial window. * * @return <code>true</code>. */ @Override public boolean isClippedToWindow() { return true; } /** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Paint p = this.paint; if (p instanceof GradientPaint) { p = this.gradientPaintTransformer.transform((GradientPaint) p, view); } g2.setPaint(p); g2.fill(view); } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DialBackground)) { return false; } DialBackground that = (DialBackground) obj; if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!this.gradientPaintTransformer.equals( that.gradientPaintTransformer)) { return false; } return super.equals(obj); } /** * Returns a hash code for this instance. * * @return The hash code. */ @Override public int hashCode() { int result = 193; result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); result = 37 * result + this.gradientPaintTransformer.hashCode(); return result; } /** * Returns a clone of this instance. * * @return The clone. * * @throws CloneNotSupportedException if some attribute of this instance * cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); } }
8,646
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialValueIndicator.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/dial/DialValueIndicator.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * DialValueIndicator.java * ----------------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 17-Oct-2007 : Updated equals() (DG); * 24-Oct-2007 : Added default constructor and missing event notification (DG); * 09-Jun-2009 : Improved indicator resizing, fixes bug 2802014 (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot.dial; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.text.DecimalFormat; import java.text.NumberFormat; import org.jfree.chart.HashUtilities; import org.jfree.chart.ui.RectangleAnchor; import org.jfree.chart.ui.RectangleInsets; import org.jfree.chart.ui.Size2D; import org.jfree.chart.ui.TextAnchor; import org.jfree.chart.util.ObjectUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.text.TextUtilities; import org.jfree.chart.util.SerialUtilities; /** * A value indicator for a {@link DialPlot}. * * @since 1.0.7 */ public class DialValueIndicator extends AbstractDialLayer implements DialLayer, Cloneable, PublicCloneable, Serializable { /** For serialization. */ static final long serialVersionUID = 803094354130942585L; /** The dataset index. */ private int datasetIndex; /** The angle that defines the anchor point. */ private double angle; /** The radius that defines the anchor point. */ private double radius; /** The frame anchor. */ private RectangleAnchor frameAnchor; /** The template value. */ private Number templateValue; /** * A data value that will be formatted to determine the maximum size of * the indicator bounds. If this is null, the indicator bounds can grow * as large as necessary to contain the actual data value. * * @since 1.0.14 */ private Number maxTemplateValue; /** The formatter. */ private NumberFormat formatter; /** The font. */ private Font font; /** The paint. */ private transient Paint paint; /** The background paint. */ private transient Paint backgroundPaint; /** The outline stroke. */ private transient Stroke outlineStroke; /** The outline paint. */ private transient Paint outlinePaint; /** The insets. */ private RectangleInsets insets; /** The value anchor. */ private RectangleAnchor valueAnchor; /** The text anchor for displaying the value. */ private TextAnchor textAnchor; /** * Creates a new instance of <code>DialValueIndicator</code>. */ public DialValueIndicator() { this(0); } /** * Creates a new instance of <code>DialValueIndicator</code>. * * @param datasetIndex the dataset index. */ public DialValueIndicator(int datasetIndex) { this.datasetIndex = datasetIndex; this.angle = -90.0; this.radius = 0.3; this.frameAnchor = RectangleAnchor.CENTER; this.templateValue = 100.0; this.maxTemplateValue = null; this.formatter = new DecimalFormat("0.0"); this.font = new Font("Dialog", Font.BOLD, 14); this.paint = Color.BLACK; this.backgroundPaint = Color.WHITE; this.outlineStroke = new BasicStroke(1.0f); this.outlinePaint = Color.BLUE; this.insets = new RectangleInsets(4, 4, 4, 4); this.valueAnchor = RectangleAnchor.RIGHT; this.textAnchor = TextAnchor.CENTER_RIGHT; } /** * Returns the index of the dataset from which this indicator fetches its * current value. * * @return The dataset index. * * @see #setDatasetIndex(int) */ public int getDatasetIndex() { return this.datasetIndex; } /** * Sets the dataset index and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param index the index. * * @see #getDatasetIndex() */ public void setDatasetIndex(int index) { this.datasetIndex = index; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the angle for the anchor point. The angle is specified in * degrees using the same orientation as Java's <code>Arc2D</code> class. * * @return The angle (in degrees). * * @see #setAngle(double) */ public double getAngle() { return this.angle; } /** * Sets the angle for the anchor point and sends a * {@link DialLayerChangeEvent} to all registered listeners. * * @param angle the angle (in degrees). * * @see #getAngle() */ public void setAngle(double angle) { this.angle = angle; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the radius. * * @return The radius. * * @see #setRadius(double) */ public double getRadius() { return this.radius; } /** * Sets the radius and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param radius the radius. * * @see #getRadius() */ public void setRadius(double radius) { this.radius = radius; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the frame anchor. * * @return The frame anchor. * * @see #setFrameAnchor(RectangleAnchor) */ public RectangleAnchor getFrameAnchor() { return this.frameAnchor; } /** * Sets the frame anchor and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getFrameAnchor() */ public void setFrameAnchor(RectangleAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.frameAnchor = anchor; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the template value. * * @return The template value (never <code>null</code>). * * @see #setTemplateValue(Number) */ public Number getTemplateValue() { return this.templateValue; } /** * Sets the template value and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param value the value (<code>null</code> not permitted). * * @see #setTemplateValue(Number) */ public void setTemplateValue(Number value) { if (value == null) { throw new IllegalArgumentException("Null 'value' argument."); } this.templateValue = value; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the template value for the maximum size of the indicator * bounds. * * @return The template value (possibly <code>null</code>). * * @since 1.0.14 * * @see #setMaxTemplateValue(java.lang.Number) */ public Number getMaxTemplateValue() { return this.maxTemplateValue; } /** * Sets the template value for the maximum size of the indicator bounds * and sends a {@link DialLayerChangeEvent} to all registered listeners. * * @param value the value (<code>null</code> permitted). * * @since 1.0.14 * * @see #getMaxTemplateValue() */ public void setMaxTemplateValue(Number value) { this.maxTemplateValue = value; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the formatter used to format the value. * * @return The formatter (never <code>null</code>). * * @see #setNumberFormat(NumberFormat) */ public NumberFormat getNumberFormat() { return this.formatter; } /** * Sets the formatter used to format the value and sends a * {@link DialLayerChangeEvent} to all registered listeners. * * @param formatter the formatter (<code>null</code> not permitted). * * @see #getNumberFormat() */ public void setNumberFormat(NumberFormat formatter) { if (formatter == null) { throw new IllegalArgumentException("Null 'formatter' argument."); } this.formatter = formatter; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the font. * * @return The font (never <code>null</code>). * * @see #getFont() */ public Font getFont() { return this.font; } /** * Sets the font and sends a {@link DialLayerChangeEvent} to all registered * listeners. * * @param font the font (<code>null</code> not permitted). */ public void setFont(Font font) { if (font == null) { throw new IllegalArgumentException("Null 'font' argument."); } this.font = font; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the paint. * * @return The paint (never <code>null</code>). * * @see #setPaint(Paint) */ public Paint getPaint() { return this.paint; } /** * Sets the paint and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getPaint() */ public void setPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.paint = paint; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the background paint. * * @return The background paint. * * @see #setBackgroundPaint(Paint) */ public Paint getBackgroundPaint() { return this.backgroundPaint; } /** * Sets the background paint and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getBackgroundPaint() */ public void setBackgroundPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.backgroundPaint = paint; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the outline stroke. * * @return The outline stroke (never <code>null</code>). * * @see #setOutlineStroke(Stroke) */ public Stroke getOutlineStroke() { return this.outlineStroke; } /** * Sets the outline stroke and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getOutlineStroke() */ public void setOutlineStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.outlineStroke = stroke; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the outline paint. * * @return The outline paint (never <code>null</code>). * * @see #setOutlinePaint(Paint) */ public Paint getOutlinePaint() { return this.outlinePaint; } /** * Sets the outline paint and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getOutlinePaint() */ public void setOutlinePaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.outlinePaint = paint; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the insets. * * @return The insets (never <code>null</code>). * * @see #setInsets(RectangleInsets) */ public RectangleInsets getInsets() { return this.insets; } /** * Sets the insets and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param insets the insets (<code>null</code> not permitted). * * @see #getInsets() */ public void setInsets(RectangleInsets insets) { if (insets == null) { throw new IllegalArgumentException("Null 'insets' argument."); } this.insets = insets; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the value anchor. * * @return The value anchor (never <code>null</code>). * * @see #setValueAnchor(RectangleAnchor) */ public RectangleAnchor getValueAnchor() { return this.valueAnchor; } /** * Sets the value anchor and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getValueAnchor() */ public void setValueAnchor(RectangleAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.valueAnchor = anchor; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the text anchor. * * @return The text anchor (never <code>null</code>). * * @see #setTextAnchor(TextAnchor) */ public TextAnchor getTextAnchor() { return this.textAnchor; } /** * Sets the text anchor and sends a {@link DialLayerChangeEvent} to all * registered listeners. * * @param anchor the anchor (<code>null</code> not permitted). * * @see #getTextAnchor() */ public void setTextAnchor(TextAnchor anchor) { if (anchor == null) { throw new IllegalArgumentException("Null 'anchor' argument."); } this.textAnchor = anchor; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns <code>true</code> to indicate that this layer should be * clipped within the dial window. * * @return <code>true</code>. */ @Override public boolean isClippedToWindow() { return true; } /** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); // the indicator bounds is calculated from the templateValue (which // determines the minimum size), the maxTemplateValue (which, if // specified, provides a maximum size) and the actual value FontMetrics fm = g2.getFontMetrics(this.font); double value = plot.getValue(this.datasetIndex); String valueStr = this.formatter.format(value); Rectangle2D valueBounds = TextUtilities.getTextBounds(valueStr, g2, fm); // calculate the bounds of the template value String s = this.formatter.format(this.templateValue); Rectangle2D tb = TextUtilities.getTextBounds(s, g2, fm); double minW = tb.getWidth(); double minH = tb.getHeight(); double maxW = Double.MAX_VALUE; double maxH = Double.MAX_VALUE; if (this.maxTemplateValue != null) { s = this.formatter.format(this.maxTemplateValue); tb = TextUtilities.getTextBounds(s, g2, fm); maxW = Math.max(tb.getWidth(), minW); maxH = Math.max(tb.getHeight(), minH); } double w = fixToRange(valueBounds.getWidth(), minW, maxW); double h = fixToRange(valueBounds.getHeight(), minH, maxH); // align this rectangle to the frameAnchor Rectangle2D bounds = RectangleAnchor.createRectangle(new Size2D(w, h), pt.getX(), pt.getY(), this.frameAnchor); // add the insets Rectangle2D fb = this.insets.createOutsetRectangle(bounds); // draw the background g2.setPaint(this.backgroundPaint); g2.fill(fb); // draw the border g2.setStroke(this.outlineStroke); g2.setPaint(this.outlinePaint); g2.draw(fb); // now find the text anchor point Shape savedClip = g2.getClip(); g2.clip(fb); Point2D pt2 = RectangleAnchor.coordinates(bounds, this.valueAnchor); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(valueStr, g2, (float) pt2.getX(), (float) pt2.getY(), this.textAnchor); g2.setClip(savedClip); } /** * A utility method that adjusts a value, if necessary, to be within a * specified range. * * @param x the value. * @param minX the minimum value in the range. * @param maxX the maximum value in the range. * * @return The adjusted value. */ private double fixToRange(double x, double minX, double maxX) { if (minX > maxX) { throw new IllegalArgumentException("Requires 'minX' <= 'maxX'."); } if (x < minX) { return minX; } else if (x > maxX) { return maxX; } else { return x; } } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof DialValueIndicator)) { return false; } DialValueIndicator that = (DialValueIndicator) obj; if (this.datasetIndex != that.datasetIndex) { return false; } if (this.angle != that.angle) { return false; } if (this.radius != that.radius) { return false; } if (!this.frameAnchor.equals(that.frameAnchor)) { return false; } if (!this.templateValue.equals(that.templateValue)) { return false; } if (!ObjectUtilities.equal(this.maxTemplateValue, that.maxTemplateValue)) { return false; } if (!this.font.equals(that.font)) { return false; } if (!PaintUtilities.equal(this.paint, that.paint)) { return false; } if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { return false; } if (!this.outlineStroke.equals(that.outlineStroke)) { return false; } if (!PaintUtilities.equal(this.outlinePaint, that.outlinePaint)) { return false; } if (!this.insets.equals(that.insets)) { return false; } if (!this.valueAnchor.equals(that.valueAnchor)) { return false; } if (!this.textAnchor.equals(that.textAnchor)) { return false; } return super.equals(obj); } /** * Returns a hash code for this instance. * * @return The hash code. */ @Override public int hashCode() { int result = 193; result = 37 * result + HashUtilities.hashCodeForPaint(this.paint); result = 37 * result + HashUtilities.hashCodeForPaint( this.backgroundPaint); result = 37 * result + HashUtilities.hashCodeForPaint( this.outlinePaint); result = 37 * result + this.outlineStroke.hashCode(); return result; } /** * Returns a clone of this instance. * * @return The clone. * * @throws CloneNotSupportedException if some attribute of this instance * cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.paint, stream); SerialUtilities.writePaint(this.backgroundPaint, stream); SerialUtilities.writePaint(this.outlinePaint, stream); SerialUtilities.writeStroke(this.outlineStroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.paint = SerialUtilities.readPaint(stream); this.backgroundPaint = SerialUtilities.readPaint(stream); this.outlinePaint = SerialUtilities.readPaint(stream); this.outlineStroke = SerialUtilities.readStroke(stream); } }
23,583
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DialScale.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/dial/DialScale.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * DialScale.java * -------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 17-Oct-2007 : Made this an extension of the DialLayer interface (DG); * */ package org.jfree.chart.plot.dial; /** * A dial scale is a specialised layer that has the ability to convert data * values into angles. * * @since 1.0.7 */ public interface DialScale extends DialLayer { /** * Converts a data value to an angle (in degrees, using the same * specification as Java's Arc2D class). * * @param value the data value. * * @return The angle in degrees. * * @see #angleToValue(double) */ public double valueToAngle(double value); /** * Converts an angle (in degrees) to a data value. * * @param angle the angle (in degrees). * * @return The data value. * * @see #valueToAngle(double) */ public double angleToValue(double angle); }
2,333
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AbstractDialLayer.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/dial/AbstractDialLayer.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * AbstractDialLayer.java * ---------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 06-Nov-2006 : Version 1 (DG); * 17-Nov-2006 : Added visible flag (DG); * 16-Oct-2007 : Implemented equals() and clone() (DG); * */ package org.jfree.chart.plot.dial; import java.io.IOException; import java.io.ObjectInputStream; import java.util.Arrays; import java.util.EventListener; import java.util.List; import javax.swing.event.EventListenerList; import org.jfree.chart.HashUtilities; /** * A base class that can be used to implement a {@link DialLayer}. It includes * an event notification mechanism. * * @since 1.0.7 */ public abstract class AbstractDialLayer implements DialLayer { /** A flag that controls whether or not the layer is visible. */ private boolean visible; /** Storage for registered listeners. */ private transient EventListenerList listenerList; /** * Creates a new instance. */ protected AbstractDialLayer() { this.visible = true; this.listenerList = new EventListenerList(); } /** * Returns <code>true</code> if this layer is visible (should be displayed), * and <code>false</code> otherwise. * * @return A boolean. * * @see #setVisible(boolean) */ @Override public boolean isVisible() { return this.visible; } /** * Sets the flag that determines whether or not this layer is drawn by * the plot, and sends a {@link DialLayerChangeEvent} to all registered * listeners. * * @param visible the flag. * * @see #isVisible() */ public void setVisible(boolean visible) { this.visible = visible; notifyListeners(new DialLayerChangeEvent(this)); } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof AbstractDialLayer)) { return false; } AbstractDialLayer that = (AbstractDialLayer) obj; return this.visible == that.visible; } /** * Returns a hash code for this instance. * * @return A hash code. */ @Override public int hashCode() { int result = 23; result = HashUtilities.hashCode(result, this.visible); return result; } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if there is a problem cloning this * instance. */ @Override public Object clone() throws CloneNotSupportedException { AbstractDialLayer clone = (AbstractDialLayer) super.clone(); // we don't clone the listeners clone.listenerList = new EventListenerList(); return clone; } /** * Registers an object for notification of changes to the dial layer. * * @param listener the object that is being registered. * * @see #removeChangeListener(DialLayerChangeListener) */ @Override public void addChangeListener(DialLayerChangeListener listener) { this.listenerList.add(DialLayerChangeListener.class, listener); } /** * Deregisters an object for notification of changes to the dial layer. * * @param listener the object to deregister. * * @see #addChangeListener(DialLayerChangeListener) */ @Override public void removeChangeListener(DialLayerChangeListener listener) { this.listenerList.remove(DialLayerChangeListener.class, listener); } /** * Returns <code>true</code> if the specified object is registered with * the dataset as a listener. Most applications won't need to call this * method, it exists mainly for use by unit testing code. * * @param listener the listener. * * @return A boolean. */ @Override public boolean hasListener(EventListener listener) { List<Object> list = Arrays.asList(this.listenerList.getListenerList()); return list.contains(listener); } /** * Notifies all registered listeners that the dial layer has changed. * The {@link DialLayerChangeEvent} provides information about the change. * * @param event information about the change to the axis. */ protected void notifyListeners(DialLayerChangeEvent event) { Object[] listeners = this.listenerList.getListenerList(); for (int i = listeners.length - 2; i >= 0; i -= 2) { if (listeners[i] == DialLayerChangeListener.class) { ((DialLayerChangeListener) listeners[i + 1]).dialLayerChanged( event); } } } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.listenerList = new EventListenerList(); } }
6,715
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ArcDialFrame.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/main/java/org/jfree/chart/plot/dial/ArcDialFrame.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * ArcDialFrame.java * ----------------- * (C) Copyright 2006-2012, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 03-Nov-2006 : Version 1 (DG); * 08-Mar-2007 : Fix in hashCode() (DG); * 17-Oct-2007 : Updated equals() (DG); * 24-Oct-2007 : Added argument checks and API docs, and renamed * StandardDialFrame --> ArcDialFrame (DG); * 16-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart.plot.dial; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics2D; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Arc2D; import java.awt.geom.Area; import java.awt.geom.GeneralPath; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import org.jfree.chart.HashUtilities; import org.jfree.chart.util.PaintUtilities; import org.jfree.chart.util.PublicCloneable; import org.jfree.chart.util.SerialUtilities; /** * A standard frame for the {@link DialPlot} class. * * @since 1.0.7 */ public class ArcDialFrame extends AbstractDialLayer implements DialFrame, Cloneable, PublicCloneable, Serializable { /** For serialization. */ static final long serialVersionUID = -4089176959553523499L; /** * The color used for the front of the panel. This field is transient * because it requires special handling for serialization. */ private transient Paint backgroundPaint; /** * The color used for the border around the window. This field is transient * because it requires special handling for serialization. */ private transient Paint foregroundPaint; /** * The stroke for drawing the frame outline. This field is transient * because it requires special handling for serialization. */ private transient Stroke stroke; /** * The start angle. */ private double startAngle; /** * The end angle. */ private double extent; /** The inner radius, relative to the framing rectangle. */ private double innerRadius; /** The outer radius, relative to the framing rectangle. */ private double outerRadius; /** * Creates a new instance of <code>ArcDialFrame</code> that spans * 180 degrees. */ public ArcDialFrame() { this(0, 180); } /** * Creates a new instance of <code>ArcDialFrame</code> that spans * the arc specified. * * @param startAngle the startAngle (in degrees). * @param extent the extent of the arc (in degrees, counter-clockwise). */ public ArcDialFrame(double startAngle, double extent) { this.backgroundPaint = Color.GRAY; this.foregroundPaint = new Color(100, 100, 150); this.stroke = new BasicStroke(2.0f); this.innerRadius = 0.25; this.outerRadius = 0.75; this.startAngle = startAngle; this.extent = extent; } /** * Returns the background paint (never <code>null</code>). * * @return The background paint. * * @see #setBackgroundPaint(Paint) */ public Paint getBackgroundPaint() { return this.backgroundPaint; } /** * Sets the background paint and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getBackgroundPaint() */ public void setBackgroundPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.backgroundPaint = paint; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the foreground paint. * * @return The foreground paint (never <code>null</code>). * * @see #setForegroundPaint(Paint) */ public Paint getForegroundPaint() { return this.foregroundPaint; } /** * Sets the foreground paint and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param paint the paint (<code>null</code> not permitted). * * @see #getForegroundPaint() */ public void setForegroundPaint(Paint paint) { if (paint == null) { throw new IllegalArgumentException("Null 'paint' argument."); } this.foregroundPaint = paint; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the stroke. * * @return The stroke (never <code>null</code>). * * @see #setStroke(Stroke) */ public Stroke getStroke() { return this.stroke; } /** * Sets the stroke and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param stroke the stroke (<code>null</code> not permitted). * * @see #getStroke() */ public void setStroke(Stroke stroke) { if (stroke == null) { throw new IllegalArgumentException("Null 'stroke' argument."); } this.stroke = stroke; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the inner radius, relative to the framing rectangle. * * @return The inner radius. * * @see #setInnerRadius(double) */ public double getInnerRadius() { return this.innerRadius; } /** * Sets the inner radius and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param radius the inner radius. * * @see #getInnerRadius() */ public void setInnerRadius(double radius) { if (radius < 0.0) { throw new IllegalArgumentException("Negative 'radius' argument."); } this.innerRadius = radius; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the outer radius, relative to the framing rectangle. * * @return The outer radius. * * @see #setOuterRadius(double) */ public double getOuterRadius() { return this.outerRadius; } /** * Sets the outer radius and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param radius the outer radius. * * @see #getOuterRadius() */ public void setOuterRadius(double radius) { if (radius < 0.0) { throw new IllegalArgumentException("Negative 'radius' argument."); } this.outerRadius = radius; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the start angle. * * @return The start angle. * * @see #setStartAngle(double) */ public double getStartAngle() { return this.startAngle; } /** * Sets the start angle and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param angle the angle. * * @see #getStartAngle() */ public void setStartAngle(double angle) { this.startAngle = angle; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the extent. * * @return The extent. * * @see #setExtent(double) */ public double getExtent() { return this.extent; } /** * Sets the extent and sends a {@link DialLayerChangeEvent} to * all registered listeners. * * @param extent the extent. * * @see #getExtent() */ public void setExtent(double extent) { this.extent = extent; notifyListeners(new DialLayerChangeEvent(this)); } /** * Returns the shape for the window for this dial. Some dial layers will * request that their drawing be clipped within this window. * * @param frame the reference frame (<code>null</code> not permitted). * * @return The shape of the dial's window. */ @Override public Shape getWindow(Rectangle2D frame) { Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius, this.innerRadius); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius, this.outerRadius); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle, this.extent, Arc2D.OPEN); Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + this.extent, -this.extent, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; } /** * Returns the outer window. * * @param frame the frame. * * @return The outer window. */ protected Shape getOuterWindow(Rectangle2D frame) { double radiusMargin = 0.02; double angleMargin = 1.5; Rectangle2D innerFrame = DialPlot.rectangleByRadius(frame, this.innerRadius - radiusMargin, this.innerRadius - radiusMargin); Rectangle2D outerFrame = DialPlot.rectangleByRadius(frame, this.outerRadius + radiusMargin, this.outerRadius + radiusMargin); Arc2D inner = new Arc2D.Double(innerFrame, this.startAngle - angleMargin, this.extent + 2 * angleMargin, Arc2D.OPEN); Arc2D outer = new Arc2D.Double(outerFrame, this.startAngle + angleMargin + this.extent, -this.extent - 2 * angleMargin, Arc2D.OPEN); GeneralPath p = new GeneralPath(); Point2D point1 = inner.getStartPoint(); p.moveTo((float) point1.getX(), (float) point1.getY()); p.append(inner, true); p.append(outer, true); p.closePath(); return p; } /** * Draws the frame. * * @param g2 the graphics target. * @param plot the plot. * @param frame the dial's reference frame. * @param view the dial's view rectangle. */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Shape window = getWindow(frame); Shape outerWindow = getOuterWindow(frame); Area area1 = new Area(outerWindow); Area area2 = new Area(window); area1.subtract(area2); g2.setPaint(Color.LIGHT_GRAY); g2.fill(area1); g2.setStroke(this.stroke); g2.setPaint(this.foregroundPaint); g2.draw(window); g2.draw(outerWindow); } /** * Returns <code>false</code> to indicate that this dial layer is not * clipped to the dial window. * * @return <code>false</code>. */ @Override public boolean isClippedToWindow() { return false; } /** * Tests this instance for equality with an arbitrary object. * * @param obj the object (<code>null</code> permitted). * * @return A boolean. */ @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (!(obj instanceof ArcDialFrame)) { return false; } ArcDialFrame that = (ArcDialFrame) obj; if (!PaintUtilities.equal(this.backgroundPaint, that.backgroundPaint)) { return false; } if (!PaintUtilities.equal(this.foregroundPaint, that.foregroundPaint)) { return false; } if (this.startAngle != that.startAngle) { return false; } if (this.extent != that.extent) { return false; } if (this.innerRadius != that.innerRadius) { return false; } if (this.outerRadius != that.outerRadius) { return false; } if (!this.stroke.equals(that.stroke)) { return false; } return super.equals(obj); } /** * Returns a hash code for this instance. * * @return The hash code. */ @Override public int hashCode() { int result = 193; long temp = Double.doubleToLongBits(this.startAngle); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.extent); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.innerRadius); result = 37 * result + (int) (temp ^ (temp >>> 32)); temp = Double.doubleToLongBits(this.outerRadius); result = 37 * result + (int) (temp ^ (temp >>> 32)); result = 37 * result + HashUtilities.hashCodeForPaint( this.backgroundPaint); result = 37 * result + HashUtilities.hashCodeForPaint( this.foregroundPaint); result = 37 * result + this.stroke.hashCode(); return result; } /** * Returns a clone of this instance. * * @return A clone. * * @throws CloneNotSupportedException if any attribute of this instance * cannot be cloned. */ @Override public Object clone() throws CloneNotSupportedException { return super.clone(); } /** * Provides serialization support. * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); SerialUtilities.writePaint(this.backgroundPaint, stream); SerialUtilities.writePaint(this.foregroundPaint, stream); SerialUtilities.writeStroke(this.stroke, stream); } /** * Provides serialization support. * * @param stream the input stream. * * @throws IOException if there is an I/O error. * @throws ClassNotFoundException if there is a classpath problem. */ private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); this.backgroundPaint = SerialUtilities.readPaint(stream); this.foregroundPaint = SerialUtilities.readPaint(stream); this.stroke = SerialUtilities.readStroke(stream); } }
15,748
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z