public final class Utilities
extends java.lang.Object
A suite of utility methods that may be useful for data source and view plugins.
These methods contain primitive mathematical and graphical operations.
For Swing-specific helpers, see GUIUtilities
.
Modifier and Type | Method and Description |
---|---|
static java.awt.Graphics2D |
antialias(java.awt.Graphics2D g2d)
Enable antialiasing and text antialiasing on the given graphics context.
|
static java.awt.Color |
gradient(double t)
Produce a color value at a certain point along a gradient.
|
static double |
lerp(double a,
double b,
double t)
Perform linear interpolation from
a to b with factor t . |
static java.awt.Color |
withAlpha(java.awt.Color color,
int alpha)
Create a version of the provided color
that has the provided value for the alpha channel value—i.e., opacity.
|
static java.awt.Color |
withAlphaFloating(java.awt.Color color,
double alpha)
Create a version of the provided color
that has the provided value opacity value.
|
public static double lerp(double a, double b, double t)
Perform linear interpolation from a
to b
with factor t
.
If t == 0
, the result will be a
;
if t == 1
, the result will be b
.
For example, lerp(1.0, 5.0, 0.75) == 4.0
.
a
- some starting pointb
- some ending pointt
- some fraction (probably between 0
and 1
, but not necessarily)t * 100
percent of the way from a
to b
public static java.awt.Color withAlphaFloating(java.awt.Color color, double alpha)
Create a version of the provided color
that has the provided value opacity value.
Setting alpha
to 0.0
will make the color completely transparent;
setting it to 1.0
will make it completely opaque.
The alpha value will be converted to an integer
and then fed to withAlpha(Color, int)
.
color
- the color whose red, green, and blue channels to usealpha
- the fractional alpha value for the color to be producedcolor
and whose alpha channel is given by alpha
java.lang.IllegalArgumentException
- if alpha < 0.0 || alpha > 1.0
public static java.awt.Color withAlpha(java.awt.Color color, int alpha)
alpha
to 0
will make the color completely transparent;
setting it to 255
(0xFF
) will make it completely opaque.color
- the color whose red, green, and blue channels to usealpha
- the alpha value for the color to be producedcolor
and whose alpha channel is given by alpha
java.lang.IllegalArgumentException
- if alpha < 0 || alpha > 0xFF
public static java.awt.Color gradient(double t)
t
- the position along the gradient:
0.0
indicates the start of the gradient,
and 1.0
indicates the endt
along a gradientpublic static java.awt.Graphics2D antialias(java.awt.Graphics2D g2d)
g2d
- the graphics context to modify