View Javadoc

1   /*
2    * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  /* $Id: LayoutInfo.java,v 686a662dbcbe 2009/01/28 09:11:26 maxberger $ */
18  
19  package net.sourceforge.jeuclid.layout;
20  
21  import java.util.List;
22  
23  /**
24   * Represented Information about a layouted object.
25   * <p>
26   * 
27   * The completeness of this information depends on the objects
28   * {@link LayoutStage}.
29   * <p>
30   * Each object is described with:
31   * <ul>
32   * <li>Origin: {@link #getPosX(LayoutStage)}, {@link #getPosY(LayoutStage)})
33   * <li>Horizontal Size: {@link #getWidth(LayoutStage)})
34   * <li>Vertical Size: {@link #getAscentHeight(LayoutStage)},
35   * {@link #getDescentHeight(LayoutStage)}
36   * </ul>
37   * <p>
38   * Coordinates are given relative to the baseline. If the object has no
39   * descent, this means the origin of the object is the lower left corner.
40   * <p>
41   * The actual Graphical representation can be retrieved with
42   * {@link #getGraphicObjects()}.
43   * <p>
44   * The stretch information ( {@link #getStretchAscent()},
45   * {@link #getStretchDescent()}, {@link #getStretchWidth()}) is set during the
46   * parents layout and defines the size to which stretchable operators are
47   * scaled to.
48   * 
49   * @version $Revision: 686a662dbcbe $
50   */
51  public interface LayoutInfo {
52  
53      /**
54       * The {@link LayoutStage} this element represents. The information will
55       * not be complete until the final LayoutStage ({@link LayoutStage#STAGE2}
56       * ) has been reached.
57       * 
58       * @return current layout stage.
59       */
60      LayoutStage getLayoutStage();
61  
62      /**
63       * @param newStage
64       *            new Layout Stage.
65       */
66      void setLayoutStage(LayoutStage newStage);
67  
68      /**
69       * Returns the current height of the upper part of this component from the
70       * baseline.
71       * 
72       * @return Height of the upper part
73       * @param stage
74       *            {@link LayoutStage} to get this information for (either
75       *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
76       */
77      float getAscentHeight(LayoutStage stage);
78  
79      /**
80       * Returns the current height of the lower part of this component from the
81       * baseline.
82       * 
83       * @return Height of the lower part.
84       * @param stage
85       *            {@link LayoutStage} to get this information for (either
86       *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
87       */
88      float getDescentHeight(LayoutStage stage);
89  
90      /**
91       * Returns the current width of this element.
92       * 
93       * @return Width of this element.
94       * @param stage
95       *            {@link LayoutStage} to get this information for (either
96       *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
97       */
98      float getWidth(LayoutStage stage);
99  
100     /**
101      * Retrieve the X-position of the horizontal center of the content. In
102      * most cases, this will be width / 2. This does not, however, take extra
103      * borders into account. An element may have different border width on
104      * left and right, in which case the center will be moved.
105      * 
106      * @return X-position of the center of the content
107      * @param stage
108      *            {@link LayoutStage} to get this information for (either
109      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
110      */
111     float getHorizontalCenterOffset(LayoutStage stage);
112 
113     /**
114      * @param newOffset
115      *            new horizontal offset.
116      * @param stage
117      *            {@link LayoutStage} to get this information for (either
118      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
119      */
120     void setHorizontalCenterOffset(float newOffset, LayoutStage stage);
121 
122     /**
123      * Retrieve the X position of this element relative to its parent.
124      * 
125      * @return X position
126      * @param stage
127      *            {@link LayoutStage} to get this information for (either
128      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
129      */
130     float getPosX(LayoutStage stage);
131 
132     /**
133      * Retrieve the Y position of this element relative to its parent.
134      * 
135      * @return Y position
136      * @param stage
137      *            {@link LayoutStage} to get this information for (either
138      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
139      */
140     float getPosY(LayoutStage stage);
141 
142     /**
143      * Move this element to the given position relative to its parent.
144      * 
145      * @param x
146      *            new X position
147      * @param y
148      *            new Y position
149      * @param stage
150      *            {@link LayoutStage} to get this information for (either
151      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
152      */
153     void moveTo(float x, float y, LayoutStage stage);
154 
155     /**
156      * Shift vertically by given offset.
157      * 
158      * @param offsetY
159      *            offset to shift.
160      * @param stage
161      *            Stage to manipulate.
162      */
163     void shiftVertically(float offsetY, LayoutStage stage);
164 
165     /**
166      * @param ascentHeight
167      *            new ascentHeight.
168      * @param stage
169      *            {@link LayoutStage} to get this information for (either
170      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
171      */
172     void setAscentHeight(float ascentHeight, LayoutStage stage);
173 
174     /**
175      * @param descentHeight
176      *            new descentHeight.
177      * @param stage
178      *            {@link LayoutStage} to get this information for (either
179      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
180      */
181     void setDescentHeight(float descentHeight, LayoutStage stage);
182 
183     /**
184      * @param width
185      *            new width.
186      * @param stage
187      *            {@link LayoutStage} to get this information for (either
188      *            {@link LayoutStage#STAGE1} or {@link LayoutStage#STAGE2})
189      */
190     void setWidth(float width, LayoutStage stage);
191 
192     /**
193      * Set the stretch width for children, or < 0 if children should be
194      * horizontally unstretched.
195      * 
196      * @param stretchWidth
197      *            new stretch width
198      */
199     void setStretchWidth(float stretchWidth);
200 
201     /**
202      * Retrieve the stretch width if set, or STAGE1.width if unset.
203      * 
204      * @return stretch width.
205      */
206     float getStretchWidth();
207 
208     /**
209      * Set the stretch descent for children. Defaults to STAGE1.descent
210      * 
211      * @param stretchDescent
212      *            new stretch descent
213      */
214     void setStretchDescent(float stretchDescent);
215 
216     /**
217      * Retrieve the stretch descent if set, or STAGE1.descent if unset.
218      * 
219      * @return stretch descent.
220      */
221     float getStretchDescent();
222 
223     /**
224      * Set the stretch ascent for children. Defaults to STAGE1.ascent
225      * 
226      * @param stretchAscent
227      *            new stretch ascent
228      */
229     void setStretchAscent(float stretchAscent);
230 
231     /**
232      * Retrieve the stretch ascent if set, or STAGE1.ascent if unset.
233      * 
234      * @return stretch ascent.
235      */
236     float getStretchAscent();
237 
238     /**
239      * @param graphicsObject
240      *            the GraphicsObject to set.
241      */
242     void setGraphicsObject(GraphicsObject graphicsObject);
243 
244     /**
245      * @return Graphic objects associated with this node.
246      */
247     List<GraphicsObject> getGraphicObjects();
248 }