Class Node<N extends Node<N>>
- Type Parameters:
N- Type of the node.
- All Implemented Interfaces:
Serializable
Note: The coordinates system used has the origin (0, 0) in the top left corner.
- Author:
- Syam
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intThe numeric precision used for formatting double values in the SVG output.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 TypeMethodDescriptionprotected StringRetrieves a string representation of the node's attributes.protected voidcompute()This method is invoked to perform any necessary computations just before the SVG content is generated.copy()Create a copy of this node instance.final DocumentCreates a newDocumentinstance associated with the currentNode.final booleanCompares this node with another object for equality.static StringEscape XML special characters in a string.protected StringProvides additional content specific to the node.final NFlips the node horizontally.final NFlips the node horizontally around the origin (0, 0).Flips the node vertically.final NFlips the node vertically around the origin (0, 0).Retrieves the coordinates associated with thisNode.final longgetId()Retrieves the unique identifier of the node.Retrieves the margin associated with this node.final StringgetSvg()Retrieves the SVG representation of the currentNode.final inthashCode()Returns a hash code for this node based on its unique ID.protected longid()Retrieves the unique identifier of the node.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.protected StringRetrieves the inner content of the node.final NmoveTo(double x, double y) Moves the node to a specified (x, y) coordinate.final NMoves the node to a specifiedPoint.final Nrotate(double angle) Rotates the node by a given angle around its origin.final NrotateAround(double angle, double x, double y) Rotates the node by a given angle around a specified point (x, y).final NrotateAround(double angle, Point point) Rotates the node by a given angle around a specifiedPoint.final NrotateAroundCenter(double angle) Rotates the node by a given angle around its center.final Nscale(double scale) Scales the node uniformly by a given factor.final Nscale(double sx, double sy) Scales the node by given factors sx and sy.final NscaleHeightTo(double toHeight) Scales the height of the node to a specified value.final NscaleTo(double toWidth, double toHeight) Scales the node to a specified width and height.final NscaleWidthTo(double toWidth) Scales the width of the node to a specified value.protected Stringstyles()Retrieves the styles associated with this node.protected Stringtag()Retrieves the tag associated with this node.final StringtoString()static StringtoString(double v) Converts the given double value to a string representation with specified numeric precision.final TransformMatrix<N> Retrieves the transformation matrix associated with this node.final Ntranslate(double dx, double dy) Translates the node by a given offset (dx, dy).final NTranslates the node by a given offset specified as aPoint.
-
Field Details
-
NUMERIC_PRECISION
public static int NUMERIC_PRECISIONThe numeric precision used for formatting double values in the SVG output. The default value is 4. -
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.Note: Computation of these values should not take care of any transformations applied to the node. Changes to the coordinates due to transformation are automatically handled.
-
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.Note: Computation of these values should not take care of any transformations applied to the node. Changes to the coordinates due to transformation are automatically handled.
-
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.Note: Computation of these values should not take care of any transformations applied to the node. Changes to the coordinates due to transformation are automatically handled.
-
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.Note: Computation of these values should not take care of any transformations applied to the node. Changes to the coordinates due to transformation are automatically handled.
-
-
Constructor Details
-
Node
public Node()Default constructor for theNodeclass. Initializes a new instance of the node object with default properties.
-
-
Method Details
-
tag
Retrieves the tag associated with this node. This tag is typically used to denote the type or category of the node in contexts such as SVG generation or XML representation.Note: If null is returned, it indicates that the node does not have a specific tag and may be treated as a generic group. In such cases, only inner content and extra content are considered.
- Returns:
- A string representing the tag of the node. The default implementation returns "g".
-
id
protected long id()Retrieves the unique identifier of the node.- Returns:
- The unique identifier as a long value.
-
attributes
Retrieves a string representation of the node's attributes. This method is typically overridden by subclasses to provide specific attributes corresponding to the node's state or properties. By default, this method returns null if no attributes are defined.- Returns:
- A string representing the attributes of the node, or null if no attributes are defined.
-
innerContent
Retrieves the inner content of the node. This method is typically implemented or overridden by subclasses to provide specific content representing the inner state or structure of the node.- Returns:
- A string containing the inner content of the node, or null if no content is defined.
-
extraContent
Provides additional content specific to the node. This method is intended to be overridden by subclasses to define custom extra content specific to their implementation. By default, it returns null if no additional content is defined.Note: The extra content should be formatted as per SVG standards with appropriate tags. No validation is performed on the extra content.
- Returns:
- A string representing the extra content of the node, or null if no extra content is defined.
-
styles
Retrieves the styles associated with this node. This method is typically overridden by subclasses to provide specific styling information related to the node's state or properties.- Returns:
- A string representing the styles of the node, or null if no styles are defined.
-
getId
public final long getId()Retrieves the unique identifier of the node.- Returns:
- The unique identifier as a long value.
-
transform
Retrieves the transformation matrix associated with this node. If the transformation matrix is not already initialized, this method creates a newTransformMatrixinstance and returns it.- Returns:
- The
TransformMatrixobject associated with this node.
-
flipVertically
-
flipVerticallyAroundOrigin
Flips the node vertically around the origin (0, 0).- Returns:
- The node itself after flipping.
-
flipHorizontally
Flips the node horizontally.- Returns:
- The node itself after flipping.
-
flipHorizontallyAroundOrigin
Flips the node horizontally around the origin (0, 0).- Returns:
- The node itself after flipping.
-
rotate
Rotates the node by a given angle around its origin.- Parameters:
angle- The clockwise angle of rotation in degrees.- Returns:
- The node itself after rotation.
-
rotateAroundCenter
Rotates the node by a given angle around its center.- Parameters:
angle- The clockwise angle of rotation in degrees.- Returns:
- The node itself after rotation.
-
rotateAround
Rotates the node by a given angle around a specified point (x, y).- Parameters:
angle- The clockwise angle of rotation in degrees.x- The x-coordinate of the rotation center.y- The y-coordinate of the rotation center.- Returns:
- The node itself after rotation.
-
rotateAround
-
translate
Translates the node by a given offset (dx, dy).- Parameters:
dx- The distance to translate along the x-axis.dy- The distance to translate along the y-axis.- Returns:
- The node itself after translation.
-
translate
-
moveTo
-
moveTo
Moves the node to a specified (x, y) coordinate.- Parameters:
x- The destination x-coordinate.y- The destination y-coordinate.- Returns:
- The node itself after moving.
-
scale
Scales the node uniformly by a given factor.- Parameters:
scale- The scaling factor.- Returns:
- The node itself after scaling.
-
scaleWidthTo
Scales the width of the node to a specified value.- Parameters:
toWidth- The target width.- Returns:
- The node itself after scaling.
-
scaleHeightTo
Scales the height of the node to a specified value.- Parameters:
toHeight- The target height.- Returns:
- The node itself after scaling.
-
scale
Scales the node by given factors sx and sy.- Parameters:
sx- The scaling factor along the x-axis.sy- The scaling factor along the y-axis.- Returns:
- The node itself after scaling.
-
scaleTo
Scales the node to a specified width and height.- Parameters:
toWidth- The target width.toHeight- The target height.- Returns:
- The node itself after scaling.
-
equals
-
hashCode
-
copy
Create a copy of this node instance.- Returns:
- a new instance that is a copy of this node but with a new unique ID.
-
toString
Converts the given double value to a string representation with specified numeric precision.- Parameters:
v- the double value to be converted to a string- Returns:
- the string representation of the given double value with the applied numeric precision
-
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.Note: This method returns the bounding coordinates of the node's content, and it does not include any margin and/or transforms applied to the node.
- Returns:
- A
Coordinatesobject representing the bounding coordinates with properties (x1, y1, x2, y2).
-
getMargin
Retrieves the margin associated with this node. If the margin is not yet initialized, a newMargininstance is created and returned.- Returns:
- The margin object associated with this node.
-
createDocument
-
getSvg
-
compute
protected void compute()This method is invoked to perform any necessary computations just before the SVG content is generated.Note: At least coordinates values should be set here properly.
-
toString
-