Class UseElement

java.lang.Object
com.vaadin.flow.dom.Node<com.vaadin.flow.dom.Element>
com.vaadin.flow.dom.Element
All Implemented Interfaces:
Serializable

public class UseElement extends SvgGraphicsElement
A typed Java API for the SVG <use> element.

The <use> element takes nodes from within the SVG document and duplicates them somewhere else. The effect is the same as if the nodes were deeply cloned and then pasted where the <use> element is.

The <use> element has optional attributes x, y, width and height which define the position and size of the referenced element.

Write-Only vs Read-Write Methods

This class provides two variants for each attribute setter:

  • Default methods (e.g., x(), y()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved via getAttribute().
  • RW methods (e.g., xRW(), yRW()) - Use traditional setAttribute() which stores values on the server for later retrieval.
See Also:
  • Constructor Details

    • UseElement

      public UseElement()
    • UseElement

      public UseElement(SvgElement element)
      Creates a use element referencing the given element. An ID is automatically generated for the referenced element if not already set.
      Parameters:
      element - the element to reference (typically a SymbolElement)
  • Method Details

    • ref

      public UseElement ref(SvgElement element)
      Sets the reference to the given element. An ID is automatically generated for the referenced element if not already set.

      Note: This method uses read-write approach to ensure ID is properly set.

      Parameters:
      element - the element to reference
      Returns:
      this element for method chaining
    • href

      public UseElement href(String href)
      Sets the href attribute to reference another element by ID.

      Uses write-only optimization. Use hrefRW(String) if you need to read the value back.

      Parameters:
      href - the reference URL (e.g., "#myElement" or "sprites.svg#icon")
      Returns:
      this element for method chaining
    • hrefRW

      public UseElement hrefRW(String href)
      Sets the href attribute to reference another element by ID (read-write).
      Parameters:
      href - the reference URL (e.g., "#myElement" or "sprites.svg#icon")
      Returns:
      this element for method chaining
    • x

      public UseElement x(double x)
      Sets the x coordinate where the referenced element will be placed.

      Uses write-only optimization. Use xRW(double) if you need to read the value back.

      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • x

      public UseElement x(String x)
      Sets the x coordinate with a unit.

      Uses write-only optimization. Use xRW(String) if you need to read the value back.

      Parameters:
      x - the x coordinate with unit (e.g., "10%", "50px")
      Returns:
      this element for method chaining
    • xRW

      public UseElement xRW(double x)
      Sets the x coordinate where the referenced element will be placed (read-write).
      Parameters:
      x - the x coordinate
      Returns:
      this element for method chaining
    • xRW

      public UseElement xRW(String x)
      Sets the x coordinate with a unit (read-write).
      Parameters:
      x - the x coordinate with unit (e.g., "10%", "50px")
      Returns:
      this element for method chaining
    • y

      public UseElement y(double y)
      Sets the y coordinate where the referenced element will be placed.

      Uses write-only optimization. Use yRW(double) if you need to read the value back.

      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • y

      public UseElement y(String y)
      Sets the y coordinate with a unit.

      Uses write-only optimization. Use yRW(String) if you need to read the value back.

      Parameters:
      y - the y coordinate with unit (e.g., "10%", "50px")
      Returns:
      this element for method chaining
    • yRW

      public UseElement yRW(double y)
      Sets the y coordinate where the referenced element will be placed (read-write).
      Parameters:
      y - the y coordinate
      Returns:
      this element for method chaining
    • yRW

      public UseElement yRW(String y)
      Sets the y coordinate with a unit (read-write).
      Parameters:
      y - the y coordinate with unit (e.g., "10%", "50px")
      Returns:
      this element for method chaining
    • width

      public UseElement width(double width)
      Sets the width of the use element.

      Uses write-only optimization. Use widthRW(double) if you need to read the value back.

      Overrides:
      width in class SvgElement
      Parameters:
      width - the width
      Returns:
      this element for method chaining
    • width

      public UseElement width(String width)
      Sets the width with a unit.

      Uses write-only optimization. Use widthRW(String) if you need to read the value back.

      Overrides:
      width in class SvgElement
      Parameters:
      width - the width with unit (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • widthRW

      public UseElement widthRW(double width)
      Sets the width of the use element (read-write).
      Parameters:
      width - the width
      Returns:
      this element for method chaining
    • widthRW

      public UseElement widthRW(String width)
      Sets the width with a unit (read-write).
      Parameters:
      width - the width with unit (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • height

      public UseElement height(double height)
      Sets the height of the use element.

      Uses write-only optimization. Use heightRW(double) if you need to read the value back.

      Overrides:
      height in class SvgElement
      Parameters:
      height - the height
      Returns:
      this element for method chaining
    • height

      public UseElement height(String height)
      Sets the height with a unit.

      Uses write-only optimization. Use heightRW(String) if you need to read the value back.

      Overrides:
      height in class SvgElement
      Parameters:
      height - the height with unit (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • heightRW

      public UseElement heightRW(double height)
      Sets the height of the use element (read-write).
      Parameters:
      height - the height
      Returns:
      this element for method chaining
    • heightRW

      public UseElement heightRW(String height)
      Sets the height with a unit (read-write).
      Parameters:
      height - the height with unit (e.g., "100%", "200px")
      Returns:
      this element for method chaining
    • position

      public UseElement position(double x, double y)
      Sets the position of the use element.

      Uses write-only optimization. Use positionRW(double, double) if you need to read the values back.

      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • positionRW

      public UseElement positionRW(double x, double y)
      Sets the position of the use element (read-write).
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • size

      public UseElement size(double width, double height)
      Sets the size of the use element.

      Uses write-only optimization. Use sizeRW(double, double) if you need to read the values back.

      Overrides:
      size in class SvgElement
      Parameters:
      width - the width
      height - the height
      Returns:
      this element for method chaining
    • sizeRW

      public UseElement sizeRW(double width, double height)
      Sets the size of the use element (read-write).
      Parameters:
      width - the width
      height - the height
      Returns:
      this element for method chaining