Mercurial > projects > dwt2
annotate org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet150.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 |
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; | |
38 | |
39 import tango.util.Convert; | |
40 | |
41 int itemCount; | |
42 CoolItem createItem(CoolBar coolBar, int count) { | |
43 ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); | |
44 for (int i = 0; i < count; i++) { | |
45 ToolItem item = new ToolItem(toolBar, SWT.PUSH); | |
46 item.setText(to!(char[])(itemCount++) ~""); | |
47 } | |
48 toolBar.pack(); | |
49 Point size = toolBar.getSize(); | |
50 CoolItem item = new CoolItem(coolBar, SWT.NONE); | |
51 item.setControl(toolBar); | |
52 Point preferred = item.computeSize(size.x, size.y); | |
53 item.setPreferredSize(preferred); | |
54 return item; | |
55 } | |
56 | |
57 void main () { | |
58 | |
59 Display display = new Display(); | |
60 final Shell shell = new Shell(display); | |
61 CoolBar coolBar = new CoolBar(shell, SWT.NONE); | |
62 createItem(coolBar, 3); | |
63 createItem(coolBar, 2); | |
64 createItem(coolBar, 3); | |
65 createItem(coolBar, 4); | |
29
4e5843b771cc
First snippets buildable on windows
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
66 int style = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL; |
28 | 67 Text text = new Text(shell, style); |
68 FormLayout layout = new FormLayout(); | |
69 shell.setLayout(layout); | |
70 FormData coolData = new FormData(); | |
71 coolData.left = new FormAttachment(0); | |
72 coolData.right = new FormAttachment(100); | |
73 coolData.top = new FormAttachment(0); | |
74 coolBar.setLayoutData(coolData); | |
75 coolBar.addListener(SWT.Resize, new class() Listener { | |
76 void handleEvent(Event event) { | |
77 shell.layout(); | |
78 } | |
79 }); | |
80 FormData textData = new FormData(); | |
81 textData.left = new FormAttachment(0); | |
82 textData.right = new FormAttachment(100); | |
83 textData.top = new FormAttachment(coolBar); | |
84 textData.bottom = new FormAttachment(100); | |
85 text.setLayoutData(textData); | |
86 shell.open(); | |
87 while (!shell.isDisposed()) { | |
88 if (!display.readAndDispatch()) display.sleep(); | |
89 } | |
90 display.dispose(); | |
91 | |
92 } |