1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/*******************************************************************************
* Copyright (c) 2006 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.jface.snippets.layout;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.layout.LayoutConstants;
import org.eclipse.jface.util.Geometry;
import org.eclipse.jface.widgets.WidgetFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
/**
* @since 3.3
*/
public class Snippet013GridLayoutFactory {
public static Shell createShell1() {
Shell shell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM);
// Populate the shell
Label text = new Label(shell, SWT.WRAP);
text
.setText("This is a layout test. This text should wrap in the test. You could call it a text test.");
GridDataFactory.generate(text, 2, 1);
List theList = new List(shell, SWT.H_SCROLL | SWT.V_SCROLL
| SWT.BORDER);
theList.add("Hello");
theList.add("World");
GridDataFactory.defaultsFor(theList).hint(300, 300)
.applyTo(theList);
Composite buttonBar = WidgetFactory.composite(SWT.NONE).create(shell);
// Populate buttonBar
WidgetFactory.button(SWT.PUSH).text("Add").create(buttonBar);
WidgetFactory.button(SWT.PUSH).text("Remove").create(buttonBar);
GridLayoutFactory.fillDefaults().generateLayout(buttonBar);
GridLayoutFactory.fillDefaults().numColumns(2).margins(
LayoutConstants.getMargins()).generateLayout(shell);
return shell;
}
public static Shell createShell3() {
Shell shell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM);
// Populate the shell
WidgetFactory.text(SWT.WRAP | SWT.BORDER).text(
"This shell has asymmetric margins. The left, right, top, and bottom margins should be 0, 10, 40, and 80 pixels respectively")
.create(shell);
Rectangle margins = Geometry.createDiffRectangle(0, 10, 40, 80);
GridLayoutFactory.fillDefaults().extendedMargins(margins)
.generateLayout(shell);
return shell;
}
public static Shell createShell2() {
Shell shell = new Shell(Display.getCurrent(), SWT.SHELL_TRIM);
// Populate the shell
WidgetFactory.label(SWT.NONE).text("Name:").create(shell);
WidgetFactory.text(SWT.BORDER).create(shell);
WidgetFactory.label(SWT.NONE).text("Quest:").create(shell);
CCombo combo = new CCombo(shell, SWT.BORDER);
combo.add("I seek the holy grail");
combo.add("What? I don't know that");
combo.add("All your base are belong to us");
WidgetFactory.label(SWT.NONE).text("Color:").create(shell);
WidgetFactory.text(SWT.BORDER).create(shell);
Composite buttonBar = new Composite(shell, SWT.NONE);
WidgetFactory.button(SWT.PUSH).text("Okay").create(buttonBar);
WidgetFactory.button(SWT.PUSH).text("Cancel").create(buttonBar);
GridLayoutFactory.fillDefaults().numColumns(2).generateLayout(
buttonBar);
GridDataFactory.fillDefaults().span(2, 1).align(SWT.RIGHT,
SWT.BOTTOM).applyTo(buttonBar);
GridLayoutFactory.fillDefaults().numColumns(2).margins(
LayoutConstants.getMargins()).generateLayout(shell);
return shell;
}
/**
* @param args
*/
public static void main(String[] args) {
Display display = new Display();
Shell shell = createShell1();
shell.pack();
shell.open();
Shell shell2 = createShell2();
shell2.pack();
shell2.open();
Shell shell3 = createShell3();
shell3.pack();
shell3.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
}
|