Class BadgedLabel
- java.lang.Object
-
- org.eclipse.swt.widgets.Widget
-
- org.eclipse.swt.widgets.Control
-
- org.eclipse.swt.widgets.Scrollable
-
- org.eclipse.swt.widgets.Composite
-
- org.eclipse.swt.widgets.Canvas
-
- org.eclipse.nebula.widgets.badgedlabel.BadgedLabel
-
- All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable
public class BadgedLabel extends org.eclipse.swt.widgets.Canvas
Instances of this class represent a non-selectable user interface object that displays a string or image. A badge is displayed on this label, so you can add extra information (the most common used is a notification label that shows the number of unread notifications).- Styles:
- SWT.BORDER
- SWT.LEFT or SWT.RIGHT (horizontal location)
- SWT.TOP or SWT.BOTTOM (vertical location)
- Events:
- (none)
-
-
Field Summary
Fields Modifier and Type Field Description private org.eclipse.swt.graphics.Color
backgroundColor
private org.eclipse.swt.graphics.Color
badgeBackground
private org.eclipse.swt.graphics.Font
badgeFont
private org.eclipse.swt.graphics.Color
badgeForeground
private org.eclipse.swt.graphics.Point
badgeTextSizeCache
private java.lang.String
badgeValue
private org.eclipse.swt.graphics.Font
boldFont
private org.eclipse.swt.graphics.Color
borderColor
private org.eclipse.swt.graphics.Point
buttonSize
private static int
CIRCLE_DIAMETER
private org.eclipse.swt.graphics.GC
gc
private int
horizontalLocation
private org.eclipse.swt.graphics.Image
image
private int
left
private static int
MARGIN
private static int
MAX_BADGE_TEXT_SIZE
private static int
PADDING
private java.lang.String
text
private org.eclipse.swt.graphics.Color
textColor
private org.eclipse.swt.graphics.Point
textSizeCache
private int
top
private int
verticalLocation
-
Constructor Summary
Constructors Constructor Description BadgedLabel(org.eclipse.swt.widgets.Composite parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkColor(org.eclipse.swt.graphics.Color color)
private static int
checkStyle(int style)
private org.eclipse.swt.graphics.Point
computeButtonSize()
org.eclipse.swt.graphics.Point
computeSize(int wHint, int hHint, boolean changed)
private void
drawBadge()
private void
drawButton()
private void
drawImageAndText()
private void
drawShape()
org.eclipse.swt.graphics.Color
getBackgroundColor()
Returns the background color that the receiver will use to draw.org.eclipse.swt.graphics.Color
getBadgeBackground()
Returns the background color that the badge will use to draw.org.eclipse.swt.graphics.Color
getBadgeForeground()
Returns the foreground color that the badge will use to draw.private org.eclipse.swt.graphics.Point
getBadgeTextSizeInPixels()
java.lang.String
getBadgeValue()
Returns the text of the badgeorg.eclipse.swt.graphics.Color
getBorderColor()
Returns the border color that the receiver will use to draw.org.eclipse.swt.graphics.Image
getImage()
Returns the receiver's image if it has one, or null if it does not.java.lang.String
getText()
Returns the receiver's text, which will be an empty string if it has never been set or if the receiver is aSEPARATOR
label.org.eclipse.swt.graphics.Color
getTextColor()
Returns the text color that the receiver will use to draw.private org.eclipse.swt.graphics.Point
getTextSizeInPixels()
private void
initDefaultColors()
private void
onPaint(org.eclipse.swt.widgets.Event e)
void
setBackgroundColor(org.eclipse.swt.graphics.Color backgroundColor)
Sets the receiver's background color to the color specified by the argumentvoid
setBadgeBackground(org.eclipse.swt.graphics.Color badgeBackground)
Sets the badge's background color to the color specified by the argumentvoid
setBadgeForeground(org.eclipse.swt.graphics.Color badgeForeground)
Sets the badge's foreground color to the color specified by the argumentvoid
setBadgeValue(java.lang.String value)
Sets the badge's value (text) to the text specified by the argumentvoid
setBorderColor(org.eclipse.swt.graphics.Color borderColor)
Sets the receiver's border color to the color specified by the argumentvoid
setEnabled(boolean enabled)
void
setFont(org.eclipse.swt.graphics.Font font)
void
setImage(org.eclipse.swt.graphics.Image image)
Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.void
setPredefinedColor(int color)
Sets the badge's color theme to the theme specified by the argumentvoid
setText(java.lang.String text)
Sets the receiver's text.void
setTextColor(org.eclipse.swt.graphics.Color textColor)
Sets the receiver's text color to the color specified by the argument-
Methods inherited from class org.eclipse.swt.widgets.Canvas
drawBackground, getCaret, getIME, scroll, setCaret, setIME
-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, checkSubclass, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getTextDirection, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isAutoScalable, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, requestLayout, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setTextDirection, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getDisplay, getListeners, getStyle, isAutoDirection, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
-
-
-
-
Field Detail
-
PADDING
private static final int PADDING
- See Also:
- Constant Field Values
-
MARGIN
private static final int MARGIN
- See Also:
- Constant Field Values
-
CIRCLE_DIAMETER
private static final int CIRCLE_DIAMETER
- See Also:
- Constant Field Values
-
MAX_BADGE_TEXT_SIZE
private static final int MAX_BADGE_TEXT_SIZE
- See Also:
- Constant Field Values
-
image
private org.eclipse.swt.graphics.Image image
-
text
private java.lang.String text
-
badgeValue
private java.lang.String badgeValue
-
textColor
private org.eclipse.swt.graphics.Color textColor
-
backgroundColor
private org.eclipse.swt.graphics.Color backgroundColor
-
borderColor
private org.eclipse.swt.graphics.Color borderColor
-
badgeForeground
private org.eclipse.swt.graphics.Color badgeForeground
-
badgeBackground
private org.eclipse.swt.graphics.Color badgeBackground
-
badgeFont
private final org.eclipse.swt.graphics.Font badgeFont
-
boldFont
private org.eclipse.swt.graphics.Font boldFont
-
horizontalLocation
private int horizontalLocation
-
verticalLocation
private int verticalLocation
-
gc
private org.eclipse.swt.graphics.GC gc
-
left
private int left
-
top
private int top
-
buttonSize
private org.eclipse.swt.graphics.Point buttonSize
-
textSizeCache
private org.eclipse.swt.graphics.Point textSizeCache
-
badgeTextSizeCache
private org.eclipse.swt.graphics.Point badgeTextSizeCache
-
-
Constructor Detail
-
BadgedLabel
public BadgedLabel(org.eclipse.swt.widgets.Composite parent, int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.The style value is either one of the style constants defined in class
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a composite control which will be the parent of the new instance (cannot be null)style
- the style of control to construct- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
org.eclipse.swt.SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
-
-
Method Detail
-
checkStyle
private static int checkStyle(int style)
-
initDefaultColors
private void initDefaultColors()
-
onPaint
private void onPaint(org.eclipse.swt.widgets.Event e)
-
drawButton
private void drawButton()
-
drawShape
private void drawShape()
-
drawImageAndText
private void drawImageAndText()
-
getTextSizeInPixels
private org.eclipse.swt.graphics.Point getTextSizeInPixels()
-
drawBadge
private void drawBadge()
-
getBadgeTextSizeInPixels
private org.eclipse.swt.graphics.Point getBadgeTextSizeInPixels()
-
setPredefinedColor
public void setPredefinedColor(int color)
Sets the badge's color theme to the theme specified by the argument- Parameters:
color
- the new color, can pick one of the following value: SWT.COLOR_BLUE, SWT.COLOR_GRAY, SWT.COLOR_GREEN, SWT.COLOR_RED, SWT.COLOR_YELLOW, SWT.COLOR_CYAN, SWT.COLOR_BLACK- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
computeSize
public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed)
- Overrides:
computeSize
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.computeSize(int, int, boolean)
-
computeButtonSize
private org.eclipse.swt.graphics.Point computeButtonSize()
-
getBackgroundColor
public org.eclipse.swt.graphics.Color getBackgroundColor()
Returns the background color that the receiver will use to draw.- Returns:
- the receiver's background color
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getBadgeBackground
public org.eclipse.swt.graphics.Color getBadgeBackground()
Returns the background color that the badge will use to draw.- Returns:
- the badge's backdground color
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getBadgeForeground
public org.eclipse.swt.graphics.Color getBadgeForeground()
Returns the foreground color that the badge will use to draw.- Returns:
- the badge's foreground color
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getBadgeValue
public java.lang.String getBadgeValue()
Returns the text of the badge- Returns:
- the badge's text
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getBorderColor
public org.eclipse.swt.graphics.Color getBorderColor()
Returns the border color that the receiver will use to draw.- Returns:
- the receiver's border color
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getImage
public org.eclipse.swt.graphics.Image getImage()
Returns the receiver's image if it has one, or null if it does not.- Returns:
- the receiver's image
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getText
public java.lang.String getText()
Returns the receiver's text, which will be an empty string if it has never been set or if the receiver is aSEPARATOR
label.- Returns:
- the receiver's text
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
getTextColor
public org.eclipse.swt.graphics.Color getTextColor()
Returns the text color that the receiver will use to draw.- Returns:
- the receiver's text color
- Throws:
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBackgroundColor
public void setBackgroundColor(org.eclipse.swt.graphics.Color backgroundColor)
Sets the receiver's background color to the color specified by the argument- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
checkColor
private void checkColor(org.eclipse.swt.graphics.Color color)
-
setBadgeBackground
public void setBadgeBackground(org.eclipse.swt.graphics.Color badgeBackground)
Sets the badge's background color to the color specified by the argument- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBadgeForeground
public void setBadgeForeground(org.eclipse.swt.graphics.Color badgeForeground)
Sets the badge's foreground color to the color specified by the argument- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBadgeValue
public void setBadgeValue(java.lang.String value)
Sets the badge's value (text) to the text specified by the argument- Parameters:
value
- the new text value- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBorderColor
public void setBorderColor(org.eclipse.swt.graphics.Color borderColor)
Sets the receiver's border color to the color specified by the argument- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setEnabled
public void setEnabled(boolean enabled)
- Overrides:
setEnabled
in classorg.eclipse.swt.widgets.Control
- See Also:
Control.setEnabled(boolean)
-
setFont
public void setFont(org.eclipse.swt.graphics.Font font)
- Overrides:
setFont
in classorg.eclipse.swt.widgets.Canvas
- See Also:
Canvas.setFont(org.eclipse.swt.graphics.Font)
-
setImage
public void setImage(org.eclipse.swt.graphics.Image image)
Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.- Parameters:
image
- the image to display on the receiver (may be null)- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the image has been disposed
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setText
public void setText(java.lang.String text)
Sets the receiver's text.This method sets the widget label. The label may include the mnemonic character and line delimiters.
Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, focus is assigned to the control that follows the label. On most platforms, the mnemonic appears underlined but may be emphasised in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed.
Note: If control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.
- Parameters:
string
- the new text- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the text is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setTextColor
public void setTextColor(org.eclipse.swt.graphics.Color textColor)
Sets the receiver's text color to the color specified by the argument- Parameters:
color
- the new color- Throws:
java.lang.IllegalArgumentException
-- ERROR_INVALID_ARGUMENT - if the argument has been disposed
- ERROR_NULL_ARGUMENT - if the argument is null
org.eclipse.swt.SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
-