/** * Returns the parsed 'type' attribute from the animation element. */ protected short parseType() { String typeString = element.getAttributeNS(null, SVG_TYPE_ATTRIBUTE); if (typeString.equals("translate")) { return SVGTransform.SVG_TRANSFORM_TRANSLATE; } else if (typeString.equals("scale")) { return SVGTransform.SVG_TRANSFORM_SCALE; } else if (typeString.equals("rotate")) { return SVGTransform.SVG_TRANSFORM_ROTATE; } else if (typeString.equals("skewX")) { return SVGTransform.SVG_TRANSFORM_SKEWX; } else if (typeString.equals("skewY")) { return SVGTransform.SVG_TRANSFORM_SKEWY; } throw new BridgeException (ctx, element, ErrorConstants.ERR_ATTRIBUTE_VALUE_MALFORMED, new Object[] { SVG_TYPE_ATTRIBUTE, typeString }); }
/** * <b>DOM</b>: Implements {@link SVGTransformList#consolidate()}. */ public SVGTransform consolidate() { revalidate(); int size = itemList.size(); if (size == 0) { return null; } else if (size == 1) { return getItem(0); } SVGTransformItem t = (SVGTransformItem) getItemImpl(0); AffineTransform at = (AffineTransform) t.affineTransform.clone(); for (int i = 1; i < size; i++) { t = (SVGTransformItem) getItemImpl(i); at.concatenate(t.affineTransform); } SVGOMMatrix matrix = new SVGOMMatrix(at); return initialize(createSVGTransformFromMatrix(matrix)); }
/** * Sets the animated value to a list of transforms. */ protected void setAnimatedValue(Iterator it) { int size = itemList.size(); int i = 0; while (i < size && it.hasNext()) { SVGTransformItem t = (SVGTransformItem) itemList.get(i); t.assign((SVGTransform) it.next()); i++; } while (it.hasNext()) { appendItemImpl(new SVGTransformItem((SVGTransform) it.next())); i++; } while (size > i) { removeItemImpl(--size); } }
/** * Returns the absolute distance between this value and the specified other * value. */ public float distanceTo(AnimatableValue other) { AnimatableTransformListValue o = (AnimatableTransformListValue) other; if (transforms.isEmpty() || o.transforms.isEmpty()) { return 0f; } AbstractSVGTransform t1 = (AbstractSVGTransform) transforms.lastElement(); AbstractSVGTransform t2 = (AbstractSVGTransform) o.transforms.lastElement(); short type1 = t1.getType(); if (type1 != t2.getType()) { return 0f; } SVGMatrix m1 = t1.getMatrix(); SVGMatrix m2 = t2.getMatrix(); switch (type1) { case SVGTransform.SVG_TRANSFORM_TRANSLATE: return Math.abs(m1.getE() - m2.getE()) + Math.abs(m1.getF() - m2.getF()); case SVGTransform.SVG_TRANSFORM_SCALE: return Math.abs(m1.getA() - m2.getA()) + Math.abs(m1.getD() - m2.getD()); case SVGTransform.SVG_TRANSFORM_ROTATE: case SVGTransform.SVG_TRANSFORM_SKEWX: case SVGTransform.SVG_TRANSFORM_SKEWY: return Math.abs(t1.getAngle() - t2.getAngle()); } return 0f; }
/** * Returns the distance between this value's first component and the * specified other value's first component. */ public float distanceTo1(AnimatableValue other) { AnimatableTransformListValue o = (AnimatableTransformListValue) other; if (transforms.isEmpty() || o.transforms.isEmpty()) { return 0f; } AbstractSVGTransform t1 = (AbstractSVGTransform) transforms.lastElement(); AbstractSVGTransform t2 = (AbstractSVGTransform) o.transforms.lastElement(); short type1 = t1.getType(); if (type1 != t2.getType()) { return 0f; } SVGMatrix m1 = t1.getMatrix(); SVGMatrix m2 = t2.getMatrix(); switch (type1) { case SVGTransform.SVG_TRANSFORM_TRANSLATE: return Math.abs(m1.getE() - m2.getE()); case SVGTransform.SVG_TRANSFORM_SCALE: return Math.abs(m1.getA() - m2.getA()); case SVGTransform.SVG_TRANSFORM_ROTATE: case SVGTransform.SVG_TRANSFORM_SKEWX: case SVGTransform.SVG_TRANSFORM_SKEWY: return Math.abs(t1.getAngle() - t2.getAngle()); } return 0f; }
/** * Returns the distance between this value's second component and the * specified other value's second component. */ public float distanceTo2(AnimatableValue other) { AnimatableTransformListValue o = (AnimatableTransformListValue) other; if (transforms.isEmpty() || o.transforms.isEmpty()) { return 0f; } AbstractSVGTransform t1 = (AbstractSVGTransform) transforms.lastElement(); AbstractSVGTransform t2 = (AbstractSVGTransform) o.transforms.lastElement(); short type1 = t1.getType(); if (type1 != t2.getType()) { return 0f; } SVGMatrix m1 = t1.getMatrix(); SVGMatrix m2 = t2.getMatrix(); switch (type1) { case SVGTransform.SVG_TRANSFORM_TRANSLATE: return Math.abs(m1.getF() - m2.getF()); case SVGTransform.SVG_TRANSFORM_SCALE: return Math.abs(m1.getD() - m2.getD()); case SVGTransform.SVG_TRANSFORM_ROTATE: return Math.abs(t1.getX() - t2.getX()); } return 0f; }
/** * Returns the distance between this value's third component and the * specified other value's third component. */ public float distanceTo3(AnimatableValue other) { AnimatableTransformListValue o = (AnimatableTransformListValue) other; if (transforms.isEmpty() || o.transforms.isEmpty()) { return 0f; } AbstractSVGTransform t1 = (AbstractSVGTransform) transforms.lastElement(); AbstractSVGTransform t2 = (AbstractSVGTransform) o.transforms.lastElement(); short type1 = t1.getType(); if (type1 != t2.getType()) { return 0f; } if (type1 == SVGTransform.SVG_TRANSFORM_ROTATE) { return Math.abs(t1.getY() - t2.getY()); } return 0f; }
/** * Asserts that the given item is an {@link SVGTransformList}. */ protected void checkItemType(Object newItem) { if (!(newItem instanceof SVGTransform)) { createSVGException(SVGException.SVG_WRONG_TYPE_ERR, "expected.transform", null); } }
/** * Creates the {@link SVGMatrix} used to store the transform. */ protected SVGMatrix createMatrix() { return new AbstractSVGMatrix() { protected AffineTransform getAffineTransform() { return SVGTransformItem.this.affineTransform; } public void setA(float a) throws DOMException { SVGTransformItem.this.type = SVGTransform.SVG_TRANSFORM_MATRIX; super.setA(a); SVGTransformItem.this.resetAttribute(); } public void setB(float b) throws DOMException { SVGTransformItem.this.type = SVGTransform.SVG_TRANSFORM_MATRIX; super.setB(b); SVGTransformItem.this.resetAttribute(); } public void setC(float c) throws DOMException { SVGTransformItem.this.type = SVGTransform.SVG_TRANSFORM_MATRIX; super.setC(c); SVGTransformItem.this.resetAttribute(); } public void setD(float d) throws DOMException { SVGTransformItem.this.type = SVGTransform.SVG_TRANSFORM_MATRIX; super.setD(d); SVGTransformItem.this.resetAttribute(); } public void setE(float e) throws DOMException { SVGTransformItem.this.type = SVGTransform.SVG_TRANSFORM_MATRIX; super.setE(e); SVGTransformItem.this.resetAttribute(); } public void setF(float f) throws DOMException { SVGTransformItem.this.type = SVGTransform.SVG_TRANSFORM_MATRIX; super.setF(f); SVGTransformItem.this.resetAttribute(); } }; }
/** * <b>DOM</b>: Implements {@link SVGTransformList#getItem(int)}. */ public SVGTransform getItem(int index) throws DOMException { if (hasAnimVal) { return super.getItem(index); } return getBaseVal().getItem(index); }
/** * <b>DOM</b>: Implements {@link SVGTransformList#initialize(SVGTransform)}. */ public SVGTransform initialize(SVGTransform newItem) throws DOMException, SVGException { throw element.createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.transform.list", null); }
/** * <b>DOM</b>: Implements {@link * SVGTransformList#insertItemBefore(SVGTransform, int)}. */ public SVGTransform insertItemBefore(SVGTransform newItem, int index) throws DOMException, SVGException { throw element.createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.transform.list", null); }
/** * <b>DOM</b>: Implements {@link * SVGTransformList#replaceItem(SVGTransform, int)}. */ public SVGTransform replaceItem(SVGTransform newItem, int index) throws DOMException, SVGException { throw element.createDOMException (DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.transform.list", null); }
/** * Sets the animated value to a single transform. */ protected void setAnimatedValue(SVGTransform transform) { int size = itemList.size(); while (size > 1) { removeItemImpl(--size); } if (size == 0) { appendItemImpl(new SVGTransformItem(transform)); } else { SVGTransformItem t = (SVGTransformItem) itemList.get(0); t.assign(transform); } }