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:com.vaadin.client.AnimationUtil.java

License:Apache License

/**
 * For internal use only. May be removed or replaced in the future.
 * //from   w  w w . j av  a2s.  c o m
 * Set the animation-delay CSS property.
 * 
 * @param elem
 *            the element whose animation-delay to set
 * @param delay
 *            the delay as a valid CSS value
 */
public static void setAnimationDelay(Element elem, String delay) {
    Style style = elem.getStyle();
    style.setProperty(ANIMATION_PROPERTY_NAME + "Delay", delay);
}

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 ww  .  j  a  va2  s .  com
 * 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.metadata.ConnectorBundleLoader.java

License:Apache License

private void notice(String productName) {
    if (notice == null) {
        notice = new HTML();
        notice.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                notice.removeFromParent();
            }/* w w w  .jav a2  s.c om*/
        });
        notice.addTouchStartHandler(new TouchStartHandler() {
            public void onTouchStart(TouchStartEvent event) {
                notice.removeFromParent();
            }
        });
    }
    String msg = notice.getText().trim();
    msg += msg.isEmpty() ? "Using Evaluation License of: " : ", ";
    notice.setText(msg + productName);
    RootPanel.get().add(notice);

    notice.getElement().setClassName("");
    Style s = notice.getElement().getStyle();

    s.setPosition(Position.FIXED);
    s.setTextAlign(TextAlign.CENTER);
    s.setRight(0, Unit.PX);
    s.setLeft(0, Unit.PX);
    s.setBottom(0, Unit.PX);
    s.setProperty("padding", "0.5em 1em");

    s.setProperty("font-family", "sans-serif");
    s.setFontSize(12, Unit.PX);
    s.setLineHeight(1.1, Unit.EM);

    s.setColor("white");
    s.setBackgroundColor("black");
    s.setOpacity(0.7);

    s.setZIndex(2147483646);
    s.setProperty("top", "auto");
    s.setProperty("width", "auto");
    s.setDisplay(Display.BLOCK);
    s.setWhiteSpace(WhiteSpace.NORMAL);
    s.setVisibility(Visibility.VISIBLE);
    s.setMargin(0, Unit.PX);
}

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  w  w  w. ja va2s .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.csslayout.CssLayoutConnector.java

License:Apache License

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

    for (ComponentConnector child : getChildComponents()) {
        if (!getState().childCss.containsKey(child)) {
            continue;
        }/*ww w  .j ava2 s.c  o m*/
        String css = getState().childCss.get(child);
        Style style = child.getWidget().getElement().getStyle();
        // should we remove styles also? How can we know what we have added
        // as it is added directly to the child component?
        String[] cssRules = css.split(";");
        for (String cssRule : cssRules) {
            String parts[] = cssRule.split(":", 2);
            if (parts.length == 2) {
                style.setProperty(makeCamelCase(parts[0].trim()), parts[1].trim());
            }
        }
    }

}

From source file:com.vaadin.client.ui.embedded.EmbeddedConnector.java

License:Apache License

@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    if (!isRealUpdate(uidl)) {
        return;//from   w ww.  j a va2 s.c o m
    }

    // Save details
    getWidget().client = client;

    boolean clearBrowserElement = true;

    clickEventHandler.handleEventHandlerRegistration();

    if (uidl.hasAttribute("type")) {
        // remove old style name related to type
        if (getWidget().type != null) {
            getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().type);
        }
        // remove old style name related to mime type
        if (getWidget().mimetype != null) {
            getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().mimetype);
        }
        getWidget().type = uidl.getStringAttribute("type");
        if (getWidget().type.equals("image")) {
            getWidget().addStyleName(VEmbedded.CLASSNAME + "-image");
            Element el = null;
            boolean created = false;
            NodeList<Node> nodes = getWidget().getElement().getChildNodes();
            if (nodes != null && nodes.getLength() == 1) {
                Node n = nodes.getItem(0);
                if (n.getNodeType() == Node.ELEMENT_NODE) {
                    Element e = (Element) n;
                    if (e.getTagName().equals("IMG")) {
                        el = e;
                    }
                }
            }
            if (el == null) {
                getWidget().setHTML("");
                el = DOM.createImg();
                created = true;
                DOM.sinkEvents(el, Event.ONLOAD);
            }

            // Set attributes
            Style style = el.getStyle();
            style.setProperty("width", getState().width);
            style.setProperty("height", getState().height);

            resourceElement = el;
            objectElement = null;
            setResourceUrl(getResourceUrl("src"));

            if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
                el.setPropertyString(EmbeddedConstants.ALTERNATE_TEXT,
                        uidl.getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT));
            }

            if (created) {
                // insert in dom late
                getWidget().getElement().appendChild(el);
            }

            /*
             * Sink tooltip events so tooltip is displayed when hovering the
             * image.
             */
            getWidget().sinkEvents(VTooltip.TOOLTIP_EVENTS);

        } else if (getWidget().type.equals("browser")) {
            getWidget().addStyleName(VEmbedded.CLASSNAME + "-browser");
            if (getWidget().browserElement == null) {
                getWidget().setHTML("<iframe width=\"100%\" height=\"100%\" frameborder=\"0\""
                        + " allowTransparency=\"true\" src=\"\"" + " name=\"" + uidl.getId() + "\"></iframe>");
                getWidget().browserElement = DOM.getFirstChild(getWidget().getElement());
            }
            resourceElement = getWidget().browserElement;
            objectElement = null;
            setResourceUrl(getResourceUrl("src"));
            clearBrowserElement = false;
        } else {
            VConsole.error("Unknown Embedded type '" + getWidget().type + "'");
        }
    } else if (uidl.hasAttribute("mimetype")) {
        // remove old style name related to type
        if (getWidget().type != null) {
            getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().type);
        }
        // remove old style name related to mime type
        if (getWidget().mimetype != null) {
            getWidget().removeStyleName(VEmbedded.CLASSNAME + "-" + getWidget().mimetype);
        }
        final String mime = uidl.getStringAttribute("mimetype");
        if (mime.equals("application/x-shockwave-flash")) {
            getWidget().mimetype = "flash";
            // Handle embedding of Flash
            getWidget().addStyleName(VEmbedded.CLASSNAME + "-flash");
            getWidget().setHTML(getWidget().createFlashEmbed(uidl));

        } else if (mime.equals("image/svg+xml")) {
            getWidget().mimetype = "svg";
            getWidget().addStyleName(VEmbedded.CLASSNAME + "-svg");
            String data;
            Map<String, String> parameters = VEmbedded.getParameters(uidl);
            ObjectElement obj = Document.get().createObjectElement();
            resourceElement = null;
            if (parameters.get("data") == null) {
                objectElement = obj;
                data = getResourceUrl("src");
                setResourceUrl(data);
            } else {
                objectElement = null;
                data = "data:image/svg+xml," + parameters.get("data");
                obj.setData(data);
            }
            getWidget().setHTML("");
            obj.setType(mime);
            if (!isUndefinedWidth()) {
                obj.getStyle().setProperty("width", "100%");
            }
            if (!isUndefinedHeight()) {
                obj.getStyle().setProperty("height", "100%");
            }
            if (uidl.hasAttribute("classid")) {
                obj.setAttribute("classid", uidl.getStringAttribute("classid"));
            }
            if (uidl.hasAttribute("codebase")) {
                obj.setAttribute("codebase", uidl.getStringAttribute("codebase"));
            }
            if (uidl.hasAttribute("codetype")) {
                obj.setAttribute("codetype", uidl.getStringAttribute("codetype"));
            }
            if (uidl.hasAttribute("archive")) {
                obj.setAttribute("archive", uidl.getStringAttribute("archive"));
            }
            if (uidl.hasAttribute("standby")) {
                obj.setAttribute("standby", uidl.getStringAttribute("standby"));
            }
            getWidget().getElement().appendChild(obj);
            if (uidl.hasAttribute(EmbeddedConstants.ALTERNATE_TEXT)) {
                obj.setInnerText(uidl.getStringAttribute(EmbeddedConstants.ALTERNATE_TEXT));
            }
        } else {
            VConsole.error("Unknown Embedded mimetype '" + mime + "'");
        }
    } else {
        VConsole.error("Unknown Embedded; no type or mimetype attribute");
    }

    if (clearBrowserElement) {
        getWidget().browserElement = null;
    }
}

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

License:Apache License

public FocusableScrollPanel() {
    // Prevent IE standard mode bug when a AbsolutePanel is contained.
    TouchScrollDelegate.enableTouchScrolling(this, getElement());
    Style style = getElement().getStyle();
    style.setProperty("zoom", "1");
    style.setPosition(Position.RELATIVE);
    browserInfo = BrowserInfo.get();/*from w ww.ja v a  2  s  .c o  m*/
}

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

License:Apache License

/**
 * Sets the vertical scroll position./*from   w  w  w  . j a  va2s  .  co m*/
 * 
 * @param position
 *            the new vertical scroll position, in pixels
 */
public void setScrollPosition(int position) {
    if (BrowserInfo.get().isAndroidWithBrokenScrollTop() && BrowserInfo.get().requiresTouchScrollDelegate()) {
        ArrayList<com.google.gwt.dom.client.Element> elements = TouchScrollDelegate.getElements(getElement());
        for (com.google.gwt.dom.client.Element el : elements) {
            final Style style = el.getStyle();
            style.setProperty("webkitTransform", "translate3d(0px," + -position + "px,0px)");
        }
        getElement().setPropertyInt("_vScrollTop", position);
    } else {
        getElement().setScrollTop(position);
    }
}

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

License:Apache License

/**
 * Called at the end of scrolling. Moves possible translate values to
 * scrolltop, causing onscroll event./*from www . j a  v a2  s  . c o  m*/
 */
private void moveTransformationToScrolloffset() {
    if (androidWithBrokenScrollTop) {
        scrolledElement.setPropertyInt("_vScrollTop", finalScrollTop);
        if (scrollHandler != null) {
            scrollHandler.onScroll(null);
        }
    } else {
        for (Element el : layers) {
            Style style = el.getStyle();
            style.setProperty("webkitTransform", "translate3d(0,0,0)");
        }
        scrolledElement.setScrollTop(finalScrollTop);
    }
    activeScrollDelegate = null;
    handlerRegistration.removeHandler();
    handlerRegistration = null;
}

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

License:Apache License

/**
 * Note positive scrolltop moves layer up, positive translate moves layer
 * down./*  ww  w.ja v a  2s  .  c om*/
 */
private void translateTo(double translateY) {
    for (Element el : layers) {
        Style style = el.getStyle();
        style.setProperty("webkitTransform", "translate3d(0px," + translateY + "px,0px)");
    }
}