List of usage examples for com.google.gwt.dom.client Element getOffsetHeight
@Override
public int getOffsetHeight()
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: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;/*w w w. j ava2s . c o 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
/** * @param e/*from w ww .j av a 2 s. c o m*/ * - 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. * /*www . j a va 2s. com*/ * @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./*from w ww .ja v a 2s. 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 ww w. j a v a2 s. com * @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 . j av a 2 s . c o m } }
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 .ja v a2s .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.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> * // ww w . ja va2 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
/** * Ensures that the given element is visible.<p> * //from ww w . j ava 2 s. co m * Assuming the scrollbars are on the container element, and that the element is a child of the container element.<p> * * @param containerElement the container element, has to be parent of the element * @param element the element to be seen * @param animationTime the animation time for scrolling, use zero for no animation */ public static void ensureVisible(final Element containerElement, Element element, int animationTime) { Element item = element; int realOffset = 0; while ((item != null) && (item != containerElement)) { realOffset += element.getOffsetTop(); item = item.getOffsetParent(); } final int endScrollTop = realOffset - (containerElement.getOffsetHeight() / 2); if (animationTime <= 0) { // no animation containerElement.setScrollTop(endScrollTop); return; } final int startScrollTop = containerElement.getScrollTop(); (new Animation() { /** * @see com.google.gwt.animation.client.Animation#onUpdate(double) */ @Override protected void onUpdate(double progress) { containerElement.setScrollTop(startScrollTop + (int) ((endScrollTop - startScrollTop) * progress)); } }).run(animationTime); }