1 22 23 24 package net.sourceforge.chart2d; 25 26 27 import java.awt.*; 28 import java.awt.image.*; 29 import javax.swing.*; 30 31 32 37 public abstract class Object2D extends JComponent { 38 39 40 43 public static final Dimension MAX_SIZE_DEFAULT = new Dimension (1024, 768); 44 45 48 public static final Dimension MIN_SIZE_DEFAULT = new Dimension (1, 1); 49 50 51 private Object2DProperties object2DProps; 52 private boolean needsUpdate; 53 54 55 59 public Object2D() { 60 61 needsUpdate = true; 62 setMaximumSize (MAX_SIZE_DEFAULT); 63 setMinimumSize (MIN_SIZE_DEFAULT); 64 } 65 66 67 71 public final void setObject2DProperties (Object2DProperties props) { 72 73 needsUpdate = true; 74 props.addObject2D (this); 75 if (object2DProps != null) object2DProps.removeObject2D (this); 76 object2DProps = props; 77 } 78 79 80 86 public abstract void setPreferredSize (Dimension size); 87 88 89 93 public final void setMaximumSize (Dimension size) { 94 95 needsUpdate = true; 96 super.setMaximumSize (size); 97 } 98 99 100 104 public final void setMinimumSize (Dimension size) { 105 106 needsUpdate = true; 107 super.setMinimumSize (size); 108 } 109 110 111 115 public final Object2DProperties getObject2DProperties() { 116 return object2DProps; 117 } 118 119 120 126 public abstract Dimension getPreferredSize(); 127 128 129 133 final boolean getNeedsUpdateObject2D() { 134 return (needsUpdate || object2DProps.getObject2DNeedsUpdate (this)); 135 } 136 137 138 142 abstract TitledArea getObjectArea(); 143 144 145 152 final boolean validateObject2D (boolean debug) { 153 154 if (debug) System.out.println ("Validating Object2D"); 155 156 boolean valid = true; 157 158 if (object2DProps == null) { 159 valid = false; 160 if (debug) System.out.println ("Object2DProperties is null"); 161 } 162 else if (!object2DProps.validate (debug)) valid = false; 163 164 if (getMaximumSize() == null || 165 getMaximumSize().height < 1 || getMaximumSize().width < 1 || 166 getMaximumSize().height < getMinimumSize().height || 167 getMaximumSize().width < getMinimumSize().width) { 168 valid = false; 169 if (debug) System.out.println ("Problem with maximum size"); 170 } 171 if (getMinimumSize() == null || 172 getMinimumSize().height < 1 || getMinimumSize().width < 1) { 173 valid = false; 174 if (debug) System.out.println ("Problem with minimum size"); 175 } 176 177 if (debug) { 178 if (valid) System.out.println ("Object2D was valid"); 179 else System.out.println ("Object2D was invalid"); 180 } 181 182 return valid; 183 } 184 185 186 189 final void updateObject2D() { 190 191 if (getNeedsUpdateObject2D()) { 192 193 needsUpdate = false; 194 object2DProps.updateObject2D (this); 195 196 TitledArea object = (TitledArea)getObjectArea(); 197 object.setAutoSizes (!object2DProps.getObjectMagnifyWhenResize(), true); 198 object.setBorderExistence (object2DProps.getObjectBorderExistence()); 199 object.setBorderThicknessModel (object2DProps.getObjectBorderThicknessModel()); 200 object.setBorderColor (object2DProps.getObjectBorderColor()); 201 object.setGapExistence (object2DProps.getObjectGapExistence()); 202 object.setGapThicknessModel (object2DProps.getObjectGapThicknessModel()); 203 object.setBackgroundExistence (object2DProps.getObjectBackgroundExistence()); 204 object.setBackgroundColor (object2DProps.getObjectBackgroundColor()); 205 object.setLightSource (object2DProps.getObjectBackgroundLightSource()); 206 object.setTitleExistence (object2DProps.getObjectTitleExistence()); 207 object.setTitle (object2DProps.getObjectTitleText()); 208 object.setFontPointModel (object2DProps.getObjectTitleFontPointModel()); 209 object.setFontName (object2DProps.getObjectTitleFontName()); 210 object.setFontColor (object2DProps.getObjectTitleFontColor()); 211 object.setFontStyle (object2DProps.getObjectTitleFontStyle()); 212 object.setBetweenTitleAndSpaceGapExistence ( 213 object2DProps.getObjectTitleBetweenRestGapExistence()); 214 object.setBetweenTitleAndSpaceGapThicknessModel ( 215 object2DProps.getObjectTitleBetweenRestGapThicknessModel()); 216 } 217 } 218 219 220 224 public abstract BufferedImage getImage(); 225 226 227 230 public abstract void pack(); 231 232 233 240 public abstract boolean validate (boolean debug); 241 } | Popular Tags |