comparison examples/controlexample/LabelTab.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children eb84f9418bbf
comparison
equal deleted inserted replaced
76:04f122e90b0a 78:4a04b6759f98
1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 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 examples.controlexample.LabelTab;
14
15
16
17 import dwt.DWT;
18 import dwt.layout.GridData;
19 import dwt.layout.GridLayout;
20 import dwt.widgets.Button;
21 import dwt.widgets.Group;
22 import dwt.widgets.Label;
23 import dwt.widgets.Widget;
24
25 import examples.controlexample.Tab;
26 import examples.controlexample.ControlExample;
27 import examples.controlexample.AlignableTab;
28
29 class LabelTab : AlignableTab {
30 /* Example widgets and groups that contain them */
31 Label label1, label2, label3, label4, label5, label6;
32 Group textLabelGroup, imageLabelGroup;
33
34 /* Style widgets added to the "Style" group */
35 Button wrapButton, separatorButton, horizontalButton, verticalButton, shadowInButton, shadowOutButton, shadowNoneButton;
36
37 /**
38 * Creates the Tab within a given instance of ControlExample.
39 */
40 this(ControlExample instance) {
41 super(instance);
42 }
43
44 /**
45 * Creates the "Example" group.
46 */
47 void createExampleGroup () {
48 super.createExampleGroup ();
49
50 /* Create a group for the text labels */
51 textLabelGroup = new Group(exampleGroup, DWT.NONE);
52 GridLayout gridLayout = new GridLayout ();
53 textLabelGroup.setLayout (gridLayout);
54 gridLayout.numColumns = 3;
55 textLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
56 textLabelGroup.setText (ControlExample.getResourceString("Text_Labels"));
57
58 /* Create a group for the image labels */
59 imageLabelGroup = new Group (exampleGroup, DWT.SHADOW_NONE);
60 gridLayout = new GridLayout ();
61 imageLabelGroup.setLayout (gridLayout);
62 gridLayout.numColumns = 3;
63 imageLabelGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
64 imageLabelGroup.setText (ControlExample.getResourceString("Image_Labels"));
65 }
66
67 /**
68 * Creates the "Example" widgets.
69 */
70 void createExampleWidgets () {
71
72 /* Compute the widget style */
73 int style = getDefaultStyle();
74 if (wrapButton.getSelection ()) style |= DWT.WRAP;
75 if (separatorButton.getSelection ()) style |= DWT.SEPARATOR;
76 if (horizontalButton.getSelection ()) style |= DWT.HORIZONTAL;
77 if (verticalButton.getSelection ()) style |= DWT.VERTICAL;
78 if (shadowInButton.getSelection ()) style |= DWT.SHADOW_IN;
79 if (shadowOutButton.getSelection ()) style |= DWT.SHADOW_OUT;
80 if (shadowNoneButton.getSelection ()) style |= DWT.SHADOW_NONE;
81 if (borderButton.getSelection ()) style |= DWT.BORDER;
82 if (leftButton.getSelection ()) style |= DWT.LEFT;
83 if (centerButton.getSelection ()) style |= DWT.CENTER;
84 if (rightButton.getSelection ()) style |= DWT.RIGHT;
85
86 /* Create the example widgets */
87 label1 = new Label (textLabelGroup, style);
88 label1.setText(ControlExample.getResourceString("One"));
89 label2 = new Label (textLabelGroup, style);
90 label2.setText(ControlExample.getResourceString("Two"));
91 label3 = new Label (textLabelGroup, style);
92 if (wrapButton.getSelection ()) {
93 label3.setText (ControlExample.getResourceString("Wrap_Text"));
94 } else {
95 label3.setText (ControlExample.getResourceString("Three"));
96 }
97 label4 = new Label (imageLabelGroup, style);
98 label4.setImage (instance.images[ControlExample.ciClosedFolder]);
99 label5 = new Label (imageLabelGroup, style);
100 label5.setImage (instance.images[ControlExample.ciOpenFolder]);
101 label6 = new Label(imageLabelGroup, style);
102 label6.setImage (instance.images[ControlExample.ciTarget]);
103 }
104
105 /**
106 * Creates the "Style" group.
107 */
108 void createStyleGroup() {
109 super.createStyleGroup ();
110
111 /* Create the extra widgets */
112 wrapButton = new Button (styleGroup, DWT.CHECK);
113 wrapButton.setText ("DWT.WRAP");
114 separatorButton = new Button (styleGroup, DWT.CHECK);
115 separatorButton.setText ("DWT.SEPARATOR");
116 horizontalButton = new Button (styleGroup, DWT.RADIO);
117 horizontalButton.setText ("DWT.HORIZONTAL");
118 verticalButton = new Button (styleGroup, DWT.RADIO);
119 verticalButton.setText ("DWT.VERTICAL");
120 Group styleSubGroup = new Group (styleGroup, DWT.NONE);
121 styleSubGroup.setLayout (new GridLayout ());
122 shadowInButton = new Button (styleSubGroup, DWT.RADIO);
123 shadowInButton.setText ("DWT.SHADOW_IN");
124 shadowOutButton = new Button (styleSubGroup, DWT.RADIO);
125 shadowOutButton.setText ("DWT.SHADOW_OUT");
126 shadowNoneButton = new Button (styleSubGroup, DWT.RADIO);
127 shadowNoneButton.setText ("DWT.SHADOW_NONE");
128 borderButton = new Button(styleGroup, DWT.CHECK);
129 borderButton.setText("DWT.BORDER");
130 }
131
132 /**
133 * Gets the "Example" widget children.
134 */
135 Widget [] getExampleWidgets () {
136 return [ cast(Widget) label1, label2, label3, label4, label5, label6 ];
137 }
138
139 /**
140 * Returns a list of set/get API method names (without the set/get prefix)
141 * that can be used to set/get values in the example control(s).
142 */
143 char[][] getMethodNames() {
144 return ["Text", "ToolTipText"];
145 }
146
147 /**
148 * Gets the text for the tab folder item.
149 */
150 char[] getTabText () {
151 return "Label";
152 }
153
154 /**
155 * Sets the alignment of the "Example" widgets.
156 */
157 void setExampleWidgetAlignment () {
158 int alignment = 0;
159 if (leftButton.getSelection ()) alignment = DWT.LEFT;
160 if (centerButton.getSelection ()) alignment = DWT.CENTER;
161 if (rightButton.getSelection ()) alignment = DWT.RIGHT;
162 label1.setAlignment (alignment);
163 label2.setAlignment (alignment);
164 label3.setAlignment (alignment);
165 label4.setAlignment (alignment);
166 label5.setAlignment (alignment);
167 label6.setAlignment (alignment);
168 }
169
170 /**
171 * Sets the state of the "Example" widgets.
172 */
173 void setExampleWidgetState () {
174 super.setExampleWidgetState ();
175 bool isSeparator = (label1.getStyle () & DWT.SEPARATOR) !is 0;
176 wrapButton.setSelection (!isSeparator && (label1.getStyle () & DWT.WRAP) !is 0);
177 leftButton.setSelection (!isSeparator && (label1.getStyle () & DWT.LEFT) !is 0);
178 centerButton.setSelection (!isSeparator && (label1.getStyle () & DWT.CENTER) !is 0);
179 rightButton.setSelection (!isSeparator && (label1.getStyle () & DWT.RIGHT) !is 0);
180 shadowInButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_IN) !is 0);
181 shadowOutButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_OUT) !is 0);
182 shadowNoneButton.setSelection (isSeparator && (label1.getStyle () & DWT.SHADOW_NONE) !is 0);
183 horizontalButton.setSelection (isSeparator && (label1.getStyle () & DWT.HORIZONTAL) !is 0);
184 verticalButton.setSelection (isSeparator && (label1.getStyle () & DWT.VERTICAL) !is 0);
185 wrapButton.setEnabled (!isSeparator);
186 leftButton.setEnabled (!isSeparator);
187 centerButton.setEnabled (!isSeparator);
188 rightButton.setEnabled (!isSeparator);
189 shadowInButton.setEnabled (isSeparator);
190 shadowOutButton.setEnabled (isSeparator);
191 shadowNoneButton.setEnabled (isSeparator);
192 horizontalButton.setEnabled (isSeparator);
193 verticalButton.setEnabled (isSeparator);
194 }
195 }