Mercurial > projects > dwt-samples
annotate examples/controlexample/TreeTab.d @ 161:eb84f9418bbf
Change module names to this not have examples in the FQN.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 01 Sep 2008 22:24:27 +0200 |
parents | 3fbc483a4599 |
children |
rev | line source |
---|---|
78 | 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 *******************************************************************************/ | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
99
diff
changeset
|
13 module controlexample.TreeTab; |
78 | 14 |
15 | |
16 import dwt.DWT; | |
17 import dwt.events.DisposeEvent; | |
18 import dwt.events.DisposeListener; | |
19 import dwt.events.SelectionAdapter; | |
20 import dwt.events.SelectionEvent; | |
21 import dwt.events.SelectionListener; | |
22 import dwt.graphics.Color; | |
23 import dwt.graphics.Font; | |
24 import dwt.graphics.FontData; | |
25 import dwt.graphics.Image; | |
26 import dwt.graphics.Point; | |
27 import dwt.graphics.RGB; | |
28 import dwt.layout.GridData; | |
29 import dwt.layout.GridLayout; | |
30 import dwt.widgets.Button; | |
31 import dwt.widgets.Event; | |
32 import dwt.widgets.Group; | |
33 import dwt.widgets.Item; | |
34 import dwt.widgets.Menu; | |
35 import dwt.widgets.MenuItem; | |
36 import dwt.widgets.TableItem; | |
37 import dwt.widgets.Tree; | |
38 import dwt.widgets.TreeColumn; | |
39 import dwt.widgets.TreeItem; | |
40 import dwt.widgets.Widget; | |
41 | |
161
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
99
diff
changeset
|
42 import controlexample.Tab; |
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
99
diff
changeset
|
43 import controlexample.ControlExample; |
eb84f9418bbf
Change module names to this not have examples in the FQN.
Frank Benoit <benoit@tionex.de>
parents:
99
diff
changeset
|
44 import controlexample.ScrollableTab; |
78 | 45 |
46 import dwt.dwthelper.utils; | |
47 | |
48 import tango.text.convert.Format; | |
49 import tango.util.Convert; | |
50 import tango.core.Exception; | |
51 | |
52 class TreeTab : ScrollableTab { | |
53 /* Example widgets and groups that contain them */ | |
54 Tree tree1, tree2; | |
55 TreeItem textNode1, imageNode1; | |
56 Group treeGroup, imageTreeGroup, itemGroup; | |
57 | |
58 /* Size widgets added to the "Size" group */ | |
59 Button packColumnsButton; | |
60 | |
61 /* Style widgets added to the "Style" group */ | |
62 Button checkButton, fullSelectionButton; | |
63 | |
64 /* Other widgets added to the "Other" group */ | |
65 Button multipleColumns, moveableColumns, resizableColumns, headerVisibleButton, sortIndicatorButton, headerImagesButton, subImagesButton, linesVisibleButton; | |
66 | |
67 /* Controls and resources added to the "Colors and Fonts" group */ | |
68 static const int ITEM_FOREGROUND_COLOR = 3; | |
69 static const int ITEM_BACKGROUND_COLOR = 4; | |
70 static const int ITEM_FONT = 5; | |
71 static const int CELL_FOREGROUND_COLOR = 6; | |
72 static const int CELL_BACKGROUND_COLOR = 7; | |
73 static const int CELL_FONT = 8; | |
74 Color itemForegroundColor, itemBackgroundColor, cellForegroundColor, cellBackgroundColor; | |
75 Font itemFont, cellFont; | |
76 | |
77 static char[] [] columnTitles; | |
78 | |
79 static char[][][] tableData; | |
80 | |
81 Point menuMouseCoords; | |
82 | |
83 /** | |
84 * Creates the Tab within a given instance of ControlExample. | |
85 */ | |
86 this(ControlExample instance) { | |
87 super(instance); | |
88 if( columnTitles.length is 0 ){ | |
89 columnTitles = [ | |
90 ControlExample.getResourceString("TableTitle_0"), | |
91 ControlExample.getResourceString("TableTitle_1"), | |
92 ControlExample.getResourceString("TableTitle_2"), | |
93 ControlExample.getResourceString("TableTitle_3")]; | |
94 } | |
95 if( tableData.length is 0 ){ | |
96 tableData = [ | |
97 [ ControlExample.getResourceString("TableLine0_0"), | |
98 ControlExample.getResourceString("TableLine0_1"), | |
99 ControlExample.getResourceString("TableLine0_2"), | |
100 ControlExample.getResourceString("TableLine0_3") ], | |
101 [ ControlExample.getResourceString("TableLine1_0"), | |
102 ControlExample.getResourceString("TableLine1_1"), | |
103 ControlExample.getResourceString("TableLine1_2"), | |
104 ControlExample.getResourceString("TableLine1_3") ], | |
105 [ ControlExample.getResourceString("TableLine2_0"), | |
106 ControlExample.getResourceString("TableLine2_1"), | |
107 ControlExample.getResourceString("TableLine2_2"), | |
108 ControlExample.getResourceString("TableLine2_3") ] ]; | |
109 } | |
110 } | |
111 | |
112 /** | |
113 * Creates the "Colors and Fonts" group. | |
114 */ | |
115 void createColorAndFontGroup () { | |
116 super.createColorAndFontGroup(); | |
117 | |
118 TableItem item = new TableItem(colorAndFontTable, DWT.None); | |
119 item.setText(ControlExample.getResourceString ("Item_Foreground_Color")); | |
120 item = new TableItem(colorAndFontTable, DWT.None); | |
121 item.setText(ControlExample.getResourceString ("Item_Background_Color")); | |
122 item = new TableItem(colorAndFontTable, DWT.None); | |
123 item.setText(ControlExample.getResourceString ("Item_Font")); | |
124 item = new TableItem(colorAndFontTable, DWT.None); | |
125 item.setText(ControlExample.getResourceString ("Cell_Foreground_Color")); | |
126 item = new TableItem(colorAndFontTable, DWT.None); | |
127 item.setText(ControlExample.getResourceString ("Cell_Background_Color")); | |
128 item = new TableItem(colorAndFontTable, DWT.None); | |
129 item.setText(ControlExample.getResourceString ("Cell_Font")); | |
130 | |
131 shell.addDisposeListener(new class() DisposeListener { | |
132 public void widgetDisposed(DisposeEvent event) { | |
133 if (itemBackgroundColor !is null) itemBackgroundColor.dispose(); | |
134 if (itemForegroundColor !is null) itemForegroundColor.dispose(); | |
135 if (itemFont !is null) itemFont.dispose(); | |
136 if (cellBackgroundColor !is null) cellBackgroundColor.dispose(); | |
137 if (cellForegroundColor !is null) cellForegroundColor.dispose(); | |
138 if (cellFont !is null) cellFont.dispose(); | |
139 itemBackgroundColor = null; | |
140 itemForegroundColor = null; | |
141 itemFont = null; | |
142 cellBackgroundColor = null; | |
143 cellForegroundColor = null; | |
144 cellFont = null; | |
145 } | |
146 }); | |
147 } | |
148 | |
149 void changeFontOrColor(int index) { | |
150 switch (index) { | |
151 case ITEM_FOREGROUND_COLOR: { | |
152 Color oldColor = itemForegroundColor; | |
153 if (oldColor is null) oldColor = textNode1.getForeground (); | |
154 colorDialog.setRGB(oldColor.getRGB()); | |
155 RGB rgb = colorDialog.open(); | |
156 if (rgb is null) return; | |
157 oldColor = itemForegroundColor; | |
158 itemForegroundColor = new Color (display, rgb); | |
159 setItemForeground (); | |
160 if (oldColor !is null) oldColor.dispose (); | |
161 } | |
162 break; | |
163 case ITEM_BACKGROUND_COLOR: { | |
164 Color oldColor = itemBackgroundColor; | |
165 if (oldColor is null) oldColor = textNode1.getBackground (); | |
166 colorDialog.setRGB(oldColor.getRGB()); | |
167 RGB rgb = colorDialog.open(); | |
168 if (rgb is null) return; | |
169 oldColor = itemBackgroundColor; | |
170 itemBackgroundColor = new Color (display, rgb); | |
171 setItemBackground (); | |
172 if (oldColor !is null) oldColor.dispose (); | |
173 } | |
174 break; | |
175 case ITEM_FONT: { | |
176 Font oldFont = itemFont; | |
177 if (oldFont is null) oldFont = textNode1.getFont (); | |
178 fontDialog.setFontList(oldFont.getFontData()); | |
179 FontData fontData = fontDialog.open (); | |
180 if (fontData is null) return; | |
181 oldFont = itemFont; | |
182 itemFont = new Font (display, fontData); | |
183 setItemFont (); | |
184 setExampleWidgetSize (); | |
185 if (oldFont !is null) oldFont.dispose (); | |
186 } | |
187 break; | |
188 case CELL_FOREGROUND_COLOR: { | |
189 Color oldColor = cellForegroundColor; | |
190 if (oldColor is null) oldColor = textNode1.getForeground (1); | |
191 colorDialog.setRGB(oldColor.getRGB()); | |
192 RGB rgb = colorDialog.open(); | |
193 if (rgb is null) return; | |
194 oldColor = cellForegroundColor; | |
195 cellForegroundColor = new Color (display, rgb); | |
196 setCellForeground (); | |
197 if (oldColor !is null) oldColor.dispose (); | |
198 } | |
199 break; | |
200 case CELL_BACKGROUND_COLOR: { | |
201 Color oldColor = cellBackgroundColor; | |
202 if (oldColor is null) oldColor = textNode1.getBackground (1); | |
203 colorDialog.setRGB(oldColor.getRGB()); | |
204 RGB rgb = colorDialog.open(); | |
205 if (rgb is null) return; | |
206 oldColor = cellBackgroundColor; | |
207 cellBackgroundColor = new Color (display, rgb); | |
208 setCellBackground (); | |
209 if (oldColor !is null) oldColor.dispose (); | |
210 } | |
211 break; | |
212 case CELL_FONT: { | |
213 Font oldFont = cellFont; | |
214 if (oldFont is null) oldFont = textNode1.getFont (1); | |
215 fontDialog.setFontList(oldFont.getFontData()); | |
216 FontData fontData = fontDialog.open (); | |
217 if (fontData is null) return; | |
218 oldFont = cellFont; | |
219 cellFont = new Font (display, fontData); | |
220 setCellFont (); | |
221 setExampleWidgetSize (); | |
222 if (oldFont !is null) oldFont.dispose (); | |
223 } | |
224 break; | |
225 default: | |
226 super.changeFontOrColor(index); | |
227 } | |
228 } | |
229 | |
230 /** | |
231 * Creates the "Other" group. | |
232 */ | |
233 void createOtherGroup () { | |
234 super.createOtherGroup (); | |
235 | |
236 /* Create display controls specific to this example */ | |
237 linesVisibleButton = new Button (otherGroup, DWT.CHECK); | |
238 linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible")); | |
239 multipleColumns = new Button (otherGroup, DWT.CHECK); | |
240 multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns")); | |
241 headerVisibleButton = new Button (otherGroup, DWT.CHECK); | |
242 headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible")); | |
243 sortIndicatorButton = new Button (otherGroup, DWT.CHECK); | |
244 sortIndicatorButton.setText (ControlExample.getResourceString("Sort_Indicator")); | |
245 moveableColumns = new Button (otherGroup, DWT.CHECK); | |
246 moveableColumns.setText (ControlExample.getResourceString("Moveable_Columns")); | |
247 resizableColumns = new Button (otherGroup, DWT.CHECK); | |
248 resizableColumns.setText (ControlExample.getResourceString("Resizable_Columns")); | |
249 headerImagesButton = new Button (otherGroup, DWT.CHECK); | |
250 headerImagesButton.setText (ControlExample.getResourceString("Header_Images")); | |
251 subImagesButton = new Button (otherGroup, DWT.CHECK); | |
252 subImagesButton.setText (ControlExample.getResourceString("Sub_Images")); | |
253 | |
254 /* Add the listeners */ | |
255 linesVisibleButton.addSelectionListener (new class() SelectionAdapter { | |
256 public void widgetSelected (SelectionEvent event) { | |
257 setWidgetLinesVisible (); | |
258 } | |
259 }); | |
260 multipleColumns.addSelectionListener (new class() SelectionAdapter { | |
261 public void widgetSelected (SelectionEvent event) { | |
262 recreateExampleWidgets (); | |
263 } | |
264 }); | |
265 headerVisibleButton.addSelectionListener (new class() SelectionAdapter { | |
266 public void widgetSelected (SelectionEvent event) { | |
267 setWidgetHeaderVisible (); | |
268 } | |
269 }); | |
270 sortIndicatorButton.addSelectionListener (new class() SelectionAdapter { | |
271 public void widgetSelected (SelectionEvent event) { | |
272 setWidgetSortIndicator (); | |
273 } | |
274 }); | |
275 moveableColumns.addSelectionListener (new class() SelectionAdapter { | |
276 public void widgetSelected (SelectionEvent event) { | |
277 setColumnsMoveable (); | |
278 } | |
279 }); | |
280 resizableColumns.addSelectionListener (new class() SelectionAdapter { | |
281 public void widgetSelected (SelectionEvent event) { | |
282 setColumnsResizable (); | |
283 } | |
284 }); | |
285 headerImagesButton.addSelectionListener (new class() SelectionAdapter { | |
286 public void widgetSelected (SelectionEvent event) { | |
287 recreateExampleWidgets (); | |
288 } | |
289 }); | |
290 subImagesButton.addSelectionListener (new class() SelectionAdapter { | |
291 public void widgetSelected (SelectionEvent event) { | |
292 recreateExampleWidgets (); | |
293 } | |
294 }); | |
295 } | |
296 | |
297 /** | |
298 * Creates the "Example" group. | |
299 */ | |
300 void createExampleGroup () { | |
301 super.createExampleGroup (); | |
302 | |
303 /* Create a group for the text tree */ | |
304 treeGroup = new Group (exampleGroup, DWT.NONE); | |
305 treeGroup.setLayout (new GridLayout ()); | |
306 treeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
307 treeGroup.setText ("Tree"); | |
308 | |
309 /* Create a group for the image tree */ | |
310 imageTreeGroup = new Group (exampleGroup, DWT.NONE); | |
311 imageTreeGroup.setLayout (new GridLayout ()); | |
312 imageTreeGroup.setLayoutData (new GridData (DWT.FILL, DWT.FILL, true, true)); | |
313 imageTreeGroup.setText (ControlExample.getResourceString("Tree_With_Images")); | |
314 } | |
315 | |
316 /** | |
317 * Creates the "Example" widgets. | |
318 */ | |
319 void createExampleWidgets () { | |
320 /* Compute the widget style */ | |
321 int style = getDefaultStyle(); | |
322 if (singleButton.getSelection()) style |= DWT.SINGLE; | |
323 if (multiButton.getSelection()) style |= DWT.MULTI; | |
324 if (horizontalButton.getSelection ()) style |= DWT.H_SCROLL; | |
325 if (verticalButton.getSelection ()) style |= DWT.V_SCROLL; | |
326 if (checkButton.getSelection()) style |= DWT.CHECK; | |
327 if (fullSelectionButton.getSelection ()) style |= DWT.FULL_SELECTION; | |
328 if (borderButton.getSelection()) style |= DWT.BORDER; | |
329 | |
330 /* Create the text tree */ | |
331 tree1 = new Tree (treeGroup, style); | |
332 bool multiColumn = multipleColumns.getSelection(); | |
333 if (multiColumn) { | |
334 for (int i = 0; i < columnTitles.length; i++) { | |
335 TreeColumn treeColumn = new TreeColumn(tree1, DWT.NONE); | |
336 treeColumn.setText(columnTitles[i]); | |
337 treeColumn.setToolTipText(Format( ControlExample.getResourceString("Tooltip") , columnTitles[i])); | |
338 } | |
339 tree1.setSortColumn(tree1.getColumn(0)); | |
340 } | |
341 for (int i = 0; i < 4; i++) { | |
342 TreeItem item = new TreeItem (tree1, DWT.NONE); | |
343 setItemText(item, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1))); | |
344 if (i < 3) { | |
345 TreeItem subitem = new TreeItem (item, DWT.NONE); | |
346 setItemText(subitem, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1) ~ "_1")); | |
347 } | |
348 } | |
349 TreeItem treeRoots[] = tree1.getItems (); | |
350 TreeItem item = new TreeItem (treeRoots[1], DWT.NONE); | |
351 setItemText(item, 1, ControlExample.getResourceString("Node_2_2")); | |
352 item = new TreeItem (item, DWT.NONE); | |
353 setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1")); | |
354 textNode1 = treeRoots[0]; | |
355 packColumns(tree1); | |
356 try { | |
357 TreeColumn column = tree1.getColumn(0); | |
358 resizableColumns.setSelection (column.getResizable()); | |
359 } catch (IllegalArgumentException ex) {} | |
360 | |
361 /* Create the image tree */ | |
362 tree2 = new Tree (imageTreeGroup, style); | |
363 Image image = instance.images[ControlExample.ciClosedFolder]; | |
364 if (multiColumn) { | |
365 for (int i = 0; i < columnTitles.length; i++) { | |
366 TreeColumn treeColumn = new TreeColumn(tree2, DWT.NONE); | |
367 treeColumn.setText(columnTitles[i]); | |
368 treeColumn.setToolTipText(Format( ControlExample.getResourceString("Tooltip"), columnTitles[i])); | |
369 if (headerImagesButton.getSelection()) treeColumn.setImage(image); | |
370 } | |
371 } | |
372 for (int i = 0; i < 4; i++) { | |
373 item = new TreeItem (tree2, DWT.NONE); | |
374 setItemText(item, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1))); | |
375 if (multiColumn && subImagesButton.getSelection()) { | |
376 for (int j = 0; j < columnTitles.length; j++) { | |
377 item.setImage(j, image); | |
378 } | |
379 } else { | |
380 item.setImage(image); | |
381 } | |
382 if (i < 3) { | |
383 TreeItem subitem = new TreeItem (item, DWT.NONE); | |
384 setItemText(subitem, i, ControlExample.getResourceString("Node_" ~ to!(char[])(i + 1) ~ "_1")); | |
385 if (multiColumn && subImagesButton.getSelection()) { | |
386 for (int j = 0; j < columnTitles.length; j++) { | |
387 subitem.setImage(j, image); | |
388 } | |
389 } else { | |
390 subitem.setImage(image); | |
391 } | |
392 } | |
393 } | |
394 treeRoots = tree2.getItems (); | |
395 item = new TreeItem (treeRoots[1], DWT.NONE); | |
396 setItemText(item, 1, ControlExample.getResourceString("Node_2_2")); | |
397 if (multiColumn && subImagesButton.getSelection()) { | |
398 for (int j = 0; j < columnTitles.length; j++) { | |
399 item.setImage(j, image); | |
400 } | |
401 } else { | |
402 item.setImage(image); | |
403 } | |
404 item = new TreeItem (item, DWT.NONE); | |
405 setItemText(item, 1, ControlExample.getResourceString("Node_2_2_1")); | |
406 if (multiColumn && subImagesButton.getSelection()) { | |
407 for (int j = 0; j < columnTitles.length; j++) { | |
408 item.setImage(j, image); | |
409 } | |
410 } else { | |
411 item.setImage(image); | |
412 } | |
413 imageNode1 = treeRoots[0]; | |
414 packColumns(tree2); | |
415 } | |
416 | |
417 void setItemText(TreeItem item, int i, char[] node) { | |
418 int index = i % 3; | |
419 if (multipleColumns.getSelection()) { | |
420 tableData [index][0] = node; | |
421 item.setText (tableData [index]); | |
422 } else { | |
423 item.setText (node); | |
424 } | |
425 } | |
426 | |
427 /** | |
428 * Creates the "Size" group. The "Size" group contains | |
429 * controls that allow the user to change the size of | |
430 * the example widgets. | |
431 */ | |
432 void createSizeGroup () { | |
433 super.createSizeGroup(); | |
434 | |
435 packColumnsButton = new Button (sizeGroup, DWT.PUSH); | |
436 packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns")); | |
437 packColumnsButton.addSelectionListener(new class() SelectionAdapter { | |
438 public void widgetSelected (SelectionEvent event) { | |
439 packColumns (tree1); | |
440 packColumns (tree2); | |
441 setExampleWidgetSize (); | |
442 } | |
443 }); | |
444 } | |
445 | |
446 /** | |
447 * Creates the "Style" group. | |
448 */ | |
449 void createStyleGroup() { | |
450 super.createStyleGroup(); | |
451 | |
452 /* Create the extra widgets */ | |
453 checkButton = new Button (styleGroup, DWT.CHECK); | |
454 checkButton.setText ("DWT.CHECK"); | |
455 fullSelectionButton = new Button (styleGroup, DWT.CHECK); | |
456 fullSelectionButton.setText ("DWT.FULL_SELECTION"); | |
457 } | |
458 | |
459 /** | |
460 * Gets the "Example" widget children's items, if any. | |
461 * | |
462 * @return an array containing the example widget children's items | |
463 */ | |
464 Item [] getExampleWidgetItems () { | |
465 /* Note: We do not bother collecting the tree items | |
466 * because tree items don't have any events. If events | |
467 * are ever added to TreeItem, then this needs to change. | |
468 */ | |
469 Item [] columns1 = tree1.getColumns(); | |
470 Item [] columns2 = tree2.getColumns(); | |
471 Item [] allItems = new Item [columns1.length + columns2.length]; | |
472 System.arraycopy(columns1, 0, allItems, 0, columns1.length); | |
473 System.arraycopy(columns2, 0, allItems, columns1.length, columns2.length); | |
474 return allItems; | |
475 } | |
476 | |
477 /** | |
478 * Gets the "Example" widget children. | |
479 */ | |
480 Widget [] getExampleWidgets () { | |
481 return [ cast(Widget) tree1, tree2 ]; | |
482 } | |
483 | |
484 /** | |
485 * Returns a list of set/get API method names (without the set/get prefix) | |
486 * that can be used to set/get values in the example control(s). | |
487 */ | |
488 char[][] getMethodNames() { | |
489 return ["ColumnOrder", "Selection", "ToolTipText", "TopItem"]; | |
490 } | |
491 | |
492 //PORTING_LEFT | |
493 /+ | |
494 Object[] parameterForType(char[] typeName, char[] value, Widget widget) { | |
495 if (typeName.equals("org.eclipse.swt.widgets.TreeItem")) { | |
496 TreeItem item = findItem(value, ((Tree) widget).getItems()); | |
497 if (item !is null) return new Object[] {item}; | |
498 } | |
499 if (typeName.equals("[Lorg.eclipse.swt.widgets.TreeItem;")) { | |
500 char[][] values = split(value, ','); | |
501 TreeItem[] items = new TreeItem[values.length]; | |
502 for (int i = 0; i < values.length; i++) { | |
503 TreeItem item = findItem(values[i], ((Tree) widget).getItems()); | |
504 if (item is null) break; | |
505 items[i] = item; | |
506 } | |
507 return new Object[] {items}; | |
508 } | |
509 return super.parameterForType(typeName, value, widget); | |
510 } | |
511 +/ | |
512 TreeItem findItem(char[] value, TreeItem[] items) { | |
513 for (int i = 0; i < items.length; i++) { | |
514 TreeItem item = items[i]; | |
515 if (item.getText() == value ) return item; | |
516 item = findItem(value, item.getItems()); | |
517 if (item !is null) return item; | |
518 } | |
519 return null; | |
520 } | |
521 | |
522 /** | |
523 * Gets the text for the tab folder item. | |
524 */ | |
525 char[] getTabText () { | |
526 return "Tree"; | |
527 } | |
528 | |
529 void packColumns (Tree tree) { | |
530 if (multipleColumns.getSelection()) { | |
531 int columnCount = tree.getColumnCount(); | |
532 for (int i = 0; i < columnCount; i++) { | |
533 TreeColumn treeColumn = tree.getColumn(i); | |
534 treeColumn.pack(); | |
535 } | |
536 } | |
537 } | |
538 | |
539 /** | |
540 * Sets the moveable columns state of the "Example" widgets. | |
541 */ | |
542 void setColumnsMoveable () { | |
543 bool selection = moveableColumns.getSelection(); | |
544 TreeColumn[] columns1 = tree1.getColumns(); | |
545 for (int i = 0; i < columns1.length; i++) { | |
546 columns1[i].setMoveable(selection); | |
547 } | |
548 TreeColumn[] columns2 = tree2.getColumns(); | |
549 for (int i = 0; i < columns2.length; i++) { | |
550 columns2[i].setMoveable(selection); | |
551 } | |
552 } | |
553 | |
554 /** | |
555 * Sets the resizable columns state of the "Example" widgets. | |
556 */ | |
557 void setColumnsResizable () { | |
558 bool selection = resizableColumns.getSelection(); | |
559 TreeColumn[] columns1 = tree1.getColumns(); | |
560 for (int i = 0; i < columns1.length; i++) { | |
561 columns1[i].setResizable(selection); | |
562 } | |
563 TreeColumn[] columns2 = tree2.getColumns(); | |
564 for (int i = 0; i < columns2.length; i++) { | |
565 columns2[i].setResizable(selection); | |
566 } | |
567 } | |
568 | |
569 /** | |
570 * Sets the foreground color, background color, and font | |
571 * of the "Example" widgets to their default settings. | |
572 * Also sets foreground and background color of the Node 1 | |
573 * TreeItems to default settings. | |
574 */ | |
575 void resetColorsAndFonts () { | |
576 super.resetColorsAndFonts (); | |
577 Color oldColor = itemForegroundColor; | |
578 itemForegroundColor = null; | |
579 setItemForeground (); | |
580 if (oldColor !is null) oldColor.dispose(); | |
581 oldColor = itemBackgroundColor; | |
582 itemBackgroundColor = null; | |
583 setItemBackground (); | |
584 if (oldColor !is null) oldColor.dispose(); | |
585 Font oldFont = font; | |
586 itemFont = null; | |
587 setItemFont (); | |
588 if (oldFont !is null) oldFont.dispose(); | |
589 oldColor = cellForegroundColor; | |
590 cellForegroundColor = null; | |
591 setCellForeground (); | |
592 if (oldColor !is null) oldColor.dispose(); | |
593 oldColor = cellBackgroundColor; | |
594 cellBackgroundColor = null; | |
595 setCellBackground (); | |
596 if (oldColor !is null) oldColor.dispose(); | |
597 oldFont = font; | |
598 cellFont = null; | |
599 setCellFont (); | |
600 if (oldFont !is null) oldFont.dispose(); | |
601 } | |
602 | |
603 /** | |
604 * Sets the state of the "Example" widgets. | |
605 */ | |
606 void setExampleWidgetState () { | |
607 setItemBackground (); | |
608 setItemForeground (); | |
609 setItemFont (); | |
610 setCellBackground (); | |
611 setCellForeground (); | |
612 setCellFont (); | |
613 if (!instance.startup) { | |
614 setColumnsMoveable (); | |
615 setColumnsResizable (); | |
616 setWidgetHeaderVisible (); | |
617 setWidgetSortIndicator (); | |
618 setWidgetLinesVisible (); | |
619 } | |
620 super.setExampleWidgetState (); | |
621 checkButton.setSelection ((tree1.getStyle () & DWT.CHECK) !is 0); | |
622 checkButton.setSelection ((tree2.getStyle () & DWT.CHECK) !is 0); | |
623 fullSelectionButton.setSelection ((tree1.getStyle () & DWT.FULL_SELECTION) !is 0); | |
624 fullSelectionButton.setSelection ((tree2.getStyle () & DWT.FULL_SELECTION) !is 0); | |
625 try { | |
626 TreeColumn column = tree1.getColumn(0); | |
627 moveableColumns.setSelection (column.getMoveable()); | |
628 resizableColumns.setSelection (column.getResizable()); | |
629 } catch (IllegalArgumentException ex) {} | |
630 headerVisibleButton.setSelection (tree1.getHeaderVisible()); | |
631 linesVisibleButton.setSelection (tree1.getLinesVisible()); | |
632 } | |
633 | |
634 /** | |
635 * Sets the background color of the Node 1 TreeItems in column 1. | |
636 */ | |
637 void setCellBackground () { | |
638 if (!instance.startup) { | |
639 textNode1.setBackground (1, cellBackgroundColor); | |
640 imageNode1.setBackground (1, cellBackgroundColor); | |
641 } | |
642 /* Set the background color item's image to match the background color of the cell. */ | |
643 Color color = cellBackgroundColor; | |
644 if (color is null) color = textNode1.getBackground (1); | |
645 TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR); | |
646 Image oldImage = item.getImage(); | |
647 if (oldImage !is null) oldImage.dispose(); | |
648 item.setImage (colorImage(color)); | |
649 } | |
650 | |
651 /** | |
652 * Sets the foreground color of the Node 1 TreeItems in column 1. | |
653 */ | |
654 void setCellForeground () { | |
655 if (!instance.startup) { | |
656 textNode1.setForeground (1, cellForegroundColor); | |
657 imageNode1.setForeground (1, cellForegroundColor); | |
658 } | |
659 /* Set the foreground color item's image to match the foreground color of the cell. */ | |
660 Color color = cellForegroundColor; | |
661 if (color is null) color = textNode1.getForeground (1); | |
662 TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR); | |
663 Image oldImage = item.getImage(); | |
664 if (oldImage !is null) oldImage.dispose(); | |
665 item.setImage (colorImage(color)); | |
666 } | |
667 | |
668 /** | |
669 * Sets the font of the Node 1 TreeItems in column 1. | |
670 */ | |
671 void setCellFont () { | |
672 if (!instance.startup) { | |
673 textNode1.setFont (1, cellFont); | |
674 imageNode1.setFont (1, cellFont); | |
675 } | |
676 /* Set the font item's image to match the font of the item. */ | |
677 Font ft = cellFont; | |
678 if (ft is null) ft = textNode1.getFont (1); | |
679 TableItem item = colorAndFontTable.getItem(CELL_FONT); | |
680 Image oldImage = item.getImage(); | |
681 if (oldImage !is null) oldImage.dispose(); | |
682 item.setImage (fontImage(ft)); | |
683 item.setFont(ft); | |
684 colorAndFontTable.layout (); | |
685 } | |
686 | |
687 /** | |
688 * Sets the background color of the Node 1 TreeItems. | |
689 */ | |
690 void setItemBackground () { | |
691 if (!instance.startup) { | |
692 textNode1.setBackground (itemBackgroundColor); | |
693 imageNode1.setBackground (itemBackgroundColor); | |
694 } | |
695 /* Set the background button's color to match the background color of the item. */ | |
696 Color color = itemBackgroundColor; | |
697 if (color is null) color = textNode1.getBackground (); | |
698 TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR); | |
699 Image oldImage = item.getImage(); | |
700 if (oldImage !is null) oldImage.dispose(); | |
701 item.setImage (colorImage(color)); | |
702 } | |
703 | |
704 /** | |
705 * Sets the foreground color of the Node 1 TreeItems. | |
706 */ | |
707 void setItemForeground () { | |
708 if (!instance.startup) { | |
709 textNode1.setForeground (itemForegroundColor); | |
710 imageNode1.setForeground (itemForegroundColor); | |
711 } | |
712 /* Set the foreground button's color to match the foreground color of the item. */ | |
713 Color color = itemForegroundColor; | |
714 if (color is null) color = textNode1.getForeground (); | |
715 TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR); | |
716 Image oldImage = item.getImage(); | |
717 if (oldImage !is null) oldImage.dispose(); | |
718 item.setImage (colorImage(color)); | |
719 } | |
720 | |
721 /** | |
722 * Sets the font of the Node 1 TreeItems. | |
723 */ | |
724 void setItemFont () { | |
725 if (!instance.startup) { | |
726 textNode1.setFont (itemFont); | |
727 imageNode1.setFont (itemFont); | |
728 } | |
729 /* Set the font item's image to match the font of the item. */ | |
730 Font ft = itemFont; | |
731 if (ft is null) ft = textNode1.getFont (); | |
732 TableItem item = colorAndFontTable.getItem(ITEM_FONT); | |
733 Image oldImage = item.getImage(); | |
734 if (oldImage !is null) oldImage.dispose(); | |
735 item.setImage (fontImage(ft)); | |
736 item.setFont(ft); | |
737 colorAndFontTable.layout (); | |
738 } | |
739 | |
740 /** | |
741 * Sets the header visible state of the "Example" widgets. | |
742 */ | |
743 void setWidgetHeaderVisible () { | |
744 tree1.setHeaderVisible (headerVisibleButton.getSelection ()); | |
745 tree2.setHeaderVisible (headerVisibleButton.getSelection ()); | |
746 } | |
747 | |
748 /** | |
749 * Sets the sort indicator state of the "Example" widgets. | |
750 */ | |
751 void setWidgetSortIndicator () { | |
752 if (sortIndicatorButton.getSelection ()) { | |
753 initializeSortState (tree1); | |
754 initializeSortState (tree2); | |
755 } else { | |
756 resetSortState (tree1); | |
757 resetSortState (tree2); | |
758 } | |
759 } | |
760 | |
761 /** | |
762 * Sets the initial sort indicator state and adds a listener | |
763 * to cycle through sort states and columns. | |
764 */ | |
765 void initializeSortState (Tree tree) { | |
766 /* Reset to known state: 'down' on column 0. */ | |
767 tree.setSortDirection (DWT.DOWN); | |
768 TreeColumn [] columns = tree.getColumns(); | |
769 for (int i = 0; i < columns.length; i++) { | |
770 TreeColumn column = columns[i]; | |
771 if (i is 0) tree.setSortColumn(column); | |
772 SelectionListener listener = new class(tree) SelectionAdapter { | |
773 Tree t; | |
774 this( Tree t ){ this.t = t; } | |
775 public void widgetSelected(SelectionEvent e) { | |
776 int sortDirection = DWT.DOWN; | |
777 if (e.widget is t.getSortColumn()) { | |
778 /* If the sort column hasn't changed, cycle down -> up -> none. */ | |
779 switch (t.getSortDirection ()) { | |
780 case DWT.DOWN: sortDirection = DWT.UP; break; | |
781 case DWT.UP: sortDirection = DWT.NONE; break; | |
782 } | |
783 } else { | |
784 t.setSortColumn(cast(TreeColumn)e.widget); | |
785 } | |
786 t.setSortDirection (sortDirection); | |
787 } | |
788 }; | |
789 column.addSelectionListener(listener); | |
790 column.setData("SortListener", cast(Object)listener); //$NON-NLS-1$ | |
791 } | |
792 } | |
793 | |
794 void resetSortState (Tree tree) { | |
795 tree.setSortDirection (DWT.NONE); | |
796 TreeColumn [] columns = tree.getColumns(); | |
797 for (int i = 0; i < columns.length; i++) { | |
798 SelectionListener listener = cast(SelectionListener)columns[i].getData("SortListener"); //$NON-NLS-1$ | |
799 if (listener !is null) columns[i].removeSelectionListener(listener); | |
800 } | |
801 } | |
802 | |
803 /** | |
804 * Sets the lines visible state of the "Example" widgets. | |
805 */ | |
806 void setWidgetLinesVisible () { | |
807 tree1.setLinesVisible (linesVisibleButton.getSelection ()); | |
808 tree2.setLinesVisible (linesVisibleButton.getSelection ()); | |
809 } | |
810 | |
99 | 811 protected override void specialPopupMenuItems(Menu menu, Event event) { |
78 | 812 MenuItem item = new MenuItem(menu, DWT.PUSH); |
813 item.setText("getItem(Point) on mouse coordinates"); | |
814 Tree t = cast(Tree) event.widget; | |
815 menuMouseCoords = t.toControl(new Point(event.x, event.y)); | |
816 item.addSelectionListener(new class(t) SelectionAdapter { | |
817 Tree t; | |
818 this( Tree t ){ this.t = t; } | |
819 public void widgetSelected(SelectionEvent e) { | |
820 eventConsole.append ("getItem(Point(" ~ menuMouseCoords.toString ~ ")) returned: " ~ (this.t.getItem(menuMouseCoords)).toString); | |
821 eventConsole.append ("\n"); | |
822 }; | |
823 }); | |
824 } | |
825 } |