Package generic.theme

Class GColor

java.lang.Object
java.awt.Color
generic.theme.GColor
All Implemented Interfaces:
Paint, Transparency, Serializable
Direct Known Subclasses:
GColorUIResource

public class GColor extends Color
A Color whose value is dynamically determined by looking up its id into a global color table that is determined by the active GTheme.

The idea is for developers to not use specific colors in their code, but to instead use a GColor with an id that hints at its use. For example, instead of hard coding a component's background color to white by coding "component.setBackground(Color.white)", you would do something like "component.setBackground(new GColor("color.mywidget.bg"). Then in a "[module name].theme.properties" file (located in the module's data directory), you would set the default value by adding this line "color.mywidget.bg = white".

See Also:
  • Constructor Details

    • GColor

      public GColor(String id)
      Construct a GColor with an id that will be used to look up the current color associated with that id, which can be changed at runtime.
      Parameters:
      id - the id used to lookup the current value for this color
    • GColor

      protected GColor(GColor gColor)
      Copy constructor. Used primarily to convert a GColorUiResource to a GColor without having to lookup the color which can cause errors during theme transitions.
      Parameters:
      gColor - the gColor to copy
  • Method Details

    • withAlpha

      public GColor withAlpha(int newAlpha)
      Creates a transparent version of this GColor. If the underlying value of this GColor changes, the transparent version will also change.
      Parameters:
      newAlpha - the transparency level for the new color
      Returns:
      a transparent version of this GColor
    • getId

      public String getId()
      Returns the id for this GColor.
      Returns:
      the id for this GColor.
    • getRed

      public int getRed()
      Overrides:
      getRed in class Color
    • getGreen

      public int getGreen()
      Overrides:
      getGreen in class Color
    • getBlue

      public int getBlue()
      Overrides:
      getBlue in class Color
    • getAlpha

      public int getAlpha()
      Overrides:
      getAlpha in class Color
    • getRGB

      public int getRGB()
      Overrides:
      getRGB in class Color
    • brighter

      public Color brighter()
      Overrides:
      brighter in class Color
    • darker

      public Color darker()
      Overrides:
      darker in class Color
    • isUnresolved

      public boolean isUnresolved()
      Returns true if this GColor could not find a value for its color id in the current theme and is using the default color as its delegate
      Returns:
      true if this GColor could not find a value for its color id in the current theme
    • toString

      public String toString()
      Overrides:
      toString in class Color
    • toHexString

      public String toHexString()
      Returns this color as a hex string that starts with '#'
      Returns:
      the hex string
    • toDebugString

      public String toDebugString()
      Generates a more verbose toString()
      Returns:
      a more verbose toString()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Color
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Color
    • getRGBComponents

      public float[] getRGBComponents(float[] compArray)
      Overrides:
      getRGBComponents in class Color
    • getRGBColorComponents

      public float[] getRGBColorComponents(float[] compArray)
      Overrides:
      getRGBColorComponents in class Color
    • getComponents

      public float[] getComponents(float[] compArray)
      Overrides:
      getComponents in class Color
    • getColorComponents

      public float[] getColorComponents(float[] compArray)
      Overrides:
      getColorComponents in class Color
    • getComponents

      public float[] getComponents(ColorSpace cspace, float[] compArray)
      Overrides:
      getComponents in class Color
    • getColorComponents

      public float[] getColorComponents(ColorSpace cspace, float[] compArray)
      Overrides:
      getColorComponents in class Color
    • getColorSpace

      public ColorSpace getColorSpace()
      Overrides:
      getColorSpace in class Color
    • createContext

      public PaintContext createContext(ColorModel cm, Rectangle r, Rectangle2D r2d, AffineTransform xform, RenderingHints hints)
      Specified by:
      createContext in interface Paint
      Overrides:
      createContext in class Color
    • getTransparency

      public int getTransparency()
      Specified by:
      getTransparency in interface Transparency
      Overrides:
      getTransparency in class Color
    • refresh

      public void refresh(GThemeValueMap currentValues)
      Reloads the delegate.
      Parameters:
      currentValues - the map of current theme values
    • refreshAll

      public static void refreshAll(GThemeValueMap currentValues)
      Static method for notifying all the existing GColors that colors have changed and they should reload their cached indirect color.
      Parameters:
      currentValues - the map of current theme values