Package com.storedobject.svg
Class Node
java.lang.Object
com.storedobject.svg.Node
- Direct Known Subclasses:
Canvas,Chart,Element,TransformedNode
Base class for all SVG objects. This represents a single visual unit or part of an SVG document. It has got its own
size and origin, and can be independently translated and scaled. Many such node objects can be combined to form
a larger visual composition.
- Author:
- Syam
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classTransformer for anchoring a node to another one.static classTransformer for adding margins.static classTransformer for moving a node.static classTransformer for scaling by factors.static classTransformer for scaling to a specific size. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringSVG content of the node.protected doubleCurrent x and y coordinates of this node.protected doubleCurrent x and y coordinates of this node.protected doubleCurrent x and y coordinates of this node.protected doubleCurrent x and y coordinates of this node. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdd another node at a specific displacement.Add another node at a specific point.Add another node to this one at a specified side.abstract voidbuild()Build the content.final DocumentCreates a newDocumentinstance associated with the currentNode.Creates and returns a duplicate of the current node instance.final booleanstatic StringEscape XML special characters in a string.Flip this node content horizontally.Flip this node content vertically.Retrieves the coordinates associated with thisNode.final doubleGet the height of the bounding box.final longgetId()Retrieves the unique identifier of the node.final StringgetSvg()Retrieves the SVG representation of the currentNode.final doublegetWidth()Get the width of the bounding box.final doublegetX1()Get the X coordinate of the top-left corner of the bounding box.final doublegetX2()Get the X coordinate of the bottom-right corner of the bounding box.final doublegetY1()Get the Y coordinate of the top-left corner of the bounding box.final doublegetY2()Get the Y coordinate of the bottom-right corner of the bounding box.final inthashCode()static StringID(long id) Generates a unique string identifier for the given numerical ID.static longIDValue()Generates a globally unique identifier in a thread-safe manner.abstract booleanisBuilt()Check if the content is built.margin(double margin) Add a margin to this content.margin(double topMargin, double rightMargin, double bottomMargin, double leftMargin) Add a margin to this content.Add a margin to this SVG on a specific side.moveTo(double x, double y) Moves the current node to a new position specified by the given x and y coordinates.Moves the current node to a new position specified by the givenPoint.scale(double scale) Scale this node content by a specified factor.scale(double scaleX, double scaleY) Scale this node content by specified factors.scaleTo(double newWidth, double newHeight) Scale this node content to new dimensions.scaleToHeight(double newHeight) Scale this node content to a new height.scaleToWidth(double newWidth) Scale this node content to a new width.toString()static StringtoString(double v, int decimals) Convert a double to string with specified decimal places and remove trailing zeros.
-
Field Details
-
svg
SVG content of the node. This is typically set by the build() method. It should not contain the top level svg tag.Note: It can contain one or more svg tags clubbed together to form a logical unit or visual part.
-
x1
protected double x1Current x and y coordinates of this node. These values should be maintained by the subclasses, and these values determine the position, width, and height of the node. If the width and height ae zero, then no output is generated. -
y1
protected double y1Current x and y coordinates of this node. These values should be maintained by the subclasses, and these values determine the position, width, and height of the node. If the width and height ae zero, then no output is generated. -
x2
protected double x2Current x and y coordinates of this node. These values should be maintained by the subclasses, and these values determine the position, width, and height of the node. If the width and height ae zero, then no output is generated. -
y2
protected double y2Current x and y coordinates of this node. These values should be maintained by the subclasses, and these values determine the position, width, and height of the node. If the width and height ae zero, then no output is generated.
-
-
Constructor Details
-
Node
public Node()Default constructor for theNodeclass. Initializes a new instance of the node object with default properties.
-
-
Method Details
-
build
public abstract void build()Build the content. This method is called internally to get before getting the output. -
getX1
public final double getX1()Get the X coordinate of the top-left corner of the bounding box.- Returns:
- X coordinate of the top-left corner.
-
getY1
public final double getY1()Get the Y coordinate of the top-left corner of the bounding box.- Returns:
- Y coordinate of the top-left corner.
-
getX2
public final double getX2()Get the X coordinate of the bottom-right corner of the bounding box.- Returns:
- X coordinate of the bottom-right corner.
-
getY2
public final double getY2()Get the Y coordinate of the bottom-right corner of the bounding box.- Returns:
- Y coordinate of the bottom-right corner.
-
getWidth
public final double getWidth()Get the width of the bounding box.- Returns:
- Width of the bounding box.
-
getHeight
public final double getHeight()Get the height of the bounding box.- Returns:
- Height of the bounding box.
-
isBuilt
public abstract boolean isBuilt()Check if the content is built.- Returns:
- True if built.
-
getId
public final long getId()Retrieves the unique identifier of the node.- Returns:
- The unique identifier as a long value.
-
equals
-
hashCode
-
toString
Convert a double to string with specified decimal places and remove trailing zeros.- Parameters:
v- Value.decimals- Number of decimal places.- Returns:
- Formatted string.
-
escapeXml
-
IDValue
public static long IDValue()Generates a globally unique identifier in a thread-safe manner. The method increments the current ID value atomically. If the ID value reachesLong.MAX_VALUE, it resets to 0 before incrementing.- Returns:
- A unique identifier as a long value.
-
ID
Generates a unique string identifier for the given numerical ID.- Parameters:
id- The numerical ID to be converted into a string identifier.- Returns:
- A string in the format "so-svg-" followed by the numerical ID.
-
getCoordinates
Retrieves the coordinates associated with thisNode.- Returns:
- A
Coordinatesobject representing the bounding coordinates with properties (x1, y1, x2, y2).
-
margin
-
margin
Add a margin to this content.- Parameters:
topMargin- Top margin value.rightMargin- Right margin value.bottomMargin- Bottom margin value.leftMargin- Left margin value.- Returns:
- A new
Nodewith the margin added.
-
margin
-
add
-
add
-
add
-
scaleToWidth
-
scaleToHeight
-
scaleTo
-
scale
-
scale
-
flipHorizontally
-
flipVertically
-
moveTo
Moves the current node to a new position specified by the given x and y coordinates. This method creates a movable version of the current node, applies the movement, and returns the updated instance of theMovableNode.- Parameters:
x- The new x-coordinate to move the node to.y- The new y-coordinate to move the node to.- Returns:
- A new instance of
MovableNodeat the specified position.
-
moveTo
Moves the current node to a new position specified by the givenPoint. This method creates a movable version of the current node, applies the movement, and returns the updated instance ofMovableNode.- Parameters:
p- The new position represented as aPointobject to move the node to.- Returns:
- A new instance of
MovableNodeat the specified position.
-
duplicate
Creates and returns a duplicate of the current node instance. The duplicate is a new instance of the same node with a different unique identifier. However, any changes made to one will reflect in the other.- Returns:
- A new instance of the current node with a different unique identifier.
-
createDocument
-
getSvg
-
toString
-