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