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

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

Introduction

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

Prototype

@Override
    public int getAbsoluteTop() 

Source Link

Usage

From source file:cc.alcina.framework.gwt.client.util.WidgetUtils.java

License:Apache License

public static void scrollIntoView(Element elem, int fromTop, boolean forceFromTop) {
    int y1 = Document.get().getBodyOffsetTop() + Window.getScrollTop();
    int y2 = y1 + Window.getClientHeight();
    Element parent = elem.getParentElement();
    int absoluteTop = elem.getAbsoluteTop();
    int offsetHeight = elem.getOffsetHeight();
    int absoluteBottom = absoluteTop + offsetHeight;
    boolean recalcAbsoluteTopAfterScroll = true;
    if (absoluteTop == 0) {
        Text tptCopy = tempPositioningText;
        tempPositioningText = null;//from  w  ww  .j a va2  s  .  co m
        Element positioning = WidgetUtils.getElementForPositioning0(elem);
        if (positioning != null) {
            absoluteTop = positioning.getAbsoluteTop();
            recalcAbsoluteTopAfterScroll = false;
        }
        releaseTempPositioningText();
        tempPositioningText = tptCopy;
    }
    if (!forceFromTop && (absoluteTop >= y1 && absoluteTop < y2)) {
        return;
    }
    if (forceFromTop && LooseContext.is(CONTEXT_REALLY_ABSOLUTE_TOP)) {
        int to = absoluteTop - fromTop;
        scrollBodyTo(to);
        return;
    }
    scrollElementIntoView(elem);
    y1 = Document.get().getBodyOffsetTop() + Window.getScrollTop();
    y2 = y1 + Window.getClientHeight();
    // not sure why...but I feel there's a reason
    if (recalcAbsoluteTopAfterScroll) {
        absoluteTop = elem.getAbsoluteTop();
    }
    if (absoluteTop < y1 || absoluteTop > y2 || fromTop != 0) {
        scrollBodyTo((Math.max(0, absoluteTop - fromTop)));
    }
}

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.
 * // w ww .  j av a 2s  .  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 ww w  .j  a  va2  s.  c o  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 va  2s .  co  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)));
        }/*www .j  a v  a2s . 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.AttributeValueView.java

License:Open Source License

/**
 * @see com.alkacon.geranium.client.dnd.I_Draggable#getDragHelper(com.alkacon.geranium.client.dnd.I_DropTarget)
 *///from  w  w w  .  j a v  a2  s. c o m
public Element getDragHelper(I_DropTarget target) {

    closeHelpBubble(null);
    // using the widget element as the drag helper also to avoid cloning issues on input fields
    m_dragHelper = getElement();
    Element parentElement = getElement().getParentElement();
    if (parentElement == null) {
        parentElement = target.getElement();
    }
    int elementTop = getElement().getAbsoluteTop();
    int parentTop = parentElement.getAbsoluteTop();
    Style style = m_dragHelper.getStyle();
    style.setWidth(m_dragHelper.getOffsetWidth(), Unit.PX);
    // the dragging class will set position absolute
    style.setTop(elementTop - parentTop, Unit.PX);
    m_dragHelper.addClassName(formCss().dragHelper());
    return m_dragHelper;
}

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

License:Open Source License

/**
 * Checks whether the submenu should be opened above instead of below.<p>
 * //from  w w  w. j  a  v a  2  s. com
 * @param referenceElement the reference element 
 * @return true if the new submenu should be opened above 
 */
public boolean openAbove(Element referenceElement) {

    int windowTop = Window.getScrollTop();
    int windowBottom = Window.getScrollTop() + Window.getClientHeight();
    int spaceAbove = referenceElement.getAbsoluteTop() - windowTop;
    int spaceBelow = windowBottom - referenceElement.getAbsoluteBottom();
    return spaceAbove > spaceBelow;
}

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>
 * /*w w  w .j  a  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.acacia.client.ui.InlineEntityWidget.java

License:Open Source License

/**
 * Creates the inline edit widget and injects it next to the context element.<p>
 * /*from   w  ww.  j  a v a2  s .co m*/
 * @param element the context element
 * @param formParent the parent widget
 * @param parentEntity the parent entity
 * @param attributeHandler the attribute handler
 * @param attributeIndex the attribute value index
 * @param htmlUpdateHandler handles HTML updates if required
 * @param widgetService the widget service
 * 
 * @return the widget instance
 */
public static InlineEntityWidget createWidgetForEntity(Element element, I_InlineFormParent formParent,
        I_Entity parentEntity, AttributeHandler attributeHandler, int attributeIndex,
        I_InlineHtmlUpdateHandler htmlUpdateHandler, I_WidgetService widgetService) {

    InlineEntityWidget widget = new InlineEntityWidget(element, formParent, parentEntity, attributeHandler,
            attributeIndex, htmlUpdateHandler, widgetService);
    InlineEditOverlay.getRootOverlay().addButton(widget, element.getAbsoluteTop());
    attributeHandler.updateButtonVisibilty(widget);
    return widget;
}

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>
 * //w w  w  .ja va  2 s  .c o 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);
}