43
|
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 *******************************************************************************/
|
|
11 module dwtsnippets.coolbar.Snippet150;
|
|
12
|
|
13 /*
|
|
14 * CoolBar example snippet: create a coolbar (relayout when resized)
|
|
15 *
|
|
16 * For a list of all SWT example snippets see
|
|
17 * http://www.eclipse.org/swt/snippets/
|
|
18 *
|
|
19 * @since 3.0
|
|
20 */
|
|
21 import dwt.DWT;
|
|
22 import dwt.graphics.Point;
|
|
23 import dwt.widgets.Button;
|
|
24 import dwt.widgets.Display;
|
|
25 import dwt.widgets.CoolBar;
|
|
26 import dwt.widgets.CoolItem;
|
|
27 import dwt.widgets.ToolBar;
|
|
28 import dwt.widgets.ToolItem;
|
|
29 import dwt.widgets.Shell;
|
|
30 import dwt.widgets.Text;
|
|
31 import dwt.widgets.Event;
|
|
32 import dwt.widgets.Listener;
|
|
33 import dwt.layout.FormLayout;
|
|
34 import dwt.layout.FormData;
|
|
35 import dwt.layout.FormAttachment;
|
|
36
|
|
37 import tango.util.Convert;
|
|
38
|
|
39 int itemCount;
|
|
40 CoolItem createItem(CoolBar coolBar, int count) {
|
|
41 ToolBar toolBar = new ToolBar(coolBar, DWT.FLAT);
|
|
42 for (int i = 0; i < count; i++) {
|
|
43 ToolItem item = new ToolItem(toolBar, DWT.PUSH);
|
|
44 item.setText(to!(char[])(itemCount++) ~"");
|
|
45 }
|
|
46 toolBar.pack();
|
|
47 Point size = toolBar.getSize();
|
|
48 CoolItem item = new CoolItem(coolBar, DWT.NONE);
|
|
49 item.setControl(toolBar);
|
|
50 Point preferred = item.computeSize(size.x, size.y);
|
|
51 item.setPreferredSize(preferred);
|
|
52 return item;
|
|
53 }
|
|
54
|
|
55 void main () {
|
|
56
|
|
57 Display display = new Display();
|
|
58 final Shell shell = new Shell(display);
|
|
59 CoolBar coolBar = new CoolBar(shell, DWT.NONE);
|
|
60 createItem(coolBar, 3);
|
|
61 createItem(coolBar, 2);
|
|
62 createItem(coolBar, 3);
|
|
63 createItem(coolBar, 4);
|
|
64 int style = DWT.BORDER | DWT.H_SCROLL | DWT.V_SCROLL;
|
|
65 Text text = new Text(shell, style);
|
|
66 FormLayout layout = new FormLayout();
|
|
67 shell.setLayout(layout);
|
|
68 FormData coolData = new FormData();
|
|
69 coolData.left = new FormAttachment(0);
|
|
70 coolData.right = new FormAttachment(100);
|
|
71 coolData.top = new FormAttachment(0);
|
|
72 coolBar.setLayoutData(coolData);
|
|
73 coolBar.addListener(DWT.Resize, new class() Listener {
|
|
74 void handleEvent(Event event) {
|
|
75 shell.layout();
|
|
76 }
|
|
77 });
|
|
78 FormData textData = new FormData();
|
|
79 textData.left = new FormAttachment(0);
|
|
80 textData.right = new FormAttachment(100);
|
|
81 textData.top = new FormAttachment(coolBar);
|
|
82 textData.bottom = new FormAttachment(100);
|
|
83 text.setLayoutData(textData);
|
|
84 shell.open();
|
|
85 while (!shell.isDisposed()) {
|
|
86 if (!display.readAndDispatch()) display.sleep();
|
|
87 }
|
|
88 display.dispose();
|
|
89
|
|
90 } |