]> git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/EclipseUiUtils.java
8e1c7e63210cd34b75caff9b901d6f9bdf0585ec
[lgpl/argeo-commons.git] / base / runtime / org.argeo.eclipse.ui / src / main / java / org / argeo / eclipse / ui / EclipseUiUtils.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
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 package org.argeo.eclipse.ui;
17
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;
26
27 /** Utilities to simplify UI development. */
28 public class EclipseUiUtils {
29 /**
30 * Create a label and a text field for a grid layout, the text field grabing
31 * excess horizontal
32 *
33 * @param parent
34 * the parent composite
35 * @param label
36 * the lable to display
37 * @param modifyListener
38 * a {@link ModifyListener} to listen on events on the text, can
39 * be null
40 * @return the created text
41 *
42 */
43 // FIXME why was this deprecated.
44 // * @ deprecated use { @ link #createGridLT(Composite, String)} instead
45 // @ Deprecated
46 public static Text createGridLT(Composite parent, String label,
47 ModifyListener modifyListener) {
48 Label lbl = new Label(parent, SWT.LEAD);
49 lbl.setText(label);
50 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
51 Text txt = new Text(parent, SWT.LEAD | SWT.BORDER);
52 txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
53 if (modifyListener != null)
54 txt.addModifyListener(modifyListener);
55 return txt;
56 }
57
58 /**
59 * Create a label and a text field for a grid layout, the text field
60 * grabbing excess horizontal
61 */
62 public static Text createGridLT(Composite parent, String label) {
63 return createGridLT(parent, label, null);
64 }
65
66 /**
67 * Creates one label and a text field not editable with background color of
68 * the parent (like a label but with selectable text)
69 */
70 public static Text createGridLL(Composite parent, String label, String text) {
71 Text txt = createGridLT(parent, label);
72 txt.setText(text);
73 txt.setEditable(false);
74 txt.setBackground(parent.getBackground());
75 return txt;
76 }
77
78 /**
79 * Create a label and a text field with password display for a grid layout,
80 * the text field grabbing excess horizontal
81 */
82 public static Text createGridLP(Composite parent, String label,
83 ModifyListener modifyListener) {
84 Label lbl = new Label(parent, SWT.LEAD);
85 lbl.setText(label);
86 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
87 Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD);
88 txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
89 if (txt != null)
90 txt.addModifyListener(modifyListener);
91 return txt;
92 }
93
94 /** Shortcut to retrieve default italic font from display */
95 public static Font getItalicFont(Composite parent) {
96 return JFaceResources.getFontRegistry().defaultFontDescriptor()
97 .setStyle(SWT.ITALIC).createFont(parent.getDisplay());
98 }
99
100 /** Shortcut to retrieve default bold font from display */
101 public static Font getBoldFont(Composite parent) {
102 return JFaceResources.getFontRegistry().defaultFontDescriptor()
103 .setStyle(SWT.BOLD).createFont(parent.getDisplay());
104 }
105
106 /** Shortcut to retrieve default bold italic font from display */
107 public static Font getBoldItalicFont(Composite parent) {
108 return JFaceResources.getFontRegistry().defaultFontDescriptor()
109 .setStyle(SWT.BOLD | SWT.ITALIC)
110 .createFont(parent.getDisplay());
111 }
112 }