Class LinearGradientElement

java.lang.Object
com.vaadin.flow.dom.Node<com.vaadin.flow.dom.Element>
com.vaadin.flow.dom.Element
org.vaadin.firitin.element.svg.SvgElement
org.vaadin.firitin.element.svg.LinearGradientElement
All Implemented Interfaces:
Serializable

public class LinearGradientElement extends SvgElement
A typed Java API for the SVG <linearGradient> element.

The <linearGradient> element defines a linear gradient to be used as a fill or stroke for other SVG elements. The gradient is defined along a line specified by x1, y1, x2, y2 coordinates.

Linear gradients must be placed inside a <defs> element and referenced by ID (e.g., fill="url(#myGradient)").

Write-Only vs Read-Write Methods

This class provides two variants for each attribute setter:

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

    • LinearGradientElement

      public LinearGradientElement()
    • LinearGradientElement

      public LinearGradientElement(String id)
      Creates a linear gradient with the given ID.
      Parameters:
      id - the ID for referencing this gradient
  • Method Details

    • x1

      public LinearGradientElement x1(double x1)
      Sets the x coordinate of the gradient start point.

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

      Parameters:
      x1 - the x coordinate (default is 0)
      Returns:
      this element for method chaining
    • x1

      public LinearGradientElement x1(String x1)
      Sets the x coordinate of the gradient start point with a unit.

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

      Parameters:
      x1 - the x coordinate (e.g., "0%", "50%")
      Returns:
      this element for method chaining
    • x1RW

      public LinearGradientElement x1RW(double x1)
      Sets the x coordinate of the gradient start point (read-write).
      Parameters:
      x1 - the x coordinate (default is 0)
      Returns:
      this element for method chaining
    • x1RW

      public LinearGradientElement x1RW(String x1)
      Sets the x coordinate of the gradient start point with a unit (read-write).
      Parameters:
      x1 - the x coordinate (e.g., "0%", "50%")
      Returns:
      this element for method chaining
    • y1

      public LinearGradientElement y1(double y1)
      Sets the y coordinate of the gradient start point.

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

      Parameters:
      y1 - the y coordinate (default is 0)
      Returns:
      this element for method chaining
    • y1

      public LinearGradientElement y1(String y1)
      Sets the y coordinate of the gradient start point with a unit.

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

      Parameters:
      y1 - the y coordinate (e.g., "0%", "50%")
      Returns:
      this element for method chaining
    • y1RW

      public LinearGradientElement y1RW(double y1)
      Sets the y coordinate of the gradient start point (read-write).
      Parameters:
      y1 - the y coordinate (default is 0)
      Returns:
      this element for method chaining
    • y1RW

      public LinearGradientElement y1RW(String y1)
      Sets the y coordinate of the gradient start point with a unit (read-write).
      Parameters:
      y1 - the y coordinate (e.g., "0%", "50%")
      Returns:
      this element for method chaining
    • x2

      public LinearGradientElement x2(double x2)
      Sets the x coordinate of the gradient end point.

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

      Parameters:
      x2 - the x coordinate (default is 1 or 100%)
      Returns:
      this element for method chaining
    • x2

      public LinearGradientElement x2(String x2)
      Sets the x coordinate of the gradient end point with a unit.

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

      Parameters:
      x2 - the x coordinate (e.g., "100%", "50%")
      Returns:
      this element for method chaining
    • x2RW

      public LinearGradientElement x2RW(double x2)
      Sets the x coordinate of the gradient end point (read-write).
      Parameters:
      x2 - the x coordinate (default is 1 or 100%)
      Returns:
      this element for method chaining
    • x2RW

      public LinearGradientElement x2RW(String x2)
      Sets the x coordinate of the gradient end point with a unit (read-write).
      Parameters:
      x2 - the x coordinate (e.g., "100%", "50%")
      Returns:
      this element for method chaining
    • y2

      public LinearGradientElement y2(double y2)
      Sets the y coordinate of the gradient end point.

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

      Parameters:
      y2 - the y coordinate (default is 0)
      Returns:
      this element for method chaining
    • y2

      public LinearGradientElement y2(String y2)
      Sets the y coordinate of the gradient end point with a unit.

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

      Parameters:
      y2 - the y coordinate (e.g., "100%", "50%")
      Returns:
      this element for method chaining
    • y2RW

      public LinearGradientElement y2RW(double y2)
      Sets the y coordinate of the gradient end point (read-write).
      Parameters:
      y2 - the y coordinate (default is 0)
      Returns:
      this element for method chaining
    • y2RW

      public LinearGradientElement y2RW(String y2)
      Sets the y coordinate of the gradient end point with a unit (read-write).
      Parameters:
      y2 - the y coordinate (e.g., "100%", "50%")
      Returns:
      this element for method chaining
    • vector

      public LinearGradientElement vector(double x1, double y1, double x2, double y2)
      Sets the gradient vector from start to end point.

      Default is horizontal (0,0 to 1,0).

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

      Parameters:
      x1 - start x coordinate
      y1 - start y coordinate
      x2 - end x coordinate
      y2 - end y coordinate
      Returns:
      this element for method chaining
    • vectorRW

      public LinearGradientElement vectorRW(double x1, double y1, double x2, double y2)
      Sets the gradient vector from start to end point (read-write).
      Parameters:
      x1 - start x coordinate
      y1 - start y coordinate
      x2 - end x coordinate
      y2 - end y coordinate
      Returns:
      this element for method chaining
    • horizontal

      public LinearGradientElement horizontal()
      Creates a horizontal gradient (left to right).

      Uses write-only optimization.

      Returns:
      this element for method chaining
    • vertical

      public LinearGradientElement vertical()
      Creates a vertical gradient (top to bottom).

      Uses write-only optimization.

      Returns:
      this element for method chaining
    • diagonal

      public LinearGradientElement diagonal()
      Creates a diagonal gradient (top-left to bottom-right).

      Uses write-only optimization.

      Returns:
      this element for method chaining
    • gradientUnits

      Sets the coordinate system for the gradient vector.

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

      Parameters:
      units - the gradient units
      Returns:
      this element for method chaining
    • gradientUnitsRW

      Sets the coordinate system for the gradient vector (read-write).
      Parameters:
      units - the gradient units
      Returns:
      this element for method chaining
    • spreadMethod

      Sets how the gradient behaves outside its bounds.

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

      Parameters:
      method - the spread method
      Returns:
      this element for method chaining
    • spreadMethodRW

      Sets how the gradient behaves outside its bounds (read-write).
      Parameters:
      method - the spread method
      Returns:
      this element for method chaining
    • gradientTransform

      public LinearGradientElement gradientTransform(String transform)
      Sets a transform on the gradient.

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

      Parameters:
      transform - the transform string
      Returns:
      this element for method chaining
    • gradientTransformRW

      public LinearGradientElement gradientTransformRW(String transform)
      Sets a transform on the gradient (read-write).
      Parameters:
      transform - the transform string
      Returns:
      this element for method chaining
    • href

      public LinearGradientElement href(String href)
      References another gradient to inherit stops and attributes from.

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

      Parameters:
      href - the reference (e.g., "#otherGradient")
      Returns:
      this element for method chaining
    • hrefRW

      public LinearGradientElement hrefRW(String href)
      References another gradient to inherit stops and attributes from (read-write).
      Parameters:
      href - the reference (e.g., "#otherGradient")
      Returns:
      this element for method chaining
    • addStops

      public LinearGradientElement addStops(StopElement... stops)
      Adds stop elements to this gradient.
      Parameters:
      stops - the stop elements
      Returns:
      this element for method chaining
    • addStop

      public LinearGradientElement addStop(double offset, in.virit.color.Color color)
      Adds a stop at the specified offset with the given color.
      Parameters:
      offset - the offset (0.0 to 1.0)
      color - the color
      Returns:
      this element for method chaining
    • addStop

      public LinearGradientElement addStop(double offset, String color)
      Adds a stop at the specified offset with the given color.
      Parameters:
      offset - the offset (0.0 to 1.0)
      color - the color string
      Returns:
      this element for method chaining