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: /**
024: * An abstract class for the common methods of GraphChart2D and PieChart2D.
025: * These are methods for handling the Chart2DProperties object and the LegendProperties object.
026: * Changes through its set methods are updated upon next repaint() or getImage() calls.
027: */
028: public abstract class Chart2D extends Object2D {
029:
030: private Chart2DProperties chart2DProps;
031: private LegendProperties legendProps;
032: private boolean needsUpdate;
033:
034: /**
035: * Creates a Chart2D object with its defaults.
036: * A Chart2DProperties object must be set for this object before it is used.
037: * An LegendProperties object must be set for this object before it is used.
038: */
039: public Chart2D() {
040: needsUpdate = true;
041: }
042:
043: /**
044: * Sets the Chart2DProperties for this Chart2D.
045: * @param props The Chart2DProperties.
046: */
047: public final void setChart2DProperties(Chart2DProperties props) {
048:
049: needsUpdate = true;
050: props.addChart2D(this );
051: if (chart2DProps != null)
052: chart2DProps.removeChart2D(this );
053: chart2DProps = props;
054: }
055:
056: /**
057: * Sets the LegendProperties for this Chart2D.
058: * @param props The LegendProperties.
059: */
060: public final void setLegendProperties(LegendProperties props) {
061:
062: needsUpdate = true;
063: props.addChart2D(this );
064: if (legendProps != null)
065: legendProps.removeChart2D(this );
066: legendProps = props;
067: }
068:
069: /**
070: * Gets the Chart2DProperties for this Chart2D.
071: * @return The Chart2DProperties.
072: */
073: public final Chart2DProperties getChart2DProperties() {
074: return chart2DProps;
075: }
076:
077: /**
078: * Gets the LegendProperties for this Chart2D.
079: * @return The LegendProperties.
080: */
081: public final LegendProperties getLegendProperties() {
082: return legendProps;
083: }
084:
085: /**
086: * Gets whether this object needs to be updated.
087: * @return If true then needs update.
088: */
089: final boolean getNeedsUpdateChart2D() {
090: return (needsUpdate || getNeedsUpdateObject2D()
091: || chart2DProps.getChart2DNeedsUpdate(this ) || legendProps
092: .getChart2DNeedsUpdate(this ));
093: }
094:
095: /**
096: * Validates the properties of this object.
097: * If debug is true then prints a messages indicating whether each property is valid.
098: * Returns true if all the properties were valid and false otherwise.
099: * @param debug If true then will print status messages.
100: * @return If true then valid.
101: */
102: final boolean validateChart2D(boolean debug) {
103:
104: if (debug)
105: System.out.println("Validating Chart2D");
106:
107: boolean valid = true;
108:
109: if (!validateObject2D(debug))
110: valid = false;
111:
112: if (chart2DProps == null) {
113: valid = false;
114: if (debug)
115: System.out.println("Chart2DProperties is null");
116: } else if (!chart2DProps.validate(debug))
117: valid = false;
118:
119: if (legendProps == null) {
120: valid = false;
121: if (debug)
122: System.out.println("LegendProperties is null");
123: } else if (!legendProps.validate(debug))
124: valid = false;
125:
126: if (debug) {
127: if (valid)
128: System.out.println("Chart2D was valid");
129: else
130: System.out.println("Chart2D was invalid");
131: }
132:
133: return valid;
134: }
135:
136: /**
137: * Updates this object with the settings from the properties objects.
138: */
139: final void updateChart2D() {
140:
141: if (getNeedsUpdateChart2D()) {
142:
143: needsUpdate = false;
144:
145: updateObject2D();
146:
147: chart2DProps.updateChart2D(this );
148: legendProps.updateChart2D(this );
149:
150: ChartArea chart = (ChartArea) getObjectArea();
151: LegendArea legend = chart.getLegend();
152:
153: chart.setLabelsPrecisionNum(chart2DProps
154: .getChartDataLabelsPrecision());
155: chart.setBetweenChartAndLegendGapExistence(chart2DProps
156: .getChartBetweenChartAndLegendGapExistence());
157: chart
158: .setBetweenChartAndLegendGapThicknessModel(chart2DProps
159: .getChartBetweenChartAndLegendGapThicknessModel());
160:
161: chart.setLegendExistence(legendProps.getLegendExistence());
162: legend.setBorderExistence(legendProps
163: .getLegendBorderExistence());
164: legend.setBorderThicknessModel(legendProps
165: .getLegendBorderThicknessModel());
166: legend.setBorderColor(legendProps.getLegendBorderColor());
167: legend.setGapExistence(legendProps.getLegendGapExistence());
168: legend.setGapThicknessModel(legendProps
169: .getLegendGapThicknessModel());
170: legend.setBackgroundExistence(legendProps
171: .getLegendBackgroundExistence());
172: legend.setBackgroundColor(legendProps
173: .getLegendBackgroundColor());
174: legend.setLabels(legendProps.getLegendLabelsTexts());
175: legend.setFontPointModel(legendProps
176: .getLegendLabelsFontPointModel());
177: legend.setFontName(legendProps.getLegendLabelsFontName());
178: legend.setFontColor(legendProps.getLegendLabelsFontColor());
179: legend.setFontStyle(legendProps.getLegendLabelsFontStyle());
180: legend.setBetweenBulletsGapExistence(legendProps
181: .getLegendBetweenLabelsOrBulletsGapExistence());
182: legend
183: .setBetweenBulletsGapThicknessModel(legendProps
184: .getLegendBetweenLabelsOrBulletsGapThicknessModel());
185: legend.setBetweenLabelsGapExistence(legendProps
186: .getLegendBetweenLabelsOrBulletsGapExistence());
187: legend
188: .setBetweenLabelsGapThicknessModel(legendProps
189: .getLegendBetweenLabelsOrBulletsGapThicknessModel());
190: legend.setBetweenBulletsAndLabelsGapExistence(legendProps
191: .getLegendBetweenLabelsAndBulletsGapExistence());
192: legend
193: .setBetweenBulletsAndLabelsGapThicknessModel(legendProps
194: .getLegendBetweenLabelsAndBulletsGapThicknessModel());
195: legend.setBulletsOutline(legendProps
196: .getLegendBulletsOutlineExistence());
197: legend.setBulletsOutlineColor(legendProps
198: .getLegendBulletsOutlineColor());
199: legend.setBulletsSizeModel(legendProps
200: .getLegendBulletsSizeModel());
201: }
202: }
203: }
|