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

The following examples show how to use com.google.gwt.dom.client.Style#setLeft() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
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 Project: cuba   File: VDDGridLayout.java    License: 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 3
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 4
/**
 * 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 5
@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 6
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
@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
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 9
private void updateSelectionBoundsAndText() {
  int left = Math.min(myCaretPosition, mySelectionStart);
  int right = Math.max(myCaretPosition, mySelectionStart);

  String text = myText == null ? "" : myText;
  text = text.substring(left, right);

  Style selectionStyle = mySelectionDiv.getStyle();
  selectionStyle.setLeft(getCaretOffset(left), Style.Unit.PX);
  selectionStyle.setWidth(getCaretOffset(right) - getCaretOffset(left), Style.Unit.PX);

  mySelectionDiv.setInnerText(TextMetricsCalculator.normalize(text));
}
 
Example 10
Source Project: cuba   File: IframeCoverUtility.java    License: 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 11
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 12
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 13
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);
}