com.vaadin.sass.internal.util
Class ColorUtil

java.lang.Object
  extended by com.vaadin.sass.internal.util.ColorUtil

public class ColorUtil
extends Object


Constructor Summary
ColorUtil()
           
 
Method Summary
static float[] colorToHsl(LexicalUnitImpl color)
          Converts a color into an array of its HSL (hue, saturation, lightness) components.
static int[] colorToRgb(LexicalUnitImpl color)
          Converts a color into an array of its RGB components.
static LexicalUnitImpl createHexColor(int[] rgb, int line, int column)
           
static LexicalUnitImpl createHexColor(int red, int green, int blue, int line, int column)
           
static LexicalUnitImpl createHslaColor(float hue, float saturation, float lightness, float alpha, int line, int column)
           
static LexicalUnitImpl createHslaOrHslColor(float[] hsl, float alpha, int line, int column)
           
static LexicalUnitImpl createRgbaColor(int red, int green, int blue, float alpha, int line, int column)
           
static LexicalUnitImpl createRgbaOrHexColor(int[] rgb, float alpha, int line, int column)
          Creates a hex color if alpha is equal to one.
static LexicalUnitImpl darken(LexicalUnitImpl color, float amount)
           
static float getAlpha(LexicalUnitImpl color)
          Returns the alpha component of the color.
static int[] hslToRgb(float[] hsl)
          Converts an array of HSL components to a string representing the color.
static boolean isColor(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid color (hexadecimal, rgb(), color name etc.), false otherwise.
static boolean isColorName(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid color name, false otherwise.
static boolean isHexColor(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid color in the hexadecimal form (three or six digits), false otherwise.
static boolean isHexColor(String string)
          Returns true if the string represents a valid color in the hexadecimal form (three or six digits), false otherwise.
static boolean isHsla(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid HSLA value, false otherwise.
static boolean isHslColor(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid hsl() color function call, false otherwise.
static boolean isRgba(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid RGBA value, false otherwise.
static boolean isRgbFunction(LexicalUnitImpl unit)
          Returns true if the lexical unit represents a valid rgb() method call , false otherwise.
static LexicalUnitImpl lighten(LexicalUnitImpl color, float amount)
           
static String rgbToColorString(int[] rgb)
          Converts an array of RGB components to a string representing the color.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorUtil

public ColorUtil()
Method Detail

isColor

public static boolean isColor(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid color (hexadecimal, rgb(), color name etc.), false otherwise. Note that rgba() and hsla() are not considered to be normal colors. To detect it, call isRgba() or isHsla().

Parameters:
unit - lexical unit
Returns:
true if unit represents a color

isRgbFunction

public static boolean isRgbFunction(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid rgb() method call , false otherwise.

Parameters:
unit - lexical unit
Returns:
true if unit represents an RGB method call

isRgba

public static boolean isRgba(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid RGBA value, false otherwise.

Parameters:
unit - lexical unit
Returns:
true if unit represents an RGBA value

isHsla

public static boolean isHsla(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid HSLA value, false otherwise.

Parameters:
unit - lexical unit
Returns:
true if unit represents an HSLA value

isHexColor

public static boolean isHexColor(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid color in the hexadecimal form (three or six digits), false otherwise.

Parameters:
unit - lexical unit
Returns:
true if unit represents a hexadecimal color

isColorName

public static boolean isColorName(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid color name, false otherwise. Currently, the 17 standard color names from the HTML and CSS color specification are supported.

Parameters:
unit - lexical unit
Returns:
true if unit represents a color name

isHslColor

public static boolean isHslColor(LexicalUnitImpl unit)
Returns true if the lexical unit represents a valid hsl() color function call, false otherwise.

Parameters:
unit - lexical unit
Returns:
true if unit represents as HSL color

getAlpha

public static float getAlpha(LexicalUnitImpl color)
Returns the alpha component of the color. For colors that do not have an explicit alpha component, returns 1.

Parameters:
color - An object representing a valid color.
Returns:
The alpha component of color.

colorToRgb

public static int[] colorToRgb(LexicalUnitImpl color)
Converts a color into an array of its RGB components. In the case of an RGBA value, the alpha channel is ignored.

Parameters:
color - a lexical unit that represents a color
Returns:
RGB components or null if not a color

rgbToColorString

public static String rgbToColorString(int[] rgb)
Converts an array of RGB components to a string representing the color.

Parameters:
rgb - the RGB components of a color
Returns:
a valid string representation of the color

hslToRgb

public static int[] hslToRgb(float[] hsl)
Converts an array of HSL components to a string representing the color.

Parameters:
hsl - the HSL components of a color
Returns:
a valid string representation of the color

colorToHsl

public static float[] colorToHsl(LexicalUnitImpl color)
Converts a color into an array of its HSL (hue, saturation, lightness) components.

Parameters:
color - a lexical unit that represents a color
Returns:
HSL components or null if not a color

isHexColor

public static boolean isHexColor(String string)
Returns true if the string represents a valid color in the hexadecimal form (three or six digits), false otherwise.

Parameters:
string - string that might represent a hex color
Returns:
true if string represents a hexadecimal color

createHexColor

public static LexicalUnitImpl createHexColor(int red,
                                             int green,
                                             int blue,
                                             int line,
                                             int column)

createHexColor

public static LexicalUnitImpl createHexColor(int[] rgb,
                                             int line,
                                             int column)

createRgbaColor

public static LexicalUnitImpl createRgbaColor(int red,
                                              int green,
                                              int blue,
                                              float alpha,
                                              int line,
                                              int column)

createHslaColor

public static LexicalUnitImpl createHslaColor(float hue,
                                              float saturation,
                                              float lightness,
                                              float alpha,
                                              int line,
                                              int column)

createHslaOrHslColor

public static LexicalUnitImpl createHslaOrHslColor(float[] hsl,
                                                   float alpha,
                                                   int line,
                                                   int column)

createRgbaOrHexColor

public static LexicalUnitImpl createRgbaOrHexColor(int[] rgb,
                                                   float alpha,
                                                   int line,
                                                   int column)
Creates a hex color if alpha is equal to one. Otherwise creates an RGBA color.

Returns:
An object representing a color.

darken

public static LexicalUnitImpl darken(LexicalUnitImpl color,
                                     float amount)

lighten

public static LexicalUnitImpl lighten(LexicalUnitImpl color,
                                      float amount)


Copyright © 2013–2015 Vaadin. All rights reserved.