2 * Jexer - Java Text User Interface
4 * License: LGPLv3 or later
6 * This module is licensed under the GNU Lesser General Public License
7 * Version 3. Please see the file "COPYING" in this directory for more
8 * information about the GNU Lesser General Public License Version 3.
10 * Copyright (C) 2015 Kevin Lamonte
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public License
14 * as published by the Free Software Foundation; either version 3 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this program; if not, see
24 * http://www.gnu.org/licenses/, or write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
33 import jexer
.bits
.CellAttributes
;
34 import jexer
.bits
.GraphicsChars
;
37 * TProgressBar implements a simple progress bar.
39 public final class TProgressBar
extends TWidget
{
42 * Value that corresponds to 0% progress.
44 private int minValue
= 0;
47 * Get the value that corresponds to 0% progress.
49 * @return the value that corresponds to 0% progress
51 public int getMinValue() {
56 * Set the value that corresponds to 0% progress.
58 * @param minValue the value that corresponds to 0% progress
60 public void setMinValue(final int minValue
) {
61 this.minValue
= minValue
;
65 * Value that corresponds to 100% progress.
67 private int maxValue
= 100;
70 * Get the value that corresponds to 100% progress.
72 * @return the value that corresponds to 100% progress
74 public int getMaxValue() {
79 * Set the value that corresponds to 100% progress.
81 * @param maxValue the value that corresponds to 100% progress
83 public void setMaxValue(final int maxValue
) {
84 this.maxValue
= maxValue
;
88 * Current value of the progress.
90 private int value
= 0;
93 * Get the current value of the progress.
95 * @return the current value of the progress
97 public int getValue() {
102 * Set the current value of the progress.
104 * @param value the current value of the progress
106 public void setValue(final int value
) {
111 * Public constructor.
113 * @param parent parent widget
114 * @param x column relative to parent
115 * @param y row relative to parent
116 * @param width width of progress bar
117 * @param value initial value of percent complete
119 public TProgressBar(final TWidget parent
, final int x
, final int y
,
120 final int width
, final int value
) {
122 // Set parent and window
123 super(parent
, false, x
, y
, width
, 1);
129 * Draw a static progress bar.
133 CellAttributes completeColor
= getTheme().getColor("tprogressbar.complete");
134 CellAttributes incompleteColor
= getTheme().getColor("tprogressbar.incomplete");
136 float progress
= ((float)value
- minValue
) / ((float)maxValue
- minValue
);
137 int progressInt
= (int)(progress
* 100);
138 int progressUnit
= 100 / (getWidth() - 2);
140 getScreen().putCharXY(0, 0, GraphicsChars
.CP437
[0xC3], incompleteColor
);
141 for (int i
= 0; i
< getWidth() - 2; i
++) {
142 float iProgress
= (float)i
/ (getWidth() - 2);
143 int iProgressInt
= (int)(iProgress
* 100);
144 if (iProgressInt
<= progressInt
- progressUnit
) {
145 getScreen().putCharXY(i
+ 1, 0, GraphicsChars
.BOX
,
148 getScreen().putCharXY(i
+ 1, 0, GraphicsChars
.SINGLE_BAR
,
152 if (value
>= maxValue
) {
153 getScreen().putCharXY(getWidth() - 2, 0, GraphicsChars
.BOX
,
156 getScreen().putCharXY(getWidth() - 2, 0, GraphicsChars
.SINGLE_BAR
,
159 getScreen().putCharXY(getWidth() - 1, 0, GraphicsChars
.CP437
[0xB4],