Mercurial > projects > dwt-samples
annotate examples/controlexample/ToolTipTab.d @ 161:eb84f9418bbf
Change module names to this not have examples in the FQN.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 01 Sep 2008 22:24:27 +0200 |
parents | 4a04b6759f98 |
children |
rev | line source |
---|---|
78 | 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 *******************************************************************************/ | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
13 module controlexample.ToolTipTab; |
78 | 14 |
15 | |
16 | |
17 import dwt.DWT; | |
18 import dwt.events.ControlAdapter; | |
19 import dwt.events.ControlEvent; | |
20 import dwt.events.DisposeEvent; | |
21 import dwt.events.DisposeListener; | |
22 import dwt.events.SelectionAdapter; | |
23 import dwt.events.SelectionEvent; | |
24 import dwt.layout.GridData; | |
25 import dwt.layout.GridLayout; | |
26 import dwt.widgets.Button; | |
27 import dwt.widgets.Composite; | |
28 import dwt.widgets.Group; | |
29 import dwt.widgets.TabFolder; | |
30 import dwt.widgets.ToolTip; | |
31 import dwt.widgets.Tray; | |
32 import dwt.widgets.TrayItem; | |
33 import dwt.widgets.Widget; | |
34 | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
35 import controlexample.Tab; |
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
36 import controlexample.ControlExample; |
78 | 37 |
38 class ToolTipTab : Tab { | |
39 | |
40 /* Example widgets and groups that contain them */ | |
41 ToolTip toolTip1; | |
42 Group toolTipGroup; | |
43 | |
44 /* Style widgets added to the "Style" group */ | |
45 Button balloonButton, iconErrorButton, iconInformationButton, iconWarningButton, noIconButton; | |
46 | |
47 /* Other widgets added to the "Other" group */ | |
48 Button autoHideButton, showInTrayButton; | |
49 | |
50 Tray tray; | |
51 TrayItem trayItem; | |
52 | |
53 /** | |
54 * Creates the Tab within a given instance of ControlExample. | |
55 */ | |
56 this(ControlExample instance) { | |
57 super(instance); | |
58 } | |
59 | |
60 /** | |
61 * Creates the "Example" group. | |
62 */ | |
63 void createExampleGroup () { | |
64 super.createExampleGroup (); | |
65 | |
66 /* Create a group for the tooltip visibility check box */ | |
67 toolTipGroup = new Group (exampleGroup, DWT.NONE); | |
68 toolTipGroup.setLayout (new GridLayout ()); | |
69 toolTipGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
70 toolTipGroup.setText ("ToolTip"); | |
71 visibleButton = new Button(toolTipGroup, DWT.CHECK); | |
72 visibleButton.setText(ControlExample.getResourceString("Visible")); | |
73 visibleButton.addSelectionListener (new class() SelectionAdapter { | |
74 public void widgetSelected (SelectionEvent event) { | |
75 setExampleWidgetVisibility (); | |
76 } | |
77 }); | |
78 } | |
79 | |
80 /** | |
81 * Creates the "Example" widgets. | |
82 */ | |
83 void createExampleWidgets () { | |
84 | |
85 /* Compute the widget style */ | |
86 int style = getDefaultStyle(); | |
87 if (balloonButton.getSelection ()) style |= DWT.BALLOON; | |
88 if (iconErrorButton.getSelection ()) style |= DWT.ICON_ERROR; | |
89 if (iconInformationButton.getSelection ()) style |= DWT.ICON_INFORMATION; | |
90 if (iconWarningButton.getSelection ()) style |= DWT.ICON_WARNING; | |
91 | |
92 /* Create the example widgets */ | |
93 toolTip1 = new ToolTip (shell, style); | |
94 toolTip1.setText(ControlExample.getResourceString("ToolTip_Title")); | |
95 toolTip1.setMessage(ControlExample.getResourceString("Example_string")); | |
96 } | |
97 | |
98 /** | |
99 * Creates the tab folder page. | |
100 * | |
101 * @param tabFolder org.eclipse.swt.widgets.TabFolder | |
102 * @return the new page for the tab folder | |
103 */ | |
104 Composite createTabFolderPage (TabFolder tabFolder) { | |
105 super.createTabFolderPage (tabFolder); | |
106 | |
107 /* | |
108 * Add a resize listener to the tabFolderPage so that | |
109 * if the user types into the example widget to change | |
110 * its preferred size, and then resizes the shell, we | |
111 * recalculate the preferred size correctly. | |
112 */ | |
113 tabFolderPage.addControlListener(new class() ControlAdapter { | |
114 public void controlResized(ControlEvent e) { | |
115 setExampleWidgetSize (); | |
116 } | |
117 }); | |
118 | |
119 return tabFolderPage; | |
120 } | |
121 | |
122 /** | |
123 * Creates the "Style" group. | |
124 */ | |
125 void createStyleGroup () { | |
126 super.createStyleGroup (); | |
127 | |
128 /* Create the extra widgets */ | |
129 balloonButton = new Button (styleGroup, DWT.CHECK); | |
130 balloonButton.setText ("DWT.BALLOON"); | |
131 iconErrorButton = new Button (styleGroup, DWT.RADIO); | |
132 iconErrorButton.setText("DWT.ICON_ERROR"); | |
133 iconInformationButton = new Button (styleGroup, DWT.RADIO); | |
134 iconInformationButton.setText("DWT.ICON_INFORMATION"); | |
135 iconWarningButton = new Button (styleGroup, DWT.RADIO); | |
136 iconWarningButton.setText("DWT.ICON_WARNING"); | |
137 noIconButton = new Button (styleGroup, DWT.RADIO); | |
138 noIconButton.setText(ControlExample.getResourceString("No_Icon")); | |
139 } | |
140 | |
141 void createColorAndFontGroup () { | |
142 // ToolTip does not need a color and font group. | |
143 } | |
144 | |
145 void createOtherGroup () { | |
146 /* Create the group */ | |
147 otherGroup = new Group (controlGroup, DWT.NONE); | |
148 otherGroup.setLayout (new GridLayout ()); | |
149 otherGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, false, false)); | |
150 otherGroup.setText (ControlExample.getResourceString("Other")); | |
151 | |
152 /* Create the controls */ | |
153 autoHideButton = new Button(otherGroup, DWT.CHECK); | |
154 autoHideButton.setText(ControlExample.getResourceString("AutoHide")); | |
155 showInTrayButton = new Button(otherGroup, DWT.CHECK); | |
156 showInTrayButton.setText(ControlExample.getResourceString("Show_In_Tray")); | |
157 tray = display.getSystemTray(); | |
158 showInTrayButton.setEnabled(tray !is null); | |
159 | |
160 /* Add the listeners */ | |
161 autoHideButton.addSelectionListener (new class() SelectionAdapter { | |
162 public void widgetSelected (SelectionEvent event) { | |
163 setExampleWidgetAutoHide (); | |
164 } | |
165 }); | |
166 showInTrayButton.addSelectionListener (new class() SelectionAdapter { | |
167 public void widgetSelected (SelectionEvent event) { | |
168 showExampleWidgetInTray (); | |
169 } | |
170 }); | |
171 shell.addDisposeListener(new class() DisposeListener { | |
172 public void widgetDisposed(DisposeEvent event) { | |
173 disposeTrayItem(); | |
174 } | |
175 }); | |
176 | |
177 /* Set the default state */ | |
178 autoHideButton.setSelection(true); | |
179 } | |
180 | |
181 void createSizeGroup () { | |
182 // ToolTip does not need a size group. | |
183 } | |
184 | |
185 /** | |
186 * Disposes the "Example" widgets. | |
187 */ | |
188 void disposeExampleWidgets () { | |
189 disposeTrayItem(); | |
190 super.disposeExampleWidgets(); | |
191 } | |
192 | |
193 /** | |
194 * Gets the "Example" widget children. | |
195 */ | |
196 // Tab uses this for many things - widgets would only get set/get, listeners, and dispose. | |
197 Widget[] getExampleWidgets () { | |
198 return [ cast(Widget) toolTip1 ]; | |
199 } | |
200 | |
201 /** | |
202 * Returns a list of set/get API method names (without the set/get prefix) | |
203 * that can be used to set/get values in the example control(s). | |
204 */ | |
205 char[][] getMethodNames() { | |
206 return ["Message", "Text"]; | |
207 } | |
208 | |
209 /** | |
210 * Gets the text for the tab folder item. | |
211 */ | |
212 char[] getTabText () { | |
213 return "ToolTip"; | |
214 } | |
215 | |
216 /** | |
217 * Sets the state of the "Example" widgets. | |
218 */ | |
219 void setExampleWidgetState () { | |
220 showExampleWidgetInTray (); | |
221 setExampleWidgetAutoHide (); | |
222 super.setExampleWidgetState (); | |
223 balloonButton.setSelection ((toolTip1.getStyle () & DWT.BALLOON) !is 0); | |
224 iconErrorButton.setSelection ((toolTip1.getStyle () & DWT.ICON_ERROR) !is 0); | |
225 iconInformationButton.setSelection ((toolTip1.getStyle () & DWT.ICON_INFORMATION) !is 0); | |
226 iconWarningButton.setSelection ((toolTip1.getStyle () & DWT.ICON_WARNING) !is 0); | |
227 noIconButton.setSelection ((toolTip1.getStyle () & (DWT.ICON_ERROR | DWT.ICON_INFORMATION | DWT.ICON_WARNING)) is 0); | |
228 autoHideButton.setSelection(toolTip1.getAutoHide()); | |
229 } | |
230 | |
231 /** | |
232 * Sets the visibility of the "Example" widgets. | |
233 */ | |
234 void setExampleWidgetVisibility () { | |
235 toolTip1.setVisible (visibleButton.getSelection ()); | |
236 } | |
237 | |
238 /** | |
239 * Sets the autoHide state of the "Example" widgets. | |
240 */ | |
241 void setExampleWidgetAutoHide () { | |
242 toolTip1.setAutoHide(autoHideButton.getSelection ()); | |
243 } | |
244 | |
245 void showExampleWidgetInTray () { | |
246 if (showInTrayButton.getSelection ()) { | |
247 createTrayItem(); | |
248 trayItem.setToolTip(toolTip1); | |
249 } else { | |
250 disposeTrayItem(); | |
251 } | |
252 } | |
253 | |
254 void createTrayItem() { | |
255 if (trayItem is null) { | |
256 trayItem = new TrayItem(tray, DWT.NONE); | |
257 trayItem.setImage(instance.images[ControlExample.ciTarget]); | |
258 } | |
259 } | |
260 | |
261 void disposeTrayItem() { | |
262 if (trayItem !is null) { | |
263 trayItem.setToolTip(null); | |
264 trayItem.dispose(); | |
265 trayItem = null; | |
266 } | |
267 } | |
268 } |