1 29 30 package nextapp.echo2.webcontainer.propertyrender; 31 32 import org.w3c.dom.Element ; 33 34 import nextapp.echo2.app.Component; 35 import nextapp.echo2.app.ImageReference; 36 import nextapp.echo2.app.Insets; 37 import nextapp.echo2.app.layout.CellLayoutData; 38 import nextapp.echo2.webcontainer.RenderContext; 39 import nextapp.echo2.webcontainer.image.ImageRenderSupport; 40 import nextapp.echo2.webrender.output.CssStyle; 41 42 47 public class CellLayoutDataRender { 48 49 private static String IMAGE_ID_PREFIX_LAYOUT_DATA_BACKGROUND_IMAGE = "CellLayoutData.BackgroundImage."; 50 private static int IMAGE_ID_PREFIX_LAYOUT_DATA_BACKGROUND_IMAGE_LENGTH = IMAGE_ID_PREFIX_LAYOUT_DATA_BACKGROUND_IMAGE.length(); 51 52 67 public static ImageReference getCellLayoutDataBackgroundImage(Component component, String imageId) { 68 if (imageId.startsWith(IMAGE_ID_PREFIX_LAYOUT_DATA_BACKGROUND_IMAGE)) { 69 String childRenderId = imageId.substring(IMAGE_ID_PREFIX_LAYOUT_DATA_BACKGROUND_IMAGE_LENGTH); 70 int childCount = component.getComponentCount(); 71 for (int i = 0; i < childCount; ++i) { 72 Component child = component.getComponent(i); 73 if (child.getRenderId().equals(childRenderId)) { 74 return ((CellLayoutData) child.getRenderProperty(Component.PROPERTY_LAYOUT_DATA)) 75 .getBackgroundImage().getImage(); 76 } 77 } 78 } 79 return null; 80 } 81 82 102 public static void renderBackgroundImageToStyle(CssStyle cssStyle, RenderContext rc, ImageRenderSupport irs, 103 Component parent, Component child) { 104 CellLayoutData layoutData = (CellLayoutData) child.getRenderProperty(Component.PROPERTY_LAYOUT_DATA); 105 if (layoutData == null || layoutData.getBackgroundImage() == null) { 106 return; 107 } 108 FillImageRender.renderToStyle(cssStyle, rc, irs, parent, 109 IMAGE_ID_PREFIX_LAYOUT_DATA_BACKGROUND_IMAGE + child.getRenderId(), layoutData.getBackgroundImage(), 0); 110 } 111 112 132 public static void renderToElementAndStyle(Element element, CssStyle cssStyle, Component component, CellLayoutData layoutData, 133 String defaultInsetsAttributeValue) { 134 if (layoutData == null) { 135 if (defaultInsetsAttributeValue != null) { 136 cssStyle.setAttribute("padding", defaultInsetsAttributeValue); 137 } 138 return; 139 } 140 141 Insets cellInsets = layoutData.getInsets(); 143 if (cellInsets == null) { 144 if (defaultInsetsAttributeValue != null) { 145 cssStyle.setAttribute("padding", defaultInsetsAttributeValue); 146 } 147 } else { 148 cssStyle.setAttribute("padding", InsetsRender.renderCssAttributeValue(cellInsets)); 149 } 150 151 ColorRender.renderToStyle(cssStyle, null, layoutData.getBackground()); 153 154 AlignmentRender.renderToElement(element, layoutData.getAlignment(), component); 156 } 157 158 172 public static void renderToStyle(CssStyle cssStyle, Component component, CellLayoutData layoutData, 173 String defaultInsetsAttributeValue) { 174 if (layoutData == null) { 175 if (defaultInsetsAttributeValue != null) { 176 cssStyle.setAttribute("padding", defaultInsetsAttributeValue); 177 } 178 return; 179 } 180 181 Insets cellInsets = layoutData.getInsets(); 183 if (cellInsets == null) { 184 if (defaultInsetsAttributeValue != null) { 185 cssStyle.setAttribute("padding", defaultInsetsAttributeValue); 186 } 187 } else { 188 cssStyle.setAttribute("padding", InsetsRender.renderCssAttributeValue(cellInsets)); 189 } 190 191 ColorRender.renderToStyle(cssStyle, null, layoutData.getBackground()); 193 194 AlignmentRender.renderToStyle(cssStyle, layoutData.getAlignment(), component); 196 } 197 198 199 private CellLayoutDataRender() { } 200 } 201 | Popular Tags |