78
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2006 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 * Jesse Phillips <Jesse.K.Phillips+D> gmail.com
|
|
12 *******************************************************************************/
|
|
13 module snippets.expandbar.Snippet223;
|
|
14 /*
|
|
15 * example snippet: ExpandBar example
|
|
16 *
|
|
17 * For a list of all SWT example snippets see
|
|
18 * http://www.eclipse.org/swt/snippets/
|
|
19 *
|
|
20 * @since 3.2
|
|
21 */
|
|
22
|
|
23 import dwt.DWT;
|
|
24 import dwt.dwthelper.ByteArrayInputStream;
|
|
25 import dwt.graphics.Image;
|
|
26 import dwt.graphics.ImageData;
|
|
27 import dwt.layout.FillLayout;
|
|
28 import dwt.layout.GridLayout;
|
|
29 import dwt.widgets.Button;
|
|
30 import dwt.widgets.Composite;
|
|
31 import dwt.widgets.Display;
|
|
32 import dwt.widgets.ExpandBar;
|
|
33 import dwt.widgets.ExpandItem;
|
|
34 import dwt.widgets.Label;
|
|
35 import dwt.widgets.Shell;
|
|
36 import dwt.widgets.Scale;
|
|
37 import dwt.widgets.Spinner;
|
|
38 import dwt.widgets.Slider;
|
|
39
|
|
40 void main () {
|
|
41 auto display = new Display ();
|
|
42 auto shell = new Shell (display);
|
|
43 shell.setLayout(new FillLayout());
|
|
44 shell.setText("ExpandBar Example");
|
|
45 auto bar = new ExpandBar (shell, DWT.V_SCROLL);
|
|
46 auto image = new Image(display, new ImageData(new ByteArrayInputStream( cast(byte[]) import("eclipse.png"))));
|
|
47
|
|
48 // First item
|
|
49 Composite composite = new Composite (bar, DWT.NONE);
|
|
50 GridLayout layout = new GridLayout ();
|
|
51 layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
|
|
52 layout.verticalSpacing = 10;
|
|
53 composite.setLayout(layout);
|
|
54 Button button = new Button (composite, DWT.PUSH);
|
|
55 button.setText("DWT.PUSH");
|
|
56 button = new Button (composite, DWT.RADIO);
|
|
57 button.setText("DWT.RADIO");
|
|
58 button = new Button (composite, DWT.CHECK);
|
|
59 button.setText("DWT.CHECK");
|
|
60 button = new Button (composite, DWT.TOGGLE);
|
|
61 button.setText("DWT.TOGGLE");
|
|
62 ExpandItem item0 = new ExpandItem (bar, DWT.NONE, 0);
|
|
63 item0.setText("What is your favorite button");
|
|
64 item0.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y);
|
|
65 item0.setControl(composite);
|
|
66 item0.setImage(image);
|
|
67
|
|
68 // Second item
|
|
69 composite = new Composite (bar, DWT.NONE);
|
|
70 layout = new GridLayout (2, false);
|
|
71 layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
|
|
72 layout.verticalSpacing = 10;
|
|
73 composite.setLayout(layout);
|
|
74 Label label = new Label (composite, DWT.NONE);
|
|
75 label.setImage(display.getSystemImage(DWT.ICON_ERROR));
|
|
76 label = new Label (composite, DWT.NONE);
|
|
77 label.setText("DWT.ICON_ERROR");
|
|
78 label = new Label (composite, DWT.NONE);
|
|
79 label.setImage(display.getSystemImage(DWT.ICON_INFORMATION));
|
|
80 label = new Label (composite, DWT.NONE);
|
|
81 label.setText("DWT.ICON_INFORMATION");
|
|
82 label = new Label (composite, DWT.NONE);
|
|
83 label.setImage(display.getSystemImage(DWT.ICON_WARNING));
|
|
84 label = new Label (composite, DWT.NONE);
|
|
85 label.setText("DWT.ICON_WARNING");
|
|
86 label = new Label (composite, DWT.NONE);
|
|
87 label.setImage(display.getSystemImage(DWT.ICON_QUESTION));
|
|
88 label = new Label (composite, DWT.NONE);
|
|
89 label.setText("DWT.ICON_QUESTION");
|
|
90 ExpandItem item1 = new ExpandItem (bar, DWT.NONE, 1);
|
|
91 item1.setText("What is your favorite icon");
|
|
92 item1.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y);
|
|
93 item1.setControl(composite);
|
|
94 item1.setImage(image);
|
|
95
|
|
96 // Third item
|
|
97 composite = new Composite (bar, DWT.NONE);
|
|
98 layout = new GridLayout (2, true);
|
|
99 layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
|
|
100 layout.verticalSpacing = 10;
|
|
101 composite.setLayout(layout);
|
|
102 label = new Label (composite, DWT.NONE);
|
|
103 label.setText("Scale");
|
|
104 new Scale (composite, DWT.NONE);
|
|
105 label = new Label (composite, DWT.NONE);
|
|
106 label.setText("Spinner");
|
|
107 new Spinner (composite, DWT.BORDER);
|
|
108 label = new Label (composite, DWT.NONE);
|
|
109 label.setText("Slider");
|
|
110 new Slider (composite, DWT.NONE);
|
|
111 ExpandItem item2 = new ExpandItem (bar, DWT.NONE, 2);
|
|
112 item2.setText("What is your favorite range widget");
|
|
113 item2.setHeight(composite.computeSize(DWT.DEFAULT, DWT.DEFAULT).y);
|
|
114 item2.setControl(composite);
|
|
115 item2.setImage(image);
|
|
116
|
|
117 item1.setExpanded(true);
|
|
118 bar.setSpacing(8);
|
|
119 shell.setSize(400, 350);
|
|
120 shell.open();
|
|
121 while (!shell.isDisposed ()) {
|
|
122 if (!display.readAndDispatch ()) {
|
|
123 display.sleep ();
|
|
124 }
|
|
125 }
|
|
126 image.dispose();
|
|
127 display.dispose();
|
|
128 }
|