001: /*******************************************************************************
002: * Copyright (c) 2004, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.layout;
011:
012: /**
013: * Describes a single row (or column) in a CellLayout
014: *
015: * @since 3.0
016: */
017: public class Row {
018: /**
019: * True iff this row will expand to fill available space
020: */
021: boolean grows = false;
022:
023: /**
024: * Size of this row. For growing rows, this is the relative size
025: * of the row with respect to other rows (ie: a row of size 100 is twice
026: * as wide as a row of size 50). For fixed rows, this is the absolute size
027: * of the row, in pixels.
028: */
029: int size = 0;
030:
031: /**
032: * True iff this row should query its child controls for its size.
033: */
034: boolean largerThanChildren = true;
035:
036: /**
037: * Creates a fixed-size row with the given width (pixels).
038: * The preferred sizes of child controls are ignored.
039: *
040: * @param size
041: */
042: public Row(int size) {
043: largerThanChildren = false;
044: this .size = size;
045: grows = false;
046: }
047:
048: /**
049: * Creates a row that automatically computes its size based on the preferred
050: * sizes of its children.
051: *
052: * @param growing
053: */
054: public Row(boolean growing) {
055: this .grows = growing;
056:
057: if (growing) {
058: size = 100;
059: }
060: }
061:
062: /**
063: * Creates a growing row.
064: *
065: * @param sizeRatio determines the size of this row with respect to other growing rows
066: * (for example, a row with size = 3 will be 3x as large as a row with size = 1)
067: * @param largerThanChildren true iff the preferred size of this row should take into
068: * account the preferred sizes of its children.
069: */
070: public Row(int size, boolean largerThanChildren) {
071: this .grows = true;
072: this .size = size;
073: this .largerThanChildren = largerThanChildren;
074: }
075:
076: /**
077: * Construct and return a typical growing row.
078: *
079: * @return a growing row
080: */
081: public static Row growing() {
082: return new Row(100, true);
083: }
084:
085: /**
086: * Construct and return a growing row with custom properties
087: *
088: * @param size relative size of this row with respect to other growing rows
089: * @param largerThanChildren true iff the preferred size of this row should
090: * be based on the preferred sizes of its children
091: * @return a new Row
092: */
093: public static Row growing(int size, boolean largerThanChildren) {
094: return new Row(size, largerThanChildren);
095: }
096:
097: /**
098: * Construct and return a fixed-size row. The row will not grow when the layout
099: * is resized, and its size will be computed from the default sizes of its children.
100: *
101: * @return a new Row
102: */
103: public static Row fixed() {
104: return new Row(false);
105: }
106:
107: /**
108: * Construct and return a fixed-size row. The row will always have the given
109: * width, regardless of the size of the layout or the preferred sizes of its children.
110: *
111: * @param pixels size of the row
112: * @return a fixed-size row with the given width (in pixels)
113: */
114: public static Row fixed(int pixels) {
115: return new Row(pixels);
116: }
117: }
|