KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > forms > widgets > TableWrapData


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.forms.widgets;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.graphics.Point;
15
16 /**
17  * Layout data used in conjunction with <code>HTMLTableLayout</code>.
18  * Children in a composite that uses this layout should call <samp>setLayoutData
19  * </samp> and pass an instance of this class to control physical placement in
20  * the parent.
21  *
22  * @see TableWrapLayout
23  * @since 3.0
24  */

25 public final class TableWrapData {
26     /**
27      * The control will be left-justified.
28      */

29     public static final int LEFT = 1 << 1;
30
31     /**
32      * The control will be centered horizontally.
33      */

34     public static final int CENTER = 1 << 2;
35
36     /**
37      * The control will be right-justified.
38      */

39     public static final int RIGHT = 1 << 3;
40
41     /**
42      * The control will be aligned with the top of the cell.
43      */

44     public static final int TOP = 1 << 4;
45
46     /**
47      * The control will be centered vertically.
48      */

49     public static final int MIDDLE = 1 << 5;
50
51     /**
52      * The control will be aligned with the bottom of the cell.
53      */

54     public static final int BOTTOM = 1 << 6;
55
56     /**
57      * The control will have the same width as the column it occupies.
58      */

59     public static final int FILL = 1 << 7;
60
61     /**
62      * In addition to filling width or height, the control will take part in
63      * allocation of any excess space. Note that this constant can only be
64      * passed to the constructor (cannot be directly assigned to
65      * <code>align</code> variable).
66      */

67     public static final int FILL_GRAB = 1 << 8;
68
69     /**
70      * Number of columns to span (default is 1).
71      */

72     public int colspan = 1;
73
74     /**
75      * Number of rows to span (default is 1).
76      */

77     public int rowspan = 1;
78
79     /**
80      * Horizontal alignment (LEFT, CENTER, RIGHT or FILL; default is LEFT).
81      */

82     public int align = LEFT;
83
84     /**
85      * Vertical alignment (TOP, MIDDLE, BOTTOM or FILL; default is TOP).
86      */

87     public int valign = TOP;
88
89     /**
90      * Horizontal indent (default is 0).
91      */

92     public int indent = 0;
93
94     /**
95      * Maximum width of the control (default is SWT.DEFAULT).
96      */

97     public int maxWidth = SWT.DEFAULT;
98
99     /**
100      * Maximum height of the control (default is SWT.DEFAULT).
101      */

102     public int maxHeight = SWT.DEFAULT;
103
104     /**
105      * Height hint of the control (default is SWT.DEFAULT).
106      */

107     public int heightHint = SWT.DEFAULT;
108
109     /**
110      * If <code>true</code>, take part in excess horizontal space
111      * distribution. (default is <code>false</code>).
112      */

113     public boolean grabHorizontal;
114
115     /**
116      * If <code>true</code>, will grab any excess vertical space (default is
117      * <code>false</code>). Note that since TableWrapLayout works top-down
118      * and does not grows to fill the parent, this only applies to local excess
119      * space created by fixed-height children that span multiple rows.
120      */

121     public boolean grabVertical;
122
123     int childIndex;
124
125     boolean isItemData = true;
126
127     int compWidth;
128
129     Point compSize;
130
131     /**
132      * The default constructor.
133      */

134     public TableWrapData() {
135     }
136
137     /**
138      * The convenience constructor - allows passing the horizontal alignment
139      * style.
140      *
141      * @param align
142      * horizontal alignment (LEFT, CENTER, RIGHT, FILL or FILL_GRAB).
143      */

144     public TableWrapData(int align) {
145         this(align, TOP, 1, 1);
146     }
147
148     /**
149      * The convenience constructor - allows passing the alignment styles.
150      *
151      * @param align
152      * horizontal alignment (LEFT, CENTER, RIGHT, FILL or FILL_GRAB).
153      * @param valign
154      * vertical alignment (TOP, MIDDLE, BOTTOM, FILL or FILL_GRAB).
155      */

156     public TableWrapData(int align, int valign) {
157         this(align, valign, 1, 1);
158     }
159
160     /**
161      * The convenience constructor - allows passing the alignment styles, column
162      * and row spans.
163      *
164      * @param align
165      * horizontal alignment (LEFT, CENTER, RIGHT, FILL or FILL_GRAB).
166      * @param valign
167      * vertical alignment (TOP, MIDDLE, BOTTOM, FILL or FILL_GRAB)
168      * @param rowspan
169      * row span (1 or more)
170      * @param colspan
171      * column span (1 or more)
172      */

173     public TableWrapData(int align, int valign, int rowspan, int colspan) {
174         if (align != LEFT && align != CENTER && align != RIGHT && align != FILL
175                 && align != FILL_GRAB)
176             SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "align"); //$NON-NLS-1$
177
if (valign != TOP && valign != MIDDLE && valign != BOTTOM
178                 && valign != FILL && valign != FILL_GRAB)
179             SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "valign"); //$NON-NLS-1$
180
if (rowspan < 1)
181             SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "rowspan"); //$NON-NLS-1$
182
if (colspan < 1)
183             SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "colspan"); //$NON-NLS-1$
184
if (align == FILL_GRAB) {
185             this.align = FILL;
186             grabHorizontal = true;
187         } else
188             this.align = align;
189         if (valign == FILL_GRAB) {
190             this.valign = FILL;
191             grabVertical = true;
192         } else
193             this.valign = valign;
194         this.rowspan = rowspan;
195         this.colspan = colspan;
196     }
197 }
198
Popular Tags