KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * TracePainterDisc.java, <enter purpose here>.
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
25
26 import java.awt.Graphics2D JavaDoc;
27
28 /**
29  * Renders traces by painting a disc (hollow circle) with choosable diameter for
30  * each {@link info.monitorenter.gui.chart.TracePoint2D} to show.
31  * <p>
32  *
33  * @author <a HREF="mailto:Achim.Westermann@gmx.de">Achim Westermann </a>
34  *
35  * @version $Revision: 1.1 $
36  *
37  */

38 public class TracePainterDisc extends ATracePainter {
39
40   /** The diameter of the discs to paint. */
41   private int m_discSize;
42
43   /** Cached m_discSize divided by two to save division for each point to render. */
44   private int m_halfDiscSize;
45
46   /**
47    * Creates an instance with a default disc size of 4.
48    * <p>
49    */

50   public TracePainterDisc() {
51     this.setDiscSize(4);
52   }
53
54   /**
55    * Creates an instance with the given disc size.
56    *
57    * @param discSize
58    * the disc size in pixel to use.
59    */

60   public TracePainterDisc(final int discSize) {
61     this.setDiscSize(discSize);
62   }
63
64   /**
65    * @see info.monitorenter.gui.chart.ITracePainter#startPaintIteration()
66    */

67   public void endPaintIteration() {
68     Graphics2D JavaDoc g2d = this.getGraphics();
69     if (g2d != null) {
70       this.getGraphics().drawOval(this.getPreviousX() - this.m_halfDiscSize,
71           this.getPreviousY() - this.m_halfDiscSize, this.m_discSize, this.m_discSize);
72     }
73   }
74
75   /**
76    * Returns the diameter of the discs to paint in pixel.
77    * <p>
78    *
79    * @return the diameter of the discs to paint in pixel.
80    */

81   public int getDiscSize() {
82     return this.m_discSize;
83   }
84
85   /**
86    * @see info.monitorenter.gui.chart.ITracePainter#paintPoint(int, int, int, int,
87    * java.awt.Graphics2D)
88    */

89   public void paintPoint(final int absoluteX, final int absoluteY, final int nextX,
90       final int nextY, final Graphics2D JavaDoc g) {
91     super.paintPoint(absoluteX, absoluteY, nextX, nextY, g);
92     g.drawOval(absoluteX - this.m_halfDiscSize, absoluteY - this.m_halfDiscSize, this.m_discSize,
93         this.m_discSize);
94   }
95
96   /**
97    * Sets the diameter of the discs to paint in pixel.
98    * <p>
99    *
100    * @param discSize
101    * the diameter of the discs to paint in pixel.
102    */

103   public void setDiscSize(final int discSize) {
104     this.m_discSize = discSize;
105     this.m_halfDiscSize = this.m_discSize / 2;
106   }
107 }
108
Popular Tags