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

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

Introduction

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

Prototype

public void setPaddingLeft(double value, Unit unit) 

Source Link

Usage

From source file:com.dianaui.universal.core.client.ui.InlineHelpBlock.java

License:Apache License

public InlineHelpBlock() {
    super();//w w  w . j ava 2  s  .com
    Style style = getElement().getStyle();
    style.setDisplay(Display.INLINE_BLOCK);
    style.setMarginTop(0, Unit.PX);
    style.setMarginBottom(5, Unit.PX);
    style.setPaddingLeft(10, Unit.PX);
}

From source file:com.github.gwtbootstrap.client.ui.WellNavList.java

License:Apache License

private void setStyle() {
    Style style = getElement().getStyle();
    style.setPaddingTop(8, Unit.PX);/*  w  ww .j  av  a 2 s. co  m*/
    style.setPaddingBottom(8, Unit.PX);
    style.setPaddingLeft(0, Unit.PX);
    style.setPaddingRight(0, Unit.PX);
}

From source file:com.haulmont.cuba.web.toolkit.ui.client.fieldgrouplayout.CubaFieldGroupLayoutComponentSlot.java

License:Apache License

@Override
public void positionHorizontally(double currentLocation, double allocatedSpace, double marginRight) {
    if (!isCaptionInline()) {
        super.positionHorizontally(currentLocation, allocatedSpace, marginRight);
        return;/*from  w w w.j  a va  2 s .c om*/
    }

    // CAUTION copied from VLayoutSlot.positionHorizontally(~)

    Style style = wrapper.getStyle();

    double availableWidth = allocatedSpace;

    VCaption caption = getCaption();
    Style captionStyle = caption != null ? caption.getElement().getStyle() : null;
    int captionWidth = getCaptionWidth();

    boolean clearCaptionRight = false;

    boolean captionAboveCompnent;
    if (caption == null) {
        captionAboveCompnent = false;
        style.clearPaddingLeft();

        clearCaptionRight = true;
    } else {
        captionAboveCompnent = !caption.shouldBePlacedAfterComponent();
        if (!captionAboveCompnent) {
            availableWidth -= captionWidth;
            if (availableWidth < 0) {
                availableWidth = 0;
            }
            captionStyle.clearLeft();
            captionStyle.setRight(0, Style.Unit.PX);
            style.setPaddingRight(captionWidth, Style.Unit.PX);
        } else {
            availableWidth -= captionWidth;
            if (availableWidth < 0) {
                availableWidth = 0;
            }
            style.setPaddingLeft(captionWidth, Style.Unit.PX);
            captionStyle.setLeft(0, Style.Unit.PX);
            captionStyle.clearRight();

            clearCaptionRight = true;
        }
    }

    // Take into account right indicators
    double indicatorsWidth = 0;
    if (rightCaption != null) {
        indicatorsWidth = WidgetUtil.getRequiredWidth(rightCaption);
        availableWidth -= indicatorsWidth;
        if (availableWidth < 0) {
            availableWidth = 0;
        }
        style.setPaddingRight(indicatorsWidth, Style.Unit.PX);
    } else if (clearCaptionRight) {
        style.clearPaddingRight();
    }

    if (marginRight > 0) {
        style.setMarginRight(marginRight, Style.Unit.PX);
    } else {
        style.clearMarginRight();
    }

    if (isRelativeWidth()) {
        style.setPropertyPx("width", (int) availableWidth);
    } else {
        style.clearProperty("width");
    }

    double allocatedContentWidth = 0;
    if (isRelativeWidth()) {
        String percentWidth = getWidget().getElement().getStyle().getWidth();
        double percentage = parsePercent(percentWidth);
        allocatedContentWidth = availableWidth * (percentage / 100);
        reportActualRelativeWidth(Math.round((float) allocatedContentWidth));
    }

    AlignmentInfo alignment = getAlignment();
    if (!alignment.isLeft()) {
        double usedWidth;
        if (isRelativeWidth()) {
            if (isCaptionInline()) {
                usedWidth = allocatedContentWidth + indicatorsWidth + captionWidth;
            } else {
                usedWidth = allocatedContentWidth + indicatorsWidth;
            }
        } else {
            usedWidth = getWidgetWidth() + indicatorsWidth;
        }
        if (alignment.isHorizontalCenter()) {
            currentLocation += (allocatedSpace - usedWidth) / 2d;
            if (captionAboveCompnent) {
                captionStyle.setLeft(Math.round(usedWidth - captionWidth) / 2, Style.Unit.PX);
            }
        } else {
            currentLocation += (allocatedSpace - usedWidth);
            if (captionAboveCompnent) {
                captionStyle.setLeft(Math.round(usedWidth - captionWidth), Style.Unit.PX);
            }
        }
    } else {
        if (captionAboveCompnent) {
            captionStyle.setLeft(0, Style.Unit.PX);
        }
    }

    style.setLeft(Math.round(currentLocation), Style.Unit.PX);
}

From source file:com.sencha.gxt.widget.core.client.container.PortalLayoutContainer.java

License:sencha.com license

/**
 * Creates a portal layout container with the specified appearance and number
 * of columns.//from w  w  w.j  a  va 2 s  .  co m
 * 
 * @param appearance the portal layout appearance
 * @param numColumns the number of columns managed by this portal
 */
public PortalLayoutContainer(PortalLayoutAppearance appearance, int numColumns) {
    this.appearance = appearance;
    this.numColumns = numColumns;

    handler = createHandler();

    container = new CssFloatLayoutContainer();
    container.setAdjustForScroll(true);

    initWidget(container);

    getElement().getStyle().setOverflow(Overflow.AUTO);

    for (int i = 0; i < numColumns; i++) {
        CssFloatLayoutContainer con = new CssFloatLayoutContainer();
        Style columnStyle = con.getElement().getStyle();
        columnStyle.setPaddingTop(spacing, Unit.PX);
        columnStyle.setPaddingRight((i < numColumns - 1) ? (spacing / 2) : spacing, Unit.PX);
        columnStyle.setPaddingBottom(0, Unit.PX); // bottom is set on the portlet
        columnStyle.setPaddingLeft((i > 0) ? (spacing / 2) : spacing, Unit.PX);
        container.insert(con, container.getWidgetCount());
    }
}

From source file:com.sencha.gxt.widget.core.client.container.PortalLayoutContainer.java

License:sencha.com license

/**
 * Sets the spacing between portlets (defaults to 10).
 * // w  w w .j av a2s  . c  om
 * @param spacing the spacing in pixels
 */
public void setSpacing(int spacing) {
    this.spacing = spacing;
    for (int i = 0; i < numColumns; i++) {
        CssFloatLayoutContainer con = getWidget(i);
        Style columnStyle = con.getElement().getStyle();
        columnStyle.setPaddingTop(spacing, Unit.PX);
        columnStyle.setPaddingRight((i < numColumns - 1) ? (spacing / 2) : spacing, Unit.PX);
        columnStyle.setPaddingBottom(0, Unit.PX); // bottom is set on the portlet
        columnStyle.setPaddingLeft((i > 0) ? (spacing / 2) : spacing, Unit.PX);

        for (int j = 0; j < con.getWidgetCount(); j++) {
            Style portletStyle = con.getWidget(j).getElement().getStyle();
            portletStyle.setMarginBottom(spacing, Unit.PX);
        }
    }
}

From source file:com.smartgwt.mobile.client.widgets.layout.NavigationBar.java

License:Open Source License

@SGWTInternal
public void _layOutMembers() {
    if (!isAttached())
        return;//from  ww w. ja v  a  2 s.  c om
    if (!isVisible() || !navStack.isVisible())
        return;
    if (layoutTimer == null) {
        layoutTimer = new Timer() {

            @Override
            public void run() {
                final float _1vw = Window.getClientWidth(); // 1 viewport width
                final NavigationItem item = ensureItem();
                final Header1 titleView = item.getTitleView();
                final float minTitleViewWidth, titleViewContentWidth;
                if (titleView == null) {
                    minTitleViewWidth = 0.0f;
                    titleViewContentWidth = 0.0f;
                } else {
                    final SpanElement span = titleView._getSpan();
                    span.getStyle().clearPadding();
                    final float titleViewWidth = ElementUtil.getOuterWidth(titleView.getElement(), true);
                    minTitleViewWidth = titleViewWidth - titleView.getElement().getClientWidth();
                    titleViewContentWidth = span.getOffsetWidth();
                }
                final float titleViewAutoWidth = minTitleViewWidth + titleViewContentWidth;
                final NavigationButton leftButton = item.getLeftButton();
                final Canvas rightBarItem = item.getRightBarItem();
                final float leftButtonHMargin, absoluteMinLeftButtonWidth, leftButtonContentWidth;
                if (leftButton == null) {
                    leftButtonHMargin = 0.0f;
                    absoluteMinLeftButtonWidth = 0.0f;
                    leftButtonContentWidth = 0.0f;
                } else {
                    final Element element = leftButton.getElement();
                    leftButtonHMargin = ElementUtil.getHMarginWidth(element);
                    absoluteMinLeftButtonWidth = ElementUtil.getMinMarginBoxWidth(element);
                    leftButtonContentWidth = leftButton._getContentWidth();
                }
                final float rightBarItemHMargin, absoluteMinRightBarItemWidth, rightBarItemContentWidth;
                if (rightBarItem == null) {
                    rightBarItemHMargin = 0.0f;
                    absoluteMinRightBarItemWidth = 0.0f;
                    rightBarItemContentWidth = 0.0f;
                } else {
                    final Element element = rightBarItem.getElement();
                    rightBarItemHMargin = ElementUtil.getHMarginWidth(element);
                    absoluteMinRightBarItemWidth = ElementUtil.getMinMarginBoxWidth(element);
                    rightBarItemContentWidth = ((NavigationBarItem) rightBarItem)._getContentWidth();
                }
                final float leftButtonAutoWidth = absoluteMinLeftButtonWidth + leftButtonContentWidth,
                        rightBarItemAutoWidth = absoluteMinRightBarItemWidth + rightBarItemContentWidth;

                final float totalWidth = titleViewAutoWidth + leftButtonAutoWidth + rightBarItemAutoWidth;

                float newLeftButtonMarginBoxWidth = 0.0f, newRightButtonMarginBoxWidth = 0.0f;
                if (totalWidth + 0.000001f >= _1vw) {
                    final float minLeftButtonWidth = leftButton == null ? 0.0f
                            : absoluteMinLeftButtonWidth + Math.min(53.0f, leftButtonContentWidth),
                            minRightBarItemWidth = rightBarItem == null ? 0.0f
                                    : absoluteMinRightBarItemWidth + (rightBarItem instanceof NavigationButtons
                                            ? rightBarItemContentWidth
                                            : Math.min(53.0f, rightBarItemContentWidth));
                    assert minLeftButtonWidth <= leftButtonAutoWidth + 0.000001f;
                    assert minRightBarItemWidth <= rightBarItemAutoWidth + 0.000001f;

                    final float r = _1vw - titleViewAutoWidth - minLeftButtonWidth - minRightBarItemWidth;
                    if (r < 0.000001f) {
                        newLeftButtonMarginBoxWidth = minLeftButtonWidth;
                        newRightButtonMarginBoxWidth = minRightBarItemWidth;
                    } else { // The title gets as much width as it needs while still giving the left and/or right
                             // buttons a minimum client width (at most 53px).  The remaining width is distributed to
                             // the left and right buttons.
                        if (leftButton != null || rightBarItem != null) {
                            final float denominator = leftButtonAutoWidth - minLeftButtonWidth
                                    + rightBarItemAutoWidth - minRightBarItemWidth;
                            if (denominator < 2.0f + 0.000001f) {
                                newLeftButtonMarginBoxWidth = minLeftButtonWidth;
                                newRightButtonMarginBoxWidth = minRightBarItemWidth;
                            } else {
                                newLeftButtonMarginBoxWidth = minLeftButtonWidth
                                        + (leftButtonAutoWidth - minLeftButtonWidth) / denominator * r;
                                newRightButtonMarginBoxWidth = minRightBarItemWidth
                                        + (rightBarItemAutoWidth - minRightBarItemWidth) / denominator * r;
                            }
                        }
                    }
                } else {
                    newLeftButtonMarginBoxWidth = leftButtonAutoWidth;
                    newRightButtonMarginBoxWidth = rightBarItemAutoWidth;

                    final float leftButtonExtra = Math.max(0.0f, leftButtonAutoWidth - rightBarItemAutoWidth),
                            rightButtonExtra = Math.max(0.0f, rightBarItemAutoWidth - leftButtonAutoWidth);
                    float r = _1vw - totalWidth;
                    assert r + 0.000001f >= 0.0f;
                    if (titleView != null) {
                        if (r + 0.000001f >= leftButtonExtra + rightButtonExtra) {
                            final float rightPadding = leftButtonExtra, leftPadding = rightButtonExtra;
                            final SpanElement span = titleView._getSpan();
                            final Style spanStyle = span.getStyle();
                            spanStyle.setPaddingRight(rightPadding, Unit.PX);
                            spanStyle.setPaddingLeft(leftPadding, Unit.PX);
                        } else {
                            if (leftButtonExtra + 0.000001f >= rightButtonExtra) {
                                final float rightPadding = r;
                                final SpanElement span = titleView._getSpan();
                                span.getStyle().setPaddingRight(rightPadding, Unit.PX);
                            } else {
                                final float leftPadding = r;
                                final SpanElement span = titleView._getSpan();
                                span.getStyle().setPaddingLeft(leftPadding, Unit.PX);
                            }
                        }
                    }
                }
                if (leftButton != null) {
                    ElementUtil.setBorderBoxWidth(leftButton.getElement(),
                            newLeftButtonMarginBoxWidth - leftButtonHMargin);
                }
                if (rightBarItem != null) {
                    ElementUtil.setBorderBoxWidth(rightBarItem.getElement(),
                            newRightButtonMarginBoxWidth - rightBarItemHMargin);
                }
                if (titleView != null) {
                    // Instead of setting the left and right padding, set the `left' and `right'
                    // CSS properties.
                    // There is a WebKit bug that affects iOS 6 where left and right padding
                    // is incorrectly factored into the calculation of how wide the <h1>
                    // element is for the purpose of centering the text.
                    // https://bugs.webkit.org/show_bug.cgi?id=75277
                    titleView.getElement().getStyle().setLeft(newLeftButtonMarginBoxWidth, Unit.PX);
                    titleView.getElement().getStyle().setRight(newRightButtonMarginBoxWidth, Unit.PX);
                    titleView.getElement().getStyle().clearVisibility();
                }

                layoutTimer = null;
            } // run()
        };
        layoutTimer.schedule(1);
    }
}

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);/*www  . j a v a  2s  .  co  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.orderedlayout.VAbstractOrderedLayout.java

License:Apache License

/**
 * Update the offset off the caption relative to the slot
 * <p>//from   ww w . j  a v a 2  s .  c  o m
 * For internal use only. May be removed or replaced in the future.
 * 
 * @param caption
 *            The caption element
 * @deprecated As of 7.2, call or override
 *             {@link #updateCaptionOffset(Element)} instead
 */
@Deprecated
public void updateCaptionOffset(com.google.gwt.user.client.Element caption) {

    Element captionWrap = caption.getParentElement();

    Style captionWrapStyle = captionWrap.getStyle();
    captionWrapStyle.clearPaddingTop();
    captionWrapStyle.clearPaddingRight();
    captionWrapStyle.clearPaddingBottom();
    captionWrapStyle.clearPaddingLeft();

    Style captionStyle = caption.getStyle();
    captionStyle.clearMarginTop();
    captionStyle.clearMarginRight();
    captionStyle.clearMarginBottom();
    captionStyle.clearMarginLeft();

    // Get caption position from the classname
    CaptionPosition captionPosition = getCaptionPositionFromElement(captionWrap);

    if (captionPosition == CaptionPosition.LEFT || captionPosition == CaptionPosition.RIGHT) {
        int captionWidth;
        if (layoutManager != null) {
            captionWidth = layoutManager.getOuterWidth(caption) - layoutManager.getMarginWidth(caption);
        } else {
            captionWidth = caption.getOffsetWidth();
        }
        if (captionWidth > 0) {
            if (captionPosition == CaptionPosition.LEFT) {
                captionWrapStyle.setPaddingLeft(captionWidth, Unit.PX);
                captionStyle.setMarginLeft(-captionWidth, Unit.PX);
            } else {
                captionWrapStyle.setPaddingRight(captionWidth, Unit.PX);
                captionStyle.setMarginRight(-captionWidth, Unit.PX);
            }
        }
    }
    if (captionPosition == CaptionPosition.TOP || captionPosition == CaptionPosition.BOTTOM) {
        int captionHeight;
        if (layoutManager != null) {
            captionHeight = layoutManager.getOuterHeight(caption) - layoutManager.getMarginHeight(caption);
        } else {
            captionHeight = caption.getOffsetHeight();
        }
        if (captionHeight > 0) {
            if (captionPosition == CaptionPosition.TOP) {
                captionWrapStyle.setPaddingTop(captionHeight, Unit.PX);
                captionStyle.setMarginTop(-captionHeight, Unit.PX);
            } else {
                captionWrapStyle.setPaddingBottom(captionHeight, Unit.PX);
                captionStyle.setMarginBottom(-captionHeight, Unit.PX);
            }
        }
    }
}

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

License:Apache License

/**
 * Calculates the width of the select if the select has undefined width.
 * Should be called when the width changes or when the icon changes.
 * <p>/*from   ww w .j a  v a  2  s.  com*/
 * For internal use only. May be removed or replaced in the future.
 */
public void updateRootWidth() {
    debug("VComboBox: updateRootWidth()");

    if (connector.isUndefinedWidth()) {

        /*
         * When the select has a undefined with we need to check that we are
         * only setting the text box width relative to the first page width
         * of the items. If this is not done the text box width will change
         * when the popup is used to view longer items than the text box is
         * wide.
         */
        int w = WidgetUtil.getRequiredWidth(this);

        if (dataReceivedHandler.isWaitingForInitialData() && suggestionPopupMinWidth > w) {
            /*
             * We want to compensate for the paddings just to preserve the
             * exact size as in Vaadin 6.x, but we get here before
             * MeasuredSize has been initialized.
             * Util.measureHorizontalPaddingAndBorder does not work with
             * border-box, so we must do this the hard way.
             */
            Style style = getElement().getStyle();
            String originalPadding = style.getPadding();
            String originalBorder = style.getBorderWidth();
            style.setPaddingLeft(0, Unit.PX);
            style.setBorderWidth(0, Unit.PX);
            style.setProperty("padding", originalPadding);
            style.setProperty("borderWidth", originalBorder);

            // Use util.getRequiredWidth instead of getOffsetWidth here

            int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil.getRequiredWidth(selectedItemIcon);
            int buttonWidth = popupOpener == null ? 0 : WidgetUtil.getRequiredWidth(popupOpener);

            /*
             * Instead of setting the width of the wrapper, set the width of
             * the combobox. Subtract the width of the icon and the
             * popupopener
             */

            tb.setWidth(suggestionPopupMinWidth - iconWidth - buttonWidth + "px");
        }

        /*
         * Lock the textbox width to its current value if it's not already
         * locked. This can happen after setWidth("") which resets the
         * textbox width to "100%".
         */
        if (!tb.getElement().getStyle().getWidth().endsWith("px")) {
            int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon.getOffsetWidth();
            tb.setWidth(tb.getOffsetWidth() - iconWidth + "px");
        }
    }
}

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

License:Apache License

/**
 * Calculates the width of the select if the select has undefined width.
 * Should be called when the width changes or when the icon changes.
 * <p>/* w ww  .  ja v a 2 s . c  o  m*/
 * For internal use only. May be removed or replaced in the future.
 */
public void updateRootWidth() {
    ComponentConnector paintable = ConnectorMap.get(client).getConnector(this);

    if (paintable.isUndefinedWidth()) {

        /*
         * When the select has a undefined with we need to check that we are
         * only setting the text box width relative to the first page width
         * of the items. If this is not done the text box width will change
         * when the popup is used to view longer items than the text box is
         * wide.
         */
        int w = WidgetUtil.getRequiredWidth(this);

        if ((!initDone || currentPage + 1 < 0) && suggestionPopupMinWidth > w) {
            /*
             * We want to compensate for the paddings just to preserve the
             * exact size as in Vaadin 6.x, but we get here before
             * MeasuredSize has been initialized.
             * Util.measureHorizontalPaddingAndBorder does not work with
             * border-box, so we must do this the hard way.
             */
            Style style = getElement().getStyle();
            String originalPadding = style.getPadding();
            String originalBorder = style.getBorderWidth();
            style.setPaddingLeft(0, Unit.PX);
            style.setBorderWidth(0, Unit.PX);
            style.setProperty("padding", originalPadding);
            style.setProperty("borderWidth", originalBorder);

            // Use util.getRequiredWidth instead of getOffsetWidth here

            int iconWidth = selectedItemIcon == null ? 0 : WidgetUtil.getRequiredWidth(selectedItemIcon);
            int buttonWidth = popupOpener == null ? 0 : WidgetUtil.getRequiredWidth(popupOpener);

            /*
             * Instead of setting the width of the wrapper, set the width of
             * the combobox. Subtract the width of the icon and the
             * popupopener
             */

            tb.setWidth((suggestionPopupMinWidth - iconWidth - buttonWidth) + "px");

        }

        /*
         * Lock the textbox width to its current value if it's not already
         * locked
         */
        if (!tb.getElement().getStyle().getWidth().endsWith("px")) {
            int iconWidth = selectedItemIcon == null ? 0 : selectedItemIcon.getOffsetWidth();
            tb.setWidth((tb.getOffsetWidth() - iconWidth) + "px");
        }
    }
}