/** * Get the HTML representation of an image. * * @param res the {@link ImageResource} to render as HTML * @return the rendered HTML */ private SafeHtml getImageHtml(ImageResource res) { // Right-justify image if LTR, left-justify if RTL AbstractImagePrototype proto = AbstractImagePrototype.create(res); SafeHtml image = proto.getSafeHtml(); SafeStylesBuilder cssBuilder = new SafeStylesBuilder(); if (LocaleInfo.getCurrentLocale().isRTL()) { cssBuilder.appendTrustedString("left:0px;"); } else { cssBuilder.appendTrustedString("right:0px;"); } cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;"); cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;"); return template.imageWrapper(cssBuilder.toSafeStyles(), image); }
/** * 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 = 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); } }
/** * Get the HTML representation of an image. * * @param res the {@link ImageResource} to render as HTML * @return the rendered HTML */ private SafeHtml getImageHtml(ImageResource res) { // Right-justify image if LTR, left-justify if RTL AbstractImagePrototype proto = AbstractImagePrototype.create(res); SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML()); SafeStylesBuilder cssBuilder = new SafeStylesBuilder(); if (LocaleInfo.getCurrentLocale().isRTL()) { cssBuilder.appendTrustedString("left:0px;"); } else { cssBuilder.appendTrustedString("right:0px;"); } cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;"); cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;"); return template.imageWrapper(cssBuilder.toSafeStyles(), image); }
/** * Get the HTML representation of an image. * * @param res the {@link ImageResource} to render as HTML * @return the rendered HTML */ private SafeHtml getImageHtml(ImageResource res) { // Right-justify image if LTR, left-justify if RTL AbstractImagePrototype proto = AbstractImagePrototype.create(res); SafeHtml image = SafeHtmlUtils.fromTrustedString(proto.getHTML()); SafeStylesBuilder cssBuilder = new SafeStylesBuilder(); if (LocaleInfo.getCurrentLocale().isRTL()) { cssBuilder.appendTrustedString("left:0px;"); } else { cssBuilder.appendTrustedString("right:0px;"); } cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;"); cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;"); return template.imageWrapper(cssBuilder.toSafeStyles(), image); }
/** * 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 = SafeHtmlUtils.fromTrustedString(proto.getHTML()); return template .imageWrapper(classesBuilder.toString(), cssBuilder.toSafeStyles(), image); }
/** * 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 = SafeHtmlUtils.fromTrustedString(proto.getHTML()); 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); } }
/** * 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); } }
@Override public void render(SafeHtmlBuilder sb, String value, FieldCell.FieldAppearanceOptions options) { int width = options.getWidth(); if (width == -1) { width = 150; } SafeStylesBuilder inputStylesBuilder = new SafeStylesBuilder(); inputStylesBuilder.appendTrustedString("width:100%;"); sb.appendHtmlConstant("<div style='width:" + width + "px;'>"); sb.appendHtmlConstant("<div class='" + RESOURCES.style().wrap() + "'>"); renderInput(sb, value, inputStylesBuilder.toSafeStyles(), options); sb.appendHtmlConstant("<span class='" + InputResources.INSTANCE.style().fieldUnits() + "'>"); sb.appendEscaped(units); sb.appendHtmlConstant("</span>"); sb.appendHtmlConstant("</div></div>"); }