Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1eede5da1fad02649fd2765466a6fd05808fbdc2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package org.eclipse.swt.examples.controls;

/*
 * (c) Copyright IBM Corp. 2000, 2001.
 * All Rights Reserved
 */

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

class ShellTab extends Tab {	
	/* Style widgets added to the "Style" group */
	Button noParentButton, parentButton;
	Button noTrimButton, closeButton, titleButton, minButton, maxButton, borderButton, resizeButton;
	Button createButton, closeAllButton;
	Group parentStyleGroup;

	/* Variables used to track the open shells */
	int shellCount = 0;
	Shell [] shells = new Shell [4];
	
	/**
	 * Close all the example shells.
	 */
	void closeAllShells() {
		for (int i = 0; i<shellCount; i++) {
			if (shells[i] != null & !shells [i].isDisposed ()) {
				shells [i].dispose();
			}
		}
		shellCount = 0;
	}
	
	/**
	 * Handle the Create button selection event.
	 *
	 * @param event org.eclipse.swt.events.SelectionEvent
	 */
	public void createButtonSelected(SelectionEvent event) {
	
		/*
		 * Remember the example shells so they
		 * can be disposed by the user.
		 */
		if (shellCount >= shells.length) {
			Shell [] newShells = new Shell [shells.length + 4];
			System.arraycopy (shells, 0, newShells, 0, shells.length);
			shells = newShells;
		}
	
		/* Compute the shell style */
		int style = SWT.NONE;
		if (noTrimButton.getSelection()) style |= SWT.NO_TRIM;
		if (closeButton.getSelection()) style |= SWT.CLOSE;
		if (titleButton.getSelection()) style |= SWT.TITLE;
		if (minButton.getSelection()) style |= SWT.MIN;
		if (maxButton.getSelection()) style |= SWT.MAX;
		if (borderButton.getSelection()) style |= SWT.BORDER;
		if (resizeButton.getSelection()) style |= SWT.RESIZE;
	
		/* Create the shell with or without a parent */
		if (noParentButton.getSelection ()) {
			shells [shellCount] = new Shell (style);
		} else {
			Shell shell = tabFolderPage.getShell ();
			shells [shellCount] = new Shell (shell, style);
		}
	
		/* Set the size, title and open the shell */
		shells [shellCount].setSize (300, 100);
		shells [shellCount].setText (ControlPlugin.getResourceString("Title") + shellCount);
		shells [shellCount++].open ();
	}
	
	/**
	 * Creates the "Control" group. 
	 */
	void createControlGroup () {
		/*
		 * Create the "Control" group.  This is the group on the
		 * left half of each example tab.  It consists of the
		 * style group, the display group and the size group.
		 */		
		controlGroup = new Group (tabFolderPage, SWT.NULL);
		GridLayout gridLayout= new GridLayout ();
		controlGroup.setLayout (gridLayout);
		gridLayout.numColumns = 1;
		gridLayout.makeColumnsEqualWidth = true;
		controlGroup.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
		controlGroup.setText (ControlPlugin.getResourceString("Parameters"));
	
		/* Create individual groups inside the "Control" group */
		styleGroup = new Group (controlGroup, SWT.NULL);
		gridLayout = new GridLayout ();
		styleGroup.setLayout (gridLayout);
		gridLayout.numColumns = 2;
		styleGroup.setLayoutData (new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
		styleGroup.setText (ControlPlugin.getResourceString("Styles"));
	
		/* Create a group for the parent sytle controls */
		parentStyleGroup = new Group (styleGroup, SWT.NULL);
		parentStyleGroup.setLayout (new GridLayout ());
		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
		gridData.horizontalSpan = 2;
		parentStyleGroup.setLayoutData (gridData);
		parentStyleGroup.setText (ControlPlugin.getResourceString("Parent"));
	}
	
	/**
	 * Creates the "Control" widget children.
	 */
	void createControlWidgets () {
	
		/* Create the parent style buttons */
		noParentButton = new Button (parentStyleGroup, SWT.RADIO);
		noParentButton.setText (ControlPlugin.getResourceString("No_Parent"));
		parentButton = new Button (parentStyleGroup, SWT.RADIO);
		parentButton.setText (ControlPlugin.getResourceString("Parent"));
	
		/* Create a group for the decoration style controls */
		Group decorationStyleGroup = new Group(styleGroup, SWT.NULL);
		decorationStyleGroup.setLayout (new GridLayout ());
		GridData gridData = new GridData (GridData.HORIZONTAL_ALIGN_CENTER);
		gridData.horizontalSpan = 2;
		decorationStyleGroup.setLayoutData (gridData);
		decorationStyleGroup.setText (ControlPlugin.getResourceString("Decoration_Styles"));
	
		/* Create the decoration style buttons */
		noTrimButton = new Button (decorationStyleGroup, SWT.CHECK);
		noTrimButton.setText (ControlPlugin.getResourceString("SWT_NO_TRIM"));
		closeButton = new Button (decorationStyleGroup, SWT.CHECK);
		closeButton.setText (ControlPlugin.getResourceString("SWT_CLOSE"));
		titleButton = new Button (decorationStyleGroup, SWT.CHECK);
		titleButton.setText (ControlPlugin.getResourceString("SWT_TITLE"));
		minButton = new Button (decorationStyleGroup, SWT.CHECK);
		minButton.setText (ControlPlugin.getResourceString("SWT_MIN"));
		maxButton = new Button (decorationStyleGroup, SWT.CHECK);
		maxButton.setText (ControlPlugin.getResourceString("SWT_MAX"));
		borderButton = new Button (decorationStyleGroup, SWT.CHECK);
		borderButton.setText (ControlPlugin.getResourceString("SWT_BORDER"));
		resizeButton = new Button (decorationStyleGroup, SWT.CHECK);
		resizeButton.setText (ControlPlugin.getResourceString("SWT_RESIZE"));
	
		/* Create the "create" and "closeAll" buttons */
		createButton = new Button (styleGroup, SWT.NULL);
		gridData = new GridData (GridData.HORIZONTAL_ALIGN_CENTER);
		createButton.setLayoutData (gridData);
		createButton.setText (ControlPlugin.getResourceString("Create_Shell"));
		closeAllButton = new Button (styleGroup, SWT.NULL);
		closeAllButton.setText (ControlPlugin.getResourceString("Close_All_Shells"));
		closeAllButton.setLayoutData (new GridData (GridData.HORIZONTAL_ALIGN_CENTER));
	
		/* Add the listeners */
		createButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				createButtonSelected(e);
			};
		});
		closeAllButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				closeAllShells ();
			};
		});
		SelectionListener decorationButtonListener = new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				decorationButtonSelected(event);
			};
		};
		noTrimButton.addSelectionListener (decorationButtonListener);
		closeButton.addSelectionListener (decorationButtonListener);
		titleButton.addSelectionListener (decorationButtonListener);
		minButton.addSelectionListener (decorationButtonListener);
		maxButton.addSelectionListener (decorationButtonListener);
		borderButton.addSelectionListener (decorationButtonListener);
		resizeButton.addSelectionListener (decorationButtonListener);
	
		/* Set the default state */
		noParentButton.setSelection (true);
	}
	
	/**
	 * Handle a decoration button selection event.
	 *
	 * @param event org.eclipse.swt.events.SelectionEvent
	 */
	public void decorationButtonSelected(SelectionEvent event) {
	
		/*
		 * Make sure if the No Trim button is selected then
		 * all other decoration buttons are deselected.
		 */
		Button widget = (Button) event.widget;
		if (widget.getSelection() && widget != noTrimButton) {
			noTrimButton.setSelection (false);
			return;
		}
		if (widget.getSelection() && widget == noTrimButton) {
			closeButton.setSelection (false);
			titleButton.setSelection (false);
			minButton.setSelection (false);
			maxButton.setSelection (false);
			borderButton.setSelection (false);
			resizeButton.setSelection (false);
			return;
		}
	}
	
	/**
	 * Gets the text for the tab folder item.
	 */
	String getTabText () {
		return ControlPlugin.getResourceString("Shell");
	}
}

Back to the top