KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > composite > DisguisedText


1 /*
2  * Created on Jan 8, 2005
3  * by alex
4  *
5  */

6 package com.nightlabs.rcp.composite;
7
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.widgets.Composite;
11 import org.eclipse.swt.widgets.Label;
12 import org.eclipse.swt.widgets.Text;
13
14 /**
15  * Provides a Text Widget with no border
16  * and the same Background as
17  * its parent. As subclassing of {@link org.eclipse.swt.widgets.Widget}
18  * is not allowed a static method will
19  * create and return a Text.
20  *
21  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
22  */

23 public class DisguisedText {
24
25     /**
26      * Creates a disguised Text.
27      *
28      * @param parent
29      */

30     public static Text createText(Composite parent) {
31         Text text = new Text(parent,SWT.NONE);
32         text.setBackground(parent.getBackground());
33         return text;
34     }
35     
36     /**
37      * Creates a Label and a disguised Text and adds
38      * GridDatas to them assuming that the parent has
39      * a GridLayout with two free columns in the current row.
40      *
41      * @param title
42      * @param parent
43      * @return
44      */

45     public static LabeledDisguisedText createLabeledText(String JavaDoc title, Composite parent) {
46         Label label = new Label(parent, SWT.NONE);
47         label.setText(title);
48         label.setLayoutData(new GridData());
49         
50         Text text = createText(parent);
51         text.setText("");
52         text.setEditable(true);
53         GridData gd = new GridData();
54         gd.grabExcessHorizontalSpace = true;
55         gd.horizontalAlignment = GridData.FILL;
56         text.setLayoutData(gd);
57         LabeledDisguisedText result = new LabeledDisguisedText();
58         result.setLabelControl(label);
59         result.setTextControl(text);
60         return result;
61     }
62     
63     /**
64      * Helper class for {@link DisguisedText#createLabeledText(String, Composite)}
65      *
66      */

67     public static class LabeledDisguisedText {
68
69         /**
70          *
71          */

72         public LabeledDisguisedText() {
73             super();
74         }
75         
76         private Label labelControl;
77         private Text textControl;
78         
79         public Label getLabelControl() {
80             return labelControl;
81         }
82         public void setLabelControl(Label labelControl) {
83             this.labelControl = labelControl;
84         }
85         public Text getTextControl() {
86             return textControl;
87         }
88         public void setTextControl(Text textControl) {
89             this.textControl = textControl;
90         }
91
92     }
93 }
94
Popular Tags