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. * LongNeedle.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: LongNeedle.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. * 16-Mar-2004 : Implemented Rotation
  40. */
  41. package org.jfree.chart.needle;
  42. import java.awt.Graphics2D;
  43. import java.awt.geom.GeneralPath;
  44. import java.awt.geom.Point2D;
  45. import java.awt.geom.Rectangle2D;
  46. import java.awt.Shape;
  47. import java.io.Serializable;
  48. /**
  49. * A needle that is represented by a long line.
  50. *
  51. * @author Bryan Scott
  52. */
  53. public class LongNeedle extends MeterNeedle implements Serializable {
  54. /**
  55. * Default constructor.
  56. */
  57. public LongNeedle() {
  58. super();
  59. setRotateY(0.8);
  60. }
  61. /**
  62. * Draws the needle.
  63. *
  64. * @param g2 the graphics device.
  65. * @param plotArea the plot area.
  66. * @param rotate the rotation point.
  67. * @param angle the angle.
  68. */
  69. protected void drawNeedle(Graphics2D g2, Rectangle2D plotArea, Point2D rotate, double angle) {
  70. GeneralPath shape1 = new GeneralPath();
  71. GeneralPath shape2 = new GeneralPath();
  72. GeneralPath shape3 = new GeneralPath();
  73. float minX = (float) plotArea.getMinX();
  74. float minY = (float) plotArea.getMinY();
  75. float maxX = (float) plotArea.getMaxX();
  76. float maxY = (float) plotArea.getMaxY();
  77. //float midX = (float) (minX + (plotArea.getWidth() * getRotateX()));
  78. //float midY = (float) (minY + (plotArea.getHeight() * getRotateY()));
  79. float midX = (float) (minX + (plotArea.getWidth() * 0.5));
  80. float midY = (float) (minY + (plotArea.getHeight() * 0.8));
  81. float y = maxY - (2 * (maxY - midY));
  82. if (y < minY) {
  83. y = minY;
  84. }
  85. shape1.moveTo(minX, midY);
  86. shape1.lineTo(midX, minY);
  87. shape1.lineTo(midX, y);
  88. shape1.closePath();
  89. shape2.moveTo(maxX, midY);
  90. shape2.lineTo(midX, minY);
  91. shape2.lineTo(midX, y);
  92. shape2.closePath();
  93. shape3.moveTo(minX, midY);
  94. shape3.lineTo(midX, maxY);
  95. shape3.lineTo(maxX, midY);
  96. shape3.lineTo(midX, y);
  97. shape3.closePath();
  98. Shape s1 = shape1;
  99. Shape s2 = shape2;
  100. Shape s3 = shape3;
  101. if ((rotate != null) && (angle != 0)) {
  102. /// we have rotation huston, please spin me
  103. getTransform().setToRotation(angle, rotate.getX(), rotate.getY());
  104. s1 = shape1.createTransformedShape(transform);
  105. s2 = shape2.createTransformedShape(transform);
  106. s3 = shape3.createTransformedShape(transform);
  107. }
  108. if (getHighlightPaint() != null) {
  109. g2.setPaint(getHighlightPaint());
  110. g2.fill(s3);
  111. }
  112. if (getFillPaint() != null) {
  113. g2.setPaint(getFillPaint());
  114. g2.fill(s1);
  115. g2.fill(s2);
  116. }
  117. if (getOutlinePaint() != null) {
  118. g2.setStroke(getOutlineStroke());
  119. g2.setPaint(getOutlinePaint());
  120. g2.draw(s1);
  121. g2.draw(s2);
  122. g2.draw(s3);
  123. }
  124. }
  125. /**
  126. * Tests another object for equality with this object.
  127. *
  128. * @param object the object to test.
  129. *
  130. * @return A boolean.
  131. */
  132. public boolean equals(Object object) {
  133. if (object == null) {
  134. return false;
  135. }
  136. if (object == this) {
  137. return true;
  138. }
  139. if (super.equals(object) && object instanceof LongNeedle) {
  140. return true;
  141. }
  142. return false;
  143. }
  144. }