KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > gui > IzPanelConstraints


1 /*
2  * $Id:$
3  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
4  *
5  * http://www.izforge.com/izpack/
6  * http://developer.berlios.de/projects/izpack/
7  *
8  * Copyright 2006 Klaus Bartz
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */

22 package com.izforge.izpack.gui;
23
24 import java.awt.Component JavaDoc;
25 import java.awt.Rectangle JavaDoc;
26
27 /**
28  * Constraints class for the layout manager <code>IzPanelLayout</code>.
29  *
30  */

31 public class IzPanelConstraints implements Cloneable JavaDoc, LayoutConstants
32 {
33
34     /**
35      * Current defined gaps. Here are the defaults which can be overwritten at the first call to
36      * method getGap. The gap type will be determined by the array index and has to be synchron to
37      * the gap identifier and the indices of array GAP_NAME_LOOK_UP
38      */

39     private int xCellAlignment = IzPanelLayout.DEFAULT_X_ALIGNMENT[0];
40
41     private int yCellAlignment = IzPanelLayout.DEFAULT_Y_ALIGNMENT[0];
42
43     private int xPos = 0;
44
45     private int yPos = NEXT_ROW;
46
47     private int xWeight = 1;
48
49     private int yWeight = 1;
50
51     private int xGap = IzPanelLayout.DEFAULT_X_GAPS[-LABEL_GAP];
52
53     private int yGap = IzPanelLayout.DEFAULT_Y_GAPS[-LABEL_GAP];
54
55     private double xStretch = 0.0;
56
57     private double yStretch = 0.0;
58
59     private Rectangle JavaDoc bounds;
60
61     /** for private use by the layout manager */
62     Component JavaDoc component = null;
63
64     /** for private use by the layout manager */
65     int preferredHeight = 0;
66     
67     /**
68      * Returns the declared stretch value in x direction.
69      *
70      * @return the declared stretch value in x direction
71      */

72     public double getXStretch()
73     {
74         return xStretch;
75     }
76
77     /**
78      * Sets the given value as stretch value for x direction.
79      *
80      * @param stretch value to be set
81      */

82     public void setXStretch(double stretch)
83     {
84         this.xStretch = stretch;
85     }
86
87     /**
88      * Returns the declared stretch value in y direction.
89      *
90      * @return the declared stretch value in y direction
91      */

92     public double getYStretch()
93     {
94         return yStretch;
95     }
96
97     /**
98      * Sets the given value as stretch value for y direction.
99      *
100      * @param stretch value to be set
101      */

102     public void setYStretch(double stretch)
103     {
104         this.yStretch = stretch;
105     }
106
107     /**
108      * Returns the declared x gap value.
109      *
110      * @return the declared x gap value
111      */

112     public int getXGap()
113     {
114         return xGap;
115     }
116
117     /**
118      * Sets the given value as x gap.
119      *
120      * @param gap value to be set
121      */

122     public void setXGap(int gap)
123     {
124         xGap = gap;
125     }
126
127     /**
128      * Returns the declared y gap value.
129      *
130      * @return the declared y gap value
131      */

132     public int getYGap()
133     {
134         return yGap;
135     }
136
137     /**
138      * Sets the given value as y gap.
139      *
140      * @param gap value to be set
141      */

142     public void setYGap(int gap)
143     {
144         yGap = gap;
145     }
146
147     /**
148      * Constructor with all existent parameters.
149      *
150      * @param xCellAlignment value to be used as x alignment
151      * @param yCellAlignment value to be used as y alignment
152      * @param xPos x position to be used
153      * @param yPos y position to be used
154      * @param xWeight weight at x direction
155      * @param yWeight weight at y direction
156      * @param xGap gap for x direction
157      * @param yGap gap for y direction
158      * @param xStretch stretch value for the x direction
159      * @param yStretch stretch value for the y direction
160      */

161     public IzPanelConstraints(int xCellAlignment, int yCellAlignment, int xPos, int yPos,
162             int xWeight, int yWeight, int xGap, int yGap, double xStretch, double yStretch)
163     {
164         this.xCellAlignment = xCellAlignment;
165         this.yCellAlignment = yCellAlignment;
166         this.xPos = xPos;
167         this.yPos = yPos;
168         this.xWeight = xWeight;
169         this.yWeight = yWeight;
170         setXGap(xGap);
171         setYGap(yGap);
172         setXStretch(xStretch);
173         setYStretch(yStretch);
174     }
175
176     /**
177      * Default constructor
178      */

179     public IzPanelConstraints()
180     {
181         super();
182     }
183
184     /*
185      * (non-Javadoc)
186      *
187      * @see java.lang.Object#clone()
188      */

189     public Object JavaDoc clone()
190     {
191         try
192         {
193             IzPanelConstraints c = (IzPanelConstraints) super.clone();
194             return c;
195         }
196         catch (CloneNotSupportedException JavaDoc e)
197         {
198             // this shouldn't happen, since we are Cloneable
199
throw new InternalError JavaDoc();
200         }
201     }
202
203     /**
204      * Returns the alignment for the x direction.
205      *
206      * @return the alignment for the x direction
207      */

208     public int getXCellAlignment()
209     {
210         return xCellAlignment;
211     }
212
213     /**
214      * Sets the alignment for the x direction. Possible values are LEFT, RIGHT and CENTER.
215      *
216      * @param cellAlignment to be used
217      */

218     public void setXCellAlignment(int cellAlignment)
219     {
220         xCellAlignment = cellAlignment;
221     }
222
223     /**
224      * Returns the x position (column number).
225      *
226      * @return the x position (column number)
227      */

228     public int getXPos()
229     {
230         return xPos;
231     }
232
233     /**
234      * Sets the x position to be used.
235      *
236      * @param pos position to be used
237      */

238     public void setXPos(int pos)
239     {
240         xPos = pos;
241     }
242
243     /**
244      * Returns the weight for the x direction. The weight determines how many cells are occupied by
245      * the component.
246      *
247      * @return the weight for the x direction
248      */

249     public int getXWeight()
250     {
251         return xWeight;
252     }
253
254     /**
255      * Sets the weight value for the x direction.
256      *
257      * @param weight to be used for the x direction
258      */

259     public void setXWeight(int weight)
260     {
261         xWeight = weight;
262     }
263
264     /**
265      * Returns the alignment for the y direction.
266      *
267      * @return the alignment for the y direction
268      */

269     public int getYCellAlignment()
270     {
271         return yCellAlignment;
272     }
273
274     /**
275      * Sets the alignment for the y direction. Possible values are TOP, BOTTOM and CENTER.
276      *
277      * @param cellAlignment to be used
278      */

279     public void setYCellAlignment(int cellAlignment)
280     {
281         yCellAlignment = cellAlignment;
282     }
283
284     /**
285      * Returns the y position (row number).
286      *
287      * @return the y position (row number)
288      */

289     public int getYPos()
290     {
291         return yPos;
292     }
293
294     /**
295      * Sets the y position to be used.
296      *
297      * @param pos position to be used
298      */

299     public void setYPos(int pos)
300     {
301         yPos = pos;
302     }
303
304     /**
305      * Returns the weight for the y direction. The weight determines how many cells are occupied by
306      * the component.
307      *
308      * @return the weight for the y direction
309      */

310     public int getYWeight()
311     {
312         return yWeight;
313     }
314
315     /**
316      * Sets the weight value for the y direction.
317      *
318      * @param weight to be used for the y direction
319      */

320     public void setYWeight(int weight)
321     {
322         yWeight = weight;
323     }
324
325     /**
326      * Returns the bounds which should be used by the corresponding component. This will be used by
327      * the layout manager at a fast layouting.
328      *
329      * @return used bounds
330      */

331     public Rectangle JavaDoc getBounds()
332     {
333         if (bounds != null) return (Rectangle JavaDoc) (bounds.clone());
334         return (new Rectangle JavaDoc());
335     }
336
337     /**
338      * Sets the bounds which should be used for the component.
339      *
340      * @param bounds bounds to be used
341      */

342     public void setBounds(Rectangle JavaDoc bounds)
343     {
344         this.bounds = (Rectangle JavaDoc) bounds.clone();
345     }
346 }
347
Popular Tags