1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.component;
21
22 import javax.swing.JLabel;
23 import javax.swing.SwingUtilities;
24
25 /***
26 * Provides a text based progress monitor.
27 */
28 public class TextProgressMonitor extends ProgressMonitorAdapter {
29
30
31
32 private JLabel label;
33 private int min;
34 private int max;
35 private int value;
36 private double percent;
37
38
39
40 public TextProgressMonitor(JLabel label)
41 {
42 this.label = label;
43 }
44
45
46
47 /***
48 * Does nothing.
49 */
50 public void done()
51 {
52 }
53
54 /***
55 * Returns false.
56 */
57 public boolean isCancelled()
58 {
59 return false;
60 }
61
62 /***
63 * Does nothing.
64 */
65 public void setCancelEnabled(boolean enabled)
66 {
67 }
68
69 public void setMaximum(int max)
70 {
71 this.max = max;
72 }
73
74 public void setMinimum(int min)
75 {
76 this.min = min;
77 }
78
79 public void setPercent(double percent)
80 {
81 this.percent = percent;
82 }
83
84 public void setValue(int value)
85 {
86 this.value = value;
87 }
88
89 public void setText(String text)
90 {
91 StringBuffer sb = new StringBuffer(text.length());
92 for (int i = 0; i < text.length() - 1; i++) {
93 if (text.charAt(i) == '%') {
94 char c = text.charAt(i + 1);
95 if (c == 'v') {
96 sb.append(value);
97 }
98 if (c == '%') {
99 sb.append('%');
100 }
101 }
102 else {
103 sb.append(text.charAt(i));
104 }
105 }
106
107 final String s = text.toString();
108 Runnable runner = new Runnable()
109 {
110 public void run()
111 {
112 label.setText(s);
113 }
114 };
115 SwingUtilities.invokeLater(runner);
116 }
117
118 }