List of usage examples for org.eclipse.jface.util Geometry max
public static Point max(Point p1, Point p2)
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 .jav a2s.com 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:au.gov.ga.earthsci.jface.extras.information.AbstractInformationControlManager.java
License:Open Source License
/** * Opens the information control with the given information and the specified * subject area. It also activates the information control closer. * * @param subjectArea the information area * @param information the information/*from www . j a v a 2 s. co m*/ */ private void internalShowInformationControl(Rectangle subjectArea, Object information) { if (this instanceof InformationControlReplacer) { ((InformationControlReplacer) this).showInformationControl(subjectArea, information); return; } IInformationControl informationControl = getInformationControl(); if (informationControl != null) { Point sizeConstraints = computeSizeConstraints(fSubjectControl, fSubjectArea, informationControl); if (informationControl instanceof IInformationControlExtension3) { IInformationControlExtension3 iControl3 = (IInformationControlExtension3) informationControl; Rectangle trim = iControl3.computeTrim(); sizeConstraints.x += trim.width; sizeConstraints.y += trim.height; } informationControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y); if (informationControl instanceof IInformationControlExtension2) ((IInformationControlExtension2) informationControl).setInput(information); else informationControl.setInformation(information.toString()); if (informationControl instanceof IInformationControlExtension) { IInformationControlExtension extension = (IInformationControlExtension) informationControl; if (!extension.hasContents()) return; } Point size = null; Point location = null; Rectangle bounds = restoreInformationControlBounds(); if (bounds != null) { if (bounds.x > -1 && bounds.y > -1) location = Geometry.getLocation(bounds); if (bounds.width > -1 && bounds.height > -1) size = Geometry.getSize(bounds); } if (size == null) size = informationControl.computeSizeHint(); if (fEnforceAsMinimalSize) size = Geometry.max(size, sizeConstraints); if (fEnforceAsMaximalSize) size = Geometry.min(size, sizeConstraints); if (location == null) location = computeInformationControlLocation(subjectArea, size); Rectangle controlBounds = Geometry.createRectangle(location, size); cropToClosestMonitor(controlBounds); location = Geometry.getLocation(controlBounds); size = Geometry.getSize(controlBounds); informationControl.setLocation(location); informationControl.setSize(size.x, size.y); showInformationControl(subjectArea); } }
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 a v 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:com.microsoft.tfs.client.common.ui.framework.sizing.ControlSize.java
License:Open Source License
/** * Returns a size that is the largest computed size (in both dimensions) of * all of the specified controls. That is, the returned size is large enough * in either dimension to accommodate any of the specified controls in that * dimension.// w ww . ja v a2s . c o m * * @param controls * the controls to compute size for (must not be <code>null</code>, * must not contains any <code>null</code> elements, and must contain * at least one element) * @param wHint * the <code>wHint</code> value to pass to * {@link Control#computeSize(int, int)} * @param hHint * the <code>hHint</code> value to pass to * {@link Control#computeSize(int, int)} * @return the max size (never <code>null</code>) */ public static Point maxSize(final Control[] controls, final int wHint, final int hHint) { Check.notNull(controls, "controls"); //$NON-NLS-1$ if (controls.length == 0) { throw new IllegalArgumentException("the controls array must have at least one control"); //$NON-NLS-1$ } if (controls[0] == null) { throw new IllegalArgumentException("controls[0] is null"); //$NON-NLS-1$ } Point size = controls[0].computeSize(wHint, hHint); for (int i = 1; i < controls.length; i++) { if (controls[i] == null) { throw new IllegalArgumentException("controls[" + i + "] is null"); //$NON-NLS-1$ //$NON-NLS-2$ } size = Geometry.max(size, controls[i].computeSize(wHint, hHint)); } return size; }
From source file:com.microsoft.tfs.client.common.ui.framework.sizing.ControlSize.java
License:Open Source License
/** * Aligns the specified group of {@link Alignable}s. See the * {@link Alignable} class javadoc for more information. * * @param alignables/*from www .j a v a 2s . co m*/ * the {@link Alignable}s to align (must not be <code>null</code>), * must contain at least one element, and must not contain any * <code>null</code> elements) * @return the align size that was used for this alignment (never * <code>null</code>) */ public static Point align(final Alignable[] alignables) { Check.notNull(alignables, "alignables"); //$NON-NLS-1$ if (alignables.length == 0) { throw new IllegalArgumentException("you must pass at least one Alignable"); //$NON-NLS-1$ } if (alignables[0] == null) { throw new IllegalArgumentException("alignables[0] is null"); //$NON-NLS-1$ } Point size = alignables[0].getPreferredAlignSize(); for (int i = 1; i < alignables.length; i++) { if (alignables[i] == null) { throw new IllegalArgumentException("alignables[" + i + "] is null"); //$NON-NLS-1$ //$NON-NLS-2$ } size = Geometry.max(size, alignables[i].getPreferredAlignSize()); } for (int i = 0; i < alignables.length; i++) { alignables[i].setAlignSize(size); } return size; }
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 ww w . ja va2 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; }
From source file:org.jboss.tools.common.text.ext.hyperlink.xpl.InformationPresenter.java
License:Open Source License
private IInformationControl showInformation_internal(boolean test) { IInformationControl iControl = getInformationControl(); Point sizeConstraints = computeSizeConstraints(viwer.getTextWidget(), null, iControl); iControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y); Point size = null;// w w w . j ava2 s . c om Rectangle bounds = restoreInformationControlBounds(); if (bounds != null) { if (bounds.width > -1 && bounds.height > -1) size = Geometry.getSize(bounds); } if (size == null) size = iControl.computeSizeHint(); size = Geometry.max(size, sizeConstraints); iControl.setSize(size.x, size.y); if (test) { ((HierarchyInformationControl) iControl).setBlockOnOpen(false); } iControl.setVisible(true); return iControl; }