Class AnimatedLabel
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 TerminalSizeprivate intprivate 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 TerminalSizeInvokes the component renderer's size calculation logic and returns the result.private static voidstatic AnimatedLabelCreates a classic spinning bar which can be used to signal to the user that an operation in is process.static AnimatedLabelcreateClassicSpinningLine(int speed) Creates a classic spinning bar which can be used to signal to the user that an operation in is process.private voidensurePreferredSize(String[] lines) voidAdvances the animated label to the next frame.voidCalled by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!private static voidremoveTaskFromTimer(AnimatedLabel animatedLabel) startAnimation(long millisecondsPerFrame) Starts the animation thread which will periodically callnextFrame()at the interval specified by themillisecondsPerFrameparameter.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 Label
addStyle, createDefaultRenderer, getBackgroundColor, getBounds, getForegroundColor, getLabelWidth, getText, removeStyle, setBackgroundColor, setForegroundColor, setLabelWidth, setLines, setText, splitIntoMultipleLinesMethods inherited from class 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:
AnimatedLabelinstance 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:
AnimatedLabelinstance which is setup to show a spinning bar
-
calculatePreferredSize
Description copied from class:AbstractComponentInvokes 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:
calculatePreferredSizein 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:ComponentCalled by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!- Specified by:
onRemovedin interfaceComponent- Overrides:
onRemovedin 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 themillisecondsPerFrameparameter. 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()
-