/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.apache.batik.anim.dom;
import org.apache.batik.anim.values.AnimatableValue;
import org.apache.batik.dom.svg.SVGOMAngle;
import org.apache.batik.util.SVGConstants;
import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.svg.SVGAnimatedAngle;
import org.w3c.dom.svg.SVGAnimatedEnumeration;
import org.w3c.dom.svg.SVGAngle;
import org.w3c.dom.svg.SVGMarkerElement;
A class that handles an SVGAnimatedAngle
and an SVGAnimatedEnumeration
for the 'marker' element's 'orient' attribute. Author: Cameron McCormack Version: $Id: SVGOMAnimatedMarkerOrientValue.java 1733416 2016-03-03 07:07:13Z gadams $
/**
* A class that handles an {@link SVGAnimatedAngle} and an
* {@link SVGAnimatedEnumeration} for the 'marker' element's
* 'orient' attribute.
*
* @author <a href="mailto:cam%40mcc%2eid%2eau">Cameron McCormack</a>
* @version $Id: SVGOMAnimatedMarkerOrientValue.java 1733416 2016-03-03 07:07:13Z gadams $
*/
public class SVGOMAnimatedMarkerOrientValue extends AbstractSVGAnimatedValue {
Whether the base value is valid.
/**
* Whether the base value is valid.
*/
protected boolean valid;
The SVGAnimatedAngle.
/**
* The SVGAnimatedAngle.
*/
protected AnimatedAngle animatedAngle = new AnimatedAngle();
The SVGAnimatedEnumeration.
/**
* The SVGAnimatedEnumeration.
*/
protected AnimatedEnumeration animatedEnumeration =
new AnimatedEnumeration();
The current base angle value.
/**
* The current base angle value.
*/
protected BaseSVGAngle baseAngleVal;
The current base enumeration value.
/**
* The current base enumeration value.
*/
protected short baseEnumerationVal;
The current animated angle value.
/**
* The current animated angle value.
*/
protected AnimSVGAngle animAngleVal;
The current animated enumeration value.
/**
* The current animated enumeration value.
*/
protected short animEnumerationVal;
Whether the value is changing.
/**
* Whether the value is changing.
*/
protected boolean changing;
Creates a new SVGOMAnimatedMarkerOrientValue.
Params: - elt – The associated element.
- ns – The attribute's namespace URI.
- ln – The attribute's local name.
/**
* Creates a new SVGOMAnimatedMarkerOrientValue.
* @param elt The associated element.
* @param ns The attribute's namespace URI.
* @param ln The attribute's local name.
*/
public SVGOMAnimatedMarkerOrientValue(AbstractElement elt,
String ns,
String ln) {
super(elt, ns, ln);
}
Updates the animated value with the given AnimatableValue
. /**
* Updates the animated value with the given {@link AnimatableValue}.
*/
protected void updateAnimatedValue(AnimatableValue val) {
// XXX TODO
throw new UnsupportedOperationException
("Animation of marker orient value is not implemented");
}
Returns the base value of the attribute as an AnimatableValue
. /**
* Returns the base value of the attribute as an {@link AnimatableValue}.
*/
public AnimatableValue getUnderlyingValue(AnimationTarget target) {
// XXX TODO
throw new UnsupportedOperationException
("Animation of marker orient value is not implemented");
}
Called when an Attr node has been added.
/**
* Called when an Attr node has been added.
*/
public void attrAdded(Attr node, String newv) {
if (!changing) {
valid = false;
}
fireBaseAttributeListeners();
if (!hasAnimVal) {
fireAnimatedAttributeListeners();
}
}
Called when an Attr node has been modified.
/**
* Called when an Attr node has been modified.
*/
public void attrModified(Attr node, String oldv, String newv) {
if (!changing) {
valid = false;
}
fireBaseAttributeListeners();
if (!hasAnimVal) {
fireAnimatedAttributeListeners();
}
}
Called when an Attr node has been removed.
/**
* Called when an Attr node has been removed.
*/
public void attrRemoved(Attr node, String oldv) {
if (!changing) {
valid = false;
}
fireBaseAttributeListeners();
if (!hasAnimVal) {
fireAnimatedAttributeListeners();
}
}
Sets the animated value to the given angle.
/**
* Sets the animated value to the given angle.
*/
public void setAnimatedValueToAngle(short unitType, float value) {
hasAnimVal = true;
animAngleVal.setAnimatedValue(unitType, value);
animEnumerationVal = SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE;
fireAnimatedAttributeListeners();
}
Sets the animated value to the "auto" value.
/**
* Sets the animated value to the "auto" value.
*/
public void setAnimatedValueToAuto() {
hasAnimVal = true;
animAngleVal.setAnimatedValue(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED, 0);
animEnumerationVal = SVGMarkerElement.SVG_MARKER_ORIENT_AUTO;
fireAnimatedAttributeListeners();
}
Resets the animated value.
/**
* Resets the animated value.
*/
public void resetAnimatedValue() {
hasAnimVal = false;
fireAnimatedAttributeListeners();
}
Returns the SVGAnimatedAngle
component of the orient value. /**
* Returns the {@link SVGAnimatedAngle} component of the orient value.
*/
public SVGAnimatedAngle getAnimatedAngle() {
return animatedAngle;
}
Returns the SVGAnimatedEnumeration
component of the orient value. /**
* Returns the {@link SVGAnimatedEnumeration} component of the orient value.
*/
public SVGAnimatedEnumeration getAnimatedEnumeration() {
return animatedEnumeration;
}
This class represents the SVGAngle returned by AnimatedAngle.getBaseVal()
. /**
* This class represents the SVGAngle returned by
* {@link AnimatedAngle#getBaseVal()}.
*/
protected class BaseSVGAngle extends SVGOMAngle {
Invalidates this angle.
/**
* Invalidates this angle.
*/
public void invalidate() {
valid = false;
}
Resets the value of the associated attribute.
/**
* Resets the value of the associated attribute.
*/
protected void reset() {
try {
changing = true;
valid = true;
String value;
if (baseEnumerationVal ==
SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE) {
value = getValueAsString();
} else if (baseEnumerationVal ==
SVGMarkerElement.SVG_MARKER_ORIENT_AUTO) {
value = SVGConstants.SVG_AUTO_VALUE;
} else {
return;
}
element.setAttributeNS(namespaceURI, localName, value);
} finally {
changing = false;
}
}
Initializes the angle, if needed.
/**
* Initializes the angle, if needed.
*/
protected void revalidate() {
if (!valid) {
Attr attr = element.getAttributeNodeNS(namespaceURI, localName);
if (attr == null) {
setUnitType(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
value = 0;
} else {
parse(attr.getValue());
}
valid = true;
}
}
Parse a String value as an SVGAngle. If orient="auto", the
method will parse the value "0" instead.
/**
* Parse a String value as an SVGAngle. If orient="auto", the
* method will parse the value "0" instead.
*/
protected void parse(String s) {
if (s.equals(SVGConstants.SVG_AUTO_VALUE)) {
setUnitType(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
value = 0;
baseEnumerationVal = SVGMarkerElement.SVG_MARKER_ORIENT_AUTO;
} else {
super.parse(s);
if (getUnitType() == SVGAngle.SVG_ANGLETYPE_UNKNOWN) {
baseEnumerationVal = SVGMarkerElement.SVG_MARKER_ORIENT_UNKNOWN;
} else {
baseEnumerationVal = SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE;
}
}
}
}
This class represents the SVGAngle returned by AnimatedAngle.getAnimVal()
. /**
* This class represents the SVGAngle returned by {@link AnimatedAngle#getAnimVal()}.
*/
protected class AnimSVGAngle extends SVGOMAngle {
DOM: Implements SVGAngle.getUnitType()
. /**
* <b>DOM</b>: Implements {@link SVGAngle#getUnitType()}.
*/
public short getUnitType() {
if (hasAnimVal) {
return super.getUnitType();
}
return animatedAngle.getBaseVal().getUnitType();
}
DOM: Implements SVGAngle.getValue()
. /**
* <b>DOM</b>: Implements {@link SVGAngle#getValue()}.
*/
public float getValue() {
if (hasAnimVal) {
return super.getValue();
}
return animatedAngle.getBaseVal().getValue();
}
DOM: Implements SVGAngle.getValueInSpecifiedUnits()
. /**
* <b>DOM</b>: Implements {@link SVGAngle#getValueInSpecifiedUnits()}.
*/
public float getValueInSpecifiedUnits() {
if (hasAnimVal) {
return super.getValueInSpecifiedUnits();
}
return animatedAngle.getBaseVal().getValueInSpecifiedUnits();
}
DOM: Implements SVGAngle.getValueAsString()
. /**
* <b>DOM</b>: Implements {@link SVGAngle#getValueAsString()}.
*/
public String getValueAsString() {
if (hasAnimVal) {
return super.getValueAsString();
}
return animatedAngle.getBaseVal().getValueAsString();
}
DOM: Implements SVGAngle.setValue(float)
. /**
* <b>DOM</b>: Implements {@link SVGAngle#setValue(float)}.
*/
public void setValue(float value) throws DOMException {
throw element.createDOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.angle",
null);
}
DOM: Implements SVGAngle.setValueInSpecifiedUnits(float)
. /**
* <b>DOM</b>: Implements {@link
* SVGAngle#setValueInSpecifiedUnits(float)}.
*/
public void setValueInSpecifiedUnits(float value) throws DOMException {
throw element.createDOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.angle",
null);
}
DOM: Implements SVGAngle.setValueAsString(String)
. /**
* <b>DOM</b>: Implements {@link SVGAngle#setValueAsString(String)}.
*/
public void setValueAsString(String value) throws DOMException {
throw element.createDOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.angle",
null);
}
DOM: Implements SVGAngle.newValueSpecifiedUnits(short, float)
. /**
* <b>DOM</b>: Implements {@link
* SVGAngle#newValueSpecifiedUnits(short,float)}.
*/
public void newValueSpecifiedUnits(short unit, float value) {
throw element.createDOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.angle",
null);
}
DOM: Implements SVGAngle.convertToSpecifiedUnits(short)
. /**
* <b>DOM</b>: Implements {@link
* SVGAngle#convertToSpecifiedUnits(short)}.
*/
public void convertToSpecifiedUnits(short unit) {
throw element.createDOMException
(DOMException.NO_MODIFICATION_ALLOWED_ERR, "readonly.angle",
null);
}
Sets the animated value.
/**
* Sets the animated value.
*/
protected void setAnimatedValue(int type, float val) {
super.newValueSpecifiedUnits((short) type, val);
}
}
The SVGAnimatedAngle
component of the marker orient value. /**
* The {@link SVGAnimatedAngle} component of the marker orient value.
*/
protected class AnimatedAngle implements SVGAnimatedAngle {
DOM: Implements SVGAnimatedAngle.getBaseVal()
. /**
* <b>DOM</b>: Implements {@link SVGAnimatedAngle#getBaseVal()}.
*/
public SVGAngle getBaseVal() {
if (baseAngleVal == null) {
baseAngleVal = new BaseSVGAngle();
}
return baseAngleVal;
}
DOM: Implements SVGAnimatedAngle.getAnimVal()
. /**
* <b>DOM</b>: Implements {@link SVGAnimatedAngle#getAnimVal()}.
*/
public SVGAngle getAnimVal() {
if (animAngleVal == null) {
animAngleVal = new AnimSVGAngle();
}
return animAngleVal;
}
}
The SVGAnimatedEnumeration
component of the marker orient value. /**
* The {@link SVGAnimatedEnumeration} component of the marker orient value.
*/
protected class AnimatedEnumeration implements SVGAnimatedEnumeration {
DOM: Implements SVGAnimatedEnumeration.getBaseVal()
. /**
* <b>DOM</b>: Implements {@link SVGAnimatedEnumeration#getBaseVal()}.
*/
public short getBaseVal() {
if (baseAngleVal == null) {
baseAngleVal = new BaseSVGAngle();
}
baseAngleVal.revalidate();
return baseEnumerationVal;
}
DOM: Implements SVGAnimatedEnumeration.setBaseVal(short)
. /**
* <b>DOM</b>: Implements {@link
* SVGAnimatedEnumeration#setBaseVal(short)}.
*/
public void setBaseVal(short baseVal) throws DOMException {
if (baseVal == SVGMarkerElement.SVG_MARKER_ORIENT_AUTO) {
baseEnumerationVal = baseVal;
if (baseAngleVal == null) {
baseAngleVal = new BaseSVGAngle();
}
baseAngleVal.setUnitType(SVGAngle.SVG_ANGLETYPE_UNSPECIFIED);
baseAngleVal.setValue(0);
baseAngleVal.reset();
} else if (baseVal == SVGMarkerElement.SVG_MARKER_ORIENT_ANGLE) {
baseEnumerationVal = baseVal;
if (baseAngleVal == null) {
baseAngleVal = new BaseSVGAngle();
}
baseAngleVal.reset();
}
}
DOM: Implements SVGAnimatedEnumeration.getAnimVal()
. /**
* <b>DOM</b>: Implements {@link SVGAnimatedEnumeration#getAnimVal()}.
*/
public short getAnimVal() {
if (hasAnimVal) {
return animEnumerationVal;
}
if (baseAngleVal == null) {
baseAngleVal = new BaseSVGAngle();
}
baseAngleVal.revalidate();
return baseEnumerationVal;
}
}
}