public final class LabelPainter extends java.lang.Object implements ObjectPainter<java.lang.String>
ObjectPainter for strings that serve as
labels, to be painted with a certain font and layout| Modifier and Type | Class and Description |
|---|---|
static class |
LabelPainter.LabelPaintState
A class describing the state of a label that is about to be
painted.
|
| Constructor and Description |
|---|
LabelPainter()
Creates a new label painter.
|
| Modifier and Type | Method and Description |
|---|---|
java.awt.Shape |
computeLabelBounds(java.awt.geom.AffineTransform worldToScreen,
java.lang.String label)
Compute the bounds of the label when it is painted with this painter
|
double |
getAngle()
Returns the angle (in radians) about that the label will be rotated
around its
anchor point. |
java.awt.Font |
getFont()
Returns the font that is used for the label.
|
java.awt.geom.Point2D |
getLabelAnchor()
Returns a new point that describes the current anchor position of
the label.
|
java.awt.geom.Point2D |
getLabelLocation()
Returns a new point that describes the location of the label.
|
java.awt.Paint |
getPaint()
Returns the paint that is used for the label.
|
boolean |
isTransformingLabels()
Returns whether this painter is transforming the labels.
|
void |
paint(java.awt.Graphics2D g,
java.awt.geom.AffineTransform worldToScreen,
double w,
double h,
java.lang.String label)
Perform the painting operations for the given object on the given
Graphics.
|
void |
setAngle(double angleRad)
Set the angle (in radians) about that the label will be rotated
around its
anchor point. |
void |
setFont(java.awt.Font font)
Set the font that should be used for the label.
|
void |
setLabelAnchor(double x,
double y)
Set the anchor position of the label.
|
void |
setLabelLocation(double x,
double y)
Set the absolute location of the label.
|
void |
setLabelPaintingCondition(java.util.function.Predicate<LabelPainter.LabelPaintState> labelPaintingCondition)
Set the condition indicating whether a certain label should be
painted.
|
void |
setPaint(java.awt.Paint paint)
Set the paint that should be used for the label.
|
void |
setTransformingLabels(boolean transformingLabels)
Set whether this painter is transforming the labels using the
worldToScreen transform that is passed to its
paint
method. |
public LabelPainter()
label anchor will be
at (0.5, 0.5), causing the label to be centered at the desired
location
label location will
be at (0.0, 0.0)
angle will be 0.0.
transforming the labels
font, paint
and label painting
condition will be null, causing the label to always
be painted, with the default font and paint of the graphics context
public void setFont(java.awt.Font font)
null, then the font of the graphics context will
be used.font - The fontpublic java.awt.Font getFont()
null if no font was set explicitly.public void setPaint(java.awt.Paint paint)
null, then the current paint of the graphics context
will be used.paint - The paintpublic java.awt.Paint getPaint()
null if no paint was set explicitly.public void setLabelAnchor(double x,
double y)
label location. For example,
in order to place the center of the label at a certain location,
an anchor point of (0.5, 0.5) may be set.rotation angle is set.x - The x-coordinate of the anchor positiony - The y-coordinate of the anchor positionpublic java.awt.geom.Point2D getLabelAnchor()
setLabelAnchor(double, double).public void setLabelLocation(double x,
double y)
x - The x coordinate of the locationy - The y-coordinate of the locationpublic java.awt.geom.Point2D getLabelLocation()
setLabelLocation(double, double).public void setAngle(double angleRad)
anchor point.angleRad - The rotation angle, in radianspublic double getAngle()
anchor point.public void setTransformingLabels(boolean transformingLabels)
worldToScreen transform that is passed to its
paint
method.true, then the label strings will
be transformed with the worldToScreen transform, like
all other painted elements: When the view is scaled, then the
text will be scaled. When the view is rotated, then the labels
will be rotated.false, then the labels will be
fixed. This means that they will always be painted with the
size that is defined via the font, and
they will always be oriented horizontally (unless they are
rotated by this painter itself, via the angle).transformingLabels - Whether this painter is transforming the labelspublic boolean isTransformingLabels()
setTransformingLabels(boolean).public void setLabelPaintingCondition(java.util.function.Predicate<LabelPainter.LabelPaintState> labelPaintingCondition)
LabelPainter.LabelPaintState
of each label that is about to be painted. It has to be assumed
that the same LabelPainter.LabelPaintState instance will be used
for all these calls. So the predicate may not store and / or
modify the LabelPainter.LabelPaintState.null, then the
labels will always be painted.labelPaintingCondition - The label painting conditionpublic void paint(java.awt.Graphics2D g,
java.awt.geom.AffineTransform worldToScreen,
double w,
double h,
java.lang.String label)
ObjectPainterPainter.paint(Graphics2D, AffineTransform, double, double)
for more information about how the Graphics object is handled among
painters.paint in interface ObjectPainter<java.lang.String>g - The Graphics used for paintingworldToScreen - The world-to-screen transform. This transform
encapsulates the translation, rotation and scaling of the viewer
to which this painter belongs.w - The width of the area, in screen coordinates, in which
this painter operates. This is the screen size of the viewer to
which this painter belongs.h - The height of the area, in screen coordinates, in which
this painter operates. This is the screen size of the viewer to
which this painter belongs.label - The object to paint. One has to assume that
this object may be null, in which case the
painting operation will usually be skipped.public java.awt.Shape computeLabelBounds(java.awt.geom.AffineTransform worldToScreen,
java.lang.String label)
worldToScreen - The world-to-screen transformlabel - The labelCopyright © 2019. All Rights Reserved.