comparison examples/controlexample/SashTab.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.SashTab;
14
15
16
17 import dwt.DWT;
18 import dwt.events.ControlAdapter;
19 import dwt.events.ControlEvent;
20 import dwt.events.SelectionAdapter;
21 import dwt.events.SelectionEvent;
22 import dwt.graphics.Rectangle;
23 import dwt.layout.FillLayout;
24 import dwt.layout.GridData;
25 import dwt.widgets.Button;
26 import dwt.widgets.Composite;
27 import dwt.widgets.Group;
28 import dwt.widgets.List;
29 import dwt.widgets.Sash;
30 import dwt.widgets.Text;
31 import dwt.widgets.Widget;
32
33 import examples.controlexample.Tab;
34 import examples.controlexample.ControlExample;
35
36 class SashTab : Tab {
37 /* Example widgets and groups that contain them */
38 Sash hSash, vSash;
39 Composite sashComp;
40 Group sashGroup;
41 List list1, list2, list3;
42 Text text;
43 Button smoothButton;
44
45 static char[] [] ListData0;
46 static char[] [] ListData1;
47
48 /* Constants */
49 static final int SASH_WIDTH = 3;
50 static final int SASH_LIMIT = 20;
51
52 /**
53 * Creates the Tab within a given instance of ControlExample.
54 */
55 this(ControlExample instance) {
56 super(instance);
57 if( ListData0.length is 0 ){
58 ListData0 = [
59 ControlExample.getResourceString("ListData0_0"),
60 ControlExample.getResourceString("ListData0_1"),
61 ControlExample.getResourceString("ListData0_2"),
62 ControlExample.getResourceString("ListData0_3"),
63 ControlExample.getResourceString("ListData0_4"),
64 ControlExample.getResourceString("ListData0_5"),
65 ControlExample.getResourceString("ListData0_6"),
66 ControlExample.getResourceString("ListData0_7"),
67 ControlExample.getResourceString("ListData0_8")];
68 }
69 if( ListData1.length is 0 ){
70 ListData1 = [
71 ControlExample.getResourceString("ListData1_0"),
72 ControlExample.getResourceString("ListData1_1"),
73 ControlExample.getResourceString("ListData1_2"),
74 ControlExample.getResourceString("ListData1_3"),
75 ControlExample.getResourceString("ListData1_4"),
76 ControlExample.getResourceString("ListData1_5"),
77 ControlExample.getResourceString("ListData1_6"),
78 ControlExample.getResourceString("ListData1_7"),
79 ControlExample.getResourceString("ListData1_8")];
80 }
81 }
82
83 /**
84 * Creates the "Example" group.
85 */
86 void createExampleGroup () {
87 super.createExampleGroup ();
88 exampleGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true));
89 exampleGroup.setLayout(new FillLayout());
90
91 /* Create a group for the sash widgets */
92 sashGroup = new Group (exampleGroup, DWT.NONE);
93 FillLayout layout = new FillLayout();
94 layout.marginHeight = layout.marginWidth = 5;
95 sashGroup.setLayout(layout);
96 sashGroup.setText ("Sash");
97 }
98
99 /**
100 * Creates the "Example" widgets.
101 */
102 void createExampleWidgets () {
103 /*
104 * Create the page. This example does not use layouts.
105 */
106 sashComp = new Composite(sashGroup, DWT.BORDER);
107
108 /* Create the list and text widgets */
109 list1 = new List (sashComp, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER);
110 list1.setItems (ListData0);
111 list2 = new List (sashComp, DWT.V_SCROLL | DWT.H_SCROLL | DWT.BORDER);
112 list2.setItems (ListData1);
113 text = new Text (sashComp, DWT.MULTI | DWT.BORDER);
114 text.setText (ControlExample.getResourceString("Multi_line"));
115
116 /* Create the sashes */
117 int style = getDefaultStyle();
118 if (smoothButton.getSelection()) style |= DWT.SMOOTH;
119 vSash = new Sash (sashComp, DWT.VERTICAL | style);
120 hSash = new Sash (sashComp, DWT.HORIZONTAL | style);
121
122 /* Add the listeners */
123 hSash.addSelectionListener (new class() SelectionAdapter {
124 public void widgetSelected (SelectionEvent event) {
125 Rectangle rect = vSash.getParent().getClientArea();
126 event.y = Math.min (Math.max (event.y, SASH_LIMIT), rect.height - SASH_LIMIT);
127 if (event.detail !is DWT.DRAG) {
128 hSash.setBounds (event.x, event.y, event.width, event.height);
129 layout ();
130 }
131 }
132 });
133 vSash.addSelectionListener (new class() SelectionAdapter {
134 public void widgetSelected (SelectionEvent event) {
135 Rectangle rect = vSash.getParent().getClientArea();
136 event.x = Math.min (Math.max (event.x, SASH_LIMIT), rect.width - SASH_LIMIT);
137 if (event.detail !is DWT.DRAG) {
138 vSash.setBounds (event.x, event.y, event.width, event.height);
139 layout ();
140 }
141 }
142 });
143 sashComp.addControlListener (new class() ControlAdapter {
144 public void controlResized (ControlEvent event) {
145 resized ();
146 }
147 });
148 }
149
150 /**
151 * Creates the "Size" group. The "Size" group contains
152 * controls that allow the user to change the size of
153 * the example widgets.
154 */
155 void createSizeGroup () {
156 }
157
158 /**
159 * Creates the "Style" group.
160 */
161 void createStyleGroup() {
162 super.createStyleGroup ();
163
164 /* Create the extra widgets */
165 smoothButton = new Button (styleGroup, DWT.CHECK);
166 smoothButton.setText("DWT.SMOOTH");
167 }
168
169 void disposeExampleWidgets () {
170 sashComp.dispose();
171 sashComp = null;
172 }
173
174 /**
175 * Gets the "Example" widget children.
176 */
177 Widget [] getExampleWidgets () {
178 return [ cast(Widget) hSash, vSash ];
179 }
180
181 /**
182 * Returns a list of set/get API method names (without the set/get prefix)
183 * that can be used to set/get values in the example control(s).
184 */
185 char[][] getMethodNames() {
186 return ["ToolTipText"];
187 }
188
189 /**
190 * Gets the text for the tab folder item.
191 */
192 char[] getTabText () {
193 return "Sash";
194 }
195
196 /**
197 * Layout the list and text widgets according to the new
198 * positions of the sashes..events.SelectionEvent
199 */
200 void layout () {
201
202 Rectangle clientArea = sashComp.getClientArea ();
203 Rectangle hSashBounds = hSash.getBounds ();
204 Rectangle vSashBounds = vSash.getBounds ();
205
206 list1.setBounds (0, 0, vSashBounds.x, hSashBounds.y);
207 list2.setBounds (vSashBounds.x + vSashBounds.width, 0, clientArea.width - (vSashBounds.x + vSashBounds.width), hSashBounds.y);
208 text.setBounds (0, hSashBounds.y + hSashBounds.height, clientArea.width, clientArea.height - (hSashBounds.y + hSashBounds.height));
209
210 /**
211 * If the horizontal sash has been moved then the vertical
212 * sash is either too long or too short and its size must
213 * be adjusted.
214 */
215 vSashBounds.height = hSashBounds.y;
216 vSash.setBounds (vSashBounds);
217 }
218 /**
219 * Sets the size of the "Example" widgets.
220 */
221 void setExampleWidgetSize () {
222 sashGroup.layout (true);
223 }
224
225 /**
226 * Sets the state of the "Example" widgets.
227 */
228 void setExampleWidgetState () {
229 super.setExampleWidgetState ();
230 smoothButton.setSelection ((hSash.getStyle () & DWT.SMOOTH) !is 0);
231 }
232
233 /**
234 * Handle the shell resized event.
235 */
236 void resized () {
237
238 /* Get the client area for the shell */
239 Rectangle clientArea = sashComp.getClientArea ();
240
241 /*
242 * Make list 1 half the width and half the height of the tab leaving room for the sash.
243 * Place list 1 in the top left quadrant of the tab.
244 */
245 Rectangle list1Bounds = new Rectangle (0, 0, (clientArea.width - SASH_WIDTH) / 2, (clientArea.height - SASH_WIDTH) / 2);
246 list1.setBounds (list1Bounds);
247
248 /*
249 * Make list 2 half the width and half the height of the tab leaving room for the sash.
250 * Place list 2 in the top right quadrant of the tab.
251 */
252 list2.setBounds (list1Bounds.width + SASH_WIDTH, 0, clientArea.width - (list1Bounds.width + SASH_WIDTH), list1Bounds.height);
253
254 /*
255 * Make the text area the full width and half the height of the tab leaving room for the sash.
256 * Place the text area in the bottom half of the tab.
257 */
258 text.setBounds (0, list1Bounds.height + SASH_WIDTH, clientArea.width, clientArea.height - (list1Bounds.height + SASH_WIDTH));
259
260 /* Position the sashes */
261 vSash.setBounds (list1Bounds.width, 0, SASH_WIDTH, list1Bounds.height);
262 hSash.setBounds (0, list1Bounds.height, clientArea.width, SASH_WIDTH);
263 }
264 }