1 7 package com.nightlabs.editor2d.impl; 8 9 import java.awt.Color ; 10 import java.awt.Rectangle ; 11 import java.awt.geom.AffineTransform ; 12 13 import com.nightlabs.editor2d.ShapeDrawComponent; 14 import com.nightlabs.editor2d.j2d.GeneralShape; 15 16 public class ShapeDrawComponentImpl 17 extends DrawComponentImpl 18 implements ShapeDrawComponent 19 { 20 23 protected static final Color FILL_COLOR_EDEFAULT = Color.WHITE; 24 protected Color fillColor = FILL_COLOR_EDEFAULT; 25 26 29 protected static final Color LINE_COLOR_EDEFAULT = Color.BLACK; 30 protected Color lineColor = LINE_COLOR_EDEFAULT; 31 32 35 protected static final int LINE_STYLE_EDEFAULT = 1; 36 protected int lineStyle = LINE_STYLE_EDEFAULT; 37 38 41 protected static final int LINE_WIDTH_EDEFAULT = 1; 42 protected int lineWidth = LINE_WIDTH_EDEFAULT; 43 44 47 protected static final GeneralShape GENERAL_SHAPE_EDEFAULT = null; 48 protected transient GeneralShape generalShape = GENERAL_SHAPE_EDEFAULT; 49 50 53 protected static final boolean FILL_EDEFAULT = true; 54 protected boolean fill = FILL_EDEFAULT; 55 56 public ShapeDrawComponentImpl() { 57 super(); 58 } 59 60 65 public boolean isFill() { 66 return fill; 67 } 68 69 74 public void setFill(boolean newFill) { 75 boolean oldFill = fill; 76 fill = newFill; 77 firePropertyChange(PROP_FILL, oldFill, fill); 78 } 79 80 85 public Color getFillColor() { 86 return fillColor; 87 } 88 89 94 public void setFillColor(Color newFillColor) { 95 Color oldFillColor = fillColor; 96 fillColor = newFillColor; 97 firePropertyChange(PROP_FILL_COLOR, oldFillColor, fillColor); 98 } 99 100 105 public Color getLineColor() { 106 return lineColor; 107 } 108 109 114 public void setLineColor(Color newLineColor) { 115 Color oldLineColor = lineColor; 116 lineColor = newLineColor; 117 firePropertyChange(PROP_LINE_COLOR, oldLineColor, lineColor); 118 } 119 120 125 public int getLineStyle() { 126 return lineStyle; 127 } 128 129 134 public void setLineStyle(int newLineStyle) { 135 int oldLineStyle = lineStyle; 136 lineStyle = newLineStyle; 137 firePropertyChange(PROP_LINE_COLOR, oldLineStyle, lineStyle); 138 } 139 140 145 public int getLineWidth() { 146 return lineWidth; 147 } 148 149 154 public void setLineWidth(int newLineWidth) { 155 int oldLineWidth = lineWidth; 156 lineWidth = newLineWidth; 157 firePropertyChange(PROP_LINE_WIDTH, oldLineWidth, lineWidth); 158 } 159 160 165 public GeneralShape getGeneralShape() { 166 return generalShape; 167 } 168 169 174 public String toString() 175 { 176 StringBuffer result = new StringBuffer (super.toString()); 177 result.append(" (fillColor: "); 178 result.append(fillColor); 179 result.append(", lineColor: "); 180 result.append(lineColor); 181 result.append(", lineStyle: "); 182 result.append(lineStyle); 183 result.append(", lineWidth: "); 184 result.append(lineWidth); 185 result.append(", generalShape: "); 186 result.append(generalShape); 187 result.append(", fill: "); 188 result.append(fill); 189 result.append(')'); 190 return result.toString(); 191 } 192 193 199 public Rectangle getBounds() 200 { 201 if (getGeneralShape() != null) 202 return getGeneralShape().getBounds(); 203 else 204 return super.getBounds(); 205 } 206 207 protected GeneralShape originalShape = null; 208 209 216 public void transform(AffineTransform at) 217 { 218 Rectangle oldBounds = getBounds(); 219 if (generalShape != null) { 220 super.transform(at); 221 generalShape = (GeneralShape) originalShape.clone(); 222 generalShape.transform(affineTransform); 223 } 224 if (getParent() != null) 225 getParent().notifyChildTransform(this); 226 227 } 231 232 public void setGeneralShape(GeneralShape newGeneralShape) 233 { 234 GeneralShape oldGeneralShape = generalShape; 235 primSetGeneralShape(newGeneralShape); 236 firePropertyChange(PROP_GENERAL_SHAPE, oldGeneralShape, generalShape); 237 } 238 239 protected void primSetGeneralShape(GeneralShape gs) 240 { 241 generalShape = gs; 242 originalShape = (GeneralShape) gs.clone(); 243 bounds = null; 244 } 245 246 public Class getRenderModeClass() { 247 return ShapeDrawComponent.class; 248 } 249 250 public String getTypeName() { 254 return "Shape"; 255 } 256 257 } | Popular Tags |