Java Code Examples for com.google.gwt.dom.client.Style#setTop()

The following examples show how to use com.google.gwt.dom.client.Style#setTop() . 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: Scrollbar.java    From djvu-html5 with GNU General Public License v2.0 6 votes vote down vote up
public void setThumb(double center, double width) {
	Style style = getElement().getStyle();
	if (width >= 1) {
		style.setVisibility(Visibility.HIDDEN);
		return;
	} else {
		style.setVisibility(Visibility.VISIBLE);
	}
	if (isHorizontal) {
		style.setLeft(100 * (center - width / 2), Unit.PCT);
		style.setRight(100 * (1 - center - width / 2), Unit.PCT);
	} else {
		style.setTop(100.0 * (center - width / 2), Unit.PCT);
		style.setBottom(100 * (1 - center - width / 2), Unit.PCT);
	}
}
 
Example 2
Source File: DomTextEditor.java    From jetpad-projectional-open-source with Apache License 2.0 6 votes vote down vote up
private void updateCaretAndSelection() {
  Style caretStyle = myCaretDiv.getStyle();
  updateCaretPosition();
  caretStyle.setTop(0, Style.Unit.PX);
  caretStyle.setWidth(1, Style.Unit.PX);
  caretStyle.setHeight(getLineHeight(), Style.Unit.PX);
  caretStyle.setBackgroundColor("black");

  Style selectionStyle = mySelectionDiv.getStyle();
  selectionStyle.setTop(0, Style.Unit.PX);
  selectionStyle.setHeight(getLineHeight(), Style.Unit.PX);
  selectionStyle.setBackgroundColor("Highlight");
  selectionStyle.setColor("HighlightText");

  updateSelectionBoundsAndText();
}
 
Example 3
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 4
Source File: MaterialCutOut.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
protected void setCutOutStyle() {
    Style style = getElement().getStyle();
    style.setWidth(100, Unit.PCT);
    style.setHeight(100, Unit.PCT);
    style.setPosition(Position.FIXED);
    style.setTop(0, Unit.PX);
    style.setLeft(0, Unit.PX);
    style.setZIndex(10000);

    focusElement.setClassName(AddinsCssName.MATERIAL_CUTOUT_FOCUS);
    style = focusElement.getStyle();
    style.setProperty("content", "\'\'");
    style.setPosition(Position.ABSOLUTE);
    style.setZIndex(-1);
}
 
Example 5
Source File: MaterialCutOut.java    From gwt-material-addins with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the computed background color, based on the backgroundColor CSS
 * class.
 */
protected void setupComputedBackgroundColor() {
    // temp is just a widget created to evaluate the computed background
    // color
    MaterialWidget temp = new MaterialWidget(Document.get().createDivElement());
    temp.setBackgroundColor(backgroundColor);

    // setting a style to make it invisible for the user
    Style style = temp.getElement().getStyle();
    style.setPosition(Position.FIXED);
    style.setWidth(1, Unit.PX);
    style.setHeight(1, Unit.PX);
    style.setLeft(-10, Unit.PX);
    style.setTop(-10, Unit.PX);
    style.setZIndex(-10000);

    // adding it to the body (on Chrome the component must be added to the
    // DOM before getting computed values).
    String computed = ColorHelper.setupComputedBackgroundColor(backgroundColor);

    // convert rgb to rgba, considering the opacity field
    if (opacity < 1 && computed.startsWith("rgb(")) {
        computed = computed.replace("rgb(", "rgba(").replace(")", ", " + opacity + ")");
    }

    computedBackgroundColor = computed;
}
 
Example 6
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 7
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 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: 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 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: 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 12
Source File: VDDGridLayout.java    From cuba with Apache License 2.0 5 votes vote down vote up
/**
 * Emphasizes a component container when user is hovering a dragged
 * component over the container.
 * 
 * @param cell
 *            The container
 * @param event
 */
protected void emphasis(CellDetails cell, VDragEvent event) {

    Style shadowStyle = dragShadow.getElement().getStyle();
    shadowStyle.setPosition(Position.ABSOLUTE);
    shadowStyle.setWidth(cell.width, Unit.PX);
    shadowStyle.setHeight(cell.height, Unit.PX);
    shadowStyle.setLeft(cell.x, Unit.PX);
    shadowStyle.setTop(cell.y, Unit.PX);

    // Remove any existing empasis
    deEmphasis();

    // Ensure we are not dragging ourself into ourself
    ComponentConnector draggedConnector = (ComponentConnector) event
            .getTransferable()
            .getData(Constants.TRANSFERABLE_DETAIL_COMPONENT);

    if (draggedConnector != null
            && draggedConnector.getWidget() == VDDGridLayout.this) {
        return;
    }

    HorizontalDropLocation hl = getHorizontalDropLocation(cell, event);
    VerticalDropLocation vl = getVerticalDropLocation(cell, event);

    // Apply over style
    setStyleName(dragShadow.getElement(), OVER, true);

    // Add vertical location dependent style
    setStyleName(dragShadow.getElement(),
            OVER + "-" + vl.toString().toLowerCase(), true);

    // Add horizontal location dependent style
    setStyleName(dragShadow.getElement(),
            OVER + "-" + hl.toString().toLowerCase(), true);

}
 
Example 13
Source File: IframeCoverUtility.java    From cuba with Apache License 2.0 4 votes vote down vote up
/**
 * Adds an iframe cover over an Embedded component
 * 
 * @param iframe
 *            The iframe element
 * @return The element which covers the iframe
 */
private static Element addIframeCover(Element iframe) {
    if (iframeCoverMap.containsKey(iframe)) {
        return iframeCoverMap.get(iframe);
    }

    // Get dimensions
    String iframeWidth = iframe.getAttribute("width");
    String iframeHeight = iframe.getAttribute("height");

    Style iframeStyle = iframe.getStyle();

    if (!iframeWidth.equals("") && !iframeHeight.equals("")) {
        iframeStyle.setPosition(Position.ABSOLUTE);
        iframeStyle.setTop(0, Unit.PX);
        iframeStyle.setLeft(0, Unit.PX);
    }

    // Create the cover element
    Element coverContainer = DOM.createDiv();
    DOM.setStyleAttribute(coverContainer, "width", iframeWidth);
    DOM.setStyleAttribute(coverContainer, "height", iframeHeight);

    coverContainer.setClassName("v-dragdrop-iframe-container");
    coverContainer.getStyle().setPosition(Position.RELATIVE);
    iframe.getParentElement().appendChild(coverContainer);

    // Move iframe to cover container
    iframe.getParentElement().replaceChild(coverContainer, iframe);
    coverContainer.appendChild(iframe);

    // Style the cover
    Element cover = DOM.createDiv();
    cover.setClassName(SHIM_STYLENAME);
    Style coverStyle = cover.getStyle();
    coverStyle.setPosition(Position.ABSOLUTE);
    coverStyle.setWidth(100, Unit.PCT);
    coverStyle.setHeight(100, Unit.PCT);
    coverStyle.setTop(0, Unit.PX);
    coverStyle.setLeft(0, Unit.PX);

    coverContainer.appendChild(cover);

    iframeCoverMap.put(iframe, coverContainer);

    return coverContainer;
}
 
Example 14
Source File: CubaVerticalSplitPanelWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void updateDockButtonPosition() {
    if (isDockable()) {

        Style dockButtonStyle = dockButtonContainer.getStyle();
        if (dockMode == SplitPanelDockMode.TOP) {
            int top = splitter.getOffsetTop();
            if (top > BUTTON_HEIGHT_SPACE) {
                dockButtonStyle.setTop(top - (dockButton.getOffsetHeight() - getSplitterSize()), Style.Unit.PX);
                dockButtonStyle.setLeft(getDockBtnContainerHorizontalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.DOWN) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_UP, SP_DOCK_BUTTON_DOWN);
                    dockButtonState = DockButtonState.UP;
                }

                updateSplitPanelStyle(SP_DOCKABLE_UP, SP_DOCKABLE_DOWN);
            } else {
                dockButtonStyle.setTop(top, Style.Unit.PX);
                dockButtonStyle.setLeft(getDockBtnContainerHorizontalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.UP) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_DOWN, SP_DOCK_BUTTON_UP);
                    dockButtonState = DockButtonState.DOWN;
                }

                updateSplitPanelStyle(SP_DOCKABLE_DOWN, SP_DOCKABLE_UP);
            }
        } else if (dockMode == SplitPanelDockMode.BOTTOM) {
            int down = splitter.getOffsetTop() + splitter.getOffsetHeight();
            int splitBottomPosition = getAbsoluteBottom();

            if (down < splitBottomPosition - BUTTON_HEIGHT_SPACE) {
                dockButtonStyle.setTop(down - getSplitterSize(), Style.Unit.PX);
                dockButtonStyle.setLeft(getDockBtnContainerHorizontalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.UP) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_DOWN, SP_DOCK_BUTTON_UP);
                    dockButtonState = DockButtonState.DOWN;
                }

                updateSplitPanelStyle(SP_DOCKABLE_DOWN, SP_DOCKABLE_UP);
            } else {
                dockButtonStyle.setTop(down - (dockButton.getOffsetHeight()), Style.Unit.PX);
                dockButtonStyle.setLeft(getDockBtnContainerHorizontalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.DOWN) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_UP, SP_DOCK_BUTTON_DOWN);
                    dockButtonState = DockButtonState.UP;
                }

                updateSplitPanelStyle(SP_DOCKABLE_UP, SP_DOCKABLE_DOWN);
            }
        }
    }
}
 
Example 15
Source File: CubaHorizontalSplitPanelWidget.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected void updateDockButtonPosition() {
    if (isDockable()) {

        Style dockButtonStyle = dockButtonContainer.getStyle();
        if (dockMode == SplitPanelDockMode.LEFT) {
            int left = splitter.getOffsetLeft();
            if (left > BUTTON_WIDTH_SPACE) {
                dockButtonStyle.setLeft(left - (dockButton.getOffsetWidth() - getSplitterSize()), Style.Unit.PX);
                dockButtonStyle.setTop(getDockBtnContainerVerticalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.RIGHT) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_LEFT, SP_DOCK_BUTTON_RIGHT);
                    dockButtonState = DockButtonState.LEFT;
                }

                updateSplitPanelStyle(SP_DOCKABLE_LEFT, SP_DOCKABLE_RIGHT);
            } else {
                dockButtonStyle.setLeft(left, Style.Unit.PX);
                dockButtonStyle.setTop(getDockBtnContainerVerticalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.LEFT) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_RIGHT, SP_DOCK_BUTTON_LEFT);
                    dockButtonState = DockButtonState.RIGHT;
                }

                updateSplitPanelStyle(SP_DOCKABLE_RIGHT, SP_DOCKABLE_LEFT);
            }
        } else if (dockMode == SplitPanelDockMode.RIGHT) {
            int right = splitter.getOffsetLeft() + splitter.getOffsetWidth();
            int splitRightPosition = getAbsoluteRight();

            if (right < splitRightPosition - BUTTON_WIDTH_SPACE) {
                dockButtonStyle.setLeft(right - getSplitterSize(), Style.Unit.PX);
                dockButtonStyle.setTop(getDockBtnContainerVerticalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.LEFT) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_RIGHT, SP_DOCK_BUTTON_LEFT);
                    dockButtonState = DockButtonState.RIGHT;
                }

                updateSplitPanelStyle(SP_DOCKABLE_RIGHT, SP_DOCKABLE_LEFT);
            } else {
                dockButtonStyle.setLeft(right - (dockButton.getOffsetWidth()), Style.Unit.PX);
                dockButtonStyle.setTop(getDockBtnContainerVerticalPosition(), Style.Unit.PX);

                if (dockButtonState == DockButtonState.RIGHT) {
                    updateDockButtonStyle(SP_DOCK_BUTTON_LEFT, SP_DOCK_BUTTON_RIGHT);
                    dockButtonState = DockButtonState.LEFT;
                }

                updateSplitPanelStyle(SP_DOCKABLE_LEFT, SP_DOCKABLE_RIGHT);
            }
        }
    }
}
 
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);
}
 
Example 17
Source File: CubaFieldGroupLayoutComponentSlot.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void positionVertically(double currentLocation, double allocatedSpace, double marginBottom) {
    if (!isCaptionInline()) {
        super.positionVertically(currentLocation, allocatedSpace, marginBottom);
        return;
    }

    // CAUTION copied from VLayoutSlot.positionVertically(~)
    Style style = wrapper.getStyle();

    double contentHeight = allocatedSpace;

    int captionHeight;
    VCaption caption = getCaption();
    if (caption == null || caption.shouldBePlacedAfterComponent() || isCaptionInline()) {
        style.clearPaddingTop();
        captionHeight = 0;
    } else {
        captionHeight = getCaptionHeight();
        contentHeight -= captionHeight;
        if (contentHeight < 0) {
            contentHeight = 0;
        }
        style.setPaddingTop(captionHeight, Style.Unit.PX);
    }

    if (marginBottom > 0) {
        style.setMarginBottom(marginBottom, Style.Unit.PX);
    } else {
        style.clearMarginBottom();
    }

    if (isRelativeHeight()) {
        style.setHeight(contentHeight, Style.Unit.PX);
    } else {
        style.clearHeight();
    }

    double allocatedContentHeight = 0;
    if (isRelativeHeight()) {
        String height = getWidget().getElement().getStyle().getHeight();
        double percentage = parsePercent(height);
        allocatedContentHeight = contentHeight * (percentage / 100);
        reportActualRelativeHeight(Math
                .round((float) allocatedContentHeight));
    }

    AlignmentInfo alignment = getAlignment();
    if (!alignment.isTop()) {
        double usedHeight;
        if (isRelativeHeight()) {
            if (isCaptionInline()) {
                usedHeight = allocatedContentHeight;
            } else {
                usedHeight = captionHeight + allocatedContentHeight;
            }
        } else {
            usedHeight = getUsedHeight();
        }
        if (alignment.isVerticalCenter()) {
            currentLocation += (allocatedSpace - usedHeight) / 2d;
        } else {
            currentLocation += (allocatedSpace - usedHeight);
        }
    }

    style.setTop(currentLocation, Style.Unit.PX);
}