Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 344460 | Differences between
and this patch

Collapse All | Expand All

(-).classpath (+1 lines)
Lines 3-7 Link Here
3
	<classpathentry kind="src" path="src"/>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
4
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
6
	<classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.swt"/>
6
	<classpathentry kind="output" path="bin"/>
7
	<classpathentry kind="output" path="bin"/>
7
</classpath>
8
</classpath>
(-)src/org/eclipse/swt/examples/mirroringTest/AlignableTab.java (+98 lines)
Added Link Here
1
                                                                     
2
                                                                     
3
                                                                     
4
                                             
5
Index: src/org/eclipse/swt/examples/mirroringTest/AlignableTab.java
6
===================================================================
7
RCS file: src/org/eclipse/swt/examples/mirroringTest/AlignableTab.java
8
diff -N src/org/eclipse/swt/examples/mirroringTest/AlignableTab.java
9
--- /dev/null	1 Jan 1970 00:00:00 -0000
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
/**
20
 * <code>AlignableTab</code> is the abstract
21
 * superclass of example controls that can be
22
 * aligned.
23
 */
24
abstract class AlignableTab extends Tab {
25
26
	/* Alignment Controls */
27
	Button leftButton, rightButton, centerButton;
28
29
	/* Alignment Group */
30
	Group alignmentGroup;
31
32
	/**
33
	 * Creates the Tab within a given instance of ControlExample.
34
	 */
35
	AlignableTab(ControlExample instance) {
36
		super(instance);
37
	}
38
39
	/**
40
	 * Creates the "Other" group. 
41
	 */
42
	void createOtherGroup () {
43
		super.createOtherGroup ();
44
		
45
		/* Create the group */
46
		alignmentGroup = new Group (otherGroup, SWT.NONE);
47
		alignmentGroup.setLayout (new GridLayout ());
48
		alignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL |
49
			GridData.VERTICAL_ALIGN_FILL));
50
		alignmentGroup.setText (ControlExample.getResourceString("Alignment"));
51
	
52
		/* Create the controls */
53
		leftButton = new Button (alignmentGroup, SWT.RADIO);
54
		leftButton.setText (ControlExample.getResourceString("Left"));
55
		centerButton = new Button (alignmentGroup, SWT.RADIO);
56
		centerButton.setText(ControlExample.getResourceString("Center"));
57
		rightButton = new Button (alignmentGroup, SWT.RADIO);
58
		rightButton.setText (ControlExample.getResourceString("Right"));
59
	
60
		/* Add the listeners */
61
		SelectionListener selectionListener = new SelectionAdapter () {
62
			public void widgetSelected(SelectionEvent event) {
63
				if (!((Button) event.widget).getSelection ()) return;
64
				setExampleWidgetAlignment ();
65
			}
66
		};
67
		leftButton.addSelectionListener (selectionListener);
68
		centerButton.addSelectionListener (selectionListener);
69
		rightButton.addSelectionListener (selectionListener);
70
	}
71
	
72
	/**
73
	 * Sets the alignment of the "Example" widgets.
74
	 */
75
	abstract void setExampleWidgetAlignment ();
76
	
77
	/**
78
	 * Sets the state of the "Example" widgets.
79
	 */
80
	void setExampleWidgetState () {
81
		super.setExampleWidgetState ();
82
		Widget [] widgets = getExampleWidgets ();
83
		if (widgets.length != 0) {
84
			leftButton.setSelection ((widgets [0].getStyle () & SWT.LEFT) != 0);
85
			centerButton.setSelection ((widgets [0].getStyle () & SWT.CENTER) != 0);
86
			rightButton.setSelection ((widgets [0].getStyle () & SWT.RIGHT) != 0);
87
		}
88
	}
89
}
(-)src/org/eclipse/swt/examples/mirroringTest/BrowserTab.java (+347 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import java.io.BufferedReader;
15
import java.io.IOException;
16
import java.io.InputStream;
17
import java.io.InputStreamReader;
18
19
import org.eclipse.swt.*;
20
import org.eclipse.swt.browser.*;
21
import org.eclipse.swt.events.*;
22
import org.eclipse.swt.layout.*;
23
import org.eclipse.swt.widgets.*;
24
25
class BrowserTab extends Tab {
26
27
	/* Example widgets and groups that contain them */
28
	Browser browser;
29
	Group browserGroup;
30
	
31
	/* Style widgets added to the "Style" group */
32
	Button mozillaButton, webKitButton;
33
	
34
	String errorMessage, lastText, lastUrl;
35
	
36
	/**
37
	 * Creates the Tab within a given instance of ControlExample.
38
	 */
39
	BrowserTab(ControlExample instance) {
40
		super(instance);
41
	}
42
	
43
	void createBackgroundModeGroup () {
44
		// Browser does not need a background mode group.
45
	}
46
	
47
	void createColorAndFontGroup () {
48
		// Browser does not need a color and font group.
49
	}
50
	
51
	/**
52
	 * Creates the "Example" group.
53
	 */
54
	void createExampleGroup () {
55
		super.createExampleGroup ();
56
		
57
		/* Create a group for the browser */
58
		browserGroup = new Group (exampleGroup, SWT.NONE);
59
		browserGroup.setLayout (new GridLayout ());
60
		browserGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
61
		browserGroup.setText ("Browser");
62
	}
63
	
64
	/**
65
	 * Creates the "Example" widgets.
66
	 */
67
	void createExampleWidgets () {
68
		
69
		/* Compute the widget style */
70
		int style = getDefaultStyle();
71
		if (borderButton.getSelection ()) style |= SWT.BORDER;
72
		if (mozillaButton.getSelection ()) style |= SWT.MOZILLA;
73
		if (webKitButton.getSelection ()) style |= SWT.WEBKIT;
74
		
75
		/* Create the example widgets */
76
		try {
77
			browser = new Browser (browserGroup, style);
78
		} catch (SWTError e) { // Probably missing browser
79
			try {
80
				browser = new Browser (browserGroup, style & ~(SWT.MOZILLA | SWT.WEBKIT));
81
			} catch (SWTError e2) { // Unsupported platform
82
				errorMessage = e.getMessage();
83
				return;
84
			}
85
			MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
86
			String resourceString = (style & SWT.MOZILLA) != 0 ? "MozillaNotFound" : "WebKitNotFound";
87
			dialog.setMessage(ControlExample.getResourceString(resourceString, new String [] {e.getMessage()}));
88
			dialog.open();
89
		}
90
91
		if (lastUrl != null) {
92
			browser.setUrl(lastUrl);
93
		} else if (lastText != null) {
94
			browser.setText(lastText);
95
		} else {
96
	        InputStream htmlStream= ControlExample.class.getResourceAsStream("browser-content.html");
97
			BufferedReader br= new BufferedReader(new InputStreamReader(htmlStream));
98
			StringBuffer sb= new StringBuffer(300);
99
			try {
100
				int read= 0;
101
				while ((read= br.read()) != -1)
102
					sb.append((char) read);
103
			} catch (IOException e) {
104
				log(e.getMessage());
105
			} finally {
106
				try {
107
					br.close();
108
				} catch (IOException e) {
109
					log(e.getMessage());
110
				}
111
			}
112
			String text= sb.toString();
113
			browser.setText(text);
114
		}
115
		lastText = lastUrl = null;
116
	}
117
	
118
	/**
119
	 * Creates the "Other" group.  This is typically
120
	 * a child of the "Control" group.
121
	 */
122
	void createOtherGroup () {
123
		super.createOtherGroup ();
124
		backgroundImageButton.dispose ();
125
	}
126
	
127
	/**
128
	 * Creates the "Size" group.  The "Size" group contains
129
	 * controls that allow the user to change the size of
130
	 * the example widgets.
131
	 */
132
	void createSizeGroup () {
133
		super.createSizeGroup ();
134
		
135
		/* Set the default state for Browser to fill horizontally & vertically. */
136
		fillHButton.setSelection (true);
137
		fillVButton.setSelection (true);
138
	}
139
140
	/**
141
	 * Creates the "Style" group.
142
	 */
143
	void createStyleGroup () {
144
		super.createStyleGroup ();
145
	
146
		/* Create the extra widgets */
147
		mozillaButton = new Button (styleGroup, SWT.CHECK);
148
		mozillaButton.setText ("SWT.MOZILLA");
149
		mozillaButton.addListener(SWT.Selection, new Listener() {
150
			public void handleEvent(Event event) {
151
				webKitButton.setSelection(false);
152
			}
153
		});
154
		webKitButton = new Button (styleGroup, SWT.CHECK);
155
		webKitButton.setText ("SWT.WEBKIT");
156
		webKitButton.addListener(SWT.Selection, new Listener() {
157
			public void handleEvent(Event event) {
158
				mozillaButton.setSelection(false);
159
			}
160
		});
161
		borderButton = new Button (styleGroup, SWT.CHECK);
162
		borderButton.setText ("SWT.BORDER");
163
	}
164
	
165
	/**
166
	 * Creates the tab folder page.
167
	 *
168
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
169
	 * @return the new page for the tab folder
170
	 */
171
	Composite createTabFolderPage (final TabFolder tabFolder) {
172
		super.createTabFolderPage (tabFolder);
173
174
		/*
175
		 * Add a resize listener to the tabFolderPage so that
176
		 * if the user types into the example widget to change
177
		 * its preferred size, and then resizes the shell, we
178
		 * recalculate the preferred size correctly.
179
		 */
180
		tabFolderPage.addControlListener(new ControlAdapter() {
181
			public void controlResized(ControlEvent e) {
182
				setExampleWidgetSize ();
183
			}
184
		});
185
		
186
		/*
187
		 * Add a selection listener to the tabFolder to bring up a
188
		 * dialog if this platform does not support the Browser.
189
		 */
190
		tabFolder.addSelectionListener(new SelectionAdapter() {
191
			public void widgetSelected(SelectionEvent e) {
192
				if (errorMessage != null && tabFolder.getSelection()[0].getText().equals(getTabText())) {
193
					MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
194
					dialog.setMessage(ControlExample.getResourceString("BrowserNotFound", new String [] {errorMessage}));
195
					dialog.open();
196
				}
197
			}
198
		});
199
		
200
		return tabFolderPage;
201
	}
202
203
	/**
204
	 * Disposes the "Example" widgets.
205
	 */
206
	void disposeExampleWidgets () {
207
		/* store the state of the Browser if applicable */
208
		if (browser != null) {
209
			String url = browser.getUrl();
210
			if (url.length() > 0 && !url.equals("about:blank")) { //$NON-NLS-1$
211
				lastUrl = url;
212
			} else {
213
				String text = browser.getText();
214
				if (text.length() > 0) {
215
					lastText = text;
216
				}
217
			}
218
		}
219
		super.disposeExampleWidgets();	
220
	}
221
222
	public static String getContents(InputStream in) throws IOException {
223
		BufferedReader br= new BufferedReader(new InputStreamReader(in));
224
		
225
		StringBuffer sb= new StringBuffer(300);
226
		try {
227
			int read= 0;
228
			while ((read= br.read()) != -1)
229
				sb.append((char) read);
230
		} finally {
231
			br.close();
232
		}
233
		return sb.toString();
234
	}
235
236
	/**
237
	 * Gets the list of custom event names.
238
	 * 
239
	 * @return an array containing custom event names
240
	 */
241
	String [] getCustomEventNames () {
242
		return new String [] {"CloseWindowListener", "LocationListener", "OpenWindowListener",
243
				"ProgressListener", "StatusTextListener", "TitleListener", "VisibilityWindowListener"};
244
	}
245
	
246
	/**
247
	 * Gets the "Example" widget children.
248
	 */
249
	Widget [] getExampleWidgets () {
250
		if (browser != null) return new Widget [] {browser};
251
		return super.getExampleWidgets();
252
	}
253
254
	/**
255
	 * Returns a list of set/get API method names (without the set/get prefix)
256
	 * that can be used to set/get values in the example control(s).
257
	 */
258
	String[] getMethodNames() {
259
		return new String[] {"Text", "Url", "ToolTipText"};
260
	}
261
262
	/**
263
	 * Gets the text for the tab folder item.
264
	 */
265
	String getTabText () {
266
		return "Browser";
267
	}
268
	
269
	/**
270
	 * Hooks the custom listener specified by eventName.
271
	 */
272
	void hookCustomListener (final String eventName) {
273
		if (browser == null) return;
274
		if (eventName == "CloseWindowListener") {
275
			browser.addCloseWindowListener (new CloseWindowListener () {
276
				public void close(WindowEvent event) {
277
					log (eventName, event);
278
				}
279
			});
280
		}
281
		if (eventName == "LocationListener") {
282
			browser.addLocationListener (new LocationListener () {
283
				public void changed(LocationEvent event) {
284
					log (eventName + ".changed", event);
285
				}
286
				public void changing(LocationEvent event) {
287
					log (eventName + ".changing", event);
288
				}
289
			});
290
		}
291
		if (eventName == "OpenWindowListener") {
292
			browser.addOpenWindowListener (new OpenWindowListener () {
293
				public void open(WindowEvent event) {
294
					log (eventName, event);
295
				}
296
			});
297
		}
298
		if (eventName == "ProgressListener") {
299
			browser.addProgressListener (new ProgressListener () {
300
				public void changed(ProgressEvent event) {
301
					log (eventName + ".changed", event);
302
				}
303
				public void completed(ProgressEvent event) {
304
					log (eventName + ".completed", event);
305
				}
306
			});
307
		}
308
		if (eventName == "StatusTextListener") {
309
			browser.addStatusTextListener (new StatusTextListener () {
310
				public void changed(StatusTextEvent event) {
311
					log (eventName, event);
312
				}
313
			});
314
		}
315
		if (eventName == "TitleListener") {
316
			browser.addTitleListener (new TitleListener () {
317
				public void changed(TitleEvent event) {
318
					log (eventName, event);
319
				}
320
			});
321
		}
322
		if (eventName == "VisibilityWindowListener") {
323
			browser.addVisibilityWindowListener (new VisibilityWindowListener () {
324
				public void hide(WindowEvent event) {
325
					log (eventName + ".hide", event);
326
				}
327
				public void show(WindowEvent event) {
328
					log (eventName + ".show", event);
329
				}
330
			});
331
		}
332
	}
333
334
	boolean rtlSupport() {
335
		return false;
336
	}
337
	
338
	/**
339
	 * Sets the state of the "Example" widgets.
340
	 */
341
	void setExampleWidgetState () {
342
		super.setExampleWidgetState ();
343
		mozillaButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.MOZILLA) != 0);
344
		webKitButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.WEBKIT) != 0);
345
		borderButton.setSelection (browser == null ? false : (browser.getStyle () & SWT.BORDER) != 0);
346
	}
347
}
(-)src/org/eclipse/swt/examples/mirroringTest/ButtonTab.java (+245 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
/**
20
 * <code>ButtonTab</code> is the class that
21
 * demonstrates SWT buttons.
22
 */
23
class ButtonTab extends AlignableTab {
24
25
	/* Example widgets and groups that contain them */
26
	Button button1, button2, button3, button4, button5, button6, button7, button8, button9;
27
	Group textButtonGroup, imageButtonGroup, imagetextButtonGroup;
28
29
	/* Alignment widgets added to the "Control" group */
30
	Button upButton, downButton;
31
32
	/* Style widgets added to the "Style" group */
33
	Button pushButton, checkButton, radioButton, toggleButton, arrowButton, flatButton, wrapButton;
34
	
35
	/**
36
	 * Creates the Tab within a given instance of ControlExample.
37
	 */
38
	ButtonTab(ControlExample instance) {
39
		super(instance);
40
	}
41
	
42
	/**
43
	 * Creates the "Control" group. 
44
	 */
45
	void createControlGroup () {
46
		super.createControlGroup ();
47
	
48
		/* Create the controls */
49
		upButton = new Button (alignmentGroup, SWT.RADIO);
50
		upButton.setText (ControlExample.getResourceString("Up"));
51
		downButton = new Button (alignmentGroup, SWT.RADIO);
52
		downButton.setText (ControlExample.getResourceString("Down"));
53
	
54
		/* Add the listeners */
55
		SelectionListener selectionListener = new SelectionAdapter() {
56
			public void widgetSelected(SelectionEvent event) {
57
				if (!((Button) event.widget).getSelection()) return;
58
				setExampleWidgetAlignment ();
59
			}
60
		};
61
		upButton.addSelectionListener(selectionListener);
62
		downButton.addSelectionListener(selectionListener);
63
	}
64
	
65
	/**
66
	 * Creates the "Example" group.
67
	 */
68
	void createExampleGroup () {
69
		super.createExampleGroup ();
70
		
71
		/* Create a group for text buttons */
72
		textButtonGroup = new Group(exampleGroup, SWT.NONE);
73
		GridLayout gridLayout = new GridLayout ();
74
		textButtonGroup.setLayout(gridLayout);
75
		gridLayout.numColumns = 3;
76
		textButtonGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
77
		textButtonGroup.setText (ControlExample.getResourceString("Text_Buttons"));
78
	
79
		/* Create a group for the image buttons */
80
		imageButtonGroup = new Group(exampleGroup, SWT.NONE);
81
		gridLayout = new GridLayout();
82
		imageButtonGroup.setLayout(gridLayout);
83
		gridLayout.numColumns = 3;
84
		imageButtonGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
85
		imageButtonGroup.setText (ControlExample.getResourceString("Image_Buttons"));
86
87
		/* Create a group for the image and text buttons */
88
		imagetextButtonGroup = new Group(exampleGroup, SWT.NONE);
89
		gridLayout = new GridLayout();
90
		imagetextButtonGroup.setLayout(gridLayout);
91
		gridLayout.numColumns = 3;
92
		imagetextButtonGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
93
		imagetextButtonGroup.setText (ControlExample.getResourceString("Image_Text_Buttons"));
94
	}
95
	
96
	/**
97
	 * Creates the "Example" widgets.
98
	 */
99
	void createExampleWidgets () {
100
	
101
		/* Compute the widget style */
102
		int style = getDefaultStyle();
103
		if (pushButton.getSelection()) style |= SWT.PUSH;
104
		if (checkButton.getSelection()) style |= SWT.CHECK;
105
		if (radioButton.getSelection()) style |= SWT.RADIO;
106
		if (toggleButton.getSelection()) style |= SWT.TOGGLE;
107
		if (flatButton.getSelection()) style |= SWT.FLAT;
108
		if (wrapButton.getSelection()) style |= SWT.WRAP;
109
		if (borderButton.getSelection()) style |= SWT.BORDER;
110
		if (leftButton.getSelection()) style |= SWT.LEFT;
111
		if (rightButton.getSelection()) style |= SWT.RIGHT;
112
		if (arrowButton.getSelection()) {
113
			style |= SWT.ARROW; 
114
			if (upButton.getSelection()) style |= SWT.UP;
115
			if (downButton.getSelection()) style |= SWT.DOWN;
116
		} else {
117
			if (centerButton.getSelection()) style |= SWT.CENTER;			
118
		}
119
	
120
		/* Create the example widgets */
121
		button1 = new Button(textButtonGroup, style);
122
		button1.setText(ControlExample.getResourceString("One..."));
123
		button2 = new Button(textButtonGroup, style);
124
		button2.setText(ControlExample.getResourceString("Two..."));
125
		button3 = new Button(textButtonGroup, style);
126
		if (wrapButton.getSelection ()) {
127
			button3.setText (ControlExample.getResourceString("Wrap_Text..."));
128
		} else {
129
			button3.setText (ControlExample.getResourceString("Three..."));
130
		}
131
		button4 = new Button(imageButtonGroup, style);
132
		button4.setImage(instance.images[ControlExample.ciClosedFolder]);
133
		button5 = new Button(imageButtonGroup, style);
134
		button5.setImage(instance.images[ControlExample.ciOpenFolder]);
135
		button6 = new Button(imageButtonGroup, style);
136
		button6.setImage(instance.images[ControlExample.ciTarget]);
137
		button7 = new Button(imagetextButtonGroup, style);
138
		button7.setText(ControlExample.getResourceString("One..."));
139
		button7.setImage(instance.images[ControlExample.ciClosedFolder]);
140
		button8 = new Button(imagetextButtonGroup, style);
141
		button8.setText(ControlExample.getResourceString("Two..."));
142
		button8.setImage(instance.images[ControlExample.ciOpenFolder]);
143
		button9 = new Button(imagetextButtonGroup, style);
144
		if (wrapButton.getSelection ()) {
145
			button9.setText (ControlExample.getResourceString("Wrap_Text..."));
146
		} else {
147
			button9.setText (ControlExample.getResourceString("Three..."));
148
		}
149
		button9.setImage(instance.images[ControlExample.ciTarget]);
150
	}
151
	
152
	/**
153
	 * Creates the "Style" group.
154
	 */
155
	void createStyleGroup() {
156
		super.createStyleGroup ();
157
	
158
		/* Create the extra widgets */
159
		pushButton = new Button (styleGroup, SWT.RADIO);
160
		pushButton.setText("SWT.PUSH");
161
		checkButton = new Button (styleGroup, SWT.RADIO);
162
		checkButton.setText ("SWT.CHECK");
163
		radioButton = new Button (styleGroup, SWT.RADIO);
164
		radioButton.setText ("SWT.RADIO");
165
		toggleButton = new Button (styleGroup, SWT.RADIO);
166
		toggleButton.setText ("SWT.TOGGLE");
167
		arrowButton = new Button (styleGroup, SWT.RADIO);
168
		arrowButton.setText ("SWT.ARROW");
169
		flatButton = new Button (styleGroup, SWT.CHECK);
170
		flatButton.setText ("SWT.FLAT");
171
		wrapButton = new Button (styleGroup, SWT.CHECK);
172
		wrapButton.setText ("SWT.WRAP");
173
		borderButton = new Button (styleGroup, SWT.CHECK);
174
		borderButton.setText ("SWT.BORDER");
175
	}
176
	
177
	/**
178
	 * Gets the "Example" widget children.
179
	 */
180
	Widget [] getExampleWidgets () {
181
		return new Widget [] {button1, button2, button3, button4, button5, button6, button7, button8, button9};
182
	}
183
	
184
	/**
185
	 * Returns a list of set/get API method names (without the set/get prefix)
186
	 * that can be used to set/get values in the example control(s).
187
	 */
188
	String[] getMethodNames() {
189
		return new String[] {"Grayed", "Selection", "Text", "ToolTipText"};
190
	}
191
192
	/**
193
	 * Gets the text for the tab folder item.
194
	 */
195
	String getTabText () {
196
		return "Button";
197
	}
198
	
199
	/**
200
	 * Sets the alignment of the "Example" widgets.
201
	 */
202
	void setExampleWidgetAlignment () {
203
		int alignment = 0;
204
		if (leftButton.getSelection ()) alignment = SWT.LEFT;
205
		if (centerButton.getSelection ()) alignment = SWT.CENTER;
206
		if (rightButton.getSelection ()) alignment = SWT.RIGHT;
207
		if (upButton.getSelection ()) alignment = SWT.UP;
208
		if (downButton.getSelection ()) alignment = SWT.DOWN;
209
		button1.setAlignment (alignment);
210
		button2.setAlignment (alignment);
211
		button3.setAlignment (alignment);
212
		button4.setAlignment (alignment);
213
		button5.setAlignment (alignment);
214
		button6.setAlignment (alignment);
215
		button7.setAlignment (alignment);
216
		button8.setAlignment (alignment);
217
		button9.setAlignment (alignment);
218
	}
219
	
220
	/**
221
	 * Sets the state of the "Example" widgets.
222
	 */
223
	void setExampleWidgetState () {
224
		super.setExampleWidgetState ();
225
		if (arrowButton.getSelection ()) {
226
			upButton.setEnabled (true);
227
			centerButton.setEnabled (false);
228
			downButton.setEnabled (true);
229
		} else {
230
			upButton.setEnabled (false);
231
			centerButton.setEnabled (true);
232
			downButton.setEnabled (false);
233
		}
234
		upButton.setSelection ((button1.getStyle () & SWT.UP) != 0);
235
		downButton.setSelection ((button1.getStyle () & SWT.DOWN) != 0);
236
		pushButton.setSelection ((button1.getStyle () & SWT.PUSH) != 0);
237
		checkButton.setSelection ((button1.getStyle () & SWT.CHECK) != 0);
238
		radioButton.setSelection ((button1.getStyle () & SWT.RADIO) != 0);
239
		toggleButton.setSelection ((button1.getStyle () & SWT.TOGGLE) != 0);
240
		arrowButton.setSelection ((button1.getStyle () & SWT.ARROW) != 0);
241
		flatButton.setSelection ((button1.getStyle () & SWT.FLAT) != 0);
242
		wrapButton.setSelection ((button1.getStyle () & SWT.WRAP) != 0);
243
		borderButton.setSelection ((button1.getStyle () & SWT.BORDER) != 0);
244
	}
245
}
(-)src/org/eclipse/swt/examples/mirroringTest/CComboTab.java (+123 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.custom.*;
17
import org.eclipse.swt.layout.*;
18
19
class CComboTab extends Tab {
20
21
	/* Example widgets and groups that contain them */
22
	CCombo combo1;
23
	Group comboGroup;
24
	
25
	/* Style widgets added to the "Style" group */
26
	Button flatButton, readOnlyButton;
27
	
28
	static String [] ListData = {ControlExample.getResourceString("ListData1_0"),
29
								 ControlExample.getResourceString("ListData1_1"),
30
								 ControlExample.getResourceString("ListData1_2"),
31
								 ControlExample.getResourceString("ListData1_3"),
32
								 ControlExample.getResourceString("ListData1_4"),
33
								 ControlExample.getResourceString("ListData1_5"),
34
								 ControlExample.getResourceString("ListData1_6"),
35
								 ControlExample.getResourceString("ListData1_7"),
36
								 ControlExample.getResourceString("ListData1_8")};
37
38
	/**
39
	 * Creates the Tab within a given instance of ControlExample.
40
	 */
41
	CComboTab(ControlExample instance) {
42
		super(instance);
43
	}
44
	
45
	/**
46
	 * Creates the "Example" group.
47
	 */
48
	void createExampleGroup () {
49
		super.createExampleGroup ();
50
		
51
		/* Create a group for the combo box */
52
		comboGroup = new Group (exampleGroup, SWT.NONE);
53
		comboGroup.setLayout (new GridLayout ());
54
		comboGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
55
		comboGroup.setText (ControlExample.getResourceString("Custom_Combo"));
56
	}
57
	
58
	/**
59
	 * Creates the "Example" widgets.
60
	 */
61
	void createExampleWidgets () {
62
		
63
		/* Compute the widget style */
64
		int style = getDefaultStyle();
65
		if (flatButton.getSelection ()) style |= SWT.FLAT;
66
		if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
67
		if (borderButton.getSelection ()) style |= SWT.BORDER;
68
		
69
		/* Create the example widgets */
70
		combo1 = new CCombo (comboGroup, style);
71
		combo1.setItems (ListData);
72
		if (ListData.length >= 3) {
73
			combo1.setText(ListData [2]);
74
		}
75
	}
76
	
77
	/**
78
	 * Creates the "Style" group.
79
	 */
80
	void createStyleGroup () {
81
		super.createStyleGroup ();
82
	
83
		/* Create the extra widgets */
84
		readOnlyButton = new Button (styleGroup, SWT.CHECK);
85
		readOnlyButton.setText ("SWT.READ_ONLY");
86
		borderButton = new Button (styleGroup, SWT.CHECK);
87
		borderButton.setText ("SWT.BORDER");
88
		flatButton = new Button (styleGroup, SWT.CHECK);
89
		flatButton.setText ("SWT.FLAT");
90
	}
91
	
92
	/**
93
	 * Gets the "Example" widget children.
94
	 */
95
	Widget [] getExampleWidgets () {
96
		return new Widget [] {combo1};
97
	}
98
	
99
	/**
100
	 * Returns a list of set/get API method names (without the set/get prefix)
101
	 * that can be used to set/get values in the example control(s).
102
	 */
103
	String[] getMethodNames() {
104
		return new String[] {"Editable", "Items", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"};
105
	}
106
107
	/**
108
	 * Gets the text for the tab folder item.
109
	 */
110
	String getTabText () {
111
		return "CCombo";
112
	}
113
	
114
	/**
115
	 * Sets the state of the "Example" widgets.
116
	 */
117
	void setExampleWidgetState () {
118
		super.setExampleWidgetState ();
119
		flatButton.setSelection ((combo1.getStyle () & SWT.FLAT) != 0);
120
		readOnlyButton.setSelection ((combo1.getStyle () & SWT.READ_ONLY) != 0);
121
		borderButton.setSelection ((combo1.getStyle () & SWT.BORDER) != 0);
122
	}
123
}
(-)src/org/eclipse/swt/examples/mirroringTest/CLabelTab.java (+135 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.custom.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.widgets.*;
18
19
class CLabelTab extends AlignableTab {
20
	/* Example widgets and groups that contain them */
21
	CLabel label1, label2, label3;
22
	Group textLabelGroup;
23
24
	/* Style widgets added to the "Style" group */
25
	Button shadowInButton, shadowOutButton, shadowNoneButton;
26
	
27
	/**
28
	 * Creates the Tab within a given instance of ControlExample.
29
	 */
30
	CLabelTab(ControlExample instance) {
31
		super(instance);
32
	}
33
	
34
	/**
35
	 * Creates the "Example" group.
36
	 */
37
	void createExampleGroup () {
38
		super.createExampleGroup ();
39
		
40
		/* Create a group for the text labels */
41
		textLabelGroup = new Group(exampleGroup, SWT.NONE);
42
		GridLayout gridLayout = new GridLayout ();
43
		textLabelGroup.setLayout (gridLayout);
44
		gridLayout.numColumns = 3;
45
		textLabelGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
46
		textLabelGroup.setText (ControlExample.getResourceString("Custom_Labels"));
47
	}
48
	
49
	/**
50
	 * Creates the "Example" widgets.
51
	 */
52
	void createExampleWidgets () {
53
		
54
		/* Compute the widget style */
55
		int style = getDefaultStyle();
56
		if (shadowInButton.getSelection ()) style |= SWT.SHADOW_IN;
57
		if (shadowNoneButton.getSelection ()) style |= SWT.SHADOW_NONE;
58
		if (shadowOutButton.getSelection ()) style |= SWT.SHADOW_OUT;
59
		if (leftButton.getSelection ()) style |= SWT.LEFT;
60
		if (centerButton.getSelection ()) style |= SWT.CENTER;
61
		if (rightButton.getSelection ()) style |= SWT.RIGHT;
62
	
63
		/* Create the example widgets */
64
		label1 = new CLabel (textLabelGroup, style);
65
		label1.setText(ControlExample.getResourceString("One"));
66
		label1.setImage (instance.images[ControlExample.ciClosedFolder]);
67
		label2 = new CLabel (textLabelGroup, style);
68
		label2.setImage (instance.images[ControlExample.ciTarget]);
69
		label3 = new CLabel (textLabelGroup, style);
70
		label3.setText(ControlExample.getResourceString("Example_string") + "\n" + ControlExample.getResourceString("One_Two_Three"));
71
	}
72
	
73
	/**
74
	 * Creates the "Style" group.
75
	 */
76
	void createStyleGroup() {
77
		super.createStyleGroup ();
78
		
79
		/* Create the extra widgets */
80
		shadowNoneButton = new Button (styleGroup, SWT.RADIO);
81
		shadowNoneButton.setText ("SWT.SHADOW_NONE");
82
		shadowInButton = new Button (styleGroup, SWT.RADIO);
83
		shadowInButton.setText ("SWT.SHADOW_IN");
84
		shadowOutButton = new Button (styleGroup, SWT.RADIO);
85
		shadowOutButton.setText ("SWT.SHADOW_OUT");
86
	}
87
	
88
	/**
89
	 * Gets the "Example" widget children.
90
	 */
91
	Widget [] getExampleWidgets () {
92
		return new Widget [] {label1, label2, label3};
93
	}
94
	
95
	/**
96
	 * Returns a list of set/get API method names (without the set/get prefix)
97
	 * that can be used to set/get values in the example control(s).
98
	 */
99
	String[] getMethodNames() {
100
		return new String[] {"BottomMargin", "LeftMargin", "RightMargin", "Text", "ToolTipText", "TopMargin"};
101
	}
102
103
	/**
104
	 * Gets the text for the tab folder item.
105
	 */
106
	String getTabText () {
107
		return "CLabel";
108
	}
109
	
110
	/**
111
	 * Sets the alignment of the "Example" widgets.
112
	 */
113
	void setExampleWidgetAlignment () {
114
		int alignment = 0;
115
		if (leftButton.getSelection ()) alignment = SWT.LEFT;
116
		if (centerButton.getSelection ()) alignment = SWT.CENTER;
117
		if (rightButton.getSelection ()) alignment = SWT.RIGHT;
118
		label1.setAlignment (alignment);
119
		label2.setAlignment (alignment);
120
		label3.setAlignment (alignment);
121
	}
122
	
123
	/**
124
	 * Sets the state of the "Example" widgets.
125
	 */
126
	void setExampleWidgetState () {
127
		super.setExampleWidgetState ();
128
		leftButton.setSelection ((label1.getStyle () & SWT.LEFT) != 0);
129
		centerButton.setSelection ((label1.getStyle () & SWT.CENTER) != 0);
130
		rightButton.setSelection ((label1.getStyle () & SWT.RIGHT) != 0);
131
		shadowInButton.setSelection ((label1.getStyle () & SWT.SHADOW_IN) != 0);
132
		shadowOutButton.setSelection ((label1.getStyle () & SWT.SHADOW_OUT) != 0);
133
		shadowNoneButton.setSelection ((label1.getStyle () & (SWT.SHADOW_IN | SWT.SHADOW_OUT)) == 0);
134
	}
135
}
(-)src/org/eclipse/swt/examples/mirroringTest/CTabFolderTab.java (+446 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.custom.*;
16
import org.eclipse.swt.events.*;
17
import org.eclipse.swt.layout.*;
18
import org.eclipse.swt.graphics.*;
19
import org.eclipse.swt.widgets.*;
20
21
class CTabFolderTab extends Tab {
22
	int lastSelectedTab = 0;
23
	
24
	/* Example widgets and groups that contain them */
25
	CTabFolder tabFolder1;
26
	Group tabFolderGroup, itemGroup;
27
	
28
	/* Style widgets added to the "Style" group */
29
	Button topButton, bottomButton, flatButton, closeButton;
30
31
	static String [] CTabItems1 = {ControlExample.getResourceString("CTabItem1_0"),
32
								  ControlExample.getResourceString("CTabItem1_1"),
33
								  ControlExample.getResourceString("CTabItem1_2")};
34
35
	/* Controls and resources added to the "Fonts" group */
36
	static final int SELECTION_FOREGROUND_COLOR = 3;
37
	static final int SELECTION_BACKGROUND_COLOR = 4;
38
	static final int ITEM_FONT = 5;
39
	Color selectionForegroundColor, selectionBackgroundColor;
40
	Font itemFont;
41
	
42
	/* Other widgets added to the "Other" group */
43
	Button simpleTabButton, singleTabButton, imageButton, showMinButton, showMaxButton, unselectedCloseButton, unselectedImageButton;
44
45
	/**
46
	 * Creates the Tab within a given instance of ControlExample.
47
	 */
48
	CTabFolderTab(ControlExample instance) {
49
		super(instance);
50
	}
51
	
52
	/**
53
	 * Creates the "Colors and Fonts" group.
54
	 */
55
	void createColorAndFontGroup () {
56
		super.createColorAndFontGroup();
57
		
58
		TableItem item = new TableItem(colorAndFontTable, SWT.None);
59
		item.setText(ControlExample.getResourceString ("Selection_Foreground_Color"));
60
		item = new TableItem(colorAndFontTable, SWT.None);
61
		item.setText(ControlExample.getResourceString ("Selection_Background_Color"));
62
		item = new TableItem(colorAndFontTable, SWT.None);
63
		item.setText(ControlExample.getResourceString ("Item_Font"));
64
65
		shell.addDisposeListener(new DisposeListener() {
66
			public void widgetDisposed(DisposeEvent event) {
67
				if (selectionBackgroundColor != null) selectionBackgroundColor.dispose();
68
				if (selectionForegroundColor != null) selectionForegroundColor.dispose();
69
				if (itemFont != null) itemFont.dispose();
70
				selectionBackgroundColor = null;
71
				selectionForegroundColor = null;			
72
				itemFont = null;
73
			}
74
		});
75
	}
76
77
	void changeFontOrColor(int index) {
78
		switch (index) {
79
			case SELECTION_FOREGROUND_COLOR: {
80
				Color oldColor = selectionForegroundColor;
81
				if (oldColor == null) oldColor = tabFolder1.getSelectionForeground();
82
				colorDialog.setRGB(oldColor.getRGB());
83
				RGB rgb = colorDialog.open();
84
				if (rgb == null) return;
85
				oldColor = selectionForegroundColor;
86
				selectionForegroundColor = new Color (display, rgb);
87
				setSelectionForeground ();
88
				if (oldColor != null) oldColor.dispose ();
89
			}
90
			break;
91
			case SELECTION_BACKGROUND_COLOR: {
92
				Color oldColor = selectionBackgroundColor;
93
				if (oldColor == null) oldColor = tabFolder1.getSelectionBackground();
94
				colorDialog.setRGB(oldColor.getRGB());
95
				RGB rgb = colorDialog.open();
96
				if (rgb == null) return;
97
				oldColor = selectionBackgroundColor;
98
				selectionBackgroundColor = new Color (display, rgb);
99
				setSelectionBackground ();
100
				if (oldColor != null) oldColor.dispose ();
101
			}
102
			break;
103
			case ITEM_FONT: {
104
				Font oldFont = itemFont;
105
				if (oldFont == null) oldFont = tabFolder1.getItem (0).getFont ();
106
				fontDialog.setFontList(oldFont.getFontData());
107
				FontData fontData = fontDialog.open ();
108
				if (fontData == null) return;
109
				oldFont = itemFont;
110
				itemFont = new Font (display, fontData);
111
				setItemFont ();
112
				setExampleWidgetSize ();
113
				if (oldFont != null) oldFont.dispose ();
114
			}
115
			break;
116
			default:
117
				super.changeFontOrColor(index);
118
		}
119
	}
120
121
	/**
122
	 * Creates the "Other" group.
123
	 */
124
	void createOtherGroup () {
125
		super.createOtherGroup ();
126
	
127
		/* Create display controls specific to this example */
128
		simpleTabButton = new Button (otherGroup, SWT.CHECK);
129
		simpleTabButton.setText (ControlExample.getResourceString("Set_Simple_Tabs"));
130
		simpleTabButton.setSelection(true);
131
		simpleTabButton.addSelectionListener (new SelectionAdapter () {
132
			public void widgetSelected (SelectionEvent event) {
133
				setSimpleTabs();
134
			}
135
		});
136
				
137
		singleTabButton = new Button (otherGroup, SWT.CHECK);
138
		singleTabButton.setText (ControlExample.getResourceString("Set_Single_Tabs"));
139
		singleTabButton.setSelection(false);
140
		singleTabButton.addSelectionListener (new SelectionAdapter () {
141
			public void widgetSelected (SelectionEvent event) {
142
				setSingleTabs();
143
			}
144
		});
145
		
146
		showMinButton = new Button (otherGroup, SWT.CHECK);
147
		showMinButton.setText (ControlExample.getResourceString("Set_Min_Visible"));
148
		showMinButton.setSelection(false);
149
		showMinButton.addSelectionListener (new SelectionAdapter () {
150
			public void widgetSelected (SelectionEvent event) {
151
				setMinimizeVisible();
152
			}
153
		});
154
		
155
		showMaxButton = new Button (otherGroup, SWT.CHECK);
156
		showMaxButton.setText (ControlExample.getResourceString("Set_Max_Visible"));
157
		showMaxButton.setSelection(false);
158
		showMaxButton.addSelectionListener (new SelectionAdapter () {
159
			public void widgetSelected (SelectionEvent event) {
160
				setMaximizeVisible();
161
			}
162
		});
163
		
164
		imageButton = new Button (otherGroup, SWT.CHECK);
165
		imageButton.setText (ControlExample.getResourceString("Set_Image"));
166
		imageButton.addSelectionListener (new SelectionAdapter () {
167
			public void widgetSelected (SelectionEvent event) {
168
				setImages();
169
			}
170
		});
171
		
172
		unselectedImageButton = new Button (otherGroup, SWT.CHECK);
173
		unselectedImageButton.setText (ControlExample.getResourceString("Set_Unselected_Image_Visible"));
174
		unselectedImageButton.setSelection(true);
175
		unselectedImageButton.addSelectionListener (new SelectionAdapter () {
176
			public void widgetSelected (SelectionEvent event) {
177
				setUnselectedImageVisible();
178
			}
179
		});
180
		unselectedCloseButton = new Button (otherGroup, SWT.CHECK);
181
		unselectedCloseButton.setText (ControlExample.getResourceString("Set_Unselected_Close_Visible"));
182
		unselectedCloseButton.setSelection(true);
183
		unselectedCloseButton.addSelectionListener (new SelectionAdapter () {
184
			public void widgetSelected (SelectionEvent event) {
185
				setUnselectedCloseVisible();
186
			}
187
		});
188
	}
189
190
	/**
191
	 * Creates the "Example" group.
192
	 */
193
	void createExampleGroup () {
194
		super.createExampleGroup ();
195
		
196
		/* Create a group for the CTabFolder */
197
		tabFolderGroup = new Group (exampleGroup, SWT.NONE);
198
		tabFolderGroup.setLayout (new GridLayout ());
199
		tabFolderGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
200
		tabFolderGroup.setText ("CTabFolder");
201
	}
202
	
203
	/**
204
	 * Creates the "Example" widgets.
205
	 */
206
	void createExampleWidgets () {
207
		
208
		/* Compute the widget style */
209
		int style = getDefaultStyle();
210
		if (topButton.getSelection ()) style |= SWT.TOP;
211
		if (bottomButton.getSelection ()) style |= SWT.BOTTOM;
212
		if (borderButton.getSelection ()) style |= SWT.BORDER;
213
		if (flatButton.getSelection ()) style |= SWT.FLAT;
214
		if (closeButton.getSelection ()) style |= SWT.CLOSE;
215
216
		/* Create the example widgets */
217
		tabFolder1 = new CTabFolder (tabFolderGroup, style);
218
		for (int i = 0; i < CTabItems1.length; i++) {
219
			CTabItem item = new CTabItem(tabFolder1, SWT.NONE);
220
			item.setText(CTabItems1[i]);
221
			Text text = new Text(tabFolder1, SWT.WRAP | SWT.MULTI);
222
			text.setText(ControlExample.getResourceString("CTabItem_content") + ": " + i);
223
			item.setControl(text);
224
		}
225
		tabFolder1.addListener(SWT.Selection, new Listener() {
226
			public void handleEvent(Event event) {
227
				lastSelectedTab = tabFolder1.getSelectionIndex();
228
			}
229
		});
230
		tabFolder1.setSelection(lastSelectedTab);
231
	}
232
	
233
	/**
234
	 * Creates the "Style" group.
235
	 */
236
	void createStyleGroup() {
237
		super.createStyleGroup ();
238
		
239
		/* Create the extra widgets */
240
		topButton = new Button (styleGroup, SWT.RADIO);
241
		topButton.setText ("SWT.TOP");
242
		topButton.setSelection(true);
243
		bottomButton = new Button (styleGroup, SWT.RADIO);
244
		bottomButton.setText ("SWT.BOTTOM");
245
		borderButton = new Button (styleGroup, SWT.CHECK);
246
		borderButton.setText ("SWT.BORDER");
247
		flatButton = new Button (styleGroup, SWT.CHECK);
248
		flatButton.setText ("SWT.FLAT");
249
		closeButton = new Button (styleGroup, SWT.CHECK);
250
		closeButton.setText ("SWT.CLOSE");
251
	}
252
	
253
	/**
254
	 * Gets the list of custom event names.
255
	 * 
256
	 * @return an array containing custom event names
257
	 */
258
	String [] getCustomEventNames () {
259
		return new String [] {"CTabFolderEvent"};
260
	}
261
	
262
	/**
263
	 * Gets the "Example" widget children's items, if any.
264
	 *
265
	 * @return an array containing the example widget children's items
266
	 */
267
	Item [] getExampleWidgetItems () {
268
		return tabFolder1.getItems();
269
	}
270
	
271
	/**
272
	 * Gets the "Example" widget children.
273
	 */
274
	Widget [] getExampleWidgets () {
275
		return new Widget [] {tabFolder1};
276
	}
277
	
278
	/**
279
	 * Gets the text for the tab folder item.
280
	 */
281
	String getTabText () {
282
		return "CTabFolder";
283
	}
284
285
	/**
286
	 * Hooks the custom listener specified by eventName.
287
	 */
288
	void hookCustomListener (final String eventName) {
289
		if (eventName == "CTabFolderEvent") {
290
			tabFolder1.addCTabFolder2Listener (new CTabFolder2Adapter () {
291
				public void close (CTabFolderEvent event) {
292
					log (eventName, event);
293
				}
294
			});
295
		}
296
	}
297
298
	/**
299
	 * Sets the foreground color, background color, and font
300
	 * of the "Example" widgets to their default settings.
301
	 * Also sets foreground and background color of the Node 1
302
	 * TreeItems to default settings.
303
	 */
304
	void resetColorsAndFonts () {
305
		super.resetColorsAndFonts ();
306
		Color oldColor = selectionForegroundColor;
307
		selectionForegroundColor = null;
308
		setSelectionForeground ();
309
		if (oldColor != null) oldColor.dispose();
310
		oldColor = selectionBackgroundColor;
311
		selectionBackgroundColor = null;
312
		setSelectionBackground ();
313
		if (oldColor != null) oldColor.dispose();
314
		Font oldFont = itemFont;
315
		itemFont = null;
316
		setItemFont ();
317
		if (oldFont != null) oldFont.dispose();
318
	}
319
	
320
	/**
321
	 * Sets the state of the "Example" widgets.
322
	 */
323
	void setExampleWidgetState () {
324
		super.setExampleWidgetState();
325
		setSimpleTabs();
326
		setSingleTabs();
327
		setImages();
328
		setMinimizeVisible();
329
		setMaximizeVisible();
330
		setUnselectedCloseVisible();
331
		setUnselectedImageVisible();
332
		setSelectionBackground ();
333
		setSelectionForeground ();
334
		setItemFont ();
335
		setExampleWidgetSize();
336
	}
337
	
338
	/**
339
	 * Sets the shape that the CTabFolder will use to render itself. 
340
	 */
341
	void setSimpleTabs () {
342
		tabFolder1.setSimple (simpleTabButton.getSelection ());
343
		setExampleWidgetSize();
344
	}
345
	
346
	/**
347
	 * Sets the number of tabs that the CTabFolder should display.
348
	 */
349
	void setSingleTabs () {
350
		tabFolder1.setSingle (singleTabButton.getSelection ());
351
		setExampleWidgetSize();
352
	}
353
	/**
354
	 * Sets an image into each item of the "Example" widgets.
355
	 */
356
	void setImages () {
357
		boolean setImage = imageButton.getSelection ();
358
		CTabItem items[] = tabFolder1.getItems ();
359
		for (int i = 0; i < items.length; i++) {
360
			if (setImage) {
361
				items[i].setImage (instance.images[ControlExample.ciClosedFolder]);
362
			} else {
363
				items[i].setImage (null);
364
			}
365
		}
366
		setExampleWidgetSize ();
367
	}
368
	/**
369
	 * Sets the visibility of the minimize button
370
	 */
371
	void setMinimizeVisible () {
372
		tabFolder1.setMinimizeVisible(showMinButton.getSelection ());
373
		setExampleWidgetSize();
374
	}
375
	/**
376
	 * Sets the visibility of the maximize button
377
	 */
378
	void setMaximizeVisible () {
379
		tabFolder1.setMaximizeVisible(showMaxButton.getSelection ());
380
		setExampleWidgetSize();
381
	}
382
	/**
383
	 * Sets the visibility of the close button on unselected tabs
384
	 */
385
	void setUnselectedCloseVisible () {
386
		tabFolder1.setUnselectedCloseVisible(unselectedCloseButton.getSelection ());
387
		setExampleWidgetSize();
388
	}
389
	/**
390
	 * Sets the visibility of the image on unselected tabs
391
	 */
392
	void setUnselectedImageVisible () {
393
		tabFolder1.setUnselectedImageVisible(unselectedImageButton.getSelection ());
394
		setExampleWidgetSize();
395
	}
396
	/**
397
	 * Sets the background color of CTabItem 0.
398
	 */
399
	void setSelectionBackground () {
400
		if (!instance.startup) {
401
			tabFolder1.setSelectionBackground(selectionBackgroundColor);
402
		}
403
		// Set the selection background item's image to match the background color of the selection.
404
		Color color = selectionBackgroundColor;
405
		if (color == null) color = tabFolder1.getSelectionBackground ();
406
		TableItem item = colorAndFontTable.getItem(SELECTION_BACKGROUND_COLOR);
407
		Image oldImage = item.getImage();
408
		if (oldImage != null) oldImage.dispose();
409
		item.setImage (colorImage(color));
410
	}
411
	
412
	/**
413
	 * Sets the foreground color of CTabItem 0.
414
	 */
415
	void setSelectionForeground () {
416
		if (!instance.startup) {
417
			tabFolder1.setSelectionForeground(selectionForegroundColor);
418
		}
419
		// Set the selection foreground item's image to match the foreground color of the selection.
420
		Color color = selectionForegroundColor;
421
		if (color == null) color = tabFolder1.getSelectionForeground ();
422
		TableItem item = colorAndFontTable.getItem(SELECTION_FOREGROUND_COLOR);
423
		Image oldImage = item.getImage();
424
		if (oldImage != null) oldImage.dispose();
425
		item.setImage (colorImage(color));
426
	}
427
	
428
	/**
429
	 * Sets the font of CTabItem 0.
430
	 */
431
	void setItemFont () {
432
		if (!instance.startup) {
433
			tabFolder1.getItem (0).setFont (itemFont);
434
			setExampleWidgetSize();
435
		}
436
		/* Set the font item's image to match the font of the item. */
437
		Font ft = itemFont;
438
		if (ft == null) ft = tabFolder1.getItem (0).getFont ();
439
		TableItem item = colorAndFontTable.getItem(ITEM_FONT);
440
		Image oldImage = item.getImage();
441
		if (oldImage != null) oldImage.dispose();
442
		item.setImage (fontImage(ft));
443
		item.setFont(ft);
444
		colorAndFontTable.layout ();
445
	}
446
}
(-)src/org/eclipse/swt/examples/mirroringTest/CanvasTab.java (+312 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.events.*;
18
import org.eclipse.swt.layout.*;
19
20
class CanvasTab extends Tab {
21
	static final int colors [] = {
22
		SWT.COLOR_RED,
23
		SWT.COLOR_GREEN,
24
		SWT.COLOR_BLUE,
25
		SWT.COLOR_MAGENTA,
26
		SWT.COLOR_YELLOW,
27
		SWT.COLOR_CYAN,
28
		SWT.COLOR_DARK_RED,
29
		SWT.COLOR_DARK_GREEN,
30
		SWT.COLOR_DARK_BLUE,
31
		SWT.COLOR_DARK_MAGENTA,
32
		SWT.COLOR_DARK_YELLOW,
33
		SWT.COLOR_DARK_CYAN
34
	};
35
	static final String canvasString = "Canvas"; //$NON-NLS-1$
36
	
37
	/* Example widgets and groups that contain them */
38
	Canvas canvas;
39
	Group canvasGroup;
40
41
	/* Style widgets added to the "Style" group */
42
	Button horizontalButton, verticalButton, noBackgroundButton, noFocusButton, 
43
	noMergePaintsButton, noRedrawResizeButton, doubleBufferedButton;
44
45
	/* Other widgets added to the "Other" group */
46
	Button caretButton, fillDamageButton;
47
48
	int paintCount;
49
	int cx, cy;
50
	int maxX, maxY;
51
	
52
	/**
53
	 * Creates the Tab within a given instance of ControlExample.
54
	 */
55
	CanvasTab(ControlExample instance) {
56
		super(instance);
57
	}
58
59
	/**
60
	 * Creates the "Other" group.
61
	 */
62
	void createOtherGroup () {
63
		super.createOtherGroup ();
64
	
65
		/* Create display controls specific to this example */
66
		caretButton = new Button (otherGroup, SWT.CHECK);
67
		caretButton.setText (ControlExample.getResourceString("Caret"));
68
		fillDamageButton = new Button (otherGroup, SWT.CHECK);
69
		fillDamageButton.setText (ControlExample.getResourceString("FillDamage"));
70
			
71
		/* Add the listeners */
72
		caretButton.addSelectionListener (new SelectionAdapter () {
73
			public void widgetSelected (SelectionEvent event) {
74
				setCaret ();
75
			}
76
		});
77
	}
78
	
79
	/**
80
	 * Creates the "Example" group.
81
	 */
82
	void createExampleGroup () {
83
		super.createExampleGroup ();
84
		
85
		/* Create a group for the canvas widget */
86
		canvasGroup = new Group (exampleGroup, SWT.NONE);
87
		canvasGroup.setLayout (new GridLayout ());
88
		canvasGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
89
		canvasGroup.setText ("Canvas");
90
	}
91
	
92
	/**
93
	 * Creates the "Example" widgets.
94
	 */
95
	void createExampleWidgets () {
96
		
97
		/* Compute the widget style */
98
		int style = getDefaultStyle();
99
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
100
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
101
		if (borderButton.getSelection ()) style |= SWT.BORDER;
102
		if (noBackgroundButton.getSelection ()) style |= SWT.NO_BACKGROUND;
103
		if (noFocusButton.getSelection ()) style |= SWT.NO_FOCUS;
104
		if (noMergePaintsButton.getSelection ()) style |= SWT.NO_MERGE_PAINTS;
105
		if (noRedrawResizeButton.getSelection ()) style |= SWT.NO_REDRAW_RESIZE;
106
		if (doubleBufferedButton.getSelection ()) style |= SWT.DOUBLE_BUFFERED;
107
108
		/* Create the example widgets */
109
		paintCount = 0; cx = 0; cy = 0;
110
		canvas = new Canvas (canvasGroup, style);
111
		canvas.addPaintListener(new PaintListener () {
112
			public void paintControl(PaintEvent e) {
113
				paintCount++;
114
				GC gc = e.gc;
115
				if (fillDamageButton.getSelection ()) {
116
					Color color = e.display.getSystemColor (colors [paintCount % colors.length]);
117
					gc.setBackground(color);
118
					gc.fillRectangle(e.x, e.y, e.width, e.height);
119
				}
120
				Point size = canvas.getSize ();
121
				gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
122
				gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10);
123
				Point extent = gc.textExtent(canvasString);
124
				gc.drawString(canvasString, cx + (size.x - extent.x) / 2, cy - extent.y + (size.y - 10) / 2, true);
125
			}
126
		});
127
		canvas.addControlListener(new ControlAdapter() {
128
			public void controlResized(ControlEvent event) {
129
				Point size = canvas.getSize ();
130
				maxX = size.x * 3 / 2; maxY = size.y * 3 / 2;
131
				resizeScrollBars ();
132
			}
133
		});
134
		ScrollBar bar = canvas.getHorizontalBar();
135
		if (bar != null) {
136
			hookListeners (bar);
137
			bar.addSelectionListener(new SelectionAdapter() {
138
				public void widgetSelected(SelectionEvent event) {
139
					scrollHorizontal ((ScrollBar)event.widget);
140
				}
141
			});
142
		}
143
		bar = canvas.getVerticalBar();
144
		if (bar != null) {
145
			hookListeners (bar);
146
			bar.addSelectionListener(new SelectionAdapter() {
147
				public void widgetSelected(SelectionEvent event) {
148
					scrollVertical ((ScrollBar)event.widget);
149
				}
150
			});
151
		}
152
	}
153
	
154
	/**
155
	 * Creates the "Style" group.
156
	 */
157
	void createStyleGroup() {
158
		super.createStyleGroup();
159
	
160
		/* Create the extra widgets */
161
		horizontalButton = new Button (styleGroup, SWT.CHECK);
162
		horizontalButton.setText ("SWT.H_SCROLL");
163
		horizontalButton.setSelection(true);
164
		verticalButton = new Button (styleGroup, SWT.CHECK);
165
		verticalButton.setText ("SWT.V_SCROLL");
166
		verticalButton.setSelection(true);
167
		borderButton = new Button (styleGroup, SWT.CHECK);
168
		borderButton.setText ("SWT.BORDER");
169
		noBackgroundButton = new Button (styleGroup, SWT.CHECK);
170
		noBackgroundButton.setText ("SWT.NO_BACKGROUND");
171
		noFocusButton = new Button (styleGroup, SWT.CHECK);
172
		noFocusButton.setText ("SWT.NO_FOCUS");
173
		noMergePaintsButton = new Button (styleGroup, SWT.CHECK);
174
		noMergePaintsButton.setText ("SWT.NO_MERGE_PAINTS");
175
		noRedrawResizeButton = new Button (styleGroup, SWT.CHECK);
176
		noRedrawResizeButton.setText ("SWT.NO_REDRAW_RESIZE");
177
		doubleBufferedButton = new Button (styleGroup, SWT.CHECK);
178
		doubleBufferedButton.setText ("SWT.DOUBLE_BUFFERED");
179
	}
180
181
	/**
182
	 * Creates the tab folder page.
183
	 *
184
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
185
	 * @return the new page for the tab folder
186
	 */
187
	Composite createTabFolderPage (TabFolder tabFolder) {
188
		super.createTabFolderPage (tabFolder);
189
190
		/*
191
		 * Add a resize listener to the tabFolderPage so that
192
		 * if the user types into the example widget to change
193
		 * its preferred size, and then resizes the shell, we
194
		 * recalculate the preferred size correctly.
195
		 */
196
		tabFolderPage.addControlListener(new ControlAdapter() {
197
			public void controlResized(ControlEvent e) {
198
				setExampleWidgetSize ();
199
			}
200
		});
201
		
202
		return tabFolderPage;
203
	}
204
205
	/**
206
	 * Gets the "Example" widget children.
207
	 */
208
	Widget [] getExampleWidgets () {
209
		return new Widget [] {canvas};
210
	}
211
	
212
	/**
213
	 * Returns a list of set/get API method names (without the set/get prefix)
214
	 * that can be used to set/get values in the example control(s).
215
	 */
216
	String[] getMethodNames() {
217
		return new String[] {"ToolTipText"};
218
	}
219
220
	/**
221
	 * Gets the text for the tab folder item.
222
	 */
223
	String getTabText () {
224
		return "Canvas";
225
	}
226
	
227
	/**
228
	 * Resizes the maximum and thumb of both scrollbars.
229
	 */
230
	void resizeScrollBars () {
231
		Rectangle clientArea = canvas.getClientArea();
232
		ScrollBar bar = canvas.getHorizontalBar();
233
		if (bar != null) {
234
			bar.setMaximum(maxX);
235
			bar.setThumb(clientArea.width);
236
			bar.setPageIncrement(clientArea.width);
237
		}
238
		bar = canvas.getVerticalBar();
239
		if (bar != null) {
240
			bar.setMaximum(maxY);
241
			bar.setThumb(clientArea.height);
242
			bar.setPageIncrement(clientArea.height);
243
		}
244
	}
245
246
	/**
247
	 * Scrolls the canvas horizontally.
248
	 * 
249
	 * @param scrollBar
250
	 */
251
	void scrollHorizontal (ScrollBar scrollBar) {
252
		Rectangle bounds = canvas.getClientArea();
253
		int x = -scrollBar.getSelection();
254
		if (x + maxX < bounds.width) {
255
			x = bounds.width - maxX;
256
		}
257
		canvas.scroll(x, cy, cx, cy, maxX, maxY, false);
258
		cx = x;
259
	}
260
261
	/**
262
	 * Scrolls the canvas vertically.
263
	 * 
264
	 * @param scrollBar
265
	 */
266
	void scrollVertical (ScrollBar scrollBar) {
267
		Rectangle bounds = canvas.getClientArea();
268
		int y = -scrollBar.getSelection();
269
		if (y + maxY < bounds.height) {
270
			y = bounds.height - maxY;
271
		}
272
		canvas.scroll(cx, y, cx, cy, maxX, maxY, false);
273
		cy = y;
274
	}
275
276
	/**
277
	 * Sets or clears the caret in the "Example" widget.
278
	 */
279
	void setCaret () {
280
		Caret oldCaret = canvas.getCaret ();
281
		if (caretButton.getSelection ()) {
282
			Caret newCaret = new Caret(canvas, SWT.NONE);
283
			Font font = canvas.getFont();
284
			newCaret.setFont(font);
285
			GC gc = new GC(canvas);
286
			gc.setFont(font);
287
			newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight());
288
			gc.dispose();
289
			canvas.setCaret (newCaret);
290
			canvas.setFocus();
291
		} else {
292
			canvas.setCaret (null);
293
		}
294
		if (oldCaret != null) oldCaret.dispose ();
295
	}
296
	
297
	/**
298
	 * Sets the state of the "Example" widgets.
299
	 */
300
	void setExampleWidgetState () {
301
		super.setExampleWidgetState ();
302
		horizontalButton.setSelection ((canvas.getStyle () & SWT.H_SCROLL) != 0);
303
		verticalButton.setSelection ((canvas.getStyle () & SWT.V_SCROLL) != 0);
304
		borderButton.setSelection ((canvas.getStyle () & SWT.BORDER) != 0);
305
		noBackgroundButton.setSelection ((canvas.getStyle () & SWT.NO_BACKGROUND) != 0);
306
		noFocusButton.setSelection ((canvas.getStyle () & SWT.NO_FOCUS) != 0);
307
		noMergePaintsButton.setSelection ((canvas.getStyle () & SWT.NO_MERGE_PAINTS) != 0);
308
		noRedrawResizeButton.setSelection ((canvas.getStyle () & SWT.NO_REDRAW_RESIZE) != 0);
309
		doubleBufferedButton.setSelection ((canvas.getStyle () & SWT.DOUBLE_BUFFERED) != 0);
310
		if (!instance.startup) setCaret ();
311
	}
312
}
(-)src/org/eclipse/swt/examples/mirroringTest/CombineComposition.java (+896 lines)
Added Link Here
1
package org.eclipse.swt.examples.mirroringTest;
2
3
import org.eclipse.swt.SWT;
4
import org.eclipse.swt.events.SelectionAdapter;
5
import org.eclipse.swt.events.SelectionEvent;
6
import org.eclipse.swt.events.SelectionListener;
7
import org.eclipse.swt.graphics.Color;
8
import org.eclipse.swt.graphics.Image;
9
import org.eclipse.swt.graphics.Point;
10
import org.eclipse.swt.graphics.Rectangle;
11
import org.eclipse.swt.layout.FormAttachment;
12
import org.eclipse.swt.layout.FormData;
13
import org.eclipse.swt.layout.FormLayout;
14
import org.eclipse.swt.layout.GridData;
15
import org.eclipse.swt.layout.GridLayout;
16
import org.eclipse.swt.widgets.Button;
17
import org.eclipse.swt.widgets.Combo;
18
import org.eclipse.swt.widgets.Composite;
19
import org.eclipse.swt.widgets.Control;
20
import org.eclipse.swt.widgets.CoolBar;
21
import org.eclipse.swt.widgets.CoolItem;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Group;
24
import org.eclipse.swt.widgets.Label;
25
import org.eclipse.swt.widgets.List;
26
import org.eclipse.swt.widgets.Menu;
27
import org.eclipse.swt.widgets.MenuItem;
28
import org.eclipse.swt.widgets.ProgressBar;
29
import org.eclipse.swt.widgets.Shell;
30
import org.eclipse.swt.widgets.Slider;
31
import org.eclipse.swt.widgets.TabFolder;
32
import org.eclipse.swt.widgets.TabItem;
33
import org.eclipse.swt.widgets.Table;
34
import org.eclipse.swt.widgets.TableColumn;
35
import org.eclipse.swt.widgets.TableItem;
36
import org.eclipse.swt.widgets.Text;
37
import org.eclipse.swt.widgets.ToolBar;
38
import org.eclipse.swt.widgets.ToolItem;
39
import org.eclipse.swt.widgets.Tree;
40
import org.eclipse.swt.widgets.TreeColumn;
41
import org.eclipse.swt.widgets.TreeItem;
42
43
public class CombineComposition extends Composite{
44
	
45
	private Button buttonRTLCompositeGroups;
46
	private Button buttonLTRCompositeGroups;
47
48
	private Button buttonListRTLCompositeGroups;
49
	private Button buttonListLTRCompositeGroups;
50
51
	private Composite compositeGroups;
52
	private Slider sliderGtoupC;
53
	private Combo comboSimpleGroupA;
54
	private Combo comboDropDownGroupA;
55
	private Button buttonTextPicGroupA;
56
	private Button buttonPic;
57
	private Button buttonTextGroupA;
58
	private Button buttonRTLGroupA;
59
	private Button buttonLTRGroupA;
60
	private Label labelPicture;
61
	private Label labelTextGroupA;
62
	private Button buttonLTRGroupC;
63
	private Button buttonRTLGroupC;
64
	private ProgressBar progressBarGroupC;
65
	private ToolBar toolBar1;
66
	CoolItem pushItem, dropDownItem, radioItem, checkItem, textItem;
67
	private CoolBar coolBarGroupC;
68
	private Tree treeGroupC;
69
	TreeItem textNode1, imageNode1;
70
	private Group groupC;
71
	private Button buttonRTLGroupD;
72
	private Button buttonLTRGroupD;
73
	private Text textAriaGroupD;
74
	private Text textSingleGroupD;
75
	private Table tableGroupD;
76
	private Composite compositeInTabGtoupD;
77
	private TabItem cTabItem1;
78
	private TabFolder tabFolderInGroupD;
79
	private Group groupD;
80
	private Group groupA;
81
	private Label labelMultiText;
82
	private Label labelSimpleText;
83
	private List list;
84
	
85
	Control[] controls;
86
	
87
	CombinedBasic combinedBasic;
88
	CombinedOrientationExample instance;
89
	
90
	static String [] ListData = {"\u05d0\u05e0\u05d9\u0020\u05e2\u05d5\u05d1\u05d3\u05ea\u0020\u05d1 - IBM \u05d9\u05e9\u05e8\u05d0\u05dc...",
91
		"I work at \u05d9\u05d1\u05de in Israel...",
92
		"My name is \u05d0\u05dc\u05d9\u05e1...",
93
		"\u05e7\u05d5\u05e8\u05d0\u05d9\u05dd\u0020\u05dc\u05d9 Alice...",
94
		"1234..."};
95
	static String [] columnTitles	= {CombinedOrientationExample.getResourceString("TableTitle_0"),
96
		CombinedOrientationExample.getResourceString("TableTitle_1"),
97
		CombinedOrientationExample.getResourceString("TableTitle_2"),
98
		CombinedOrientationExample.getResourceString("TableTitle_3")};
99
		   
100
	static String[][] tableData = {
101
			{ CombinedOrientationExample.getResourceString("TableLine0_0"),
102
				CombinedOrientationExample.getResourceString("TableLine0_1"),
103
				CombinedOrientationExample.getResourceString("TableLine0_2"),
104
				CombinedOrientationExample.getResourceString("TableLine0_3") },
105
			{ CombinedOrientationExample.getResourceString("TableLine1_0"),
106
				CombinedOrientationExample.getResourceString("TableLine1_1"),
107
				CombinedOrientationExample.getResourceString("TableLine1_2"),
108
				CombinedOrientationExample.getResourceString("TableLine1_3") },
109
			{ CombinedOrientationExample.getResourceString("TableLine2_0"),
110
				CombinedOrientationExample.getResourceString("TableLine2_1"),
111
				CombinedOrientationExample.getResourceString("TableLine2_2"),
112
				CombinedOrientationExample.getResourceString("TableLine2_3") } };
113
114
115
	static String [] widgetsListData = {
116
		"\u05e7\u05d1\u05d5\u05e6\u05d4 \u05e7\u05d8\u05e0\u05d4 - group D...",
117
		"Tab folder...",
118
//		"Tab Item...",
119
		"Composite in tab Item...",
120
		"Table...",
121
		"Simple Text Label...",
122
		"Simple Text...",
123
		"Multi Text Label...",
124
		"Multi Text...",
125
		"\u05e7\u05d1\u05d5\u05e6\u05d4 \u05e7\u05d8\u05e0\u05d4 LTR...",
126
		"\u05e7\u05d1\u05d5\u05e6\u05d4 \u05e7\u05d8\u05e0\u05d4 RTL...", 
127
		"---",
128
		"Complex Group",
129
		"Text Label - Complex group...",
130
		"Picture Label - Complex group",
131
		"Text Button - Complex group",
132
		"Picture Button - Complex group",
133
		"Text & Picture Button - Complex group",
134
		"Drop down combo - Complex group",
135
		"Simple combo - Complex group",
136
		"LTR button - Complex group",
137
		"RTL button - Complex group",
138
		"---",		
139
		"Small Group",
140
		"Tree - Small group",
141
		"CoolBar - Small group",
142
		"Progress Bar - Small group",
143
		"Slider - Small group",
144
//		"pushItem",
145
//		"dropDownItem",
146
//		"radioItem",
147
//		"checkItem",
148
//		"textItem",
149
		"LTR button - Small group",
150
		"RTL button - Small group",
151
		"---",
152
		"List - Me..."
153
		};
154
	
155
156
	
157
	public CombineComposition(Composite parent, int style, CombinedOrientationExample instance) {
158
		super(parent, style);
159
		this.instance = instance;
160
		initGUI(style);
161
	}
162
	/**
163
	* Initializes the GUI.
164
	*/
165
	private void initGUI(int style) {
166
		try {
167
			SelectionListener bidiListener = new SelectionAdapter () {
168
				public void widgetSelected (SelectionEvent event) {
169
170
					if(event.widget == buttonRTLCompositeGroups || event.widget == buttonLTRCompositeGroups){
171
						compositeGroups.setOrientation(event.widget == buttonLTRCompositeGroups ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
172
						compositeGroups.setToolTipText("I'm " + (event.widget == buttonLTRCompositeGroups ? "LTR" : "RTL"));
173
					}
174
					if(event.widget == buttonRTLGroupA || event.widget == buttonLTRGroupA){
175
						groupA.setOrientation(event.widget == buttonLTRGroupA ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
176
					}
177
					if(event.widget == buttonLTRGroupC || event.widget == buttonRTLGroupC){
178
						groupC.setOrientation(event.widget == buttonLTRGroupC ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
179
					}
180
					if(event.widget == buttonLTRGroupD || event.widget == buttonRTLGroupD){
181
						groupD.setOrientation(event.widget == buttonLTRGroupD ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
182
					}
183
					if(event.widget == buttonListRTLCompositeGroups || event.widget == buttonListLTRCompositeGroups){
184
						setOrientationItemFromList(list.getSelectionIndices(), event.widget == buttonListLTRCompositeGroups ? SWT.LEFT_TO_RIGHT : SWT.RIGHT_TO_LEFT);
185
					}
186
				}
187
			};
188
			
189
			//this.setBackground(new Color(Display.getDefault(),192, 192, 192));
190
			FormLayout thisLayout = new FormLayout();
191
			this.setLayout(thisLayout);
192
			{
193
				{
194
					FormData listLData = new FormData();
195
					listLData.left =  new FormAttachment(0, 1000, 505);
196
					listLData.top =  new FormAttachment(0, 1000, 26);
197
					listLData.width = 99;
198
					listLData.height = 509;
199
					list = new List(this, style | SWT.MULTI | SWT.BORDER);
200
					list.setItems (widgetsListData);
201
					
202
					list.setLayoutData(listLData);
203
				}
204
				{
205
					buttonListRTLCompositeGroups = new Button(this, SWT.PUSH | SWT.CENTER | style);
206
					FormData buttonRTLCompositeGroupsLData = new FormData();
207
					buttonRTLCompositeGroupsLData.left =  new FormAttachment(0, 1000, 505);
208
					buttonRTLCompositeGroupsLData.top =  new FormAttachment(904, 1000, 0);
209
					buttonRTLCompositeGroupsLData.width = 50;
210
					buttonRTLCompositeGroupsLData.height = 23;
211
					buttonListRTLCompositeGroups.setLayoutData(buttonRTLCompositeGroupsLData);
212
					buttonListRTLCompositeGroups.setText("Item RTL");
213
				}
214
				{
215
					buttonListLTRCompositeGroups = new Button(this, SWT.PUSH | SWT.CENTER | style);
216
					FormData buttonLTRCompositeGroupsLData = new FormData();
217
					buttonLTRCompositeGroupsLData.width = 50;
218
					buttonLTRCompositeGroupsLData.height = 23;
219
					buttonLTRCompositeGroupsLData.left =  new FormAttachment(0, 1000, 559);
220
					buttonLTRCompositeGroupsLData.top =  new FormAttachment(904, 1000, 0);
221
					buttonListLTRCompositeGroups.setLayoutData(buttonLTRCompositeGroupsLData);
222
					buttonListLTRCompositeGroups.setText("Item LTR");
223
				}
224
				{
225
					buttonRTLCompositeGroups = new Button(this, SWT.PUSH | SWT.CENTER | style);
226
					FormData buttonRTLCompositeGroupsLData = new FormData();
227
					buttonRTLCompositeGroupsLData.left =  new FormAttachment(860, 1000, 0);
228
					buttonRTLCompositeGroupsLData.top =  new FormAttachment(950, 1000, 0);
229
					buttonRTLCompositeGroupsLData.width = 30;
230
					buttonRTLCompositeGroupsLData.height = 23;
231
					buttonRTLCompositeGroups.setLayoutData(buttonRTLCompositeGroupsLData);
232
					buttonRTLCompositeGroups.setText("RTL");
233
				}
234
				{
235
					buttonLTRCompositeGroups = new Button(this, SWT.PUSH | SWT.CENTER | style);
236
					FormData buttonLTRCompositeGroupsLData = new FormData();
237
					buttonLTRCompositeGroupsLData.width = 30;
238
					buttonLTRCompositeGroupsLData.height = 23;
239
					buttonLTRCompositeGroupsLData.left =  new FormAttachment(916, 1000, 0);
240
					buttonLTRCompositeGroupsLData.top =  new FormAttachment(950, 1000, 0);
241
					buttonLTRCompositeGroups.setLayoutData(buttonLTRCompositeGroupsLData);
242
					buttonLTRCompositeGroups.setText("LTR");
243
				}
244
				{
245
					groupA = new Group(this, SWT.NONE | style);
246
					FormLayout groupALayout = new FormLayout();
247
					groupA.setLayout(groupALayout);
248
					FormData groupALData = new FormData();
249
					groupALData.width = 385;
250
					groupALData.height = 421;
251
					groupALData.left =  new FormAttachment(11, 1000, 0);
252
					groupALData.right =  new FormAttachment(817, 1000, 0);
253
					groupALData.top =  new FormAttachment(9, 1000, 0);
254
					groupALData.bottom =  new FormAttachment(731, 1000, 0);
255
					groupA.setLayoutData(groupALData);
256
					groupA.setText("Very complex group...");
257
					groupA.setBackground(new Color(Display.getDefault(),192,192,192));
258
					{
259
						comboSimpleGroupA = new Combo(groupA, SWT.NONE | style | SWT.SIMPLE);
260
						FormData comboSimpleGroupALData = new FormData();
261
						comboSimpleGroupALData.left =  new FormAttachment(0, 1000, 315);
262
						comboSimpleGroupALData.top =  new FormAttachment(0, 1000, 188);
263
						comboSimpleGroupALData.width = 135;
264
//						comboSimpleGroupALData.height = 21;
265
						comboSimpleGroupA.setLayoutData(comboSimpleGroupALData);
266
						comboSimpleGroupA.setText("combo");
267
						comboSimpleGroupA.setItems (ListData);
268
						if (ListData.length >= 3) {
269
							comboSimpleGroupA.setText(ListData [2]);
270
						}
271
					}
272
					{
273
						comboDropDownGroupA = new Combo(groupA, SWT.NONE | style | SWT.DROP_DOWN);
274
						FormData comboDropDownGroupALData = new FormData();
275
						comboDropDownGroupALData.left =  new FormAttachment(0, 1000, 315);
276
						comboDropDownGroupALData.top =  new FormAttachment(0, 1000, 150);
277
//						comboDropDownGroupALData.width = 31;
278
//						comboDropDownGroupALData.height = 21;
279
						comboDropDownGroupA.setLayoutData(comboDropDownGroupALData);
280
						comboDropDownGroupA.setText("simple combo");
281
						comboDropDownGroupA.setItems (ListData);
282
						if (ListData.length >= 3) {
283
							comboDropDownGroupA.setText(ListData [2]);
284
						}
285
					}
286
					{
287
						buttonTextPicGroupA = new Button(groupA, SWT.PUSH | SWT.CENTER | style);
288
						FormData buttonTextPicGroupALData = new FormData();
289
						buttonTextPicGroupALData.left =  new FormAttachment(0, 1000, 316);
290
						buttonTextPicGroupALData.top =  new FormAttachment(0, 1000, 103);
291
						buttonTextPicGroupALData.width = 91;
292
						buttonTextPicGroupALData.height = 23;
293
						buttonTextPicGroupA.setLayoutData(buttonTextPicGroupALData);
294
						buttonTextPicGroupA.setText("Text...");
295
						buttonTextPicGroupA.setImage(instance.images[CombinedOrientationExample.ciOpenFolder]);
296
297
					}
298
					{
299
						buttonPic = new Button(groupA, SWT.PUSH | SWT.CENTER | style);
300
						FormData buttonPicLData = new FormData();
301
						buttonPicLData.left =  new FormAttachment(0, 1000, 374);
302
						buttonPicLData.top =  new FormAttachment(0, 1000, 74);
303
						buttonPic.setLayoutData(buttonPicLData);
304
						buttonPic.setImage(instance.images[CombinedOrientationExample.ciOpenFolder]);
305
306
					}
307
					{
308
						buttonTextGroupA = new Button(groupA, SWT.PUSH | SWT.CENTER | style);
309
						FormData buttonTextGroupALData = new FormData();
310
						buttonTextGroupALData.left =  new FormAttachment(0, 1000, 316);
311
						buttonTextGroupALData.top =  new FormAttachment(0, 1000, 74);
312
						buttonTextGroupALData.width = 46;
313
						buttonTextGroupALData.height = 23;
314
						buttonTextGroupA.setLayoutData(buttonTextGroupALData);
315
						buttonTextGroupA.setText("Text...");
316
					}
317
					{
318
						buttonRTLGroupA = new Button(groupA, SWT.PUSH | SWT.CENTER | style);
319
						FormData buttonRTLGroupALData = new FormData();
320
						buttonRTLGroupALData.left =  new FormAttachment(0, 1000, 353);
321
						buttonRTLGroupALData.top =  new FormAttachment(0, 1000, 384);
322
						buttonRTLGroupALData.width = 30;
323
						buttonRTLGroupALData.height = 23;
324
						buttonRTLGroupA.setLayoutData(buttonRTLGroupALData);
325
						buttonRTLGroupA.setText("RTL");
326
					}
327
					{
328
						buttonLTRGroupA = new Button(groupA, SWT.PUSH | SWT.CENTER | style);
329
						FormData buttonLTRGroupALData = new FormData();
330
						buttonLTRGroupALData.left =  new FormAttachment(0, 1000, 317);
331
						buttonLTRGroupALData.top =  new FormAttachment(0, 1000, 384);
332
						buttonLTRGroupALData.width = 30;
333
						buttonLTRGroupALData.height = 23;
334
						buttonLTRGroupA.setLayoutData(buttonLTRGroupALData);
335
						buttonLTRGroupA.setText("LTR");
336
					}
337
					{
338
						labelPicture = new Label(groupA, SWT.NONE | style);
339
						FormData labelPictureLData = new FormData();
340
						labelPictureLData.left =  new FormAttachment(0, 1000, 316);
341
						labelPictureLData.top =  new FormAttachment(0, 1000, 38);
342
						labelPicture.setLayoutData(labelPictureLData);
343
						labelPicture.setImage (instance.images[CombinedOrientationExample.ciOpenFolder]);
344
					}
345
					{
346
						groupD = new Group(groupA, SWT.NONE | style);
347
						FormLayout groupDLayout = new FormLayout();
348
						groupD.setLayout(groupDLayout);
349
						FormData groupDLData = new FormData();
350
						groupDLData.width = 267;
351
						groupDLData.height = 384;
352
						groupDLData.left =  new FormAttachment(14, 1000, 0);
353
						groupDLData.right =  new FormAttachment(638, 1000, 0);
354
						groupDLData.top =  new FormAttachment(13, 1000, 0);
355
						groupDLData.bottom =  new FormAttachment(963, 1000, 0);
356
						groupD.setLayoutData(groupDLData);
357
						groupD.setText("\u05e7\u05d1\u05d5\u05e6\u05d4 \u05e7\u05d8\u05e0\u05d4...");
358
						groupD.setBackground(new Color(Display.getDefault(),192, 192, 192));
359
						{
360
							labelMultiText = new Label(groupD, SWT.NONE);
361
							FormData labelMultiTextLData = new FormData();
362
							labelMultiTextLData.left =  new FormAttachment(0, 1000, 0);
363
							labelMultiTextLData.top =  new FormAttachment(0, 1000, 306);
364
							//labelMultiTextLData.width = 56;
365
							labelMultiTextLData.height = 13;
366
							labelMultiText.setLayoutData(labelMultiTextLData);
367
							labelMultiText.setText("SWT.MULTI...");
368
						}
369
						{
370
							labelSimpleText = new Label(groupD, SWT.NONE);
371
							FormData labelSimpleTextLData = new FormData();
372
							labelSimpleTextLData.left =  new FormAttachment(0, 1000, 0);
373
							labelSimpleTextLData.top =  new FormAttachment(0, 1000, 280);
374
							//labelSimpleTextLData.width = 53;
375
							labelSimpleTextLData.height = 13;
376
							labelSimpleText.setLayoutData(labelSimpleTextLData);
377
							labelSimpleText.setText("SWT.SINGLE...");
378
						}
379
						{
380
							buttonRTLGroupD = new Button(groupD, SWT.PUSH | SWT.CENTER);
381
							FormData buttonRTLGroupDLData = new FormData();
382
							buttonRTLGroupDLData.width = 108;
383
							buttonRTLGroupDLData.height = 23;
384
							buttonRTLGroupDLData.left =  new FormAttachment(20, 1000, 0);
385
							buttonRTLGroupDLData.right =  new FormAttachment(425, 1000, 0);
386
							buttonRTLGroupDLData.top =  new FormAttachment(14, 1000, 0);
387
							buttonRTLGroupDLData.bottom =  new FormAttachment(74, 1000, 0);
388
							buttonRTLGroupD.setLayoutData(buttonRTLGroupDLData);
389
							buttonRTLGroupD.setText("\u05e7\u05d1\u05d5\u05e6\u05d4 \u05e7\u05d8\u05e0\u05d4 RTL...");
390
						}
391
						{
392
							buttonLTRGroupD = new Button(groupD, SWT.PUSH | SWT.CENTER);
393
							FormData buttonLTRGroupDLData = new FormData();
394
							buttonLTRGroupDLData.width = 108;
395
							buttonLTRGroupDLData.height = 23;
396
							buttonLTRGroupDLData.left =  new FormAttachment(20, 1000, 0);
397
							buttonLTRGroupDLData.right =  new FormAttachment(425, 1000, 0);
398
							buttonLTRGroupDLData.top =  new FormAttachment(87, 1000, 0);
399
							buttonLTRGroupDLData.bottom =  new FormAttachment(147, 1000, 0);
400
							buttonLTRGroupD.setLayoutData(buttonLTRGroupDLData);
401
							buttonLTRGroupD.setText("\u05e7\u05d1\u05d5\u05e6\u05d4 \u05e7\u05d8\u05e0\u05d4 LTR...");
402
						}
403
						{
404
							tabFolderInGroupD = new TabFolder(groupD, SWT.NONE | style);
405
							{
406
								cTabItem1 = new TabItem(tabFolderInGroupD, SWT.NONE | style);
407
								cTabItem1.setText("Tab");
408
								{
409
									compositeInTabGtoupD = new Composite(tabFolderInGroupD, SWT.NONE | style);
410
									GridLayout compositeInTabGtoupDLayout = new GridLayout();
411
									compositeInTabGtoupDLayout.makeColumnsEqualWidth = true;
412
									compositeInTabGtoupD.setLayout(compositeInTabGtoupDLayout);
413
									cTabItem1.setControl(compositeInTabGtoupD);
414
									{
415
										GridData tableGroupDLData = new GridData();
416
										tableGroupDLData.widthHint = 222;
417
										tableGroupDLData.heightHint = 166;
418
										tableGroupD = new Table(compositeInTabGtoupD, SWT.NONE | style);
419
										for (int i = 0; i < columnTitles.length; i++) {
420
											TableColumn tableColumn = new TableColumn(tableGroupD, SWT.NONE);
421
											tableColumn.setText(columnTitles[i]);
422
											tableColumn.setImage(instance.images [i % 3]);
423
										}
424
										tableGroupD.setSortColumn(tableGroupD.getColumn(0));
425
										for (int i=0; i<16; i++) {
426
											TableItem item = new TableItem (tableGroupD, SWT.NONE);
427
											setItemText (item, i, CombinedOrientationExample.getResourceString("Index") + i);
428
										}
429
										packColumns();
430
										tableGroupD.setHeaderVisible(true);
431
										tableGroupD.setLinesVisible (true);
432
										tableGroupD.setLayoutData(tableGroupDLData);
433
									}
434
								}
435
							}
436
	FormData tabFolderInGroupDLData = new FormData();
437
							tabFolderInGroupDLData.width = 250;
438
							tabFolderInGroupDLData.height = 193;
439
							tabFolderInGroupDLData.left =  new FormAttachment(20, 1000, 0);
440
							tabFolderInGroupDLData.right =  new FormAttachment(971, 1000, 0);
441
							tabFolderInGroupDLData.top =  new FormAttachment(160, 1000, 0);
442
							tabFolderInGroupDLData.bottom =  new FormAttachment(720, 1000, 0);
443
							tabFolderInGroupD.setLayoutData(tabFolderInGroupDLData);
444
							tabFolderInGroupD.setSelection(0);
445
							tabFolderInGroupD.setBackground(new Color(Display.getDefault(),192, 192, 192));
446
						}
447
						{
448
							textSingleGroupD = new Text(groupD, SWT.NONE | style | SWT.BORDER);
449
	FormData textSingleGroupDLData = new FormData();
450
							textSingleGroupDLData.width = 188;
451
							textSingleGroupDLData.height = 20;
452
							textSingleGroupDLData.left =  new FormAttachment(256, 1000, 0);
453
							textSingleGroupDLData.right =  new FormAttachment(983, 1000, 0);
454
							textSingleGroupDLData.top =  new FormAttachment(730, 1000, 0);
455
							textSingleGroupDLData.bottom =  new FormAttachment(782, 1000, 0);
456
							textSingleGroupD.setLayoutData(textSingleGroupDLData);
457
						}
458
						{
459
							textAriaGroupD = new Text(groupD, SWT.MULTI | SWT.WRAP | style | SWT.BORDER);
460
	FormData textAriaGroupDLData = new FormData();
461
							textAriaGroupDLData.width = 188;
462
							textAriaGroupDLData.height = 63;
463
							textAriaGroupDLData.left =  new FormAttachment(256, 1000, 0);
464
							textAriaGroupDLData.right =  new FormAttachment(983, 1000, 0);
465
							textAriaGroupDLData.top =  new FormAttachment(798, 1000, 0);
466
							textAriaGroupDLData.bottom =  new FormAttachment(962, 1000, 0);
467
							textAriaGroupD.setLayoutData(textAriaGroupDLData);
468
						}
469
					}
470
					{
471
						labelTextGroupA = new Label(groupA, SWT.NONE | style);
472
						FormData labelTextGroupALData = new FormData();
473
						labelTextGroupALData.width = 121;
474
						labelTextGroupALData.height = 13;
475
			labelTextGroupALData.left =  new FormAttachment(704, 1000, 0);
476
						labelTextGroupALData.right =  new FormAttachment(980, 1000, 0);
477
						labelTextGroupALData.top =  new FormAttachment(32, 1000, 0);
478
						labelTextGroupALData.bottom =  new FormAttachment(62, 1000, 0);
479
						labelTextGroupA.setLayoutData(labelTextGroupALData);
480
						labelTextGroupA.setText("I work at \u05d9\u05d1\u05de Israel...");
481
					}
482
				}
483
				{
484
					groupC = new Group(this, SWT.NONE | style);
485
					FormLayout groupCLayout = new FormLayout();
486
					groupC.setLayout(groupCLayout);
487
					FormData groupCLData = new FormData();
488
					groupCLData.width = 439;
489
					groupCLData.height = 134;
490
					groupCLData.left =  new FormAttachment(11, 1000, 0);
491
					groupCLData.right =  new FormAttachment(819, 1000, 0);
492
					groupCLData.top =  new FormAttachment(741, 1000, 0);
493
					groupCLData.bottom =  new FormAttachment(989, 1000, 0);
494
					groupC.setLayoutData(groupCLData);
495
					groupC.setText("Small group...");
496
					groupC.setBackground(new Color(Display.getDefault(),192,192,192));
497
					{
498
						FormData sliderGtoupCLData = new FormData();
499
						sliderGtoupCLData.left =  new FormAttachment(0, 1000, 201);
500
						sliderGtoupCLData.top =  new FormAttachment(0, 1000, 110);
501
						sliderGtoupCLData.width = 155;
502
						sliderGtoupCLData.height = 17;
503
						sliderGtoupC = new Slider(groupC, SWT.NONE);
504
						sliderGtoupC.setLayoutData(sliderGtoupCLData);
505
					}
506
					{
507
						buttonRTLGroupC = new Button(groupC, SWT.PUSH | SWT.CENTER | style);
508
						FormData buttonRTLGroupCLData = new FormData();
509
						buttonRTLGroupCLData.left =  new FormAttachment(0, 1000, 400);
510
						buttonRTLGroupCLData.top =  new FormAttachment(0, 1000, 110);
511
						buttonRTLGroupCLData.width = 30;
512
						buttonRTLGroupCLData.height = 23;
513
						buttonRTLGroupC.setLayoutData(buttonRTLGroupCLData);
514
						buttonRTLGroupC.setText("RTL");
515
					}
516
					{
517
						FormData treeGroupCLData = new FormData();
518
						treeGroupCLData.width = 150;
519
						treeGroupCLData.height = 112;
520
						treeGroupCLData.left =  new FormAttachment(7, 1000, 0);
521
//						treeGroupCLData.right =  new FormAttachment(413, 1000, 0);
522
						treeGroupCLData.top =  new FormAttachment(26, 1000, 0);
523
//						treeGroupCLData.bottom =  new FormAttachment(988, 1000, 0);
524
						treeGroupC = new Tree(groupC, SWT.NONE | style);
525
						updateTree();
526
						treeGroupC.setLayoutData(treeGroupCLData);
527
					}
528
					{
529
						FormData coolBarGroupCLData = new FormData();
530
						coolBarGroupCLData.width = 223;
531
						coolBarGroupCLData.height = 22;
532
						coolBarGroupCLData.left =  new FormAttachment(458, 1000, 0);
533
						coolBarGroupCLData.right =  new FormAttachment(966, 1000, 0);
534
						coolBarGroupCLData.top =  new FormAttachment(26, 1000, 0);
535
						coolBarGroupCLData.bottom =  new FormAttachment(190, 1000, 0);
536
						coolBarGroupC = new CoolBar(groupC, SWT.NONE | style);
537
						updateCoolbar();
538
						coolBarGroupC.setLayoutData(coolBarGroupCLData);
539
//						{
540
//							coolItem1 = new CoolItem(coolBarGroupC, SWT.NONE | style);
541
//							coolItem1.setMinimumSize(new org.eclipse.swt.graphics.Point(48, 23));
542
//							coolItem1.setPreferredSize(new org.eclipse.swt.graphics.Point(48, 23));
543
//							coolItem1.setSize(48, 23);
544
//							{
545
//								toolBar1 = new ToolBar(coolBarGroupC, SWT.NONE | style);
546
//								coolItem1.setControl(toolBar1);
547
//							}
548
//						}
549
					}
550
					{
551
						FormData progressBarGroupCLData = new FormData();
552
						progressBarGroupCLData.width = 229;
553
						progressBarGroupCLData.height = 17;
554
						progressBarGroupCLData.left =  new FormAttachment(458, 1000, 0);
555
						progressBarGroupCLData.right =  new FormAttachment(980, 1000, 0);
556
						progressBarGroupCLData.top =  new FormAttachment(652, 1000, 0);
557
						progressBarGroupCLData.bottom =  new FormAttachment(779, 1000, 0);
558
						progressBarGroupC = new ProgressBar(groupC,  style | SWT.INDETERMINATE);
559
						progressBarGroupC.setLayoutData(progressBarGroupCLData);
560
					}
561
					{
562
						buttonLTRGroupC = new Button(groupC, SWT.PUSH | SWT.CENTER | style);
563
						FormData buttonLTRGroupCLData = new FormData();
564
						buttonLTRGroupCLData.width = 32;
565
						buttonLTRGroupCLData.height = 23;
566
						buttonLTRGroupCLData.left =  new FormAttachment(0, 1000, 362);
567
						buttonLTRGroupCLData.top =  new FormAttachment(0, 1000, 110);
568
						buttonLTRGroupC.setLayoutData(buttonLTRGroupCLData);
569
						buttonLTRGroupC.setText("LTR");
570
					}
571
				}
572
			}
573
			buttonRTLGroupA.addSelectionListener (bidiListener); 
574
			buttonLTRGroupA.addSelectionListener (bidiListener); 
575
			buttonRTLCompositeGroups.addSelectionListener (bidiListener); 
576
			buttonLTRCompositeGroups.addSelectionListener (bidiListener); 
577
			buttonListRTLCompositeGroups.addSelectionListener (bidiListener); 
578
			buttonListLTRCompositeGroups.addSelectionListener (bidiListener); 
579
			buttonLTRGroupC.addSelectionListener (bidiListener); 
580
			buttonRTLGroupC.addSelectionListener (bidiListener); 
581
			buttonLTRGroupD.addSelectionListener (bidiListener); 
582
			buttonRTLGroupD.addSelectionListener (bidiListener); 
583
		this.layout();
584
		} catch (Exception e) {
585
			e.printStackTrace();
586
		}
587
		setToolTipText("I'm " + (style == SWT.LEFT_TO_RIGHT ? "LTR" : "RTL"));
588
		this.compositeGroups = this;
589
		
590
		controls = new Control[]{groupD,
591
				tabFolderInGroupD,
592
//				cTabItem1,
593
				compositeInTabGtoupD,
594
				tableGroupD,
595
				labelSimpleText,
596
				textSingleGroupD,
597
				labelMultiText,
598
				textAriaGroupD,
599
				buttonLTRGroupD,
600
				buttonRTLGroupD,
601
				null,
602
				groupA,
603
				labelTextGroupA,
604
				labelPicture,
605
				buttonTextGroupA,
606
				buttonPic,
607
				buttonTextPicGroupA,
608
				comboDropDownGroupA,
609
				comboSimpleGroupA,
610
				buttonLTRGroupA,
611
				buttonRTLGroupA,
612
				null,
613
				groupC,
614
				treeGroupC,
615
				coolBarGroupC,
616
				progressBarGroupC,
617
				sliderGtoupC,
618
//				pushItem,
619
//				dropDownItem, 
620
//				radioItem,
621
//				checkItem,
622
//				textItem,
623
				buttonLTRGroupC,
624
				buttonRTLGroupC,
625
				null,
626
				list};
627
	}
628
	void setItemText(TableItem item, int i, String node) {
629
		int index = i % 3;
630
			tableData [index][0] = node;
631
			item.setText (tableData [index]);
632
	}
633
	void packColumns () {
634
		int columnCount = tableGroupD.getColumnCount(); 
635
		for (int i = 0; i < columnCount; i++) {
636
			TableColumn tableColumn = tableGroupD.getColumn(i);
637
			tableColumn.pack();
638
		}
639
	}
640
	void updateTree(){
641
		/* Create the image tree */	
642
		TreeItem treeRoots[];
643
		TreeItem item;
644
		Image image = instance.images[CombinedOrientationExample.ciClosedFolder];
645
		for (int i = 0; i < 4; i++) {
646
			item = new TreeItem (treeGroupC, SWT.NONE);
647
			setItemText(item, i, CombinedOrientationExample.getResourceString("Node_" + (i + 1)));
648
				item.setImage(image);
649
			if (i < 3) {
650
				TreeItem subitem = new TreeItem (item, SWT.NONE);
651
				setItemText(subitem, i, CombinedOrientationExample.getResourceString("Node_" + (i + 1) + "_1"));
652
					subitem.setImage(image);
653
				}
654
			}
655
		treeRoots = treeGroupC.getItems ();
656
		item = new TreeItem (treeRoots[1], SWT.NONE);
657
		setItemText(item, 1, CombinedOrientationExample.getResourceString("Node_2_2"));
658
			item.setImage(image);
659
		item = new TreeItem (item, SWT.NONE);
660
		setItemText(item, 1, CombinedOrientationExample.getResourceString("Node_2_2_1"));
661
			item.setImage(image);
662
		imageNode1 = treeRoots[0];
663
		packColumns(treeGroupC);
664
665
	}
666
	void updateCoolbar(){
667
		int style = getStyle(), itemStyle = 0;
668
669
		/* Compute the widget, item, and item toolBar styles */
670
		int toolBarStyle = SWT.FLAT;
671
		boolean vertical = false;
672
		style |= SWT.HORIZONTAL;
673
		toolBarStyle |= SWT.HORIZONTAL;
674
		style |= SWT.BORDER;
675
	
676
		/* Create the push button toolbar cool item */
677
		ToolBar toolBar = new ToolBar (coolBarGroupC, toolBarStyle);
678
		ToolItem item = new ToolItem (toolBar, SWT.PUSH);
679
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
680
		item.setToolTipText ("SWT.PUSH");
681
		item = new ToolItem (toolBar, SWT.PUSH);
682
		item.setImage (instance.images[CombinedOrientationExample.ciOpenFolder]);
683
		item.setToolTipText ("SWT.PUSH");
684
		item = new ToolItem (toolBar, SWT.PUSH);
685
		item.setImage (instance.images[CombinedOrientationExample.ciTarget]);
686
		item.setToolTipText ("SWT.PUSH");
687
		item = new ToolItem (toolBar, SWT.SEPARATOR);
688
		item = new ToolItem (toolBar, SWT.PUSH);
689
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
690
		item.setToolTipText ("SWT.PUSH");
691
		item = new ToolItem (toolBar, SWT.PUSH);
692
		item.setImage (instance.images[CombinedOrientationExample.ciOpenFolder]);
693
		item.setToolTipText ("SWT.PUSH");		
694
		pushItem = new CoolItem (coolBarGroupC, itemStyle);
695
		pushItem.setControl (toolBar);
696
		pushItem.addSelectionListener (new CoolItemSelectionListener());
697
				
698
		/* Create the dropdown toolbar cool item */
699
		toolBar = new ToolBar (coolBarGroupC, toolBarStyle);
700
		item = new ToolItem (toolBar, SWT.DROP_DOWN);
701
		item.setImage (instance.images[CombinedOrientationExample.ciOpenFolder]);
702
		item.setToolTipText ("SWT.DROP_DOWN");
703
//		item.addSelectionListener (new DropDownSelectionListener());
704
		item = new ToolItem (toolBar, SWT.DROP_DOWN);
705
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
706
		item.setToolTipText ("SWT.DROP_DOWN");
707
//		item.addSelectionListener (new DropDownSelectionListener());
708
		dropDownItem = new CoolItem (coolBarGroupC, itemStyle);
709
		dropDownItem.setControl (toolBar);
710
		dropDownItem.addSelectionListener (new CoolItemSelectionListener());
711
712
		/* Create the radio button toolbar cool item */
713
		toolBar = new ToolBar (coolBarGroupC, toolBarStyle);
714
		item = new ToolItem (toolBar, SWT.RADIO);
715
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
716
		item.setToolTipText ("SWT.RADIO");
717
		item = new ToolItem (toolBar, SWT.RADIO);
718
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
719
		item.setToolTipText ("SWT.RADIO");
720
		item = new ToolItem (toolBar, SWT.RADIO);
721
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
722
		item.setToolTipText ("SWT.RADIO");
723
		radioItem = new CoolItem (coolBarGroupC, itemStyle);
724
		radioItem.setControl (toolBar);
725
		radioItem.addSelectionListener (new CoolItemSelectionListener());
726
		
727
		/* Create the check button toolbar cool item */
728
		toolBar = new ToolBar (coolBarGroupC, toolBarStyle);
729
		item = new ToolItem (toolBar, SWT.CHECK);
730
		item.setImage (instance.images[CombinedOrientationExample.ciClosedFolder]);
731
		item.setToolTipText ("SWT.CHECK");
732
		item = new ToolItem (toolBar, SWT.CHECK);
733
		item.setImage (instance.images[CombinedOrientationExample.ciTarget]);
734
		item.setToolTipText ("SWT.CHECK");
735
		item = new ToolItem (toolBar, SWT.CHECK);
736
		item.setImage (instance.images[CombinedOrientationExample.ciOpenFolder]);
737
		item.setToolTipText ("SWT.CHECK");
738
		item = new ToolItem (toolBar, SWT.CHECK);
739
		item.setImage (instance.images[CombinedOrientationExample.ciTarget]);
740
		item.setToolTipText ("SWT.CHECK");
741
		checkItem = new CoolItem (coolBarGroupC, itemStyle);
742
		checkItem.setControl (toolBar);
743
		checkItem.addSelectionListener (new CoolItemSelectionListener());
744
		
745
		/* Create the text cool item */
746
		if (!vertical) {
747
			Text text = new Text (coolBarGroupC, SWT.BORDER | SWT.SINGLE);
748
			textItem = new CoolItem (coolBarGroupC, itemStyle);
749
			textItem.setControl (text);
750
			textItem.addSelectionListener (new CoolItemSelectionListener());
751
			Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
752
			textSize = textItem.computeSize(textSize.x, textSize.y);
753
			textItem.setMinimumSize(textSize);
754
			textItem.setPreferredSize(textSize);
755
			textItem.setSize(textSize);
756
		}
757
758
		/* Set the sizes after adding all cool items */
759
		CoolItem[] coolItems = coolBarGroupC.getItems();
760
		for (int i = 0; i < coolItems.length; i++) {
761
			CoolItem coolItem = coolItems[i];
762
			Control control = coolItem.getControl();
763
			Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
764
			Point coolSize = coolItem.computeSize(size.x, size.y);
765
			if (control instanceof ToolBar) {
766
				ToolBar bar = (ToolBar)control;
767
				if (bar.getItemCount() > 0) {
768
					if (vertical) {
769
						size.y = bar.getItem(0).getBounds().height;
770
					} else {
771
						size.x = bar.getItem(0).getWidth();
772
					}
773
				}
774
			}
775
			coolItem.setMinimumSize(size);
776
			coolItem.setPreferredSize(coolSize);
777
			coolItem.setSize(coolSize);
778
		}		
779
	}
780
	void setItemText(TreeItem item, int i, String node) {
781
		int index = i % 3;
782
			tableData [index][0] = node;
783
			item.setText (tableData [index]);
784
	}
785
	void packColumns (Tree tree) {
786
			int columnCount = tree.getColumnCount();
787
			for (int i = 0; i < columnCount; i++) {
788
				TreeColumn treeColumn = tree.getColumn(i);
789
				treeColumn.pack();
790
			}
791
	}
792
	void setOrientationItemFromList(int[] indexArr, int orientation){
793
	    for (int i = 0; i < indexArr.length; i++) {
794
	        controls[indexArr[i]].setOrientation(orientation);
795
	      }
796
	}
797
	class CoolItemSelectionListener extends SelectionAdapter {
798
		private Menu menu = null;
799
		
800
		public void widgetSelected(SelectionEvent event) {
801
			/**
802
			 * A selection event will be fired when the cool item
803
			 * is selected by its gripper or if the drop down arrow
804
			 * (or 'chevron') is selected. Examine the event detail
805
			 * to determine where the widget was selected.
806
			 */
807
			if (event.detail == SWT.ARROW) {
808
				/* If the popup menu is already up (i.e. user pressed arrow twice),
809
				 * then dispose it.
810
				 */
811
				if (menu != null) {
812
					menu.dispose();
813
					menu = null;
814
					return;
815
				}
816
				
817
				/* Get the cool item and convert its bounds to display coordinates. */
818
				CoolItem coolItem = (CoolItem) event.widget;
819
				Rectangle itemBounds = coolItem.getBounds ();
820
				itemBounds.width = event.x - itemBounds.x;
821
				Point pt = coolBarGroupC.toDisplay(new Point (itemBounds.x, itemBounds.y));
822
				itemBounds.x = pt.x;
823
				itemBounds.y = pt.y;
824
				
825
				/* Get the toolbar from the cool item. */
826
				ToolBar toolBar = (ToolBar) coolItem.getControl ();
827
				ToolItem[] tools = toolBar.getItems ();
828
				int toolCount = tools.length;
829
								
830
				/* Convert the bounds of each tool item to display coordinates,
831
				 * and determine which ones are past the bounds of the cool item.
832
				 */
833
				int i = 0;
834
				while (i < toolCount) {
835
					Rectangle toolBounds = tools[i].getBounds ();
836
					pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y));
837
					toolBounds.x = pt.x;
838
					toolBounds.y = pt.y;
839
			  		Rectangle intersection = itemBounds.intersection (toolBounds);
840
			  		if (!intersection.equals (toolBounds)) break;
841
			  		i++;
842
				}
843
				
844
				/* Create a pop-up menu with items for each of the hidden buttons. */
845
				menu = new Menu (getShell(), SWT.POP_UP | (coolBarGroupC.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT)));
846
				for (int j = i; j < toolCount; j++) {
847
					ToolItem tool = tools[j];
848
					Image image = tool.getImage();
849
					if (image == null) {
850
						new MenuItem (menu, SWT.SEPARATOR);
851
					} else {
852
						if ((tool.getStyle() & SWT.DROP_DOWN) != 0) {
853
							MenuItem menuItem = new MenuItem (menu, SWT.CASCADE);
854
							menuItem.setImage(image);
855
							String text = tool.getToolTipText();
856
							if (text != null) menuItem.setText(text);
857
							Menu m = new Menu(menu);
858
							menuItem.setMenu(m);
859
							for (int k = 0; k < 9; ++k) {
860
								text = ControlExample.getResourceString("DropDownData_" + k);
861
								if (text.length() != 0) {
862
									MenuItem mi = new MenuItem(m, SWT.NONE);
863
									mi.setText(text);
864
									/* Application code to perform the action for the submenu item would go here. */
865
								} else {
866
									new MenuItem(m, SWT.SEPARATOR);
867
								}
868
							}
869
						} else {
870
							MenuItem menuItem = new MenuItem (menu, SWT.NONE);
871
							menuItem.setImage(image);
872
							String text = tool.getToolTipText();
873
							if (text != null) menuItem.setText(text);
874
						}
875
						/* Application code to perform the action for the menu item would go here. */
876
					}
877
				}
878
				
879
				/* Display the pop-up menu at the lower left corner of the arrow button.
880
				 * Dispose the menu when the user is done with it.
881
				 */
882
				pt = coolBarGroupC.toDisplay(new Point(event.x, event.y));
883
				menu.setLocation (pt.x, pt.y);
884
				menu.setVisible (true);
885
				while (menu != null && !menu.isDisposed() && menu.isVisible ()) {
886
					if (!getDisplay().readAndDispatch ()) getDisplay().sleep ();
887
				}
888
				if (menu != null) {
889
					menu.dispose ();
890
					menu = null;
891
				}
892
			}
893
		}
894
	}
895
896
}
(-)src/org/eclipse/swt/examples/mirroringTest/CombinedBasic.java (+164 lines)
Added Link Here
1
package org.eclipse.swt.examples.mirroringTest;
2
import org.eclipse.swt.*;
3
import org.eclipse.swt.events.SelectionAdapter;
4
import org.eclipse.swt.events.SelectionEvent;
5
import org.eclipse.swt.events.SelectionListener;
6
import org.eclipse.swt.graphics.Color;
7
import org.eclipse.swt.graphics.Point;
8
import org.eclipse.swt.graphics.Rectangle;
9
10
import org.eclipse.swt.layout.FillLayout;
11
import org.eclipse.swt.layout.FormAttachment;
12
import org.eclipse.swt.layout.FormData;
13
import org.eclipse.swt.layout.FormLayout;
14
import org.eclipse.swt.widgets.Button;
15
import org.eclipse.swt.widgets.Composite;
16
import org.eclipse.swt.widgets.Display;
17
import org.eclipse.swt.widgets.Menu;
18
import org.eclipse.swt.widgets.MenuItem;
19
import org.eclipse.swt.widgets.Shell;
20
21
public class CombinedBasic extends org.eclipse.swt.widgets.Composite {
22
	private Menu menu1;
23
	private Menu fileMenu;
24
	private MenuItem fileMenuItem;
25
	private MenuItem aboutMenuItem;
26
	private MenuItem contentsMenuItem;
27
	private Menu helpMenu;
28
	private MenuItem helpMenuItem;
29
	private MenuItem exitMenuItem;
30
	private MenuItem closeFileMenuItem;
31
	private MenuItem saveFileMenuItem;
32
	private MenuItem newFileMenuItem;
33
	private MenuItem openFileMenuItem;
34
35
	private Button buttonLTRFocused;
36
	private Button buttonRTLFocused;
37
//	private Button buttonRTLShell;
38
//	private Button buttonLTRShell;
39
40
	private CombineComposition composition1;// = new CombineComposition(this, getStyle() | SWT.LEFT_TO_RIGHT);
41
	private CombineComposition composition2;// = new CombineComposition(this, getStyle() | SWT.RIGHT_TO_LEFT);
42
43
	public CombinedBasic(Composite parent, int style, CombinedOrientationExample instance) {
44
		super(parent, style);
45
		initGUI(instance);
46
	}
47
48
	/**
49
	* Initializes the GUI.
50
	*/
51
	private void initGUI(CombinedOrientationExample instance) {
52
		/* Add the listeners */
53
		SelectionListener setOrientationListener = new SelectionAdapter() {
54
			public void widgetSelected(SelectionEvent event) {
55
				int flag = event.widget == buttonRTLFocused ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; 
56
			}
57
		};
58
		try {
59
			this.setSize(1049, 612);
60
			this.setBackground(new Color(Display.getDefault(),192, 192, 192));
61
			FormLayout thisLayout = new FormLayout();
62
			this.setLayout(thisLayout);
63
			{
64
				composition1 = new CombineComposition(this, getStyle() | SWT.LEFT_TO_RIGHT, instance);
65
				FormLayout compositeGroupsLayout = new FormLayout();
66
				FormData compositeGroupsLData = new FormData();
67
				compositeGroupsLData.left =  new FormAttachment(0, 1000, 10);
68
				compositeGroupsLData.top =  new FormAttachment(0, 1000, 7);
69
				compositeGroupsLData.width = 612;
70
				compositeGroupsLData.height = 605;
71
				composition1.setLayoutData(compositeGroupsLData);
72
				composition1.setLayout(compositeGroupsLayout);		
73
			}
74
			{
75
				composition2 = new CombineComposition(this,  SWT.RIGHT_TO_LEFT, instance);
76
				FormLayout compositeGroupsLayout = new FormLayout();
77
				FormData compositeGroupsLData = new FormData();
78
				compositeGroupsLData.left =  new FormAttachment(0, 1000, 632);
79
				compositeGroupsLData.top =  new FormAttachment(0, 1000, 7);
80
				compositeGroupsLData.width = 612;
81
				compositeGroupsLData.height = 605;
82
				composition2.setLayoutData(compositeGroupsLData);
83
				composition2.setLayout(compositeGroupsLayout);						
84
			}
85
			{
86
				menu1 = new Menu(getShell(), SWT.BAR);
87
				getShell().setMenuBar(menu1);
88
				{
89
					fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
90
					fileMenuItem.setText("File");
91
					{
92
						fileMenu = new Menu(fileMenuItem);
93
						{
94
							openFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
95
							openFileMenuItem.setText("Open");
96
						}
97
						{
98
							newFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
99
							newFileMenuItem.setText("New");
100
						}
101
						{
102
							saveFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
103
							saveFileMenuItem.setText("Save");
104
						}
105
						{
106
							closeFileMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
107
							closeFileMenuItem.setText("Close");
108
						}
109
						{
110
							exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
111
							exitMenuItem.setText("Exit");
112
						}
113
						fileMenuItem.setMenu(fileMenu);
114
					}
115
				}
116
				{
117
					helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
118
					helpMenuItem.setText("Help");
119
					{
120
						helpMenu = new Menu(helpMenuItem);
121
						{
122
							contentsMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
123
							contentsMenuItem.setText("Contents");
124
						}
125
						{
126
							aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
127
							aboutMenuItem.setText("About");
128
						}
129
						helpMenuItem.setMenu(helpMenu);
130
					}
131
				}
132
			}
133
			this.layout();
134
		} catch (Exception e) {
135
			e.printStackTrace();
136
		}
137
	}
138
	
139
	/**
140
	* Auto-generated main method to display this 
141
	* org.eclipse.swt.widgets.Composite inside a new Shell.
142
	
143
	public static void main(String[] args) {
144
		Display display = Display.getDefault();
145
		Shell shell = new Shell(display);
146
		CombinedBasic inst = new CombinedBasic(shell, SWT.NULL);
147
		Point size = inst.getSize();
148
		shell.setLayout(new FillLayout());
149
		shell.layout();
150
		if(size.x == 0 && size.y == 0) {
151
			inst.pack();
152
			shell.pack();
153
		} else {
154
			Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
155
			shell.setSize(shellBounds.width, shellBounds.height);
156
		}
157
		shell.open();
158
		while (!shell.isDisposed()) {
159
			if (!display.readAndDispatch())
160
				display.sleep();
161
		}
162
	}
163
*/
164
}
(-)src/org/eclipse/swt/examples/mirroringTest/CombinedOrientationExample.java (+202 lines)
Added Link Here
1
package org.eclipse.swt.examples.mirroringTest;
2
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.text.MessageFormat;
6
import java.util.MissingResourceException;
7
import java.util.ResourceBundle;
8
9
import org.eclipse.swt.SWT;
10
import org.eclipse.swt.events.SelectionAdapter;
11
import org.eclipse.swt.events.SelectionEvent;
12
import org.eclipse.swt.events.SelectionListener;
13
import org.eclipse.swt.graphics.Image;
14
import org.eclipse.swt.graphics.ImageData;
15
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.graphics.Rectangle;
17
import org.eclipse.swt.layout.FormAttachment;
18
import org.eclipse.swt.layout.FormData;
19
import org.eclipse.swt.layout.FormLayout;
20
import org.eclipse.swt.layout.RowLayout;
21
import org.eclipse.swt.widgets.Button;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Display;
24
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.TabFolder;
26
import org.eclipse.swt.widgets.TabItem;
27
import java.util.HashMap;
28
import java.util.Iterator;
29
import java.util.Vector;
30
31
public class CombinedOrientationExample {
32
33
	protected static ResourceBundle resourceBundle =
34
		ResourceBundle.getBundle("examples_control"); //$NON-NLS-1$
35
	protected CombinedBasic combineBasic;
36
	Image images[];
37
	Shell shell;
38
39
	static final int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2, ciBackground = 3, ciParentBackground = 4;
40
	static final String[] imageLocations = {
41
		"/org/eclipse/swt/examples/controlexample/closedFolder.gif", 			//$NON-NLS-1$
42
		"/org/eclipse/swt/examples/controlexample/openFolder.gif", 				//$NON-NLS-1$
43
		"/org/eclipse/swt/examples/controlexample/target.gif", 					//$NON-NLS-1$
44
		"/org/eclipse/swt/examples/controlexample/backgroundImage.png", 			//$NON-NLS-1$
45
		"/org/eclipse/swt/examples/controlexample/parentBackgroundImage.png"}; 	//$NON-NLS-1$
46
	static final int[] imageTypes = {
47
		SWT.ICON,
48
		SWT.ICON,
49
		SWT.ICON,
50
		SWT.BITMAP,
51
		SWT.BITMAP};
52
	boolean startup = true;
53
	/**
54
	 * Creates an instance of a ControlExample embedded inside
55
	 * the supplied parent Composite.
56
	 * 
57
	 * @param parent the container of the example
58
	 */
59
	public CombinedOrientationExample(Shell parent) {
60
		initResources();
61
		this.shell = parent;
62
		combineBasic = new CombinedBasic(parent, SWT.LEFT_TO_RIGHT, this);
63
		startup = false;
64
	}
65
	/**
66
	 * Loads the resources
67
	 */
68
	void initResources() {
69
		final Class clazz = ControlExample.class;
70
		if (resourceBundle != null) {
71
			try {
72
				if (images == null) {
73
					images = new Image[imageLocations.length];
74
					
75
					for (int i = 0; i < imageLocations.length; ++i) {
76
						InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]);
77
						ImageData source = new ImageData(sourceStream);
78
						if (imageTypes[i] == SWT.ICON) {
79
							ImageData mask = source.getTransparencyMask();
80
							images[i] = new Image(null, source, mask);
81
						} else {
82
							images[i] = new Image(null, source);
83
						}
84
						try {
85
							sourceStream.close();
86
						} catch (IOException e) {
87
							e.printStackTrace();
88
						}
89
					}
90
				}
91
				return;
92
			} catch (Throwable t) {
93
			}
94
		}
95
		String error = (resourceBundle != null) ?
96
			getResourceString("error.CouldNotLoadResources") :
97
			"Unable to load resources"; //$NON-NLS-1$
98
		freeResources();
99
		throw new RuntimeException(error);
100
	}
101
	/**
102
	 * Gets a string from the resource bundle.
103
	 * We don't want to crash because of a missing String.
104
	 * Returns the key if not found.
105
	 */
106
	static String getResourceString(String key) {
107
		try {
108
			return resourceBundle.getString(key)+"...";
109
		} catch (MissingResourceException e) {
110
			return key;
111
		} catch (NullPointerException e) {
112
			return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
113
		}			
114
	}
115
116
	/**
117
	 * Gets a string from the resource bundle and binds it
118
	 * with the given arguments. If the key is not found,
119
	 * return the key.
120
	 */
121
	static String getResourceString(String key, Object[] args) {
122
		try {
123
			return MessageFormat.format(getResourceString(key), args);
124
		} catch (MissingResourceException e) {
125
			return key;
126
		} catch (NullPointerException e) {
127
			return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
128
		}
129
	}
130
	/**
131
	 * Disposes of all resources associated with a particular
132
	 * instance of the ControlExample.
133
	 */	
134
	public void dispose() {
135
		/*
136
		 * Destroy any shells that may have been created
137
		 * by the Shells tab.  When a shell is disposed,
138
		 * all child shells are also disposed.  Therefore
139
		 * it is necessary to check for disposed shells
140
		 * in the shells list to avoid disposing a shell
141
		 * twice.
142
		 */
143
//		tabFolder = null;
144
		freeResources();
145
	}
146
147
	/**
148
	 * Frees the resources
149
	 */
150
	void freeResources() {
151
		if (images != null) {
152
			for (int i = 0; i < images.length; ++i) {
153
				final Image image = images[i];
154
				if (image != null) image.dispose();
155
			}
156
			images = null;
157
		}
158
	}
159
	/**
160
	 * @param args
161
	 */
162
	public static void main(String[] args) {
163
		Display display = new Display();
164
		final Shell shell = new Shell(display, SWT.SHELL_TRIM);
165
		shell.setLayout(new RowLayout());
166
		//CombinedBasic instance = new CombinedBasic(shell, 0, this);
167
		CombinedOrientationExample instance = new CombinedOrientationExample(shell);
168
		
169
		final Button buttonRtl = new Button(shell, SWT.PUSH);
170
		buttonRtl.setText("Shell RTL");
171
		final Button buttonLtr = new Button(shell, SWT.PUSH);
172
		buttonLtr.setText("Shell LTR");
173
174
		/* Add the listeners */
175
		SelectionListener setOrientationListener = new SelectionAdapter() {
176
			public void widgetSelected(SelectionEvent event) {
177
				int flag = event.widget == buttonRtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; 
178
            	shell.setOrientation(flag);
179
			}
180
		};
181
		buttonRtl.addSelectionListener(setOrientationListener);
182
		buttonLtr.addSelectionListener(setOrientationListener);
183
		shell.setText(getResourceString("window.title"));
184
		setShellSize(instance, shell);
185
		shell.open();
186
		while (! shell.isDisposed()) {
187
			if (! display.readAndDispatch()) display.sleep();
188
		}
189
		instance.dispose();
190
		display.dispose();
191
	}
192
	/**
193
	 * Sets the size of the shell to it's "packed" size,
194
	 * unless that makes it larger than the monitor it is being displayed on,
195
	 * in which case just set the shell size to be slightly smaller than the monitor.
196
	 */
197
	static void setShellSize(CombinedOrientationExample instance, Shell shell) {
198
		Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
199
		Rectangle monitorArea = shell.getMonitor().getClientArea();
200
		shell.setSize(Math.min(size.x, monitorArea.width), Math.min(size.y, monitorArea.height));
201
	}
202
}
(-)src/org/eclipse/swt/examples/mirroringTest/ComboTab.java (+148 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.events.*;
17
import org.eclipse.swt.layout.*;
18
19
class ComboTab extends Tab {
20
21
	/* Example widgets and groups that contain them */
22
	Combo combo1;
23
	Group comboGroup;
24
	
25
	/* Style widgets added to the "Style" group */
26
	Button dropDownButton, readOnlyButton, simpleButton;
27
	
28
	static String [] ListData = {ControlExample.getResourceString("ListData0_0"),
29
								 ControlExample.getResourceString("ListData0_1"),
30
								 ControlExample.getResourceString("ListData0_2"),
31
								 ControlExample.getResourceString("ListData0_3"),
32
								 ControlExample.getResourceString("ListData0_4"),
33
								 ControlExample.getResourceString("ListData0_5"),
34
								 ControlExample.getResourceString("ListData0_6"),
35
								 ControlExample.getResourceString("ListData0_7"),
36
								 ControlExample.getResourceString("ListData0_8")};
37
38
	/**
39
	 * Creates the Tab within a given instance of ControlExample.
40
	 */
41
	ComboTab(ControlExample instance) {
42
		super(instance);
43
	}
44
	
45
	/**
46
	 * Creates the "Example" group.
47
	 */
48
	void createExampleGroup () {
49
		super.createExampleGroup ();
50
		
51
		/* Create a group for the combo box */
52
		comboGroup = new Group (exampleGroup, SWT.NONE);
53
		comboGroup.setLayout (new GridLayout ());
54
		comboGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
55
		comboGroup.setText ("Combo");
56
	}
57
	
58
	/**
59
	 * Creates the "Example" widgets.
60
	 */
61
	void createExampleWidgets () {
62
		
63
		/* Compute the widget style */
64
		int style = getDefaultStyle();
65
		if (dropDownButton.getSelection ()) style |= SWT.DROP_DOWN;
66
		if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
67
		if (simpleButton.getSelection ()) style |= SWT.SIMPLE;
68
		
69
		/* Create the example widgets */
70
		combo1 = new Combo (comboGroup, style);
71
		combo1.setItems (ListData);
72
		if (ListData.length >= 3) {
73
			combo1.setText(ListData [2]);
74
		}
75
	}
76
	
77
	/**
78
	 * Creates the tab folder page.
79
	 *
80
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
81
	 * @return the new page for the tab folder
82
	 */
83
	Composite createTabFolderPage (TabFolder tabFolder) {
84
		super.createTabFolderPage (tabFolder);
85
86
		/*
87
		 * Add a resize listener to the tabFolderPage so that
88
		 * if the user types into the example widget to change
89
		 * its preferred size, and then resizes the shell, we
90
		 * recalculate the preferred size correctly.
91
		 */
92
		tabFolderPage.addControlListener(new ControlAdapter() {
93
			public void controlResized(ControlEvent e) {
94
				setExampleWidgetSize ();
95
			}
96
		});
97
		
98
		return tabFolderPage;
99
	}
100
101
	/**
102
	 * Creates the "Style" group.
103
	 */
104
	void createStyleGroup () {
105
		super.createStyleGroup ();
106
	
107
		/* Create the extra widgets */
108
		dropDownButton = new Button (styleGroup, SWT.RADIO);
109
		dropDownButton.setText ("SWT.DROP_DOWN");
110
		simpleButton = new Button (styleGroup, SWT.RADIO);
111
		simpleButton.setText("SWT.SIMPLE");
112
		readOnlyButton = new Button (styleGroup, SWT.CHECK);
113
		readOnlyButton.setText ("SWT.READ_ONLY");
114
	}
115
	
116
	/**
117
	 * Gets the "Example" widget children.
118
	 */
119
	Widget [] getExampleWidgets () {
120
		return new Widget [] {combo1};
121
	}
122
	
123
	/**
124
	 * Returns a list of set/get API method names (without the set/get prefix)
125
	 * that can be used to set/get values in the example control(s).
126
	 */
127
	String[] getMethodNames() {
128
		return new String[] {"Items", "Orientation", "Selection", "Text", "TextLimit", "ToolTipText", "VisibleItemCount"};
129
	}
130
131
	/**
132
	 * Gets the text for the tab folder item.
133
	 */
134
	String getTabText () {
135
		return "Combo";
136
	}
137
	
138
	/**
139
	 * Sets the state of the "Example" widgets.
140
	 */
141
	void setExampleWidgetState () {
142
		super.setExampleWidgetState ();
143
		dropDownButton.setSelection ((combo1.getStyle () & SWT.DROP_DOWN) != 0);
144
		simpleButton.setSelection ((combo1.getStyle () & SWT.SIMPLE) != 0);
145
		readOnlyButton.setSelection ((combo1.getStyle () & SWT.READ_ONLY) != 0);
146
		readOnlyButton.setEnabled(!simpleButton.getSelection());
147
	}
148
}
(-)src/org/eclipse/swt/examples/mirroringTest/ControlExample.java (+265 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.graphics.*;
19
import org.eclipse.swt.layout.*;
20
import org.eclipse.swt.widgets.*;
21
import org.eclipse.swt.examples.controlexample.*;
22
23
import java.io.*;
24
import java.text.*;
25
import java.util.*;
26
27
public class ControlExample {
28
	protected static ResourceBundle resourceBundle =
29
		ResourceBundle.getBundle("examples_control"); //$NON-NLS-1$
30
	protected ShellTab shellTab;
31
	protected TabFolder tabFolder;
32
	protected Tab [] tabs;
33
	Image images[];
34
35
	static final int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2, ciBackground = 3, ciParentBackground = 4;
36
	static final String[] imageLocations = {
37
		"/org/eclipse/swt/examples/controlexample/closedFolder.gif", 			//$NON-NLS-1$
38
		"/org/eclipse/swt/examples/controlexample/openFolder.gif", 				//$NON-NLS-1$
39
		"/org/eclipse/swt/examples/controlexample/target.gif", 					//$NON-NLS-1$
40
		"/org/eclipse/swt/examples/controlexample/backgroundImage.png", 			//$NON-NLS-1$
41
		"/org/eclipse/swt/examples/controlexample/parentBackgroundImage.png"}; 	//$NON-NLS-1$
42
	static final int[] imageTypes = {
43
		SWT.ICON,
44
		SWT.ICON,
45
		SWT.ICON,
46
		SWT.BITMAP,
47
		SWT.BITMAP};
48
49
	boolean startup = true;
50
51
	/**
52
	 * Creates an instance of a ControlExample embedded inside
53
	 * the supplied parent Composite.
54
	 * 
55
	 * @param parent the container of the example
56
	 */
57
	public ControlExample(Composite parent) {
58
		initResources();
59
		tabFolder = new TabFolder (parent, SWT.NONE);
60
		tabs = createTabs();
61
		for (int i=0; i<tabs.length; i++) {
62
			TabItem item = new TabItem (tabFolder, SWT.NONE);
63
		    item.setText (tabs [i].getTabText ());
64
		    item.setControl (tabs [i].createTabFolderPage (tabFolder));
65
		    item.setData (tabs [i]);
66
		}
67
		
68
		/* Workaround: if the tab folder is wider than the screen,
69
		 * Mac platforms clip instead of somehow scrolling the tab items.
70
		 * We try to recover some width by using shorter tab names. */
71
		Point size = parent.computeSize(SWT.DEFAULT, SWT.DEFAULT);
72
		Rectangle monitorArea = parent.getMonitor().getClientArea();
73
		boolean isMac = SWT.getPlatform().equals("carbon") || SWT.getPlatform().equals("cocoa");
74
		if (size.x > monitorArea.width && isMac) {
75
			TabItem [] tabItems = tabFolder.getItems();
76
			for (int i=0; i<tabItems.length; i++) {
77
				tabItems[i].setText (tabs [i].getShortTabText ());
78
			}
79
		}
80
		startup = false;
81
	}
82
83
	/**
84
	 * Answers the set of example Tabs
85
	 */
86
	Tab[] createTabs() {
87
		return new Tab [] {
88
			new ButtonTab (this),
89
			new CanvasTab (this),
90
			new ComboTab (this),
91
			new CoolBarTab (this),
92
			new DateTimeTab (this),
93
			new DialogTab (this),
94
			new ExpandBarTab (this),
95
			new GroupTab (this),
96
			new LabelTab (this),
97
			new LinkTab (this),
98
			new ListTab (this),
99
			new MenuTab (this),
100
			new ProgressBarTab (this),
101
			new SashTab (this),
102
			new ScaleTab (this),
103
			shellTab = new ShellTab(this),
104
			new SliderTab (this),
105
			new SpinnerTab (this),
106
			new TabFolderTab (this),
107
			new TableTab (this),
108
			new TextTab (this),
109
			new ToolBarTab (this),
110
			new ToolTipTab (this),
111
			new TreeTab (this),
112
			new BrowserTab (this),
113
		};
114
	}
115
116
	/**
117
	 * Disposes of all resources associated with a particular
118
	 * instance of the ControlExample.
119
	 */	
120
	public void dispose() {
121
		/*
122
		 * Destroy any shells that may have been created
123
		 * by the Shells tab.  When a shell is disposed,
124
		 * all child shells are also disposed.  Therefore
125
		 * it is necessary to check for disposed shells
126
		 * in the shells list to avoid disposing a shell
127
		 * twice.
128
		 */
129
		if (shellTab != null) shellTab.closeAllShells ();
130
		shellTab = null;
131
		tabFolder = null;
132
		freeResources();
133
	}
134
135
	/**
136
	 * Frees the resources
137
	 */
138
	void freeResources() {
139
		if (images != null) {
140
			for (int i = 0; i < images.length; ++i) {
141
				final Image image = images[i];
142
				if (image != null) image.dispose();
143
			}
144
			images = null;
145
		}
146
	}
147
	
148
	/**
149
	 * Gets a string from the resource bundle.
150
	 * We don't want to crash because of a missing String.
151
	 * Returns the key if not found.
152
	 */
153
	static String getResourceString(String key) {
154
		try {
155
			return resourceBundle.getString(key)+"...";
156
		} catch (MissingResourceException e) {
157
			return key;
158
		} catch (NullPointerException e) {
159
			return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
160
		}			
161
	}
162
163
	/**
164
	 * Gets a string from the resource bundle and binds it
165
	 * with the given arguments. If the key is not found,
166
	 * return the key.
167
	 */
168
	static String getResourceString(String key, Object[] args) {
169
		try {
170
			return MessageFormat.format(getResourceString(key), args);
171
		} catch (MissingResourceException e) {
172
			return key;
173
		} catch (NullPointerException e) {
174
			return "!" + key + "!"; //$NON-NLS-1$ //$NON-NLS-2$
175
		}
176
	}
177
178
	/**
179
	 * Loads the resources
180
	 */
181
	void initResources() {
182
		final Class clazz = ControlExample.class;
183
		if (resourceBundle != null) {
184
			try {
185
				if (images == null) {
186
					images = new Image[imageLocations.length];
187
					
188
					for (int i = 0; i < imageLocations.length; ++i) {
189
						InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i]);
190
						ImageData source = new ImageData(sourceStream);
191
						if (imageTypes[i] == SWT.ICON) {
192
							ImageData mask = source.getTransparencyMask();
193
							images[i] = new Image(null, source, mask);
194
						} else {
195
							images[i] = new Image(null, source);
196
						}
197
						try {
198
							sourceStream.close();
199
						} catch (IOException e) {
200
							e.printStackTrace();
201
						}
202
					}
203
				}
204
				return;
205
			} catch (Throwable t) {
206
			}
207
		}
208
		String error = (resourceBundle != null) ?
209
			getResourceString("error.CouldNotLoadResources") :
210
			"Unable to load resources"; //$NON-NLS-1$
211
		freeResources();
212
		throw new RuntimeException(error);
213
	}
214
215
	/**
216
	 * Invokes as a standalone program.
217
	 */
218
	public static void main(String[] args) {
219
		Display display = new Display();
220
		final Shell shell = new Shell(display, SWT.SHELL_TRIM);
221
		shell.setLayout(new RowLayout());
222
		ControlExample instance = new ControlExample(shell);
223
		final Button buttonRtl = new Button(shell, SWT.PUSH);
224
		buttonRtl.setText("Shell RTL");
225
		final Button buttonLtr = new Button(shell, SWT.PUSH);
226
		buttonLtr.setText("Shell LTR");
227
228
		/* Add the listeners */
229
		SelectionListener setOrientationListener = new SelectionAdapter() {
230
			public void widgetSelected(SelectionEvent event) {
231
				int flag = event.widget == buttonRtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; 
232
            	shell.setOrientation(flag);
233
			}
234
		};
235
		buttonRtl.addSelectionListener(setOrientationListener);
236
		buttonLtr.addSelectionListener(setOrientationListener);
237
		shell.setText(getResourceString("window.title"));
238
		setShellSize(instance, shell);
239
		shell.open();
240
		while (! shell.isDisposed()) {
241
			if (! display.readAndDispatch()) display.sleep();
242
		}
243
		instance.dispose();
244
		display.dispose();
245
	}
246
	
247
	/**
248
	 * Grabs input focus.
249
	 */
250
	public void setFocus() {
251
		tabFolder.setFocus();
252
	}
253
	
254
	/**
255
	 * Sets the size of the shell to it's "packed" size,
256
	 * unless that makes it larger than the monitor it is being displayed on,
257
	 * in which case just set the shell size to be slightly smaller than the monitor.
258
	 */
259
	static void setShellSize(ControlExample instance, Shell shell) {
260
		Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
261
		Rectangle monitorArea = shell.getMonitor().getClientArea();
262
		shell.setSize(Math.min(size.x, monitorArea.width), Math.min(size.y, monitorArea.height));
263
	}
264
}
265
(-)src/org/eclipse/swt/examples/mirroringTest/ControlExampleRTL.java (+79 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.events.SelectionListener;
18
import org.eclipse.swt.graphics.*;
19
import org.eclipse.swt.layout.*;
20
import org.eclipse.swt.widgets.*;
21
22
import java.io.*;
23
import java.text.*;
24
import java.util.*;
25
26
public class ControlExampleRTL extends ControlExample{
27
28
	/**
29
	 * Creates an instance of a ControlExample embedded inside
30
	 * the supplied parent Composite.
31
	 * 
32
	 * @param parent the container of the example
33
	 */
34
	public ControlExampleRTL(Composite parent) {
35
		super(parent);
36
		
37
	}
38
39
40
41
	/**
42
	 * Invokes as a standalone program.
43
	 */
44
	public static void main(String[] args) {
45
		Display display = new Display();
46
		final Shell shell = new Shell(display, SWT.SHELL_TRIM);
47
		shell.setOrientation(SWT.RIGHT_TO_LEFT);
48
		shell.setLayout(new RowLayout());
49
		ControlExampleRTL instance = new ControlExampleRTL(shell);
50
		
51
		final Button buttonRtl = new Button(shell, SWT.PUSH);
52
		buttonRtl.setText("Shell RTL");
53
		final Button buttonLtr = new Button(shell, SWT.PUSH);
54
		buttonLtr.setText("Shell LTR");
55
56
		/* Add the listeners */
57
		SelectionListener setOrientationListener = new SelectionAdapter() {
58
			public void widgetSelected(SelectionEvent event) {
59
				int flag = event.widget == buttonRtl ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; 
60
            	shell.setOrientation(flag);
61
			}
62
		};
63
		buttonRtl.addSelectionListener(setOrientationListener);
64
		buttonLtr.addSelectionListener(setOrientationListener);
65
		
66
		shell.setText(getResourceString("window.title"));
67
		setShellSize(instance, shell);
68
		shell.open();
69
		
70
		while (! shell.isDisposed()) {
71
			if (! display.readAndDispatch()) display.sleep();
72
		}
73
		instance.dispose();
74
		display.dispose();
75
	}
76
	
77
78
}
79
(-)src/org/eclipse/swt/examples/mirroringTest/CoolBarTab.java (+491 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
 
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.layout.*;
18
import org.eclipse.swt.events.*;
19
20
class CoolBarTab extends Tab {
21
	/* Example widgets and group that contains them */
22
	CoolBar coolBar;
23
	CoolItem pushItem, dropDownItem, radioItem, checkItem, textItem;
24
	Group coolBarGroup;
25
	
26
	/* Style widgets added to the "Style" group */
27
	Button horizontalButton, verticalButton;
28
	Button dropDownButton, flatButton;
29
30
	/* Other widgets added to the "Other" group */
31
	Button lockedButton;
32
	
33
	Point[] sizes;
34
	int[] wrapIndices;
35
	int[] order;
36
	
37
	/**
38
	 * Creates the Tab within a given instance of ControlExample.
39
	 */
40
	CoolBarTab(ControlExample instance) {
41
		super(instance);
42
	}
43
	
44
	/**
45
	 * Creates the "Other" group.
46
	 */
47
	void createOtherGroup () {
48
		super.createOtherGroup ();
49
	
50
		/* Create display controls specific to this example */
51
		lockedButton = new Button (otherGroup, SWT.CHECK);
52
		lockedButton.setText (ControlExample.getResourceString("Locked"));
53
	
54
		/* Add the listeners */
55
		lockedButton.addSelectionListener (new SelectionAdapter () {
56
			public void widgetSelected (SelectionEvent event) {
57
				setWidgetLocked ();
58
			}
59
		});
60
	}
61
	
62
	/**
63
	 * Creates the "Example" group.
64
	 */
65
	void createExampleGroup () {
66
		super.createExampleGroup ();
67
		coolBarGroup = new Group (exampleGroup, SWT.NONE);
68
		coolBarGroup.setLayout (new GridLayout ());
69
		coolBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
70
		coolBarGroup.setText ("CoolBar");
71
	}
72
	
73
	/**
74
	 * Creates the "Example" widgets.
75
	 */
76
	void createExampleWidgets () {
77
		int style = getDefaultStyle(), itemStyle = 0;
78
79
		/* Compute the widget, item, and item toolBar styles */
80
		int toolBarStyle = SWT.FLAT;
81
		boolean vertical = false;
82
		if (horizontalButton.getSelection ()) {
83
			style |= SWT.HORIZONTAL;
84
			toolBarStyle |= SWT.HORIZONTAL;
85
		}
86
		if (verticalButton.getSelection ()) {
87
			style |= SWT.VERTICAL;
88
			toolBarStyle |= SWT.VERTICAL;
89
			vertical = true;
90
		}
91
		if (borderButton.getSelection()) style |= SWT.BORDER;
92
		if (flatButton.getSelection()) style |= SWT.FLAT;
93
		if (dropDownButton.getSelection()) itemStyle |= SWT.DROP_DOWN;
94
	
95
		/*
96
		* Create the example widgets.
97
		*/
98
		coolBar = new CoolBar (coolBarGroup, style);
99
		
100
		/* Create the push button toolbar cool item */
101
		ToolBar toolBar = new ToolBar (coolBar, toolBarStyle);
102
		ToolItem item = new ToolItem (toolBar, SWT.PUSH);
103
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
104
		item.setToolTipText ("SWT.PUSH");
105
		item = new ToolItem (toolBar, SWT.PUSH);
106
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
107
		item.setToolTipText ("SWT.PUSH");
108
		item = new ToolItem (toolBar, SWT.PUSH);
109
		item.setImage (instance.images[ControlExample.ciTarget]);
110
		item.setToolTipText ("SWT.PUSH");
111
		item = new ToolItem (toolBar, SWT.SEPARATOR);
112
		item = new ToolItem (toolBar, SWT.PUSH);
113
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
114
		item.setToolTipText ("SWT.PUSH");
115
		item = new ToolItem (toolBar, SWT.PUSH);
116
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
117
		item.setToolTipText ("SWT.PUSH");		
118
		pushItem = new CoolItem (coolBar, itemStyle);
119
		pushItem.setControl (toolBar);
120
		pushItem.addSelectionListener (new CoolItemSelectionListener());
121
				
122
		/* Create the dropdown toolbar cool item */
123
		toolBar = new ToolBar (coolBar, toolBarStyle);
124
		item = new ToolItem (toolBar, SWT.DROP_DOWN);
125
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
126
		item.setToolTipText ("SWT.DROP_DOWN");
127
		item.addSelectionListener (new DropDownSelectionListener());
128
		item = new ToolItem (toolBar, SWT.DROP_DOWN);
129
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
130
		item.setToolTipText ("SWT.DROP_DOWN");
131
		item.addSelectionListener (new DropDownSelectionListener());
132
		dropDownItem = new CoolItem (coolBar, itemStyle);
133
		dropDownItem.setControl (toolBar);
134
		dropDownItem.addSelectionListener (new CoolItemSelectionListener());
135
136
		/* Create the radio button toolbar cool item */
137
		toolBar = new ToolBar (coolBar, toolBarStyle);
138
		item = new ToolItem (toolBar, SWT.RADIO);
139
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
140
		item.setToolTipText ("SWT.RADIO");
141
		item = new ToolItem (toolBar, SWT.RADIO);
142
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
143
		item.setToolTipText ("SWT.RADIO");
144
		item = new ToolItem (toolBar, SWT.RADIO);
145
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
146
		item.setToolTipText ("SWT.RADIO");
147
		radioItem = new CoolItem (coolBar, itemStyle);
148
		radioItem.setControl (toolBar);
149
		radioItem.addSelectionListener (new CoolItemSelectionListener());
150
		
151
		/* Create the check button toolbar cool item */
152
		toolBar = new ToolBar (coolBar, toolBarStyle);
153
		item = new ToolItem (toolBar, SWT.CHECK);
154
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
155
		item.setToolTipText ("SWT.CHECK");
156
		item = new ToolItem (toolBar, SWT.CHECK);
157
		item.setImage (instance.images[ControlExample.ciTarget]);
158
		item.setToolTipText ("SWT.CHECK");
159
		item = new ToolItem (toolBar, SWT.CHECK);
160
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
161
		item.setToolTipText ("SWT.CHECK");
162
		item = new ToolItem (toolBar, SWT.CHECK);
163
		item.setImage (instance.images[ControlExample.ciTarget]);
164
		item.setToolTipText ("SWT.CHECK");
165
		checkItem = new CoolItem (coolBar, itemStyle);
166
		checkItem.setControl (toolBar);
167
		checkItem.addSelectionListener (new CoolItemSelectionListener());
168
		
169
		/* Create the text cool item */
170
		if (!vertical) {
171
			Text text = new Text (coolBar, SWT.BORDER | SWT.SINGLE);
172
			textItem = new CoolItem (coolBar, itemStyle);
173
			textItem.setControl (text);
174
			textItem.addSelectionListener (new CoolItemSelectionListener());
175
			Point textSize = text.computeSize(SWT.DEFAULT, SWT.DEFAULT);
176
			textSize = textItem.computeSize(textSize.x, textSize.y);
177
			textItem.setMinimumSize(textSize);
178
			textItem.setPreferredSize(textSize);
179
			textItem.setSize(textSize);
180
		}
181
182
		/* Set the sizes after adding all cool items */
183
		CoolItem[] coolItems = coolBar.getItems();
184
		for (int i = 0; i < coolItems.length; i++) {
185
			CoolItem coolItem = coolItems[i];
186
			Control control = coolItem.getControl();
187
			Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
188
			Point coolSize = coolItem.computeSize(size.x, size.y);
189
			if (control instanceof ToolBar) {
190
				ToolBar bar = (ToolBar)control;
191
				if (bar.getItemCount() > 0) {
192
					if (vertical) {
193
						size.y = bar.getItem(0).getBounds().height;
194
					} else {
195
						size.x = bar.getItem(0).getWidth();
196
					}
197
				}
198
			}
199
			coolItem.setMinimumSize(size);
200
			coolItem.setPreferredSize(coolSize);
201
			coolItem.setSize(coolSize);
202
		}
203
		
204
		/* If we have saved state, restore it */
205
		if (order != null && order.length == coolBar.getItemCount()) {
206
			coolBar.setItemLayout(order, wrapIndices, sizes);
207
		} else {
208
			coolBar.setWrapIndices(new int[] {1, 3});
209
		}
210
		
211
		/* Add a listener to resize the group box to match the coolbar */
212
		coolBar.addListener(SWT.Resize, new Listener() {
213
			public void handleEvent(Event event) {
214
				exampleGroup.layout();
215
			}
216
		});
217
	}
218
	
219
	/**
220
	 * Creates the "Style" group.
221
	 */
222
	void createStyleGroup() {
223
		super.createStyleGroup();
224
	
225
		/* Create the extra widgets */
226
		horizontalButton = new Button (styleGroup, SWT.RADIO);
227
		horizontalButton.setText ("SWT.HORIZONTAL");
228
		verticalButton = new Button (styleGroup, SWT.RADIO);
229
		verticalButton.setText ("SWT.VERTICAL");
230
		borderButton = new Button (styleGroup, SWT.CHECK);
231
		borderButton.setText ("SWT.BORDER");
232
		flatButton = new Button (styleGroup, SWT.CHECK);
233
		flatButton.setText ("SWT.FLAT");
234
		Group itemGroup = new Group(styleGroup, SWT.NONE);
235
		itemGroup.setLayout (new GridLayout ());
236
		itemGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
237
		itemGroup.setText(ControlExample.getResourceString("Item_Styles"));
238
		dropDownButton = new Button (itemGroup, SWT.CHECK);
239
		dropDownButton.setText ("SWT.DROP_DOWN");
240
	}
241
	
242
	/**
243
	 * Disposes the "Example" widgets.
244
	 */
245
	void disposeExampleWidgets () {
246
		/* store the state of the toolbar if applicable */
247
		if (coolBar != null) {
248
			sizes = coolBar.getItemSizes();
249
			wrapIndices = coolBar.getWrapIndices();
250
			order = coolBar.getItemOrder();
251
		}
252
		super.disposeExampleWidgets();	
253
	}
254
255
	/**
256
	 * Gets the "Example" widget children's items, if any.
257
	 *
258
	 * @return an array containing the example widget children's items
259
	 */
260
	Item [] getExampleWidgetItems () {
261
		return coolBar.getItems();
262
	}
263
	
264
	/**
265
	 * Gets the "Example" widget children.
266
	 */
267
	Widget [] getExampleWidgets () {
268
		return new Widget [] {coolBar};
269
	}
270
	
271
	/**
272
	 * Returns a list of set/get API method names (without the set/get prefix)
273
	 * that can be used to set/get values in the example control(s).
274
	 */
275
	String[] getMethodNames() {
276
		return new String[] {"ToolTipText"};
277
	}
278
279
	/**
280
	 * Gets the short text for the tab folder item.
281
	 */
282
	String getShortTabText() {
283
		return "CB";
284
	}
285
286
	/**
287
	 * Gets the text for the tab folder item.
288
	 */
289
	String getTabText () {
290
		return "CoolBar";
291
	}
292
	
293
	/**
294
	 * Sets the state of the "Example" widgets.
295
	 */
296
	void setExampleWidgetState () {
297
		super.setExampleWidgetState ();
298
		horizontalButton.setSelection ((coolBar.getStyle () & SWT.HORIZONTAL) != 0);
299
		verticalButton.setSelection ((coolBar.getStyle () & SWT.VERTICAL) != 0);
300
		borderButton.setSelection ((coolBar.getStyle () & SWT.BORDER) != 0);
301
		flatButton.setSelection ((coolBar.getStyle () & SWT.FLAT) != 0);
302
		dropDownButton.setSelection ((coolBar.getItem(0).getStyle () & SWT.DROP_DOWN) != 0);
303
		lockedButton.setSelection(coolBar.getLocked());
304
		if (!instance.startup) setWidgetLocked ();
305
	}
306
	
307
	/**
308
	 * Sets the header visible state of the "Example" widgets.
309
	 */
310
	void setWidgetLocked () {
311
		coolBar.setLocked (lockedButton.getSelection ());
312
	}
313
	
314
	/**
315
	 * Listens to widgetSelected() events on SWT.DROP_DOWN type ToolItems
316
	 * and opens/closes a menu when appropriate.
317
	 */
318
	class DropDownSelectionListener extends SelectionAdapter {
319
		private Menu menu = null;
320
		private boolean visible = false;
321
		
322
		public void widgetSelected(SelectionEvent event) {
323
			// Create the menu if it has not already been created
324
			if (menu == null) {
325
				// Lazy create the menu.
326
				menu = new Menu(shell, SWT.POP_UP | (coolBar.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT)));
327
				menu.addMenuListener(new MenuAdapter() {
328
					public void menuHidden(MenuEvent e) {
329
						visible = false;
330
					}
331
				});
332
				for (int i = 0; i < 9; ++i) {
333
					final String text = ControlExample.getResourceString("DropDownData_" + i);
334
					if (text.length() != 0) {
335
						MenuItem menuItem = new MenuItem(menu, SWT.NONE);
336
						menuItem.setText(text);
337
						/*
338
						 * Add a menu selection listener so that the menu is hidden
339
						 * when the user selects an item from the drop down menu.
340
						 */
341
						menuItem.addSelectionListener(new SelectionAdapter() {
342
							public void widgetSelected(SelectionEvent e) {
343
								setMenuVisible(false);
344
							}
345
						});
346
					} else {
347
						new MenuItem(menu, SWT.SEPARATOR);
348
					}
349
				}
350
			}
351
			
352
			/**
353
			 * A selection event will be fired when a drop down tool
354
			 * item is selected in the main area and in the drop
355
			 * down arrow.  Examine the event detail to determine
356
			 * where the widget was selected.
357
			 */		
358
			if (event.detail == SWT.ARROW) {
359
				/*
360
				 * The drop down arrow was selected.
361
				 */
362
				if (visible) {
363
					// Hide the menu to give the Arrow the appearance of being a toggle button.
364
					setMenuVisible(false);
365
				} else {	
366
					// Position the menu below and vertically aligned with the the drop down tool button.
367
					final ToolItem toolItem = (ToolItem) event.widget;
368
					final ToolBar  toolBar = toolItem.getParent();
369
					
370
					Rectangle toolItemBounds = toolItem.getBounds();
371
					Point point = toolBar.toDisplay(new Point(toolItemBounds.x, toolItemBounds.y));
372
					menu.setLocation(point.x, point.y + toolItemBounds.height);
373
					setMenuVisible(true);
374
				}
375
			} else {
376
				/*
377
				 * Main area of drop down tool item selected.
378
				 * An application would invoke the code to perform the action for the tool item.
379
				 */
380
			}
381
		}
382
		private void setMenuVisible(boolean visible) {
383
			menu.setVisible(visible);
384
			menu.setOrientation(menu.getParent().getOrientation());
385
			this.visible = visible;
386
		}
387
	}
388
389
	/**
390
	 * Listens to widgetSelected() events on SWT.DROP_DOWN type CoolItems
391
	 * and opens/closes a menu when appropriate.
392
	 */
393
	class CoolItemSelectionListener extends SelectionAdapter {
394
		private Menu menu = null;
395
		
396
		public void widgetSelected(SelectionEvent event) {
397
			/**
398
			 * A selection event will be fired when the cool item
399
			 * is selected by its gripper or if the drop down arrow
400
			 * (or 'chevron') is selected. Examine the event detail
401
			 * to determine where the widget was selected.
402
			 */
403
			if (event.detail == SWT.ARROW) {
404
				/* If the popup menu is already up (i.e. user pressed arrow twice),
405
				 * then dispose it.
406
				 */
407
				if (menu != null) {
408
					menu.dispose();
409
					menu = null;
410
					return;
411
				}
412
				
413
				/* Get the cool item and convert its bounds to display coordinates. */
414
				CoolItem coolItem = (CoolItem) event.widget;
415
				Rectangle itemBounds = coolItem.getBounds ();
416
				itemBounds.width = event.x - itemBounds.x;
417
				Point pt = coolBar.toDisplay(new Point (itemBounds.x, itemBounds.y));
418
				itemBounds.x = pt.x;
419
				itemBounds.y = pt.y;
420
				
421
				/* Get the toolbar from the cool item. */
422
				ToolBar toolBar = (ToolBar) coolItem.getControl ();
423
				ToolItem[] tools = toolBar.getItems ();
424
				int toolCount = tools.length;
425
								
426
				/* Convert the bounds of each tool item to display coordinates,
427
				 * and determine which ones are past the bounds of the cool item.
428
				 */
429
				int i = 0;
430
				while (i < toolCount) {
431
					Rectangle toolBounds = tools[i].getBounds ();
432
					pt = toolBar.toDisplay(new Point(toolBounds.x, toolBounds.y));
433
					toolBounds.x = pt.x;
434
					toolBounds.y = pt.y;
435
			  		Rectangle intersection = itemBounds.intersection (toolBounds);
436
			  		if (!intersection.equals (toolBounds)) break;
437
			  		i++;
438
				}
439
				
440
				/* Create a pop-up menu with items for each of the hidden buttons. */
441
				menu = new Menu (shell, SWT.POP_UP | (coolBar.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT)));
442
				for (int j = i; j < toolCount; j++) {
443
					ToolItem tool = tools[j];
444
					Image image = tool.getImage();
445
					if (image == null) {
446
						new MenuItem (menu, SWT.SEPARATOR);
447
					} else {
448
						if ((tool.getStyle() & SWT.DROP_DOWN) != 0) {
449
							MenuItem menuItem = new MenuItem (menu, SWT.CASCADE);
450
							menuItem.setImage(image);
451
							String text = tool.getToolTipText();
452
							if (text != null) menuItem.setText(text);
453
							Menu m = new Menu(menu);
454
							menuItem.setMenu(m);
455
							for (int k = 0; k < 9; ++k) {
456
								text = ControlExample.getResourceString("DropDownData_" + k);
457
								if (text.length() != 0) {
458
									MenuItem mi = new MenuItem(m, SWT.NONE);
459
									mi.setText(text);
460
									/* Application code to perform the action for the submenu item would go here. */
461
								} else {
462
									new MenuItem(m, SWT.SEPARATOR);
463
								}
464
							}
465
						} else {
466
							MenuItem menuItem = new MenuItem (menu, SWT.NONE);
467
							menuItem.setImage(image);
468
							String text = tool.getToolTipText();
469
							if (text != null) menuItem.setText(text);
470
						}
471
						/* Application code to perform the action for the menu item would go here. */
472
					}
473
				}
474
				
475
				/* Display the pop-up menu at the lower left corner of the arrow button.
476
				 * Dispose the menu when the user is done with it.
477
				 */
478
				pt = coolBar.toDisplay(new Point(event.x, event.y));
479
				menu.setLocation (pt.x, pt.y);
480
				menu.setVisible (true);
481
				while (menu != null && !menu.isDisposed() && menu.isVisible ()) {
482
					if (!display.readAndDispatch ()) display.sleep ();
483
				}
484
				if (menu != null) {
485
					menu.dispose ();
486
					menu = null;
487
				}
488
			}
489
		}
490
	}
491
}
(-)src/org/eclipse/swt/examples/mirroringTest/CustomControlExample.java (+58 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
import org.eclipse.swt.layout.*;
14
import org.eclipse.swt.widgets.*;
15
16
17
public class CustomControlExample extends ControlExample {
18
19
	/**
20
	 * Creates an instance of a CustomControlExample embedded
21
	 * inside the supplied parent Composite.
22
	 * 
23
	 * @param parent the container of the example
24
	 */
25
	public CustomControlExample(Composite parent) {
26
		super (parent);
27
	}
28
	
29
	/**
30
	 * Answers the set of example Tabs
31
	 */
32
	Tab[] createTabs() {
33
		return new Tab [] {
34
			new CComboTab (this),
35
			new CLabelTab (this),
36
			new CTabFolderTab (this),
37
			new SashFormTab (this),
38
			new StyledTextTab (this),
39
		};
40
	}
41
	
42
	/**
43
	 * Invokes as a standalone program.
44
	 */
45
	public static void main(String[] args) {
46
		Display display = new Display();
47
		Shell shell = new Shell(display);
48
		shell.setLayout(new FillLayout());
49
		CustomControlExample instance = new CustomControlExample(shell);
50
		shell.setText(getResourceString("custom.window.title"));
51
		setShellSize(instance, shell);
52
		shell.open();
53
		while (! shell.isDisposed()) {
54
			if (! display.readAndDispatch()) display.sleep();
55
		}
56
		instance.dispose();
57
	}
58
}
(-)src/org/eclipse/swt/examples/mirroringTest/DateTimeTab.java (+137 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
18
class DateTimeTab extends Tab {
19
	/* Example widgets and groups that contain them */
20
	DateTime dateTime1;
21
	Group dateTimeGroup;
22
	
23
	/* Style widgets added to the "Style" group */
24
	//Button /*dateButton, timeButton, calendarButton, shortButton, mediumButton, longButton, dropDownButton*/;
25
	
26
	/**
27
	 * Creates the Tab within a given instance of ControlExample.
28
	 */
29
	DateTimeTab(ControlExample instance) {
30
		super(instance);
31
	}
32
	
33
	/**
34
	 * Creates the "Example" group.
35
	 */
36
	void createExampleGroup () {
37
		super.createExampleGroup ();
38
		
39
		/* Create a group for the list */
40
		dateTimeGroup = new Group (exampleGroup, SWT.NONE);
41
		dateTimeGroup.setLayout (new GridLayout ());
42
		dateTimeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
43
		dateTimeGroup.setText ("Calendar");//("DateTime");
44
	}
45
	
46
	/**
47
	 * Creates the "Example" widgets.
48
	 */
49
	void createExampleWidgets () {
50
		
51
		/* Compute the widget style */
52
		int style = getDefaultStyle();
53
	/*	if (dateButton.getSelection ()) style |= SWT.DATE;
54
		if (timeButton.getSelection ()) style |= SWT.TIME;
55
		if (calendarButton.getSelection ()) style |= SWT.CALENDAR;
56
*/		style |= SWT.CALENDAR;
57
/*		if (shortButton.getSelection ()) style |= SWT.SHORT;
58
		if (mediumButton.getSelection ()) style |= SWT.MEDIUM;
59
		if (longButton.getSelection ()) style |= SWT.LONG;
60
		if (dropDownButton.getSelection ()) style |= SWT.DROP_DOWN;
61
   */	if (borderButton.getSelection ()) style |= SWT.BORDER;
62
	
63
		/* Create the example widgets */		
64
		dateTime1 = new DateTime (dateTimeGroup, style);
65
	}
66
	
67
	/**
68
	 * Creates the "Style" group.
69
	 */
70
	void createStyleGroup() {
71
		super.createStyleGroup ();
72
		
73
		/* Create the extra widgets */
74
/*		dateButton = new Button(styleGroup, SWT.RADIO);
75
		dateButton.setText("SWT.DATE");
76
		timeButton = new Button(styleGroup, SWT.RADIO);
77
		timeButton.setText("SWT.TIME");
78
		calendarButton = new Button(styleGroup, SWT.RADIO);
79
		calendarButton.setText("SWT.CALENDAR");
80
		Group formatGroup = new Group(styleGroup, SWT.NONE);
81
		formatGroup.setLayout(new GridLayout());
82
		shortButton = new Button(formatGroup, SWT.RADIO);
83
		shortButton.setText("SWT.SHORT");
84
		mediumButton = new Button(formatGroup, SWT.RADIO);
85
		mediumButton.setText("SWT.MEDIUM");
86
		longButton = new Button(formatGroup, SWT.RADIO);
87
		longButton.setText("SWT.LONG");
88
		dropDownButton = new Button(styleGroup, SWT.CHECK);
89
		dropDownButton.setText("SWT.DROP_DOWN");
90
*/		borderButton = new Button(styleGroup, SWT.CHECK);
91
		borderButton.setText("SWT.BORDER");
92
	}
93
	
94
	/**
95
	 * Gets the "Example" widget children.
96
	 */
97
	Widget [] getExampleWidgets () {
98
		return new Widget [] {dateTime1};
99
	}
100
	
101
	/**
102
	 * Returns a list of set/get API method names (without the set/get prefix)
103
	 * that can be used to set/get values in the example control(s).
104
	 */
105
	String[] getMethodNames() {
106
		return new String[] {"Day", "Hours", "Minutes", "Month", "Seconds", "Year"};
107
	}
108
	
109
	/**
110
	 * Gets the short text for the tab folder item.
111
	 */
112
	String getShortTabText() {
113
		return "DT";
114
	}
115
116
	/**
117
	 * Gets the text for the tab folder item.
118
	 */
119
	String getTabText () {
120
		return "DateTime";
121
	}
122
123
	/**
124
	 * Sets the state of the "Example" widgets.
125
	 */
126
	void setExampleWidgetState () {
127
		super.setExampleWidgetState ();
128
/*		dateButton.setSelection ((dateTime1.getStyle () & SWT.DATE) != 0);
129
		timeButton.setSelection ((dateTime1.getStyle () & SWT.TIME) != 0);
130
		calendarButton.setSelection ((dateTime1.getStyle () & SWT.CALENDAR) != 0);
131
		shortButton.setSelection ((dateTime1.getStyle () & SWT.SHORT) != 0);
132
		mediumButton.setSelection ((dateTime1.getStyle () & SWT.MEDIUM) != 0);
133
		longButton.setSelection ((dateTime1.getStyle () & SWT.LONG) != 0);
134
		dropDownButton.setSelection ((dateTime1.getStyle () & SWT.DROP_DOWN) != 0);
135
*/		borderButton.setSelection ((dateTime1.getStyle () & SWT.BORDER) != 0);
136
	}
137
}
(-)src/org/eclipse/swt/examples/mirroringTest/DialogTab.java (+521 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.layout.*;
18
import org.eclipse.swt.printing.*;
19
import org.eclipse.swt.events.*;
20
21
class DialogTab extends Tab {
22
	/* Example widgets and groups that contain them */
23
	Group dialogStyleGroup, resultGroup;
24
	Text textWidget;
25
	
26
	/* Style widgets added to the "Style" group */
27
	Combo dialogCombo;
28
	Button createButton;
29
	Button okButton, cancelButton;
30
	Button yesButton, noButton;
31
	Button retryButton;
32
	Button abortButton, ignoreButton;
33
	Button iconErrorButton, iconInformationButton, iconQuestionButton;
34
	Button iconWarningButton, iconWorkingButton, noIconButton;
35
	Button primaryModalButton, applicationModalButton, systemModalButton;
36
	Button sheetButton;
37
	Button saveButton, openButton, multiButton;
38
39
	static String [] FilterExtensions	= {"*.txt", "*.bat", "*.doc", "*"};
40
	static String [] FilterNames		= {ControlExample.getResourceString("FilterName_0"),
41
										   ControlExample.getResourceString("FilterName_1"),
42
										   ControlExample.getResourceString("FilterName_2"),
43
										   ControlExample.getResourceString("FilterName_3")};
44
45
	/**
46
	 * Creates the Tab within a given instance of ControlExample.
47
	 */
48
	DialogTab(ControlExample instance) {
49
		super(instance);
50
	}
51
52
	/**
53
	 * Handle a button style selection event.
54
	 *
55
	 * @param event the selection event
56
	 */
57
	void buttonStyleSelected(SelectionEvent event) {
58
		/*
59
		 * Only certain combinations of button styles are
60
		 * supported for various dialogs.  Make sure the
61
		 * control widget reflects only valid combinations.
62
		 */
63
		boolean ok = okButton.getSelection ();
64
		boolean cancel = cancelButton.getSelection ();
65
		boolean yes = yesButton.getSelection ();
66
		boolean no = noButton.getSelection ();
67
		boolean abort = abortButton.getSelection ();
68
		boolean retry = retryButton.getSelection ();
69
		boolean ignore = ignoreButton.getSelection ();
70
		
71
		okButton.setEnabled (!(yes || no || retry || abort || ignore));
72
		cancelButton.setEnabled (!(abort || ignore || (yes != no)));
73
		yesButton.setEnabled (!(ok || retry || abort || ignore || (cancel && !yes && !no)));
74
		noButton.setEnabled (!(ok || retry || abort || ignore || (cancel && !yes && !no)));
75
		retryButton.setEnabled (!(ok || yes || no));
76
		abortButton.setEnabled (!(ok || cancel || yes || no));
77
		ignoreButton.setEnabled (!(ok || cancel || yes || no));
78
		
79
		createButton.setEnabled (
80
				!(ok || cancel || yes || no || retry || abort || ignore) ||
81
				ok ||
82
				(ok && cancel) ||
83
				(yes && no) ||
84
				(yes && no && cancel) ||
85
				(retry && cancel) ||
86
				(abort && retry && ignore));
87
		
88
89
	}
90
	
91
	/**
92
	 * Handle the create button selection event.
93
	 *
94
	 * @param event org.eclipse.swt.events.SelectionEvent
95
	 */
96
	void createButtonSelected(SelectionEvent event) {
97
	
98
		/* Compute the appropriate dialog style */
99
		int style = getDefaultStyle();
100
		if (okButton.getEnabled () && okButton.getSelection ()) style |= SWT.OK;
101
		if (cancelButton.getEnabled () && cancelButton.getSelection ()) style |= SWT.CANCEL;
102
		if (yesButton.getEnabled () && yesButton.getSelection ()) style |= SWT.YES;
103
		if (noButton.getEnabled () && noButton.getSelection ()) style |= SWT.NO;
104
		if (retryButton.getEnabled () && retryButton.getSelection ()) style |= SWT.RETRY;
105
		if (abortButton.getEnabled () && abortButton.getSelection ()) style |= SWT.ABORT;
106
		if (ignoreButton.getEnabled () && ignoreButton.getSelection ()) style |= SWT.IGNORE;
107
		if (iconErrorButton.getEnabled () && iconErrorButton.getSelection ()) style |= SWT.ICON_ERROR;
108
		if (iconInformationButton.getEnabled () && iconInformationButton.getSelection ()) style |= SWT.ICON_INFORMATION;
109
		if (iconQuestionButton.getEnabled () && iconQuestionButton.getSelection ()) style |= SWT.ICON_QUESTION;
110
		if (iconWarningButton.getEnabled () && iconWarningButton.getSelection ()) style |= SWT.ICON_WARNING;
111
		if (iconWorkingButton.getEnabled () && iconWorkingButton.getSelection ()) style |= SWT.ICON_WORKING;
112
		if (primaryModalButton.getEnabled () && primaryModalButton.getSelection ()) style |= SWT.PRIMARY_MODAL;
113
		if (applicationModalButton.getEnabled () && applicationModalButton.getSelection ()) style |= SWT.APPLICATION_MODAL;
114
		if (systemModalButton.getEnabled () && systemModalButton.getSelection ()) style |= SWT.SYSTEM_MODAL;
115
		if (sheetButton.getSelection ()) style |= SWT.SHEET;
116
		if (saveButton.getEnabled () && saveButton.getSelection ()) style |= SWT.SAVE;
117
		if (openButton.getEnabled () && openButton.getSelection ()) style |= SWT.OPEN;
118
		if (multiButton.getEnabled () && multiButton.getSelection ()) style |= SWT.MULTI;
119
	
120
		/* Open the appropriate dialog type */
121
		String name = dialogCombo.getText ();
122
		
123
		if (name.equals (ControlExample.getResourceString("ColorDialog"))) {
124
			ColorDialog dialog = new ColorDialog (shell ,style);
125
			dialog.setRGB (new RGB (100, 100, 100));
126
			dialog.setText (ControlExample.getResourceString("Title"));
127
			RGB result = dialog.open ();
128
			textWidget.append (ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
129
			textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER);
130
			textWidget.append ("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
131
			return;
132
		}
133
		
134
		if (name.equals (ControlExample.getResourceString("DirectoryDialog"))) {
135
			DirectoryDialog dialog = new DirectoryDialog (shell, style);
136
			dialog.setMessage (ControlExample.getResourceString("Example_string"));
137
			dialog.setText (ControlExample.getResourceString("Title"));
138
			String result = dialog.open ();
139
			textWidget.append (ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
140
			textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER + Text.DELIMITER);
141
			return;
142
		}
143
		
144
		if (name.equals (ControlExample.getResourceString("FileDialog"))) {
145
			FileDialog dialog = new FileDialog (shell, style);
146
			dialog.setFileName (ControlExample.getResourceString("readme_txt"));
147
			dialog.setFilterNames (FilterNames);
148
			dialog.setFilterExtensions (FilterExtensions);
149
			dialog.setText (ControlExample.getResourceString("Title"));
150
			String result = dialog.open();
151
			textWidget.append (ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
152
			textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER);
153
			textWidget.append ("getFilterPath() =" + dialog.getFilterPath() + Text.DELIMITER);
154
			textWidget.append ("getFileName() =" + dialog.getFileName() + Text.DELIMITER);
155
			textWidget.append ("getFileNames() =" + Text.DELIMITER);
156
			String [] files = dialog.getFileNames ();
157
			for (int i=0; i<files.length; i++) {
158
				textWidget.append ("\t" + files [i] + Text.DELIMITER);
159
			}
160
			textWidget.append ("getFilterIndex() = " + dialog.getFilterIndex() + Text.DELIMITER + Text.DELIMITER);
161
			return;
162
		}
163
		
164
		if (name.equals (ControlExample.getResourceString("FontDialog"))) {
165
			FontDialog dialog = new FontDialog (shell, style);
166
			dialog.setText (ControlExample.getResourceString("Title"));
167
			FontData result = dialog.open ();
168
			textWidget.append (ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
169
			textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER);
170
			textWidget.append ("getFontList() =" + Text.DELIMITER);
171
			FontData [] fonts = dialog.getFontList ();
172
			if (fonts != null) {
173
				for (int i=0; i<fonts.length; i++) {
174
					textWidget.append ("\t" + fonts [i] + Text.DELIMITER);
175
				}
176
			}
177
			textWidget.append ("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
178
			return;
179
		}
180
		
181
		if (name.equals (ControlExample.getResourceString("PrintDialog"))) {
182
			PrintDialog dialog = new PrintDialog (shell, style);
183
			dialog.setText(ControlExample.getResourceString("Title"));
184
			PrinterData result = dialog.open ();
185
			textWidget.append (ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
186
			textWidget.append (ControlExample.getResourceString("Result", new String [] {"" + result}) + Text.DELIMITER);
187
			textWidget.append ("getScope() = " + dialog.getScope() + Text.DELIMITER);
188
			textWidget.append ("getStartPage() = " + dialog.getStartPage() + Text.DELIMITER);
189
			textWidget.append ("getEndPage() = " + dialog.getEndPage() + Text.DELIMITER);
190
			textWidget.append ("getPrintToFile() = " + dialog.getPrintToFile() + Text.DELIMITER);
191
			if (result != null) {
192
				textWidget.append ("result.fileName = " + result.fileName + Text.DELIMITER);
193
				textWidget.append ("result.orientation = " + (result.orientation == PrinterData.LANDSCAPE ? "PrinterData.LANDSCAPE" : "PrinterData.PORTRAIT") + Text.DELIMITER);
194
				textWidget.append ("result.copyCount = " + result.copyCount + Text.DELIMITER);
195
				textWidget.append ("result.collate = " + result.collate + Text.DELIMITER);
196
			}
197
			textWidget.append (Text.DELIMITER);
198
			return;
199
		}
200
	
201
		if (name.equals(ControlExample.getResourceString("MessageBox"))) {
202
			MessageBox dialog = new MessageBox (shell, style);
203
			dialog.setMessage (ControlExample.getResourceString("Example_string"));
204
			dialog.setText (ControlExample.getResourceString("Title"));
205
			int result = dialog.open ();
206
			textWidget.append (ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
207
			/*
208
			 * The resulting integer depends on the original
209
			 * dialog style.  Decode the result and display it.
210
			 */
211
			switch (result) {
212
				case SWT.OK:
213
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.OK"}));
214
					break;
215
				case SWT.YES:
216
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.YES"}));
217
					break;
218
				case SWT.NO:
219
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.NO"}));
220
					break;
221
				case SWT.CANCEL:
222
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.CANCEL"}));
223
					break;
224
				case SWT.ABORT: 
225
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.ABORT"}));
226
					break;
227
				case SWT.RETRY:
228
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.RETRY"}));
229
					break;
230
				case SWT.IGNORE:
231
					textWidget.append (ControlExample.getResourceString("Result", new String [] {"SWT.IGNORE"}));
232
					break;
233
				default:
234
					textWidget.append(ControlExample.getResourceString("Result", new String [] {"" + result}));
235
					break;
236
			}
237
			textWidget.append (Text.DELIMITER + Text.DELIMITER);
238
		}
239
	}
240
	
241
	/**
242
	 * Creates the "Control" group. 
243
	 */
244
	void createControlGroup () {
245
		/*
246
		 * Create the "Control" group.  This is the group on the
247
		 * right half of each example tab.  It consists of the
248
		 * style group, the display group and the size group.
249
		 */			
250
		controlGroup = new Group (tabFolderPage, SWT.NONE);
251
		GridLayout gridLayout= new GridLayout ();
252
		controlGroup.setLayout(gridLayout);
253
		gridLayout.numColumns = 2;
254
		gridLayout.makeColumnsEqualWidth = true;
255
		controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
256
		controlGroup.setText (ControlExample.getResourceString("Parameters"));
257
		
258
		/*
259
		 * Create a group to hold the dialog style combo box and
260
		 * create dialog button.
261
		 */
262
		dialogStyleGroup = new Group (controlGroup, SWT.NONE);
263
		dialogStyleGroup.setLayout (new GridLayout ());
264
		GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_CENTER);
265
		gridData.horizontalSpan = 2;
266
		dialogStyleGroup.setLayoutData (gridData);
267
		dialogStyleGroup.setText (ControlExample.getResourceString("Dialog_Type"));
268
	}
269
	
270
	/**
271
	 * Creates the "Control" widget children.
272
	 */
273
	void createControlWidgets () {
274
	
275
		/* Create the combo */
276
		String [] strings = {
277
			ControlExample.getResourceString("ColorDialog"), 
278
			ControlExample.getResourceString("DirectoryDialog"),
279
			ControlExample.getResourceString("FileDialog"),
280
			ControlExample.getResourceString("FontDialog"),
281
			ControlExample.getResourceString("PrintDialog"),
282
			ControlExample.getResourceString("MessageBox"),
283
		};
284
		dialogCombo = new Combo (dialogStyleGroup, SWT.READ_ONLY);
285
		dialogCombo.setItems (strings);
286
		dialogCombo.setText (strings [0]);
287
		dialogCombo.setVisibleItemCount(strings.length);
288
	
289
		/* Create the create dialog button */
290
		createButton = new Button(dialogStyleGroup, SWT.NONE);
291
		createButton.setText (ControlExample.getResourceString("Create_Dialog"));
292
		createButton.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
293
	
294
		/* Create a group for the various dialog button style controls */
295
		Group buttonStyleGroup = new Group (controlGroup, SWT.NONE);
296
		buttonStyleGroup.setLayout (new GridLayout ());
297
		buttonStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
298
		buttonStyleGroup.setText (ControlExample.getResourceString("Button_Styles"));
299
	
300
		/* Create the button style buttons */
301
		okButton = new Button (buttonStyleGroup, SWT.CHECK);
302
		okButton.setText ("SWT.OK");
303
		cancelButton = new Button (buttonStyleGroup, SWT.CHECK);
304
		cancelButton.setText ("SWT.CANCEL");
305
		yesButton = new Button (buttonStyleGroup, SWT.CHECK);
306
		yesButton.setText ("SWT.YES");
307
		noButton = new Button (buttonStyleGroup, SWT.CHECK);
308
		noButton.setText ("SWT.NO");
309
		retryButton = new Button (buttonStyleGroup, SWT.CHECK);
310
		retryButton.setText ("SWT.RETRY");
311
		abortButton = new Button (buttonStyleGroup, SWT.CHECK);
312
		abortButton.setText ("SWT.ABORT");
313
		ignoreButton = new Button (buttonStyleGroup, SWT.CHECK);
314
		ignoreButton.setText ("SWT.IGNORE");
315
	
316
		/* Create a group for the icon style controls */
317
		Group iconStyleGroup = new Group (controlGroup, SWT.NONE);
318
		iconStyleGroup.setLayout (new GridLayout ());
319
		iconStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
320
		iconStyleGroup.setText (ControlExample.getResourceString("Icon_Styles"));
321
	
322
		/* Create the icon style buttons */
323
		iconErrorButton = new Button (iconStyleGroup, SWT.RADIO);
324
		iconErrorButton.setText ("SWT.ICON_ERROR");
325
		iconInformationButton = new Button (iconStyleGroup, SWT.RADIO);
326
		iconInformationButton.setText ("SWT.ICON_INFORMATION");
327
		iconQuestionButton = new Button (iconStyleGroup, SWT.RADIO);
328
		iconQuestionButton.setText ("SWT.ICON_QUESTION");
329
		iconWarningButton = new Button (iconStyleGroup, SWT.RADIO);
330
		iconWarningButton.setText ("SWT.ICON_WARNING");
331
		iconWorkingButton = new Button (iconStyleGroup, SWT.RADIO);
332
		iconWorkingButton.setText ("SWT.ICON_WORKING");
333
		noIconButton = new Button (iconStyleGroup, SWT.RADIO);
334
		noIconButton.setText (ControlExample.getResourceString("No_Icon"));
335
		
336
		/* Create a group for the modal style controls */
337
		Group modalStyleGroup = new Group (controlGroup, SWT.NONE);
338
		modalStyleGroup.setLayout (new GridLayout ());
339
		modalStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
340
		modalStyleGroup.setText (ControlExample.getResourceString("Modal_Styles"));
341
	
342
		/* Create the modal style buttons */
343
		primaryModalButton = new Button (modalStyleGroup, SWT.RADIO);
344
		primaryModalButton.setText ("SWT.PRIMARY_MODAL");
345
		applicationModalButton = new Button (modalStyleGroup, SWT.RADIO);
346
		applicationModalButton.setText ("SWT.APPLICATION_MODAL");
347
		systemModalButton = new Button (modalStyleGroup, SWT.RADIO);
348
		systemModalButton.setText ("SWT.SYSTEM_MODAL");
349
	
350
		/* Create a group for other style controls */
351
		Group otherStyleGroup = new Group (controlGroup, SWT.NONE);
352
		otherStyleGroup.setLayout (new GridLayout ());
353
		otherStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
354
		otherStyleGroup.setText (ControlExample.getResourceString("Other_Styles"));
355
	
356
		/* Create the other style buttons */
357
		sheetButton = new Button(otherStyleGroup, SWT.CHECK);
358
		sheetButton.setText("SWT.SHEET");
359
360
		/* Create a group for the file dialog style controls */
361
		Group fileDialogStyleGroup = new Group (controlGroup, SWT.NONE);
362
		fileDialogStyleGroup.setLayout (new GridLayout ());
363
		fileDialogStyleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
364
		fileDialogStyleGroup.setText (ControlExample.getResourceString("File_Dialog_Styles"));
365
	
366
		/* Create the file dialog style buttons */
367
		openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
368
		openButton.setText("SWT.OPEN");
369
		saveButton = new Button (fileDialogStyleGroup, SWT.RADIO);
370
		saveButton.setText ("SWT.SAVE");
371
		multiButton = new Button(fileDialogStyleGroup, SWT.CHECK);
372
		multiButton.setText("SWT.MULTI");
373
	
374
		/* Create the orientation group */
375
		if (RTL_SUPPORT_ENABLE) {
376
			createOrientationGroup();
377
		}
378
		
379
		/* Add the listeners */
380
		dialogCombo.addSelectionListener (new SelectionAdapter () {
381
			public void widgetSelected (SelectionEvent event) {
382
				dialogSelected (event);
383
			}
384
		});
385
		createButton.addSelectionListener (new SelectionAdapter () {
386
			public void widgetSelected (SelectionEvent event) {
387
				createButtonSelected (event);
388
			}
389
		});
390
		SelectionListener buttonStyleListener = new SelectionAdapter () {
391
			public void widgetSelected (SelectionEvent event) {
392
				buttonStyleSelected (event);
393
			}
394
		};
395
		okButton.addSelectionListener (buttonStyleListener);
396
		cancelButton.addSelectionListener (buttonStyleListener);
397
		yesButton.addSelectionListener (buttonStyleListener);
398
		noButton.addSelectionListener (buttonStyleListener);
399
		retryButton.addSelectionListener (buttonStyleListener);
400
		abortButton.addSelectionListener (buttonStyleListener);
401
		ignoreButton.addSelectionListener (buttonStyleListener);
402
	
403
		/* Set default values for style buttons */
404
		okButton.setEnabled (false);
405
		cancelButton.setEnabled (false);
406
		yesButton.setEnabled (false);
407
		noButton.setEnabled (false);
408
		retryButton.setEnabled (false);
409
		abortButton.setEnabled (false);
410
		ignoreButton.setEnabled (false);
411
		iconErrorButton.setEnabled (false);
412
		iconInformationButton.setEnabled (false);
413
		iconQuestionButton.setEnabled (false);
414
		iconWarningButton.setEnabled (false);
415
		iconWorkingButton.setEnabled (false);
416
		noIconButton.setEnabled (false);
417
		saveButton.setEnabled (false);
418
		openButton.setEnabled (false);
419
		openButton.setSelection (true);
420
		multiButton.setEnabled (false);
421
		noIconButton.setSelection (true);
422
	}
423
	
424
	/**
425
	 * Creates the "Example" group.
426
	 */
427
	void createExampleGroup () {
428
		super.createExampleGroup ();
429
		exampleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
430
		
431
		/*
432
		 * Create a group for the text widget to display
433
		 * the results returned by the example dialogs.
434
		 */
435
		resultGroup = new Group (exampleGroup, SWT.NONE);
436
		resultGroup.setLayout (new GridLayout ());
437
		resultGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
438
		resultGroup.setText (ControlExample.getResourceString("Dialog_Result"));
439
	}
440
	
441
	/**
442
	 * Creates the "Example" widgets.
443
	 */
444
	void createExampleWidgets () {
445
		/*
446
		 * Create a multi lined, scrolled text widget for output.
447
		 */
448
		textWidget = new Text(resultGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
449
		GridData gridData = new GridData (GridData.FILL_BOTH);
450
		textWidget.setLayoutData (gridData);	
451
	}
452
	
453
	/**
454
	 * The platform dialogs do not have SWT listeners.
455
	 */
456
	void createListenersGroup () {
457
	}
458
459
	/**
460
	 * Handle a dialog type combo selection event.
461
	 *
462
	 * @param event the selection event
463
	 */
464
	void dialogSelected (SelectionEvent event) {
465
	
466
		/* Enable/Disable the buttons */
467
		String name = dialogCombo.getText ();
468
		boolean isMessageBox = name.equals (ControlExample.getResourceString("MessageBox"));
469
		boolean isFileDialog = name.equals (ControlExample.getResourceString("FileDialog"));
470
		okButton.setEnabled (isMessageBox);
471
		cancelButton.setEnabled (isMessageBox);
472
		yesButton.setEnabled (isMessageBox);
473
		noButton.setEnabled (isMessageBox);
474
		retryButton.setEnabled (isMessageBox);
475
		abortButton.setEnabled (isMessageBox);
476
		ignoreButton.setEnabled (isMessageBox);
477
		iconErrorButton.setEnabled (isMessageBox);
478
		iconInformationButton.setEnabled (isMessageBox);
479
		iconQuestionButton.setEnabled (isMessageBox);
480
		iconWarningButton.setEnabled (isMessageBox);
481
		iconWorkingButton.setEnabled (isMessageBox);
482
		noIconButton.setEnabled (isMessageBox);
483
		saveButton.setEnabled (isFileDialog);
484
		openButton.setEnabled (isFileDialog);
485
		multiButton.setEnabled (isFileDialog);
486
	
487
		/* Unselect the buttons */
488
		if (!isMessageBox) {
489
			okButton.setSelection (false);
490
			cancelButton.setSelection (false);
491
			yesButton.setSelection (false);
492
			noButton.setSelection (false);
493
			retryButton.setSelection (false);
494
			abortButton.setSelection (false);
495
			ignoreButton.setSelection (false);
496
		}
497
	}
498
	
499
	/**
500
	 * Gets the "Example" widget children.
501
	 */
502
	Widget [] getExampleWidgets () {
503
		return new Widget [0];
504
	}
505
	
506
	/**
507
	 * Gets the text for the tab folder item.
508
	 */
509
	String getTabText () {
510
		return "Dialog";
511
	}
512
	
513
	/**
514
	 * Recreates the "Example" widgets.
515
	 */
516
	void recreateExampleWidgets () {
517
		if (textWidget == null) {
518
			super.recreateExampleWidgets ();
519
		} 
520
	}
521
}
(-)src/org/eclipse/swt/examples/mirroringTest/ExpandBarTab.java (+145 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
18
class ExpandBarTab extends Tab {
19
	/* Example widgets and groups that contain them */
20
	ExpandBar expandBar1;
21
	Group expandBarGroup;
22
	
23
	/* Style widgets added to the "Style" group */	
24
	Button verticalButton;
25
26
	/**
27
	 * Creates the Tab within a given instance of ControlExample.
28
	 */
29
	ExpandBarTab(ControlExample instance) {
30
		super(instance);
31
	}
32
	
33
	/**
34
	 * Creates the "Example" group.
35
	 */
36
	void createExampleGroup () {
37
		super.createExampleGroup ();
38
		
39
		/* Create a group for the list */
40
		expandBarGroup = new Group (exampleGroup, SWT.NONE);
41
		expandBarGroup.setLayout (new GridLayout ());
42
		expandBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
43
		expandBarGroup.setText ("ExpandBar");
44
	}
45
	
46
	/**
47
	 * Creates the "Example" widgets.
48
	 */
49
	void createExampleWidgets () {
50
		
51
		/* Compute the widget style */
52
		int style = getDefaultStyle();
53
		if (borderButton.getSelection ()) style |= SWT.BORDER;
54
		if (verticalButton.getSelection()) style |= SWT.V_SCROLL;
55
	
56
		/* Create the example widgets */		
57
		expandBar1 = new ExpandBar (expandBarGroup, style);
58
		
59
		// First item
60
		Composite composite = new Composite (expandBar1, SWT.NONE);
61
		composite.setLayout(new GridLayout ());
62
		new Button (composite, SWT.PUSH).setText("SWT.PUSH");
63
		new Button (composite, SWT.RADIO).setText("SWT.RADIO");
64
		new Button (composite, SWT.CHECK).setText("SWT.CHECK");
65
		new Button (composite, SWT.TOGGLE).setText("SWT.TOGGLE");
66
		ExpandItem item = new ExpandItem (expandBar1, SWT.NONE, 0);
67
		item.setText(ControlExample.getResourceString("Item1_Text"));
68
		item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
69
		item.setControl(composite);
70
		item.setImage(instance.images[ControlExample.ciClosedFolder]);
71
		
72
		// Second item
73
		composite = new Composite (expandBar1, SWT.NONE);
74
		composite.setLayout(new GridLayout (2, false));	
75
		new Label (composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_ERROR));
76
		new Label (composite, SWT.NONE).setText("SWT.ICON_ERROR");
77
		new Label (composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_INFORMATION));
78
		new Label (composite, SWT.NONE).setText("SWT.ICON_INFORMATION");
79
		new Label (composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_WARNING));
80
		new Label (composite, SWT.NONE).setText("SWT.ICON_WARNING");
81
		new Label (composite, SWT.NONE).setImage(display.getSystemImage(SWT.ICON_QUESTION));
82
		new Label (composite, SWT.NONE).setText("SWT.ICON_QUESTION");
83
		item = new ExpandItem (expandBar1, SWT.NONE, 1);
84
		item.setText(ControlExample.getResourceString("Item2_Text"));
85
		item.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
86
		item.setControl(composite);
87
		item.setImage(instance.images[ControlExample.ciOpenFolder]);
88
		item.setExpanded(true);
89
	}
90
	
91
	/**
92
	 * Creates the "Style" group.
93
	 */
94
	void createStyleGroup() {
95
		super.createStyleGroup ();
96
		
97
		/* Create the extra widgets */
98
		verticalButton = new Button (styleGroup, SWT.CHECK);
99
		verticalButton.setText ("SWT.V_SCROLL");
100
		verticalButton.setSelection(true);
101
		borderButton = new Button(styleGroup, SWT.CHECK);
102
		borderButton.setText("SWT.BORDER");
103
	}
104
	
105
	/**
106
	 * Gets the "Example" widget children.
107
	 */
108
	Widget [] getExampleWidgets () {
109
		return new Widget [] {expandBar1};
110
	}
111
	
112
	/**
113
	 * Returns a list of set/get API method names (without the set/get prefix)
114
	 * that can be used to set/get values in the example control(s).
115
	 */
116
	String[] getMethodNames() {
117
		return new String[] {"Spacing"};
118
	}
119
	
120
	/**
121
	 * Gets the short text for the tab folder item.
122
	 */
123
	String getShortTabText() {
124
		return "EB";
125
	}
126
127
	/**
128
	 * Gets the text for the tab folder item.
129
	 */
130
	String getTabText () {
131
		return "ExpandBar";
132
	}
133
134
	/**
135
	 * Sets the state of the "Example" widgets.
136
	 */
137
	void setExampleWidgetState () {
138
		super.setExampleWidgetState ();
139
		Widget [] widgets = getExampleWidgets ();
140
		if (widgets.length != 0){
141
			verticalButton.setSelection ((widgets [0].getStyle () & SWT.V_SCROLL) != 0);
142
			borderButton.setSelection ((widgets [0].getStyle () & SWT.BORDER) != 0);
143
		}
144
	}
145
}
(-)src/org/eclipse/swt/examples/mirroringTest/GroupTab.java (+154 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.events.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.widgets.*;
18
19
class GroupTab extends Tab {
20
	Button titleButton;
21
	
22
	/* Example widgets and groups that contain them */
23
	Group group1;
24
	Group groupGroup;
25
	
26
	/* Style widgets added to the "Style" group */
27
	Button shadowEtchedInButton, shadowEtchedOutButton, shadowInButton, shadowOutButton, shadowNoneButton;
28
29
	/**
30
	 * Creates the Tab within a given instance of ControlExample.
31
	 */
32
	GroupTab(ControlExample instance) {
33
		super(instance);
34
	}
35
	
36
	/**
37
	 * Creates the "Other" group.
38
	 */
39
	void createOtherGroup () {
40
		super.createOtherGroup ();
41
	
42
		/* Create display controls specific to this example */
43
		titleButton = new Button (otherGroup, SWT.CHECK);
44
		titleButton.setText (ControlExample.getResourceString("Title_Text"));
45
	
46
		/* Add the listeners */
47
		titleButton.addSelectionListener (new SelectionAdapter () {
48
			public void widgetSelected (SelectionEvent event) {
49
				setTitleText ();
50
			}
51
		});
52
	}
53
	
54
	/**
55
	 * Creates the "Example" group.
56
	 */
57
	void createExampleGroup () {
58
		super.createExampleGroup ();
59
		
60
		/* Create a group for the Group */
61
		groupGroup = new Group (exampleGroup, SWT.NONE);
62
		groupGroup.setLayout (new GridLayout ());
63
		groupGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
64
		groupGroup.setText ("Group");
65
	}
66
	
67
	/**
68
	 * Creates the "Example" widgets.
69
	 */
70
	void createExampleWidgets () {
71
		
72
		/* Compute the widget style */
73
		int style = getDefaultStyle();
74
		if (shadowEtchedInButton.getSelection ()) style |= SWT.SHADOW_ETCHED_IN;
75
		if (shadowEtchedOutButton.getSelection ()) style |= SWT.SHADOW_ETCHED_OUT;
76
		if (shadowInButton.getSelection ()) style |= SWT.SHADOW_IN;
77
		if (shadowOutButton.getSelection ()) style |= SWT.SHADOW_OUT;
78
		if (shadowNoneButton.getSelection ()) style |= SWT.SHADOW_NONE;
79
		if (borderButton.getSelection ()) style |= SWT.BORDER;
80
81
		/* Create the example widgets */
82
		group1 = new Group (groupGroup, style);
83
	}
84
	
85
	/**
86
	 * Creates the "Style" group.
87
	 */
88
	void createStyleGroup() {
89
		super.createStyleGroup ();
90
		
91
		/* Create the extra widgets */
92
		shadowEtchedInButton = new Button (styleGroup, SWT.RADIO);
93
		shadowEtchedInButton.setText ("SWT.SHADOW_ETCHED_IN");
94
		shadowEtchedInButton.setSelection(true);
95
		shadowEtchedOutButton = new Button (styleGroup, SWT.RADIO);
96
		shadowEtchedOutButton.setText ("SWT.SHADOW_ETCHED_OUT");
97
		shadowInButton = new Button (styleGroup, SWT.RADIO);
98
		shadowInButton.setText ("SWT.SHADOW_IN");
99
		shadowOutButton = new Button (styleGroup, SWT.RADIO);
100
		shadowOutButton.setText ("SWT.SHADOW_OUT");
101
		shadowNoneButton = new Button (styleGroup, SWT.RADIO);
102
		shadowNoneButton.setText ("SWT.SHADOW_NONE");
103
		borderButton = new Button (styleGroup, SWT.CHECK);
104
		borderButton.setText ("SWT.BORDER");
105
	}
106
	
107
	/**
108
	 * Gets the "Example" widget children.
109
	 */
110
	Widget [] getExampleWidgets () {
111
		return new Widget [] {group1};
112
	}
113
	
114
	/**
115
	 * Returns a list of set/get API method names (without the set/get prefix)
116
	 * that can be used to set/get values in the example control(s).
117
	 */
118
	String[] getMethodNames() {
119
		return new String[] {"Text", "ToolTipText"};
120
	}
121
122
	/**
123
	 * Gets the text for the tab folder item.
124
	 */
125
	String getTabText () {
126
		return "Group";
127
	}
128
129
	/**
130
	 * Sets the title text of the "Example" widgets.
131
	 */
132
	void setTitleText () {
133
		if (titleButton.getSelection ()) {
134
			group1.setText (ControlExample.getResourceString("Title_Text"));
135
		} else {
136
			group1.setText ("");
137
		}
138
		setExampleWidgetSize ();
139
	}
140
141
	/**
142
	 * Sets the state of the "Example" widgets.
143
	 */
144
	void setExampleWidgetState () {
145
		super.setExampleWidgetState ();
146
		shadowEtchedInButton.setSelection ((group1.getStyle () & SWT.SHADOW_ETCHED_IN) != 0);
147
		shadowEtchedOutButton.setSelection ((group1.getStyle () & SWT.SHADOW_ETCHED_OUT) != 0);
148
		shadowInButton.setSelection ((group1.getStyle () & SWT.SHADOW_IN) != 0);
149
		shadowOutButton.setSelection ((group1.getStyle () & SWT.SHADOW_OUT) != 0);
150
		shadowNoneButton.setSelection ((group1.getStyle () & SWT.SHADOW_NONE) != 0);
151
		borderButton.setSelection ((group1.getStyle () & SWT.BORDER) != 0);
152
		if (!instance.startup) setTitleText ();
153
	}
154
}
(-)src/org/eclipse/swt/examples/mirroringTest/LabelTab.java (+184 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
18
class LabelTab extends AlignableTab {
19
	/* Example widgets and groups that contain them */
20
	Label label1, label2, label3, label4, label5, label6;
21
	Group textLabelGroup, imageLabelGroup;
22
23
	/* Style widgets added to the "Style" group */
24
	Button wrapButton, separatorButton, horizontalButton, verticalButton, shadowInButton, shadowOutButton, shadowNoneButton;
25
	
26
	/**
27
	 * Creates the Tab within a given instance of ControlExample.
28
	 */
29
	LabelTab(ControlExample instance) {
30
		super(instance);
31
	}
32
	
33
	/**
34
	 * Creates the "Example" group.
35
	 */
36
	void createExampleGroup () {
37
		super.createExampleGroup ();
38
		
39
		/* Create a group for the text labels */
40
		textLabelGroup = new Group(exampleGroup, SWT.NONE);
41
		GridLayout gridLayout = new GridLayout ();
42
		textLabelGroup.setLayout (gridLayout);
43
		gridLayout.numColumns = 3;
44
		textLabelGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
45
		textLabelGroup.setText (ControlExample.getResourceString("Text_Labels"));
46
	
47
		/* Create a group for the image labels */
48
		imageLabelGroup = new Group (exampleGroup, SWT.SHADOW_NONE);
49
		gridLayout = new GridLayout ();
50
		imageLabelGroup.setLayout (gridLayout);
51
		gridLayout.numColumns = 3;
52
		imageLabelGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
53
		imageLabelGroup.setText (ControlExample.getResourceString("Image_Labels"));
54
	}
55
	
56
	/**
57
	 * Creates the "Example" widgets.
58
	 */
59
	void createExampleWidgets () {
60
		
61
		/* Compute the widget style */
62
		int style = getDefaultStyle();
63
		if (wrapButton.getSelection ()) style |= SWT.WRAP;
64
		if (separatorButton.getSelection ()) style |= SWT.SEPARATOR;
65
		if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
66
		if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
67
		if (shadowInButton.getSelection ()) style |= SWT.SHADOW_IN;
68
		if (shadowOutButton.getSelection ()) style |= SWT.SHADOW_OUT;
69
		if (shadowNoneButton.getSelection ()) style |= SWT.SHADOW_NONE;
70
		if (borderButton.getSelection ()) style |= SWT.BORDER;
71
		if (leftButton.getSelection ()) style |= SWT.LEFT;
72
		if (centerButton.getSelection ()) style |= SWT.CENTER;
73
		if (rightButton.getSelection ()) style |= SWT.RIGHT;
74
	
75
		/* Create the example widgets */
76
		label1 = new Label (textLabelGroup, style);
77
		label1.setText(ControlExample.getResourceString("One"));
78
		label2 = new Label (textLabelGroup, style);
79
		label2.setText(ControlExample.getResourceString("Two"));
80
		label3 = new Label (textLabelGroup, style);
81
		if (wrapButton.getSelection ()) {
82
			label3.setText (ControlExample.getResourceString("Wrap_Text"));
83
		} else {
84
			label3.setText (ControlExample.getResourceString("Three"));
85
		}
86
		label4 = new Label (imageLabelGroup, style);
87
		label4.setImage (instance.images[ControlExample.ciClosedFolder]);
88
		label5 = new Label (imageLabelGroup, style);
89
		label5.setImage (instance.images[ControlExample.ciOpenFolder]);
90
		label6 = new Label(imageLabelGroup, style);
91
		label6.setImage (instance.images[ControlExample.ciTarget]);
92
	}
93
	
94
	/**
95
	 * Creates the "Style" group.
96
	 */
97
	void createStyleGroup() {
98
		super.createStyleGroup ();
99
		
100
		/* Create the extra widgets */
101
		wrapButton = new Button (styleGroup, SWT.CHECK);
102
		wrapButton.setText ("SWT.WRAP");
103
		separatorButton = new Button (styleGroup, SWT.CHECK);
104
		separatorButton.setText ("SWT.SEPARATOR");
105
		horizontalButton = new Button (styleGroup, SWT.RADIO);
106
		horizontalButton.setText ("SWT.HORIZONTAL");
107
		verticalButton = new Button (styleGroup, SWT.RADIO);
108
		verticalButton.setText ("SWT.VERTICAL");
109
		Group styleSubGroup = new Group (styleGroup, SWT.NONE);
110
		styleSubGroup.setLayout (new GridLayout ());
111
		shadowInButton = new Button (styleSubGroup, SWT.RADIO);
112
		shadowInButton.setText ("SWT.SHADOW_IN");
113
		shadowOutButton = new Button (styleSubGroup, SWT.RADIO);
114
		shadowOutButton.setText ("SWT.SHADOW_OUT");
115
		shadowNoneButton = new Button (styleSubGroup, SWT.RADIO);
116
		shadowNoneButton.setText ("SWT.SHADOW_NONE");
117
		borderButton = new Button(styleGroup, SWT.CHECK);
118
		borderButton.setText("SWT.BORDER");
119
	}
120
	
121
	/**
122
	 * Gets the "Example" widget children.
123
	 */
124
	Widget [] getExampleWidgets () {
125
		return new Widget [] {label1, label2, label3, label4, label5, label6};
126
	}
127
	
128
	/**
129
	 * Returns a list of set/get API method names (without the set/get prefix)
130
	 * that can be used to set/get values in the example control(s).
131
	 */
132
	String[] getMethodNames() {
133
		return new String[] {"Text", "ToolTipText"};
134
	}
135
136
	/**
137
	 * Gets the text for the tab folder item.
138
	 */
139
	String getTabText () {
140
		return "Label";
141
	}
142
	
143
	/**
144
	 * Sets the alignment of the "Example" widgets.
145
	 */
146
	void setExampleWidgetAlignment () {
147
		int alignment = 0;
148
		if (leftButton.getSelection ()) alignment = SWT.LEFT;
149
		if (centerButton.getSelection ()) alignment = SWT.CENTER;
150
		if (rightButton.getSelection ()) alignment = SWT.RIGHT;
151
		label1.setAlignment (alignment);
152
		label2.setAlignment (alignment);
153
		label3.setAlignment (alignment);
154
		label4.setAlignment (alignment);
155
		label5.setAlignment (alignment);
156
		label6.setAlignment (alignment);
157
	}
158
	
159
	/**
160
	 * Sets the state of the "Example" widgets.
161
	 */
162
	void setExampleWidgetState () {
163
		super.setExampleWidgetState ();
164
		boolean isSeparator = (label1.getStyle () & SWT.SEPARATOR) != 0;
165
		wrapButton.setSelection (!isSeparator && (label1.getStyle () & SWT.WRAP) != 0);
166
		leftButton.setSelection (!isSeparator && (label1.getStyle () & SWT.LEFT) != 0);
167
		centerButton.setSelection (!isSeparator && (label1.getStyle () & SWT.CENTER) != 0);
168
		rightButton.setSelection (!isSeparator && (label1.getStyle () & SWT.RIGHT) != 0);
169
		shadowInButton.setSelection (isSeparator && (label1.getStyle () & SWT.SHADOW_IN) != 0);
170
		shadowOutButton.setSelection (isSeparator && (label1.getStyle () & SWT.SHADOW_OUT) != 0);
171
		shadowNoneButton.setSelection (isSeparator && (label1.getStyle () & SWT.SHADOW_NONE) != 0);
172
		horizontalButton.setSelection (isSeparator && (label1.getStyle () & SWT.HORIZONTAL) != 0);
173
		verticalButton.setSelection (isSeparator && (label1.getStyle () & SWT.VERTICAL) != 0);		
174
		wrapButton.setEnabled (!isSeparator);
175
		leftButton.setEnabled (!isSeparator);
176
		centerButton.setEnabled (!isSeparator);
177
		rightButton.setEnabled (!isSeparator);
178
		shadowInButton.setEnabled (isSeparator);
179
		shadowOutButton.setEnabled (isSeparator);
180
		shadowNoneButton.setEnabled (isSeparator);
181
		horizontalButton.setEnabled (isSeparator);
182
		verticalButton.setEnabled (isSeparator);
183
	}
184
}
(-)src/org/eclipse/swt/examples/mirroringTest/LinkTab.java (+98 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
18
class LinkTab extends Tab {
19
	/* Example widgets and groups that contain them */
20
	Link link1;
21
	Group linkGroup;
22
	
23
	/**
24
	 * Creates the Tab within a given instance of ControlExample.
25
	 */
26
	LinkTab(ControlExample instance) {
27
		super(instance);
28
	}
29
	
30
	/**
31
	 * Creates the "Example" group.
32
	 */
33
	void createExampleGroup () {
34
		super.createExampleGroup ();
35
		
36
		/* Create a group for the list */
37
		linkGroup = new Group (exampleGroup, SWT.NONE);
38
		linkGroup.setLayout (new GridLayout ());
39
		linkGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
40
		linkGroup.setText ("Link");
41
	}
42
	
43
	/**
44
	 * Creates the "Example" widgets.
45
	 */
46
	void createExampleWidgets () {
47
		
48
		/* Compute the widget style */
49
		int style = getDefaultStyle();
50
		if (borderButton.getSelection ()) style |= SWT.BORDER;
51
	
52
		/* Create the example widgets */		
53
		try {
54
			link1 = new Link (linkGroup, style);
55
			link1.setText (ControlExample.getResourceString("LinkText"));
56
		} catch (SWTError e) {
57
			// temporary code for photon
58
			Label label = new Label (linkGroup, SWT.CENTER | SWT.WRAP);
59
			label.setText ("Link widget not suported");
60
		}
61
	}
62
	
63
	/**
64
	 * Creates the "Style" group.
65
	 */
66
	void createStyleGroup() {
67
		super.createStyleGroup ();
68
		
69
		/* Create the extra widgets */
70
		borderButton = new Button(styleGroup, SWT.CHECK);
71
		borderButton.setText("SWT.BORDER");
72
	}
73
	
74
	/**
75
	 * Gets the "Example" widget children.
76
	 */
77
	Widget [] getExampleWidgets () {
78
//		 temporary code for photon
79
		if (link1 != null) return new Widget [] {link1};
80
		return new Widget[] {};
81
	}
82
	
83
	/**
84
	 * Returns a list of set/get API method names (without the set/get prefix)
85
	 * that can be used to set/get values in the example control(s).
86
	 */
87
	String[] getMethodNames() {
88
		return new String[] {"Text", "ToolTipText"};
89
	}
90
	
91
	/**
92
	 * Gets the text for the tab folder item.
93
	 */
94
	String getTabText () {
95
		return "Link";
96
	}
97
98
}
(-)src/org/eclipse/swt/examples/mirroringTest/ListTab.java (+93 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
18
class ListTab extends ScrollableTab {
19
20
	/* Example widgets and groups that contain them */
21
	List list1;
22
	Group listGroup;
23
	
24
	static String [] ListData1 = {ControlExample.getResourceString("ListData1_0"),
25
								  ControlExample.getResourceString("ListData1_1"),
26
								  ControlExample.getResourceString("ListData1_2"),
27
								  ControlExample.getResourceString("ListData1_3"),
28
								  ControlExample.getResourceString("ListData1_4"),
29
								  ControlExample.getResourceString("ListData1_5"),
30
								  ControlExample.getResourceString("ListData1_6"),
31
								  ControlExample.getResourceString("ListData1_7"),
32
								  ControlExample.getResourceString("ListData1_8")};
33
34
	/**
35
	 * Creates the Tab within a given instance of ControlExample.
36
	 */
37
	ListTab(ControlExample instance) {
38
		super(instance);
39
	}
40
	
41
	/**
42
	 * Creates the "Example" group.
43
	 */
44
	void createExampleGroup () {
45
		super.createExampleGroup ();
46
		
47
		/* Create a group for the list */
48
		listGroup = new Group (exampleGroup, SWT.NONE);
49
		listGroup.setLayout (new GridLayout ());
50
		listGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
51
		listGroup.setText ("List");
52
	}
53
	
54
	/**
55
	 * Creates the "Example" widgets.
56
	 */
57
	void createExampleWidgets () {
58
		
59
		/* Compute the widget style */
60
		int style = getDefaultStyle();
61
		if (singleButton.getSelection ()) style |= SWT.SINGLE;
62
		if (multiButton.getSelection ()) style |= SWT.MULTI;
63
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
64
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
65
		if (borderButton.getSelection ()) style |= SWT.BORDER;
66
	
67
		/* Create the example widgets */
68
		list1 = new List (listGroup, style);
69
		list1.setItems (ListData1);
70
	}
71
	
72
	/**
73
	 * Gets the "Example" widget children.
74
	 */
75
	Widget [] getExampleWidgets () {
76
		return new Widget [] {list1};
77
	}
78
	
79
	/**
80
	 * Returns a list of set/get API method names (without the set/get prefix)
81
	 * that can be used to set/get values in the example control(s).
82
	 */
83
	String[] getMethodNames() {
84
		return new String[] {"Items", "Selection", "ToolTipText", "TopIndex"};
85
	}
86
87
	/**
88
	 * Gets the text for the tab folder item.
89
	 */
90
	String getTabText () {
91
		return "List";
92
	}
93
}
(-)src/org/eclipse/swt/examples/mirroringTest/MenuTab.java (+319 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
class MenuTab extends Tab {	
20
	/* Widgets added to the "Menu Style", "MenuItem Style" and "Other" groups */
21
	Button barButton, dropDownButton, popUpButton, noRadioGroupButton, leftToRightButton, rightToLeftButton;
22
	Button checkButton, cascadeButton, pushButton, radioButton, separatorButton;
23
	Button imagesButton, acceleratorsButton, mnemonicsButton, subMenuButton, subSubMenuButton;
24
	Button createButton, closeAllButton, enabledButton;
25
	Group menuItemStyleGroup;
26
27
	/* Variables used to track the open shells */
28
	int shellCount = 0;
29
	Shell [] shells = new Shell [4];
30
	
31
	/**
32
	 * Creates the Tab within a given instance of ControlExample.
33
	 */
34
	MenuTab(ControlExample instance) {
35
		super(instance);
36
	}
37
38
	/**
39
	 * Close all the example shells.
40
	 */
41
	void closeAllShells() {
42
		for (int i = 0; i<shellCount; i++) {
43
			if (shells[i] != null & !shells [i].isDisposed ()) {
44
				shells [i].dispose();
45
			}
46
		}
47
		shellCount = 0;
48
	}
49
	
50
	/**
51
	 * Handle the Create button selection event.
52
	 *
53
	 * @param event org.eclipse.swt.events.SelectionEvent
54
	 */
55
	public void createButtonSelected(SelectionEvent event) {
56
	
57
		/*
58
		 * Remember the example shells so they
59
		 * can be disposed by the user.
60
		 */
61
		if (shellCount >= shells.length) {
62
			Shell [] newShells = new Shell [shells.length + 4];
63
			System.arraycopy (shells, 0, newShells, 0, shells.length);
64
			shells = newShells;
65
		}
66
	
67
		int orientation = 0;
68
		if (leftToRightButton.getSelection()) orientation |= SWT.LEFT_TO_RIGHT;
69
		if (rightToLeftButton.getSelection()) orientation |= SWT.RIGHT_TO_LEFT;
70
		int radioBehavior = 0;
71
		if (noRadioGroupButton.getSelection()) radioBehavior |= SWT.NO_RADIO_GROUP;
72
		
73
		/* Create the shell and menu(s) */
74
		Shell shell = new Shell (SWT.SHELL_TRIM | orientation);
75
		shells [shellCount] = shell;
76
		if (barButton.getSelection ()) {
77
			/* Create menu bar. */
78
			Menu menuBar = new Menu(shell, SWT.BAR | radioBehavior );
79
			shell.setMenuBar(menuBar);
80
			hookListeners(menuBar);
81
82
			if (dropDownButton.getSelection() && cascadeButton.getSelection()) {
83
				/* Create cascade button and drop-down menu in menu bar. */
84
				MenuItem item = new MenuItem(menuBar, SWT.CASCADE);
85
				item.setText(getMenuItemText("Cascade"));
86
				item.setEnabled(enabledButton.getSelection());
87
				if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]);
88
				hookListeners(item);
89
				Menu dropDownMenu = new Menu(shell, SWT.DROP_DOWN | radioBehavior);
90
				item.setMenu(dropDownMenu);
91
				hookListeners(dropDownMenu);
92
	
93
				/* Create various menu items, depending on selections. */
94
				createMenuItems(dropDownMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection());
95
			}
96
		}
97
		
98
		if (popUpButton.getSelection()) {
99
			/* Create pop-up menu. */
100
			Menu popUpMenu = new Menu(shell, SWT.POP_UP | radioBehavior);
101
			shell.setMenu(popUpMenu);
102
			hookListeners(popUpMenu);
103
104
			/* Create various menu items, depending on selections. */
105
			createMenuItems(popUpMenu, subMenuButton.getSelection(), subSubMenuButton.getSelection());
106
		}
107
		
108
		/* Set the size, title and open the shell. */
109
		shell.setSize (300, 100);
110
		shell.setText (ControlExample.getResourceString("Title") + shellCount);
111
		shell.addPaintListener(new PaintListener() {
112
			public void paintControl(PaintEvent e) {
113
				e.gc.drawString(ControlExample.getResourceString("PopupMenuHere"), 20, 20);
114
			}
115
		});
116
		shell.open ();
117
		shellCount++;
118
	}
119
	
120
	/**
121
	 * Creates the "Control" group. 
122
	 */
123
	void createControlGroup () {
124
		/*
125
		 * Create the "Control" group.  This is the group on the
126
		 * right half of each example tab.  For MenuTab, it consists of
127
		 * the Menu style group, the MenuItem style group and the 'other' group.
128
		 */		
129
		controlGroup = new Group (tabFolderPage, SWT.NONE);
130
		controlGroup.setLayout (new GridLayout (2, true));
131
		controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
132
		controlGroup.setText (ControlExample.getResourceString("Parameters"));
133
	
134
		/* Create a group for the menu style controls */
135
		styleGroup = new Group (controlGroup, SWT.NONE);
136
		styleGroup.setLayout (new GridLayout ());
137
		styleGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
138
		styleGroup.setText (ControlExample.getResourceString("Menu_Styles"));
139
	
140
		/* Create a group for the menu item style controls */
141
		menuItemStyleGroup = new Group (controlGroup, SWT.NONE);
142
		menuItemStyleGroup.setLayout (new GridLayout ());
143
		menuItemStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
144
		menuItemStyleGroup.setText (ControlExample.getResourceString("MenuItem_Styles"));
145
146
		/* Create a group for the 'other' controls */
147
		otherGroup = new Group (controlGroup, SWT.NONE);
148
		otherGroup.setLayout (new GridLayout ());
149
		otherGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
150
		otherGroup.setText (ControlExample.getResourceString("Other"));
151
	}
152
	
153
	/**
154
	 * Creates the "Control" widget children.
155
	 */
156
	void createControlWidgets () {
157
	
158
		/* Create the menu style buttons */
159
		barButton = new Button (styleGroup, SWT.CHECK);
160
		barButton.setText ("SWT.BAR");
161
		dropDownButton = new Button (styleGroup, SWT.CHECK);
162
		dropDownButton.setText ("SWT.DROP_DOWN");
163
		popUpButton = new Button (styleGroup, SWT.CHECK);
164
		popUpButton.setText ("SWT.POP_UP");
165
		noRadioGroupButton = new Button (styleGroup, SWT.CHECK);
166
		noRadioGroupButton.setText ("SWT.NO_RADIO_GROUP");
167
		leftToRightButton = new Button (styleGroup, SWT.RADIO);
168
		leftToRightButton.setText ("SWT.LEFT_TO_RIGHT");
169
		leftToRightButton.setSelection(true);
170
		rightToLeftButton = new Button (styleGroup, SWT.RADIO);
171
		rightToLeftButton.setText ("SWT.RIGHT_TO_LEFT");
172
	
173
		/* Create the menu item style buttons */
174
		cascadeButton = new Button (menuItemStyleGroup, SWT.CHECK);
175
		cascadeButton.setText ("SWT.CASCADE");
176
		checkButton = new Button (menuItemStyleGroup, SWT.CHECK);
177
		checkButton.setText ("SWT.CHECK");
178
		pushButton = new Button (menuItemStyleGroup, SWT.CHECK);
179
		pushButton.setText ("SWT.PUSH");
180
		radioButton = new Button (menuItemStyleGroup, SWT.CHECK);
181
		radioButton.setText ("SWT.RADIO");
182
		separatorButton = new Button (menuItemStyleGroup, SWT.CHECK);
183
		separatorButton.setText ("SWT.SEPARATOR");
184
		
185
		/* Create the 'other' buttons */
186
		imagesButton = new Button (otherGroup, SWT.CHECK);
187
		imagesButton.setText (ControlExample.getResourceString("Images"));
188
		acceleratorsButton = new Button (otherGroup, SWT.CHECK);
189
		acceleratorsButton.setText (ControlExample.getResourceString("Accelerators"));
190
		mnemonicsButton = new Button (otherGroup, SWT.CHECK);
191
		mnemonicsButton.setText (ControlExample.getResourceString("Mnemonics"));
192
		subMenuButton = new Button (otherGroup, SWT.CHECK);
193
		subMenuButton.setText (ControlExample.getResourceString("SubMenu"));
194
		subSubMenuButton = new Button (otherGroup, SWT.CHECK);
195
		subSubMenuButton.setText (ControlExample.getResourceString("SubSubMenu"));
196
		enabledButton = new Button(otherGroup, SWT.CHECK);
197
		enabledButton.setText(ControlExample.getResourceString("Cascade Menu Enabled"));
198
199
		
200
		/* Create the "create" and "closeAll" buttons (and a 'filler' label to place them) */
201
		new Label(controlGroup, SWT.NONE);
202
		createButton = new Button (controlGroup, SWT.NONE);
203
		createButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_END));
204
		createButton.setText (ControlExample.getResourceString("Create_Shell"));
205
		closeAllButton = new Button (controlGroup, SWT.NONE);
206
		closeAllButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING));
207
		closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells"));
208
	
209
		/* Add the listeners */
210
		enabledButton.addSelectionListener (new SelectionAdapter () {
211
			public void widgetSelected (SelectionEvent event) {
212
				setExampleWidgetEnabled ();
213
			}
214
		});
215
		
216
		createButton.addSelectionListener(new SelectionAdapter() {
217
			public void widgetSelected(SelectionEvent e) {
218
				createButtonSelected(e);
219
			}
220
		});
221
		closeAllButton.addSelectionListener(new SelectionAdapter() {
222
			public void widgetSelected(SelectionEvent e) {
223
				closeAllShells ();
224
			}
225
		});
226
		subMenuButton.addSelectionListener(new SelectionAdapter() {
227
			public void widgetSelected(SelectionEvent e) {
228
				subSubMenuButton.setEnabled (subMenuButton.getSelection ());
229
			}
230
		});
231
	
232
		/* Set the default state */
233
		barButton.setSelection (true);
234
		dropDownButton.setSelection (true);
235
		popUpButton.setSelection (true);
236
		cascadeButton.setSelection (true);
237
		checkButton.setSelection (true);
238
		pushButton.setSelection (true);
239
		radioButton.setSelection (true);
240
		separatorButton.setSelection (true);
241
		subSubMenuButton.setEnabled (subMenuButton.getSelection ());
242
	}
243
	
244
	/* Create various menu items, depending on selections. */
245
	void createMenuItems(Menu menu, boolean createSubMenu, boolean createSubSubMenu) {
246
		MenuItem item;
247
		if (pushButton.getSelection()) {
248
			item = new MenuItem(menu, SWT.PUSH);
249
			item.setText(getMenuItemText("Push"));
250
			if (acceleratorsButton.getSelection()) item.setAccelerator(SWT.MOD1 + SWT.MOD2 + 'P');
251
			if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciClosedFolder]);
252
			hookListeners(item);
253
		}
254
		
255
		if (separatorButton.getSelection()) {
256
			new MenuItem(menu, SWT.SEPARATOR);
257
		}
258
		
259
		if (checkButton.getSelection()) {
260
			item = new MenuItem(menu, SWT.CHECK);
261
			item.setText(getMenuItemText("Check"));
262
			if (acceleratorsButton.getSelection()) item.setAccelerator(SWT.MOD1 + SWT.MOD2 + 'C');
263
			if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]);
264
			hookListeners(item);
265
		}
266
				
267
		if (radioButton.getSelection()) {
268
			item = new MenuItem(menu, SWT.RADIO);
269
			item.setText(getMenuItemText("1Radio"));
270
			if (acceleratorsButton.getSelection()) item.setAccelerator(SWT.MOD1 + SWT.MOD2 + '1');
271
			if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciTarget]);
272
			item.setSelection(true);
273
			hookListeners(item);
274
275
			item = new MenuItem(menu, SWT.RADIO);
276
			item.setText(getMenuItemText("2Radio"));
277
			if (acceleratorsButton.getSelection()) item.setAccelerator(SWT.MOD1 + SWT.MOD2 + '2');
278
			if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciTarget]);
279
			hookListeners(item);
280
		}
281
282
		if (createSubMenu && cascadeButton.getSelection()) {
283
			/* Create cascade button and drop-down menu for the sub-menu. */
284
			item = new MenuItem(menu, SWT.CASCADE);
285
			item.setText(getMenuItemText("Cascade"));
286
			if (imagesButton.getSelection()) item.setImage(instance.images[ControlExample.ciOpenFolder]);
287
			hookListeners(item);
288
			Menu subMenu = new Menu(menu.getShell(), SWT.DROP_DOWN);
289
			item.setMenu(subMenu);
290
			hookListeners(subMenu);
291
			
292
			createMenuItems(subMenu, createSubSubMenu, false);
293
		}
294
	}
295
	
296
	String getMenuItemText(String item) {
297
		boolean cascade = item.equals("Cascade");
298
		boolean mnemonic = mnemonicsButton.getSelection();
299
		boolean accelerator = acceleratorsButton.getSelection();
300
		char acceleratorKey = item.charAt(0);
301
		if (mnemonic && accelerator && !cascade) {
302
			return ControlExample.getResourceString(item + "WithMnemonic") + "\tCtrl+Shift+" + acceleratorKey;
303
		}
304
		if (accelerator && !cascade) {
305
			return ControlExample.getResourceString(item) + "\tCtrl+Shift+" + acceleratorKey;
306
		}
307
		if (mnemonic) {
308
			return ControlExample.getResourceString(item + "WithMnemonic");
309
		}
310
		return ControlExample.getResourceString(item);
311
	}
312
	
313
	/**
314
	 * Gets the text for the tab folder item.
315
	 */
316
	String getTabText () {
317
		return "Menu";
318
	}
319
}
(-)src/org/eclipse/swt/examples/mirroringTest/ProgressBarTab.java (+178 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
18
class ProgressBarTab extends RangeTab {
19
	/* Example widgets and groups that contain them */
20
	ProgressBar progressBar1;
21
	Group progressBarGroup;
22
23
	/* Style widgets added to the "Style" group */
24
	Button smoothButton;
25
	Button indeterminateButton;
26
27
	/**
28
	 * Creates the Tab within a given instance of ControlExample.
29
	 */
30
	ProgressBarTab(ControlExample instance) {
31
		super(instance);
32
	}
33
34
	/**
35
	 * Creates the "Example" group.
36
	 */
37
	void createExampleGroup() {
38
		super.createExampleGroup ();
39
40
		/* Create a group for the progress bar */
41
		progressBarGroup = new Group (exampleGroup, SWT.NONE);
42
		progressBarGroup.setLayout (new GridLayout ());
43
		progressBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
44
		progressBarGroup.setText ("ProgressBar");
45
	}
46
47
	/**
48
	 * Creates the "Example" widgets.
49
	 */
50
	void createExampleWidgets () {
51
52
		/* Compute the widget style */
53
		int style = getDefaultStyle();
54
		if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
55
		if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
56
		if (smoothButton.getSelection ()) style |= SWT.SMOOTH;
57
		if (borderButton.getSelection ()) style |= SWT.BORDER;
58
		if (indeterminateButton.getSelection ()) style |= SWT.INDETERMINATE;
59
60
		/* Create the example widgets */
61
		progressBar1 = new ProgressBar (progressBarGroup, style);
62
	}
63
64
	/**
65
	 * Creates the "Style" group.
66
	 */
67
	void createStyleGroup () {
68
		super.createStyleGroup ();
69
70
		/* Create the extra widgets */
71
		smoothButton = new Button (styleGroup, SWT.CHECK);
72
		smoothButton.setText ("SWT.SMOOTH");
73
		indeterminateButton = new Button (styleGroup, SWT.CHECK);
74
		indeterminateButton.setText ("SWT.INDETERMINATE");
75
	}
76
77
	/**
78
	 * Gets the "Example" widget children.
79
	 */
80
	Widget [] getExampleWidgets () {
81
		return new Widget [] {progressBar1};
82
	}
83
84
	/**
85
	 * Returns a list of set/get API method names (without the set/get prefix)
86
	 * that can be used to set/get values in the example control(s).
87
	 */
88
	String[] getMethodNames() {
89
		return new String[] {"Selection", "State", "ToolTipText"};
90
	}
91
92
	/**
93
	 * Gets the short text for the tab folder item.
94
	 */
95
	String getShortTabText() {
96
		return "PB";
97
	}
98
99
	/**
100
	 * Gets the text for the tab folder item.
101
	 */
102
	String getTabText () {
103
		return "ProgressBar";
104
	}
105
106
	/**
107
	 * Sets the state of the "Example" widgets.
108
	 */
109
	void setExampleWidgetState () {
110
		super.setExampleWidgetState ();
111
		if (indeterminateButton.getSelection ()) {
112
			selectionSpinner.setEnabled (false);
113
			minimumSpinner.setEnabled (false);
114
			maximumSpinner.setEnabled (false);
115
		} else {
116
			selectionSpinner.setEnabled (true);
117
			minimumSpinner.setEnabled (true);
118
			maximumSpinner.setEnabled (true);
119
		}
120
		smoothButton.setSelection ((progressBar1.getStyle () & SWT.SMOOTH) != 0);
121
		indeterminateButton.setSelection ((progressBar1.getStyle () & SWT.INDETERMINATE) != 0);
122
	}
123
124
	/**
125
	 * Gets the default maximum of the "Example" widgets.
126
	 */
127
	int getDefaultMaximum () {
128
		return progressBar1.getMaximum();
129
	}
130
	
131
	/**
132
	 * Gets the default minimim of the "Example" widgets.
133
	 */
134
	int getDefaultMinimum () {
135
		return progressBar1.getMinimum();
136
	}
137
	
138
	/**
139
	 * Gets the default selection of the "Example" widgets.
140
	 */
141
	int getDefaultSelection () {
142
		return progressBar1.getSelection();
143
	}
144
145
	/**
146
	 * Sets the maximum of the "Example" widgets.
147
	 */
148
	void setWidgetMaximum () {
149
		progressBar1.setMaximum (maximumSpinner.getSelection ());
150
		updateSpinners ();
151
	}
152
153
	/**
154
	 * Sets the minimim of the "Example" widgets.
155
	 */
156
	void setWidgetMinimum () {
157
		progressBar1.setMinimum (minimumSpinner.getSelection ());
158
		updateSpinners ();
159
	}
160
161
	/**
162
	 * Sets the selection of the "Example" widgets.
163
	 */
164
	void setWidgetSelection () {
165
		progressBar1.setSelection (selectionSpinner.getSelection ());
166
		updateSpinners ();
167
	}
168
169
	/**
170
	 * Update the Spinner widgets to reflect the actual value set 
171
	 * on the "Example" widget.
172
	 */
173
	void updateSpinners () {
174
		minimumSpinner.setSelection (progressBar1.getMinimum ());
175
		selectionSpinner.setSelection (progressBar1.getSelection ());
176
		maximumSpinner.setSelection (progressBar1.getMaximum ());
177
	}
178
}
(-)src/org/eclipse/swt/examples/mirroringTest/RangeTab.java (+197 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
abstract class RangeTab extends Tab {
20
	/* Style widgets added to the "Style" group */
21
	Button horizontalButton, verticalButton;
22
	boolean orientationButtons = true;
23
24
	/* Scale widgets added to the "Control" group */
25
	Spinner minimumSpinner, selectionSpinner, maximumSpinner;
26
27
	/**
28
	 * Creates the Tab within a given instance of ControlExample.
29
	 */
30
	RangeTab(ControlExample instance) {
31
		super(instance);
32
	}
33
34
	/**
35
	 * Creates the "Control" widget children.
36
	 */
37
	void createControlWidgets () {
38
		/* Create controls specific to this example */
39
		createMinimumGroup ();
40
		createMaximumGroup ();
41
		createSelectionGroup ();
42
	}
43
	
44
	/**
45
	 * Create a group of widgets to control the maximum
46
	 * attribute of the example widget.
47
	 */
48
	void createMaximumGroup() {
49
	
50
		/* Create the group */
51
		Group maximumGroup = new Group (controlGroup, SWT.NONE);
52
		maximumGroup.setLayout (new GridLayout ());
53
		maximumGroup.setText (ControlExample.getResourceString("Maximum"));
54
		maximumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
55
	
56
		/* Create a Spinner widget */
57
		maximumSpinner = new Spinner (maximumGroup, SWT.BORDER);
58
		maximumSpinner.setMaximum (100000);
59
		maximumSpinner.setSelection (getDefaultMaximum());
60
		maximumSpinner.setPageIncrement (100);
61
		maximumSpinner.setIncrement (1);
62
		maximumSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
63
	
64
		/* Add the listeners */
65
		maximumSpinner.addSelectionListener(new SelectionAdapter () {
66
			public void widgetSelected (SelectionEvent event) {
67
				setWidgetMaximum ();
68
			}
69
		});
70
	}
71
	
72
	/**
73
	 * Create a group of widgets to control the minimum
74
	 * attribute of the example widget.
75
	 */
76
	void createMinimumGroup() {
77
	
78
		/* Create the group */
79
		Group minimumGroup = new Group (controlGroup, SWT.NONE);
80
		minimumGroup.setLayout (new GridLayout ());
81
		minimumGroup.setText (ControlExample.getResourceString("Minimum"));
82
		minimumGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
83
	
84
		/* Create a Spinner widget */
85
		minimumSpinner = new Spinner (minimumGroup, SWT.BORDER);
86
		minimumSpinner.setMaximum (100000);
87
		minimumSpinner.setSelection(getDefaultMinimum());
88
		minimumSpinner.setPageIncrement (100);
89
		minimumSpinner.setIncrement (1);
90
		minimumSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
91
92
		/* Add the listeners */
93
		minimumSpinner.addSelectionListener (new SelectionAdapter () {
94
			public void widgetSelected (SelectionEvent event) {
95
				setWidgetMinimum ();
96
			}
97
		});
98
	
99
	}
100
	
101
	/**
102
	 * Create a group of widgets to control the selection
103
	 * attribute of the example widget.
104
	 */
105
	void createSelectionGroup() {
106
	
107
		/* Create the group */
108
		Group selectionGroup = new Group(controlGroup, SWT.NONE);
109
		selectionGroup.setLayout(new GridLayout());
110
		GridData gridData = new GridData(SWT.FILL, SWT.BEGINNING, false, false);
111
		selectionGroup.setLayoutData(gridData);
112
		selectionGroup.setText(ControlExample.getResourceString("Selection"));
113
	
114
		/* Create a Spinner widget */
115
		selectionSpinner = new Spinner (selectionGroup, SWT.BORDER);
116
		selectionSpinner.setMaximum (100000);
117
		selectionSpinner.setSelection (getDefaultSelection());
118
		selectionSpinner.setPageIncrement (100);
119
		selectionSpinner.setIncrement (1);
120
		selectionSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
121
122
		/* Add the listeners */
123
		selectionSpinner.addSelectionListener(new SelectionAdapter() {
124
			public void widgetSelected(SelectionEvent event) {
125
				setWidgetSelection ();
126
			}
127
		});
128
		
129
	}
130
	
131
	/**
132
	 * Creates the "Style" group.
133
	 */
134
	void createStyleGroup () {
135
		super.createStyleGroup ();
136
	
137
		/* Create the extra widgets */
138
		if (orientationButtons) {
139
			horizontalButton = new Button (styleGroup, SWT.RADIO);
140
			horizontalButton.setText ("SWT.HORIZONTAL");
141
			verticalButton = new Button (styleGroup, SWT.RADIO);
142
			verticalButton.setText ("SWT.VERTICAL");
143
		}
144
		borderButton = new Button (styleGroup, SWT.CHECK);
145
		borderButton.setText ("SWT.BORDER");
146
	}
147
	
148
	/**
149
	 * Sets the state of the "Example" widgets.
150
	 */
151
	void setExampleWidgetState () {
152
		super.setExampleWidgetState ();
153
		if (!instance.startup) {
154
			setWidgetMinimum ();
155
			setWidgetMaximum ();
156
			setWidgetSelection ();
157
		}
158
		Widget [] widgets = getExampleWidgets ();
159
		if (widgets.length != 0) {
160
			if (orientationButtons) {
161
				horizontalButton.setSelection ((widgets [0].getStyle () & SWT.HORIZONTAL) != 0);
162
				verticalButton.setSelection ((widgets [0].getStyle () & SWT.VERTICAL) != 0);
163
			}
164
			borderButton.setSelection ((widgets [0].getStyle () & SWT.BORDER) != 0);
165
		}
166
	}
167
	
168
	/**
169
	 * Gets the default maximum of the "Example" widgets.
170
	 */
171
	abstract int getDefaultMaximum ();
172
	
173
	/**
174
	 * Gets the default minimim of the "Example" widgets.
175
	 */
176
	abstract int getDefaultMinimum ();
177
	
178
	/**
179
	 * Gets the default selection of the "Example" widgets.
180
	 */
181
	abstract int getDefaultSelection ();
182
183
	/**
184
	 * Sets the maximum of the "Example" widgets.
185
	 */
186
	abstract void setWidgetMaximum ();
187
	
188
	/**
189
	 * Sets the minimim of the "Example" widgets.
190
	 */
191
	abstract void setWidgetMinimum ();
192
	
193
	/**
194
	 * Sets the selection of the "Example" widgets.
195
	 */
196
	abstract void setWidgetSelection ();
197
}
(-)src/org/eclipse/swt/examples/mirroringTest/SashFormTab.java (+122 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.custom.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.widgets.*;
18
19
class SashFormTab extends Tab {
20
	/* Example widgets and groups that contain them */
21
	Group sashFormGroup;
22
	SashForm form;
23
	List list1, list2;
24
	Text text;
25
	
26
	/* Style widgets added to the "Style" group */
27
	Button horizontalButton, verticalButton, smoothButton;
28
29
	static String [] ListData0 = {ControlExample.getResourceString("ListData0_0"), //$NON-NLS-1$
30
								  ControlExample.getResourceString("ListData0_1"), //$NON-NLS-1$
31
								  ControlExample.getResourceString("ListData0_2"), //$NON-NLS-1$
32
								  ControlExample.getResourceString("ListData0_3"), //$NON-NLS-1$
33
								  ControlExample.getResourceString("ListData0_4"), //$NON-NLS-1$
34
								  ControlExample.getResourceString("ListData0_5"), //$NON-NLS-1$
35
								  ControlExample.getResourceString("ListData0_6"), //$NON-NLS-1$
36
								  ControlExample.getResourceString("ListData0_7")}; //$NON-NLS-1$
37
								  
38
	static String [] ListData1 = {ControlExample.getResourceString("ListData1_0"), //$NON-NLS-1$
39
								  ControlExample.getResourceString("ListData1_1"), //$NON-NLS-1$
40
								  ControlExample.getResourceString("ListData1_2"), //$NON-NLS-1$
41
								  ControlExample.getResourceString("ListData1_3"), //$NON-NLS-1$
42
								  ControlExample.getResourceString("ListData1_4"), //$NON-NLS-1$
43
								  ControlExample.getResourceString("ListData1_5"), //$NON-NLS-1$
44
								  ControlExample.getResourceString("ListData1_6"), //$NON-NLS-1$
45
								  ControlExample.getResourceString("ListData1_7")}; //$NON-NLS-1$
46
47
48
	/**
49
	 * Creates the Tab within a given instance of ControlExample.
50
	 */
51
	SashFormTab(ControlExample instance) {
52
		super(instance);
53
	}
54
	void createExampleGroup () {
55
		super.createExampleGroup ();
56
		
57
		/* Create a group for the sashform widget */
58
		sashFormGroup = new Group (exampleGroup, SWT.NONE);
59
		sashFormGroup.setLayout (new GridLayout ());
60
		sashFormGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
61
		sashFormGroup.setText ("SashForm");
62
	}
63
	void createExampleWidgets () {
64
		
65
		/* Compute the widget style */
66
		int style = getDefaultStyle();
67
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
68
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
69
		if (smoothButton.getSelection ()) style |= SWT.SMOOTH;
70
		
71
		/* Create the example widgets */
72
		form = new SashForm (sashFormGroup, style);
73
		list1 = new List (form, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
74
		list1.setItems (ListData0);
75
		list2 = new List (form, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
76
		list2.setItems (ListData1);
77
		text = new Text (form, SWT.MULTI | SWT.BORDER);
78
		text.setText (ControlExample.getResourceString("Multi_line")); //$NON-NLS-1$
79
		form.setWeights(new int[] {1, 1, 1});
80
	}
81
	/**
82
	 * Creates the "Style" group.
83
	 */
84
	void createStyleGroup() {
85
		super.createStyleGroup();
86
	
87
		/* Create the extra widgets */
88
		horizontalButton = new Button (styleGroup, SWT.RADIO);
89
		horizontalButton.setText ("SWT.HORIZONTAL");
90
		horizontalButton.setSelection(true);
91
		verticalButton = new Button (styleGroup, SWT.RADIO);
92
		verticalButton.setText ("SWT.VERTICAL");
93
		verticalButton.setSelection(false);
94
		smoothButton = new Button (styleGroup, SWT.CHECK);
95
		smoothButton.setText ("SWT.SMOOTH");
96
		smoothButton.setSelection(false);
97
	}
98
	
99
	/**
100
	 * Gets the "Example" widget children.
101
	 */
102
	Widget [] getExampleWidgets () {
103
		return new Widget [] {form};
104
	}
105
	
106
	/**
107
	 * Gets the text for the tab folder item.
108
	 */
109
	String getTabText () {
110
		return "SashForm"; //$NON-NLS-1$
111
	}
112
	
113
		/**
114
	 * Sets the state of the "Example" widgets.
115
	 */
116
	void setExampleWidgetState () {
117
		super.setExampleWidgetState ();
118
		horizontalButton.setSelection ((form.getStyle () & SWT.H_SCROLL) != 0);
119
		verticalButton.setSelection ((form.getStyle () & SWT.V_SCROLL) != 0);
120
		smoothButton.setSelection ((form.getStyle () & SWT.SMOOTH) != 0);
121
	}
122
}
(-)src/org/eclipse/swt/examples/mirroringTest/SashTab.java (+241 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.widgets.*;
18
import org.eclipse.swt.events.*;
19
20
class SashTab extends Tab {
21
	/* Example widgets and groups that contain them */
22
	Sash hSash, vSash;
23
	Composite sashComp;
24
	Group sashGroup;
25
	List list1, list2, list3;
26
	Text text;
27
	Button smoothButton;
28
29
	static String [] ListData0 = {ControlExample.getResourceString("ListData0_0"),
30
								  ControlExample.getResourceString("ListData0_1"),
31
								  ControlExample.getResourceString("ListData0_2"),
32
								  ControlExample.getResourceString("ListData0_3"),
33
								  ControlExample.getResourceString("ListData0_4"),
34
								  ControlExample.getResourceString("ListData0_5"),
35
								  ControlExample.getResourceString("ListData0_6"),
36
								  ControlExample.getResourceString("ListData0_7"),
37
								  ControlExample.getResourceString("ListData0_8")};
38
								  
39
	static String [] ListData1 = {ControlExample.getResourceString("ListData1_0"),
40
								  ControlExample.getResourceString("ListData1_1"),
41
								  ControlExample.getResourceString("ListData1_2"),
42
								  ControlExample.getResourceString("ListData1_3"),
43
								  ControlExample.getResourceString("ListData1_4"),
44
								  ControlExample.getResourceString("ListData1_5"),
45
								  ControlExample.getResourceString("ListData1_6"),
46
								  ControlExample.getResourceString("ListData1_7"),
47
								  ControlExample.getResourceString("ListData1_8")};
48
49
	/* Constants */
50
	static final int SASH_WIDTH = 3;
51
	static final int SASH_LIMIT = 20;
52
53
	/**
54
	 * Creates the Tab within a given instance of ControlExample.
55
	 */
56
	SashTab(ControlExample instance) {
57
		super(instance);
58
	}
59
	
60
	/**
61
	 * Creates the "Example" group.
62
	 */
63
	void createExampleGroup () {
64
		super.createExampleGroup ();
65
		exampleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
66
		exampleGroup.setLayout(new FillLayout());
67
		
68
		/* Create a group for the sash widgets */
69
		sashGroup = new Group (exampleGroup, SWT.NONE);
70
		FillLayout layout = new FillLayout();
71
		layout.marginHeight = layout.marginWidth = 5;
72
		sashGroup.setLayout(layout);
73
		sashGroup.setText ("Sash");
74
	}
75
76
	/**
77
	 * Creates the "Example" widgets.
78
	 */
79
	void createExampleWidgets () {
80
		/*
81
		 * Create the page.  This example does not use layouts.
82
		 */
83
		int style = getDefaultStyle();
84
		sashComp = new Composite(sashGroup, SWT.BORDER | style);
85
	
86
		/* Create the list and text widgets */
87
		list1 = new List (sashComp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
88
		list1.setItems (ListData0);
89
		list2 = new List (sashComp, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
90
		list2.setItems (ListData1);
91
		text = new Text (sashComp, SWT.MULTI | SWT.BORDER);
92
		text.setText (ControlExample.getResourceString("Multi_line"));
93
	
94
		/* Create the sashes */
95
		style = smoothButton.getSelection() ? SWT.SMOOTH : SWT.NONE;
96
		vSash = new Sash (sashComp, SWT.VERTICAL | style);
97
		hSash = new Sash (sashComp, SWT.HORIZONTAL | style);
98
		
99
		/* Add the listeners */
100
		hSash.addSelectionListener (new SelectionAdapter () {
101
			public void widgetSelected (SelectionEvent event) {
102
				Rectangle rect = vSash.getParent().getClientArea();
103
				event.y = Math.min (Math.max (event.y, SASH_LIMIT), rect.height - SASH_LIMIT);
104
				if (event.detail != SWT.DRAG) {
105
					hSash.setBounds (event.x, event.y, event.width, event.height);
106
					layout ();
107
				}
108
			}
109
		});
110
		vSash.addSelectionListener (new SelectionAdapter () {
111
			public void widgetSelected (SelectionEvent event) {
112
				Rectangle rect = vSash.getParent().getClientArea();
113
				event.x = Math.min (Math.max (event.x, SASH_LIMIT), rect.width - SASH_LIMIT);
114
				if (event.detail != SWT.DRAG) {
115
					vSash.setBounds (event.x, event.y, event.width, event.height);
116
					layout ();
117
				}
118
			}
119
		});
120
		sashComp.addControlListener (new ControlAdapter () {
121
			public void controlResized (ControlEvent event) {
122
				resized ();
123
			}
124
		});
125
	}
126
127
	/**
128
	 * Creates the "Size" group.  The "Size" group contains
129
	 * controls that allow the user to change the size of
130
	 * the example widgets.
131
	 */	
132
	void createSizeGroup () {		
133
	}
134
	
135
	/**
136
	 * Creates the "Style" group.
137
	 */
138
	void createStyleGroup() {
139
		super.createStyleGroup ();
140
	
141
		/* Create the extra widgets */
142
		smoothButton = new Button (styleGroup, SWT.CHECK);
143
		smoothButton.setText("SWT.SMOOTH");
144
	}
145
	
146
	void disposeExampleWidgets () {
147
		sashComp.dispose();
148
		sashComp = null;
149
	}
150
151
	/**
152
	 * Gets the "Example" widget children.
153
	 */
154
	Widget [] getExampleWidgets () {
155
		return new Widget [] {hSash, vSash};
156
	}
157
	
158
	/**
159
	 * Returns a list of set/get API method names (without the set/get prefix)
160
	 * that can be used to set/get values in the example control(s).
161
	 */
162
	String[] getMethodNames() {
163
		return new String[] {"ToolTipText"};
164
	}
165
166
	/**
167
	 * Gets the text for the tab folder item.
168
	 */
169
	String getTabText () {
170
		return "Sash";
171
	}
172
	
173
	/**
174
	 * Layout the list and text widgets according to the new
175
	 * positions of the sashes..events.SelectionEvent
176
	 */
177
	void layout () {
178
		
179
		Rectangle clientArea = sashComp.getClientArea ();
180
		Rectangle hSashBounds = hSash.getBounds ();
181
		Rectangle vSashBounds = vSash.getBounds ();
182
		
183
		list1.setBounds (0, 0, vSashBounds.x, hSashBounds.y);
184
		list2.setBounds (vSashBounds.x + vSashBounds.width, 0, clientArea.width - (vSashBounds.x + vSashBounds.width), hSashBounds.y);
185
		text.setBounds (0, hSashBounds.y + hSashBounds.height, clientArea.width, clientArea.height - (hSashBounds.y + hSashBounds.height));
186
	
187
		/**
188
		* If the horizontal sash has been moved then the vertical
189
		* sash is either too long or too short and its size must
190
		* be adjusted.
191
		*/
192
		vSashBounds.height = hSashBounds.y;
193
		vSash.setBounds (vSashBounds);
194
	}
195
	/**
196
	 * Sets the size of the "Example" widgets.
197
	 */
198
	void setExampleWidgetSize () {
199
		sashGroup.layout (true);
200
	}
201
	
202
	/**
203
	 * Sets the state of the "Example" widgets.
204
	 */
205
	void setExampleWidgetState () {
206
		super.setExampleWidgetState ();
207
		smoothButton.setSelection ((hSash.getStyle () & SWT.SMOOTH) != 0);
208
	}
209
	
210
	/**
211
	 * Handle the shell resized event.
212
	 */
213
	void resized () {
214
	
215
		/* Get the client area for the shell */
216
		Rectangle clientArea = sashComp.getClientArea ();
217
		
218
		/*
219
		* Make list 1 half the width and half the height of the tab leaving room for the sash.
220
		* Place list 1 in the top left quadrant of the tab.
221
		*/
222
		Rectangle list1Bounds = new Rectangle (0, 0, (clientArea.width - SASH_WIDTH) / 2, (clientArea.height - SASH_WIDTH) / 2);
223
		list1.setBounds (list1Bounds);
224
	
225
		/*
226
		* Make list 2 half the width and half the height of the tab leaving room for the sash.
227
		* Place list 2 in the top right quadrant of the tab.
228
		*/
229
		list2.setBounds (list1Bounds.width + SASH_WIDTH, 0, clientArea.width - (list1Bounds.width + SASH_WIDTH), list1Bounds.height);
230
	
231
		/*
232
		* Make the text area the full width and half the height of the tab leaving room for the sash.
233
		* Place the text area in the bottom half of the tab.
234
		*/
235
		text.setBounds (0, list1Bounds.height + SASH_WIDTH, clientArea.width, clientArea.height - (list1Bounds.height + SASH_WIDTH));
236
	
237
		/* Position the sashes */
238
		vSash.setBounds (list1Bounds.width, 0, SASH_WIDTH, list1Bounds.height);
239
		hSash.setBounds (0, list1Bounds.height, clientArea.width, SASH_WIDTH);
240
	}
241
}
(-)src/org/eclipse/swt/examples/mirroringTest/ScaleTab.java (+230 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
class ScaleTab extends RangeTab {
20
	/* Example widgets and groups that contain them */
21
	Scale scale1;
22
	Group scaleGroup;
23
24
	/* Spinner widgets added to the "Control" group */
25
	Spinner incrementSpinner, pageIncrementSpinner;
26
	
27
	/**
28
	 * Creates the Tab within a given instance of ControlExample.
29
	 */
30
	ScaleTab(ControlExample instance) {
31
		super(instance);
32
	}
33
34
	/**
35
	 * Creates the "Control" widget children.
36
	 */
37
	void createControlWidgets () {
38
		super.createControlWidgets ();
39
		createIncrementGroup ();
40
		createPageIncrementGroup ();
41
	}
42
	
43
	/**
44
	 * Creates the "Example" group.
45
	 */
46
	void createExampleGroup () {
47
		super.createExampleGroup ();
48
		
49
		/* Create a group for the scale */
50
		scaleGroup = new Group (exampleGroup, SWT.NONE);
51
		scaleGroup.setLayout (new GridLayout ());
52
		scaleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
53
		scaleGroup.setText ("Scale");
54
	
55
	}
56
	
57
	/**
58
	 * Creates the "Example" widgets.
59
	 */
60
	void createExampleWidgets () {
61
		
62
		/* Compute the widget style */
63
		int style = getDefaultStyle();
64
		if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
65
		if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
66
		if (borderButton.getSelection ()) style |= SWT.BORDER;
67
	
68
		/* Create the example widgets */
69
		scale1 = new Scale (scaleGroup, style);
70
	}
71
	
72
	/**
73
	 * Create a group of widgets to control the increment
74
	 * attribute of the example widget.
75
	 */
76
	void createIncrementGroup() {
77
	
78
		/* Create the group */
79
		Group incrementGroup = new Group (controlGroup, SWT.NONE);
80
		incrementGroup.setLayout (new GridLayout ());
81
		incrementGroup.setText (ControlExample.getResourceString("Increment"));
82
		incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
83
	
84
		/* Create the Spinner widget */
85
		incrementSpinner = new Spinner (incrementGroup, SWT.BORDER);
86
		incrementSpinner.setMaximum (100000);
87
		incrementSpinner.setSelection (getDefaultIncrement());
88
		incrementSpinner.setPageIncrement (100);
89
		incrementSpinner.setIncrement (1);
90
		incrementSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
91
	
92
		/* Add the listeners */
93
		incrementSpinner.addSelectionListener (new SelectionAdapter () {
94
			public void widgetSelected (SelectionEvent e) {		
95
				setWidgetIncrement ();
96
			}
97
		});
98
	}
99
	
100
	/**
101
	 * Create a group of widgets to control the page increment
102
	 * attribute of the example widget.
103
	 */
104
	void createPageIncrementGroup() {
105
	
106
		/* Create the group */
107
		Group pageIncrementGroup = new Group (controlGroup, SWT.NONE);
108
		pageIncrementGroup.setLayout (new GridLayout ());
109
		pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment"));
110
		pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
111
			
112
		/* Create the Spinner widget */
113
		pageIncrementSpinner = new Spinner (pageIncrementGroup, SWT.BORDER);
114
		pageIncrementSpinner.setMaximum (100000);
115
		pageIncrementSpinner.setSelection (getDefaultPageIncrement());
116
		pageIncrementSpinner.setPageIncrement (100);
117
		pageIncrementSpinner.setIncrement (1);
118
		pageIncrementSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
119
120
		/* Add the listeners */
121
		pageIncrementSpinner.addSelectionListener (new SelectionAdapter () {
122
			public void widgetSelected (SelectionEvent event) {
123
				setWidgetPageIncrement ();
124
			}
125
		});
126
	}
127
	
128
	/**
129
	 * Gets the "Example" widget children.
130
	 */
131
	Widget [] getExampleWidgets () {
132
		return new Widget [] {scale1};
133
	}
134
	
135
	/**
136
	 * Returns a list of set/get API method names (without the set/get prefix)
137
	 * that can be used to set/get values in the example control(s).
138
	 */
139
	String[] getMethodNames() {
140
		return new String[] {"Selection", "ToolTipText"};
141
	}
142
143
	/**
144
	 * Gets the text for the tab folder item.
145
	 */
146
	String getTabText () {
147
		return "Scale";
148
	}
149
	
150
	/**
151
	 * Sets the state of the "Example" widgets.
152
	 */
153
	void setExampleWidgetState () {
154
		super.setExampleWidgetState ();
155
		if (!instance.startup) {
156
			setWidgetIncrement ();
157
			setWidgetPageIncrement ();
158
		}
159
	}
160
	
161
	/**
162
	 * Gets the default maximum of the "Example" widgets.
163
	 */
164
	int getDefaultMaximum () {
165
		return scale1.getMaximum();
166
	}
167
	
168
	/**
169
	 * Gets the default minimim of the "Example" widgets.
170
	 */
171
	int getDefaultMinimum () {
172
		return scale1.getMinimum();
173
	}
174
	
175
	/**
176
	 * Gets the default selection of the "Example" widgets.
177
	 */
178
	int getDefaultSelection () {
179
		return scale1.getSelection();
180
	}
181
182
	/**
183
	 * Gets the default increment of the "Example" widgets.
184
	 */
185
	int getDefaultIncrement () {
186
		return scale1.getIncrement();
187
	}
188
	
189
	/**
190
	 * Gets the default page increment of the "Example" widgets.
191
	 */
192
	int getDefaultPageIncrement () {
193
		return scale1.getPageIncrement();
194
	}
195
	
196
	/**
197
	 * Sets the increment of the "Example" widgets.
198
	 */
199
	void setWidgetIncrement () {
200
		scale1.setIncrement (incrementSpinner.getSelection ());
201
	}
202
	
203
	/**
204
	 * Sets the minimim of the "Example" widgets.
205
	 */
206
	void setWidgetMaximum () {
207
		scale1.setMaximum (maximumSpinner.getSelection ());
208
	}
209
	
210
	/**
211
	 * Sets the minimim of the "Example" widgets.
212
	 */
213
	void setWidgetMinimum () {
214
		scale1.setMinimum (minimumSpinner.getSelection ());
215
	}
216
	
217
	/**
218
	 * Sets the page increment of the "Example" widgets.
219
	 */
220
	void setWidgetPageIncrement () {
221
		scale1.setPageIncrement (pageIncrementSpinner.getSelection ());
222
	}
223
	
224
	/**
225
	 * Sets the selection of the "Example" widgets.
226
	 */
227
	void setWidgetSelection () {
228
		scale1.setSelection (selectionSpinner.getSelection ());
229
	}
230
}
(-)src/org/eclipse/swt/examples/mirroringTest/ScrollableTab.java (+63 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
17
abstract class ScrollableTab extends Tab {
18
	/* Style widgets added to the "Style" group */	
19
	Button singleButton, multiButton, horizontalButton, verticalButton;
20
21
	/**
22
	 * Creates the Tab within a given instance of ControlExample.
23
	 */
24
	ScrollableTab(ControlExample instance) {
25
		super(instance);
26
	}
27
28
	/**
29
	 * Creates the "Style" group.
30
	 */
31
	void createStyleGroup () {
32
		super.createStyleGroup ();
33
	
34
		/* Create the extra widgets */
35
		singleButton = new Button (styleGroup, SWT.RADIO);
36
		singleButton.setText ("SWT.SINGLE");
37
		multiButton = new Button (styleGroup, SWT.RADIO);
38
		multiButton.setText ("SWT.MULTI");
39
		horizontalButton = new Button (styleGroup, SWT.CHECK);
40
		horizontalButton.setText ("SWT.H_SCROLL");
41
		horizontalButton.setSelection(true);
42
		verticalButton = new Button (styleGroup, SWT.CHECK);
43
		verticalButton.setText ("SWT.V_SCROLL");
44
		verticalButton.setSelection(true);
45
		borderButton = new Button (styleGroup, SWT.CHECK);
46
		borderButton.setText ("SWT.BORDER");
47
	}
48
	
49
	/**
50
	 * Sets the state of the "Example" widgets.
51
	 */
52
	void setExampleWidgetState () {
53
		super.setExampleWidgetState ();
54
		Widget [] widgets = getExampleWidgets ();
55
		if (widgets.length != 0){
56
			singleButton.setSelection ((widgets [0].getStyle () & SWT.SINGLE) != 0);
57
			multiButton.setSelection ((widgets [0].getStyle () & SWT.MULTI) != 0);
58
			horizontalButton.setSelection ((widgets [0].getStyle () & SWT.H_SCROLL) != 0);
59
			verticalButton.setSelection ((widgets [0].getStyle () & SWT.V_SCROLL) != 0);
60
			borderButton.setSelection ((widgets [0].getStyle () & SWT.BORDER) != 0);
61
		}
62
	}
63
}
(-)src/org/eclipse/swt/examples/mirroringTest/ShellTab.java (+341 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2006 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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
class ShellTab extends Tab {	
20
	/* Style widgets added to the "Style" groups, and "Other" group */
21
	Button noParentButton, parentButton;
22
	Button noTrimButton, closeButton, titleButton, minButton, maxButton, borderButton, resizeButton, onTopButton, toolButton, sheetButton, shellTrimButton, dialogTrimButton;
23
	Button createButton, closeAllButton;
24
	Button modelessButton, primaryModalButton, applicationModalButton, systemModalButton;
25
	Button imageButton;
26
	Group parentStyleGroup, modalStyleGroup;
27
28
	/* Variables used to track the open shells */
29
	int shellCount = 0;
30
	Shell [] shells = new Shell [4];
31
	
32
	/**
33
	 * Creates the Tab within a given instance of ControlExample.
34
	 */
35
	ShellTab(ControlExample instance) {
36
		super(instance);
37
	}
38
39
	/**
40
	 * Close all the example shells.
41
	 */
42
	void closeAllShells() {
43
		for (int i = 0; i<shellCount; i++) {
44
			if (shells [i] != null & !shells [i].isDisposed ()) {
45
				shells [i].dispose();
46
				shells [i] = null;
47
			}
48
		}
49
		shellCount = 0;
50
	}
51
	
52
	/**
53
	 * Handle the Create button selection event.
54
	 *
55
	 * @param event org.eclipse.swt.events.SelectionEvent
56
	 */
57
	public void createButtonSelected(SelectionEvent event) {
58
	
59
		/*
60
		 * Remember the example shells so they
61
		 * can be disposed by the user.
62
		 */
63
		if (shellCount >= shells.length) {
64
			Shell [] newShells = new Shell [shells.length + 4];
65
			System.arraycopy (shells, 0, newShells, 0, shells.length);
66
			shells = newShells;
67
		}
68
	
69
		/* Compute the shell style */
70
		int style = SWT.NONE;
71
		if (noTrimButton.getSelection()) style |= SWT.NO_TRIM;
72
		if (closeButton.getSelection()) style |= SWT.CLOSE;
73
		if (titleButton.getSelection()) style |= SWT.TITLE;
74
		if (minButton.getSelection()) style |= SWT.MIN;
75
		if (maxButton.getSelection()) style |= SWT.MAX;
76
		if (borderButton.getSelection()) style |= SWT.BORDER;
77
		if (resizeButton.getSelection()) style |= SWT.RESIZE;
78
		if (onTopButton.getSelection()) style |= SWT.ON_TOP;
79
		if (toolButton.getSelection()) style |= SWT.TOOL;
80
		if (sheetButton.getSelection()) style |= SWT.SHEET;
81
		if (modelessButton.getSelection()) style |= SWT.MODELESS;
82
		if (primaryModalButton.getSelection()) style |= SWT.PRIMARY_MODAL;
83
		if (applicationModalButton.getSelection()) style |= SWT.APPLICATION_MODAL;
84
		if (systemModalButton.getSelection()) style |= SWT.SYSTEM_MODAL;
85
	
86
		/* Create the shell with or without a parent */
87
		if (noParentButton.getSelection ()) {
88
			shells [shellCount] = new Shell (style);
89
		} else {
90
			shells [shellCount] = new Shell (shell, style);
91
		}
92
		final Shell currentShell = shells [shellCount];
93
		currentShell.setBackgroundMode(SWT.INHERIT_DEFAULT);
94
		final Button button = new Button(currentShell, SWT.CHECK);
95
		button.setBounds(20, 20, 120, 30);
96
		button.setText(ControlExample.getResourceString("FullScreen"));
97
		button.addSelectionListener(new SelectionAdapter() {
98
			public void widgetSelected(SelectionEvent e) {
99
				currentShell.setFullScreen(button.getSelection());
100
			}
101
		});
102
		Button close = new Button(currentShell, SWT.PUSH);
103
		close.setBounds(160, 20, 120, 30);
104
		close.setText(ControlExample.getResourceString("Close"));
105
		close.addListener(SWT.Selection, new Listener() {
106
			public void handleEvent(Event event) {
107
				currentShell.dispose();
108
			}
109
		});
110
	
111
		/* Set the size, title, and image, and open the shell */
112
		currentShell.setSize (300, 100);
113
		currentShell.setText (ControlExample.getResourceString("Title") + shellCount);
114
		if (imageButton.getSelection()) currentShell.setImage(instance.images[ControlExample.ciTarget]);
115
		if (backgroundImageButton.getSelection()) currentShell.setBackgroundImage(instance.images[ControlExample.ciBackground]);
116
		hookListeners (currentShell);
117
		currentShell.open ();
118
		shellCount++;
119
	}
120
	
121
	/**
122
	 * Creates the "Control" group. 
123
	 */
124
	void createControlGroup () {
125
		/*
126
		 * Create the "Control" group.  This is the group on the
127
		 * right half of each example tab.  It consists of the
128
		 * style group, the 'other' group and the size group.
129
		 */		
130
		controlGroup = new Group (tabFolderPage, SWT.NONE);
131
		controlGroup.setLayout (new GridLayout (2, true));
132
		controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
133
		controlGroup.setText (ControlExample.getResourceString("Parameters"));
134
	
135
		/* Create a group for the decoration style controls */
136
		styleGroup = new Group (controlGroup, SWT.NONE);
137
		styleGroup.setLayout (new GridLayout ());
138
		styleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false, 1, 3));
139
		styleGroup.setText (ControlExample.getResourceString("Decoration_Styles"));
140
	
141
		/* Create a group for the modal style controls */
142
		modalStyleGroup = new Group (controlGroup, SWT.NONE);
143
		modalStyleGroup.setLayout (new GridLayout ());
144
		modalStyleGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
145
		modalStyleGroup.setText (ControlExample.getResourceString("Modal_Styles"));		
146
147
		/* Create a group for the 'other' controls */
148
		otherGroup = new Group (controlGroup, SWT.NONE);
149
		otherGroup.setLayout (new GridLayout ());
150
		otherGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false));
151
		otherGroup.setText (ControlExample.getResourceString("Other"));
152
153
		/* Create a group for the parent style controls */
154
		parentStyleGroup = new Group (controlGroup, SWT.NONE);
155
		parentStyleGroup.setLayout (new GridLayout ());
156
		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
157
		parentStyleGroup.setLayoutData (gridData);
158
		parentStyleGroup.setText (ControlExample.getResourceString("Parent"));
159
	}
160
	
161
	/**
162
	 * Creates the "Control" widget children.
163
	 */
164
	void createControlWidgets () {
165
	
166
		/* Create the parent style buttons */
167
		noParentButton = new Button (parentStyleGroup, SWT.RADIO);
168
		noParentButton.setText (ControlExample.getResourceString("No_Parent"));
169
		parentButton = new Button (parentStyleGroup, SWT.RADIO);
170
		parentButton.setText (ControlExample.getResourceString("Parent"));
171
	
172
		/* Create the decoration style buttons */
173
		noTrimButton = new Button (styleGroup, SWT.CHECK);
174
		noTrimButton.setText ("SWT.NO_TRIM");
175
		closeButton = new Button (styleGroup, SWT.CHECK);
176
		closeButton.setText ("SWT.CLOSE");
177
		titleButton = new Button (styleGroup, SWT.CHECK);
178
		titleButton.setText ("SWT.TITLE");
179
		minButton = new Button (styleGroup, SWT.CHECK);
180
		minButton.setText ("SWT.MIN");
181
		maxButton = new Button (styleGroup, SWT.CHECK);
182
		maxButton.setText ("SWT.MAX");
183
		borderButton = new Button (styleGroup, SWT.CHECK);
184
		borderButton.setText ("SWT.BORDER");
185
		resizeButton = new Button (styleGroup, SWT.CHECK);
186
		resizeButton.setText ("SWT.RESIZE");
187
		onTopButton = new Button (styleGroup, SWT.CHECK);
188
		onTopButton.setText ("SWT.ON_TOP");
189
		toolButton = new Button (styleGroup, SWT.CHECK);
190
		toolButton.setText ("SWT.TOOL");
191
		sheetButton = new Button (styleGroup, SWT.CHECK);
192
		sheetButton.setText ("SWT.SHEET");
193
		Label separator = new Label(styleGroup, SWT.SEPARATOR | SWT.HORIZONTAL);
194
		separator.setLayoutData(new GridData (SWT.FILL, SWT.CENTER, true, false));
195
		shellTrimButton = new Button (styleGroup, SWT.CHECK);
196
		shellTrimButton.setText ("SWT.SHELL_TRIM");
197
		dialogTrimButton = new Button (styleGroup, SWT.CHECK);
198
		dialogTrimButton.setText ("SWT.DIALOG_TRIM");
199
	
200
		/* Create the modal style buttons */
201
		modelessButton = new Button (modalStyleGroup, SWT.RADIO);
202
		modelessButton.setText ("SWT.MODELESS");
203
		primaryModalButton = new Button (modalStyleGroup, SWT.RADIO);
204
		primaryModalButton.setText ("SWT.PRIMARY_MODAL");
205
		applicationModalButton = new Button (modalStyleGroup, SWT.RADIO);
206
		applicationModalButton.setText ("SWT.APPLICATION_MODAL");
207
		systemModalButton = new Button (modalStyleGroup, SWT.RADIO);
208
		systemModalButton.setText ("SWT.SYSTEM_MODAL");
209
	
210
		/* Create the 'other' buttons */
211
		imageButton = new Button (otherGroup, SWT.CHECK);
212
		imageButton.setText (ControlExample.getResourceString("Image"));
213
		backgroundImageButton = new Button(otherGroup, SWT.CHECK);
214
		backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage"));
215
	
216
		/* Create the "create" and "closeAll" buttons */
217
		createButton = new Button (controlGroup, SWT.NONE);
218
		GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_END);
219
		createButton.setLayoutData (gridData);
220
		createButton.setText (ControlExample.getResourceString("Create_Shell"));
221
		closeAllButton = new Button (controlGroup, SWT.NONE);
222
		gridData = new GridData (GridData.HORIZONTAL_ALIGN_BEGINNING);
223
		closeAllButton.setText (ControlExample.getResourceString("Close_All_Shells"));
224
		closeAllButton.setLayoutData (gridData);
225
	
226
		/* Add the listeners */
227
		createButton.addSelectionListener(new SelectionAdapter() {
228
			public void widgetSelected(SelectionEvent e) {
229
				createButtonSelected(e);
230
			}
231
		});
232
		closeAllButton.addSelectionListener(new SelectionAdapter() {
233
			public void widgetSelected(SelectionEvent e) {
234
				closeAllShells ();
235
			}
236
		});
237
		SelectionListener decorationButtonListener = new SelectionAdapter() {
238
			public void widgetSelected(SelectionEvent event) {
239
				decorationButtonSelected(event);
240
			}
241
		};
242
		noTrimButton.addSelectionListener (decorationButtonListener);
243
		closeButton.addSelectionListener (decorationButtonListener);
244
		titleButton.addSelectionListener (decorationButtonListener);
245
		minButton.addSelectionListener (decorationButtonListener);
246
		maxButton.addSelectionListener (decorationButtonListener);
247
		borderButton.addSelectionListener (decorationButtonListener);
248
		resizeButton.addSelectionListener (decorationButtonListener);
249
		dialogTrimButton.addSelectionListener (decorationButtonListener);
250
		shellTrimButton.addSelectionListener (decorationButtonListener);
251
		applicationModalButton.addSelectionListener (decorationButtonListener);
252
		systemModalButton.addSelectionListener (decorationButtonListener);
253
	
254
		/* Set the default state */
255
		noParentButton.setSelection (true);
256
		modelessButton.setSelection (true);
257
	}
258
	
259
	/**
260
	 * Handle a decoration button selection event.
261
	 *
262
	 * @param event org.eclipse.swt.events.SelectionEvent
263
	 */
264
	public void decorationButtonSelected(SelectionEvent event) {
265
		Button widget = (Button) event.widget;
266
		
267
		/*
268
		 * Make sure that if the modal style is SWT.APPLICATION_MODAL 
269
		 * or SWT.SYSTEM_MODAL the style SWT.CLOSE is also selected.
270
		 * This is to make sure the user can close the shell.
271
		 */
272
		if (widget == applicationModalButton || widget == systemModalButton) {
273
			if (widget.getSelection()) {
274
				closeButton.setSelection (true);
275
				noTrimButton.setSelection (false);
276
			} 
277
			return;
278
		}
279
		if (widget == closeButton) {
280
			if (applicationModalButton.getSelection() || systemModalButton.getSelection()) {
281
				closeButton.setSelection (true);
282
			}
283
		}	
284
		/*
285
		 * Make sure that if the SWT.NO_TRIM button is selected
286
		 * then all other decoration buttons are deselected.
287
		 */
288
		if (widget.getSelection()) {
289
			if (widget == noTrimButton) {
290
				if (applicationModalButton.getSelection() || systemModalButton.getSelection()) {
291
					noTrimButton.setSelection (false);
292
					return;
293
				}
294
				closeButton.setSelection (false);
295
				titleButton.setSelection (false);
296
				minButton.setSelection (false);
297
				maxButton.setSelection (false);
298
				borderButton.setSelection (false);
299
				resizeButton.setSelection (false);
300
			} else {
301
				noTrimButton.setSelection (false);
302
			}
303
		}
304
		
305
		/*
306
		 * Make sure that the SWT.DIALOG_TRIM and SWT.SHELL_TRIM buttons
307
		 * are consistent.
308
		 */
309
		if (widget == dialogTrimButton || widget == shellTrimButton) {
310
			if (widget.getSelection() && widget == dialogTrimButton) {
311
				shellTrimButton.setSelection(false);
312
			} else {
313
				dialogTrimButton.setSelection(false);
314
			}
315
			//SHELL_TRIM = CLOSE | TITLE | MIN | MAX | RESIZE;
316
			//DIALOG_TRIM = TITLE | CLOSE | BORDER;
317
			closeButton.setSelection (widget.getSelection ());
318
			titleButton.setSelection (widget.getSelection ());
319
			minButton.setSelection (widget == shellTrimButton && widget.getSelection( ));
320
			maxButton.setSelection (widget == shellTrimButton && widget.getSelection ());
321
			borderButton.setSelection (widget == dialogTrimButton && widget.getSelection ());
322
			resizeButton.setSelection (widget == shellTrimButton && widget.getSelection ());
323
		} else {
324
			boolean title = titleButton.getSelection ();
325
			boolean close = closeButton.getSelection ();
326
			boolean min = minButton.getSelection ();
327
			boolean max = maxButton.getSelection ();
328
			boolean border = borderButton.getSelection ();
329
			boolean resize = resizeButton.getSelection ();
330
			dialogTrimButton.setSelection(title && close && border && !min && !max && !resize);
331
			shellTrimButton.setSelection(title && close && min && max && resize && !border);
332
		}
333
	}
334
	
335
	/**
336
	 * Gets the text for the tab folder item.
337
	 */
338
	String getTabText () {
339
		return "Shell";
340
	}
341
}
(-)src/org/eclipse/swt/examples/mirroringTest/SliderTab.java (+273 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.events.*;
18
19
class SliderTab extends RangeTab {
20
	/* Example widgets and groups that contain them */
21
	Slider slider1;
22
	Group sliderGroup;
23
24
	/* Spinner widgets added to the "Control" group */
25
	Spinner incrementSpinner, pageIncrementSpinner, thumbSpinner;
26
	
27
	/**
28
	 * Creates the Tab within a given instance of ControlExample.
29
	 */
30
	SliderTab(ControlExample instance) {
31
		super(instance);
32
	}
33
34
	/**
35
	 * Creates the "Control" widget children.
36
	 */
37
	void createControlWidgets () {
38
		super.createControlWidgets ();
39
		createThumbGroup ();
40
		createIncrementGroup ();
41
		createPageIncrementGroup ();
42
	}
43
	
44
	/**
45
	 * Creates the "Example" group.
46
	 */
47
	void createExampleGroup () {
48
		super.createExampleGroup ();
49
		
50
		/* Create a group for the slider */
51
		sliderGroup = new Group (exampleGroup, SWT.NONE);
52
		sliderGroup.setLayout (new GridLayout ());
53
		sliderGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
54
		sliderGroup.setText ("Slider");
55
	}
56
	
57
	/**
58
	 * Creates the "Example" widgets.
59
	 */
60
	void createExampleWidgets () {
61
		
62
		/* Compute the widget style */
63
		int style = getDefaultStyle();
64
		if (horizontalButton.getSelection ()) style |= SWT.HORIZONTAL;
65
		if (verticalButton.getSelection ()) style |= SWT.VERTICAL;
66
		if (borderButton.getSelection ()) style |= SWT.BORDER;
67
	
68
		/* Create the example widgets */
69
		slider1 = new Slider(sliderGroup, style);
70
	}
71
	
72
	/**
73
	 * Create a group of widgets to control the increment
74
	 * attribute of the example widget.
75
	 */
76
	void createIncrementGroup() {
77
	
78
		/* Create the group */
79
		Group incrementGroup = new Group (controlGroup, SWT.NONE);
80
		incrementGroup.setLayout (new GridLayout ());
81
		incrementGroup.setText (ControlExample.getResourceString("Increment"));
82
		incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
83
	
84
		/* Create the Spinner widget */
85
		incrementSpinner = new Spinner (incrementGroup, SWT.BORDER);
86
		incrementSpinner.setMaximum (100000);
87
		incrementSpinner.setSelection (getDefaultIncrement());
88
		incrementSpinner.setPageIncrement (100);
89
		incrementSpinner.setIncrement (1);
90
		incrementSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
91
	
92
		/* Add the listeners */
93
		incrementSpinner.addSelectionListener (new SelectionAdapter () {
94
			public void widgetSelected (SelectionEvent e) {		
95
				setWidgetIncrement ();
96
			}
97
		});
98
	}
99
	
100
	/**
101
	 * Create a group of widgets to control the page increment
102
	 * attribute of the example widget.
103
	 */
104
	void createPageIncrementGroup() {
105
	
106
		/* Create the group */
107
		Group pageIncrementGroup = new Group (controlGroup, SWT.NONE);
108
		pageIncrementGroup.setLayout (new GridLayout ());
109
		pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment"));
110
		pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
111
			
112
		/* Create the Spinner widget */
113
		pageIncrementSpinner = new Spinner (pageIncrementGroup, SWT.BORDER);
114
		pageIncrementSpinner.setMaximum (100000);
115
		pageIncrementSpinner.setSelection (getDefaultPageIncrement());
116
		pageIncrementSpinner.setPageIncrement (100);
117
		pageIncrementSpinner.setIncrement (1);
118
		pageIncrementSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
119
120
		/* Add the listeners */
121
		pageIncrementSpinner.addSelectionListener (new SelectionAdapter () {
122
			public void widgetSelected (SelectionEvent event) {
123
				setWidgetPageIncrement ();
124
			}
125
		});
126
	}
127
	
128
	/**
129
	 * Create a group of widgets to control the thumb
130
	 * attribute of the example widget.
131
	 */
132
	void createThumbGroup() {
133
	
134
		/* Create the group */
135
		Group thumbGroup = new Group (controlGroup, SWT.NONE);
136
		thumbGroup.setLayout (new GridLayout ());
137
		thumbGroup.setText (ControlExample.getResourceString("Thumb"));
138
		thumbGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
139
		
140
		/* Create the Spinner widget */
141
		thumbSpinner = new Spinner (thumbGroup, SWT.BORDER);
142
		thumbSpinner.setMaximum (100000);
143
		thumbSpinner.setSelection (getDefaultThumb());
144
		thumbSpinner.setPageIncrement (100);
145
		thumbSpinner.setIncrement (1);
146
		thumbSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
147
148
		/* Add the listeners */
149
		thumbSpinner.addSelectionListener (new SelectionAdapter () {
150
			public void widgetSelected (SelectionEvent event) {
151
				setWidgetThumb ();
152
			}
153
		});
154
	}
155
	
156
	/**
157
	 * Gets the "Example" widget children.
158
	 */
159
	Widget [] getExampleWidgets () {
160
		return new Widget [] {slider1};
161
	}
162
	
163
	/**
164
	 * Returns a list of set/get API method names (without the set/get prefix)
165
	 * that can be used to set/get values in the example control(s).
166
	 */
167
	String[] getMethodNames() {
168
		return new String[] {"Selection", "ToolTipText"};
169
	}
170
171
	/**
172
	 * Gets the text for the tab folder item.
173
	 */
174
	String getTabText () {
175
		return "Slider";
176
	}
177
	
178
	/**
179
	 * Sets the state of the "Example" widgets.
180
	 */
181
	void setExampleWidgetState () {
182
		super.setExampleWidgetState ();
183
		if (!instance.startup) {
184
			setWidgetIncrement ();
185
			setWidgetPageIncrement ();
186
			setWidgetThumb ();
187
		}
188
	}
189
	
190
	/**
191
	 * Gets the default maximum of the "Example" widgets.
192
	 */
193
	int getDefaultMaximum () {
194
		return slider1.getMaximum();
195
	}
196
	
197
	/**
198
	 * Gets the default minimim of the "Example" widgets.
199
	 */
200
	int getDefaultMinimum () {
201
		return slider1.getMinimum();
202
	}
203
	
204
	/**
205
	 * Gets the default selection of the "Example" widgets.
206
	 */
207
	int getDefaultSelection () {
208
		return slider1.getSelection();
209
	}
210
211
	/**
212
	 * Gets the default increment of the "Example" widgets.
213
	 */
214
	int getDefaultIncrement () {
215
		return slider1.getIncrement();
216
	}
217
	
218
	/**
219
	 * Gets the default page increment of the "Example" widgets.
220
	 */
221
	int getDefaultPageIncrement () {
222
		return slider1.getPageIncrement();
223
	}
224
	
225
	/**
226
	 * Gets the default thumb of the "Example" widgets.
227
	 */
228
	int getDefaultThumb () {
229
		return slider1.getThumb();
230
	}
231
232
	/**
233
	 * Sets the increment of the "Example" widgets.
234
	 */
235
	void setWidgetIncrement () {
236
		slider1.setIncrement (incrementSpinner.getSelection ());
237
	}
238
	
239
	/**
240
	 * Sets the minimim of the "Example" widgets.
241
	 */
242
	void setWidgetMaximum () {
243
		slider1.setMaximum (maximumSpinner.getSelection ());
244
	}
245
	
246
	/**
247
	 * Sets the minimim of the "Example" widgets.
248
	 */
249
	void setWidgetMinimum () {
250
		slider1.setMinimum (minimumSpinner.getSelection ());
251
	}
252
	
253
	/**
254
	 * Sets the page increment of the "Example" widgets.
255
	 */
256
	void setWidgetPageIncrement () {
257
		slider1.setPageIncrement (pageIncrementSpinner.getSelection ());
258
	}
259
	
260
	/**
261
	 * Sets the selection of the "Example" widgets.
262
	 */
263
	void setWidgetSelection () {
264
		slider1.setSelection (selectionSpinner.getSelection ());
265
	}
266
	
267
	/**
268
	 * Sets the thumb of the "Example" widgets.
269
	 */
270
	void setWidgetThumb () {
271
		slider1.setThumb (thumbSpinner.getSelection ());
272
	}
273
}
(-)src/org/eclipse/swt/examples/mirroringTest/SpinnerTab.java (+317 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.events.*;
17
import org.eclipse.swt.layout.*;
18
19
class SpinnerTab extends RangeTab {
20
21
	/* Example widgets and groups that contain them */
22
	Spinner spinner1;
23
	Group spinnerGroup;
24
	
25
	/* Style widgets added to the "Style" group */
26
	Button readOnlyButton, wrapButton;
27
	
28
	/* Spinner widgets added to the "Control" group */
29
	Spinner incrementSpinner, pageIncrementSpinner, digitsSpinner;
30
31
	/**
32
	 * Creates the Tab within a given instance of ControlExample.
33
	 */
34
	SpinnerTab(ControlExample instance) {
35
		super(instance);
36
	}
37
	
38
	/**
39
	 * Creates the "Control" widget children.
40
	 */
41
	void createControlWidgets () {
42
		super.createControlWidgets ();
43
		createIncrementGroup ();
44
		createPageIncrementGroup ();
45
		createDigitsGroup ();
46
	}
47
	
48
	/**
49
	 * Creates the "Example" group.
50
	 */
51
	void createExampleGroup () {
52
		super.createExampleGroup ();
53
		
54
		/* Create a group for the spinner */
55
		spinnerGroup = new Group (exampleGroup, SWT.NONE);
56
		spinnerGroup.setLayout (new GridLayout ());
57
		spinnerGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
58
		spinnerGroup.setText ("Spinner");
59
	}
60
	
61
	/**
62
	 * Creates the "Example" widgets.
63
	 */
64
	void createExampleWidgets () {
65
		
66
		/* Compute the widget style */
67
		int style = getDefaultStyle();
68
		if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
69
		if (borderButton.getSelection ()) style |= SWT.BORDER;
70
		if (wrapButton.getSelection ()) style |= SWT.WRAP;
71
		
72
		/* Create the example widgets */
73
		spinner1 = new Spinner (spinnerGroup, style);
74
	}
75
	
76
	/**
77
	 * Create a group of widgets to control the increment
78
	 * attribute of the example widget.
79
	 */
80
	void createIncrementGroup() {
81
	
82
		/* Create the group */
83
		Group incrementGroup = new Group (controlGroup, SWT.NONE);
84
		incrementGroup.setLayout (new GridLayout ());
85
		incrementGroup.setText (ControlExample.getResourceString("Increment"));
86
		incrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
87
	
88
		/* Create the Spinner widget */
89
		incrementSpinner = new Spinner (incrementGroup, SWT.BORDER);
90
		incrementSpinner.setMaximum (100000);
91
		incrementSpinner.setSelection (getDefaultIncrement());
92
		incrementSpinner.setPageIncrement (100);
93
		incrementSpinner.setIncrement (1);
94
		incrementSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
95
	
96
		/* Add the listeners */
97
		incrementSpinner.addSelectionListener (new SelectionAdapter () {
98
			public void widgetSelected (SelectionEvent e) {		
99
				setWidgetIncrement ();
100
			}
101
		});
102
	}
103
	
104
	/**
105
	 * Create a group of widgets to control the page increment
106
	 * attribute of the example widget.
107
	 */
108
	void createPageIncrementGroup() {
109
	
110
		/* Create the group */
111
		Group pageIncrementGroup = new Group (controlGroup, SWT.NONE);
112
		pageIncrementGroup.setLayout (new GridLayout ());
113
		pageIncrementGroup.setText (ControlExample.getResourceString("Page_Increment"));
114
		pageIncrementGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
115
			
116
		/* Create the Spinner widget */
117
		pageIncrementSpinner = new Spinner (pageIncrementGroup, SWT.BORDER);
118
		pageIncrementSpinner.setMaximum (100000);
119
		pageIncrementSpinner.setSelection (getDefaultPageIncrement());
120
		pageIncrementSpinner.setPageIncrement (100);
121
		pageIncrementSpinner.setIncrement (1);
122
		pageIncrementSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
123
124
		/* Add the listeners */
125
		pageIncrementSpinner.addSelectionListener (new SelectionAdapter () {
126
			public void widgetSelected (SelectionEvent event) {
127
				setWidgetPageIncrement ();
128
			}
129
		});
130
	}
131
	
132
	/**
133
	 * Create a group of widgets to control the digits
134
	 * attribute of the example widget.
135
	 */
136
	void createDigitsGroup() {
137
	
138
		/* Create the group */
139
		Group digitsGroup = new Group (controlGroup, SWT.NONE);
140
		digitsGroup.setLayout (new GridLayout ());
141
		digitsGroup.setText (ControlExample.getResourceString("Digits"));
142
		digitsGroup.setLayoutData (new GridData (GridData.FILL_HORIZONTAL));
143
	
144
		/* Create the Spinner widget */
145
		digitsSpinner = new Spinner (digitsGroup, SWT.BORDER);
146
		digitsSpinner.setMaximum (100000);
147
		digitsSpinner.setSelection (getDefaultDigits());
148
		digitsSpinner.setPageIncrement (100);
149
		digitsSpinner.setIncrement (1);
150
		digitsSpinner.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
151
	
152
		/* Add the listeners */
153
		digitsSpinner.addSelectionListener (new SelectionAdapter () {
154
			public void widgetSelected (SelectionEvent e) {		
155
				setWidgetDigits ();
156
			}
157
		});
158
	}
159
	
160
	/**
161
	 * Creates the tab folder page.
162
	 *
163
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
164
	 * @return the new page for the tab folder
165
	 */
166
	Composite createTabFolderPage (TabFolder tabFolder) {
167
		super.createTabFolderPage (tabFolder);
168
169
		/*
170
		 * Add a resize listener to the tabFolderPage so that
171
		 * if the user types into the example widget to change
172
		 * its preferred size, and then resizes the shell, we
173
		 * recalculate the preferred size correctly.
174
		 */
175
		tabFolderPage.addControlListener(new ControlAdapter() {
176
			public void controlResized(ControlEvent e) {
177
				setExampleWidgetSize ();
178
			}
179
		});
180
		
181
		return tabFolderPage;
182
	}
183
184
	/**
185
	 * Creates the "Style" group.
186
	 */
187
	void createStyleGroup () {
188
		orientationButtons = false;
189
		super.createStyleGroup ();
190
	
191
		/* Create the extra widgets */
192
		readOnlyButton = new Button (styleGroup, SWT.CHECK);
193
		readOnlyButton.setText ("SWT.READ_ONLY");
194
		wrapButton = new Button (styleGroup, SWT.CHECK);
195
		wrapButton.setText ("SWT.WRAP");
196
	}
197
	
198
	/**
199
	 * Gets the "Example" widget children.
200
	 */
201
	Widget [] getExampleWidgets () {
202
		return new Widget [] {spinner1};
203
	}
204
	
205
	/**
206
	 * Returns a list of set/get API method names (without the set/get prefix)
207
	 * that can be used to set/get values in the example control(s).
208
	 */
209
	String[] getMethodNames() {
210
		return new String[] {"Selection", "TextLimit", "ToolTipText"};
211
	}
212
213
	/**
214
	 * Gets the text for the tab folder item.
215
	 */
216
	String getTabText () {
217
		return "Spinner";
218
	}
219
	
220
	/**
221
	 * Sets the state of the "Example" widgets.
222
	 */
223
	void setExampleWidgetState () {
224
		super.setExampleWidgetState ();
225
		readOnlyButton.setSelection ((spinner1.getStyle () & SWT.READ_ONLY) != 0);
226
		wrapButton.setSelection ((spinner1.getStyle () & SWT.WRAP) != 0);
227
		if (!instance.startup) {
228
			setWidgetIncrement ();
229
			setWidgetPageIncrement ();
230
			setWidgetDigits ();
231
		}
232
	}
233
234
	/**
235
	 * Gets the default maximum of the "Example" widgets.
236
	 */
237
	int getDefaultMaximum () {
238
		return spinner1.getMaximum();
239
	}
240
	
241
	/**
242
	 * Gets the default minimim of the "Example" widgets.
243
	 */
244
	int getDefaultMinimum () {
245
		return spinner1.getMinimum();
246
	}
247
	
248
	/**
249
	 * Gets the default selection of the "Example" widgets.
250
	 */
251
	int getDefaultSelection () {
252
		return spinner1.getSelection();
253
	}
254
255
	/**
256
	 * Gets the default increment of the "Example" widgets.
257
	 */
258
	int getDefaultIncrement () {
259
		return spinner1.getIncrement();
260
	}
261
	
262
	/**
263
	 * Gets the default page increment of the "Example" widgets.
264
	 */
265
	int getDefaultPageIncrement () {
266
		return spinner1.getPageIncrement();
267
	}
268
	
269
	/**
270
	 * Gets the default digits of the "Example" widgets.
271
	 */
272
	int getDefaultDigits () {
273
		return spinner1.getDigits();
274
	}
275
276
	/**
277
	 * Sets the increment of the "Example" widgets.
278
	 */
279
	void setWidgetIncrement () {
280
		spinner1.setIncrement (incrementSpinner.getSelection ());
281
	}
282
	
283
	/**
284
	 * Sets the minimim of the "Example" widgets.
285
	 */
286
	void setWidgetMaximum () {
287
		spinner1.setMaximum (maximumSpinner.getSelection ());
288
	}
289
	
290
	/**
291
	 * Sets the minimim of the "Example" widgets.
292
	 */
293
	void setWidgetMinimum () {
294
		spinner1.setMinimum (minimumSpinner.getSelection ());
295
	}
296
	
297
	/**
298
	 * Sets the page increment of the "Example" widgets.
299
	 */
300
	void setWidgetPageIncrement () {
301
		spinner1.setPageIncrement (pageIncrementSpinner.getSelection ());
302
	}
303
	
304
	/**
305
	 * Sets the digits of the "Example" widgets.
306
	 */
307
	void setWidgetDigits () {
308
		spinner1.setDigits (digitsSpinner.getSelection ());
309
	}
310
	
311
	/**
312
	 * Sets the selection of the "Example" widgets.
313
	 */
314
	void setWidgetSelection () {
315
		spinner1.setSelection (selectionSpinner.getSelection ());
316
	}
317
}
(-)src/org/eclipse/swt/examples/mirroringTest/StyledTextTab.java (+413 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import java.io.*;
15
import org.eclipse.swt.*;
16
import org.eclipse.swt.graphics.*;
17
import org.eclipse.swt.widgets.*;
18
import org.eclipse.swt.layout.*;
19
import org.eclipse.swt.events.*;
20
import org.eclipse.swt.custom.*;
21
22
class StyledTextTab extends ScrollableTab {
23
	/* Example widgets and groups that contain them */
24
	StyledText styledText;
25
	Group styledTextGroup, styledTextStyleGroup;
26
27
	/* Style widgets added to the "Style" group */
28
	Button wrapButton, readOnlyButton, fullSelectionButton;
29
	
30
	/* Buttons for adding StyleRanges to StyledText */
31
	Button boldButton, italicButton, redButton, yellowButton, underlineButton, strikeoutButton;
32
	Image boldImage, italicImage, redImage, yellowImage, underlineImage, strikeoutImage;
33
	
34
	/* Variables for saving state. */
35
	String text;
36
	StyleRange[] styleRanges;
37
38
	/**
39
	 * Creates the Tab within a given instance of ControlExample.
40
	 */
41
	StyledTextTab(ControlExample instance) {
42
		super(instance);
43
	}
44
	
45
	/**
46
	 * Creates a bitmap image. 
47
	 */
48
	Image createBitmapImage (Display display, String name) {
49
		InputStream sourceStream = ControlExample.class.getResourceAsStream (name + ".bmp");
50
		InputStream maskStream = ControlExample.class.getResourceAsStream (name + "_mask.bmp");
51
		ImageData source = new ImageData (sourceStream);
52
		ImageData mask = new ImageData (maskStream);
53
		Image result = new Image (display, source, mask);
54
		try {
55
			sourceStream.close ();
56
			maskStream.close ();
57
		} catch (IOException e) {
58
			e.printStackTrace ();
59
		}
60
		return result;
61
	}
62
	
63
	/**
64
	 * Creates the "Control" widget children.
65
	 */
66
	void createControlWidgets () {
67
		super.createControlWidgets ();
68
		
69
		/* Add a group for modifying the StyledText widget */
70
		createStyledTextStyleGroup ();
71
	}
72
73
	/**
74
	 * Creates the "Example" group.
75
	 */
76
	void createExampleGroup () {
77
		super.createExampleGroup ();
78
		
79
		/* Create a group for the styled text widget */
80
		styledTextGroup = new Group (exampleGroup, SWT.NONE);
81
		styledTextGroup.setLayout (new GridLayout ());
82
		styledTextGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
83
		styledTextGroup.setText ("StyledText");
84
	}
85
	
86
	/**
87
	 * Creates the "Example" widgets.
88
	 */
89
	void createExampleWidgets () {
90
		
91
		/* Compute the widget style */
92
		int style = getDefaultStyle();
93
		if (singleButton.getSelection ()) style |= SWT.SINGLE;
94
		if (multiButton.getSelection ()) style |= SWT.MULTI;
95
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
96
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
97
		if (wrapButton.getSelection ()) style |= SWT.WRAP;
98
		if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
99
		if (borderButton.getSelection ()) style |= SWT.BORDER;
100
		if (fullSelectionButton.getSelection ()) style |= SWT.FULL_SELECTION;
101
	
102
		/* Create the example widgets */
103
		styledText = new StyledText (styledTextGroup, style);
104
		styledText.setText (ControlExample.getResourceString("Example_string"));
105
		styledText.append ("\n");
106
		styledText.append (ControlExample.getResourceString("One_Two_Three"));
107
		
108
		if (text != null) {
109
			styledText.setText(text);
110
			text = null;
111
		}
112
		if (styleRanges != null) {
113
			styledText.setStyleRanges(styleRanges);
114
			styleRanges = null;
115
		}
116
	}
117
	
118
	/**
119
	 * Creates the "Style" group.
120
	 */
121
	void createStyleGroup() {
122
		super.createStyleGroup();
123
	
124
		/* Create the extra widgets */
125
		wrapButton = new Button (styleGroup, SWT.CHECK);
126
		wrapButton.setText ("SWT.WRAP");
127
		readOnlyButton = new Button (styleGroup, SWT.CHECK);
128
		readOnlyButton.setText ("SWT.READ_ONLY");
129
		fullSelectionButton = new Button (styleGroup, SWT.CHECK);
130
		fullSelectionButton.setText ("SWT.FULL_SELECTION");
131
	}
132
	
133
	/**
134
	 * Creates the "StyledText Style" group.
135
	 */
136
	void createStyledTextStyleGroup () {
137
		styledTextStyleGroup = new Group (controlGroup, SWT.NONE);
138
		styledTextStyleGroup.setText (ControlExample.getResourceString ("StyledText_Styles"));
139
		styledTextStyleGroup.setLayout (new GridLayout(6, false));
140
		GridData data = new GridData (GridData.HORIZONTAL_ALIGN_FILL);
141
		data.horizontalSpan = 2;
142
		styledTextStyleGroup.setLayoutData (data);
143
		
144
		/* Get images */
145
		boldImage = createBitmapImage (display, "bold");
146
		italicImage = createBitmapImage (display, "italic");
147
		redImage = createBitmapImage (display, "red");
148
		yellowImage = createBitmapImage (display, "yellow");
149
		underlineImage = createBitmapImage (display, "underline");
150
		strikeoutImage = createBitmapImage (display, "strikeout");
151
		
152
		/* Create controls to modify the StyledText */
153
		Label label = new Label (styledTextStyleGroup, SWT.NONE);
154
		label.setText (ControlExample.getResourceString ("StyledText_Style_Instructions"));
155
		label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 6, 1));
156
		label = new Label (styledTextStyleGroup, SWT.NONE);
157
		label.setText (ControlExample.getResourceString ("Bold"));
158
		label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
159
		boldButton = new Button (styledTextStyleGroup, SWT.PUSH);
160
		boldButton.setImage (boldImage);
161
		label = new Label (styledTextStyleGroup, SWT.NONE);
162
		label.setText (ControlExample.getResourceString ("Underline"));
163
		label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
164
		underlineButton = new Button (styledTextStyleGroup, SWT.PUSH);
165
		underlineButton.setImage (underlineImage);
166
		label = new Label (styledTextStyleGroup, SWT.NONE);
167
		label.setText (ControlExample.getResourceString ("Foreground_Style"));
168
		label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
169
		redButton = new Button (styledTextStyleGroup, SWT.PUSH);
170
		redButton.setImage (redImage);
171
		label = new Label (styledTextStyleGroup, SWT.NONE);
172
		label.setText (ControlExample.getResourceString ("Italic"));
173
		label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
174
		italicButton = new Button (styledTextStyleGroup, SWT.PUSH);
175
		italicButton.setImage (italicImage);
176
		label = new Label (styledTextStyleGroup, SWT.NONE);
177
		label.setText (ControlExample.getResourceString ("Strikeout"));
178
		label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
179
		strikeoutButton = new Button (styledTextStyleGroup, SWT.PUSH);
180
		strikeoutButton.setImage (strikeoutImage);
181
		label = new Label (styledTextStyleGroup, SWT.NONE);
182
		label.setText (ControlExample.getResourceString ("Background_Style"));
183
		label.setLayoutData(new GridData(SWT.END, SWT.CENTER, true, false));
184
		yellowButton = new Button (styledTextStyleGroup, SWT.PUSH);
185
		yellowButton.setImage (yellowImage);
186
		SelectionListener styleListener = new SelectionAdapter () {
187
			public void widgetSelected (SelectionEvent e) {
188
				Point sel = styledText.getSelectionRange();
189
				if ((sel == null) || (sel.y == 0)) return;
190
				StyleRange style;
191
				for (int i = sel.x; i<sel.x+sel.y; i++) {
192
					StyleRange range = styledText.getStyleRangeAtOffset(i);
193
					if (range != null) {
194
						style = (StyleRange)range.clone();
195
						style.start = i;
196
						style.length = 1;
197
					} else {
198
						style = new StyleRange(i, 1, null, null, SWT.NORMAL);
199
					}
200
					if (e.widget == boldButton) {
201
						style.fontStyle ^= SWT.BOLD;
202
					} else if (e.widget == italicButton) {
203
						style.fontStyle ^= SWT.ITALIC;						
204
					} else if (e.widget == underlineButton) {
205
						style.underline = !style.underline;
206
					} else if (e.widget == strikeoutButton) {
207
						style.strikeout = !style.strikeout;
208
					}
209
					styledText.setStyleRange(style);
210
				}
211
				styledText.setSelectionRange(sel.x + sel.y, 0);			
212
			}
213
		};
214
		SelectionListener colorListener = new SelectionAdapter () {
215
			public void widgetSelected (SelectionEvent e) {
216
				Point sel = styledText.getSelectionRange();
217
				if ((sel == null) || (sel.y == 0)) return;
218
				Color fg = null, bg = null;
219
				if (e.widget == redButton) {
220
					fg = display.getSystemColor (SWT.COLOR_RED);
221
				} else if (e.widget == yellowButton) {
222
					bg = display.getSystemColor (SWT.COLOR_YELLOW);
223
				}
224
				StyleRange style;
225
				for (int i = sel.x; i<sel.x+sel.y; i++) {
226
					StyleRange range = styledText.getStyleRangeAtOffset(i);
227
					if (range != null) {
228
						style = (StyleRange)range.clone();
229
						style.start = i;
230
						style.length = 1;
231
						style.foreground = style.foreground != null ? null : fg;
232
						style.background = style.background != null ? null : bg;
233
					} else {
234
						style = new StyleRange (i, 1, fg, bg, SWT.NORMAL);
235
					}
236
					styledText.setStyleRange(style);
237
				}
238
				styledText.setSelectionRange(sel.x + sel.y, 0);
239
			}
240
		};
241
		boldButton.addSelectionListener(styleListener);
242
		italicButton.addSelectionListener(styleListener);
243
		underlineButton.addSelectionListener(styleListener);
244
		strikeoutButton.addSelectionListener(styleListener);
245
		redButton.addSelectionListener(colorListener);
246
		yellowButton.addSelectionListener(colorListener);
247
		yellowButton.addDisposeListener(new DisposeListener () {
248
			public void widgetDisposed (DisposeEvent e) {
249
				boldImage.dispose();
250
				italicImage.dispose();
251
				redImage.dispose();
252
				yellowImage.dispose();
253
				underlineImage.dispose();
254
				strikeoutImage.dispose();
255
			}
256
		});
257
	}
258
	
259
	/**
260
	 * Creates the tab folder page.
261
	 *
262
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
263
	 * @return the new page for the tab folder
264
	 */
265
	Composite createTabFolderPage (TabFolder tabFolder) {
266
		super.createTabFolderPage (tabFolder);
267
268
		/*
269
		 * Add a resize listener to the tabFolderPage so that
270
		 * if the user types into the example widget to change
271
		 * its preferred size, and then resizes the shell, we
272
		 * recalculate the preferred size correctly.
273
		 */
274
		tabFolderPage.addControlListener(new ControlAdapter() {
275
			public void controlResized(ControlEvent e) {
276
				setExampleWidgetSize ();
277
			}
278
		});
279
		
280
		return tabFolderPage;
281
	}
282
283
	/**
284
	 * Disposes the "Example" widgets.
285
	 */
286
	void disposeExampleWidgets () {
287
		/* store the state of the styledText if applicable */
288
		if (styledText != null) {
289
			styleRanges = styledText.getStyleRanges();
290
			text = styledText.getText();
291
		}
292
		super.disposeExampleWidgets();	
293
	}
294
295
	/**
296
	 * Gets the list of custom event names.
297
	 * 
298
	 * @return an array containing custom event names
299
	 */
300
	String [] getCustomEventNames () {
301
		return new String [] {
302
				"ExtendedModifyListener", "BidiSegmentListener", "LineBackgroundListener",
303
				"LineStyleListener", "PaintObjectListener", "TextChangeListener",
304
				"VerifyKeyListener", "WordMovementListener"};
305
	}
306
307
	/**
308
	 * Gets the "Example" widget children.
309
	 */
310
	Widget [] getExampleWidgets () {
311
		return new Widget [] {styledText};
312
	}
313
	
314
	/**
315
	 * Returns a list of set/get API method names (without the set/get prefix)
316
	 * that can be used to set/get values in the example control(s).
317
	 */
318
	String[] getMethodNames() {
319
		return new String[] {"Alignment", "BlockSelection", "BottomMargin", "CaretOffset", "DoubleClickEnabled", "Editable", "HorizontalIndex", "HorizontalPixel", "Indent", "Justify", "LeftMargin", "LineSpacing", "Orientation", "RightMargin", "Selection", "Tabs", "Text", "TextLimit", "ToolTipText", "TopIndex", "TopMargin", "TopPixel", "WordWrap"};
320
	}
321
322
	
323
	/**
324
	 * Gets the text for the tab folder item.
325
	 */
326
	String getTabText () {
327
		return "StyledText";
328
	}
329
	
330
	/**
331
	 * Hooks the custom listener specified by eventName.
332
	 */
333
	void hookCustomListener (final String eventName) {
334
		if (eventName == "ExtendedModifyListener") {
335
			styledText.addExtendedModifyListener (new ExtendedModifyListener() {
336
				public void modifyText(ExtendedModifyEvent event) {
337
					log (eventName, event);
338
				}
339
			});
340
		}
341
		if (eventName == "BidiSegmentListener") {
342
			styledText.addBidiSegmentListener (new BidiSegmentListener() {
343
				public void lineGetSegments(BidiSegmentEvent event) {
344
					log (eventName, event);
345
				}
346
			});
347
		}
348
		if (eventName == "LineBackgroundListener") {
349
			styledText.addLineBackgroundListener (new LineBackgroundListener() {
350
				public void lineGetBackground(LineBackgroundEvent event) {
351
					log (eventName, event);
352
				}
353
			});
354
		}
355
		if (eventName == "LineStyleListener") {
356
			styledText.addLineStyleListener (new LineStyleListener() {
357
				public void lineGetStyle(LineStyleEvent event) {
358
					log (eventName, event);
359
				}
360
			});
361
		}
362
		if (eventName == "PaintObjectListener") {
363
			styledText.addPaintObjectListener (new PaintObjectListener() {
364
				public void paintObject(PaintObjectEvent event) {
365
					log (eventName, event);
366
				}
367
			});
368
		}
369
		if (eventName == "TextChangeListener") {
370
			styledText.getContent().addTextChangeListener (new TextChangeListener() {
371
				public void textChanged(TextChangedEvent event) {
372
					log (eventName + ".textChanged", event);
373
				}
374
				public void textChanging(TextChangingEvent event) {
375
					log (eventName + ".textChanging", event);
376
				}
377
				public void textSet(TextChangedEvent event) {
378
					log (eventName + ".textSet", event);
379
				}
380
			});
381
		}
382
		if (eventName == "VerifyKeyListener") {
383
			styledText.addVerifyKeyListener (new VerifyKeyListener() {
384
				public void verifyKey(VerifyEvent event) {
385
					log (eventName, event);
386
				}
387
			});
388
		}
389
		if (eventName == "WordMovementListener") {
390
			styledText.addWordMovementListener (new MovementListener() {
391
				public void getNextOffset(MovementEvent event) {
392
					log (eventName + ".getNextOffset", event);
393
				}
394
				public void getPreviousOffset(MovementEvent event) {
395
					log (eventName + ".getPreviousOffset", event);
396
				}
397
			});
398
		}
399
	}
400
401
	/**
402
	 * Sets the state of the "Example" widgets.
403
	 */
404
	void setExampleWidgetState () {
405
		super.setExampleWidgetState ();
406
		wrapButton.setSelection ((styledText.getStyle () & SWT.WRAP) != 0);
407
		readOnlyButton.setSelection ((styledText.getStyle () & SWT.READ_ONLY) != 0);
408
		fullSelectionButton.setSelection ((styledText.getStyle () & SWT.FULL_SELECTION) != 0);
409
		horizontalButton.setEnabled ((styledText.getStyle () & SWT.MULTI) != 0);
410
		verticalButton.setEnabled ((styledText.getStyle () & SWT.MULTI) != 0);
411
		wrapButton.setEnabled ((styledText.getStyle () & SWT.MULTI) != 0);
412
	}
413
}
(-)src/org/eclipse/swt/examples/mirroringTest/Tab.java (+1831 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.layout.*;
18
import org.eclipse.swt.events.*;
19
20
/**
21
 * <code>Tab</code> is the abstract superclass of every page
22
 * in the example's tab folder.  Each page in the tab folder
23
 * describes a control.
24
 *
25
 * A Tab itself is not a control but instead provides a
26
 * hierarchy with which to share code that is common to
27
 * every page in the folder.
28
 *
29
 * A typical page in a Tab contains a two column composite.
30
 * The left column contains the "Example" group.  The right
31
 * column contains "Control" group.  The "Control" group
32
 * contains controls that allow the user to interact with
33
 * the example control.  The "Control" group typically
34
 * contains a "Style", "Other" and "Size" group.  Subclasses
35
 * can override these defaults to augment a group or stop
36
 * a group from being created.
37
 */
38
abstract class Tab {
39
	Shell shell;
40
	Display display;
41
	
42
	/* Common control buttons */
43
	Button borderButton, enabledButton, visibleButton, backgroundImageButton, popupMenuButton;
44
	Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton;
45
46
	/* Common groups and composites */
47
	Composite tabFolderPage;
48
	Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup;
49
50
	/* Controlling instance */
51
	final ControlExample instance;
52
53
	/* Sizing constants for the "Size" group */
54
	static final int TOO_SMALL_SIZE	= 10;
55
	static final int SMALL_SIZE		= 50;
56
	static final int LARGE_SIZE		= 100;
57
	
58
	/* Right-to-left support */
59
	static final boolean RTL_SUPPORT_ENABLE = "win32".equals(SWT.getPlatform()) || "gtk".equals(SWT.getPlatform());
60
	Group orientationGroup;
61
	Button rtlButtonRecreate, rtlButtonSet, ltrButtonRecreate, ltrButtonSet, defaultOrietationButton;
62
63
	/* Controls and resources for the "Colors & Fonts" group */
64
	static final int IMAGE_SIZE = 12;
65
	static final int FOREGROUND_COLOR = 0;
66
	static final int BACKGROUND_COLOR = 1;
67
	static final int FONT = 2;
68
	Table colorAndFontTable;
69
	ColorDialog colorDialog;
70
	FontDialog fontDialog;
71
	Color foregroundColor, backgroundColor;
72
	Font font;
73
	
74
	/* Controls and resources for the "Background Mode" group */
75
	Combo backgroundModeCombo;
76
	Button backgroundModeImageButton, backgroundModeColorButton;
77
78
	boolean samplePopup = false;
79
	
80
	/* Set/Get API controls */
81
	Combo nameCombo;
82
	Label returnTypeLabel;
83
	Button getButton, setButton;
84
	Text setText, getText;
85
	Shell setGetDialog;
86
87
	/* Event logging variables and controls */
88
	Text eventConsole;
89
	boolean logging = false;
90
	boolean [] eventsFilter;
91
	int setFieldsMask = 0;
92
	Event setFieldsEvent = new Event ();
93
	boolean ignore = false;
94
	
95
	/* Event logging constants */
96
	static final int DOIT	= 0x0100;
97
	static final int DETAIL	= 0x0200;
98
	static final int TEXT	= 0x0400;
99
	static final int X		= 0x0800;
100
	static final int Y		= 0x1000;
101
	static final int WIDTH	= 0x2000;
102
	static final int HEIGHT	= 0x4000;
103
104
	static final int DETAIL_IME			= 0;
105
	static final int DETAIL_ERASE_ITEM	= 1;
106
	static final int DETAIL_TRAVERSE	= 2;
107
108
	static class EventInfo {
109
		String name;
110
		int type;
111
		int settableFields;
112
		int setFields;
113
		Event event;
114
		EventInfo (String name, int type, int settableFields, int setFields, Event event) {
115
			this.name = name;
116
			this.type = type;
117
			this.settableFields = settableFields;
118
			this.setFields = setFields;
119
			this.event = event;
120
		}
121
	}
122
	
123
	final EventInfo [] EVENT_INFO = {
124
		new EventInfo ("Activate", SWT.Activate, 0, 0, new Event()), 
125
		new EventInfo ("Arm", SWT.Arm, 0, 0, new Event()), 
126
		new EventInfo ("Close", SWT.Close, DOIT, 0, new Event()),
127
		new EventInfo ("Collapse", SWT.Collapse, 0, 0, new Event()),
128
		new EventInfo ("Deactivate", SWT.Deactivate, 0, 0, new Event()),
129
		new EventInfo ("DefaultSelection", SWT.DefaultSelection, 0, 0, new Event()),
130
		new EventInfo ("Deiconify", SWT.Deiconify, 0, 0, new Event()), 
131
		new EventInfo ("Dispose", SWT.Dispose, 0, 0, new Event()),
132
		new EventInfo ("DragDetect", SWT.DragDetect, 0, 0, new Event()), 
133
		new EventInfo ("EraseItem", SWT.EraseItem, DETAIL | DETAIL_ERASE_ITEM, 0, new Event()),
134
		new EventInfo ("Expand", SWT.Expand, 0, 0, new Event()), 
135
		new EventInfo ("FocusIn", SWT.FocusIn, 0, 0, new Event()), 
136
		new EventInfo ("FocusOut", SWT.FocusOut, 0, 0, new Event()),
137
		new EventInfo ("HardKeyDown", SWT.HardKeyDown, 0, 0, new Event()), 
138
		new EventInfo ("HardKeyUp", SWT.HardKeyUp, 0, 0, new Event()),
139
		new EventInfo ("Help", SWT.Help, 0, 0, new Event()), 
140
		new EventInfo ("Hide", SWT.Hide, 0, 0, new Event()),
141
		new EventInfo ("Iconify", SWT.Iconify, 0, 0, new Event()), 
142
		new EventInfo ("KeyDown", SWT.KeyDown, DOIT, 0, new Event()),
143
		new EventInfo ("KeyUp", SWT.KeyUp, DOIT, 0, new Event()),
144
		new EventInfo ("MeasureItem", SWT.MeasureItem, 0, 0, new Event()),
145
		new EventInfo ("MenuDetect", SWT.MenuDetect, X | Y | DOIT, 0, new Event()),
146
		new EventInfo ("Modify", SWT.Modify, 0, 0, new Event()), 
147
		new EventInfo ("MouseDoubleClick", SWT.MouseDoubleClick, 0, 0, new Event()),
148
		new EventInfo ("MouseDown", SWT.MouseDown, 0, 0, new Event()), 
149
		new EventInfo ("MouseEnter", SWT.MouseEnter, 0, 0, new Event()), 
150
		new EventInfo ("MouseExit", SWT.MouseExit, 0, 0, new Event()), 
151
		new EventInfo ("MouseHover", SWT.MouseHover, 0, 0, new Event()),
152
		new EventInfo ("MouseMove", SWT.MouseMove, 0, 0, new Event()), 
153
		new EventInfo ("MouseUp", SWT.MouseUp, 0, 0, new Event()), 
154
		new EventInfo ("MouseWheel", SWT.MouseWheel, 0, 0, new Event()),
155
		new EventInfo ("Move", SWT.Move, 0, 0, new Event()), 
156
		new EventInfo ("Paint", SWT.Paint, 0, 0, new Event()), 
157
		new EventInfo ("PaintItem", SWT.PaintItem, 0, 0, new Event()),
158
		new EventInfo ("Resize", SWT.Resize, 0, 0, new Event()), 
159
		new EventInfo ("Selection", SWT.Selection, X | Y | DOIT, 0, new Event()), // sash
160
		new EventInfo ("SetData", SWT.SetData, 0, 0, new Event()),
161
//		new EventInfo ("Settings", SWT.Settings, 0, 0, new Event()),  // note: this event only goes to Display
162
		new EventInfo ("Show", SWT.Show, 0, 0, new Event()), 
163
		new EventInfo ("Traverse", SWT.Traverse, DETAIL | DETAIL_TRAVERSE | DOIT, 0, new Event()),
164
		new EventInfo ("Verify", SWT.Verify, TEXT | DOIT, 0, new Event()),
165
		new EventInfo ("ImeComposition", SWT.ImeComposition, DETAIL | DETAIL_IME | TEXT | DOIT, 0, new Event()),
166
	};
167
168
	static final String [][] DETAIL_CONSTANTS = {
169
		{ // DETAIL_IME = 0
170
			"SWT.COMPOSITION_CHANGED",
171
			"SWT.COMPOSITION_OFFSET",
172
			"SWT.COMPOSITION_SELECTION",
173
		},
174
		{ // DETAIL_ERASE_ITEM = 1
175
			"SWT.SELECTED",
176
			"SWT.FOCUSED",
177
			"SWT.BACKGROUND",
178
			"SWT.FOREGROUND",
179
			"SWT.HOT",
180
		},
181
		{ // DETAIL_TRAVERSE = 2
182
			"SWT.TRAVERSE_NONE",
183
			"SWT.TRAVERSE_ESCAPE",
184
			"SWT.TRAVERSE_RETURN",
185
			"SWT.TRAVERSE_TAB_PREVIOUS",
186
			"SWT.TRAVERSE_TAB_NEXT",
187
			"SWT.TRAVERSE_ARROW_PREVIOUS",
188
			"SWT.TRAVERSE_ARROW_NEXT",
189
			"SWT.TRAVERSE_MNEMONIC",
190
			"SWT.TRAVERSE_PAGE_PREVIOUS",
191
			"SWT.TRAVERSE_PAGE_NEXT",
192
		},
193
	};
194
195
	static final Object [] DETAIL_VALUES = {
196
		"SWT.COMPOSITION_CHANGED", new Integer(SWT.COMPOSITION_CHANGED),
197
		"SWT.COMPOSITION_OFFSET", new Integer(SWT.COMPOSITION_OFFSET),
198
		"SWT.COMPOSITION_SELECTION", new Integer(SWT.COMPOSITION_SELECTION),
199
		"SWT.SELECTED", new Integer(SWT.SELECTED),
200
		"SWT.FOCUSED", new Integer(SWT.FOCUSED),
201
		"SWT.BACKGROUND", new Integer(SWT.BACKGROUND),
202
		"SWT.FOREGROUND", new Integer(SWT.FOREGROUND),
203
		"SWT.HOT", new Integer(SWT.HOT),
204
		"SWT.TRAVERSE_NONE", new Integer(SWT.TRAVERSE_NONE),
205
		"SWT.TRAVERSE_ESCAPE", new Integer(SWT.TRAVERSE_ESCAPE),
206
		"SWT.TRAVERSE_RETURN", new Integer(SWT.TRAVERSE_RETURN),
207
		"SWT.TRAVERSE_TAB_PREVIOUS", new Integer(SWT.TRAVERSE_TAB_PREVIOUS),
208
		"SWT.TRAVERSE_TAB_NEXT", new Integer(SWT.TRAVERSE_TAB_NEXT),
209
		"SWT.TRAVERSE_ARROW_PREVIOUS", new Integer(SWT.TRAVERSE_ARROW_PREVIOUS),
210
		"SWT.TRAVERSE_ARROW_NEXT", new Integer(SWT.TRAVERSE_ARROW_NEXT),
211
		"SWT.TRAVERSE_MNEMONIC", new Integer(SWT.TRAVERSE_MNEMONIC),
212
		"SWT.TRAVERSE_PAGE_PREVIOUS", new Integer(SWT.TRAVERSE_PAGE_PREVIOUS),
213
		"SWT.TRAVERSE_PAGE_NEXT", new Integer(SWT.TRAVERSE_PAGE_NEXT),
214
	};
215
		
216
	/**
217
	 * Creates the Tab within a given instance of ControlExample.
218
	 */
219
	Tab(ControlExample instance) {
220
		this.instance = instance;
221
	}
222
223
	/**
224
	 * Creates the "Control" group.  The "Control" group
225
	 * is typically the right hand column in the tab.
226
	 */
227
	void createControlGroup () {
228
	
229
		/*
230
		 * Create the "Control" group.  This is the group on the
231
		 * right half of each example tab.  It consists of the
232
		 * "Style" group, the "Other" group and the "Size" group.
233
		 */	
234
		controlGroup = new Group (tabFolderPage, SWT.NONE);
235
		controlGroup.setLayout (new GridLayout (2, true));
236
		controlGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false));
237
		controlGroup.setText (ControlExample.getResourceString("Parameters"));
238
	
239
		/* Create individual groups inside the "Control" group */
240
		createStyleGroup ();
241
		createOtherGroup ();
242
		createSetGetGroup();
243
		createSizeGroup ();
244
		createColorAndFontGroup ();
245
		if (rtlSupport()) {
246
			createOrientationGroup ();
247
		}
248
//		createBackgroundModeGroup ();
249
	
250
		/*
251
		 * For each Button child in the style group, add a selection
252
		 * listener that will recreate the example controls.  If the
253
		 * style group button is a RADIO button, ensure that the radio
254
		 * button is selected before recreating the example controls.
255
		 * When the user selects a RADIO button, the current RADIO
256
		 * button in the group is deselected and the new RADIO button
257
		 * is selected automatically.  The listeners are notified for
258
		 * both these operations but typically only do work when a RADIO
259
		 * button is selected.
260
		 */
261
		SelectionListener selectionListener = new SelectionAdapter () {
262
			public void widgetSelected (SelectionEvent event) {
263
				if ((event.widget.getStyle () & SWT.RADIO) != 0) {
264
					if (!((Button) event.widget).getSelection ()) return;
265
				}
266
				recreateExampleWidgets ();
267
			}
268
		};
269
		Control [] children = styleGroup.getChildren ();
270
		for (int i=0; i<children.length; i++) {
271
			if (children [i] instanceof Button) {
272
				Button button = (Button) children [i];
273
				button.addSelectionListener (selectionListener);
274
			} else {
275
				if (children [i] instanceof Composite) {
276
					/* Look down one more level of children in the style group. */
277
					Composite composite = (Composite) children [i];
278
					Control [] grandchildren = composite.getChildren ();
279
					for (int j=0; j<grandchildren.length; j++) {
280
						if (grandchildren [j] instanceof Button) {
281
							Button button = (Button) grandchildren [j];
282
							button.addSelectionListener (selectionListener);
283
						}
284
					}
285
				}
286
			}
287
		}
288
		if (rtlSupport()) {
289
			rtlButtonRecreate.addSelectionListener (selectionListener); 
290
			ltrButtonRecreate.addSelectionListener (selectionListener);		
291
			defaultOrietationButton.addSelectionListener (selectionListener);
292
293
			SelectionListener bidiListener = new SelectionAdapter () {
294
				public void widgetSelected (SelectionEvent event) {
295
					Control [] controls = getExampleControls ();
296
					int flag = event.widget == rtlButtonSet ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; 
297
					for (int i=0; i<controls.length; i++) {
298
						controls [i].setOrientation(flag);
299
						//controls [i].setTextDirectionRTL();
300
					}
301
				}
302
			};
303
			rtlButtonSet.addSelectionListener (bidiListener); 
304
			ltrButtonSet.addSelectionListener (bidiListener);		
305
		}
306
	}
307
	
308
	/**
309
	 * Append the Set/Get API controls to the "Other" group.
310
	 */
311
	void createSetGetGroup() {
312
		/*
313
		 * Create the button to access set/get API functionality.
314
		 */
315
		final String [] methodNames = getMethodNames ();
316
		if (methodNames != null) {
317
			final Button setGetButton = new Button (otherGroup, SWT.PUSH);
318
			setGetButton.setText (ControlExample.getResourceString ("Set_Get"));
319
			setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
320
			setGetButton.addSelectionListener (new SelectionAdapter() {
321
				public void widgetSelected (SelectionEvent e) {
322
					if (getExampleWidgets().length >  0) {
323
						if (setGetDialog == null) {
324
							setGetDialog = createSetGetDialog(methodNames);
325
						}
326
						Point pt = setGetButton.getLocation();
327
						pt = display.map(setGetButton.getParent(), null, pt);
328
						setGetDialog.setLocation(pt.x, pt.y);
329
						setGetDialog.open();
330
					}
331
				}
332
			});
333
		}
334
	}
335
336
	/**
337
	 * Creates the "Control" widget children.
338
	 * Subclasses override this method to augment
339
	 * the standard controls created in the "Style",
340
	 * "Other" and "Size" groups.
341
	 */
342
	void createControlWidgets () {
343
	}
344
	
345
	/**
346
	 * Creates the "Colors and Fonts" group. This is typically
347
	 * a child of the "Control" group. Subclasses override
348
	 * this method to customize color and font settings.
349
	 */
350
	void createColorAndFontGroup () {
351
		/* Create the group. */
352
		colorGroup = new Group(controlGroup, SWT.NONE);
353
		colorGroup.setLayout (new GridLayout (2, true));
354
		colorGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
355
		colorGroup.setText (ControlExample.getResourceString ("Colors"));
356
		colorAndFontTable = new Table(colorGroup, SWT.BORDER | SWT.V_SCROLL);
357
		colorAndFontTable.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));
358
		TableItem item = new TableItem(colorAndFontTable, SWT.None);
359
		item.setText(ControlExample.getResourceString ("Foreground_Color"));
360
		colorAndFontTable.setSelection(0);
361
		item = new TableItem(colorAndFontTable, SWT.None);
362
		item.setText(ControlExample.getResourceString ("Background_Color"));
363
		item = new TableItem(colorAndFontTable, SWT.None);
364
		item.setText(ControlExample.getResourceString ("Font"));
365
		Button changeButton = new Button (colorGroup, SWT.PUSH);
366
		changeButton.setText(ControlExample.getResourceString("Change"));
367
		changeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
368
		Button defaultsButton = new Button (colorGroup, SWT.PUSH);
369
		defaultsButton.setText(ControlExample.getResourceString("Defaults"));
370
		defaultsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
371
372
		/* Add listeners to set/reset colors and fonts. */
373
		colorDialog = new ColorDialog (shell);
374
		fontDialog = new FontDialog (shell);
375
		colorAndFontTable.addSelectionListener(new SelectionAdapter() {
376
			public void widgetDefaultSelected(SelectionEvent event) {
377
				changeFontOrColor (colorAndFontTable.getSelectionIndex());
378
			}
379
		});
380
		changeButton.addSelectionListener(new SelectionAdapter() {
381
			public void widgetSelected(SelectionEvent event) {
382
				changeFontOrColor (colorAndFontTable.getSelectionIndex());
383
			}
384
		});
385
		defaultsButton.addSelectionListener(new SelectionAdapter () {
386
			public void widgetSelected (SelectionEvent e) {
387
				resetColorsAndFonts ();
388
			}
389
		});
390
		shell.addDisposeListener(new DisposeListener() {
391
			public void widgetDisposed(DisposeEvent event) {
392
				if (foregroundColor != null) foregroundColor.dispose();
393
				if (backgroundColor != null) backgroundColor.dispose();
394
				if (font != null) font.dispose();
395
				foregroundColor = null;
396
				backgroundColor = null;
397
				font = null;
398
				if (colorAndFontTable != null && !colorAndFontTable.isDisposed()) {
399
					TableItem [] items = colorAndFontTable.getItems();
400
					for (int i = 0; i < items.length; i++) {
401
						Image image = items[i].getImage();
402
						if (image != null) image.dispose();
403
					}
404
				}
405
			}
406
		});
407
	}
408
	
409
	void changeFontOrColor(int index) {
410
		switch (index) {
411
			case FOREGROUND_COLOR: {
412
				Color oldColor = foregroundColor;
413
				if (oldColor == null) {
414
					Control [] controls = getExampleControls ();
415
					if (controls.length > 0) oldColor = controls [0].getForeground ();
416
				}
417
				if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color
418
				RGB rgb = colorDialog.open();
419
				if (rgb == null) return;
420
				oldColor = foregroundColor; // save old foreground color to dispose when done
421
				foregroundColor = new Color (display, rgb);
422
				setExampleWidgetForeground ();
423
				if (oldColor != null) oldColor.dispose ();
424
			}
425
			break;
426
			case BACKGROUND_COLOR: {
427
				Color oldColor = backgroundColor;
428
				if (oldColor == null) {
429
					Control [] controls = getExampleControls ();
430
					if (controls.length > 0) oldColor = controls [0].getBackground (); // seed dialog with current color
431
				}
432
				if (oldColor != null) colorDialog.setRGB(oldColor.getRGB());
433
				RGB rgb = colorDialog.open();
434
				if (rgb == null) return;
435
				oldColor = backgroundColor; // save old background color to dispose when done
436
				backgroundColor = new Color (display, rgb);
437
				setExampleWidgetBackground ();
438
				if (oldColor != null) oldColor.dispose ();
439
			}
440
			break;
441
			case FONT: {
442
				Font oldFont = font;
443
				if (oldFont == null) {
444
					Control [] controls = getExampleControls ();
445
					if (controls.length > 0) oldFont = controls [0].getFont ();
446
				}
447
				if (oldFont != null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font
448
				FontData fontData = fontDialog.open ();
449
				if (fontData == null) return;
450
				oldFont = font; // dispose old font when done
451
				font = new Font (display, fontData);
452
				setExampleWidgetFont ();
453
				setExampleWidgetSize ();
454
				if (oldFont != null) oldFont.dispose ();
455
			}
456
			break;
457
		}
458
	}
459
460
	/**
461
	 * Creates the "Other" group.  This is typically
462
	 * a child of the "Control" group.
463
	 */
464
	void createOtherGroup () {
465
		/* Create the group */
466
		otherGroup = new Group (controlGroup, SWT.NONE);
467
		otherGroup.setLayout (new GridLayout ());
468
		otherGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
469
		otherGroup.setText (ControlExample.getResourceString("Other"));
470
	
471
		/* Create the controls */
472
		enabledButton = new Button(otherGroup, SWT.CHECK);
473
		enabledButton.setText(ControlExample.getResourceString("Enabled"));
474
		visibleButton = new Button(otherGroup, SWT.CHECK);
475
		visibleButton.setText(ControlExample.getResourceString("Visible"));
476
		backgroundImageButton = new Button(otherGroup, SWT.CHECK);
477
		backgroundImageButton.setText(ControlExample.getResourceString("BackgroundImage"));
478
		popupMenuButton = new Button(otherGroup, SWT.CHECK);
479
		popupMenuButton.setText(ControlExample.getResourceString("PopupMenu"));
480
		
481
		/* Add the listeners */
482
		enabledButton.addSelectionListener (new SelectionAdapter () {
483
			public void widgetSelected (SelectionEvent event) {
484
				setExampleWidgetEnabled ();
485
			}
486
		});
487
		visibleButton.addSelectionListener (new SelectionAdapter () {
488
			public void widgetSelected (SelectionEvent event) {
489
				setExampleWidgetVisibility ();
490
			}
491
		});
492
		backgroundImageButton.addSelectionListener (new SelectionAdapter () {
493
			public void widgetSelected (SelectionEvent event) {
494
				setExampleWidgetBackgroundImage ();
495
			}
496
		});
497
		popupMenuButton.addSelectionListener (new SelectionAdapter () {
498
			public void widgetSelected (SelectionEvent event) {
499
				setExampleWidgetPopupMenu ();
500
			}
501
		});
502
	
503
		/* Set the default state */
504
		enabledButton.setSelection(true);
505
		visibleButton.setSelection(true);
506
		backgroundImageButton.setSelection(false);
507
		popupMenuButton.setSelection(false);
508
	}
509
	
510
	/**
511
	 * Creates the "Background Mode" group.
512
	 */
513
	void createBackgroundModeGroup () {
514
		/* Create the group */
515
		backgroundModeGroup = new Group (controlGroup, SWT.NONE);
516
		backgroundModeGroup.setLayout (new GridLayout ());
517
		backgroundModeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
518
		backgroundModeGroup.setText (ControlExample.getResourceString("Background_Mode"));
519
	
520
		/* Create the controls */
521
		backgroundModeCombo = new Combo(backgroundModeGroup, SWT.READ_ONLY);
522
		backgroundModeCombo.setItems(new String[] {"SWT.INHERIT_NONE", "SWT.INHERIT_DEFAULT", "SWT.INHERIT_FORCE"});
523
		backgroundModeImageButton = new Button(backgroundModeGroup, SWT.CHECK);
524
		backgroundModeImageButton.setText(ControlExample.getResourceString("BackgroundImage"));
525
		backgroundModeColorButton = new Button(backgroundModeGroup, SWT.CHECK);
526
		backgroundModeColorButton.setText(ControlExample.getResourceString("BackgroundColor"));
527
	
528
		/* Add the listeners */
529
		backgroundModeCombo.addSelectionListener (new SelectionAdapter () {
530
			public void widgetSelected (SelectionEvent event) {
531
				setExampleGroupBackgroundMode ();
532
			}
533
		});
534
		backgroundModeImageButton.addSelectionListener (new SelectionAdapter () {
535
			public void widgetSelected (SelectionEvent event) {
536
				setExampleGroupBackgroundImage ();
537
			}
538
		});
539
		backgroundModeColorButton.addSelectionListener (new SelectionAdapter () {
540
			public void widgetSelected (SelectionEvent event) {
541
				setExampleGroupBackgroundColor ();
542
			}
543
		});
544
	
545
		/* Set the default state */
546
		backgroundModeCombo.setText(backgroundModeCombo.getItem(0));
547
		backgroundModeImageButton.setSelection(false);
548
		backgroundModeColorButton.setSelection(false);
549
	}
550
	
551
	void createEditEventDialog(Shell parent, int x, int y, final int index) {
552
		final Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
553
		dialog.setLayout(new GridLayout());
554
		dialog.setText(ControlExample.getResourceString ("Edit_Event"));
555
		Label label = new Label (dialog, SWT.NONE);
556
		label.setText (ControlExample.getResourceString ("Edit_Event_Fields", new String [] {EVENT_INFO[index].name}));
557
		
558
		Group group = new Group (dialog, SWT.NONE);
559
		group.setLayout(new GridLayout(2, false));
560
		group.setLayoutData(new GridData (SWT.FILL, SWT.FILL, true, true)); 
561
		
562
		final int fields = EVENT_INFO[index].settableFields;
563
		final int eventType = EVENT_INFO[index].type;
564
		setFieldsMask = EVENT_INFO[index].setFields;
565
		setFieldsEvent = EVENT_INFO[index].event;
566
		
567
		if ((fields & DOIT) != 0) {
568
			new Label (group, SWT.NONE).setText ("doit");
569
			final Combo doitCombo = new Combo (group, SWT.READ_ONLY);
570
			doitCombo.setItems (new String [] {"", "true", "false"});
571
			if ((setFieldsMask & DOIT) != 0) doitCombo.setText(Boolean.toString(setFieldsEvent.doit));
572
			doitCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
573
			doitCombo.addSelectionListener(new SelectionAdapter () {
574
				public void widgetSelected(SelectionEvent e) {
575
					String newValue = doitCombo.getText();
576
					if (newValue.length() == 0) {
577
						setFieldsMask &= ~DOIT;
578
					} else {
579
						setFieldsEvent.type = eventType;
580
						setFieldsEvent.doit = newValue.equals("true");
581
						setFieldsMask |= DOIT;
582
					}
583
				}
584
			});
585
		}
586
587
		if ((fields & DETAIL) != 0) {
588
			new Label (group, SWT.NONE).setText ("detail");			
589
			int detailType = fields & 0xFF;
590
			final Combo detailCombo = new Combo (group, SWT.READ_ONLY);
591
			detailCombo.setItems (DETAIL_CONSTANTS[detailType]);
592
			detailCombo.add ("", 0);
593
			detailCombo.setVisibleItemCount(detailCombo.getItemCount());
594
			if ((setFieldsMask & DETAIL) != 0) detailCombo.setText (DETAIL_CONSTANTS[detailType][setFieldsEvent.detail]);
595
			detailCombo.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
596
			detailCombo.addSelectionListener(new SelectionAdapter () {
597
				public void widgetSelected(SelectionEvent e) {
598
					String newValue = detailCombo.getText();
599
					if (newValue.length() == 0) {
600
						setFieldsMask &= ~DETAIL;
601
					} else {
602
						setFieldsEvent.type = eventType;
603
						for (int i = 0; i < DETAIL_VALUES.length; i += 2) {
604
							if (newValue.equals (DETAIL_VALUES [i])) {
605
								setFieldsEvent.detail = ((Integer) DETAIL_VALUES [i + 1]).intValue();
606
								break;
607
							}
608
						}
609
						setFieldsMask |= DETAIL;
610
					}
611
				}
612
			});
613
		}
614
615
		if ((fields & TEXT) != 0) {
616
			new Label (group, SWT.NONE).setText ("text");	
617
			final Text textText = new Text (group, SWT.BORDER);
618
			if ((setFieldsMask & TEXT) != 0) textText.setText(setFieldsEvent.text);
619
			textText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
620
			textText.addModifyListener(new ModifyListener () {
621
				public void modifyText(ModifyEvent e) {
622
					String newValue = textText.getText();
623
					if (newValue.length() == 0) {
624
						setFieldsMask &= ~TEXT;
625
					} else {
626
						setFieldsEvent.type = eventType;
627
						setFieldsEvent.text = newValue;
628
						setFieldsMask |= TEXT;
629
					}
630
				}
631
			});
632
		}
633
634
		if ((fields & X) != 0) {
635
			new Label (group, SWT.NONE).setText ("x");	
636
			final Text xText = new Text (group, SWT.BORDER);
637
			if ((setFieldsMask & X) != 0) xText.setText(Integer.toString(setFieldsEvent.x));
638
			xText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
639
			xText.addModifyListener(new ModifyListener () {
640
				public void modifyText(ModifyEvent e) {
641
					String newValue = xText.getText ();
642
					try {
643
						int newIntValue = Integer.parseInt (newValue);
644
						setFieldsEvent.type = eventType;
645
						setFieldsEvent.x = newIntValue;
646
						setFieldsMask |= X;
647
					} catch (NumberFormatException ex) {
648
						setFieldsMask &= ~X;
649
					}
650
				}
651
			});
652
		}
653
654
		if ((fields & Y) != 0) {
655
			new Label (group, SWT.NONE).setText ("y");	
656
			final Text yText = new Text (group, SWT.BORDER);
657
			if ((setFieldsMask & Y) != 0) yText.setText(Integer.toString(setFieldsEvent.y));
658
			yText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
659
			yText.addModifyListener(new ModifyListener () {
660
				public void modifyText(ModifyEvent e) {
661
					String newValue = yText.getText ();
662
					try {
663
						int newIntValue = Integer.parseInt (newValue);
664
						setFieldsEvent.type = eventType;
665
						setFieldsEvent.y = newIntValue;
666
						setFieldsMask |= Y;
667
					} catch (NumberFormatException ex) {
668
						setFieldsMask &= ~Y;
669
					}
670
				}
671
			});
672
		}
673
674
		if ((fields & WIDTH) != 0) {
675
			new Label (group, SWT.NONE).setText ("width");	
676
			final Text widthText = new Text (group, SWT.BORDER);
677
			if ((setFieldsMask & WIDTH) != 0) widthText.setText(Integer.toString(setFieldsEvent.width));
678
			widthText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
679
			widthText.addModifyListener(new ModifyListener () {
680
				public void modifyText(ModifyEvent e) {
681
					String newValue = widthText.getText ();
682
					try {
683
						int newIntValue = Integer.parseInt (newValue);
684
						setFieldsEvent.type = eventType;
685
						setFieldsEvent.width = newIntValue;
686
						setFieldsMask |= WIDTH;
687
					} catch (NumberFormatException ex) {
688
						setFieldsMask &= ~WIDTH;
689
					}
690
				}
691
			});
692
		}
693
694
		if ((fields & HEIGHT) != 0) {
695
			new Label (group, SWT.NONE).setText ("height");	
696
			final Text heightText = new Text (group, SWT.BORDER);
697
			if ((setFieldsMask & HEIGHT) != 0) heightText.setText(Integer.toString(setFieldsEvent.height));
698
			heightText.setLayoutData (new GridData (SWT.FILL, SWT.CENTER, true, false));
699
			heightText.addModifyListener(new ModifyListener () {
700
				public void modifyText(ModifyEvent e) {
701
					String newValue = heightText.getText ();
702
					try {
703
						int newIntValue = Integer.parseInt (newValue);
704
						setFieldsEvent.type = eventType;
705
						setFieldsEvent.height = newIntValue;
706
						setFieldsMask |= HEIGHT;
707
					} catch (NumberFormatException ex) {
708
						setFieldsMask &= ~HEIGHT;
709
					}
710
				}
711
			});
712
		}
713
714
		Button ok = new Button (dialog, SWT.PUSH);
715
		ok.setText (ControlExample.getResourceString("OK"));
716
		GridData data = new GridData (70, SWT.DEFAULT);
717
		data.horizontalAlignment = SWT.RIGHT;
718
		ok.setLayoutData (data);
719
		ok.addSelectionListener (new SelectionAdapter() {
720
			public void widgetSelected(SelectionEvent e) {
721
				EVENT_INFO[index].setFields = setFieldsMask;
722
				EVENT_INFO[index].event = setFieldsEvent;
723
				dialog.dispose();
724
			}
725
		});
726
727
		dialog.setDefaultButton(ok);
728
		dialog.pack();
729
		dialog.setLocation(x, y);
730
		dialog.open();
731
	}
732
733
	/**
734
	 * Create the event console popup menu.
735
	 */
736
	void createEventConsolePopup () {
737
		Menu popup = new Menu (shell, SWT.POP_UP);
738
		eventConsole.setMenu (popup);
739
740
		MenuItem cut = new MenuItem (popup, SWT.PUSH);
741
		cut.setText (ControlExample.getResourceString("MenuItem_Cut"));
742
		cut.addListener (SWT.Selection, new Listener () {
743
			public void handleEvent (Event event) {
744
				eventConsole.cut ();
745
			}
746
		});
747
		MenuItem copy = new MenuItem (popup, SWT.PUSH);
748
		copy.setText (ControlExample.getResourceString("MenuItem_Copy"));
749
		copy.addListener (SWT.Selection, new Listener () {
750
			public void handleEvent (Event event) {
751
				eventConsole.copy ();
752
			}
753
		});
754
		MenuItem paste = new MenuItem (popup, SWT.PUSH);
755
		paste.setText (ControlExample.getResourceString("MenuItem_Paste"));
756
		paste.addListener (SWT.Selection, new Listener () {
757
			public void handleEvent (Event event) {
758
				eventConsole.paste ();
759
			}
760
		});
761
		new MenuItem (popup, SWT.SEPARATOR);
762
		MenuItem selectAll = new MenuItem (popup, SWT.PUSH);
763
		selectAll.setText(ControlExample.getResourceString("MenuItem_SelectAll"));
764
		selectAll.addListener (SWT.Selection, new Listener () {
765
			public void handleEvent (Event event) {
766
				eventConsole.selectAll ();
767
			}
768
		});
769
	}
770
771
	/**
772
	 * Creates the "Example" group.  The "Example" group
773
	 * is typically the left hand column in the tab.
774
	 */
775
	void createExampleGroup () {
776
		exampleGroup = new Group (tabFolderPage, SWT.NONE);
777
		exampleGroup.setLayout (new GridLayout ());
778
		exampleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
779
	}
780
	
781
	/**
782
	 * Creates the "Example" widget children of the "Example" group.
783
	 * Subclasses override this method to create the particular
784
	 * example control.
785
	 */
786
	void createExampleWidgets () {
787
		/* Do nothing */
788
	}
789
	
790
	/**
791
	 * Creates and opens the "Listener selection" dialog.
792
	 */
793
	void createListenerSelectionDialog () {
794
		final Shell dialog = new Shell (shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
795
		dialog.setText (ControlExample.getResourceString ("Select_Listeners"));
796
		dialog.setLayout (new GridLayout (2, false));
797
		final Table table = new Table (dialog, SWT.BORDER | SWT.V_SCROLL | SWT.CHECK);
798
		GridData data = new GridData(GridData.FILL_BOTH);
799
		data.verticalSpan = 3;
800
		table.setLayoutData(data);
801
		for (int i = 0; i < EVENT_INFO.length; i++) {
802
			TableItem item = new TableItem (table, SWT.NONE);
803
			item.setText (EVENT_INFO[i].name);
804
			item.setChecked (eventsFilter[i]);
805
		}
806
		final String [] customNames = getCustomEventNames ();
807
		for (int i = 0; i < customNames.length; i++) {
808
			TableItem item = new TableItem (table, SWT.NONE);
809
			item.setText (customNames[i]);
810
			item.setChecked (eventsFilter[EVENT_INFO.length + i]);
811
		}
812
		Button selectAll = new Button (dialog, SWT.PUSH);
813
		selectAll.setText(ControlExample.getResourceString ("Select_All"));
814
		selectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
815
		selectAll.addSelectionListener (new SelectionAdapter() {
816
			public void widgetSelected(SelectionEvent e) {
817
				TableItem [] items = table.getItems();
818
				for (int i = 0; i < EVENT_INFO.length; i++) {
819
					items[i].setChecked(true);
820
				}
821
				for (int i = 0; i < customNames.length; i++) {
822
					items[EVENT_INFO.length + i].setChecked(true);
823
				}
824
			}
825
		});
826
		Button deselectAll = new Button (dialog, SWT.PUSH);
827
		deselectAll.setText(ControlExample.getResourceString ("Deselect_All"));
828
		deselectAll.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
829
		deselectAll.addSelectionListener (new SelectionAdapter() {
830
			public void widgetSelected(SelectionEvent e) {
831
				TableItem [] items = table.getItems();
832
				for (int i = 0; i < EVENT_INFO.length; i++) {
833
					items[i].setChecked(false);
834
				}
835
				for (int i = 0; i < customNames.length; i++) {
836
					items[EVENT_INFO.length + i].setChecked(false);
837
				}
838
			}
839
		});
840
		final Button editEvent = new Button (dialog, SWT.PUSH);
841
		editEvent.setText (ControlExample.getResourceString ("Edit_Event"));
842
		editEvent.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING));
843
		editEvent.addSelectionListener (new SelectionAdapter() {
844
			public void widgetSelected (SelectionEvent e) {
845
				Point pt = editEvent.getLocation();
846
				pt = e.display.map(editEvent, null, pt);
847
				int index = table.getSelectionIndex();
848
				if (getExampleWidgets().length > 0 && index != -1) {
849
					createEditEventDialog(dialog, pt.x, pt.y, index);
850
				}
851
			}
852
		});
853
		editEvent.setEnabled(false);
854
		table.addSelectionListener(new SelectionAdapter() {
855
			public void widgetSelected(SelectionEvent e) {
856
				int fields = 0;
857
				int index = table.getSelectionIndex();
858
				if (index != -1 && index < EVENT_INFO.length) {  // TODO: Allow custom widgets to specify event info
859
					fields = (EVENT_INFO[index].settableFields);
860
				}
861
				editEvent.setEnabled(fields != 0);
862
			}
863
			public void widgetDefaultSelected(SelectionEvent e) {
864
				if (editEvent.getEnabled()) {
865
					Point pt = editEvent.getLocation();
866
					pt = e.display.map(editEvent, null, pt);
867
					int index = table.getSelectionIndex();
868
					if (getExampleWidgets().length > 0 && index != -1 && index < EVENT_INFO.length) {
869
						createEditEventDialog(dialog, pt.x, pt.y, index);
870
					}
871
				}
872
			}
873
		});
874
875
		new Label(dialog, SWT.NONE); /* Filler */
876
		Button ok = new Button (dialog, SWT.PUSH);
877
		ok.setText(ControlExample.getResourceString ("OK"));
878
		dialog.setDefaultButton(ok);
879
		ok.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
880
		ok.addSelectionListener (new SelectionAdapter() {
881
			public void widgetSelected(SelectionEvent e) {
882
				TableItem [] items = table.getItems();
883
				for (int i = 0; i < EVENT_INFO.length; i++) {
884
					eventsFilter[i] = items[i].getChecked();
885
				}
886
				for (int i = 0; i < customNames.length; i++) {
887
					eventsFilter[EVENT_INFO.length + i] = items[EVENT_INFO.length + i].getChecked();
888
				}
889
				dialog.dispose();
890
			}
891
		});
892
		dialog.pack ();
893
		/*
894
		 * If the preferred size of the dialog is too tall for the display,
895
		 * then reduce the height, so that the vertical scrollbar will appear.
896
		 */
897
		Rectangle bounds = dialog.getBounds();
898
		Rectangle trim = dialog.computeTrim(0, 0, 0, 0);
899
		Rectangle clientArea = display.getClientArea();
900
		if (bounds.height > clientArea.height) {
901
			dialog.setSize(bounds.width, clientArea.height - trim.height);
902
		}
903
		dialog.setLocation(bounds.x, clientArea.y);
904
		dialog.open ();
905
		while (! dialog.isDisposed()) {
906
			if (! display.readAndDispatch()) display.sleep();
907
		}
908
	}
909
910
	/**
911
	 * Creates the "Listeners" group.  The "Listeners" group
912
	 * goes below the "Example" and "Control" groups.
913
	 */
914
	void createListenersGroup () {
915
		listenersGroup = new Group (tabFolderPage, SWT.NONE);
916
		listenersGroup.setLayout (new GridLayout (3, false));
917
		listenersGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true, 2, 1));
918
		listenersGroup.setText (ControlExample.getResourceString ("Listeners"));
919
920
		/*
921
		 * Create the button to access the 'Listeners' dialog.
922
		 */
923
		Button listenersButton = new Button (listenersGroup, SWT.PUSH);
924
		listenersButton.setText (ControlExample.getResourceString ("Select_Listeners"));
925
		listenersButton.addSelectionListener (new SelectionAdapter() {
926
			public void widgetSelected (SelectionEvent e) {
927
				createListenerSelectionDialog ();
928
				recreateExampleWidgets ();
929
			}
930
		});
931
		
932
		/*
933
		 * Create the checkbox to add/remove listeners to/from the example widgets.
934
		 */
935
		final Button listenCheckbox = new Button (listenersGroup, SWT.CHECK);
936
		listenCheckbox.setText (ControlExample.getResourceString ("Listen"));
937
		listenCheckbox.addSelectionListener (new SelectionAdapter () {
938
			public void widgetSelected(SelectionEvent e) {
939
				logging = listenCheckbox.getSelection ();
940
				recreateExampleWidgets ();
941
			}
942
		});
943
944
		/*
945
		 * Create the button to clear the text.
946
		 */
947
		Button clearButton = new Button (listenersGroup, SWT.PUSH);
948
		clearButton.setText (ControlExample.getResourceString ("Clear"));
949
		clearButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
950
		clearButton.addSelectionListener (new SelectionAdapter() {
951
			public void widgetSelected (SelectionEvent e) {
952
				eventConsole.setText ("");
953
			}
954
		});
955
		
956
		/* Initialize the eventsFilter to log all events. */
957
		int customEventCount = getCustomEventNames ().length;
958
		eventsFilter = new boolean [EVENT_INFO.length + customEventCount];
959
		for (int i = 0; i < EVENT_INFO.length + customEventCount; i++) {
960
			eventsFilter [i] = true;
961
		}
962
963
		/* Create the event console Text. */
964
		eventConsole = new Text (listenersGroup, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
965
		GridData data = new GridData (GridData.FILL_BOTH);
966
		data.horizontalSpan = 3;
967
		data.heightHint = 80;
968
		eventConsole.setLayoutData (data);
969
		createEventConsolePopup ();
970
		eventConsole.addKeyListener (new KeyAdapter () {
971
			public void keyPressed (KeyEvent e) {
972
				if ((e.keyCode == 'A' || e.keyCode == 'a') && (e.stateMask & SWT.MOD1) != 0) {
973
					eventConsole.selectAll ();
974
					e.doit = false;
975
				}
976
			}
977
		});
978
	}
979
	
980
	/**
981
	 * Returns a list of set/get API method names (without the set/get prefix)
982
	 * that can be used to set/get values in the example control(s).
983
	 */
984
	String[] getMethodNames() {
985
		return null;
986
	}
987
988
	Shell createSetGetDialog(String[] methodNames) {
989
		final Shell dialog = new Shell(shell, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MODELESS);
990
		dialog.setLayout(new GridLayout(2, false));
991
		dialog.setText(getTabText() + " " + ControlExample.getResourceString ("Set_Get"));
992
		nameCombo = new Combo(dialog, SWT.READ_ONLY);
993
		nameCombo.setItems(methodNames);
994
		nameCombo.setText(methodNames[0]);
995
		nameCombo.setVisibleItemCount(methodNames.length);
996
		nameCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
997
		nameCombo.addSelectionListener(new SelectionAdapter() {
998
			public void widgetSelected(SelectionEvent e) {
999
				resetLabels();
1000
			}
1001
		});
1002
		returnTypeLabel = new Label(dialog, SWT.NONE);
1003
		returnTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
1004
		setButton = new Button(dialog, SWT.PUSH);
1005
		setButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
1006
		setButton.addSelectionListener(new SelectionAdapter() {
1007
			public void widgetSelected(SelectionEvent e) {
1008
				setValue();
1009
				setText.selectAll();
1010
				setText.setFocus();
1011
			}
1012
		});
1013
		setText = new Text(dialog, SWT.SINGLE | SWT.BORDER);
1014
		setText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1015
		getButton = new Button(dialog, SWT.PUSH);
1016
		getButton.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, false, false));
1017
		getButton.addSelectionListener(new SelectionAdapter() {
1018
			public void widgetSelected(SelectionEvent e) {
1019
				getValue();
1020
			}
1021
		});
1022
		getText = new Text(dialog, SWT.MULTI | SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
1023
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
1024
		data.widthHint = 240;
1025
		data.heightHint = 200;
1026
		getText.setLayoutData(data);
1027
		resetLabels();
1028
		dialog.setDefaultButton(setButton);
1029
		dialog.pack();
1030
		dialog.addDisposeListener(new DisposeListener() {
1031
			public void widgetDisposed(DisposeEvent e) {
1032
				setGetDialog = null;
1033
			}
1034
		});
1035
		return dialog;
1036
	}
1037
1038
	void resetLabels() {
1039
		String methodRoot = nameCombo.getText();
1040
		returnTypeLabel.setText(parameterInfo(methodRoot));
1041
		setButton.setText(setMethodName(methodRoot));
1042
		getButton.setText("get" + methodRoot);
1043
		setText.setText("");
1044
		getText.setText("");
1045
		getValue();
1046
		setText.setFocus();
1047
	}
1048
1049
	String setMethodName(String methodRoot) {
1050
		return "set" + methodRoot;
1051
	}
1052
1053
	String parameterInfo(String methodRoot) {
1054
		String typeName = null;
1055
		Class returnType = getReturnType(methodRoot);
1056
		boolean isArray = returnType.isArray();
1057
		if (isArray) {
1058
			typeName = returnType.getComponentType().getName();
1059
		} else {
1060
			typeName = returnType.getName();
1061
		}
1062
		String typeNameString = typeName;
1063
		int index = typeName.lastIndexOf('.');
1064
		if (index != -1 && index+1 < typeName.length()) typeNameString = typeName.substring(index+1);
1065
		String info = ControlExample.getResourceString("Info_" + typeNameString + (isArray ? "A" : ""));
1066
		if (isArray) {
1067
			typeNameString += "[]";
1068
		}
1069
		return ControlExample.getResourceString("Parameter_Info", new Object[] {typeNameString, info});
1070
	}
1071
1072
	void getValue() {
1073
		String methodName = "get" + nameCombo.getText();
1074
		getText.setText("");
1075
		Widget[] widgets = getExampleWidgets();
1076
		for (int i = 0; i < widgets.length; i++) {
1077
			try {
1078
				java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, null);
1079
				Object result = method.invoke(widgets[i], null);
1080
				if (result == null) {
1081
					getText.append("null");
1082
				} else if (result.getClass().isArray()) {
1083
					int length = java.lang.reflect.Array.getLength(result);
1084
					if (length == 0) {
1085
						getText.append(result.getClass().getComponentType() + "[0]");
1086
					}
1087
					for (int j = 0; j < length; j++) {
1088
						getText.append(java.lang.reflect.Array.get(result,j).toString() + "\n");
1089
					}
1090
				} else {
1091
					getText.append(result.toString());
1092
				}
1093
			} catch (Exception e) {
1094
				getText.append(e.toString());
1095
			}
1096
			if (i + 1 < widgets.length) {
1097
				getText.append("\n\n");
1098
			}
1099
		}
1100
	}
1101
1102
	Class getReturnType(String methodRoot) {
1103
		Class returnType = null;
1104
		String methodName = "get" + methodRoot;
1105
		Widget[] widgets = getExampleWidgets();
1106
		try {
1107
			java.lang.reflect.Method method = widgets[0].getClass().getMethod(methodName, null);
1108
			returnType = method.getReturnType();
1109
		} catch (Exception e) {
1110
		}
1111
		return returnType;
1112
	}
1113
	
1114
	void setValue() {
1115
		/* The parameter type must be the same as the get method's return type */
1116
		String methodRoot = nameCombo.getText();
1117
		Class returnType = getReturnType(methodRoot);
1118
		String methodName = setMethodName(methodRoot);
1119
		String value = setText.getText();
1120
		Widget[] widgets = getExampleWidgets();
1121
		for (int i = 0; i < widgets.length; i++) {
1122
			try {
1123
				java.lang.reflect.Method method = widgets[i].getClass().getMethod(methodName, new Class[] {returnType});
1124
				String typeName = returnType.getName();
1125
				Object[] parameter = null;
1126
				if (value.equals("null")) {
1127
					parameter = new Object[] {null};
1128
				} else if (typeName.equals("int")) {
1129
					parameter = new Object[] {new Integer(value)};
1130
				} else if (typeName.equals("long")) {
1131
					parameter = new Object[] {new Long(value)};
1132
				} else if (typeName.equals("char")) {
1133
					parameter = new Object[] {value.length() == 1 ? new Character(value.charAt(0)) : new Character('\0')};
1134
				} else if (typeName.equals("boolean")) {
1135
					parameter = new Object[] {new Boolean(value)};
1136
				} else if (typeName.equals("java.lang.String")) {
1137
					parameter = new Object[] {value};
1138
				} else if (typeName.equals("org.eclipse.swt.graphics.Point")) {
1139
					String xy[] = split(value, ',');
1140
					parameter = new Object[] {new Point(new Integer(xy[0]).intValue(),new Integer(xy[1]).intValue())};
1141
				} else if (typeName.equals("[I")) {
1142
					String strings[] = split(value, ',');
1143
					int[] ints = new int[strings.length];
1144
					for (int j = 0; j < strings.length; j++) {
1145
						ints[j] = new Integer(strings[j]).intValue();
1146
					}
1147
					parameter = new Object[] {ints};
1148
				} else if (typeName.equals("[Ljava.lang.String;")) {
1149
					parameter = new Object[] {split(value, ',')};
1150
				} else {
1151
					parameter = parameterForType(typeName, value, widgets[i]);
1152
				}
1153
				method.invoke(widgets[i], parameter);
1154
			} catch (Exception e) {
1155
				Throwable cause = e.getCause();
1156
				String message = e.getMessage();
1157
				getText.setText(e.toString());
1158
				if (cause != null) getText.append(", cause=\n" + cause.toString());
1159
				if (message != null) getText.append(", message=\n" + message);
1160
			}
1161
		}
1162
	}
1163
1164
	Object[] parameterForType(String typeName, String value, Widget widget) {
1165
		return new Object[] {value};
1166
	}
1167
1168
	void createOrientationGroup () {
1169
		/* Create Orientation group*/
1170
		orientationGroup = new Group (controlGroup, SWT.NONE);
1171
		orientationGroup.setLayout (new GridLayout());
1172
		orientationGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
1173
		orientationGroup.setText (ControlExample.getResourceString("Orientation"));
1174
		defaultOrietationButton = new Button (orientationGroup, SWT.RADIO);
1175
		defaultOrietationButton.setText (ControlExample.getResourceString("Default"));
1176
		defaultOrietationButton.setSelection (true);
1177
		ltrButtonRecreate = new Button (orientationGroup, SWT.RADIO);
1178
		ltrButtonRecreate.setText ("create new SWT.LEFT_TO_RIGHT");
1179
		rtlButtonRecreate = new Button (orientationGroup, SWT.RADIO);
1180
		rtlButtonRecreate.setText ("create new SWT.RIGHT_TO_LEFT");
1181
		ltrButtonSet= new Button (orientationGroup, SWT.RADIO);
1182
		ltrButtonSet.setText ("set orientation SWT.LEFT_TO_RIGHT");
1183
		rtlButtonSet = new Button (orientationGroup, SWT.RADIO);
1184
		rtlButtonSet.setText ("set orientation SWT.RIGHT_TO_LEFT");
1185
1186
		
1187
	}
1188
	
1189
	/**
1190
	 * Creates the "Size" group.  The "Size" group contains
1191
	 * controls that allow the user to change the size of
1192
	 * the example widgets.
1193
	 */
1194
	void createSizeGroup () {
1195
		/* Create the group */
1196
		sizeGroup = new Group (controlGroup, SWT.NONE);
1197
		sizeGroup.setLayout (new GridLayout());
1198
		sizeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
1199
		sizeGroup.setText (ControlExample.getResourceString("Size"));
1200
	
1201
		/* Create the controls */
1202
	
1203
		/*
1204
		 * The preferred size of a widget is the size returned
1205
		 * by widget.computeSize (SWT.DEFAULT, SWT.DEFAULT).
1206
		 * This size is defined on a widget by widget basis.
1207
		 * Many widgets will attempt to display their contents.
1208
		 */
1209
		preferredButton = new Button (sizeGroup, SWT.RADIO);
1210
		preferredButton.setText (ControlExample.getResourceString("Preferred"));
1211
		tooSmallButton = new Button (sizeGroup, SWT.RADIO);
1212
		tooSmallButton.setText (TOO_SMALL_SIZE + " X " + TOO_SMALL_SIZE);
1213
		smallButton = new Button(sizeGroup, SWT.RADIO);
1214
		smallButton.setText (SMALL_SIZE + " X " + SMALL_SIZE);
1215
		largeButton = new Button (sizeGroup, SWT.RADIO);
1216
		largeButton.setText (LARGE_SIZE + " X " + LARGE_SIZE);
1217
		fillHButton = new Button (sizeGroup, SWT.CHECK);
1218
		fillHButton.setText (ControlExample.getResourceString("Fill_X"));
1219
		fillVButton = new Button (sizeGroup, SWT.CHECK);
1220
		fillVButton.setText (ControlExample.getResourceString("Fill_Y"));
1221
		
1222
		/* Add the listeners */
1223
		SelectionAdapter selectionListener = new SelectionAdapter () {
1224
			public void widgetSelected (SelectionEvent event) {
1225
				setExampleWidgetSize ();
1226
			}
1227
		};
1228
		preferredButton.addSelectionListener(selectionListener);
1229
		tooSmallButton.addSelectionListener(selectionListener);
1230
		smallButton.addSelectionListener(selectionListener);
1231
		largeButton.addSelectionListener(selectionListener);
1232
		fillHButton.addSelectionListener(selectionListener);
1233
		fillVButton.addSelectionListener(selectionListener);
1234
	
1235
		/* Set the default state */
1236
		preferredButton.setSelection (true);
1237
	}
1238
	
1239
	/**
1240
	 * Creates the "Style" group.  The "Style" group contains
1241
	 * controls that allow the user to change the style of
1242
	 * the example widgets.  Changing a widget "Style" causes
1243
	 * the widget to be destroyed and recreated.
1244
	 */
1245
	void createStyleGroup () {
1246
		styleGroup = new Group (controlGroup, SWT.NONE);
1247
		styleGroup.setLayout (new GridLayout ());
1248
		styleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
1249
		styleGroup.setText (ControlExample.getResourceString("Styles"));
1250
	}
1251
	
1252
	/**
1253
	 * Creates the tab folder page.
1254
	 *
1255
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
1256
	 * @return the new page for the tab folder
1257
	 */
1258
	Composite createTabFolderPage (TabFolder tabFolder) {
1259
		/* Cache the shell and display. */
1260
		shell = tabFolder.getShell ();
1261
		display = shell.getDisplay ();
1262
		
1263
		/* Create a two column page. */
1264
		tabFolderPage = new Composite (tabFolder, SWT.NONE);
1265
		tabFolderPage.setLayout (new GridLayout (2, false));
1266
	
1267
		/* Create the "Example" and "Control" groups. */
1268
		createExampleGroup ();
1269
		createControlGroup ();
1270
		
1271
		/* Create the "Listeners" group under the "Control" group. */
1272
		createListenersGroup ();
1273
		
1274
		/* Create and initialize the example and control widgets. */
1275
		createExampleWidgets ();
1276
		hookExampleWidgetListeners ();
1277
		createControlWidgets ();
1278
		setExampleWidgetState ();
1279
		
1280
		return tabFolderPage;
1281
	}
1282
	
1283
	void setExampleWidgetPopupMenu() {
1284
		Control[] controls = getExampleControls();
1285
		for (int i = 0; i < controls.length; i++) {
1286
			final Control control = controls [i];
1287
			control.addListener(SWT.MenuDetect, new Listener() {
1288
				public void handleEvent(Event event) {
1289
		        	Menu menu = control.getMenu();
1290
		        	if (menu != null && samplePopup) {
1291
		        		menu.dispose();
1292
		        		menu = null;
1293
		        	}
1294
		        	if (menu == null && popupMenuButton.getSelection()) {
1295
		        		menu = new Menu(shell, SWT.POP_UP | (control.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT)));
1296
			        	MenuItem item = new MenuItem(menu, SWT.PUSH);
1297
			        	item.setText("Sample popup menu item");
1298
			        	specialPopupMenuItems(menu, event);
1299
			        	control.setMenu(menu);
1300
		        		samplePopup = true;
1301
		        	}
1302
				}
1303
			});
1304
		}
1305
	}
1306
1307
	protected void specialPopupMenuItems(final Menu menu, final Event event) {
1308
	}
1309
1310
	/**
1311
	 * Disposes the "Example" widgets.
1312
	 */
1313
	void disposeExampleWidgets () {
1314
		Widget [] widgets = getExampleWidgets ();
1315
		for (int i=0; i<widgets.length; i++) {
1316
			widgets [i].dispose ();
1317
		}
1318
	}
1319
	
1320
	Image colorImage (Color color) {
1321
		Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
1322
		GC gc = new GC(image);
1323
		gc.setBackground(color);
1324
		Rectangle bounds = image.getBounds();
1325
		gc.fillRectangle(0, 0, bounds.width, bounds.height);
1326
		gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1327
		gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
1328
		gc.dispose();
1329
		return image;
1330
	}
1331
	
1332
	Image fontImage (Font font) {
1333
		Image image = new Image (display, IMAGE_SIZE, IMAGE_SIZE);
1334
		GC gc = new GC(image);
1335
		Rectangle bounds = image.getBounds();
1336
		gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
1337
		gc.fillRectangle(0, 0, bounds.width, bounds.height);
1338
		gc.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
1339
		gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
1340
		FontData data[] = font.getFontData();
1341
		int style = data[0].getStyle();
1342
		switch (style) {
1343
		case SWT.NORMAL:
1344
			gc.drawLine(3, 3, 3, 8);
1345
			gc.drawLine(4, 3, 7, 8);
1346
			gc.drawLine(8, 3, 8, 8);
1347
			break;
1348
		case SWT.BOLD:
1349
			gc.drawLine(3, 2, 3, 9);
1350
			gc.drawLine(4, 2, 4, 9);
1351
			gc.drawLine(5, 2, 7, 2);
1352
			gc.drawLine(5, 3, 8, 3);
1353
			gc.drawLine(5, 5, 7, 5);
1354
			gc.drawLine(5, 6, 7, 6);
1355
			gc.drawLine(5, 8, 8, 8);
1356
			gc.drawLine(5, 9, 7, 9);
1357
			gc.drawLine(7, 4, 8, 4);
1358
			gc.drawLine(7, 7, 8, 7);
1359
			break;
1360
		case SWT.ITALIC:
1361
			gc.drawLine(6, 2, 8, 2);
1362
			gc.drawLine(7, 3, 4, 8);
1363
			gc.drawLine(3, 9, 5, 9);
1364
			break;
1365
		case SWT.BOLD | SWT.ITALIC:
1366
			gc.drawLine(5, 2, 8, 2);
1367
			gc.drawLine(5, 3, 8, 3);
1368
			gc.drawLine(6, 4, 4, 7);
1369
			gc.drawLine(7, 4, 5, 7);
1370
			gc.drawLine(3, 8, 6, 8);
1371
			gc.drawLine(3, 9, 6, 9);
1372
			break;
1373
		}
1374
		gc.dispose();
1375
		return image;
1376
	}
1377
	
1378
	/**
1379
	 * Gets the list of custom event names.
1380
	 * Subclasses override this method to allow adding of custom events.
1381
	 * 
1382
	 * @return an array containing custom event names
1383
	 * @see hookCustomListener
1384
	 */
1385
	String [] getCustomEventNames () {
1386
		return new String [0];
1387
	}
1388
	
1389
	/**
1390
	 * Gets the default style for a widget
1391
	 *
1392
	 * @return the default style bit
1393
	 */
1394
	int getDefaultStyle () {
1395
		if (ltrButtonRecreate != null && ltrButtonRecreate.getSelection()) {
1396
			return SWT.LEFT_TO_RIGHT;
1397
		}
1398
		if (rtlButtonRecreate != null && rtlButtonRecreate.getSelection()) {
1399
			return SWT.RIGHT_TO_LEFT;
1400
		}
1401
		if (rtlButtonSet != null && rtlButtonSet.getSelection()) {
1402
			return SWT.RIGHT_TO_LEFT;
1403
		}
1404
		if (ltrButtonSet != null && ltrButtonSet.getSelection()) {
1405
			return SWT.LEFT_TO_RIGHT;
1406
		}
1407
		return SWT.NONE;
1408
	}
1409
	
1410
	/**
1411
	 * Gets the "Example" widgets.
1412
	 *
1413
	 * @return an array containing the example widgets
1414
	 */
1415
	Widget [] getExampleWidgets () {
1416
		return new Widget [0];
1417
	}
1418
	
1419
	/**
1420
	 * Gets the "Example" controls.
1421
	 * This is the subset of "Example" widgets that are controls.
1422
	 *
1423
	 * @return an array containing the example controls
1424
	 */
1425
	Control [] getExampleControls () {
1426
		Widget [] widgets = getExampleWidgets ();
1427
		Control [] controls = new Control [0];
1428
		for (int i = 0; i < widgets.length; i++) {
1429
			if (widgets[i] instanceof Control) {
1430
				Control[] newControls = new Control[controls.length + 1];
1431
				System.arraycopy(controls, 0, newControls, 0, controls.length);
1432
				controls = newControls;
1433
				controls[controls.length - 1] = (Control)widgets[i];
1434
			}
1435
		}
1436
		return controls;
1437
	}
1438
	
1439
	/**
1440
	 * Gets the "Example" widget's items, if any.
1441
	 *
1442
	 * @return an array containing the example widget's items
1443
	 */
1444
	Item [] getExampleWidgetItems () {
1445
		return new Item [0];
1446
	}
1447
	
1448
	/**
1449
	 * Gets the short text for the tab folder item.
1450
	 *
1451
	 * @return the short text for the tab item
1452
	 */
1453
	String getShortTabText() {
1454
		return getTabText();
1455
	}
1456
1457
	/**
1458
	 * Gets the text for the tab folder item.
1459
	 *
1460
	 * @return the text for the tab item
1461
	 */
1462
	String getTabText () {
1463
		return "";
1464
	}
1465
	
1466
	/**
1467
	 * Hooks all listeners to all example controls
1468
	 * and example control items.
1469
	 */
1470
	void hookExampleWidgetListeners () {
1471
		if (logging) {
1472
			Widget[] widgets = getExampleWidgets ();
1473
			for (int i = 0; i < widgets.length; i++) {
1474
				hookListeners (widgets [i]);
1475
			}
1476
			Item[] exampleItems = getExampleWidgetItems ();
1477
			for (int i = 0; i < exampleItems.length; i++) {
1478
				hookListeners (exampleItems [i]);
1479
			}
1480
			String [] customNames = getCustomEventNames ();
1481
			for (int i = 0; i < customNames.length; i++) {
1482
				if (eventsFilter [EVENT_INFO.length + i]) {
1483
					hookCustomListener (customNames[i]);
1484
				}
1485
			}
1486
		}
1487
	}
1488
	
1489
	/**
1490
	 * Hooks the custom listener specified by eventName.
1491
	 * Subclasses override this method to add custom listeners.
1492
	 * @see getCustomEventNames
1493
	 */
1494
	void hookCustomListener (String eventName) {
1495
	}
1496
	
1497
	/**
1498
	 * Hooks all listeners to the specified widget.
1499
	 */
1500
	void hookListeners (Widget widget) {
1501
		if (logging) {
1502
			Listener listener = new Listener() {
1503
				public void handleEvent (Event event) {
1504
					log (event);
1505
				}
1506
			};
1507
			for (int i = 0; i < EVENT_INFO.length; i++) {
1508
				if (eventsFilter [i]) {
1509
					widget.addListener (EVENT_INFO[i].type, listener);
1510
				}
1511
			}
1512
		}
1513
	}
1514
	
1515
	/**
1516
	 * Logs an untyped event to the event console.
1517
	 */
1518
	void log(Event event) {
1519
		int i = 0;
1520
		while (i < EVENT_INFO.length) {
1521
			if (EVENT_INFO[i].type == event.type) break;
1522
			i++;
1523
		}
1524
		String toString = EVENT_INFO[i].name + " [" + event.type + "]: ";
1525
		switch (event.type) {
1526
			case SWT.KeyDown:
1527
			case SWT.KeyUp: toString += new KeyEvent (event).toString (); break;
1528
			case SWT.MouseDown:
1529
			case SWT.MouseUp:
1530
			case SWT.MouseMove:
1531
			case SWT.MouseEnter:
1532
			case SWT.MouseExit:
1533
			case SWT.MouseDoubleClick:
1534
			case SWT.MouseWheel: 
1535
			case SWT.MouseHover: toString += new MouseEvent (event).toString (); break;
1536
			case SWT.Paint: toString += new PaintEvent (event).toString (); break;
1537
			case SWT.Move:
1538
			case SWT.Resize: toString += new ControlEvent (event).toString (); break;
1539
			case SWT.Dispose: toString += new DisposeEvent (event).toString (); break;
1540
			case SWT.Selection:
1541
			case SWT.DefaultSelection: toString += new SelectionEvent (event).toString (); break;
1542
			case SWT.FocusIn:
1543
			case SWT.FocusOut: toString += new FocusEvent (event).toString (); break;
1544
			case SWT.Expand:
1545
			case SWT.Collapse: toString += new TreeEvent (event).toString (); break;
1546
			case SWT.Iconify:
1547
			case SWT.Deiconify:
1548
			case SWT.Close:
1549
			case SWT.Activate:
1550
			case SWT.Deactivate: toString += new ShellEvent (event).toString (); break;
1551
			case SWT.Show:
1552
			case SWT.Hide: toString += (event.widget instanceof Menu) ? new MenuEvent (event).toString () : event.toString(); break;
1553
			case SWT.Modify: toString += new ModifyEvent (event).toString (); break;
1554
			case SWT.Verify: toString += new VerifyEvent (event).toString (); break;
1555
			case SWT.Help: toString += new HelpEvent (event).toString (); break;
1556
			case SWT.Arm: toString += new ArmEvent (event).toString (); break;
1557
			case SWT.Traverse: toString += new TraverseEvent (event).toString (); break;
1558
			case SWT.HardKeyDown:
1559
			case SWT.HardKeyUp:
1560
			case SWT.DragDetect:
1561
			case SWT.MenuDetect:
1562
			case SWT.SetData:
1563
			default: toString += event.toString ();
1564
		}
1565
		log (toString);
1566
		
1567
		/* Return values for event fields. */
1568
		int mask = EVENT_INFO[i].setFields;
1569
		if (!ignore && mask != 0) {
1570
			Event setFieldsEvent = EVENT_INFO[i].event;
1571
			if ((mask & DOIT) != 0) event.doit = setFieldsEvent.doit;
1572
			if ((mask & DETAIL) != 0) event.detail = setFieldsEvent.detail;
1573
			if ((mask & TEXT) != 0) event.text = setFieldsEvent.text;
1574
			if ((mask & X) != 0) event.x = setFieldsEvent.x;
1575
			if ((mask & Y) != 0) event.y = setFieldsEvent.y;
1576
			if ((mask & WIDTH) != 0) event.width = setFieldsEvent.width;
1577
			if ((mask & HEIGHT) != 0) event.height = setFieldsEvent.height;
1578
			eventConsole.append (ControlExample.getResourceString("Returning"));
1579
			ignore = true;
1580
			log (event);
1581
			ignore = false;
1582
		}
1583
	}
1584
	
1585
	/**
1586
	 * Logs a string to the event console.
1587
	 */
1588
	void log (String string) {
1589
		if (!eventConsole.isDisposed()) {
1590
			eventConsole.append (string);
1591
			eventConsole.append ("\n");
1592
		}
1593
	}
1594
1595
	/**
1596
	 * Logs a typed event to the event console.
1597
	 */
1598
	void log (String eventName, TypedEvent event) {
1599
		log (eventName + ": " + event.toString ());
1600
	}
1601
	
1602
	/**
1603
	 * Recreates the "Example" widgets.
1604
	 */
1605
	void recreateExampleWidgets () {
1606
		disposeExampleWidgets ();
1607
		createExampleWidgets ();
1608
		hookExampleWidgetListeners ();
1609
		setExampleWidgetState ();
1610
	}
1611
	
1612
	/**
1613
	 * Sets the foreground color, background color, and font
1614
	 * of the "Example" widgets to their default settings.
1615
	 * Subclasses may extend in order to reset other colors
1616
	 * and fonts to default settings as well.
1617
	 */
1618
	void resetColorsAndFonts () {
1619
		Color oldColor = foregroundColor;
1620
		foregroundColor = null;
1621
		setExampleWidgetForeground ();
1622
		if (oldColor != null) oldColor.dispose();
1623
		oldColor = backgroundColor;
1624
		backgroundColor = null;
1625
		setExampleWidgetBackground ();
1626
		if (oldColor != null) oldColor.dispose();
1627
		Font oldFont = font;
1628
		font = null;
1629
		setExampleWidgetFont ();
1630
		setExampleWidgetSize ();
1631
		if (oldFont != null) oldFont.dispose();
1632
	}
1633
	
1634
	boolean rtlSupport() {
1635
		return RTL_SUPPORT_ENABLE;
1636
	}
1637
	
1638
	/**
1639
	 * Sets the background color of the "Example" widgets' parent.
1640
	 */
1641
	void setExampleGroupBackgroundColor () {
1642
		if (backgroundModeGroup == null) return;
1643
		exampleGroup.setBackground (backgroundModeColorButton.getSelection () ? display.getSystemColor(SWT.COLOR_BLUE) : null);
1644
	}
1645
	/**
1646
	 * Sets the background image of the "Example" widgets' parent.
1647
	 */
1648
	void setExampleGroupBackgroundImage () {
1649
		if (backgroundModeGroup == null) return;
1650
		exampleGroup.setBackgroundImage (backgroundModeImageButton.getSelection () ? instance.images[ControlExample.ciParentBackground] : null);
1651
	}
1652
1653
	/**
1654
	 * Sets the background mode of the "Example" widgets' parent.
1655
	 */
1656
	void setExampleGroupBackgroundMode () {
1657
		if (backgroundModeGroup == null) return;
1658
		String modeString = backgroundModeCombo.getText ();
1659
		int mode = SWT.INHERIT_NONE;
1660
		if (modeString.equals("SWT.INHERIT_DEFAULT")) mode = SWT.INHERIT_DEFAULT;
1661
		if (modeString.equals("SWT.INHERIT_FORCE")) mode = SWT.INHERIT_FORCE;
1662
		exampleGroup.setBackgroundMode (mode);
1663
	}
1664
1665
	/**
1666
	 * Sets the background color of the "Example" widgets.
1667
	 */
1668
	void setExampleWidgetBackground () {
1669
		if (colorAndFontTable == null) return; // user cannot change color/font on this tab
1670
		Control [] controls = getExampleControls ();
1671
		if (!instance.startup) {
1672
			for (int i = 0; i < controls.length; i++) {
1673
				controls[i].setBackground (backgroundColor);
1674
			}
1675
		}
1676
		// Set the background color item's image to match the background color of the example widget(s).
1677
		Color color = backgroundColor;
1678
		if (controls.length == 0) return;
1679
		if (color == null) color = controls [0].getBackground ();
1680
		TableItem item = colorAndFontTable.getItem(BACKGROUND_COLOR);
1681
		Image oldImage = item.getImage();
1682
		if (oldImage != null) oldImage.dispose();
1683
		item.setImage (colorImage (color));
1684
	}
1685
	
1686
	/**
1687
	 * Sets the enabled state of the "Example" widgets.
1688
	 */
1689
	void setExampleWidgetEnabled () {
1690
		Control [] controls = getExampleControls ();
1691
		for (int i=0; i<controls.length; i++) {
1692
			controls [i].setEnabled (enabledButton.getSelection ());
1693
		}
1694
	}
1695
	
1696
	/**
1697
	 * Sets the font of the "Example" widgets.
1698
	 */
1699
	void setExampleWidgetFont () {
1700
		if (colorAndFontTable == null) return; // user cannot change color/font on this tab
1701
		Control [] controls = getExampleControls ();
1702
		if (!instance.startup) {
1703
			for (int i = 0; i < controls.length; i++) {
1704
				controls[i].setFont(font);
1705
			}
1706
		}
1707
		/* Set the font item's image and font to match the font of the example widget(s). */
1708
		Font ft = font;
1709
		if (controls.length == 0) return;
1710
		if (ft == null) ft = controls [0].getFont ();
1711
		TableItem item = colorAndFontTable.getItem(FONT);
1712
		Image oldImage = item.getImage();
1713
		if (oldImage != null) oldImage.dispose();
1714
		item.setImage (fontImage (ft));
1715
		item.setFont(ft);
1716
		colorAndFontTable.layout ();
1717
	}
1718
	
1719
	/**
1720
	 * Sets the foreground color of the "Example" widgets.
1721
	 */
1722
	void setExampleWidgetForeground () {
1723
		if (colorAndFontTable == null) return; // user cannot change color/font on this tab
1724
		Control [] controls = getExampleControls ();
1725
		if (!instance.startup) {
1726
			for (int i = 0; i < controls.length; i++) {
1727
				controls[i].setForeground (foregroundColor);
1728
			}
1729
		}
1730
		/* Set the foreground color item's image to match the foreground color of the example widget(s). */
1731
		Color color = foregroundColor;
1732
		if (controls.length == 0) return;
1733
		if (color == null) color = controls [0].getForeground ();
1734
		TableItem item = colorAndFontTable.getItem(FOREGROUND_COLOR);
1735
		Image oldImage = item.getImage();
1736
		if (oldImage != null) oldImage.dispose();
1737
		item.setImage (colorImage(color));
1738
	}
1739
	
1740
	/**
1741
	 * Sets the size of the "Example" widgets.
1742
	 */
1743
	void setExampleWidgetSize () {
1744
		int size = SWT.DEFAULT;
1745
		if (preferredButton == null) return;
1746
		if (preferredButton.getSelection()) size = SWT.DEFAULT;
1747
		if (tooSmallButton.getSelection()) size = TOO_SMALL_SIZE;
1748
		if (smallButton.getSelection()) size = SMALL_SIZE;
1749
		if (largeButton.getSelection()) size = LARGE_SIZE;
1750
		Control [] controls = getExampleControls ();
1751
		for (int i=0; i<controls.length; i++) {
1752
			GridData gridData = new GridData(size, size); 
1753
			gridData.grabExcessHorizontalSpace = fillHButton.getSelection();
1754
			gridData.grabExcessVerticalSpace = fillVButton.getSelection();
1755
			gridData.horizontalAlignment = fillHButton.getSelection() ? SWT.FILL : SWT.LEFT;
1756
			gridData.verticalAlignment = fillVButton.getSelection() ? SWT.FILL : SWT.TOP;
1757
			controls [i].setLayoutData (gridData);
1758
		}
1759
		tabFolderPage.layout (controls);
1760
	}
1761
	
1762
	/**
1763
	 * Sets the state of the "Example" widgets.  Subclasses
1764
	 * may extend this method to set "Example" widget state
1765
	 * that is specific to the widget.
1766
	 */
1767
	void setExampleWidgetState () {
1768
		setExampleWidgetBackground ();
1769
		setExampleWidgetForeground ();
1770
		setExampleWidgetFont ();
1771
		if (!instance.startup) {
1772
			setExampleWidgetEnabled ();
1773
			setExampleWidgetVisibility ();
1774
			setExampleGroupBackgroundMode ();
1775
			setExampleGroupBackgroundColor ();
1776
			setExampleGroupBackgroundImage ();
1777
			setExampleWidgetBackgroundImage ();
1778
			setExampleWidgetPopupMenu ();
1779
			setExampleWidgetSize ();
1780
		}
1781
		//TEMPORARY CODE
1782
//		Control [] controls = getExampleControls ();
1783
//		for (int i=0; i<controls.length; i++) {
1784
//			log ("Control=" + controls [i] + ", border width=" + controls [i].getBorderWidth ());
1785
//		}
1786
	}
1787
	
1788
	/**
1789
	 * Sets the visibility of the "Example" widgets.
1790
	 */
1791
	void setExampleWidgetVisibility () {
1792
		Control [] controls = getExampleControls ();
1793
		for (int i=0; i<controls.length; i++) {
1794
			controls [i].setVisible (visibleButton.getSelection ());
1795
		}
1796
	}
1797
1798
	/**
1799
	 * Sets the background image of the "Example" widgets.
1800
	 */
1801
	void setExampleWidgetBackgroundImage () {
1802
		if (backgroundImageButton != null && backgroundImageButton.isDisposed()) return;
1803
		Control [] controls = getExampleControls ();
1804
		for (int i=0; i<controls.length; i++) {
1805
			controls [i].setBackgroundImage (backgroundImageButton.getSelection () ? instance.images[ControlExample.ciBackground] : null);
1806
		}
1807
	}
1808
	
1809
	/**
1810
	 * Splits the given string around matches of the given character.
1811
	 * 
1812
	 * This subset of java.lang.String.split(String regex)
1813
	 * uses only code that can be run on CLDC platforms.
1814
	 */
1815
	String [] split (String string, char ch) {
1816
		String [] result = new String[0];
1817
		int start = 0;
1818
		int length = string.length();
1819
		while (start < length) {
1820
			int end = string.indexOf(ch, start);
1821
			if (end == -1) end = length;
1822
			String substr = string.substring(start, end);
1823
			String [] newResult = new String[result.length + 1];
1824
			System.arraycopy(result, 0, newResult, 0, result.length);
1825
			newResult [result.length] = substr;
1826
			result = newResult;
1827
			start = end + 1;
1828
		}
1829
		return result;
1830
	}
1831
}
(-)src/org/eclipse/swt/examples/mirroringTest/TabFolderTab.java (+166 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.layout.*;
16
import org.eclipse.swt.widgets.*;
17
18
class TabFolderTab extends Tab {
19
	/* Example widgets and groups that contain them */
20
	TabFolder tabFolder1;
21
	Group tabFolderGroup;
22
	
23
	/* Style widgets added to the "Style" group */
24
	Button topButton, bottomButton;
25
26
	static String [] TabItems1 = {ControlExample.getResourceString("TabItem1_0"),
27
								  ControlExample.getResourceString("TabItem1_1"),
28
								  ControlExample.getResourceString("TabItem1_2")};
29
30
	/**
31
	 * Creates the Tab within a given instance of ControlExample.
32
	 */
33
	TabFolderTab(ControlExample instance) {
34
		super(instance);
35
	}
36
	
37
	/**
38
	 * Creates the "Example" group.
39
	 */
40
	void createExampleGroup () {
41
		super.createExampleGroup ();
42
		
43
		/* Create a group for the TabFolder */
44
		tabFolderGroup = new Group (exampleGroup, SWT.NONE);
45
		tabFolderGroup.setLayout (new GridLayout ());
46
		tabFolderGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
47
		tabFolderGroup.setText ("TabFolder");
48
	}
49
	
50
	/**
51
	 * Creates the "Example" widgets.
52
	 */
53
	void createExampleWidgets () {
54
		
55
		/* Compute the widget style */
56
		int style = getDefaultStyle();
57
		if (topButton.getSelection ()) style |= SWT.TOP;
58
		if (bottomButton.getSelection ()) style |= SWT.BOTTOM;
59
		if (borderButton.getSelection ()) style |= SWT.BORDER;
60
61
		/* Create the example widgets */
62
		tabFolder1 = new TabFolder (tabFolderGroup, style);
63
		for (int i = 0; i < TabItems1.length; i++) {
64
			TabItem item = new TabItem(tabFolder1, SWT.NONE);
65
			item.setText(TabItems1[i]);
66
			item.setToolTipText(ControlExample.getResourceString("Tooltip", new String [] {TabItems1[i]}));
67
			Text content = new Text(tabFolder1, SWT.WRAP | SWT.MULTI);
68
			content.setText(ControlExample.getResourceString("TabItem_content") + ": " + i);
69
			item.setControl(content);
70
		}
71
	}
72
	
73
	/**
74
	 * Creates the "Style" group.
75
	 */
76
	void createStyleGroup() {
77
		super.createStyleGroup ();
78
		
79
		/* Create the extra widgets */
80
		topButton = new Button (styleGroup, SWT.RADIO);
81
		topButton.setText ("SWT.TOP");
82
		topButton.setSelection(true);
83
		bottomButton = new Button (styleGroup, SWT.RADIO);
84
		bottomButton.setText ("SWT.BOTTOM");
85
		borderButton = new Button (styleGroup, SWT.CHECK);
86
		borderButton.setText ("SWT.BORDER");
87
	}
88
	
89
	/**
90
	 * Gets the "Example" widget children's items, if any.
91
	 *
92
	 * @return an array containing the example widget children's items
93
	 */
94
	Item [] getExampleWidgetItems () {
95
		return tabFolder1.getItems();
96
	}
97
	
98
	/**
99
	 * Gets the "Example" widget children.
100
	 */
101
	Widget [] getExampleWidgets () {
102
		return new Widget [] {tabFolder1};
103
	}
104
	
105
	/**
106
	 * Returns a list of set/get API method names (without the set/get prefix)
107
	 * that can be used to set/get values in the example control(s).
108
	 */
109
	String[] getMethodNames() {
110
		return new String[] {"Selection", "SelectionIndex", "ToolTipText"};
111
	}
112
113
	String setMethodName(String methodRoot) {
114
		/* Override to handle special case of int getSelectionIndex()/setSelection(int) */
115
		return (methodRoot.equals("SelectionIndex")) ? "setSelection" : "set" + methodRoot;
116
	}
117
118
	Object[] parameterForType(String typeName, String value, Widget widget) {
119
		if (value.equals("")) return new Object[] {new TabItem[0]};
120
		if (typeName.equals("org.eclipse.swt.widgets.TabItem")) {
121
			TabItem item = findItem(value, ((TabFolder) widget).getItems());
122
			if (item != null) return new Object[] {item};
123
		}
124
		if (typeName.equals("[Lorg.eclipse.swt.widgets.TabItem;")) {
125
			String[] values = split(value, ',');
126
			TabItem[] items = new TabItem[values.length];
127
			for (int i = 0; i < values.length; i++) {
128
				items[i] = findItem(values[i], ((TabFolder) widget).getItems());
129
			}
130
			return new Object[] {items};
131
		}
132
		return super.parameterForType(typeName, value, widget);
133
	}
134
135
	TabItem findItem(String value, TabItem[] items) {
136
		for (int i = 0; i < items.length; i++) {
137
			TabItem item = items[i];
138
			if (item.getText().equals(value)) return item;
139
		}
140
		return null;
141
	}
142
143
	/**
144
	 * Gets the short text for the tab folder item.
145
	 */
146
	String getShortTabText() {
147
		return "TF";
148
	}
149
150
	/**
151
	 * Gets the text for the tab folder item.
152
	 */
153
	String getTabText () {
154
		return "TabFolder";
155
	}
156
157
	/**
158
	 * Sets the state of the "Example" widgets.
159
	 */
160
	void setExampleWidgetState () {
161
		super.setExampleWidgetState ();
162
		topButton.setSelection ((tabFolder1.getStyle () & SWT.TOP) != 0);
163
		bottomButton.setSelection ((tabFolder1.getStyle () & SWT.BOTTOM) != 0);
164
		borderButton.setSelection ((tabFolder1.getStyle () & SWT.BORDER) != 0);
165
	}
166
}
(-)src/org/eclipse/swt/examples/mirroringTest/TableTab.java (+685 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.layout.*;
18
import org.eclipse.swt.events.*;
19
20
class TableTab extends ScrollableTab {
21
	/* Example widgets and groups that contain them */
22
	Table table1;
23
	Group tableGroup;
24
25
	/* Size widgets added to the "Size" group */
26
	Button packColumnsButton;
27
	
28
	/* Style widgets added to the "Style" group */
29
	Button noScrollButton, checkButton, fullSelectionButton, hideSelectionButton;
30
31
	/* Other widgets added to the "Other" group */
32
	Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, linesVisibleButton, subImagesButton;
33
	
34
	/* Controls and resources added to the "Colors and Fonts" group */
35
	static final int ITEM_FOREGROUND_COLOR = 3;
36
	static final int ITEM_BACKGROUND_COLOR = 4;
37
	static final int ITEM_FONT = 5;
38
	static final int CELL_FOREGROUND_COLOR = 6;
39
	static final int CELL_BACKGROUND_COLOR = 7;
40
	static final int CELL_FONT = 8;
41
	Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor;
42
	Font itemFont, cellFont;
43
	
44
	static String [] columnTitles	= {ControlExample.getResourceString("TableTitle_0"),
45
									   ControlExample.getResourceString("TableTitle_1"),
46
									   ControlExample.getResourceString("TableTitle_2"),
47
									   ControlExample.getResourceString("TableTitle_3")};
48
									   
49
	static String[][] tableData = {
50
		{ ControlExample.getResourceString("TableLine0_0"),
51
				ControlExample.getResourceString("TableLine0_1"),
52
				ControlExample.getResourceString("TableLine0_2"),
53
				ControlExample.getResourceString("TableLine0_3") },
54
		{ ControlExample.getResourceString("TableLine1_0"),
55
				ControlExample.getResourceString("TableLine1_1"),
56
				ControlExample.getResourceString("TableLine1_2"),
57
				ControlExample.getResourceString("TableLine1_3") },
58
		{ ControlExample.getResourceString("TableLine2_0"),
59
				ControlExample.getResourceString("TableLine2_1"),
60
				ControlExample.getResourceString("TableLine2_2"),
61
				ControlExample.getResourceString("TableLine2_3") } };
62
63
	Point menuMouseCoords;
64
	
65
	/**
66
	 * Creates the Tab within a given instance of ControlExample.
67
	 */
68
	TableTab(ControlExample instance) {
69
		super(instance);
70
	}
71
	
72
	/**
73
	 * Creates the "Colors and Fonts" group.
74
	 */
75
	void createColorAndFontGroup () {
76
		super.createColorAndFontGroup();
77
		
78
		TableItem item = new TableItem(colorAndFontTable, SWT.None);
79
		item.setText(ControlExample.getResourceString ("Item_Foreground_Color"));
80
		item = new TableItem(colorAndFontTable, SWT.None);
81
		item.setText(ControlExample.getResourceString ("Item_Background_Color"));
82
		item = new TableItem(colorAndFontTable, SWT.None);
83
		item.setText(ControlExample.getResourceString ("Item_Font"));
84
		item = new TableItem(colorAndFontTable, SWT.None);
85
		item.setText(ControlExample.getResourceString ("Cell_Foreground_Color"));
86
		item = new TableItem(colorAndFontTable, SWT.None);
87
		item.setText(ControlExample.getResourceString ("Cell_Background_Color"));
88
		item = new TableItem(colorAndFontTable, SWT.None);
89
		item.setText(ControlExample.getResourceString ("Cell_Font"));
90
91
		shell.addDisposeListener(new DisposeListener() {
92
			public void widgetDisposed(DisposeEvent event) {
93
				if (itemBackgroundColor != null) itemBackgroundColor.dispose();
94
				if (itemForegroundColor != null) itemForegroundColor.dispose();
95
				if (itemFont != null) itemFont.dispose();
96
				if (cellBackgroundColor != null) cellBackgroundColor.dispose();
97
				if (cellForegroundColor != null) cellForegroundColor.dispose();
98
				if (cellFont != null) cellFont.dispose();
99
				itemBackgroundColor = null;
100
				itemForegroundColor = null;			
101
				itemFont = null;
102
				cellBackgroundColor = null;
103
				cellForegroundColor = null;			
104
				cellFont = null;
105
			}
106
		});
107
	}
108
109
	void changeFontOrColor(int index) {
110
		switch (index) {
111
		case ITEM_FOREGROUND_COLOR: {
112
			Color oldColor = itemForegroundColor;
113
			if (oldColor == null) oldColor = table1.getItem (0).getForeground ();
114
			colorDialog.setRGB(oldColor.getRGB());
115
			RGB rgb = colorDialog.open();
116
			if (rgb == null) return;
117
			oldColor = itemForegroundColor;
118
			itemForegroundColor = new Color (display, rgb);
119
			setItemForeground ();
120
			if (oldColor != null) oldColor.dispose ();
121
		}
122
		break;
123
		case ITEM_BACKGROUND_COLOR: {
124
			Color oldColor = itemBackgroundColor;
125
			if (oldColor == null) oldColor = table1.getItem (0).getBackground ();
126
			colorDialog.setRGB(oldColor.getRGB());
127
			RGB rgb = colorDialog.open();
128
			if (rgb == null) return;
129
			oldColor = itemBackgroundColor;
130
			itemBackgroundColor = new Color (display, rgb);
131
			setItemBackground ();
132
			if (oldColor != null) oldColor.dispose ();
133
		}
134
		break;
135
		case ITEM_FONT: {
136
			Font oldFont = itemFont;
137
			if (oldFont == null) oldFont = table1.getItem (0).getFont ();
138
			fontDialog.setFontList(oldFont.getFontData());
139
			FontData fontData = fontDialog.open ();
140
			if (fontData == null) return;
141
			oldFont = itemFont;
142
			itemFont = new Font (display, fontData);
143
			setItemFont ();
144
			setExampleWidgetSize ();
145
			if (oldFont != null) oldFont.dispose ();
146
		}
147
		break;
148
		case CELL_FOREGROUND_COLOR: {
149
			Color oldColor = cellForegroundColor;
150
			if (oldColor == null) oldColor = table1.getItem (0).getForeground (1);
151
			colorDialog.setRGB(oldColor.getRGB());
152
			RGB rgb = colorDialog.open();
153
			if (rgb == null) return;
154
			oldColor = cellForegroundColor;
155
			cellForegroundColor = new Color (display, rgb);
156
			setCellForeground ();
157
			if (oldColor != null) oldColor.dispose ();
158
		}
159
		break;
160
		case CELL_BACKGROUND_COLOR: {
161
			Color oldColor = cellBackgroundColor;
162
			if (oldColor == null) oldColor = table1.getItem (0).getBackground (1);
163
			colorDialog.setRGB(oldColor.getRGB());
164
			RGB rgb = colorDialog.open();
165
			if (rgb == null) return;
166
			oldColor = cellBackgroundColor;
167
			cellBackgroundColor = new Color (display, rgb);
168
			setCellBackground ();
169
			if (oldColor != null) oldColor.dispose ();
170
		}
171
		break;
172
		case CELL_FONT: {
173
			Font oldFont = cellFont;
174
			if (oldFont == null) oldFont = table1.getItem (0).getFont (1);
175
			fontDialog.setFontList(oldFont.getFontData());
176
			FontData fontData = fontDialog.open ();
177
			if (fontData == null) return;
178
			oldFont = cellFont;
179
			cellFont = new Font (display, fontData);
180
			setCellFont ();
181
			setExampleWidgetSize ();
182
			if (oldFont != null) oldFont.dispose ();
183
		}
184
		break;
185
		default:
186
			super.changeFontOrColor(index);
187
	}
188
	}
189
190
	/**
191
	 * Creates the "Other" group.
192
	 */
193
	void createOtherGroup () {
194
		super.createOtherGroup ();
195
	
196
		/* Create display controls specific to this example */
197
		linesVisibleButton = new Button (otherGroup, SWT.CHECK);
198
		linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible"));
199
		multipleColumns = new Button (otherGroup, SWT.CHECK);
200
		multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns"));
201
		multipleColumns.setSelection(true);
202
		headerVisibleButton = new Button (otherGroup, SWT.CHECK);
203
		headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible"));
204
		sortIndicatorButton = new Button (otherGroup, SWT.CHECK);
205
		sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator"));
206
		moveableColumns = new Button (otherGroup, SWT.CHECK);
207
		moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns"));
208
		resizableColumns = new Button (otherGroup, SWT.CHECK);
209
		resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns"));
210
		headerImagesButton = new Button (otherGroup, SWT.CHECK);
211
		headerImagesButton.setText (ControlExample.getResourceString("Header_Images"));
212
		subImagesButton = new Button (otherGroup, SWT.CHECK);
213
		subImagesButton.setText (ControlExample.getResourceString("Sub_Images"));
214
215
		/* Add the listeners */
216
		linesVisibleButton.addSelectionListener (new SelectionAdapter () {
217
			public void widgetSelected (SelectionEvent event) {
218
				setWidgetLinesVisible ();
219
			}
220
		});
221
		multipleColumns.addSelectionListener (new SelectionAdapter () {
222
			public void widgetSelected (SelectionEvent event) {
223
				recreateExampleWidgets ();
224
			}
225
		});
226
		headerVisibleButton.addSelectionListener (new SelectionAdapter () {
227
			public void widgetSelected (SelectionEvent event) {
228
				setWidgetHeaderVisible ();
229
			}
230
		});
231
		sortIndicatorButton.addSelectionListener (new SelectionAdapter () {
232
			public void widgetSelected (SelectionEvent event) {
233
				setWidgetSortIndicator ();
234
			}
235
		});
236
		moveableColumns.addSelectionListener (new SelectionAdapter () {
237
			public void widgetSelected (SelectionEvent event) {
238
				setColumnsMoveable ();
239
			}
240
		});
241
		resizableColumns.addSelectionListener (new SelectionAdapter () {
242
			public void widgetSelected (SelectionEvent event) {
243
				setColumnsResizable ();
244
			}
245
		});
246
		headerImagesButton.addSelectionListener (new SelectionAdapter () {
247
			public void widgetSelected (SelectionEvent event) {
248
				recreateExampleWidgets ();
249
			}
250
		});
251
		subImagesButton.addSelectionListener (new SelectionAdapter () {
252
			public void widgetSelected (SelectionEvent event) {
253
				recreateExampleWidgets ();
254
			}
255
		});
256
	}
257
	
258
	/**
259
	 * Creates the "Example" group.
260
	 */
261
	void createExampleGroup () {
262
		super.createExampleGroup ();
263
		
264
		/* Create a group for the table */
265
		tableGroup = new Group (exampleGroup, SWT.NONE);
266
		tableGroup.setLayout (new GridLayout ());
267
		tableGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
268
		tableGroup.setText ("Table");
269
	}
270
	
271
	/**
272
	 * Creates the "Example" widgets.
273
	 */
274
	void createExampleWidgets () {	
275
		/* Compute the widget style */
276
		int style = getDefaultStyle();
277
		if (singleButton.getSelection ()) style |= SWT.SINGLE;
278
		if (multiButton.getSelection ()) style |= SWT.MULTI;
279
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
280
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
281
		if (noScrollButton.getSelection ()) style |= SWT.NO_SCROLL;
282
		if (checkButton.getSelection ()) style |= SWT.CHECK;
283
		if (fullSelectionButton.getSelection ()) style |= SWT.FULL_SELECTION;
284
		if (hideSelectionButton.getSelection ()) style |= SWT.HIDE_SELECTION;
285
		if (borderButton.getSelection ()) style |= SWT.BORDER;
286
	
287
		/* Create the table widget */
288
		table1 = new Table (tableGroup, style);
289
	
290
		/* Fill the table with data */
291
		boolean multiColumn = multipleColumns.getSelection();
292
		if (multiColumn) {
293
			for (int i = 0; i < columnTitles.length; i++) {
294
				TableColumn tableColumn = new TableColumn(table1, SWT.NONE);
295
				tableColumn.setText(columnTitles[i]);
296
				tableColumn.setToolTipText(ControlExample.getResourceString("Tooltip", new String [] {columnTitles[i]}));
297
				if (headerImagesButton.getSelection()) tableColumn.setImage(instance.images [i % 3]);
298
			}
299
			table1.setSortColumn(table1.getColumn(0));
300
		}
301
		for (int i=0; i<16; i++) {
302
			TableItem item = new TableItem (table1, SWT.NONE);
303
			if (multiColumn && subImagesButton.getSelection()) {
304
				for (int j = 0; j < columnTitles.length; j++) {
305
					item.setImage(j, instance.images [i % 3]);
306
				}
307
			} else {
308
				item.setImage(instance.images [i % 3]);
309
			}
310
			setItemText (item, i, ControlExample.getResourceString("Index") + i);
311
		}
312
		packColumns();
313
	}
314
	
315
	void setItemText(TableItem item, int i, String node) {
316
		int index = i % 3;
317
		if (multipleColumns.getSelection()) {
318
			tableData [index][0] = node;
319
			item.setText (tableData [index]);
320
		} else {
321
			item.setText (node);
322
		}
323
	}
324
	
325
	/**
326
	 * Creates the "Size" group.  The "Size" group contains
327
	 * controls that allow the user to change the size of
328
	 * the example widgets.
329
	 */
330
	void createSizeGroup () {
331
		super.createSizeGroup();
332
	
333
		packColumnsButton = new Button (sizeGroup, SWT.PUSH);
334
		packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns"));
335
		packColumnsButton.addSelectionListener(new SelectionAdapter () {
336
			public void widgetSelected (SelectionEvent event) {
337
				packColumns ();
338
				setExampleWidgetSize ();
339
			}
340
		});
341
	}
342
	
343
	/**
344
	 * Creates the "Style" group.
345
	 */
346
	void createStyleGroup () {
347
		super.createStyleGroup ();
348
		
349
		/* Create the extra widgets */
350
		noScrollButton = new Button (styleGroup, SWT.CHECK);
351
		noScrollButton.setText ("SWT.NO_SCROLL");
352
		noScrollButton.moveAbove(borderButton);
353
		checkButton = new Button (styleGroup, SWT.CHECK);
354
		checkButton.setText ("SWT.CHECK");
355
		fullSelectionButton = new Button (styleGroup, SWT.CHECK);
356
		fullSelectionButton.setText ("SWT.FULL_SELECTION");
357
		hideSelectionButton = new Button (styleGroup, SWT.CHECK);
358
		hideSelectionButton.setText ("SWT.HIDE_SELECTION");
359
	}
360
	
361
	/**
362
	 * Gets the "Example" widget children's items, if any.
363
	 *
364
	 * @return an array containing the example widget children's items
365
	 */
366
	Item [] getExampleWidgetItems () {
367
		Item [] columns = table1.getColumns();
368
		Item [] items = table1.getItems();
369
		Item [] allItems = new Item [columns.length + items.length];
370
		System.arraycopy(columns, 0, allItems, 0, columns.length);
371
		System.arraycopy(items, 0, allItems, columns.length, items.length);
372
		return allItems;
373
	}
374
	
375
	/**
376
	 * Gets the "Example" widget children.
377
	 */
378
	Widget [] getExampleWidgets () {
379
		return new Widget [] {table1};
380
	}
381
	
382
	/**
383
	 * Returns a list of set/get API method names (without the set/get prefix)
384
	 * that can be used to set/get values in the example control(s).
385
	 */
386
	String[] getMethodNames() {
387
		return new String[] {"ColumnOrder", "ItemCount", "Selection", "SelectionIndex", "ToolTipText", "TopIndex"};
388
	}
389
390
	String setMethodName(String methodRoot) {
391
		/* Override to handle special case of int getSelectionIndex()/setSelection(int) */
392
		return (methodRoot.equals("SelectionIndex")) ? "setSelection" : "set" + methodRoot;
393
	}
394
395
	void packColumns () {
396
		int columnCount = table1.getColumnCount(); 
397
		for (int i = 0; i < columnCount; i++) {
398
			TableColumn tableColumn = table1.getColumn(i);
399
			tableColumn.pack();
400
		}
401
	}
402
403
	Object[] parameterForType(String typeName, String value, Widget widget) {
404
		if (value.equals("")) return new Object[] {new TableItem[0]}; // bug in Table?
405
		if (typeName.equals("org.eclipse.swt.widgets.TableItem")) {
406
			TableItem item = findItem(value, ((Table) widget).getItems());
407
			if (item != null) return new Object[] {item};
408
		}
409
		if (typeName.equals("[Lorg.eclipse.swt.widgets.TableItem;")) {
410
			String[] values = split(value, ',');
411
			TableItem[] items = new TableItem[values.length];
412
			for (int i = 0; i < values.length; i++) {
413
				items[i] = findItem(values[i], ((Table) widget).getItems());
414
			}
415
			return new Object[] {items};
416
		}
417
		return super.parameterForType(typeName, value, widget);
418
	}
419
420
	TableItem findItem(String value, TableItem[] items) {
421
		for (int i = 0; i < items.length; i++) {
422
			TableItem item = items[i];
423
			if (item.getText().equals(value)) return item;
424
		}
425
		return null;
426
	}
427
428
	/**
429
	 * Gets the text for the tab folder item.
430
	 */
431
	String getTabText () {
432
		return "Table";
433
	}
434
	
435
	/**
436
	 * Sets the foreground color, background color, and font
437
	 * of the "Example" widgets to their default settings.
438
	 * Also sets foreground and background color of TableItem [0]
439
	 * to default settings.
440
	 */
441
	void resetColorsAndFonts () {
442
		super.resetColorsAndFonts ();
443
		Color oldColor = itemForegroundColor;
444
		itemForegroundColor = null;
445
		setItemForeground ();
446
		if (oldColor != null) oldColor.dispose();
447
		oldColor = itemBackgroundColor;
448
		itemBackgroundColor = null;
449
		setItemBackground ();
450
		if (oldColor != null) oldColor.dispose();
451
		Font oldFont = font;
452
		itemFont = null;
453
		setItemFont ();
454
		if (oldFont != null) oldFont.dispose();
455
		oldColor = cellForegroundColor;
456
		cellForegroundColor = null;
457
		setCellForeground ();
458
		if (oldColor != null) oldColor.dispose();
459
		oldColor = cellBackgroundColor;
460
		cellBackgroundColor = null;
461
		setCellBackground ();
462
		if (oldColor != null) oldColor.dispose();
463
		oldFont = font;
464
		cellFont = null;
465
		setCellFont ();
466
		if (oldFont != null) oldFont.dispose();
467
	}
468
	
469
	/**
470
	 * Sets the background color of the Row 0 TableItem in column 1.
471
	 */
472
	void setCellBackground () {
473
		if (!instance.startup) {
474
			table1.getItem (0).setBackground (1, cellBackgroundColor);
475
		}
476
		/* Set the background color item's image to match the background color of the cell. */
477
		Color color = cellBackgroundColor;
478
		if (color == null) color = table1.getItem (0).getBackground (1);
479
		TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR);
480
		Image oldImage = item.getImage();
481
		if (oldImage != null) oldImage.dispose();
482
		item.setImage (colorImage(color));
483
	}
484
	
485
	/**
486
	 * Sets the foreground color of the Row 0 TableItem in column 1.
487
	 */
488
	void setCellForeground () {
489
		if (!instance.startup) {
490
			table1.getItem (0).setForeground (1, cellForegroundColor);
491
		}
492
		/* Set the foreground color item's image to match the foreground color of the cell. */
493
		Color color = cellForegroundColor;
494
		if (color == null) color = table1.getItem (0).getForeground (1);
495
		TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR);
496
		Image oldImage = item.getImage();
497
		if (oldImage != null) oldImage.dispose();
498
		item.setImage (colorImage(color));
499
	}
500
	
501
	/**
502
	 * Sets the font of the Row 0 TableItem in column 1.
503
	 */
504
	void setCellFont () {
505
		if (!instance.startup) {
506
			table1.getItem (0).setFont (1, cellFont);
507
		}
508
		/* Set the font item's image to match the font of the item. */
509
		Font ft = cellFont;
510
		if (ft == null) ft = table1.getItem (0).getFont (1);
511
		TableItem item = colorAndFontTable.getItem(CELL_FONT);
512
		Image oldImage = item.getImage();
513
		if (oldImage != null) oldImage.dispose();
514
		item.setImage (fontImage(ft));
515
		item.setFont(ft);
516
		colorAndFontTable.layout ();
517
	}
518
519
	/**
520
	 * Sets the background color of TableItem [0].
521
	 */
522
	void setItemBackground () {
523
		if (!instance.startup) {
524
			table1.getItem (0).setBackground (itemBackgroundColor);
525
		}
526
		/* Set the background color item's image to match the background color of the item. */
527
		Color color = itemBackgroundColor;
528
		if (color == null) color = table1.getItem (0).getBackground ();
529
		TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR);
530
		Image oldImage = item.getImage();
531
		if (oldImage != null) oldImage.dispose();
532
		item.setImage (colorImage(color));
533
	}
534
	
535
	/**
536
	 * Sets the foreground color of TableItem [0].
537
	 */
538
	void setItemForeground () {
539
		if (!instance.startup) {
540
			table1.getItem (0).setForeground (itemForegroundColor);
541
		}
542
		/* Set the foreground color item's image to match the foreground color of the item. */
543
		Color color = itemForegroundColor;
544
		if (color == null) color = table1.getItem (0).getForeground ();
545
		TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR);
546
		Image oldImage = item.getImage();
547
		if (oldImage != null) oldImage.dispose();
548
		item.setImage (colorImage(color));
549
	}
550
	
551
	/**
552
	 * Sets the font of TableItem 0.
553
	 */
554
	void setItemFont () {
555
		if (!instance.startup) {
556
			table1.getItem (0).setFont (itemFont);
557
		}
558
		/* Set the font item's image to match the font of the item. */
559
		Font ft = itemFont;
560
		if (ft == null) ft = table1.getItem (0).getFont ();
561
		TableItem item = colorAndFontTable.getItem(ITEM_FONT);
562
		Image oldImage = item.getImage();
563
		if (oldImage != null) oldImage.dispose();
564
		item.setImage (fontImage(ft));
565
		item.setFont(ft);
566
		colorAndFontTable.layout ();
567
	}
568
569
	/**
570
	 * Sets the moveable columns state of the "Example" widgets.
571
	 */
572
	void setColumnsMoveable () {
573
		boolean selection = moveableColumns.getSelection();
574
		TableColumn[] columns = table1.getColumns();
575
		for (int i = 0; i < columns.length; i++) {
576
			columns[i].setMoveable(selection);
577
		}
578
	}
579
580
	/**
581
	 * Sets the resizable columns state of the "Example" widgets.
582
	 */
583
	void setColumnsResizable () {
584
		boolean selection = resizableColumns.getSelection();
585
		TableColumn[] columns = table1.getColumns();
586
		for (int i = 0; i < columns.length; i++) {
587
			columns[i].setResizable(selection);
588
		}
589
	}
590
591
	/**
592
	 * Sets the state of the "Example" widgets.
593
	 */
594
	void setExampleWidgetState () {
595
		setItemBackground ();
596
		setItemForeground ();
597
		setItemFont ();
598
		setCellBackground ();
599
		setCellForeground ();
600
		setCellFont ();
601
		if (!instance.startup) {
602
			setColumnsMoveable ();
603
			setColumnsResizable ();
604
			setWidgetHeaderVisible ();
605
			setWidgetSortIndicator ();
606
			setWidgetLinesVisible ();
607
		}
608
		super.setExampleWidgetState ();
609
		noScrollButton.setSelection ((table1.getStyle () & SWT.NO_SCROLL) != 0);
610
		checkButton.setSelection ((table1.getStyle () & SWT.CHECK) != 0);
611
		fullSelectionButton.setSelection ((table1.getStyle () & SWT.FULL_SELECTION) != 0);
612
		hideSelectionButton.setSelection ((table1.getStyle () & SWT.HIDE_SELECTION) != 0);
613
		try {
614
			TableColumn column = table1.getColumn(0);
615
			moveableColumns.setSelection (column.getMoveable());
616
			resizableColumns.setSelection (column.getResizable());
617
		} catch (IllegalArgumentException ex) {}
618
		headerVisibleButton.setSelection (table1.getHeaderVisible());
619
		linesVisibleButton.setSelection (table1.getLinesVisible());
620
	}
621
	
622
	/**
623
	 * Sets the header visible state of the "Example" widgets.
624
	 */
625
	void setWidgetHeaderVisible () {
626
		table1.setHeaderVisible (headerVisibleButton.getSelection ());
627
	}
628
	
629
	/**
630
	 * Sets the sort indicator state of the "Example" widgets.
631
	 */
632
	void setWidgetSortIndicator () {
633
		TableColumn [] columns = table1.getColumns();
634
		if (sortIndicatorButton.getSelection ()) {
635
			/* Reset to known state: 'down' on column 0. */
636
			table1.setSortDirection (SWT.DOWN);
637
			for (int i = 0; i < columns.length; i++) {
638
				TableColumn column = columns[i];
639
				if (i == 0) table1.setSortColumn(column);
640
				SelectionListener listener = new SelectionAdapter() {
641
					public void widgetSelected(SelectionEvent e) {
642
						int sortDirection = SWT.DOWN;
643
						if (e.widget == table1.getSortColumn()) {
644
							/* If the sort column hasn't changed, cycle down -> up -> none. */
645
							switch (table1.getSortDirection ()) {
646
							case SWT.DOWN: sortDirection = SWT.UP; break;
647
							case SWT.UP: sortDirection = SWT.NONE; break;
648
							}
649
						} else {
650
							table1.setSortColumn((TableColumn)e.widget);
651
						}
652
						table1.setSortDirection (sortDirection);
653
					}
654
				};
655
				column.addSelectionListener(listener);
656
				column.setData("SortListener", listener);	//$NON-NLS-1$
657
			}
658
		} else {
659
			table1.setSortDirection (SWT.NONE);
660
			for (int j = 0; j < columns.length; j++) {
661
				SelectionListener listener = (SelectionListener)columns[j].getData("SortListener");	//$NON-NLS-1$
662
				if (listener != null) columns[j].removeSelectionListener(listener);
663
			}
664
		}
665
	}
666
	
667
	/**
668
	 * Sets the lines visible state of the "Example" widgets.
669
	 */
670
	void setWidgetLinesVisible () {
671
		table1.setLinesVisible (linesVisibleButton.getSelection ());
672
	}
673
	
674
	protected void specialPopupMenuItems(Menu menu, Event event) {
675
    	MenuItem item = new MenuItem(menu, SWT.PUSH);
676
    	item.setText("getItem(Point) on mouse coordinates");
677
    	menuMouseCoords = table1.toControl(new Point(event.x, event.y));
678
    	item.addSelectionListener(new SelectionAdapter() {
679
    		public void widgetSelected(SelectionEvent e) {
680
    			eventConsole.append ("getItem(Point(" + menuMouseCoords + ")) returned: " + table1.getItem(menuMouseCoords));
681
    			eventConsole.append ("\n");
682
    		}
683
    	});
684
	}
685
}
(-)src/org/eclipse/swt/examples/mirroringTest/TextTab.java (+190 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.events.*;
17
import org.eclipse.swt.layout.*;
18
19
class TextTab extends ScrollableTab {
20
	/* Example widgets and groups that contain them */
21
	Text text;
22
	Group textGroup;
23
24
	/* Style widgets added to the "Style" group */
25
	Button wrapButton, readOnlyButton, passwordButton, searchButton, iconCancelButton, iconSearchButton;
26
	Button leftButton, centerButton, rightButton;
27
	
28
	/**
29
	 * Creates the Tab within a given instance of ControlExample.
30
	 */
31
	TextTab(ControlExample instance) {
32
		super(instance);
33
	}
34
35
	/**
36
	 * Creates the "Example" group.
37
	 */
38
	void createExampleGroup () {
39
		super.createExampleGroup ();
40
		
41
		/* Create a group for the text widget */
42
		textGroup = new Group (exampleGroup, SWT.NONE);
43
		textGroup.setLayout (new GridLayout ());
44
		textGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
45
		textGroup.setText ("Text");
46
	}
47
	
48
	/**
49
	 * Creates the "Example" widgets.
50
	 */
51
	void createExampleWidgets () {
52
		
53
		/* Compute the widget style */
54
		int style = getDefaultStyle();
55
		if (singleButton.getSelection ()) style |= SWT.SINGLE;
56
		if (multiButton.getSelection ()) style |= SWT.MULTI;
57
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
58
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
59
		if (wrapButton.getSelection ()) style |= SWT.WRAP;
60
		if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
61
		if (passwordButton.getSelection ()) style |= SWT.PASSWORD;
62
		if (searchButton.getSelection ()) style |= SWT.SEARCH;
63
		if (iconCancelButton.getSelection ()) style |= SWT.ICON_CANCEL;
64
		if (iconSearchButton.getSelection ()) style |= SWT.ICON_SEARCH;
65
		if (borderButton.getSelection ()) style |= SWT.BORDER;
66
		if (leftButton.getSelection ()) style |= SWT.LEFT;
67
		if (centerButton.getSelection ()) style |= SWT.CENTER;
68
		if (rightButton.getSelection ()) style |= SWT.RIGHT;
69
	
70
		/* Create the example widgets */
71
		text = new Text (textGroup, style);
72
		text.setText (ControlExample.getResourceString("Example_string") + Text.DELIMITER + ControlExample.getResourceString("One_Two_Three"));
73
	}
74
	
75
	/**
76
	 * Creates the "Style" group.
77
	 */
78
	void createStyleGroup() {
79
		super.createStyleGroup();
80
	
81
		/* Create the extra widgets */
82
		wrapButton = new Button (styleGroup, SWT.CHECK);
83
		wrapButton.setText ("SWT.WRAP");
84
		readOnlyButton = new Button (styleGroup, SWT.CHECK);
85
		readOnlyButton.setText ("SWT.READ_ONLY");
86
		passwordButton = new Button (styleGroup, SWT.CHECK);
87
		passwordButton.setText ("SWT.PASSWORD");
88
		searchButton = new Button (styleGroup, SWT.CHECK);
89
		searchButton.setText ("SWT.SEARCH");
90
		iconCancelButton = new Button (styleGroup, SWT.CHECK);
91
		iconCancelButton.setText ("SWT.ICON_CANCEL");
92
		iconSearchButton = new Button (styleGroup, SWT.CHECK);
93
		iconSearchButton.setText ("SWT.ICON_SEARCH");
94
95
		Composite alignmentGroup = new Composite (styleGroup, SWT.NONE);
96
		GridLayout layout = new GridLayout ();
97
		layout.marginWidth = layout.marginHeight = 0;
98
		alignmentGroup.setLayout (layout);
99
		alignmentGroup.setLayoutData (new GridData (GridData.FILL_BOTH));
100
		leftButton = new Button (alignmentGroup, SWT.RADIO);
101
		leftButton.setText ("SWT.LEFT");
102
		centerButton = new Button (alignmentGroup, SWT.RADIO);
103
		centerButton.setText ("SWT.CENTER");
104
		rightButton = new Button (alignmentGroup, SWT.RADIO);
105
		rightButton.setText ("SWT.RIGHT");
106
	}
107
108
	/**
109
	 * Creates the tab folder page.
110
	 *
111
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
112
	 * @return the new page for the tab folder
113
	 */
114
	Composite createTabFolderPage (TabFolder tabFolder) {
115
		super.createTabFolderPage (tabFolder);
116
117
		/*
118
		 * Add a resize listener to the tabFolderPage so that
119
		 * if the user types into the example widget to change
120
		 * its preferred size, and then resizes the shell, we
121
		 * recalculate the preferred size correctly.
122
		 */
123
		tabFolderPage.addControlListener(new ControlAdapter() {
124
			public void controlResized(ControlEvent e) {
125
				setExampleWidgetSize ();
126
			}
127
		});
128
		
129
		return tabFolderPage;
130
	}
131
132
	/**
133
	 * Gets the "Example" widget children.
134
	 */
135
	Widget [] getExampleWidgets () {
136
		return new Widget [] {text};
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
	String[] getMethodNames() {
144
		return new String[] {"DoubleClickEnabled", "EchoChar", "Editable", "Message", "Orientation", "Selection", "Tabs", "Text", "TextLimit", "ToolTipText", "TopIndex"};
145
	}
146
147
	/**
148
	 * Gets the text for the tab folder item.
149
	 */
150
	String getTabText () {
151
		return "Text";
152
	}
153
	
154
	/**
155
	 * Sets the state of the "Example" widgets.
156
	 */
157
	void setExampleWidgetState () {
158
		super.setExampleWidgetState ();
159
		wrapButton.setSelection ((text.getStyle () & SWT.WRAP) != 0);
160
		readOnlyButton.setSelection ((text.getStyle () & SWT.READ_ONLY) != 0);
161
		passwordButton.setSelection ((text.getStyle () & SWT.PASSWORD) != 0);
162
		searchButton.setSelection ((text.getStyle () & SWT.SEARCH) != 0);
163
		leftButton.setSelection ((text.getStyle () & SWT.LEFT) != 0);
164
		centerButton.setSelection ((text.getStyle () & SWT.CENTER) != 0);
165
		rightButton.setSelection ((text.getStyle () & SWT.RIGHT) != 0);
166
		
167
		/* Special case: ICON_CANCEL and H_SCROLL have the same value,
168
		 * and ICON_SEARCH and V_SCROLL have the same value,
169
		 * so to avoid confusion, only set CANCEL if SEARCH is set. */
170
		if ((text.getStyle () & SWT.SEARCH) != 0) {
171
			iconCancelButton.setSelection ((text.getStyle () & SWT.ICON_CANCEL) != 0);
172
			iconSearchButton.setSelection ((text.getStyle () & SWT.ICON_SEARCH) != 0);
173
			horizontalButton.setSelection (false);
174
			verticalButton.setSelection (false);
175
		} else {
176
			iconCancelButton.setSelection (false);
177
			iconSearchButton.setSelection (false);
178
			horizontalButton.setSelection ((text.getStyle () & SWT.H_SCROLL) != 0);
179
			verticalButton.setSelection ((text.getStyle () & SWT.V_SCROLL) != 0);
180
		}
181
182
		passwordButton.setEnabled ((text.getStyle () & SWT.SINGLE) != 0);
183
		searchButton.setEnabled ((text.getStyle () & SWT.SINGLE) != 0);
184
		iconCancelButton.setEnabled ((text.getStyle () & SWT.SEARCH) != 0);
185
		iconSearchButton.setEnabled ((text.getStyle () & SWT.SEARCH) != 0);
186
		wrapButton.setEnabled ((text.getStyle () & SWT.MULTI) != 0);
187
		horizontalButton.setEnabled ((text.getStyle () & SWT.MULTI) != 0);
188
		verticalButton.setEnabled ((text.getStyle () & SWT.MULTI) != 0);
189
	}
190
}
(-)src/org/eclipse/swt/examples/mirroringTest/ToolBarTab.java (+364 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.layout.*;
18
import org.eclipse.swt.events.*;
19
20
class ToolBarTab extends Tab {
21
	/* Example widgets and groups that contain them */
22
	ToolBar imageToolBar, textToolBar, imageTextToolBar;
23
	Group imageToolBarGroup, textToolBarGroup, imageTextToolBarGroup;
24
	
25
	/* Style widgets added to the "Style" group */
26
	Button horizontalButton, verticalButton, flatButton, shadowOutButton, wrapButton, rightButton;
27
28
	/* Other widgets added to the "Other" group */
29
	Button comboChildButton;
30
	
31
	/**
32
	 * Creates the Tab within a given instance of ControlExample.
33
	 */
34
	ToolBarTab(ControlExample instance) {
35
		super(instance);
36
	}
37
38
	/**
39
	 * Creates the "Example" group.
40
	 */
41
	void createExampleGroup () {
42
		super.createExampleGroup ();
43
		
44
		/* Create a group for the image tool bar */
45
		imageToolBarGroup = new Group (exampleGroup, SWT.NONE);
46
		imageToolBarGroup.setLayout (new GridLayout ());
47
		imageToolBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
48
		imageToolBarGroup.setText (ControlExample.getResourceString("Image_ToolBar"));
49
	
50
		/* Create a group for the text tool bar */
51
		textToolBarGroup = new Group (exampleGroup, SWT.NONE);
52
		textToolBarGroup.setLayout (new GridLayout ());
53
		textToolBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
54
		textToolBarGroup.setText (ControlExample.getResourceString("Text_ToolBar"));
55
		
56
		/* Create a group for the image and text tool bar */
57
		imageTextToolBarGroup = new Group (exampleGroup, SWT.NONE);
58
		imageTextToolBarGroup.setLayout (new GridLayout ());
59
		imageTextToolBarGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
60
		imageTextToolBarGroup.setText (ControlExample.getResourceString("ImageText_ToolBar"));
61
	}
62
	
63
	/**
64
	 * Creates the "Example" widgets.
65
	 */
66
	void createExampleWidgets () {
67
	
68
		/* Compute the widget style */
69
		int style = getDefaultStyle();
70
		if (horizontalButton.getSelection()) style |= SWT.HORIZONTAL;
71
		if (verticalButton.getSelection()) style |= SWT.VERTICAL;
72
		if (flatButton.getSelection()) style |= SWT.FLAT;
73
		if (wrapButton.getSelection()) style |= SWT.WRAP;
74
		if (borderButton.getSelection()) style |= SWT.BORDER;
75
		if (shadowOutButton.getSelection()) style |= SWT.SHADOW_OUT;
76
		if (rightButton.getSelection()) style |= SWT.RIGHT;
77
	
78
		/*
79
		* Create the example widgets.
80
		*
81
		* A tool bar must consist of all image tool
82
		* items or all text tool items but not both.
83
		*/
84
	
85
		/* Create the image tool bar */
86
		imageToolBar = new ToolBar (imageToolBarGroup, style);
87
		ToolItem item = new ToolItem (imageToolBar, SWT.PUSH);
88
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
89
		item.setToolTipText("SWT.PUSH");
90
		item = new ToolItem (imageToolBar, SWT.PUSH);
91
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
92
		item.setToolTipText ("SWT.PUSH");
93
		item = new ToolItem (imageToolBar, SWT.RADIO);
94
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
95
		item.setToolTipText ("SWT.RADIO");
96
		item = new ToolItem (imageToolBar, SWT.RADIO);
97
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
98
		item.setToolTipText ("SWT.RADIO");
99
		item = new ToolItem (imageToolBar, SWT.CHECK);
100
		item.setImage (instance.images[ControlExample.ciTarget]);
101
		item.setToolTipText ("SWT.CHECK");
102
		item = new ToolItem (imageToolBar, SWT.RADIO);
103
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
104
		item.setToolTipText ("SWT.RADIO");
105
		item = new ToolItem (imageToolBar, SWT.RADIO);
106
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
107
		item.setToolTipText ("SWT.RADIO");
108
		item = new ToolItem (imageToolBar, SWT.SEPARATOR);
109
		item.setToolTipText("SWT.SEPARATOR");
110
		if (comboChildButton.getSelection ()) {
111
			Combo combo = new Combo (imageToolBar, SWT.NONE);
112
			combo.setItems (new String [] {"250", "500", "750"});
113
			combo.setText (combo.getItem (0));
114
			combo.pack ();
115
			item.setWidth (combo.getSize ().x);
116
			item.setControl (combo);
117
		}
118
		item = new ToolItem (imageToolBar, SWT.DROP_DOWN);
119
		item.setImage (instance.images[ControlExample.ciTarget]);
120
		item.setToolTipText ("SWT.DROP_DOWN");
121
		item.addSelectionListener(new DropDownSelectionListener());
122
	
123
		/* Create the text tool bar */
124
		textToolBar = new ToolBar (textToolBarGroup, style);
125
		item = new ToolItem (textToolBar, SWT.PUSH);
126
		item.setText (ControlExample.getResourceString("Push"));
127
		item.setToolTipText("SWT.PUSH");
128
		item = new ToolItem (textToolBar, SWT.PUSH);
129
		item.setText (ControlExample.getResourceString("Push"));
130
		item.setToolTipText("SWT.PUSH");
131
		item = new ToolItem (textToolBar, SWT.RADIO);
132
		item.setText (ControlExample.getResourceString("Radio"));
133
		item.setToolTipText("SWT.RADIO");
134
		item = new ToolItem (textToolBar, SWT.RADIO);
135
		item.setText (ControlExample.getResourceString("Radio"));
136
		item.setToolTipText("SWT.RADIO");
137
		item = new ToolItem (textToolBar, SWT.CHECK);
138
		item.setText (ControlExample.getResourceString("Check"));
139
		item.setToolTipText("SWT.CHECK");
140
		item = new ToolItem (textToolBar, SWT.RADIO);
141
		item.setText (ControlExample.getResourceString("Radio"));
142
		item.setToolTipText("SWT.RADIO");
143
		item = new ToolItem (textToolBar, SWT.RADIO);
144
		item.setText (ControlExample.getResourceString("Radio"));
145
		item.setToolTipText("SWT.RADIO");
146
		item = new ToolItem (textToolBar, SWT.SEPARATOR);
147
		item.setToolTipText("SWT.SEPARATOR");
148
		if (comboChildButton.getSelection ()) {
149
			Combo combo = new Combo (textToolBar, SWT.NONE);
150
			combo.setItems (new String [] {"250", "500", "750"});
151
			combo.setText (combo.getItem (0));
152
			combo.pack ();
153
			item.setWidth (combo.getSize ().x);
154
			item.setControl (combo);
155
		}
156
		item = new ToolItem (textToolBar, SWT.DROP_DOWN);
157
		item.setText (ControlExample.getResourceString("Drop_Down"));
158
		item.setToolTipText("SWT.DROP_DOWN");
159
		item.addSelectionListener(new DropDownSelectionListener());
160
161
		/* Create the image and text tool bar */
162
		imageTextToolBar = new ToolBar (imageTextToolBarGroup, style);
163
		item = new ToolItem (imageTextToolBar, SWT.PUSH);
164
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
165
		item.setText (ControlExample.getResourceString("Push"));
166
		item.setToolTipText("SWT.PUSH");
167
		item = new ToolItem (imageTextToolBar, SWT.PUSH);
168
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
169
		item.setText (ControlExample.getResourceString("Push"));
170
		item.setToolTipText("SWT.PUSH");
171
		item = new ToolItem (imageTextToolBar, SWT.RADIO);
172
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
173
		item.setText (ControlExample.getResourceString("Radio"));
174
		item.setToolTipText("SWT.RADIO");
175
		item = new ToolItem (imageTextToolBar, SWT.RADIO);
176
		item.setImage (instance.images[ControlExample.ciOpenFolder]);
177
		item.setText (ControlExample.getResourceString("Radio"));
178
		item.setToolTipText("SWT.RADIO");
179
		item = new ToolItem (imageTextToolBar, SWT.CHECK);
180
		item.setImage (instance.images[ControlExample.ciTarget]);
181
		item.setText (ControlExample.getResourceString("Check"));
182
		item.setToolTipText("SWT.CHECK");
183
		item = new ToolItem (imageTextToolBar, SWT.RADIO);
184
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
185
		item.setText (ControlExample.getResourceString("Radio"));
186
		item.setToolTipText("SWT.RADIO");
187
		item = new ToolItem (imageTextToolBar, SWT.RADIO);
188
		item.setImage (instance.images[ControlExample.ciClosedFolder]);
189
		item.setText (ControlExample.getResourceString("Radio"));
190
		item.setToolTipText("SWT.RADIO");
191
		item = new ToolItem (imageTextToolBar, SWT.SEPARATOR);
192
		item.setToolTipText("SWT.SEPARATOR");
193
		if (comboChildButton.getSelection ()) {
194
			Combo combo = new Combo (imageTextToolBar, SWT.NONE);
195
			combo.setItems (new String [] {"250", "500", "750"});
196
			combo.setText (combo.getItem (0));
197
			combo.pack ();
198
			item.setWidth (combo.getSize ().x);
199
			item.setControl (combo);
200
		}
201
		item = new ToolItem (imageTextToolBar, SWT.DROP_DOWN);
202
		item.setImage (instance.images[ControlExample.ciTarget]);
203
		item.setText (ControlExample.getResourceString("Drop_Down"));
204
		item.setToolTipText("SWT.DROP_DOWN");
205
		item.addSelectionListener(new DropDownSelectionListener());
206
207
		/*
208
		* Do not add the selection event for this drop down
209
		* tool item.  Without hooking the event, the drop down
210
		* widget does nothing special when the drop down area
211
		* is selected.
212
		*/
213
	}
214
	
215
	/**
216
	 * Creates the "Other" group.
217
	 */
218
	void createOtherGroup () {
219
		super.createOtherGroup ();
220
	
221
		/* Create display controls specific to this example */
222
		comboChildButton = new Button (otherGroup, SWT.CHECK);
223
		comboChildButton.setText (ControlExample.getResourceString("Combo_child"));
224
	
225
		/* Add the listeners */
226
		comboChildButton.addSelectionListener (new SelectionAdapter () {
227
			public void widgetSelected (SelectionEvent event) {
228
				recreateExampleWidgets ();
229
			}
230
		});
231
	}
232
	
233
	/**
234
	 * Creates the "Style" group.
235
	 */
236
	void createStyleGroup() {
237
		super.createStyleGroup();
238
	
239
		/* Create the extra widgets */
240
		horizontalButton = new Button (styleGroup, SWT.RADIO);
241
		horizontalButton.setText ("SWT.HORIZONTAL");
242
		verticalButton = new Button (styleGroup, SWT.RADIO);
243
		verticalButton.setText ("SWT.VERTICAL");
244
		flatButton = new Button (styleGroup, SWT.CHECK);
245
		flatButton.setText ("SWT.FLAT");
246
		shadowOutButton = new Button (styleGroup, SWT.CHECK);
247
		shadowOutButton.setText ("SWT.SHADOW_OUT");
248
		wrapButton = new Button (styleGroup, SWT.CHECK);
249
		wrapButton.setText ("SWT.WRAP");
250
		rightButton = new Button (styleGroup, SWT.CHECK);
251
		rightButton.setText ("SWT.RIGHT");
252
		borderButton = new Button (styleGroup, SWT.CHECK);
253
		borderButton.setText ("SWT.BORDER");
254
	}
255
	
256
	void disposeExampleWidgets () {
257
		super.disposeExampleWidgets ();
258
	}
259
	
260
	/**
261
	 * Gets the "Example" widget children's items, if any.
262
	 *
263
	 * @return an array containing the example widget children's items
264
	 */
265
	Item [] getExampleWidgetItems () {
266
		Item [] imageToolBarItems = imageToolBar.getItems();
267
		Item [] textToolBarItems = textToolBar.getItems();
268
		Item [] imageTextToolBarItems = imageTextToolBar.getItems();
269
		Item [] allItems = new Item [imageToolBarItems.length + textToolBarItems.length + imageTextToolBarItems.length];
270
		System.arraycopy(imageToolBarItems, 0, allItems, 0, imageToolBarItems.length);
271
		System.arraycopy(textToolBarItems, 0, allItems, imageToolBarItems.length, textToolBarItems.length);
272
		System.arraycopy(imageTextToolBarItems, 0, allItems, imageToolBarItems.length + textToolBarItems.length, imageTextToolBarItems.length);
273
		return allItems;
274
	}
275
	
276
	/**
277
	 * Gets the "Example" widget children.
278
	 */
279
	Widget [] getExampleWidgets () {
280
		return new Widget [] {imageToolBar, textToolBar, imageTextToolBar};
281
	}
282
	
283
	/**
284
	 * Returns a list of set/get API method names (without the set/get prefix)
285
	 * that can be used to set/get values in the example control(s).
286
	 */
287
	String[] getMethodNames() {
288
		return new String[] {"ToolTipText"};
289
	}
290
291
	/**
292
	 * Gets the short text for the tab folder item.
293
	 */
294
	String getShortTabText() {
295
		return "TB";
296
	}
297
298
	/**
299
	 * Gets the text for the tab folder item.
300
	 */
301
	String getTabText () {
302
		return "ToolBar";
303
	}
304
	
305
	/**
306
	 * Sets the state of the "Example" widgets.
307
	 */
308
	void setExampleWidgetState () {
309
		super.setExampleWidgetState ();
310
		horizontalButton.setSelection ((imageToolBar.getStyle () & SWT.HORIZONTAL) != 0);
311
		verticalButton.setSelection ((imageToolBar.getStyle () & SWT.VERTICAL) != 0);
312
		flatButton.setSelection ((imageToolBar.getStyle () & SWT.FLAT) != 0);
313
		wrapButton.setSelection ((imageToolBar.getStyle () & SWT.WRAP) != 0);
314
		shadowOutButton.setSelection ((imageToolBar.getStyle () & SWT.SHADOW_OUT) != 0);
315
		borderButton.setSelection ((imageToolBar.getStyle () & SWT.BORDER) != 0);
316
		rightButton.setSelection ((imageToolBar.getStyle () & SWT.RIGHT) != 0);
317
	}
318
	
319
	/**
320
	 * Listens to widgetSelected() events on SWT.DROP_DOWN type ToolItems
321
	 * and opens/closes a menu when appropriate.
322
	 */
323
	class DropDownSelectionListener extends SelectionAdapter {
324
		private Menu    menu = null;
325
		
326
		public void widgetSelected(SelectionEvent event) {
327
			// Create the menu if it has not already been created
328
			if (menu == null) {
329
				// Lazy create the menu.
330
				ToolBar toolbar = ((ToolItem) event.widget).getParent();
331
				int style = toolbar.getStyle() & (SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT);
332
				menu = new Menu(shell, style | SWT.POP_UP);
333
				for (int i = 0; i < 9; ++i) {
334
					final String text = ControlExample.getResourceString("DropDownData_" + i);
335
					if (text.length() != 0) {
336
						MenuItem menuItem = new MenuItem(menu, SWT.NONE);
337
						menuItem.setText(text);
338
					} else {
339
						new MenuItem(menu, SWT.SEPARATOR);
340
					}
341
				}
342
			}
343
			
344
			/**
345
			 * A selection event will be fired when a drop down tool
346
			 * item is selected in the main area and in the drop
347
			 * down arrow.  Examine the event detail to determine
348
			 * where the widget was selected.
349
			 */		
350
			if (event.detail == SWT.ARROW) {
351
				/*
352
				 * The drop down arrow was selected.
353
				 */
354
				// Position the menu below and vertically aligned with the the drop down tool button.
355
				final ToolItem toolItem = (ToolItem) event.widget;
356
				final ToolBar  toolBar = toolItem.getParent();
357
				
358
				Point point = toolBar.toDisplay(new Point(event.x, event.y));
359
				menu.setLocation(point.x, point.y);
360
				menu.setVisible(true);
361
			} 
362
		}
363
	}
364
}
(-)src/org/eclipse/swt/examples/mirroringTest/ToolTipTab.java (+260 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.widgets.*;
16
import org.eclipse.swt.events.*;
17
import org.eclipse.swt.layout.*;
18
19
class ToolTipTab extends Tab {
20
21
	/* Example widgets and groups that contain them */
22
	ToolTip toolTip1;
23
	Group toolTipGroup;
24
	
25
	/* Style widgets added to the "Style" group */
26
	Button balloonButton, iconErrorButton, iconInformationButton, iconWarningButton, noIconButton;
27
	
28
	/* Other widgets added to the "Other" group */
29
	Button autoHideButton, showInTrayButton;
30
	
31
	Tray tray;
32
	TrayItem trayItem;
33
	
34
	/**
35
	 * Creates the Tab within a given instance of ControlExample.
36
	 */
37
	ToolTipTab(ControlExample instance) {
38
		super(instance);
39
	}
40
	
41
	/**
42
	 * Creates the "Example" group.
43
	 */
44
	void createExampleGroup () {
45
		super.createExampleGroup ();
46
		
47
		/* Create a group for the tooltip visibility check box */
48
		toolTipGroup = new Group (exampleGroup, SWT.NONE);
49
		toolTipGroup.setLayout (new GridLayout ());
50
		toolTipGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
51
		toolTipGroup.setText ("ToolTip");
52
		visibleButton = new Button(toolTipGroup, SWT.CHECK);
53
		visibleButton.setText(ControlExample.getResourceString("Visible"));
54
		visibleButton.addSelectionListener (new SelectionAdapter () {
55
			public void widgetSelected (SelectionEvent event) {
56
				setExampleWidgetVisibility ();
57
			}
58
		});
59
	}
60
	
61
	/**
62
	 * Creates the "Example" widgets.
63
	 */
64
	void createExampleWidgets () {
65
		
66
		/* Compute the widget style */
67
		int style = getDefaultStyle();
68
		if (balloonButton.getSelection ()) style |= SWT.BALLOON;
69
		if (iconErrorButton.getSelection ()) style |= SWT.ICON_ERROR;
70
		if (iconInformationButton.getSelection ()) style |= SWT.ICON_INFORMATION;
71
		if (iconWarningButton.getSelection ()) style |= SWT.ICON_WARNING;
72
		
73
		/* Create the example widgets */
74
		toolTip1 = new ToolTip (shell, style);
75
		toolTip1.setText(ControlExample.getResourceString("ToolTip_Title"));
76
		toolTip1.setMessage(ControlExample.getResourceString("Example_string"));
77
	}
78
	
79
	/**
80
	 * Creates the tab folder page.
81
	 *
82
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
83
	 * @return the new page for the tab folder
84
	 */
85
	Composite createTabFolderPage (TabFolder tabFolder) {
86
		super.createTabFolderPage (tabFolder);
87
88
		/*
89
		 * Add a resize listener to the tabFolderPage so that
90
		 * if the user types into the example widget to change
91
		 * its preferred size, and then resizes the shell, we
92
		 * recalculate the preferred size correctly.
93
		 */
94
		tabFolderPage.addControlListener(new ControlAdapter() {
95
			public void controlResized(ControlEvent e) {
96
				setExampleWidgetSize ();
97
			}
98
		});
99
		
100
		return tabFolderPage;
101
	}
102
103
	/**
104
	 * Creates the "Style" group.
105
	 */
106
	void createStyleGroup () {
107
		super.createStyleGroup ();
108
	
109
		/* Create the extra widgets */
110
		balloonButton = new Button (styleGroup, SWT.CHECK);
111
		balloonButton.setText ("SWT.BALLOON");
112
		iconErrorButton = new Button (styleGroup, SWT.RADIO);
113
		iconErrorButton.setText("SWT.ICON_ERROR");
114
		iconInformationButton = new Button (styleGroup, SWT.RADIO);
115
		iconInformationButton.setText("SWT.ICON_INFORMATION");
116
		iconWarningButton = new Button (styleGroup, SWT.RADIO);
117
		iconWarningButton.setText("SWT.ICON_WARNING");
118
		noIconButton = new Button (styleGroup, SWT.RADIO);
119
		noIconButton.setText(ControlExample.getResourceString("No_Icon"));
120
	}
121
	
122
	void createColorAndFontGroup () {
123
		// ToolTip does not need a color and font group.
124
	}
125
	
126
	void createOtherGroup () {
127
		/* Create the group */
128
		otherGroup = new Group (controlGroup, SWT.NONE);
129
		otherGroup.setLayout (new GridLayout ());
130
		otherGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));
131
		otherGroup.setText (ControlExample.getResourceString("Other"));
132
	
133
		/* Create the controls */
134
		autoHideButton = new Button(otherGroup, SWT.CHECK);
135
		autoHideButton.setText(ControlExample.getResourceString("AutoHide"));
136
		showInTrayButton = new Button(otherGroup, SWT.CHECK);
137
		showInTrayButton.setText(ControlExample.getResourceString("Show_In_Tray"));
138
		tray = display.getSystemTray();
139
		showInTrayButton.setEnabled(tray != null);
140
141
		/* Add the listeners */
142
		autoHideButton.addSelectionListener (new SelectionAdapter () {
143
			public void widgetSelected (SelectionEvent event) {
144
				setExampleWidgetAutoHide ();
145
			}
146
		});
147
		showInTrayButton.addSelectionListener (new SelectionAdapter () {
148
			public void widgetSelected (SelectionEvent event) {
149
				showExampleWidgetInTray ();
150
			}
151
		});
152
		shell.addDisposeListener(new DisposeListener() {
153
			public void widgetDisposed(DisposeEvent event) {
154
				disposeTrayItem();
155
			}
156
		});
157
158
		/* Set the default state */
159
		autoHideButton.setSelection(true);
160
	}
161
	
162
	void createSizeGroup () {
163
		// ToolTip does not need a size group.
164
	}
165
	
166
	void createBackgroundModeGroup () {
167
		// ToolTip does not need a background mode group.
168
	}
169
	
170
	/**
171
	 * Disposes the "Example" widgets.
172
	 */
173
	void disposeExampleWidgets () {
174
		disposeTrayItem();
175
		super.disposeExampleWidgets();
176
	}
177
	
178
	/**
179
	 * Gets the "Example" widget children.
180
	 */
181
	// Tab uses this for many things - widgets would only get set/get, listeners, and dispose.
182
	Widget[] getExampleWidgets () {
183
		return new Widget [] {toolTip1};
184
	}
185
	
186
	/**
187
	 * Returns a list of set/get API method names (without the set/get prefix)
188
	 * that can be used to set/get values in the example control(s).
189
	 */
190
	String[] getMethodNames() {
191
		return new String[] {"Message", "Text"};
192
	}
193
194
	/**
195
	 * Gets the short text for the tab folder item.
196
	 */
197
	String getShortTabText() {
198
		return "TT";
199
	}
200
201
	/**
202
	 * Gets the text for the tab folder item.
203
	 */
204
	String getTabText () {
205
		return "ToolTip";
206
	}
207
	
208
	/**
209
	 * Sets the state of the "Example" widgets.
210
	 */
211
	void setExampleWidgetState () {
212
		showExampleWidgetInTray ();
213
		setExampleWidgetAutoHide ();
214
		super.setExampleWidgetState ();
215
		balloonButton.setSelection ((toolTip1.getStyle () & SWT.BALLOON) != 0);
216
		iconErrorButton.setSelection ((toolTip1.getStyle () & SWT.ICON_ERROR) != 0);
217
		iconInformationButton.setSelection ((toolTip1.getStyle () & SWT.ICON_INFORMATION) != 0);
218
		iconWarningButton.setSelection ((toolTip1.getStyle () & SWT.ICON_WARNING) != 0);
219
		noIconButton.setSelection ((toolTip1.getStyle () & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) == 0);
220
		autoHideButton.setSelection(toolTip1.getAutoHide());
221
	}
222
223
	/**
224
	 * Sets the visibility of the "Example" widgets.
225
	 */
226
	void setExampleWidgetVisibility () {
227
		toolTip1.setVisible (visibleButton.getSelection ());
228
	}
229
	
230
	/**
231
	 * Sets the autoHide state of the "Example" widgets.
232
	 */
233
	void setExampleWidgetAutoHide () {
234
		toolTip1.setAutoHide(autoHideButton.getSelection ());
235
	}
236
	
237
	void showExampleWidgetInTray () {
238
		if (showInTrayButton.getSelection ()) {
239
			createTrayItem();
240
			trayItem.setToolTip(toolTip1);
241
		} else {
242
			disposeTrayItem();
243
		}
244
	}
245
246
	void createTrayItem() {
247
		if (trayItem == null) {
248
			trayItem = new TrayItem(tray, SWT.NONE);
249
			trayItem.setImage(instance.images[ControlExample.ciTarget]);
250
		}
251
	}
252
	
253
	void disposeTrayItem() {
254
		if (trayItem != null) {
255
			trayItem.setToolTip(null);
256
			trayItem.dispose();
257
			trayItem = null;
258
		}
259
	}
260
}
(-)src/org/eclipse/swt/examples/mirroringTest/TreeTab.java (+783 lines)
Added Link Here
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
 *******************************************************************************/
11
package org.eclipse.swt.examples.mirroringTest;
12
13
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.layout.*;
16
import org.eclipse.swt.widgets.*;
17
import org.eclipse.swt.graphics.*;
18
import org.eclipse.swt.events.*;
19
20
class TreeTab extends ScrollableTab {
21
	/* Example widgets and groups that contain them */
22
	Tree tree1, tree2;
23
	TreeItem textNode1, imageNode1;
24
	Group treeGroup, imageTreeGroup, itemGroup;
25
	
26
	/* Size widgets added to the "Size" group */
27
	Button packColumnsButton;
28
	
29
	/* Style widgets added to the "Style" group */
30
	Button noScrollButton, checkButton, fullSelectionButton;
31
32
	/* Other widgets added to the "Other" group */
33
	Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, subImagesButton, linesVisibleButton;
34
	
35
	/* Controls and resources added to the "Colors and Fonts" group */
36
	static final int ITEM_FOREGROUND_COLOR = 3;
37
	static final int ITEM_BACKGROUND_COLOR = 4;
38
	static final int ITEM_FONT = 5;
39
	static final int CELL_FOREGROUND_COLOR = 6;
40
	static final int CELL_BACKGROUND_COLOR = 7;
41
	static final int CELL_FONT = 8;
42
	Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor;
43
	Font itemFont, cellFont;
44
45
	static String [] columnTitles	= {ControlExample.getResourceString("TableTitle_0"),
46
		   ControlExample.getResourceString("TableTitle_1"),
47
		   ControlExample.getResourceString("TableTitle_2"),
48
		   ControlExample.getResourceString("TableTitle_3")};
49
		   
50
	static String[][] tableData = {
51
			{ ControlExample.getResourceString("TableLine0_0"),
52
					ControlExample.getResourceString("TableLine0_1"),
53
					ControlExample.getResourceString("TableLine0_2"),
54
					ControlExample.getResourceString("TableLine0_3") },
55
			{ ControlExample.getResourceString("TableLine1_0"),
56
					ControlExample.getResourceString("TableLine1_1"),
57
					ControlExample.getResourceString("TableLine1_2"),
58
					ControlExample.getResourceString("TableLine1_3") },
59
			{ ControlExample.getResourceString("TableLine2_0"),
60
					ControlExample.getResourceString("TableLine2_1"),
61
					ControlExample.getResourceString("TableLine2_2"),
62
					ControlExample.getResourceString("TableLine2_3") } };
63
64
	Point menuMouseCoords;
65
66
	/**
67
	 * Creates the Tab within a given instance of ControlExample.
68
	 */
69
	TreeTab(ControlExample instance) {
70
		super(instance);
71
	}
72
73
	/**
74
	 * Creates the "Colors and Fonts" group.
75
	 */
76
	void createColorAndFontGroup () {
77
		super.createColorAndFontGroup();
78
		
79
		TableItem item = new TableItem(colorAndFontTable, SWT.None);
80
		item.setText(ControlExample.getResourceString ("Item_Foreground_Color"));
81
		item = new TableItem(colorAndFontTable, SWT.None);
82
		item.setText(ControlExample.getResourceString ("Item_Background_Color"));
83
		item = new TableItem(colorAndFontTable, SWT.None);
84
		item.setText(ControlExample.getResourceString ("Item_Font"));
85
		item = new TableItem(colorAndFontTable, SWT.None);
86
		item.setText(ControlExample.getResourceString ("Cell_Foreground_Color"));
87
		item = new TableItem(colorAndFontTable, SWT.None);
88
		item.setText(ControlExample.getResourceString ("Cell_Background_Color"));
89
		item = new TableItem(colorAndFontTable, SWT.None);
90
		item.setText(ControlExample.getResourceString ("Cell_Font"));
91
92
		shell.addDisposeListener(new DisposeListener() {
93
			public void widgetDisposed(DisposeEvent event) {
94
				if (itemBackgroundColor != null) itemBackgroundColor.dispose();
95
				if (itemForegroundColor != null) itemForegroundColor.dispose();
96
				if (itemFont != null) itemFont.dispose();
97
				if (cellBackgroundColor != null) cellBackgroundColor.dispose();
98
				if (cellForegroundColor != null) cellForegroundColor.dispose();
99
				if (cellFont != null) cellFont.dispose();
100
				itemBackgroundColor = null;
101
				itemForegroundColor = null;			
102
				itemFont = null;
103
				cellBackgroundColor = null;
104
				cellForegroundColor = null;			
105
				cellFont = null;
106
			}
107
		});
108
	}
109
110
	void changeFontOrColor(int index) {
111
		switch (index) {
112
		case ITEM_FOREGROUND_COLOR: {
113
			Color oldColor = itemForegroundColor;
114
			if (oldColor == null) oldColor = textNode1.getForeground ();
115
			colorDialog.setRGB(oldColor.getRGB());
116
			RGB rgb = colorDialog.open();
117
			if (rgb == null) return;
118
			oldColor = itemForegroundColor;
119
			itemForegroundColor = new Color (display, rgb);
120
			setItemForeground ();
121
			if (oldColor != null) oldColor.dispose ();
122
		}
123
		break;
124
		case ITEM_BACKGROUND_COLOR: {
125
			Color oldColor = itemBackgroundColor;
126
			if (oldColor == null) oldColor = textNode1.getBackground ();
127
			colorDialog.setRGB(oldColor.getRGB());
128
			RGB rgb = colorDialog.open();
129
			if (rgb == null) return;
130
			oldColor = itemBackgroundColor;
131
			itemBackgroundColor = new Color (display, rgb);
132
			setItemBackground ();
133
			if (oldColor != null) oldColor.dispose ();
134
		}
135
		break;
136
		case ITEM_FONT: {
137
			Font oldFont = itemFont;
138
			if (oldFont == null) oldFont = textNode1.getFont ();
139
			fontDialog.setFontList(oldFont.getFontData());
140
			FontData fontData = fontDialog.open ();
141
			if (fontData == null) return;
142
			oldFont = itemFont;
143
			itemFont = new Font (display, fontData);
144
			setItemFont ();
145
			setExampleWidgetSize ();
146
			if (oldFont != null) oldFont.dispose ();
147
		}
148
		break;
149
		case CELL_FOREGROUND_COLOR: {
150
			Color oldColor = cellForegroundColor;
151
			if (oldColor == null) oldColor = textNode1.getForeground (1);
152
			colorDialog.setRGB(oldColor.getRGB());
153
			RGB rgb = colorDialog.open();
154
			if (rgb == null) return;
155
			oldColor = cellForegroundColor;
156
			cellForegroundColor = new Color (display, rgb);
157
			setCellForeground ();
158
			if (oldColor != null) oldColor.dispose ();
159
		}
160
		break;
161
		case CELL_BACKGROUND_COLOR: {
162
			Color oldColor = cellBackgroundColor;
163
			if (oldColor == null) oldColor = textNode1.getBackground (1);
164
			colorDialog.setRGB(oldColor.getRGB());
165
			RGB rgb = colorDialog.open();
166
			if (rgb == null) return;
167
			oldColor = cellBackgroundColor;
168
			cellBackgroundColor = new Color (display, rgb);
169
			setCellBackground ();
170
			if (oldColor != null) oldColor.dispose ();
171
		}
172
		break;
173
		case CELL_FONT: {
174
			Font oldFont = cellFont;
175
			if (oldFont == null) oldFont = textNode1.getFont (1);
176
			fontDialog.setFontList(oldFont.getFontData());
177
			FontData fontData = fontDialog.open ();
178
			if (fontData == null) return;
179
			oldFont = cellFont;
180
			cellFont = new Font (display, fontData);
181
			setCellFont ();
182
			setExampleWidgetSize ();
183
			if (oldFont != null) oldFont.dispose ();
184
		}
185
		break;
186
		default:
187
			super.changeFontOrColor(index);
188
		}
189
	}
190
191
	/**
192
	 * Creates the "Other" group.
193
	 */
194
	void createOtherGroup () {
195
		super.createOtherGroup ();
196
	
197
		/* Create display controls specific to this example */
198
		linesVisibleButton = new Button (otherGroup, SWT.CHECK);
199
		linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible"));
200
		multipleColumns = new Button (otherGroup, SWT.CHECK);
201
		multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns"));
202
		headerVisibleButton = new Button (otherGroup, SWT.CHECK);
203
		headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible"));
204
		sortIndicatorButton = new Button (otherGroup, SWT.CHECK);
205
		sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator"));
206
		moveableColumns = new Button (otherGroup, SWT.CHECK);
207
		moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns"));
208
		resizableColumns = new Button (otherGroup, SWT.CHECK);
209
		resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns"));
210
		headerImagesButton = new Button (otherGroup, SWT.CHECK);
211
		headerImagesButton.setText (ControlExample.getResourceString("Header_Images"));
212
		subImagesButton = new Button (otherGroup, SWT.CHECK);
213
		subImagesButton.setText (ControlExample.getResourceString("Sub_Images"));
214
	
215
		/* Add the listeners */
216
		linesVisibleButton.addSelectionListener (new SelectionAdapter () {
217
			public void widgetSelected (SelectionEvent event) {
218
				setWidgetLinesVisible ();
219
			}
220
		});
221
		multipleColumns.addSelectionListener (new SelectionAdapter () {
222
			public void widgetSelected (SelectionEvent event) {
223
				recreateExampleWidgets ();
224
			}
225
		});
226
		headerVisibleButton.addSelectionListener (new SelectionAdapter () {
227
			public void widgetSelected (SelectionEvent event) {
228
				setWidgetHeaderVisible ();
229
			}
230
		});
231
		sortIndicatorButton.addSelectionListener (new SelectionAdapter () {
232
			public void widgetSelected (SelectionEvent event) {
233
				setWidgetSortIndicator ();
234
			}
235
		});
236
		moveableColumns.addSelectionListener (new SelectionAdapter () {
237
			public void widgetSelected (SelectionEvent event) {
238
				setColumnsMoveable ();
239
			}
240
		});
241
		resizableColumns.addSelectionListener (new SelectionAdapter () {
242
			public void widgetSelected (SelectionEvent event) {
243
				setColumnsResizable ();
244
			}
245
		});
246
		headerImagesButton.addSelectionListener (new SelectionAdapter () {
247
			public void widgetSelected (SelectionEvent event) {
248
				recreateExampleWidgets ();
249
			}
250
		});
251
		subImagesButton.addSelectionListener (new SelectionAdapter () {
252
			public void widgetSelected (SelectionEvent event) {
253
				recreateExampleWidgets ();
254
			}
255
		});
256
	}
257
	
258
	/**
259
	 * Creates the "Example" group.
260
	 */
261
	void createExampleGroup () {
262
		super.createExampleGroup ();
263
		
264
		/* Create a group for the text tree */
265
		treeGroup = new Group (exampleGroup, SWT.NONE);
266
		treeGroup.setLayout (new GridLayout ());
267
		treeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
268
		treeGroup.setText ("Tree");
269
	
270
		/* Create a group for the image tree */
271
		imageTreeGroup = new Group (exampleGroup, SWT.NONE);
272
		imageTreeGroup.setLayout (new GridLayout ());
273
		imageTreeGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
274
		imageTreeGroup.setText (ControlExample.getResourceString("Tree_With_Images"));
275
	}
276
	
277
	/**
278
	 * Creates the "Example" widgets.
279
	 */
280
	void createExampleWidgets () {
281
		/* Compute the widget style */
282
		int style = getDefaultStyle();
283
		if (singleButton.getSelection()) style |= SWT.SINGLE;
284
		if (multiButton.getSelection()) style |= SWT.MULTI;
285
		if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL;
286
		if (verticalButton.getSelection ()) style |= SWT.V_SCROLL;
287
		if (noScrollButton.getSelection()) style |= SWT.NO_SCROLL;
288
		if (checkButton.getSelection()) style |= SWT.CHECK;
289
		if (fullSelectionButton.getSelection ()) style |= SWT.FULL_SELECTION;
290
		if (borderButton.getSelection()) style |= SWT.BORDER;
291
	
292
		/* Create the text tree */
293
		tree1 = new Tree (treeGroup, style);
294
		boolean multiColumn = multipleColumns.getSelection();
295
		if (multiColumn) {
296
			for (int i = 0; i < columnTitles.length; i++) {
297
				TreeColumn treeColumn = new TreeColumn(tree1, SWT.NONE);
298
				treeColumn.setText(columnTitles[i]);
299
				treeColumn.setToolTipText(ControlExample.getResourceString("Tooltip", new String [] {columnTitles[i]}));
300
			}
301
			tree1.setSortColumn(tree1.getColumn(0));
302
		}
303
		for (int i = 0; i < 4; i++) {
304
			TreeItem item = new TreeItem (tree1, SWT.NONE);
305
			setItemText(item, i, ControlExample.getResourceString("Node_" + (i + 1)));
306
			if (i < 3) {
307
				TreeItem subitem = new TreeItem (item, SWT.NONE);
308
				setItemText(subitem, i, ControlExample.getResourceString("Node_" + (i + 1) + "_1"));
309
			}
310
		}
311
		TreeItem treeRoots[] = tree1.getItems ();
312
		TreeItem item = new TreeItem (treeRoots[1], SWT.NONE);
313
		setItemText(item, 1, ControlExample.getResourceString("Node_2_2"));
314
		item = new TreeItem (item, SWT.NONE);
315
		setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1"));					
316
		textNode1 = treeRoots[0];
317
		packColumns(tree1);
318
		try {
319
			TreeColumn column = tree1.getColumn(0);
320
			resizableColumns.setSelection (column.getResizable());
321
		} catch (IllegalArgumentException ex) {}
322
323
		/* Create the image tree */	
324
		tree2 = new Tree (imageTreeGroup, style);
325
		Image image = instance.images[ControlExample.ciClosedFolder];
326
		if (multiColumn) {
327
			for (int i = 0; i < columnTitles.length; i++) {
328
				TreeColumn treeColumn = new TreeColumn(tree2, SWT.NONE);
329
				treeColumn.setText(columnTitles[i]);
330
				treeColumn.setToolTipText(ControlExample.getResourceString("Tooltip", new String [] {columnTitles[i]}));
331
				if (headerImagesButton.getSelection()) treeColumn.setImage(instance.images [i % 3]);
332
			}
333
		}
334
		for (int i = 0; i < 4; i++) {
335
			item = new TreeItem (tree2, SWT.NONE);
336
			setItemText(item, i, ControlExample.getResourceString("Node_" + (i + 1)));
337
			if (multiColumn && subImagesButton.getSelection()) {
338
				for (int j = 0; j < columnTitles.length; j++) {
339
					item.setImage(j, image);
340
				}
341
			} else {
342
				item.setImage(image);
343
			}
344
			if (i < 3) {
345
				TreeItem subitem = new TreeItem (item, SWT.NONE);
346
				setItemText(subitem, i, ControlExample.getResourceString("Node_" + (i + 1) + "_1"));
347
				if (multiColumn && subImagesButton.getSelection()) {
348
					for (int j = 0; j < columnTitles.length; j++) {
349
						subitem.setImage(j, image);
350
					}
351
				} else {
352
					subitem.setImage(image);
353
				}
354
			}
355
		}
356
		treeRoots = tree2.getItems ();
357
		item = new TreeItem (treeRoots[1], SWT.NONE);
358
		setItemText(item, 1, ControlExample.getResourceString("Node_2_2"));
359
		if (multiColumn && subImagesButton.getSelection()) {
360
			for (int j = 0; j < columnTitles.length; j++) {
361
				item.setImage(j, image);
362
			}
363
		} else {
364
			item.setImage(image);
365
		}
366
		item = new TreeItem (item, SWT.NONE);
367
		setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1"));
368
		if (multiColumn && subImagesButton.getSelection()) {
369
			for (int j = 0; j < columnTitles.length; j++) {
370
				item.setImage(j, image);
371
			}
372
		} else {
373
			item.setImage(image);
374
		}
375
		imageNode1 = treeRoots[0];
376
		packColumns(tree2);
377
	}
378
	
379
	void setItemText(TreeItem item, int i, String node) {
380
		int index = i % 3;
381
		if (multipleColumns.getSelection()) {
382
			tableData [index][0] = node;
383
			item.setText (tableData [index]);
384
		} else {
385
			item.setText (node);
386
		}		
387
	}
388
	
389
	/**
390
	 * Creates the "Size" group.  The "Size" group contains
391
	 * controls that allow the user to change the size of
392
	 * the example widgets.
393
	 */
394
	void createSizeGroup () {
395
		super.createSizeGroup();
396
	
397
		packColumnsButton = new Button (sizeGroup, SWT.PUSH);
398
		packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns"));
399
		packColumnsButton.addSelectionListener(new SelectionAdapter () {
400
			public void widgetSelected (SelectionEvent event) {
401
				packColumns (tree1);
402
				packColumns (tree2);
403
				setExampleWidgetSize ();
404
			}
405
		});
406
	}
407
	
408
	/**
409
	 * Creates the "Style" group.
410
	 */
411
	void createStyleGroup() {
412
		super.createStyleGroup();
413
		
414
		/* Create the extra widgets */
415
		noScrollButton = new Button (styleGroup, SWT.CHECK);
416
		noScrollButton.setText ("SWT.NO_SCROLL");
417
		noScrollButton.moveAbove(borderButton);
418
		checkButton = new Button (styleGroup, SWT.CHECK);
419
		checkButton.setText ("SWT.CHECK");
420
		fullSelectionButton = new Button (styleGroup, SWT.CHECK);
421
		fullSelectionButton.setText ("SWT.FULL_SELECTION");
422
	}
423
	
424
	/**
425
	 * Gets the "Example" widget children's items, if any.
426
	 *
427
	 * @return an array containing the example widget children's items
428
	 */
429
	Item [] getExampleWidgetItems () {
430
		/* Note: We do not bother collecting the tree items
431
		 * because tree items don't have any events. If events
432
		 * are ever added to TreeItem, then this needs to change.
433
		 */
434
		Item [] columns1 = tree1.getColumns();
435
		Item [] columns2 = tree2.getColumns();
436
		Item [] allItems = new Item [columns1.length + columns2.length];
437
		System.arraycopy(columns1, 0, allItems, 0, columns1.length);
438
		System.arraycopy(columns2, 0, allItems, columns1.length, columns2.length);
439
		return allItems;
440
	}
441
	
442
	/**
443
	 * Gets the "Example" widget children.
444
	 */
445
	Widget [] getExampleWidgets () {
446
		return new Widget [] {tree1, tree2};
447
	}
448
	
449
	/**
450
	 * Returns a list of set/get API method names (without the set/get prefix)
451
	 * that can be used to set/get values in the example control(s).
452
	 */
453
	String[] getMethodNames() {
454
		return new String[] {"ColumnOrder", "Selection", "ToolTipText", "TopItem"};
455
	}
456
457
	Object[] parameterForType(String typeName, String value, Widget widget) {
458
		if (typeName.equals("org.eclipse.swt.widgets.TreeItem")) {
459
			TreeItem item = findItem(value, ((Tree) widget).getItems());
460
			if (item != null) return new Object[] {item};
461
		}
462
		if (typeName.equals("[Lorg.eclipse.swt.widgets.TreeItem;")) {
463
			String[] values = split(value, ',');
464
			TreeItem[] items = new TreeItem[values.length];
465
			for (int i = 0; i < values.length; i++) {
466
				TreeItem item = findItem(values[i], ((Tree) widget).getItems());
467
				if (item == null) break;
468
				items[i] = item;				
469
			}
470
			return new Object[] {items};
471
		}
472
		return super.parameterForType(typeName, value, widget);
473
	}
474
475
	TreeItem findItem(String value, TreeItem[] items) {
476
		for (int i = 0; i < items.length; i++) {
477
			TreeItem item = items[i];
478
			if (item.getText().equals(value)) return item;
479
			item = findItem(value, item.getItems());
480
			if (item != null) return item;
481
		}
482
		return null;
483
	}
484
485
	/**
486
	 * Gets the text for the tab folder item.
487
	 */
488
	String getTabText () {
489
		return "Tree";
490
	}
491
492
	void packColumns (Tree tree) {
493
		if (multipleColumns.getSelection()) {
494
			int columnCount = tree.getColumnCount();
495
			for (int i = 0; i < columnCount; i++) {
496
				TreeColumn treeColumn = tree.getColumn(i);
497
				treeColumn.pack();
498
			}
499
		}
500
	}
501
	
502
	/**
503
	 * Sets the moveable columns state of the "Example" widgets.
504
	 */
505
	void setColumnsMoveable () {
506
		boolean selection = moveableColumns.getSelection();
507
		TreeColumn[] columns1 = tree1.getColumns();
508
		for (int i = 0; i < columns1.length; i++) {
509
			columns1[i].setMoveable(selection);
510
		}
511
		TreeColumn[] columns2 = tree2.getColumns();
512
		for (int i = 0; i < columns2.length; i++) {
513
			columns2[i].setMoveable(selection);
514
		}
515
	}
516
517
	/**
518
	 * Sets the resizable columns state of the "Example" widgets.
519
	 */
520
	void setColumnsResizable () {
521
		boolean selection = resizableColumns.getSelection();
522
		TreeColumn[] columns1 = tree1.getColumns();
523
		for (int i = 0; i < columns1.length; i++) {
524
			columns1[i].setResizable(selection);
525
		}
526
		TreeColumn[] columns2 = tree2.getColumns();
527
		for (int i = 0; i < columns2.length; i++) {
528
			columns2[i].setResizable(selection);
529
		}
530
	}
531
532
	/**
533
	 * Sets the foreground color, background color, and font
534
	 * of the "Example" widgets to their default settings.
535
	 * Also sets foreground and background color of the Node 1
536
	 * TreeItems to default settings.
537
	 */
538
	void resetColorsAndFonts () {
539
		super.resetColorsAndFonts ();
540
		Color oldColor = itemForegroundColor;
541
		itemForegroundColor = null;
542
		setItemForeground ();
543
		if (oldColor != null) oldColor.dispose();
544
		oldColor = itemBackgroundColor;
545
		itemBackgroundColor = null;
546
		setItemBackground ();
547
		if (oldColor != null) oldColor.dispose();
548
		Font oldFont = font;
549
		itemFont = null;
550
		setItemFont ();
551
		if (oldFont != null) oldFont.dispose();
552
		oldColor = cellForegroundColor;
553
		cellForegroundColor = null;
554
		setCellForeground ();
555
		if (oldColor != null) oldColor.dispose();
556
		oldColor = cellBackgroundColor;
557
		cellBackgroundColor = null;
558
		setCellBackground ();
559
		if (oldColor != null) oldColor.dispose();
560
		oldFont = font;
561
		cellFont = null;
562
		setCellFont ();
563
		if (oldFont != null) oldFont.dispose();
564
	}
565
	
566
	/**
567
	 * Sets the state of the "Example" widgets.
568
	 */
569
	void setExampleWidgetState () {
570
		setItemBackground ();
571
		setItemForeground ();
572
		setItemFont ();
573
		setCellBackground ();
574
		setCellForeground ();
575
		setCellFont ();
576
		if (!instance.startup) {
577
			setColumnsMoveable ();
578
			setColumnsResizable ();
579
			setWidgetHeaderVisible ();
580
			setWidgetSortIndicator ();
581
			setWidgetLinesVisible ();
582
		}
583
		super.setExampleWidgetState ();
584
		noScrollButton.setSelection ((tree1.getStyle () & SWT.NO_SCROLL) != 0);
585
		checkButton.setSelection ((tree1.getStyle () & SWT.CHECK) != 0);
586
		fullSelectionButton.setSelection ((tree1.getStyle () & SWT.FULL_SELECTION) != 0);
587
		try {
588
			TreeColumn column = tree1.getColumn(0);
589
			moveableColumns.setSelection (column.getMoveable());
590
			resizableColumns.setSelection (column.getResizable());
591
		} catch (IllegalArgumentException ex) {}
592
		headerVisibleButton.setSelection (tree1.getHeaderVisible());
593
		linesVisibleButton.setSelection (tree1.getLinesVisible());
594
	}
595
	
596
	/**
597
	 * Sets the background color of the Node 1 TreeItems in column 1.
598
	 */
599
	void setCellBackground () {
600
		if (!instance.startup) {
601
			textNode1.setBackground (1, cellBackgroundColor);
602
			imageNode1.setBackground (1, cellBackgroundColor);
603
		}
604
		/* Set the background color item's image to match the background color of the cell. */
605
		Color color = cellBackgroundColor;
606
		if (color == null) color = textNode1.getBackground (1);
607
		TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR);
608
		Image oldImage = item.getImage();
609
		if (oldImage != null) oldImage.dispose();
610
		item.setImage (colorImage(color));
611
	}
612
	
613
	/**
614
	 * Sets the foreground color of the Node 1 TreeItems in column 1.
615
	 */
616
	void setCellForeground () {
617
		if (!instance.startup) {
618
			textNode1.setForeground (1, cellForegroundColor);
619
			imageNode1.setForeground (1, cellForegroundColor);
620
		}
621
		/* Set the foreground color item's image to match the foreground color of the cell. */
622
		Color color = cellForegroundColor;
623
		if (color == null) color = textNode1.getForeground (1);
624
		TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR);
625
		Image oldImage = item.getImage();
626
		if (oldImage != null) oldImage.dispose();
627
		item.setImage (colorImage(color));
628
	}
629
	
630
	/**
631
	 * Sets the font of the Node 1 TreeItems in column 1.
632
	 */
633
	void setCellFont () {
634
		if (!instance.startup) {
635
			textNode1.setFont (1, cellFont);
636
			imageNode1.setFont (1, cellFont);
637
		}
638
		/* Set the font item's image to match the font of the item. */
639
		Font ft = cellFont;
640
		if (ft == null) ft = textNode1.getFont (1);
641
		TableItem item = colorAndFontTable.getItem(CELL_FONT);
642
		Image oldImage = item.getImage();
643
		if (oldImage != null) oldImage.dispose();
644
		item.setImage (fontImage(ft));
645
		item.setFont(ft);
646
		colorAndFontTable.layout ();
647
	}
648
649
	/**
650
	 * Sets the background color of the Node 1 TreeItems.
651
	 */
652
	void setItemBackground () {
653
		if (!instance.startup) {
654
			textNode1.setBackground (itemBackgroundColor);
655
			imageNode1.setBackground (itemBackgroundColor);
656
		}
657
		/* Set the background button's color to match the background color of the item. */
658
		Color color = itemBackgroundColor;
659
		if (color == null) color = textNode1.getBackground ();
660
		TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR);
661
		Image oldImage = item.getImage();
662
		if (oldImage != null) oldImage.dispose();
663
		item.setImage (colorImage(color));
664
	}
665
	
666
	/**
667
	 * Sets the foreground color of the Node 1 TreeItems.
668
	 */
669
	void setItemForeground () {
670
		if (!instance.startup) {
671
			textNode1.setForeground (itemForegroundColor);
672
			imageNode1.setForeground (itemForegroundColor);
673
		}
674
		/* Set the foreground button's color to match the foreground color of the item. */
675
		Color color = itemForegroundColor;
676
		if (color == null) color = textNode1.getForeground ();
677
		TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR);
678
		Image oldImage = item.getImage();
679
		if (oldImage != null) oldImage.dispose();
680
		item.setImage (colorImage(color));
681
	}
682
	
683
	/**
684
	 * Sets the font of the Node 1 TreeItems.
685
	 */
686
	void setItemFont () {
687
		if (!instance.startup) {
688
			textNode1.setFont (itemFont);
689
			imageNode1.setFont (itemFont);
690
		}
691
		/* Set the font item's image to match the font of the item. */
692
		Font ft = itemFont;
693
		if (ft == null) ft = textNode1.getFont ();
694
		TableItem item = colorAndFontTable.getItem(ITEM_FONT);
695
		Image oldImage = item.getImage();
696
		if (oldImage != null) oldImage.dispose();
697
		item.setImage (fontImage(ft));
698
		item.setFont(ft);
699
		colorAndFontTable.layout ();
700
	}
701
702
	/**
703
	 * Sets the header visible state of the "Example" widgets.
704
	 */
705
	void setWidgetHeaderVisible () {
706
		tree1.setHeaderVisible (headerVisibleButton.getSelection ());
707
		tree2.setHeaderVisible (headerVisibleButton.getSelection ());
708
	}
709
	
710
	/**
711
	 * Sets the sort indicator state of the "Example" widgets.
712
	 */
713
	void setWidgetSortIndicator () {
714
		if (sortIndicatorButton.getSelection ()) {
715
			initializeSortState (tree1);
716
			initializeSortState (tree2);
717
		} else {
718
			resetSortState (tree1);
719
			resetSortState (tree2);
720
		}
721
	}
722
	
723
	/**
724
	 * Sets the initial sort indicator state and adds a listener
725
	 * to cycle through sort states and columns.
726
	 */
727
	void initializeSortState (final Tree tree) {
728
		/* Reset to known state: 'down' on column 0. */
729
		tree.setSortDirection (SWT.DOWN);
730
		TreeColumn [] columns = tree.getColumns();
731
		for (int i = 0; i < columns.length; i++) {
732
			TreeColumn column = columns[i];
733
			if (i == 0) tree.setSortColumn(column);
734
			SelectionListener listener = new SelectionAdapter() {
735
				public void widgetSelected(SelectionEvent e) {
736
					int sortDirection = SWT.DOWN;
737
					if (e.widget == tree.getSortColumn()) {
738
						/* If the sort column hasn't changed, cycle down -> up -> none. */
739
						switch (tree.getSortDirection ()) {
740
						case SWT.DOWN: sortDirection = SWT.UP; break;
741
						case SWT.UP: sortDirection = SWT.NONE; break;
742
						}
743
					} else {
744
						tree.setSortColumn((TreeColumn)e.widget);
745
					}
746
					tree.setSortDirection (sortDirection);
747
				}
748
			};
749
			column.addSelectionListener(listener);
750
			column.setData("SortListener", listener);	//$NON-NLS-1$
751
		}
752
	}
753
754
	void resetSortState (final Tree tree) {
755
		tree.setSortDirection (SWT.NONE);
756
		TreeColumn [] columns = tree.getColumns();
757
		for (int i = 0; i < columns.length; i++) {
758
			SelectionListener listener = (SelectionListener)columns[i].getData("SortListener");	//$NON-NLS-1$
759
			if (listener != null) columns[i].removeSelectionListener(listener);
760
		}
761
	}
762
	
763
	/**
764
	 * Sets the lines visible state of the "Example" widgets.
765
	 */
766
	void setWidgetLinesVisible () {
767
		tree1.setLinesVisible (linesVisibleButton.getSelection ());
768
		tree2.setLinesVisible (linesVisibleButton.getSelection ());
769
	}
770
771
	protected void specialPopupMenuItems(Menu menu, Event event) {
772
    	MenuItem item = new MenuItem(menu, SWT.PUSH);
773
    	item.setText("getItem(Point) on mouse coordinates");
774
    	final Tree t = (Tree) event.widget;
775
    	menuMouseCoords = t.toControl(new Point(event.x, event.y));
776
    	item.addSelectionListener(new SelectionAdapter() {
777
    		public void widgetSelected(SelectionEvent e) {
778
    			eventConsole.append ("getItem(Point(" + menuMouseCoords + ")) returned: " + t.getItem(menuMouseCoords));
779
    			eventConsole.append ("\n");
780
    		}
781
    	});
782
	}
783
}
(-)src/org/eclipse/swt/examples/mirroringTest/browser-content.html (+35 lines)
Added Link Here
1
<html>
2
<head>
3
<title>SWT Browser</title>
4
</head>
5
6
<h3>About SWT Browser</h3>
7
<p>You are looking at HTML content in a <b>Browser</b> widget.
8
<ul>
9
<li>For a definition of the Browser widget, see:
10
<a href="http://www.eclipse.org/swt/faq.php#whatisbrowser">http://www.eclipse.org/swt/faq.php#whatisbrowser</a></li>
11
<li>For a list of the platforms that Browser supports, see:
12
<a href="http://www.eclipse.org/swt/faq.php#browserplatforms">http://www.eclipse.org/swt/faq.php#browserplatforms</a></li>
13
<li>For more information on the SWT.WEBKIT Browser style, see:
14
<a href="http://www.eclipse.org/swt/faq.php#howusewebkit">http://www.eclipse.org/swt/faq.php#howusewebkit</a></li>
15
<li>For more information on the SWT.MOZILLA Browser style, see:
16
<a href="http://www.eclipse.org/swt/faq.php#howusemozilla">http://www.eclipse.org/swt/faq.php#howusemozilla</a></li>
17
<li>For more examples that use a Browser widget, see BrowserExample, BrowserDemo, and WebBrowser:
18
<a href="http://www.eclipse.org/swt/examples.php">http://www.eclipse.org/swt/examples.php</a></li>
19
</ul></p>
20
21
<h3>About SWT</h3>
22
<p>For more information on SWT, including the Widget Gallery, Snippets, Examples, FAQ, Tools, Documentation
23
and more, check out <a href="http://www.eclipse.org/swt/">http://www.eclipse.org/swt</a>.</p>
24
25
<h3>Eclipse Downloads Page</h3>
26
<p>To download the latest Integration Build of eclipse, go to:
27
<a href="http://download.eclipse.org/eclipse/downloads/">http://download.eclipse.org/eclipse/downloads</a>.</p>
28
29
<h3>Bug Reports and Feature Requests</h3>
30
<p>To report an SWT bug or request an SWT feature, go to:
31
<a href="https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform">https://bugs.eclipse.org/bugs</a>
32
and select <b>Component: SWT</b>.</p>
33
34
</body>
35
</html>

Return to bug 344460