Mercurial > projects > dwt-samples
annotate snippets/table/Snippet144.d @ 179:89de7ff0752c default tip
Add JFace snippet Snippet054NativeControlsInViewers, thanks to WasserDragoon
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 29 Apr 2009 11:01:41 +0200 |
parents | 1f0a7a472680 |
children |
rev | line source |
---|---|
78 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2004 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 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com | |
12 *******************************************************************************/ | |
120
1f0a7a472680
fix rm snippets from module statements.
Frank Benoit <benoit@tionex.de>
parents:
78
diff
changeset
|
13 module table.Snippet144; |
78 | 14 |
15 /* | |
16 * Virtual Table example snippet: create a table with 1,000,000 items (lazy) | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.0 | |
22 */ | |
23 import dwt.DWT; | |
24 import dwt.widgets.Button; | |
25 import dwt.widgets.Display; | |
26 import dwt.widgets.Event; | |
27 import dwt.widgets.Label; | |
28 import dwt.widgets.Listener; | |
29 import dwt.widgets.Shell; | |
30 import dwt.widgets.Table; | |
31 import dwt.widgets.TableItem; | |
32 import dwt.layout.RowLayout; | |
33 import dwt.layout.RowData; | |
34 | |
35 import tango.io.Stdout; | |
36 import tango.time.StopWatch; | |
37 import tango.util.Convert; | |
38 | |
39 const int COUNT = 1000000; | |
40 | |
41 void main() { | |
42 auto display = new Display (); | |
43 auto shell = new Shell (display); | |
44 shell.setLayout (new RowLayout (DWT.VERTICAL)); | |
45 auto table = new Table (shell, DWT.VIRTUAL | DWT.BORDER); | |
46 table.addListener (DWT.SetData, new class Listener { | |
47 public void handleEvent (Event event) { | |
48 auto item = cast(TableItem) event.item; | |
49 auto index = table.indexOf (item); | |
50 item.setText ("Item " ~ to!(char[])(index)); | |
51 Stdout(item.getText ()).newline; | |
52 } | |
53 }); | |
54 table.setLayoutData (new RowData (200, 200)); | |
55 auto button = new Button (shell, DWT.PUSH); | |
56 button.setText ("Add Items"); | |
57 auto label = new Label(shell, DWT.NONE); | |
58 button.addListener (DWT.Selection, new class Listener { | |
59 public void handleEvent (Event event) { | |
60 StopWatch elapsed; | |
61 elapsed.start; | |
62 table.setItemCount (COUNT); | |
63 auto t = elapsed.stop; | |
64 label.setText ("Items: " ~ to!(char[])(COUNT) ~ | |
65 ", Time: " ~ to!(char[])(t) ~ " (sec)"); | |
66 shell.layout (); | |
67 } | |
68 }); | |
69 shell.pack (); | |
70 shell.open (); | |
71 while (!shell.isDisposed ()) { | |
72 if (!display.readAndDispatch ()) display.sleep (); | |
73 } | |
74 display.dispose (); | |
75 } |