KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chart2d > FancyDot


1 /**
2  * Chart2D, a java library for drawing two dimensional charts.
3  * Copyright (C) 2001 Jason J. Simas
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  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * The author of this library may be contacted at:
19  * E-mail: jjsimas@users.sourceforge.net
20  * Street Address: J J Simas, 887 Tico Road, Ojai, CA 93023-3555 USA
21  */

22
23
24 package net.sourceforge.chart2d;
25
26
27 import java.awt.*;
28 import java.awt.geom.*;
29 import java.util.*;
30
31
32 /**
33  * A circle capable of automatic gradient paint and warning region coloring.
34  */

35 final class FancyDot extends FancyShape {
36
37
38   private Rectangle2D.Float bounds, clipBounds;
39   private Ellipse2D.Float dot;
40   private FancyDot[] warningDots;
41   private boolean needsUpdate;
42
43
44   /**
45    * Creates a default fancy dot.
46    */

47   FancyDot() {
48     needsUpdate = true;
49   }
50
51
52   /**
53    * Sets the bounds for this bar (specifying the size and location of the bar).
54    * @param b The bounds.
55    */

56   final void setBounds (Rectangle2D.Float b) {
57     bounds = b;
58     needsUpdate = true;
59   }
60
61
62   /**
63    * Sets the clip bounds for this bar (specifying what will show).
64    * @param b The bounds.
65    */

66   final void setClipBounds (Rectangle2D.Float b) {
67     clipBounds = b;
68     needsUpdate = true;
69   }
70
71
72   /**
73    * Gets the bounds for this bar (specifying the size and location of the bar).
74    * @return The bounds.
75    */

76   final Rectangle2D.Float getBounds() {
77     return bounds;
78   }
79
80
81   /**
82    * Gets the clip bounds for this bar (specifying what will show).
83    * @return The bounds.
84    */

85   final Rectangle2D.Float getClipBounds() {
86     return clipBounds;
87   }
88
89
90   /**
91    * Paints the dot on the Graphics2D object after calling update.
92    * @param g2D The Graphics2D object.
93    */

94   final void paint (Graphics2D g2D) {
95
96     update();
97
98     Paint oldPaint = g2D.getPaint();
99     g2D.setPaint (getPaint());
100
101     Shape oldClip = g2D.getClip();
102     java.awt.geom.Area JavaDoc clipArea = new java.awt.geom.Area JavaDoc (clipBounds);
103     clipArea.intersect (new java.awt.geom.Area JavaDoc (oldClip));
104     g2D.setClip (clipArea);
105
106     g2D.fill (dot);
107
108     if (getOutlineExistence() && bounds.width > 2f && bounds.height > 2f) {
109       g2D.setPaint (getOutlinePaint());
110       g2D.draw (dot);
111     }
112
113     g2D.setPaint (oldPaint);
114     g2D.setClip (oldClip);
115
116     if (getWarningRegions() != null) {
117       for (int i = 0; i < warningDots.length; ++i) warningDots[i].paint (g2D);
118     }
119   }
120
121
122   /**
123    * Updates the FancyDot.
124    */

125   final void update() {
126
127     super.update();
128
129     if (needsUpdate) {
130
131       dot = new Ellipse2D.Float (bounds.x, bounds.y, bounds.width, bounds.height);
132
133       if (getWarningRegions() != null) {
134
135         warningDots = new FancyDot[getWarningRegions().size()];
136         for (int i = 0; i < warningDots.length; ++i) {
137
138           FancyDot warningDot = new FancyDot();
139           warningDot.setBounds (bounds);
140           warningDot.setWarningRegions (null);
141           warningDot.setLightBounds (getLightBounds());
142           warningDot.setLightSource (getLightSource());
143           warningDot.setOutlineExistence (getOutlineExistence());
144           warningDot.setOutlineColor (getOutlineColor());
145           warningDot.setType (getType());
146           warningDot.setGraphBounds (getGraphBounds());
147           WarningRegion warningRegion = (WarningRegion)getWarningRegions().get (i);
148           Rectangle2D tempRect2D = bounds.createIntersection (warningRegion.getBackgroundBounds());
149           Rectangle2D.Float clipBoundsWR = new Rectangle2D.Float();
150           clipBoundsWR.setRect (tempRect2D);
151           warningDot.setClipBounds (clipBoundsWR);
152           warningDot.setColor (warningRegion.getComponentColor());
153           warningDots[i] = warningDot;
154         }
155       }
156       needsUpdate = false;
157     }
158   }
159 }
Popular Tags