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

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

Introduction

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

Prototype

public void setPaddingRight(double value, Unit unit) 

Source Link

Usage

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);// ww  w.  ja v a 2s . c o  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;/* ww w. j a  v a 2 s.  c  o  m*/
    }

    // 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  .ja v  a2s  . c  o  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).
 * //from w  w w. j a  va  2 s  .  com
 * @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;/*w  w w  . jav a2s. c o m*/
    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.ui.layout.VLayoutSlot.java

License:Apache License

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

    double availableWidth = allocatedSpace;

    VCaption caption = getCaption();//from w  ww . ja v a  2s. c o m
    Style captionStyle = caption != null ? caption.getElement().getStyle() : null;
    int captionWidth = getCaptionWidth();

    boolean captionAboveCompnent;
    if (caption == null) {
        captionAboveCompnent = false;
        style.clearPaddingRight();
    } else {
        captionAboveCompnent = !caption.shouldBePlacedAfterComponent();
        if (!captionAboveCompnent) {
            availableWidth -= captionWidth;
            if (availableWidth < 0) {
                availableWidth = 0;
            }
            captionStyle.clearLeft();
            captionStyle.setRight(0, Unit.PX);
            style.setPaddingRight(captionWidth, Unit.PX);
        } else {
            captionStyle.setLeft(0, Unit.PX);
            captionStyle.clearRight();
            style.clearPaddingRight();
        }
    }

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

    style.setPropertyPx("width", (int) availableWidth);

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

    style.setLeft(Math.round(currentLocation), Unit.PX);
    AlignmentInfo alignment = getAlignment();
    if (!alignment.isLeft()) {
        double usedWidth;
        if (isRelativeWidth()) {
            usedWidth = allocatedContentWidth;
        } else {
            usedWidth = getWidgetWidth();
        }

        double padding = (allocatedSpace - usedWidth);
        if (alignment.isHorizontalCenter()) {
            padding = padding / 2;
        }

        long roundedPadding = Math.round(padding);
        if (captionAboveCompnent) {
            captionStyle.setLeft(roundedPadding, Unit.PX);
        }
        widget.getElement().getStyle().setLeft(roundedPadding, Unit.PX);
    } else {
        if (captionAboveCompnent) {
            captionStyle.setLeft(0, Unit.PX);
        }
        // Reset left when changing back to align left
        widget.getElement().getStyle().clearLeft();
    }

}

From source file:com.vaadin.client.ui.orderedlayout.VAbstractOrderedLayout.java

License:Apache License

/**
 * Update the offset off the caption relative to the slot
 * <p>// w w w .  j  a va2s.  co  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.tests.widgetset.client.WidgetUtilTestWidget.java

License:Apache License

private void setPadding(Element e) {
    Style borderStyle = e.getStyle();
    borderStyle.setPaddingLeft(2.4, Unit.PX);
    borderStyle.setPaddingRight(3.5, Unit.PX);
    borderStyle.setPaddingTop(2.4, Unit.PX);
    borderStyle.setPaddingBottom(3.5, Unit.PX);
}

From source file:org.anstis.client.grid.widget.dom.TextBoxDOMElement.java

License:Apache License

public TextBoxDOMElement(final GridLayer gridLayer, final BaseGridWidget<?, ?> gridWidget,
        final IDOMElementFactory<String, ?> factory, final AbsolutePanel domElementContainer) {
    super(gridLayer, gridWidget, factory, domElementContainer);
    final Style style = tb.getElement().getStyle();
    style.setWidth(100, Style.Unit.PCT);
    style.setHeight(HEIGHT, Style.Unit.PX);
    style.setPaddingLeft(2, Style.Unit.PX);
    style.setPaddingRight(2, Style.Unit.PX);
    style.setFontSize(10, Style.Unit.PX);

    getContainer().getElement().getStyle().setPaddingLeft(5, Style.Unit.PX);
    getContainer().getElement().getStyle().setPaddingRight(5, Style.Unit.PX);
    getContainer().setWidget(tb);//  w  w  w . j ava2  s .  c om

    tb.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(final ValueChangeEvent event) {
            flush();
        }
    });
    tb.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(final BlurEvent event) {
            if (context != null) {
                factory.freeUnusedResources();
            }
        }
    });
}

From source file:org.dashbuilder.renderer.client.metric.MetricViewImpl.java

License:Apache License

public void applySettings(DisplayerSettings displayerSettings) {
    this.displayerSettings = displayerSettings;
    int w = displayerSettings.getChartWidth();
    int h = displayerSettings.getChartHeight();
    int mtop = displayerSettings.getChartMarginTop();
    int mbottom = displayerSettings.getChartMarginBottom();
    int mleft = displayerSettings.getChartMarginLeft();
    int mright = displayerSettings.getChartMarginRight();

    // Hero panel (size)
    Style style = heroPanel.getElement().getStyle();
    style.setPadding(0, Style.Unit.PX);
    style.setWidth(w, Style.Unit.PX);
    style.setHeight(h, Style.Unit.PX);
    style.setTextAlign(Style.TextAlign.CENTER);
    style.setVerticalAlign(Style.VerticalAlign.MIDDLE);
    if (!StringUtils.isBlank(displayerSettings.getChartBackgroundColor())) {
        style.setBackgroundColor("#" + displayerSettings.getChartBackgroundColor());
    }//from w  ww  . ja v a2 s  .co m

    // Center panel (paddings)
    style = centerPanel.getElement().getStyle();
    style.setPaddingTop(mtop, Style.Unit.PX);
    style.setPaddingBottom(mbottom, Style.Unit.PX);
    style.setPaddingLeft(mleft, Style.Unit.PX);
    style.setPaddingRight(mright, Style.Unit.PX);

    // Title panel
    titlePanel.setVisible(displayerSettings.isTitleVisible());
    titlePanel.setText(displayerSettings.getTitle());
}