Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet150.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 4e5843b771cc |
children | 536e43f63c81 |
rev | line source |
---|---|
28 | 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 * Bill Baxter | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.snippets.Snippet150; | |
14 | |
15 /* | |
16 * CoolBar example snippet: create a coolbar (relayout when resized) | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 * | |
21 * @since 3.0 | |
22 */ | |
23 import org.eclipse.swt.SWT; | |
24 import org.eclipse.swt.graphics.Point; | |
25 import org.eclipse.swt.widgets.Button; | |
26 import org.eclipse.swt.widgets.Display; | |
27 import org.eclipse.swt.widgets.CoolBar; | |
28 import org.eclipse.swt.widgets.CoolItem; | |
29 import org.eclipse.swt.widgets.ToolBar; | |
30 import org.eclipse.swt.widgets.ToolItem; | |
31 import org.eclipse.swt.widgets.Shell; | |
32 import org.eclipse.swt.widgets.Text; | |
33 import org.eclipse.swt.widgets.Event; | |
34 import org.eclipse.swt.widgets.Listener; | |
35 import org.eclipse.swt.layout.FormLayout; | |
36 import org.eclipse.swt.layout.FormData; | |
37 import org.eclipse.swt.layout.FormAttachment; | |
112 | 38 import java.lang.all; |
28 | 39 |
112 | 40 version(Tango){ |
41 import tango.util.Convert; | |
42 } else { // Phobos | |
43 import std.conv; | |
44 } | |
28 | 45 |
46 int itemCount; | |
47 CoolItem createItem(CoolBar coolBar, int count) { | |
48 ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); | |
49 for (int i = 0; i < count; i++) { | |
50 ToolItem item = new ToolItem(toolBar, SWT.PUSH); | |
112 | 51 item.setText(to!(String)(itemCount++) ~""); |
28 | 52 } |
53 toolBar.pack(); | |
54 Point size = toolBar.getSize(); | |
55 CoolItem item = new CoolItem(coolBar, SWT.NONE); | |
56 item.setControl(toolBar); | |
57 Point preferred = item.computeSize(size.x, size.y); | |
58 item.setPreferredSize(preferred); | |
59 return item; | |
60 } | |
61 | |
62 void main () { | |
63 | |
64 Display display = new Display(); | |
112 | 65 Shell shell = new Shell(display); |
28 | 66 CoolBar coolBar = new CoolBar(shell, SWT.NONE); |
67 createItem(coolBar, 3); | |
68 createItem(coolBar, 2); | |
69 createItem(coolBar, 3); | |
70 createItem(coolBar, 4); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
71 int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL; |
28 | 72 Text text = new Text(shell, style); |
73 FormLayout layout = new FormLayout(); | |
74 shell.setLayout(layout); | |
75 FormData coolData = new FormData(); | |
76 coolData.left = new FormAttachment(0); | |
77 coolData.right = new FormAttachment(100); | |
78 coolData.top = new FormAttachment(0); | |
79 coolBar.setLayoutData(coolData); | |
80 coolBar.addListener(SWT.Resize, new class() Listener { | |
81 void handleEvent(Event event) { | |
82 shell.layout(); | |
83 } | |
84 }); | |
85 FormData textData = new FormData(); | |
86 textData.left = new FormAttachment(0); | |
87 textData.right = new FormAttachment(100); | |
88 textData.top = new FormAttachment(coolBar); | |
89 textData.bottom = new FormAttachment(100); | |
90 text.setLayoutData(textData); | |
91 shell.open(); | |
92 while (!shell.isDisposed()) { | |
93 if (!display.readAndDispatch()) display.sleep(); | |
94 } | |
95 display.dispose(); | |
96 | |
97 } |