Package smile.swing

Record Class AlphaIcon

java.lang.Object
java.lang.Record
smile.swing.AlphaIcon
Record Components:
icon - the Icon to wrap
alpha - the opacity should be in the range 0.0F (fully transparent) to 1.0F (fully opaque).
All Implemented Interfaces:
Icon

public record AlphaIcon(Icon icon, float alpha) extends Record implements Icon
An Icon wrapper that paints the contained icon with a specified transparency.

Note: This class is not suitable for wrapping an ImageIcon that holds an animated image.

  • Constructor Summary

    Constructors
    Constructor
    Description
    AlphaIcon(Icon icon, float alpha)
    Creates an instance of a AlphaIcon record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    Returns the value of the alpha record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    int
    Gets the height of the bounding rectangle of this AlphaIcon.
    int
    Gets the width of the bounding rectangle of this AlphaIcon.
    final int
    Returns a hash code value for this object.
    Returns the value of the icon record component.
    void
    paintIcon(Component c, Graphics g, int x, int y)
    Paints the wrapped icon with this AlphaIcon's transparency.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • AlphaIcon

      public AlphaIcon(Icon icon, float alpha)
      Creates an instance of a AlphaIcon record class.
      Parameters:
      icon - the value for the icon record component
      alpha - the value for the alpha record component
  • Method Details

    • paintIcon

      public void paintIcon(Component c, Graphics g, int x, int y)
      Paints the wrapped icon with this AlphaIcon's transparency.
      Specified by:
      paintIcon in interface Icon
      Parameters:
      c - The component to which the icon is painted
      g - the graphics context
      x - the X coordinate of the icon's top-left corner
      y - the Y coordinate of the icon's top-left corner
    • getIconWidth

      public int getIconWidth()
      Gets the width of the bounding rectangle of this AlphaIcon. Returns the width of the wrapped icon.
      Specified by:
      getIconWidth in interface Icon
      Returns:
      the width in pixels
    • getIconHeight

      public int getIconHeight()
      Gets the height of the bounding rectangle of this AlphaIcon. * Returns the height of the wrapped icon.
      Specified by:
      getIconHeight in interface Icon
      Returns:
      the height in pixels
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • icon

      public Icon icon()
      Returns the value of the icon record component.
      Returns:
      the value of the icon record component
    • alpha

      public float alpha()
      Returns the value of the alpha record component.
      Returns:
      the value of the alpha record component