org.apache.pivot.wtk
Class GraphicsUtilities

java.lang.Object
  extended by org.apache.pivot.wtk.GraphicsUtilities

public final class GraphicsUtilities
extends Object

Contains utility methods dealing with the Java2D API.


Nested Class Summary
static class GraphicsUtilities.PaintType
          Enumeration representing a paint type.
 
Field Summary
static String CENTER_X_KEY
           
static String CENTER_Y_KEY
           
static String COLOR_KEY
           
static String END_COLOR_KEY
           
static String END_X_KEY
           
static String END_Y_KEY
           
static String OFFSET_KEY
           
static String PAINT_TYPE_KEY
           
static String RADIUS_KEY
           
static String START_COLOR_KEY
           
static String START_X_KEY
           
static String START_Y_KEY
           
static String STOPS_KEY
           
 
Method Summary
static Color decodeColor(String value)
          Interprets a string as a color value.
static Paint decodePaint(Dictionary<String,?> dictionary)
          Interpret a dictionary as a Paint value
static Paint decodePaint(String value)
          Interpret a string as a Paint value
static void drawLine(Graphics2D graphics, int x, int y, int length, Orientation orientation)
           
static void drawLine(Graphics2D graphics, int x, int y, int length, Orientation orientation, int thickness)
           
static void drawRect(Graphics2D graphics, int x, int y, int width, int height)
          Draws a rectangle with a thickness of 1 pixel at the specified coordinates whose outer border is the specified width and height.
static void drawRect(Graphics2D graphics, int x, int y, int width, int height, int thickness)
          Draws a rectangle with the specified thickness at the specified coordinates whose outer border is the specified width and height.
static Color getColor(int rgb, float alpha)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PAINT_TYPE_KEY

public static final String PAINT_TYPE_KEY
See Also:
Constant Field Values

COLOR_KEY

public static final String COLOR_KEY
See Also:
Constant Field Values

START_X_KEY

public static final String START_X_KEY
See Also:
Constant Field Values

START_Y_KEY

public static final String START_Y_KEY
See Also:
Constant Field Values

END_X_KEY

public static final String END_X_KEY
See Also:
Constant Field Values

END_Y_KEY

public static final String END_Y_KEY
See Also:
Constant Field Values

START_COLOR_KEY

public static final String START_COLOR_KEY
See Also:
Constant Field Values

END_COLOR_KEY

public static final String END_COLOR_KEY
See Also:
Constant Field Values

CENTER_X_KEY

public static final String CENTER_X_KEY
See Also:
Constant Field Values

CENTER_Y_KEY

public static final String CENTER_Y_KEY
See Also:
Constant Field Values

RADIUS_KEY

public static final String RADIUS_KEY
See Also:
Constant Field Values

STOPS_KEY

public static final String STOPS_KEY
See Also:
Constant Field Values

OFFSET_KEY

public static final String OFFSET_KEY
See Also:
Constant Field Values
Method Detail

drawLine

public static final void drawLine(Graphics2D graphics,
                                  int x,
                                  int y,
                                  int length,
                                  Orientation orientation)

drawLine

public static final void drawLine(Graphics2D graphics,
                                  int x,
                                  int y,
                                  int length,
                                  Orientation orientation,
                                  int thickness)

drawRect

public static final void drawRect(Graphics2D graphics,
                                  int x,
                                  int y,
                                  int width,
                                  int height)
Draws a rectangle with a thickness of 1 pixel at the specified coordinates whose outer border is the specified width and height. In other words, the distance from the left edge of the leftmost pixel to the left edge of the rightmost pixel is width - 1.

This method provides more reliable pixel rounding behavior than java.awt.Graphics#drawRect when scaling is applied because this method does not stroke the shape but instead explicitly fills the desired pixels with the graphics context's paint. For this reason, and because Pivot supports scaling the display host, it is recommended that skins use this method over java.awt.Graphics#drawRect.

Parameters:
graphics - The graphics context that will be used to perform the operation.
x - The x-coordinate of the upper-left corner of the rectangle.
y - The y-coordinate of the upper-left corner of the rectangle.
width - The outer width of the rectangle.
height - The outer height of the rectangle.

drawRect

public static final void drawRect(Graphics2D graphics,
                                  int x,
                                  int y,
                                  int width,
                                  int height,
                                  int thickness)
Draws a rectangle with the specified thickness at the specified coordinates whose outer border is the specified width and height. In other words, the distance from the left edge of the leftmost pixel to the left edge of the rightmost pixel is width - thickness.

This method provides more reliable pixel rounding behavior than java.awt.Graphics#drawRect when scaling is applied because this method does not stroke the shape but instead explicitly fills the desired pixels with the graphics context's paint. For this reason, and because Pivot supports scaling the display host, it is recommended that skins use this method over java.awt.Graphics#drawRect.

Parameters:
graphics - The graphics context that will be used to perform the operation.
x - The x-coordinate of the upper-left corner of the rectangle.
y - The y-coordinate of the upper-left corner of the rectangle.
width - The outer width of the rectangle.
height - The outer height of the rectangle.
thickness - The thickness of each edge.

decodeColor

public static Color decodeColor(String value)
                         throws NumberFormatException
Interprets a string as a color value.

Parameters:
value - One of the following forms:
  • 0xdddddddd - 8 hexadecimal digits, specifying 8 bits each of red, green, and blue, followed by 8 bits of alpha.
  • #dddddd - 6 hexadecimal digits, specifying 8 bits each of red, green, and blue.
  • Any of the names of the static colors in the Java Color class.
Returns:
A Color on successful decoding
Throws:
NumberFormatException - if the value in the first two cases contains illegal hexadecimal digits.
IllegalArgumentException - if the value is not in one of the formats listed above.

getColor

public static Color getColor(int rgb,
                             float alpha)

decodePaint

public static Paint decodePaint(String value)
Interpret a string as a Paint value

Parameters:
value - Either (a) One of the color values recognized by Pivot or (b) A JSON dictionary describing a Paint value.

decodePaint

public static Paint decodePaint(Dictionary<String,?> dictionary)
Interpret a dictionary as a Paint value

Parameters:
dictionary - A dictionary containing a key "paintType" and further elements according to its value: