comparison examples/controlexample/TabFolderTab.d @ 78:4a04b6759f98

Clean up directory names
author John Reimer <terminal.node@gmail.com>
date Sat, 10 May 2008 13:32:45 -0700
parents
children eb84f9418bbf
comparison
equal deleted inserted replaced
76:04f122e90b0a 78:4a04b6759f98
1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module examples.controlexample.TabFolderTab;
14
15
16
17 import dwt.DWT;
18 import dwt.layout.GridData;
19 import dwt.layout.GridLayout;
20 import dwt.widgets.Button;
21 import dwt.widgets.Group;
22 import dwt.widgets.Item;
23 import dwt.widgets.TabFolder;
24 import dwt.widgets.TabItem;
25 import dwt.widgets.Text;
26 import dwt.widgets.Widget;
27
28 import examples.controlexample.Tab;
29 import examples.controlexample.ControlExample;
30 import tango.text.convert.Format;
31
32 class TabFolderTab : Tab {
33 /* Example widgets and groups that contain them */
34 TabFolder tabFolder1;
35 Group tabFolderGroup;
36
37 /* Style widgets added to the "Style" group */
38 Button topButton, bottomButton;
39
40 static char[] [] TabItems1;
41
42 /**
43 * Creates the Tab within a given instance of ControlExample.
44 */
45 this(ControlExample instance) {
46 super(instance);
47 if( TabItems1.length is 0 ){
48 TabItems1 = [
49 ControlExample.getResourceString("TabItem1_0"),
50 ControlExample.getResourceString("TabItem1_1"),
51 ControlExample.getResourceString("TabItem1_2")];
52 }
53 }
54
55 /**
56 * Creates the "Example" group.
57 */
58 void createExampleGroup () {
59 super.createExampleGroup ();
60
61 /* Create a group for the TabFolder */
62 tabFolderGroup = new Group (exampleGroup, DWT.NONE);
63 tabFolderGroup.setLayout (new GridLayout ());
64 tabFolderGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
65 tabFolderGroup.setText ("TabFolder");
66 }
67
68 /**
69 * Creates the "Example" widgets.
70 */
71 void createExampleWidgets () {
72
73 /* Compute the widget style */
74 int style = getDefaultStyle();
75 if (topButton.getSelection ()) style |= DWT.TOP;
76 if (bottomButton.getSelection ()) style |= DWT.BOTTOM;
77 if (borderButton.getSelection ()) style |= DWT.BORDER;
78
79 /* Create the example widgets */
80 tabFolder1 = new TabFolder (tabFolderGroup, style);
81 for (int i = 0; i < TabItems1.length; i++) {
82 TabItem item = new TabItem(tabFolder1, DWT.NONE);
83 item.setText(TabItems1[i]);
84 item.setToolTipText(Format( ControlExample.getResourceString("Tooltip"), TabItems1[i] ));
85 Text content = new Text(tabFolder1, DWT.WRAP | DWT.MULTI);
86 content.setText(Format( "{}: {}", ControlExample.getResourceString("TabItem_content"), i));
87 item.setControl(content);
88 }
89 }
90
91 /**
92 * Creates the "Style" group.
93 */
94 void createStyleGroup() {
95 super.createStyleGroup ();
96
97 /* Create the extra widgets */
98 topButton = new Button (styleGroup, DWT.RADIO);
99 topButton.setText ("DWT.TOP");
100 topButton.setSelection(true);
101 bottomButton = new Button (styleGroup, DWT.RADIO);
102 bottomButton.setText ("DWT.BOTTOM");
103 borderButton = new Button (styleGroup, DWT.CHECK);
104 borderButton.setText ("DWT.BORDER");
105 }
106
107 /**
108 * Gets the "Example" widget children's items, if any.
109 *
110 * @return an array containing the example widget children's items
111 */
112 Item [] getExampleWidgetItems () {
113 return tabFolder1.getItems();
114 }
115
116 /**
117 * Gets the "Example" widget children.
118 */
119 Widget [] getExampleWidgets () {
120 return [cast(Widget) tabFolder1 ];
121 }
122
123 /**
124 * Returns a list of set/get API method names (without the set/get prefix)
125 * that can be used to set/get values in the example control(s).
126 */
127 char[][] getMethodNames() {
128 return ["Selection", "SelectionIndex"];
129 }
130
131 char[] setMethodName(char[] methodRoot) {
132 /* Override to handle special case of int getSelectionIndex()/setSelection(int) */
133 return (methodRoot == "SelectionIndex") ? "setSelection" : "set" ~ methodRoot;
134 }
135
136 //PROTING_LEFT
137 /+
138 Object[] parameterForType(char[] typeName, char[] value, Widget widget) {
139 if (value.length is 0 ) return new Object[] {new TabItem[0]};
140 if (typeName.equals("org.eclipse.swt.widgets.TabItem")) {
141 TabItem item = findItem(value, ((TabFolder) widget).getItems());
142 if (item !is null) return new Object[] {item};
143 }
144 if (typeName.equals("[Lorg.eclipse.swt.widgets.TabItem;")) {
145 char[][] values = split(value, ',');
146 TabItem[] items = new TabItem[values.length];
147 for (int i = 0; i < values.length; i++) {
148 items[i] = findItem(values[i], ((TabFolder) widget).getItems());
149 }
150 return new Object[] {items};
151 }
152 return super.parameterForType(typeName, value, widget);
153 }
154 +/
155 TabItem findItem(char[] value, TabItem[] items) {
156 for (int i = 0; i < items.length; i++) {
157 TabItem item = items[i];
158 if (item.getText() ==/*eq*/ value) return item;
159 }
160 return null;
161 }
162
163 /**
164 * Gets the short text for the tab folder item.
165 */
166 public char[] getShortTabText() {
167 return "TF";
168 }
169
170 /**
171 * Gets the text for the tab folder item.
172 */
173 char[] getTabText () {
174 return "TabFolder";
175 }
176
177 /**
178 * Sets the state of the "Example" widgets.
179 */
180 void setExampleWidgetState () {
181 super.setExampleWidgetState ();
182 topButton.setSelection ((tabFolder1.getStyle () & DWT.TOP) !is 0);
183 bottomButton.setSelection ((tabFolder1.getStyle () & DWT.BOTTOM) !is 0);
184 borderButton.setSelection ((tabFolder1.getStyle () & DWT.BORDER) !is 0);
185 }
186 }