public class Label extends AbstractDrawable
Constructor and Description |
---|
Label()
Initializes a new empty
Label instance. |
Label(java.lang.String text)
Initializes a new
Label instance with the specified text. |
Modifier and Type | Method and Description |
---|---|
void |
draw(DrawingContext context)
Draws the object with the specified drawing context.
|
double |
getAlignmentX()
Returns the horizontal alignment within the bounding rectangle.
0.0 means left, 1.0 means right.
|
double |
getAlignmentY()
Returns the vertical alignment within the bounding rectangle.
0.0 means top, 1.0 means bottom.
|
protected java.awt.Shape |
getCachedOutline(boolean wordWrap)
Returns a cached instance of the outline shape for this label.
|
java.awt.Paint |
getColor()
Returns the paint used to draw the label shape.
|
java.awt.Font |
getFont()
Returns the font used to display the text of this label.
|
protected java.awt.Shape |
getOutline(boolean wordWrap)
Returns an outline shape for this label.
|
java.awt.geom.Dimension2D |
getPreferredSize()
Returns the preferred size of the
Drawable . |
double |
getRotation()
Returns the rotation of this label.
|
java.lang.String |
getText()
Returns the text of this label.
|
double |
getTextAlignment()
Returns the alignment of text with multiple lines.
0.0 means left, 1.0 means right.
|
java.awt.geom.Rectangle2D |
getTextRectangle()
Returns the bounding rectangle of the text without rotation or word
wrapping.
|
protected void |
invalidate()
Marks the text layout as invalid.
|
protected boolean |
isValid()
Returns whether the cached values in this label are valid.
|
boolean |
isWordWrapEnabled()
Returns whether words of the text should be wrapped to fit the size of the label.
|
void |
setAlignmentX(double alignmentX)
Sets the horizontal alignment within the bounding rectangle.
0.0 means left, 1.0 means right.
|
void |
setAlignmentY(double alignmentY)
Sets the vertical alignment within the bounding rectangle.
0.0 means top, 1.0 means bottom.
|
void |
setBounds(double x,
double y,
double width,
double height)
Sets the bounds to the specified coordinates, width and height.
|
void |
setColor(java.awt.Paint color)
Sets the paint used to draw the label shape.
|
void |
setFont(java.awt.Font font)
Sets the font used to display the text of this label.
|
void |
setRotation(double angle)
Sets the rotation of this label.
|
void |
setText(java.lang.String text)
Sets the displayed text to the specified value.
|
void |
setTextAlignment(double textAlignment)
Sets the alignment of text with multiple lines.
0.0 means left, 1.0 means right.
|
void |
setWordWrapEnabled(boolean wordWrapEnabled)
Sets whether words of the text should be wrapped to fit the size of the label.
|
public Label()
Label
instance.public Label(java.lang.String text)
Label
instance with the specified text.text
- Text to be displayed.public void draw(DrawingContext context)
context
- Environment used for drawingpublic java.awt.geom.Dimension2D getPreferredSize()
AbstractDrawable
Drawable
.getPreferredSize
in interface Drawable
getPreferredSize
in class AbstractDrawable
protected java.awt.Shape getOutline(boolean wordWrap)
wordWrap
- Wrap the words of the text to fit the current size.protected java.awt.Shape getCachedOutline(boolean wordWrap)
wordWrap
- Flag, whether to wrap lines to fit the current size.public java.awt.geom.Rectangle2D getTextRectangle()
public java.lang.String getText()
public void setText(java.lang.String text)
text
- Text to be displayed.protected void invalidate()
protected boolean isValid()
true
if all cached values are valid,
otherwise false
.public void setBounds(double x, double y, double width, double height)
AbstractDrawable
setBounds
in interface Drawable
setBounds
in class AbstractDrawable
x
- horizontal position of the upper-left cornery
- vertical position of the upper-left cornerwidth
- horizontal extentheight
- vertical extentpublic double getAlignmentX()
public void setAlignmentX(double alignmentX)
alignmentX
- Horizontal label alignment.public double getAlignmentY()
public void setAlignmentY(double alignmentY)
alignmentY
- Vertical label alignment.public java.awt.Font getFont()
public void setFont(java.awt.Font font)
font
- Font used for text display.public double getRotation()
public void setRotation(double angle)
angle
- Rotation in degrees.public java.awt.Paint getColor()
public void setColor(java.awt.Paint color)
color
- Paint for shape drawing.public double getTextAlignment()
public void setTextAlignment(double textAlignment)
textAlignment
- Relative text alignment.public boolean isWordWrapEnabled()
true
if the text should be wrapped, false
otherwise.public void setWordWrapEnabled(boolean wordWrapEnabled)
wordWrapEnabled
- true
if the text should be wrapped, false
otherwise.