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

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

Introduction

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

Prototype

public void addStyleName(String style) 

Source Link

Document

Adds a secondary or dependent style name to this object.

Usage

From source file:com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.java

License:sencha.com license

@Override
protected void doLayout() {
    Size size = getElement().getStyleSize();

    if (GXTLogConfiguration.loggingIsEnabled()) {
        logger.finest(getId() + " doLayout  size: " + size);
    }//  w  w w.j  a v a 2s. c  o  m

    if ((size.getHeight() == 0 && size.getWidth() == 0) || size.getWidth() == 0) {
        return;
    }

    int w = size.getWidth() - getScrollOffset();
    int h = size.getHeight();

    int styleHeight = Util.parseInt(getElement().getStyle().getProperty("height"), Style.DEFAULT);
    int styleWidth = Util.parseInt(getElement().getStyle().getProperty("width"), Style.DEFAULT);

    boolean findWidth = styleWidth == -1;
    boolean findHeight = styleHeight == -1;

    if (GXTLogConfiguration.loggingIsEnabled()) {
        logger.finest(getId() + " findWidth: " + findWidth + " findHeight: " + findHeight);
    }

    int calculateWidth = 0;

    int maxWidgetHeight = 0;
    int maxMarginTop = 0;
    int maxMarginBottom = 0;

    for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        BoxLayoutData layoutData = null;
        Object d = widget.getLayoutData();
        if (d instanceof BoxLayoutData) {
            layoutData = (BoxLayoutData) d;
        } else {
            layoutData = new BoxLayoutData();
            widget.setLayoutData(layoutData);
        }

        Margins cm = layoutData.getMargins();
        if (cm == null) {
            cm = new Margins(0);
            layoutData.setMargins(cm);
        }
    }

    if (findWidth || findHeight) {
        for (int i = 0, len = getWidgetCount(); i < len; i++) {
            Widget widget = getWidget(i);

            if (!widget.isVisible()) {
                continue;
            }

            BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
            Margins cm = layoutData.getMargins();

            calculateWidth += widget.getOffsetWidth();
            maxWidgetHeight = Math.max(maxWidgetHeight, widget.getOffsetHeight());

            calculateWidth += (cm.getLeft() + cm.getRight());
            maxMarginTop = Math.max(maxMarginTop, cm.getTop());
            maxMarginBottom = Math.max(maxMarginBottom, cm.getBottom());
        }
        maxWidgetHeight += (maxMarginTop + maxMarginBottom);

        if (findWidth) {
            w = calculateWidth;
        }

        if (findHeight) {
            h = maxWidgetHeight;
        }
    }

    int pl = 0;
    int pt = 0;
    int pb = 0;
    int pr = 0;
    if (getPadding() != null) {
        pl = getPadding().getLeft();
        pt = getPadding().getTop();
        pb = getPadding().getBottom();
        pr = getPadding().getRight();
    }

    if (findHeight) {
        h += pt + pb;
    }
    if (findWidth) {
        w += pl + pr;
    }

    int stretchHeight = h - pt - pb;
    int totalFlex = 0;
    int totalWidth = 0;
    int maxHeight = 0;

    for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        widget.addStyleName(CommonStyles.get().positionable());
        widget.getElement().getStyle().setMargin(0, Unit.PX);

        if (!widget.isVisible()) {
            continue;
        }

        if (widget == more) {
            triggerWidth = widget.getOffsetWidth() + 10;
        }

        BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
        Margins cm = layoutData.getMargins();

        // TODO strange issue where getOffsetWidth call in 2nd loop is returning smaller number than actual offset
        // when packing CENTER or END so we cache the offsetWidth for use in 2nd loop
        // with buttons, the button is word wrapping causing the button to be narrower and taller
        int ww = widget.getOffsetWidth();
        loopWidthMap.put(widget, ww);
        loopHeightMap.put(widget, widget.getOffsetHeight());

        totalFlex += layoutData.getFlex();
        totalWidth += (ww + cm.getLeft() + cm.getRight());
        maxHeight = Math.max(maxHeight, widget.getOffsetHeight() + cm.getTop() + cm.getBottom());
    }

    int innerCtHeight = maxHeight + pt + pb;

    if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
        getContainerTarget().setSize(w, h, true);
    } else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)
            || hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
        getContainerTarget().setSize(w, h = Math.max(h, innerCtHeight), true);
    } else {
        getContainerTarget().setSize(w, innerCtHeight, true);
    }

    int extraWidth = w - totalWidth - pl - pr;
    int allocated = 0;
    int componentWidth, componentHeight, componentTop;
    int availableHeight = h - pt - pb;

    if (getPack().equals(BoxLayoutPack.CENTER)) {
        pl += extraWidth / 2;
    } else if (getPack().equals(BoxLayoutPack.END)) {
        pl += extraWidth;
    }

    for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        if (!widget.isVisible()) {
            continue;
        }

        BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
        Margins cm = layoutData.getMargins();

        componentWidth = loopWidthMap.remove(widget);
        componentHeight = loopHeightMap.remove(widget);

        pl += cm.getLeft();

        pl = Math.max(0, pl);
        if (hBoxLayoutAlign.equals(HBoxLayoutAlign.MIDDLE)) {
            int diff = availableHeight - (componentHeight + cm.getTop() + cm.getBottom());
            if (diff == 0) {
                componentTop = pt + cm.getTop();
            } else {
                componentTop = pt + cm.getTop() + (diff / 2);
            }
        } else {
            if (hBoxLayoutAlign.equals(HBoxLayoutAlign.BOTTOM)) {
                componentTop = h - (pb + cm.getBottom() + componentHeight);
            } else {
                componentTop = pt + cm.getTop();
            }

        }

        boolean component = widget instanceof Component;
        Component c = null;
        if (component) {
            c = (Component) widget;
        }

        int width = -1;
        if (component) {
            c.setPosition(pl, componentTop);
        } else {
            XElement.as(widget.getElement()).setLeftTop(pl, componentTop);
        }

        if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) {
            int add = (int) Math.floor(extraWidth * (layoutData.getFlex() / totalFlex));
            allocated += add;
            if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) {
                add += (extraWidth - allocated);
            }

            componentWidth += add;
            width = componentWidth;
        }
        if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCH)) {
            applyLayout(widget, width, Util.constrain(stretchHeight - cm.getTop() - cm.getBottom(),
                    layoutData.getMinSize(), layoutData.getMaxSize()));
        } else if (hBoxLayoutAlign.equals(HBoxLayoutAlign.STRETCHMAX)) {
            applyLayout(widget, width, Util.constrain(maxHeight - cm.getTop() - cm.getBottom(),
                    layoutData.getMinSize(), layoutData.getMaxSize()));
        } else if (width > 0) {
            applyLayout(widget, width, -1);
        }
        pl += componentWidth + cm.getRight();
    }

    // do we need overflow
    if (enableOverflow) {
        int runningWidth = 0;
        for (int i = 0, len = getWidgetCount(); i < len; i++) {
            Widget widget = getWidget(i);

            if (widget == more) {
                continue;
            }

            BoxLayoutData layoutData = null;
            Object d = widget.getLayoutData();
            if (d instanceof BoxLayoutData) {
                layoutData = (BoxLayoutData) d;
            } else {
                layoutData = new BoxLayoutData();
            }
            Margins cm = layoutData.getMargins();
            if (cm == null) {
                cm = new Margins(0);
            }
            runningWidth += getWidgetWidth(widget);
            runningWidth += cm.getLeft();
            runningWidth += cm.getRight();
        }

        if (runningWidth > w) {
            hasOverflow = true;
            onOverflow();
        } else {
            hasOverflow = false;
            if (more != null && more.getParent() == this) {
                onUnoverflow();
            }

        }
    }
}

From source file:com.sencha.gxt.widget.core.client.container.HBoxLayoutContainer.java

License:sencha.com license

@Override
protected void onInsert(int index, Widget child) {
    super.onInsert(index, child);
    child.addStyleName(CommonStyles.get().floatLeft());
}

From source file:com.sencha.gxt.widget.core.client.container.VBoxLayoutContainer.java

License:sencha.com license

@Override
protected void doLayout() {
    Size size = getElement().getStyleSize();

    if (GXTLogConfiguration.loggingIsEnabled()) {
        logger.finest(getId() + " doLayout  size: " + size);
    }//from   w w w.j a  va  2s .c o  m

    int w = size.getWidth() - getScrollOffset();
    int h = size.getHeight();

    int styleHeight = Util.parseInt(getElement().getStyle().getProperty("height"), Style.DEFAULT);
    int styleWidth = Util.parseInt(getElement().getStyle().getProperty("width"), Style.DEFAULT);

    boolean findWidth = styleWidth == -1;
    boolean findHeight = styleHeight == -1;

    if (GXTLogConfiguration.loggingIsEnabled()) {
        logger.finest(getId() + " findWidth: " + findWidth + " findHeight: " + findHeight);
    }

    int calculateHeight = 0;

    int maxWidgetWidth = 0;
    int maxMarginLeft = 0;
    int maxMarginRight = 0;

    for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        BoxLayoutData layoutData = null;
        Object d = widget.getLayoutData();
        if (d instanceof BoxLayoutData) {
            layoutData = (BoxLayoutData) d;
        } else {
            layoutData = new BoxLayoutData();
            widget.setLayoutData(layoutData);
        }

        Margins cm = layoutData.getMargins();
        if (cm == null) {
            cm = new Margins(0);
            layoutData.setMargins(cm);
        }
    }

    if (findWidth || findHeight) {
        for (int i = 0, len = getWidgetCount(); i < len; i++) {
            Widget widget = getWidget(i);

            if (!widget.isVisible()) {
                continue;
            }

            BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
            Margins cm = layoutData.getMargins();

            calculateHeight += widget.getOffsetHeight();
            maxWidgetWidth = Math.max(maxWidgetWidth, widget.getOffsetWidth());

            calculateHeight += (cm.getTop() + cm.getBottom());
            maxMarginLeft = Math.max(maxMarginLeft, cm.getLeft());
            maxMarginRight = Math.max(maxMarginRight, cm.getRight());
        }
        maxWidgetWidth += (maxMarginLeft + maxMarginRight);

        if (findHeight) {
            h = calculateHeight;
        }

        if (findWidth) {
            w = maxWidgetWidth;
        }
    }

    int pl = 0;
    int pt = 0;
    int pb = 0;
    int pr = 0;
    if (getPadding() != null) {
        pl = getPadding().getLeft();
        pt = getPadding().getTop();
        pb = getPadding().getBottom();
        pr = getPadding().getRight();
    }

    if (findHeight) {
        h += pt + pb;
    }
    if (findWidth) {
        w += pl + pr;
    }

    int stretchWidth = w - pl - pr;
    int totalFlex = 0;
    int totalHeight = 0;
    int maxWidth = 0;
    for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);
        widget.addStyleName(CommonStyles.get().positionable());

        widget.getElement().getStyle().setMargin(0, Unit.PX);

        // callLayout(widget, false);

        BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
        Margins cm = layoutData.getMargins();

        totalFlex += layoutData.getFlex();
        totalHeight += widget.getOffsetHeight() + cm.getTop() + cm.getBottom();
        maxWidth = Math.max(maxWidth, widget.getOffsetWidth() + cm.getLeft() + cm.getRight());
    }

    int innerCtWidth = maxWidth + pl + pr;

    if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCH)) {
        getContainerTarget().setSize(w, h, true);
    } else {
        getContainerTarget().setSize(w = Math.max(w, innerCtWidth), h, true);
    }

    int extraHeight = h - totalHeight - pt - pb;
    int allocated = 0;
    int cw, ch, cl;
    int availableWidth = w - pl - pr;

    if (getPack().equals(BoxLayoutPack.CENTER)) {
        pt += extraHeight / 2;
    } else if (getPack().equals(BoxLayoutPack.END)) {
        pt += extraHeight;
    }

    for (int i = 0, len = getWidgetCount(); i < len; i++) {
        Widget widget = getWidget(i);

        BoxLayoutData layoutData = (BoxLayoutData) widget.getLayoutData();
        Margins cm = layoutData.getMargins();

        cw = widget.getOffsetWidth();
        ch = widget.getOffsetHeight();
        pt += cm.getTop();
        if (vBoxLayoutAlign.equals(VBoxLayoutAlign.CENTER)) {
            int diff = availableWidth - (cw + cm.getLeft() + cm.getRight());
            if (diff == 0) {
                cl = pl + cm.getLeft();
            } else {
                cl = pl + cm.getLeft() + (diff / 2);
            }
        } else {
            if (vBoxLayoutAlign.equals(VBoxLayoutAlign.RIGHT)) {
                cl = w - (pr + cm.getRight() + cw);
            } else {
                cl = pl + cm.getLeft();
            }
        }

        boolean component = widget instanceof Component;
        Component c = null;
        if (component) {
            c = (Component) widget;
        }

        int height = -1;
        if (component) {
            c.setPosition(cl, pt);
        } else {
            XElement.as(widget.getElement()).setLeftTop(cl, pt);
        }

        if (getPack().equals(BoxLayoutPack.START) && layoutData.getFlex() > 0) {
            int add = (int) Math.floor(extraHeight * (layoutData.getFlex() / totalFlex));
            allocated += add;
            if (isAdjustForFlexRemainder() && i == getWidgetCount() - 1) {
                add += extraHeight - allocated;
            }
            ch += add;
            height = ch;
        }
        if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCH)) {
            applyLayout(widget, Util.constrain(stretchWidth - cm.getLeft() - cm.getRight(),
                    layoutData.getMinSize(), layoutData.getMaxSize()), height);
        } else if (vBoxLayoutAlign.equals(VBoxLayoutAlign.STRETCHMAX)) {
            applyLayout(widget, Util.constrain(maxWidth - cm.getLeft() - cm.getRight(), layoutData.getMinSize(),
                    layoutData.getMaxSize()), height);
        } else if (height > 0) {
            applyLayout(widget, -1, height);
        }
        pt += ch + cm.getBottom();
    }
}

From source file:com.sencha.gxt.widget.core.client.grid.editing.GridRowEditing.java

License:sencha.com license

@SuppressWarnings("unchecked")
protected <N, O> IsWidget doStartEditing(ColumnConfig<M, N> c, M value) {
    if (c.isHidden()) {
        return null;
    }/*  www  . j a  v a 2s.  c o  m*/

    IsField<O> f = getEditor(c);

    ValueProvider<? super M, N> v = c.getValueProvider();
    N colValue = getEditableGrid().getStore().hasRecord(value)
            ? getEditableGrid().getStore().getRecord(value).getValue(v)
            : v.getValue(value);

    if (f != null) {
        Converter<N, O> converter = getConverter(c);
        O convertedValue;
        if (converter != null) {
            convertedValue = converter.convertModelValue(colValue);
        } else {
            convertedValue = (O) colValue;
        }

        if (GXTLogConfiguration.loggingIsEnabled()) {
            logger.finest("doStartEditing convertedValue = " + convertedValue);
        }
        f.setValue(convertedValue);

        if (f instanceof HasErrorHandler) {
            HasErrorHandler errorHandler = (HasErrorHandler) f;
            if (!(errorHandler.getErrorSupport() == null
                    || errorHandler.getErrorSupport() instanceof TitleErrorHandler)) {
                errorHandler.setErrorSupport(new TitleErrorHandler(f.asWidget()));
            }
        }

        return f;
    } else {
        final Widget label;
        if (renderers.containsKey(c)) {
            SafeHtmlRenderer<N> renderer = (SafeHtmlRenderer<N>) renderers.get(c);
            label = new HTML(renderer.render(colValue));
        } else {
            label = new Label(colValue != null ? colValue.toString() : "");
        }
        label.addStyleName(rowEditor.getAppearance().labelClass());
        return label;
    }

}

From source file:com.spinque.gwt.utils.client.widgets.VerticalTabLayoutPanel.java

License:Apache License

private void insert(final Widget child, Tab tab, int beforeIndex) {
    assert (beforeIndex >= 0) && (beforeIndex <= getWidgetCount()) : "beforeIndex out of bounds";

    // Check to see if the TabPanel already contains the Widget. If so,
    // remove it and see if we need to shift the position to the left.
    int idx = getWidgetIndex(child);
    if (idx != -1) {
        remove(child);//www .j a  v  a  2 s. com
        if (idx < beforeIndex) {
            beforeIndex--;
        }
    }

    deckPanel.insertProtected(child, beforeIndex);
    tabs.add(beforeIndex, tab);

    tabBar.insert(tab, beforeIndex);
    tab.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            selectTab(child);
        }
    });

    child.addStyleName(CONTENT_STYLE);

    if (selectedIndex == -1) {
        selectTab(0);
    } else if (selectedIndex >= beforeIndex) {
        // If we inserted before the currently selected tab, its index has just
        // increased.
        selectedIndex++;
    }
}

From source file:com.square.composant.tarificateur.square.client.view.devis.DevisViewImpl.java

License:Open Source License

private HorizontalPanel creerBlocLibelleValeur(String libelle, Widget wValeur) {
    final Label lLibelle = new Label(libelle);
    lLibelle.setWordWrap(false);/*from  w  w  w.ja  va  2s .co m*/
    lLibelle.addStyleName(ComposantTarificateur.RESOURCES.css().important());
    if (wValeur instanceof HasText) {
        wValeur.addStyleName(ComposantTarificateur.RESOURCES.css().important());
    }
    final HorizontalPanel conteneurBloc = new HorizontalPanel();
    conteneurBloc.add(lLibelle);
    conteneurBloc.add(wValeur);
    conteneurBloc.setCellVerticalAlignment(lLibelle, HasVerticalAlignment.ALIGN_MIDDLE);
    conteneurBloc.setCellVerticalAlignment(wValeur, HasVerticalAlignment.ALIGN_MIDDLE);
    return conteneurBloc;
}

From source file:com.square.composant.tarificateur.square.client.view.ligne.devis.LigneDevisViewImpl.java

License:Open Source License

private HorizontalPanel creerBlocLibelleValeur(String libelle, Widget wValeur) {
    final Label lLibelle = new Label(libelle);
    lLibelle.setWordWrap(false);/* w  w  w  . jav a2s .  c om*/
    lLibelle.addStyleName(ComposantTarificateur.RESOURCES.css().important());
    if (wValeur instanceof HasText) {
        wValeur.addStyleName(ComposantTarificateur.RESOURCES.css().important());
    }
    final HorizontalPanel conteneurBloc = new HorizontalPanel();
    conteneurBloc.setSpacing(2);
    conteneurBloc.add(lLibelle);
    conteneurBloc.add(wValeur);
    conteneurBloc.setCellVerticalAlignment(lLibelle, HasVerticalAlignment.ALIGN_MIDDLE);
    conteneurBloc.setCellVerticalAlignment(wValeur, HasVerticalAlignment.ALIGN_MIDDLE);
    return conteneurBloc;
}

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

License:Open Source License

/**
 * Display a rounded popup window//  w w w  . j a  va2 s  .co m
 * @param w Content widget
 * @param title Title widget. Use alternate method signature to pass in string
 * @param popup Popup returned by getPopupPanel()
 * @param x Position. Set to -1 to center it
 * @param y Position. Set to -1 to center it
 * @param cdm ClientDataManager
 * @param width Width of the enclosed widget. Will be used to resize the popup on ie
 */
public static void showRoundedPopup(Widget w, Widget title, final PopupPanel popup, int x, int y, int width,
        boolean showCloseButton) {

    VerticalPanel vP = new VerticalPanel();
    if (showCloseButton) {
        Button b = new Button("Close");
        b.addClickHandler(new DEClickHandler<PopupPanel>(popup) {

            @Override
            public void onClick(ClickEvent ce) {
                data.hide();
            }
        });

        Grid hP = new Grid(1, 2);
        if (title != null) {
            hP.setWidget(0, 0, title);
        }
        hP.setWidget(0, 1, b);
        hP.getCellFormatter().setWidth(0, 0, (width - 53) + "px");
        hP.getCellFormatter().setWidth(0, 1, "50px");
        hP.getCellFormatter().setHorizontalAlignment(0, 1, HorizontalPanel.ALIGN_RIGHT);
        vP.add(hP);
    } else {
        if (title != null) {
            vP.add(title);
        }
    }

    w.getElement().getStyle().setPropertyPx("padding", 5);
    w.addStyleName("popupColors");
    vP.add(w);

    Grid fP = new Grid(1, 1);
    fP.setStyleName("popupColors");
    fP.setHeight("100%");
    fP.setWidget(0, 0, vP);

    RoundedLinePanel rp = new RoundedLinePanel(fP, RoundedPanel.ALL, 5);
    //rp.setCornerStyleName("popupColors");
    rp.setCornerColor("#005480", "#5382a1", "#5382a1");
    popup.add(rp);
    popup.setAnimationEnabled(true);
    CssDefsImpl.impl.setRoundedPopupWidth(popup, width);

    if (x == -1 && y == -1) {
        popup.center();
    } else {
        popup.setPopupPosition(x, y);
        popup.show();
    }

}

From source file:com.sun.labs.aura.music.wsitm.client.ui.widget.DualRoundedPanel.java

License:Open Source License

public void setContent(Widget w, boolean addRoundedPanel) {
    if (addRoundedPanel) {
        RoundedPanel rp = new RoundedPanel(w, RoundedPanel.BOTTOM, 4);
        w.addStyleName("roundedPageBack");
        rp.setCornerStyleName("roundedPageBack");
        mainPanel.setWidget(1, 0, rp);/*from   w  ww  .j av a  2s. c  o  m*/
    } else {
        mainPanel.setWidget(1, 0, w);
    }
}

From source file:com.threerings.gwt.ui.Bindings.java

License:Open Source License

/**
 * Configures either `onStyle` or `offStyle` on the supplied target widgets depending on the
 * state of the supplied boolean `value`.
 *
 * @param onStyle the style name to be applied when the value is true, or null.
 * @param offStyle the style name to be applied when the value is false, or null.
 */// ww w .  ja v  a  2 s.c  om
public static void bindStateStyle(Value<Boolean> value, final String onStyle, final String offStyle,
        final Widget... targets) {
    value.addListenerAndTrigger(new Value.Listener<Boolean>() {
        public void valueChanged(Boolean value) {
            String add, remove;
            if (value) {
                remove = offStyle;
                add = onStyle;
            } else {
                remove = onStyle;
                add = offStyle;
            }
            for (Widget target : targets) {
                if (remove != null) {
                    target.removeStyleName(remove);
                }
                if (add != null) {
                    target.addStyleName(add);
                }
            }
        }
    });
}