Java Code Examples for com.google.gwt.dom.client.Element#getAbsoluteLeft()

The following examples show how to use com.google.gwt.dom.client.Element#getAbsoluteLeft() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 6 votes vote down vote up
/**
 * Get the horizontal drop location in an ordered layout
 * 
 * @param element
 *            The target element or cell
 * @param clientX
 *            The x-coordinate of the drop
 * @param leftRightRatio
 *            The ratio of how the cell has been divided
 * @return the drop location relative to the cell
 */
public static HorizontalDropLocation getHorizontalDropLocation(
        Element element, int clientX, double leftRightRatio) {

    int absoluteLeft = element.getAbsoluteLeft();
    int offsetWidth = element.getOffsetWidth();
    int fromTop = clientX - absoluteLeft;

    float percentageFromTop = (fromTop / (float) offsetWidth);
    if (percentageFromTop < leftRightRatio) {
        return HorizontalDropLocation.LEFT;
    } else if (percentageFromTop > 1 - leftRightRatio) {
        return HorizontalDropLocation.RIGHT;
    } else {
        return HorizontalDropLocation.CENTER;
    }
}
 
Example 2
Source File: Scrolling.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
public static void scrollTo(Rectangle rect, Element element) {
  rect = rect.intersect(new Rectangle(0, 0, element.getScrollWidth(), element.getScrollHeight()));

  adjustScrollers(rect, element);
  Rectangle visibleArea = new Rectangle(getScrollX(), getScrollY(), getScrollWidth(), getScrollHeight());
  Rectangle elementBounds = getBounds(element);
  Rectangle bounds = new Rectangle(elementBounds.origin.add(rect.origin), rect.dimension);
  if (!visibleArea.contains(bounds)) {    // are we sure about this?
    int top = element.getAbsoluteTop() + rect.origin.y;
    int left = element.getAbsoluteLeft() + rect.origin.x;
    int width = rect.dimension.x;
    int height = rect.dimension.y;

    int winTop = getScrollY();
    int winLeft = getScrollX();
    int winWidth = getScrollWidth();
    int winHeigh = getScrollHeight();

    int deltaX = getScrollAdjustment(new Interval(winLeft, winLeft + winWidth), new Interval(left, left + width), winLeft);
    int deltaY = getScrollAdjustment(new Interval(winTop, winTop + winHeigh), new Interval(top, top + height), winTop);

    if (deltaX != 0 || deltaY != 0) {
      Window.scrollTo(winLeft + deltaX, winTop + deltaY);
    }
  }
}
 
Example 3
Source File: TDialog.java    From openchemlib-js with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public DialogResult doModalAt(final double x, final double y) {
  final Element element = getElementFromPoint((int) x, (int) y);
  if (element != null) {
    final int left = element.getAbsoluteLeft();
    final int top = element.getAbsoluteTop();

    onInitialUpdate();
    setPopupPositionAndShow(new PositionCallback() {

      @Override
      public void setPosition(int offsetWidth, int offsetHeight) {
        setPopupPosition(left + (element.getOffsetWidth() - offsetWidth) / 2,
            Math.max(top, top + (element.getOffsetHeight() - offsetHeight) / 2));

      }
    });
    setStyles();
    return DialogResult.IDOK;
  }
  return DialogResult.IDABORT;
}
 
Example 4
Source File: SimpleDropdown.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void open() {
	StyleUtils.addStyle(this, SimpleDropdown.STYLE_OPEN);
	Element menuElt = this.menuContainer.getElement();
	int topMenu = menuElt.getAbsoluteTop() - Window.getScrollTop();
	int menuHeight = menuElt.getOffsetHeight();
	int anchorHeight = this.anchor.getOffsetHeight();
	int clientHeight = Window.getClientHeight();
	if (topMenu + menuHeight > clientHeight && topMenu >= anchorHeight + menuHeight) {
		StyleUtils.addStyle(this, SimpleDropdown.STYLE_OPEN_UP);
	}
	int leftMenu = menuElt.getAbsoluteLeft() - Window.getScrollLeft();
	int menuWidth = menuElt.getOffsetWidth();
	int anchorWidth = this.anchor.getOffsetWidth();
	int clientWidth = Window.getClientWidth();
	if (leftMenu + menuWidth > clientWidth && leftMenu >= anchorWidth + menuWidth) {
		StyleUtils.addStyle(this, SimpleDropdown.STYLE_OPEN_LEFT);
	}
	this.open = true;
	this.updateHandlers();
}
 
Example 5
Source File: MaterialCutOut.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Setups the cut out position when the screen changes size or is scrolled.
 */
protected void setupCutOutPosition(Element cutOut, Element relativeTo, int padding, boolean circle) {
    float top = relativeTo.getOffsetTop() - (Math.max($("html").scrollTop(), $("body").scrollTop()));
    float left = relativeTo.getAbsoluteLeft();

    float width = relativeTo.getOffsetWidth();
    float height = relativeTo.getOffsetHeight();

    if (circle) {
        if (width != height) {
            float dif = width - height;
            if (width > height) {
                height += dif;
                top -= dif / 2;
            } else {
                dif = -dif;
                width += dif;
                left -= dif / 2;
            }
        }
    }

    top -= padding;
    left -= padding;
    width += padding * 2;
    height += padding * 2;

    $(cutOut).css("top", top + "px");
    $(cutOut).css("left", left + "px");
    $(cutOut).css("width", width + "px");
    $(cutOut).css("height", height + "px");
}
 
Example 6
Source File: OffsetPosition.java    From swellrt with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the position of target relative to a specified element.
 * @param target
 * @param relative
 */
public static OffsetPosition getRelativePosition(OffsetPosition target, Element relative) {
  int parentLeft = 0;
  int parentTop = 0;
  if (target.offsetParent != null) {
    parentLeft = target.offsetParent.getAbsoluteLeft();
    parentTop = target.offsetParent.getAbsoluteTop();
  }
  int left = parentLeft + target.left - relative.getAbsoluteLeft();
  int top =  parentTop + target.top - relative.getAbsoluteTop();
  return new OffsetPosition(left, top, relative);
}
 
Example 7
Source File: VSliderPanel.java    From vaadin-sliderpanel with MIT License 5 votes vote down vote up
/**
 * checks whether the event come's from a elements that lays visually within the slider<br>
 * it doesn't lay directly in the dom tree - for example dropdown popups
 * 
 * @param event NativeEvent
 * @return true when events comes from within
 */
private boolean eventTargetsInnerElementsPopover(NativeEvent event) {
    EventTarget target = event.getEventTarget();
    if (Element.is(target)) {
        Element targetElement = Element.as(target);

        int absoluteLeft = targetElement.getAbsoluteLeft();
        int absoluteTop = targetElement.getAbsoluteTop();
        
        return contentNode.getAbsoluteLeft() <= absoluteLeft && contentNode.getAbsoluteRight() >= absoluteLeft && contentNode.getAbsoluteTop() <= absoluteTop
                && contentNode.getAbsoluteBottom() >= absoluteTop;
    }
    return false;
}
 
Example 8
Source File: OffsetPosition.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the position of target relative to a specified element.
 * @param target
 * @param relative
 */
public static OffsetPosition getRelativePosition(OffsetPosition target, Element relative) {
  int parentLeft = 0;
  int parentTop = 0;
  if (target.offsetParent != null) {
    parentLeft = target.offsetParent.getAbsoluteLeft();
    parentTop = target.offsetParent.getAbsoluteTop();
  }
  int left = parentLeft + target.left - relative.getAbsoluteLeft();
  int top =  parentTop + target.top - relative.getAbsoluteTop();
  return new OffsetPosition(left, top, relative);
}
 
Example 9
Source File: VLayoutDragDropMouseHandler.java    From cuba with Apache License 2.0 5 votes vote down vote up
private boolean isEventOnScrollBar(NativeEvent event) {
    Element element = Element.as(event.getEventTarget());
    ;

    if (WidgetUtil.mayHaveScrollBars(element)) {

        final int nativeScrollbarSize = WidgetUtil.getNativeScrollbarSize();

        int x = WidgetUtil.getTouchOrMouseClientX(event)
                - element.getAbsoluteLeft();
        int y = WidgetUtil.getTouchOrMouseClientY(event)
                - element.getAbsoluteTop();

        // Hopefully we have horizontal scroll.
        final int scrollWidth = element.getScrollWidth();
        final int clientWidth = element.getClientWidth();
        if (scrollWidth > clientWidth
                && clientWidth - nativeScrollbarSize < x) {
            return true;
        }

        // Hopefully we have vertical scroll.
        final int scrollHeight = element.getScrollHeight();
        final int clientHeight = element.getClientHeight();
        if (scrollHeight > clientHeight
                && clientHeight - nativeScrollbarSize < y) {
            return true;
        }

    }

    return false;
}
 
Example 10
Source File: Scrolling.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
private static Rectangle getBounds(Element element) {
  int x = element.getAbsoluteLeft();
  int y = element.getAbsoluteTop();
  int width = element.getScrollWidth();
  int height = element.getScrollHeight();
  return new Rectangle(x, y, width, height);
}
 
Example 11
Source File: Scrolling.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
private static void adjustScrollers(Rectangle rect, Element element) {
  int left = element.getAbsoluteLeft() + rect.origin.x;
  int top = element.getAbsoluteTop() + rect.origin.y;
  int width = rect.dimension.x;
  int height = rect.dimension.y;

  while (element.getParentElement() != null) {
    Element parent = element.getParentElement();

    String overflow = $(parent).css("overflow");
    if ("scroll".equals(overflow) || "auto".equals(overflow)) {
      int scrollTop = parent.getScrollTop();
      int parentTop = parent.getAbsoluteTop();
      int parentHeight = parent.getClientHeight();
      int scrollLeft = parent.getScrollLeft();
      int parentLeft = parent.getAbsoluteLeft();
      int parentWidth = parent.getClientWidth();

      int deltaX = getScrollAdjustment(new Interval(parentLeft, parentLeft + parentWidth), new Interval(left, left + width), scrollLeft);
      if (deltaX != 0) {
        parent.setScrollLeft(scrollLeft + deltaX);
        left -= deltaX;
      }
      int deltaY = getDelta(new Interval(parentTop, parentTop + parentHeight), new Interval(top, top + height));
      if (deltaY != 0) {
        parent.setScrollTop(scrollTop + deltaY);
        top -= deltaY;
      }
    }

    element = parent;
  }
}
 
Example 12
Source File: MeasurerInstance.java    From swellrt with Apache License 2.0 4 votes vote down vote up
@Override
public double left(Element base, Element e) {
  return e.getAbsoluteLeft() - (base != null ? base.getAbsoluteLeft() : 0);
}
 
Example 13
Source File: Geometry.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
public static final int getX(Element e) {
    return e.getAbsoluteLeft();
}
 
Example 14
Source File: GanttWidget.java    From gantt with Apache License 2.0 4 votes vote down vote up
private boolean isResizingLeft(Element bar) {
    if (movePoint.getX() <= (bar.getAbsoluteLeft() + RESIZE_WIDTH)) {
        return true;
    }
    return false;
}
 
Example 15
Source File: MeasurerInstance.java    From incubator-retired-wave with Apache License 2.0 4 votes vote down vote up
@Override
public double left(Element base, Element e) {
  return e.getAbsoluteLeft() - (base != null ? base.getAbsoluteLeft() : 0);
}
 
Example 16
Source File: FinderColumn.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void openTopContextMenu(Element anchor, final NativeEvent event) {

        Element el = Element.as(event.getEventTarget());
        //Element anchor = el.getParentElement().getParentElement();

        final PopupPanel popupPanel = new PopupPanel(true);
        final MenuBar popupMenuBar = new MenuBar(true);
        popupMenuBar.setStyleName("dropdown-menu");

        int i=0;
        for (final MenuDelegate menuitem : accessibleTopMenuItems) {

            if(i>0) {     // skip the "default" action
                MenuItem cmd = new MenuItem(menuitem.getTitle(), true, new Command() {

                    @Override
                    public void execute() {
                        Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                            @Override
                            public void execute() {
                                menuitem.getCommand().executeOn(null);
                            }
                        });

                        popupPanel.hide();
                    }

                });

                popupMenuBar.addItem(cmd);
            }
            i++;
        }

        popupMenuBar.setVisible(true);


        popupPanel.setWidget(popupMenuBar);
        int left = anchor.getAbsoluteLeft();
        int top = anchor.getAbsoluteTop() + 30;

        popupPanel.setPopupPosition(left, top);
        popupPanel.setAutoHideEnabled(true);
        popupPanel.show();
    }
 
Example 17
Source File: VDragDropUtil.java    From cuba with Apache License 2.0 2 votes vote down vote up
/**
 * Measures the left margin of an element
 * 
 * @param element
 *            The element to measure
 * @return Left margin in pixels
 */
public static int measureMarginLeft(Element element) {
    return element.getAbsoluteLeft()
            - element.getParentElement().getAbsoluteLeft();
}