|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.samskivert.swing.Label
public class Label
The label is a multipurpose text display mechanism that can display small amounts of text wrapped to fit into a variety of constrained spaces. It can be requested to conform to a particular width or height and will expand into the other dimension in order to accomodate the text at hand. It is not a component, but is intended for use by components and other more heavyweight entities.
| Field Summary | |
|---|---|
protected int |
_align
The text alignment. |
protected Color |
_alternateColor
The color in which to render the text outline or shadow if we're rendering in outline or shadow mode. |
protected Dimension |
_constraints
Our size constraints in either the x or y direction. |
protected Font |
_font
The font we use when laying out and rendering out text, or null if we're to use the default font. |
protected TextLayout[] |
_layouts
Formatted text layout instances that contain each line of text. |
protected Rectangle2D[] |
_lbounds
Formatted text layout instances that contain each line of text. |
protected float[] |
_leaders
Some fonts (God bless 'em) extend to the left of the position at which you request that they be rendered. |
protected boolean |
_mainDraw
Will be true only when we're drawing a textlayout for the "main" portion of the label. |
protected String |
_rawText
The raw text, with color tags, or null if there are no color tags. |
protected Dimension |
_size
Our calculated size. |
protected int |
_style
The text style. |
protected String |
_text
The text of the label. |
protected Color |
_textColor
The color in which to render the text or null if the text should be rendered with the graphics context color. |
static Pattern |
COLOR_PATTERN
The pattern used to mark the start/end of color blocks. |
protected static double |
GOLDEN_RATIO
An approximation of the golden ratio. |
| Fields inherited from interface javax.swing.SwingConstants |
|---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Fields inherited from interface com.samskivert.swing.LabelStyleConstants |
|---|
BOLD, NORMAL, OUTLINE, SHADOW, UNDERLINE |
| Constructor Summary | |
|---|---|
Label()
Constructs a blank label. |
|
Label(String text)
Constructs a label with the supplied text. |
|
Label(String text,
Color textColor,
Font font)
Constructs a label with the supplied text and configuration parameters. |
|
Label(String text,
int style,
Color textColor,
Color altColor,
Font font)
Constructs a label with the supplied text and configuration parameters. |
|
| Method Summary | |
|---|---|
protected void |
addAttributes(AttributedString text)
Add any attributes to the text. |
void |
clearTargetDimens()
Clears out previously configured target dimensions for this label. |
protected ArrayList<Tuple<TextLayout,Rectangle2D>> |
computeLines(LineBreakMeasurer measurer,
int targetWidth,
Dimension size,
boolean keepWordsWhole)
Computes the lines of text for this label given the specified target width. |
static String |
escapeColors(String txt)
Escape any special tags so that they won't be interpreted by the label. |
static String |
filterColors(String txt)
Filter out any color tags from the specified text. |
int |
getAlignment()
Returns the alignment of the text within the label. |
Color |
getAlternateColor()
Returns the alternate color used to render the text's outline or shadow, if any. |
protected Rectangle2D |
getBounds(TextLayout layout)
Gets the bounds of the supplied text layout in a way that works around the various befuckeries that currently happen on the Mac. |
protected float |
getHeight(TextLayout layout)
Computes the height based on the leading, ascent and descent rather than what the layout reports via getBounds() which
rarely seems to have any bearing on reality. |
int |
getLineCount()
Returns the number of lines used by this label. |
Dimension |
getSize()
Returns our computed dimensions. |
String |
getText()
Returns the text displayed by this label. |
Color |
getTextColor()
Returns the color used to render the text. |
protected double |
getWidth(Rectangle2D laybounds)
Computes the total width of a TextLayout given bounds
returned from a call to TextLayout.getBounds(). |
protected void |
invalidate(String where)
Called when the label is changed in such a way that it must be relaid out before again being rendered. |
boolean |
isLaidOut()
Returns true if this label has been laid out, false if not. |
void |
layout(Component comp)
Calls layout(Graphics2D) with the graphics context for the
given component. |
void |
layout(Graphics2D gfx)
Requests that this label lay out its text, obtaining information from the supplied graphics context to do so. |
void |
render(Graphics2D gfx,
float x,
float y)
Renders the layout at the specified position in the supplied graphics context. |
void |
setAlignment(int align)
Sets the alignment of the text within the label to either SwingConstants.LEFT, SwingConstants.RIGHT, or SwingConstants.CENTER. |
void |
setAlternateColor(Color color)
Instructs the label to render the text with the specified alternate color when rendering. |
void |
setFont(Font font)
Sets the font to be used by this label. |
void |
setGoldenLayout()
Instructs the label to attempt to achieve a balance between width and height that approximates the golden ratio (width ~1.618 times height). |
void |
setStyle(int style)
Sets the style of the text within the label to one of the styles defined in LabelStyleConstants. |
void |
setTargetHeight(int targetHeight)
Sets the target height for this label. |
void |
setTargetWidth(int targetWidth)
Sets the target width for this label. |
boolean |
setText(String text)
Sets the text to be displayed by this label. |
void |
setTextColor(Color color)
Sets the color used to render the text. |
protected AttributedCharacterIterator |
textIterator(Graphics2D gfx)
Constructs an attributed character iterator with our text and the appropriate font. |
static String |
unescapeColors(String txt)
Un-escape special tags so that they again look correct. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Pattern COLOR_PATTERN
protected String _text
protected String _rawText
protected int _style
protected int _align
protected Dimension _constraints
protected Dimension _size
protected float[] _leaders
protected Font _font
protected TextLayout[] _layouts
protected Rectangle2D[] _lbounds
protected Color _alternateColor
protected Color _textColor
protected boolean _mainDraw
protected static final double GOLDEN_RATIO
| Constructor Detail |
|---|
public Label()
public Label(String text)
public Label(String text,
Color textColor,
Font font)
public Label(String text,
int style,
Color textColor,
Color altColor,
Font font)
| Method Detail |
|---|
public static String filterColors(String txt)
public static String escapeColors(String txt)
public static String unescapeColors(String txt)
public String getText()
public boolean setText(String text)
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public void setFont(Font font)
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public Color getTextColor()
public void setTextColor(Color color)
null will render the label in the graphics context
color (which is the default).
public Color getAlternateColor()
public void setAlternateColor(Color color)
public int getAlignment()
public void setAlignment(int align)
SwingConstants.LEFT, SwingConstants.RIGHT, or SwingConstants.CENTER. The default alignment is selected to be
appropriate for the locale of the text being rendered.
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public void setStyle(int style)
LabelStyleConstants. Some styles can be combined
together into a mask, ie. BOLD|UNDERLINE.
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public void setGoldenLayout()
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public void setTargetWidth(int targetWidth)
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public void setTargetHeight(int targetHeight)
This should be followed by a call to layout(java.awt.Component) before a
call is made to render(java.awt.Graphics2D, float, float) as this method invalidates the
layout information.
public void clearTargetDimens()
public int getLineCount()
public Dimension getSize()
layout(java.awt.Component).
public boolean isLaidOut()
public void layout(Component comp)
layout(Graphics2D) with the graphics context for the
given component.
public void layout(Graphics2D gfx)
protected ArrayList<Tuple<TextLayout,Rectangle2D>> computeLines(LineBreakMeasurer measurer,
int targetWidth,
Dimension size,
boolean keepWordsWhole)
size parameter.
ArrayList or null if keepWordsWhole
was true and the lines could not be layed out in the target width.
public void render(Graphics2D gfx,
float x,
float y)
protected AttributedCharacterIterator textIterator(Graphics2D gfx)
protected void addAttributes(AttributedString text)
protected double getWidth(Rectangle2D laybounds)
TextLayout given bounds
returned from a call to TextLayout.getBounds().
protected Rectangle2D getBounds(TextLayout layout)
protected float getHeight(TextLayout layout)
getBounds() which
rarely seems to have any bearing on reality.
protected void invalidate(String where)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||