View Javadoc

1   /*
2    * Copyright (c) 2003, Andreas Pataki 
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    *
9    * Redistributions of source code must retain the above copyright notice,
10   * this list of conditions and the following disclaimer.
11   * 
12   * Redistributions in binary form must reproduce the above copyright notice,
13   * this list of conditions and the following disclaimer in the documentation
14   * and/or other materials provided with the distribution.
15   * 
16   * Neither the name of the author nor the names of its contributors
17   * may be used to endorse or promote products derived from this software
18   * without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS
21   * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22   * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   */
32  
33  package net.sf.tm.plugin.ui;
34  
35  import org.eclipse.jface.dialogs.IDialogConstants;
36  import org.eclipse.swt.SWT;
37  import org.eclipse.swt.layout.GridData;
38  import org.eclipse.swt.layout.GridLayout;
39  import org.eclipse.swt.widgets.Button;
40  import org.eclipse.swt.widgets.Combo;
41  import org.eclipse.swt.widgets.Composite;
42  import org.eclipse.swt.widgets.Group;
43  import org.eclipse.swt.widgets.Label;
44  import org.eclipse.swt.widgets.Text;
45  
46  /***
47   * @author Andreas Pataki
48   * @version $Id: WidgetFactory.java,v 1.4 2003/11/17 20:53:07 apataki Exp $
49   */
50  class WidgetFactory {
51  
52  
53      /***
54        * Creates a component group.
55        * 
56        * @param parent parent
57        * @param text display text
58        * @return created group
59        */
60      public Group createGroup(Composite parent, String text) {
61          Group group = new Group(parent, SWT.NULL);
62          group.setText(text);
63          GridData data = new GridData(GridData.FILL_HORIZONTAL);
64          data.horizontalSpan = 2;
65  
66          group.setLayoutData(data);
67          GridLayout layout = new GridLayout();
68          layout.numColumns = 2;
69          group.setLayout(layout);
70          return group;
71      }
72  
73      /***
74       * Creates an input label.
75       * 
76       * @param parent parent component
77       * @param text label text
78       * @return the created label
79       */
80      public Label createLabel(Composite parent, String text) {
81          return createLabel(parent, text, 1);
82      }
83  
84      /***
85       * Creates an input label.
86       * 
87       * @param parent parent component
88       * @param text label text
89       * @param hspan horizontal cell span
90       * @return created label
91       */
92      public Label createLabel(Composite parent, String text, int hspan) {
93          Label label = new Label(parent, SWT.LEFT);
94          label.setText(text);
95          GridData data = new GridData();
96          data.horizontalSpan = hspan;
97          data.horizontalAlignment = GridData.FILL;
98          data.horizontalIndent = 0;
99          label.setLayoutData(data);
100         return label;
101     }
102 
103     /***
104      * Creates an input text field.
105      * 
106      * @param parent parent component
107      * @return created input field
108      */
109     public Text createTextField(Composite parent) {
110         Text text = new Text(parent, SWT.SINGLE | SWT.BORDER);
111         GridData data = new GridData(GridData.FILL_HORIZONTAL);
112         data.verticalAlignment = GridData.CENTER;
113         data.grabExcessVerticalSpace = false;
114         data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
115         text.setLayoutData(data);
116         return text;
117     }
118 
119     /***
120      * Create a checkbox
121      * 
122      * @param parent parent composite
123      * @param text checkbox text
124      * @return The created Checkbox
125      */
126     public Button createCheckbox(Composite parent, String text) {
127         return createCheckbox(parent, text, 3);    
128     }
129 
130     /***
131      * Create a checkbox
132      * 
133      * @param parent parent composite
134      * @param text checkbox text
135      * @param hspan the horizontal span
136      * @return The created Checkbox
137      */
138     public Button createCheckbox(Composite parent, String text, int hspan) {
139         Button button = new Button(parent, SWT.CHECK);
140         button.setText(text);
141         GridData grid = new GridData();
142         grid.horizontalSpan = hspan;
143         button.setLayoutData(grid);
144         return button;
145     }
146     
147     
148     /***
149      * Creates an editable combo box
150      * 
151      * @param parent  the parent of the combo box
152      * @return the created combo
153      */
154     protected Combo createEditableCombo(Composite parent) {
155         Combo combo = new Combo(parent, SWT.NULL);
156         GridData data = new GridData(GridData.FILL_HORIZONTAL);
157         data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
158         combo.setLayoutData(data);
159         return combo;
160     }
161 
162 }