root/branches/0.2/controlexample/tabfoldertab.d

Revision 46, 4.1 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.tabfoldertab;
12
13 private {
14 import swt.all;
15 import controlexample.tab;
16 import controlexample.controlexample;
17 }
18
19
20 class TabFolderTab : Tab {
21     /* Example widgets and groups that contain them */
22     TabFolder tabFolder1;
23     Group tabFolderGroup;
24    
25     /* Style widgets added to the "Style" group */
26     Button topButton, bottomButton;
27
28     static String [] TabItems1;
29
30     /**
31      * Creates the Tab within a given instance_ren of ControlExample.
32      */
33     this(ControlExample instance_ren) {
34        
35         if(TabItems1 is null) {
36             TabItems1 ~= ControlExample.getResourceString("TabItem1_0"),
37             TabItems1 ~= ControlExample.getResourceString("TabItem1_1"),
38             TabItems1 ~= ControlExample.getResourceString("TabItem1_2");
39         };
40         super(instance_ren);
41
42     }
43    
44     /**
45      * Creates the "Example" group.
46      */
47     void createExampleGroup () {
48         super.createExampleGroup ();
49        
50         /* Create a group for the TabFolder */
51         tabFolderGroup = new Group (exampleGroup, SWT.NONE);
52         tabFolderGroup.setLayout (new GridLayout ());
53         tabFolderGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
54         tabFolderGroup.setText ("TabFolder");
55     }
56    
57     /**
58      * Creates the "Example" widgets.
59      */
60     void createExampleWidgets () {
61        
62         /* Compute the widget style */
63         int style = getDefaultStyle();
64         if (topButton.getSelection ()) style |= SWT.TOP;
65         if (bottomButton.getSelection ()) style |= SWT.BOTTOM;
66         if (borderButton.getSelection ()) style |= SWT.BORDER;
67
68         /* Create the example widgets */
69         tabFolder1 = new TabFolder (tabFolderGroup, style);
70         for (int i = 0; i < TabItems1.length; i++) {
71             TabItem item = new TabItem(tabFolder1, SWT.NONE);
72             item.setText(TabItems1[i]);
73             Text content = new Text(tabFolder1, SWT.WRAP | SWT.MULTI);
74             content.setText(ControlExample.getResourceString("TabItem_content") ~ ": " ~ std.string.toString(i));
75             item.setControl(content);
76         }
77     }
78    
79     /**
80      * Creates the "Style" group.
81      */
82     void createStyleGroup() {
83         super.createStyleGroup ();
84        
85         /* Create the extra widgets */
86         topButton = new Button (styleGroup, SWT.RADIO);
87         topButton.setText ("SWT.TOP");
88         topButton.setSelection(true);
89         bottomButton = new Button (styleGroup, SWT.RADIO);
90         bottomButton.setText ("SWT.BOTTOM");
91         borderButton = new Button (styleGroup, SWT.CHECK);
92         borderButton.setText ("SWT.BORDER");
93    
94         /* Add the listeners */
95         void widgetSelected(SelectionEvent event) {
96             TabFolderTab c = cast(TabFolderTab)event.cData;
97             if (!(cast(Button) event.widget).getSelection ()) return;
98             c.recreateExampleWidgets ();
99
100         };
101         topButton.handleSelection(this, &widgetSelected);
102         bottomButton.handleSelection(this, &widgetSelected);
103     }
104    
105     /**
106      * Gets the "Example" widget children's items, if any.
107      *
108      * @return an array containing the example widget children's items
109      */
110     Item [] getExampleWidgetItems () {
111         return tabFolder1.getItems();
112     }
113    
114     /**
115      * Gets the "Example" widget children.
116      */
117     Control [] getExampleWidgets () {
118         Control[] controls;
119         controls ~= tabFolder1;
120         return controls;
121     }
122    
123     /**
124      * Gets the text for the tab folder item.
125      */
126     String getTabText () {
127         return "TabFolder";
128     }
129
130     /**
131      * Sets the state of the "Example" widgets.
132      */
133     void setExampleWidgetState () {
134         super.setExampleWidgetState ();
135         topButton.setSelection ((tabFolder1.getStyle () & SWT.TOP) != 0);
136         bottomButton.setSelection ((tabFolder1.getStyle () & SWT.BOTTOM) != 0);
137         borderButton.setSelection ((tabFolder1.getStyle () & SWT.BORDER) != 0);
138     }
139 }
Note: See TracBrowser for help on using the browser.