X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.eclipse.ui%2Fsrc%2Forg%2Fargeo%2Feclipse%2Fui%2FEclipseUiUtils.java;h=52eaf9b8412fb97e47924df53646fffff6286847;hb=f9432dc625d89fdc42acd4960545769bc513fb3b;hp=3455577ceac63e7679071eb1acf994850b27e759;hpb=7f945886dbd3cd0cf5b0e06b481b78ba1e2c9db9;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java index 3455577ce..52eaf9b84 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiUtils.java @@ -19,16 +19,76 @@ import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; /** Utilities to simplify UI development. */ public class EclipseUiUtils { + + // + // Simplify grid layouts management + // + public static GridLayout noSpaceGridLayout() { + return noSpaceGridLayout(new GridLayout()); + } + + public static GridLayout noSpaceGridLayout(GridLayout layout) { + layout.horizontalSpacing = 0; + layout.verticalSpacing = 0; + layout.marginWidth = 0; + layout.marginHeight = 0; + return layout; + } + + public static GridData fillWidth() { + return grabWidth(SWT.FILL, SWT.FILL); + } + + public static GridData fillWidth(int colSpan) { + GridData gd = grabWidth(SWT.FILL, SWT.FILL); + gd.horizontalSpan = colSpan; + return gd; + } + + public static GridData fillAll() { + return new GridData(SWT.FILL, SWT.FILL, true, true); + } + + public static GridData fillAll(int colSpan, int rowSpan) { + return new GridData(SWT.FILL, SWT.FILL, true, true, colSpan, rowSpan); + } + + public static GridData grabWidth(int horizontalAlignment, + int verticalAlignment) { + return new GridData(horizontalAlignment, horizontalAlignment, true, + false); + } + + // + // Simplify Form layout management + // + /** - * Create a label and a text field for a grid layout, the text field grabbing - * excess horizontal + * Creates a basic form data that is attached to the 4 corners of the parent + * composite + */ + public static FormData fillFormData() { + FormData formData = new FormData(); + formData.top = new FormAttachment(0, 0); + formData.left = new FormAttachment(0, 0); + formData.right = new FormAttachment(100, 0); + formData.bottom = new FormAttachment(100, 0); + return formData; + } + + /** + * Create a label and a text field for a grid layout, the text field + * grabbing excess horizontal * * @param parent * the parent composite @@ -91,6 +151,10 @@ public class EclipseUiUtils { return txt; } + // + // FONTS + // + /** Shortcut to retrieve default italic font from display */ public static Font getItalicFont(Composite parent) { return JFaceResources.getFontRegistry().defaultFontDescriptor()