Class LoadButton

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

The button component, that when it's pressed, the text on the button is replaced with a loading animation. When the loading has finished, the animation will stop automatically, and it will be replaced by the button text. During the animation, the user can't press the button again, as it becomes inactive during the loading process.

The animation can be started manually by using the start method. It can be stopped by using the stop method.

The component supports the use of animations that can be used for the button's appearance or disappearance. To do this, use the setAnimation method, where the type can be specified. For the applicable animations, 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
  • Field Details

    • text

      protected String text
    • icon

      protected Icon icon
    • image

      protected Image image
  • Constructor Details

    • LoadButton

      public LoadButton(String text, LoadButtonAnimation animation)
      Creates a new load button with the specified text and animation.
      Parameters:
      text - The button text
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • LoadButton

      public LoadButton(String id, String text, LoadButtonAnimation animation)
      Creates a new load button with the specified text and animation.
      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
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • LoadButton

      public LoadButton(String text, LoadButtonAnimation animation, StyleElement... styles)
      Creates a new load button with the specified text, animation and style(s)
      Parameters:
      text - The button text
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      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.
    • LoadButton

      public LoadButton(String id, String text, LoadButtonAnimation animation, StyleElement... styles)
      Creates a new load button with the specified text, animation 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.)
      text - The button text
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      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.
    • LoadButton

      public LoadButton(Icon icon, String text, LoadButtonAnimation animation, StyleElement... styles)
      Creates a new load button with the specified icon, text, animation and style(s)
      Parameters:
      icon - The icon of the button. For the applicable icons, see the Icon enum.
      text - The button text
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      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.
    • LoadButton

      public LoadButton(String id, Icon icon, String text, LoadButtonAnimation animation, StyleElement... styles)
      Creates a new load button with the specified icon, text, animation 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
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      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<LoadButton>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • setText

      public LoadButton 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 LoadButton 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 LoadButton 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 LoadButton 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 LoadButton 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
    • setAnimation

      public final LoadButton setAnimation(LoadButtonAnimation animation)
      Sets the loading animation type
      Parameters:
      animation - The loading animation. For the applicable animations, see the LoadButtonAnimation enum.
      Returns:
      The Load Button component
    • setSpinnerColor

      public LoadButton setSpinnerColor(Color color)
      Sets the loading spinner's color. Default is white
      Parameters:
      color - The loading spinner's color. Available colors are listed in the enum Color. You can use any standard HTML colors.
      Returns:
      The Load Button component
    • start

      public final void start()
      Starts the loading animation.
      If the process starts on a click event, no need to start it manually, it will be automatic.
    • stop

      public final void stop()
      Stops the loading animation
      If the process started by a click event, no need to stop it manually, it will be automatic.
    • addClickHandler

      public LoadButton addClickHandler(ClickEventHandler handler)
      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<LoadButton>
      Parameters:
      handler - The ClickEventHandler implementation
      Returns:
      The component
      See Also:
    • addDoubleClickHandler

      public LoadButton addDoubleClickHandler(DoubleClickEventHandler handler)
      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<LoadButton>
      Parameters:
      handler - A DoubleClickEventHandler implementation
      Returns:
      The component
      See Also:
    • onDefaultClickHandler

      public void onDefaultClickHandler(MouseEvent event)
      Parameters:
      event - The event object
    • onDefaultDoubleClickHandler

      public void onDefaultDoubleClickHandler(MouseEvent event)
      Parameters:
      event - The event object
    • 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<LoadButton>
      Returns:
      If the componentwas drawn, true, otherwise false