|
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.WrapLabel
public class WrapLabel
An extended label that has the following extra features:
1- It is capable of showing selection and focus feedback (primary or
secondary) 2- It is capable of optionally underlining the label's text 3- It
is capable of wrapping the label's text at a given width with a given
alignment 4- It is capable of supporting multiple label icons (temporary
feature)
This class was originally deriving off Draw2d's Label
class
but with the introduction of the auto-wrapping feature, a copy had to be made
overriding was not straightforward. Hopefully, this extended version can be
pushed to opensource
Code taken from Eclipse reference bugzilla #98820
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 |
---|
Fields inherited from class org.eclipse.draw2d.Figure |
---|
bgColor, border, bounds, fgColor, flags, font, MAX_FLAG, 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 | |
---|---|
WrapLabel()
Construct an empty Label. |
|
WrapLabel(Image i)
Construct a Label with passed Image as its icon. |
|
WrapLabel(java.lang.String s)
Construct a Label with passed String as its text. |
|
WrapLabel(java.lang.String s,
Image i)
Construct a Label with passed String as text and 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. |
protected Dimension |
calculateSubStringTextSize()
Calculates the size of the Label's text size. |
protected Dimension |
calculateTextSize(int wHint,
int hHint)
Calculates and returns the size of the Label's text. |
protected java.lang.String |
getEllipse()
Return the ellipse string. |
Image |
getIcon()
Returns the Label's icon. |
Image |
getIcon(int index)
Gets the label's icon at the given index |
int |
getIconAlignment()
Returns the current alignment of the Label's icon. |
Rectangle |
getIconBounds()
Returns the bounds of the Label's icon. |
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 |
getMaximumSize()
|
Dimension |
getMinimumSize(int w,
int h)
|
protected int |
getNumberofIcons()
getIconNumber |
Dimension |
getPreferredSize(int wHint,
int hHint)
|
java.lang.String |
getSubStringText()
Calculates the amount of the Label's current text will fit in the Label, including an elipsis "..." if truncation is required. |
protected Dimension |
getSubStringTextSize()
Returns the size of the Label's current text. |
java.lang.String |
getText()
Returns the text of the label. |
int |
getTextAlignment()
Returns the current alignment of the Label's text. |
Rectangle |
getTextBounds()
Returns the bounds of the label's text. |
protected Point |
getTextLocation()
Returns the location of the label's text relative to the label. |
int |
getTextPlacement()
Returns the current placement of the label's text relative to its icon. |
protected Dimension |
getTextSize(int wHint,
int hHint)
Returns the size of the label's complete text. |
int |
getTextWrapAlignment()
|
protected Dimension |
getTotalIconSize()
getTotalIconSize Calculates the total union of icon sizes |
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 |
isTextWrapped()
|
void |
paintFigure(Graphics graphics)
|
void |
setFocus(boolean b)
Sets the focus state of this label |
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 align)
Sets the icon alignment relative to the .abel's alignment to the passed value. |
void |
setLabelAlignment(int align)
Sets the Label's alignment to the passed value. |
void |
setSelected(boolean b)
Sets the selection state of this label |
void |
setText(java.lang.String s)
Sets the label's text. |
void |
setTextAlignment(int align)
Sets the text alignment of the Label relative to the label alignment. |
void |
setTextPlacement(int where)
Sets the text placement of the label relative to its icon. |
void |
setTextStrikeThrough(boolean b)
Sets whether the label text should be striked-through |
void |
setTextUnderline(boolean b)
Sets whether the label text should be underlined |
void |
setTextWrap(boolean b)
Sets whether the label text should wrap |
void |
setTextWrapAlignment(int i)
Sets the wrapping width of the label text. |
void |
setTextWrapWidth(int i)
Sets the wrapping width of the label text. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WrapLabel()
public WrapLabel(java.lang.String s)
s
- the label textpublic WrapLabel(Image i)
i
- the label imagepublic WrapLabel(java.lang.String s, Image i)
s
- the label texti
- the label imageMethod Detail |
---|
protected Dimension calculateLabelSize(Dimension txtSize)
txtSize
- the precalculated size of the label's text
protected Dimension calculateSubStringTextSize()
calculateTextSize(int, int)
.
protected Dimension calculateTextSize(int wHint, int hHint)
calculateSubStringTextSize()
.
wHint
- a width hinthHint
- a height hint
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
.
public Rectangle getIconBounds()
protected Point getIconLocation()
public int getIconTextGap()
public Dimension getMinimumSize(int w, int h)
getMinimumSize
in interface IFigure
getMinimumSize
in class Figure
IFigure#getMinimumSize(int, int)
public Dimension getPreferredSize(int wHint, int hHint)
getPreferredSize
in interface IFigure
getPreferredSize
in class Figure
public Dimension getMaximumSize()
getMaximumSize
in interface IFigure
getMaximumSize
in class Figure
public java.lang.String getSubStringText()
protected Dimension getSubStringTextSize()
public java.lang.String getText()
getSubStringText()
to return the label's current text contents
with truncation considered.
public int getTextAlignment()
PositionConstants.CENTER
.
public Rectangle getTextBounds()
protected Point getTextLocation()
public int getTextPlacement()
PositionConstants.EAST
.
protected Dimension getTextSize(int wHint, int hHint)
getSubStringTextSize()
.
wHint
- a width hinthHint
- a height hint
public void invalidate()
invalidate
in interface IFigure
invalidate
in class Figure
IFigure#invalidate()
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 truncatedpublic void paintFigure(Graphics graphics)
paintFigure
in class Figure
Figure.paintFigure(org.eclipse.draw2d.Graphics)
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 align)
PositionConstants.CENTER
. Other possible
values are PositionConstants.TOP
,
PositionConstants.BOTTOM
,PositionConstants.LEFT
and
PositionConstants.RIGHT
.
align
- the icon alignmentprotected Dimension getIconSize(int index)
index
- of icon to retrieve size of.
protected int getNumberofIcons()
protected Dimension getTotalIconSize()
public void setLabelAlignment(int align)
PositionConstants.CENTER
. Other possible values are
PositionConstants.TOP
,PositionConstants.BOTTOM
,
PositionConstants.LEFT
and PositionConstants.RIGHT
.
align
- label alignmentprotected java.lang.String getEllipse()
String
that represents the fact that the
text has been truncated and that more text is available but hidden.
Usually this is represented by "...".public void setText(java.lang.String s)
s
- the new label textpublic void setTextAlignment(int align)
PositionConstants.CENTER
. Other possible values are
PositionConstants.TOP
,PositionConstants.BOTTOM
,
PositionConstants.LEFT
and PositionConstants.RIGHT
.
align
- the text alignmentpublic void setTextPlacement(int where)
PositionConstants.EAST
. Other possible values are
PositionConstants.NORTH
,PositionConstants.SOUTH
and
PositionConstants.WEST
.
where
- the text placementpublic void setTextUnderline(boolean b)
b
- Wether the label text should be underlinedpublic boolean isTextUnderlined()
public void setTextStrikeThrough(boolean b)
b
- Wether the label text should be stricked-throughpublic boolean isTextStrikedThrough()
public void setTextWrap(boolean b)
b
- whether the label text should wrappublic boolean isTextWrapped()
public void setTextWrapWidth(int i)
i
- The label text wrapping widthpublic void setTextWrapAlignment(int i)
i
- The label text wrapping widthpublic int getTextWrapAlignment()
public void setSelected(boolean b)
b
- true will cause the label to appear selectedpublic boolean isSelected()
public void setFocus(boolean b)
b
- true will cause a focus rectangle to be drawn around the text
of the Labelpublic boolean hasFocus()
hasFocus
in interface IFigure
hasFocus
in class Figure
|
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.