KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > GridBagConstraints


1 /*
2  * @(#)GridBagConstraints.java 1.34 04/03/15
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package java.awt;
8
9 /**
10  * The <code>GridBagConstraints</code> class specifies constraints
11  * for components that are laid out using the
12  * <code>GridBagLayout</code> class.
13  *
14  * @version 1.34, 03/15/04
15  * @author Doug Stein
16  * @see java.awt.GridBagLayout
17  * @since JDK1.0
18  */

19 public class GridBagConstraints implements Cloneable JavaDoc, java.io.Serializable JavaDoc {
20
21    /**
22      * Specifies that this component is the next-to-last component in its
23      * column or row (<code>gridwidth</code>, <code>gridheight</code>),
24      * or that this component be placed next to the previously added
25      * component (<code>gridx</code>, <code>gridy</code>).
26      * @see java.awt.GridBagConstraints#gridwidth
27      * @see java.awt.GridBagConstraints#gridheight
28      * @see java.awt.GridBagConstraints#gridx
29      * @see java.awt.GridBagConstraints#gridy
30      */

31   public static final int RELATIVE = -1;
32
33    /**
34      * Specifies that this component is the
35      * last component in its column or row.
36      */

37   public static final int REMAINDER = 0;
38
39    /**
40      * Do not resize the component.
41      */

42   public static final int NONE = 0;
43
44    /**
45      * Resize the component both horizontally and vertically.
46      */

47   public static final int BOTH = 1;
48
49    /**
50      * Resize the component horizontally but not vertically.
51      */

52   public static final int HORIZONTAL = 2;
53
54    /**
55      * Resize the component vertically but not horizontally.
56      */

57   public static final int VERTICAL = 3;
58
59    /**
60     * Put the component in the center of its display area.
61     */

62   public static final int CENTER = 10;
63
64    /**
65      * Put the component at the top of its display area,
66      * centered horizontally.
67      */

68   public static final int NORTH = 11;
69
70     /**
71      * Put the component at the top-right corner of its display area.
72      */

73   public static final int NORTHEAST = 12;
74
75     /**
76      * Put the component on the right side of its display area,
77      * centered vertically.
78      */

79   public static final int EAST = 13;
80
81     /**
82      * Put the component at the bottom-right corner of its display area.
83      */

84   public static final int SOUTHEAST = 14;
85
86     /**
87      * Put the component at the bottom of its display area, centered
88      * horizontally.
89      */

90   public static final int SOUTH = 15;
91
92    /**
93      * Put the component at the bottom-left corner of its display area.
94      */

95   public static final int SOUTHWEST = 16;
96
97     /**
98      * Put the component on the left side of its display area,
99      * centered vertically.
100      */

101   public static final int WEST = 17;
102
103    /**
104      * Put the component at the top-left corner of its display area.
105      */

106   public static final int NORTHWEST = 18;
107
108     /**
109      * Place the component centered along the edge of its display area
110      * associated with the start of a page for the current
111      * <code>ComponentOrienation</code>. Equal to NORTH for horizontal
112      * orientations.
113      */

114   public static final int PAGE_START = 19;
115
116     /**
117      * Place the component centered along the edge of its display area
118      * associated with the end of a page for the current
119      * <code>ComponentOrienation</code>. Equal to SOUTH for horizontal
120      * orientations.
121      */

122   public static final int PAGE_END = 20;
123
124     /**
125      * Place the component centered along the edge of its display area where
126      * lines of text would normally begin for the current
127      * <code>ComponentOrienation</code>. Equal to WEST for horizontal,
128      * left-to-right orientations and EAST for horizontal, right-to-left
129      * orientations.
130      */

131   public static final int LINE_START = 21;
132
133     /**
134      * Place the component centered along the edge of its display area where
135      * lines of text would normally end for the current
136      * <code>ComponentOrienation</code>. Equal to EAST for horizontal,
137      * left-to-right orientations and WEST for horizontal, right-to-left
138      * orientations.
139      */

140   public static final int LINE_END = 22;
141
142     /**
143      * Place the component in the corner of its display area where
144      * the first line of text on a page would normally begin for the current
145      * <code>ComponentOrienation</code>. Equal to NORTHWEST for horizontal,
146      * left-to-right orientations and NORTHEAST for horizontal, right-to-left
147      * orientations.
148      */

149   public static final int FIRST_LINE_START = 23;
150
151     /**
152      * Place the component in the corner of its display area where
153      * the first line of text on a page would normally end for the current
154      * <code>ComponentOrienation</code>. Equal to NORTHEAST for horizontal,
155      * left-to-right orientations and NORTHWEST for horizontal, right-to-left
156      * orientations.
157      */

158   public static final int FIRST_LINE_END = 24;
159
160     /**
161      * Place the component in the corner of its display area where
162      * the last line of text on a page would normally start for the current
163      * <code>ComponentOrienation</code>. Equal to SOUTHWEST for horizontal,
164      * left-to-right orientations and SOUTHEAST for horizontal, right-to-left
165      * orientations.
166      */

167   public static final int LAST_LINE_START = 25;
168
169     /**
170      * Place the component in the corner of its display area where
171      * the last line of text on a page would normally end for the current
172      * <code>ComponentOrienation</code>. Equal to SOUTHEAST for horizontal,
173      * left-to-right orientations and SOUTHWEST for horizontal, right-to-left
174      * orientations.
175      */

176   public static final int LAST_LINE_END = 26;
177
178    /**
179      * Specifies the cell containing the leading edge of the component's
180      * display area, where the first cell in a row has <code>gridx=0</code>.
181      * The leading edge of a component's display area is its left edge for
182      * a horizontal, left-to-right container and its right edge for a
183      * horizontal, right-to-left container.
184      * The value
185      * <code>RELATIVE</code> specifies that the component be placed
186      * immediately following the component that was added to the container
187      * just before this component was added.
188      * <p>
189      * The default value is <code>RELATIVE</code>.
190      * <code>gridx</code> should be a non-negative value.
191      * @serial
192      * @see #clone()
193      * @see java.awt.GridBagConstraints#gridy
194      * @see java.awt.ComponentOrientation
195      */

196   public int gridx;
197
198    /**
199      * Specifies the cell at the top of the component's display area,
200      * where the topmost cell has <code>gridy=0</code>. The value
201      * <code>RELATIVE</code> specifies that the component be placed just
202      * below the component that was added to the container just before
203      * this component was added.
204      * <p>
205      * The default value is <code>RELATIVE</code>.
206      * <code>gridy</code> should be a non-negative value.
207      * @serial
208      * @see #clone()
209      * @see java.awt.GridBagConstraints#gridx
210      */

211   public int gridy;
212
213    /**
214      * Specifies the number of cells in a row for the component's
215      * display area.
216      * <p>
217      * Use <code>REMAINDER</code> to specify that the component's
218      * display area will be from <code>gridx</code> to the last
219      * cell in the row.
220      * Use <code>RELATIVE</code> to specify that the component's
221      * display area will be from <code>gridx</code> to the next
222      * to the last one in its row.
223      * <p>
224      * <code>gridwidth</code> should be non-negative and the default
225      * value is 1.
226      * @serial
227      * @see #clone()
228      * @see java.awt.GridBagConstraints#gridheight
229      */

230   public int gridwidth;
231
232    /**
233      * Specifies the number of cells in a column for the component's
234      * display area.
235      * <p>
236      * Use <code>REMAINDER</code> to specify that the component's
237      * display area will be from <code>gridy</code> to the last
238      * cell in the column.
239      * Use <code>RELATIVE</code> to specify that the component's
240      * display area will be from <code>gridy</code> to the next
241      * to the last one in its column.
242      * <p>
243      * <code>gridheight</code> should be a non-negative value and the
244      * default value is 1.
245      * @serial
246      * @see #clone()
247      * @see java.awt.GridBagConstraints#gridwidth
248      */

249   public int gridheight;
250
251    /**
252      * Specifies how to distribute extra horizontal space.
253      * <p>
254      * The grid bag layout manager calculates the weight of a column to
255      * be the maximum <code>weightx</code> of all the components in a
256      * column. If the resulting layout is smaller horizontally than the area
257      * it needs to fill, the extra space is distributed to each column in
258      * proportion to its weight. A column that has a weight of zero receives
259      * no extra space.
260      * <p>
261      * If all the weights are zero, all the extra space appears between
262      * the grids of the cell and the left and right edges.
263      * <p>
264      * The default value of this field is <code>0</code>.
265      * <code>weightx</code> should be a non-negative value.
266      * @serial
267      * @see #clone()
268      * @see java.awt.GridBagConstraints#weighty
269      */

270   public double weightx;
271
272    /**
273      * Specifies how to distribute extra vertical space.
274      * <p>
275      * The grid bag layout manager calculates the weight of a row to be
276      * the maximum <code>weighty</code> of all the components in a row.
277      * If the resulting layout is smaller vertically than the area it
278      * needs to fill, the extra space is distributed to each row in
279      * proportion to its weight. A row that has a weight of zero receives no
280      * extra space.
281      * <p>
282      * If all the weights are zero, all the extra space appears between
283      * the grids of the cell and the top and bottom edges.
284      * <p>
285      * The default value of this field is <code>0</code>.
286      * <code>weighty</code> should be a non-negative value.
287      * @serial
288      * @see #clone()
289      * @see java.awt.GridBagConstraints#weightx
290      */

291   public double weighty;
292
293    /**
294     * This field is used when the component is smaller than its display
295      * area. It determines where, within the display area, to place the
296      * component.
297      * <p>
298      * There are two kinds of possible values: relative and
299      * absolute. Relative values are interpreted relative to the container's
300      * component orientation property while absolute values are not. The absolute
301      * values are:
302      * <code>CENTER</code>, <code>NORTH</code>, <code>NORTHEAST</code>,
303      * <code>EAST</code>, <code>SOUTHEAST</code>, <code>SOUTH</code>,
304      * <code>SOUTHWEST</code>, <code>WEST</code>, and <code>NORTHWEST</code>.
305      * The relative values are: <code>PAGE_START</code>, <code>PAGE_END</code>,
306      * <code>LINE_START</code>, <code>LINE_END</code>,
307      * <code>FIRST_LINE_START</code>, <code>FIRST_LINE_END</code>,
308      * <code>LAST_LINE_START</code> and <code>LAST_LINE_END</code>.
309      * The default value is <code>CENTER</code>.
310      * @serial
311      * @see #clone()
312      * @see java.awt.ComponentOrientation
313      */

314   public int anchor;
315
316    /**
317      * This field is used when the component's display area is larger
318      * than the component's requested size. It determines whether to
319      * resize the component, and if so, how.
320      * <p>
321      * The following values are valid for <code>fill</code>:
322      * <p>
323      * <ul>
324      * <li>
325      * <code>NONE</code>: Do not resize the component.
326      * <li>
327      * <code>HORIZONTAL</code>: Make the component wide enough to fill
328      * its display area horizontally, but do not change its height.
329      * <li>
330      * <code>VERTICAL</code>: Make the component tall enough to fill its
331      * display area vertically, but do not change its width.
332      * <li>
333      * <code>BOTH</code>: Make the component fill its display area
334      * entirely.
335      * </ul>
336      * <p>
337      * The default value is <code>NONE</code>.
338      * @serial
339      * @see #clone()
340      */

341   public int fill;
342
343    /**
344      * This field specifies the external padding of the component, the
345      * minimum amount of space between the component and the edges of its
346      * display area.
347      * <p>
348      * The default value is <code>new Insets(0, 0, 0, 0)</code>.
349      * @serial
350      * @see #clone()
351      */

352   public Insets JavaDoc insets;
353
354    /**
355      * This field specifies the internal padding of the component, how much
356      * space to add to the minimum width of the component. The width of
357      * the component is at least its minimum width plus
358      * <code>ipadx</code> pixels.
359      * <p>
360      * The default value is <code>0</code>.
361      * @serial
362      * @see #clone()
363      * @see java.awt.GridBagConstraints#ipady
364      */

365   public int ipadx;
366
367    /**
368      * This field specifies the internal padding, that is, how much
369      * space to add to the minimum height of the component. The height of
370      * the component is at least its minimum height plus
371      * <code>ipady</code> pixels.
372      * <p>
373      * The default value is 0.
374      * @serial
375      * @see #clone()
376      * @see java.awt.GridBagConstraints#ipadx
377      */

378   public int ipady;
379
380    /**
381      * Temporary place holder for the x coordinate.
382      * @serial
383      */

384   int tempX;
385    /**
386      * Temporary place holder for the y coordinate.
387      * @serial
388      */

389   int tempY;
390    /**
391      * Temporary place holder for the Width of the component.
392      * @serial
393      */

394   int tempWidth;
395    /**
396      * Temporary place holder for the Height of the component.
397      * @serial
398      */

399   int tempHeight;
400    /**
401      * The minimum width of the component. It is used to calculate
402      * <code>ipady</code>, where the default will be 0.
403      * @serial
404      * @see #ipady
405      */

406   int minWidth;
407    /**
408      * The minimum height of the component. It is used to calculate
409      * <code>ipadx</code>, where the default will be 0.
410      * @serial
411      * @see #ipadx
412      */

413   int minHeight;
414
415   /*
416    * JDK 1.1 serialVersionUID
417    */

418   private static final long serialVersionUID = -1000070633030801713L;
419
420    /**
421      * Creates a <code>GridBagConstraint</code> object with
422      * all of its fields set to their default value.
423      */

424   public GridBagConstraints () {
425     gridx = RELATIVE;
426     gridy = RELATIVE;
427     gridwidth = 1;
428     gridheight = 1;
429
430     weightx = 0;
431     weighty = 0;
432     anchor = CENTER;
433     fill = NONE;
434
435     insets = new Insets JavaDoc(0, 0, 0, 0);
436     ipadx = 0;
437     ipady = 0;
438   }
439
440   /**
441     * Creates a <code>GridBagConstraints</code> object with
442     * all of its fields set to the passed-in arguments.
443     *
444     * Note: Because the use of this constructor hinders readability
445     * of source code, this constructor should only be used by
446     * automatic source code generation tools.
447     *
448     * @param gridx The initial gridx value.
449     * @param gridy The initial gridy value.
450     * @param gridwidth The initial gridwidth value.
451     * @param gridheight The initial gridheight value.
452     * @param weightx The initial weightx value.
453     * @param weighty The initial weighty value.
454     * @param anchor The initial anchor value.
455     * @param fill The initial fill value.
456     * @param insets The initial insets value.
457     * @param ipadx The initial ipadx value.
458     * @param ipady The initial ipady value.
459     *
460     * @see java.awt.GridBagConstraints#gridx
461     * @see java.awt.GridBagConstraints#gridy
462     * @see java.awt.GridBagConstraints#gridwidth
463     * @see java.awt.GridBagConstraints#gridheight
464     * @see java.awt.GridBagConstraints#weightx
465     * @see java.awt.GridBagConstraints#weighty
466     * @see java.awt.GridBagConstraints#anchor
467     * @see java.awt.GridBagConstraints#fill
468     * @see java.awt.GridBagConstraints#insets
469     * @see java.awt.GridBagConstraints#ipadx
470     * @see java.awt.GridBagConstraints#ipady
471     *
472     * @since 1.2
473     */

474   public GridBagConstraints(int gridx, int gridy,
475                             int gridwidth, int gridheight,
476                             double weightx, double weighty,
477                             int anchor, int fill,
478                             Insets JavaDoc insets, int ipadx, int ipady) {
479     this.gridx = gridx;
480     this.gridy = gridy;
481     this.gridwidth = gridwidth;
482     this.gridheight = gridheight;
483     this.fill = fill;
484     this.ipadx = ipadx;
485     this.ipady = ipady;
486     this.insets = insets;
487     this.anchor = anchor;
488     this.weightx = weightx;
489     this.weighty = weighty;
490   }
491
492    /**
493     * Creates a copy of this grid bag constraint.
494     * @return a copy of this grid bag constraint
495     */

496   public Object JavaDoc clone () {
497       try {
498       GridBagConstraints JavaDoc c = (GridBagConstraints JavaDoc)super.clone();
499       c.insets = (Insets JavaDoc)insets.clone();
500       return c;
501       } catch (CloneNotSupportedException JavaDoc e) {
502       // this shouldn't happen, since we are Cloneable
503
throw new InternalError JavaDoc();
504       }
505   }
506 }
507
Popular Tags