Example usage for com.google.gwt.resources.client ImageResource getWidth

List of usage examples for com.google.gwt.resources.client ImageResource getWidth

Introduction

In this page you can find the example usage for com.google.gwt.resources.client ImageResource getWidth.

Prototype

int getWidth();

Source Link

Document

Returns the width of the image.

Usage

From source file:com.mgwt.imustlearn.client.ui.CellListWithButtons.java

License:Apache License

public void setIcons(Element element, ImageResource icon, boolean active) {
    ImageResource highlight = MGWTStyle.getTheme().getMGWTClientBundle().getButtonBarHighlightImage();

    if (icon == null)
        return;//ww  w.ja  v  a  2s .c om

    if (!active) {
        element.getStyle().setBackgroundImage("url(" + icon.getSafeUri().asString() + ")");

        if (MGWT.getOsDetection().isRetina() || MGWT.getOsDetection().isIPadRetina()) {
            element.getStyle().setProperty("backgroundSize",
                    (icon.getWidth() / 2) + "px " + (icon.getHeight() / 2) + "px");
        }
    } else {

        // don't set active state if we don't have a hightlight icon...
        //            if (highlight == null) {
        //                return;
        //            }

        element.getStyle().setBackgroundImage(
                "url(" + highlight.getSafeUri().asString() + "), url(" + icon.getSafeUri().asString() + ")");
        if (MGWT.getOsDetection().isRetina() || MGWT.getOsDetection().isIPadRetina()) {
            element.getStyle().setProperty("backgroundSize",
                    (highlight.getWidth()) + "px " + (highlight.getHeight()) + "px, " + (icon.getWidth() / 2)
                            + "px " + (icon.getHeight() / 2) + "px");
        }
    }

}

From source file:com.sencha.gxt.chart.client.draw.sprite.ImageSprite.java

License:sencha.com license

/**
 * Sets the {@link ImageResource} used by the image sprite.
 * //from  w  w w .j av  a2 s.c om
 * @param resource the image resource
 */
public void setResource(ImageResource resource) {
    if (resource != this.resource) {
        this.resource = resource;
        if (resource != null) {
            this.setWidth(resource.getWidth());
            this.setHeight(resource.getHeight());
        } else {
            this.setWidth(Double.NaN);
            this.setHeight(Double.NaN);
        }
        resourceDirty = true;
    }
}

From source file:com.sencha.gxt.theme.base.client.button.ButtonCellDefaultAppearance.java

License:sencha.com license

@Override
public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    SafeHtml valueHtml = SafeHtmlUtils.fromTrustedString(hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "");

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String cls = style.button();/*from   w  w w .  ja  v  a 2s .  c o m*/
    String arrowCls = "";
    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.split();
                break;
            case BOTTOM:
                arrowCls = style.splitBottom();
                break;
            default:
                // empty
            }

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.arrow();
                break;
            case BOTTOM:
                arrowCls = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        cls += " " + style.small();
        break;
    case MEDIUM:
        cls += " " + style.medium();
        break;
    case LARGE:
        cls += " " + style.large();
        break;
    default:
        // empty
    }

    SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

    int width = -1;

    if (cell.getWidth() != -1) {
        int w = cell.getWidth();
        if (w < cell.getMinWidth()) {
            w = cell.getMinWidth();
        }
        stylesBuilder.appendTrustedString("width:" + w + "px;");
        cls += " " + style.hasWidth() + " x-has-width";
        width = w;
    } else {

        if (cell.getMinWidth() != -1) {
            TextMetrics.get().bind(style.text());
            int length = TextMetrics.get().getWidth(valueHtml);
            length += 6; // frames

            if (icon != null) {
                switch (iconAlign) {
                case LEFT:
                case RIGHT:
                    length += icon.getWidth();
                    break;
                default:
                    // empty
                }
            }

            if (cell.getMinWidth() > length) {
                stylesBuilder.appendTrustedString("width:" + cell.getMinWidth() + "px;");
                cls += " " + style.hasWidth() + " x-has-width";
                width = cell.getMinWidth();
            }
        }
    }

    final int height = cell.getHeight();
    if (height != -1) {
        stylesBuilder.appendTrustedString("height:" + height + "px;");
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            arrowCls += " " + style.iconTop();
            break;
        case BOTTOM:
            arrowCls += " " + style.iconBottom();
            break;
        case LEFT:
            arrowCls += " " + style.iconLeft();
            break;
        case RIGHT:
            arrowCls += " " + style.iconRight();
            break;
        }

    } else {
        arrowCls += " " + style.noIcon();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        cls += " " + frame.pressedClass();
    }

    sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles()));

    SafeHtmlBuilder inside = new SafeHtmlBuilder();

    String innerWrap = arrowCls;

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    boolean hasText = valueHtml != null && !valueHtml.equals("");

    if (icon != null) {
        switch (iconAlign) {
        case LEFT:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeValue(inside, valueHtml, w, height);
            }
            inside.appendHtmlConstant("</tr>");
            break;
        case RIGHT:
            inside.appendHtmlConstant("<tr>");
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeValue(inside, valueHtml, w, height);
            }
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        case TOP:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeValue(inside, valueHtml, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            break;
        case BOTTOM:
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeValue(inside, valueHtml, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        }

    } else {
        inside.appendHtmlConstant("<tr>");
        if (valueHtml != null) {
            writeValue(inside, valueHtml, width, height);
        }
        inside.appendHtmlConstant("</tr>");
    }
    inside.appendHtmlConstant("</table>");
    inside.appendHtmlConstant("</div>");

    frame.render(sb,
            new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()),
            inside.toSafeHtml());

    sb.appendHtmlConstant("</div>");

}

From source file:com.smartgwt.mobile.client.widgets.BaseButton.java

License:Open Source License

private void setIcon(final ImageResource icon, boolean mask, boolean fireContentChangedEvent) {
    assert !mask || icon == null || (icon.getTop() == 0 && icon
            .getLeft() == 0) : "When using masking, the ImageResource must be a separate resource at runtime.";
    if (iconLoadRegistration != null) {
        iconLoadRegistration.removeHandler();
    }//from   w w  w .ja  v a2  s  .co  m
    if (iconImage != null) {
        remove(iconImage);
        iconImage = null;
    }
    this.icon = icon;
    this.masked = mask;

    if (icon != null) {
        iconImage = new Image(icon);
        getElement().addClassName(_CSS.buttonHasIconClass());
        if (icon.getWidth() > 0) {
            doSetIcon(false);
        } else {
            iconImage.getElement().getStyle().setVisibility(Style.Visibility.HIDDEN);
            iconLoadRegistration = iconImage.addLoadHandler(new com.google.gwt.event.dom.client.LoadHandler() {
                @Override
                public void onLoad(com.google.gwt.event.dom.client.LoadEvent event) {
                    iconLoadRegistration.removeHandler();
                    doSetIcon(true);
                }
            });
        }
        if (iconAlign != IconAlign.RIGHT) {
            insert(iconImage, contentElem.<com.google.gwt.user.client.Element>cast(), 0, true);
        } else {
            add(iconImage, contentElem.<com.google.gwt.user.client.Element>cast());
        }
    } else {
        getElement().removeClassName(_CSS.buttonHasIconClass());
    }
    if (fireContentChangedEvent)
        _fireContentChangedEvent();
}

From source file:cz.metacentrum.perun.webgui.widgets.ImageResourceAltRenderer.java

License:Apache License

public SafeHtml render(ImageResource image, String alt) {
    if (image instanceof ImageResourcePrototype.Bundle) {
        return AbstractImagePrototype.create(image).getSafeHtml();
    } else {/*  ww  w  . ja v  a2 s.co  m*/
        return TEMPLATE.image(image.getSafeUri(), image.getWidth(), image.getHeight(), alt);
    }
}

From source file:de.swm.commons.mobile.client.widgets.DecoratedListItem.java

License:Apache License

/**
 * Default constructor.//from  w ww  .  j  av a2s .c o  m
 *
 * @param image    image od the text box
 * @param title    title
 * @param subtitle subtitle
 */
@UiConstructor
public DecoratedListItem(ImageResource image, String title, String subtitle) {
    this();
    this.img.setUrlAndVisibleRect(image.getSafeUri(), image.getLeft(), image.getTop(), image.getWidth(),
            image.getHeight());
    this.titleLabel.setText(title);
    this.subtitleLabel.setText(subtitle);
}

From source file:de.swm.commons.mobile.client.widgets.ImageButton.java

License:Apache License

public void setIcon(ImageResource image) {
    img.setResource(image);/* w w w .jav a2 s. c o m*/
    getElement().getStyle().setHeight(image.getHeight(), Unit.PX);
    getElement().getStyle().setWidth(image.getWidth(), Unit.PX);
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.button.Css3ButtonCellAppearance.java

License:sencha.com license

@Override
public void render(ButtonCell<M> cell, Context context, M value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    String text = hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "";

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String arrowClass = "";
    String scaleClass = "";
    String iconClass = "";

    int width = cell.getWidth();
    int height = cell.getHeight();
    boolean hasIcon = cell.getIcon() != null;
    boolean isSplitButton = cell instanceof SplitButtonCell;
    boolean hasMenu = cell.getMenu() != null;

    boolean hasWidth = width != -1;

    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowClass = style.split();
                break;
            case BOTTOM:
                arrowClass = style.splitBottom();
                break;
            }//from  w w w  .  j  ava2  s .  c  om

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowClass = style.arrow();
                break;
            case BOTTOM:
                arrowClass = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        scaleClass = style.small();
        break;

    case MEDIUM:
        scaleClass = style.medium();
        break;

    case LARGE:
        scaleClass = style.large();
        break;
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            iconClass = style.iconTop();
            break;
        case BOTTOM:
            iconClass = style.iconBottom();
            break;
        case LEFT:
            iconClass = style.iconLeft();
            break;
        case RIGHT:
            iconClass = style.iconRight();
            break;
        }
    }

    String buttonClass = style.button();
    boolean hasText = text != null && !text.equals("");
    if (!hasText) {
        buttonClass += " " + style.noText();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        buttonClass += " " + style.pressed();
    }

    String innerClass = style.buttonInner() + " " + iconClass;

    innerClass += " " + arrowClass;
    innerClass += " " + scaleClass;

    SafeHtmlBuilder builder = new SafeHtmlBuilder();

    SafeStylesBuilder ss = new SafeStylesBuilder();

    if (height != -1) {
        ButtonDetails bd = resources.theme().button();
        EdgeDetails padding = bd.padding();
        EdgeDetails paddingInner = bd.radiusMinusBorderWidth();
        int ah = height;
        ah -= padding.top();
        ah -= padding.bottom();
        ah -= paddingInner.top();
        ah -= paddingInner.bottom();

        ss.appendTrustedString("line-height: " + ah + "px;");
    }

    builder.appendHtmlConstant("<div class='" + buttonClass + "'>");

    // get iconbuilder ready
    SafeHtmlBuilder iconBuilder = new SafeHtmlBuilder();
    if (icon != null) {
        int iconWidth = icon != null ? icon.getWidth() : 0;
        int iconHeight = icon != null ? icon.getHeight() : 0;
        String styles = "width: " + iconWidth + "px; height: " + iconHeight + "px;";

        iconBuilder.appendHtmlConstant("<div class='" + iconClass + "' style='" + styles + "'>");
        iconBuilder.append(AbstractImagePrototype.create(icon).getSafeHtml());
        iconBuilder.appendHtmlConstant("</div>");
    }

    // for left / right aligned icons with a fixed button width we render the icon outside of the inner div
    if (hasWidth && hasIcon && iconAlign == IconAlign.LEFT) {
        builder.append(iconBuilder.toSafeHtml());
    }

    if (hasWidth && hasIcon && (iconAlign == IconAlign.LEFT)) {
        int tw = width - (resources.theme().button().borderRadius() * 2);
        if (isSplitButton && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) {
            tw -= resources.split().getWidth() + 10;
        }

        if (!isSplitButton && iconAlign == IconAlign.LEFT && hasMenu
                && cell.getArrowAlign() == ButtonArrowAlign.RIGHT) {
            tw -= resources.arrow().getWidth() + 10;
        }

        if (hasIcon && iconAlign == IconAlign.LEFT) {
            tw -= icon.getWidth();
        }

        ss.appendTrustedString("width: " + tw + "px;");
    }

    builder.appendHtmlConstant("<div class='" + innerClass + "' style='" + ss.toSafeStyles().asString() + "'>");

    if (icon != null) {
        if ((!hasWidth && iconAlign == IconAlign.LEFT) || iconAlign == IconAlign.TOP) {
            builder.append(iconBuilder.toSafeHtml());
        }
        builder.appendHtmlConstant(text);
        if (iconAlign == IconAlign.RIGHT || iconAlign == IconAlign.BOTTOM) {
            builder.append(iconBuilder.toSafeHtml());
        }
    } else {
        builder.appendHtmlConstant(text);
    }

    builder.appendHtmlConstant("</div></div>");
    sb.append(builder.toSafeHtml());
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.sliced.button.SlicedButtonCellAppearance.java

License:sencha.com license

@Override
public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    String text = hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "";

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String cls = style.button();//  ww w .j a va2s.  c  om
    String arrowCls = "";
    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.split();
                break;
            case BOTTOM:
                arrowCls = style.splitBottom();
                break;
            default:
                // empty
            }

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.arrow();
                break;
            case BOTTOM:
                arrowCls = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        cls += " " + style.small();
        break;
    case MEDIUM:
        cls += " " + style.medium();
        break;
    case LARGE:
        cls += " " + style.large();
        break;
    default:
        // empty
    }

    SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

    int width = -1;

    if (cell.getWidth() != -1) {
        int w = cell.getWidth();
        if (w < cell.getMinWidth()) {
            w = cell.getMinWidth();
        }
        stylesBuilder.appendTrustedString("width:" + w + "px;");
        cls += " " + style.hasWidth() + " x-has-width";
        width = w;
    } else {

        if (cell.getMinWidth() != -1) {
            TextMetrics.get().bind(style.text());
            int length = TextMetrics.get().getWidth(text);
            length += 6; // frames

            if (icon != null) {
                switch (iconAlign) {
                case LEFT:
                case RIGHT:
                    length += icon.getWidth();
                    break;
                default:
                    // empty
                }
            }
        }
    }

    final int height = cell.getHeight();
    if (height != -1) {
        stylesBuilder.appendTrustedString("height:" + height + "px;");
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            arrowCls += " " + style.iconTop();
            break;
        case BOTTOM:
            arrowCls += " " + style.iconBottom();
            break;
        case LEFT:
            arrowCls += " " + style.iconLeft();
            break;
        case RIGHT:
            arrowCls += " " + style.iconRight();
            break;
        }

    } else {
        arrowCls += " " + style.noIcon();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        cls += " " + frame.pressedClass();
    }

    sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles()));

    SafeHtmlBuilder inside = new SafeHtmlBuilder();

    String innerWrap = arrowCls;
    if (GXT.isIE6() || GXT.isIE7()) {
        arrowCls += " " + CommonStyles.get().inlineBlock();
    }

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    boolean hasText = text != null && !text.equals("");

    if (icon != null) {
        switch (iconAlign) {
        case LEFT:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeText(inside, text, w, height);
            }
            inside.appendHtmlConstant("</tr>");
            break;
        case RIGHT:
            inside.appendHtmlConstant("<tr>");
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeText(inside, text, w, height);
            }
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        case TOP:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeText(inside, text, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            break;
        case BOTTOM:
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeText(inside, text, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        }

    } else {
        inside.appendHtmlConstant("<tr>");
        if (text != null) {
            writeText(inside, text, width, height);
        }
        inside.appendHtmlConstant("</tr>");
    }
    inside.appendHtmlConstant("</table>");
    inside.appendHtmlConstant("</div>");

    frame.render(sb,
            new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()),
            inside.toSafeHtml());

    sb.appendHtmlConstant("</div>");

}

From source file:mx.org.pescadormvp.core.client.internallinks.InternalButtonLink.java

License:Open Source License

/**
 * Set the image to be used in the button. 
 */// ww  w . j a va  2  s. c  o  m
public void setImageResource(ImageResource imageResource) {
    ensureImage();
    imageWidth = imageResource.getWidth();
    imageHeight = imageResource.getHeight();
    image.setResource(imageResource);
    setupImage();
}