Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 99bbffba19df8907d7ef318993f711f640953194 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*******************************************************************************
 * Copyright (c) 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.swt.examples.controlexample;


import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.layout.*;

class ToolTipTab extends Tab {

	/* Example widgets and groups that contain them */
	ToolTip toolTip1;
	Group toolTipGroup;
	
	/* Style widgets added to the "Style" group */
	Button balloonButton, iconErrorButton, iconInformationButton, iconWarningButton, noIconButton;
	
	/* Other widgets added to the "Other" group */
	Button autoHideButton, showInTrayButton;
	
	Tray tray;
	TrayItem trayItem;
	
	/**
	 * Creates the Tab within a given instance of ControlExample.
	 */
	ToolTipTab(ControlExample instance) {
		super(instance);
	}
	
	/**
	 * Creates the "Example" group.
	 */
	@Override
	void createExampleGroup () {
		super.createExampleGroup ();
		
		/* Create a group for the tooltip visibility check box */
		toolTipGroup = new Group (exampleGroup, SWT.NONE);
		toolTipGroup.setLayout (new GridLayout ());
		toolTipGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
		toolTipGroup.setText ("ToolTip");
		visibleButton = new Button(toolTipGroup, SWT.CHECK);
		visibleButton.setText(ControlExample.getResourceString("Visible"));
		visibleButton.addSelectionListener (new SelectionAdapter () {
			@Override
			public void widgetSelected (SelectionEvent event) {
				setExampleWidgetVisibility ();
			}
		});
	}
	
	/**
	 * Creates the "Example" widgets.
	 */
	@Override
	void createExampleWidgets () {
		
		/* Compute the widget style */
		int style = getDefaultStyle();
		if (balloonButton.getSelection ()) style |= SWT.BALLOON;
		if (iconErrorButton.getSelection ()) style |= SWT.ICON_ERROR;
		if (iconInformationButton.getSelection ()) style |= SWT.ICON_INFORMATION;
		if (iconWarningButton.getSelection ()) style |= SWT.ICON_WARNING;
		
		/* Create the example widgets */
		toolTip1 = new ToolTip (shell, style);
		toolTip1.setText(ControlExample.getResourceString("ToolTip_Title"));
		toolTip1.setMessage(ControlExample.getResourceString("Example_string"));
	}
	
	/**
	 * Creates the tab folder page.
	 *
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
	 * @return the new page for the tab folder
	 */
	@Override
	Composite createTabFolderPage (TabFolder tabFolder) {
		super.createTabFolderPage (tabFolder);

		/*
		 * Add a resize listener to the tabFolderPage so that
		 * if the user types into the example widget to change
		 * its preferred size, and then resizes the shell, we
		 * recalculate the preferred size correctly.
		 */
		tabFolderPage.addControlListener(new ControlAdapter() {
			@Override
			public void controlResized(ControlEvent e) {
				setExampleWidgetSize ();
			}
		});
		
		return tabFolderPage;
	}

	/**
	 * Creates the "Style" group.
	 */
	@Override
	void createStyleGroup () {
		super.createStyleGroup ();
	
		/* Create the extra widgets */
		balloonButton = new Button (styleGroup, SWT.CHECK);
		balloonButton.setText ("SWT.BALLOON");
		iconErrorButton = new Button (styleGroup, SWT.RADIO);
		iconErrorButton.setText("SWT.ICON_ERROR");
		iconInformationButton = new Button (styleGroup, SWT.RADIO);
		iconInformationButton.setText("SWT.ICON_INFORMATION");
		iconWarningButton = new Button (styleGroup, SWT.RADIO);
		iconWarningButton.setText("SWT.ICON_WARNING");
		noIconButton = new Button (styleGroup, SWT.RADIO);
		noIconButton.setText(ControlExample.getResourceString("No_Icon"));
	}
	
	@Override
	void createColorAndFontGroup () {
		// ToolTip does not need a color and font group.
	}
	
	@Override
	void createOtherGroup () {
		/* Create the group */
		otherGroup = new Group (controlGroup, SWT.NONE);
		otherGroup.setLayout (new GridLayout ());
		otherGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
		otherGroup.setText (ControlExample.getResourceString("Other"));
	
		/* Create the controls */
		autoHideButton = new Button(otherGroup, SWT.CHECK);
		autoHideButton.setText(ControlExample.getResourceString("AutoHide"));
		showInTrayButton = new Button(otherGroup, SWT.CHECK);
		showInTrayButton.setText(ControlExample.getResourceString("Show_In_Tray"));
		tray = display.getSystemTray();
		showInTrayButton.setEnabled(tray != null);

		/* Add the listeners */
		autoHideButton.addSelectionListener (new SelectionAdapter () {
			@Override
			public void widgetSelected (SelectionEvent event) {
				setExampleWidgetAutoHide ();
			}
		});
		showInTrayButton.addSelectionListener (new SelectionAdapter () {
			@Override
			public void widgetSelected (SelectionEvent event) {
				showExampleWidgetInTray ();
			}
		});
		shell.addDisposeListener(new DisposeListener() {
			public void widgetDisposed(DisposeEvent event) {
				disposeTrayItem();
			}
		});

		/* Set the default state */
		autoHideButton.setSelection(true);
	}
	
	@Override
	void createSizeGroup () {
		// ToolTip does not need a size group.
	}
	
	@Override
	void createBackgroundModeGroup () {
		// ToolTip does not need a background mode group.
	}
	
	/**
	 * Disposes the "Example" widgets.
	 */
	@Override
	void disposeExampleWidgets () {
		disposeTrayItem();
		super.disposeExampleWidgets();
	}
	
	/**
	 * Gets the "Example" widget children.
	 */
	@Override
	// Tab uses this for many things - widgets would only get set/get, listeners, and dispose.
	Widget[] getExampleWidgets () {
		return new Widget [] {toolTip1};
	}
	
	/**
	 * Returns a list of set/get API method names (without the set/get prefix)
	 * that can be used to set/get values in the example control(s).
	 */
	@Override
	String[] getMethodNames() {
		return new String[] {"Message", "Text"};
	}

	/**
	 * Gets the short text for the tab folder item.
	 */
	@Override
	String getShortTabText() {
		return "TT";
	}

	/**
	 * Gets the text for the tab folder item.
	 */
	@Override
	String getTabText () {
		return "ToolTip";
	}
	
	/**
	 * Sets the state of the "Example" widgets.
	 */
	@Override
	void setExampleWidgetState () {
		showExampleWidgetInTray ();
		setExampleWidgetAutoHide ();
		super.setExampleWidgetState ();
		balloonButton.setSelection ((toolTip1.getStyle () & SWT.BALLOON) != 0);
		iconErrorButton.setSelection ((toolTip1.getStyle () & SWT.ICON_ERROR) != 0);
		iconInformationButton.setSelection ((toolTip1.getStyle () & SWT.ICON_INFORMATION) != 0);
		iconWarningButton.setSelection ((toolTip1.getStyle () & SWT.ICON_WARNING) != 0);
		noIconButton.setSelection ((toolTip1.getStyle () & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) == 0);
		autoHideButton.setSelection(toolTip1.getAutoHide());
	}

	/**
	 * Sets the visibility of the "Example" widgets.
	 */
	@Override
	void setExampleWidgetVisibility () {
		toolTip1.setVisible (visibleButton.getSelection ());
	}
	
	/**
	 * Sets the autoHide state of the "Example" widgets.
	 */
	void setExampleWidgetAutoHide () {
		toolTip1.setAutoHide(autoHideButton.getSelection ());
	}
	
	void showExampleWidgetInTray () {
		if (showInTrayButton.getSelection ()) {
			createTrayItem();
			trayItem.setToolTip(toolTip1);
		} else {
			disposeTrayItem();
		}
	}

	void createTrayItem() {
		if (trayItem == null) {
			trayItem = new TrayItem(tray, SWT.NONE);
			trayItem.setImage(instance.images[ControlExample.ciTarget]);
		}
	}
	
	void disposeTrayItem() {
		if (trayItem != null) {
			trayItem.setToolTip(null);
			trayItem.dispose();
			trayItem = null;
		}
	}
}

Back to the top