annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet7.d @ 29:4e5843b771cc

First snippets buildable on windows
author Frank Benoit <benoit@tionex.de>
date Sun, 22 Mar 2009 19:55:00 +0100
parents 69b1fa94a4a8
children 9f4c18c268b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
1 /*******************************************************************************
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
5 * which accompanies this distribution, and is available at
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
7 *
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
8 * Contributors:
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
10 * D Port:
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Thomas Demmer <t_demmer AT web DOT de>
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
12 *******************************************************************************/
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
13 module org.eclipse.swt.snippets.Snippet7;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
14
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
15 /*
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
16 * example snippet: create a table (lazy)
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
17 *
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
18 * For a list of all SWT example snippets see
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
19 * http://www.eclipse.org/swt/snippets/
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
20 */
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
21 import org.eclipse.swt.SWT;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
22 import org.eclipse.swt.layout.FillLayout;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import org.eclipse.swt.graphics.GC;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 import org.eclipse.swt.graphics.Image;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 import org.eclipse.swt.widgets.Display;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 import org.eclipse.swt.widgets.Item;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
27 import org.eclipse.swt.widgets.Shell;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28 import org.eclipse.swt.widgets.Table;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
29 import org.eclipse.swt.widgets.TableItem;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
30
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
31 import java.lang.all;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
32
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
33 import tango.core.Thread;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34 import tango.util.Convert;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 void main (String [] args) {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 Display display = new Display ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 Image image = new Image (display, 16, 16);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 GC gc = new GC (image);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 gc.setBackground (display.getSystemColor (SWT.COLOR_RED));
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
41 gc.fillRectangle (image.getBounds ());
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 gc.dispose ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 Shell shell = new Shell (display);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 shell.setText ("Lazy Table");
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 shell.setLayout (new FillLayout ());
29
4e5843b771cc First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents: 28
diff changeset
47 Table table = new Table (shell, SWT.BORDER | SWT.MULTI);
28
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 table.setSize (200, 200);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 Thread thread = new Thread({
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 for(int i=0; i< 20000; i++){
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
51 if (table.isDisposed ()) return;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
52
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
53 int [] index = [i];
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 display.syncExec (new class() Runnable{
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 public void run () {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 if (table.isDisposed ()) return;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 TableItem item = new TableItem (table, SWT.NONE);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 item.setText ("Table Item " ~ to!(String)(index [0]));
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 item.setImage (image);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 }
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
61 });
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
62 }
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
63 });
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
64
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
65 thread.start ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
66 shell.setSize (200, 200);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
67 shell.open ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
68 while (!shell.isDisposed ()) {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
69 if (!display.readAndDispatch ()) display.sleep ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
70 }
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
71 image.dispose ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
72 display.dispose ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
73 }