01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.ui.wizards.dialogfields;
11:
12: import org.eclipse.swt.SWT;
13: import org.eclipse.swt.widgets.Composite;
14: import org.eclipse.swt.widgets.Control;
15: import org.eclipse.swt.widgets.Label;
16:
17: import org.eclipse.swt.layout.GridData;
18:
19: /**
20: * Dialog field describing a separator.
21: */
22: public class Separator extends DialogField {
23:
24: private Label fSeparator;
25: private int fStyle;
26:
27: public Separator() {
28: this (SWT.NONE);
29: }
30:
31: /**
32: * @param style of the separator. See <code>Label</code> for possible
33: * styles.
34: */
35: public Separator(int style) {
36: super ();
37: fStyle = style;
38: }
39:
40: // ------- layout helpers
41:
42: /**
43: * Creates the separator and fills it in a MGridLayout.
44: * @param height The height of the separator
45: */
46: public Control[] doFillIntoGrid(Composite parent, int nColumns,
47: int height) {
48: assertEnoughColumns(nColumns);
49:
50: Control separator = getSeparator(parent);
51: separator.setLayoutData(gridDataForSeperator(nColumns, height));
52:
53: return new Control[] { separator };
54: }
55:
56: /*
57: * @see DialogField#doFillIntoGrid
58: */
59: public Control[] doFillIntoGrid(Composite parent, int nColumns) {
60: return doFillIntoGrid(parent, nColumns, 4);
61: }
62:
63: /*
64: * @see DialogField#getNumberOfControls
65: */
66: public int getNumberOfControls() {
67: return 1;
68: }
69:
70: protected static GridData gridDataForSeperator(int span, int height) {
71: GridData gd = new GridData();
72: gd.horizontalAlignment = GridData.FILL;
73: gd.verticalAlignment = GridData.BEGINNING;
74: gd.heightHint = height;
75: gd.horizontalSpan = span;
76: return gd;
77: }
78:
79: // ------- ui creation
80:
81: /**
82: * Creates or returns the created separator.
83: * @param parent The parent composite or <code>null</code> if the widget has
84: * already been created.
85: */
86: public Control getSeparator(Composite parent) {
87: if (fSeparator == null) {
88: assertCompositeNotNull(parent);
89: fSeparator = new Label(parent, fStyle);
90: }
91: return fSeparator;
92: }
93:
94: }
|