diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:23:09 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 13:24:09 +0200 |
commit | c7da892cb23d50d4d85746c9a0b6b14bf570989d (patch) | |
tree | e7136073f386d6156f51766c498c52c30c8df85f /plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/SWTFactory.java | |
download | eclipse-poky-kepler-c7da892cb23d50d4d85746c9a0b6b14bf570989d.tar.gz |
initial commit for Enea Linux 4.0daisy
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/SWTFactory.java')
-rw-r--r-- | plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/SWTFactory.java | 642 |
1 files changed, 642 insertions, 0 deletions
diff --git a/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/SWTFactory.java b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/SWTFactory.java new file mode 100644 index 0000000..27b5dae --- /dev/null +++ b/plugins/org.yocto.sdk.remotetools/src/org/yocto/sdk/remotetools/SWTFactory.java | |||
@@ -0,0 +1,642 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2000, 2010 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 | package org.yocto.sdk.remotetools; | ||
12 | |||
13 | import org.eclipse.core.runtime.Assert; | ||
14 | import org.eclipse.jface.dialogs.IDialogConstants; | ||
15 | import org.eclipse.jface.layout.PixelConverter; | ||
16 | import org.eclipse.jface.resource.JFaceResources; | ||
17 | import org.eclipse.swt.SWT; | ||
18 | import org.eclipse.swt.custom.CLabel; | ||
19 | import org.eclipse.swt.custom.ViewForm; | ||
20 | import org.eclipse.swt.graphics.Font; | ||
21 | import org.eclipse.swt.graphics.Image; | ||
22 | import org.eclipse.swt.layout.GridData; | ||
23 | import org.eclipse.swt.layout.GridLayout; | ||
24 | import org.eclipse.swt.widgets.Button; | ||
25 | import org.eclipse.swt.widgets.Combo; | ||
26 | import org.eclipse.swt.widgets.Composite; | ||
27 | import org.eclipse.swt.widgets.Group; | ||
28 | import org.eclipse.swt.widgets.Label; | ||
29 | import org.eclipse.swt.widgets.Layout; | ||
30 | import org.eclipse.swt.widgets.Text; | ||
31 | import org.eclipse.ui.forms.widgets.ExpandableComposite; | ||
32 | |||
33 | /** | ||
34 | * Factory class to create some SWT resources. | ||
35 | */ | ||
36 | public class SWTFactory { | ||
37 | |||
38 | /** | ||
39 | * Returns a width hint for a button control. | ||
40 | */ | ||
41 | public static int getButtonWidthHint(Button button) { | ||
42 | /*button.setFont(JFaceResources.getDialogFont());*/ | ||
43 | PixelConverter converter= new PixelConverter(button); | ||
44 | int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); | ||
45 | return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); | ||
46 | } | ||
47 | |||
48 | /** | ||
49 | * Sets width and height hint for the button control. | ||
50 | * <b>Note:</b> This is a NOP if the button's layout data is not | ||
51 | * an instance of <code>GridData</code>. | ||
52 | * | ||
53 | * @param the button for which to set the dimension hint | ||
54 | */ | ||
55 | public static void setButtonDimensionHint(Button button) { | ||
56 | Assert.isNotNull(button); | ||
57 | Object gd= button.getLayoutData(); | ||
58 | if (gd instanceof GridData) { | ||
59 | ((GridData)gd).widthHint= getButtonWidthHint(button); | ||
60 | ((GridData)gd).horizontalAlignment = GridData.FILL; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Creates a check box button using the parents' font | ||
66 | * @param parent the parent to add the button to | ||
67 | * @param label the label for the button | ||
68 | * @param image the image for the button | ||
69 | * @param checked the initial checked state of the button | ||
70 | * @param hspan the horizontal span to take up in the parent composite | ||
71 | * @return a new checked button set to the initial checked state | ||
72 | * @since 3.3 | ||
73 | */ | ||
74 | public static Button createCheckButton(Composite parent, String label, Image image, boolean checked, int hspan) { | ||
75 | Button button = new Button(parent, SWT.CHECK); | ||
76 | button.setFont(parent.getFont()); | ||
77 | button.setSelection(checked); | ||
78 | if(image != null) { | ||
79 | button.setImage(image); | ||
80 | } | ||
81 | if(label != null) { | ||
82 | button.setText(label); | ||
83 | } | ||
84 | GridData gd = new GridData(); | ||
85 | gd.horizontalSpan = hspan; | ||
86 | button.setLayoutData(gd); | ||
87 | setButtonDimensionHint(button); | ||
88 | return button; | ||
89 | } | ||
90 | |||
91 | /** | ||
92 | * Creates and returns a new push button with the given | ||
93 | * label and/or image. | ||
94 | * | ||
95 | * @param parent parent control | ||
96 | * @param label button label or <code>null</code> | ||
97 | * @param image image of <code>null</code> | ||
98 | * | ||
99 | * @return a new push button | ||
100 | */ | ||
101 | public static Button createPushButton(Composite parent, String label, Image image) { | ||
102 | Button button = new Button(parent, SWT.PUSH); | ||
103 | button.setFont(parent.getFont()); | ||
104 | if (image != null) { | ||
105 | button.setImage(image); | ||
106 | } | ||
107 | if (label != null) { | ||
108 | button.setText(label); | ||
109 | } | ||
110 | GridData gd = new GridData(); | ||
111 | button.setLayoutData(gd); | ||
112 | setButtonDimensionHint(button); | ||
113 | return button; | ||
114 | } | ||
115 | |||
116 | /** | ||
117 | * Creates and returns a new push button with the given | ||
118 | * label and/or image. | ||
119 | * | ||
120 | * @param parent parent control | ||
121 | * @param label button label or <code>null</code> | ||
122 | * @param image image of <code>null</code> | ||
123 | * @param fill the alignment for the new button | ||
124 | * | ||
125 | * @return a new push button | ||
126 | * @since 3.4 | ||
127 | */ | ||
128 | public static Button createPushButton(Composite parent, String label, Image image, int fill) { | ||
129 | Button button = new Button(parent, SWT.PUSH); | ||
130 | button.setFont(parent.getFont()); | ||
131 | if (image != null) { | ||
132 | button.setImage(image); | ||
133 | } | ||
134 | if (label != null) { | ||
135 | button.setText(label); | ||
136 | } | ||
137 | GridData gd = new GridData(fill); | ||
138 | button.setLayoutData(gd); | ||
139 | setButtonDimensionHint(button); | ||
140 | return button; | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * Creates and returns a new push button with the given | ||
145 | * label, tooltip and/or image. | ||
146 | * | ||
147 | * @param parent parent control | ||
148 | * @param label button label or <code>null</code> | ||
149 | * @param tooltip the tooltip text for the button or <code>null</code> | ||
150 | * @param image image of <code>null</code> | ||
151 | * | ||
152 | * @return a new push button | ||
153 | * @since 3.6 | ||
154 | */ | ||
155 | public static Button createPushButton(Composite parent, String label, String tooltip, Image image) { | ||
156 | Button button = createPushButton(parent, label, image); | ||
157 | button.setToolTipText(tooltip); | ||
158 | return button; | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * Creates and returns a new radio button with the given | ||
163 | * label. | ||
164 | * | ||
165 | * @param parent parent control | ||
166 | * @param label button label or <code>null</code> | ||
167 | * | ||
168 | * @return a new radio button | ||
169 | */ | ||
170 | public static Button createRadioButton(Composite parent, String label) { | ||
171 | Button button = new Button(parent, SWT.RADIO); | ||
172 | button.setFont(parent.getFont()); | ||
173 | if (label != null) { | ||
174 | button.setText(label); | ||
175 | } | ||
176 | GridData gd = new GridData(); | ||
177 | button.setLayoutData(gd); | ||
178 | setButtonDimensionHint(button); | ||
179 | return button; | ||
180 | } | ||
181 | |||
182 | /** | ||
183 | * Creates and returns a new radio button with the given | ||
184 | * label. | ||
185 | * | ||
186 | * @param parent parent control | ||
187 | * @param label button label or <code>null</code> | ||
188 | * @param hspan the number of columns to span in the parent composite | ||
189 | * | ||
190 | * @return a new radio button | ||
191 | * @since 3.6 | ||
192 | */ | ||
193 | public static Button createRadioButton(Composite parent, String label, int hspan) { | ||
194 | Button button = new Button(parent, SWT.RADIO); | ||
195 | button.setFont(parent.getFont()); | ||
196 | if (label != null) { | ||
197 | button.setText(label); | ||
198 | } | ||
199 | GridData gd = new GridData(GridData.BEGINNING); | ||
200 | gd.horizontalSpan = hspan; | ||
201 | button.setLayoutData(gd); | ||
202 | setButtonDimensionHint(button); | ||
203 | return button; | ||
204 | } | ||
205 | |||
206 | /** | ||
207 | * Creates a new label widget | ||
208 | * @param parent the parent composite to add this label widget to | ||
209 | * @param text the text for the label | ||
210 | * @param hspan the horizontal span to take up in the parent composite | ||
211 | * @return the new label | ||
212 | * @since 3.2 | ||
213 | * | ||
214 | */ | ||
215 | public static Label createLabel(Composite parent, String text, int hspan) { | ||
216 | Label l = new Label(parent, SWT.NONE); | ||
217 | l.setFont(parent.getFont()); | ||
218 | l.setText(text); | ||
219 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
220 | gd.horizontalSpan = hspan; | ||
221 | gd.grabExcessHorizontalSpace = false; | ||
222 | l.setLayoutData(gd); | ||
223 | return l; | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * Creates a new label widget | ||
228 | * @param parent the parent composite to add this label widget to | ||
229 | * @param text the text for the label | ||
230 | * @param font the font for the label | ||
231 | * @param hspan the horizontal span to take up in the parent composite | ||
232 | * @return the new label | ||
233 | * @since 3.3 | ||
234 | */ | ||
235 | public static Label createLabel(Composite parent, String text, Font font, int hspan) { | ||
236 | Label l = new Label(parent, SWT.NONE); | ||
237 | l.setFont(font); | ||
238 | l.setText(text); | ||
239 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
240 | gd.horizontalSpan = hspan; | ||
241 | l.setLayoutData(gd); | ||
242 | return l; | ||
243 | } | ||
244 | |||
245 | /** | ||
246 | * Creates a wrapping label | ||
247 | * @param parent the parent composite to add this label to | ||
248 | * @param text the text to be displayed in the label | ||
249 | * @param hspan the horizontal span that label should take up in the parent composite | ||
250 | * @param wrapwidth the width hint that the label should wrap at | ||
251 | * @return a new label that wraps at a specified width | ||
252 | * @since 3.3 | ||
253 | */ | ||
254 | public static Label createWrapLabel(Composite parent, String text, int hspan, int wrapwidth) { | ||
255 | Label l = new Label(parent, SWT.NONE | SWT.WRAP); | ||
256 | l.setFont(parent.getFont()); | ||
257 | l.setText(text); | ||
258 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
259 | gd.horizontalSpan = hspan; | ||
260 | gd.widthHint = wrapwidth; | ||
261 | l.setLayoutData(gd); | ||
262 | return l; | ||
263 | } | ||
264 | |||
265 | /** | ||
266 | * Creates a new <code>CLabel</code> that will wrap at the specified width and has the specified image | ||
267 | * @param parent the parent to add this label to | ||
268 | * @param text the text for the label | ||
269 | * @param image the image for the label | ||
270 | * @param hspan the h span to take up in the parent | ||
271 | * @param wrapwidth the with to wrap at | ||
272 | * @return a new <code>CLabel</code> | ||
273 | * @since 3.3 | ||
274 | */ | ||
275 | public static CLabel createWrapCLabel(Composite parent, String text, Image image, int hspan, int wrapwidth) { | ||
276 | CLabel label = new CLabel(parent, SWT.NONE | SWT.WRAP); | ||
277 | label.setFont(parent.getFont()); | ||
278 | if(text != null) { | ||
279 | label.setText(text); | ||
280 | } | ||
281 | if(image != null) { | ||
282 | label.setImage(image); | ||
283 | } | ||
284 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
285 | gd.horizontalSpan = hspan; | ||
286 | gd.widthHint = wrapwidth; | ||
287 | label.setLayoutData(gd); | ||
288 | return label; | ||
289 | } | ||
290 | |||
291 | /** | ||
292 | * Creates a wrapping label | ||
293 | * @param parent the parent composite to add this label to | ||
294 | * @param text the text to be displayed in the label | ||
295 | * @param hspan the horizontal span that label should take up in the parent composite | ||
296 | * @return a new label that wraps at a specified width | ||
297 | * @since 3.3 | ||
298 | */ | ||
299 | public static Label createWrapLabel(Composite parent, String text, int hspan) { | ||
300 | Label l = new Label(parent, SWT.NONE | SWT.WRAP); | ||
301 | l.setFont(parent.getFont()); | ||
302 | l.setText(text); | ||
303 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
304 | gd.horizontalSpan = hspan; | ||
305 | l.setLayoutData(gd); | ||
306 | return l; | ||
307 | } | ||
308 | |||
309 | /** | ||
310 | * Creates a new text widget | ||
311 | * @param parent the parent composite to add this text widget to | ||
312 | * @param hspan the horizontal span to take up on the parent composite | ||
313 | * @return the new text widget | ||
314 | * @since 3.2 | ||
315 | * | ||
316 | */ | ||
317 | public static Text createSingleText(Composite parent, int hspan) { | ||
318 | Text t = new Text(parent, SWT.SINGLE | SWT.BORDER); | ||
319 | t.setFont(parent.getFont()); | ||
320 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
321 | gd.horizontalSpan = hspan; | ||
322 | t.setLayoutData(gd); | ||
323 | return t; | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * Creates a new text widget | ||
328 | * @param parent the parent composite to add this text widget to | ||
329 | * @param style the style bits for the text widget | ||
330 | * @param hspan the horizontal span to take up on the parent composite | ||
331 | * @param fill the fill for the grid layout | ||
332 | * @return the new text widget | ||
333 | * @since 3.3 | ||
334 | */ | ||
335 | public static Text createText(Composite parent, int style, int hspan, int fill) { | ||
336 | Text t = new Text(parent, style); | ||
337 | t.setFont(parent.getFont()); | ||
338 | GridData gd = new GridData(fill); | ||
339 | gd.horizontalSpan = hspan; | ||
340 | t.setLayoutData(gd); | ||
341 | return t; | ||
342 | } | ||
343 | |||
344 | /** | ||
345 | * Creates a new text widget | ||
346 | * @param parent the parent composite to add this text widget to | ||
347 | * @param style the style bits for the text widget | ||
348 | * @param hspan the horizontal span to take up on the parent composite | ||
349 | * @return the new text widget | ||
350 | * @since 3.3 | ||
351 | */ | ||
352 | public static Text createText(Composite parent, int style, int hspan) { | ||
353 | Text t = new Text(parent, style); | ||
354 | t.setFont(parent.getFont()); | ||
355 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
356 | gd.horizontalSpan = hspan; | ||
357 | t.setLayoutData(gd); | ||
358 | return t; | ||
359 | } | ||
360 | |||
361 | /** | ||
362 | * Creates a new text widget | ||
363 | * @param parent the parent composite to add this text widget to | ||
364 | * @param style the style bits for the text widget | ||
365 | * @param hspan the horizontal span to take up on the parent composite | ||
366 | * @param width the desired width of the text widget | ||
367 | * @param height the desired height of the text widget | ||
368 | * @param fill the fill style for the widget | ||
369 | * @return the new text widget | ||
370 | * @since 3.3 | ||
371 | */ | ||
372 | public static Text createText(Composite parent, int style, int hspan, int width, int height, int fill) { | ||
373 | Text t = new Text(parent, style); | ||
374 | t.setFont(parent.getFont()); | ||
375 | GridData gd = new GridData(fill); | ||
376 | gd.horizontalSpan = hspan; | ||
377 | gd.widthHint = width; | ||
378 | gd.heightHint = height; | ||
379 | t.setLayoutData(gd); | ||
380 | return t; | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * Creates a new text widget | ||
385 | * @param parent the parent composite to add this text widget to | ||
386 | * @param style the style bits for the text widget | ||
387 | * @param hspan the horizontal span to take up on the parent composite | ||
388 | * @param text the initial text, not <code>null</code> | ||
389 | * @return the new text widget | ||
390 | * @since 3.6 | ||
391 | */ | ||
392 | public static Text createText(Composite parent, int style, int hspan, String text) { | ||
393 | Text t = new Text(parent, style); | ||
394 | t.setFont(parent.getFont()); | ||
395 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
396 | gd.horizontalSpan = hspan; | ||
397 | t.setLayoutData(gd); | ||
398 | t.setText(text); | ||
399 | return t; | ||
400 | } | ||
401 | |||
402 | /** | ||
403 | * Creates a Group widget | ||
404 | * @param parent the parent composite to add this group to | ||
405 | * @param text the text for the heading of the group | ||
406 | * @param columns the number of columns within the group | ||
407 | * @param hspan the horizontal span the group should take up on the parent | ||
408 | * @param fill the style for how this composite should fill into its parent | ||
409 | * @return the new group | ||
410 | * @since 3.2 | ||
411 | * | ||
412 | */ | ||
413 | public static Group createGroup(Composite parent, String text, int columns, int hspan, int fill) { | ||
414 | Group g = new Group(parent, SWT.NONE); | ||
415 | g.setLayout(new GridLayout(columns, false)); | ||
416 | g.setText(text); | ||
417 | g.setFont(parent.getFont()); | ||
418 | GridData gd = new GridData(fill); | ||
419 | gd.horizontalSpan = hspan; | ||
420 | g.setLayoutData(gd); | ||
421 | return g; | ||
422 | } | ||
423 | |||
424 | /** | ||
425 | * Creates a Composite widget | ||
426 | * @param parent the parent composite to add this composite to | ||
427 | * @param font the font to set on the control | ||
428 | * @param columns the number of columns within the composite | ||
429 | * @param hspan the horizontal span the composite should take up on the parent | ||
430 | * @param fill the style for how this composite should fill into its parent | ||
431 | * @return the new group | ||
432 | * @since 3.3 | ||
433 | */ | ||
434 | public static Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill) { | ||
435 | Composite g = new Composite(parent, SWT.NONE); | ||
436 | g.setLayout(new GridLayout(columns, false)); | ||
437 | g.setFont(font); | ||
438 | GridData gd = new GridData(fill); | ||
439 | gd.horizontalSpan = hspan; | ||
440 | g.setLayoutData(gd); | ||
441 | return g; | ||
442 | } | ||
443 | |||
444 | /** | ||
445 | * Creates an ExpandibleComposite widget | ||
446 | * @param parent the parent to add this widget to | ||
447 | * @param style the style for ExpandibleComposite expanding handle, and layout | ||
448 | * @param label the label for the widget | ||
449 | * @param hspan how many columns to span in the parent | ||
450 | * @param fill the fill style for the widget | ||
451 | * Can be one of <code>GridData.FILL_HORIZONAL</code>, <code>GridData.FILL_BOTH</code> or <code>GridData.FILL_VERTICAL</code> | ||
452 | * @return a new ExpandibleComposite widget | ||
453 | * @since 3.6 | ||
454 | */ | ||
455 | public static ExpandableComposite createExpandibleComposite(Composite parent, int style, String label, int hspan, int fill) { | ||
456 | ExpandableComposite ex = new ExpandableComposite(parent, SWT.NONE, style); | ||
457 | ex.setText(label); | ||
458 | ex.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT)); | ||
459 | GridData gd = new GridData(fill); | ||
460 | gd.horizontalSpan = hspan; | ||
461 | ex.setLayoutData(gd); | ||
462 | return ex; | ||
463 | } | ||
464 | |||
465 | /** | ||
466 | * Creates a composite that uses the parent's font and has a grid layout | ||
467 | * @param parent the parent to add the composite to | ||
468 | * @param columns the number of columns the composite should have | ||
469 | * @param hspan the horizontal span the new composite should take up in the parent | ||
470 | * @param fill the fill style of the composite {@link GridData} | ||
471 | * @return a new composite with a grid layout | ||
472 | * | ||
473 | * @since 3.3 | ||
474 | */ | ||
475 | public static Composite createComposite(Composite parent, int columns, int hspan, int fill) { | ||
476 | Composite g = new Composite(parent, SWT.NONE); | ||
477 | g.setLayout(new GridLayout(columns, false)); | ||
478 | g.setFont(parent.getFont()); | ||
479 | GridData gd = new GridData(fill); | ||
480 | gd.horizontalSpan = hspan; | ||
481 | g.setLayoutData(gd); | ||
482 | return g; | ||
483 | } | ||
484 | |||
485 | /** | ||
486 | * Creates a vertical spacer for separating components. If applied to a | ||
487 | * <code>GridLayout</code>, this method will automatically span all of the columns of the parent | ||
488 | * to make vertical space | ||
489 | * | ||
490 | * @param parent the parent composite to add this spacer to | ||
491 | * @param numlines the number of vertical lines to make as space | ||
492 | * @since 3.3 | ||
493 | */ | ||
494 | public static void createVerticalSpacer(Composite parent, int numlines) { | ||
495 | Label lbl = new Label(parent, SWT.NONE); | ||
496 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
497 | Layout layout = parent.getLayout(); | ||
498 | if(layout instanceof GridLayout) { | ||
499 | gd.horizontalSpan = ((GridLayout)parent.getLayout()).numColumns; | ||
500 | } | ||
501 | gd.heightHint = numlines; | ||
502 | lbl.setLayoutData(gd); | ||
503 | } | ||
504 | |||
505 | /** | ||
506 | * creates a horizontal spacer for separating components | ||
507 | * @param comp | ||
508 | * @param numlines | ||
509 | * @since 3.3 | ||
510 | */ | ||
511 | public static void createHorizontalSpacer(Composite comp, int numlines) { | ||
512 | Label lbl = new Label(comp, SWT.NONE); | ||
513 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
514 | gd.horizontalSpan = numlines; | ||
515 | lbl.setLayoutData(gd); | ||
516 | } | ||
517 | |||
518 | /** | ||
519 | * Creates a Composite widget | ||
520 | * @param parent the parent composite to add this composite to | ||
521 | * @param font the font to set on the control | ||
522 | * @param columns the number of columns within the composite | ||
523 | * @param hspan the horizontal span the composite should take up on the parent | ||
524 | * @param fill the style for how this composite should fill into its parent | ||
525 | * @param marginwidth the width of the margin to place on the sides of the composite (default is 5, specified by GridLayout) | ||
526 | * @param marginheight the height of the margin to place o the top and bottom of the composite | ||
527 | * @return the new composite | ||
528 | * @since 3.3 | ||
529 | */ | ||
530 | public static Composite createComposite(Composite parent, Font font, int columns, int hspan, int fill, int marginwidth, int marginheight) { | ||
531 | Composite g = new Composite(parent, SWT.NONE); | ||
532 | GridLayout layout = new GridLayout(columns, false); | ||
533 | layout.marginWidth = marginwidth; | ||
534 | layout.marginHeight = marginheight; | ||
535 | g.setLayout(layout); | ||
536 | g.setFont(font); | ||
537 | GridData gd = new GridData(fill); | ||
538 | gd.horizontalSpan = hspan; | ||
539 | g.setLayoutData(gd); | ||
540 | return g; | ||
541 | } | ||
542 | |||
543 | /** | ||
544 | * Creates a {@link ViewForm} | ||
545 | * @param parent | ||
546 | * @param style | ||
547 | * @param cols | ||
548 | * @param span | ||
549 | * @param fill | ||
550 | * @param marginwidth | ||
551 | * @param marginheight | ||
552 | * @return a new {@link ViewForm} | ||
553 | * @since 3.6 | ||
554 | */ | ||
555 | public static ViewForm createViewform(Composite parent, int style, int cols, int span, int fill, int marginwidth, int marginheight) { | ||
556 | ViewForm form = new ViewForm(parent, style); | ||
557 | form.setFont(parent.getFont()); | ||
558 | GridLayout layout = new GridLayout(cols, false); | ||
559 | layout.marginWidth = marginwidth; | ||
560 | layout.marginHeight = marginheight; | ||
561 | form.setLayout(layout); | ||
562 | GridData gd = new GridData(fill); | ||
563 | gd.horizontalSpan = span; | ||
564 | form.setLayoutData(gd); | ||
565 | return form; | ||
566 | } | ||
567 | |||
568 | /** | ||
569 | * Creates a Composite widget | ||
570 | * @param parent the parent composite to add this composite to | ||
571 | * @param font the font to set on the control | ||
572 | * @param columns the number of columns within the composite | ||
573 | * @param hspan the horizontal span the composite should take up on the parent | ||
574 | * @param fill the style for how this composite should fill into its parent | ||
575 | * @param marginwidth the width of the margin to place on the sides of the composite (default is 5, specified by GridLayout) | ||
576 | * @param marginheight the height of the margin to place o the top and bottom of the composite | ||
577 | * @return the new composite | ||
578 | * @since 3.6 | ||
579 | */ | ||
580 | public static Composite createComposite(Composite parent, Font font, int style, int columns, int hspan, int fill, int marginwidth, int marginheight) { | ||
581 | Composite g = new Composite(parent, style); | ||
582 | GridLayout layout = new GridLayout(columns, false); | ||
583 | layout.marginWidth = marginwidth; | ||
584 | layout.marginHeight = marginheight; | ||
585 | g.setLayout(layout); | ||
586 | g.setFont(font); | ||
587 | GridData gd = new GridData(fill); | ||
588 | gd.horizontalSpan = hspan; | ||
589 | g.setLayoutData(gd); | ||
590 | return g; | ||
591 | } | ||
592 | |||
593 | /** | ||
594 | * This method is used to make a combo box | ||
595 | * @param parent the parent composite to add the new combo to | ||
596 | * @param style the style for the Combo | ||
597 | * @param hspan the horizontal span to take up on the parent composite | ||
598 | * @param fill how the combo will fill into the composite | ||
599 | * Can be one of <code>GridData.FILL_HORIZONAL</code>, <code>GridData.FILL_BOTH</code> or <code>GridData.FILL_VERTICAL</code> | ||
600 | * @param items the item to put into the combo | ||
601 | * @return a new Combo instance | ||
602 | * @since 3.3 | ||
603 | */ | ||
604 | public static Combo createCombo(Composite parent, int style, int hspan, int fill, String[] items) { | ||
605 | Combo c = new Combo(parent, style); | ||
606 | c.setFont(parent.getFont()); | ||
607 | GridData gd = new GridData(fill); | ||
608 | gd.horizontalSpan = hspan; | ||
609 | c.setLayoutData(gd); | ||
610 | if (items != null){ | ||
611 | c.setItems(items); | ||
612 | } | ||
613 | // Some platforms open up combos in bad sizes without this, see bug 245569 | ||
614 | c.setVisibleItemCount(30); | ||
615 | c.select(0); | ||
616 | return c; | ||
617 | } | ||
618 | |||
619 | /** | ||
620 | * This method is used to make a combo box with a default fill style of GridData.FILL_HORIZONTAL | ||
621 | * @param parent the parent composite to add the new combo to | ||
622 | * @param style the style for the Combo | ||
623 | * @param hspan the horizontal span to take up on the parent composite | ||
624 | * @param items the item to put into the combo | ||
625 | * @return a new Combo instance | ||
626 | * @since 3.3 | ||
627 | */ | ||
628 | public static Combo createCombo(Composite parent, int style, int hspan, String[] items) { | ||
629 | Combo c = new Combo(parent, style); | ||
630 | c.setFont(parent.getFont()); | ||
631 | GridData gd = new GridData(GridData.FILL_HORIZONTAL); | ||
632 | gd.horizontalSpan = hspan; | ||
633 | c.setLayoutData(gd); | ||
634 | if (items != null){ | ||
635 | c.setItems(items); | ||
636 | } | ||
637 | // Some platforms open up combos in bad sizes without this, see bug 245569 | ||
638 | c.setVisibleItemCount(30); | ||
639 | c.select(0); | ||
640 | return c; | ||
641 | } | ||
642 | } | ||