Class Badge

All Implemented Interfaces:
Animatable<Badge>, CanDrop<Badge>, Clickable<Badge>, Draggable<Badge>, HandleHotKey<Badge>, HandleMouseEvents<Badge>, Scrollable<Badge>, Touchable<Badge>

Badge component

This component displays a badge which can contain an icon. The color can also be specified. The badges have rounded edges. See the JBStrap showcase for an example

Supported events:

AnimationStart AnimationEnd, Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, Scrollable TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd HotKey

Since:
4.0
Author:
JBStrap
  • Constructor Details

    • Badge

      public Badge()
      Creates an empty badge component.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public through an annotation.
    • Badge

      public Badge(String text)
      Creates a badge with the specified text
      Parameters:
      text - The text that will be on the badge. If it's specified as null, there won't be any text on the badge
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Badge

      public Badge(String id, String text)
      Creates a badge with the specified text
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      text - The text that will be on the badge. If it's specified as null, there won't be any text on the badge
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Badge

      public Badge(Icon icon, String text)
      Creates a badge with the specified icon and text
      Parameters:
      icon - The icon that will be on the badge. For the applicable icons, see the Icon enum. If specified as null, no icon will be on the badge.
      text - The text that will be on the badge. If it's specified as null, there won't be any text on the badge
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Badge

      public Badge(String id, Icon icon, String text)
      Creates a badge with the specified icon and text
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      icon - The icon that will be on the badge. For the applicable icons, see the Icon enum. If specified as null, no icon will be on the badge.
      text - The text that will be on the badge. If it's specified as null, there won't be any text on the badge
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Badge

      public Badge(Icon icon, String text, StyleElement... styles)
      Creates a badge with the specified icon, text and style
      Parameters:
      icon - The icon that will be on the badge. For the applicable icons, see the Icon enum. If specified as null, no icon will be on the badge.
      text - The text that will be on the badge. If it's specified as null, there won't be any text on the badge
      styles - One or more style, that will be applied to the badge. For the applicable badge styles, see the BadgeType enum, and/or the TextType enum, that can be applied to the badge text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • Badge

      public Badge(String id, Icon icon, String text, StyleElement... styles)
      Creates a badge with the specified icon, text and style
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      icon - The icon that will be on the badge. For the applicable icons, see the Icon enum. If specified as null, no icon will be on the badge.
      text - The text that will be on the badge. If it's specified as null, there won't be any text on the badge
      styles - One or more style, that will be applied to the badge. For the applicable badge styles, see the BadgeType enum, and/or the TextType enum, that can be applied to the badge text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
  • Method Details

    • setText

      public Badge setText(String text)
      Sets the text content of the component
      Parameters:
      text - The text that will appear in the component. If specified as null, nothing will appear in it.
      Returns:
      The span component
    • getText

      public String getText()
      Gets the text content of the component
      Returns:
      The text content or null if no text was specified
    • setIcon

      public Badge setIcon(Icon icon)
      Sets the icon of the component
      Parameters:
      icon - The icon that will appear in the beginning of the component.For the applicable icons, see the Icon enum. If specified as null, no icon will be used.
      Returns:
      The span component
    • getIcon

      public Icon getIcon()
      Gets the icon of the component
      Returns:
      The icon of the component or null if no icon was specified
    • setBadgeType

      public Badge setBadgeType(BadgeType badgeType)
      Sets the badge type
      Parameters:
      badgeType - The badge type. For the applicable badge styles, see the BadgeType enum
      Returns:
      The badge component
    • setTextType

      public Badge setTextType(TextType textType)
      Sets the type of the badge text
      Parameters:
      textType - The type of the badge text. For the applicable text styles, see the TextType enum
      Returns:
      The badge component
    • addClickHandler

      public Badge addClickHandler(ClickEventHandler handler)
      Description copied from interface: Clickable
      Adds a single click event handler to the component. This handler runs when the user clicks once on the component.
      Specified by:
      addClickHandler in interface Clickable<Badge>
      Parameters:
      handler - The ClickEventHandler implementation
      Returns:
      The component
      See Also:
    • addDoubleClickHandler

      public Badge addDoubleClickHandler(DoubleClickEventHandler handler)
      Description copied from interface: Clickable
      Adds a double click event handler to the component. This handler runs when the user clicks twice on the component.
      Specified by:
      addDoubleClickHandler in interface Clickable<Badge>
      Parameters:
      handler - A DoubleClickEventHandler implementation
      Returns:
      The component
      See Also:
    • setRounded

      public Badge setRounded(boolean rounded)
      Set whether the sides of the badge are rounded. By default, the pages of the badge are torn off.
      Parameters:
      rounded - If set to true , badge pages will be retrieved, otherwise not.
      Returns:
      The badge component
    • isRounded

      public boolean isRounded()
      Determine whether the sides of the badge are rounded
      Returns:
      If true , the pages of the badge are rounded, otherwise they are not
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (StringWriter class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<Badge>
      Returns:
      If the componentwas drawn, true, otherwise false