List of usage examples for com.google.gwt.resources.client ImageResource getLeft
int getLeft();
From source file:com.emitrom.ti4j.mobile.client.ui.ImageView.java
License:Apache License
/** * Set the image of the image view according to a blob, and then clip it * using a GWT image resource.//www. ja v a 2s .c om * * @param blob * The blob * @param resource * The resource */ public void setImage(Blob blob, ImageResource resource) { setImage(blob.imageAsCropped(resource.getLeft(), resource.getTop(), resource.getHeight(), resource.getWidth())); }
From source file:com.google.speedtracer.client.util.dom.ImageResourceElementCreator.java
License:Apache License
public static Element createElementFrom(ImageResource resource) { SpanElement img = DocumentExt.get().createSpanElement(); String style = "url(" + resource.getURL() + ") no-repeat " + (-resource.getLeft() + "px ") + (-resource.getTop() + "px"); img.getStyle().setProperty("background", style); img.getStyle().setPropertyPx("width", resource.getWidth()); img.getStyle().setPropertyPx("height", resource.getHeight()); img.getStyle().setDisplay(Display.INLINE_BLOCK); return img;//from ww w .j a v a 2 s . c o m }
From source file:com.sencha.gxt.chart.client.draw.engine.VML.java
License:sencha.com license
/** * Applies pending attributes to the DOM element of a {@link Sprite}. * //from w w w. j av a2 s. c o m * @param sprite the sprite in need of attributes to be set. */ private void applyAttributes(Sprite sprite) { String vml = null; XElement element = getElement(sprite); // Create sprite element if necessary if (element == null) { element = createSpriteElement(sprite); } if (sprite instanceof EllipseSprite || sprite instanceof CircleSprite) { vml = ellipticalArc(sprite); } else if (sprite instanceof RectangleSprite) { RectangleSprite rect = (RectangleSprite) sprite; if (rect.isXDirty() || rect.isYDirty() || rect.isWidthDirty() || rect.isHeightDirty() || rect.isRadiusDirty() || ignoreOptimizations) { // faster conversion for rectangles without rounded corners if (Double.isNaN(rect.getRadius()) || rect.getRadius() == 0) { StringBuilder path = new StringBuilder(); long x = Math.round(rect.getX() * zoom); long y = Math.round(rect.getY() * zoom); long width = Math.round((rect.getX() + rect.getWidth()) * zoom); long height = Math.round((rect.getY() + rect.getHeight()) * zoom); vml = path.append("m").append(x).append(",").append(y).append(" l").append(width).append(",") .append(y).append(" l").append(width).append(",").append(height).append(" l").append(x) .append(",").append(height).append(" x e").toString(); } else { vml = path2vml(new PathSprite(rect)); } } } else if (sprite instanceof PathSprite) { PathSprite pathSprite = (PathSprite) sprite; vml = path2vml(pathSprite); } else if (sprite instanceof TextSprite) { // Handle text (special handling required) setTextAttributes((TextSprite) sprite, element); } else if (sprite instanceof ImageSprite) { ImageSprite image = (ImageSprite) sprite; if (image.isXDirty() || ignoreOptimizations) { element.setLeft((int) Math.round(image.getX())); } if (image.isYDirty() || ignoreOptimizations) { element.setTop((int) Math.round(image.getY())); } if (image.isWidthDirty() || image.isHeightDirty() || ignoreOptimizations) { element.setSize(new Size((int) Math.round(image.getWidth()), (int) Math.round(image.getHeight()))); } if (image.isResourceDirty() || ignoreOptimizations) { ImageResource resource = image.getResource(); if (resource != null) { StringBuilder builder = new StringBuilder(); builder.append("url(").append(image.getResource().getSafeUri().asString()).append(") "); builder.append(-resource.getLeft()).append("px "); builder.append(-resource.getTop()).append("px"); element.getStyle().setProperty("background", builder.toString()); } else { element.getStyle().clearBackgroundImage(); } } } if (vml != null) { element.setPropertyString("path", vml); } if (sprite.isZIndexDirty() || ignoreOptimizations) { applyZIndex(sprite, element); } String id = spriteIds.get(sprite); if (id != null) { element.setId(id); } // Apply clip rectangle to the sprite if (sprite.getClipRectangle() != null) { applyClip(sprite); } // Handle fill and opacity if (sprite.isOpacityDirty() || sprite.isStrokeOpacityDirty() || sprite.isFillDirty() || ignoreOptimizations) { setFill(sprite, element); } // Handle stroke (all fills require a stroke element) if (sprite.isStrokeDirty() || sprite.isStrokeWidthDirty() || sprite.isStrokeOpacityDirty() || sprite.isFillDirty() || ignoreOptimizations) { setStroke(sprite, element); } // Hide or show the sprite if (sprite.isHiddenDirty() || ignoreOptimizations) { if (sprite.isHidden()) { element.addClassName(css.hideClass()); } else { element.removeClassName(css.hideClass()); } } }
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(); }// w ww. jav a2 s . c o 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:de.swm.commons.mobile.client.widgets.DecoratedListItem.java
License:Apache License
/** * Default constructor.//from w w w . j av a 2s . co 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.DecoratedListItem.java
License:Apache License
/** * Default constructor.// w w w . ja va2s . c o m * * @param image image od the text box * @param title title * @param subtitle subtitle */ public DecoratedListItem(ImageResource image, int width, int height, String title, String subtitle) { this(); this.img.setUrlAndVisibleRect(image.getSafeUri(), image.getLeft(), image.getTop(), width, height); this.titleLabel.setText(title); this.subtitleLabel.setText(subtitle); }
From source file:org.cruxframework.crux.widgets.client.promobanner.BannerImpl.java
License:Apache License
protected void addBanner(ImageResource image, String title, String text, String styleName, String buttonLabel, final SelectHandler selectHandler) { SimplePanel panel = new SimplePanel(); Style style = panel.getElement().getStyle(); style.setProperty("background", "url(" + Screen.rewriteUrl(image.getSafeUri().asString()) + ") no-repeat " + (-image.getLeft() + "px ") + (-image.getTop() + "px")); style.setPropertyPx("width", image.getWidth()); style.setPropertyPx("height", image.getHeight()); doAddBanner(title, text, styleName, buttonLabel, selectHandler, panel); }
From source file:org.kaaproject.avro.ui.gwt.client.widget.ActionsButton.java
License:Apache License
public HandlerRegistration addMenuItem(ImageResource image, String text, final ActionMenuItemListener listener) { SafeHtml html = null;//www. ja va2 s . co m if (image != null) { SafeUri uri = image.getSafeUri(); int left = image.getLeft(); int top = image.getTop(); int width = image.getWidth(); int height = image.getHeight(); int paddingRight = width + 8; String background = "url(\"" + uri.asString() + "\") no-repeat " + (-left + "px ") + (-top + "px"); SafeStylesBuilder builder = new SafeStylesBuilder(); builder.trustedNameAndValue("background", background).width(width, Unit.PX).height(height, Unit.PX) .paddingRight(paddingRight, Unit.PX); SafeStyles style = SafeStylesUtils.fromTrustedString(builder.toSafeStyles().asString()); html = template.menuImageItemContent(style, text); } else { html = template.menuItemContent(text); } final MenuItem item = new MenuItem(html, new Command() { @Override public void execute() { if (actionsPopup != null && actionsPopup.isVisible()) actionsPopup.hide(); listener.onMenuItemSelected(); } }); menu.addItem(item); HandlerRegistration registration = new HandlerRegistration() { @Override public void removeHandler() { menu.removeItem(item); } }; return registration; }
From source file:org.kaaproject.avro.ui.gwt.client.widget.grid.cell.ActionsButtonCell.java
License:Apache License
public void addMenuItem(ImageResource image, String text, final ActionMenuItemListener<T> listener) { SafeHtml html = null;//from www. j a v a 2 s . c o m if (image != null) { SafeUri uri = image.getSafeUri(); int left = image.getLeft(); int top = image.getTop(); int width = image.getWidth(); int height = image.getHeight(); int paddingRight = width + 8; String background = "url(\"" + uri.asString() + "\") no-repeat " + (-left + "px ") + (-top + "px"); SafeStylesBuilder builder = new SafeStylesBuilder(); builder.trustedNameAndValue("background", background).width(width, Unit.PX).height(height, Unit.PX) .paddingRight(paddingRight, Unit.PX); SafeStyles style = SafeStylesUtils.fromTrustedString(builder.toSafeStyles().asString()); html = template.menuImageItemContent(style, text); } else { html = template.menuItemContent(text); } final MenuItem item = new MenuItem(html, new Command() { @Override public void execute() { if (actionsPopup != null && actionsPopup.isVisible()) actionsPopup.hide(); listener.onMenuItemSelected(currentValue); } }); menu.addItem(item); }
From source file:org.kaaproject.kaa.sandbox.web.client.mvp.view.widget.ActionsLabel.java
License:Apache License
public void addMenuItem(ImageResource image, String text, final ActionMenuItemListener listener) { SafeHtml html = null;//from w w w . j a va2 s .c o m if (image != null) { SafeUri uri = image.getSafeUri(); int left = image.getLeft(); int top = image.getTop(); int width = image.getWidth(); int height = image.getHeight(); int paddingRight = width + 8; String background = "url(\"" + uri.asString() + "\") no-repeat " + (-left + "px ") + (-top + "px"); SafeStylesBuilder builder = new SafeStylesBuilder(); builder.trustedNameAndValue("background", background).width(width, Unit.PX).height(height, Unit.PX) .paddingRight(paddingRight, Unit.PX); SafeStyles style = SafeStylesUtils.fromTrustedString(builder.toSafeStyles().asString()); html = template.menuImageItemContent(style, text); } else { html = template.menuItemContent(text); } MenuItem item = new MenuItem(html, new Command() { @Override public void execute() { if (actionsPopup != null && actionsPopup.isVisible()) actionsPopup.hide(); listener.onMenuItemSelected(); } }); menu.addItem(item); }