KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > DrawComponent


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d;
28
29 import java.awt.Rectangle JavaDoc;
30 import java.awt.geom.AffineTransform JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.util.Enumeration JavaDoc;
33
34 import org.nightlabs.editor2d.render.RenderModeManager;
35 import org.nightlabs.editor2d.render.Renderer;
36 import org.nightlabs.i18n.I18nText;
37
38 /**
39  * This is the base interface for all drawable objects
40  * The complete NightLabs Editor2D Framework is based on this interface
41  *
42  * <p> Author: Daniel.Mazurek[AT]NightLabs[DOT]de </p>
43  */

44 public interface DrawComponent
45 extends Cloneable JavaDoc
46 {
47     public static final String JavaDoc TRANSFORM_CHANGED = "transform changed";
48     
49     // Default Values
50
public static final int ROTATION_X_DEFAULT = Integer.MAX_VALUE;
51     public static final int ROTATION_Y_DEFAULT = Integer.MAX_VALUE;
52     public static final long ID_EDEFAULT = 0L;
53     public static final int X_EDEFAULT = 0;
54     public static final int Y_EDEFAULT = 0;
55     public static final int WIDTH_EDEFAULT = 0;
56     public static final int HEIGHT_EDEFAULT = 0;
57     public static final Rectangle JavaDoc BOUNDS_EDEFAULT = new Rectangle JavaDoc(X_EDEFAULT, Y_EDEFAULT, WIDTH_EDEFAULT, HEIGHT_EDEFAULT);
58     public static final double ROTATION_EDEFAULT = 0.0;
59     public static final int TMP_ROTATION_X_EDEFAULT = ROTATION_X_DEFAULT;
60     public static final int TMP_ROTATION_Y_EDEFAULT = ROTATION_Y_DEFAULT;
61     public static final int RENDER_MODE_EDEFAULT = RenderModeManager.DEFAULT_MODE;
62     public static final String JavaDoc DEFAULT_LANGUAGE_ID = I18nText.DEFAULT_LANGUAGEID;
63     
64     // Property Names
65
public static final String JavaDoc PROP_AFFINE_TRANSFORM = "affineTransform";
66     public static final String JavaDoc PROP_BOUNDS = "bounds";
67     public static final String JavaDoc PROP_HEIGHT = "height";
68     public static final String JavaDoc PROP_WIDTH = "width";
69     public static final String JavaDoc PROP_NAME = "name";
70     public static final String JavaDoc PROP_ID = "id";
71     public static final String JavaDoc PROP_PARENT = "parent";
72     public static final String JavaDoc PROP_RENDERER = "renderer";
73     public static final String JavaDoc PROP_RENDER_MODE = "renderMode";
74     public static final String JavaDoc PROP_ROTATION = "rotation";
75     public static final String JavaDoc PROP_ROTATION_X = "rotationX";
76     public static final String JavaDoc PROP_ROTATION_Y = "rotationY";
77     public static final String JavaDoc PROP_X = "x";
78     public static final String JavaDoc PROP_Y = "y";
79     public static final String JavaDoc PROP_HORIZONTAL_GUIDE = "horizontalGuide";
80     public static final String JavaDoc PROP_VERTICAL_GUIDE = "verticalGuide";
81     public static final String JavaDoc PROP_TMP_ROTATION_X = "tmpRotationX";
82     public static final String JavaDoc PROP_TMP_ROTATION_Y = "tmpRotationY";
83     public static final String JavaDoc PROP_LANGUAGE_ID = "languageID";
84     
85     /**
86      * adds an PropertyChangeListener to the DrawComponent
87      * is needed to get notified for property changes of the model
88      * @param pcl the PropertyChangeListener to add
89      */

90     void addPropertyChangeListener(PropertyChangeListener JavaDoc pcl);
91     
92     /**
93      * removes the given PropertyChangeListener from the DrawComponent
94      * @param pcl the PropertyChangeListener to remove
95      */

96     void removePropertyChangeListener(PropertyChangeListener JavaDoc pcl);
97     
98     /**
99      *
100      * @return the ID of the DrawComponent
101      */

102     long getId();
103     
104     /**
105      *
106      * @param value sets the ID of the DrawComponent
107      */

108     void setId(long value);
109
110     /**
111      *
112      * @return the name of the DrawComponent, for the current languageID
113      * @see getLanguageID()
114      */

115     String JavaDoc getName();
116     
117     /**
118      * sets the name of the DrawComponent
119      * (normally this is done by adding the name for the current languageID to the i18nText)
120      * @param name the name to set
121      */

122     void setName(String JavaDoc name);
123     
124     /**
125      * sets the languageID for the DrawComponent
126      * @param languageId the languageID to set
127      */

128     void setLanguageId(String JavaDoc languageId);
129     
130     /**
131      * the LanguageID is formated like in java.util.Locale (DE, EN, ...)
132      * @return the LanguageID for the DrawComponent
133      */

134     String JavaDoc getLanguageId();
135
136     /**
137      * the I18nText which contains localized Strings for different languageIDs
138      * @return the I18nText for the DrawComponent
139      * @see org.nightlabs.i18n.I18nText
140      */

141     I18nText getI18nText();
142     
143     /**
144      *
145      * @param text the I18nText to set for the DrawComponent
146      * @see org.nightlabs.i18n.I18nText
147      */

148     void setI18nText(I18nText text);
149     
150     /**
151      *
152      * @return the X-Coordinate for the DrawComponent in absolute Coordinates
153      */

154     int getX();
155     
156     /**
157      *
158      * @param value the X-Coordinate for the DrawComponent to set in absolute Coordinates
159      */

160     void setX(int value);
161
162     /**
163      *
164      * @return the Y-Coordinate for the DrawComponent in absolute Coordinates
165      */

166     int getY();
167     
168     /**
169      *
170      * @param value the Y-Coordinate for the DrawComponent to set in absolute Coordinates
171      */

172     void setY(int value);
173
174     /**
175      *
176      * @return the Width for the DrawComponent in absolute Coordinates
177      */

178     int getWidth();
179     
180     /**
181      *
182      * @param value the Width for the DrawComponent to set in absolute Coordinates
183      */

184     void setWidth(int value);
185
186     /**
187      *
188      * @return the Height for the DrawComponent in absolute Coordinates
189      */

190     int getHeight();
191
192     /**
193      *
194      * @param value the Height for the DrawComponent to set in absolute Coordinates
195      */

196     void setHeight(int value);
197     
198     /**
199      *
200      * @return the rotation of the DrawComponent in degrees (e.g. 45.00)
201      */

202     double getRotation();
203     
204     /**
205      *
206      * @param value the rotation of DrawComponent to set in degrees
207      */

208     void setRotation(double value);
209     
210     /**
211      * if no HorizontalGuide is set this Method should return null
212      * @return the Horizontal EditorGuide of the DrawComponent
213      * @see org.nightlabs.editor2d.EditorGuide
214      */

215     EditorGuide getHorizontalGuide();
216     
217     /**
218      *
219      * @param value the Horizontal EditorGuide of the DrawComponent to set
220      * @see org.nightlabs.editor2d.EditorGuide
221      */

222     void setHorizontalGuide(EditorGuide value);
223
224     /**
225      * if no VerticalGuide is set this Method should return null
226      * @return the Vertical EditorGuide of the DrawComponent
227      * @see org.nightlabs.editor2d.EditorGuide
228      */

229     EditorGuide getVerticalGuide();
230     
231     /**
232      *
233      * @param value the Vertical EditorGuide of the DrawComponent to set
234      * @see org.nightlabs.editor2d.EditorGuide
235      */

236     void setVerticalGuide(EditorGuide value);
237
238     /**
239      *
240      * @return the X-Coordinate of the RotationCenter in absolute Coordinates
241      */

242     int getRotationX();
243     
244     /**
245      *
246      * @param value the X-Coordinate of the RotationCenter to set in absolute Coordinates
247      */

248     void setRotationX(int value);
249
250     /**
251      *
252      * @return the Y-Coordinate of the RotationCenter in absolute Coordinates
253      */

254     int getRotationY();
255     
256     /**
257      *
258      * @param value the Y-Coordinate of the RotationCenter to set in absolute Coordinates
259      */

260     void setRotationY(int value);
261
262     /**
263      *
264      * @return the Bounds of the DrawComponent in absolute Coordinates
265      */

266     Rectangle JavaDoc getBounds();
267     
268     /**
269      * This Method should also update the values for (X, Y, Width, Height)
270      * @param bounds the Bounds to set for the DrawComponent in absolute Coordinates
271      */

272     void setBounds(Rectangle JavaDoc bounds);
273
274     /**
275      *
276      * @return the current AffineTransform
277      */

278     AffineTransform JavaDoc getAffineTransform();
279     
280     /**
281      * this Method does not transform the DrawComponent, it only sets the current AffineTransform
282      * @param at the AffineTransform to set,
283      */

284     void setAffineTransform(AffineTransform JavaDoc at);
285
286     /**
287      * the Temporary Rotation-Center is used when a Group of DrawComponents is rotated, so
288      * that for this time not the normal Rotation-Center (getRotationX, getRotationY) is used but
289      * the temporary Rotation-Center (getTmpRotationX, getTmpRotationY)
290      * This value should not be serialzied.
291      *
292      * @param newTmpRotationX the X-Coordinate of the temporary Rotation-Center
293      * in absolute Coordinates
294      */

295     void setTmpRotationX(int newTmpRotationX);
296     
297     /**
298      *
299      * @return the temporary X-Coordinate of the Rotation-Center when rotating a group of DrawComponents
300      * in absolute Coordinates
301      */

302     int getTmpRotationX();
303
304     /**
305      * the Temporary Rotation-Center is used when a Group of DrawComponents is rotated, so
306      * that for this time not the normal Rotation-Center (getRotationX, getRotationY) is used but
307      * the temporary Rotation-Center (getTmpRotationX, getTmpRotationY)
308      * This value should not be serialzied.
309      *
310      * @param newTmpRotationY the Y-Coordinate of the temporary Rotation-Center
311      * in absolute Coordinates
312      */

313     void setTmpRotationY(int newTmpRotationY);
314     
315     /**
316      *
317      * @return the temporary Y-Coordinate of the Rotation-Center when rotating a group of DrawComponents
318      * in absolute Coordinates
319      */

320     int getTmpRotationY();
321
322     /**
323      * Based on the renderMode the DrawComponent is drawn
324      * @param mode the renderMode to set
325      * @see org.nightlabs.editor2d.render.RenderModeManager
326      */

327     void setRenderMode(int mode);
328     
329     /**
330      *
331      * @return the renderMode of the DrawComponent
332      * @see org.nightlabs.editor2d.render.RenderModeManager
333      */

334     int getRenderMode();
335
336     /**
337      * the Renderer determines how the DrawComponent is drawn
338      *
339      * @return the Renderer of the DrawComponent
340      * @see org.nightlabs.editor2d.render.Renderer
341      * @see org.nightlabs.editor2d.render.RenderModeManager
342      */

343     Renderer getRenderer();
344
345     /**
346      * sets the RenderModeManager for the DrawComponent, which
347      * contains all Renderer for the renderModes and the corresponding Class
348      *
349      * @param man the RenderModeManager to set
350      * @see org.nightlabs.editor2d.render.RenderModeManager
351      */

352     void setRenderModeManager(RenderModeManager man);
353     
354     /**
355      *
356      * @return the RenderModeManager for the DrawComponent
357      * @see org.nightlabs.editor2d.render.RenderModeManager
358      */

359     RenderModeManager getRenderModeManager();
360     
361     /**
362      *
363      * @return a String which describes the type of the DrawComponent
364      * e.g. LineDrawComponent
365      */

366     String JavaDoc getTypeName();
367
368     /**
369      *
370      * @return the Model-Root-Object for the DrawComponent
371      * @see org.nightlabs.editor2d.MultiLayerDrawComponent
372      */

373     MultiLayerDrawComponent getRoot();
374     
375     /**
376      * sets the Location of the DrawComponent in absolute Coordinates
377      * @param x the X-Coordinate in absolute Coordinates
378      * @param y the Y-Coordinate in absolute Coordinates
379      */

380     void setLocation(int x, int y);
381     
382     /**
383      *
384      * @return the DrawComponentContainer in which the DrawComponent is contained
385      * @see org.nightlabs.editor2d.DrawComponentContainer
386      */

387     DrawComponentContainer getParent();
388     
389     /**
390      *
391      * @param value sets the DrawComponentContainer in which the DrawComponent is contained
392      * @see org.nightlabs.editor2d.DrawComponentContainer
393      */

394     void setParent(DrawComponentContainer value);
395
396     /**
397      * Method which is only used for deserialization, as it only sets the member rotation, without
398      * transforming the model or firing a propertyChange
399      *
400      * WARNING!
401      * This Method should never be called otherwise, because it could lead to a
402      * inconsistent Model
403      *
404      * @param value the value of the member rotation
405      */

406     void setRotationMember(double value);
407     
408     /**
409      * Transformes the DrawComponent and its bounds based on the given AffineTransform
410      *
411      * all geometric transformations {@link DrawComponent#setWidth(int)}, {@link DrawComponent#setHeight(int)},
412      * {@link DrawComponent#setX(int)}, {@link DrawComponent#setY(int)}, {@link DrawComponent#setLocation(int, int)},
413      * {@link DrawComponent#setRotation(double)}
414      * should be based on this Method or respectivly call this Method by transform the
415      * AffineTransform with the given values and apply it
416      *
417      * @param at the AffineTransform which determines the transformation
418      * @see java.awt.geom.AffineTransform
419      */

420     void transform(AffineTransform JavaDoc at);
421     
422     /**
423      * This Method can be implemented to avoid the firing of a propertyChange
424      * if the transformation comes from the parent.
425      *
426      * IMPORTANT:
427      * Inheritated classes should override this Method and transform the DrawComponent but also call
428      * super.transform(newAT, fromParent) first
429      *
430      * This is necessary because all Geometric Transformation
431      * (setX(), setY(), setWidth(), setHeight(), setLocation(), setSize(), setRotation())
432      * depend on this Method
433      *
434      * @param newAT the AffineTransform to transform
435      * @param fromParent determines if the Transformation comes from the parent DrawComponentContainer
436      * or if the DrawComponent is transformed directly, means it notificies the parent
437      * (getParent.notifyChildTransform(this)) about the transformation or not
438      */

439     void transform(AffineTransform JavaDoc at, boolean fromParent);
440     
441     /**
442      * resets the cached bounds
443      */

444     void clearBounds();
445     
446     /**
447      * clones the DrawComponent
448      *
449      * @return a clone of the DrawComponent of the same class
450      * @see Object#clone()
451      */

452     public Object JavaDoc clone();
453     
454     public Object JavaDoc clone(DrawComponentContainer parent);
455 // /**
456
// * Clones the DrawComponent
457
// * @return a clone of the DrawComponent
458
// */
459
// DrawComponent clone();
460

461 // void setRoot(MultiLayerDrawComponent mldc);
462
} // DrawComponent
463
Popular Tags