java.lang.Object
com.googlecode.lanterna.gui2.AbstractComponent<ProgressBar>
com.googlecode.lanterna.gui2.ProgressBar
- All Implemented Interfaces:
Component
,TextGUIElement
This GUI element gives a visual indication of how far a process of some sort has progressed at any given time. It's
a classic user interface component that most people are familiar with. It works based on a scale expressed as having
a minimum, a maximum and a current value somewhere along that range. When the current
value is the same as the minimum, the progress indication is empty, at 0%. If the value is the
same as the maximum, the progress indication is filled, at 100%. Any value in between the
minimum and the maximum will be indicated proportionally to where on this range between minimum
and maximum it is.
In order to add a label to the progress bar, for example to print the % completed, this class supports adding a
format specification. This label format, before drawing, will be passed in through a String.format(..)
with
the current progress of value from minimum to maximum expressed as a float
passed in as
a single vararg parameter. This parameter will be scaled from 0.0f to 100.0f. By default, the label format is set to
"%2.0f%%" which becomes a simple percentage string when formatted.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Default implementation of the progress bar GUI component renderer.static class
This progress bar renderer implementation takes slightly more space (three rows) and draws a slightly more complicates progress bar with fixed measurers to mark 25%, 50% and 75%. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new progress bar initially defined with a range from 0 to 100.ProgressBar
(int min, int max) Creates a new progress bar with a defined range of minimum to maximumProgressBar
(int min, int max, int preferredWidth) Creates a new progress bar with a defined range of minimum to maximum and also with a hint as to how wide the progress bar should be drawn -
Method Summary
Modifier and TypeMethodDescriptionprotected ComponentRenderer
<ProgressBar> When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).Returns the label of this progress bar formatted throughString.format(..)
with the current progress value.Returns the current label format string which is the template for what the progress bar would like to be the label printed.int
getMax()
Returns the current maximum value for this progress barint
getMin()
Returns the current minimum value for this progress barint
Returns the preferred width of the progress bar component, in number of columns.float
Returns the current progress of this progress bar's value from minimum to maximum, expressed as a float from 0.0f to 1.0f.int
getValue()
Returns the current value of this progress bar, which represents how complete the progress indication is.setLabelFormat
(String labelFormat) Sets the label format this progress bar should use when the component is drawn.setMax
(int max) Updates the maximum value of this progress bar.setMin
(int min) Updates the minimum value of this progress bar.void
setPreferredWidth
(int preferredWidth) Updated the preferred width hint, which tells the renderer how wide this progress bar would like to be.setValue
(int value) Updates the value of this progress bar, which will update the visual state.Methods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
addTo, calculatePreferredSize, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, invalidate, isInside, isInvalid, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
-
Field Details
-
min
private int min -
max
private int max -
value
private int value -
preferredWidth
private int preferredWidth -
labelFormat
-
-
Constructor Details
-
ProgressBar
public ProgressBar()Creates a new progress bar initially defined with a range from 0 to 100. The -
ProgressBar
public ProgressBar(int min, int max) Creates a new progress bar with a defined range of minimum to maximum- Parameters:
min
- The minimum value of this progress barmax
- The maximum value of this progress bar
-
ProgressBar
public ProgressBar(int min, int max, int preferredWidth) Creates a new progress bar with a defined range of minimum to maximum and also with a hint as to how wide the progress bar should be drawn- Parameters:
min
- The minimum value of this progress barmax
- The maximum value of this progress barpreferredWidth
- Width size hint, in number of columns, for this progress bar. The renderer may choose to not use this hint. 0 or less means that there is no hint.
-
-
Method Details
-
getMin
public int getMin()Returns the current minimum value for this progress bar- Returns:
- The minimum value of this progress bar
-
setMin
Updates the minimum value of this progress bar. If the current maximum and/or value are smaller than this new minimum, they are automatically adjusted so that the range is still valid.- Parameters:
min
- New minimum value to assign to this progress bar- Returns:
- Itself
-
getMax
public int getMax()Returns the current maximum value for this progress bar- Returns:
- The maximum value of this progress bar
-
setMax
Updates the maximum value of this progress bar. If the current minimum and/or value are greater than this new maximum, they are automatically adjusted so that the range is still valid.- Parameters:
max
- New maximum value to assign to this progress bar- Returns:
- Itself
-
getValue
public int getValue()Returns the current value of this progress bar, which represents how complete the progress indication is.- Returns:
- The progress value of this progress bar
-
setValue
Updates the value of this progress bar, which will update the visual state. If the value passed in is outside the minimum-maximum range, it is automatically adjusted.- Parameters:
value
- New value of the progress bar- Returns:
- Itself
-
getPreferredWidth
public int getPreferredWidth()Returns the preferred width of the progress bar component, in number of columns. If 0 or less, it should be interpreted as no preference on width and it's up to the renderer to decide.- Returns:
- Preferred width this progress bar would like to have, or 0 (or less) if no preference
-
setPreferredWidth
public void setPreferredWidth(int preferredWidth) Updated the preferred width hint, which tells the renderer how wide this progress bar would like to be. If called with 0 (or less), it means no preference on width and the renderer will have to figure out on its own how wide to make it.- Parameters:
preferredWidth
- New preferred width in number of columns, or 0 if no preference
-
getLabelFormat
Returns the current label format string which is the template for what the progress bar would like to be the label printed. Exactly how this label is printed depends on the renderer, but the default renderer will print the label centered in the middle of the progress indication.- Returns:
- The label format template string this progress bar is currently using
-
setLabelFormat
Sets the label format this progress bar should use when the component is drawn. The string would be compatible withString.format(..)
, the class will pass the string through that method and pass in the current progress as a single vararg parameter (passed in as afloat
in the range of 0.0f to 100.0f). Setting this format string to null or empty string will turn off the label rendering.- Parameters:
labelFormat
- Label format to use when drawing the progress bar, ornull
to disable- Returns:
- Itself
-
getProgress
public float getProgress()Returns the current progress of this progress bar's value from minimum to maximum, expressed as a float from 0.0f to 1.0f.- Returns:
- current progress of this progress bar expressed as a float from 0.0f to 1.0f.
-
getFormattedLabel
Returns the label of this progress bar formatted throughString.format(..)
with the current progress value.- Returns:
- The progress bar label formatted with the current progress
-
createDefaultRenderer
Description copied from class:AbstractComponent
When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRenderer
in classAbstractComponent<ProgressBar>
- Returns:
- Renderer to use when sizing and drawing this component
-