public class SSColor
extends java.awt.Color
from(StringScanner)
.
If the string is invalid, the value is DEFAULT_COLOR. It is almost black, but not black so black itself is valid.
The constructor with a StringScanner argument advances the scanner across the color name.
The arguments to the Color class constructors always list the alpha value last: 'rgba' or 'int r, int g, int b, int a' HOWEVER, when color is an integer, the bytes are ordered a r g b
The list of color names is in an asset called colorlist.csv. At build time, that
list is copied from physpics.com/pictools/colorlist.csv
.
Neither list is expected to change, but if either does, they may diverge.
An individual user may install a private, modifiable list in
~/.physpics/assets/com.physpics.tools/colorlist.csv
.
SSColor is among the physpics color tools listed in
http://physpics.com/Essays/coding/ColorTools.php
.
Modifier and Type | Class and Description |
---|---|
static class |
SSColor.PopupForTextField
Provide a color completion popup menu to augment a JTextField.
|
Modifier and Type | Field and Description |
---|---|
static SSColor |
DEFAULT_COLOR |
protected int[] |
hsl |
protected java.lang.String |
key |
java.lang.String |
link |
protected static int |
nNamedColors
how many colors come from colorlist.csv + DEFAULT_COLOR
|
protected static java.util.HashMap<java.lang.Integer,java.util.ArrayList<SSColor>> |
registered
Map from color value to an ArrayList of SSColors having that color.
|
protected java.lang.String |
source |
protected static java.util.HashMap<java.lang.String,java.util.ArrayList<SSColor>> |
stemMap
Map from name stem to list of colors with that stem.
|
protected java.lang.String |
stemName |
protected int |
variant |
Modifier | Constructor and Description |
---|---|
protected |
SSColor(int i,
boolean hasAlpha)
Construct an SSColor for a given integer, possibly including alpha.
|
Modifier and Type | Method and Description |
---|---|
SSColor |
brighter() |
static java.util.ArrayList<SSColor> |
colorRegistrees(int avalue) |
static java.util.ArrayList<java.lang.String> |
continuations(java.lang.String input) |
SSColor |
darker() |
static SSColor |
from(java.awt.Color klr)
Convert a color value to an SSColor with the same value.
|
static SSColor |
from(int value)
Convert a Color to an SSColor with the same value.
|
static SSColor |
from(int value,
boolean hasAlpha)
Convert a color value with alpha to an SSColor with the same value.
|
static SSColor |
from(int r,
int g,
int b)
Combine three int values into an rgb.
|
static SSColor |
from(java.lang.String klrspec)
Parse a string as a color spec and return a corresponding SSColor.
|
static SSColor |
from(StringScanner ss)
Parse the String following the selected portion of a StringScanner
for a color specification.
|
static SSColor |
from(java.lang.String hashRGB,
java.lang.String stem,
java.lang.String vrnt)
Create or find a color with the given rgb, name, and variant.
|
java.lang.String |
getDisplayName() |
int[] |
getHsl() |
java.lang.String |
getKey() |
java.lang.String |
getLink() |
java.lang.String |
getName() |
java.lang.String |
getSource() |
static java.util.ArrayList<SSColor> |
getVariants(java.lang.String keyName) |
static double |
grayScale(int r,
int g,
int b)
Compute the gray scale value for this color.
|
static int[] |
hslToRgb(double h,
double s,
double l)
Converts an HSL color value to RGB.
|
protected static double |
hueToRgb(double p,
double q,
double t)
Helper method that converts hue to rgb.
|
static java.lang.String |
intToHex(int klr)
Convert an int to hex.
|
boolean |
isRegistered() |
static java.lang.String |
keyName(java.lang.String name)
Produce a key name from a full color name.
|
static int |
mulround(double v,
int max)
Convert a value in [0,1] to [0,max] by multiplying and rounding.
|
static int |
parseInt(java.lang.String h)
Compute the rgb integer for a hex color.
|
void |
register()
Register a color for later lookup.
|
static double[] |
rgbToHSL(int pR,
int pG,
int pB)
Converts an RGB color value to HSL.
|
void |
setLink(java.lang.String lnk) |
void |
setSource(java.lang.String src)
Set the parenthesized source segment.
|
java.lang.String |
toAHex()
Produce a string of 8 hex digits for this color.
|
int |
toAValue() |
java.lang.String |
toCSS()
Return a css string for this color.
|
java.lang.String |
toHex()
Produce the body of a hex string for this color.
|
java.lang.String |
toHSL() |
int |
toInt()
Produce the body of a hex string for this color.
|
java.lang.String |
toString() |
void |
unregister()
Remove registration of a color.
|
createContext, decode, equals, getAlpha, getBlue, getColor, getColor, getColor, getColorComponents, getColorComponents, getColorSpace, getComponents, getComponents, getGreen, getHSBColor, getRed, getRGB, getRGBColorComponents, getRGBComponents, getTransparency, hashCode, HSBtoRGB, RGBtoHSB
public static final SSColor DEFAULT_COLOR
protected static java.util.HashMap<java.lang.Integer,java.util.ArrayList<SSColor>> registered
protected static final java.util.HashMap<java.lang.String,java.util.ArrayList<SSColor>> stemMap
protected static int nNamedColors
protected java.lang.String stemName
protected int variant
protected java.lang.String source
public java.lang.String link
protected java.lang.String key
protected int[] hsl
protected SSColor(int i, boolean hasAlpha)
i
- The color. Eight bits per value: alpha, red, green, blue.hasAlpha
- If true, the integer has alpha in its leading eight bits.
Alpha ranges from 0 to 255; that is, from transparent to opaque.public java.lang.String getDisplayName()
public java.lang.String getName()
public java.lang.String getKey()
public java.lang.String getSource()
public void setSource(java.lang.String src)
src
- the new parentheses segment String. May be null.public java.lang.String getLink()
public void setLink(java.lang.String lnk)
lnk
- the link to set. May be null to remove link.public SSColor brighter()
brighter
in class java.awt.Color
public SSColor darker()
darker
in class java.awt.Color
public static java.lang.String keyName(java.lang.String name)
name
- A full color name.public int[] getHsl()
public static java.util.ArrayList<SSColor> getVariants(java.lang.String keyName)
keyName
- the stemName of the requested SSColorspublic void register()
public boolean isRegistered()
public void unregister()
public static java.util.ArrayList<SSColor> colorRegistrees(int avalue)
avalue
- an integer argb color value.
That is, the value from getAValue.public static SSColor from(int value, boolean hasAlpha)
value
- An int with rgb in lower 24 bits
and alpha in the top eight bits.hasAlpha
- indicates whether the alpha value is present;
if not, it is set to FF, fully opaque.from(StringScanner)
public static SSColor from(int value)
value
- An int of rgb in lower 24 bits as a source for the value
of the returned SSColor.from(StringScanner)
public static SSColor from(int r, int g, int b)
r
- red [0,255]g
- green [0,255]b
- blue [0,255]public static SSColor from(java.awt.Color klr)
klr
- A Color object as a source for the value
of the returned SSColor.from(StringScanner)
public static SSColor from(java.lang.String klrspec)
klrspec
- A String expected to describe a color according
to one of the forms accepted by from(StringScanner).from(StringScanner)
public static SSColor from(java.lang.String hashRGB, java.lang.String stem, java.lang.String vrnt)
hashRGB
- The color value as a #rrggbb string.stem
- Name for the color. May be null. Examples: "Blue", "Forest green"vrnt
- A small integer to distinguish colors with same stem names.
May be empty to indicate no variant.
May be "*" to assign a new largest variant number.public static SSColor from(StringScanner ss)
Parameter values can be specified as integer [0,255] double [0.0,1.0] precent [0%,100%] or [0.0%,100.0%] in all cases, if the opacity (or a) is omitted, it defaults to 100% opaque. A string color specification ("color spec") is one of: -- a color name, see below (value may have alpha in high order bits) -- any form of number. This is interpreted as though it were the corresponding six digit hex value. No alpha value. A double value is rounded to the nearest integer. Example: 29, a pale blue. -- #hex: #rgb #rrggbb (no alpha portion is accepted) -- rgb(r,g,b) or rgb(r,g,b,a) -- hsb(h,s,b) or hsb(h,s,b,a) -- rgba(r,g,b,a) -- hsba(h,s,b,a) parameters are parsed by procParam; see that method for the forms r is red, g is green, b is blue, a is opacity (255==opaque) Any of the above may be optionally followed by an asterisk and an opacity procParam. Example: blue*25% This overrides an alpha in the value.A color name starts with a letter and continues with letters, digits, and spaces. It may be followed by a dash and a variant number. (At present, the only name with digits in it is "Mordant Red 19".) There are several names with accented letters; these are ignored when looking for the color in the list of named colors.
Whitespace is allowed between tokens, but - not within a color number - not between # and the following hex digits - not between a number and a following '%'The parser for each sort of value always produces an argb value. Where no alpha is allowed, the value used is 0xFF (fully opaque, not transparent).
ss
- The StringScanner to parse.public static java.util.ArrayList<java.lang.String> continuations(java.lang.String input)
input
- A prefix of a name. The value
is keyword-converted so accents and upper-case are converted
to lower case ASCII and digits are ignored.public static int mulround(double v, int max)
v
- A value in [0,1]max
- The maximum value to produce.public static int[] hslToRgb(double h, double s, double l)
h
- The hues
- The saturationl
- The lightnessprotected static double hueToRgb(double p, double q, double t)
p
- basis of return valueq
- correction to return valuet
- huepublic static double[] rgbToHSL(int pR, int pG, int pB)
pR
- The red color valuepG
- The green color valuepB
- The blue color valuepublic static int parseInt(java.lang.String h)
h
- The hex stringpublic static java.lang.String intToHex(int klr)
klr
- the color valuepublic static double grayScale(int r, int g, int b)
r
- red component [0-255]g
- green component [0-255]b
- blue component [0-255]public java.lang.String toHex()
public int toInt()
public int toAValue()
public java.lang.String toAHex()
public java.lang.String toCSS()
public java.lang.String toHSL()
newColor = SSColor.from(origColor.toHSL());
new2 = SSColor.from(newColor.toHSL();
results in newColor.equals(origColor) but more often the
value is slightly off. One might hope that newColor
would now be able to survive the transform, but half the time
new2.equals(newColor) is also false.
All these colors are, however, visually identical.public java.lang.String toString()
toString
in class java.awt.Color