Skip to main content
summaryrefslogtreecommitdiffstats
blob: 036842b1b3fe3d676ca3765937d9e5a4983599cd (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
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.*;

/**
 * <code>ButtonTab</code> is the class that
 * demonstrates SWT buttons.
 */
class ButtonTab extends AlignableTab {

	/* Example widgets and groups that contain them */
	Button button1, button2, button3, button4, button5, button6;
	Group textButtonGroup, imageButtonGroup;

	/* Allignment widgets added to the "Control" group */
	Button upButton, downButton;

	/* Style widgets added to the "Style" group */
	Button pushButton, checkButton, radioButton, toggleButton, arrowButton;
	
	/**
	 * Creates the "Control" group. 
	 */
	void createControlGroup () {
		super.createControlGroup ();
	
		/* Create the controls */
		upButton = new Button (allignmentGroup, SWT.RADIO);
		upButton.setText (ControlPlugin.getResourceString("Up"));
		downButton = new Button (allignmentGroup, SWT.RADIO);
		downButton.setText (ControlPlugin.getResourceString("Down"));
	
		/* Add the listeners */
		SelectionListener selectionListener = new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				if (!((Button) event.widget).getSelection()) return;
				setExampleWidgetAlignment ();
			};
		};
		upButton.addSelectionListener(selectionListener);
		downButton.addSelectionListener(selectionListener);
	}
	
	/**
	 * Creates the "Example" group.
	 */
	void createExampleGroup () {
		super.createExampleGroup ();
		
		/* Create a group for text buttons */
		textButtonGroup = new Group(exampleGroup, SWT.NONE);
		GridLayout gridLayout = new GridLayout ();
		textButtonGroup.setLayout(gridLayout);
		gridLayout.numColumns = 3;
		textButtonGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
		textButtonGroup.setText (ControlPlugin.getResourceString("Text_Buttons"));
	
		/* Create a group for the image buttons */
		imageButtonGroup = new Group(exampleGroup, SWT.NONE);
		gridLayout = new GridLayout();
		imageButtonGroup.setLayout(gridLayout);
		gridLayout.numColumns = 3;
		imageButtonGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
		imageButtonGroup.setText (ControlPlugin.getResourceString("Image_Buttons"));
	}
	
	/**
	 * Creates the "Example" widgets.
	 */
	void createExampleWidgets () {
	
		/* Compute the widget style */
		int style = SWT.NONE;
		if (pushButton.getSelection()) style |= SWT.PUSH;
		if (checkButton.getSelection()) style |= SWT.CHECK;
		if (radioButton.getSelection()) style |= SWT.RADIO;
		if (toggleButton.getSelection()) style |= SWT.TOGGLE;
		if (arrowButton.getSelection()) style |= SWT.ARROW;
		if (borderButton.getSelection()) style |= SWT.BORDER;
	
		/* Create the example widgets */
		button1 = new Button(textButtonGroup, style);
		button1.setText(ControlPlugin.getResourceString("One"));
		button2 = new Button(textButtonGroup, style);
		button2.setText(ControlPlugin.getResourceString("Two"));
		button3 = new Button(textButtonGroup, style);
		button3.setText(ControlPlugin.getResourceString("Three"));
		button4 = new Button(imageButtonGroup, style);
		button4.setImage(ControlPlugin.images[ControlPlugin.ciClosedFolder]);
		button5 = new Button(imageButtonGroup, style);
		button5.setImage(ControlPlugin.images[ControlPlugin.ciOpenFolder]);
		button6 = new Button(imageButtonGroup, style);
		button6.setImage(ControlPlugin.images[ControlPlugin.ciTarget]);
	}
	
	/**
	 * Creates the "Style" group.
	 */
	void createStyleGroup() {
		super.createStyleGroup ();
	
		/* Create the extra widgets */
		pushButton = new Button (styleGroup, SWT.RADIO);
		pushButton.setText(ControlPlugin.getResourceString("SWT_PUSH"));
		checkButton = new Button (styleGroup, SWT.RADIO);
		checkButton.setText (ControlPlugin.getResourceString("SWT_CHECK"));
		radioButton = new Button (styleGroup, SWT.RADIO);
		radioButton.setText (ControlPlugin.getResourceString("SWT_RADIO"));
		toggleButton = new Button (styleGroup, SWT.RADIO);
		toggleButton.setText (ControlPlugin.getResourceString("SWT_TOGGLE"));
		arrowButton = new Button (styleGroup, SWT.RADIO);
		arrowButton.setText (ControlPlugin.getResourceString("SWT_ARROW"));
		borderButton = new Button (styleGroup, SWT.CHECK);
		borderButton.setText (ControlPlugin.getResourceString("SWT_BORDER"));
	}
	
	/**
	 * Gets the "Example" widget children.
	 */
	Control [] getExampleWidgets () {
		return new Control [] {button1, button2, button3, button4, button5, button6};
	}
	
	/**
	 * Gets the text for the tab folder item.
	 */
	String getTabText () {
		return ControlPlugin.getResourceString("Button");
	}
	
	/**
	 * Sets the alignment of the "Example" widgets.
	 */
	void setExampleWidgetAlignment () {
		int allignment = 0;
		if (leftButton.getSelection ()) allignment = SWT.LEFT;
		if (centerButton.getSelection ()) allignment = SWT.CENTER;
		if (rightButton.getSelection ()) allignment = SWT.RIGHT;
		if (upButton.getSelection ()) allignment = SWT.UP;
		if (downButton.getSelection ()) allignment = SWT.DOWN;
		button1.setAlignment (allignment);
		button2.setAlignment (allignment);
		button3.setAlignment (allignment);
		button4.setAlignment (allignment);
		button5.setAlignment (allignment);
		button6.setAlignment (allignment);
	}
	
	/**
	 * Sets the state of the "Example" widgets.
	 */
	void setExampleWidgetState () {
		super.setExampleWidgetState ();
		if (arrowButton.getSelection ()) {
			upButton.setEnabled (true);
			centerButton.setEnabled (false);
			downButton.setEnabled (true);
		} else {
			upButton.setEnabled (false);
			centerButton.setEnabled (true);
			downButton.setEnabled (false);
		}
		upButton.setSelection ((button1.getStyle () & SWT.UP) != 0);
		downButton.setSelection ((button1.getStyle () & SWT.DOWN) != 0);
		pushButton.setSelection ((button1.getStyle () & SWT.PUSH) != 0);
		checkButton.setSelection ((button1.getStyle () & SWT.CHECK) != 0);
		radioButton.setSelection ((button1.getStyle () & SWT.RADIO) != 0);
		toggleButton.setSelection ((button1.getStyle () & SWT.TOGGLE) != 0);
		arrowButton.setSelection ((button1.getStyle () & SWT.ARROW) != 0);
		borderButton.setSelection ((button1.getStyle () & SWT.BORDER) != 0);
	}
}

Back to the top