KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > editor2d > impl > ShapeDrawComponentImpl


1 /**
2  * <copyright>
3  * </copyright>
4  *
5  * $Id: ShapeDrawComponentImpl.java 1634 2005-08-26 19:26:15Z nozkiller $
6  */

7 package com.nightlabs.editor2d.impl;
8
9 import java.awt.Color JavaDoc;
10 import java.awt.Rectangle JavaDoc;
11 import java.awt.geom.AffineTransform JavaDoc;
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     /**
21      * The Default Fill Color = WHITE
22      */

23   protected static final Color JavaDoc FILL_COLOR_EDEFAULT = Color.WHITE;
24   protected Color JavaDoc fillColor = FILL_COLOR_EDEFAULT;
25
26   /**
27    * The Default Line Color = BLACK
28    */

29   protected static final Color JavaDoc LINE_COLOR_EDEFAULT = Color.BLACK;
30   protected Color JavaDoc lineColor = LINE_COLOR_EDEFAULT;
31
32   /**
33    * The Default Line Style = 1
34    */

35   protected static final int LINE_STYLE_EDEFAULT = 1;
36   protected int lineStyle = LINE_STYLE_EDEFAULT;
37
38   /**
39    * The Default Line Width = 1
40    */

41   protected static final int LINE_WIDTH_EDEFAULT = 1;
42   protected int lineWidth = LINE_WIDTH_EDEFAULT;
43
44   /**
45    * The Default GeneralShape = null
46    */

47   protected static final GeneralShape GENERAL_SHAPE_EDEFAULT = null;
48   protected transient GeneralShape generalShape = GENERAL_SHAPE_EDEFAULT;
49
50   /**
51    * The Default Fill Behaviour = true
52    */

53   protected static final boolean FILL_EDEFAULT = true;
54   protected boolean fill = FILL_EDEFAULT;
55
56   public ShapeDrawComponentImpl() {
57         super();
58     }
59
60     /**
61      * <!-- begin-user-doc -->
62    * <!-- end-user-doc -->
63      * @generated
64      */

65   public boolean isFill() {
66         return fill;
67     }
68
69     /**
70      * <!-- begin-user-doc -->
71    * <!-- end-user-doc -->
72      * @generated
73      */

74   public void setFill(boolean newFill) {
75         boolean oldFill = fill;
76         fill = newFill;
77         firePropertyChange(PROP_FILL, oldFill, fill);
78     }
79
80     /**
81      * <!-- begin-user-doc -->
82    * <!-- end-user-doc -->
83      * @generated
84      */

85   public Color JavaDoc getFillColor() {
86         return fillColor;
87     }
88
89     /**
90      * <!-- begin-user-doc -->
91    * <!-- end-user-doc -->
92      * @generated
93      */

94   public void setFillColor(Color JavaDoc newFillColor) {
95         Color JavaDoc oldFillColor = fillColor;
96         fillColor = newFillColor;
97         firePropertyChange(PROP_FILL_COLOR, oldFillColor, fillColor);
98   }
99
100     /**
101      * <!-- begin-user-doc -->
102    * <!-- end-user-doc -->
103      * @generated
104      */

105   public Color JavaDoc getLineColor() {
106         return lineColor;
107     }
108
109     /**
110      * <!-- begin-user-doc -->
111    * <!-- end-user-doc -->
112      * @generated
113      */

114   public void setLineColor(Color JavaDoc newLineColor) {
115         Color JavaDoc oldLineColor = lineColor;
116         lineColor = newLineColor;
117         firePropertyChange(PROP_LINE_COLOR, oldLineColor, lineColor);
118     }
119
120     /**
121      * <!-- begin-user-doc -->
122    * <!-- end-user-doc -->
123      * @generated
124      */

125   public int getLineStyle() {
126         return lineStyle;
127     }
128
129     /**
130      * <!-- begin-user-doc -->
131    * <!-- end-user-doc -->
132      * @generated
133      */

134   public void setLineStyle(int newLineStyle) {
135         int oldLineStyle = lineStyle;
136         lineStyle = newLineStyle;
137         firePropertyChange(PROP_LINE_COLOR, oldLineStyle, lineStyle);
138     }
139
140     /**
141      * <!-- begin-user-doc -->
142    * <!-- end-user-doc -->
143      * @generated
144      */

145   public int getLineWidth() {
146         return lineWidth;
147     }
148
149     /**
150      * <!-- begin-user-doc -->
151    * <!-- end-user-doc -->
152      * @generated
153      */

154   public void setLineWidth(int newLineWidth) {
155         int oldLineWidth = lineWidth;
156         lineWidth = newLineWidth;
157         firePropertyChange(PROP_LINE_WIDTH, oldLineWidth, lineWidth);
158     }
159
160     /**
161      * <!-- begin-user-doc -->
162    * <!-- end-user-doc -->
163      * @generated
164      */

165   public GeneralShape getGeneralShape() {
166         return generalShape;
167     }
168
169     /**
170      * <!-- begin-user-doc -->
171    * <!-- end-user-doc -->
172      * @generated
173      */

174   public String JavaDoc toString()
175   {
176         StringBuffer JavaDoc result = new StringBuffer JavaDoc(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   /**
194    * @return the Bounds of the ShapeDrawComponent
195    * if a GeneralShape is present (!= null), those bounds are returned,
196    * else a new Rectangle with the values of the members x, y, width, height is returned
197    *
198    */

199   public Rectangle JavaDoc 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   /**
210    * transforms the GeneralShape based on the given AffineTransform
211    * this is done by first cloning the originalShape and then transforming the clone,
212    * this reduces rounding errors when transforming multiple times
213    * @param at the AffineTransform which contains the transform Information
214    * @see java.awt.geom.AffineTransform
215    */

216   public void transform(AffineTransform JavaDoc at)
217   {
218     Rectangle JavaDoc 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     // TODO: maybe also fire Bounds Change
228
// if (eNotificationRequired())
229
// eNotify(new ENotificationImpl(this, Notification.SET, Editor2DPackage.SHAPE_DRAW_COMPONENT__BOUNDS, oldBounds, getBounds()));
230
}
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 JavaDoc getRenderModeClass() {
247     return ShapeDrawComponent.class;
248   }
249   
250 // public String getTypeName() {
251
// return ModelPlugin.getResourceString("type.shapeDrawComponent");
252
// }
253
public String JavaDoc getTypeName() {
254     return "Shape";
255   }
256   
257 } //ShapeDrawComponentImpl
258
Popular Tags