comparison snippets/display/Snippet7.d @ 132:104f5ed240fc

More snippets from TomD, thanks!
author Frank Benoit <benoit@tionex.de>
date Tue, 29 Jul 2008 01:50:10 +0200
parents
children
comparison
equal deleted inserted replaced
130:5c1906bfc206 132:104f5ed240fc
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 * Thomas Demmer <t_demmer AT web DOT de>
12 *******************************************************************************/
13 module display.Snippet7;
14
15 /*
16 * example snippet: create a table (lazy)
17 *
18 * For a list of all DWT example snippets see
19 * http://www.eclipse.org/swt/snippets/
20 */
21 import dwt.DWT;
22 import dwt.layout.FillLayout;
23 import dwt.graphics.GC;
24 import dwt.graphics.Image;
25 import dwt.widgets.Display;
26 import dwt.widgets.Item;
27 import dwt.widgets.Shell;
28 import dwt.widgets.Table;
29 import dwt.widgets.TableItem;
30
31 import dwt.dwthelper.Runnable;
32 import dwt.dwthelper.utils;
33
34 import tango.core.Thread;
35 import tango.util.Convert;
36
37 void main (String [] args) {
38 Display display = new Display ();
39 Image image = new Image (display, 16, 16);
40 GC gc = new GC (image);
41 gc.setBackground (display.getSystemColor (DWT.COLOR_RED));
42 gc.fillRectangle (image.getBounds ());
43 gc.dispose ();
44
45 Shell shell = new Shell (display);
46 shell.setText ("Lazy Table");
47 shell.setLayout (new FillLayout ());
48 Table table = new Table (shell, DWT.BORDER | DWT.MULTI);
49 table.setSize (200, 200);
50 Thread thread = new Thread({
51 for(int i=0; i< 20000; i++){
52 if (table.isDisposed ()) return;
53
54 int [] index = [i];
55 display.syncExec (new class() Runnable{
56 public void run () {
57 if (table.isDisposed ()) return;
58 TableItem item = new TableItem (table, DWT.NONE);
59 item.setText ("Table Item " ~ to!(String)(index [0]));
60 item.setImage (image);
61 }
62 });
63 }
64 });
65
66 thread.start ();
67 shell.setSize (200, 200);
68 shell.open ();
69 while (!shell.isDisposed ()) {
70 if (!display.readAndDispatch ()) display.sleep ();
71 }
72 image.dispose ();
73 display.dispose ();
74 }