comparison dwtexamples/controlexample/TextTab.d @ 0:052c3aebd1d3

initial import
author Frank Benoit <benoit@tionex.de>
date Fri, 01 Feb 2008 21:46:26 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:052c3aebd1d3
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 dwtexamples.controlexample.TextTab;
14
15
16
17 import dwt.DWT;
18 import dwt.events.ControlAdapter;
19 import dwt.events.ControlEvent;
20 import dwt.layout.GridData;
21 import dwt.layout.GridLayout;
22 import dwt.widgets.Button;
23 import dwt.widgets.Composite;
24 import dwt.widgets.Group;
25 import dwt.widgets.TabFolder;
26 import dwt.widgets.Text;
27 import dwt.widgets.Widget;
28
29 import dwtexamples.controlexample.Tab;
30 import dwtexamples.controlexample.ControlExample;
31 import dwtexamples.controlexample.ScrollableTab;
32
33 class TextTab : ScrollableTab {
34 /* Example widgets and groups that contain them */
35 Text text;
36 Group textGroup;
37
38 /* Style widgets added to the "Style" group */
39 Button wrapButton, readOnlyButton, passwordButton, searchButton, cancelButton;
40 Button leftButton, centerButton, rightButton;
41
42 /**
43 * Creates the Tab within a given instance of ControlExample.
44 */
45 this(ControlExample instance) {
46 super(instance);
47 }
48
49 /**
50 * Creates the "Example" group.
51 */
52 void createExampleGroup () {
53 super.createExampleGroup ();
54
55 /* Create a group for the text widget */
56 textGroup = new Group (exampleGroup, DWT.NONE);
57 textGroup.setLayout (new GridLayout ());
58 textGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
59 textGroup.setText ("Text");
60 }
61
62 /**
63 * Creates the "Example" widgets.
64 */
65 void createExampleWidgets () {
66
67 /* Compute the widget style */
68 int style = getDefaultStyle();
69 if (singleButton.getSelection ()) style |= DWT.SINGLE;
70 if (multiButton.getSelection ()) style |= DWT.MULTI;
71 if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL;
72 if (verticalButton.getSelection ()) style |= DWT.V_SCROLL;
73 if (wrapButton.getSelection ()) style |= DWT.WRAP;
74 if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY;
75 if (passwordButton.getSelection ()) style |= DWT.PASSWORD;
76 if (searchButton.getSelection ()) style |= DWT.SEARCH;
77 if (cancelButton.getSelection ()) style |= DWT.CANCEL;
78 if (borderButton.getSelection ()) style |= DWT.BORDER;
79 if (leftButton.getSelection ()) style |= DWT.LEFT;
80 if (centerButton.getSelection ()) style |= DWT.CENTER;
81 if (rightButton.getSelection ()) style |= DWT.RIGHT;
82
83 /* Create the example widgets */
84 text = new Text (textGroup, style);
85 text.setText (ControlExample.getResourceString("Example_string") ~ Text.DELIMITER ~ ControlExample.getResourceString("One_Two_Three"));
86 }
87
88 /**
89 * Creates the "Style" group.
90 */
91 void createStyleGroup() {
92 super.createStyleGroup();
93
94 /* Create the extra widgets */
95 wrapButton = new Button (styleGroup, DWT.CHECK);
96 wrapButton.setText ("DWT.WRAP");
97 readOnlyButton = new Button (styleGroup, DWT.CHECK);
98 readOnlyButton.setText ("DWT.READ_ONLY");
99 passwordButton = new Button (styleGroup, DWT.CHECK);
100 passwordButton.setText ("DWT.PASSWORD");
101 searchButton = new Button (styleGroup, DWT.CHECK);
102 searchButton.setText ("DWT.SEARCH");
103 cancelButton = new Button (styleGroup, DWT.CHECK);
104 cancelButton.setText ("DWT.CANCEL");
105
106 Composite alignmentGroup = new Composite (styleGroup, DWT.NONE);
107 GridLayout layout = new GridLayout ();
108 layout.marginWidth = layout.marginHeight = 0;
109 alignmentGroup.setLayout (layout);
110 alignmentGroup.setLayoutData (new GridData (GridData.FILL_BOTH));
111 leftButton = new Button (alignmentGroup, DWT.RADIO);
112 leftButton.setText ("DWT.LEFT");
113 centerButton = new Button (alignmentGroup, DWT.RADIO);
114 centerButton.setText ("DWT.CENTER");
115 rightButton = new Button (alignmentGroup, DWT.RADIO);
116 rightButton.setText ("DWT.RIGHT");
117 }
118
119 /**
120 * Creates the tab folder page.
121 *
122 * @param tabFolder org.eclipse.swt.widgets.TabFolder
123 * @return the new page for the tab folder
124 */
125 Composite createTabFolderPage (TabFolder tabFolder) {
126 super.createTabFolderPage (tabFolder);
127
128 /*
129 * Add a resize listener to the tabFolderPage so that
130 * if the user types into the example widget to change
131 * its preferred size, and then resizes the shell, we
132 * recalculate the preferred size correctly.
133 */
134 tabFolderPage.addControlListener(new class() ControlAdapter {
135 public void controlResized(ControlEvent e) {
136 setExampleWidgetSize ();
137 }
138 });
139
140 return tabFolderPage;
141 }
142
143 /**
144 * Gets the "Example" widget children.
145 */
146 Widget [] getExampleWidgets () {
147 return [ cast(Widget) text];
148 }
149
150 /**
151 * Returns a list of set/get API method names (without the set/get prefix)
152 * that can be used to set/get values in the example control(s).
153 */
154 char[][] getMethodNames() {
155 return ["DoubleClickEnabled", "EchoChar", "Editable", "Orientation", "Selection", "Tabs", "Text", "TextLimit", "ToolTipText", "TopIndex"];
156 }
157
158 /**
159 * Gets the text for the tab folder item.
160 */
161 char[] getTabText () {
162 return "Text";
163 }
164
165 /**
166 * Sets the state of the "Example" widgets.
167 */
168 void setExampleWidgetState () {
169 super.setExampleWidgetState ();
170 wrapButton.setSelection ((text.getStyle () & DWT.WRAP) !is 0);
171 readOnlyButton.setSelection ((text.getStyle () & DWT.READ_ONLY) !is 0);
172 passwordButton.setSelection ((text.getStyle () & DWT.PASSWORD) !is 0);
173 searchButton.setSelection ((text.getStyle () & DWT.SEARCH) !is 0);
174 leftButton.setSelection ((text.getStyle () & DWT.LEFT) !is 0);
175 centerButton.setSelection ((text.getStyle () & DWT.CENTER) !is 0);
176 rightButton.setSelection ((text.getStyle () & DWT.RIGHT) !is 0);
177
178 /* Special case: CANCEL and H_SCROLL have the same value,
179 * so to avoid confusion, only set CANCEL if SEARCH is set. */
180 if ((text.getStyle () & DWT.SEARCH) !is 0) {
181 cancelButton.setSelection ((text.getStyle () & DWT.CANCEL) !is 0);
182 horizontalButton.setSelection (false);
183 } else {
184 cancelButton.setSelection (false);
185 horizontalButton.setSelection ((text.getStyle () & DWT.H_SCROLL) !is 0);
186 }
187
188 passwordButton.setEnabled ((text.getStyle () & DWT.SINGLE) !is 0);
189 searchButton.setEnabled ((text.getStyle () & DWT.SINGLE) !is 0);
190 cancelButton.setEnabled ((text.getStyle () & DWT.SEARCH) !is 0);
191 wrapButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0);
192 horizontalButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0);
193 verticalButton.setEnabled ((text.getStyle () & DWT.MULTI) !is 0);
194 }
195 }