001: /**
002: * Chart2D, a java library for drawing two dimensional charts.
003: * Copyright (C) 2001 Jason J. Simas
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * The author of this library may be contacted at:
019: * E-mail: jjsimas@users.sourceforge.net
020: * Street Address: J J Simas, 887 Tico Road, Ojai, CA 93023-3555 USA
021: */package net.sourceforge.chart2d;
022:
023: import java.awt.*;
024: import java.awt.geom.*;
025: import java.util.*;
026:
027: /**
028: * A circle capable of automatic gradient paint and warning region coloring.
029: */
030: final class FancyDot extends FancyShape {
031:
032: private Rectangle2D.Float bounds, clipBounds;
033: private Ellipse2D.Float dot;
034: private FancyDot[] warningDots;
035: private boolean needsUpdate;
036:
037: /**
038: * Creates a default fancy dot.
039: */
040: FancyDot() {
041: needsUpdate = true;
042: }
043:
044: /**
045: * Sets the bounds for this bar (specifying the size and location of the bar).
046: * @param b The bounds.
047: */
048: final void setBounds(Rectangle2D.Float b) {
049: bounds = b;
050: needsUpdate = true;
051: }
052:
053: /**
054: * Sets the clip bounds for this bar (specifying what will show).
055: * @param b The bounds.
056: */
057: final void setClipBounds(Rectangle2D.Float b) {
058: clipBounds = b;
059: needsUpdate = true;
060: }
061:
062: /**
063: * Gets the bounds for this bar (specifying the size and location of the bar).
064: * @return The bounds.
065: */
066: final Rectangle2D.Float getBounds() {
067: return bounds;
068: }
069:
070: /**
071: * Gets the clip bounds for this bar (specifying what will show).
072: * @return The bounds.
073: */
074: final Rectangle2D.Float getClipBounds() {
075: return clipBounds;
076: }
077:
078: /**
079: * Paints the dot on the Graphics2D object after calling update.
080: * @param g2D The Graphics2D object.
081: */
082: final void paint(Graphics2D g2D) {
083:
084: update();
085:
086: Paint oldPaint = g2D.getPaint();
087: g2D.setPaint(getPaint());
088:
089: Shape oldClip = g2D.getClip();
090: java.awt.geom.Area clipArea = new java.awt.geom.Area(clipBounds);
091: clipArea.intersect(new java.awt.geom.Area(oldClip));
092: g2D.setClip(clipArea);
093:
094: g2D.fill(dot);
095:
096: if (getOutlineExistence() && bounds.width > 2f
097: && bounds.height > 2f) {
098: g2D.setPaint(getOutlinePaint());
099: g2D.draw(dot);
100: }
101:
102: g2D.setPaint(oldPaint);
103: g2D.setClip(oldClip);
104:
105: if (getWarningRegions() != null) {
106: for (int i = 0; i < warningDots.length; ++i)
107: warningDots[i].paint(g2D);
108: }
109: }
110:
111: /**
112: * Updates the FancyDot.
113: */
114: final void update() {
115:
116: super .update();
117:
118: if (needsUpdate) {
119:
120: dot = new Ellipse2D.Float(bounds.x, bounds.y, bounds.width,
121: bounds.height);
122:
123: if (getWarningRegions() != null) {
124:
125: warningDots = new FancyDot[getWarningRegions().size()];
126: for (int i = 0; i < warningDots.length; ++i) {
127:
128: FancyDot warningDot = new FancyDot();
129: warningDot.setBounds(bounds);
130: warningDot.setWarningRegions(null);
131: warningDot.setLightBounds(getLightBounds());
132: warningDot.setLightSource(getLightSource());
133: warningDot
134: .setOutlineExistence(getOutlineExistence());
135: warningDot.setOutlineColor(getOutlineColor());
136: warningDot.setType(getType());
137: warningDot.setGraphBounds(getGraphBounds());
138: WarningRegion warningRegion = (WarningRegion) getWarningRegions()
139: .get(i);
140: Rectangle2D tempRect2D = bounds
141: .createIntersection(warningRegion
142: .getBackgroundBounds());
143: Rectangle2D.Float clipBoundsWR = new Rectangle2D.Float();
144: clipBoundsWR.setRect(tempRect2D);
145: warningDot.setClipBounds(clipBoundsWR);
146: warningDot.setColor(warningRegion
147: .getComponentColor());
148: warningDots[i] = warningDot;
149: }
150: }
151: needsUpdate = false;
152: }
153: }
154: }
|