Class ColorMutable

java.lang.Object
info.monitorenter.gui.util.ColorMutable

public class ColorMutable extends Object
Mutable Color implementation.

The color is wrapped by the logic to fake mutability. As long as the color is not set setting of values will not have an effect but only be stored until color is set and then applied to it.

Author:
Achim Westermann
  • Constructor Details

    • ColorMutable

      public ColorMutable()
  • Method Details

    • applyColorIfChange

      public Color applyColorIfChange(Graphics g)
      Sets the color to the graphics context if it is different and returns the previous one of the graphics context or null if there was no change.

      Parameters:
      g - the graphics context to use.
      Returns:
      the previously configured color of the graphics context or null if nothing was done.
    • applyColorUnconditionally

      public Color applyColorUnconditionally(Graphics g)
      Sets the color to the graphics context.

      Parameters:
      g - the graphics context to use.
      Returns:
      the previously configured color of the graphics context or null if nothing was done.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      See Also:
    • getAlpha

      public int getAlpha()
      Returns the alpha value of the wrapped color.

      Returns:
      the alpha value of the wrapped color.
    • getBlue

      public int getBlue()
      Returns the blue value of the wrapped color.

      Returns:
      the blue value of the wrapped color.
    • getColor

      public Color getColor()
      Returns the wrapped color.

      This will be null if no color has been set before even if other values have been set before.

      Returns:
      the wrapped color.
    • getGreen

      public int getGreen()
      Returns the green value of the wrapped color.

      Returns:
      the green value of the wrapped color.
    • getRed

      public int getRed()
      Returns the red value of the wrapped color.

      Returns:
      the red value of the wrapped color.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      See Also:
    • setAlpha

      public int setAlpha(int alpha)
      Sets the transparency to use for painting.

      This value will be fold into color. If color has not been configured before it will not have any effect (until a color is set).

      Caution: using a value greater 0 may cost a multiple cpu load!

      Parameters:
      alpha - a transparency value between 0 and 255.
      Returns:
      the previous transparency used.
    • setBlue

      public int setBlue(int blue)
      Sets the blue to use for painting.

      This value will be fold into color. If color has not been configured before it will not have any effect (until a color is set).

      Parameters:
      blue - a blue value between 0 and 255.
      Returns:
      the previous blue used.
    • setColor

      public Color setColor(Color color)
      Sets the color to use.

      If any other setters have been invoked before (e.g. setAlpha(int)) and the internal color was null those values will be implanted to the new color before overtaking it.

      Parameters:
      color - the new color to use as base for modifications.
      Returns:
      the previous color or null if none was set.
    • setGreen

      public int setGreen(int green)
      Sets the green to use for painting.

      This value will be fold into color. If color has not been configured before it will not have any effect (until a color is set).

      Parameters:
      green - a green value between 0 and 255.
      Returns:
      the previous green used.
    • setRed

      public int setRed(int red)
      Sets the red to use for painting.

      This value will be fold into color. If color has not been configured before it will not have any effect (until a color is set).

      Parameters:
      red - a red value between 0 and 255.
      Returns:
      the previous red used.