1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.slf4j.migrator.internal;
26
27 import java.io.File;
28 import java.io.IOException;
29
30 import org.slf4j.migrator.helper.Abbreviator;
31
32 public class ProgressListenerImpl implements ProgressListener {
33
34 static final int TARGET_FILE_LENGTH = 85;
35 static final int UPDATE_THRESHOLD = 100;
36
37 int addFileCount = 0;
38 int scanFileCount = 0;
39 int inplaceConversionCount = 0;
40 final MigratorFrame frame;
41
42 Abbreviator abbr;
43
44 long lastUpdate = 0;
45
46
47
48 public ProgressListenerImpl(File projectFolder, MigratorFrame frame) {
49 this.frame = frame;
50 this.abbr = new Abbreviator((int) projectFolder.length(),
51 TARGET_FILE_LENGTH, File.separatorChar);
52 }
53
54 public void onMigrationBegin() {
55 frame.disableInput();
56 }
57
58 boolean isTooSoon() {
59 long now = System.currentTimeMillis();
60 if(now-lastUpdate < UPDATE_THRESHOLD) {
61 return true;
62 } else {
63 lastUpdate = now;
64 return false;
65 }
66 }
67
68 public void onDirectory(File file) {
69 if(isTooSoon()) return;
70
71 String abbreviatedName = getShortName(file);
72 frame.otherLabel.setText("<html><p>Searching folder [" + abbreviatedName
73 + "]<p>Found " + addFileCount + " java files to scan.</html>");
74 }
75
76 public void onDone() {
77 frame.progressBar.setVisible(false);
78 frame.otherLabel.setText("<html><font color='BLUE'>Scanned " + addFileCount
79 + " java files, " + inplaceConversionCount
80 + " files were modified.</font></html>");
81
82 frame.migrateButton.setActionCommand(MigratorFrame.EXIT_COMMAND);
83 frame.migrateButton.setText("Exit");
84 frame.migrateButton
85 .setToolTipText("Click on this button to exit this application.");
86 frame.migrateButton.setEnabled(true);
87
88 }
89
90 public void onFileAddition(File file) {
91 addFileCount++;
92 }
93
94 public void onFileScan(File file) {
95
96 scanFileCount++;
97 if(isTooSoon()) return;
98 String abbreviatedName = getShortName(file);
99
100 frame.otherLabel.setText("<html><p>Scanning file [" + abbreviatedName
101 + "]<p></html>");
102
103
104
105 frame.progressBar.setValue(scanFileCount);
106 }
107
108 public void onInplaceConversion(File file) {
109 inplaceConversionCount++;
110 }
111
112 String getShortName(File file) {
113 try {
114 return abbr.abbreviate(file.getCanonicalPath());
115 } catch (IOException e) {
116 return file.toString();
117 }
118 }
119
120 public void onFileScanBegin() {
121 frame.progressBar.setMaximum(addFileCount);
122 frame.progressBar.setValue(0);
123 frame.progressBar.setVisible(true);
124 }
125
126 }