001: /*
002: * @(#)GridBagConstraints.java 1.19 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027: package java.awt;
028:
029: /**
030: * The <code>GridBagConstraints</code> class specifies constraints
031: * for components that are laid out using the
032: * <code>GridBagLayout</code> class.
033: *
034: * @version 1.15, 08/19/02
035: * @author Doug Stein
036: * @see java.awt.GridBagLayout
037: * @since JDK1.0
038: */
039: public class GridBagConstraints implements Cloneable,
040: java.io.Serializable {
041: /**
042: * Specify that this component is the next-to-last component in its
043: * column or row (<code>gridwidth</code>, <code>gridheight</code>),
044: * or that this component be placed next to the previously added
045: * component (<code>gridx</code>, <code>gridy</code>).
046: * @see java.awt.GridBagConstraints#gridwidth
047: * @see java.awt.GridBagConstraints#gridheight
048: * @see java.awt.GridBagConstraints#gridx
049: * @see java.awt.GridBagConstraints#gridy
050: * @since JDK1.0
051: */
052: public static final int RELATIVE = -1;
053: /**
054: * Specify that this component is the
055: * last component in its column or row.
056: * @since JDK1.0
057: */
058: public static final int REMAINDER = 0;
059: /**
060: * Do not resize the component.
061: * @since JDK1.0
062: */
063: public static final int NONE = 0;
064: /**
065: * Resize the component both horizontally and vertically.
066: * @since JDK1.0
067: */
068: public static final int BOTH = 1;
069: /**
070: * Resize the component horizontally but not vertically.
071: * @since JDK1.0
072: */
073: public static final int HORIZONTAL = 2;
074: /**
075: * Resize the component vertically but not horizontally.
076: * @since JDK1.0
077: */
078: public static final int VERTICAL = 3;
079: /**
080: * Put the component in the center of its display area.
081: * @since JDK1.0
082: */
083: public static final int CENTER = 10;
084: /**
085: * Put the component at the top of its display area,
086: * centered horizontally.
087: * @since JDK1.0
088: */
089: public static final int NORTH = 11;
090: /**
091: * Put the component at the top-right corner of its display area.
092: * @since JDK1.0
093: */
094: public static final int NORTHEAST = 12;
095: /**
096: * Put the component on the right side of its display area,
097: * centered vertically.
098: * @since JDK1.0
099: */
100: public static final int EAST = 13;
101: /**
102: * Put the component at the bottom-right corner of its display area.
103: * @since JDK1.0
104: */
105: public static final int SOUTHEAST = 14;
106: /**
107: * Put the component at the bottom of its display area, centered
108: * horizontally.
109: * @since JDK1.0
110: */
111: public static final int SOUTH = 15;
112: /**
113: * Put the component at the bottom-left corner of its display area.
114: * @since JDK1.0
115: */
116: public static final int SOUTHWEST = 16;
117: /**
118: * Put the component on the left side of its display area,
119: * centered vertically.
120: * @since JDK1.0
121: */
122: public static final int WEST = 17;
123: /**
124: * Put the component at the top-left corner of its display area.
125: * @since JDK1.0
126: */
127: public static final int NORTHWEST = 18;
128: /**
129: * Specifies the cell at the left of the component's display area,
130: * where the leftmost cell has <code>gridx = 0</code>. The value
131: * <code>RELATIVE</code> specifies that the component be placed just
132: * to the right of the component that was added to the container just
133: * before this component was added.
134: * <p>
135: * The default value is <code>RELATIVE</code>.
136: * @see java.awt.GridBagConstraints#gridy
137: * @since JDK1.0
138: */
139: public int gridx;
140: /**
141: * Specifies the cell at the top of the component's display area,
142: * where the topmost cell has <code>gridy = 0</code>. The value
143: * <code>RELATIVE</code> specifies that the component be placed just
144: * below the component that was added to the container just before
145: * this component was added.
146: * <p>
147: * The default value is <code>RELATIVE</code>.
148: * @see java.awt.GridBagConstraints#gridx
149: * @since JDK1.0
150: */
151: public int gridy;
152: /**
153: * Specifies the number of cells in a row for the component's
154: * display area.
155: * <p>
156: * Use <code>REMAINDER</code> to specify that the component be the
157: * last one in its row. Use <code>RELATIVE</code> to specify that the
158: * component be the next-to-last one in its row.
159: * <p>
160: * The default value is 1.
161: * @see java.awt.GridBagConstraints#gridheight
162: * @since JDK1.0
163: */
164: public int gridwidth;
165: /**
166: * Specifies the number of cells in a column for the component's
167: * display area.
168: * <p>
169: * Use <code>REMAINDER</code> to specify that the component be the
170: * last one in its column. Use <code>RELATIVE</code> to specify that
171: * the component be the next-to-last one in its column.
172: * <p>
173: * The default value is 1.
174: * @see java.awt.GridBagConstraints#gridwidth
175: * @since JDK1.0
176: */
177: public int gridheight;
178: /**
179: * Specifies how to distribute extra horizontal space.
180: * <p>
181: * The grid bag layout manager calculates the weight of a column to
182: * be the maximum <code>weighty</code> of all the components in a
183: * row. If the resulting layout is smaller horizontally than the area
184: * it needs to fill, the extra space is distributed to each column in
185: * proportion to its weight. A column that has a weight zero receives no
186: * extra space.
187: * <p>
188: * If all the weights are zero, all the extra space appears between
189: * the grids of the cell and the left and right edges.
190: * <p>
191: * The default value of this field is <code>0</code>.
192: * @see java.awt.GridBagConstraints#weighty
193: * @since JDK1.0
194: */
195: public double weightx;
196: /**
197: * Specifies how to distribute extra vertical space.
198: * <p>
199: * The grid bag layout manager calculates the weight of a row to be
200: * the maximum <code>weightx</code> of all the components in a row.
201: * If the resulting layout is smaller vertically than the area it
202: * needs to fill, the extra space is distributed to each row in
203: * proportion to its weight. A row that has a weight of zero receives no
204: * extra space.
205: * <p>
206: * If all the weights are zero, all the extra space appears between
207: * the grids of the cell and the top and bottom edges.
208: * <p>
209: * The default value of this field is <code>0</code>.
210: * @see java.awt.GridBagConstraints#weightx
211: * @since JDK1.0
212: */
213: public double weighty;
214: /**
215: * This field is used when the component is smaller than its display
216: * area. It determines where, within the display area, to place the
217: * component. Possible values are <code>CENTER<code>,
218: * <code>NORTH<code>, <code>NORTHEAST<code>, <code>EAST<code>,
219: * <code>SOUTHEAST<code>, <code>SOUTH<code>, <code>SOUTHWEST<code>,
220: * <code>WEST<code>, and <code>NORTHWEST<code>.
221: * The default value is <code>CENTER</code>.
222: * @since JDK1.0
223: */
224: public int anchor;
225: /**
226: * This field is used when the component's display area is larger
227: * than the component's requested size. It determines whether to
228: * resize the component, and if so, how.
229: * <p>
230: * The following values are valid for <code>fill</code>:
231: * <p>
232: * <ul>
233: * <li>
234: * <code>NONE</code>: Do not resize the component.
235: * <li>
236: * <code>HORIZONTAL</code>: Make the component wide enough to fill
237: * its display area horizontally, but do not change its height.
238: * <li>
239: * <code>VERTICAL</code>: Make the component tall enough to fill its
240: * display area vertically, but do not change its width.
241: * <li>
242: * <code>BOTH</code>: Make the component fill its display area
243: * entirely.
244: * </ul>
245: * <p>
246: * The default value is <code>NONE</code>.
247: * @since JDK1.0
248: */
249: public int fill;
250: /**
251: * This field specifies the external padding of the component, the
252: * minimum amount of space between the component and the edges of its
253: * display area.
254: * <p>
255: * The default value is <code>new Insets(0, 0, 0, 0)</code>.
256: * @since JDK1.0
257: */
258: public Insets insets;
259: /**
260: * This field specifies the internal padding of the component, how much
261: * space to add to the minimum width of the component. The width of
262: * the component is at least its minimum width plus
263: * <code>(ipadx * 2)</code> pixels.
264: * <p>
265: * The default value is <code>0</code>.
266: * @see java.awt.GridBagConstraints#ipady
267: * @since JDK1.0
268: */
269: public int ipadx;
270: /**
271: * This field specifies the internal padding, that is, how much
272: * space to add to the minimum height of the component. The height of
273: * the component is at least its minimum height plus
274: * <code>(ipady * 2)</code> pixels.
275: * <p>
276: * The default value is 0.
277: * @see java.awt.GridBagConstraints#ipadx
278: * @since JDK1.0
279: */
280: public int ipady;
281: int tempX, tempY;
282: int tempWidth, tempHeight;
283: int minWidth, minHeight;
284:
285: /**
286: * Creates a <code>GridBagConstraint</code> object with
287: * all of its fields set to their default value.
288: * @since JDK1.0
289: */
290: public GridBagConstraints() {
291: gridx = RELATIVE;
292: gridy = RELATIVE;
293: gridwidth = 1;
294: gridheight = 1;
295: weightx = 0;
296: weighty = 0;
297: anchor = CENTER;
298: fill = NONE;
299: insets = new Insets(0, 0, 0, 0);
300: ipadx = 0;
301: ipady = 0;
302: }
303:
304: /**
305: * Creates a copy of this grid bag constraint.
306: * @return a copy of this grid bag constraint
307: * @since JDK1.0
308: */
309: public Object clone() {
310: try {
311: GridBagConstraints c = (GridBagConstraints) super .clone();
312: c.insets = (Insets) insets.clone();
313: return c;
314: } catch (CloneNotSupportedException e) {
315: // this shouldn't happen, since we are Cloneable
316: throw new InternalError();
317: }
318: }
319: }
|