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

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

Introduction

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

Prototype

public void clearMarginRight() 

Source Link

Usage

From source file:com.haulmont.cuba.web.toolkit.ui.client.aggregation.TableAggregationRow.java

License:Apache License

public void setCellWidth(int cellIx, int width) {
    // CAUTION: copied from VScrollTableRow with small changes
    final Element cell = DOM.getChild(tr, cellIx);
    Style wrapperStyle = cell.getFirstChildElement().getStyle();
    int wrapperWidth = width;
    if (BrowserInfo.get().isWebkit() || BrowserInfo.get().isOpera10()) {
        /*/*w  w  w  .  j  av a 2 s  .  c  o m*/
         * Some versions of Webkit and Opera ignore the width
         * definition of zero width table cells. Instead, use 1px
         * and compensate with a negative margin.
         */
        if (width == 0) {
            wrapperWidth = 1;
            wrapperStyle.setMarginRight(-1, Style.Unit.PX);
        } else {
            wrapperStyle.clearMarginRight();
        }
    }
    wrapperStyle.setPropertyPx("width", wrapperWidth);
    cell.getStyle().setPropertyPx("width", width);
}

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 v  a2s. 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.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 .jav  a 2 s .  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 ava 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:org.waveprotocol.wave.client.editor.content.paragraph.DefaultParagraphHtmlRenderer.java

License:Apache License

@Override
public void updateRendering(HasImplNodelets element, String type, String listStyle, int indent,
        Alignment alignment, Direction direction) {

    Element implNodelet = element.getImplNodelet();
    ParagraphBehaviour behaviour = ParagraphBehaviour.of(type);
    boolean toListItem = behaviour == ParagraphBehaviour.LIST;
    boolean isListItem = implNodelet.getTagName().equalsIgnoreCase(LIST_IMPL_TAGNAME);

    if (isListItem != toListItem) {
        Element newNodelet = createNodeletInner(toListItem);
        DomHelper.replaceElement(implNodelet, newNodelet);
        element.setBothNodelets(newNodelet);
        // Ideally onRepair shouldn't require a ContentElement
        ParagraphHelper.INSTANCE.onRepair((ContentElement) element);

        implNodelet = newNodelet;//from   w ww  .j  a v a 2s .  c  om
    }

    //// Type logic ////

    double fontSize = -1;
    FontWeight fontWeight = null;
    implNodelet.removeClassName(NUMBERED_CLASSNAME);

    switch (behaviour) {
    case LIST:
        if (Paragraph.LIST_STYLE_DECIMAL.equals(listStyle)) {
            implNodelet.addClassName(NUMBERED_CLASSNAME);
        }
        break;
    case HEADING:
        fontWeight = FontWeight.BOLD;
        double headingNum = Integer.parseInt(type.substring(1));
        // Do this with CSS instead.
        // h1 -> 1.75, h4 -> 1, others linearly in between.
        double factor = 1 - (headingNum - 1) / (Paragraph.NUM_HEADING_SIZES - 1);
        fontSize = MIN_HEADING_SIZE_EM + factor * (MAX_HEADING_SIZE_EM - MIN_HEADING_SIZE_EM);
        break;
    }

    //// Indent logic ////

    for (String bulletType : BULLET_CLASSNAMES) {
        implNodelet.removeClassName(bulletType);
    }

    if (behaviour == ParagraphBehaviour.LIST) {
        if (listStyle == null) {
            implNodelet.addClassName(bulletClassName(indent));
        }
        indent++;
    }

    int margin = indent * INDENT_UNIT_SIZE_PX;

    //// Update actual values ////

    // NOTE(danilatos): For these, it might be more efficient to check that the
    // value has changed before changing it. This is not currently  known.

    Style style = implNodelet.getStyle();

    if (fontSize != -1) {
        style.setFontSize(fontSize, Unit.EM);
    } else {
        style.clearFontSize();
    }

    if (fontWeight != null) {
        style.setFontWeight(fontWeight);
    } else {
        style.clearFontWeight();
    }

    if (alignment != null) {
        style.setProperty("textAlign", alignment.cssValue());
    } else {
        style.clearProperty("textAlign");
    }

    if (direction != null) {
        style.setProperty("direction", direction.cssValue());
    } else {
        style.clearProperty("direction");
    }

    if (margin == 0) {
        style.clearMarginLeft();
        style.clearMarginRight();
    } else {
        if (direction == Direction.RTL) {
            style.setMarginRight(margin, Unit.PX);
            style.clearMarginLeft();
        } else {
            style.setMarginLeft(margin, Unit.PX);
            style.clearMarginRight();
        }
    }
}