1 18 package org.apache.batik.css.engine.value; 19 20 import org.apache.batik.css.engine.CSSEngine; 21 import org.apache.batik.css.engine.CSSStylableElement; 22 import org.apache.batik.css.engine.StyleMap; 23 import org.apache.batik.util.CSSConstants; 24 import org.w3c.css.sac.LexicalUnit; 25 import org.w3c.dom.DOMException ; 26 import org.w3c.dom.css.CSSPrimitiveValue; 27 28 35 public abstract class AbstractColorManager extends IdentifierManager { 36 37 40 protected final static StringMap values = new StringMap(); 41 static { 42 values.put(CSSConstants.CSS_AQUA_VALUE, 43 ValueConstants.AQUA_VALUE); 44 values.put(CSSConstants.CSS_BLACK_VALUE, 45 ValueConstants.BLACK_VALUE); 46 values.put(CSSConstants.CSS_BLUE_VALUE, 47 ValueConstants.BLUE_VALUE); 48 values.put(CSSConstants.CSS_FUCHSIA_VALUE, 49 ValueConstants.FUCHSIA_VALUE); 50 values.put(CSSConstants.CSS_GRAY_VALUE, 51 ValueConstants.GRAY_VALUE); 52 values.put(CSSConstants.CSS_GREEN_VALUE, 53 ValueConstants.GREEN_VALUE); 54 values.put(CSSConstants.CSS_LIME_VALUE, 55 ValueConstants.LIME_VALUE); 56 values.put(CSSConstants.CSS_MAROON_VALUE, 57 ValueConstants.MAROON_VALUE); 58 values.put(CSSConstants.CSS_NAVY_VALUE, 59 ValueConstants.NAVY_VALUE); 60 values.put(CSSConstants.CSS_OLIVE_VALUE, 61 ValueConstants.OLIVE_VALUE); 62 values.put(CSSConstants.CSS_PURPLE_VALUE, 63 ValueConstants.PURPLE_VALUE); 64 values.put(CSSConstants.CSS_RED_VALUE, 65 ValueConstants.RED_VALUE); 66 values.put(CSSConstants.CSS_SILVER_VALUE, 67 ValueConstants.SILVER_VALUE); 68 values.put(CSSConstants.CSS_TEAL_VALUE, 69 ValueConstants.TEAL_VALUE); 70 values.put(CSSConstants.CSS_WHITE_VALUE, 71 ValueConstants.WHITE_VALUE); 72 values.put(CSSConstants.CSS_YELLOW_VALUE, 73 ValueConstants.YELLOW_VALUE); 74 75 values.put(CSSConstants.CSS_ACTIVEBORDER_VALUE, 76 ValueConstants.ACTIVEBORDER_VALUE); 77 values.put(CSSConstants.CSS_ACTIVECAPTION_VALUE, 78 ValueConstants.ACTIVECAPTION_VALUE); 79 values.put(CSSConstants.CSS_APPWORKSPACE_VALUE, 80 ValueConstants.APPWORKSPACE_VALUE); 81 values.put(CSSConstants.CSS_BACKGROUND_VALUE, 82 ValueConstants.BACKGROUND_VALUE); 83 values.put(CSSConstants.CSS_BUTTONFACE_VALUE, 84 ValueConstants.BUTTONFACE_VALUE); 85 values.put(CSSConstants.CSS_BUTTONHIGHLIGHT_VALUE, 86 ValueConstants.BUTTONHIGHLIGHT_VALUE); 87 values.put(CSSConstants.CSS_BUTTONSHADOW_VALUE, 88 ValueConstants.BUTTONSHADOW_VALUE); 89 values.put(CSSConstants.CSS_BUTTONTEXT_VALUE, 90 ValueConstants.BUTTONTEXT_VALUE); 91 values.put(CSSConstants.CSS_CAPTIONTEXT_VALUE, 92 ValueConstants.CAPTIONTEXT_VALUE); 93 values.put(CSSConstants.CSS_GRAYTEXT_VALUE, 94 ValueConstants.GRAYTEXT_VALUE); 95 values.put(CSSConstants.CSS_HIGHLIGHT_VALUE, 96 ValueConstants.HIGHLIGHT_VALUE); 97 values.put(CSSConstants.CSS_HIGHLIGHTTEXT_VALUE, 98 ValueConstants.HIGHLIGHTTEXT_VALUE); 99 values.put(CSSConstants.CSS_INACTIVEBORDER_VALUE, 100 ValueConstants.INACTIVEBORDER_VALUE); 101 values.put(CSSConstants.CSS_INACTIVECAPTION_VALUE, 102 ValueConstants.INACTIVECAPTION_VALUE); 103 values.put(CSSConstants.CSS_INACTIVECAPTIONTEXT_VALUE, 104 ValueConstants.INACTIVECAPTIONTEXT_VALUE); 105 values.put(CSSConstants.CSS_INFOBACKGROUND_VALUE, 106 ValueConstants.INFOBACKGROUND_VALUE); 107 values.put(CSSConstants.CSS_INFOTEXT_VALUE, 108 ValueConstants.INFOTEXT_VALUE); 109 values.put(CSSConstants.CSS_MENU_VALUE, 110 ValueConstants.MENU_VALUE); 111 values.put(CSSConstants.CSS_MENUTEXT_VALUE, 112 ValueConstants.MENUTEXT_VALUE); 113 values.put(CSSConstants.CSS_SCROLLBAR_VALUE, 114 ValueConstants.SCROLLBAR_VALUE); 115 values.put(CSSConstants.CSS_THREEDDARKSHADOW_VALUE, 116 ValueConstants.THREEDDARKSHADOW_VALUE); 117 values.put(CSSConstants.CSS_THREEDFACE_VALUE, 118 ValueConstants.THREEDFACE_VALUE); 119 values.put(CSSConstants.CSS_THREEDHIGHLIGHT_VALUE, 120 ValueConstants.THREEDHIGHLIGHT_VALUE); 121 values.put(CSSConstants.CSS_THREEDLIGHTSHADOW_VALUE, 122 ValueConstants.THREEDLIGHTSHADOW_VALUE); 123 values.put(CSSConstants.CSS_THREEDSHADOW_VALUE, 124 ValueConstants.THREEDSHADOW_VALUE); 125 values.put(CSSConstants.CSS_WINDOW_VALUE, 126 ValueConstants.WINDOW_VALUE); 127 values.put(CSSConstants.CSS_WINDOWFRAME_VALUE, 128 ValueConstants.WINDOWFRAME_VALUE); 129 values.put(CSSConstants.CSS_WINDOWTEXT_VALUE, 130 ValueConstants.WINDOWTEXT_VALUE); 131 } 132 133 136 protected final static StringMap computedValues = new StringMap(); 137 static { 138 computedValues.put(CSSConstants.CSS_BLACK_VALUE, 139 ValueConstants.BLACK_RGB_VALUE); 140 computedValues.put(CSSConstants.CSS_SILVER_VALUE, 141 ValueConstants.SILVER_RGB_VALUE); 142 computedValues.put(CSSConstants.CSS_GRAY_VALUE, 143 ValueConstants.GRAY_RGB_VALUE); 144 computedValues.put(CSSConstants.CSS_WHITE_VALUE, 145 ValueConstants.WHITE_RGB_VALUE); 146 computedValues.put(CSSConstants.CSS_MAROON_VALUE, 147 ValueConstants.MAROON_RGB_VALUE); 148 computedValues.put(CSSConstants.CSS_RED_VALUE, 149 ValueConstants.RED_RGB_VALUE); 150 computedValues.put(CSSConstants.CSS_PURPLE_VALUE, 151 ValueConstants.PURPLE_RGB_VALUE); 152 computedValues.put(CSSConstants.CSS_FUCHSIA_VALUE, 153 ValueConstants.FUCHSIA_RGB_VALUE); 154 computedValues.put(CSSConstants.CSS_GREEN_VALUE, 155 ValueConstants.GREEN_RGB_VALUE); 156 computedValues.put(CSSConstants.CSS_LIME_VALUE, 157 ValueConstants.LIME_RGB_VALUE); 158 computedValues.put(CSSConstants.CSS_OLIVE_VALUE, 159 ValueConstants.OLIVE_RGB_VALUE); 160 computedValues.put(CSSConstants.CSS_YELLOW_VALUE, 161 ValueConstants.YELLOW_RGB_VALUE); 162 computedValues.put(CSSConstants.CSS_NAVY_VALUE, 163 ValueConstants.NAVY_RGB_VALUE); 164 computedValues.put(CSSConstants.CSS_BLUE_VALUE, 165 ValueConstants.BLUE_RGB_VALUE); 166 computedValues.put(CSSConstants.CSS_TEAL_VALUE, 167 ValueConstants.TEAL_RGB_VALUE); 168 computedValues.put(CSSConstants.CSS_AQUA_VALUE, 169 ValueConstants.AQUA_RGB_VALUE); 170 } 171 172 175 public Value createValue(LexicalUnit lu, CSSEngine engine) 176 throws DOMException { 177 if (lu.getLexicalUnitType() == LexicalUnit.SAC_RGBCOLOR) { 178 lu = lu.getParameters(); 179 Value red = createColorComponent(lu); 180 lu = lu.getNextLexicalUnit().getNextLexicalUnit(); 181 Value green = createColorComponent(lu); 182 lu = lu.getNextLexicalUnit().getNextLexicalUnit(); 183 Value blue = createColorComponent(lu); 184 return createRGBColor(red, green, blue); 185 } 186 return super.createValue(lu, engine); 187 } 188 189 193 public Value computeValue(CSSStylableElement elt, 194 String pseudo, 195 CSSEngine engine, 196 int idx, 197 StyleMap sm, 198 Value value) { 199 if (value.getPrimitiveType() == CSSPrimitiveValue.CSS_IDENT) { 200 String ident = value.getStringValue(); 201 Value v = (Value)computedValues.get(ident); 203 if (v != null) { 204 return v; 205 } 206 if (values.get(ident) == null) { 208 throw new InternalError (); 209 } 210 return engine.getCSSContext().getSystemColor(ident); 211 } 212 return super.computeValue(elt, pseudo, engine, idx, sm, value); 213 } 214 215 218 protected Value createRGBColor(Value r, Value g, Value b) { 219 return new RGBColorValue(r, g, b); 220 } 221 222 225 protected Value createColorComponent(LexicalUnit lu) throws DOMException { 226 switch (lu.getLexicalUnitType()) { 227 case LexicalUnit.SAC_INTEGER: 228 return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 229 lu.getIntegerValue()); 230 231 case LexicalUnit.SAC_REAL: 232 return new FloatValue(CSSPrimitiveValue.CSS_NUMBER, 233 lu.getFloatValue()); 234 235 case LexicalUnit.SAC_PERCENTAGE: 236 return new FloatValue(CSSPrimitiveValue.CSS_PERCENTAGE, 237 lu.getFloatValue()); 238 } 239 throw createInvalidRGBComponentUnitDOMException 240 (lu.getLexicalUnitType()); 241 } 242 243 246 public StringMap getIdentifiers() { 247 return values; 248 } 249 250 private DOMException createInvalidRGBComponentUnitDOMException 251 (short type) { 252 Object [] p = new Object [] { getPropertyName(), 253 new Integer (type) }; 254 String s = Messages.formatMessage("invalid.rgb.component.unit", p); 255 return new DOMException (DOMException.NOT_SUPPORTED_ERR, s); 256 } 257 258 } 259 | Popular Tags |