2 * Copyright (C) 2007-2012 Argeo GmbH
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.eclipse
.ui
;
18 import org
.eclipse
.jface
.resource
.JFaceResources
;
19 import org
.eclipse
.swt
.SWT
;
20 import org
.eclipse
.swt
.events
.ModifyListener
;
21 import org
.eclipse
.swt
.graphics
.Font
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Label
;
25 import org
.eclipse
.swt
.widgets
.Text
;
27 /** Utilities to simplify UI development. */
28 public class EclipseUiUtils
{
30 * Create a label and a text field for a grid layout, the text field grabing
34 * the parent composite
36 * the lable to display
37 * @param modifyListener
38 * a {@link ModifyListener} to listen on events on the text, can
40 * @return the created text
42 * @deprecated use {@link #createGridLT(Composite, String)} instead
45 public static Text
createGridLT(Composite parent
, String label
,
46 ModifyListener modifyListener
) {
47 Label lbl
= new Label(parent
, SWT
.LEAD
);
49 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
50 Text txt
= new Text(parent
, SWT
.LEAD
| SWT
.BORDER
);
51 txt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
52 if (modifyListener
!= null)
53 txt
.addModifyListener(modifyListener
);
57 public static Text
createGridLT(Composite parent
, String label
) {
58 return createGridLT(parent
, label
, null);
62 * Creates one label and a text field not editable with background color of
63 * the parent (like a label but with selectable text)
65 public static Text
createGridLL(Composite parent
, String label
, String text
) {
66 Text txt
= createGridLT(parent
, label
);
68 txt
.setEditable(false);
69 txt
.setBackground(parent
.getBackground());
73 public static Text
createGridLP(Composite parent
, String label
,
74 ModifyListener modifyListener
) {
75 Label lbl
= new Label(parent
, SWT
.LEAD
);
77 lbl
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.CENTER
, false, false));
78 Text txt
= new Text(parent
, SWT
.LEAD
| SWT
.BORDER
| SWT
.PASSWORD
);
79 txt
.setLayoutData(new GridData(SWT
.FILL
, SWT
.CENTER
, true, false));
81 txt
.addModifyListener(modifyListener
);
85 public static Font
getItalicFont(Composite parent
) {
86 return JFaceResources
.getFontRegistry().defaultFontDescriptor()
87 .setStyle(SWT
.ITALIC
).createFont(parent
.getDisplay());
90 public static Font
getBoldFont(Composite parent
) {
91 return JFaceResources
.getFontRegistry().defaultFontDescriptor()
92 .setStyle(SWT
.BOLD
).createFont(parent
.getDisplay());
95 public static Font
getBoldItalicFont(Composite parent
) {
96 return JFaceResources
.getFontRegistry().defaultFontDescriptor()
97 .setStyle(SWT
.BOLD
| SWT
.ITALIC
)
98 .createFont(parent
.getDisplay());