Class SvgElement

java.lang.Object
com.vaadin.flow.component.svg.elements.SvgElement
Direct Known Subclasses:
AbstractPolyElement, Circle, Ellipse, Group, Image, Path, Rect, Text, TextPath

public abstract class SvgElement extends Object
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
    Constructor
    Description
    Creates a new SvgElement with the given id
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addClassName(String className)
    Add a class name for this element
    void
    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.
    tools.jackson.databind.node.ObjectNode
    Returns a cloned set of the current attributes (including updates) of this SvgElement.
    protected static tools.jackson.databind.node.ArrayNode
    createArgArray(tools.jackson.databind.JsonNode... args)
    Creates a Json array based on the provided Json values
    void
    flip(String axis)
    Flips the component in relation to the axis given.
    Returns a value from the internal attributes map
    protected tools.jackson.databind.node.ObjectNode
    Returns the attributes object that should contain the complete state of this SvgElement
    protected Boolean
    Convenience method for getting a Boolean attribute.
    Returns the current fill color of this element
    Returns the id of this SvgElement
    protected Number
    Convenience method for fetching a number attribute from the internal array.
    protected String
    Convenience method for getting a String attribute from the internal array.
    tools.jackson.databind.node.ObjectNode
    Deprecated.
    protected tools.jackson.databind.node.ArrayNode
    Returns the pending updates for this element
    boolean
    Returns the current draggable flag for this element as last given.
    void
    move(double x, double y)
    Moves the given element within the viewbox with the relative values provided.
    protected void
    pushUpdate(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.
    void
    Remove a class name for this element
    void
    rotate(double angle)
    Rotates the component with the amount given in the angle.
    protected void
    setAttribute(String key, boolean value)
    Convenience method for setting a Java Boolean.
    protected void
    setAttribute(String key, Number value)
    Convenience method for setting a Java number attribute.
    void
    setAttribute(String key, String value)
    Convenience method for setting a string attribute.
    protected void
    setAttribute(String key, tools.jackson.databind.JsonNode value)
    Maps a Json value to a key in the internal attributes array.
    protected void
    setAttributes(tools.jackson.databind.node.ObjectNode attributes)
    Sets the internal attributes array.
    protected void
    setConstructor(SvgType type, tools.jackson.databind.JsonNode... args)
    Sets the constructor value for the client side as well as the initial arguments list.
    void
    setDraggable(boolean draggable)
    Sets the draggable flag for this element.
    void
    Sets the fill color of this element.
    protected void
    Sets the id of this element, should never be null.
    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
    void
    setStroke(String color, int width)
    Sets the stroke for this element.
    void
    setStroke(String color, int width, Path.LINE_CAP lineCap, Path.LINE_JOIN lineJoin)
    Sets the stroke for this element.
    protected void
    size(double width, double height)
    Sets the size of a SvgElement.
    protected static tools.jackson.databind.JsonNode
    val(double value)
    Convenience method for converting a double to a JsonNumber.
    protected static tools.jackson.databind.JsonNode
    val(Boolean value)
    Convenience method for converting a Java Boolean to a JsonNode.
    protected static tools.jackson.databind.JsonNode
    val(String value)
    Convenience method for converting a Java String to a JsonNode

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SvgElement

      public SvgElement(String id)
      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-axis
      y - the amount this element should move in the y-axis
    • flip

      public void flip(String axis)
      Flips the component in relation to the axis given. I.e. flip("x") will flip the component relative to the x-axis while flip("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 instance rotate(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 this SvgElement. Changes in this array do not reflect back to this SvgElement anymore.

      Primarily use defined public API for setting and getting attributes

      Returns:
      the cloned set of attributes, (including updates) for this SvgElement
    • getId

      public String getId()
      Returns the id of this SvgElement
      Returns:
      the id of this element, should never be null
    • setId

      protected void setId(String id)
      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

      public void setFillColor(String color)
      Sets the fill color of this element.
      Parameters:
      color - the color to use for filling the element
    • getFillColor

      public String getFillColor()
      Returns the current fill color of this element
      Returns:
      the current fill color
    • setStroke

      public void setStroke(String color, int width)
      Sets the stroke for this element.
      Parameters:
      color - the color used for the stroke, never null
      width - the width of this stroke
      See Also:
    • setStroke

      public void setStroke(String color, int width, Path.LINE_CAP lineCap, Path.LINE_JOIN lineJoin)
      Sets the stroke for this element.
      Parameters:
      color - the color used for the stroke, never null
      width - the width of this stroke
      lineCap - the optional Path.LINE_CAP for this element
      lineJoin - the optional Path.LINE_JOIN for 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 position
      y - y position
      unit - numbers unit
    • addClassName

      public void addClassName(String className)
      Add a class name for this element
      Parameters:
      className - ccs class name
    • removeClassName

      public void removeClassName(String className)
      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 this SvgElement
      Returns:
      the actual attributes map for this SvgElement
      See Also:
    • getUnsafeAttributesMap

      @Deprecated public tools.jackson.databind.node.ObjectNode 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

      protected void setConstructor(SvgType type, tools.jackson.databind.JsonNode... args)
      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 the SvgType enumeration.
      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

      protected void pushUpdate(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.
      Parameters:
      name - the name of the client-side method to call
      args - 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

      protected static tools.jackson.databind.JsonNode val(String value)
      Convenience method for converting a Java String to a JsonNode
      Parameters:
      value - the string to convert
      Returns:
      the converted JsonNode
    • val

      protected static tools.jackson.databind.JsonNode val(Boolean value)
      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 element
      height - the height of the svg element
    • setAttribute

      public void setAttribute(String key, String value)
      Convenience method for setting a string attribute.
      Parameters:
      key - the key to set
      value - the Java String value to set
    • setAttribute

      protected void setAttribute(String key, boolean value)
      Convenience method for setting a Java Boolean.
      Parameters:
      key - the key to set
      value - the boolean value to set
    • setAttribute

      protected void setAttribute(String key, Number value)
      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 set
      value - the value to convert
    • setAttribute

      protected void setAttribute(String key, tools.jackson.databind.JsonNode value)
      Maps a Json value to a key in the internal attributes array.
      Parameters:
      key - the key to set
      value - the value to set
    • getAttribute

      public Object getAttribute(String key)
      Returns a value from the internal attributes map
      Parameters:
      key - the key to fetch
      Returns:
      the value or null if not present
    • getStringAttribute

      protected String getStringAttribute(String key)
      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

      protected Boolean getBooleanAttribute(String key)
      Convenience method for getting a Boolean attribute.
      Parameters:
      key - the key to fetch
      Returns:
      the value or null if none set.
    • getNumberAttribute

      protected Number getNumberAttribute(String key)
      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