Example usage for com.google.gwt.user.client.ui Widget setStyleName

List of usage examples for com.google.gwt.user.client.ui Widget setStyleName

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Widget setStyleName.

Prototype

public void setStyleName(String style) 

Source Link

Document

Clears all of the object's style names and sets it to the given style.

Usage

From source file:com.sun.labs.aura.dbbrowser.client.viz.Util.java

License:Open Source License

public static HorizontalPanel getHisto(String name, int value, int maxValue, int maxWidth, String text) {

    int leftWidth = Math.round(((float) value / (float) maxValue) * (float) maxWidth);
    if (leftWidth < 1) {
        leftWidth = 1;/*w ww.j  a v  a2 s.  c o m*/
    } else if (leftWidth > maxWidth) {
        leftWidth = maxWidth;
    }
    int rightWidth = maxWidth - leftWidth;
    boolean alert = false;
    if (value / (float) maxValue > 0.75) {
        alert = true;
    }

    HorizontalPanel all = new HorizontalPanel();
    all.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    all.add(new StyleLabel(name + ":", "viz-histoName"));

    HorizontalPanel table = new HorizontalPanel();
    table.setWidth(maxWidth + "px");
    table.setBorderWidth(0);
    table.setSpacing(0);

    Widget left = new Label("");
    if (alert) {
        left.setStyleName("viz-histoLeftAlert");
    } else {
        left.setStyleName("viz-histoLeft");
    }
    left.setWidth(leftWidth + "");
    left.setHeight("10px");
    left.getElement().getStyle().setPropertyPx("fontSize", 6);

    Widget right = new Label("");
    if (alert) {
        right.setStyleName("viz-histoRightAlert");
    } else {
        right.setStyleName("viz-histoRight");
    }
    right.setWidth(rightWidth + "");
    right.setHeight("10px");
    right.getElement().getStyle().setPropertyPx("fontSize", 6);

    table.add(left);
    table.add(right);
    all.add(table);
    all.add(new StyleLabel(text, "viz-histoText"));
    return all;
}

From source file:com.sun.labs.aura.music.wsitm.client.ui.swidget.SimpleSearchSwidget.java

License:Open Source License

/**
 * Child method of invokeArtistSearchService
 * @param sr/*from   w  ww.j  a v a 2  s  .co  m*/
 */
private void searchResultsToArtistList(SearchResults sr) {
    showTopMessage("Found " + sr.getItemResults(cdm).length + " matches");
    Widget searchResults = getItemInfoList("Pick one: ", sr.getItemResults(cdm), null, true, true,
            cdm.getArtistOracle());
    searchResults.setStyleName("searchResults");
    searchResults.setWidth("300px");
    setResults(sr.toString(), searchResults);
}

From source file:com.sun.labs.aura.music.wsitm.client.WebLib.java

License:Open Source License

/**
 * Returns a populatiry histrogram. To get it wrapped with a title, use other
 * utility functions getSmallPopularityWidget() or getPopularityWidget()
 * @param normPopularity popularity as a number between 0 and 1
 * @param log plot on log scale/*w ww . j  a  v a 2  s  .c o m*/
 * @param height maximum size of 15
 * @param maxWidth
 * @return
 */
public static HorizontalPanel getPopularityHisto(double normPopularity, boolean log, int height, int maxWidth) {

    if (log) {
        normPopularity = Math.log(normPopularity + 1) / Math.log(2); // get the base 2 log
    }
    int leftWidth = (int) (normPopularity * maxWidth);
    if (leftWidth < 1) {
        leftWidth = 1;
    } else if (leftWidth > maxWidth) {
        leftWidth = maxWidth;
    }
    int rightWidth = maxWidth - leftWidth;

    HorizontalPanel table = new HorizontalPanel();
    table.setWidth(maxWidth + "px");
    table.setBorderWidth(0);
    table.setSpacing(0);

    Widget left = new Label("");
    left.setStyleName("popLeft");
    left.setWidth(leftWidth + "");
    left.setHeight(height + "px");
    left.getElement().getStyle().setPropertyPx("fontSize", height - 2);

    Widget right = new Label("");
    right.setStyleName("popRight");
    right.setWidth(rightWidth + "");
    right.setHeight(height + "px");
    right.getElement().getStyle().setPropertyPx("fontSize", height - 2);

    table.add(left);
    table.add(right);

    return table;
}

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

License:Open Source License

/**
 * Update generic component features.//from ww w  .  j  av  a  2s . c o m
 * 
 * <h2>Selecting correct implementation</h2>
 * 
 * <p>
 * The implementation of a component depends on many properties, including
 * styles, component features, etc. Sometimes the user changes those
 * properties after the component has been created. Calling this method in
 * the beginning of your updateFromUIDL -method automatically replaces your
 * component with more appropriate if the requested implementation changes.
 * </p>
 * 
 * <h2>Caption, icon, error messages and description</h2>
 * 
 * <p>
 * Component can delegate management of caption, icon, error messages and
 * description to parent layout. This is optional an should be decided by
 * component author
 * </p>
 * 
 * <h2>Component visibility and disabling</h2>
 * 
 * This method will manage component visibility automatically and if
 * component is an instanceof FocusWidget, also handle component disabling
 * when needed.
 * 
 * @param component
 *            Widget to be updated, expected to implement an instance of
 *            Paintable
 * @param uidl
 *            UIDL to be painted
 * @param manageCaption
 *            True if you want to delegate caption, icon, description and
 *            error message management to parent.
 * 
 * @return Returns true iff no further painting is needed by caller
 */
public boolean updateComponent(Widget component, UIDL uidl, boolean manageCaption) {
    String pid = getPid(component.getElement());
    if (pid == null) {
        VConsole.error("Trying to update an unregistered component: " + Util.getSimpleName(component));
        return true;
    }

    ComponentDetail componentDetail = idToPaintableDetail.get(pid);

    if (componentDetail == null) {
        VConsole.error("ComponentDetail not found for " + Util.getSimpleName(component) + " with PID " + pid
                + ". This should not happen.");
        return true;
    }

    // If the server request that a cached instance should be used, do
    // nothing
    if (uidl.getBooleanAttribute("cached")) {
        return true;
    }

    // register the listened events by the server-side to the event-handler
    // of the component
    componentDetail.registerEventListenersFromUIDL(uidl);

    // Visibility
    boolean visible = !uidl.getBooleanAttribute("invisible");
    boolean wasVisible = component.isVisible();
    component.setVisible(visible);
    if (wasVisible != visible) {
        // Changed invisibile <-> visible
        if (wasVisible && manageCaption) {
            // Must hide caption when component is hidden
            final Container parent = Util.getLayout(component);
            if (parent != null) {
                parent.updateCaption((Paintable) component, uidl);
            }

        }
    }

    if (configuration.useDebugIdInDOM() && uidl.getId().startsWith("PID_S")) {
        DOM.setElementProperty(component.getElement(), "id", uidl.getId().substring(5));
    }

    if (!visible) {
        // component is invisible, delete old size to notify parent, if
        // later make visible
        componentDetail.setOffsetSize(null);
        return true;
    }

    // Switch to correct implementation if needed
    if (!widgetSet.isCorrectImplementation(component, uidl, configuration)) {
        final Widget w = (Widget) widgetSet.createWidget(uidl, configuration);
        // deferred binding check TODO change isCorrectImplementation to use
        // stored detected class, making this innecessary
        if (w.getClass() != component.getClass()) {
            final Container parent = Util.getLayout(component);
            if (parent != null) {
                parent.replaceChildComponent(component, w);
                unregisterPaintable((Paintable) component);
                registerPaintable(uidl.getId(), (Paintable) w);
                ((Paintable) w).updateFromUIDL(uidl, this);
                return true;
            }
        }
    }

    boolean enabled = !uidl.getBooleanAttribute("disabled");
    if (uidl.hasAttribute("tabindex") && component instanceof Focusable) {
        ((Focusable) component).setTabIndex(uidl.getIntAttribute("tabindex"));
    }
    /*
     * Disabled state may affect (override) tabindex so the order must be
     * first setting tabindex, then enabled state.
     */
    if (component instanceof FocusWidget) {
        FocusWidget fw = (FocusWidget) component;
        fw.setEnabled(enabled);
    }

    StringBuffer styleBuf = new StringBuffer();
    final String primaryName = component.getStylePrimaryName();
    styleBuf.append(primaryName);

    // first disabling and read-only status
    if (!enabled) {
        styleBuf.append(" ");
        styleBuf.append(DISABLED_CLASSNAME);
    }
    if (uidl.getBooleanAttribute("readonly")) {
        styleBuf.append(" ");
        styleBuf.append("v-readonly");
    }

    // add additional styles as css classes, prefixed with component default
    // stylename
    if (uidl.hasAttribute("style")) {
        final String[] styles = uidl.getStringAttribute("style").split(" ");
        for (int i = 0; i < styles.length; i++) {
            styleBuf.append(" ");
            styleBuf.append(primaryName);
            styleBuf.append("-");
            styleBuf.append(styles[i]);
            styleBuf.append(" ");
            styleBuf.append(styles[i]);
        }
    }

    // add modified classname to Fields
    if (uidl.hasAttribute("modified") && component instanceof Field) {
        styleBuf.append(" ");
        styleBuf.append(MODIFIED_CLASSNAME);
    }

    TooltipInfo tooltipInfo = componentDetail.getTooltipInfo(null);
    // Update tooltip
    if (uidl.hasAttribute(ATTRIBUTE_DESCRIPTION)) {
        tooltipInfo.setTitle(uidl.getStringAttribute(ATTRIBUTE_DESCRIPTION));
    } else {
        tooltipInfo.setTitle(null);
    }

    // add error classname to components w/ error
    if (uidl.hasAttribute(ATTRIBUTE_ERROR)) {
        tooltipInfo.setErrorUidl(uidl.getErrors());
        styleBuf.append(" ");
        styleBuf.append(primaryName);
        styleBuf.append(ERROR_CLASSNAME_EXT);
    } else {
        tooltipInfo.setErrorUidl(null);
    }

    // add required style to required components
    if (uidl.hasAttribute("required")) {
        styleBuf.append(" ");
        styleBuf.append(primaryName);
        styleBuf.append(REQUIRED_CLASSNAME_EXT);
    }

    // Styles + disabled & readonly
    component.setStyleName(styleBuf.toString());

    // Set captions
    if (manageCaption) {
        final Container parent = Util.getLayout(component);
        if (parent != null) {
            parent.updateCaption((Paintable) component, uidl);
        }
    }
    /*
     * updateComponentSize need to be after caption update so caption can be
     * taken into account
     */

    updateComponentSize(componentDetail, uidl);

    return false;
}

From source file:com.ziroby.dmassist.gwt.client.MainPanel.java

License:GNU General Public License

private void createFooter() {
    footer = new HorizontalPanel();

    Anchor aboutLink = new Anchor("About");
    aboutLink.setStyleName("hyperlink");
    aboutLink.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            displayAboutBox();//from   w  w w.j  a v  a  2  s. co m
        }
    });

    footer.add(aboutLink);
    Widget gplLink = new Anchor("GPL", "http://www.gnu.org/licenses/gpl.html");
    gplLink.setStyleName("hyperlink");
    footer.add(gplLink);
    Widget oglLink = new Anchor("OGL", "http://www.opengamingfoundation.org/ogl.html");
    oglLink.setStyleName("hyperlink");
    footer.add(oglLink);

    footer.setStyleName("footer");

}

From source file:com.ziroby.dmassist.gwt.client.MainPanel.java

License:GNU General Public License

private Widget createInitCount() {
    Panel panel = new FlowPanel();

    Widget label = new Label("Init Count");
    panel.add(label);/*from   ww w .  j a  v a2  s  .co m*/

    final Label initCountLabel = new Label("-");
    initCountLabel.setStyleName("initBox");
    initCountLabel.setWidth("3em");
    panel.add(initCountLabel);

    label.setStyleName("initLabel");
    initCountLabel.setStyleName("initBox");
    panel.setStyleName("initPanel");

    entityList.addListener(new Listener() {
        public void objectChanged(ObjectEvent event) {
            Integer initCount = entityList.getInitCount();
            initCountLabel.setText((initCount == null) ? "-" : initCount.toString());
        }
    });

    return panel;
}

From source file:edu.caltech.ipac.firefly.core.layout.AbstractLayoutManager.java

protected Region makeSearchTitle() {
    BaseRegion r = new BaseRegion(SEARCH_TITLE_REGION);
    Widget w = r.getDisplay();
    w.setStyleName("result-title");
    w.setWidth("100%");
    return r;/*  w  w  w  . j a  va  2s  .co  m*/
}

From source file:edu.caltech.ipac.firefly.core.layout.AbstractLayoutManager.java

protected Region makeSearchDesc() {
    BaseRegion r = new BaseRegion(SEARCH_DESC_REGION);
    Widget w = r.getDisplay();
    w.setStyleName("result-desc");
    w.setWidth("100%");
    return r;//from   w w  w . j a  va 2  s  . com
}

From source file:edu.caltech.ipac.firefly.ui.BadgeButton.java

public static Widget makeBadge(int cnt) {
    Widget badge = new HTML(cnt + "");
    badge.setStyleName("firefly-v2-badge");
    if (cnt > 9) {
        badge.addStyleName("firefly-v2-badge-2-digit");
    } else {//from w ww  .j  av  a2  s . com
        badge.addStyleName("firefly-v2-badge-1-digit");

    }
    return badge;
}

From source file:edu.caltech.ipac.firefly.ui.PopupUtil.java

private static Widget makeMsg(Widget w, String msgStyle, boolean makeScrollArea) {
    SimplePanel panel = new SimplePanel();
    DOM.setStyleAttribute(panel.getElement(), "fontSize", "120%");
    panel.setWidget(w);//  w w  w  . j  a v  a  2 s .co  m
    w.setStyleName(msgStyle);
    return makeScrollArea ? new ScrollPanel(panel) : panel;

}