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