Class ColorMutable


  • public class ColorMutable
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      ColorMutable()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.awt.Color applyColorIfChange​(java.awt.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.
      java.awt.Color applyColorUnconditionally​(java.awt.Graphics g)
      Sets the color to the graphics context.
      boolean equals​(java.lang.Object obj)  
      int getAlpha()
      Returns the alpha value of the wrapped color.
      int getBlue()
      Returns the blue value of the wrapped color.
      java.awt.Color getColor()
      Returns the wrapped color.
      int getGreen()
      Returns the green value of the wrapped color.
      int getRed()
      Returns the red value of the wrapped color.
      int hashCode()  
      int setAlpha​(int alpha)
      Sets the transparency to use for painting.
      int setBlue​(int blue)
      Sets the blue to use for painting.
      java.awt.Color setColor​(java.awt.Color color)
      Sets the color to use.
      int setGreen​(int green)
      Sets the green to use for painting.
      int setRed​(int red)
      Sets the red to use for painting.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ColorMutable

        public ColorMutable()
    • Method Detail

      • applyColorIfChange

        public java.awt.Color applyColorIfChange​(java.awt.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 java.awt.Color applyColorUnconditionally​(java.awt.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​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
        See Also:
        Object.equals(java.lang.Object)
      • 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 java.awt.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 java.lang.Object
        See Also:
        Object.hashCode()
      • 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 java.awt.Color setColor​(java.awt.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.