root/branches/0.2/controlexample/combotab.d

Revision 46, 4.3 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.combotab;
12
13 private {
14 import swt.all;
15 import controlexample.tab;
16 import controlexample.controlexample;
17 }
18
19 class ComboTab : Tab {
20
21     /* Example widgets and groups that contain them */
22     Combo combo1;
23     Group comboGroup;
24    
25     /* Style widgets added to the "Style" group */
26     Button dropDownButton, readOnlyButton, simpleButton;
27    
28     static String [] ListData;
29
30     /**
31      * Creates the Tab within a given instance_ren of ControlExample.
32      */
33     this(ControlExample instance_ren) {
34         if(ListData is null){
35             ListData ~= ControlExample.getResourceString("ListData0_0");
36             ListData ~= ControlExample.getResourceString("ListData0_1");
37             ListData ~= ControlExample.getResourceString("ListData0_2");
38             ListData ~= ControlExample.getResourceString("ListData0_3");
39             ListData ~= ControlExample.getResourceString("ListData0_4");
40             ListData ~= ControlExample.getResourceString("ListData0_5");
41             ListData ~= ControlExample.getResourceString("ListData0_6");
42             ListData ~= ControlExample.getResourceString("ListData0_7");
43             ListData ~= ControlExample.getResourceString("ListData0_8");
44         }
45
46         super(instance_ren);
47     }
48    
49     /**
50      * Creates the "Example" group.
51      */
52     void createExampleGroup () {
53         super.createExampleGroup ();
54        
55         /* Create a group for the combo box */
56         comboGroup = new Group (exampleGroup, SWT.NONE);
57         comboGroup.setLayout (new GridLayout ());
58         comboGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
59         comboGroup.setText ("Combo");
60     }
61    
62     /**
63      * Creates the "Example" widgets.
64      */
65     void createExampleWidgets () {
66        
67         /* Compute the widget style */
68         int style = getDefaultStyle();
69         if (dropDownButton.getSelection ()) style |= SWT.DROP_DOWN;
70         if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY;
71         if (simpleButton.getSelection ()) style |= SWT.SIMPLE;
72        
73         /* Create the example widgets */
74         combo1 = new Combo (comboGroup, style);
75         combo1.setItems (ListData);
76         if (ListData.length >= 3) {
77             combo1.setText(ListData [2]);
78         }
79     }
80    
81     /**
82      * Creates the tab folder page.
83      *
84      * @param tabFolder org.eclipse.swt.widgets.TabFolder
85      * @return the new page for the tab folder
86      */
87     Composite createTabFolderPage (TabFolder tabFolder) {
88         super.createTabFolderPage (tabFolder);
89
90         /*
91          * Add a resize listener to the tabFolderPage so that
92          * if the user types into the example widget to change
93          * its preferred size, and then resizes the shell, we
94          * recalculate the preferred size correctly.
95          */
96         tabFolderPage.handleEvent(this, SWT.Resize, &setExampleWidgetSize);
97        
98         return tabFolderPage;
99     }
100
101     /**
102      * Creates the "Style" group.
103      */
104     void createStyleGroup () {
105         super.createStyleGroup ();
106    
107         /* Create the extra widgets */
108         dropDownButton = new Button (styleGroup, SWT.RADIO);
109         dropDownButton.setText ("SWT.DROP_DOWN");
110         simpleButton = new Button (styleGroup, SWT.RADIO);
111         simpleButton.setText("SWT.SIMPLE");
112         readOnlyButton = new Button (styleGroup, SWT.CHECK);
113         readOnlyButton.setText ("SWT.READ_ONLY");
114     }
115    
116     /**
117      * Gets the "Example" widget children.
118      */
119     Control [] getExampleWidgets () {
120         Control[] result;
121         result ~= combo1;
122         return result;
123     }
124    
125     /**
126      * Gets the text for the tab folder item.
127      */
128     String getTabText () {
129         return "Combo";
130     }
131    
132     /**
133      * Sets the state of the "Example" widgets.
134      */
135     void setExampleWidgetState () {
136         super.setExampleWidgetState ();
137         dropDownButton.setSelection ((combo1.getStyle () & SWT.DROP_DOWN) != 0);
138         simpleButton.setSelection ((combo1.getStyle () & SWT.SIMPLE) != 0);
139         readOnlyButton.setSelection ((combo1.getStyle () & SWT.READ_ONLY) != 0);
140         readOnlyButton.setEnabled(!simpleButton.getSelection());
141     }
142 }
Note: See TracBrowser for help on using the browser.