Class PaintUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final GradientPaint
static final Paint
static final GradientPaint
static final GradientPaint
static final GradientPaint
static final GradientPaint
static final GradientPaint
static final GradientPaint
static final Paint
static final GradientPaint
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Point2D[]
adjustPoints
(Point2D[] pts, int width, int height) static Color
Blends two colors to create a new color.private static double
static Color
Computes an appropriate foreground color (either white or black) for the given background color.static Paint
static Paint
getCheckerPaint
(Paint c1, Paint c2, int size) Creates a newPaint
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
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 aString
that represents the supplied color as a hex-value RGB triplet, including the "#".
-
Field Details
-
BLUE_EXPERIENCE
-
MAC_OSX_SELECTED
-
MAC_OSX
-
AERITH
-
GRAY
-
RED_XP
-
NIGHT_GRAY
-
NIGHT_GRAY_LIGHT
-
ORANGE_DELIGHT
-
BLACK_STAR
-
-
Constructor Details
-
PaintUtils
private PaintUtils()
-
-
Method Details
-
resizeGradient
Resizes a gradient to fill the width and height available. If the gradient is left to right it will be resized to fill the entire width. If the gradient is top to bottom it will be resized to fill the entire height. If the gradient is on an angle it will be resized to go from one corner to the other of the rectangle formed by (0,0 -> width,height). This method can resize java.awt.GradientPaint, java.awt.LinearGradientPaint, and the LinearGradientPaint implementation from Apache's Batik project. Note, this method does not require the MultipleGradientPaint.jar from Apache to compile or to run. MultipleGradientPaint.jar *is* required if you want to resize the LinearGradientPaint from that jar. Any paint passed into this method which is not a kind of gradient paint (like a Color or TexturePaint) will be returned unmodified. It will not throw an exception. If the gradient cannot be resized due to other errors the original paint will be returned unmodified. It will not throw an exception. -
resizeLinearGradient
-
invokeMethod
private static Object invokeMethod(Object p, String methodName) throws NoSuchMethodException, InvocationTargetException, IllegalArgumentException, SecurityException, IllegalAccessException -
adjustPoints
-
isNear
private static boolean isNear(double angle, double target, double error) -
normalize
private static float normalize(double original, float target) -
calcAngle
-
getCheckerPaint
- Returns:
- a the checkered paint
-
getCheckerPaint
Creates a newPaint
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.
- Parameters:
c1
- the first colorc2
- the second colorsize
- the size of the paint- Returns:
- a new
Paint
checkering the supplied colors
-
toHexString
Creates aString
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.- Parameters:
color
- the color to convert- Returns:
- the hex
String
-
removeAlpha
Returns a new color equal to the old one, except that there is no alpha (transparency) channel.This method is a convenience and has the same effect as
setAlpha(color, 255)
.- Parameters:
color
- the color to remove the alpha (transparency) from- Returns:
- a new non-transparent
Color
- Throws:
NullPointerException
- ifcolor
isnull
-
setAlpha
Returns a new color equal to the old one, except alpha (transparency) channel is set to the new value.- Parameters:
color
- the color to modifyalpha
- the new alpha (transparency) level. Must be an int between 0 and 255- Returns:
- a new alpha-applied
Color
- Throws:
IllegalArgumentException
- ifalpha
is not between 0 and 255 inclusiveNullPointerException
- ifcolor
isnull
-
setSaturation
Returns a new color equal to the old one, except the saturation is set to the new value. The new color will have the same alpha (transparency) as the original color.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.
- Parameters:
color
- the color to modifysaturation
- the saturation to use in the new color- Returns:
- a new saturation-applied
Color
- Throws:
IllegalArgumentException
- ifsaturation
is not between 0 and 1 inclusiveNullPointerException
- ifcolor
isnull
-
setBrightness
Returns a new color equal to the old one, except the brightness is set to the new value. The new color will have the same alpha (transparency) as the original color.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.
- Parameters:
color
- the color to modifybrightness
- the brightness to use in the new color- Returns:
- a new brightness-applied
Color
- Throws:
IllegalArgumentException
- ifbrightness
is not between 0 and 1 inclusiveNullPointerException
- ifcolor
isnull
-
blend
Blends two colors to create a new color. Theorigin
color is the base for the new color and regardless of its alpha component, it is treated as fully opaque (alpha 255).- Parameters:
origin
- the base of the new colorover
- the alpha-enabled color to add to theorigin
color- Returns:
- a new color comprised of the
origin
andover
colors
-
interpolate
Interpolates a color.- Parameters:
b
- the first colora
- the second colort
- the amount to interpolate- Returns:
- a new color
-
computeForeground
Computes an appropriate foreground color (either white or black) for the given background color.- Parameters:
bg
- the background color- Returns:
Color.WHITE
orColor.BLACK
- Throws:
NullPointerException
- ifbg
isnull
-