1 #!/usr/bin/env dub
2 /+
3 dub.sdl:
4     name "snippet144"
5     dependency "dwt" path="../../../../../../"
6     libs \
7       "atk-1.0" \
8       "cairo" \
9       "dl" \
10       "fontconfig" \
11       "gdk-x11-2.0" \
12       "gdk_pixbuf-2.0" \
13       "glib-2.0" \
14       "gmodule-2.0" \
15       "gnomeui-2" \
16       "gnomevfs-2" \
17       "gobject-2.0" \
18       "gthread-2.0" \
19       "gtk-x11-2.0" \
20       "pango-1.0" \
21       "pangocairo-1.0" \
22       "X11" \
23       "Xcomposite" \
24       "Xcursor" \
25       "Xdamage" \
26       "Xext" \
27       "Xfixes" \
28       "Xi" \
29       "Xinerama" \
30       "Xrandr" \
31       "Xrender" \
32       "Xtst" \
33       platform="linux"
34 +/
35 
36 /*******************************************************************************
37  * Copyright (c) 2000, 2004 IBM Corporation and others.
38  * All rights reserved. This program and the accompanying materials
39  * are made available under the terms of the Eclipse Public License v1.0
40  * which accompanies this distribution, and is available at
41  * http://www.eclipse.org/legal/epl-v10.html
42  *
43  * Contributors:
44  *     IBM Corporation - initial API and implementation
45  * D Port:
46  *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
47  *******************************************************************************/
48 module org.eclipse.swt.snippets.Snippet144;
49 
50 /*
51  * Virtual Table example snippet: create a table with 1,000,000 items (lazy)
52  *
53  * For a list of all SWT example snippets see
54  * http://www.eclipse.org/swt/snippets/
55  *
56  * @since 3.0
57  */
58 import org.eclipse.swt.SWT;
59 import org.eclipse.swt.widgets.Button;
60 import org.eclipse.swt.widgets.Display;
61 import org.eclipse.swt.widgets.Event;
62 import org.eclipse.swt.widgets.Label;
63 import org.eclipse.swt.widgets.Listener;
64 import org.eclipse.swt.widgets.Shell;
65 import org.eclipse.swt.widgets.Table;
66 import org.eclipse.swt.widgets.TableItem;
67 import org.eclipse.swt.layout.RowLayout;
68 import org.eclipse.swt.layout.RowData;
69 import java.lang.all;
70 
71 version(Tango){
72     import tango.io.Stdout;
73     void writeln(in char[] line) {
74         Stdout(line)("\n").flush();
75     }
76     import tango.time.StopWatch;
77     import tango.util.Convert;
78 } else {
79     import std.stdio;
80     import std.datetime;
81     import std.conv;
82 }
83 
84 const int COUNT = 1000000;
85 
86 void main() {
87     auto display = new Display ();
88     auto shell = new Shell (display);
89     shell.setLayout (new RowLayout (SWT.VERTICAL));
90     auto table = new Table (shell, SWT.VIRTUAL | SWT.BORDER);
91     table.addListener (SWT.SetData, new class Listener {
92         public void handleEvent (Event event) {
93             auto item = cast(TableItem) event.item;
94             auto index = table.indexOf (item);
95             item.setText ("Item " ~ to!(String)(index));
96             writeln(item.getText ());
97         }
98     });
99     table.setLayoutData (new RowData (200, 200));
100     auto button = new Button (shell, SWT.PUSH);
101     button.setText ("Add Items");
102     auto label = new Label(shell, SWT.NONE);
103     button.addListener (SWT.Selection, new class Listener {
104         public void handleEvent (Event event) {
105             StopWatch elapsed; //Tango or Phobos StopWatch
106             elapsed.start();
107             table.setItemCount (COUNT);
108             version(Tango){
109                 auto t = elapsed.stop() * 1_000;
110             } else { // Phobos
111                 elapsed.stop();
112                 auto t = elapsed.peek.msecs;
113             }
114             label.setText ("Items: " ~ to!(String)(COUNT) ~
115                            ", Time: " ~ to!(String)(t) ~ " (msec)");
116             shell.layout ();
117         }
118     });
119     shell.pack ();
120     shell.open ();
121     while (!shell.isDisposed ()) {
122         if (!display.readAndDispatch ()) display.sleep ();
123     }
124     display.dispose ();
125 }