1 26 27 package org.nightlabs.editor2d.impl; 28 29 import java.awt.Color ; 30 import java.awt.Rectangle ; 31 import java.awt.geom.AffineTransform ; 32 import java.util.Iterator ; 33 34 import org.nightlabs.editor2d.DrawComponent; 35 import org.nightlabs.editor2d.DrawComponentContainer; 36 import org.nightlabs.editor2d.ShapeDrawComponent; 37 import org.nightlabs.editor2d.j2d.GeneralShape; 38 39 public class ShapeDrawComponentImpl 40 extends DrawComponentImpl 41 implements ShapeDrawComponent 42 { 43 46 protected static final Color FILL_COLOR_EDEFAULT = Color.WHITE; 47 protected Color fillColor = FILL_COLOR_EDEFAULT; 48 49 52 protected static final Color LINE_COLOR_EDEFAULT = Color.BLACK; 53 protected Color lineColor = LINE_COLOR_EDEFAULT; 54 55 58 protected static final int LINE_STYLE_EDEFAULT = 1; 59 protected int lineStyle = LINE_STYLE_EDEFAULT; 60 61 64 protected static final int LINE_WIDTH_EDEFAULT = 1; 65 protected int lineWidth = LINE_WIDTH_EDEFAULT; 66 67 70 protected static final GeneralShape GENERAL_SHAPE_EDEFAULT = null; 71 protected GeneralShape generalShape = GENERAL_SHAPE_EDEFAULT; 72 73 76 protected static final boolean FILL_EDEFAULT = true; 77 protected boolean fill = FILL_EDEFAULT; 78 79 public ShapeDrawComponentImpl() { 80 super(); 81 } 82 83 88 public boolean isFill() { 89 return fill; 90 } 91 92 97 public void setFill(boolean newFill) { 98 boolean oldFill = fill; 99 fill = newFill; 100 firePropertyChange(PROP_FILL, oldFill, fill); 101 } 102 103 108 public Color getFillColor() { 109 return fillColor; 110 } 111 112 117 public void setFillColor(Color newFillColor) { 118 Color oldFillColor = fillColor; 119 fillColor = newFillColor; 120 firePropertyChange(PROP_FILL_COLOR, oldFillColor, fillColor); 121 } 122 123 128 public Color getLineColor() { 129 return lineColor; 130 } 131 132 137 public void setLineColor(Color newLineColor) { 138 Color oldLineColor = lineColor; 139 lineColor = newLineColor; 140 firePropertyChange(PROP_LINE_COLOR, oldLineColor, lineColor); 141 } 142 143 148 public int getLineStyle() { 149 return lineStyle; 150 } 151 152 157 public void setLineStyle(int newLineStyle) { 158 int oldLineStyle = lineStyle; 159 lineStyle = newLineStyle; 160 firePropertyChange(PROP_LINE_COLOR, oldLineStyle, lineStyle); 161 } 162 163 168 public int getLineWidth() { 169 return lineWidth; 170 } 171 172 177 public void setLineWidth(int newLineWidth) { 178 int oldLineWidth = lineWidth; 179 lineWidth = newLineWidth; 180 firePropertyChange(PROP_LINE_WIDTH, oldLineWidth, lineWidth); 181 } 182 183 188 public GeneralShape getGeneralShape() { 189 return generalShape; 190 } 191 192 197 public String toString() 198 { 199 StringBuffer result = new StringBuffer (super.toString()); 200 result.append(" (fillColor: "); 201 result.append(fillColor); 202 result.append(", lineColor: "); 203 result.append(lineColor); 204 result.append(", lineStyle: "); 205 result.append(lineStyle); 206 result.append(", lineWidth: "); 207 result.append(lineWidth); 208 result.append(", generalShape: "); 209 result.append(generalShape); 210 result.append(", fill: "); 211 result.append(fill); 212 result.append(')'); 213 return result.toString(); 214 } 215 216 222 public Rectangle getBounds() 223 { 224 if (getGeneralShape() != null) 225 return getGeneralShape().getBounds(); 226 else 227 return super.getBounds(); 228 } 229 230 protected GeneralShape originalShape = null; 231 public GeneralShape getOriginalShape() { 232 return originalShape; 233 } 234 235 242 public void transform(AffineTransform at, boolean fromParent) 243 { 244 Rectangle oldBounds = getBounds(); 245 if (generalShape != null) { 246 super.transform(at, fromParent); 248 generalShape = (GeneralShape) originalShape.clone(); 249 generalShape.transform(affineTransform); 250 } 251 252 if (!fromParent && getParent() != null) 253 getParent().notifyChildTransform(this); 254 255 bounds = null; 256 } 257 258 public void setGeneralShape(GeneralShape newGeneralShape) 259 { 260 GeneralShape oldGeneralShape = generalShape; 261 primSetGeneralShape(newGeneralShape); 262 firePropertyChange(PROP_GENERAL_SHAPE, oldGeneralShape, generalShape); 263 } 264 265 protected void primSetGeneralShape(GeneralShape gs) 266 { 267 generalShape = gs; 268 originalShape = (GeneralShape) gs.clone(); 269 bounds = null; 270 } 271 272 public Class getRenderModeClass() { 273 return ShapeDrawComponent.class; 274 } 275 276 public String getTypeName() { 280 return "Shape"; 281 } 282 283 293 public Object clone(DrawComponentContainer parent) 294 { 295 ShapeDrawComponentImpl sdc = (ShapeDrawComponentImpl) super.clone(parent); 296 sdc.generalShape = (GeneralShape) generalShape.clone(); 297 sdc.originalShape = (GeneralShape) originalShape.clone(); 298 sdc.fillColor = new Color (fillColor.getRed(), fillColor.getGreen(), fillColor.getBlue(), fillColor.getAlpha()); 299 sdc.lineColor = new Color (lineColor.getRed(), lineColor.getGreen(), lineColor.getBlue(), lineColor.getAlpha()); 300 301 sdc.fill = fill; 302 sdc.lineStyle = lineStyle; 303 sdc.lineWidth = lineWidth; 304 305 return sdc; 306 } 307 308 315 } | Popular Tags |