Skip to main content
summaryrefslogtreecommitdiffstats
blob: d05d2873b569abf5b2a915439130dd92de183ed2 (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
package org.eclipse.swt.examples.controlexample;

/*
 * Licensed Materials - Property of IBM,
 * WebSphere Studio Workbench
 * (c) Copyright IBM Corp 2000
 */

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

class ToolBarTab extends Tab {

	/* Example widgets and groups that contain them */
	ToolBar imageToolBar, textToolBar;
	Shell dropDownShell;
	List dropDownList;
	Group imageToolBarGroup, textToolBarGroup;
	
	/* Style widgets added to the "Style" group */
	Button flatButton, wrapButton;

	static String [] ListData0 = {resControls.getString("ListData0_0"),
								  resControls.getString("ListData0_1"),
								  resControls.getString("ListData0_2"),
								  resControls.getString("ListData0_3"),
								  resControls.getString("ListData0_4"),
								  resControls.getString("ListData0_5"),
								  resControls.getString("ListData0_6"),
								  resControls.getString("ListData0_7"),
								  resControls.getString("ListData0_8")};

/**
* Create the drop down list widget used by the 
* drop down style tool bar item.
*/
void createDropDownList() {

	/* Don't create more than one list */
	if (dropDownList != null) return;

	/* Create the list */
	Shell shell = tabFolderPage.getShell ();
	dropDownShell = new Shell (shell, SWT.NO_TRIM);
	dropDownList = new List(dropDownShell, SWT.VERTICAL);
	dropDownShell.setLayout (new FillLayout ());
	dropDownList.setItems (ListData0);

	/*
	* Add a list selection listener so that the list is hidden
	* when the user selects an item from the drop down list.
	*/
	dropDownList.addSelectionListener(new SelectionAdapter() {
		public void widgetSelected(SelectionEvent e) {
			disposeDropDownList ();
		}
	});
}
/**
* Creates the "Example" group.
*/
void createExampleGroup () {
	super.createExampleGroup ();
	
	/* Create a group for the image tool bar */
	imageToolBarGroup = new Group (exampleGroup, SWT.NULL);
	imageToolBarGroup.setLayout (new GridLayout ());
	imageToolBarGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
	imageToolBarGroup.setText (resControls.getString("Image_ToolBar"));

	/* Create a group for the text tool bar */
	textToolBarGroup = new Group (exampleGroup, SWT.NULL);
	textToolBarGroup.setLayout (new GridLayout ());
	textToolBarGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
	textToolBarGroup.setText (resControls.getString("Text_ToolBar"));
}
/**
* Creates the "Example" widgets.
*/
void createExampleWidgets () {

	/* Compute the widget style */
	int style = SWT.NONE;
	if (flatButton.getSelection()) style |= SWT.FLAT;
	if (wrapButton.getSelection()) style |= SWT.WRAP;
	if (borderButton.getSelection()) style |= SWT.BORDER;

	/*
	* Create the example widgets.
	*
	* A tool bar must consist of all image tool
	* items or all text tool items but not both.
	*/

	/* Create the image tool bar */
	imageToolBar = new ToolBar (imageToolBarGroup, style);
	ToolItem item = new ToolItem (imageToolBar, SWT.PUSH);
	item.setImage (Images.CLOSED_FOLDER_IMAGE);
	item.setToolTipText(resControls.getString("SWT_PUSH"));
	item = new ToolItem (imageToolBar, SWT.PUSH);
	item.setImage (Images.CLOSED_FOLDER_IMAGE);
	item.setToolTipText (resControls.getString("SWT_PUSH"));
	item = new ToolItem (imageToolBar, SWT.RADIO);
	item.setImage (Images.OPEN_FOLDER_IMAGE);
	item.setToolTipText (resControls.getString("SWT_RADIO"));
	item = new ToolItem (imageToolBar, SWT.RADIO);
	item.setImage (Images.OPEN_FOLDER_IMAGE);
	item.setToolTipText (resControls.getString("SWT_RADIO"));
	item = new ToolItem (imageToolBar, SWT.CHECK);
	item.setImage (Images.TARGET_IMAGE);
	item.setToolTipText (resControls.getString("SWT_CHECK"));
	item = new ToolItem (imageToolBar, SWT.RADIO);
	item.setImage (Images.CLOSED_FOLDER_IMAGE);
	item.setToolTipText (resControls.getString("SWT_RADIO"));
	item = new ToolItem (imageToolBar, SWT.RADIO);
	item.setImage (Images.CLOSED_FOLDER_IMAGE);
	item.setToolTipText (resControls.getString("SWT_RADIO"));
	item = new ToolItem (imageToolBar, SWT.SEPARATOR);
	item.setToolTipText(resControls.getString("SWT_SEPARATOR"));
	item = new ToolItem (imageToolBar, SWT.DROP_DOWN);
	item.setImage (Images.TARGET_IMAGE);
	item.setToolTipText (resControls.getString("SWT_DROP_DOWN"));

	/*
	* Add a selection listener to the drop down tool item
	* so that we can show the list when the drop down area
	* is pressed.
	*/
	item.addSelectionListener (new SelectionAdapter () {
		public void widgetSelected (SelectionEvent event) {
			dropDownToolItemSelected (event);
		}
	});

	/* Create the text tool bar */
	textToolBar = new ToolBar (textToolBarGroup, style);
	item = new ToolItem (textToolBar, SWT.PUSH);
	item.setText (resControls.getString("Push"));
	item.setToolTipText(resControls.getString("SWT_PUSH"));
	item = new ToolItem (textToolBar, SWT.PUSH);
	item.setText (resControls.getString("Push"));
	item.setToolTipText(resControls.getString("SWT_PUSH"));
	item = new ToolItem (textToolBar, SWT.RADIO);
	item.setText (resControls.getString("Radio"));
	item.setToolTipText(resControls.getString("SWT_RADIO"));
	item = new ToolItem (textToolBar, SWT.RADIO);
	item.setText (resControls.getString("Radio"));
	item.setToolTipText(resControls.getString("SWT_RADIO"));
	item = new ToolItem (textToolBar, SWT.CHECK);
	item.setText (resControls.getString("Check"));
	item.setToolTipText(resControls.getString("SWT_CHECK"));
	item = new ToolItem (textToolBar, SWT.RADIO);
	item.setText (resControls.getString("Radio"));
	item.setToolTipText(resControls.getString("SWT_RADIO"));
	item = new ToolItem (textToolBar, SWT.RADIO);
	item.setText (resControls.getString("Radio"));
	item.setToolTipText(resControls.getString("SWT_RADIO"));
	item = new ToolItem (textToolBar, SWT.SEPARATOR);
	item.setToolTipText(resControls.getString("SWT_SEPARATOR"));
	item = new ToolItem (textToolBar, SWT.DROP_DOWN);
	item.setText (resControls.getString("Drop_Down"));
	item.setToolTipText(resControls.getString("SWT_DROP_DOWN"));

	/*
	* Do not add the selection event for this drop down
	* tool item.  Without hooking the event, the drop down
	* widget does nothing special when the drop down area
	* is selected.
	*/
}
/**
* Creates the "Style" group.
*/
void createStyleGroup() {
	super.createStyleGroup();

	/* Create the extra widgets */
	flatButton = new Button (styleGroup, SWT.CHECK);
	flatButton.setText (resControls.getString("SWT_FLAT"));
	wrapButton = new Button (styleGroup, SWT.CHECK);
	wrapButton.setText (resControls.getString("SWT_WRAP"));
	borderButton = new Button (styleGroup, SWT.CHECK);
	borderButton.setText (resControls.getString("SWT_BORDER"));
}
void disposeDropDownList () {
	if (dropDownShell != null) dropDownShell.dispose ();
	dropDownShell = null; dropDownList = null;
}
void disposeExampleWidgets () {
	super.disposeExampleWidgets ();
	disposeDropDownList ();
}
/**
* Handle the drop down tool item selection event.
*
* @param event the selection event
*/
void dropDownToolItemSelected (SelectionEvent event) {

	/*
	* If list was already dropped down then close it.
	* We would do this regardless of where the tool
	* item was selected.
	*/
	createDropDownList ();
	if (dropDownShell.getVisible ()) {
		disposeDropDownList ();
		return;
	}
	
	/**
	* A selection event will be fired when a drop down tool
	* item is selected in the main area and in the drop
	* down arrow.  Examine the event detail to determine
	* where the widget was selected.
	*/		
	if (event.detail == SWT.ARROW) {
		/*
		* The drop down arrow was selected.
		* Position the list below and vertically 
		* alligned with the the drop down tool button.
		*/
		ToolItem item = (ToolItem) event.widget;
		Rectangle toolItemBounds = item.getBounds ();
		Point point1 = imageToolBar.toDisplay (new Point (toolItemBounds.x, toolItemBounds.y));
		dropDownShell.setBounds (point1.x, point1.y + toolItemBounds.height, 100, 100);
		dropDownShell.setVisible (true);
	} else {
		/*
		* Main area of drop down tool item selected.
		* An application would invoke the code was
		* required to perform the action for the tool
		* item.
		*/
	}
}
/**
* Gets the "Example" widget children.
*/
Control [] getExampleWidgets () {
	return new Control [] {imageToolBar, textToolBar};
}
/**
* Gets the text for the tab folder item.
*/
String getTabText () {
	return resControls.getString("ToolBar");
}
/**
* Sets the state of the "Example" widgets.
*/
void setExampleWidgetState () {
	super.setExampleWidgetState ();
	flatButton.setSelection ((imageToolBar.getStyle () & SWT.FLAT) != 0);
	wrapButton.setSelection ((imageToolBar.getStyle () & SWT.WRAP) != 0);
	borderButton.setSelection ((imageToolBar.getStyle () & SWT.BORDER) != 0);
}

}

Back to the top