KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > layout > RowData


1 /*******************************************************************************
2  * Copyright (c) 2000, 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 package org.eclipse.swt.layout;
12
13 import org.eclipse.swt.*;
14 import org.eclipse.swt.graphics.*;
15
16 /**
17  * Each control controlled by a <code>RowLayout</code> can have its initial
18  * width and height specified by setting a <code>RowData</code> object
19  * into the control.
20  * <p>
21  * The following code uses a <code>RowData</code> object to change the initial
22  * size of a <code>Button</code> in a <code>Shell</code>:
23  * <pre>
24  * Display display = new Display();
25  * Shell shell = new Shell(display);
26  * shell.setLayout(new RowLayout());
27  * Button button1 = new Button(shell, SWT.PUSH);
28  * button1.setText("Button 1");
29  * button1.setLayoutData(new RowData(50, 40));
30  * </pre>
31  * </p>
32  *
33  * @see RowLayout
34  */

35 public final class RowData {
36     /**
37      * width specifies the desired width in pixels. This value
38      * is the wHint passed into Control.computeSize(int, int, boolean)
39      * to determine the preferred size of the control.
40      *
41      * The default value is SWT.DEFAULT.
42      *
43      * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
44      */

45     public int width = SWT.DEFAULT;
46     /**
47      * height specifies the preferred height in pixels. This value
48      * is the hHint passed into Control.computeSize(int, int, boolean)
49      * to determine the preferred size of the control.
50      *
51      * The default value is SWT.DEFAULT.
52      *
53      * @see org.eclipse.swt.widgets.Control#computeSize(int, int, boolean)
54      */

55     public int height = SWT.DEFAULT;
56     
57     /**
58      * exclude informs the layout to ignore this control when sizing
59      * and positioning controls. If this value is <code>true</code>,
60      * the size and position of the control will not be managed by the
61      * layout. If this value is <code>false</code>, the size and
62      * position of the control will be computed and assigned.
63      *
64      * The default value is <code>false</code>.
65      *
66      * @since 3.1
67      */

68     public boolean exclude = false;
69     
70 /**
71  * Constructs a new instance of RowData using
72  * default values.
73  */

74 public RowData () {
75 }
76
77 /**
78  * Constructs a new instance of RowData according to the parameters.
79  * A value of SWT.DEFAULT indicates that no minimum width or
80  * no minimum height is specified.
81  *
82  * @param width a minimum width for the control
83  * @param height a minimum height for the control
84  */

85 public RowData (int width, int height) {
86     this.width = width;
87     this.height = height;
88 }
89
90 /**
91  * Constructs a new instance of RowData according to the parameter.
92  * A value of SWT.DEFAULT indicates that no minimum width or
93  * no minimum height is specified.
94  *
95  * @param point a point whose x coordinate specifies a minimum width for the control
96  * and y coordinate specifies a minimum height for the control
97  */

98 public RowData (Point point) {
99     this (point.x, point.y);
100 }
101
102 String JavaDoc getName () {
103     String JavaDoc string = getClass ().getName ();
104     int index = string.lastIndexOf ('.');
105     if (index == -1) 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 JavaDoc toString () {
116     String JavaDoc string = getName ()+" {";
117     if (width != SWT.DEFAULT) string += "width="+width+" ";
118     if (height != SWT.DEFAULT) string += "height="+height+" ";
119     if (exclude) string += "exclude="+exclude+" ";
120     string = string.trim();
121     string += "}";
122     return string;
123 }
124 }
125
Popular Tags