Class Size

java.lang.Object
swingtree.layout.Size

@Immutable public final class Size extends Object
An immutable value object that represents a size in the form of a width and height or lack thereof. This is used to represent the size of icons as part of IconDeclarations and the SwingTree style API, see UIForAnySwing.withStyle(Styler), ComponentStyleDelegate.image(swingtree.api.Configurator) and ImageConf.size(int, int).
  • Method Details

    • unknown

      public static Size unknown()
      Exposes the UNKNOWN size instance, which is a null object that represents an unknown size. It uses -1 for both width and height and will return Optional.empty() for both width and height.
      Returns:
      A Size instance that represents an unknown size.
    • of

      public static Size of(float width, float height)
      A factory method that creates a Size instance from a width and height. If the width or height is negative, the returned size will have be the UNKNOWN size with a width or height of -1.
      Parameters:
      width - The width of the size.
      height - The height of the size.
      Returns:
      A Size instance that represents the given width and height.
    • of

      public static Size of(@Nullable Dimension dimension)
      A factory method that creates a Size instance from a Dimension.
      Parameters:
      dimension - The dimension to convert to a Size instance.
      Returns:
      A Size instance that represents the given dimension.
    • width

      public Optional<Float> width()
      The width of this Size instance may not be specified, in which case this method returns Optional.empty() and the thing that this configuration is applied to should resort to its default width.
      Returns:
      The width of this Size instance or Optional.empty() if unknown.
    • height

      public Optional<Float> height()
      The height of this Size instance may not be specified, in which case this method returns Optional.empty() and the thing that this configuration is applied to should resort to its default height.
      Returns:
      The height of this Size instance or Optional.empty() if unknown.
    • hasPositiveWidth

      public boolean hasPositiveWidth()
    • hasPositiveHeight

      public boolean hasPositiveHeight()
    • withWidth

      public Size withWidth(int width)
      Creates an updated Size instance with the given width. If the width is negative, the width of the returned size will be -1.
      Parameters:
      width - The width of the size to create.
      Returns:
      A new Size instance with the given width.
    • withHeight

      public Size withHeight(int height)
      Creates an updated Size instance with the given height. If the height is negative, the height of the returned size will be -1.
      Parameters:
      height - The height of the size to create.
      Returns:
      A new Size instance with the given height.
    • toDimension

      public Dimension toDimension()
    • scale

      public Size scale(double scaleFactor)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object