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

The following examples show how to use com.google.gwt.dom.client.Style#setHeight() . 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 downloadFileById(String resourceId) {
    final String url = getResourceUrl(resourceId);
    if (url != null && !url.isEmpty()) {
        final IFrameElement iframe = Document.get().createIFrameElement();

        Style style = iframe.getStyle();
        style.setVisibility(Style.Visibility.HIDDEN);
        style.setHeight(0, Style.Unit.PX);
        style.setWidth(0, Style.Unit.PX);

        iframe.setFrameBorder(0);
        iframe.setTabIndex(-1);
        iframe.setSrc(url);
        RootPanel.getBodyElement().appendChild(iframe);

        Timer removeTimer = new Timer() {
            @Override
            public void run() {
                iframe.removeFromParent();
            }
        };
        removeTimer.schedule(60 * 1000);
    }
}
 
Example 2
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 3
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 4
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 5
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 6
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 7
/**
 * 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 8
TextLine(int minY, int maxY, int prevY, TextPage parent, List<Zone> lineTokens) {
	Style style = getElement().getStyle();
	double marginTop = round((prevY - maxY) * 100.0 / parent.width, PCT_ACCURACY);
	if (parent.getWidgetCount() == 0) {
		style.setPaddingTop(marginTop, Unit.PCT);
	} else {
		style.setMarginTop(marginTop, Unit.PCT);
	}
	style.setHeight(round((maxY - minY) * 100.0 / parent.height, PCT_ACCURACY), Unit.PCT);
	
	Token lastToken = null;
	int prevXmax = 0;
	for (Zone zone : lineTokens) {
		Token token = new Token(zone, prevXmax, parent);
		if (token.text.isEmpty()) {
			if (lastToken != null)
				lastToken.setText(lastToken.getText() + token.getText());
			continue;
		}
		add(token);
		lastToken = token;
		if (token.text.length() > 1 || lineTokens.size() == 1) {
			tokens.add(token);
		}
		prevXmax = zone.xmax;
	}

	parent.textLines.add(this);
	parent.add(this);
}
 
Example 9
Source Project: swellrt   File: ImageThumbnailWidget.java    License: Apache License 2.0 5 votes vote down vote up
private void setImageSize() {
  int width = isFullSize?attachmentWidth:thumbnailWidth;
  int height = isFullSize?attachmentHeight:thumbnailHeight;
  image.setPixelSize(width, height);
  //TODO(user,danilatos): Whinge about how declarative UI doesn't let us avoid this hack:
  Style pstyle = image.getElement().getParentElement().getParentElement().getStyle();
  if (width == 0) {
    image.setWidth("");
    pstyle.clearWidth();
  } else {
    pstyle.setWidth(width, Unit.PX);
  }
  if (height == 0) {
    image.setHeight("");
    pstyle.clearHeight();
  } else {
    pstyle.setHeight(height, Unit.PX);
  }

  String url = isFullSize?attachmentUrl:thumbnailUrl;
  if (url != null) {
    if (doubleBufferLoader == null) {
      doubleBufferLoader = new DoubleBufferImage(spin, errorLabel, image);
    }
    doubleBufferLoader.loadImage(url);
    DOM.setStyleAttribute(image.getElement(), "visibility", "");
  }

  // NOTE(user): IE requires that the imageCaptionContainer element has a width
  //   in order to correctly center the caption.
  if (DO_FRAME_WIDTH_UPDATE) {
    captionPanel.getElement().getStyle().setWidth(width, Unit.PX);
  }
}
 
Example 10
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 11
private void setImageSize() {
  int width = isFullSize?attachmentWidth:thumbnailWidth;
  int height = isFullSize?attachmentHeight:thumbnailHeight;
  image.setPixelSize(width, height);
  //TODO(user,danilatos): Whinge about how declarative UI doesn't let us avoid this hack:
  Style pstyle = image.getElement().getParentElement().getParentElement().getStyle();
  if (width == 0) {
    image.setWidth("");
    pstyle.clearWidth();
  } else {
    pstyle.setWidth(width, Unit.PX);
  }
  if (height == 0) {
    image.setHeight("");
    pstyle.clearHeight();
  } else {
    pstyle.setHeight(height, Unit.PX);
  }

  String url = isFullSize?attachmentUrl:thumbnailUrl;
  if (url != null) {
    if (doubleBufferLoader == null) {
      doubleBufferLoader = new DoubleBufferImage(spin, errorLabel, image);
    }
    doubleBufferLoader.loadImage(url);
    DOM.setStyleAttribute(image.getElement(), "visibility", "");
  }

  // NOTE(user): IE requires that the imageCaptionContainer element has a width
  //   in order to correctly center the caption.
  if (DO_FRAME_WIDTH_UPDATE) {
    captionPanel.getElement().getStyle().setWidth(width, Unit.PX);
  }
}
 
Example 12
@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);
}
 
Example 13
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;
}