Package sc.fiji.snt.util
Class SNTColor
java.lang.Object
sc.fiji.snt.util.SNTColor
A simple class for handling Colors including the ability to map an AWT Color
to a SWC type integer tag.
- Author:
- Tiago Ferreira
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ColoralphaColor(Color c, double percent) Adds an alpha component to an AWT color.static Coloraverage(Collection<Color> colors) Averages a collection of colorscolor()Retrieves the AWT colorstatic StringcolorToString(Object color) Returns the color encoded as hex string with the format #rrggbbaa.static ColorReturns a suitable 'contrast' color.booleanstatic ColorReturns an AWT Color from a (#)RRGGBB(AA) hex string.static ColorfromString(String colorName) Returns an AWT Color from any css-valid costatic org.scijava.util.ColorRGB[]getDistinctColors(int nColors) Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded).static org.scijava.util.ColorRGB[]getDistinctColors(int nColors, String excludedHue) Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded).static Color[]getDistinctColorsAWT(int nColors) static String[]getDistinctColorsHex(int nColors) Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded) as Hex values.static String[]getDistinctColorsHex(int nColors, String excludedHue) Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded) as Hex values.inthashCode()static voidinterpolateNullEntries(Color[] colors) Replaces null colors in an array with the average of flanking non-null colors.booleanChecks if an SWC type has been defined.voidsetAWTColor(Color color) Re-assigns an AWT color.voidsetSWCType(int swcType) Re-assigns a SWC type integer flagtoString()inttype()Retrieves the SWC typestatic org.scijava.util.ColorRGBParses a color from the given string.
-
Field Details
-
SWC_TYPE_IGNORED
protected static final int SWC_TYPE_IGNORED- See Also:
-
-
Constructor Details
-
SNTColor
Instantiates a new SNT color.- Parameters:
color- the AWT colorswcType- the SWC type integer flag to be associated with color
-
SNTColor
Instantiates a new SNT color without SWC type association- Parameters:
color- the AWT color
-
-
Method Details
-
color
Retrieves the AWT color- Returns:
- the AWT color
-
type
public int type()Retrieves the SWC type- Returns:
- the SWC type integer flag
-
isTypeDefined
public boolean isTypeDefined()Checks if an SWC type has been defined.- Returns:
- true, if an SWC integer flag has been specified
-
setAWTColor
Re-assigns an AWT color.- Parameters:
color- the new color
-
setSWCType
public void setSWCType(int swcType) Re-assigns a SWC type integer flag- Parameters:
swcType- the new SWC type
-
hashCode
public int hashCode() -
equals
-
toString
-
colorToString
Returns the color encoded as hex string with the format #rrggbbaa.- Parameters:
color- the input AWT color- Returns:
- the converted string
-
fromString
Returns an AWT Color from any css-valid co- Parameters:
colorName- the input string- Returns:
- the converted AWT color
-
fromHex
Returns an AWT Color from a (#)RRGGBB(AA) hex string.- Parameters:
hex- the input string- Returns:
- the converted AWT color
-
average
Averages a collection of colors- Parameters:
colors- the colors to be averaged- Returns:
- the averaged color. Note that an average will never be accurate because the RGB space is not linear. Color.BLACK is returned if all colors in input collection are null;
-
interpolateNullEntries
Replaces null colors in an array with the average of flanking non-null colors.- Parameters:
colors- the color array
-
alphaColor
Adds an alpha component to an AWT color.- Parameters:
c- the input colorpercent- alpha value in percentage- Returns:
- the color with an alpha component
-
contrastColor
Returns a suitable 'contrast' color.- Parameters:
c- the input color- Returns:
- Either white or black, as per hue of input color.
-
getDistinctColors
public static org.scijava.util.ColorRGB[] getDistinctColors(int nColors) Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded). More details on this SO discussion- Parameters:
nColors- the number of colors to be retrieved.- Returns:
- the maximum contrast colors
-
getDistinctColors
Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded). More details on this SO discussion- Parameters:
nColors- the number of colors to be retrievedexcludedHue- an optional string defining a hue to be excluded. Either 'red', 'green', 'blue', or 'dim'- Returns:
- the maximum contrast colors
-
valueOf
Parses a color from the given string.The following formats are supported: Hex format [HTML color codes starting with hash (#)], Color presets (e.g., 'blue', 'pink', 'silver', etc.), and integer triples of the form r,g,b, with each element in the range [0, 255].
- Parameters:
colorSpec- string defining the color value- Returns:
- the color
-
getDistinctColorsHex
Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded) as Hex values. More details on this SO discussion- Parameters:
nColors- the number of colors to be retrievedexcludedHue- an optional string defining a hue to be excluded. Either 'red', 'green', 'blue', or 'dim'- Returns:
- the maximum contrast colors as hex color strings
-
getDistinctColorsHex
Returns distinct colors based on Kenneth Kelly's 22 colors of maximum contrast (black and white excluded) as Hex values. More details on this SO discussion- Parameters:
nColors- the number of colors to be retrieved- Returns:
- the maximum contrast colors as hex color strings
-
getDistinctColorsAWT
-