de.erichseifert.gral.graphics
Class Label
- java.lang.Object
-
- de.erichseifert.gral.graphics.AbstractDrawable
-
- de.erichseifert.gral.graphics.Label
-
- All Implemented Interfaces:
- Drawable, java.io.Serializable
public class Label extends AbstractDrawable
Class that draws a label to a specific location. A Label is able to manage its settings and to set and get the displayed text, as well as calculating its bounds.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description Label()Initializes a new emptyLabelinstance.Label(java.lang.String text)Initializes a newLabelinstance with the specified text.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voiddraw(DrawingContext context)Draws the object with the specified drawing context.booleanequals(java.lang.Object obj)doublegetAlignmentX()Returns the horizontal alignment within the bounding rectangle.doublegetAlignmentY()Returns the vertical alignment within the bounding rectangle.java.awt.PaintgetBackground()Returns the background color.java.awt.PaintgetColor()Returns the paint used to draw the label shape.java.awt.FontgetFont()Returns the font used to display the text of this label.java.awt.geom.Dimension2DgetPreferredSize()Returns the preferred size of theDrawable.doublegetRotation()Returns the rotation of this label.java.lang.StringgetText()Returns the text of this label.doublegetTextAlignment()Returns the alignment of text with multiple lines.java.awt.geom.Rectangle2DgetTextRectangle()Returns the bounding rectangle of the text without rotation or word wrapping.booleanisWordWrapEnabled()Returns whether words of the text should be wrapped to fit the size of the label.voidsetAlignmentX(double alignmentX)Sets the horizontal alignment within the bounding rectangle.voidsetAlignmentY(double alignmentY)Sets the vertical alignment within the bounding rectangle.voidsetBackground(java.awt.Paint background)Sets the background color to the specified value.voidsetBounds(double x, double y, double width, double height)Sets the bounds to the specified coordinates, width and height.voidsetColor(java.awt.Paint color)Sets the paint used to draw the label shape.voidsetFont(java.awt.Font font)Sets the font used to display the text of this label.voidsetRotation(double angle)Sets the rotation of this label.voidsetText(java.lang.String text)Sets the displayed text to the specified value.voidsetTextAlignment(double textAlignment)Sets the alignment of text with multiple lines.voidsetWordWrapEnabled(boolean wordWrapEnabled)Sets whether words of the text should be wrapped to fit the size of the label.-
Methods inherited from class de.erichseifert.gral.graphics.AbstractDrawable
getBounds, getHeight, getWidth, getX, getY, setBounds, setPosition
-
-
-
-
Constructor Detail
-
Label
public Label()
Initializes a new emptyLabelinstance.
-
Label
public Label(java.lang.String text)
Initializes a newLabelinstance with the specified text.- Parameters:
text- Text to be displayed.
-
-
Method Detail
-
draw
public void draw(DrawingContext context)
Draws the object with the specified drawing context.- Parameters:
context- Environment used for drawing
-
getPreferredSize
public java.awt.geom.Dimension2D getPreferredSize()
Description copied from class:AbstractDrawableReturns the preferred size of theDrawable.- Specified by:
getPreferredSizein interfaceDrawable- Overrides:
getPreferredSizein classAbstractDrawable- Returns:
- horizontal and vertical extent that wants to be reached
-
getTextRectangle
public java.awt.geom.Rectangle2D getTextRectangle()
Returns the bounding rectangle of the text without rotation or word wrapping.- Returns:
- Bounding rectangle.
-
getText
public java.lang.String getText()
Returns the text of this label.- Returns:
- Text.
-
setText
public void setText(java.lang.String text)
Sets the displayed text to the specified value.- Parameters:
text- Text to be displayed.
-
setBounds
public void setBounds(double x, double y, double width, double height)Description copied from class:AbstractDrawableSets the bounds to the specified coordinates, width and height. This method should be used when overriding functionality.- Specified by:
setBoundsin interfaceDrawable- Overrides:
setBoundsin classAbstractDrawable- Parameters:
x- horizontal position of the upper-left cornery- vertical position of the upper-left cornerwidth- horizontal extentheight- vertical extent
-
getAlignmentX
public double getAlignmentX()
Returns the horizontal alignment within the bounding rectangle. 0.0 means left, 1.0 means right.- Returns:
- Horizontal label alignment.
-
setAlignmentX
public void setAlignmentX(double alignmentX)
Sets the horizontal alignment within the bounding rectangle. 0.0 means left, 1.0 means right.- Parameters:
alignmentX- Horizontal label alignment.
-
getAlignmentY
public double getAlignmentY()
Returns the vertical alignment within the bounding rectangle. 0.0 means top, 1.0 means bottom.- Returns:
- Vertical label alignment.
-
setAlignmentY
public void setAlignmentY(double alignmentY)
Sets the vertical alignment within the bounding rectangle. 0.0 means top, 1.0 means bottom.- Parameters:
alignmentY- Vertical label alignment.
-
getFont
public java.awt.Font getFont()
Returns the font used to display the text of this label.- Returns:
- Font used for text display.
-
setFont
public void setFont(java.awt.Font font)
Sets the font used to display the text of this label.- Parameters:
font- Font used for text display.
-
getRotation
public double getRotation()
Returns the rotation of this label. The rotation will be counterclockwise.- Returns:
- Rotation in degrees.
-
setRotation
public void setRotation(double angle)
Sets the rotation of this label. The rotation will be counterclockwise.- Parameters:
angle- Rotation in degrees.
-
getColor
public java.awt.Paint getColor()
Returns the paint used to draw the label shape.- Returns:
- Paint for shape drawing.
-
setColor
public void setColor(java.awt.Paint color)
Sets the paint used to draw the label shape.- Parameters:
color- Paint for shape drawing.
-
getTextAlignment
public double getTextAlignment()
Returns the alignment of text with multiple lines. 0.0 means left, 1.0 means right.- Returns:
- Relative text alignment.
-
setTextAlignment
public void setTextAlignment(double textAlignment)
Sets the alignment of text with multiple lines. 0.0 means left, 1.0 means right.- Parameters:
textAlignment- Relative text alignment.
-
isWordWrapEnabled
public boolean isWordWrapEnabled()
Returns whether words of the text should be wrapped to fit the size of the label.- Returns:
trueif the text should be wrapped,falseotherwise.
-
setWordWrapEnabled
public void setWordWrapEnabled(boolean wordWrapEnabled)
Sets whether words of the text should be wrapped to fit the size of the label.- Parameters:
wordWrapEnabled-trueif the text should be wrapped,falseotherwise.
-
getBackground
public java.awt.Paint getBackground()
Returns the background color.- Returns:
- Background color or
null, if no background is defined.
-
setBackground
public void setBackground(java.awt.Paint background)
Sets the background color to the specified value.- Parameters:
background- Background color.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-
DataMelt 3.0 © DataMelt by jWork.ORG