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

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

Introduction

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

Prototype

public void setProperty(String name, String value) 

Source Link

Usage

From source file:cc.alcina.framework.gwt.client.util.ClientUtils.java

License:Apache License

public static String trimToWidth(String s, String style, int pxWidth, String ellipsis) {
    if (pxWidth <= 20) {
        return s;
    }//from   w w  w  .j  av a  2 s .  c  om
    ellipsis = ellipsis == null ? "\u2026" : ellipsis;
    int r0 = 0;
    int r1 = s.length();
    Label l = new Label();
    setElementStyle(l.getElement(), style);
    Style cStyle = l.getElement().getStyle();
    cStyle.setPosition(Position.ABSOLUTE);
    cStyle.setLeft(0, Unit.PX);
    cStyle.setTop(0, Unit.PX);
    cStyle.setDisplay(Display.INLINE_BLOCK);
    cStyle.setProperty("whitespace", "nowrap");
    cStyle.setProperty("visibility", "hidden");
    RootPanel.get().add(l);
    boolean tried = false;
    while (true) {
        int mid = (r1 - r0) / 2 + r0;
        String t = tried ? s.substring(0, mid) + ellipsis : s;
        l.setText(t);
        if (l.getOffsetWidth() <= pxWidth) {
            if (!tried || (r1 - r0) <= 1) {
                RootPanel.get().remove(l);
                return t;
            }
            r0 = mid;
        } else {
            if (!tried) {
                tried = true;
            } else {
                r1 = mid;
            }
        }
    }
}

From source file:com.alkacon.geranium.client.util.StyleSaver.java

License:Open Source License

/**
 * Restores all saved style properties on this instance's DOM element.<p>
 *//*w  w w.java2s .c om*/
public void restore() {

    Style style = m_element.getStyle();
    for (Map.Entry<String, String> entry : m_propertyValues.entrySet()) {
        style.setProperty(entry.getKey(), entry.getValue());
    }
}

From source file:com.alkacon.geranium.client.util.TextMetrics.java

License:Open Source License

/**
 * Binds this text metrics instance to an element from which to copy existing
 * CSS styles that can affect the size of the rendered text.<p>
 * /*from  www.ja  v  a  2 s  . c om*/
 * @param element the element
 * @param attributes the attributes to bind
 */
protected void bind(Element element, DomUtil.Style... attributes) {

    if (m_elem == null) {
        // create playground
        m_elem = DOM.createDiv();
        Style style = m_elem.getStyle();
        style.setVisibility(Style.Visibility.HIDDEN);
        style.setPosition(Style.Position.ABSOLUTE);
        style.setLeft(-5000, Style.Unit.PX);
        style.setTop(-5000, Style.Unit.PX);
    }
    // copy all relevant CSS properties
    Style style = m_elem.getStyle();
    for (DomUtil.Style attr : attributes) {
        String attrName = attr.toString();
        style.setProperty(attrName, DomUtil.getCurrentStyle(element, attr));
    }
    // append playground
    RootPanel.getBodyElement().appendChild(m_elem);
}

From source file:com.allen_sauer.gwt.dnd.client.MouseDragHandler.java

License:Apache License

private void initCapturingWidget() {
    capturingWidget = new FocusPanel();
    capturingWidget.addMouseMoveHandler(this);
    capturingWidget.addMouseUpHandler(this);
    capturingWidget.addTouchMoveHandler(this);
    capturingWidget.addTouchEndHandler(this);
    capturingWidget.addTouchCancelHandler(this);
    Style style = capturingWidget.getElement().getStyle();
    // workaround for IE8 opacity http://code.google.com/p/google-web-toolkit/issues/detail?id=5538
    style.setProperty("filter", "alpha(opacity=0)");
    style.setOpacity(0);/*from  w w  w  . j  a  v  a  2  s.  co  m*/
    style.setZIndex(1000);
    style.setMargin(0, Style.Unit.PX);
    style.setBorderStyle(BorderStyle.NONE);
    style.setBackgroundColor("blue");
}

From source file:com.cgxlib.xq.client.css.CssProperty.java

License:Apache License

protected void set(Style s, T value) {
    s.setProperty(getCssName(), value != null ? value.getCssName() : "");
}

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

License:Apache License

@Override
public void setVisible(final boolean visible) {
    Style style = container.getElement().getStyle();

    if (visible) {
        style.setDisplay(Style.Display.BLOCK);
        style.setZIndex(9999);/*from   ww w.  java 2  s .  co m*/
        style.setPosition(Style.Position.ABSOLUTE);
        style.setProperty("right", "auto");
    } else {
        super.setVisible(false);

        style.clearDisplay();
        style.clearZIndex();
        style.clearPosition();
        style.clearTop();
        style.clearLeft();
    }
}

From source file:com.extjs.gxt.ui.client.widget.treepanel.TreePanel.java

License:sencha.com license

private void ensureFocusElement() {
    if (focusEl != null) {
        focusEl.removeFromParent();//from   w  w w  . j  a v a 2 s .co  m
    }
    focusEl = new El(DOM.asOld(focusImpl.createFocusable()));
    focusEl.dom.getStyle().setProperty("outline", "none");
    getElement().appendChild(focusEl.dom);
    if (focusEl.dom.hasChildNodes()) {
        focusEl.dom.getFirstChildElement().getStyle().setProperty("outline", "none");
        com.google.gwt.dom.client.Style focusElStyle = focusEl.dom.getFirstChildElement().getStyle();
        focusElStyle.setProperty("borderWidth", "0px");
        focusElStyle.setProperty("fontSize", "1px");
        focusElStyle.setPropertyPx("lineHeight", 1);
    }
    focusEl.setLeft(0);
    focusEl.setTop(0);
    focusEl.makePositionable(true);
    focusEl.addEventsSunk(Event.FOCUSEVENTS);
}

From source file:com.google.appinventor.client.editor.simple.components.MockForm.java

License:Open Source License

private static int getVerticalScrollbarWidth() {
    // We only calculate the vertical scroll bar width once, then we store it in the static field
    // verticalScrollbarWidth. If the field is non-zero, we don't need to calculate it again.
    if (verticalScrollbarWidth == 0) {
        // The following code will calculate (on the fly) the width of a vertical scroll bar.
        // We'll create two divs, one inside the other and add the outer div to the document body,
        // but off-screen where the user won't see it.
        // We'll measure the width of the inner div twice: (first) when the outer div's vertical
        // scrollbar is hidden and (second) when the outer div's vertical scrollbar is visible.
        // The width of inner div will be smaller when outer div's vertical scrollbar is visible.
        // By subtracting the two measurements, we can calculate the width of the vertical scrollbar.

        // I used code from the following websites as reference material:
        // http://jdsharp.us/jQuery/minute/calculate-scrollbar-width.php
        // http://www.fleegix.org/articles/2006-05-30-getting-the-scrollbar-width-in-pixels

        Document document = Document.get();

        // Create an outer div.
        DivElement outerDiv = document.createDivElement();
        Style outerDivStyle = outerDiv.getStyle();
        // Use absolute positioning and set the top/left so that it is off-screen.
        // We don't want the user to see anything while we do this calculation.
        outerDivStyle.setProperty("position", "absolute");
        outerDivStyle.setProperty("top", "-1000px");
        outerDivStyle.setProperty("left", "-1000px");
        // Set the width and height of the outer div to a fixed size in pixels.
        outerDivStyle.setProperty("width", "100px");
        outerDivStyle.setProperty("height", "50px");
        // Hide the outer div's scrollbar by setting the "overflow" property to "hidden".
        outerDivStyle.setProperty("overflow", "hidden");

        // Create an inner div and put it inside the outer div.
        DivElement innerDiv = document.createDivElement();
        Style innerDivStyle = innerDiv.getStyle();
        // Set the height of the inner div to be 4 times the height of the outer div so that a
        // vertical scrollbar will be necessary (but hidden for now) on the outer div.
        innerDivStyle.setProperty("height", "200px");
        outerDiv.appendChild(innerDiv);// w  w  w .ja  va2 s .  com

        // Temporarily add the outer div to the document body. It's off-screen so the user won't
        // actually see anything.
        Element bodyElement = document.getElementsByTagName("body").getItem(0);
        bodyElement.appendChild(outerDiv);

        // Get the width of the inner div while the outer div's vertical scrollbar is hidden.
        int widthWithoutScrollbar = innerDiv.getOffsetWidth();
        // Show the outer div's vertical scrollbar by setting the "overflow" property to "auto".
        outerDivStyle.setProperty("overflow", "auto");
        // Now, get the width of the inner div while the vertical scrollbar is visible.
        int widthWithScrollbar = innerDiv.getOffsetWidth();

        // Remove the outer div from the document body.
        bodyElement.removeChild(outerDiv);

        // Calculate the width of the vertical scrollbar by subtracting the two widths.
        verticalScrollbarWidth = widthWithoutScrollbar - widthWithScrollbar;
    }

    return verticalScrollbarWidth;
}

From source file:com.google.livingstories.client.ui.AnchoredPanel.java

License:Apache License

@Override
public void setWidget(Widget widget) {
    super.setWidget(widget);
    Style style = widget.getElement().getStyle();
    style.setProperty("position", "relative");
    style.setPropertyPx("left", 0);
    style.setPropertyPx("top", 0);

    removeHandlers();/*from ww w  .j av a2 s.c  o  m*/

    scrollHandler = Window.addWindowScrollHandler(new ScrollHandler() {
        @Override
        public void onWindowScroll(ScrollEvent event) {
            reposition();
        }
    });

    resizeHandler = Window.addResizeHandler(new ResizeHandler() {
        @Override
        public void onResize(ResizeEvent event) {
            reposition();
        }
    });
}

From source file:com.google.livingstories.client.ui.AnchoredPanel.java

License:Apache License

public void reposition() {
    Widget content = getWidget();/*from ww w  .  j  a v  a2 s  .c  o  m*/
    Element boundingBox = getElement().getParentElement();
    int windowTop = Window.getScrollTop();
    int windowLeft = Window.getScrollLeft();
    int topBound = boundingBox.getAbsoluteTop();
    int bottomBound = topBound + boundingBox.getOffsetHeight() - content.getOffsetHeight();
    if (!scrolling) {
        if (windowTop > topBound && windowTop < bottomBound) {
            scrolling = true;
            Style style = content.getElement().getStyle();
            style.setProperty("position", "fixed");
            style.setPropertyPx("top", 0);
            style.setPropertyPx("left", boundingBox.getAbsoluteLeft() - windowLeft);
        }
    } else {
        if (windowTop < topBound) {
            scrolling = false;
            Style style = content.getElement().getStyle();
            style.setProperty("position", "relative");
            style.setPropertyPx("top", 0);
            style.setPropertyPx("left", 0);
        } else if (windowTop > bottomBound) {
            scrolling = false;
            Style style = content.getElement().getStyle();
            style.setProperty("position", "relative");
            // Can't use bottom:0px here because the spacer has no height.
            // Even if we set the spacer's height to be 100%, it won't necessarily
            // work if this panel is in a table cell.
            style.setPropertyPx("top", bottomBound - topBound);
            style.setPropertyPx("left", 0);
        } else {
            content.getElement().getStyle().setPropertyPx("left", boundingBox.getAbsoluteLeft() - windowLeft);
        }
    }
}