1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, by Object Refinery Limited and Contributors.
  6. *
  7. * Project Info: http://www.jfree.org/jfreechart/index.html
  8. *
  9. * This library is free software; you can redistribute it and/or modify it under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ----------------
  25. * ArrowNeedle.java
  26. * ----------------
  27. * (C) Copyright 2002, 2003, by the Australian Antarctic Division and Contributors.
  28. *
  29. * Original Author: Bryan Scott (for the Australian Antarctic Division);
  30. * Contributor(s): David Gilbert (for Object Refinery Limited);
  31. *
  32. * $Id: ArrowNeedle.java,v 1.1 2004/08/31 14:37:36 mungady Exp $
  33. *
  34. * Changes:
  35. * --------
  36. * 25-Sep-2002 : Version 1, contributed by Bryan Scott (DG);
  37. * 27-Mar-2003 : Implemented Serializable (DG);
  38. * 09-Sep-2003 : Added equals(...) method (DG);
  39. *
  40. */
  41. package org.jfree.chart.needle;
  42. import java.awt.Graphics2D;
  43. import java.awt.Shape;
  44. import java.awt.geom.GeneralPath;
  45. import java.awt.geom.Line2D;
  46. import java.awt.geom.Point2D;
  47. import java.awt.geom.Rectangle2D;
  48. import java.io.Serializable;
  49. /**
  50. * A needle in the shape of an arrow.
  51. *
  52. * @author Bryan Scott
  53. */
  54. public class ArrowNeedle extends MeterNeedle implements Serializable {
  55. /** A flag controlling whether or not there is an arrow at the top of the needle. */
  56. private boolean isArrowAtTop = true;
  57. /**
  58. * Constructs a new arrow needle.
  59. *
  60. * @param isArrowAtTop a flag that controls whether or not there is an arrow at the top of
  61. * the needle.
  62. */
  63. public ArrowNeedle(boolean isArrowAtTop) {
  64. this.isArrowAtTop = isArrowAtTop;
  65. }
  66. /**
  67. * Draws the needle.
  68. *
  69. * @param g2 the graphics device.
  70. * @param plotArea the plot area.
  71. * @param rotate the rotation point.
  72. * @param angle the angle.
  73. */
  74. protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {
  75. Line2D shape = new Line2D.Float();
  76. Shape d = null;
  77. float x = (float) (plotArea.getMinX() + (plotArea.getWidth() / 2));
  78. float minY = (float) plotArea.getMinY();
  79. float maxY = (float) plotArea.getMaxY();
  80. shape.setLine(x, minY, x, maxY);
  81. GeneralPath shape1 = new GeneralPath();
  82. if (this.isArrowAtTop) {
  83. shape1.moveTo(x, minY);
  84. minY += 4 * getSize();
  85. }
  86. else {
  87. shape1.moveTo(x, maxY);
  88. minY = maxY - 4 * getSize();
  89. }
  90. shape1.lineTo(x + getSize(), minY);
  91. shape1.lineTo(x - getSize(), minY);
  92. shape1.closePath();
  93. if ((rotate != null) && (angle != 0)) {
  94. getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
  95. d = getTransform().createTransformedShape(shape);
  96. }
  97. else {
  98. d = shape;
  99. }
  100. defaultDisplay(g2, d);
  101. if ((rotate != null) && (angle != 0)) {
  102. d = getTransform().createTransformedShape(shape1);
  103. }
  104. else {
  105. d = shape1;
  106. }
  107. defaultDisplay(g2, d);
  108. }
  109. /**
  110. * Tests another object for equality with this object.
  111. *
  112. * @param object the object to test.
  113. *
  114. * @return A boolean.
  115. */
  116. public boolean equals(Object object) {
  117. if (object == null) {
  118. return false;
  119. }
  120. if (object == this) {
  121. return true;
  122. }
  123. if (super.equals(object) && object instanceof ArrowNeedle) {
  124. ArrowNeedle an = (ArrowNeedle) object;
  125. return this.isArrowAtTop == an.isArrowAtTop;
  126. }
  127. return false;
  128. }
  129. }