Class SvgElement
java.lang.Object
com.vaadin.flow.component.svg.elements.SvgElement
- Direct Known Subclasses:
AbstractPolyElement,Circle,Ellipse,Group,Image,Path,Rect,Text,TextPath
This is the base class for all the Svg elements and contains the attributes
as they were given to the client as well as any pending complex updates to
be sent.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddClassName(String className) Add a class name for this elementvoidPrimarily intended for internal use for clearing and setting the updates array (for complex updates) after each push to the client by the Svg class.tools.jackson.databind.node.ObjectNodeReturns a cloned set of the current attributes (including updates) of thisSvgElement.protected static tools.jackson.databind.node.ArrayNodecreateArgArray(tools.jackson.databind.JsonNode... args) Creates a Json array based on the provided Json valuesvoidFlips the component in relation to the axis given.getAttribute(String key) Returns a value from the internal attributes mapprotected tools.jackson.databind.node.ObjectNodeReturns the attributes object that should contain the complete state of thisSvgElementprotected BooleanConvenience method for getting a Boolean attribute.Returns the current fill color of this elementgetId()Returns the id of thisSvgElementprotected NumbergetNumberAttribute(String key) Convenience method for fetching a number attribute from the internal array.protected StringgetStringAttribute(String key) Convenience method for getting a String attribute from the internal array.tools.jackson.databind.node.ObjectNodeDeprecated.protected tools.jackson.databind.node.ArrayNodeReturns the pending updates for this elementbooleanReturns the current draggable flag for this element as last given.voidmove(double x, double y) Moves the given element within the viewbox with the relative values provided.protected voidpushUpdate(String name, tools.jackson.databind.JsonNode... args) Creates a more complex update call where a specific client-side method needs to be called with arguments in order to perform a client-side update.voidremoveClassName(String className) Remove a class name for this elementvoidrotate(double angle) Rotates the component with the amount given in the angle.protected voidsetAttribute(String key, boolean value) Convenience method for setting a Java Boolean.protected voidsetAttribute(String key, Number value) Convenience method for setting a Java number attribute.voidsetAttribute(String key, String value) Convenience method for setting a string attribute.protected voidsetAttribute(String key, tools.jackson.databind.JsonNode value) Maps a Json value to a key in the internal attributes array.protected voidsetAttributes(tools.jackson.databind.node.ObjectNode attributes) Sets the internal attributes array.protected voidsetConstructor(SvgType type, tools.jackson.databind.JsonNode... args) Sets the constructor value for the client side as well as the initial arguments list.voidsetDraggable(boolean draggable) Sets the draggable flag for this element.voidsetFillColor(String color) Sets the fill color of this element.protected voidSets the id of this element, should never be null.voidsetPosition(double x, double y, com.vaadin.flow.component.Unit unit) Convenience method to set both x and y attributes at the same timevoidSets the stroke for this element.voidsetStroke(String color, int width, Path.LINE_CAP lineCap, Path.LINE_JOIN lineJoin) Sets the stroke for this element.protected voidsize(double width, double height) Sets the size of a SvgElement.protected static tools.jackson.databind.JsonNodeval(double value) Convenience method for converting a double to a JsonNumber.protected static tools.jackson.databind.JsonNodeConvenience method for converting a Java Boolean to a JsonNode.protected static tools.jackson.databind.JsonNodeConvenience method for converting a Java String to a JsonNode
-
Constructor Details
-
SvgElement
Creates a new SvgElement with the given id- Parameters:
id- the id for this element, never null
-
-
Method Details
-
move
public void move(double x, double y) Moves the given element within the viewbox with the relative values provided. I.e. the values given represent a move frm the current position, not absolute values.- Parameters:
x- the amount this element should move in the x-axisy- the amount this element should move in the y-axis
-
flip
Flips the component in relation to the axis given. I.e.flip("x")will flip the component relative to the x-axis whileflip("y")will flip the component relative to the y-axis.- Parameters:
axis- the axis that the component flip should be measured against
-
rotate
public void rotate(double angle) Rotates the component with the amount given in the angle. For instancerotate(90)will rotate the component 90 degrees.- Parameters:
angle- the angle amount to rotate
-
cloneAttributesToJson
public tools.jackson.databind.node.ObjectNode cloneAttributesToJson()Returns a cloned set of the current attributes (including updates) of thisSvgElement. Changes in this array do not reflect back to thisSvgElementanymore.Primarily use defined public API for setting and getting attributes
- Returns:
- the cloned set of attributes, (including updates) for this
SvgElement
-
getId
Returns the id of thisSvgElement- Returns:
- the id of this element, should never be null
-
setId
Sets the id of this element, should never be null.- Parameters:
id- the id of this element
-
setDraggable
public void setDraggable(boolean draggable) Sets the draggable flag for this element.- Parameters:
draggable- true if this element should be draggable, false otherwise
-
isDraggable
public boolean isDraggable()Returns the current draggable flag for this element as last given.- Returns:
- true if the element should be draggable, false otherwise
-
setFillColor
Sets the fill color of this element.- Parameters:
color- the color to use for filling the element
-
getFillColor
Returns the current fill color of this element- Returns:
- the current fill color
-
setStroke
Sets the stroke for this element.- Parameters:
color- the color used for the stroke, never nullwidth- the width of this stroke- See Also:
-
setStroke
Sets the stroke for this element.- Parameters:
color- the color used for the stroke, never nullwidth- the width of this strokelineCap- the optionalPath.LINE_CAPfor this elementlineJoin- the optionalPath.LINE_JOINfor this element
-
setPosition
public void setPosition(double x, double y, com.vaadin.flow.component.Unit unit) Convenience method to set both x and y attributes at the same time- Parameters:
x- x positiony- y positionunit- numbers unit
-
addClassName
Add a class name for this element- Parameters:
className- ccs class name
-
removeClassName
Remove a class name for this element- Parameters:
className- ccs class name
-
getUpdates
protected tools.jackson.databind.node.ArrayNode getUpdates()Returns the pending updates for this element- Returns:
- the array with pending updates
-
clearUpdates
public void clearUpdates()Primarily intended for internal use for clearing and setting the updates array (for complex updates) after each push to the client by the Svg class. -
getAttributes
protected tools.jackson.databind.node.ObjectNode getAttributes()Returns the attributes object that should contain the complete state of thisSvgElement- Returns:
- the actual attributes map for this
SvgElement - See Also:
-
getUnsafeAttributesMap
Deprecated.This is primarily intended as a fallback while the API is developed. This method will return the actual internal map containing the state of this SvgElement without any protections. Avoid using this and instead use or create proper public API for setting the attributes as this method is likely to be removed in the future.- Returns:
- the actual attributes map for this
SvgElement - See Also:
-
setAttributes
protected void setAttributes(tools.jackson.databind.node.ObjectNode attributes) Sets the internal attributes array.- Parameters:
attributes- the array to set
-
setConstructor
Sets the constructor value for the client side as well as the initial arguments list. This is specific for the client-side svg.js implementation where the client-side element will be instantiated with a specific consturctor and arguments list.- Parameters:
type- the constructor to call, known suitable values available in theSvgTypeenumeration.args- the initial constructor arguments to pass
-
createArgArray
protected static tools.jackson.databind.node.ArrayNode createArgArray(tools.jackson.databind.JsonNode... args) Creates a Json array based on the provided Json values- Parameters:
args- the values to put into the array, never null- Returns:
- the array with the given values
-
pushUpdate
Creates a more complex update call where a specific client-side method needs to be called with arguments in order to perform a client-side update.- Parameters:
name- the name of the client-side method to callargs- the arguments to pass to the client-side method- See Also:
-
val
protected static tools.jackson.databind.JsonNode val(double value) Convenience method for converting a double to a JsonNumber.- Parameters:
value- the value to convert- Returns:
- the converted JsonNumber
-
val
Convenience method for converting a Java String to a JsonNode- Parameters:
value- the string to convert- Returns:
- the converted JsonNode
-
val
Convenience method for converting a Java Boolean to a JsonNode.- Parameters:
value- the boolean to convert- Returns:
- the converted JsonNode
-
size
protected void size(double width, double height) Sets the size of a SvgElement. Not all Svg components handle size in the same way, hence this API is protected until the actual component exposes it publicly if it's applicable.- Parameters:
width- the width of the svg elementheight- the height of the svg element
-
setAttribute
Convenience method for setting a string attribute.- Parameters:
key- the key to setvalue- the Java String value to set
-
setAttribute
Convenience method for setting a Java Boolean.- Parameters:
key- the key to setvalue- the boolean value to set
-
setAttribute
Convenience method for setting a Java number attribute. Note that the number will be converted to a double before conversion.- Parameters:
key- the key to setvalue- the value to convert
-
setAttribute
Maps a Json value to a key in the internal attributes array.- Parameters:
key- the key to setvalue- the value to set
-
getAttribute
Returns a value from the internal attributes map- Parameters:
key- the key to fetch- Returns:
- the value or null if not present
-
getStringAttribute
Convenience method for getting a String attribute from the internal array.- Parameters:
key- the key to fetch- Returns:
- the String value or null if not set.
-
getBooleanAttribute
Convenience method for getting a Boolean attribute.- Parameters:
key- the key to fetch- Returns:
- the value or null if none set.
-
getNumberAttribute
Convenience method for fetching a number attribute from the internal array.- Parameters:
key- the key to fetch- Returns:
- the value or null if none set
-