Mercurial > projects > dwt-samples
annotate snippets/tree/Snippet193.d @ 120:1f0a7a472680
fix rm snippets from module statements.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 20 Jul 2008 19:17:23 +0200 |
parents | 799099686955 |
children |
rev | line source |
---|---|
94 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 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 * D Port: | |
11 * Bill Baxter <wbaxter@gmail.com> | |
12 *******************************************************************************/ | |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
94
diff
changeset
|
13 module tree.Snippet193; |
94 | 14 |
15 /* | |
16 * Tree example snippet: allow user to reorder columns by dragging and programmatically. | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.2 | |
22 */ | |
23 import dwt.DWT; | |
24 import dwt.widgets.Display; | |
25 import dwt.widgets.Shell; | |
26 import dwt.widgets.Tree; | |
27 import dwt.widgets.TreeItem; | |
28 import dwt.widgets.TreeColumn; | |
29 import dwt.widgets.Button; | |
30 import dwt.widgets.Listener; | |
31 import dwt.widgets.Event; | |
32 import dwt.layout.RowLayout; | |
33 import dwt.layout.RowData; | |
34 | |
35 import tango.util.Convert; | |
36 import tango.io.Stdout; | |
37 | |
38 import dwt.dwthelper.utils; | |
39 | |
40 | |
41 void main() { | |
42 Display display = new Display(); | |
43 Shell shell = new Shell(display); | |
44 shell.setLayout(new RowLayout(DWT.HORIZONTAL)); | |
45 final Tree tree = new Tree(shell, DWT.BORDER | DWT.CHECK); | |
46 tree.setLayoutData(new RowData(-1, 300)); | |
47 tree.setHeaderVisible(true); | |
48 TreeColumn column = new TreeColumn(tree, DWT.LEFT); | |
49 column.setText("Column 0"); | |
50 column = new TreeColumn(tree, DWT.CENTER); | |
51 column.setText("Column 1"); | |
52 column = new TreeColumn(tree, DWT.LEFT); | |
53 column.setText("Column 2"); | |
54 column = new TreeColumn(tree, DWT.RIGHT); | |
55 column.setText("Column 3"); | |
56 column = new TreeColumn(tree, DWT.CENTER); | |
57 column.setText("Column 4"); | |
58 for (int i = 0; i < 5; i++) { | |
59 TreeItem item = new TreeItem(tree, DWT.NONE); | |
60 auto istr = to!(String)(i); | |
61 String[] text = [istr~":0", | |
62 istr~":1", | |
63 istr~":2", | |
64 istr~":3", | |
65 istr~":4"]; | |
66 item.setText(text); | |
67 for (int j = 0; j < 5; j++) { | |
68 auto jstr = to!(String)(j); | |
69 TreeItem subItem = new TreeItem(item, DWT.NONE); | |
70 text = [istr~","~jstr~":0", | |
71 istr~","~jstr~":1", | |
72 istr~","~jstr~":2", | |
73 istr~","~jstr~":3", | |
74 istr~","~jstr~":4"]; | |
75 subItem.setText(text); | |
76 for (int k = 0; k < 5; k++) { | |
77 auto kstr = to!(String)(k); | |
78 TreeItem subsubItem = new TreeItem(subItem, DWT.NONE); | |
79 text = [istr~","~jstr~","~kstr~":0", | |
80 istr~","~jstr~","~kstr~":1", | |
81 istr~","~jstr~","~kstr~":2", | |
82 istr~","~jstr~","~kstr~":3", | |
83 istr~","~jstr~","~kstr~":4"]; | |
84 subsubItem.setText(text); | |
85 } | |
86 } | |
87 } | |
88 Listener listener = new class Listener { | |
89 public void handleEvent(Event e) { | |
90 Stdout.print("Move "~e.widget.toString).newline; | |
91 } | |
92 }; | |
93 TreeColumn[] columns = tree.getColumns(); | |
94 for (int i = 0; i < columns.length; i++) { | |
95 columns[i].setWidth(100); | |
96 columns[i].setMoveable(true); | |
97 columns[i].addListener(DWT.Move, listener); | |
98 } | |
99 Button b = new Button(shell, DWT.PUSH); | |
100 b.setText("invert column order"); | |
101 b.addListener(DWT.Selection, new class Listener { | |
102 public void handleEvent(Event e) { | |
103 int[] order = tree.getColumnOrder(); | |
104 for (int i = 0; i < order.length / 2; i++) { | |
105 int temp = order[i]; | |
106 order[i] = order[order.length - i - 1]; | |
107 order[order.length - i - 1] = temp; | |
108 } | |
109 tree.setColumnOrder(order); | |
110 } | |
111 }); | |
112 shell.pack(); | |
113 shell.open(); | |
114 while (!shell.isDisposed()) { | |
115 if (!display.readAndDispatch()) | |
116 display.sleep(); | |
117 } | |
118 display.dispose(); | |
119 } |