Package com.inductiveautomation.snap.gfx
Class SnapColor
- java.lang.Object
-
- com.inductiveautomation.snap.gfx.SnapColor
-
public class SnapColor extends java.lang.Object
This class represents an RGBA color, just like Java.awt.Color. It was originally needed when running without AWT. It still has some convenience, but maybe one day should be replaced by, or just subclass, Java.awt.Color.
-
-
Field Summary
Fields Modifier and Type Field Description static SnapColor
BLACK
static SnapColor
BLUE
static SnapColor
CLEAR
static SnapColor
CLEARWHITE
static SnapColor
CYAN
static SnapColor
DARKGRAY
static SnapColor
GRAY
static SnapColor
GREEN
static SnapColor
LIGHTBLUE
static SnapColor
LIGHTGRAY
static SnapColor
MAGENTA
static SnapColor
ORANGE
static SnapColor
PINK
static SnapColor
RED
static SnapColor
WHITE
static SnapColor
YELLOW
-
Constructor Summary
Constructors Constructor Description SnapColor()
Creates a plain black opaque color.SnapColor(double g)
Creates a color with the given gray value (0-1).SnapColor(double g, double a)
Creates a color with the given gray and alpha values (0-1).SnapColor(double r, double g, double b)
Creates a color with the given red, green blue values (0-1).SnapColor(double r, double g, double b, double a)
Creates a color with the given red, green, blue values (0-1).SnapColor(float c, float m, float y, float k, float a)
Creates a color with the given cyan, magenta, yellow, black and alpha values (0-1).SnapColor(int r, int g, int b)
Creates a color with the given red, green blue values (0-1).SnapColor(java.lang.String aHexString)
Creates a new color from the given hex string.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.Color
awt()
Returns an AWT version of this color.SnapColor
blend(SnapColor aColor, double aFraction)
Returns a color darker than this color (by this given fraction).SnapColor
brighter()
Returns a color brighter than this color (blended with white).static SnapColor
colorValue(java.lang.Object anObj)
Returns a color value for a given object.SnapColor
darker()
Returns a color darker than this color (blended with black).boolean
equals(java.lang.Object anObj)
Standard equals implementation.double
getAlpha2D()
Returns the alpha component in the range 0-1.int
getAlphaInt()
Returns the alpha component in the range 0-255.double
getBlue2D()
Returns the blue component in the range 0-1.int
getBlueInt()
Returns the blue component in the range 0-255.double
getGreen2D()
Returns the green component in the range 0-1.int
getGreenInt()
Returns the green component in the range 0-255.static SnapColor
getRandom()
Returns a random color.double
getRed2D()
Returns the red component in the range 0-1.int
getRedInt()
Returns the red component in the range 0-255.int
getRGBA()
Returns the color as an int.int
hashCode()
Standard Hashcode implementation.java.lang.String
toHexString()
Returns a hex string representation of this color.java.lang.String
toString()
Returns a string representation of this color.
-
-
-
Field Detail
-
BLACK
public static SnapColor BLACK
-
BLUE
public static SnapColor BLUE
-
CYAN
public static SnapColor CYAN
-
DARKGRAY
public static SnapColor DARKGRAY
-
GRAY
public static SnapColor GRAY
-
GREEN
public static SnapColor GREEN
-
LIGHTGRAY
public static SnapColor LIGHTGRAY
-
MAGENTA
public static SnapColor MAGENTA
-
ORANGE
public static SnapColor ORANGE
-
PINK
public static SnapColor PINK
-
RED
public static SnapColor RED
-
WHITE
public static SnapColor WHITE
-
YELLOW
public static SnapColor YELLOW
-
CLEAR
public static SnapColor CLEAR
-
LIGHTBLUE
public static SnapColor LIGHTBLUE
-
CLEARWHITE
public static SnapColor CLEARWHITE
-
-
Constructor Detail
-
SnapColor
public SnapColor()
Creates a plain black opaque color.
-
SnapColor
public SnapColor(double g)
Creates a color with the given gray value (0-1).
-
SnapColor
public SnapColor(double g, double a)
Creates a color with the given gray and alpha values (0-1).
-
SnapColor
public SnapColor(double r, double g, double b)
Creates a color with the given red, green blue values (0-1).
-
SnapColor
public SnapColor(int r, int g, int b)
Creates a color with the given red, green blue values (0-1).
-
SnapColor
public SnapColor(double r, double g, double b, double a)
Creates a color with the given red, green, blue values (0-1).
-
SnapColor
public SnapColor(float c, float m, float y, float k, float a)
Creates a color with the given cyan, magenta, yellow, black and alpha values (0-1). Bogus right now.
-
SnapColor
public SnapColor(java.lang.String aHexString)
Creates a new color from the given hex string.
-
-
Method Detail
-
getRed2D
public double getRed2D()
Returns the red component in the range 0-1.
-
getGreen2D
public double getGreen2D()
Returns the green component in the range 0-1.
-
getBlue2D
public double getBlue2D()
Returns the blue component in the range 0-1.
-
getAlpha2D
public double getAlpha2D()
Returns the alpha component in the range 0-1.
-
getRedInt
public int getRedInt()
Returns the red component in the range 0-255.
-
getGreenInt
public int getGreenInt()
Returns the green component in the range 0-255.
-
getBlueInt
public int getBlueInt()
Returns the blue component in the range 0-255.
-
getAlphaInt
public int getAlphaInt()
Returns the alpha component in the range 0-255.
-
getRGBA
public int getRGBA()
Returns the color as an int.
-
brighter
public SnapColor brighter()
Returns a color brighter than this color (blended with white).
-
darker
public SnapColor darker()
Returns a color darker than this color (blended with black).
-
blend
public SnapColor blend(SnapColor aColor, double aFraction)
Returns a color darker than this color (by this given fraction).
-
equals
public boolean equals(java.lang.Object anObj)
Standard equals implementation.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Standard Hashcode implementation.- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Returns a string representation of this color.- Overrides:
toString
in classjava.lang.Object
-
toHexString
public java.lang.String toHexString()
Returns a hex string representation of this color.
-
colorValue
public static SnapColor colorValue(java.lang.Object anObj)
Returns a color value for a given object.
-
getRandom
public static SnapColor getRandom()
Returns a random color.
-
awt
public java.awt.Color awt()
Returns an AWT version of this color.
-
-