]> git.argeo.org Git - lgpl/argeo-commons.git/blob - EclipseUiUtils.java
85d514ba9cc5a76dac96d019f6cdbd77b4ec9367
[lgpl/argeo-commons.git] / EclipseUiUtils.java
1 package org.argeo.eclipse.ui;
2
3 import org.eclipse.jface.resource.JFaceResources;
4 import org.eclipse.swt.SWT;
5 import org.eclipse.swt.events.ModifyListener;
6 import org.eclipse.swt.graphics.Font;
7 import org.eclipse.swt.layout.GridData;
8 import org.eclipse.swt.widgets.Composite;
9 import org.eclipse.swt.widgets.Label;
10 import org.eclipse.swt.widgets.Text;
11
12 /** Utilities to simplify UI development. */
13 public class EclipseUiUtils {
14 /**
15 * Create a label and a text field for a grid layout, the text field grabing
16 * excess horizontal
17 *
18 * @param parent
19 * the parent composite
20 * @param label
21 * the lable to display
22 * @param modifyListener
23 * a {@link ModifyListener} to listen on events on the text, can
24 * be null
25 * @return the created text
26 *
27 * @deprecated use {@link #createGridLT(Composite, String)} instead
28 */
29 @Deprecated
30 public static Text createGridLT(Composite parent, String label,
31 ModifyListener modifyListener) {
32 Label lbl = new Label(parent, SWT.LEAD);
33 lbl.setText(label);
34 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
35 Text txt = new Text(parent, SWT.LEAD | SWT.BORDER);
36 txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
37 if (modifyListener != null)
38 txt.addModifyListener(modifyListener);
39 return txt;
40 }
41
42 public static Text createGridLT(Composite parent, String label) {
43 return createGridLT(parent, label, null);
44 }
45
46 /**
47 * Creates one label and a text field not editable with background color of
48 * the parent (like a label but with selectable text)
49 */
50 public static Text createGridLL(Composite parent, String label, String text) {
51 Text txt = createGridLT(parent, label);
52 txt.setText(text);
53 txt.setEditable(false);
54 txt.setBackground(parent.getBackground());
55 return txt;
56 }
57
58 public static Text createGridLP(Composite parent, String label,
59 ModifyListener modifyListener) {
60 Label lbl = new Label(parent, SWT.LEAD);
61 lbl.setText(label);
62 lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
63 Text txt = new Text(parent, SWT.LEAD | SWT.BORDER | SWT.PASSWORD);
64 txt.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
65 if (txt != null)
66 txt.addModifyListener(modifyListener);
67 return txt;
68 }
69
70 public static Font getItalicFont(Composite parent) {
71 return JFaceResources.getFontRegistry().defaultFontDescriptor()
72 .setStyle(SWT.ITALIC).createFont(parent.getDisplay());
73 }
74
75 public static Font getBoldFont(Composite parent) {
76 return JFaceResources.getFontRegistry().defaultFontDescriptor()
77 .setStyle(SWT.BOLD).createFont(parent.getDisplay());
78 }
79
80 public static Font getBoldItalicFont(Composite parent) {
81 return JFaceResources.getFontRegistry().defaultFontDescriptor()
82 .setStyle(SWT.BOLD | SWT.ITALIC)
83 .createFont(parent.getDisplay());
84 }
85
86 }