Class PolygonElement

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

public class PolygonElement extends SvgGraphicsElement
A typed Java API for the SVG <polygon> element.

The <polygon> element defines a closed shape consisting of a set of connected straight line segments. The last point is connected to the first point.

For an open shape (where the last point is not connected to the first), use a polyline element instead.

Write-Only vs Read-Write Methods

This class provides two variants for attribute setters:

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

    • PolygonElement

      public PolygonElement()
  • Method Details

    • points

      public PolygonElement points(String points)
      Sets the points directly as a string.

      This replaces any points added using the fluent methods.

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

      Parameters:
      points - the points string (e.g., "0,100 50,25 50,75 100,0")
      Returns:
      this element for method chaining
    • pointsRW

      public PolygonElement pointsRW(String points)
      Sets the points directly as a string (read-write).

      This replaces any points added using the fluent methods.

      Parameters:
      points - the points string (e.g., "0,100 50,25 50,75 100,0")
      Returns:
      this element for method chaining
    • points

      public PolygonElement points(double... coords)
      Sets the points from an array of coordinate pairs.

      Each pair of values represents an x,y coordinate.

      Parameters:
      coords - the coordinates as x1,y1,x2,y2,... sequence
      Returns:
      this element for method chaining
    • addPoint

      public PolygonElement addPoint(double x, double y)
      Adds a point to the polygon.
      Parameters:
      x - the x coordinate
      y - the y coordinate
      Returns:
      this element for method chaining
    • addPoints

      public PolygonElement addPoints(double... coords)
      Adds multiple points to the polygon.
      Parameters:
      coords - the coordinates as x1,y1,x2,y2,... sequence
      Returns:
      this element for method chaining
    • clearPoints

      public PolygonElement clearPoints()
      Clears all points from the polygon.
      Returns:
      this element for method chaining
    • pathLength

      public PolygonElement pathLength(double pathLength)
      Sets the total length for the polygon's perimeter in user units.

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

      Parameters:
      pathLength - the total path length
      Returns:
      this element for method chaining
    • pathLengthRW

      public PolygonElement pathLengthRW(double pathLength)
      Sets the total length for the polygon's perimeter in user units (read-write).
      Parameters:
      pathLength - the total path length
      Returns:
      this element for method chaining
    • regularPolygon

      public PolygonElement regularPolygon(double cx, double cy, double radius, int sides)
      Creates a regular polygon with the specified number of sides.
      Parameters:
      cx - the x coordinate of the center
      cy - the y coordinate of the center
      radius - the radius (distance from center to vertices)
      sides - the number of sides (minimum 3)
      Returns:
      this element for method chaining
    • triangle

      public PolygonElement triangle(double x1, double y1, double x2, double y2, double x3, double y3)
      Creates a triangle with the specified vertices.
      Parameters:
      x1 - x coordinate of first vertex
      y1 - y coordinate of first vertex
      x2 - x coordinate of second vertex
      y2 - y coordinate of second vertex
      x3 - x coordinate of third vertex
      y3 - y coordinate of third vertex
      Returns:
      this element for method chaining
    • star

      public PolygonElement star(double cx, double cy, double outerRadius, double innerRadius, int points)
      Creates a star shape.
      Parameters:
      cx - the x coordinate of the center
      cy - the y coordinate of the center
      outerRadius - the outer radius (to the points)
      innerRadius - the inner radius (to the inner corners)
      points - the number of points on the star (minimum 3)
      Returns:
      this element for method chaining