001: /*******************************************************************************
002: * Copyright (c) 2000, 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.swt.layout;
011:
012: import org.eclipse.swt.*;
013: import org.eclipse.swt.graphics.*;
014:
015: /**
016: * Each control controlled by a <code>RowLayout</code> can have its initial
017: * width and height specified by setting a <code>RowData</code> object
018: * into the control.
019: * <p>
020: * The following code uses a <code>RowData</code> object to change the initial
021: * size of a <code>Button</code> in a <code>Shell</code>:
022: * <pre>
023: * Display display = new Display();
024: * Shell shell = new Shell(display);
025: * shell.setLayout(new RowLayout());
026: * Button button1 = new Button(shell, SWT.PUSH);
027: * button1.setText("Button 1");
028: * button1.setLayoutData(new RowData(50, 40));
029: * </pre>
030: * </p>
031: *
032: * @see RowLayout
033: */
034: public final class RowData {
035: /**
036: * width specifies the desired width in pixels. This value
037: * is the wHint passed into Control.computeSize(int, int, boolean)
038: * to determine the preferred size of the control.
039: *
040: * The default value is SWT.DEFAULT.
041: *
042: * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
043: */
044: public int width = SWT.DEFAULT;
045: /**
046: * height specifies the preferred height in pixels. This value
047: * is the hHint passed into Control.computeSize(int, int, boolean)
048: * to determine the preferred size of the control.
049: *
050: * The default value is SWT.DEFAULT.
051: *
052: * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
053: */
054: public int height = SWT.DEFAULT;
055:
056: /**
057: * exclude informs the layout to ignore this control when sizing
058: * and positioning controls. If this value is <code>true</code>,
059: * the size and position of the control will not be managed by the
060: * layout. If this value is <code>false</code>, the size and
061: * position of the control will be computed and assigned.
062: *
063: * The default value is <code>false</code>.
064: *
065: * @since 3.1
066: */
067: public boolean exclude = false;
068:
069: /**
070: * Constructs a new instance of RowData using
071: * default values.
072: */
073: public RowData() {
074: }
075:
076: /**
077: * Constructs a new instance of RowData according to the parameters.
078: * A value of SWT.DEFAULT indicates that no minimum width or
079: * no minimum height is specified.
080: *
081: * @param width a minimum width for the control
082: * @param height a minimum height for the control
083: */
084: public RowData(int width, int height) {
085: this .width = width;
086: this .height = height;
087: }
088:
089: /**
090: * Constructs a new instance of RowData according to the parameter.
091: * A value of SWT.DEFAULT indicates that no minimum width or
092: * no minimum height is specified.
093: *
094: * @param point a point whose x coordinate specifies a minimum width for the control
095: * and y coordinate specifies a minimum height for the control
096: */
097: public RowData(Point point) {
098: this (point.x, point.y);
099: }
100:
101: String getName() {
102: String string = getClass().getName();
103: int index = string.lastIndexOf('.');
104: if (index == -1)
105: return string;
106: return string.substring(index + 1, string.length());
107: }
108:
109: /**
110: * Returns a string containing a concise, human-readable
111: * description of the receiver.
112: *
113: * @return a string representation of the RowData object
114: */
115: public String toString() {
116: String string = getName() + " {";
117: if (width != SWT.DEFAULT)
118: string += "width=" + width + " ";
119: if (height != SWT.DEFAULT)
120: string += "height=" + height + " ";
121: if (exclude)
122: string += "exclude=" + exclude + " ";
123: string = string.trim();
124: string += "}";
125: return string;
126: }
127: }
|