View Javadoc

1   package fr.ove.openmath.jome.ctrlview.bidim;
2   
3   import java.awt.*;
4   import java.io.Serializable;
5   import fr.ove.openmath.jome.ctrlview.bidim.GraphicContext;
6   import fr.ove.openmath.jome.ctrlview.bidim.Sizable;
7   import fr.ove.openmath.jome.ctrlview.bidim.Localisable;
8   
9   /***
10  * An implementation of the <CODE>Displayable</CODE> interface.<BR>
11  * Nevertheless, it is an abstract class, because we don't know a priori
12  * how to paint it. This will be one of the tasks of the inherited classes.
13  *
14  * @author © 1999 DIRAT Laurent
15  * @version 2.0 29/06/1999
16  */
17  public abstract class DisplayableImpl implements Displayable, Serializable {
18      /***
19      * The bounds of the instance. We keep location and size information.
20      */
21      private Rectangle bounds;
22      
23      /***
24      * Distance between the top of the bounding box of the element to display
25      * and its baseline.
26      */
27      private int ascent;
28  
29      /***
30      * Distance between the bottom of the bounding box of the element to display
31      * and its baseline.
32      */
33      private int descent;
34  
35      /***
36      * An horizontal shift.
37      */
38      private int shiftX;
39  
40      /***
41      * A vertical shift.
42      */
43      private int shiftY;
44      
45      /***
46      * The graphic context of the displayable object.
47      */
48      private GraphicContext graphicContext;
49      
50      /***
51      * The default constructor.<BR>
52      * By default, all the parameters equal to 0.
53      */
54      public DisplayableImpl() {
55          this(new Rectangle(), 0, 0, 0, 0);
56      }
57      
58      /***
59      * The constructor.
60      * @param bounds the bounds of the instance.
61      * @param ascent the ascent of the instance.
62      * @param descent the descent of the instance.
63      * @param shiftX the horizontal shift of the instance.
64      * @param shiftY the vertical shift of the instance.
65      */
66      public DisplayableImpl(Rectangle bounds, int ascent, int descent, int shiftX, int shiftY) {
67          this.bounds = bounds;
68          this.ascent = ascent;
69          this.descent = descent;
70          this.shiftX = shiftX;
71          this.shiftY = shiftY;
72      }
73      
74      
75      // #################################################
76      // ### ImplÈmentation des diffÈrentes interfaces ###
77      // #################################################
78      
79      // *************************************************
80      // *** ImplÈmentation de l'interface Displayable ***
81      
82      /***
83      * Sets the ascent.
84      * @param ascent the new ascent value.
85      */
86      public void setAscent(int ascent) {
87          this.ascent = ascent;
88      }
89      
90      /***
91      * Returns the ascent.
92      * @return the ascent.
93      */
94      public int getAscent() {
95          return ascent;
96      }
97      
98      /***
99      * Sets the descent.
100     * @param descent the new descent value.
101     */
102     public void setDescent(int descent) {
103         this.descent = descent;
104     }
105     
106     /***
107     * Returns the descent.
108     * @return the descent.
109     */
110     public int getDescent() {
111         return descent;
112     }
113     
114     /***
115     * Sets the horizontal shift.
116     * @param shiftX the new horizontal shift value.
117     */
118     public void setShiftX(int shiftX) {
119         this.shiftX = shiftX;
120     }
121     
122     /***
123     * Returns the horizontal shift.
124     * @return the horizontal shift.
125     */
126     public int getShiftX() {
127         return shiftX;
128     }
129     
130     /***
131     * Sets the vertical shift.
132     * @param shiftY the new vertical shift value.
133     */
134     public void setShiftY(int shiftY) {
135         this.shiftY = shiftY;
136     }
137     
138     /***
139     * Returns the vertical shift.
140     * @return the vertical shift.
141     */
142     public int getShiftY() {
143         return shiftY;
144     }
145     
146     /***
147     * Sets all the attributes.
148     * @param ascent the new ascent value.
149     * @param descent the new descent value.
150     * @param shiftX the new horizontal shift value.
151     * @param shiftY the new vertical shift value.
152     */
153     public void setAttributes(int ascent, int descent, int shiftX, int shiftY) {
154         this.ascent = ascent;
155         this.descent = descent;
156         this.shiftX = shiftX;
157         this.shiftY = shiftY;
158     }
159     
160     /***
161     * Sets the graphic context of the instance.
162     * @param graphicContext the graphic context.
163     */
164     public void setGraphicContext(GraphicContext graphicContext) {
165         // contrairement ? la crÈation d'un display, il n'y a pas allocation mais maintient d'une rÈfÈrence
166         // sur graphicContext, qui est en fait le contexte graphique du display (dans notre cas prÈcis) qui
167         // va afficher l'objet.
168         this.graphicContext = graphicContext;
169     }
170     
171     /***
172     * Returns the graphic context of the instance.
173     */
174     public GraphicContext getGraphicContext() {
175         return graphicContext;
176     }
177     
178     // *** Fin de l'interface Displayable ***
179     // **************************************
180     
181     // *************************************************
182     // *** ImplÈmentation de l'interface Localisable ***
183     
184     /***
185     * Sets the x-location of the instance.
186     * @param x the x-location of the instance.
187     */
188     public void setX(int x) {
189         bounds.x = x;
190     }
191     
192     /***
193     * Returns the x-location of the instance.
194     */
195     public int getX() {
196         return bounds.x;
197     }
198     
199     /***
200     * Sets the y-location of the instance.
201     * @param y the y-location of the instance.
202     */
203     public void setY(int y) {
204         bounds.y = y;
205     }
206     
207     /***
208     * Returns the y-location of the instance.
209     */
210     public int getY() {
211         return bounds.y;
212     }
213     
214     /***
215     * Sets the location of the instance.
216     * @param x the x-location of the instance.
217     * @param y the y-location of the instance.
218     */
219     public void setLocation(int x, int y) {
220         bounds.setLocation(x, y);
221     }
222     
223     /***
224     * Sets the location of the instance.
225     * @param location the location of the instance.
226     */
227     public void setLocation(Point location) {
228         bounds.setLocation(location);
229     }
230     
231     /***
232     * Returns the location of the instance.
233     * @return A <CODE>Point</CODE> representing the location of the instance.
234     */
235     public Point getLocation() {
236         return bounds.getLocation();
237     }
238     
239     // *** Fin de l'interface Localisable ***
240     // **************************************
241     
242     // *********************************************
243     // *** ImplÈmentation de l'interface Sizable ***
244     
245     /***
246     * Returns the width of the instance.
247     */
248     public int getWidth() {
249         return bounds.width;
250     }
251     
252     /***
253     * Sets the width of the instance.
254     * @param width the width of the instance
255     */
256     public void setWidth(int width) {
257         bounds.width = width;
258     }
259     
260     /***
261     * Returns the height of the instance.
262     */
263     public int getHeight() {
264         return bounds.height;
265     }
266     
267     /***
268     * Sets the height of the instance.
269     * @param height the height of the instance
270     */
271     public void setHeight(int height) {
272         bounds.height = height;
273     }
274     
275     /***
276     * Returns the size of the instance.
277     */
278     public Dimension getSize() {
279         return bounds.getSize();
280     }
281     
282     /***
283     * Sets the size of the instance.
284     * @param width the width of the instance.
285     * @param height the height of the instance
286     */
287     public void setSize(int width, int height) {
288         bounds.setSize(width, height);
289     }
290     
291     /***
292     * Sets the size of the instance.
293     * @param size the size of the instance.
294     */
295     public void setSize(Dimension size) {
296         bounds.setSize(size);
297     }
298     
299     // Le comportement par dÈfaut est que la taille de bounds est la taille prÈfÈrÈe.
300     /***
301     * Returns the preferred size of the instance.
302     */
303     public Dimension getPreferredSize() {
304         return bounds.getSize();
305     }
306     
307     // *** Fin de l'interface sizable ***
308     // **********************************
309 }