comparison examples/controlexample/ComboTab.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 8a1930f94cbb
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 dwtexamples.controlexample.ComboTab;
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.Combo;
24 import dwt.widgets.Composite;
25 import dwt.widgets.Group;
26 import dwt.widgets.TabFolder;
27 import dwt.widgets.Widget;
28
29 import dwtexamples.controlexample.Tab;
30 import dwtexamples.controlexample.ControlExample;
31
32 class ComboTab : Tab {
33
34 /* Example widgets and groups that contain them */
35 Combo combo1;
36 Group comboGroup;
37
38 /* Style widgets added to the "Style" group */
39 Button dropDownButton, readOnlyButton, simpleButton;
40
41 static char[] [] ListData;
42
43 /**
44 * Creates the Tab within a given instance of ControlExample.
45 */
46 this(ControlExample instance) {
47 super(instance);
48 if( ListData.length is 0 ){
49 ListData = [ControlExample.getResourceString("ListData0_0"),
50 ControlExample.getResourceString("ListData0_1"),
51 ControlExample.getResourceString("ListData0_2"),
52 ControlExample.getResourceString("ListData0_3"),
53 ControlExample.getResourceString("ListData0_4"),
54 ControlExample.getResourceString("ListData0_5"),
55 ControlExample.getResourceString("ListData0_6"),
56 ControlExample.getResourceString("ListData0_7"),
57 ControlExample.getResourceString("ListData0_8")];
58 }
59 }
60
61 /**
62 * Creates the "Example" group.
63 */
64 void createExampleGroup () {
65 super.createExampleGroup ();
66
67 /* Create a group for the combo box */
68 comboGroup = new Group (exampleGroup, DWT.NONE);
69 comboGroup.setLayout (new GridLayout ());
70 comboGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
71 comboGroup.setText ("Combo");
72 }
73
74 /**
75 * Creates the "Example" widgets.
76 */
77 void createExampleWidgets () {
78
79 /* Compute the widget style */
80 int style = getDefaultStyle();
81 if (dropDownButton.getSelection ()) style |= DWT.DROP_DOWN;
82 if (readOnlyButton.getSelection ()) style |= DWT.READ_ONLY;
83 if (simpleButton.getSelection ()) style |= DWT.SIMPLE;
84
85 /* Create the example widgets */
86 combo1 = new Combo (comboGroup, style);
87 combo1.setItems (ListData);
88 if (ListData.length >= 3) {
89 combo1.setText(ListData [2]);
90 }
91 }
92
93 /**
94 * Creates the tab folder page.
95 *
96 * @param tabFolder org.eclipse.swt.widgets.TabFolder
97 * @return the new page for the tab folder
98 */
99 Composite createTabFolderPage (TabFolder tabFolder) {
100 super.createTabFolderPage (tabFolder);
101
102 /*
103 * Add a resize listener to the tabFolderPage so that
104 * if the user types into the example widget to change
105 * its preferred size, and then resizes the shell, we
106 * recalculate the preferred size correctly.
107 */
108 tabFolderPage.addControlListener(new class() ControlAdapter {
109 public void controlResized(ControlEvent e) {
110 setExampleWidgetSize ();
111 }
112 });
113
114 return tabFolderPage;
115 }
116
117 /**
118 * Creates the "Style" group.
119 */
120 void createStyleGroup () {
121 super.createStyleGroup ();
122
123 /* Create the extra widgets */
124 dropDownButton = new Button (styleGroup, DWT.RADIO);
125 dropDownButton.setText ("DWT.DROP_DOWN");
126 simpleButton = new Button (styleGroup, DWT.RADIO);
127 simpleButton.setText("DWT.SIMPLE");
128 readOnlyButton = new Button (styleGroup, DWT.CHECK);
129 readOnlyButton.setText ("DWT.READ_ONLY");
130 }
131
132 /**
133 * Gets the "Example" widget children.
134 */
135 Widget [] getExampleWidgets () {
136 return [ cast(Widget) combo1];
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 ["Items", "Orientation", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"];
145 }
146
147 /**
148 * Gets the text for the tab folder item.
149 */
150 char[] getTabText () {
151 return "Combo";
152 }
153
154 /**
155 * Sets the state of the "Example" widgets.
156 */
157 void setExampleWidgetState () {
158 super.setExampleWidgetState ();
159 dropDownButton.setSelection ((combo1.getStyle () & DWT.DROP_DOWN) !is 0);
160 simpleButton.setSelection ((combo1.getStyle () & DWT.SIMPLE) !is 0);
161 readOnlyButton.setSelection ((combo1.getStyle () & DWT.READ_ONLY) !is 0);
162 readOnlyButton.setEnabled(!simpleButton.getSelection());
163 }
164 }