annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet58.d @ 112:9f4c18c268b2

Update to compile and execute with dmd 2.052.
author kntroh
date Wed, 16 Mar 2011 21:53:53 +0900
parents 69b1fa94a4a8
children
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 * Port to the D programming language:
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
11 * Bill Baxter <bill@billbaxter.com>
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.Snippet58;
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 * ToolBar example snippet: place a combo box in a tool bar
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.widgets.Display;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
23 import org.eclipse.swt.widgets.Shell;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
24 import org.eclipse.swt.widgets.ToolBar;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
25 import org.eclipse.swt.widgets.ToolItem;
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
26 import org.eclipse.swt.widgets.Combo;
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
27 import java.lang.all;
28
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
28
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
29 version(Tango){
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
30 import tango.util.Convert;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
31 } else { // Phobos
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
32 import std.conv;
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
33 }
28
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
34
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
35 void main () {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
36 Display display = new Display ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
37 Shell shell = new Shell (display);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
38 ToolBar bar = new ToolBar (shell, SWT.BORDER);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
39 for (int i=0; i<4; i++) {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
40 ToolItem item = new ToolItem (bar, 0);
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
41 item.setText ("Item " ~ to!(String)(i));
28
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
42 }
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
43 ToolItem sep = new ToolItem (bar, SWT.SEPARATOR);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
44 int start = bar.getItemCount ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
45 for (int i=start; i<start+4; i++) {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
46 ToolItem item = new ToolItem (bar, 0);
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
47 item.setText ("Item " ~ to!(String)(i));
28
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
48 }
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
49 Combo combo = new Combo (bar, SWT.READ_ONLY);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
50 for (int i=0; i<4; i++) {
112
9f4c18c268b2 Update to compile and execute with dmd 2.052.
kntroh
parents: 28
diff changeset
51 combo.add ("Item " ~ to!(String)(i));
28
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 combo.pack ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
54 sep.setWidth (combo.getSize ().x);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
55 sep.setControl (combo);
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
56 bar.pack ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
57 shell.pack ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
58 shell.open ();
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
59 while (!shell.isDisposed ()) {
69b1fa94a4a8 Added SWT snippets
Frank Benoit <benoit@tionex.de>
parents:
diff changeset
60 if (!display.readAndDispatch ()) display.sleep ();
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 display.dispose ();
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