KickJava   Java API By Example, From Geeks To Geeks.

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


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
29
30 /**
31  * A customizable legend for a chart, enabling charting of multiple data sets.
32  * <p><b>Features:</b><br>
33  * Supports any number of text labels, allows for associating of any color with
34  * any text label. Includes bordering, gapping, auto and manual resizing
35  * and locating, and growing and shrinking components. The only shape of bullet
36  * that is available is a rectangle, however.
37  */

38 final class LegendArea extends VerticalTextListArea {
39
40
41   private boolean needsUpdate;
42
43
44   /**
45    * Creates a legend area using all the defaults of vertical text list area.
46    * Defaults:<br>
47    * setAutoSizes (false, false);<br>
48    * setAutoJustifys (false, false);<br>
49    * resetLegendAreaModel (true);<br>
50    */

51   LegendArea() {
52
53     setAutoSizes (false, false);
54     setAutoJustifys (false, false);
55     resetLegendAreaModel (true);
56     needsUpdate = true;
57   }
58
59
60   /**
61    * Specifies which colors to use for the label's bullets. Each label has
62    * a bullet to its left. This method sets the colors for these bullets.
63    * The uppermost label will get the lowest order array member.
64    * @param colors The bullet colors.
65    */

66   final void setColors (Color[] colors) {
67
68     needsUpdate = true;
69     setBulletColors (colors);
70   }
71
72
73   /**
74    * Resets the model for this class. The model is used for shrinking and
75    * growing of its components based on the maximum size of this class. If this
76    * method is called, then the next time the maximum size is set, this classes
77    * model maximum size will be made equal to the new maximum size. Effectively
78    * what this does is ensure that whenever this objects maximum size is equal
79    * to the one given, then all of the components will take on their default
80    * model sizes. Note: This is only useful when auto model max sizing is
81    * disabled.
82    * @param reset True causes the max model size to be set upon the next max
83    * sizing.
84    */

85   final void resetLegendAreaModel (boolean reset) {
86
87     needsUpdate = true;
88     resetVerticalTextListAreaModel (reset);
89   }
90
91
92   /**
93    * Indicates whether some property of this class has changed.
94    * @return True if some property has changed.
95    */

96   final boolean getLegendAreaNeedsUpdate() {
97
98     return (needsUpdate || getVerticalTextListAreaNeedsUpdate());
99   }
100
101
102   /**
103    * Updates all variables. First updates the variables of its parent class,
104    * then updates its own variables.
105    * @param g2D The graphics context used for calculations.
106    */

107   final void updateLegendArea (Graphics2D g2D) {
108     if (getLegendAreaNeedsUpdate()) {
109       updateVerticalTextListArea (g2D);
110     }
111     needsUpdate = false;
112   }
113
114
115   /**
116    * Paints all the components of this class. First all variables are updated.
117    * @param g2D The graphics context for calculations and painting.
118    */

119   void paintComponent (Graphics2D g2D) {
120
121     updateLegendArea (g2D);
122     super.paintComponent (g2D);
123   }
124 }
Popular Tags