Eclipse Draw2d
2.1

org.eclipse.draw2d
Class Label

java.lang.Object
  |
  +--org.eclipse.draw2d.Figure
        |
        +--org.eclipse.draw2d.Label
All Implemented Interfaces:
IFigure, PositionConstants

public class Label
extends Figure
implements PositionConstants


Nested Class Summary
 
Nested classes inherited from class org.eclipse.draw2d.Figure
Figure.FigureIterator
 
Nested classes inherited from class 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
BOTTOM, CENTER, EAST, EAST_WEST, LEFT, LEFT_CENTER_RIGHT, MIDDLE, NONE, NORTH, NORTH_EAST, NORTH_SOUTH, NORTH_WEST, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TOP_MIDDLE_BOTTOM, WEST
 
Fields inherited from interface org.eclipse.draw2d.IFigure
MAX_DIMENSION, MIN_DIMENSION, NO_INSETS
 
Constructor Summary
Label()
          Construct an empty Label.
Label(Image i)
          Construct a Label with passed Image as its icon.
Label(String s)
          Construct a Label with passed String as its text.
Label(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()
          Calculates and returns the size of the Label's text.
 Image getIcon()
          Returns the Label's icon
 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
 int getIconTextGap()
          Returns the gap in pixels between the Label's icon and its text.
 Dimension getMinimumSize(int w, int h)
          Returns a hint indicating the smallest desireable size for the IFigure.
 Dimension getPreferredSize(int wHint, int hHint)
          Returns the desireable size for this IFigure using the provided width and height hints.
 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.
 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()
          Returns the size of the Label's complete text.
 void invalidate()
          Invalidates this IFigure.
 boolean isTextTruncated()
          Returns true 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 setIcon(Image image)
          Sets the Label's icon to the passed image
 void setIconAlignment(int align)
          Sets the icon alignment relative to the Label's alignment to the passed value.
 void setIconDimension(Dimension d)
          Sets the Label's icon size to the passed Dimension.
 void 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 Label's alignment to the passed value.
 void setText(String s)
          Sets the Label's text to the passed String.
 void setTextAlignment(int align)
          Sets the text alignment of the Label relative to the label alignment Default is org.eclipse.draw2d.PositionConstants.CENTER
 void setTextPlacement(int where)
          Sets the text placement of the Label relative to its icon.
 
Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, add, addAncestorListener, addFigureListener, addFocusListener, addKeyListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, findMouseEventTargetInDescendantsAt, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getClientArea, getClientArea, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getLocalBackgroundColor, 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, isEnabled, isFocusTraversable, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isValid, isValidationRoot, isVisible, layout, paint, paintBorder, paintChildren, paintClientArea, primTranslate, remove, removeAll, removeAncestorListener, removeFigureListener, removeFocusListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setBounds, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Label

public Label()
Construct an empty Label.

Since:
2.0

Label

public Label(String s)
Construct a Label with passed String as its text.

Since:
2.0

Label

public Label(Image i)
Construct a Label with passed Image as its icon.

Since:
2.0

Label

public Label(String s,
             Image i)
Construct a Label with passed String as text and passed Image as its icon.

Since:
2.0
Method Detail

calculateLabelSize

protected Dimension calculateLabelSize(Dimension txtSize)
Calculates the size of the Label using the passed Dimension as the size of the Label's text.

Parameters:
txtSize - Pre-calculated size of the Label's text.
Since:
2.0

calculateSubStringTextSize

protected Dimension 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, use calculateTextSize().

Since:
2.0

calculateTextSize

protected Dimension 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, use calculateSubStringSize()

Since:
2.0

getIcon

public Image getIcon()
Returns the Label's icon

Since:
2.0

getIconAlignment

public int getIconAlignment()
Returns the current alignment of the Label's icon. Default is PositionConstants.CENTER

Since:
2.0

getIconBounds

public Rectangle getIconBounds()
Returns the bounds of the Label's icon.

Since:
2.0

getIconLocation

protected Point getIconLocation()
Returns the location of the Label's icon relative to the Label

Since:
2.0

getIconTextGap

public int getIconTextGap()
Returns the gap in pixels between the Label's icon and its text.

Since:
2.0

getMinimumSize

public Dimension getMinimumSize(int w,
                                int h)
Description copied from interface: IFigure
Returns a hint indicating the smallest desireable size for the IFigure. Returned Dimension is by value.

Specified by:
getMinimumSize in interface IFigure
Overrides:
getMinimumSize in class Figure
Parameters:
w - the width hint
h - the height hint
Returns:
The minimum size

getPreferredSize

public Dimension getPreferredSize(int wHint,
                                  int hHint)
Description copied from interface: IFigure
Returns the desireable size for this IFigure using the provided width and height hints. Returned Dimension is by value. If a hint is less than or equal to 0 (usually, it's set to -1), it means that hint should be ignored.

Specified by:
getPreferredSize in interface IFigure
Overrides:
getPreferredSize in class Figure
See Also:
IFigure.getPreferredSize(int, int)

getSubStringText

public String getSubStringText()
Calculates the amount of the Label's current text will fit in the Label, including an elipsis "..." if truncation is required. Returns this text.

Since:
2.0

getSubStringTextSize

protected Dimension 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.

Since:
2.0

getText

public String getText()
Returns the text of the Label. Note that this is the complete text of the Label, regardless of if it is currently being truncated. Call getSubStringText() to return the Label's current text contents with truncation considered.

Since:
2.0

getTextAlignment

public int getTextAlignment()
Returns the current alignment of the Label's text. Default text alignment is PositionConstants.CENTER


getTextBounds

public Rectangle 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.

Since:
2.0

getTextLocation

protected Point getTextLocation()
Returns the location of the Label's text relative to the Label

Since:
2.0

getTextPlacement

public int getTextPlacement()
Returns the current placement of the Label's text relative to its icon. Default text placement is PositionConstants.EAST

Since:
2.0

getTextSize

protected Dimension 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, call getSubStringTextSize().

Since:
2.0

invalidate

public void invalidate()
Description copied from interface: IFigure
Invalidates this IFigure.

Specified by:
invalidate in interface IFigure
Overrides:
invalidate in class Figure
See Also:
IFigure.invalidate()

isTextTruncated

public boolean isTextTruncated()
Returns true if the Label's text is currently truncated and is displaying an ellipsis, false otherwise.

Since:
2.0

paintFigure

protected void paintFigure(Graphics graphics)
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 to Figure.paintClientArea(Graphics) and Figure.paintBorder(Graphics). Furthermore, it is safe to call graphics.restoreState() within this method, and doing so will restore the graphics to its original state upon entry.

Overrides:
paintFigure in class Figure
Parameters:
graphics - The Graphics used to paint

setIcon

public void setIcon(Image image)
Sets the Label's icon to the passed image

Parameters:
image - The desired icon for the Label
Since:
2.0

setIconAlignment

public void setIconAlignment(int align)
Sets the icon alignment relative to the Label's alignment to the passed value. Default is org.eclipse.draw2d.PositionConstants.CENTER

Parameters:
align - The desired icon alignment Valid values are integer constants CENTER,TOP,BOTTOM,LEFT,RIGHT in PositionConstants
Since:
2.0

setIconDimension

public void setIconDimension(Dimension d)
Sets the Label's icon size to the passed Dimension.

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. Default is 4.

Since:
2.0

setLabelAlignment

public void setLabelAlignment(int align)
Sets the Label's alignment to the passed value. Default is org.eclipse.draw2d.PositionConstants.CENTER

Parameters:
align - The desired label alignment. Valid values are the integer constants TOP, CENTER, BOTTOM, RIGHT, LEFT in PositionConstants

setText

public void setText(String s)
Sets the Label's text to the passed String.

Since:
2.0

setTextAlignment

public void setTextAlignment(int align)
Sets the text alignment of the Label relative to the label alignment Default is org.eclipse.draw2d.PositionConstants.CENTER

Parameters:
align - The desired text alignment. Valid values are the integer constants TOP, CENTER, BOTTOM, RIGHT, LEFT in PositionConstants
Since:
2.0

setTextPlacement

public void setTextPlacement(int where)
Sets the text placement of the Label relative to its icon. Default is org.eclipse.draw2d.PositionConstants.EAST

Parameters:
where - The desired text placement. Valid values are the integer constants NORTH, SOUTH, EAST, WEST in PositionConstants
Since:
2.0

Eclipse Draw2d
2.1

Copyright (c) IBM Corp. and others 2000, 2003. All Rights Reserved.