KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
28  * An abstract class for the common methods of GraphChart2D and PieChart2D.
29  * These are methods for handling the Chart2DProperties object and the LegendProperties object.
30  * Changes through its set methods are updated upon next repaint() or getImage() calls.
31  */

32 public abstract class Chart2D extends Object2D {
33
34
35   private Chart2DProperties chart2DProps;
36   private LegendProperties legendProps;
37   private boolean needsUpdate;
38
39
40   /**
41    * Creates a Chart2D object with its defaults.
42    * A Chart2DProperties object must be set for this object before it is used.
43    * An LegendProperties object must be set for this object before it is used.
44    */

45   public Chart2D() {
46     needsUpdate = true;
47   }
48
49
50   /**
51    * Sets the Chart2DProperties for this Chart2D.
52    * @param props The Chart2DProperties.
53    */

54   public final void setChart2DProperties (Chart2DProperties props) {
55
56     needsUpdate = true;
57     props.addChart2D (this);
58     if (chart2DProps != null) chart2DProps.removeChart2D (this);
59     chart2DProps = props;
60   }
61
62
63   /**
64    * Sets the LegendProperties for this Chart2D.
65    * @param props The LegendProperties.
66    */

67   public final void setLegendProperties (LegendProperties props) {
68
69     needsUpdate = true;
70     props.addChart2D (this);
71     if (legendProps != null) legendProps.removeChart2D (this);
72     legendProps = props;
73   }
74
75
76   /**
77    * Gets the Chart2DProperties for this Chart2D.
78    * @return The Chart2DProperties.
79    */

80   public final Chart2DProperties getChart2DProperties() {
81     return chart2DProps;
82   }
83
84
85   /**
86    * Gets the LegendProperties for this Chart2D.
87    * @return The LegendProperties.
88    */

89   public final LegendProperties getLegendProperties() {
90     return legendProps;
91   }
92
93
94   /**
95    * Gets whether this object needs to be updated.
96    * @return If true then needs update.
97    */

98   final boolean getNeedsUpdateChart2D() {
99     return (needsUpdate || getNeedsUpdateObject2D() ||
100     chart2DProps.getChart2DNeedsUpdate (this) || legendProps.getChart2DNeedsUpdate (this));
101   }
102
103
104   /**
105    * Validates the properties of this object.
106    * If debug is true then prints a messages indicating whether each property is valid.
107    * Returns true if all the properties were valid and false otherwise.
108    * @param debug If true then will print status messages.
109    * @return If true then valid.
110    */

111   final boolean validateChart2D (boolean debug) {
112
113     if (debug) System.out.println ("Validating Chart2D");
114
115     boolean valid = true;
116
117     if (!validateObject2D (debug)) valid = false;
118
119     if (chart2DProps == null) {
120       valid = false;
121       if (debug) System.out.println ("Chart2DProperties is null");
122     }
123     else if (!chart2DProps.validate (debug)) valid = false;
124
125     if (legendProps == null) {
126       valid = false;
127       if (debug) System.out.println ("LegendProperties is null");
128     }
129     else if (!legendProps.validate (debug)) valid = false;
130
131     if (debug) {
132       if (valid) System.out.println ("Chart2D was valid");
133       else System.out.println ("Chart2D was invalid");
134     }
135
136     return valid;
137   }
138
139
140   /**
141    * Updates this object with the settings from the properties objects.
142    */

143   final void updateChart2D() {
144
145     if (getNeedsUpdateChart2D()) {
146
147       needsUpdate = false;
148
149       updateObject2D();
150
151       chart2DProps.updateChart2D (this);
152       legendProps.updateChart2D (this);
153
154       ChartArea chart = (ChartArea)getObjectArea();
155       LegendArea legend = chart.getLegend();
156
157       chart.setLabelsPrecisionNum (chart2DProps.getChartDataLabelsPrecision());
158       chart.setBetweenChartAndLegendGapExistence (
159         chart2DProps.getChartBetweenChartAndLegendGapExistence());
160       chart.setBetweenChartAndLegendGapThicknessModel (
161         chart2DProps.getChartBetweenChartAndLegendGapThicknessModel());
162
163       chart.setLegendExistence (legendProps.getLegendExistence());
164       legend.setBorderExistence (legendProps.getLegendBorderExistence());
165       legend.setBorderThicknessModel (legendProps.getLegendBorderThicknessModel());
166       legend.setBorderColor (legendProps.getLegendBorderColor());
167       legend.setGapExistence (legendProps.getLegendGapExistence());
168       legend.setGapThicknessModel (legendProps.getLegendGapThicknessModel());
169       legend.setBackgroundExistence (legendProps.getLegendBackgroundExistence());
170       legend.setBackgroundColor (legendProps.getLegendBackgroundColor());
171       legend.setLabels (legendProps.getLegendLabelsTexts());
172       legend.setFontPointModel (legendProps.getLegendLabelsFontPointModel());
173       legend.setFontName (legendProps.getLegendLabelsFontName());
174       legend.setFontColor (legendProps.getLegendLabelsFontColor());
175       legend.setFontStyle (legendProps.getLegendLabelsFontStyle());
176       legend.setBetweenBulletsGapExistence (
177         legendProps.getLegendBetweenLabelsOrBulletsGapExistence());
178       legend.setBetweenBulletsGapThicknessModel (
179         legendProps.getLegendBetweenLabelsOrBulletsGapThicknessModel());
180       legend.setBetweenLabelsGapExistence (
181         legendProps.getLegendBetweenLabelsOrBulletsGapExistence());
182       legend.setBetweenLabelsGapThicknessModel (
183         legendProps.getLegendBetweenLabelsOrBulletsGapThicknessModel());
184       legend.setBetweenBulletsAndLabelsGapExistence (
185         legendProps.getLegendBetweenLabelsAndBulletsGapExistence());
186       legend.setBetweenBulletsAndLabelsGapThicknessModel (
187         legendProps.getLegendBetweenLabelsAndBulletsGapThicknessModel());
188       legend.setBulletsOutline (legendProps.getLegendBulletsOutlineExistence());
189       legend.setBulletsOutlineColor (legendProps.getLegendBulletsOutlineColor());
190       legend.setBulletsSizeModel (legendProps.getLegendBulletsSizeModel());
191     }
192   }
193 }
Popular Tags