Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / wizards / dialogfields / Separator.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.ui.wizards.dialogfields;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.layout.GridData;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Label;
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 heigth of the separator
45          */             
46         public Control[] doFillIntoGrid(Composite parent, int nColumns, int height) {
47                 assertEnoughColumns(nColumns);
48                 
49                 Control separator= getSeparator(parent);
50                 separator.setLayoutData(gridDataForSeperator(nColumns, height));
51                 
52                 return new Control[] { separator };
53         }
54
55         /*
56          * @see DialogField#doFillIntoGrid
57          */     
58         public Control[] doFillIntoGrid(Composite parent, int nColumns) {
59                 return doFillIntoGrid(parent, nColumns, 4);
60         }
61
62         /*
63          * @see DialogField#getNumberOfControls
64          */     
65         public int getNumberOfControls() {
66                 return 1;       
67         }
68         
69         protected static GridData gridDataForSeperator(int span, int height) {
70                 GridData gd= new GridData();
71                 gd.horizontalAlignment= GridData.FILL;
72                 gd.verticalAlignment= GridData.BEGINNING;
73                 gd.heightHint= height;          
74                 gd.horizontalSpan= span;
75                 return gd;
76         }
77         
78         // ------- ui creation  
79
80         /**
81          * Creates or returns the created separator.
82          * @param parent The parent composite or <code>null</code> if the widget has
83          * already been created.
84          */     
85         public Control getSeparator(Composite parent) {
86                 if (fSeparator == null) {
87                         assertCompositeNotNull(parent);
88                         fSeparator= new Label(parent, fStyle);
89                 }       
90                 return fSeparator;
91         }
92
93 }