|
Runtime | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.draw2d.Figure
org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel
public class WrappingLabel
An extended label that has the following extra features:
1. Allows selection, focus feedback, underlined and striked-through text.
2. Enhanced layout functionality for placing icon and text.
3. Text will be word-wrapped to fit the text in the width available.
4. Text will be truncated with an ellipsis if the entire text does not fit in
the space available.
EXPLANATION OF LAYOUTS
This WrappingLabel contains functionality to display an icon alongside text.
The following will describe how the layout of the icon and text are done.
Using setTextPlacement(int)
:
The position of the text relative to the icon depends on
setTextPlacement(int)
. If the text placement is set to
PositionConstants.EAST
, then the text would be placed on the right
of the icon. Similarly, if text placement is set to
PositionConstants.WEST
, the text will be placed on the left of the
icon; PositionConstants.NORTH
would put the text above the icon; and
PositionConstants.SOUTH
would place the text below the icon.
Using setTextAlignment(int)
and setIconAlignment(int)
:
Use setTextAlignment(int)
and setIconAlignment(int)
to
align the text and icons relative to each other for more dynamic
control. If the text placement is on the east or west of the icon(s) (i.e.
the text on the right or left of the icon respectively), then only
PositionConstants.TOP
, PositionConstants.CENTER
, and
PositionConstants.BOTTOM
can be used when calling
setTextAlignment(int)
and setIconAlignment(int)
. In this
case, setting the text alignment to PositionConstants.TOP
will make
sure that the top of the text is aligned horizontally with the top of the
icon if the height of the icon is greater than the height of the
text. Similarly, setting the text alignment to
PositionConstants.CENTER
will make sure that the top of the text is
aligned horizontally with the vertical center of the size of icon if
the height of the icon is greater than the height of the text. Also, setting
the text alignment to PositionConstants.BOTTOM
will make sure that
the bottom of the text is aligned horizontally with the bottom of the icon
if the height of the icon is greater than the height of the text.
The other scenario is when the text placement is on the south or north of the
icon (i.e. the text is below or above the icon respectively). If this is
true, only PositionConstants.LEFT
, PositionConstants.CENTER
,
and PositionConstants.RIGHT
can be used when calling
setTextAlignment(int)
and setIconAlignment(int)
. In this
case, setting the text alignment to PositionConstants.LEFT
will make
sure that the left of the text is aligned vertically with the left of the
icon if the width of the icon is greater than the width of the text.
Similarly, setting the text alignment to PositionConstants.CENTER
will make sure that the left of the text is aligned vertically with the
horizontal center of the icon if the width of the icon is greater
than the width of the text. Also, setting the text alignment to
PositionConstants.RIGHT
will make sure that the right of the text is
aligned vertically with the right of the icon if the width of the
icon is greater than the width of the text.
setIconAlignment(int)
works identically as
setTextAlignment(int)
, except the roles of text and icon are
switched in the above descriptions.
Using setAlignment(int)
:
The entire label, text and icon, can be moved into different positions with
the label figure, if the figure is bigger than the icon and text. The
alignment of the label places the text and icon (no matter how they are
arranged relatively to each other) in the top-left, top, top-right, left,
center, right, bottom-left, bottom, or bottom-right of the bounds of this
WrappingLabel
figure.
Using #setTextHorizontalAlignment(int)
:
Use setTextJustification(int)
with PositionConstants.LEFT
,
PositionConstants.CENTER
, or PositionConstants.RIGHT
to
justify the text when wordwrap is turned on. The effect will be noticed in
multi-lined text only.
WARNING: User-nested figures are not expected within this figure.
Some code taken from the original WrapLabel
in GMF by
melaasar.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class org.eclipse.draw2d.Figure |
---|
Figure.FigureIterator, Figure.IdentitySearch |
Nested classes/interfaces inherited from interface org.eclipse.draw2d.IFigure |
---|
IFigure.NoInsets |
Field Summary | |
---|---|
protected static int |
MAX_FLAG
The largest flag defined in this class. |
protected Dimension |
preferredTextSize
The cached preferred text size that can be used after getPreferredSize(int, int) is called. |
Fields inherited from class org.eclipse.draw2d.Figure |
---|
bgColor, border, bounds, fgColor, flags, font, maxSize, minSize, NO_MANAGER, prefSize, toolTip |
Fields inherited from interface org.eclipse.draw2d.PositionConstants |
---|
ALWAYS_LEFT, ALWAYS_RIGHT, BOTTOM, CENTER, EAST, EAST_WEST, HORIZONTAL, LEFT, LEFT_CENTER_RIGHT, MIDDLE, NONE, NORTH, NORTH_EAST, NORTH_SOUTH, NORTH_WEST, NSEW, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TOP_MIDDLE_BOTTOM, VERTICAL, WEST |
Fields inherited from interface org.eclipse.draw2d.IFigure |
---|
MAX_DIMENSION, MIN_DIMENSION, NO_INSETS |
Constructor Summary | |
---|---|
WrappingLabel()
Construct an empty wrapping label. |
|
WrappingLabel(Image image)
Construct a wrapping label with thepassed Image as its icon. |
|
WrappingLabel(java.lang.String text)
Construct a wrapping label with the passed String as its text. |
|
WrappingLabel(java.lang.String text,
Image image)
Construct a wrapping label with passed the String as its text and the passed Image as its icon. |
Method Summary | |
---|---|
protected Dimension |
calculateLabelSize(Dimension txtSize)
Calculates the size of the Label using the passed Dimension as the size of the Label's text. |
int |
getAlignment()
Returns the alignment of the label (icon and text) within the figure. |
Image |
getIcon()
Returns the label's icon. |
Image |
getIcon(int index)
Gets the label's icon at the given index |
int |
getIconAlignment()
Returns the alignment of the label's icon relative to the label's text bounds. |
protected Point |
getIconLocation()
Returns the location of the Label's icon relative to the Label. |
protected Dimension |
getIconSize(int index)
getIconSize |
int |
getIconTextGap()
Returns the gap in pixels between the Label's icon and its text. |
Dimension |
getMinimumSize(int w,
int h)
|
protected int |
getNumberofIcons()
getIconNumber |
Dimension |
getPreferredSize(int wHint,
int hHint)
|
java.lang.String |
getText()
Returns the text of the label. |
int |
getTextAlignment()
Gets the alignment of the label's text relative to the label's icon bounds. |
Rectangle |
getTextBounds()
Returns the bounds of the label's text. |
IFigure |
getTextFigure()
Returns the top-level text figure. |
int |
getTextJustification()
Gets the text justification of the label text. |
int |
getTextPlacement()
Returns the current placement of the label's text relative to its icon. |
protected Dimension |
getTotalIconSize()
getTotalIconSize Calculates the total union of icon sizes |
protected java.lang.String |
getTruncationString()
Gets the truncation string. |
boolean |
hasFocus()
|
protected boolean |
hasIcons()
Determines if there is any icons by checking if icon size is zeros. |
void |
invalidate()
|
boolean |
isSelected()
|
boolean |
isTextStrikedThrough()
|
boolean |
isTextTruncated()
Returns true if the label's text is currently truncated and
is displaying an ellipsis, false otherwise. |
boolean |
isTextUnderlined()
|
boolean |
isTextWrapOn()
|
void |
layout()
|
protected void |
paintClientArea(Graphics graphics)
|
void |
paintFigure(Graphics graphics)
|
void |
setAlignment(int alignment)
Sets the alignment of the label (icon and text) within the figure. |
void |
setFocus(boolean focus)
Sets the focus state of this label |
void |
setFont(Font f)
|
void |
setIcon(Image image)
Sets the label's icon to the passed image. |
void |
setIcon(Image image,
int index)
Sets the label's icon at given index |
void |
setIconAlignment(int alignment)
Sets the alignment of the label's icon relative to the label's text bounds. |
protected void |
setIconLocation(Point location)
|
void |
setSelected(boolean selected)
Sets the selection state of this label |
void |
setText(java.lang.String text)
Sets the text in this label. |
void |
setTextAlignment(int alignment)
Sets the alignment of the label's text relative to the label's icon bounds. |
void |
setTextJustification(int justification)
Sets the text justification of the label text. |
void |
setTextPlacement(int where)
Sets the text placement of the label relative to its icon. |
void |
setTextStrikeThrough(boolean strikeThrough)
Sets whether the label text should be striked-through |
void |
setTextUnderline(boolean underline)
Sets whether the label text should be underlined |
void |
setTextWrap(boolean textWrapOn)
Sets whether the label text should wrap |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final int MAX_FLAG
Figure.MAX_FLAG
protected Dimension preferredTextSize
getPreferredSize(int, int)
is called.
Constructor Detail |
---|
public WrappingLabel()
public WrappingLabel(java.lang.String text)
text
- the label textpublic WrappingLabel(Image image)
image
- the label imagepublic WrappingLabel(java.lang.String text, Image image)
text
- the label textimage
- the label imageMethod Detail |
---|
public IFigure getTextFigure()
protected Dimension calculateLabelSize(Dimension txtSize)
txtSize
- the precalculated size of the label's text
public void layout()
layout
in class Figure
public Image getIcon()
public Image getIcon(int index)
index
- The icon index
Image
that is the icon for the given index.protected boolean hasIcons()
public int getIconAlignment()
PositionConstants.CENTER
.
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
protected Point getIconLocation()
protected void setIconLocation(Point location)
public int getIconTextGap()
public Dimension getMinimumSize(int w, int h)
getMinimumSize
in interface IFigure
getMinimumSize
in class Figure
public Dimension getPreferredSize(int wHint, int hHint)
getPreferredSize
in interface IFigure
getPreferredSize
in class Figure
public java.lang.String getText()
public int getTextAlignment()
PositionConstants.CENTER
.
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
public int getAlignment()
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
public Rectangle getTextBounds()
public int getTextPlacement()
PositionConstants.EAST
.
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
public void invalidate()
invalidate
in interface IFigure
invalidate
in class Figure
public void paintFigure(Graphics graphics)
paintFigure
in class Figure
protected void paintClientArea(Graphics graphics)
paintClientArea
in class Figure
public void setIcon(Image image)
image
- the new label imagepublic void setIcon(Image image, int index)
image
- The icon image or null to remove the iconindex
- The icon indexpublic void setIconAlignment(int alignment)
PositionConstants.CENTER
.
If the text placement is NORTH/SOUTH, valid values are:
If the text placement is EAST/WEST, valid values are:
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
alignment
- the icon alignment relative to the text boundsprotected Dimension getIconSize(int index)
index
- of icon to retrieve size of.
protected int getNumberofIcons()
protected Dimension getTotalIconSize()
public void setAlignment(int alignment)
PositionConstants.LEFT
. Valid values are:
PositionConstants.TOP
| PositionConstants.LEFT
PositionConstants.TOP
PositionConstants.TOP
| PositionConstants.RIGHT
PositionConstants.LEFT
PositionConstants.CENTER
PositionConstants.RIGHT
PositionConstants.BOTTOM
| PositionConstants.LEFT
PositionConstants.BOTTOM
PositionConstants.BOTTOM
| PositionConstants.RIGHT
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
alignment
- label alignmentprotected java.lang.String getTruncationString()
truncationStringSize
is cleared.
public void setText(java.lang.String text)
text
- the new text to be setpublic void setTextAlignment(int alignment)
PositionConstants.CENTER
.
If the text placement is EAST/WEST, valid values are:
If the text placement is NORTH/SOUTH, and the icon is bigger than the
text, then the location of the text can be controlled by how the text is
justified setTextJustification(int)
.
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
alignment
- the text alignment relative to the icon boundspublic void setTextPlacement(int where)
PositionConstants.EAST
. Valid values are
e.g. PositionConstants#EAST indicates the text is on the east of the
icon.
See the documentation describing the layout of the label in the class
header WrappingLabel
for more detailed information.
where
- the text placementpublic void setTextUnderline(boolean underline)
underline
- Whether the label text should be underlinedpublic boolean isTextUnderlined()
public void setTextStrikeThrough(boolean strikeThrough)
strikeThrough
- whether the label text should be striked-throughpublic boolean isTextStrikedThrough()
public void setTextWrap(boolean textWrapOn)
b
- whether the label text should wrappublic boolean isTextWrapOn()
public void setTextJustification(int justification)
PositionConstants.LEFT
. Valid values are
alignment
- the text justification.public int getTextJustification()
PositionConstants.LEFT
,
PositionConstants.CENTER
, or
PositionConstants.RIGHT
public boolean hasFocus()
hasFocus
in interface IFigure
hasFocus
in class Figure
public void setFocus(boolean focus)
focus
- true will cause a focus rectangle to be drawn around the text
of the Labelpublic boolean isSelected()
public void setSelected(boolean selected)
selected
- true will cause the label to appear selectedpublic void setFont(Font f)
setFont
in interface IFigure
setFont
in class Figure
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isTextTruncated()
true
if the label's text is currently truncated and
is displaying an ellipsis, false
otherwise.
true
if the label's text is truncated
|
Runtime | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.