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

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

Introduction

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

Prototype

@Override
    public int getOffsetWidth() 

Source Link

Usage

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

License:Apache License

public static boolean isZeroOffsetDims(Element e) {
    return e.getOffsetHeight() == 0 || e.getOffsetWidth() == 0;
}

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

License:Apache License

/**
 * @param e//from   ww w .ja va  2s  .  c om
 *            - a HTML element
 * @return the area of the HTML element in square pixels
 */
protected long getAreaOfWidget(Element e) {
    return e.getOffsetHeight() * e.getOffsetWidth();
}

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

License:Apache License

/**
 * Repositions the dragged widget to a specific x and y position taking into account the offset between the original widget coordinates and the mouse
 * pointer position at the begin of the drag. The offset is kept in percentages to make the offset calculation independent of the drag-proxy size.
 * //from  w  ww .j  a va2s .  c o m
 * @param x
 * @param y
 * @param withOffset
 */
protected void setPosition(int x, int y, boolean withOffset) {
    Element dragProxy = conf.getDragProxy();
    int newX = x - (withOffset ? (int) (dragProxy.getOffsetWidth() / 100.0 * percOffsetX) : 0);
    int newY = y - (withOffset ? (int) (dragProxy.getOffsetHeight() / 100.0 * percOffsetY) : 0);
    dragProxy.getStyle().setLeft(
            Math.max(conf.getMinX(), Math.min(newX, conf.getMaxX() - dragProxy.getOffsetWidth())), Unit.PX);
    dragProxy.getStyle().setTop(
            Math.max(conf.getMinY(), Math.min(newY, conf.getMaxY() - dragProxy.getOffsetHeight())), Unit.PX);
}

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.//  w  ww .ja v a 2 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  w  w . 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.panel.scrollbars.ScrollablePanel.java

License:Apache License

public void updateSize() {
    final Element parentElement = getElement().getParentElement();
    final int width = parentElement.getOffsetWidth();
    final int height = parentElement.getOffsetHeight();

    if (width > 0 && height > 0) {
        updateSize(width, height);//from   w  w w .jav  a 2  s .co m
    }
}

From source file:com.alkacon.acacia.client.widgets.TinyMCEWidget.java

License:Open Source License

/**
 * Calculates the widget width.<p>
 * //from   w w w  . j  a v  a  2 s.  co m
 * @return the widget width
 */
int calculateWidth() {

    int result;
    if (m_inline && DomUtil.getCurrentStyle(getElement(), Style.display).equals("inline")) {
        com.google.gwt.dom.client.Element parentBlock = getElement().getParentElement();
        while (DomUtil.getCurrentStyle(parentBlock, Style.display).equals("inline")) {
            parentBlock = parentBlock.getParentElement();
        }
        result = parentBlock.getOffsetWidth();
    } else {
        result = getElement().getOffsetWidth();
    }
    return result - 2;
}

From source file:com.alkacon.geranium.client.ui.input.A_SelectCell.java

License:Open Source License

/**
 * Measures the required width for this cell.<p>
 * /*from  www.  j  ava2s.co m*/
 * @return the required width
 */
public int getRequiredWidth() {

    Element clone = DomUtil.clone(getElement());
    clone.getStyle().setPosition(Position.ABSOLUTE);
    RootPanel.getBodyElement().appendChild(clone);
    int result = clone.getOffsetWidth();
    clone.removeFromParent();
    return result;
}

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

License:Open Source License

/**
 * Returns if the given client position is over the given element.<p>
 * Use <code>-1</code> for x or y to ignore one ordering orientation.<p>
 * //from   w  w w. j  av  a  2 s .  co m
 * @param element the element
 * @param x the client x position, use <code>-1</code> to ignore x position 
 * @param y the client y position, use <code>-1</code> to ignore y position
 * 
 * @return <code>true</code> if the given position is over the given element
 */
public static boolean checkPositionInside(Element element, int x, int y) {

    // ignore x / left-right values for x == -1
    if (x != -1) {
        // check if the mouse pointer is within the width of the target 
        int left = DomUtil.getRelativeX(x, element);
        int offsetWidth = element.getOffsetWidth();
        if ((left <= 0) || (left >= offsetWidth)) {
            return false;
        }
    }
    // ignore y / top-bottom values for y == -1
    if (y != -1) {
        // check if the mouse pointer is within the height of the target 
        int top = DomUtil.getRelativeY(y, element);
        int offsetHeight = element.getOffsetHeight();
        if ((top <= 0) || (top >= offsetHeight)) {
            return false;
        }
    }
    return true;
}

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

License:Open Source License

/**
 * Returns if the given element has any dimension.<p>
 * All visible elements should have a dimension.<p>
 * //from   w  w w . ja  v  a2s  . c o  m
 * @param element the element to test
 * 
 * @return <code>true</code> if the given element has any dimension
 */
public static boolean hasDimension(Element element) {

    return (element.getOffsetHeight() > 0) || (element.getOffsetWidth() > 0);
}