From 6a351f4a8071f1d8004400432c13251b5e1ccf1b Mon Sep 17 00:00:00 2001 From: ColorsWind <1748591300@qq.com> Date: Fri, 3 Apr 2020 14:02:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=96=B0=E7=9A=84=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=9D=A1=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../submitmanager/ConflictStrategy.java | 7 +++- .../submitmanager/FIleOperator.java | 11 +++++-- .../colors_wind/submitmanager/FormMap.java | 16 ++++++++-- .../submitmanager/ImageOpeator.java | 11 +++++-- .../submitmanager/ProcessFileTask.java | 32 +++++++------------ 5 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/net/colors_wind/submitmanager/ConflictStrategy.java b/src/net/colors_wind/submitmanager/ConflictStrategy.java index a366655..5e6f70a 100644 --- a/src/net/colors_wind/submitmanager/ConflictStrategy.java +++ b/src/net/colors_wind/submitmanager/ConflictStrategy.java @@ -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 --------"); + } + } diff --git a/src/net/colors_wind/submitmanager/FIleOperator.java b/src/net/colors_wind/submitmanager/FIleOperator.java index 6b628bf..2fb8179 100644 --- a/src/net/colors_wind/submitmanager/FIleOperator.java +++ b/src/net/colors_wind/submitmanager/FIleOperator.java @@ -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 { @@ -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()); @@ -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); + } + } diff --git a/src/net/colors_wind/submitmanager/FormMap.java b/src/net/colors_wind/submitmanager/FormMap.java index 5a83d91..ef5fd3b 100644 --- a/src/net/colors_wind/submitmanager/FormMap.java +++ b/src/net/colors_wind/submitmanager/FormMap.java @@ -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) { @@ -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 { diff --git a/src/net/colors_wind/submitmanager/ImageOpeator.java b/src/net/colors_wind/submitmanager/ImageOpeator.java index 8e8ccdd..68ca1a9 100644 --- a/src/net/colors_wind/submitmanager/ImageOpeator.java +++ b/src/net/colors_wind/submitmanager/ImageOpeator.java @@ -45,7 +45,7 @@ public void start(Collection 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); @@ -58,12 +58,12 @@ public void start(Collection 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 { @@ -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); + } } diff --git a/src/net/colors_wind/submitmanager/ProcessFileTask.java b/src/net/colors_wind/submitmanager/ProcessFileTask.java index 1f0bf6a..90510ec 100644 --- a/src/net/colors_wind/submitmanager/ProcessFileTask.java +++ b/src/net/colors_wind/submitmanager/ProcessFileTask.java @@ -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(); @@ -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() {