01 /*
02 * ProgressPrinter.java
03 *
04 * Copyright (c) 1995-2010, The University of Sheffield. See the file
05 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
06 *
07 * This file is part of GATE (see http://gate.ac.uk/), and is free
08 * software, licenced under the GNU Library General Public License,
09 * Version 2, June 1991 (in the distribution as file licence.html,
10 * and also available at http://gate.ac.uk/gate/licence.html).
11 *
12 * Valentin Tablan, 21/07/2000
13 *
14 * $Id: ProgressPrinter.java 12006 2009-12-01 17:24:28Z thomas_heitz $
15 */
16
17 package gate.util;
18
19 import java.io.PrintStream;
20
21 import gate.event.ProgressListener;
22
23
24 /**
25 * Class used to simulate the behaviour of a progress bar on an OutputStream.
26 *
27 */
28 public class ProgressPrinter implements ProgressListener {
29
30 /** Debug flag
31 */
32 private static final boolean DEBUG = false;
33
34 /**
35 * Constructor.
36 *
37 * @param out the stream used for output
38 * @param numberOfSteps the number of steps until the process is over (the
39 * number of characters printed for a full run)
40 */
41 public ProgressPrinter(PrintStream out, int numberOfSteps) {
42 this.out = out;
43 this.numberOfSteps = numberOfSteps;
44 }
45
46 /**
47 * Constructor. Uses the default number of steps.
48 *
49 * @param out
50 */
51 public ProgressPrinter(PrintStream out) {
52 this.out = out;
53 }
54
55 public void processFinished() {
56 for(int i = currentValue; i < numberOfSteps; i++) {
57 out.print("#");
58 }
59 out.println("]");
60 currentValue = 0;
61 started = false;
62 }
63
64 public void progressChanged(int newValue) {
65 if(!started){
66 out.print("[");
67 started = true;
68 }
69 newValue = newValue * numberOfSteps / 100;
70 if(newValue > currentValue){
71 for(int i = currentValue; i < newValue; i++) {
72 out.print("#");
73 }
74 currentValue = newValue;
75 }
76 }
77
78 /** *
79 */
80 int currentValue = 0;
81
82 /** *
83 */
84 int numberOfSteps = 70;
85
86 /** */
87 PrintStream out;
88
89 /** */
90 boolean started = false;
91
92 } // class ProgressPrinter
|