Example usage for com.google.gwt.dom.client Element getAbsoluteLeft

List of usage examples for com.google.gwt.dom.client Element getAbsoluteLeft

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Element getAbsoluteLeft.

Prototype

@Override
    public int getAbsoluteLeft() 

Source Link

Usage

From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java

License:Apache License

/**
 * Returns the drop target that has the highest priority and that has the biggest intersection area with the given element.
 * //from w  w w .  java2 s .c o  m
 * @param e
 * @return a tuple of the drop target widget and the intersecting area or null if the element does not intersect with another element
 */
protected Tuple<Widget, Long> getHoverDropTarget(Element e) {
    Set<Widget> affected = getAffectedDropTargets(e);
    if (affected == null || affected.isEmpty())
        return null;
    Widget max = null;
    long maxArea = 0;
    for (Widget target : affected) {
        boolean widgetIsLeftOfTarget = target.getAbsoluteLeft() - e.getAbsoluteLeft() > 0;
        boolean widgetIsTopOfTarget = target.getAbsoluteTop() - e.getAbsoluteTop() > 0;
        long collision = getCollisionArea(widgetIsLeftOfTarget ? e : target.getElement(),
                widgetIsLeftOfTarget ? target.getElement() : e, widgetIsTopOfTarget ? e : target.getElement(),
                widgetIsTopOfTarget ? target.getElement() : e);
        if (collision > maxArea || max == null) {
            max = target;
            maxArea = collision;
        }
    }
    return new Tuple<Widget, Long>(max, maxArea);
}

From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java

License:Apache License

/**
 * This method takes two different elements which are passed multiple times depending on their relative position and calculates the collision area in square
 * pixels./*from w  ww . j  a  v  a2  s  . co  m*/
 * 
 * @param left
 *            - the element which is further left than the other
 * @param right
 *            - the element which is further right than the other
 * @param top
 *            - the element which is further top than the other
 * @param bottom
 *            - the element which is further bottom than the other
 * @return the collision area between the elements in square pixels
 */
protected long getCollisionArea(Element left, Element right, Element top, Element bottom) {
    int collX = Math.min(left.getAbsoluteLeft() + left.getOffsetWidth(),
            right.getAbsoluteLeft() + right.getOffsetWidth()) - right.getAbsoluteLeft();
    int collY = Math.min(top.getAbsoluteTop() + top.getOffsetHeight(),
            bottom.getAbsoluteTop() + bottom.getOffsetHeight()) - bottom.getAbsoluteTop();
    return collX * collY;
}

From source file:ch.unifr.pai.twice.dragndrop.client.MPDragNDrop.java

License:Apache License

/**
 * This method looks up all the drop targets which are intersecting with the given element. If the drop targets differ in their priorities ({@link Priority}
 * ), only widgets of the highest priority are returned.
 * //from   w ww  . j a v  a 2 s .c  o  m
 * @param e
 *            - a HTML element (typically the HTML element of the dragged widget)
 * @return the drop target widgets which are intersecting with the given element and do have the highest priority
 */
protected Set<Widget> getAffectedDropTargets(Element e) {
    int w1X = e.getAbsoluteLeft();
    int w1Y = e.getAbsoluteTop();
    int w1Width = e.getOffsetWidth();
    int w1Height = e.getOffsetHeight();
    Map<Integer, HashSet<Widget>> targets = new HashMap<Integer, HashSet<Widget>>();
    for (Widget w2 : dropTargetRegistry.keySet()) {
        int w2X = w2.getAbsoluteLeft();
        int w2Y = w2.getAbsoluteTop();
        boolean xCollision = w1X < w2X ? w2X - w1X < w1Width : w1X - w2X < w2.getOffsetWidth();
        boolean yCollision = w1Y < w2Y ? w2Y - w1Y < w1Height : w1Y - w2Y < w2.getOffsetHeight();
        String idStyle = w2.getElement().getId() != null && !w2.getElement().getId().equals("")
                ? "hover-" + w2.getElement().getId()
                : null;
        if (xCollision && yCollision) {
            if (idStyle != null) {
                e.addClassName(idStyle);
            }
            DropTargetHandler h = dropTargetRegistry.get(w2);
            if (h != null) {
                int prio = h.getPriority().getValue();
                HashSet<Widget> widgetsForPrio = targets.get(prio);
                if (widgetsForPrio == null) {
                    widgetsForPrio = new HashSet<Widget>();
                    targets.put(prio, widgetsForPrio);
                }
                widgetsForPrio.add(w2);
            }
        } else if (idStyle != null) {
            e.removeClassName(idStyle);
        }
    }
    if (targets.isEmpty())
        return null;
    int maxprio = 0;
    for (Integer i : targets.keySet()) {
        if (i > maxprio) {
            maxprio = i;
        }
    }
    return targets.get(maxprio);
}

From source file:com.ait.lienzo.client.widget.LienzoHandlerManager.java

License:Open Source License

private final List<TouchPoint> getTouches(final TouchEvent<?> event) {
    final JsArray<Touch> jsarray = event.getTouches();

    final Element element = event.getRelativeElement();

    if ((null != jsarray) && (jsarray.length() > 0)) {
        final int size = jsarray.length();

        final ArrayList<TouchPoint> touches = new ArrayList<TouchPoint>(size);

        for (int i = 0; i < size; i++) {
            final Touch touch = jsarray.get(i);

            touches.add(new TouchPoint(touch.getRelativeX(element), touch.getRelativeY(element)));
        }//from w w w  .j  av  a 2 s .co  m
        return touches;
    } else {
        int x = event.getNativeEvent().getClientX() - element.getAbsoluteLeft() + element.getScrollLeft()
                + element.getOwnerDocument().getScrollLeft();

        int y = event.getNativeEvent().getClientY() - element.getAbsoluteTop() + element.getScrollTop()
                + element.getOwnerDocument().getScrollTop();

        return Arrays.asList(new TouchPoint(x, y));
    }
}

From source file:com.alkacon.acacia.client.ui.ChoiceSubmenu.java

License:Open Source License

/**
 * Helper method to position a submenu on the left side of a menu entry.<p>
 * //from   w w w.  ja  va  2  s  .  c  o  m
 * @param widgetEntry the widget entry relative to which the submenu should  be positioned 
 */
protected void positionNextToMenuEntry(final ChoiceMenuEntryWidget widgetEntry) {

    Element elem = getElement();
    elem.getStyle().setPosition(Style.Position.ABSOLUTE);
    Element referenceElement = null;
    int startX = -2000;
    int startY = -2000;
    int deltaX = 0;
    int deltaY = 0;
    referenceElement = widgetEntry.getElement();
    Style style = elem.getStyle();
    style.setLeft(startX, Unit.PX);
    style.setTop(startY, Unit.PX);
    int myRight = elem.getAbsoluteRight();
    int myTop = elem.getAbsoluteTop();
    int refLeft = referenceElement.getAbsoluteLeft();
    int refTop = referenceElement.getAbsoluteTop();
    int newLeft = startX + (refLeft - myRight) + deltaX;
    int newTop;
    if (openAbove(referenceElement)) {
        int myHeight = elem.getOffsetHeight();
        int refHeight = referenceElement.getOffsetHeight();
        newTop = startY + ((refTop + refHeight) - (myTop + myHeight)) + deltaY;
    } else {
        newTop = startY + (refTop - myTop) + deltaY;
    }
    style.setLeft(newLeft, Unit.PX);
    style.setTop(newTop, Unit.PX);
}

From source file:com.alkacon.geranium.client.dnd.DNDHandler.java

License:Open Source License

/**
 * Shows the end animation on drop or cancel. Executes the given callback afterwards.<p>
 * //from ww  w  .  j a  va 2 s  .  co m
 * @param callback the callback to execute
 * @param top absolute top of the animation end position
 * @param left absolute left of the animation end position
 */
private void showEndAnimation(Command callback, int top, int left) {

    if (!isAnimationEnabled() || (m_dragHelper == null)) {
        callback.execute();
        return;
    }
    Element parentElement = m_dragHelper.getParentElement();
    int endTop = top - parentElement.getAbsoluteTop();
    int endLeft = left - parentElement.getAbsoluteLeft();
    int startTop = DomUtil.getCurrentStyleInt(m_dragHelper, Style.top);
    int startLeft = DomUtil.getCurrentStyleInt(m_dragHelper, Style.left);
    m_currentAnimation = new MoveAnimation(m_dragHelper, startTop, startLeft, endTop, endLeft, callback);
    m_currentAnimation.run(300);
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Gets the horizontal position of the given x-coordinate relative to a given element.<p>
 * //from   ww w . j  a  v  a  2s. c o m
 * @param x the coordinate to use 
 * @param target the element whose coordinate system is to be used
 * 
 * @return the relative horizontal position
 * 
 * @see com.google.gwt.event.dom.client.MouseEvent#getRelativeX(com.google.gwt.dom.client.Element)
 */
public static int getRelativeX(int x, Element target) {

    return (x - target.getAbsoluteLeft())
            + /* target.getScrollLeft() + */target.getOwnerDocument().getScrollLeft();
}

From source file:com.alkacon.geranium.client.util.DomUtil.java

License:Open Source License

/**
 * Positions an element in the DOM relative to another element.<p>
 * /*from w w  w  . j a  va2 s .  c  o m*/
 * @param elem the element to position
 * @param referenceElement the element relative to which the first element should be positioned
 * @param dx the x offset relative to the reference element
 * @param dy the y offset relative to the reference element 
 */
public static void positionElement(Element elem, Element referenceElement, int dx, int dy) {

    com.google.gwt.dom.client.Style style = elem.getStyle();
    style.setLeft(0, Unit.PX);
    style.setTop(0, Unit.PX);
    int myX = elem.getAbsoluteLeft();
    int myY = elem.getAbsoluteTop();
    int refX = referenceElement.getAbsoluteLeft();
    int refY = referenceElement.getAbsoluteTop();
    int newX = (refX - myX) + dx;
    int newY = (refY - myY) + dy;
    style.setLeft(newX, Unit.PX);
    style.setTop(newY, Unit.PX);
}

From source file:com.alkacon.geranium.client.util.PositionBean.java

License:Open Source License

/**
 * Collects the position information of the given UI object and returns a position info bean.<p> 
 * //from w  w w .j a v a  2  s  . com
 * @param element the object to read the position data from
 * 
 * @return the position data
 */
public static PositionBean generatePositionInfo(Element element) {

    PositionBean result = new PositionBean();
    result.setHeight(element.getOffsetHeight());
    result.setWidth(element.getOffsetWidth());
    result.setTop(element.getAbsoluteTop());
    result.setLeft(element.getAbsoluteLeft());
    return result;
}

From source file:com.alkacon.geranium.client.util.PositionBean.java

License:Open Source License

/**
 * Returns a position info representing the dimensions of all visible child elements of the given panel (excluding elements with position:absolute).
 * If the panel has no visible child elements, it's outer dimensions are returned.<p>
 * //from  www.  ja va 2  s. c  o  m
 * @param panel the panel
 * @param levels the levels to traverse down the DOM tree
 * @param includeSelf <code>true</code> to include the outer dimensions of the given panel
 * 
 * @return the position info
 */
public static PositionBean getInnerDimensions(Element panel, int levels, boolean includeSelf) {

    boolean first = true;
    int top = 0;
    int left = 0;
    int bottom = 0;
    int right = 0;
    // if overflow is set to hidden, use the outer dimensions
    if (!Overflow.HIDDEN.getCssName().equals(DomUtil.getCurrentStyle(panel, Style.overflow))) {
        if (!includeSelf) {
            // check for any text content
            NodeList<Node> children = panel.getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                if ((children.getItem(i).getNodeType() == Node.TEXT_NODE)
                        && (children.getItem(i).getNodeValue().trim().length() > 0)) {
                    includeSelf = true;
                    break;
                }
            }
        }
        if (includeSelf) {
            top = panel.getAbsoluteTop();
            left = panel.getAbsoluteLeft();
            bottom = top + panel.getOffsetHeight();
            right = left + panel.getOffsetWidth();
            first = false;
        }
        Element child = panel.getFirstChildElement();
        while (child != null) {
            String tagName = child.getTagName();
            if (tagName.equalsIgnoreCase("br") || tagName.equalsIgnoreCase("tr")
                    || tagName.equalsIgnoreCase("thead") || tagName.equalsIgnoreCase("tfoot")
                    || tagName.equalsIgnoreCase("script") || tagName.equalsIgnoreCase("style")) {
                // ignore tags with no relevant position info
                child = child.getNextSiblingElement();
                continue;
            }
            String positioning = DomUtil.getCurrentStyle(child, Style.position);
            if (!Display.NONE.getCssName().equals(DomUtil.getCurrentStyle(child, Style.display))
                    && !(positioning.equalsIgnoreCase(Position.ABSOLUTE.getCssName())
                            || positioning.equalsIgnoreCase(Position.FIXED.getCssName()))) {
                PositionBean childDimensions = levels > 0 ? getInnerDimensions(child, levels - 1, true)
                        : generatePositionInfo(panel);
                if (first) {
                    first = false;
                    top = childDimensions.getTop();
                    left = childDimensions.getLeft();
                    bottom = top + childDimensions.getHeight();
                    right = left + childDimensions.getWidth();
                } else {
                    int wTop = childDimensions.getTop();
                    top = top < wTop ? top : wTop;
                    int wLeft = childDimensions.getLeft();
                    left = left < wLeft ? left : wLeft;
                    int wBottom = wTop + childDimensions.getHeight();
                    bottom = bottom > wBottom ? bottom : wBottom;
                    int wRight = wLeft + childDimensions.getWidth();
                    right = right > wRight ? right : wRight;
                }
            }
            child = child.getNextSiblingElement();
        }
    }
    if (!first) {
        PositionBean result = new PositionBean();
        result.setHeight(bottom - top);
        result.setWidth(right - left);
        result.setTop(top);
        result.setLeft(left);
        return result;
    } else {
        return generatePositionInfo(panel);
    }
}