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