Class AnimatedLabel

All Implemented Interfaces:
Component, TextGUIElement

public class AnimatedLabel extends Label
This is a special label that contains not just a single text to display but a number of frames that are cycled through. The class will manage a timer on its own and ensure the label is updated and redrawn. There is a static helper method available to create the classic "spinning bar": createClassicSpinningLine()
  • Field Details

  • Constructor Details

    • AnimatedLabel

      public AnimatedLabel(String firstFrameText)
      Creates a new animated label, initially set to one frame. You will need to add more frames and call startAnimation() for this to start moving.
      Parameters:
      firstFrameText - The content of the label at the first frame
  • Method Details

    • createClassicSpinningLine

      public static AnimatedLabel createClassicSpinningLine()
      Creates a classic spinning bar which can be used to signal to the user that an operation in is process.
      Returns:
      AnimatedLabel instance which is setup to show a spinning bar
    • createClassicSpinningLine

      public static AnimatedLabel createClassicSpinningLine(int speed)
      Creates a classic spinning bar which can be used to signal to the user that an operation in is process.
      Parameters:
      speed - Delay in between each frame
      Returns:
      AnimatedLabel instance which is setup to show a spinning bar
    • calculatePreferredSize

      protected TerminalSize calculatePreferredSize()
      Description copied from class: AbstractComponent
      Invokes the component renderer's size calculation logic and returns the result. This value represents the preferred size and isn't necessarily what it will eventually be assigned later on.
      Overrides:
      calculatePreferredSize in class AbstractComponent<Label>
      Returns:
      Size that the component renderer believes the component should be
    • addFrame

      public AnimatedLabel addFrame(String text)
      Adds one more frame at the end of the list of frames
      Parameters:
      text - Text to use for the label at this frame
      Returns:
      Itself
    • ensurePreferredSize

      private void ensurePreferredSize(String[] lines)
    • nextFrame

      public void nextFrame()
      Advances the animated label to the next frame. You normally don't need to call this manually as it will be done by the animation thread.
    • onRemoved

      public void onRemoved(Container container)
      Description copied from interface: Component
      Called by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!
      Specified by:
      onRemoved in interface Component
      Overrides:
      onRemoved in class AbstractComponent<Label>
      Parameters:
      container - Container that this component was just removed from
    • startAnimation

      public AnimatedLabel startAnimation(long millisecondsPerFrame)
      Starts the animation thread which will periodically call nextFrame() at the interval specified by the millisecondsPerFrame parameter. After all frames have been cycled through, it will start over from the first frame again.
      Parameters:
      millisecondsPerFrame - The interval in between every frame
      Returns:
      Itself
    • stopAnimation

      public AnimatedLabel stopAnimation()
      Halts the animation thread and the label will stop at whatever was the current frame at the time when this was called
      Returns:
      Itself
    • removeTaskFromTimer

      private static void removeTaskFromTimer(AnimatedLabel animatedLabel)
    • canCloseTimer

      private static void canCloseTimer()