diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-07-03 19:09:31 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-07-03 19:09:31 +0100 |
| commit | 39b60d4225f5efa4e0287a2c6ce69d90391c69db (patch) | |
| tree | 18c5b05726f39baa4d3ca8b228e24ad1f0182f2a /src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java | |
| parent | 133dab6e21f263df2baca913d3d0b7a4fd152d08 (diff) | |
| download | ACQuA-39b60d4225f5efa4e0287a2c6ce69d90391c69db.tar.gz ACQuA-39b60d4225f5efa4e0287a2c6ce69d90391c69db.zip | |
Many little changes.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java b/src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java new file mode 100644 index 0000000..3c4aad7 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/util/SimpleProgressBar.java | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util; | ||
| 2 | |||
| 3 | import uk.ac.ox.cs.pagoda.util.disposable.Disposable; | ||
| 4 | |||
| 5 | public class SimpleProgressBar extends Disposable { | ||
| 6 | |||
| 7 | private final String name; | ||
| 8 | private int lastPercent; | ||
| 9 | private int maxValue; | ||
| 10 | |||
| 11 | public SimpleProgressBar() { | ||
| 12 | this(""); | ||
| 13 | } | ||
| 14 | |||
| 15 | public SimpleProgressBar(String name) { | ||
| 16 | this(name, 100); | ||
| 17 | } | ||
| 18 | |||
| 19 | public SimpleProgressBar(String name, int maxValue) { | ||
| 20 | this.name = name; | ||
| 21 | this.maxValue = maxValue; | ||
| 22 | } | ||
| 23 | |||
| 24 | public void update(int value) { | ||
| 25 | int percent = value * 100 / maxValue; | ||
| 26 | StringBuilder template = new StringBuilder("\r" + name + " ["); | ||
| 27 | for (int i = 0; i < 50; i++) { | ||
| 28 | if (i < percent * .5) { | ||
| 29 | template.append("="); | ||
| 30 | } else if (i == percent * .5) { | ||
| 31 | template.append(">"); | ||
| 32 | } else { | ||
| 33 | template.append(" "); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | template.append("] %s "); | ||
| 37 | System.out.printf(template.toString(), percent + "%"); | ||
| 38 | System.out.flush(); | ||
| 39 | lastPercent = percent; | ||
| 40 | } | ||
| 41 | |||
| 42 | @Override | ||
| 43 | public void dispose() { | ||
| 44 | super.dispose(); | ||
| 45 | |||
| 46 | System.out.println(); | ||
| 47 | } | ||
| 48 | } | ||
