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

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

Introduction

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

Prototype

public static Point subtract(Point point1, Point point2) 

Source Link

Document

Performs vector subtraction on two points.

Usage

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

License:Open Source License

public void create() {
    windowShell = ((WorkbenchWindow) page.getWorkbenchWindow()).getDetachedWindowPool()
            .allocateShell(shellListener);
    windowShell.setData(this);
    windowShell.setText(""); //$NON-NLS-1$
    DragUtil.addDragTarget(windowShell, this);
    hideViewsOnClose = true;//from www .j a  va 2s  . c  o  m
    if (bounds.isEmpty()) {
        Point center = Geometry.centerPoint(page.getWorkbenchWindow().getShell().getBounds());
        Point size = new Point(300, 200);
        Point upperLeft = Geometry.subtract(center, Geometry.divide(size, 2));

        bounds = Geometry.createRectangle(upperLeft, size);
    }

    // Force the rect into the current display
    Rectangle dispBounds = getShell().getDisplay().getBounds();
    if (bounds.width > dispBounds.width)
        bounds.width = dispBounds.width;
    if (bounds.height > dispBounds.height)
        bounds.height = dispBounds.height;
    if (bounds.x + bounds.width > dispBounds.width)
        bounds.x = dispBounds.width - bounds.width;
    if (bounds.y + bounds.height > dispBounds.height)
        bounds.y = dispBounds.height - bounds.height;

    getShell().setBounds(bounds);

    configureShell(windowShell);

    createContents(windowShell);
    windowShell.layout(true);
    folder.setBounds(windowShell.getClientArea());
}

From source file:org.pentaho.di.ui.core.gui.WindowProperty.java

License:Apache License

/**
 * @param constrainee// w  w  w . ja v a 2s  . c o  m
 * @param container
 */
private void constrainRectangleToContainer(Rectangle constrainee, Rectangle container) {
    Point originalSize = Geometry.getSize(constrainee);
    Point containerSize = Geometry.getSize(container);
    Point oversize = Geometry.subtract(originalSize, containerSize);
    if (oversize.x > 0) {
        constrainee.width = originalSize.x - oversize.x;
    }
    if (oversize.y > 0) {
        constrainee.height = originalSize.y - oversize.y;
    }
    // Detect if the dialog was positioned outside the container
    Geometry.moveInside(constrainee, container);
}