org.moxieapps.gwt.highcharts.client
Class Color

java.lang.Object
  extended by org.moxieapps.gwt.highcharts.client.Configurable<Color>
      extended by org.moxieapps.gwt.highcharts.client.Color

public class Color
extends Configurable<Color>

Represents a color as either a solid RGB color, an RBG color with an alpha channel, or a gradient of colors. Many of the configurable chart objects support setting various color options (backgrounds, borders, etc). They all support a simply mechanism for setting the color to a standard RGB hex value (such as BaseChart.setBackgroundColor(String). However, if they also support alpha channels or gradients an overloaded method will be provided that takes a Color instance instead (e.g. BaseChart.setBackgroundColor(Color).

Example which sets the background color to a 10% opacity red color:


 chart.setBackgroundColor(new Color(255, 0, 0, .1));
 

Example which sets the background color to a linear gradient from white to a 50% opaque blue:


 chart.setBackgroundColor(new Color()
   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
   .addColorStop(0, "#FFFFFF")
   .addColorStop(0, 200, 200, 255, 0.5)
 );
 

Since:
1.0.0
Author:
squinn@moxiegroup.com (Shawn Quinn)

Constructor Summary
Color()
          An empty constructor that can be used when creating a color as a gradient.
Color(int r, int g, int b)
          Create a color instance specifying the three components of the RGB color separately (will result in a color that looks like "rgb(200, 255, 10)".
Color(int r, int g, int b, double a)
          Create a color instance specifying the three components of the RGB color separately as we as the alpha channel (will result in a color that looks like "rgb(200, 255, 10, 0.5)".
Color(String rgbHexColor)
          Create a color instance specifying the color in standard RGB hex notation (include the "#")
 
Method Summary
 Color addColorStop(double offset, int r, int g, int b)
          Adds the specified color at some position within the gradient (to be used in conjunction with the setLinearGradient(double, double, double, double) method or another one of its overloaded variants.)

Example which sets the background color to a linear gradient from white to blue:

 Color addColorStop(double offset, int r, int g, int b, double a)
          Adds the specified color at some position within the gradient allowing for the color to be specified with an alpha channel (to be used in conjunction with the setLinearGradient(double, double, double, double) method or another one of its overloaded variants.)

Example which sets the background color to a linear gradient from solid white to a 50% opaque blue:

 Color addColorStop(double offset, String rgbHexColor)
          Adds the specified color at some position within the gradient (to be used in conjunction with the setLinearGradient(double, double, double, double) method or another one of its overloaded variants.)

Example which sets the background color to a linear gradient from white to blue:

 com.google.gwt.json.client.JSONValue getOptionValue()
          This method will return the value of the object as a single value if it is represented as just a solid color or as a JSONObject if it represents a gradient.
 Color setLinearGradient(double x1, double x2, double y1, double y2)
          Sets up this color as a linear gradient from one location in space to another, specifying the coordinates in percentages of the space the gradient will fill.
 Color setLinearGradient(int x1, int x2, int y1, int y2)
          Sets up this color as a linear gradient from one location in space to another, specifying the coordinates in pixels.
 Color setLinearGradient(String x1, String x2, String y1, String y2)
          Sets up this color as a linear gradient from one location in space to another.
 
Methods inherited from class org.moxieapps.gwt.highcharts.client.Configurable
getOptions, setOption
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Color

public Color()
An empty constructor that can be used when creating a color as a gradient. See the setLinearGradient(double, double, double, double) and addColorStop(double, String) methods (and their overloaded variants.)


Color

public Color(String rgbHexColor)
Create a color instance specifying the color in standard RGB hex notation (include the "#")

Parameters:
rgbHexColor - The RGB hex of the color (include the "#").

Color

public Color(int r,
             int g,
             int b)
Create a color instance specifying the three components of the RGB color separately (will result in a color that looks like "rgb(200, 255, 10)".

Parameters:
r - The red component of the color in the RGB color space (0 to 255)
g - The green component of the color in the RGB color space (0 to 255)
b - The blue component of the color in the RGB color space (0 to 255)

Color

public Color(int r,
             int g,
             int b,
             double a)
Create a color instance specifying the three components of the RGB color separately as we as the alpha channel (will result in a color that looks like "rgb(200, 255, 10, 0.5)".

Parameters:
r - The red component of the color in the RGB color space (0 to 255)
g - The green component of the color in the RGB color space (0 to 255)
b - The blue component of the color in the RGB color space (0 to 255)
a - The alpha channel of the color (0.0 to 1.0)
Method Detail

setLinearGradient

public Color setLinearGradient(String x1,
                               String x2,
                               String y1,
                               String y2)
Sets up this color as a linear gradient from one location in space to another. Coordinates can either be provided as whole numbers, in which case they are treated as pixels. Or, they can be provided as number with a "%" character on the end, in which case they are treated in percentages. E.g.


   color.setLinearGradient("0", "0", "500", "500");
 
Or:

   color.setLinearGradient("20%", "20%", "80%", "80%");
 
Note that you can also use the setLinearGradient(int, int, int, int) version if you know you're only going to be operating in pixels, or the setLinearGradient(double, double, double, double) if you're only operating in percentages.

Parameters:
x1 - The x-coordinate of the start point of the gradient.
x2 - The x-coordinate of the end point of the gradient.
y1 - The y-coordinate of the start point of the gradient.
y2 - The y-coordinate of the end point of the gradient.
Returns:
A reference to this Color instance for convenient method chaining.

setLinearGradient

public Color setLinearGradient(int x1,
                               int x2,
                               int y1,
                               int y2)
Sets up this color as a linear gradient from one location in space to another, specifying the coordinates in pixels.

Note that you can also use the setLinearGradient(double, double, double, double) version if you know you instead want to operate in percentages, or the setLinearGradient(String, String, String, String) version if you need to operate in both percentages and pixels concurrently.

Parameters:
x1 - The x-coordinate of the start point of the gradient (in pixels).
x2 - The x-coordinate of the end point of the gradient (in pixels).
y1 - The y-coordinate of the start point of the gradient (in pixels).
y2 - The y-coordinate of the end point of the gradient (in pixels).
Returns:
A reference to this Color instance for convenient method chaining.

setLinearGradient

public Color setLinearGradient(double x1,
                               double x2,
                               double y1,
                               double y2)
Sets up this color as a linear gradient from one location in space to another, specifying the coordinates in percentages of the space the gradient will fill. Note that the percentage is specified by providing a floating point number in the range of 0.0 to 1.0, where 0.0 is equivalent to "0%" and 1.0 is equivalent to "100%".

Note that you can also use the setLinearGradient(int, int, int, int) version if you know you instead want to operate in pixels, or the setLinearGradient(String, String, String, String) version if you need to operate in both percentages and pixels concurrently.

Parameters:
x1 - The x-percentage of the start point of the gradient (0.0 to 1.0)
x2 - The x-percentage of the end point of the gradient (0.0 to 1.0)
y1 - The y-percentage of the start point of the gradient (0.0 to 1.0)
y2 - The y-percentage of the end point of the gradient (0.0 to 1.0)
Returns:
A reference to this Color instance for convenient method chaining.

addColorStop

public Color addColorStop(double offset,
                          String rgbHexColor)
Adds the specified color at some position within the gradient (to be used in conjunction with the setLinearGradient(double, double, double, double) method or another one of its overloaded variants.)

Example which sets the background color to a linear gradient from white to blue:


 chart.setBackgroundColor(new Color()
   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
   .addColorStop(0.0, "#FFFFFF")
   .addColorStop(0.0, "#0000FF")
 );
 
Note that this method is intended to be used when you simply want to set the gradient stop color to a standard RGB hex value. If you need more control use the addColorStop(double, int, int, int) or addColorStop(double, int, int, int, double) method instead.

Parameters:
offset - A floating point value between 0.0 and 1.0 that represents the position between the start and end points in a gradient.
rgbHexColor - The RGB hex color that the gradient should display at the given offset (include the "#").
Returns:
A reference to this Color instance for convenient method chaining.

addColorStop

public Color addColorStop(double offset,
                          int r,
                          int g,
                          int b)
Adds the specified color at some position within the gradient (to be used in conjunction with the setLinearGradient(double, double, double, double) method or another one of its overloaded variants.)

Example which sets the background color to a linear gradient from white to blue:


 chart.setBackgroundColor(new Color()
   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
   .addColorStop(0.0, 255, 255, 255)
   .addColorStop(0.0, 0, 0, 255)
 );
 
Note that this method is intended to be used when you simply want to set the gradient stop color to a standard RGB hex value. If you need more control use the addColorStop(double, int, int, int, double) method instead.

Parameters:
offset - A floating point value between 0.0 and 1.0 that represents the position between the start and end points in a gradient.
r - The red component of the color in the RGB color space (0 to 255)
g - The green component of the color in the RGB color space (0 to 255)
b - The blue component of the color in the RGB color space (0 to 255)
Returns:
A reference to this Color instance for convenient method chaining.

addColorStop

public Color addColorStop(double offset,
                          int r,
                          int g,
                          int b,
                          double a)
Adds the specified color at some position within the gradient allowing for the color to be specified with an alpha channel (to be used in conjunction with the setLinearGradient(double, double, double, double) method or another one of its overloaded variants.)

Example which sets the background color to a linear gradient from solid white to a 50% opaque blue:


 chart.setBackgroundColor(new Color()
   .setLinearGradient(0.0, 0.0, 1.0, 1.0)
   .addColorStop(0.0, 255, 255, 255)
   .addColorStop(0.0, 0, 0, 255, 0.5)
 );
 

Parameters:
offset - A floating point value between 0.0 and 1.0 that represents the position between the start and end points in a gradient.
r - The red component of the color in the RGB color space (0 to 255)
g - The green component of the color in the RGB color space (0 to 255)
b - The blue component of the color in the RGB color space (0 to 255)
a - The alpha channel of the color (0.0 to 1.0)
Returns:
A reference to this Color instance for convenient method chaining.

getOptionValue

public com.google.gwt.json.client.JSONValue getOptionValue()
This method will return the value of the object as a single value if it is represented as just a solid color or as a JSONObject if it represents a gradient. Note that this method is primarily intended for internal use.

Returns:
The value of this object as a single value (if appropriate), or a JSONObject if this color represents a gradient.


Copyright © 2015. All Rights Reserved.