1 /*
2  * @(#)Figure.java 5.1
3  *
4  */
5 
6 package CH.ifa.draw.framework;
7 
8 import CH.ifa.draw.util.*;
9 import java.awt.*;
10 import java.util.*;
11 import java.io.Serializable;
12 
13 /**
14  * The interface of a graphical figure. A figure knows
15  * its display box and can draw itself. A figure can be
16  * composed of several figures. To interact and manipulate
17  * with a figure it can provide Handles and Connectors.<p>
18  * A figure has a set of handles to manipulate its shape or attributes.
19  * A figure has one or more connectors that define how
20  * to locate a connection point.<p>
21  * Figures can have an open ended set of attributes.
22  * An attribute is identified by a string.<p>
23  * Default implementations for the Figure interface are provided
24  * by AbstractFigure.
25  *
26  * @see Handle
27  * @see Connector
28  * @see AbstractFigure
29  */
30 
31 public interface Figure
32                 extends Storable, Cloneable, Serializable {
33 
34     /**
35      * Moves the Figure to a new location.
36      * @param x the x delta
37      * @param y the y delta
38      */
moveBy(int dx, int dy)39     public void moveBy(int dx, int dy);
40 
41     /**
42      * Changes the display box of a figure. This method is
43      * always implemented in figure subclasses.
44      * It only changes
45      * the displaybox and does not announce any changes. It
46      * is usually not called by the client. Clients typically call
47      * displayBox to change the display box.
48      * @param origin the new origin
49      * @param corner the new corner
50      * @see #displayBox
51      */
basicDisplayBox(Point origin, Point corner)52     public void basicDisplayBox(Point origin, Point corner);
53 
54     /**
55      * Changes the display box of a figure. Clients usually
56      * invoke this method. It changes the display box
57      * and announces the corresponding changes.
58      * @param origin the new origin
59      * @param corner the new corner
60      * @see #displayBox
61      */
displayBox(Point origin, Point corner)62     public void displayBox(Point origin, Point corner);
63 
64     /**
65      * Gets the display box of a figure
66      * @see #basicDisplayBox
67      */
displayBox()68     public Rectangle displayBox();
69 
70     /**
71      * Draws the figure.
72      * @param g the Graphics to draw into
73      */
draw(Graphics g, boolean showGuides)74     public void draw(Graphics g, boolean showGuides);
75 
76     /**
77      * Returns the handles used to manipulate
78      * the figure. Handles is a Factory Method for
79      * creating handle objects.
80      *
81      * @return a Vector of handles
82      * @see Handle
83      */
handles()84     public Vector handles();
85 
86     /**
87      * Gets the size of the figure
88      */
size()89     public Dimension size();
90 
91     /**
92      * Gets the figure's center
93      */
center()94     public Point center();
95 
96     /**
97      * Checks if the Figure should be considered as empty.
98      */
isEmpty()99     public boolean isEmpty();
100 
101     /**
102      * Returns an Enumeration of the figures contained in this figure
103      */
figures()104     public FigureEnumeration figures();
105 
106     /**
107      * Returns the figure that contains the given point.
108      */
findFigureInside(int x, int y)109     public Figure findFigureInside(int x, int y);
110 
111     /**
112      * Checks if a point is inside the figure.
113      */
containsPoint(int x, int y)114     public boolean containsPoint(int x, int y);
115 
116     /**
117      * Returns a Clone of this figure
118      */
clone()119     public Object clone();
120 
121     /**
122      * Changes the display box of a figure. This is a
123      * convenience method. Implementors should only
124      * have to override basicDisplayBox
125      * @see #displayBox
126      */
displayBox(Rectangle r)127     public void displayBox(Rectangle r);
128 
129     /**
130      * Checks whether the given figure is contained in this figure.
131      */
includes(Figure figure)132     public boolean includes(Figure figure);
133 
134     /**
135      * Decomposes a figure into its parts. A figure is considered
136      * as a part of itself.
137      */
decompose()138     public FigureEnumeration decompose();
139 
140     /**
141      * Sets the Figure's container and registers the container
142      * as a figure change listener. A figure's container can be
143      * any kind of FigureChangeListener. A figure is not restricted
144      * to have a single container.
145      */
addToContainer(FigureChangeListener c)146     public void addToContainer(FigureChangeListener c);
147 
148     /**
149      * Removes a figure from the given container and unregisters
150      * it as a change listener.
151      */
removeFromContainer(FigureChangeListener c)152     public void removeFromContainer(FigureChangeListener c);
153 
154     /**
155      * Gets the Figure's listeners.
156      */
listener()157     public FigureChangeListener listener();
158 
159     /**
160      * Adds a listener for this figure.
161      */
addFigureChangeListener(FigureChangeListener l)162     public void addFigureChangeListener(FigureChangeListener l);
163 
164     /**
165      * Removes a listener for this figure.
166      */
removeFigureChangeListener(FigureChangeListener l)167     public void removeFigureChangeListener(FigureChangeListener l);
168 
169     /**
170      * Releases a figure's resources. Release is called when
171      * a figure is removed from a drawing. Informs the listeners that
172      * the figure is removed by calling figureRemoved.
173      */
release()174     public void release();
175 
176     /**
177      * Invalidates the figure. This method informs its listeners
178      * that its current display box is invalid and should be
179      * refreshed.
180      */
invalidate()181     public void invalidate();
182 
183     /**
184      * Informes that a figure is about to change such that its
185      * display box is affected.
186      * Here is an example of how it is used together with changed()
187      * <pre>
188      * public void move(int x, int y) {
189      *      willChange();
190      *      // change the figure's location
191      *      changed();
192      *  }
193      * </pre>
194      * @see #invalidate
195      * @see #changed
196      */
willChange()197     public void willChange();
198 
199     /**
200      * Informes that a figure has changed its display box.
201      * This method also triggers an update call for its
202      * registered observers.
203      * @see #invalidate
204      * @see #willChange
205      *
206      */
changed()207     public void changed();
208 
209     /**
210      * Checks if this figure can be connected
211      */
canConnect()212     public boolean canConnect();
213 
214     /**
215      * Gets a connector for this figure at the given location.
216      * A figure can have different connectors at different locations.
217      */
connectorAt(int x, int y)218     public Connector connectorAt(int x, int y);
219 
220     /**
221      * Sets whether the connectors should be visible.
222      * Connectors can be optionally visible. Implement
223      * this method and react on isVisible to turn the
224      * connectors on or off.
225      */
connectorVisibility(boolean isVisible)226     public void connectorVisibility(boolean isVisible);
227 
228     /**
229      * Returns the connection inset. This is only a hint that
230      * connectors can use to determine the connection location.
231      * The inset defines the area where the display box of a
232      * figure should not be connected.
233      *
234      */
connectionInsets()235     public Insets connectionInsets();
236 
237     /**
238      * Returns the locator used to located connected text.
239      */
connectedTextLocator(Figure text)240     public Locator connectedTextLocator(Figure text);
241 
242     /**
243      * Returns the named attribute or null if a
244      * a figure doesn't have an attribute.
245      * All figures support the attribute names
246      * FillColor and FrameColor
247      */
getAttribute(String name)248     public Object getAttribute(String name);
249 
250     /**
251      * Sets the named attribute to the new value
252      */
setAttribute(String name, Object value)253     public void setAttribute(String name, Object value);
254 }
255