ShapeNodepublic class ShapeNode extends AbstractShapeNode A ShapesNode is an AbstractShapeNode
which draws a java.awt.geom.GeneralPath.
Note that the paint method throws a NullPointerException
when called before setting the shape property to a non-null
value.
|
Fields Summary |
---|
static final com.sun.perseus.j2d.Path | EMPTY_PATHEMPTY_PATH is used initially by the ShapeNode class.
This constant is used so that a new ShapeNode, right upon creation,
may be rendered. The only place where the path is mutated is in
the animation code. But the animation can only work if the
path has real data. Therefore, it is safe to use this final static
constant to initialize all ShapeNode instances (and avoid instantiating
Path objects that are always tossed away later on). | static final String[] | PATH_REQUIRED_TRAITSThe d attribute is required on | static final String[] | POLY_ALL_REQUIRED_TRAITSThe points attribute is required on and | protected com.sun.perseus.j2d.Path | pathThe Path painted by this node. Should _never_ be set to null. | protected String | localNameThe path's local name. One of
SVGConstants.SVG_PATH_TAG, SVGConstants.SVG_POLYGON_TAG,
or SVGConstants.SVG_POLYLINE_TAG. |
Constructors Summary |
---|
public ShapeNode(DocumentNode ownerDocument)Constructor.
this(ownerDocument, SVGConstants.SVG_PATH_TAG);
// The ShapeNode initially has an empty path, so that is reflected in
// the canRenderState.
canRenderState |= CAN_RENDER_EMPTY_PATH_BIT;
| public ShapeNode(DocumentNode ownerDocument, String localName)Constructs a new ShapeNode to represent an path, polyline,
or polygon (depending on the localName value).
super(ownerDocument);
if (SVGConstants.SVG_POLYLINE_TAG == localName
||
SVGConstants.SVG_POLYGON_TAG == localName
||
SVGConstants.SVG_PATH_TAG == localName) {
this.localName = localName;
} else {
throw new IllegalArgumentException();
}
|
Methods Summary |
---|
com.sun.perseus.j2d.Box | addNodeBBox(com.sun.perseus.j2d.Box bbox, com.sun.perseus.j2d.Transform t)
return addShapeBBox(bbox, path, t);
| public boolean | contains(float x, float y, int fillRule)
return PathSupport.isHit(path, fillRule, x, y);
| TraitAnim | createTraitAnimImpl(java.lang.String traitName)
if (SVGConstants.SVG_D_ATTRIBUTE == traitName
||
SVGConstants.SVG_POINTS_ATTRIBUTE == traitName) {
return new FloatTraitAnim(this, traitName, TRAIT_TYPE_SVG_PATH);
} else {
return super.createTraitAnimImpl(traitName);
}
| public void | drawShape(com.sun.perseus.j2d.RenderGraphics rg)
rg.draw(path);
| public void | fillShape(com.sun.perseus.j2d.RenderGraphics rg)
rg.fill(path);
| public java.lang.String | getLocalName()
return localName;
| org.w3c.dom.svg.SVGPath | getPathTraitImpl(java.lang.String name)ShapeNode handles the 'd' trait.
if (SVGConstants.SVG_PATH_TAG.equals(localName)
&& SVGConstants.SVG_D_ATTRIBUTE.equals(name)) {
return new Path(path);
} else {
return super.getPathTraitImpl(name);
}
| public java.lang.String[] | getRequiredTraits()
if (SVGConstants.SVG_PATH_TAG == localName) {
return PATH_REQUIRED_TRAITS;
} else {
return POLY_ALL_REQUIRED_TRAITS;
}
| public com.sun.perseus.j2d.Path | getShape()
return path;
| java.lang.Object | getStrokedPath(com.sun.perseus.j2d.GraphicsProperties gp)Returns the stroked shape, using the given stroke properties.
return PathSupport.getStrokedPath(path, gp);
| public java.lang.String | getTraitImpl(java.lang.String name)ShapeNode handles the 'd' trait.
if (SVGConstants.SVG_PATH_TAG == localName) {
if (SVGConstants.SVG_D_ATTRIBUTE == name) {
return path.toString();
}
} else if (SVGConstants.SVG_POINTS_ATTRIBUTE == name) {
return path.toPointsString();
}
return super.getTraitImpl(name);
| public ElementNode | newInstance(DocumentNode doc)Used by DocumentNode to create a new instance from
a prototype SVG .
return new ShapeNode(doc, localName);
| void | setFloatArrayTrait(java.lang.String name, float[][] value)Set the trait value as float.
if (SVGConstants.SVG_D_ATTRIBUTE == name
||
SVGConstants.SVG_POINTS_ATTRIBUTE == name) {
if (!path.equals(value)) {
modifyingNode();
renderingDirty();
path.setData(value[0]);
modifiedNode();
}
} else {
super.setFloatArrayTrait(name, value);
}
| public void | setPath(com.sun.perseus.j2d.Path newPath)
if (equal(newPath, path)) {
return;
}
modifyingNode();
renderingDirty();
if (newPath != null) {
this.path = newPath;
} else {
this.path = new Path();
}
computeCanRenderEmptyPathBit(this.path);
modifiedNode();
| void | setPathTraitImpl(java.lang.String name, org.w3c.dom.svg.SVGPath path)ShapeNode handles the 'd' trait.
// Note that here, we use equals because the strings
// have not been interned.
if (SVGConstants.SVG_PATH_TAG.equals(localName)
&&
SVGConstants.SVG_D_ATTRIBUTE.equals(name)) {
if (path.getNumberOfSegments() > 0
&&
path.getSegment(0) != SVGPath.MOVE_TO) {
// The first command _must_ be a moveTo.
// However, note than an empty path is accepted.
throw illegalTraitValue(name, path.toString());
}
setPath(new Path((Path) path));
} else {
super.setPathTraitImpl(name, path);
}
| public void | setTraitImpl(java.lang.String name, java.lang.String value)ShapeNode handles the 'd' trait if it is a path and the
'points' trait if it is a polygon or a polyline.
if (SVGConstants.SVG_PATH_TAG == localName) {
if (SVGConstants.SVG_D_ATTRIBUTE == name) {
setPath(parsePathTrait(name, value));
} else {
super.setTraitImpl(name, value);
}
} else if (SVGConstants.SVG_POINTS_ATTRIBUTE == name) {
setPath(parsePointsTrait(name, value));
// As per the specification, section 9.7 of the SVG 1.1 spec.,
// we need to close the path if we are dealing with a polygon.
// Only do so if the document does not have a delayed exception
// which means this element was loading and an error was detected
// in the points data.
if (ownerDocument.getDelayedException() == null) {
if (SVGConstants.SVG_POLYGON_TAG == localName) {
path.close();
}
}
} else {
super.setTraitImpl(name, value);
}
| boolean | supportsTrait(java.lang.String traitName)ShapeNode handles the 'd' trait.
if (SVGConstants.SVG_PATH_TAG == localName) {
if (SVGConstants.SVG_D_ATTRIBUTE == traitName) {
return true;
}
} else if (SVGConstants.SVG_POINTS_ATTRIBUTE == traitName) {
// For polygon and polyline, the points trait is
// supported.
return true;
}
return super.supportsTrait(traitName);
| java.lang.String | toStringTrait(java.lang.String name, float[][] value)
if (SVGConstants.SVG_PATH_TAG.equals(localName)
&&
SVGConstants.SVG_D_ATTRIBUTE.equals(name)) {
return path.toString(value[0]);
} else if (SVGConstants.SVG_POINTS_ATTRIBUTE.equals(name)) {
return path.toPointsString(value[0]);
} else {
return super.toStringTrait(name, value);
}
| public float[][] | validateFloatArrayTrait(java.lang.String traitName, java.lang.String value, java.lang.String reqNamespaceURI, java.lang.String reqLocalName, java.lang.String reqTraitNamespace, java.lang.String reqTraitName)Validates the input trait value.
if (SVGConstants.SVG_D_ATTRIBUTE == traitName) {
Path path = parsePathTrait(traitName, value);
return toAnimatedFloatArray(path);
} else if (SVGConstants.SVG_POINTS_ATTRIBUTE == traitName) {
Path path = parsePointsTrait(traitName, value);
if (SVGConstants.SVG_POLYGON_TAG == localName) {
path.close();
}
return toAnimatedFloatArray(path);
} else {
return super.validateFloatArrayTrait(traitName,
value,
reqNamespaceURI,
reqLocalName,
reqTraitNamespace,
reqTraitName);
}
|
|