| 1068 | new SwingWorker<Void, Void>() { |
| 1069 | |
| 1070 | @Override |
| 1071 | protected Void doInBackground() throws Exception { |
| 1072 | addPropertyChangeListener(new PropertyChangeListener() { |
| 1073 | public void propertyChange(PropertyChangeEvent evt) { |
| 1074 | if ("progress".equals(evt.getPropertyName())) { |
| 1075 | progressBar.setValue((Integer) evt.getNewValue()); |
| 1076 | } |
| 1077 | } |
| 1078 | }); |
| 1079 | |
| 1080 | long totalSize = 0; |
| 1081 | for (File copyable : copyItems) { |
| 1082 | totalSize += Util.calcSize(copyable); |
| 1083 | } |
| 1084 | |
| 1085 | long progress = 0; |
| 1086 | setProgress(0); |
| 1087 | for (File copyable : copyItems) { |
| 1088 | if (copyable.isDirectory()) { |
| 1089 | copyDir(copyable, |
| 1090 | new File(newFolder, copyable.getName()), |
| 1091 | progress, totalSize); |
| 1092 | progress += Util.calcSize(copyable); |
| 1093 | } else { |
| 1094 | copyFile(copyable, |
| 1095 | new File(newFolder, copyable.getName()), |
| 1096 | progress, totalSize); |
| 1097 | if (Util.calcSize(copyable) < 512 * 1024) { |
| 1098 | // If the file length > 0.5MB, the copyFile() function has |
| 1099 | // been redesigned to change progress every 0.5MB so that |
| 1100 | // the progress bar doesn't stagnate during that time |
| 1101 | progress += Util.calcSize(copyable); |
| 1102 | setProgress((int) (progress * 100L / totalSize)); |
| 1103 | } |
| 1104 | } |
| 1105 | } |
| 1106 | saving.set(false); |
| 1107 | return null; |
| 1108 | } |
| 1109 | |
| 1110 | |
| 1111 | /** |