Example usage for com.google.gwt.dom.client Style setHeight

List of usage examples for com.google.gwt.dom.client Style setHeight

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Style setHeight.

Prototype

public void setHeight(double value, Unit unit) 

Source Link

Usage

From source file:com.vaadin.addon.spreadsheet.client.GroupingWidget.java

protected void copyfields(GroupingWidget newWidget) {
    newWidget.collapsed = collapsed;//  w w w.ja v a 2 s  . c om
    newWidget.index = index;
    newWidget.inversed = inversed;

    newWidget.btn.setInnerText(btn.getInnerText());

    Style style = newWidget.getElement().getStyle();

    newWidget.setStyleName(getStyleName());

    if (marginLeft > -1) {
        style.setMarginLeft(marginLeft, Unit.PX);
    }
    if (marginTop > -1) {
        style.setMarginTop(marginTop, Unit.PX);
    }
    if (height > -1) {
        style.setHeight(height, Unit.PX);
    }
    if (width > -1) {
        style.setWidth(width, Unit.PX);
    }
    if (top > -1) {
        style.setTop(top, Unit.PX);
    }
    if (left > -1) {
        style.setLeft(left, Unit.PX);
    }
}

From source file:com.vaadin.addon.spreadsheet.client.SheetWidget.java

/**
 * Updates the left & top style property for sheet panes depending if
 * headers are shown or not./*from w  w  w.j av  a2  s  .co m*/
 */
void updateSheetPanePositions() {
    int extraSize = horizontalSplitPosition > 0 ? 1 : 0;
    if (spreadsheet.getAttribute("class").contains("report")) {
        extraSize = 0;
    }
    int widthIncrease = 0;
    if (rowHeaders != null && !rowHeaders.isEmpty()) {
        widthIncrease = getRowHeaderSize();
    }

    int heightIncrease = 0;
    if (colHeaders != null && !colHeaders.isEmpty()) {
        heightIncrease = getColHeaderSize();
    }

    // Measure formula bar height
    int formulaBarHeight = 0;
    if (actionHandler.getFormulaBarWidget() != null) {
        MeasuredSize measuredSize = new MeasuredSize();
        measuredSize.measure(actionHandler.getFormulaBarWidget().getElement());
        formulaBarHeight = (int) measuredSize.getOuterHeight();
    }

    int addedHeaderHeight = updateExtraColumnHeaderElements(formulaBarHeight);
    int addedHeaderWidth = updateExtraRowHeaderElements(formulaBarHeight);
    updateExtraCornerElements(formulaBarHeight, addedHeaderHeight, addedHeaderWidth);

    if (!displayRowColHeadings) {
        widthIncrease = 0;
        heightIncrease = 0;
    }

    topOffset = heightIncrease + formulaBarHeight + addedHeaderHeight;
    leftOffset = widthIncrease + addedHeaderWidth;

    Style style = topLeftPane.getStyle();
    style.setWidth(leftFrozenPanelWidth + widthIncrease + 1, Unit.PX);
    style.setHeight(topFrozenPanelHeight + heightIncrease, Unit.PX);
    style.setTop(formulaBarHeight + addedHeaderHeight, Unit.PX);
    style.setLeft(addedHeaderWidth, Unit.PX);

    style = topRightPane.getStyle();
    // left offset is the same as the width increase
    style.setLeft(leftFrozenPanelWidth + leftOffset + extraSize, Unit.PX);
    style.setHeight(topFrozenPanelHeight + heightIncrease, Unit.PX);
    style.setTop(formulaBarHeight + addedHeaderHeight, Unit.PX);

    style = bottomLeftPane.getStyle();
    // The +1 is to accommodate the vertical border of the freeze pane
    style.setWidth(leftFrozenPanelWidth + widthIncrease + 1, Unit.PX);
    style.setTop(topFrozenPanelHeight + topOffset, Unit.PX);
    style.setLeft(addedHeaderWidth, Unit.PX);

    style = sheet.getStyle();
    style.setLeft(leftFrozenPanelWidth + leftOffset + extraSize, Unit.PX);
    style.setTop(topFrozenPanelHeight + topOffset, Unit.PX);

    style = corner.getStyle();
    style.setTop(formulaBarHeight + addedHeaderHeight, Unit.PX);
    style.setLeft(addedHeaderWidth, Unit.PX);

}

From source file:com.vaadin.client.debug.internal.Highlight.java

License:Apache License

/**
 * Highlight the given {@link Element} using the given color.
 * <p>//from w  w w  .  ja v  a  2  s  .  co  m
 * Pass the returned highlight {@link Element} to {@link #hide(Element)} to
 * remove this particular highlight.
 * </p>
 * 
 * @param element
 *            Element to highlight
 * @param color
 *            Color of highlight
 * @return Highlight element
 */
static Element show(Element element, String color) {
    if (element != null) {
        if (highlights == null) {
            highlights = new HashSet<Element>();
        }

        Element highlight = DOM.createDiv();
        Style style = highlight.getStyle();
        style.setTop(element.getAbsoluteTop(), Unit.PX);
        style.setLeft(element.getAbsoluteLeft(), Unit.PX);
        int width = element.getOffsetWidth();
        if (width < MIN_WIDTH) {
            width = MIN_WIDTH;
        }
        style.setWidth(width, Unit.PX);
        int height = element.getOffsetHeight();
        if (height < MIN_HEIGHT) {
            height = MIN_HEIGHT;
        }
        style.setHeight(height, Unit.PX);
        RootPanel.getBodyElement().appendChild(highlight);

        style.setPosition(Position.ABSOLUTE);
        style.setZIndex(VWindow.Z_INDEX + 1000);
        style.setBackgroundColor(color);
        style.setOpacity(DEFAULT_OPACITY);
        if (BrowserInfo.get().isIE()) {
            style.setProperty("filter", "alpha(opacity=" + (DEFAULT_OPACITY * 100) + ")");
        }

        highlights.add(highlight);

        return highlight;
    }
    return null;
}

From source file:com.vaadin.client.extensions.FileDownloaderConnector.java

License:Apache License

@Override
public void onClick(ClickEvent event) {
    final String url = getResourceUrl("dl");
    if (url != null && !url.isEmpty()) {
        BrowserInfo browser = BrowserInfo.get();
        if (browser.isIOS()) {
            Window.open(url, "_blank", "");
        } else {// ww  w  .ja  v  a2 s.  c  o  m
            if (iframe != null) {
                // make sure it is not on dom tree already, might start
                // multiple downloads at once
                iframe.removeFromParent();
            }
            iframe = Document.get().createIFrameElement();

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

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

From source file:com.vaadin.client.SimpleTree.java

License:Apache License

public SimpleTree() {
    setElement(Document.get().createDivElement());
    Style style = getElement().getStyle();
    style.setProperty("whiteSpace", "nowrap");
    style.setPadding(3, Unit.PX);//from ww  w.  jav a2  s  .  c  o  m
    style.setPaddingLeft(12, Unit.PX);
    // handle styling
    style = handle.getStyle();
    style.setDisplay(Display.NONE);
    style.setTextAlign(TextAlign.CENTER);
    style.setWidth(0.5, Unit.EM);
    style.setHeight(0.5, Unit.EM);
    style.setCursor(Cursor.POINTER);
    style.setBackgroundColor("gray");
    style.setColor("white");
    style.setPadding(4, Unit.PX);
    style.setMarginRight(3, Unit.PX);
    style.setLineHeight(0.5, Unit.EM);
    handle.setInnerHTML("+");
    getElement().appendChild(handle);
    getElement().appendChild(text);
    // children styling
    style = children.getStyle();
    style.setPaddingLeft(1.5, Unit.EM);
    style.setDisplay(Display.NONE);

    getElement().appendChild(children);
    addDomHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            if (event.getNativeEvent().getEventTarget().cast() == handle) {
                if (children.getStyle().getDisplay().intern() == Display.NONE.getCssName()) {
                    open(event.getNativeEvent().getAltKey());
                } else {
                    close();
                }

            } else if (event.getNativeEvent().getEventTarget().cast() == text) {
                select(event);
            }
        }
    }, ClickEvent.getType());
}

From source file:com.vaadin.client.ui.audio.AudioConnector.java

License:Apache License

@Override
public void onStateChanged(StateChangeEvent stateChangeEvent) {
    super.onStateChanged(stateChangeEvent);

    // Opera (12.14) has a bug where an audio element w/o controls is shown
    // as 150x300px, which is not usually desired. However, in order to show
    // the error/alt message, we only do this in the exact situation.
    if (BrowserInfo.get().isOpera() && stateChangeEvent.hasPropertyChanged("showControls")) {
        Style style = getWidget().getElement().getStyle();
        if (!getState().showControls) {
            if (isUndefinedHeight() && isUndefinedWidth() && getWidget().getOffsetHeight() == 150
                    && getWidget().getOffsetWidth() == 300) {
                // only if no size set and 150x300
                style.setWidth(0, Unit.PX);
                style.setHeight(0, Unit.PX);
            }/* w w  w  .j a  v  a 2 s .c o  m*/
        } else {
            // clear sizes if it's supposed to be undefined
            if (isUndefinedHeight()) {
                style.clearHeight();
            }
            if (isUndefinedWidth()) {
                style.clearWidth();
            }
        }
    }
}

From source file:com.vaadin.client.ui.layout.VLayoutSlot.java

License:Apache License

public void positionVertically(double currentLocation, double allocatedSpace, double marginBottom) {
    Style style = wrapper.getStyle();

    double contentHeight = allocatedSpace;

    int captionHeight;
    VCaption caption = getCaption();/*ww  w . j  a v a 2s .  c  o m*/
    if (caption == null || caption.shouldBePlacedAfterComponent()) {
        style.clearPaddingTop();
        captionHeight = 0;
    } else {
        captionHeight = getCaptionHeight();
        contentHeight -= captionHeight;
        if (contentHeight < 0) {
            contentHeight = 0;
        }
        style.setPaddingTop(captionHeight, Unit.PX);
    }

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

    style.setHeight(contentHeight, Unit.PX);

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

    style.setTop(currentLocation, Unit.PX);
    double padding = 0;
    AlignmentInfo alignment = getAlignment();
    if (!alignment.isTop()) {
        double usedHeight;
        if (isRelativeHeight()) {
            usedHeight = captionHeight + allocatedContentHeight;
        } else {
            usedHeight = getUsedHeight();
        }
        if (alignment.isVerticalCenter()) {
            padding = (allocatedSpace - usedHeight) / 2d;
        } else {
            padding = (allocatedSpace - usedHeight);
        }
        padding += captionHeight;

        widget.getElement().getStyle().setTop(padding, Unit.PX);
    } else {
        // Reset top when changing back to align top
        widget.getElement().getStyle().clearTop();

    }
}

From source file:com.vaadin.client.ui.VMenuBar.java

License:Apache License

private int adjustPopupHeight(int top, final int shadowSpace) {
    // Check that the popup will fit the screen
    int availableHeight = RootPanel.getBodyElement().getOffsetHeight() - top - shadowSpace;
    int missingHeight = popup.getOffsetHeight() - availableHeight;
    if (missingHeight > 0) {
        // First move the top of the popup to get more space
        // Don't move above top of screen, don't move more than needed
        int moveUpBy = Math.min(top - shadowSpace, missingHeight);

        // Update state
        top -= moveUpBy;//from   ww  w .j a  v  a  2s.c  o m
        missingHeight -= moveUpBy;
        availableHeight += moveUpBy;

        if (missingHeight > 0) {
            int contentWidth = visibleChildMenu.getOffsetWidth();

            // If there's still not enough room, limit height to fit and add
            // a scroll bar
            Style style = popup.getElement().getStyle();
            style.setHeight(availableHeight, Unit.PX);
            style.setOverflowY(Overflow.SCROLL);

            // Make room for the scroll bar by adjusting the width of the
            // popup
            style.setWidth(contentWidth + WidgetUtil.getNativeScrollbarSize(), Unit.PX);
            popup.positionOrSizeUpdated();
        }
    }
    return top;
}

From source file:com.vaadin.client.ui.VWindow.java

License:Apache License

private void fixIE8FocusCaptureIssue() {
    Element e = DOM.createInputText();
    Style elemStyle = e.getStyle();
    elemStyle.setPosition(Position.ABSOLUTE);
    elemStyle.setTop(-10, Unit.PX);//from   www .  j  a  v a 2s  .  co m
    elemStyle.setWidth(0, Unit.PX);
    elemStyle.setHeight(0, Unit.PX);

    contentPanel.getElement().appendChild(e);
    e.focus();
    contentPanel.getElement().removeChild(e);
}

From source file:com.vaadin.client.VDebugConsole.java

License:Apache License

@Override
public void init() {
    panel = new FlowPanel();
    if (!quietMode) {
        DOM.appendChild(getContainerElement(), caption);
        setWidget(panel);/*  w  w w. ja v a2  s  .  c  o  m*/
        caption.setClassName("v-debug-console-caption");
        setStyleName("v-debug-console");
        getElement().getStyle().setZIndex(20000);
        getElement().getStyle().setOverflow(Overflow.HIDDEN);

        sinkEvents(Event.ONDBLCLICK);

        sinkEvents(Event.MOUSEEVENTS);

        panel.setStyleName("v-debug-console-content");

        caption.setInnerHTML("Debug window");
        caption.getStyle().setHeight(25, Unit.PX);
        caption.setTitle(help);

        show();
        setToDefaultSizeAndPos();

        actions = new HorizontalPanel();
        Style style = actions.getElement().getStyle();
        style.setPosition(Position.ABSOLUTE);
        style.setBackgroundColor("#666");
        style.setLeft(135, Unit.PX);
        style.setHeight(25, Unit.PX);
        style.setTop(0, Unit.PX);

        actions.add(clear);
        actions.add(restart);
        actions.add(forceLayout);
        actions.add(analyzeLayout);
        actions.add(highlight);
        actions.add(connectorStats);
        connectorStats.setTitle("Show connector statistics for client");
        highlight.setTitle(
                "Select a component and print details about it to the server log and client side console.");
        actions.add(savePosition);
        savePosition.setTitle("Saves the position and size of debug console to a cookie");
        actions.add(autoScroll);
        addDevMode();
        addSuperDevMode();

        autoScroll.setTitle("Automatically scroll so that new messages are visible");

        panel.add(actions);

        panel.add(new HTML("<i>" + help + "</i>"));

        clear.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                int width = panel.getOffsetWidth();
                int height = panel.getOffsetHeight();
                panel = new FlowPanel();
                panel.setPixelSize(width, height);
                panel.setStyleName("v-debug-console-content");
                panel.add(actions);
                setWidget(panel);
            }
        });

        restart.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {

                String queryString = Window.Location.getQueryString();
                if (queryString != null && queryString.contains("restartApplications")) {
                    Window.Location.reload();
                } else {
                    String url = Location.getHref();
                    String separator = "?";
                    if (url.contains("?")) {
                        separator = "&";
                    }
                    if (!url.contains("restartApplication")) {
                        url += separator;
                        url += "restartApplication";
                    }
                    if (!"".equals(Location.getHash())) {
                        String hash = Location.getHash();
                        url = url.replace(hash, "") + hash;
                    }
                    Window.Location.replace(url);
                }

            }
        });

        forceLayout.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                for (ApplicationConnection applicationConnection : ApplicationConfiguration
                        .getRunningApplications()) {
                    applicationConnection.forceLayout();
                }
            }
        });

        analyzeLayout.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                List<ApplicationConnection> runningApplications = ApplicationConfiguration
                        .getRunningApplications();
                for (ApplicationConnection applicationConnection : runningApplications) {
                    applicationConnection.analyzeLayouts();
                }
            }
        });
        analyzeLayout.setTitle("Analyzes currently rendered view and "
                + "reports possible common problems in usage of relative sizes."
                + "Will cause server visit/rendering of whole screen and loss of"
                + " all non committed variables form client side.");

        savePosition.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                String pos = getAbsoluteLeft() + "," + getAbsoluteTop() + "," + getOffsetWidth() + ","
                        + getOffsetHeight() + "," + autoScroll.getValue();
                Cookies.setCookie(POS_COOKIE_NAME, pos);
            }
        });

        highlight.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                final Label label = new Label("--");
                log("<i>Use mouse to select a component or click ESC to exit highlight mode.</i>");
                panel.add(label);
                highlightModeRegistration = Event.addNativePreviewHandler(new HighlightModeHandler(label));

            }
        });

    }
    connectorStats.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            for (ApplicationConnection a : ApplicationConfiguration.getRunningApplications()) {
                dumpConnectorInfo(a);
            }
        }
    });
    log("Starting Vaadin client side engine. Widgetset: " + GWT.getModuleName());

    log("Widget set is built on version: " + Version.getFullVersion());

    logToDebugWindow("<div class=\"v-theme-version v-theme-version-"
            + Version.getFullVersion().replaceAll("\\.", "_") + "\">Warning: widgetset version "
            + Version.getFullVersion() + " does not seem to match theme version </div>", true);

}