1 16 package scriptella.interactive; 17 18 import java.text.DecimalFormat ; 19 import java.util.logging.Logger ; 20 21 22 28 public class ConsoleProgressIndicator extends ProgressIndicatorBase { 29 private static final Logger LOG = Logger.getLogger(ConsoleProgressIndicator.class.getName()); 30 private final DecimalFormat decimalFormat = new DecimalFormat ("###"); 31 private String title; 32 33 public ConsoleProgressIndicator(String title) { 34 this.title = title; 35 } 36 37 public ConsoleProgressIndicator() { 38 } 39 40 protected void show(final String label, final double percentage) { 41 StringBuilder r = new StringBuilder (32); 42 43 if (title != null) { 44 r.append(title); 45 } 46 47 if (label != null) { 48 if (title != null) { 49 r.append("."); 50 } 51 52 r.append(label); 53 } 54 55 r.append(": "); 56 57 r.append(decimalFormat.format(100 * percentage)); 58 r.append('%'); 59 LOG.info(r.toString()); 60 } 61 62 protected void onComplete(final String label) { 63 LOG.info(((title == null) ? "" : title + ".") + "Complete"); 64 } 65 } 66 | Popular Tags |