- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<Label>
-
- com.googlecode.lanterna.gui2.Label
-
- com.googlecode.lanterna.gui2.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()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAnimatedLabel.AnimationTimerTask
-
Field Summary
Fields Modifier and Type Field Description private TerminalSizecombinedMaximumPreferredSizeprivate intcurrentFrameprivate java.util.List<java.lang.String[]>framesprivate static java.util.WeakHashMap<AnimatedLabel,java.util.TimerTask>SCHEDULED_TASKSprivate static java.util.TimerTIMER
-
Constructor Summary
Constructors Constructor Description AnimatedLabel(java.lang.String firstFrameText)Creates a new animated label, initially set to one frame.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description AnimatedLabeladdFrame(java.lang.String text)Adds one more frame at the end of the list of framesprotected TerminalSizecalculatePreferredSize()Invokes the component renderer's size calculation logic and returns the result.private static voidcanCloseTimer()static AnimatedLabelcreateClassicSpinningLine()Creates 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(java.lang.String[] lines)voidnextFrame()Advances the animated label to the next frame.voidonRemoved(Container container)Called by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!private static voidremoveTaskFromTimer(AnimatedLabel animatedLabel)AnimatedLabelstartAnimation(long millisecondsPerFrame)Starts the animation thread which will periodically callnextFrame()at the interval specified by themillisecondsPerFrameparameter.AnimatedLabelstopAnimation()Halts the animation thread and the label will stop at whatever was the current frame at the time when this was called-
Methods 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 Detail
-
TIMER
private static java.util.Timer TIMER
-
SCHEDULED_TASKS
private static final java.util.WeakHashMap<AnimatedLabel,java.util.TimerTask> SCHEDULED_TASKS
-
frames
private final java.util.List<java.lang.String[]> frames
-
combinedMaximumPreferredSize
private TerminalSize combinedMaximumPreferredSize
-
currentFrame
private int currentFrame
-
-
Constructor Detail
-
AnimatedLabel
public AnimatedLabel(java.lang.String firstFrameText)
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 Detail
-
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:
AnimatedLabelinstance 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:
AnimatedLabelinstance which is setup to show a spinning bar
-
calculatePreferredSize
protected TerminalSize 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
public AnimatedLabel addFrame(java.lang.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(java.lang.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: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
public AnimatedLabel startAnimation(long millisecondsPerFrame)
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
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()
-
-