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

The following examples show how to use com.google.gwt.dom.client.Element#getStyle() . 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: CellContainerToDomMapper.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
private void refreshLineHighlight() {
  if (myLineHighlightUpToDate || !isAttached()) return;
  Cell current = getSource().focusedCell.get();
  for (Element e : Arrays.asList(myLineHighlight1, myLineHighlight2)) {
    Style style = e.getStyle();
    if (current == null || !Cells.isLeaf(current)) {
      style.setVisibility(Style.Visibility.HIDDEN);
    } else {
      int deltaTop = myContent.getAbsoluteTop() - getTarget().getAbsoluteTop();
      style.setVisibility(Style.Visibility.VISIBLE);
      int rootTop = myContent.getAbsoluteTop();
      final Element currentElement = getElement(current);
      int currentTop = currentElement.getAbsoluteTop();
      style.setTop(currentTop - rootTop + deltaTop, Style.Unit.PX);
      style.setHeight(currentElement.getClientHeight(), Style.Unit.PX);
      if (e == myLineHighlight2) {
        style.setWidth(0, Style.Unit.PX);
        style.setWidth(getTarget().getScrollWidth(), Style.Unit.PX);
      }
    }
  }
  myLineHighlightUpToDate = true;
}
 
Example 2
Source File: CubaGridLayoutSlot.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected int getButtonHeight(CubaButtonWidget widget) {
    Element element = widget.getElement();
    if (!element.hasClassName("link")) {
        return getWidgetHeight(widget);
    }

    Element captionElement = findLinkButtonCaptionElement(element);
    if (captionElement == null) {
        return getWidgetHeight(widget);
    }
    // The LinkButton component has an ability to wrap caption onto multiple rows.
    // Thus, at the first recalculation of the heights for the slots, the "getWidgetHeight()" call
    // returns an invalid multiline component height.
    // In order to calculate the really required caption height, regardless of the 'white-space' mode,
    // we need to explicitly set it to 'nowrap'. After calculation, it's reverted back.
    Style style = captionElement.getStyle();
    String prevWhiteSpace = style.getWhiteSpace();
    style.setWhiteSpace(Style.WhiteSpace.NOWRAP);
    int buttonHeight = element.getOffsetHeight();

    if (prevWhiteSpace != null && !prevWhiteSpace.isEmpty()) {
        style.setWhiteSpace(Style.WhiteSpace.valueOf(prevWhiteSpace));
    } else {
        style.clearWhiteSpace();
    }

    return buttonHeight;
}
 
Example 3
Source File: CubaFileUploadProgressWindow.java    From cuba with Apache License 2.0 5 votes vote down vote up
private void fixIE8FocusCaptureIssue() {
    Element e = DOM.createInputText();
    Style elemStyle = e.getStyle();
    elemStyle.setPosition(Style.Position.ABSOLUTE);
    elemStyle.setTop(-10, Style.Unit.PX);
    elemStyle.setWidth(0, Style.Unit.PX);
    elemStyle.setHeight(0, Style.Unit.PX);

    contentPanel.getElement().appendChild(e);
    e.focus();
    contentPanel.getElement().removeChild(e);
}
 
Example 4
Source File: InteractiveSuggestionsManager.java    From swellrt with Apache License 2.0 5 votes vote down vote up
@Override
public void setPopupPositionAndMakeVisible(Element reference, final Element popup) {
  Style popupStyle = popup.getStyle();

  // TODO(danilatos): Do something more intelligent than arbitrary constants (which might be
  // susceptible to font size changes, etc)
  popupStyle.setLeft(popupAnchor.getAbsoluteLeft() - popup.getOffsetWidth() + 26, Unit.PX);
  popupStyle.setTop(popupAnchor.getAbsoluteBottom() + 5, Unit.PX);

  popupStyle.setVisibility(Visibility.VISIBLE);
}
 
Example 5
Source File: DiffHighlightingFilter.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private void applyAnnotationsToElement(Element element, ReadableStringMap<Object> annotations) {
  final Style style = element.getStyle();
  annotations.each(new ReadableStringMap.ProcV<Object>() {
    @Override
    public void apply(String key, Object value) {
      if (value != null && value instanceof String) {
        String styleValue = (String) value;
        if (!styleValue.isEmpty()) {
          style.setProperty(StyleAnnotationHandler.suffix(key), styleValue);
        }
      }
    }
  });
}
 
Example 6
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 7
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 8
Source File: Affix.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void toggleAffix(Affixed affix) {
	Element e = this.getElement();
	Style style = e.getStyle();

	if (this.affixed != affix) {
		this.clearElementStyle();
		this.affixed = affix;
		StyleUtils.addStyle(e, this.affixed);
	}

	switch (affix) {
		case AFFIX:
			style.setTop(this.offsetTop, Unit.PX);
			style.setWidth(this.offsetWidth, Unit.PX);
			style.setHeight(this.offsetHeight, Unit.PX);
			style.setZIndex(this.layerIndex);
			e.getParentElement().getStyle().setPaddingTop(this.offsetHeight, Unit.PX);
			break;
		case BOTTOM:
			int docHeigth = Document.get().getScrollHeight();
			int scrollTop = Window.getScrollTop();

			int bottom = this.offsetBottom - (docHeigth - scrollTop - this.clientHeigth);
			if (this.fixBottom != Integer.MIN_VALUE) {
				bottom = Math.max(bottom, this.fixBottom);
			}
			style.setPosition(Position.FIXED);
			style.setBottom(bottom, Unit.PX);
			style.setWidth(this.offsetWidth, Unit.PX);
			style.setHeight(this.offsetHeight, Unit.PX);
			style.setZIndex(this.layerIndex);
			break;
		default:
			break;
	}
}
 
Example 9
Source File: Affix.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void clearElementStyle() {
	Element e = this.getElement();
	Style style = e.getStyle();

	style.clearPosition();
	style.clearTop();
	style.clearBottom();
	style.clearWidth();
	style.clearHeight();
	style.clearZIndex();
	e.getParentElement().getStyle().clearPaddingTop();
}
 
Example 10
Source File: InteractiveSuggestionsManager.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
@Override
public void setPopupPositionAndMakeVisible(Element reference, final Element popup) {
  Style popupStyle = popup.getStyle();

  // TODO(danilatos): Do something more intelligent than arbitrary constants (which might be
  // susceptible to font size changes, etc)
  popupStyle.setLeft(popupAnchor.getAbsoluteLeft() - popup.getOffsetWidth() + 26, Unit.PX);
  popupStyle.setTop(popupAnchor.getAbsoluteBottom() + 5, Unit.PX);

  popupStyle.setVisibility(Visibility.VISIBLE);
}
 
Example 11
Source File: DiffHighlightingFilter.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void applyAnnotationsToElement(Element element, ReadableStringMap<Object> annotations) {
  final Style style = element.getStyle();
  annotations.each(new ReadableStringMap.ProcV<Object>() {
    @Override
    public void apply(String key, Object value) {
      if (value != null && value instanceof String) {
        String styleValue = (String) value;
        if (!styleValue.isEmpty()) {
          style.setProperty(StyleAnnotationHandler.suffix(key), styleValue);
        }
      }
    }
  });
}
 
Example 12
Source File: BaseViewMapper.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
protected Element createSVG() {
  Element result = SvgUtil.createSvgElement("svg");
  //without setting absolute position svg element might move down for unknown reason
  Style style = result.getStyle();
  style.setPosition(Style.Position.ABSOLUTE);
  style.setLeft(0, Style.Unit.PX);
  style.setTop(0, Style.Unit.PX);
  return result;
}
 
Example 13
Source File: DomTextEditor.java    From jetpad-projectional-open-source with Apache License 2.0 5 votes vote down vote up
public DomTextEditor(Element root) {
  myRoot = root;

  Style rootStyle = myRoot.getStyle();
  rootStyle.setPosition(Style.Position.RELATIVE);

  myTextContainer = DOM.createSpan();
  Style textStyle = myTextContainer.getStyle();
  textStyle.setZIndex(10);
  textStyle.setWhiteSpace(Style.WhiteSpace.NOWRAP);
  myRoot.appendChild(myTextContainer);

  Element caretDiv = DOM.createDiv();
  Style caretStyle = caretDiv.getStyle();
  caretStyle.setPosition(Style.Position.ABSOLUTE);
  caretStyle.setZIndex(10);
  myRoot.appendChild(caretDiv);
  myCaretDiv = caretDiv;

  Element selectionDiv = DOM.createDiv();
  Style selectionStyle = selectionDiv.getStyle();
  selectionStyle.setPosition(Style.Position.ABSOLUTE);
  selectionStyle.setZIndex(1);
  myRoot.appendChild(selectionDiv);
  mySelectionDiv = selectionDiv;

  update();
  updateCaretVisibility();
  updateSelectionVisibility();
  updateCaretAndSelection();
}
 
Example 14
Source File: Geometry.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
public static final void setInvisibleToMeasure(Element e) {
    Style s = e.getStyle();
    s.setProperty("visibility", "hidden");
    s.setProperty("display", "block");
}
 
Example 15
Source File: Geometry.java    From gwt-traction with Apache License 2.0 4 votes vote down vote up
public static final void unsetInvisibleToMeasure(Element e) {
    Style s = e.getStyle();
    s.setProperty("display", "none");
    s.setProperty("visibility", "");
}
 
Example 16
Source File: PopupPositioner.java    From jetpad-projectional-open-source with Apache License 2.0 4 votes vote down vote up
private void setPosition(Element child, int left, int top) {
  Style style = child.getStyle();
  style.setLeft(left - myContext.rootElement.getAbsoluteLeft(), Style.Unit.PX);
  style.setTop(top - myContext.rootElement.getAbsoluteTop(), Style.Unit.PX);
}