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:
025: /**
026: * A customizable legend for a chart, enabling charting of multiple data sets.
027: * <p><b>Features:</b><br>
028: * Supports any number of text labels, allows for associating of any color with
029: * any text label. Includes bordering, gapping, auto and manual resizing
030: * and locating, and growing and shrinking components. The only shape of bullet
031: * that is available is a rectangle, however.
032: */
033: final class LegendArea extends VerticalTextListArea {
034:
035: private boolean needsUpdate;
036:
037: /**
038: * Creates a legend area using all the defaults of vertical text list area.
039: * Defaults:<br>
040: * setAutoSizes (false, false);<br>
041: * setAutoJustifys (false, false);<br>
042: * resetLegendAreaModel (true);<br>
043: */
044: LegendArea() {
045:
046: setAutoSizes(false, false);
047: setAutoJustifys(false, false);
048: resetLegendAreaModel(true);
049: needsUpdate = true;
050: }
051:
052: /**
053: * Specifies which colors to use for the label's bullets. Each label has
054: * a bullet to its left. This method sets the colors for these bullets.
055: * The uppermost label will get the lowest order array member.
056: * @param colors The bullet colors.
057: */
058: final void setColors(Color[] colors) {
059:
060: needsUpdate = true;
061: setBulletColors(colors);
062: }
063:
064: /**
065: * Resets the model for this class. The model is used for shrinking and
066: * growing of its components based on the maximum size of this class. If this
067: * method is called, then the next time the maximum size is set, this classes
068: * model maximum size will be made equal to the new maximum size. Effectively
069: * what this does is ensure that whenever this objects maximum size is equal
070: * to the one given, then all of the components will take on their default
071: * model sizes. Note: This is only useful when auto model max sizing is
072: * disabled.
073: * @param reset True causes the max model size to be set upon the next max
074: * sizing.
075: */
076: final void resetLegendAreaModel(boolean reset) {
077:
078: needsUpdate = true;
079: resetVerticalTextListAreaModel(reset);
080: }
081:
082: /**
083: * Indicates whether some property of this class has changed.
084: * @return True if some property has changed.
085: */
086: final boolean getLegendAreaNeedsUpdate() {
087:
088: return (needsUpdate || getVerticalTextListAreaNeedsUpdate());
089: }
090:
091: /**
092: * Updates all variables. First updates the variables of its parent class,
093: * then updates its own variables.
094: * @param g2D The graphics context used for calculations.
095: */
096: final void updateLegendArea(Graphics2D g2D) {
097: if (getLegendAreaNeedsUpdate()) {
098: updateVerticalTextListArea(g2D);
099: }
100: needsUpdate = false;
101: }
102:
103: /**
104: * Paints all the components of this class. First all variables are updated.
105: * @param g2D The graphics context for calculations and painting.
106: */
107: void paintComponent(Graphics2D g2D) {
108:
109: updateLegendArea(g2D);
110: super.paintComponent(g2D);
111: }
112: }
|