51
|
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 module dwt.layout.RowData;
|
|
12
|
|
13 import dwt.SWT;
|
|
14 import dwt.graphics.Point;
|
|
15 import dwt.widgets.Control;
|
|
16
|
|
17 import tango.text.Util;
|
|
18 import tango.util.Convert;
|
|
19
|
|
20 /**
|
|
21 * Each control controlled by a <code>RowLayout</code> can have its initial
|
|
22 * width and height specified by setting a <code>RowData</code> object
|
|
23 * into the control.
|
|
24 * <p>
|
|
25 * The following code uses a <code>RowData</code> object to change the initial
|
|
26 * size of a <code>Button</code> in a <code>Shell</code>:
|
|
27 * <pre>
|
|
28 * Display display = new Display();
|
|
29 * Shell shell = new Shell(display);
|
|
30 * shell.setLayout(new RowLayout());
|
|
31 * Button button1 = new Button(shell, SWT.PUSH);
|
|
32 * button1.setText("Button 1");
|
|
33 * button1.setLayoutData(new RowData(50, 40));
|
|
34 * </pre>
|
|
35 * </p>
|
|
36 *
|
|
37 * @see RowLayout
|
|
38 */
|
|
39 public final class RowData {
|
|
40 /**
|
|
41 * width specifies the desired width in pixels. This value
|
|
42 * is the wHint passed into Control.computeSize(int, int, bool)
|
|
43 * to determine the preferred size of the control.
|
|
44 *
|
|
45 * The default value is SWT.DEFAULT.
|
|
46 *
|
|
47 * @see dwt.widgets.Control#computeSize(int, int, bool)
|
|
48 */
|
|
49 public int width = SWT.DEFAULT;
|
|
50 /**
|
|
51 * height specifies the preferred height in pixels. This value
|
|
52 * is the hHint passed into Control.computeSize(int, int, bool)
|
|
53 * to determine the preferred size of the control.
|
|
54 *
|
|
55 * The default value is SWT.DEFAULT.
|
|
56 *
|
|
57 * @see dwt.widgets.Control#computeSize(int, int, bool)
|
|
58 */
|
|
59 public int height = SWT.DEFAULT;
|
|
60
|
|
61 /**
|
|
62 * exclude informs the layout to ignore this control when sizing
|
|
63 * and positioning controls. If this value is <code>true</code>,
|
|
64 * the size and position of the control will not be managed by the
|
|
65 * layout. If this value is <code>false</code>, the size and
|
|
66 * position of the control will be computed and assigned.
|
|
67 *
|
|
68 * The default value is <code>false</code>.
|
|
69 *
|
|
70 * @since 3.1
|
|
71 */
|
|
72 public bool exclude = false;
|
|
73
|
|
74 /**
|
|
75 * Constructs a new instance of RowData using
|
|
76 * default values.
|
|
77 */
|
|
78 public this () {
|
|
79 }
|
|
80
|
|
81 /**
|
|
82 * Constructs a new instance of RowData according to the parameters.
|
|
83 * A value of SWT.DEFAULT indicates that no minimum width or
|
|
84 * no minimum height is specified.
|
|
85 *
|
|
86 * @param width a minimum width for the control
|
|
87 * @param height a minimum height for the control
|
|
88 */
|
|
89 public this (int width, int height) {
|
|
90 this.width = width;
|
|
91 this.height = height;
|
|
92 }
|
|
93
|
|
94 /**
|
|
95 * Constructs a new instance of RowData according to the parameter.
|
|
96 * A value of SWT.DEFAULT indicates that no minimum width or
|
|
97 * no minimum height is specified.
|
|
98 *
|
|
99 * @param point a point whose x coordinate specifies a minimum width for the control
|
|
100 * and y coordinate specifies a minimum height for the control
|
|
101 */
|
|
102 public this (Point point) {
|
|
103 this (point.x, point.y);
|
|
104 }
|
|
105
|
|
106 char[] getName () {
|
|
107 char[] string = this.classinfo.name;
|
|
108 int index = locatePrior( string, '.');
|
|
109 if (index is string.length ) return string;
|
|
110 return string[ index + 1 .. string.length ];
|
|
111 }
|
|
112
|
|
113 /**
|
|
114 * Returns a string containing a concise, human-readable
|
|
115 * description of the receiver.
|
|
116 *
|
|
117 * @return a string representation of the RowData object
|
|
118 */
|
|
119 public char[] toString () {
|
|
120 char[] string = getName ()~" {";
|
|
121 if (width !is SWT.DEFAULT) string ~= "width="~to!(char[])(width)~" ";
|
|
122 if (height !is SWT.DEFAULT) string ~= "height="~to!(char[])(height)~" ";
|
|
123 if (exclude) string ~= "exclude="~to!(char[])(exclude)~" ";
|
|
124 string = trim( string );
|
|
125 string ~= "}";
|
|
126 return string;
|
|
127 }
|
|
128 }
|