- java.lang.Object
-
- eu.ess.xaos.ui.util.ColorUtils
-
public class ColorUtils extends Object
Various utility methods operating onColor
.- Author:
- claudio.rosati@esss.se
- See Also:
- ESS Control System OPI Development Style Guide
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Color
bestConstrasting(Color color, Color... others)
static Color
changeOpacity(Color color, double offset)
Adds the givenoffset
to thecolor
's opacity.static double
getLuma(Color color)
Returns the weighted brightness (luma) according to the HSP color model.static Color
mean(List<Color> colors)
static Color
meanColor(List<Stop> stops)
static Color
toColor(Paint paint)
static String
toWeb(Color color)
Converts the givenColor
to its web string representation.
-
-
-
Field Detail
-
ESS_BLUE
public static final Color ESS_BLUE
-
ESS_BLUE_DARK
public static final Color ESS_BLUE_DARK
-
ESS_BLUE_LED
public static final Color ESS_BLUE_LED
-
ESS_BLUE_LED_OFF
public static final Color ESS_BLUE_LED_OFF
-
ESS_GRAY
public static final Color ESS_GRAY
-
ESS_GRAY_DARK
public static final Color ESS_GRAY_DARK
-
ESS_GREEN
public static final Color ESS_GREEN
-
ESS_GREEN_DARK
public static final Color ESS_GREEN_DARK
-
ESS_GREEN_LED
public static final Color ESS_GREEN_LED
-
ESS_GREEN_LED_OFF
public static final Color ESS_GREEN_LED_OFF
-
ESS_MAGENTA
public static final Color ESS_MAGENTA
-
ESS_MAGENTA_DARK
public static final Color ESS_MAGENTA_DARK
-
ESS_MAGENTA_LED
public static final Color ESS_MAGENTA_LED
-
ESS_MAGENTA_LED_OFF
public static final Color ESS_MAGENTA_LED_OFF
-
ESS_ORANGE
public static final Color ESS_ORANGE
-
ESS_ORANGE_DARK
public static final Color ESS_ORANGE_DARK
-
ESS_ORANGE_LED
public static final Color ESS_ORANGE_LED
-
ESS_ORANGE_LED_OFF
public static final Color ESS_ORANGE_LED_OFF
-
ESS_PRIMARY
public static final Color ESS_PRIMARY
-
ESS_PRIMARY_DARK
public static final Color ESS_PRIMARY_DARK
-
ESS_PRIMARY_LIGHT
public static final Color ESS_PRIMARY_LIGHT
-
ESS_RED
public static final Color ESS_RED
-
ESS_RED_DARK
public static final Color ESS_RED_DARK
-
ESS_RED_LED
public static final Color ESS_RED_LED
-
ESS_RED_LED_OFF
public static final Color ESS_RED_LED_OFF
-
ESS_SECONDARY
public static final Color ESS_SECONDARY
-
ESS_SECONDARY_DARK
public static final Color ESS_SECONDARY_DARK
-
ESS_SECONDARY_LIGHT
public static final Color ESS_SECONDARY_LIGHT
-
ESS_YELLOW
public static final Color ESS_YELLOW
-
ESS_YELLOW_DARK
public static final Color ESS_YELLOW_DARK
-
ESS_YELLOW_LED
public static final Color ESS_YELLOW_LED
-
ESS_YELLOW_LED_OFF
public static final Color ESS_YELLOW_LED_OFF
-
ESS_ATTENTION
public static final Color ESS_ATTENTION
-
ESS_DISCONNECTED
public static final Color ESS_DISCONNECTED
-
ESS_ERROR
public static final Color ESS_ERROR
-
ESS_INVALID
public static final Color ESS_INVALID
-
ESS_MAJOR
public static final Color ESS_MAJOR
-
ESS_MINOR
public static final Color ESS_MINOR
-
ESS_OFF
public static final Color ESS_OFF
-
ESS_OK
public static final Color ESS_OK
-
ESS_ON
public static final Color ESS_ON
-
ESS_STOP
public static final Color ESS_STOP
-
ESS_WARNING
public static final Color ESS_WARNING
-
-
Method Detail
-
bestConstrasting
public static Color bestConstrasting(Color color, Color... others)
- Parameters:
color
- TheColor
who needs a best contrasting one from theothers
ones.others
- The array ofColor
s from which the best contrasting one must be chosen.- Returns:
- The best contrasting color.
- Throws:
NullPointerException
- Ifcolor
orothers
isnull
.IllegalArgumentException
- Ifothers
is an empty array.- See Also:
getLuma(javafx.scene.paint.Color)
-
changeOpacity
public static Color changeOpacity(Color color, double offset)
Adds the givenoffset
to thecolor
's opacity. Negative values will increase transparency (lower opacity), positive values will increase opacity.- Parameters:
color
- TheColor
whose opacity must be changed.offset
- The opacity offset to be added to the currentcolor
's opacity.- Returns:
- The changed
Color
. - Throws:
NullPointerException
- Ifcolor
is null.IllegalArgumentException
- Ifoffset
is not in the[0, 1]
range.
-
getLuma
public static double getLuma(Color color)
Returns the weighted brightness (luma) according to the HSP color model.- Parameters:
color
- The color whose perceived brightness must be returned.- Returns:
- The weighted brightness (luma).
- Throws:
NullPointerException
- Ifcolor
is null.- See Also:
- HSP Color Model, Weighted Methods.
-
toColor
public static Color toColor(Paint paint)
Converts the givenPaint
object to aColor
one. If the givenpaint
object is already aColor
, then simple cast is performed. If thepaint
object is aLinearGradient
or aRadialGradient
, themean
color of itsstops
is returned instead. In all other casesnull
is returned.
-
toWeb
public static String toWeb(Color color)
Converts the givenColor
to its web string representation.If the given
color
isopaque
then the returned string will be#rrggbb
otherwise#rrggbboo
, whererr
,gg
, andbb
are the hexadecimal value of the three color components (red, green, and blue), whileoo
is the hexadecimal representation of the color's opacity.- Parameters:
color
- TheColor
to be converted.- Returns:
- A
String
representation of the givencolor
. - Throws:
NullPointerException
- Ifcolor
is null.
-
-