KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > monitorenter > gui > chart > traces > painters > ATracePainter


1 /*
2  * ATracePainter.java, base class for ITracePainter implementations.
3  * Copyright (C) 2005 Achim Westermann, Achim.Westermann@gmx.de
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * If you modify or optimize the code in a useful way please let me know.
20  * Achim.Westermann@gmx.de
21  */

22 package info.monitorenter.gui.chart.traces.painters;
23
24 import java.awt.Graphics2D JavaDoc;
25
26 /**
27  * A trace painter that adds the service of knowing the previous point that had
28  * to be painted.
29  * <p>
30  *
31  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
32  *
33  * @version $Revision: 1.3 $
34  *
35  */

36 public abstract class ATracePainter implements info.monitorenter.gui.chart.ITracePainter {
37
38   /**
39    * Stores the last grapcics sent to
40    * {@link #paintPoint(int, int, int, int, Graphics2D)} to allow painting
41    * polygon at the end of the paint iteration.
42    */

43
44   protected Graphics2D JavaDoc m_graphics;
45
46   /** Flag to remember if a paint iteration has ended. */
47   private boolean m_isEnded = false;
48
49   /**
50    * The last x coordinate that was sent to
51    * {@link #paintPoint(int, int, int, int, Graphics2D)}.
52    * <p>
53    * It will be needed at {@link #endPaintIteration()} as the former method only
54    * uses the first set of coordinates to store in the internal list to avoid
55    * duplicates.
56    * <p>
57    */

58
59   protected int m_lastX;
60
61   /**
62    * The last � coordinate that was sent to
63    * {@link #paintPoint(int, int, int, int, Graphics2D)}.
64    * <p>
65    * It will be needed at {@link #endPaintIteration()} as the former method only
66    * uses the first set of coordinates to store in the internal list to avoid
67    * duplicates.
68    * <p>
69    */

70
71   protected int m_lastY;
72
73   /**
74    * @see java.lang.Comparable#compareTo(java.lang.Object)
75    */

76   public int compareTo(final Object JavaDoc o) {
77
78     return this.getClass().getName().compareTo(o.getClass().getName());
79   }
80
81   /**
82    * @see info.monitorenter.gui.chart.ITracePainter#discontinue()
83    */

84   public void discontinue() {
85     this.endPaintIteration();
86     this.startPaintIteration();
87   }
88
89   /**
90    * @see info.monitorenter.gui.chart.ITracePainter#endPaintIteration()
91    */

92   public void endPaintIteration() {
93     // nop
94
}
95
96   /**
97    * Two instances are judged equal if they are of the same class.
98    * <p>
99    * This implies that any state of a {@link ATracePainter} is unimportant -
100    * implementations that have a state (e.g. the radius for discs to paint in
101    * {@link TracePainterDisc}) this method should be considered to be
102    * overrriden (along with {@link #hashCode()}.
103    * <p>
104    *
105    * @see java.lang.Object#equals(java.lang.Object)
106    */

107   public boolean equals(final Object JavaDoc obj) {
108     return this.getClass() == obj.getClass();
109   }
110
111   /**
112    * @return Returns the m_graphics.
113    */

114   protected final Graphics2D JavaDoc getGraphics() {
115     return this.m_graphics;
116   }
117
118   /**
119    * Returns the previous X value that had to be painted by
120    * {@link #paintPoint(int, int, int, int, Graphics2D)}.
121    * <p>
122    *
123    * This value will be {@link Integer#MIN_VALUE} if no previous point had to be
124    * painted.
125    * <p>
126    *
127    * @return the previous X value that had to be painted by
128    * {@link #paintPoint(int, int, int, int, Graphics2D)}.
129    */

130   public int getPreviousX() {
131     int result = this.m_lastX;
132     if (this.m_isEnded) {
133       this.m_lastX = Integer.MIN_VALUE;
134       if (this.m_lastY == Integer.MIN_VALUE) {
135         this.m_isEnded = false;
136       }
137
138     }
139     return result;
140   }
141
142   /**
143    * Returns the previous Y value that had to be painted by
144    * {@link #paintPoint(int, int, int, int, Graphics2D)}.
145    * <p>
146    *
147    * This value will be {@link Integer#MIN_VALUE} if no previous point had to be
148    * painted.
149    * <p>
150    *
151    * @return the previous Y value that had to be painted by
152    * {@link #paintPoint(int, int, int, int, Graphics2D)}.
153    */

154   public int getPreviousY() {
155     int result = this.m_lastY;
156     if (this.m_isEnded) {
157       this.m_lastY = Integer.MIN_VALUE;
158       if (this.m_lastX == Integer.MIN_VALUE) {
159         this.m_isEnded = false;
160       }
161     }
162     return result;
163   }
164
165   /**
166    * @see java.lang.Object#hashCode()
167    */

168   public int hashCode() {
169     return this.getClass().hashCode();
170   }
171
172   /**
173    * @see info.monitorenter.gui.chart.ITracePainter#paintPoint(int, int, int,
174    * int, Graphics2D)
175    */

176   public void paintPoint(final int absoluteX, final int absoluteY, final int nextX,
177       final int nextY, final Graphics2D JavaDoc g) {
178     this.m_lastX = nextX;
179     this.m_lastY = nextY;
180     this.m_graphics = g;
181   }
182
183   /**
184    * @see info.monitorenter.gui.chart.ITracePainter#startPaintIteration()
185    */

186   public void startPaintIteration() {
187     // nop
188
}
189 }
190
Popular Tags