KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > layout > Row


1 /*******************************************************************************
2  * Copyright (c) 2004, 2006 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
12 package org.eclipse.ui.internal.layout;
13
14 /**
15  * Describes a single row (or column) in a CellLayout
16  *
17  * @since 3.0
18  */

19 public class Row {
20     /**
21      * True iff this row will expand to fill available space
22      */

23     boolean grows = false;
24
25     /**
26      * Size of this row. For growing rows, this is the relative size
27      * of the row with respect to other rows (ie: a row of size 100 is twice
28      * as wide as a row of size 50). For fixed rows, this is the absolute size
29      * of the row, in pixels.
30      */

31     int size = 0;
32
33     /**
34      * True iff this row should query its child controls for its size.
35      */

36     boolean largerThanChildren = true;
37
38     /**
39      * Creates a fixed-size row with the given width (pixels).
40      * The preferred sizes of child controls are ignored.
41      *
42      * @param size
43      */

44     public Row(int size) {
45         largerThanChildren = false;
46         this.size = size;
47         grows = false;
48     }
49
50     /**
51      * Creates a row that automatically computes its size based on the preferred
52      * sizes of its children.
53      *
54      * @param growing
55      */

56     public Row(boolean growing) {
57         this.grows = growing;
58
59         if (growing) {
60             size = 100;
61         }
62     }
63
64     /**
65      * Creates a growing row.
66      *
67      * @param sizeRatio determines the size of this row with respect to other growing rows
68      * (for example, a row with size = 3 will be 3x as large as a row with size = 1)
69      * @param largerThanChildren true iff the preferred size of this row should take into
70      * account the preferred sizes of its children.
71      */

72     public Row(int size, boolean largerThanChildren) {
73         this.grows = true;
74         this.size = size;
75         this.largerThanChildren = largerThanChildren;
76     }
77
78     /**
79      * Construct and return a typical growing row.
80      *
81      * @return a growing row
82      */

83     public static Row growing() {
84         return new Row(100, true);
85     }
86
87     /**
88      * Construct and return a growing row with custom properties
89      *
90      * @param size relative size of this row with respect to other growing rows
91      * @param largerThanChildren true iff the preferred size of this row should
92      * be based on the preferred sizes of its children
93      * @return a new Row
94      */

95     public static Row growing(int size, boolean largerThanChildren) {
96         return new Row(size, largerThanChildren);
97     }
98
99     /**
100      * Construct and return a fixed-size row. The row will not grow when the layout
101      * is resized, and its size will be computed from the default sizes of its children.
102      *
103      * @return a new Row
104      */

105     public static Row fixed() {
106         return new Row(false);
107     }
108
109     /**
110      * Construct and return a fixed-size row. The row will always have the given
111      * width, regardless of the size of the layout or the preferred sizes of its children.
112      *
113      * @param pixels size of the row
114      * @return a fixed-size row with the given width (in pixels)
115      */

116     public static Row fixed(int pixels) {
117         return new Row(pixels);
118     }
119 }
120
Popular Tags