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

The following examples show how to use com.google.gwt.dom.client.Element#getOffsetWidth() . 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: 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 3
Source File: ArrowPositionData.java    From gantt with Apache License 2.0 6 votes vote down vote up
public ArrowPositionData(Element from, Element to) {
    this.from = from;
    this.to = to;

    predecessorHeightCenter = from.getOffsetHeight() / 2;
    predecessorTop = from.getOffsetTop();
    predecesorBottom = from.getOffsetTop() + from.getOffsetHeight();
    predecessorRight = from.getOffsetLeft() + from.getOffsetWidth();
    predecessorLeft = from.getOffsetLeft();
    thisBottom = to.getOffsetTop() + to.getOffsetHeight();
    thisCenter = to.getOffsetHeight() / 2;

    top = Math.min(predecessorTop, to.getOffsetTop());
    bottom = Math.max(predecesorBottom, thisBottom);
    height = bottom - top;

    left = Math.min(predecessorRight, to.getOffsetLeft());
    right = Math.max(predecessorRight, to.getOffsetLeft());
    width = right - left;

    fromTop = predecessorTop <= to.getOffsetTop();
    fromLeft = predecessorRight <= to.getOffsetLeft();
    halfWidth = (int) width / 2;
}
 
Example 4
Source File: CubaSuggestionFieldWidget.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setPosition(int offsetWidth, int offsetHeight) {
    // CAUTION: offsetWidth and offsetHeight are ignored because we measure width/height after show

    offsetHeight = getOffsetHeight();

    if (popupOuterPadding == -1) {
        popupOuterPadding = WidgetUtil.measureHorizontalPaddingAndBorder(getElement(), 2);
    }

    int top;
    int left;

    if (offsetHeight + getPopupTop() > Window.getClientHeight() + Window.getScrollTop()) {
        top = getPopupTop() - offsetHeight - textField.getOffsetHeight();
        if (top < 0) {
            top = 0;
        }
    } else {
        top = getPopupTop();
        int topMargin = (top - topPosition);
        top -= topMargin;
    }

    Widget popup = getWidget();
    Element containerFirstChild = popup.getElement().getFirstChild().cast();
    final int textFieldWidth = textField.getOffsetWidth();

    offsetWidth = containerFirstChild.getOffsetWidth();
    if (offsetWidth + getPopupLeft() > Window.getClientWidth() + Window.getScrollLeft()) {
        left = textField.getAbsoluteLeft() + textFieldWidth + Window.getScrollLeft() - offsetWidth;
        if (left < 0) {
            left = 0;
        }
    } else {
        left = getPopupLeft();
    }

    setPopupPosition(left, top);
}
 
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: DesktopUniversalPopup.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public void hide() {
  // nothing to do if we are already invisible
  if (!showing) {
    return;
  }

  final Element clone = (Element)getElement().cloneNode(true);
  RootPanel.getBodyElement().appendChild(clone);
  showing = false;
  if (isMaskEnabled) {
    setMaskVisible(false);
  }
  RootPanel.get().remove(DesktopUniversalPopup.this);
  if (shouldAutoHide) {
    deregisterAutoHider();
  }

  // trigger fade-out
  clone.removeClassName(Resources.INSTANCE.css().fadeIn());
  clone.addClassName(Resources.INSTANCE.css().fadeOut());
  clone.getOffsetWidth(); // Force update
  clone.getStyle().setOpacity(0.0);


  // schedule removal of clone from DOM once animation complete
  new ScheduleTimer() {
    @Override
    public void run() {
      clone.removeFromParent();
    }
  }.schedule(DEFAULT_REMOVE_MS);

  // fire popup event listeners
  for (PopupEventListener listener : listeners) {
    listener.onHide(DesktopUniversalPopup.this);
  }
}
 
Example 7
Source File: Geometry.java    From gwt-traction with Apache License 2.0 5 votes vote down vote up
/**
 * Updated to factor in border and padding
 */
public static final int getW(Element e) {
    int ret = e.getOffsetWidth();
    ret -= MiscUtils.getComputedStyleInt(e, "paddingLeft");
    ret -= MiscUtils.getComputedStyleInt(e, "paddingRight");
    ret -= MiscUtils.getComputedStyleInt(e, "borderLeftWidth");
    ret -= MiscUtils.getComputedStyleInt(e, "borderRightWidth");
    return Math.max(ret, 0);
}
 
Example 8
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void popup(Widget container, Widget relativeTo) {
	this.setVisible(true);
	StyleUtils.addStyle(this, InputDatePicker.STYLE_POPUP);
	RootPanel.get().add(this);

	Element positioningElement = this.getElement();
	Element relativeElement = relativeTo.getElement();

	int targetHeight = relativeElement.getOffsetHeight();
	int targetTop = relativeElement.getAbsoluteTop();

	int positioningWidth = positioningElement.getOffsetWidth();
	int targetRight = relativeElement.getAbsoluteRight();

	Style elementStyle = positioningElement.getStyle();
	elementStyle.setPosition(Position.ABSOLUTE);
	elementStyle.setLeft(targetRight - positioningWidth, Unit.PX);
	elementStyle.setTop(targetTop + targetHeight, Unit.PX);

	StyleUtils.addStyle(this, InputDatePicker.STYLE_FADE);
	StyleUtils.addStyle(this, InputDatePicker.STYLE_SHOW);

	this.setFocus(true);

	if (this.popupBlurHandler == null) {
		this.popupBlurHandler = this.addBlurHandler(new BlurHandler() {

			@Override
			public void onBlur(BlurEvent event) {
				InputDatePicker.this.hide();
			}
		});
	}
}
 
Example 9
Source File: AbstractHover.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void resetPosition(Element toPositionedElement, Widget relativeTo, Placement placement) {
	Element relativeElement = relativeTo.getElement();

	com.google.gwt.dom.client.Style elementStyle = toPositionedElement.getStyle();
	int tooltipWidth = toPositionedElement.getOffsetWidth();
	int tooltipHeight = toPositionedElement.getOffsetHeight();

	int targetWidth = relativeElement.getOffsetWidth();
	int targetHeight = relativeElement.getOffsetHeight();
	int targetTop = relativeElement.getOffsetTop();
	int targetLeft = relativeElement.getOffsetLeft();

	elementStyle.setPosition(Position.ABSOLUTE);
	switch (placement) {
		case TOP:
			elementStyle.setLeft(targetLeft + targetWidth / 2 - tooltipWidth / 2, Unit.PX);
			elementStyle.setTop(targetTop - tooltipHeight, Unit.PX);
			break;
		case BOTTOM:
			elementStyle.setLeft(targetLeft + targetWidth / 2 - tooltipWidth / 2, Unit.PX);
			elementStyle.setTop(targetTop + targetHeight, Unit.PX);
			break;
		case LEFT:
			elementStyle.setLeft(targetLeft - tooltipWidth, Unit.PX);
			elementStyle.setTop(targetTop + targetHeight / 2 - tooltipHeight / 2, Unit.PX);
			break;
		case RIGHT:
			elementStyle.setLeft(targetLeft + targetWidth, Unit.PX);
			elementStyle.setTop(targetTop + targetHeight / 2 - tooltipHeight / 2, Unit.PX);
			break;
		default:
			break;
	}
}
 
Example 10
Source File: DesktopUniversalPopup.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void hide() {
  // nothing to do if we are already invisible
  if (!showing) {
    return;
  }

  final Element clone = (Element)getElement().cloneNode(true);
  RootPanel.getBodyElement().appendChild(clone);
  showing = false;
  if (isMaskEnabled) {
    setMaskVisible(false);
  }
  RootPanel.get().remove(DesktopUniversalPopup.this);
  if (shouldAutoHide) {
    deregisterAutoHider();
  }

  // trigger fade-out
  clone.removeClassName(Resources.INSTANCE.css().fadeIn());
  clone.addClassName(Resources.INSTANCE.css().fadeOut());
  clone.getOffsetWidth(); // Force update
  clone.getStyle().setOpacity(0.0);


  // schedule removal of clone from DOM once animation complete
  new ScheduleTimer() {
    @Override
    public void run() {
      clone.removeFromParent();
    }
  }.schedule(DEFAULT_REMOVE_MS);

  // fire popup event listeners
  for (PopupEventListener listener : listeners) {
    listener.onHide(DesktopUniversalPopup.this);
  }
}