Class 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)
    • 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 badge
      org.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 a SEPARATOR 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 argument
      void setBadgeBackground​(org.eclipse.swt.graphics.Color badgeBackground)
      Sets the badge's background color to the color specified by the argument
      void setBadgeForeground​(org.eclipse.swt.graphics.Color badgeForeground)
      Sets the badge's foreground color to the color specified by the argument
      void setBadgeValue​(java.lang.String value)
      Sets the badge's value (text) to the text specified by the argument
      void setBorderColor​(org.eclipse.swt.graphics.Color borderColor)
      Sets the receiver's border color to the color specified by the argument
      void 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 argument
      void 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 the int "|" operator) two or more of those SWT 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 class org.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 a SEPARATOR 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 class org.eclipse.swt.widgets.Control
        See Also:
        Control.setEnabled(boolean)
      • setFont

        public void setFont​(org.eclipse.swt.graphics.Font font)
        Overrides:
        setFont in class org.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