Interface SVGPrimitive
-
- All Known Implementing Classes:
SVGArrow
,SVGClassBox
,SVGLine
,SVGLink
,SVGRectangle
,SVGText
,SVGUnion
public interface SVGPrimitive
This interface is the root of all drawable SVG primitives. It includes functions to render, rescaling and translate them.- Author:
- Martin Schroeder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description List<Point2D.Double>
getAttachmentPoints()
Returns the list of points to which other elements (especially arrows) can be attached.Rectangle2D.Double
getBounds()
Returns the outer, rectangular bounds of this primitive.void
moveTo(Point2D.Double pos)
Move the object to the given (x,y) position.Element
render(Document doc)
This function should return an element containing the primitive in question at its current location that can be inserted into the givenDocument
.void
rescale(double factor, boolean applyToStyles)
Rescales the primitive by the given positive factor.void
translate(Point2D.Double offset)
Translate the current position by the given (x,y) tuple.
-
-
-
Method Detail
-
render
Element render(Document doc)
This function should return an element containing the primitive in question at its current location that can be inserted into the givenDocument
.- Parameters:
doc
- the document to render into- Returns:
- an XML
Element
that contains the necessary attributes to draw the primitive into an SVG document. Must return a new copy of the element on every invocation to allow for one primitive to generate multiple copies.
-
translate
void translate(Point2D.Double offset)
Translate the current position by the given (x,y) tuple.It is strictly necessary that the translation is applied identically to all sub-elements as long as it makes sense to translate them. Links or rotations for example do not need to be moved; as they only alter their child primitives and do not have a "location" to speak of.
- Parameters:
offset
- the amount to move the primitive in (x,y) direction.
-
moveTo
void moveTo(Point2D.Double pos)
Move the object to the given (x,y) position.It is strictly necessary that the move is applied identically to all sub-elements as long as it makes sense to move them. Links or rotations for example do not need to be moved; as they only alter their child primitives and do not have a "location" to speak of.
- Parameters:
pos
- the new position in the (x,y) plane.
-
rescale
void rescale(double factor, boolean applyToStyles)
Rescales the primitive by the given positive factor. Rescaling must keep the aspect ratio and must not alter the (x,y) position of the top left corner.That means; resizing does not move the primitive; but only expands or shrinks it in the positive x/y direction.
- Parameters:
factor
- the multiplier to rescale the primitive by. Must be positive.applyToStyles
- if set to true; rescaling also affects styling, for example line widths.
-
getBounds
Rectangle2D.Double getBounds()
Returns the outer, rectangular bounds of this primitive.It is assumed that this value is being cached and not recomputed until the element is translated. After recomputation, the returned element can, but does not have to be a new object.
If you want to get the center of this element, call this function followed by
RectangularShape.getCenterX()
andRectangularShape.getCenterY()
.- Returns:
- the outer bounds of this object; or null if not a graphical primitive.
-
getAttachmentPoints
List<Point2D.Double> getAttachmentPoints()
Returns the list of points to which other elements (especially arrows) can be attached. The points should ideally be on the exterior surface of the element; but that is not a strict demand.This function may return null or an empty list if the element is not graphical.
- Returns:
- a list of points.
-
-