public class Label extends StylableDrawable
Modifier and Type | Field and Description |
---|---|
static Key |
ALIGNMENT_TEXT
Key for specifying a
Number value for the alignment of text
with multiple lines. 0 means left, 1 means right. |
static Key |
ALIGNMENT_X
Key for specifying a
Number value for the horizontal alignment
within the bounding rectangle. 0 means left, 1 means right. |
static Key |
ALIGNMENT_Y
Key for specifying a
Number value for the vertical alignment
within the bounding rectangle. 0 means top, 1 means bottom. |
static Key |
COLOR
Key for specifying the
Paint instance to be used to
paint the label shape. |
static Key |
FONT
Key for specifying the
Font instance used to display
the text of this label. |
static Key |
ROTATION
Key for specifying a
Number value for the rotation of this
label in degrees. |
static Key |
WORD_WRAP
Key for specifying a
Boolean value whether the words of the
text should be wrapped to fit the size of the label. |
Constructor and Description |
---|
Label()
Initializes a new empty
Label instance. |
Label(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.
|
protected Shape |
getCachedOutline(boolean wordWrap)
Returns a cached instance of the outline shape for this label.
|
protected Shape |
getOutline(boolean wordWrap)
Returns an outline shape for this label.
|
Dimension2D |
getPreferredSize()
Returns the preferred size of the
Drawable . |
String |
getText()
Returns the text of this label.
|
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.
|
void |
setBounds(double x,
double y,
double width,
double height)
Sets the bounds to the specified coordinates, width and height.
|
void |
setText(String text)
Sets the displayed text to the specified value.
|
void |
settingChanged(SettingChangeEvent event)
Invoked if a setting has changed.
|
getSetting, removeSetting, removeSettingDefault, setSetting, setSettingDefault
public static final Key ALIGNMENT_X
Number
value for the horizontal alignment
within the bounding rectangle. 0 means left, 1 means right.public static final Key ALIGNMENT_Y
Number
value for the vertical alignment
within the bounding rectangle. 0 means top, 1 means bottom.public static final Key FONT
Font
instance used to display
the text of this label.public static final Key ROTATION
Number
value for the rotation of this
label in degrees. The rotation will be counterclockwise.public static final Key COLOR
Paint
instance to be used to
paint the label shape.public static final Key ALIGNMENT_TEXT
Number
value for the alignment of text
with multiple lines. 0 means left, 1 means right.public Label()
Label
instance.public Label(String text)
Label
instance with the specified text.text
- Text to be displayed.public void draw(DrawingContext context)
context
- Environment used for drawingpublic Dimension2D getPreferredSize()
AbstractDrawable
Drawable
.getPreferredSize
in interface Drawable
getPreferredSize
in class AbstractDrawable
protected Shape getOutline(boolean wordWrap)
wordWrap
- Wrap the words of the text to fit the current size.protected Shape getCachedOutline(boolean wordWrap)
wordWrap
- Flag, whether to wrap lines to fit the current size.public Rectangle2D getTextRectangle()
public String getText()
public void setText(String text)
text
- Text to be displayed.protected void invalidate()
protected boolean isValid()
true
if all cached values are valid,
otherwise false
.public void settingChanged(SettingChangeEvent event)
settingChanged
in interface SettingsListener
settingChanged
in class StylableDrawable
event
- Event containing information about the changed setting.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 extentCopyright © 2009-2013. All Rights Reserved.