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