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

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

Introduction

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

Prototype

public static Rectangle copy(Rectangle toCopy) 

Source Link

Document

Returns a copy of the given rectangle

Usage

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

License:Open Source License

/**
 * Tests whether a given mouse location is within the keep-up zone.
 * The hover should not be hidden as long as the mouse stays inside this zone.
 *
 * @param x the x coordinate, relative to the <em>subject control</em>
 * @param y the y coordinate, relative to the <em>subject control</em>
 * @param subjectControl the subject control
 * @param subjectArea the area for which the presented information is valid
 * @param blowUp If <code>true</code>, then calculate for the closer, i.e. blow up the keepUp area.
 *        If <code>false</code>, then use tight bounds for hover detection.
 *
 * @return <code>true</code> iff the mouse event occurred in the keep-up zone
 * @since 3.4/*w  ww .j  av  a 2  s  .  c  o  m*/
 */
private boolean inKeepUpZone(int x, int y, Control subjectControl, Rectangle subjectArea, boolean blowUp) {
    if (subjectArea.contains(x, y))
        return true;

    IInformationControl iControl = getCurrentInformationControl();
    if ((iControl instanceof IInformationControlExtension5
            && !((IInformationControlExtension5) iControl).isVisible())) {
        iControl = null;
        if (getInformationControlReplacer() != null) {
            iControl = getInformationControlReplacer().getCurrentInformationControl2();
            if ((iControl instanceof IInformationControlExtension5
                    && !((IInformationControlExtension5) iControl).isVisible())) {
                return false;
            }
        }
    }
    if (iControl instanceof IInformationControlExtension3) {
        IInformationControlExtension3 iControl3 = (IInformationControlExtension3) iControl;

        Rectangle iControlBounds = subjectControl.getDisplay().map(null, subjectControl, iControl3.getBounds());
        Rectangle totalBounds = Geometry.copy(iControlBounds);
        if (blowUp && isReplaceInProgress()) {
            //Problem: blown up iControl overlaps rest of subjectArea's line
            // solution for now: only blow up for keep up (closer), but not for further hover detection
            int margin = getInformationControlReplacer().getKeepUpMargin();
            Geometry.expand(totalBounds, margin, margin, margin, margin);
        }

        if (!blowUp) {
            if (iControlBounds.contains(x, y))
                return true;

            if (subjectArea.y + subjectArea.height < iControlBounds.y) {
                // special case for hover events: subjectArea totally above iControl:
                //  +-----------+
                //  |subjectArea|
                //  +-----------+
                //  |also keepUp|
                // ++-----------+-------+
                // | InformationControl |
                // +--------------------+
                if (subjectArea.y + subjectArea.height <= y && y <= totalBounds.y) {
                    // is vertically between subject area and iControl
                    if (subjectArea.x <= x && x <= subjectArea.x + subjectArea.width) {
                        // is below subject area (in a vertical projection)
                        return true;
                    }
                    // FIXME: cases when subjectArea extends to left or right of iControl?
                }
                return false;

            } else if (iControlBounds.x + iControlBounds.width < subjectArea.x) {
                // special case for hover events (e.g. in overview ruler): iControl totally left of subjectArea
                // +--------------------+-----------+
                // |                    |           +-----------+
                // | InformationControl |also keepUp|subjectArea|
                // |                    |           +-----------+
                // +--------------------+-----------+
                if (iControlBounds.x + iControlBounds.width <= x && x <= subjectArea.x) {
                    // is horizontally between iControl and subject area
                    if (iControlBounds.y <= y && y <= iControlBounds.y + iControlBounds.height) {
                        // is to the right of iControl (in a horizontal projection)
                        return true;
                    }
                }
                return false;

            } else if (subjectArea.x + subjectArea.width < iControlBounds.x) {
                // special case for hover events (e.g. in annotation ruler): subjectArea totally left of iControl
                //             +-----------+--------------------+
                // +-----------+           |                    |
                // |subjectArea|also keepUp| InformationControl |
                // +-----------+           |                    |
                //             +-----------+--------------------+
                if (subjectArea.x + subjectArea.width <= x && x <= iControlBounds.x) {
                    // is horizontally between subject area and iControl
                    if (iControlBounds.y <= y && y <= iControlBounds.y + iControlBounds.height) {
                        // is to the left of iControl (in a horizontal projection)
                        return true;
                    }
                }
                return false;
            }
        }

        // FIXME: should maybe use convex hull, not bounding box
        totalBounds.add(subjectArea);
        if (totalBounds.contains(x, y))
            return true;
    }
    return false;
}

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

License:Open Source License

/**
 * Computes the size constraints of the information control in points based on the
 * default font of the given subject control as well as the size constraints in character
 * width./*from w  ww.j  av  a  2s.  com*/
 *
 * @param subjectControl the subject control
 * @param informationControl the information control whose size constraints are computed
 * @return the computed size constraints in points
 */
protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) {

    if (fSizeConstraints == null) {
        if (informationControl instanceof IInformationControlExtension5) {
            IInformationControlExtension5 iControl5 = (IInformationControlExtension5) informationControl;
            fSizeConstraints = iControl5.computeSizeConstraints(fWidthConstraint, fHeightConstraint);
            if (fSizeConstraints != null)
                return Geometry.copy(fSizeConstraints);
        }
        if (subjectControl == null)
            return null;

        GC gc = new GC(subjectControl);
        gc.setFont(subjectControl.getFont());
        int width = gc.getFontMetrics().getAverageCharWidth();
        int height = gc.getFontMetrics().getHeight();
        gc.dispose();

        fSizeConstraints = new Point(fWidthConstraint * width, fHeightConstraint * height);
    }

    return new Point(fSizeConstraints.x, fSizeConstraints.y);
}

From source file:com.aptana.editor.common.hover.CustomAbstractInformationControl.java

License:Open Source License

/**
 * Returns the size constraints.//  w w  w  . j  ava2 s  .c o m
 * 
 * @return the size constraints or <code>null</code> if not set
 * @see #setSizeConstraints(int, int)
 */
protected final Point getSizeConstraints() {
    return fSizeConstraints != null ? Geometry.copy(fSizeConstraints) : null;
}

From source file:com.aptana.ide.core.ui.DefaultAnimationFeedback.java

License:Open Source License

/**
 * Perform any initialization you want to have happen -before- the
 * amination starts//  w  ww .  ja v a 2  s.  co  m
 */
public void jobInit() {
    // Compute the shell's bounds
    Rectangle shellBounds = Geometry.copy((Rectangle) startRects.get(0));
    Iterator startIter = startRects.iterator();
    Iterator endIter = endRects.iterator();
    while (startIter.hasNext()) {
        shellBounds.add((Rectangle) startIter.next());
        shellBounds.add((Rectangle) endIter.next());
    }
    theShell.setBounds(shellBounds);

    // Making the shell visible will be slow on old video cards, so only start
    // the timer once it is visible.
    theShell.setVisible(true);
}

From source file:de.loskutov.eclipseskins.presentation.VSViewStackPresentation.java

License:Open Source License

protected void layout() {
    if (!isVisible) {
        if (PresentationPlugin.DEBUG_LAYOUT) {
            System.out.println(getDebugPartName() + ": cancel layout as invisible");
        }/*from   w w  w.j  av a  2s  . c  om*/

        return;
    }
    if (parts.isEmpty()) {
        if (PresentationPlugin.DEBUG_LAYOUT) {
            System.out.println(getDebugPartName() + ": cancel layout as no parts");
        }

        tabArea.setVisible(false);
        tabButtons.setVisible(false);
        return;
    }
    if (PresentationPlugin.DEBUG_LAYOUT) {
        System.out.println(getDebugPartName() + ": do layout");
    }

    Rectangle clientArea = presentationControl.getClientArea();
    Point titleSize = title.computeSize(clientArea.width, SWT.DEFAULT, true);
    title.setBounds(clientArea.x, clientArea.y, clientArea.width, titleSize.y);
    title.setVisible(true);
    boolean hasContent = currentPart != null;
    Control toolBar = hasContent ? currentPart.getToolBar() : null;

    // handle minimized state
    if (isMinimized()) {
        if (PresentationPlugin.DEBUG_LAYOUT) {
            System.out.println(getDebugPartName() + ": cancel layout as minimized");
        }

        if (hasContent) {
            // WORKAROUND if perspective was switched and the view in the target perspective was
            // minimized, so we get strange painting problems without to set the bounds of control
            //                currentPart.getControl().setBounds(0, 0, 0,0);
            currentPart.getControl().setVisible(false);
            if (toolBar != null) {
                // the same workaround as with control before
                //                    toolBar.setBounds(0, 0, 0, 0);
                toolBar.setVisible(false);
            }
        }
        tabArea.setVisible(false);
        tabButtons.setVisible(false);
        return;
    }

    /*
     * now we really do layout :)
     */
    ThemeWrapper theme = getCurrentTheme();
    boolean tabsVisible = getFlag(F_TAB_AREA_VISIBLE);
    boolean toolbarVisible = getFlag(F_TOOLBAR_VISIBLE);
    boolean topPosition = SWT.TOP == theme.getInt(ThemeConstants.VIEW_TAB_POSITION);
    int borderSize_x_2 = borderSize * 2;
    int topHeight = titleSize.y;

    Rectangle contentArea = Geometry.copy(clientArea);
    // Only show tabs, if there are more then one part to display
    int tabButtonsPosX = 0;
    int tabAreaPosY = contentArea.y;
    int maxToolbarWidth = 0;
    int gtkHeightFix = 0;
    int toolbarHeight = 0;
    int toolbarWidth = 0;
    if (toolBar != null && toolbarVisible) {
        Point toolBarSize = toolBar.computeSize(SWT.DEFAULT, SWT.DEFAULT);
        toolbarHeight = toolBarSize.y;
        if (UIUtils.isGtk) {
            gtkHeightFix = theme.getInt(ThemeConstants.GTK_TOOLBAR_FIX);
        } else {
            gtkHeightFix = 0;
        }
        toolbarWidth = toolBarSize.x;
    } else {
        //toolBarSize = new Point(0, 0);
    }

    boolean allowToolbarInTabArea = false;
    if (parts.size() > 1) {
        // Layout tabs
        int tabAreaHeight;
        if (tabsVisible) {
            tabAreaHeight = tabArea.computeHeight();
            maxToolbarWidth = clientArea.width - tabArea.getEstimatedWidth() - borderSize;
            allowToolbarInTabArea = tabArea.hasEnoughSpace() && maxToolbarWidth > 0
                    && maxToolbarWidth > toolbarWidth;
            if (allowToolbarInTabArea) {
                tabAreaHeight = Math.max(tabAreaHeight, toolbarHeight - gtkHeightFix);
                if (tabAreaHeight == toolbarHeight - gtkHeightFix) {
                    tabAreaHeight += borderSize_x_2;
                    if (!topPosition) {
                        tabAreaHeight += borderSize;
                    }
                }
            }
        } else {
            tabAreaHeight = 0;
        }

        if (clientArea.height - topHeight < tabAreaHeight) {
            tabsVisible = false;
            tabArea.setVisible(false);
            tabButtons.setVisible(false);
            contentArea.height -= borderSize;
        } else {
            contentArea.height -= tabAreaHeight + borderSize;
            if (topPosition) {
                tabAreaPosY += topHeight;
                topHeight += tabAreaHeight;
                contentArea.height += tabAreaHeight;
            } else {
                tabAreaPosY += contentArea.height;
            }
            Point tabButtonsSize = tabButtons.computeSize(SWT.DEFAULT, tabAreaHeight, true);
            if (tabsVisible) {
                tabArea.setBounds(clientArea.x + borderSize, tabAreaPosY,
                        clientArea.width - tabButtonsSize.x - borderSize_x_2, tabAreaHeight);
                tabButtonsPosX = clientArea.x + clientArea.width - tabButtonsSize.x - borderSize;
                tabButtons.setBounds(tabButtonsPosX, tabAreaPosY, tabButtonsSize.x, tabAreaHeight);
                tabArea.setVisible(true);
                tabButtons.setVisible(true);

            } else {
                tabsVisible = false;
                tabArea.setVisible(false);
                tabButtons.setVisible(false);
            }
        }
    } else {
        tabsVisible = false;
        tabArea.setVisible(false);
        tabButtons.setVisible(false);
        contentArea.height -= borderSize;
    }

    // Layout view toolBar
    if (toolBar != null) {
        boolean tooLessHeight = contentArea.height - topHeight - CONTROL_GAP <= toolbarHeight - gtkHeightFix;
        if (!toolbarVisible || (tooLessHeight && (!tabsVisible || !allowToolbarInTabArea))) {
            toolBar.setVisible(false);
        } else {

            if (tabsVisible && allowToolbarInTabArea) {
                int toolbarYpos;
                if (topPosition) {
                    toolbarYpos = tabAreaPosY;
                } else {
                    toolbarYpos = tabAreaPosY + CONTROL_GAP * 2;
                }
                // tab area may have space for toolbar...
                Point toolBarDisplayPos = presentationControl
                        .toDisplay(clientArea.x + clientArea.width - toolbarWidth - borderSize, toolbarYpos);
                Point toolBarControlPos = toolBar.getParent().toControl(toolBarDisplayPos);
                toolBar.setBackground(theme.getColor(ThemeConstants.TAB_COLOR_NOFOCUS));
                toolBar.setBounds(toolBarControlPos.x, toolBarControlPos.y, toolbarWidth,
                        toolbarHeight - gtkHeightFix);

            } else {
                // no place on tab area or it is invisible
                int toolbarYpos = clientArea.y + topHeight;
                Point toolBarDisplayPos = presentationControl.toDisplay(clientArea.x, toolbarYpos);
                Point toolBarControlPos = toolBar.getParent().toControl(toolBarDisplayPos);
                toolBar.setBackground(theme.getColor(ThemeConstants.TAB_COLOR_FOCUS));
                toolBar.setBounds(toolBarControlPos.x + borderSize, toolBarControlPos.y,
                        clientArea.width - borderSize_x_2, toolbarHeight - gtkHeightFix);
                topHeight += toolbarHeight - gtkHeightFix + CONTROL_GAP;
            }
            toolBar.setVisible(true);
        }

    }

    // Compute content area size
    contentArea.y += topHeight;
    contentArea.height -= topHeight;

    // Layout content
    if (hasContent && contentArea.height > 2) {
        if (PresentationPlugin.DEBUG_LAYOUT) {
            System.out.println(getDebugPartName() + ": layout content");
        }

        Point contentDisplayPos = presentationControl.toDisplay(contentArea.x + borderSize, contentArea.y);
        Control control = currentPart.getControl();
        Point contentControlPos = control.getParent().toControl(contentDisplayPos);
        control.setBounds(contentControlPos.x, contentControlPos.y, contentArea.width - borderSize_x_2,
                contentArea.height);
        control.setVisible(true);
    } else if (hasContent) {
        if (PresentationPlugin.DEBUG_LAYOUT) {
            System.out.println(getDebugPartName() + ": layout content canceled as invisible");
        }

        Control control = currentPart.getControl();
        control.setVisible(false);
    }
}

From source file:de.loskutov.eclipseskins.ui.TabArea.java

License:Open Source License

protected void layoutTabs() {
    if (PresentationPlugin.DEBUG_LAYOUT) {
        System.out.println((presentation.isView() ? "view" : "edit") + "Tabs:layout");
    }/*ww  w.j  av  a  2s .c  o  m*/
    Rectangle clientArea = getClientArea();
    if (!initDone || clientArea.width == 0 || clientArea.height == 0 || tabs.isEmpty()) {
        if (initDone) {
            // listeners may be interested even if we do not need to relayout us
            //                notifyListeners();
        }
        return;
    }
    // TODO check if we do not really need to recompute it here
    //      tabButtSize = tabButtons.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    tabArea = Geometry.copy(clientArea);

    // calculate real total width
    totalWidth = 0;

    for (int i = 0; i < tabs.size(); i++) {
        PartTab tab = (PartTab) tabs.get(i);
        int width = tab.computeSize(hasEnoughSpace, null).x;
        totalWidth += width;
    }

    if (hasEnoughSpace) {
        xPosition = 0;
    } else {
        if (totalWidth < clientArea.width - tabButtSize.x) {
            xPosition = clientArea.x;
        }
        if (xPosition < clientArea.x
                && xPosition + totalWidth < clientArea.x + clientArea.width - tabButtSize.x) {
            xPosition = clientArea.x + clientArea.width - totalWidth;
        }
        tabArea.x += xPosition;
    }

    int oldHiddenCount = hiddenTabCount;
    hiddenTabCount = 0;

    for (int i = 0; i < tabs.size(); i++) {
        PartTab tab = (PartTab) tabs.get(i);
        Point tabSize = tab.computeSize(hasEnoughSpace, null);
        // minimum visible pixel to be counted as "visible" tab is a half tab width
        int minVisibleArea = tabSize.x / 2;
        // invisible with "minVisibleArea" tolerance
        boolean inVisible = tabArea.x + tabSize.x - minVisibleArea < clientArea.x
                || tabArea.x + minVisibleArea > clientArea.x + clientArea.width;
        // really really not visible on screen
        boolean reallyInVisible = tabArea.x + tabSize.x < clientArea.x
                || tabArea.x > clientArea.x + clientArea.width;
        tab.setHidden(inVisible);
        if (inVisible) {
            if (reallyInVisible) {
                tab.setVisible(false);
            } else {
                tab.setVisible(true);
            }
            // for user, the tab isn't really accessible now
            hiddenTabCount++;
        } else {
            tab.setVisible(true);
        }

        // TODO does we need to distinct between top/bottom instead here?
        if (isView) {
            tab.setBounds(tabArea.x, tabArea.y + 1, tabSize.x, tabArea.height - Y_GAP);
        } else {
            tab.setBounds(tabArea.x, tabArea.y + tabArea.height - tabSize.y, tabSize.x, tabSize.y);
        }
        tabArea.x += tabSize.x;
    }

    boolean showLeft = xPosition < clientArea.x - 2;
    boolean showRight = xPosition + totalWidth > clientArea.x + clientArea.width + 2;
    boolean navigatorShown = showLeft || showRight || hiddenTabCount > 0;
    tabButtons.setLeftEnabled(showLeft);
    tabButtons.setRightEnabled(showRight);
    tabButtons.setShowNavigator(navigatorShown);
    if (oldHiddenCount != hiddenTabCount) {
        // number of hidden editors changed
        tabButtons.redraw();
    }
    initDone = true;
    notifyListeners();
}

From source file:eu.jucy.gui.representation.WrappedTabsPartPresentation.java

License:Open Source License

public void setBounds(Rectangle bounds) {
    Rectangle newBounds = Geometry.copy(bounds);

    if (newBounds.width == 0) {
        // Workaround a bug in the Eclipse 3.0 release: minimized presentations will be
        // given a width of 0.
        newBounds.width = presentationControl.getBounds().width;
    }/*w w  w.  j  a  v  a2s.  c  o  m*/

    if (getSite().getState() == IStackPresentationSite.STATE_MINIMIZED) {
        newBounds.height = computeMinimumSize().y;
    }

    // Set the bounds of the presentation widge
    presentationControl.setBounds(newBounds);

    // Update the bounds of the currently visible part
    layout();
}

From source file:net.sf.eclipsensis.editor.codeassist.NSISInformationControl.java

License:Open Source License

protected final Point getSizeConstraints() {
    return mSizeConstraints != null ? Geometry.copy(mSizeConstraints) : null;
}

From source file:org.eclipse.e4.ui.workbench.addons.dndaddon.DnDManager.java

License:Open Source License

public void setRectangle(Rectangle newRect) {
    if (tracker == null)
        return;/*  w w  w .  j  a v a2s . co m*/

    Rectangle[] rectArray = { Geometry.copy(newRect) };
    tracker.setRectangles(rectArray);
}

From source file:org.eclipse.ui.forms.widgets.SizeCache.java

License:Open Source License

/**
 * Computes the preferred size of the control.
 *  //from  w w  w.  j a va  2s  . c o  m
 * @param widthHint the known width of the control (pixels) or SWT.DEFAULT if unknown
 * @param heightHint the known height of the control (pixels) or SWT.DEFAULT if unknown
 * @return the preferred size of the control
 */
public Point computeSize(int widthHint, int heightHint) {
    if (control == null || control.isDisposed()) {
        return new Point(0, 0);
    }

    // If we're asking for a result smaller than the minimum width
    int minWidth = computeMinimumWidth();

    if (widthHint != SWT.DEFAULT && widthHint + widthAdjustment < minWidth) {
        if (heightHint == SWT.DEFAULT) {
            return new Point(minWidth, computeHeightAtMinimumWidth());
        }

        widthHint = minWidth - widthAdjustment;
    }

    // If we're asking for a result smaller than the minimum height
    int minHeight = computeMinimumHeight();

    if (heightHint != SWT.DEFAULT && heightHint + heightAdjustment < minHeight) {
        if (widthHint == SWT.DEFAULT) {
            return new Point(computeWidthAtMinimumHeight(), minHeight);
        }

        heightHint = minHeight - heightAdjustment;
    }

    // If both dimensions were supplied in the input, compute the trivial result
    if (widthHint != SWT.DEFAULT && heightHint != SWT.DEFAULT) {
        return new Point(widthHint + widthAdjustment, heightHint + heightAdjustment);
    }

    // No hints given -- find the preferred size
    if (widthHint == SWT.DEFAULT && heightHint == SWT.DEFAULT) {
        return Geometry.copy(getPreferredSize());
    }

    // If the length and width are independent, compute the preferred size
    // and adjust whatever dimension was supplied in the input
    if (independentDimensions) {
        Point result = Geometry.copy(getPreferredSize());

        if (widthHint != SWT.DEFAULT) {
            result.x = widthHint + widthAdjustment;
        }

        if (heightHint != SWT.DEFAULT) {
            result.y = heightHint + heightAdjustment;
        }

        return result;
    }

    // Computing a height
    if (heightHint == SWT.DEFAULT) {
        // If we know the control's preferred size
        if (preferredSize != null) {
            // If the given width is the preferred width, then return the preferred size
            if (widthHint + widthAdjustment == preferredSize.x) {
                return Geometry.copy(preferredSize);
            }
        }

        // If we have a cached height measurement
        if (cachedHeightQuery != -1) {
            // If this was measured with the same width hint
            if (cachedHeightQuery == widthHint) {
                return new Point(widthHint + widthAdjustment, cachedHeightResult);
            }
        }

        // If this is a control where any hint larger than the
        // preferred width results in the minimum height, determine if
        // we can compute the result based on the preferred height
        if (preferredWidthOrLargerIsMinimumHeight) {
            // Computed the preferred size (if we don't already know it)
            getPreferredSize();

            // If the width hint is larger than the preferred width, then
            // we can compute the result from the preferred width
            if (widthHint + widthAdjustment >= preferredSize.x) {
                return new Point(widthHint + widthAdjustment, preferredSize.y);
            }
        }

        // Else we can't find an existing size in the cache, so recompute
        // it from scratch.
        Point newHeight = controlComputeSize(widthHint - widthAdjustment, SWT.DEFAULT);

        cachedHeightQuery = heightHint;
        cachedHeightResult = newHeight.y;

        return newHeight;
    }

    // Computing a width
    if (widthHint == SWT.DEFAULT) {
        // If we know the control's preferred size
        if (preferredSize != null) {
            // If the given height is the preferred height, then return the preferred size
            if (heightHint + heightAdjustment == preferredSize.y) {
                return Geometry.copy(preferredSize);
            }
        }

        // If we have a cached width measurement with the same height hint
        if (cachedWidthQuery == heightHint) {
            return new Point(cachedWidthResult, heightHint + heightAdjustment);
        }

        Point widthResult = controlComputeSize(SWT.DEFAULT, heightHint - heightAdjustment);

        cachedWidthQuery = heightHint;
        cachedWidthResult = widthResult.x;

        return widthResult;
    }

    return controlComputeSize(widthHint, heightHint);
}