1 29 30 package nextapp.echo2.webcontainer.propertyrender; 31 32 import nextapp.echo2.app.FillImage; 33 import nextapp.echo2.app.Component; 34 import nextapp.echo2.webcontainer.RenderContext; 35 import nextapp.echo2.webcontainer.image.ImageRenderSupport; 36 import nextapp.echo2.webcontainer.image.ImageTools; 37 import nextapp.echo2.webrender.ClientProperties; 38 import nextapp.echo2.webrender.output.CssStyle; 39 40 44 public class FillImageRender { 45 46 50 public static final int FLAG_DISABLE_FIXED_MODE = 0x1; 51 52 65 public static final int FLAG_ENABLE_IE_PNG_ALPHA_FILTER = 0x2; 66 67 80 public static void renderToStyle(CssStyle cssStyle, RenderContext rc, ImageRenderSupport irs, 81 Component component, String imageId, FillImage fillImage, int flags) { 82 83 if (fillImage == null) { 84 return; 85 } 86 String imageUri = ImageTools.getUri(rc, irs, component, imageId); 87 88 if ((flags & FLAG_ENABLE_IE_PNG_ALPHA_FILTER) != 0 && rc.getContainerInstance().getClientProperties().getBoolean( 89 ClientProperties.PROPRIETARY_IE_PNG_ALPHA_FILTER_REQUIRED)) { 90 cssStyle.setAttribute("background-image", "none"); 91 cssStyle.setAttribute("filter", 92 "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + imageUri + "', sizingMethod='scale')"); 93 } else { 94 cssStyle.setAttribute("background-image", "url(" + imageUri + ")"); 95 } 96 97 if (rc.getContainerInstance().getClientProperties().getBoolean( 98 ClientProperties.QUIRK_CSS_BACKGROUND_ATTACHMENT_USE_FIXED)) { 99 cssStyle.setAttribute("background-attachment", "fixed"); 100 } 101 102 switch (fillImage.getRepeat()) { 103 case FillImage.NO_REPEAT: 104 cssStyle.setAttribute("background-repeat", "no-repeat"); 105 break; 106 case FillImage.REPEAT_HORIZONTAL: 107 cssStyle.setAttribute("background-repeat", "repeat-x"); 108 break; 109 case FillImage.REPEAT_VERTICAL: 110 cssStyle.setAttribute("background-repeat", "repeat-y"); 111 break; 112 default: 113 cssStyle.setAttribute("background-repeat", "repeat"); 114 } 115 if (fillImage.getHorizontalOffset() != null || fillImage.getVerticalOffset() != null) { 116 StringBuffer positionText = new StringBuffer (); 117 if (fillImage.getHorizontalOffset() == null) { 118 positionText.append("0px"); 119 } else { 120 positionText.append(ExtentRender.renderCssAttributeValue(fillImage.getHorizontalOffset())); 121 } 122 positionText.append(" " ); 123 if (fillImage.getVerticalOffset() == null) { 124 positionText.append("0px"); 125 } else { 126 positionText.append(ExtentRender.renderCssAttributeValue(fillImage.getVerticalOffset())); 127 } 128 cssStyle.setAttribute("background-position", positionText.toString()); 129 } 130 } 131 132 133 private FillImageRender() { } 134 } 135 | Popular Tags |