Example usage for org.eclipse.jface.util Geometry getDimension

List of usage examples for org.eclipse.jface.util Geometry getDimension

Introduction

In this page you can find the example usage for org.eclipse.jface.util Geometry getDimension.

Prototype

public static int getDimension(Rectangle toMeasure, boolean width) 

Source Link

Document

Returns the height or width of the given rectangle.

Usage

From source file:org.eclipse.ui.internal.FastViewBar.java

License:Open Source License

/**
 * Returns the approximate location where the next fastview icon
 * will be drawn (display coordinates)//w w w .j a va2  s  . c o m
 */
public Rectangle getLocationOfNextIcon() {
    ToolBar control = getToolBar();

    Rectangle result = control.getBounds();
    Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
    result.height = size.y;
    result.width = size.x;

    boolean horizontal = Geometry.isHorizontal(getSide());
    if (control.getItemCount() == 0) {
        Geometry.setDimension(result, horizontal, 0);
    }

    int hoverSide = horizontal ? SWT.RIGHT : SWT.BOTTOM;

    result = Geometry.getExtrudedEdge(result, -Geometry.getDimension(result, !horizontal), hoverSide);

    return Geometry.toDisplay(control.getParent(), result);
}

From source file:org.eclipse.ui.internal.FastViewDnDHandler.java

License:Open Source License

/**
 * Returns the approximate location where the next fastview icon
 * will be drawn (display coordinates)//from   w  ww  . j  ava 2s .  c o  m
 */
public Rectangle getLocationOfNextIcon() {
    ToolBar control = tbm.getControl();

    Rectangle result = control.getBounds();
    Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
    result.height = size.y;
    result.width = size.x;

    boolean horizontal = (control.getStyle() & SWT.VERTICAL) == 0;
    if (control.getItemCount() == 0) {
        Geometry.setDimension(result, horizontal, 0);
    }

    int hoverSide = horizontal ? SWT.RIGHT : SWT.BOTTOM;

    result = Geometry.getExtrudedEdge(result, -Geometry.getDimension(result, !horizontal), hoverSide);

    return Geometry.toDisplay(control.getParent(), result);
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

/**
 * Returns the current fastview size ratio. Returns 0.0 if there is no fastview visible.
 *///from ww w  . j  a va2  s . c  om
public float getCurrentRatio() {
    if (currentPane == null) {
        return 0.0f;
    }

    boolean isVertical = !Geometry.isHorizontal(side);
    Rectangle clientArea = clientComposite.getClientArea();

    int clientSize = Geometry.getDimension(clientArea, isVertical);

    return (float) size / (float) clientSize;
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

private Rectangle getBounds() {
    Rectangle bounds = getClientArea();

    if (site.getState() == IStackPresentationSite.STATE_MAXIMIZED) {
        return bounds;
    }/*from www .j  a v  a 2  s .  co m*/

    boolean horizontal = Geometry.isHorizontal(side);

    int available = Geometry.getDimension(bounds, !horizontal);

    return Geometry.getExtrudedEdge(bounds, Math.min(FastViewPane.this.size, available), side);
}

From source file:org.eclipse.ui.internal.FastViewPane.java

License:Open Source License

/**
 * Displays the given view as a fastview. The view will be docked to the edge of the
 * given composite until it is subsequently hidden by a call to hideFastView. 
 * /*from  w  w  w.ja v a 2  s . co m*/
 * @param newClientComposite
 * @param pane
 * @param newSide
 */
public void showView(Composite newClientComposite, ViewPane pane, int newSide, float sizeRatio) {
    side = newSide;

    if (currentPane != null) {
        hideView();
    }

    currentPane = new PresentablePart(pane, newClientComposite);

    fastViewAction.setPane(currentPane);
    clientComposite = newClientComposite;

    clientComposite.addListener(SWT.Resize, resizeListener);

    // Create the control first
    Control ctrl = pane.getControl();
    if (ctrl == null) {
        pane.createControl(clientComposite);
        ctrl = pane.getControl();
    }

    // RAP [bm]: 
    //        ctrl.addListener(SWT.Traverse, escapeListener);

    // Temporarily use the same appearance as docked views .. eventually, fastviews will
    // be independently pluggable.
    AbstractPresentationFactory factory = getPresentationFactory();
    StackPresentation presentation = factory.createViewPresentation(newClientComposite, site);

    site.setPresentation(presentation);
    site.setPresentationState(IStackPresentationSite.STATE_RESTORED);
    presentation.addPart(currentPane, null);
    presentation.selectPart(currentPane);
    presentation.setActive(StackPresentation.AS_ACTIVE_FOCUS);
    presentation.setVisible(true);

    boolean horizontalResize = Geometry.isHorizontal(side);

    minSize = presentation.computePreferredSize(horizontalResize, ISizeProvider.INFINITE,
            Geometry.getDimension(getClientArea(), horizontalResize), 0);

    // Show pane fast.
    ctrl.setEnabled(true); // Add focus support.
    Composite parent = ctrl.getParent();

    boolean horizontal = Geometry.isHorizontal(side);

    // Create a sash of the correct style using the factory
    int style = AbstractPresentationFactory.SASHTYPE_FLOATING;
    if (horizontal)
        style |= AbstractPresentationFactory.SASHORIENTATION_HORIZONTAL;
    else
        style |= AbstractPresentationFactory.SASHORIENTATION_VERTICAL;
    sash = factory.createSash(parent, style);

    sash.addSelectionListener(selectionListener);

    Rectangle clientArea = newClientComposite.getClientArea();

    getPresentation().getControl().moveAbove(null);
    currentPane.getPane().moveAbove(null);
    sash.moveAbove(null);

    setSize((int) (Geometry.getDimension(clientArea, !horizontal) * sizeRatio));

    Display display = sash.getDisplay();

    display.addFilter(SWT.MouseDown, mouseDownListener);

    pane.setFocus();
}

From source file:org.eclipse.ui.internal.PartSashContainer.java

License:Open Source License

static int measureTree(Rectangle outerBounds, LayoutTree toMeasure, boolean horizontal) {
    if (toMeasure == null) {
        return Geometry.getDimension(outerBounds, horizontal);
    }//from  w w w  .  j  av  a 2s  . c om

    LayoutTreeNode parent = toMeasure.getParent();
    if (parent == null) {
        return Geometry.getDimension(outerBounds, horizontal);
    }

    if (parent.getSash().isHorizontal() == horizontal) {
        return measureTree(outerBounds, parent, horizontal);
    }

    boolean isLeft = parent.isLeftChild(toMeasure);

    LayoutTree otherChild = parent.getChild(!isLeft);
    if (otherChild.isVisible()) {
        int left = parent.getSash().getLeft();
        int right = parent.getSash().getRight();
        int childSize = isLeft ? left : right;

        int bias = parent.getCompressionBias();

        // Normalize bias: 1 = we're fixed, -1 = other child is fixed
        if (isLeft) {
            bias = -bias;
        }

        if (bias == 1) {
            // If we're fixed, return the fixed size
            return childSize;
        } else if (bias == -1) {

            // If the other child is fixed, return the size of the parent minus the fixed size of the
            // other child
            return measureTree(outerBounds, parent, horizontal) - (left + right - childSize);
        }

        // Ensure we don't get a 'divide by zero'
        if ((left + right) == 0)
            return 0;

        // Else return the size of the parent, scaled appropriately
        return measureTree(outerBounds, parent, horizontal) * childSize / (left + right);
    }

    return measureTree(outerBounds, parent, horizontal);
}