Example usage for org.eclipse.jface.layout LayoutConstants getMinButtonSize

List of usage examples for org.eclipse.jface.layout LayoutConstants getMinButtonSize

Introduction

In this page you can find the example usage for org.eclipse.jface.layout LayoutConstants getMinButtonSize.

Prototype

public static final Point getMinButtonSize() 

Source Link

Document

Returns the default minimum button size, in pixels

Usage

From source file:au.com.langdale.ui.builder.LayoutGenerator.java

License:Open Source License

/**
 * Determine how to layout the given control within a Grid.
 * The layout information is returned indirectly in the form 
 * of an object that sets layout on a control.
 *//*from   w  w  w .  j a  va2s .  c  om*/
public static GridDataFactory defaultsFor(Control control) {
    if (control instanceof Button) {
        Button button = (Button) control;

        if (hasStyle(button, SWT.CHECK)) {
            return nonWrappingLabelData.copy();
        } else {
            return GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(Geometry.max(
                    button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true), LayoutConstants.getMinButtonSize()));
        }
    }

    if (control instanceof Composite) {
        Composite composite = (Composite) control;

        Layout theLayout = composite.getLayout();
        if (theLayout instanceof GridLayout) {
            boolean growsHorizontally = false;
            boolean growsVertically = false;

            Control[] children = composite.getChildren();
            for (int i = 0; i < children.length; i++) {
                Control child = children[i];

                GridData data = (GridData) child.getLayoutData();

                if (data != null) {
                    if (data.grabExcessHorizontalSpace) {
                        growsHorizontally = true;
                    }
                    if (data.grabExcessVerticalSpace) {
                        growsVertically = true;
                    }
                }
            }

            return GridDataFactory.fillDefaults().grab(growsHorizontally, growsVertically);
        }
    }

    Point size = control.getSize();
    boolean wrapping = hasStyle(control, SWT.WRAP);
    boolean containsText = hasMethod(control, "setText", new Class[] { String.class })
            || (control instanceof FormText);
    boolean variable = !(control instanceof Label);
    boolean variableText = containsText && variable;
    boolean hScroll = hasStyle(control, SWT.H_SCROLL);
    boolean vScroll = hasStyle(control, SWT.V_SCROLL);
    boolean multiLine = hasStyle(control, SWT.MULTI);

    boolean grabHorizontal = hScroll || variableText && !wrapping || containsText && wrapping;
    boolean grabVertical = (vScroll || variableText && multiLine) && size.y <= 0;

    int hHint, vHint, vAlign;

    if (grabHorizontal) {
        // For horizontally-scrollable controls, override their horizontal
        // preferred size with a constant
        if (wrapping) {
            // For wrapping controls, there are two cases.
            if (containsText)
                // 1. For controls that contain text (like wrapping labels,
                // read-only text boxes,
                // etc.) override their preferred size with the preferred wrapping
                // point and
                // make them grab horizontal space.

                hHint = wrapSize;
            else
                // 2. For non-text controls (like wrapping toolbars), assume that
                // their non-wrapped
                // size is best.
                hHint = SWT.DEFAULT;
        } else {
            hHint = defaultSize.x;
        }
    } else {
        hHint = SWT.DEFAULT;
    }

    if (size.y > 0) {
        vHint = size.y;
    } else if (grabVertical) {
        vHint = defaultSize.y;
    } else {
        vHint = SWT.DEFAULT;
    }

    if (containsText && !variableText) {
        // Heuristic for labels: Controls that contain non-wrapping read-only
        // text should be
        // center-aligned rather than fill-aligned
        vAlign = SWT.CENTER;
    } else {
        vAlign = SWT.FILL;
    }

    return GridDataFactory.fillDefaults().grab(grabHorizontal, grabVertical).align(SWT.FILL, vAlign).hint(hHint,
            vHint);
}

From source file:com.google.dart.tools.ui.internal.preferences.DartKeyBindingPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    Composite composite = new Composite(parent, SWT.NONE);

    GridDataFactory.fillDefaults().grab(true, false).indent(0, 10).align(SWT.FILL, SWT.BEGINNING)
            .applyTo(composite);/*from w  ww . j av a 2 s  . c o m*/
    GridLayoutFactory.fillDefaults().spacing(0, 8).margins(0, 10).applyTo(composite);

    Group generalGroup = new Group(composite, SWT.NONE);
    generalGroup.setText(PreferencesMessages.DartKeyBindingPref_Modify);
    GridDataFactory.fillDefaults().grab(true, false).align(SWT.FILL, SWT.BEGINNING).applyTo(generalGroup);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(8, 8).applyTo(generalGroup);

    new Label(generalGroup, SWT.NONE).setText(DESCR_EXPORT);
    exportButton = new Button(generalGroup, SWT.PUSH | SWT.FLAT | SWT.CENTER);
    exportButton.setText(PreferencesMessages.DartKeyBindingPref_ToFile);
    exportButton.setLayoutData(new GridData(SWT.CENTER, SWT.END, false, false));
    exportButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            exportKeys();
        }
    });

    new Label(generalGroup, SWT.NONE).setText(DESCR_IMPORT);
    importButton = new Button(generalGroup, SWT.PUSH | SWT.FLAT | SWT.CENTER);
    importButton.setText(PreferencesMessages.DartKeyBindingPref_FromFile);
    importButton.setLayoutData(new GridData(SWT.CENTER, SWT.END, false, false));
    importButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            importKeys();
        }
    });

    new Label(generalGroup, SWT.NONE).setText(DESCR_RESET);
    resetButton = new Button(generalGroup, SWT.PUSH | SWT.FLAT | SWT.CENTER);
    resetButton.setText(PreferencesMessages.DartKeyBindingPref_ToDefaults);
    resetButton.setLayoutData(new GridData(SWT.CENTER, SWT.END, false, false));
    resetButton.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            resetBindings();
        }
    });

    if (DartCoreDebug.ENABLE_ALT_KEY_BINDINGS) {
        new Label(generalGroup, SWT.NONE).setText(DESCR_EMACS);
        emacsButton = new Button(generalGroup, SWT.PUSH | SWT.FLAT | SWT.CENTER);
        emacsButton.setText(PreferencesMessages.DartKeyBindingPref_ToEmacs);
        emacsButton.setLayoutData(new GridData(SWT.CENTER, SWT.END, false, false));
        emacsButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                setEmacsBindings();
            }
        });
    }

    Point preferredSize = resetButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
    Point hint = Geometry.max(LayoutConstants.getMinButtonSize(), preferredSize);
    GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(hint).applyTo(exportButton);
    GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(hint).applyTo(importButton);
    GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(hint).applyTo(resetButton);
    if (DartCoreDebug.ENABLE_ALT_KEY_BINDINGS) {
        GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).hint(hint).applyTo(emacsButton);
    }

    return composite;
}

From source file:org.eclipse.swt.widgets.FileComposite.java

License:Open Source License

protected FileUpload createFileUpload(Composite parent, String text) {
    FileUpload fileUpload = new FileUpload(parent, isMulti() ? SWT.MULTI : SWT.NONE);
    fileUpload.setText(text);//from  w  w  w .j av a2 s  .co m
    Point preferredSize = fileUpload.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
    Point hint = Geometry.max(LayoutConstants.getMinButtonSize(), preferredSize);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(hint).applyTo(fileUpload);

    fileUpload.addListener(SWT.Selection, new Listener() {
        @Override
        public void handleEvent(Event event) {
            handleFileUploadSelection((FileUpload) event.widget);
        }
    });
    fileUpload.moveAbove(null);
    return fileUpload;
}