Class DropDownButton

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

DropDownButton component

With this component, a button can be placed on the interface. The button can be customized, and it can have an icon and/or text on it. The click event handler can be implemented on the server side.

Other menu items can be placed on the button, and they will appear to the user when they press the button. The menu items have their own individual click events, that can be programmed individually.

The button component supports the use of animations, that can be used when the button appears or disappears. The animation can be set by using the setAnimation method. For the types of animation, see the Animation enum.

A counter can also be placed on the right side of the button. The counter can have any integer number in it. This can be used to count content, for example, the amount of unread messages

Supported events:

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

Since:
4.0
Author:
JBStrap
  • Constructor Details

    • DropDownButton

      public DropDownButton(Icon icon)
      creates a button with the specified icon
      Parameters:
      icon - the icon of the button. for the applicable icons, see the Icon enum.
      Throws:
      illegalstateexception - if the component is set to be both private and public, through an annotation.
    • DropDownButton

      public DropDownButton(String id, Icon icon)
      Creates a button with the specified icon
      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 of the button. For the applicable icons, see the Icon enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(String text)
      Creates a button with the specified text
      Parameters:
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(String id, String text)
      Creates a button 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 button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(Icon icon, String text)
      Creates a button with the specified icon and text
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(String id, Icon icon, String text)
      Creates a button 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 of the button. For the applicable icons, see the Icon enum.
      text - The button text
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(String text, StyleElement... styles)
      Creates a button with the specified text and style(s).
      Parameters:
      text - The button text
      styles - The style (type and/or size) of the button. For the applicable types, see the ButtonType enum. For the applicable sizes, see the ButtonSize enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(Icon icon, String text, StyleElement... styles)
      Creates a button with the specified icon, text and style(s).
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      styles - The style (type and/or size) of the button. For the applicable types, see the ButtonType enum. For the applicable sizes, see the ButtonSize enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • DropDownButton

      public DropDownButton(String id, Icon icon, String text, StyleElement... styles)
      Creates a button with the specified icon, text and style(s).
      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 of the button. For the applicable icons, see the Icon enum.
      text - The button text
      styles - The style (type and/or size) of the button. For the applicable types, see the ButtonType enum. For the applicable sizes, see the ButtonSize enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
  • Method Details

    • init

      public void init() throws JavaScriptLoadError
      Description copied from class: Component
      The component initialization method.

      Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.

      Overrides:
      init in class Component<DropDownButton>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • setText

      public DropDownButton setText(String text)
      Sets the button text
      Parameters:
      text - The button text
      Returns:
      The button component
    • getText

      public String getText()
      Gets the button text
      Returns:
      The current button text. If it has no text, returns with null
    • setIcon

      public DropDownButton setIcon(Icon icon)
      Sets the button icon
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      Returns:
      The button component
    • getIcon

      public Icon getIcon()
      Gets the button icon
      Returns:
      The current button icon. If it has no icon, returns with null
    • setImage

      public DropDownButton setImage(Image image)
      Places an image on the button
      Parameters:
      image - The image that will be on the button. If specified as null, nothing will be placed.
      Returns:
      The button component
    • setType

      public DropDownButton setType(ButtonType type)
      Sets the button size
      Parameters:
      type - The size of the button. For the applicable types, see the ButtonType enum.
      Returns:
      The button
    • setSize

      public DropDownButton setSize(ButtonSize size)
      Stets the button size
      Parameters:
      size - The style size of the button. For the applicable types, see the ButtonSize enum.
      Returns:
      The button
    • setCounter

      public final DropDownButton setCounter(long value)
      Adds a counter to the right side of the button.
      Parameters:
      value - The counter value
      Returns:
      The button component
    • getCounter

      public final long getCounter()
      Gets the counter value
      Returns:
      The current value on the button counter. If the button has no counter, returns with -1.
    • setDirection

      public DropDownButton setDirection(DropDownDirection direction)
      Sets the dropdown direction. By default, a dropdown menu opens downwards, but you can use this method to modify it upwards or left/right.
      Parameters:
      direction - Dropdown direction If null is specified, the dropdown menu opens downwards. Available directions are listed in the enum DropDownDirection
      Returns:
      Button component
    • getDirection

      public DropDownDirection getDirection()
      Gets the dropdown direction.
      Returns:
      Dropdown direction
    • addMenuItem

      public final DropDownButton addMenuItem(Icon icon, String text, ClickEventHandler handler)
      Adds a menu item with the specified icon, text and click handler to the button's drop down menu
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      handler - The click even handler implementation
      Returns:
      The button component
    • addMenuItem

      public DropDownButton addMenuItem(Icon icon, String text, int hotKey, ClickEventHandler clickHandler)
      Adds a menu item with the specified icon, text, hot key and click handler to the button's drop down menu
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      hotKey - The menu hot key. This can be specified by using one of the Key class' constants. For example, adding CTRL+S: Key.CRTL + Key.KEY_S
      clickHandler - The click even handler implementation
      Returns:
      The button component
    • addDivider

      public final DropDownButton addDivider()
      Adds a divider to the button drop down menu.
      Returns:
      The button component
    • addHeader

      public DropDownButton addHeader(String text)
      Adds a header to the dropdown menu. Users cannot click on a header, it is only displayed as an information box.
      Parameters:
      text - Header text
      Returns:
      Button component
    • addComponent

      public DropDownButton addComponent(Component<?> component)
      Adds a component to the dropdown menu.
      Overrides:
      addComponent in class Component<DropDownButton>
      Parameters:
      component - The component to be added
      Returns:
      The component
    • getItem

      public DropDownButton.DropDownMenuItem getItem(int index)
      Gets a menu item by referencing its index.
      Parameters:
      index - Menu item index
      Returns:
      Menu item component or null, if there is no menu item with the specified index
    • setAnimation

      public DropDownButton setAnimation(Animation animation)
      Description copied from interface: Animatable
      Sets the animation type on the component
      Specified by:
      setAnimation in interface Animatable<DropDownButton>
      Parameters:
      animation - The animation type. The usable animation types can be found in the Animation enum
      Returns:
      The component
    • getAnimation

      public Animation getAnimation()
      Description copied from interface: Animatable
      Gets the component's animation type
      Specified by:
      getAnimation in interface Animatable<DropDownButton>
      Returns:
      The animation type that is assigned to the component
    • removeAnimation

      public DropDownButton removeAnimation()
      Description copied from interface: Animatable
      Removes animation from the component
      Specified by:
      removeAnimation in interface Animatable<DropDownButton>
      Returns:
      The component
    • addAnimationStartHandler

      public DropDownButton addAnimationStartHandler(AnimationStartEventHandler handler)
      Description copied from interface: Animatable
      Adds an animation start event handler to the component. This handler is used, when the animation has starts.
      Specified by:
      addAnimationStartHandler in interface Animatable<DropDownButton>
      Parameters:
      handler - The AnimationStartEventHandler implementation
      Returns:
      The component
      See Also:
    • addAnimationEndHandler

      public DropDownButton addAnimationEndHandler(AnimationEndEventHandler handler)
      Description copied from interface: Animatable
      Adds an animation end event handler to the component. This handler is used, when the animation has ended.
      Specified by:
      addAnimationEndHandler in interface Animatable<DropDownButton>
      Parameters:
      handler - The AnimationEndEventHandler implementation
      Returns:
      The component
      See Also:
    • addClickHandler

      public DropDownButton addClickHandler(ClickEventHandler handler)

      Adds a click event handler to the button.

      If you add a click event handler to the dropdown menu item, the menu opens only by clicking on the dropdown icon. If you click on the button, only the specified event handler runs.

      Specified by:
      addClickHandler in interface Clickable<DropDownButton>
      Parameters:
      handler - The ClickEventHandler implementation
      Returns:
      The component
      See Also:
    • addDoubleClickHandler

      public DropDownButton addDoubleClickHandler(DoubleClickEventHandler handler)

      Adds a double click event handler to the button.

      If you add a click event handler to the dropdown menu item, the menu opens only by clicking on the dropdown icon. If you click on the button, only the specified event handler runs.

      Specified by:
      addDoubleClickHandler in interface Clickable<DropDownButton>
      Parameters:
      handler - A DoubleClickEventHandler implementation
      Returns:
      The component
      See Also:
    • addHotKey

      public DropDownButton addHotKey(int hotKey)
      Description copied from interface: HandleHotKey
      Adds the specified hot key to the component. If the user presses the hot key, the component's Click event handler will be fired. If the hot key was assigned to an input field, the field will gain focus.
      Specified by:
      addHotKey in interface HandleHotKey<DropDownButton>
      Parameters:
      hotKey - The button combination, that will be assigned to the component. This button combination can be specified, by using the Key class' constants. If the hot key is a combination of two buttons, then the values must be added. For example, the CTRL+S combination is specified as KEY.CTRL + KEY.KEY_S
      Returns:
      The component
    • addHotKey

      public DropDownButton addHotKey(int hotKey, HotKeyEventHandler handler)
      Description copied from interface: HandleHotKey
      Adds the specified hot key to the component. If the user presses the hot key, the specified event handler will be fired
      Specified by:
      addHotKey in interface HandleHotKey<DropDownButton>
      Parameters:
      hotKey - The button combination, that will be assigned to the component. This button combination can be specified, by using the Key class' constants. If the hot key is a combination of two buttons, then the values must be added. For example, the CTRL+S combination is specified as KEY.CTRL + KEY.KEY_S
      handler - The HotKeyEventHandler implementation
      Returns:
      The component
      See Also:
    • removeHotKey

      public DropDownButton removeHotKey(int hotKey)
      Description copied from interface: HandleHotKey
      Removes the specified hot key from the component
      Specified by:
      removeHotKey in interface HandleHotKey<DropDownButton>
      Parameters:
      hotKey - The button combination assigned to the component. This button combination can be specified, by using the Key class' constants. If the hot key is a combination of two buttons, then the values must be added. For example, the CTRL+S combination is specified as KEY.CTRL + KEY.KEY_S
      Returns:
      The component
    • removeHotKeys

      public DropDownButton removeHotKeys()
      Description copied from interface: HandleHotKey
      Removes every hot key from the component
      Specified by:
      removeHotKeys in interface HandleHotKey<DropDownButton>
      Returns:
      The component
    • addMouseDownHandler

      public DropDownButton addMouseDownHandler(MouseDownEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse button down event handler to the component. The handler will run when the user presses a mouse button while having the mouse in the component
      Specified by:
      addMouseDownHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseDownEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseEnterHandler

      public DropDownButton addMouseEnterHandler(MouseEnterEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse enter event handler to the component. The handler will run when the mouse cursor enters the component, i.e. when the user hovers with the mouse over the component.
      Specified by:
      addMouseEnterHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseEnterEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseLeaveHandler

      public DropDownButton addMouseLeaveHandler(MouseLeaveEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse leave event handler to the component. The handler will run when the mouse cursor leaves the component.
      Specified by:
      addMouseLeaveHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseLeaveEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseMoveHandler

      public DropDownButton addMouseMoveHandler(MouseMoveEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse move event handler to the component. The handler will run when the mouse cursor moves inside the component area.
      Specified by:
      addMouseMoveHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseMoveEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseOutHandler

      public DropDownButton addMouseOutHandler(MouseOutEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse out event handler to the component. The handler will run when the mouse cursor moves out of a component
      Specified by:
      addMouseOutHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseOutEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseOverHandler

      public DropDownButton addMouseOverHandler(MouseOverEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse over event handler to the component. The handler will run when the mouse cursor moves over a component
      Specified by:
      addMouseOverHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseOverEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseUpHandler

      public DropDownButton addMouseUpHandler(MouseUpEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse up event handler to the component. The handler will run when the mouse button is released, while the cursor is in a component.
      Specified by:
      addMouseUpHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseUpEventHandler implementation
      Returns:
      The component
      See Also:
    • addMouseWheelHandler

      public DropDownButton addMouseWheelHandler(MouseWheelEventHandler handler)
      Description copied from interface: HandleMouseEvents
      Adds a mouse wheel event handler to the component. The handler will run when the mouse wheel is used (scrolling), while the cursor is in a component
      Specified by:
      addMouseWheelHandler in interface HandleMouseEvents<DropDownButton>
      Parameters:
      handler - The MouseWheelEventHandler implementation
      Returns:
      The component
      See Also:
    • addTouchCancelHandler

      public DropDownButton addTouchCancelHandler(TouchCancelEventHandler handler)
      Description copied from interface: Touchable
      Adds a touch cancel event handler to the component. The event is fired when the touch event is cancelled by the device. Each device cancels the touch event differently, and certain devices use this event. If the device fires the event, the event handler will also be called.
      Specified by:
      addTouchCancelHandler in interface Touchable<DropDownButton>
      Parameters:
      handler - The TouchCancelEventHandler implementation
      Returns:
      The component
      See Also:
    • addTouchEndHandler

      public DropDownButton addTouchEndHandler(TouchEndEventHandler handler)
      Description copied from interface: Touchable
      Adds a touch end event handler to the component. The specified handler will be used, when the user takes their finger off the component.
      Specified by:
      addTouchEndHandler in interface Touchable<DropDownButton>
      Parameters:
      handler - The TouchEndEventHandler implementation
      Returns:
      The component
      See Also:
    • addTouchMoveHandler

      public DropDownButton addTouchMoveHandler(TouchMoveEventHandler handler)
      Description copied from interface: Touchable
      Adds a touch move event handler. The handler will be used, when the user moves their finger on the screen.
      Specified by:
      addTouchMoveHandler in interface Touchable<DropDownButton>
      Parameters:
      handler - The TouchMoveEventHandler implementation
      Returns:
      The component
      See Also:
    • addTouchStartHandler

      public DropDownButton addTouchStartHandler(TouchStartEventHandler handler)
      Description copied from interface: Touchable
      Adds a touch start event handler to the component. The handler will be used, when the user touches component.
      Specified by:
      addTouchStartHandler in interface Touchable<DropDownButton>
      Parameters:
      handler - The TouchStartEventHandler implementation
      Returns:
      The component
      See Also:
    • setMenuOffset

      public DropDownButton setMenuOffset(int offsetX, int offsetY)
      Sets the X and Y axis offset of the dropdown menu.
      Parameters:
      offsetX - X axis offset in pixels
      offsetY - Y axis offset in pixels
      Returns:
      Button component
    • setMenuAlignament

      public DropDownButton setMenuAlignament(DropDownAlignament align)
      Dropdown menu alignment relative to the button. By default, the dropdown menu is displayed to the left from the button.
      Parameters:
      align - Dropdown menu alignment If null is specified, the menu opens on the left side of the button. Available alignment types are listed in the enum DropDownAlignament
      Returns:
      Button component
    • getMenuAlignament

      public DropDownAlignament getMenuAlignament()
      Gets the dropdown menu alignment.
      Returns:
      Dropdown menu alignment
    • clear

      public final DropDownButton clear()
      Removes all components, headers, borders and menu items from the dropdown menu.
    • 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<DropDownButton>
      Returns:
      If the componentwas drawn, true, otherwise false