1 46 47 package org.jfree.chart.axis; 48 49 import java.awt.BasicStroke ; 50 import java.awt.Color ; 51 import java.awt.Font ; 52 import java.awt.Paint ; 53 import java.awt.Stroke ; 54 import java.io.IOException ; 55 import java.io.ObjectInputStream ; 56 import java.io.ObjectOutputStream ; 57 import java.io.Serializable ; 58 import java.lang.reflect.Constructor ; 59 import java.text.DateFormat ; 60 import java.util.Date ; 61 import java.util.TimeZone ; 62 63 import org.jfree.data.time.RegularTimePeriod; 64 import org.jfree.io.SerialUtilities; 65 import org.jfree.ui.RectangleInsets; 66 67 71 public class PeriodAxisLabelInfo implements Cloneable , Serializable { 72 73 78 79 private static final long serialVersionUID = 5710451740920277357L; 80 81 82 public static final RectangleInsets DEFAULT_INSETS 83 = new RectangleInsets(2, 2, 2, 2); 84 85 86 public static final Font DEFAULT_FONT 87 = new Font ("SansSerif", Font.PLAIN, 10); 88 89 90 public static final Paint DEFAULT_LABEL_PAINT = Color.black; 91 92 93 public static final Stroke DEFAULT_DIVIDER_STROKE = new BasicStroke (0.5f); 94 95 96 public static final Paint DEFAULT_DIVIDER_PAINT = Color.gray; 97 98 99 private Class periodClass; 100 101 102 private RectangleInsets padding; 103 104 105 private DateFormat dateFormat; 106 107 108 private Font labelFont; 109 110 111 private transient Paint labelPaint; 112 113 114 private boolean drawDividers; 115 116 117 private transient Stroke dividerStroke; 118 119 120 private transient Paint dividerPaint; 121 122 129 public PeriodAxisLabelInfo(Class periodClass, DateFormat dateFormat) { 130 this( 131 periodClass, dateFormat, DEFAULT_INSETS, DEFAULT_FONT, 132 DEFAULT_LABEL_PAINT, true, DEFAULT_DIVIDER_STROKE, 133 DEFAULT_DIVIDER_PAINT 134 ); 135 } 136 137 153 public PeriodAxisLabelInfo(Class periodClass, DateFormat dateFormat, 154 RectangleInsets padding, 155 Font labelFont, Paint labelPaint, 156 boolean drawDividers, Stroke dividerStroke, 157 Paint dividerPaint) { 158 if (periodClass == null) { 159 throw new IllegalArgumentException ("Null 'periodClass' argument."); 160 } 161 if (dateFormat == null) { 162 throw new IllegalArgumentException ("Null 'dateFormat' argument."); 163 } 164 if (padding == null) { 165 throw new IllegalArgumentException ("Null 'padding' argument."); 166 } 167 if (labelFont == null) { 168 throw new IllegalArgumentException ("Null 'labelFont' argument."); 169 } 170 if (labelPaint == null) { 171 throw new IllegalArgumentException ("Null 'labelPaint' argument."); 172 } 173 if (dividerStroke == null) { 174 throw new IllegalArgumentException ("Null 'dividerStroke' argument."); 175 } 176 if (dividerPaint == null) { 177 throw new IllegalArgumentException ("Null 'dividerPaint' argument."); 178 } 179 this.periodClass = periodClass; 180 this.dateFormat = dateFormat; 181 this.padding = padding; 182 this.labelFont = labelFont; 183 this.labelPaint = labelPaint; 184 this.drawDividers = drawDividers; 185 this.dividerStroke = dividerStroke; 186 this.dividerPaint = dividerPaint; 187 } 188 189 195 public Class getPeriodClass() { 196 return this.periodClass; 197 } 198 199 204 public DateFormat getDateFormat() { 205 return this.dateFormat; 206 } 207 208 213 public RectangleInsets getPadding() { 214 return this.padding; 215 } 216 217 222 public Font getLabelFont() { 223 return this.labelFont; 224 } 225 226 231 public Paint getLabelPaint() { 232 return this.labelPaint; 233 } 234 235 240 public boolean getDrawDividers() { 241 return this.drawDividers; 242 } 243 244 249 public Stroke getDividerStroke() { 250 return this.dividerStroke; 251 } 252 253 258 public Paint getDividerPaint() { 259 return this.dividerPaint; 260 } 261 262 271 public RegularTimePeriod createInstance(Date millisecond, TimeZone zone) { 272 RegularTimePeriod result = null; 273 try { 274 Constructor c = this.periodClass.getDeclaredConstructor( 275 new Class [] {Date .class, TimeZone .class} 276 ); 277 result = (RegularTimePeriod) c.newInstance( 278 new Object [] {millisecond, zone} 279 ); 280 } 281 catch (Exception e) { 282 } 284 return result; 285 } 286 287 294 public boolean equals(Object obj) { 295 if (obj == this) { 296 return true; 297 } 298 if (obj instanceof PeriodAxisLabelInfo) { 299 PeriodAxisLabelInfo info = (PeriodAxisLabelInfo) obj; 300 if (!info.periodClass.equals(this.periodClass)) { 301 return false; 302 } 303 if (!info.dateFormat.equals(this.dateFormat)) { 304 return false; 305 } 306 if (!info.padding.equals(this.padding)) { 307 return false; 308 } 309 if (!info.labelFont.equals(this.labelFont)) { 310 return false; 311 } 312 if (!info.labelPaint.equals(this.labelPaint)) { 313 return false; 314 } 315 if (info.drawDividers != this.drawDividers) { 316 return false; 317 } 318 if (!info.dividerStroke.equals(this.dividerStroke)) { 319 return false; 320 } 321 if (!info.dividerPaint.equals(this.dividerPaint)) { 322 return false; 323 } 324 return true; 325 } 326 return false; 327 } 328 329 334 public int hashCode() { 335 int result = 41; 336 result = 37 * this.periodClass.hashCode(); 337 result = 37 * this.dateFormat.hashCode(); 338 return result; 339 } 340 341 348 public Object clone() throws CloneNotSupportedException { 349 Object clone = (PeriodAxisLabelInfo) super.clone(); 350 return clone; 351 } 352 353 360 private void writeObject(ObjectOutputStream stream) throws IOException { 361 stream.defaultWriteObject(); 362 SerialUtilities.writePaint(this.labelPaint, stream); 363 SerialUtilities.writeStroke(this.dividerStroke, stream); 364 SerialUtilities.writePaint(this.dividerPaint, stream); 365 } 366 367 375 private void readObject(ObjectInputStream stream) 376 throws IOException , ClassNotFoundException { 377 stream.defaultReadObject(); 378 this.labelPaint = SerialUtilities.readPaint(stream); 379 this.dividerStroke = SerialUtilities.readStroke(stream); 380 this.dividerPaint = SerialUtilities.readPaint(stream); 381 } 382 383 } 384 | Popular Tags |