KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > interactive > ConsoleProgressIndicator


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.interactive;
17
18 import java.text.DecimalFormat JavaDoc;
19 import java.util.logging.Logger JavaDoc;
20
21
22 /**
23  * Progress indicator to send out
24  *
25  * @author Fyodor Kupolov
26  * @version 1.0
27  */

28 public class ConsoleProgressIndicator extends ProgressIndicatorBase {
29     private static final Logger JavaDoc LOG = Logger.getLogger(ConsoleProgressIndicator.class.getName());
30     private final DecimalFormat JavaDoc decimalFormat = new DecimalFormat JavaDoc("###");
31     private String JavaDoc title;
32
33     public ConsoleProgressIndicator(String JavaDoc title) {
34         this.title = title;
35     }
36
37     public ConsoleProgressIndicator() {
38     }
39
40     protected void show(final String JavaDoc label, final double percentage) {
41         StringBuilder JavaDoc r = new StringBuilder JavaDoc(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 JavaDoc label) {
63         LOG.info(((title == null) ? "" : title + ".") + "Complete");
64     }
65 }
66
Popular Tags