View | Details | Raw Unified | Return to bug 242163 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/swt/examples/controlexample/ControlExample.java (-25 / +69 lines)
Lines 12-17 Link Here
12
12
13
13
14
import org.eclipse.swt.*;
14
import org.eclipse.swt.*;
15
import org.eclipse.swt.custom.StackLayout;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
15
import org.eclipse.swt.graphics.*;
18
import org.eclipse.swt.graphics.*;
16
import org.eclipse.swt.layout.*;
19
import org.eclipse.swt.layout.*;
17
import org.eclipse.swt.widgets.*;
20
import org.eclipse.swt.widgets.*;
Lines 24-31 Link Here
24
	private static ResourceBundle resourceBundle =
27
	private static ResourceBundle resourceBundle =
25
		ResourceBundle.getBundle("examples_control"); //$NON-NLS-1$
28
		ResourceBundle.getBundle("examples_control"); //$NON-NLS-1$
26
	private ShellTab shellTab;
29
	private ShellTab shellTab;
27
	private TabFolder tabFolder;
30
	private Combo tabCombo;
31
	private Composite tabArea;
32
	private StackLayout tabLayout;
28
	private Tab [] tabs;
33
	private Tab [] tabs;
34
	private Composite[] tabPages;
29
	Image images[];
35
	Image images[];
30
36
31
	static final int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2, ciBackground = 3, ciParentBackground = 4;
37
	static final int ciClosedFolder = 0, ciOpenFolder = 1, ciTarget = 2, ciBackground = 3, ciParentBackground = 4;
Lines 52-65 Link Here
52
	 */
58
	 */
53
	public ControlExample(Composite parent) {
59
	public ControlExample(Composite parent) {
54
		initResources();
60
		initResources();
55
		tabFolder = new TabFolder (parent, SWT.NONE);
56
		tabs = createTabs();
61
		tabs = createTabs();
57
		for (int i=0; i<tabs.length; i++) {
62
		
58
			TabItem item = new TabItem (tabFolder, SWT.NONE);
63
		String comboEntries[] = new String[tabs.length];
59
		    item.setText (tabs [i].getTabText ());
64
		for (int i = 0; i < tabs.length; i++) {
60
		    item.setControl (tabs [i].createTabFolderPage (tabFolder));
65
			comboEntries[i] = tabs[i].getTabText();
61
		    item.setData (tabs [i]);
62
		}
66
		}
67
		
68
		Composite top = new Composite(parent, SWT.NONE);
69
		top.setLayout(new GridLayout(2, false));
70
		
71
		Label tabLabel = new Label(top, SWT.NONE);
72
		tabLabel.setText("Control");
73
		tabLabel.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
74
		
75
		tabCombo = new Combo(top, SWT.READ_ONLY);
76
		tabCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
77
		tabCombo.setItems(comboEntries);
78
		tabCombo.addSelectionListener(new SelectionAdapter() {
79
			public void widgetSelected(SelectionEvent e) {
80
				selectTab(tabCombo.getSelectionIndex());
81
			}
82
		});
83
		
84
		tabLayout = new StackLayout();
85
		tabArea = new Composite(top, SWT.NONE);
86
		tabArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
87
		tabArea.setLayout(tabLayout);
88
		tabPages = new Composite[tabs.length];
89
		for (int i = 0; i < tabs.length; i++) {
90
			tabPages[i] = tabs[i].createPageComposite(tabArea);
91
		}
92
93
		tabCombo.select(0);
94
		tabLayout.topControl = tabPages[0];
95
		tabArea.layout();
96
		
63
		startup = false;
97
		startup = false;
64
	}
98
	}
65
99
Lines 69-96 Link Here
69
	Tab[] createTabs() {
103
	Tab[] createTabs() {
70
		return new Tab [] {
104
		return new Tab [] {
71
			new ButtonTab (this),
105
			new ButtonTab (this),
72
			new CanvasTab (this),
106
//			new CanvasTab (this), TODO
73
			new ComboTab (this),
107
//			new ComboTab (this), TODO
74
			new CoolBarTab (this),
108
			new CoolBarTab (this),
75
			new DateTimeTab (this),
109
			new DateTimeTab (this),
76
			new DialogTab (this),
110
//			new DialogTab (this), TODO
77
			new ExpandBarTab (this),
111
			new ExpandBarTab (this),
78
			new GroupTab (this),
112
			new GroupTab (this),
79
			new LabelTab (this),
113
			new LabelTab (this),
80
			new LinkTab (this),
114
			new LinkTab (this),
81
			new ListTab (this),
115
			new ListTab (this),
82
			new MenuTab (this),
116
//			new MenuTab (this), TODO
83
			new ProgressBarTab (this),
117
			new ProgressBarTab (this),
84
			new SashTab (this),
118
			new SashTab (this),
85
			new ScaleTab (this),
119
			new ScaleTab (this),
86
			shellTab = new ShellTab(this),
120
//			shellTab = new ShellTab(this), TODO
87
			new SliderTab (this),
121
			new SliderTab (this),
88
			new SpinnerTab (this),
122
//			new SpinnerTab (this), TODO
89
			new TabFolderTab (this),
123
			new TabFolderTab (this),
90
			new TableTab (this),
124
			new TableTab (this),
91
			new TextTab (this),
125
//			new TextTab (this), TODO
92
			new ToolBarTab (this),
126
			new ToolBarTab (this),
93
			new ToolTipTab (this),
127
//			new ToolTipTab (this), TODO
94
			new TreeTab (this),
128
			new TreeTab (this),
95
			new BrowserTab (this),
129
			new BrowserTab (this),
96
		};
130
		};
Lines 111-117 Link Here
111
		 */
145
		 */
112
		if (shellTab != null) shellTab.closeAllShells ();
146
		if (shellTab != null) shellTab.closeAllShells ();
113
		shellTab = null;
147
		shellTab = null;
114
		tabFolder = null;
148
		tabArea = null;
149
		tabCombo = null;
115
		freeResources();
150
		freeResources();
116
	}
151
	}
117
152
Lines 214-223 Link Here
214
	}
249
	}
215
	
250
	
216
	/**
251
	/**
252
	 * Changes the tab displayed in the group.
253
	 * @param index the index of the tab in tabs[]
254
	 */
255
	void selectTab(int index) {
256
		tabLayout.topControl = tabPages[index];
257
		tabArea.layout();
258
	}
259
	
260
	/**
217
	 * Grabs input focus.
261
	 * Grabs input focus.
218
	 */
262
	 */
219
	public void setFocus() {
263
	public void setFocus() {
220
		tabFolder.setFocus();
264
		tabCombo.setFocus();
221
	}
265
	}
222
	
266
	
223
	/**
267
	/**
Lines 231-244 Link Here
231
		/* Workaround: if the tab folder is wider than the screen,
275
		/* Workaround: if the tab folder is wider than the screen,
232
		 * carbon clips instead of somehow scrolling the tab items.
276
		 * carbon clips instead of somehow scrolling the tab items.
233
		 * We try to recover some width by using shorter tab names. */
277
		 * We try to recover some width by using shorter tab names. */
234
		if (size.x > monitorArea.width && SWT.getPlatform().equals("carbon")) {
278
//		if (size.x > monitorArea.width && SWT.getPlatform().equals("carbon")) {
235
			TabItem [] tabItems = instance.tabFolder.getItems();
279
//			TabItem [] tabItems = instance.tabFolder.getItems();
236
			for (int i=0; i<tabItems.length; i++) {
280
//			for (int i=0; i<tabItems.length; i++) {
237
				tabItems[i].setText (instance.tabs [i].getShortTabText ());
281
//				tabItems[i].setText (instance.tabs [i].getShortTabText ());
238
			}
282
//			}
239
			size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
283
//			size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
240
		}
284
//		}
241
		shell.setSize(Math.min(size.x, monitorArea.width), Math.min(size.y, monitorArea.height));
285
//		shell.setSize(Math.min(size.x, monitorArea.width), Math.min(size.y, monitorArea.height));
242
	}
286
	}
243
}
287
}
244
288
(-)src/org/eclipse/swt/examples/controlexample/Tab.java (-28 / +30 lines)
Lines 44-50 Link Here
44
	Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton;
44
	Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton;
45
45
46
	/* Common groups and composites */
46
	/* Common groups and composites */
47
	Composite tabFolderPage;
47
	Composite pageComposite;
48
	Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup;
48
	Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup;
49
49
50
	/* Controlling instance */
50
	/* Controlling instance */
Lines 231-237 Link Here
231
		 * right half of each example tab.  It consists of the
231
		 * right half of each example tab.  It consists of the
232
		 * "Style" group, the "Other" group and the "Size" group.
232
		 * "Style" group, the "Other" group and the "Size" group.
233
		 */	
233
		 */	
234
		controlGroup = new Group (tabFolderPage, SWT.NONE);
234
		controlGroup = new Group (pageComposite, SWT.NONE);
235
		controlGroup.setLayout (new GridLayout (2, true));
235
		controlGroup.setLayout (new GridLayout (2, true));
236
		controlGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false));
236
		controlGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false));
237
		controlGroup.setText (ControlExample.getResourceString("Parameters"));
237
		controlGroup.setText (ControlExample.getResourceString("Parameters"));
Lines 762-768 Link Here
762
	 * is typically the left hand column in the tab.
762
	 * is typically the left hand column in the tab.
763
	 */
763
	 */
764
	void createExampleGroup () {
764
	void createExampleGroup () {
765
		exampleGroup = new Group (tabFolderPage, SWT.NONE);
765
		exampleGroup = new Group (pageComposite, SWT.NONE);
766
		exampleGroup.setLayout (new GridLayout ());
766
		exampleGroup.setLayout (new GridLayout ());
767
		exampleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
767
		exampleGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true));
768
	}
768
	}
Lines 901-907 Link Here
901
	 * goes below the "Example" and "Control" groups.
901
	 * goes below the "Example" and "Control" groups.
902
	 */
902
	 */
903
	void createListenersGroup () {
903
	void createListenersGroup () {
904
		listenersGroup = new Group (tabFolderPage, SWT.NONE);
904
		listenersGroup = new Group (pageComposite, SWT.NONE);
905
		listenersGroup.setLayout (new GridLayout (3, false));
905
		listenersGroup.setLayout (new GridLayout (3, false));
906
		listenersGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true, 2, 1));
906
		listenersGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, true, true, 2, 1));
907
		listenersGroup.setText (ControlExample.getResourceString ("Listeners"));
907
		listenersGroup.setText (ControlExample.getResourceString ("Listeners"));
Lines 1238-1267 Link Here
1238
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
1238
	 * @param tabFolder org.eclipse.swt.widgets.TabFolder
1239
	 * @return the new page for the tab folder
1239
	 * @return the new page for the tab folder
1240
	 */
1240
	 */
1241
	Composite createTabFolderPage (TabFolder tabFolder) {
1241
	Composite createPageComposite(Composite parent) {
1242
		/* Cache the shell and display. */
1242
		if (pageComposite == null) {
1243
		shell = tabFolder.getShell ();
1243
			/* Cache the shell and display. */
1244
		display = shell.getDisplay ();
1244
			shell = parent.getShell ();
1245
		
1245
			display = shell.getDisplay ();
1246
		/* Create a two column page. */
1246
1247
		tabFolderPage = new Composite (tabFolder, SWT.NONE);
1247
			/* Create a two column page. */
1248
		tabFolderPage.setLayout (new GridLayout (2, false));
1248
			pageComposite = new Composite (parent, SWT.NONE);
1249
	
1249
			pageComposite.setLayout (new GridLayout (2, false));
1250
		/* Create the "Example" and "Control" groups. */
1250
1251
		createExampleGroup ();
1251
			/* Create the "Example" and "Control" groups. */
1252
		createControlGroup ();
1252
			createExampleGroup ();
1253
		
1253
			createControlGroup ();
1254
		/* Create the "Listeners" group under the "Control" group. */
1254
1255
		createListenersGroup ();
1255
			/* Create the "Listeners" group under the "Control" group. */
1256
		
1256
			createListenersGroup ();
1257
		/* Create and initialize the example and control widgets. */
1257
1258
		createExampleWidgets ();
1258
			/* Create and initialize the example and control widgets. */
1259
		hookExampleWidgetListeners ();
1259
			createExampleWidgets ();
1260
		createControlWidgets ();
1260
			hookExampleWidgetListeners ();
1261
		createBackgroundModeGroup ();
1261
			createControlWidgets ();
1262
		setExampleWidgetState ();
1262
			createBackgroundModeGroup ();
1263
			setExampleWidgetState ();
1264
		}
1263
		
1265
		
1264
		return tabFolderPage;
1266
		return pageComposite;
1265
	}
1267
	}
1266
	
1268
	
1267
	void setExampleWidgetPopupMenu() {
1269
	void setExampleWidgetPopupMenu() {
Lines 1734-1740 Link Here
1734
			gridData.verticalAlignment = fillVButton.getSelection() ? SWT.FILL : SWT.TOP;
1736
			gridData.verticalAlignment = fillVButton.getSelection() ? SWT.FILL : SWT.TOP;
1735
			controls [i].setLayoutData (gridData);
1737
			controls [i].setLayoutData (gridData);
1736
		}
1738
		}
1737
		tabFolderPage.layout (controls);
1739
		pageComposite.layout (controls);
1738
	}
1740
	}
1739
	
1741
	
1740
	/**
1742
	/**

Return to bug 242163