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 package net.sf.tm.plugin.ui;
34
35 import org.eclipse.jface.dialogs.IDialogConstants;
36 import org.eclipse.swt.SWT;
37 import org.eclipse.swt.layout.GridData;
38 import org.eclipse.swt.layout.GridLayout;
39 import org.eclipse.swt.widgets.Button;
40 import org.eclipse.swt.widgets.Combo;
41 import org.eclipse.swt.widgets.Composite;
42 import org.eclipse.swt.widgets.Group;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.Text;
45
46 /***
47 * @author Andreas Pataki
48 * @version $Id: WidgetFactory.java,v 1.4 2003/11/17 20:53:07 apataki Exp $
49 */
50 class WidgetFactory {
51
52
53 /***
54 * Creates a component group.
55 *
56 * @param parent parent
57 * @param text display text
58 * @return created group
59 */
60 public Group createGroup(Composite parent, String text) {
61 Group group = new Group(parent, SWT.NULL);
62 group.setText(text);
63 GridData data = new GridData(GridData.FILL_HORIZONTAL);
64 data.horizontalSpan = 2;
65
66 group.setLayoutData(data);
67 GridLayout layout = new GridLayout();
68 layout.numColumns = 2;
69 group.setLayout(layout);
70 return group;
71 }
72
73 /***
74 * Creates an input label.
75 *
76 * @param parent parent component
77 * @param text label text
78 * @return the created label
79 */
80 public Label createLabel(Composite parent, String text) {
81 return createLabel(parent, text, 1);
82 }
83
84 /***
85 * Creates an input label.
86 *
87 * @param parent parent component
88 * @param text label text
89 * @param hspan horizontal cell span
90 * @return created label
91 */
92 public Label createLabel(Composite parent, String text, int hspan) {
93 Label label = new Label(parent, SWT.LEFT);
94 label.setText(text);
95 GridData data = new GridData();
96 data.horizontalSpan = hspan;
97 data.horizontalAlignment = GridData.FILL;
98 data.horizontalIndent = 0;
99 label.setLayoutData(data);
100 return label;
101 }
102
103 /***
104 * Creates an input text field.
105 *
106 * @param parent parent component
107 * @return created input field
108 */
109 public Text createTextField(Composite parent) {
110 Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
111 GridData data = new GridData(GridData.FILL_HORIZONTAL);
112 data.verticalAlignment = GridData.CENTER;
113 data.grabExcessVerticalSpace = false;
114 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
115 text.setLayoutData(data);
116 return text;
117 }
118
119 /***
120 * Create a checkbox
121 *
122 * @param parent parent composite
123 * @param text checkbox text
124 * @return The created Checkbox
125 */
126 public Button createCheckbox(Composite parent, String text) {
127 return createCheckbox(parent, text, 3);
128 }
129
130 /***
131 * Create a checkbox
132 *
133 * @param parent parent composite
134 * @param text checkbox text
135 * @param hspan the horizontal span
136 * @return The created Checkbox
137 */
138 public Button createCheckbox(Composite parent, String text, int hspan) {
139 Button button = new Button(parent, SWT.CHECK);
140 button.setText(text);
141 GridData grid = new GridData();
142 grid.horizontalSpan = hspan;
143 button.setLayoutData(grid);
144 return button;
145 }
146
147
148 /***
149 * Creates an editable combo box
150 *
151 * @param parent the parent of the combo box
152 * @return the created combo
153 */
154 protected Combo createEditableCombo(Composite parent) {
155 Combo combo = new Combo(parent, SWT.NULL);
156 GridData data = new GridData(GridData.FILL_HORIZONTAL);
157 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
158 combo.setLayoutData(data);
159 return combo;
160 }
161
162 }