View Javadoc

1   /* ====================================================================
2    *   Copyright 2003-2004 Fabrizio Giustina.
3    *
4    *   Licensed under the Apache License, Version 2.0 (the "License");
5    *   you may not use this file except in compliance with the License.
6    *   You may obtain a copy of the License at
7    *
8    *       http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *   Unless required by applicable law or agreed to in writing, software
11   *   distributed under the License is distributed on an "AS IS" BASIS,
12   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *   See the License for the specific language governing permissions and
14   *   limitations under the License.
15   * ====================================================================
16   */
17  package net.sf.commonclipse.preferences;
18  
19  import org.eclipse.jface.preference.FieldEditor;
20  import org.eclipse.swt.layout.GridData;
21  import org.eclipse.swt.widgets.Composite;
22  import org.eclipse.swt.widgets.Label;
23  
24  /***
25   * A field editor for displaying labels not associated with other widgets.
26   * @author fgiust
27   * @version $Revision: 1.3 $ ($Author: fgiust $)
28   */
29  class LabelFieldEditor extends FieldEditor
30  {
31  
32      /***
33       * Label for this field editor.
34       */
35      private Label label;
36  
37      /***
38       * All labels can use the same preference name since they don't store any preference.
39       * @param labelText text for the label
40       * @param parent Composite
41       */
42      public LabelFieldEditor(String labelText, Composite parent)
43      {
44          super("label", labelText, parent); //$NON-NLS-1$
45      }
46  
47      /***
48       * Adjusts the field editor to be displayed correctly for the given number of columns.
49       * @param numColumns number of columns
50       */
51      protected void adjustForNumColumns(int numColumns)
52      {
53          ((GridData) this.label.getLayoutData()).horizontalSpan = numColumns;
54      }
55  
56      /***
57       * Fills the field editor's controls into the given parent.
58       * @param parent Composite
59       * @param numColumns cumber of columns
60       */
61      protected void doFillIntoGrid(Composite parent, int numColumns)
62      {
63          this.label = getLabelControl(parent);
64  
65          GridData gridData = new GridData();
66          gridData.horizontalSpan = numColumns;
67          gridData.horizontalAlignment = GridData.FILL;
68          gridData.grabExcessHorizontalSpace = false;
69          gridData.verticalAlignment = GridData.CENTER;
70          gridData.grabExcessVerticalSpace = false;
71  
72          this.label.setLayoutData(gridData);
73      }
74  
75      /***
76       * Returns the number of controls in the field editor.
77       * @return 1
78       */
79      public int getNumberOfControls()
80      {
81          return 1;
82      }
83  
84      /***
85       * Labels do not persist any preferences, so this method is empty.
86       */
87      protected void doLoad()
88      {
89      }
90  
91      /***
92       * Labels do not persist any preferences, so this method is empty.
93       */
94      protected void doLoadDefault()
95      {
96      }
97  
98      /***
99       * Labels do not persist any preferences, so this method is empty.
100      */
101     protected void doStore()
102     {
103     }
104 }