KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > dialogfields > Separator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.eclipse.jdt.internal.ui.wizards.dialogfields;
12
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.widgets.Composite;
15 import org.eclipse.swt.widgets.Control;
16 import org.eclipse.swt.widgets.Label;
17
18 import org.eclipse.swt.layout.GridData;
19
20 /**
21  * Dialog field describing a separator.
22  */

23 public class Separator extends DialogField {
24     
25     private Label fSeparator;
26     private int fStyle;
27     
28     public Separator() {
29         this(SWT.NONE);
30     }
31     
32     /**
33      * @param style of the separator. See <code>Label</code> for possible
34      * styles.
35      */

36     public Separator(int style) {
37         super();
38         fStyle= style;
39     }
40             
41     // ------- layout helpers
42

43     /**
44      * Creates the separator and fills it in a MGridLayout.
45      * @param height The height of the separator
46      */

47     public Control[] doFillIntoGrid(Composite parent, int nColumns, 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 }
95
Popular Tags