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

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

Introduction

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

Prototype

public static Point getLocation(Rectangle toQuery) 

Source Link

Document

Returns the x,y position of the given rectangle.

Usage

From source file:au.gov.ga.earthsci.jface.extras.information.AbstractInformationControlManager.java

License:Open Source License

/**
 * Computes the location of the information control depending on the
 * subject area and the size of the information control. This method attempts
 * to find a location at which the information control lies completely in the display's
 * client area while honoring the manager's default anchor. If this isn't possible using the
 * default anchor, the fallback anchors are tried out.
 *
 * @param subjectArea the information area
 * @param controlSize the size of the information control
 * @return the computed location of the information control
 *//*w  w  w.  j  a  v a2s  .  c  o m*/
protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) {
    Rectangle subjectAreaDisplayRelative = Geometry.toDisplay(fSubjectControl, subjectArea);

    Point upperLeft;
    Anchor testAnchor = fAnchor;
    Rectangle bestBounds = null;
    int bestArea = Integer.MIN_VALUE;
    Anchor bestAnchor = null;
    do {

        upperLeft = computeLocation(subjectArea, controlSize, testAnchor);
        Monitor monitor = getClosestMonitor(subjectAreaDisplayRelative, testAnchor);
        if (updateLocation(upperLeft, controlSize, monitor.getClientArea(), testAnchor))
            return upperLeft;

        // compute available area for this anchor and update if better than best
        Rectangle available = computeAvailableArea(subjectAreaDisplayRelative, monitor.getClientArea(),
                testAnchor);
        Rectangle proposed = new Rectangle(upperLeft.x, upperLeft.y, controlSize.x, controlSize.y);
        available.intersect(proposed);
        int area = available.width * available.height;
        if (area > bestArea) {
            bestArea = area;
            bestBounds = available;
            bestAnchor = testAnchor;
        }

        testAnchor = getNextFallbackAnchor(testAnchor);

    } while (testAnchor != fAnchor && testAnchor != null);

    // no anchor is perfect - select the one with larges area and set the size to not overlap with the subjectArea
    if (bestAnchor != ANCHOR_GLOBAL)
        Geometry.set(controlSize, Geometry.getSize(bestBounds));
    return Geometry.getLocation(bestBounds);
}

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  w  w w.ja  va2 s  . c  om*/
 */
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:au.gov.ga.earthsci.jface.extras.information.InformationControlReplacer.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  w w  w.  java2 s  .  c  o m
 */
public void showInformationControl(Rectangle subjectArea, Object information) {
    IInformationControl informationControl = getInformationControl();

    Rectangle controlBounds = fContentBounds;
    if (informationControl instanceof IInformationControlExtension3) {
        IInformationControlExtension3 iControl3 = (IInformationControlExtension3) informationControl;
        Rectangle trim = iControl3.computeTrim();
        controlBounds = Geometry.add(controlBounds, trim);

        /*
         * Ensure minimal size. Interacting with a tiny information control
         * (resizing, selecting text) would be a pain.
         */
        controlBounds.width = Math.max(controlBounds.width, MIN_WIDTH);
        controlBounds.height = Math.max(controlBounds.height, MIN_HEIGHT);

        getInternalAccessor().cropToClosestMonitor(controlBounds);
    }

    Point location = Geometry.getLocation(controlBounds);
    Point size = Geometry.getSize(controlBounds);

    // Caveat: some IInformationControls fail unless setSizeConstraints(..) is called with concrete values
    informationControl.setSizeConstraints(size.x, size.y);

    if (informationControl instanceof IInformationControlExtension2)
        ((IInformationControlExtension2) informationControl).setInput(information);
    else
        informationControl.setInformation(information.toString());

    informationControl.setLocation(location);
    informationControl.setSize(size.x, size.y);

    showInformationControl(subjectArea);
}

From source file:com.buglabs.bug.dragonfly.uitests.DndUtil.java

License:Open Source License

/**
 * Performs a DND operation to an arbitrary location. The drag start
 * location will be chosen depending on this widget's default
 * implementation.//from  ww  w  . java 2s.c  o  m
 * 
 * @param source
 *            the source widget to drag
 * @param target
 *            The target locations where the DND shall finish.
 * @see #before(AbstractSWTBot)
 * @see #on(AbstractSWTBot)
 * @see #after(AbstractSWTBot)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final Point target) {
    final Rectangle sourceLocation = absoluteLocation(source);
    final Point slightOffset = Geometry.add(Geometry.getLocation(sourceLocation),
            new Point(DRAG_THRESHOLD, DRAG_THRESHOLD));
    doDragAndDrop(Geometry.min(Geometry.centerPoint(sourceLocation), slightOffset), target);
}

From source file:com.cubrid.common.ui.query.control.jface.text.contentassist.CompletionProposalPopup.java

License:Open Source License

/**
 * Returns the graphical location at which this popup should be made visible.
 *
 * @return the location of this popup// www.j av  a 2 s .c  om
 */
private Point getLocation() {
    int caret = fContentAssistSubjectControlAdapter.getCaretOffset();
    Rectangle location = fContentAssistant.getLayoutManager().computeBoundsBelowAbove(fProposalShell,
            fSize == null ? fProposalShell.getSize() : fSize, caret, this);
    return Geometry.getLocation(location);
}

From source file:org.eclipse.sirius.tests.swtbot.support.utils.dnd.DndUtil.java

License:Open Source License

/**
 * Performs a DND operation to an arbitrary location. The drag start
 * location will be chosen depending on this widget's default
 * implementation./*from www . j a  va2  s.c  o m*/
 * 
 * @param source
 *            the source widget to drag
 * @param target
 *            The target locations where the DND shall finish.
 * @see #before(AbstractSWTBot)
 * @see #on(AbstractSWTBot)
 * @see #after(AbstractSWTBot)
 */
public void dragAndDrop(final AbstractSWTBot<? extends Widget> source, final Point target) {
    final Rectangle sourceLocation = DndUtil.absoluteLocation(source);
    final Point slightOffset = Geometry.add(Geometry.getLocation(sourceLocation),
            new Point(DndUtil.DRAG_THRESHOLD, DndUtil.DRAG_THRESHOLD));
    doDragAndDrop(Geometry.min(Geometry.centerPoint(sourceLocation), slightOffset), target);
}

From source file:org.jboss.tools.ui.bot.ext.helper.DragAndDropHelper.java

License:Open Source License

public static void dnd(final TreeItem ti, final TreeItem ti2) {
    Rectangle r1 = UIThreadRunnable.syncExec(new Result<Rectangle>() {

        public Rectangle run() {
            return ti.getDisplay().map(ti.getParent(), null, ti.getBounds());
        }/*from   w w w. j a  va  2 s  . co  m*/
    });
    final Point slightOffset = Geometry.add(Geometry.getLocation(r1), new Point(10, 10));

    Rectangle r2 = UIThreadRunnable.syncExec(new Result<Rectangle>() {

        public Rectangle run() {
            return ti2.getDisplay().map(ti2.getParent(), null, ti2.getBounds());
        }
    });

    doDragAndDrop(Geometry.min(Geometry.centerPoint(r1), slightOffset), Geometry.centerPoint(r2));
}

From source file:org.jboss.tools.ui.bot.ext.helper.DragAndDropHelper.java

License:Open Source License

public static void dnd(final TreeItem ti, final FigureCanvas fc) {
    Rectangle r1 = UIThreadRunnable.syncExec(new Result<Rectangle>() {

        public Rectangle run() {
            return ti.getDisplay().map(ti.getParent(), null, ti.getBounds());
        }/*from   w w w .  j  av  a 2  s.co  m*/
    });
    final Point slightOffset = Geometry.add(Geometry.getLocation(r1), new Point(10, 10));

    Rectangle r2 = UIThreadRunnable.syncExec(new Result<Rectangle>() {

        public Rectangle run() {
            return fc.getDisplay().map(fc.getParent(), null, fc.getBounds());
        }
    });

    doDragAndDrop(Geometry.min(Geometry.centerPoint(r1), slightOffset), Geometry.centerPoint(r2));
}

From source file:org.jboss.tools.ui.bot.ext.helper.DragAndDropHelper.java

License:Open Source License

public static void dnd(final TreeItem ti, final Control fc, final int x, final int y) {
    Rectangle r1 = UIThreadRunnable.syncExec(new Result<Rectangle>() {

        public Rectangle run() {
            return ti.getDisplay().map(ti.getParent(), null, ti.getBounds());
        }// ww w  .  j  ava 2s  .co  m
    });
    final Point slightOffset = Geometry.add(Geometry.getLocation(r1), new Point(10, 10));

    Point r2 = UIThreadRunnable.syncExec(new Result<Point>() {

        public Point run() {
            log.info("xxx: " + fc.getLocation().x + ":" + fc.getLocation().y);
            return fc.getDisplay().map(fc, null, x, y);
        }
    });

    doDragAndDrop(Geometry.min(Geometry.centerPoint(r1), slightOffset), r2);
}