Skip to content

Commit

Permalink
使用新的进度条机制
Browse files Browse the repository at this point in the history
  • Loading branch information
ColorsWind committed Apr 3, 2020
1 parent 0134560 commit 6a351f4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 28 deletions.
7 changes: 6 additions & 1 deletion src/net/colors_wind/submitmanager/ConflictStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ public void setSelect(boolean select) {

public static void finish(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Resolving Conflict Completed --------");
task.publishConflict(1, 1);
task.publish(100);

}

public static void preStart(MainWindow mainWindow, ProcessFileTask task) {
task.publish(0);
mainWindow.println("-------- Resolving Conflict Start --------");
}

}
11 changes: 9 additions & 2 deletions src/net/colors_wind/submitmanager/FIleOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void start(MainWindow mainWindow, FormMap form, ProcessFileTask task) {
}

private void publish(ProcessFileTask task, int process, int total) {
task.publishFile(process, total);
task.publish(process, total);
}

private static void savePdf(File targetFile, StudentInfo studentInfo, TrueTypeFont font) throws IOException {
Expand Down Expand Up @@ -102,7 +102,7 @@ private static void savePdf(File targetFile, StudentInfo studentInfo, TrueTypeFo
});
}

public void finish(MainWindow mainWindow) {
public void finish(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- File Opeation Completed --------");
Desktop desktop = Desktop.getDesktop();
mainWindow.println(new StringBuilder("保存文件到: ").append(targetDir.getAbsolutePath()).toString());
Expand All @@ -112,7 +112,14 @@ public void finish(MainWindow mainWindow) {
mainWindow.printlnError("无法打开资源管理器, 请手动查看文件.", e);
e.printStackTrace();
}
task.publish(100);
mainWindow.println("\n\n\n\n");
}


public void preStart(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- File Opeation Start --------");
task.publish(0);
}

}
16 changes: 14 additions & 2 deletions src/net/colors_wind/submitmanager/FormMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,14 @@ public void inputForm(@NonNull File file, @NonNull MainWindow mainWindow) throws
}
}

public void finishForm(MainWindow mainWindow) {
public void preStartForm(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Import Form Start --------");
task.publish(0);
}

public void finishForm(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Import Form Completed --------");
task.publish(50);
}

public void inputFiles(File dir, MainWindow mainWindow) {
Expand All @@ -69,11 +75,17 @@ public void inputFiles(File dir, MainWindow mainWindow) {
}
});
}
public void preStartFiles(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Import Files Start --------");
}

public void finishFiles(MainWindow mainWindow) {
public void finishFiles(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Import Files Completed --------");
task.publish(100);
}





public StudentInfo getStudentInfo(@NonNull String fileName) throws IllegalArgumentException {
Expand Down
11 changes: 8 additions & 3 deletions src/net/colors_wind/submitmanager/ImageOpeator.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void start(Collection<StudentInfo> students, MainWindow mainWindow, Proce
if (IMG_FILTER.accept(null, rawName)) {
try {
entry.setValue(process(entry.getValue()));
} catch (IOException e) {
} catch (Exception e) {
mainWindow.printlnError(
new StringBuilder("将图片 ").append(entry.getValue().getName()).append(" 转为 PDF 时候出现异常: "),
e);
Expand All @@ -58,12 +58,12 @@ public void start(Collection<StudentInfo> students, MainWindow mainWindow, Proce
}

private void publish(ProcessFileTask task, int process, int total) {
task.publishImage(process, total);
task.publish(process, total);
}

public void finish(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Image Opeation Completed --------");
task.publishImage(1, 1);
task.publish(100);
}

private static File process(File file) throws IOException {
Expand All @@ -80,6 +80,11 @@ private static File process(File file) throws IOException {
pdf.close();
return pdfFile;
}

public void preStart(MainWindow mainWindow, ProcessFileTask task) {
mainWindow.println("-------- Image Opeation Start --------");
task.publish(0);
}


}
32 changes: 12 additions & 20 deletions src/net/colors_wind/submitmanager/ProcessFileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ public void run() {
mainWindow.handleTaskStart();
try {
FormMap form = new FormMap();
form.preStartForm(mainWindow, this);
form.inputForm(xlsFile, mainWindow);
form.finishForm(mainWindow);
checkStop();
form.preStartFiles(mainWindow, this);
form.finishForm(mainWindow, this);
checkStop();
form.inputFiles(dataDir, mainWindow);
form.finishFiles(mainWindow);
form.finishFiles(mainWindow, this);
checkStop();
if (Main.OPTIONS.isConvertImage()) {
ImageOpeator image = new ImageOpeator();
image.preStart(mainWindow, this);
image.start(form.getStudents(), mainWindow, this);
image.finish(mainWindow, this);
checkStop();
}
ConflictStrategy.preStart(mainWindow, this);
Main.OPTIONS.getStrategy().resolveConflict(mainWindow, this, form);
ConflictStrategy.finish(mainWindow, this);
checkStop();
FIleOperator fileOperator = new FIleOperator(dataDir);
fileOperator.preStart(mainWindow, this);
fileOperator.start(mainWindow, form, this);
this.publish(100);
fileOperator.finish(mainWindow);
fileOperator.finish(mainWindow, this);
} catch (InterruptedException e) {
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -63,25 +69,11 @@ public void publish(int i) {
SwingUtilities.invokeLater(() -> mainWindow.progressBar.setValue(i));
}
}
public static final int PROGESS_FORM = 20;
public static final int PROGRESS_IMAGE = 25;
public static final int PROGRESS_CONFLICT = 10;
public static final int PROGRESS_FILE = 45;

public void publishImage(int processed, int total) {
double d = PROGRESS_IMAGE * processed / (double)total;
publish(PROGESS_FORM + (int)d);
public void publish(int processed, int total) {
publish(100 * processed / total);
}

public void publishConflict(int processed, int total) {
double d = PROGRESS_CONFLICT * processed / (double)total;
publish(PROGESS_FORM + PROGRESS_IMAGE + (int)d);
}

public void publishFile(int processed, int total) {
double d = PROGRESS_FILE * processed / (double)total;
publish(PROGESS_FORM + PROGRESS_IMAGE + PROGRESS_CONFLICT + (int)d);
}

@SneakyThrows
public void start() {
Expand Down

0 comments on commit 6a351f4

Please sign in to comment.