1 29 30 package nextapp.echo2.webcontainer.propertyrender; 31 32 import nextapp.echo2.app.Color; 33 import nextapp.echo2.app.Component; 34 import nextapp.echo2.webrender.output.CssStyle; 35 36 40 public class ColorRender { 41 42 private static final String COLOR_MASK = "#000000"; 43 44 52 public static void renderToStyle(CssStyle cssStyle, Color foreground, Color background) { 53 if (foreground != null) { 54 cssStyle.setAttribute("color", renderCssAttributeValue(foreground)); 55 } 56 if (background != null) { 57 cssStyle.setAttribute("background-color", renderCssAttributeValue(background)); 58 } 59 } 60 61 68 public static void renderToStyle(CssStyle cssStyle, Component component) { 69 renderToStyle(cssStyle, (Color) component.getRenderProperty(Component.PROPERTY_FOREGROUND), 70 (Color) component.getRenderProperty(Component.PROPERTY_BACKGROUND)); 71 } 72 73 80 public static final String renderCssAttributeValue(Color color) { 81 if (color == null) { 82 return ""; 83 } 84 int rgb = color.getRgb(); 85 String colorString = Integer.toString(rgb, 16); 86 return COLOR_MASK.substring(0, 7 - colorString.length()) + colorString; 87 } 88 89 90 private ColorRender() { } 91 } 92 | Popular Tags |