Package org.eclipse.draw2d
Class Label
java.lang.Object
org.eclipse.draw2d.Figure
org.eclipse.draw2d.Label
- All Implemented Interfaces:
IFigure
,PositionConstants
A figure that can display text and/or an image.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.draw2d.Figure
Figure.FigureIterator, Figure.IdentitySearch, Figure.ReverseFigureChildrenIterator
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.IFigure
MAX_DIMENSION, MIN_DIMENSION, NO_INSETS
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Dimension
calculateLabelSize
(Dimension txtSize) Calculates the size of the Label using the passed Dimension as the size of the Label's text.protected Dimension
Calculates the size of the Label's text size.protected Dimension
Calculates and returns the size of the Label's text.getIcon()
Returns the Label's icon.int
Returns the current alignment of the Label's icon.Returns the bounds of the Label's icon.protected Point
Returns the location of the Label's icon relative to the Label.protected Dimension
Gets the icon sizeint
Returns the gap in pixels between the Label's icon and its text.int
Returns the alignment of the entire label (icon and text).getMinimumSize
(int w, int h) Returns a hint indicating the smallest desireable size for the IFigure.getPreferredSize
(int wHint, int hHint) Returns the preferred size for this IFigure using the provided width and height hints.Calculates the amount of the Label's current text will fit in the Label, including an elipsis "..." if truncation is required.protected Dimension
Returns the size of the Label's current text.getText()
Returns the text of the label.int
Returns the current alignment of the Label's text.Returns the bounds of the label's text.protected Point
Returns the location of the label's text relative to the label.int
Returns the current placement of the label's text relative to its icon.protected Dimension
Returns the size of the label's complete text.Gets theTextUtilities
instance to be used in measurement calculations.protected String
Gets the string that will be appended to the text when the label is truncated.void
Invalidates this IFigure.boolean
Returnstrue
if the label's text is currently truncated and is displaying an ellipsis,false
otherwise.protected void
paintFigure
(Graphics graphics) Paints this Figure's primary representation, or background.void
Sets the label's icon to the passed image.void
setIconAlignment
(int align) This method sets the alignment of the icon within the bounds of the label.void
Deprecated.the icon is automatically displayed at 1:1void
setIconTextGap
(int gap) Sets the gap in pixels between the label's icon and text to the passed value.void
setLabelAlignment
(int align) Sets the alignment of the label (icon and text) within the figure.void
Sets the label's text.void
setTextAlignment
(int align) Sets the alignment of the text relative to the icon within the label.void
setTextPlacement
(int where) Sets the placement of the text relative to the icon within the label.Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, add, addAncestorListener, addCoordinateListener, addFigureListener, addFocusListener, addKeyListener, addLayoutListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, findMouseEventTargetInDescendantsAt, fireCoordinateSystemChanged, fireFigureMoved, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getChildrenRevIterable, getClientArea, getClientArea, getClippingStrategy, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getListenersIterable, getLocalBackgroundColor, getLocalFont, getLocalForegroundColor, getLocation, getMaximumSize, getMinimumSize, getParent, getPreferredSize, getSize, getToolTip, getUpdateManager, handleFocusGained, handleFocusLost, handleKeyPressed, handleKeyReleased, handleMouseDoubleClicked, handleMouseDragged, handleMouseEntered, handleMouseExited, handleMouseHover, handleMouseMoved, handleMousePressed, handleMouseReleased, hasFocus, internalGetEventDispatcher, intersects, invalidateTree, isCoordinateSystem, isEnabled, isFocusTraversable, isMirrored, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isShowing, isValid, isValidationRoot, isVisible, layout, optimizeClip, paint, paintBorder, paintChildren, paintClientArea, primTranslate, remove, removeAll, removeAncestorListener, removeCoordinateListener, removeFigureListener, removeFocusListener, removeKeyListener, removeLayoutListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setBounds, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, setClippingStrategy, setConstraint, setCursor, setEnabled, setFlag, setFocusTraversable, setFont, setForegroundColor, setLayoutManager, setLocation, setMaximumSize, setMinimumSize, setOpaque, setParent, setPreferredSize, setPreferredSize, setRequestFocusEnabled, setSize, setSize, setToolTip, setValid, setVisible, translate, translateFromParent, translateToAbsolute, translateToParent, translateToRelative, useLocalCoordinates, validate
-
Constructor Details
-
Label
public Label()Construct an empty Label.- Since:
- 2.0
-
Label
Construct a Label with passed String as its text.- Parameters:
s
- the label text- Since:
- 2.0
-
Label
Construct a Label with passed Image as its icon.- Parameters:
i
- the label image- Since:
- 2.0
-
Label
Construct a Label with passed String as text and passed Image as its icon.- Parameters:
s
- the label texti
- the label image- Since:
- 2.0
-
-
Method Details
-
calculateLabelSize
Calculates the size of the Label using the passed Dimension as the size of the Label's text.- Parameters:
txtSize
- the precalculated size of the label's text- Returns:
- the label's size
- Since:
- 2.0
-
calculateSubStringTextSize
Calculates the size of the Label's text size. The text size calculated takes into consideration if the Label's text is currently truncated. If text size without considering current truncation is desired, usecalculateTextSize()
.- Returns:
- the size of the label's text, taking into account truncation
- Since:
- 2.0
-
calculateTextSize
Calculates and returns the size of the Label's text. Note that this Dimension is calculated using the Label's full text, regardless of whether or not its text is currently truncated. If text size considering current truncation is desired, usecalculateSubStringTextSize()
.- Returns:
- the size of the label's text, ignoring truncation
- Since:
- 2.0
-
getIcon
Returns the Label's icon.- Returns:
- the label icon
- Since:
- 2.0
-
getIconAlignment
public int getIconAlignment()Returns the current alignment of the Label's icon. The default isPositionConstants.CENTER
.- Returns:
- the icon alignment
- Since:
- 2.0
-
getIconBounds
Returns the bounds of the Label's icon.- Returns:
- the icon's bounds
- Since:
- 2.0
-
getIconLocation
Returns the location of the Label's icon relative to the Label.- Returns:
- the icon's location
- Since:
- 2.0
-
getIconTextGap
public int getIconTextGap()Returns the gap in pixels between the Label's icon and its text.- Returns:
- the gap
- Since:
- 2.0
-
getMinimumSize
Description copied from interface:IFigure
Returns a hint indicating the smallest desireable size for the IFigure. The returned dimension may be by reference, and it must not be modified by the caller.- Specified by:
getMinimumSize
in interfaceIFigure
- Overrides:
getMinimumSize
in classFigure
- Parameters:
w
- the width hinth
- the height hint- Returns:
- The minimum size
- See Also:
-
getPreferredSize
Description copied from interface:IFigure
Returns the preferred size for this IFigure using the provided width and height hints. The returned dimension may be by reference, and it must not be modified by the caller. A value of-1
indicates that there is no constraint in that direction.- Specified by:
getPreferredSize
in interfaceIFigure
- Overrides:
getPreferredSize
in classFigure
- Parameters:
wHint
- a width hinthHint
- a height hint- Returns:
- The preferred size
- See Also:
-
getSubStringText
Calculates the amount of the Label's current text will fit in the Label, including an elipsis "..." if truncation is required.- Returns:
- the substring
- Since:
- 2.0
-
getSubStringTextSize
Returns the size of the Label's current text. If the text is currently truncated, the truncated text with its ellipsis is used to calculate the size.- Returns:
- the size of this label's text, taking into account truncation
- Since:
- 2.0
-
getText
Returns the text of the label. Note that this is the complete text of the label, regardless of whether it is currently being truncated. CallgetSubStringText()
to return the label's current text contents with truncation considered.- Returns:
- the complete text of this label
- Since:
- 2.0
-
getTextAlignment
public int getTextAlignment()Returns the current alignment of the Label's text. The default text alignment isPositionConstants.CENTER
.- Returns:
- the text alignment
-
getTextBounds
Returns the bounds of the label's text. Note that the bounds are calculated using the label's complete text regardless of whether the label's text is currently truncated.- Returns:
- the bounds of this label's complete text
- Since:
- 2.0
-
getTextLocation
Returns the location of the label's text relative to the label.- Returns:
- the text location
- Since:
- 2.0
-
getTextPlacement
public int getTextPlacement()Returns the current placement of the label's text relative to its icon. The default text placement isPositionConstants.EAST
.- Returns:
- the text placement
- Since:
- 2.0
-
getTextSize
Returns the size of the label's complete text. Note that the text used to make this calculation is the label's full text, regardless of whether the label's text is currently being truncated and is displaying an ellipsis. If the size considering current truncation is desired, callgetSubStringTextSize()
.- Returns:
- the size of this label's complete text
- Since:
- 2.0
-
invalidate
public void invalidate()Description copied from interface:IFigure
Invalidates this IFigure. If this figure has a LayoutManager, thenLayoutManager.invalidate()
should be called on that layout.- Specified by:
invalidate
in interfaceIFigure
- Overrides:
invalidate
in classFigure
- See Also:
-
isTextTruncated
public boolean isTextTruncated()Returnstrue
if the label's text is currently truncated and is displaying an ellipsis,false
otherwise.- Returns:
true
if the label's text is truncated- Since:
- 2.0
-
paintFigure
Description copied from class:Figure
Paints this Figure's primary representation, or background. Changes made to the graphics to the graphics current state will not affect the subsequent calls toFigure.paintClientArea(Graphics)
andFigure.paintBorder(Graphics)
. Furthermore, it is safe to callgraphics.restoreState()
within this method, and doing so will restore the graphics to its original state upon entry.- Overrides:
paintFigure
in classFigure
- Parameters:
graphics
- The Graphics used to paint- See Also:
-
setIcon
Sets the label's icon to the passed image.- Parameters:
image
- the new label image- Since:
- 2.0
-
setIconAlignment
public void setIconAlignment(int align) This method sets the alignment of the icon within the bounds of the label. If the label is larger than the icon, then the icon will be aligned according to this alignment. Valid values are:- Parameters:
align
- the icon alignment- Since:
- 2.0
-
setIconDimension
Deprecated.the icon is automatically displayed at 1:1Sets the label's icon size to the passed Dimension.- Parameters:
d
- the new icon size- Since:
- 2.0
-
setIconTextGap
public void setIconTextGap(int gap) Sets the gap in pixels between the label's icon and text to the passed value. The default is 4.- Parameters:
gap
- the gap- Since:
- 2.0
-
setLabelAlignment
public void setLabelAlignment(int align) Sets the alignment of the label (icon and text) within the figure. If this figure's bounds are larger than the size needed to display the label, the label will be aligned accordingly. Valid values are:- Parameters:
align
- label alignment
-
setText
Sets the label's text.- Parameters:
s
- the new label text- Since:
- 2.0
-
setTextAlignment
public void setTextAlignment(int align) Sets the alignment of the text relative to the icon within the label. The text alignment must be orthogonal to the text placement. For example, if the placement is EAST, then the text can be aligned using TOP, CENTER, or BOTTOM. Valid values are:- Parameters:
align
- the text alignment- Since:
- 2.0
- See Also:
-
setTextPlacement
public void setTextPlacement(int where) Sets the placement of the text relative to the icon within the label. Valid values are:- Parameters:
where
- the text placement- Since:
- 2.0
-
getTextUtilities
Gets theTextUtilities
instance to be used in measurement calculations.- Returns:
- a
TextUtilities
instance - Since:
- 3.4
-
getTruncationString
Gets the string that will be appended to the text when the label is truncated. By default, this returns an ellipsis.- Returns:
- the string to append to the text when truncated
- Since:
- 3.4
-
getIconSize
Gets the icon size- Returns:
- the icon size
- Since:
- 3.4
-
getLabelAlignment
public int getLabelAlignment()Returns the alignment of the entire label (icon and text). The default label alignment isPositionConstants.CENTER
.- Returns:
- the label alignment
- Since:
- 3.5
-