java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<Label>
com.googlecode.lanterna.gui2.Label
com.googlecode.lanterna.gui2.AnimatedLabel
- All Implemented Interfaces:
Component
,TextGUIElement
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()
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TerminalSize
private int
private static final WeakHashMap
<AnimatedLabel, TimerTask> private static Timer
-
Constructor Summary
ConstructorsConstructorDescriptionAnimatedLabel
(String firstFrameText) Creates a new animated label, initially set to one frame. -
Method Summary
Modifier and TypeMethodDescriptionAdds one more frame at the end of the list of framesprotected TerminalSize
Invokes the component renderer's size calculation logic and returns the result.private static void
static AnimatedLabel
Creates a classic spinning bar which can be used to signal to the user that an operation in is process.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.private void
ensurePreferredSize
(String[] lines) void
Advances the animated label to the next frame.void
Called by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!private static void
removeTaskFromTimer
(AnimatedLabel animatedLabel) startAnimation
(long millisecondsPerFrame) Starts the animation thread which will periodically callnextFrame()
at the interval specified by themillisecondsPerFrame
parameter.Halts the animation thread and the label will stop at whatever was the current frame at the time when this was calledMethods inherited from class com.googlecode.lanterna.gui2.Label
addStyle, createDefaultRenderer, getBackgroundColor, getBounds, getForegroundColor, getLabelWidth, getText, removeStyle, setBackgroundColor, setForegroundColor, setLabelWidth, setLines, setText, splitIntoMultipleLines
Methods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
addTo, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
-
Field Details
-
TIMER
-
SCHEDULED_TASKS
-
frames
-
combinedMaximumPreferredSize
-
currentFrame
private int currentFrame
-
-
Constructor Details
-
AnimatedLabel
Creates a new animated label, initially set to one frame. You will need to add more frames and callstartAnimation()
for this to start moving.- Parameters:
firstFrameText
- The content of the label at the first frame
-
-
Method Details
-
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
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
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 classAbstractComponent<Label>
- Returns:
- Size that the component renderer believes the component should be
-
addFrame
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
-
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
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 interfaceComponent
- Overrides:
onRemoved
in classAbstractComponent<Label>
- Parameters:
container
- Container that this component was just removed from
-
startAnimation
Starts the animation thread which will periodically callnextFrame()
at the interval specified by themillisecondsPerFrame
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
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
-
canCloseTimer
private static void canCloseTimer()
-