public abstract class TupleColorFormat extends Object implements ColorFormat
colorMethodName(list of number values seperated by comma)
".Modifier and Type | Field and Description |
---|---|
org.apache.commons.logging.Log |
logger |
Constructor and Description |
---|
TupleColorFormat() |
Modifier and Type | Method and Description |
---|---|
protected String |
formatColorMethod(String data)
Packs a a list of colors values inside a tuple color format, "colorMethodName(data)".
|
protected String |
formatTuples(String postfix,
int digits,
double... values)
Formats a series of double values, seperated by comma and postfixed.
|
abstract String |
getColorMethodName()
The method name which identifies the color method (aka rgb, rgba, hsl, hsla etc.)
|
org.apache.commons.logging.Log |
getLogger() |
protected String[] |
getMethodTokens(String text,
int numberOfTokens)
Retrieves the string tokens inside the "methodName(token1,token1,...tokenN)"
|
boolean |
isOfColorMethodFormat(String text)
Evaluates if a text represense the color format method.
|
protected double |
limitsValue(double min,
double max,
double value)
Clamps the value to the range limits, if the value is outside the valid range.
|
protected float |
limitsValue(float min,
float max,
float value)
Clamps the value to the range limits, if the value is outside the valid range.
|
protected int |
limitsValue(int min,
int max,
int value)
Clamps the value to the range limits, if the value is outside the valid range.
|
protected float |
parseFloatToken(String concerning,
String token,
float minValue,
float maxValue,
boolean autoLimit)
Validates that a string is a float between minValue and maxValue (inclusive).
|
protected int |
parseIntToken(String concerning,
String token,
int minValue,
int maxValue,
boolean autoLimit,
boolean wrapValue)
Validates that a string is an integer between minValue and maxValue of int or (0x)hex string value.
|
protected float |
parsePercentageToken(String concerning,
String token,
boolean autoLimit)
Validates that a string is a float between 0.0 and 100.0 (inclusive).
|
protected int |
parseRGBToken(String concerning,
String token,
boolean autoLimit,
boolean wrapResult)
Validates that a string is an integer between 0 and 255 of int or hex 0x00 and 0xFF string value.
|
protected void |
validateRange(String concerning,
double minInclusive,
double maxInclusive,
double value,
String originalValue)
Validates that number is inside a valid range, will throw an exception if outside the range.
Common used method for TupleColorFormat formats. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
format, isAlphaSupported, parse
public org.apache.commons.logging.Log getLogger()
public abstract String getColorMethodName()
protected final void validateRange(String concerning, double minInclusive, double maxInclusive, double value, String originalValue) throws ColorFormatException
concerning
- a message that describes the area/contense which the value is concerning, use for a describing exception, if any.minInclusive
- the minimum value which the value must be greater or equal to, for not throwing an exception.maxInclusive
- the maximum value which the value must be less or equal to, for not throwing an exception.value
- the valueoriginalValue
- the String value before parse and manipulated.ColorFormatException
- if value<minInclusive
or value>maxInclusive
.public final boolean isOfColorMethodFormat(String text)
text
- the texttrue
if the text starts with "methodName(" and ends with ")", otherwise false
.protected final String[] getMethodTokens(String text, int numberOfTokens) throws ColorFormatException
text
- the text line containing the the color value.numberOfTokens
- the expected number of tokens.ColorFormatException,
- If the text do not start with the "methodName(". null
. ColorFormatException
protected final int limitsValue(int min, int max, int value)
min
- the minimum value (inclusive) the value is allowed to be.max
- the maximum value (inclusive) the value is allowed to be.value
- the valuemin
if value
below min
, max
if value
is above max
, otherwise value
.protected final double limitsValue(double min, double max, double value)
min
- the minimum value (inclusive) the value is allowed to be.max
- the maximum value (inclusive) the value is allowed to be.value
- the valuemin
if value
below min
, max
if value
is above max
, otherwise value
.protected final float limitsValue(float min, float max, float value)
min
- the minimum value (inclusive) the value is allowed to be.max
- the maximum value (inclusive) the value is allowed to be.value
- the valuemin
if value
below min
, max
if value
is above max
, otherwise value
.protected final int parseIntToken(String concerning, String token, int minValue, int maxValue, boolean autoLimit, boolean wrapValue) throws ColorFormatException
concerning
- the field/area the value is concerning.token
- the string valueminValue
- the minimum value allowed, inclusive.maxValue
- the maximum value allowed, inclusive.autoLimit
- auto limit the value to range limits, if outside the valid range. Mutual exclusive with wrapResult.wrapValue
- if true
maxValue will be added if the integer is below minValue or maxValue will be subtracted if the value is above maxValue. Mutual exclusive with autoLimit.ColorFormatException
protected final float parseFloatToken(String concerning, String token, float minValue, float maxValue, boolean autoLimit) throws ColorFormatException
concerning
- the field/area the value is concerning.token
- the string valueminValue
- the minimum value allowed, inclusive.maxValue
- the maximum value allowed, inclusive.autoLimit
- auto limit the value to range limits, if outside the valid range.ColorFormatException
protected final float parsePercentageToken(String concerning, String token, boolean autoLimit) throws ColorFormatException
concerning
- the field/area the value is concerning.token
- the string valueautoLimit
- auto limit the value to range limits, if outside the valid range.ColorFormatException
protected final int parseRGBToken(String concerning, String token, boolean autoLimit, boolean wrapResult) throws ColorFormatException
concerning
- the field/area the value is concerning.token
- the string valueautoLimit
- auto limit the value to range limits, if outside the valid range. Mutual exclusive with wrapResult.wrapResult
- if true
maxValue will be added if the integer is below minValue or maxValue will be subtracted if the value is above maxValue. Mutual exclusive with autoLimit.ColorFormatException
protected final String formatColorMethod(String data)
data
- the values for the color format, it is assumed this a list of numbers seperated by comma.getColorMethodName()
protected final String formatTuples(String postfix, int digits, double... values)
postfix
- appends this to every value if it is null
.digits
- the number of digits format on each value, if value is below the precision the integer value is returned.values
- the array of double values to be parseFormattingUtils.formatDouble(double, int, String)