/** * 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); } }
/** * 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); } }
@Template("<div style=\"{0}position:relative;zoom:1;\">{1}<div>{2}</div></div>") SafeHtml outerDiv(SafeStyles padding, SafeHtml icon, SafeHtml cellContents);
@Template("<div style=\"{0}position:relative;zoom:1;\">{1}<div>{2}</div></div>") SafeHtml outerDiv(SafeStyles padding, SafeHtml icon, SafeHtml cellContents);
/** * The wrapper around the image vertically aligned to the top. */ @Template("<div style=\"{0}position:absolute;top:0px;line-height:0px;\">{1}</div>") SafeHtml imageWrapperTop(SafeStyles styles, SafeHtml image); }
/** * The wrapper around the image vertically aligned to the bottom. */ @Template("<div style=\"{0}position:absolute;bottom:0px;line-height:0px;\">{1}</div>") SafeHtml imageWrapperBottom(SafeStyles styles, SafeHtml image);
public void render(Context context, C value, SafeHtmlBuilder sb) { SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder(); cell.render(context, value, cellBuilder); sb.append(template.outerDiv(outerDivPadding, isIconUsed(value) ? getIconHtml(value) : placeHolderHtml, cellBuilder.toSafeHtml())); }
/** * The wrapper around the image vertically aligned to the bottom. */ @Template("<div style=\"{0}position:absolute;bottom:0px;line-height:0px;\">{1}</div>") SafeHtml imageWrapperBottom(SafeStyles styles, SafeHtml image);
/** * The wrapper around the image vertically aligned to the top. */ @Template("<div style=\"{0}position:absolute;top:0px;line-height:0px;\">{1}</div>") SafeHtml imageWrapperTop(SafeStyles styles, SafeHtml image); }
public void render(Context context, C value, SafeHtmlBuilder sb) { SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder(); cell.render(context, value, cellBuilder); sb.append(template.outerDiv(outerDivPadding, isIconUsed(value) ? getIconHtml(value) : placeHolderHtml, cellBuilder.toSafeHtml())); }
/** * The wrapper around the image vertically aligned to the middle. */ @Template("<div style=\"{0}position:absolute;top:50%;line-height:0px;\">{1}</div>") SafeHtml imageWrapperMiddle(SafeStyles styles, SafeHtml image);
/** * The wrapper around the image vertically aligned to the middle. */ @Template("<div style=\"{0}position:absolute;top:50%;line-height:0px;\">{1}</div>") SafeHtml imageWrapperMiddle(SafeStyles styles, SafeHtml 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 = 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); } }
@Template("<div style=\"{0}position:relative;zoom:1;\">{1}<div>{2}</div></div>") SafeHtml outerDiv(SafeStyles padding, SafeHtml icon, SafeHtml cellContents);
/** * The wrapper around the image vertically aligned to the middle. */ @Template("<div style=\"{0}position:absolute;top:50%;line-height:0px;\">{1}</div>") SafeHtml imageWrapperMiddle(SafeStyles styles, SafeHtml image);
/** * The wrapper around the image vertically aligned to the bottom. */ @Template("<div style=\"{0}position:absolute;bottom:0px;line-height:0px;\">{1}</div>") SafeHtml imageWrapperBottom(SafeStyles styles, SafeHtml image);
/** * The wrapper around the image vertically aligned to the top. */ @Template("<div style=\"{0}position:absolute;top:0px;line-height:0px;\">{1}</div>") SafeHtml imageWrapperTop(SafeStyles styles, SafeHtml image); }
public void render(Context context, C value, SafeHtmlBuilder sb) { SafeHtmlBuilder cellBuilder = new SafeHtmlBuilder(); cell.render(context, value, cellBuilder); sb.append(template.outerDiv(outerDivPadding, isIconUsed(value) ? getIconHtml(value) : placeHolderHtml, cellBuilder.toSafeHtml())); }