public class PaintUtils extends Object
Modifier and Type | Field and Description |
---|---|
static GradientPaint |
AERITH |
static Paint |
BLACK_STAR |
static GradientPaint |
BLUE_EXPERIENCE |
static GradientPaint |
GRAY |
static GradientPaint |
MAC_OSX |
static GradientPaint |
MAC_OSX_SELECTED |
static GradientPaint |
NIGHT_GRAY |
static GradientPaint |
NIGHT_GRAY_LIGHT |
static Paint |
ORANGE_DELIGHT |
static GradientPaint |
RED_XP |
Modifier | Constructor and Description |
---|---|
private |
PaintUtils() |
Modifier and Type | Method and Description |
---|---|
private static Point2D[] |
adjustPoints(Point2D[] pts,
int width,
int height) |
static Color |
blend(Color origin,
Color over)
Blends two colors to create a new color.
|
private static double |
calcAngle(Point2D p1,
Point2D p2) |
static Color |
computeForeground(Color bg)
Computes an appropriate foreground color (either white or black) for the
given background color.
|
static Paint |
getCheckerPaint()
|
static Paint |
getCheckerPaint(Paint c1,
Paint c2,
int size)
Creates a new
Paint that is a checkered effect using the specified colors. |
static Color |
interpolate(Color b,
Color a,
float t)
Interpolates a color.
|
private static Object |
invokeMethod(Object p,
String methodName) |
private static boolean |
isNear(double angle,
double target,
double error) |
private static float |
normalize(double original,
float target) |
static Color |
removeAlpha(Color color)
Returns a new color equal to the old one, except that there is no alpha
(transparency) channel.
|
static Paint |
resizeGradient(Paint p,
int width,
int height)
Resizes a gradient to fill the width and height available.
|
private static Paint |
resizeLinearGradient(Paint p,
int width,
int height) |
static Color |
setAlpha(Color color,
int alpha)
Returns a new color equal to the old one, except alpha (transparency)
channel is set to the new value.
|
static Color |
setBrightness(Color color,
float brightness)
Returns a new color equal to the old one, except the brightness is set to
the new value.
|
static Color |
setSaturation(Color color,
float saturation)
Returns a new color equal to the old one, except the saturation is set to
the new value.
|
static String |
toHexString(Color color)
Creates a
String that represents the supplied color as a
hex-value RGB triplet, including the "#". |
public static final GradientPaint BLUE_EXPERIENCE
public static final GradientPaint MAC_OSX_SELECTED
public static final GradientPaint MAC_OSX
public static final GradientPaint AERITH
public static final GradientPaint GRAY
public static final GradientPaint RED_XP
public static final GradientPaint NIGHT_GRAY
public static final GradientPaint NIGHT_GRAY_LIGHT
public static final Paint ORANGE_DELIGHT
public static final Paint BLACK_STAR
private PaintUtils()
public static Paint resizeGradient(Paint p, int width, int height)
private static Paint resizeLinearGradient(Paint p, int width, int height)
private static Object invokeMethod(Object p, String methodName) throws NoSuchMethodException, InvocationTargetException, IllegalArgumentException, SecurityException, IllegalAccessException
private static Point2D[] adjustPoints(Point2D[] pts, int width, int height)
private static boolean isNear(double angle, double target, double error)
private static float normalize(double original, float target)
public static Paint getCheckerPaint()
public static Paint getCheckerPaint(Paint c1, Paint c2, int size)
Paint
that is a checkered effect using the specified colors.
While this method supports transparent colors, this implementation performs painting operations using the second color after it performs operations using the first color. This means that to create a checkered paint with a fully-transparent color, you MUST specify that color first.
c1
- the first colorc2
- the second colorsize
- the size of the paintPaint
checkering the supplied colorspublic static String toHexString(Color color)
String
that represents the supplied color as a
hex-value RGB triplet, including the "#". The return value is suitable
for use in HTML. The alpha (transparency) channel is neither include nor
used in producing the string.color
- the color to convertString
public static Color removeAlpha(Color color)
This method is a convenience and has the same effect as setAlpha(color, 255)
.
color
- the color to remove the alpha (transparency) fromColor
NullPointerException
- if color
is null
public static Color setAlpha(Color color, int alpha)
color
- the color to modifyalpha
- the new alpha (transparency) level. Must be an int between 0
and 255Color
IllegalArgumentException
- if alpha
is not between 0 and 255 inclusiveNullPointerException
- if color
is null
public static Color setSaturation(Color color, float saturation)
The color is modified using HSB calculations. The saturation must be a float between 0 and 1. If 0 the resulting color will be gray. If 1 the resulting color will be the most saturated possible form of the passed in color.
color
- the color to modifysaturation
- the saturation to use in the new colorColor
IllegalArgumentException
- if saturation
is not between 0 and 1 inclusiveNullPointerException
- if color
is null
public static Color setBrightness(Color color, float brightness)
The color is modified using HSB calculations. The brightness must be a float between 0 and 1. If 0 the resulting color will be black. If 1 the resulting color will be the brightest possible form of the passed in color.
color
- the color to modifybrightness
- the brightness to use in the new colorColor
IllegalArgumentException
- if brightness
is not between 0 and 1 inclusiveNullPointerException
- if color
is null
public static Color blend(Color origin, Color over)
origin
color is the
base for the new color and regardless of its alpha component, it is
treated as fully opaque (alpha 255).origin
- the base of the new colorover
- the alpha-enabled color to add to the origin
colororigin
and over
colorspublic static Color interpolate(Color b, Color a, float t)
b
- the first colora
- the second colort
- the amount to interpolatepublic static Color computeForeground(Color bg)
bg
- the background colorColor.WHITE
or Color.BLACK
NullPointerException
- if bg
is null
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses