summaryrefslogtreecommitdiffstats
path: root/examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/AlignableTab.java
blob: bfd1c60de250071db90700fd3ae5c5a727b8ecd0 (plain)
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
package org.eclipse.swt.examples.controlexample;

/*

 * (c) Copyright IBM Corp. 2000, 2001.

 * All Rights Reserved

 */

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

/**

 * <code>AlignableTab</code> is the abstract

 * superclass of example controls that can be

 * aligned.

 */
abstract class AlignableTab extends Tab {

	/* Allignment Controls */
	Button leftButton, rightButton, centerButton;

	/* Alignment Group */
	Group allignmentGroup;

	/**

	 * Creates the Tab within a given instance of ControlExample.

	 */
	AlignableTab(ControlExample instance) {
		super(instance);
	}

	/**

	 * Creates the "Control" group. 

	 */
	void createControlGroup () {
		super.createControlGroup ();
		
		/* Create the group */
		allignmentGroup = new Group (controlGroup, SWT.NULL);
		allignmentGroup.setLayout (new GridLayout ());
		allignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL |
			GridData.VERTICAL_ALIGN_FILL));
		allignmentGroup.setText (ControlExample.getResourceString("Alignment"));
	
		/* Create the controls */
		leftButton = new Button (allignmentGroup, SWT.RADIO);
		leftButton.setText (ControlExample.getResourceString("Left"));
		centerButton = new Button (allignmentGroup, SWT.RADIO);
		centerButton.setText(ControlExample.getResourceString("Center"));
		rightButton = new Button (allignmentGroup, SWT.RADIO);
		rightButton.setText (ControlExample.getResourceString("Right"));
	
		/* Add the listeners */
		SelectionListener selectionListener = new SelectionAdapter () {
			public void widgetSelected(SelectionEvent event) {
				if (!((Button) event.widget).getSelection ()) return;
				setExampleWidgetAlignment ();
			};
		};
		leftButton.addSelectionListener (selectionListener);
		centerButton.addSelectionListener (selectionListener);
		rightButton.addSelectionListener (selectionListener);
	}
	
	/**

	 * Sets the alignment of the "Example" widgets.

	 */
	abstract void setExampleWidgetAlignment ();
	
	/**

	 * Sets the state of the "Example" widgets.

	 */
	void setExampleWidgetState () {
		super.setExampleWidgetState ();
		Control [] controls = getExampleWidgets ();
		if (controls.length != 0) {
			leftButton.setSelection ((controls [0].getStyle () & SWT.LEFT) != 0);
			centerButton.setSelection ((controls [0].getStyle () & SWT.CENTER) != 0);
			rightButton.setSelection ((controls [0].getStyle () & SWT.RIGHT) != 0);
		}
	}
}