blob: f6dc58ec3da16f6af0375c7a0c1562d50f51d60e (
plain)
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
|
/*******************************************************************************
* Copyright (c) 2011 Google, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Google, Inc. - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.internal.core.utils.ui;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Layout;
/**
* GridLayoutFactory provides a convenient shorthand for creating and initializing GridLayout.
*
* @author scheglov_ke
*/
public final class GridLayoutFactory {
private final GridLayout m_layout;
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
private GridLayoutFactory(Composite composite, GridLayout layout) {
m_layout = layout;
composite.setLayout(m_layout);
}
public static GridLayoutFactory create(Composite composite) {
return new GridLayoutFactory(composite, new GridLayout());
}
public static GridLayoutFactory modify(Composite composite) {
Layout layout = composite.getLayout();
if (layout instanceof GridLayout) {
return new GridLayoutFactory(composite, (GridLayout) layout);
}
return create(composite);
}
////////////////////////////////////////////////////////////////////////////
//
// Access
//
////////////////////////////////////////////////////////////////////////////
/**
* Sets number of columns in {@link GridLayout}.
*/
public GridLayoutFactory columns(int numColumns) {
m_layout.numColumns = numColumns;
return this;
}
/**
* Specifies whether all columns in the layout will be forced to have the same width.
*/
public GridLayoutFactory equalColumns() {
m_layout.makeColumnsEqualWidth = true;
return this;
}
/**
* Sets the horizontal margins.
*/
public GridLayoutFactory marginsH(int margins) {
m_layout.marginWidth = margins;
return this;
}
/**
* Sets the vertical margins.
*/
public GridLayoutFactory marginsV(int margins) {
m_layout.marginHeight = margins;
return this;
}
/**
* Sets the horizontal/vertical margins.
*/
public GridLayoutFactory margins(int margins) {
m_layout.marginWidth = m_layout.marginHeight = margins;
return this;
}
/**
* Sets zero horizontal and vertical margins.
*/
public GridLayoutFactory noMargins() {
m_layout.marginWidth = m_layout.marginHeight = 0;
return this;
}
/**
* Sets zero horizontal and vertical spacing.
*/
public GridLayoutFactory noSpacing() {
m_layout.horizontalSpacing = m_layout.verticalSpacing = 0;
return this;
}
/**
* Sets horizontal spacing.
*/
public GridLayoutFactory spacingH(int spacing) {
m_layout.horizontalSpacing = spacing;
return this;
}
/**
* Sets vertical spacing.
*/
public GridLayoutFactory spacingV(int spacing) {
m_layout.verticalSpacing = spacing;
return this;
}
}
|