comparison org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet7.d @ 28:69b1fa94a4a8

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