root/branches/0.2/controlexample/alignabletab.d

Revision 46, 2.9 kB (checked in by JJR, 4 years ago)

* 0.2 Branch added: New working DWT version submitted by Shawn Liu.

Line 
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 module controlexample.alignabletab;
12
13 private {
14 import swt.all;
15 import controlexample.tab;
16 import controlexample.controlexample;
17 }
18 /**
19  * <code>AlignableTab</code> is the abstract
20  * superclass of example controls that can be
21  * aligned.
22  */
23 abstract class AlignableTab : Tab {
24
25     /* Alignment Controls */
26     Button leftButton, rightButton, centerButton;
27
28     /* Alignment Group */
29     Group alignmentGroup;
30
31     /**
32      * Creates the Tab within a given instance_ren of ControlExample.
33      */
34     this(ControlExample instance_ren) {
35         super(instance_ren);
36     }
37
38     /**
39      * Creates the "Control" group.
40      */
41     void createControlGroup () {
42         super.createControlGroup ();
43        
44         /* Create the group */
45         alignmentGroup = new Group (controlGroup, SWT.NONE);
46         alignmentGroup.setLayout (new GridLayout ());
47         alignmentGroup.setLayoutData (new GridData(GridData.HORIZONTAL_ALIGN_FILL |
48             GridData.VERTICAL_ALIGN_FILL));
49         alignmentGroup.setText (ControlExample.getResourceString("Alignment"));
50    
51         /* Create the controls */
52         leftButton = new Button (alignmentGroup, SWT.RADIO);
53         leftButton.setText (ControlExample.getResourceString("Left"));
54         centerButton = new Button (alignmentGroup, SWT.RADIO);
55         centerButton.setText(ControlExample.getResourceString("Center"));
56         rightButton = new Button (alignmentGroup, SWT.RADIO);
57         rightButton.setText (ControlExample.getResourceString("Right"));
58    
59         /* Add the listeners */
60         void widgetSelected(SelectionEvent event) {
61             AlignableTab c = cast(AlignableTab)event.cData;
62             if (!(cast(Button) event.widget).getSelection ()) return;
63             c.setExampleWidgetAlignment ();
64         };
65         leftButton.handleSelection(this, &widgetSelected);
66         centerButton.handleSelection(this, &widgetSelected);
67         rightButton.handleSelection(this, &widgetSelected);
68     }
69    
70     /**
71      * Sets the alignment of the "Example" widgets.
72      */
73     abstract void setExampleWidgetAlignment ();
74    
75     /**
76      * Sets the state of the "Example" widgets.
77      */
78     void setExampleWidgetState () {
79         super.setExampleWidgetState ();
80         Control [] controls = getExampleWidgets ();
81         if (controls.length != 0) {
82             leftButton.setSelection ((controls [0].getStyle () & SWT.LEFT) != 0);
83             centerButton.setSelection ((controls [0].getStyle () & SWT.CENTER) != 0);
84             rightButton.setSelection ((controls [0].getStyle () & SWT.RIGHT) != 0);
85         }
86     }
87 }
Note: See TracBrowser for help on using the browser.