SafeUri uri = image.getSafeUri(); int left = image.getLeft(); int top = image.getTop(); int width = image.getWidth(); int height = image.getHeight(); int paddingRight = width + 8;
private void updateImageElementFromImageResource(Element imageSpan, ImageResource res, int spacing) { SafeUri url = res.getSafeUri(); int width = res.getWidth(); int height = res.getHeight(); int paddingRight = width + spacing; String style = "url(\"" + url.asString() + "\") no-repeat scroll left center"; imageSpan.getStyle().setProperty("background", style); imageSpan.getStyle().setPropertyPx("width", width); imageSpan.getStyle().setPropertyPx("height", height); imageSpan.getStyle().setPropertyPx("paddingRight", paddingRight); }
ImageResource desc = table.getResources().sortDescending(); if (asc != null) { sortAscIconWidth = asc.getWidth() + ICON_PADDING; sortAscIconHalfHeight = (int) Math.round(asc.getHeight() / 2.0); } else { sortAscIconWidth = 0; sortDescIconWidth = desc.getWidth() + ICON_PADDING; sortDescIconHalfHeight = (int) Math.round(desc.getHeight() / 2.0); } else { sortDescIconWidth = 0;
protected AbstractImageShape(final ShapeType type, final ImageResource resource, final boolean listening, final ImageSelectionMode mode) { this(type, resource.getSafeUri().asString(), listening, mode); }
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 {
/** * Construct a new {@link IconCellDecorator}. * * @param icon the icon to use * @param cell the cell to decorate * @param valign the vertical alignment attribute of the contents * @param spacing the pixel space between the icon and the cell */ public IconCellDecorator(ImageResource icon, Cell<C> cell, VerticalAlignmentConstant valign, int spacing) { if (template == null) { template = GWT.create(Template.class); } this.cell = cell; this.iconHtml = getImageHtml(icon, valign, false); this.imageWidth = icon.getWidth() + spacing; this.placeHolderHtml = getImageHtml(icon, valign, true); this.outerDivPadding = SafeStylesUtils.fromTrustedString("padding-" + direction + ": " + imageWidth + "px;"); }
/** * Get the HTML representation of an image. Visible for testing. * * @param res the {@link ImageResource} to render as HTML * @param valign the vertical alignment * @param isPlaceholder if true, do not include the background image * @return the rendered HTML */ SafeHtml getImageHtml(ImageResource res, VerticalAlignmentConstant valign, boolean isPlaceholder) { // Get the HTML for the image. SafeHtml image; if (isPlaceholder) { image = SafeHtmlUtils.fromSafeConstant("<div></div>"); } else { AbstractImagePrototype proto = AbstractImagePrototype.create(res); image = proto.getSafeHtml(); } // Create the wrapper based on the vertical alignment. SafeStylesBuilder cssStyles = new SafeStylesBuilder().appendTrustedString(direction + ":0px;"); if (HasVerticalAlignment.ALIGN_TOP == valign) { return template.imageWrapperTop(cssStyles.toSafeStyles(), image); } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) { return template.imageWrapperBottom(cssStyles.toSafeStyles(), image); } else { int halfHeight = (int) Math.round(res.getHeight() / 2.0); cssStyles.appendTrustedString("margin-top:-" + halfHeight + "px;"); return template.imageWrapperMiddle(cssStyles.toSafeStyles(), image); } }
@Override public RolodexCard[] getRolodexCards() { RolodexCard[] cards = new RolodexCard[3]; for (int index = 0; index < 3; index++) { ClippedImagePrototype expanded = new ClippedImagePrototype(defaultImage.getURL(), 0, 0, 300, 200); ClippedImagePrototype collapseLeft = new ClippedImagePrototype(defaultImage.getURL(), 0, 0, 100, 100); ClippedImagePrototype collapseRight = new ClippedImagePrototype(defaultImage.getURL(), 0, 0, 100, 100); cards[index] = new RolodexCard(expanded, collapseLeft, collapseRight, 300, 100, 0); } return cards; }
@Override public SafeHtml render(ImageResource image) { if (image instanceof ImageResourcePrototype.Bundle) { return AbstractImagePrototype.create(image).getSafeHtml(); } else { return TEMPLATE.image(image.getSafeUri(), image.getWidth(), image.getHeight()); } } }
protected Picture(ImageResource resource, boolean load, boolean listening, String pictureCategory) { this(resource.getSafeUri().asString(), load, listening, pictureCategory); // resource.getSafeUri().asString() is the same as resource.getURL() - which is deprecated }
/** * Get the HTML representation of an image. * * @param res the {@link ImageResource} to render as HTML * @param isTop true if the image is for a top level element. * @return the rendered HTML */ private SafeHtml getImageHtml(ImageResource res, boolean isTop) { // Build the classes. StringBuilder classesBuilder = new StringBuilder(style.cellTreeItemImage()); if (isTop) { classesBuilder.append(" ").append(style.cellTreeTopItemImage()); } // Build the css. SafeStylesBuilder cssBuilder = new SafeStylesBuilder(); if (LocaleInfo.getCurrentLocale().isRTL()) { cssBuilder.appendTrustedString("right: 0px;"); } else { cssBuilder.appendTrustedString("left: 0px;"); } cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;"); cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;"); AbstractImagePrototype proto = AbstractImagePrototype.create(res); SafeHtml image = proto.getSafeHtml(); return template .imageWrapper(classesBuilder.toString(), cssBuilder.toSafeStyles(), image); }
/** * Get the HTML representation of an image. Visible for testing. * * @param res the {@link ImageResource} to render as HTML * @param valign the vertical alignment * @param isPlaceholder if true, do not include the background image * @return the rendered HTML */ SafeHtml getImageHtml(ImageResource res, VerticalAlignmentConstant valign, boolean isPlaceholder) { // Get the HTML for the image. SafeHtml image; if (isPlaceholder) { image = SafeHtmlUtils.fromSafeConstant("<div></div>"); } else { AbstractImagePrototype proto = AbstractImagePrototype.create(res); image = SafeHtmlUtils.fromTrustedString(proto.getHTML()); } // Create the wrapper based on the vertical alignment. SafeStylesBuilder cssStyles = new SafeStylesBuilder().appendTrustedString(direction + ":0px;"); if (HasVerticalAlignment.ALIGN_TOP == valign) { return template.imageWrapperTop(cssStyles.toSafeStyles(), image); } else if (HasVerticalAlignment.ALIGN_BOTTOM == valign) { return template.imageWrapperBottom(cssStyles.toSafeStyles(), image); } else { int halfHeight = (int) Math.round(res.getHeight() / 2.0); cssStyles.appendTrustedString("margin-top:-" + halfHeight + "px;"); return template.imageWrapperMiddle(cssStyles.toSafeStyles(), image); } }
_buffer.append("background-image:url(" + img.getURL() + ");");
/** * Create an AbstractImagePrototype backed by a ClientBundle ImageResource. * This method provides an API compatibility mapping for the new ImageResource * API. * * @param resource an ImageResource produced by a ClientBundle * @return an AbstractImagePrototype that displays the contents of the * ImageResource */ public static AbstractImagePrototype create(ImageResource resource) { // for backwards compatilibity, and to keep things simple, we treat standalone resources the // same as composite ones (which means using a clear gif with the image as the CSS background) return new ClippedImagePrototype(resource.getSafeUri(), resource.getLeft(), resource.getTop(), resource.getWidth(), resource.getHeight()); }
@Override public SafeHtml render(ImageResource image) { if (image instanceof ImageResourcePrototype.Bundle) { return AbstractImagePrototype.create(image).getSafeHtml(); } else { return TEMPLATE.image(image.getSafeUri(), image.getWidth(), image.getHeight()); } } }
protected AbstractImageShape(final ShapeType type, final ImageResource resource, final boolean listening, final ImageSelectionMode mode) { this(type, resource.getSafeUri().asString(), listening, mode); }