1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.Color ; 28 import java.awt.Dimension ; 29 import java.awt.Font ; 30 import java.util.Vector ; 31 32 33 38 public final class Chart2DProperties extends Properties { 39 40 41 44 public static final int MAX_INTEGER = 38; 45 46 49 public static final int MAX_FLOAT = -38; 50 51 54 public final static int CHART_DATA_LABELS_PRECISION_DEFAULT = MAX_INTEGER; 55 56 59 public final static boolean CHART_BETWEEN_CHART_AND_LEGEND_GAP_EXISTENCE_DEFAULT = true; 60 61 64 public final static int CHART_BETWEEN_CHART_AND_LEGEND_GAP_THICKNESS_MODEL_DEFAULT = 5; 65 66 67 private int chartDataLabelsPrecision; 68 private boolean chartBetweenChartAndLegendGapExistence; 69 private int chartBetweenChartAndLegendGapThicknessModel; 70 71 private boolean needsUpdate = true; 72 private final Vector chart2DVector = new Vector (5, 5); 73 private final Vector needsUpdateVector = new Vector (5, 5); 74 75 76 79 public Chart2DProperties() { 80 81 needsUpdate = true; 82 setChart2DPropertiesToDefaults(); 83 } 84 85 86 91 public Chart2DProperties (Chart2DProperties chart2DProps) { 92 93 needsUpdate = true; 94 setChart2DProperties (chart2DProps); 95 } 96 97 98 101 public final void setChart2DPropertiesToDefaults() { 102 103 needsUpdate = true; 104 setChartDataLabelsPrecision (CHART_DATA_LABELS_PRECISION_DEFAULT); 105 setChartBetweenChartAndLegendGapExistence ( 106 CHART_BETWEEN_CHART_AND_LEGEND_GAP_EXISTENCE_DEFAULT); 107 setChartBetweenChartAndLegendGapThicknessModel ( 108 CHART_BETWEEN_CHART_AND_LEGEND_GAP_THICKNESS_MODEL_DEFAULT); 109 } 110 111 112 117 public final void setChart2DProperties (Chart2DProperties chart2DProps) { 118 119 needsUpdate = true; 120 setChartDataLabelsPrecision (chart2DProps.getChartDataLabelsPrecision()); 121 setChartBetweenChartAndLegendGapExistence ( 122 chart2DProps.getChartBetweenChartAndLegendGapExistence()); 123 setChartBetweenChartAndLegendGapThicknessModel ( 124 chart2DProps.getChartBetweenChartAndLegendGapThicknessModel()); 125 } 126 127 128 156 public final void setChartDataLabelsPrecision (int precision) { 157 158 needsUpdate = true; 159 chartDataLabelsPrecision = precision; 160 } 161 162 163 168 public final void setChartBetweenChartAndLegendGapExistence (boolean existence) { 169 170 needsUpdate = true; 171 chartBetweenChartAndLegendGapExistence = existence; 172 } 173 174 175 179 public final void setChartBetweenChartAndLegendGapThicknessModel (int thickness) { 180 181 needsUpdate = true; 182 chartBetweenChartAndLegendGapThicknessModel = thickness; 183 } 184 185 186 214 public final int getChartDataLabelsPrecision() { 215 return chartDataLabelsPrecision; 216 } 217 218 219 224 public final boolean getChartBetweenChartAndLegendGapExistence() { 225 return chartBetweenChartAndLegendGapExistence; 226 } 227 228 229 233 public final int getChartBetweenChartAndLegendGapThicknessModel() { 234 return chartBetweenChartAndLegendGapThicknessModel; 235 } 236 237 238 243 final boolean getChart2DNeedsUpdate (Chart2D chart2D) { 244 245 if (needsUpdate) return true; 246 int index = -1; 247 if ((index = chart2DVector.indexOf (chart2D)) != -1) { 248 return ((Boolean )needsUpdateVector.get (index)).booleanValue(); 249 } 250 return false; 251 } 252 253 254 258 final void addChart2D (Chart2D chart2D) { 259 if (!chart2DVector.contains (chart2D)) { 260 chart2DVector.add (chart2D); 261 needsUpdateVector.add (new Boolean (true)); 262 } 263 } 264 265 266 270 final void removeChart2D (Chart2D chart2D) { 271 int index = -1; 272 if ((index = chart2DVector.indexOf (chart2D)) != -1) { 273 chart2DVector.remove (index); 274 needsUpdateVector.remove (index); 275 } 276 } 277 278 279 286 final boolean validate (boolean debug) { 287 288 if (debug) System.out.println ("Validating Chart2DProperties"); 289 290 boolean valid = true; 291 292 if (chartDataLabelsPrecision > MAX_INTEGER || chartDataLabelsPrecision < MAX_FLOAT) { 293 valid = false; 294 if (debug) System.out.println ("Problem with ChartDataLabelsPrecision"); 295 } 296 if (chartBetweenChartAndLegendGapThicknessModel < 0) { 297 valid = false; 298 if (debug) System.out.println ("ChartBetweenChartAndLegendGapThicknessModel < 0"); 299 } 300 301 if (debug) { 302 if (valid) System.out.println ("Chart2DProperties was valid"); 303 else System.out.println ("Chart2DProperties was invalid"); 304 } 305 306 return valid; 307 } 308 309 310 314 final void updateChart2D (Chart2D chart2D) { 315 316 if (getChart2DNeedsUpdate (chart2D)) { 317 318 if (needsUpdate) { 319 for (int i = 0; i < needsUpdateVector.size(); ++i) { 320 needsUpdateVector.set (i, new Boolean (true)); 321 } 322 needsUpdate = false; 323 } 324 325 int index = -1; 326 if ((index = chart2DVector.indexOf (chart2D)) != -1) { 327 needsUpdateVector.set (index, new Boolean (false)); 328 } 329 } 330 } 331 } | Popular Tags |