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.terminal.gwt.client.ui.TouchScrollDelegate.java

License:Open Source License

/**
 * Called at the end of scrolling. Moves possible translate values to
 * scrolltop, causing onscroll event./*w  w  w  .  jav  a  2 s. c o  m*/
 */
private void moveTransformationToScrolloffset() {
    for (Element el : layers) {
        Style style = el.getStyle();
        style.setProperty("webkitTransitionProperty", "none");
        style.setProperty("webkitTransform", "translate3d(0,0,0)");
    }
    scrolledElement.setScrollTop(finalScrollTop);
    activeScrollDelegate = null;
    handlerRegistration.removeHandler();
    handlerRegistration = null;

}

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

License:Open Source License

/**
 * Note positive scrolltop moves layer up, positive translate moves layer
 * down./*from  w w w.  j av a  2 s  . co  m*/
 * 
 * @param duration
 * @param translateY
 */
private void translateTo(int duration, int translateY) {
    for (Element el : layers) {
        final Style style = el.getStyle();
        if (duration > 0) {
            style.setProperty("webkitTransitionDuration", duration + "ms");
            style.setProperty("webkitTransitionTimingFunction", "cubic-bezier(0,0,0.25,1)");
            style.setProperty("webkitTransitionProperty", "-webkit-transform");
            transitionOn = true;
            transitionStart = new Date();
            transitionDuration = new Date();
        } else {
            style.setProperty("webkitTransitionProperty", "none");
        }
        style.setProperty("webkitTransform", "translate3d(0px," + translateY + "px,0px)");
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VEmbedded.java

License:Open Source License

public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    if (client.updateComponent(this, uidl, true)) {
        return;//from  ww w.j a va  2  s.  c  o m
    }
    this.client = client;

    boolean clearBrowserElement = true;

    clickEventHandler.handleEventHandlerRegistration(client);

    if (uidl.hasAttribute("type")) {
        type = uidl.getStringAttribute("type");
        if (type.equals("image")) {
            addStyleName(CLASSNAME + "-image");
            Element el = null;
            boolean created = false;
            NodeList<Node> nodes = 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) {
                setHTML("");
                el = DOM.createImg();
                created = true;
                DOM.sinkEvents(el, Event.ONLOAD);
            }

            // Set attributes
            Style style = el.getStyle();
            String w = uidl.getStringAttribute("width");
            if (w != null) {
                style.setProperty("width", w);
            } else {
                style.setProperty("width", "");
            }
            String h = uidl.getStringAttribute("height");
            if (h != null) {
                style.setProperty("height", h);
            } else {
                style.setProperty("height", "");
            }
            DOM.setElementProperty(el, "src", getSrc(uidl, client));

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

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

        } else if (type.equals("browser")) {
            addStyleName(CLASSNAME + "-browser");
            if (browserElement == null) {
                setHTML("<iframe width=\"100%\" height=\"100%\" frameborder=\"0\""
                        + " allowTransparency=\"true\" src=\"\"" + " name=\"" + uidl.getId() + "\"></iframe>");
                browserElement = DOM.getFirstChild(getElement());
            }
            DOM.setElementAttribute(browserElement, "src", getSrc(uidl, client));
            clearBrowserElement = false;
        } else {
            VConsole.log("Unknown Embedded type '" + type + "'");
        }
    } else if (uidl.hasAttribute("mimetype")) {
        final String mime = uidl.getStringAttribute("mimetype");
        if (mime.equals("application/x-shockwave-flash")) {
            // Handle embedding of Flash
            addStyleName(CLASSNAME + "-flash");
            setHTML(createFlashEmbed(uidl));

        } else if (mime.equals("image/svg+xml")) {
            addStyleName(CLASSNAME + "-svg");
            String data;
            Map<String, String> parameters = getParameters(uidl);
            if (parameters.get("data") == null) {
                data = getSrc(uidl, client);
            } else {
                data = "data:image/svg+xml," + parameters.get("data");
            }
            setHTML("");
            ObjectElement obj = Document.get().createObjectElement();
            obj.setType(mime);
            obj.setData(data);
            if (width != null) {
                obj.getStyle().setProperty("width", "100%");
            }
            if (height != null) {
                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"));
            }
            getElement().appendChild(obj);

        } else {
            VConsole.log("Unknown Embedded mimetype '" + mime + "'");
        }
    } else {
        VConsole.log("Unknown Embedded; no type or mimetype attribute");
    }

    if (clearBrowserElement) {
        browserElement = null;
    }
}

From source file:com.vaadin.terminal.gwt.client.ui.VTabsheet.java

License:Open Source License

private void updateDynamicWidth() {
    // Find width consumed by tabs
    TableCellElement spacerCell = ((TableElement) tb.getElement().cast()).getRows().getItem(0).getCells()
            .getItem(tb.getTabCount());/*from  w w w .  ja v  a2  s.  c  o  m*/

    int spacerWidth = spacerCell.getOffsetWidth();
    DivElement div = (DivElement) spacerCell.getFirstChildElement();

    int spacerMinWidth = spacerCell.getOffsetWidth() - div.getOffsetWidth();

    int tabsWidth = tb.getOffsetWidth() - spacerWidth + spacerMinWidth;

    // Find content width
    Style style = tp.getElement().getStyle();
    String overflow = style.getProperty("overflow");
    style.setProperty("overflow", "hidden");
    style.setPropertyPx("width", tabsWidth);

    boolean hasTabs = tp.getWidgetCount() > 0;

    Style wrapperstyle = null;
    if (hasTabs) {
        wrapperstyle = tp.getWidget(tp.getVisibleWidget()).getElement().getParentElement().getStyle();
        wrapperstyle.setPropertyPx("width", tabsWidth);
    }
    // Get content width from actual widget

    int contentWidth = 0;
    if (hasTabs) {
        contentWidth = tp.getWidget(tp.getVisibleWidget()).getOffsetWidth();
    }
    style.setProperty("overflow", overflow);

    // Set widths to max(tabs,content)
    if (tabsWidth < contentWidth) {
        tabsWidth = contentWidth;
    }

    int outerWidth = tabsWidth + getContentAreaBorderWidth();

    tabs.getStyle().setPropertyPx("width", outerWidth);
    style.setPropertyPx("width", tabsWidth);
    if (hasTabs) {
        wrapperstyle.setPropertyPx("width", tabsWidth);
    }

    contentNode.getStyle().setPropertyPx("width", tabsWidth);
    super.setWidth(outerWidth + "px");
    updateOpenTabSize();
}

From source file:com.vaadin.terminal.gwt.client.ui.VTabsheet.java

License:Open Source License

/**
 * Layouts the tab-scroller elements, and applies styles.
 *//*from w  w w  .j  a v a  2 s.com*/
private void updateTabScroller() {
    if (width != null) {
        DOM.setStyleAttribute(tabs, "width", width);
    }

    // Make sure scrollerIndex is valid
    if (scrollerIndex < 0 || scrollerIndex > tb.getTabCount()) {
        scrollerIndex = tb.getFirstVisibleTab();
    } else if (tb.getTabCount() > 0 && tb.getTab(scrollerIndex).isHiddenOnServer()) {
        scrollerIndex = tb.getNextVisibleTab(scrollerIndex);
    }

    boolean scrolled = isScrolledTabs();
    boolean clipped = isClippedTabs();
    if (tb.getTabCount() > 0 && tb.isVisible() && (scrolled || clipped)) {
        DOM.setStyleAttribute(scroller, "display", "");
        DOM.setElementProperty(scrollerPrev, "className",
                SCROLLER_CLASSNAME + (scrolled ? "Prev" : "Prev-disabled"));
        DOM.setElementProperty(scrollerNext, "className",
                SCROLLER_CLASSNAME + (clipped ? "Next" : "Next-disabled"));
    } else {
        DOM.setStyleAttribute(scroller, "display", "none");
    }

    if (BrowserInfo.get().isSafari()) {
        // fix tab height for safari, bugs sometimes if tabs contain icons
        String property = tabs.getStyle().getProperty("height");
        if (property == null || property.equals("")) {
            tabs.getStyle().setPropertyPx("height", tb.getOffsetHeight());
        }
        /*
         * another hack for webkits. tabscroller sometimes drops without
         * "shaking it" reproducable in
         * com.vaadin.tests.components.tabsheet.TabSheetIcons
         */
        final Style style = scroller.getStyle();
        style.setProperty("whiteSpace", "normal");
        Scheduler.get().scheduleDeferred(new Command() {
            public void execute() {
                style.setProperty("whiteSpace", "");
            }
        });
    }

}

From source file:com.vaadin.terminal.gwt.client.Util.java

License:Open Source License

/**
 * Temporarily sets the {@code styleProperty} to {@code tempValue} and then
 * resets it to its current value. Used mainly to work around rendering
 * issues in IE (and possibly in other browsers)
 * /* w  w  w  .  j av a  2s  .c om*/
 * @param element
 *            The target element
 * @param styleProperty
 *            The name of the property to set
 * @param tempValue
 *            The temporary value
 */
public static void setStyleTemporarily(Element element, final String styleProperty, String tempValue) {
    final Style style = element.getStyle();
    final String currentValue = style.getProperty(styleProperty);

    style.setProperty(styleProperty, tempValue);
    element.getOffsetWidth();
    style.setProperty(styleProperty, currentValue);

}

From source file:cz.filmtit.client.subgestbox.PosteditBox.java

License:Open Source License

public PosteditBox(TimedChunk chunk, TranslationWorkspace workspace, int tabIndex) {
    this.chunk = chunk;
    this.workspace = workspace;
    if (this.workspace == null) {
        Gui.log("workspace for subgestbox is null!!!");
    }/*w w w .  j  av a 2 s  .  co  m*/

    this.subgestBox = null;

    this.setHeight("36px");
    this.setHTML(posteditBoxHTML(""));

    this.addFocusHandler(this.workspace.posteditHandler);
    this.addKeyDownHandler(this.workspace.posteditHandler);
    this.addKeyUpHandler(this.workspace.posteditHandler);
    this.setTabIndex(tabIndex);

    this.addStyleName("posteditwidth");

    final RichTextArea richtext = this;
    richtext.addInitializeHandler(new InitializeHandler() {
        public void onInitialize(InitializeEvent ie) {
            IFrameElement fe = (IFrameElement) richtext.getElement().cast();
            Style s = fe.getContentDocument().getBody().getStyle();
            s.setProperty("fontFamily", "Arial Unicode MS,Arial,sans-serif");
            s.setProperty("fontSize", "small");
            s.setColor("#333");
        }
    });
}

From source file:cz.filmtit.client.subgestbox.SubgestBox.java

License:Open Source License

/**
 * Primary constructor for the SubgestBox.
 *
 * @param chunk - the source chunk of the underlying TranslationResult
 * @param workspace - the TranslationWorkspace in which this SubgestBox
 * operates//from w  w w .j  ava2s.c  o m
 * @param tabIndex - intended tabIndex within the workspace
 */
public SubgestBox(TimedChunk chunk, TranslationWorkspace workspace, int tabIndex) {
    this.chunk = chunk;
    this.translationResult = new TranslationResult(chunk);
    this.workspace = workspace;
    if (this.workspace == null) {
        Gui.log("workspace for subgestbox is null!!!");
    }

    this.posteditBox = null;

    this.setHeight("36px");
    this.setHTML(subgestBoxHTML(""));

    this.addFocusHandler(this.workspace.subgestHandler);
    this.addKeyDownHandler(this.workspace.subgestHandler);
    this.addKeyUpHandler(this.workspace.subgestHandler);
    this.setTabIndex(tabIndex);

    if (workspace.isPosteditOn()) {
        this.addStyleName("posteditwidth");
    } else {
        this.addStyleName("subgest_fullwidth");
    }

    final RichTextArea richtext = this;
    richtext.addInitializeHandler(new InitializeHandler() {
        public void onInitialize(InitializeEvent ie) {
            IFrameElement fe = (IFrameElement) richtext.getElement().cast();
            Style s = fe.getContentDocument().getBody().getStyle();
            s.setProperty("fontFamily", "Arial Unicode MS,Arial,sans-serif");
            s.setProperty("fontSize", "small");
            s.setColor("#333");
        }
    });

}

From source file:de.eckhartarnold.client.Fade.java

License:Apache License

/**
 * Sets the opacity (i.e. translucency) of a widget to a specified value
 * between 0.0 (invisible) and 1.0 (fully visible, i.e. not translucent).
 * @param widget  the widget the opacity of which is to be changed
 * @param opacity the opacity value ranging from 0.0 to 1.0
 */// w w  w  .  j  a v a2s  .  c  o  m
public static void setOpacity(Widget widget, double opacity) {
    assert opacity >= 0.0 && opacity <= 1.0;

    Style style = widget.getElement().getStyle();
    String opStr = String.valueOf(opacity);
    String ieOpStr = String.valueOf((int) (opacity * 100 + 0.5));

    style.setProperty("opacity", opStr);
    style.setProperty("MozOpacity", opStr);
    style.setProperty("KhtmlOpacity", opStr);
    style.setProperty("filter", "alpha(opacity=" + ieOpStr + ")");
}

From source file:forplay.html.HtmlImageLayerDom.java

License:Apache License

private void applyBackgroundSize() {
    Style style = element().getStyle();

    // Set background-repeat to get the right repeating behavior.
    String repeat = repeatX ? "repeat-x " : "";
    repeat += repeatY ? "repeat-y" : "";
    style.setProperty("backgroundRepeat", repeat);

    // Set background-size to get the right pinning behavior.
    if (sourceRectSet) {
        float wratio = widthSet ? (width / sw) : (image().width() / sw);
        float hratio = heightSet ? (height / sh) : (image().height() / sh);
        if (wratio == 0) {
            wratio = 1;//  w  ww  .  j  a va 2s.  c  o  m
        }
        if (hratio == 0) {
            hratio = 1;
        }
        float backWidth = image().width() * wratio;
        float backHeight = image().height() * hratio;

        style.setProperty("backgroundSize", backWidth + "px " + backHeight + "px");
        style.setProperty("backgroundPosition", (-sx * wratio) + "px " + (-sy * hratio) + "px");
    } else {
        String size = repeatX ? image().width() + "px " : "100% ";
        size += repeatY ? image().height() + "px" : "100%";
        style.setProperty("backgroundSize", size);
        style.clearProperty("backgroundPosition");
    }
}