01: /*
02: * ConsoleStatusBar.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.gui.components;
13:
14: import java.io.PrintStream;
15: import workbench.interfaces.StatusBar;
16: import workbench.util.StringUtil;
17:
18: /**
19: *
20: * @author support@sql-workbench.net
21: */
22: public class ConsoleStatusBar implements StatusBar {
23: private PrintStream output;
24: private String lastMessage;
25:
26: public ConsoleStatusBar() {
27: output = System.out;
28: }
29:
30: private String createDeleteString(String original) {
31: if (original == null)
32: return StringUtil.EMPTY_STRING;
33: StringBuilder result = new StringBuilder(original.length() + 2);
34: result.append('\r');
35: for (int i = 0; i < original.length(); i++) {
36: result.append(' ');
37: }
38: result.append('\r');
39: return result.toString();
40: }
41:
42: public void setStatusMessage(String message) {
43: if (lastMessage != null) {
44: output.print(createDeleteString(lastMessage));
45: }
46: output.print(message);
47: this .lastMessage = message;
48: }
49:
50: public void clearStatusMessage() {
51: if (lastMessage != null) {
52: output.print(createDeleteString(lastMessage));
53: lastMessage = null;
54: }
55: }
56:
57: public void repaint() {
58: }
59:
60: public String getText() {
61: return lastMessage;
62: }
63:
64: }
|