public SVGStylableElementCSSHandler(CSSEngine cssEngine, SVGStylableElement element) { this.cssEngine = cssEngine; this.element = element; this.originalCSSText = element.getStyle().getCssText(); SVGStylableElement.StyleDeclaration embedStyle = (SVGStylableElement.StyleDeclaration) element.getStyle(); this.originalStyle = new CloneableStyleDeclaration(embedStyle.getStyleDeclaration()); }
public void updateCSSColor(Color colorToChange, Color newColor) { if (colorToChange == null || newColor == null || colorToChange.equals(newColor)) { return; } FloatValue newRedValue = new FloatValue((short) 1, (float) newColor.getRed()); FloatValue newGreenValue = new FloatValue((short) 1, (float) newColor.getGreen()); FloatValue newBlueValue = new FloatValue((short) 1, (float) newColor.getBlue()); RGBColorValue newRGBColorValue = new RGBColorValue(newRedValue, newGreenValue, newBlueValue); StyleDeclaration sd = originalStyle.clone(); int sdlen = sd.size(); for (int sdindex = 0; sdindex < sdlen; sdindex++) { Value val = sd.getValue(sdindex); if (val instanceof RGBColorValue) { RGBColorValue colorVal = (RGBColorValue) val; if (isSameColor(colorVal, colorToChange)) { sd.put(sdindex, newRGBColorValue, sd.getIndex(sdindex), sd.getPriority(sdindex)); } } } element.getStyle().setCssText(sd.toString(cssEngine)); }
@Override public void resetCSSStyle() { element.getStyle().setCssText(originalCSSText); }