From ef42c50c8e0669afca4cd93a787c21da726fa01a Mon Sep 17 00:00:00 2001 From: Mara Date: Wed, 11 Jul 2018 17:00:40 +0800 Subject: [PATCH] v2.2 --- MyBox/pom.xml | 2 +- MyBox/src/main/java/mara/mybox/MainApp.java | 2 +- .../mara/mybox/controller/BaseController.java | 62 +- .../DirectorySynchronizeController.java | 436 ++++++++----- .../controller/FilesArrangeController.java | 617 ++++++++++++++++++ .../controller/FilesRenameController.java | 90 +-- .../mybox/controller/ImageBaseController.java | 129 ++-- .../controller/ImageConverterController.java | 2 +- .../mybox/controller/MainMenuController.java | 5 + .../mybox/controller/MyBoxController.java | 10 +- .../mybox/controller/PdfBaseController.java | 139 ++-- .../PdfConvertImagesController.java | 2 +- .../PdfExtractImagesController.java | 2 +- .../java/mara/mybox/objects/CommonValues.java | 5 +- .../main/java/mara/mybox/tools/FileTools.java | 2 +- .../resources/bundles/Messages.properties | 56 +- .../bundles/Messages_en_US.properties | 56 +- .../bundles/Messages_zh_CN.properties | 30 +- .../src/main/resources/fxml/FilesArrange.fxml | 168 +++++ .../src/main/resources/fxml/FilesRename.fxml | 8 +- .../main/resources/fxml/FilesRenameTable.fxml | 4 +- .../main/resources/fxml/ImageManufacture.fxml | 2 +- MyBox/src/main/resources/fxml/MainMenu.fxml | 1 + README.md | 17 +- docs/1-en.png | Bin 115201 -> 118198 bytes docs/1.png | Bin 110627 -> 110927 bytes docs/22-en.jpg | Bin 0 -> 200801 bytes docs/22.jpg | Bin 0 -> 182776 bytes docs/23-en.jpg | Bin 0 -> 239224 bytes docs/23.jpg | Bin 0 -> 206379 bytes docs/7-en.png | Bin 73802 -> 74345 bytes docs/7.png | Bin 73994 -> 73744 bytes docs/english_interface.html | 10 +- 33 files changed, 1427 insertions(+), 430 deletions(-) create mode 100644 MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java create mode 100644 MyBox/src/main/resources/fxml/FilesArrange.fxml create mode 100644 docs/22-en.jpg create mode 100644 docs/22.jpg create mode 100644 docs/23-en.jpg create mode 100644 docs/23.jpg diff --git a/MyBox/pom.xml b/MyBox/pom.xml index 78bc1d4ab..719ac68a0 100644 --- a/MyBox/pom.xml +++ b/MyBox/pom.xml @@ -4,7 +4,7 @@ mara MyBox - 2.1 + 2.2 jar MyBox diff --git a/MyBox/src/main/java/mara/mybox/MainApp.java b/MyBox/src/main/java/mara/mybox/MainApp.java index 48bab30b1..f559ebc8c 100644 --- a/MyBox/src/main/java/mara/mybox/MainApp.java +++ b/MyBox/src/main/java/mara/mybox/MainApp.java @@ -32,7 +32,7 @@ public void start(Stage stage) throws Exception { System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider"); File userPath = new File(CommonValues.UserFilePath); if (!userPath.exists()) { - userPath.mkdir(); + userPath.mkdirs(); } File configFile = new File(CommonValues.UserConfigFile); if (!configFile.exists()) { diff --git a/MyBox/src/main/java/mara/mybox/controller/BaseController.java b/MyBox/src/main/java/mara/mybox/controller/BaseController.java index 15549c6ce..0c01481b6 100644 --- a/MyBox/src/main/java/mara/mybox/controller/BaseController.java +++ b/MyBox/src/main/java/mara/mybox/controller/BaseController.java @@ -4,6 +4,7 @@ import java.io.File; import java.net.URL; import java.util.List; +import java.util.Optional; import java.util.ResourceBundle; import javafx.beans.binding.Bindings; import javafx.beans.value.ChangeListener; @@ -19,6 +20,7 @@ import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; import javafx.scene.control.CheckBox; import javafx.scene.control.TextField; import javafx.scene.layout.Pane; @@ -28,6 +30,7 @@ import javafx.stage.Modality; import javafx.stage.Stage; import javafx.stage.StageStyle; +import javafx.stage.WindowEvent; import mara.mybox.objects.AppVaribles; import static mara.mybox.objects.AppVaribles.getMessage; import mara.mybox.objects.CommonValues; @@ -50,13 +53,13 @@ public class BaseController implements Initializable { protected List fileExtensionFilter; - protected String myFxml, parentFxml; + protected String myFxml, parentFxml, currentStatus; protected Stage myStage, loadingStage; protected Alert loadingAlert; protected Task task; protected BaseController parentController; - protected boolean isPreview, targetIsFile; + protected boolean isPreview, targetIsFile, paused; protected File sourceFile, targetPath; protected List sourceFiles; protected ObservableList sourceFilesInformation; @@ -336,6 +339,25 @@ protected void startProcess(ActionEvent event) { @FXML protected void pauseProcess(ActionEvent event) { + paused = true; + if (task != null && task.isRunning()) { + task.cancel(); + } else { + updateInterface("Canceled"); + } + } + + protected void cancelProcess(ActionEvent event) { + paused = false; + if (task != null && task.isRunning()) { + task.cancel(); + } else { + updateInterface("Canceled"); + } + } + + protected void updateInterface(final String newStatus) { + } protected void markFileHandled(int index) { @@ -360,6 +382,12 @@ public void reloadStage(String newFxml, String title) { openStage(newFxml, title, false); return; } + if (parentController != null) { + if (parentController.task != null && parentController.task.isRunning()) { + openStage(newFxml, title, false); + return; + } + } getMyStage(); FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(newFxml), AppVaribles.CurrentBundle); Pane pane = fxmlLoader.load(); @@ -371,6 +399,12 @@ public void reloadStage(String newFxml, String title) { } else if (getMyStage().getTitle() == null) { myStage.setTitle(AppVaribles.getMessage("AppTitle")); } + myStage.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + stageClosing(event); + } + }); } catch (Exception e) { logger.error(e.toString()); } @@ -402,12 +436,36 @@ public void openStage(String newFxml, String title, boolean isOwned) { } stage.getIcons().add(CommonValues.AppIcon); stage.setScene(scene); + stage.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + stageClosing(event); + } + }); stage.show(); } catch (Exception e) { logger.error(e.toString()); } } + // Looks task has been destoryed before this is called. + public void stageClosing(WindowEvent event) { + if ((task != null && task.isRunning()) + || (parentController != null && parentController.task != null && parentController.task.isRunning())) { + logger.debug("isRunning"); + Alert alert = new Alert(Alert.AlertType.CONFIRMATION); + alert.setTitle(AppVaribles.getMessage("AppTitle")); + alert.setContentText(AppVaribles.getMessage("SureCloseWindow")); + + Optional result = alert.showAndWait(); + if (result.get() == ButtonType.OK) { + task.cancel(); + } else { + event.consume(); + } + } + } + public void popInformation(String information) { try { Alert alert = new Alert(Alert.AlertType.INFORMATION); diff --git a/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java b/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java index 1e875cb7e..db8455a39 100644 --- a/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java +++ b/MyBox/src/main/java/mara/mybox/controller/DirectorySynchronizeController.java @@ -46,35 +46,36 @@ */ public class DirectorySynchronizeController extends BaseController { - private boolean isConditional; - protected String currentStatus, lastFileName; + protected boolean isConditional, startHandle; + protected String lastFileName; protected Date startTime; protected FileSynchronizeAttributes copyAttr; protected StringBuffer newLogs; protected int newlines, maxLines, totalLines, cacheLines = 200; - protected String strFailedCopy, strCreatedSuccessfully, strCopySuccessfully, strDeleteSuccessfully, strFailedDelete; + protected String strFailedCopy, strCreatedSuccessfully, strCopySuccessfully, strFailedDelete; + protected String strDeleteSuccessfully, strFileDeleteSuccessfully, strDirectoryDeleteSuccessfully; protected File sourcePath; @FXML - private VBox dirsBox, conditionsBox, condBox, logsBox; + protected VBox dirsBox, conditionsBox, condBox, logsBox; @FXML - private TextField sourcePathInput, maxLinesinput, notCopyInput; + protected TextField sourcePathInput, maxLinesinput, notCopyInput; @FXML - private ToggleGroup copyGroup; + protected ToggleGroup copyGroup; @FXML - private CheckBox copySubdirCheck, copyEmptyCheck, copyNewCheck, copyHiddenCheck, copyReadonlyCheck; + protected CheckBox copySubdirCheck, copyEmptyCheck, copyNewCheck, copyHiddenCheck, copyReadonlyCheck; @FXML - private CheckBox copyExistedCheck, copyModifiedCheck, deleteNonExistedCheck, notCopyCheck, copyAttrCheck, continueCheck; + protected CheckBox copyExistedCheck, copyModifiedCheck, deleteNonExistedCheck, notCopyCheck, copyAttrCheck, continueCheck; @FXML - private DatePicker modifyAfterInput; + protected DatePicker modifyAfterInput; @FXML - private TextArea logsTextArea; + protected TextArea logsTextArea; @FXML - private Button clearButton; + protected Button clearButton; public DirectorySynchronizeController() { - targetPathKey = "FileTargetPath"; - sourcePathKey = "FileSourcePath"; + targetPathKey = "DirectorySynchronizeTargetPath"; + sourcePathKey = "DirectorySynchronizeSourcePath"; fileExtensionFilter = new ArrayList(); fileExtensionFilter.add(new FileChooser.ExtensionFilter("*", "*.*")); @@ -84,7 +85,38 @@ public DirectorySynchronizeController() { protected void initializeNext() { try { - FxmlTools.setPathExistedValidation(sourcePathInput); + sourcePathInput.setText(AppVaribles.getConfigValue(sourcePathKey, System.getProperty("user.home"))); + sourcePathInput.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + final File file = new File(newValue); + if (!file.exists() || !file.isDirectory()) { + sourcePathInput.setStyle(badStyle); + return; + } + sourcePathInput.setStyle(null); + AppVaribles.setConfigValue("LastPath", newValue); + AppVaribles.setConfigValue(sourcePathKey, newValue); + } + }); + + targetPathInput.setText(AppVaribles.getConfigValue(targetPathKey, System.getProperty("user.home"))); + targetPathInput.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + final File file = new File(newValue); + if (!file.isDirectory()) { + targetPathInput.setStyle(badStyle); + return; + } + targetPathInput.setStyle(null); + AppVaribles.setConfigValue("LastPath", newValue); + AppVaribles.setConfigValue(targetPathKey, newValue); + } + }); + FxmlTools.setNonnegativeValidation(maxLinesinput); checkIsConditional(); @@ -176,11 +208,10 @@ protected void clearLogs(ActionEvent event) { logsTextArea.setText(""); } - private boolean initAttributes() { + protected boolean initAttributes() { try { sourcePath = new File(sourcePathInput.getText()); - - if (!"Paused".equals(currentStatus)) { + if (!paused || lastFileName == null) { copyAttr = new FileSynchronizeAttributes(); copyAttr.setContinueWhenError(continueCheck.isSelected()); copyAttr.setCopyAttrinutes(copyAttrCheck.isSelected()); @@ -205,48 +236,59 @@ private boolean initAttributes() { } copyAttr.setDeleteNotExisteds(deleteNonExistedCheck.isSelected()); + if (!copyAttr.isCopyNew() && !copyAttr.isCopyExisted() && !copyAttr.isCopySubdir()) { + popInformation(getMessage("NothingCopy")); + return false; + } + // In case that the source path itself is in blacklist + if (copyAttr.isNotCopySome()) { + List keys = copyAttr.getNotCopyNames(); + String srcName = sourcePath.getName(); + for (String key : keys) { + if (srcName.contains(key)) { + popInformation(getMessage("NothingCopy")); + return false; + } + } + } + logsTextArea.setText(AppVaribles.getMessage("SourcePath") + ": " + sourcePathInput.getText() + "\n"); logsTextArea.appendText(AppVaribles.getMessage("TargetPath") + ": " + targetPathInput.getText() + "\n"); newLogs = new StringBuffer(); newlines = 0; totalLines = 0; + try { maxLines = Integer.parseInt(maxLinesinput.getText()); } catch (Exception e) { maxLines = 5000; } - lastFileName = null; - } - if (!copyAttr.isCopyNew() && !copyAttr.isCopyExisted() && !copyAttr.isCopySubdir()) { - popInformation(getMessage("NothingCopy")); - return false; - } - // In case that the source path itself is in blacklist - if (copyAttr.isNotCopySome()) { - List keys = copyAttr.getNotCopyNames(); - String srcName = sourcePath.getName(); - for (String key : keys) { - if (srcName.contains(key)) { - popInformation(getMessage("NothingCopy")); - return false; - } + strFailedCopy = AppVaribles.getMessage("FailedCopy") + ": "; + strCreatedSuccessfully = AppVaribles.getMessage("CreatedSuccessfully") + ": "; + strCopySuccessfully = AppVaribles.getMessage("CopySuccessfully") + ": "; + strDeleteSuccessfully = AppVaribles.getMessage("DeletedSuccessfully") + ": "; + strFailedDelete = AppVaribles.getMessage("FailedDelete") + ": "; + strFileDeleteSuccessfully = AppVaribles.getMessage("FileDeletedSuccessfully") + ": "; + strDirectoryDeleteSuccessfully = AppVaribles.getMessage("DirectoryDeletedSuccessfully") + ": "; + + targetPath = new File(targetPathInput.getText()); + if (!targetPath.exists()) { + targetPath.mkdirs(); + updateLogs(strCreatedSuccessfully + targetPath.getAbsolutePath(), true); } - } + targetPath.setWritable(true); + targetPath.setExecutable(true); - strFailedCopy = AppVaribles.getMessage("FailedCopy") + ": "; - strCreatedSuccessfully = AppVaribles.getMessage("CreatedSuccessfully") + ": "; - strCopySuccessfully = AppVaribles.getMessage("CopySuccessfully") + ": "; - strDeleteSuccessfully = AppVaribles.getMessage("DeletedSuccessfully") + ": "; - strFailedDelete = AppVaribles.getMessage("FailedDelete") + ": "; + startHandle = true; + lastFileName = null; - targetPath = new File(targetPathInput.getText()); - if (!targetPath.exists()) { - targetPath.mkdir(); - logsTextArea.appendText(strCreatedSuccessfully + targetPath.getAbsolutePath() + "\n"); + } else { + startHandle = false; + updateLogs(getMessage("LastHanldedFile") + " " + lastFileName, true); } - targetPath.setWritable(true); - targetPath.setExecutable(true); + + startTime = new Date(); return true; @@ -264,22 +306,26 @@ protected void startProcess(ActionEvent event) { return; } - startTime = new Date(); updateInterface("Started"); task = new Task() { @Override protected Void call() { if (copyAttr.isConditionalCopy()) { + paused = false; conditionalCopy(sourcePath, targetPath); } else { - updateLogs(AppVaribles.getMessage("ClearingTarget")); - if (!clearDir(targetPath, false)) { - updateLogs(AppVaribles.getMessage("FailClearTarget")); - } else { - updateLogs(AppVaribles.getMessage("TargetCleared")); - copyWholeDirectory(sourcePath, targetPath); + if (!paused && targetPath.exists()) { + updateLogs(AppVaribles.getMessage("ClearingTarget"), true); + if (clearDir(targetPath, false)) { + updateLogs(AppVaribles.getMessage("TargetCleared"), true); + } else if (!copyAttr.isContinueWhenError()) { + updateLogs(AppVaribles.getMessage("FailClearTarget"), true); + return null; + } } + paused = false; + copyWholeDirectory(sourcePath, targetPath); } return null; } @@ -313,29 +359,18 @@ protected void failed() { } - @FXML @Override - protected void pauseProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Paused"); - } - - protected void cancelProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Canceled"); - } - protected void updateInterface(final String newStatus) { currentStatus = newStatus; Platform.runLater(new Runnable() { @Override public void run() { try { - updateLogs(AppVaribles.getMessage(newStatus)); + if (paused) { + updateLogs(AppVaribles.getMessage("Paused"), true); + } else { + updateLogs(AppVaribles.getMessage(newStatus), true); + } switch (newStatus) { case "Started": operationBarController.statusLabel.setText(getMessage("Handling...") + " " @@ -362,55 +397,50 @@ public void handle(ActionEvent event) { conditionsBox.setDisable(true); break; - case "Paused": - operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); - operationBarController.startButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - cancelProcess(event); - } - }); - operationBarController.pauseButton.setVisible(true); - operationBarController.pauseButton.setDisable(false); - operationBarController.pauseButton.setText(AppVaribles.getMessage("Continue")); - operationBarController.pauseButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - startProcess(event); - } - }); - showCost(); - dirsBox.setDisable(false); - conditionsBox.setDisable(false); - condBox.setDisable(false); - break; - case "Done": default: - operationBarController.startButton.setText(AppVaribles.getMessage("Start")); - operationBarController.startButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - startProcess(event); - } - }); - operationBarController.pauseButton.setVisible(false); - operationBarController.pauseButton.setDisable(true); + if (paused) { + operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + cancelProcess(event); + } + }); + operationBarController.pauseButton.setVisible(true); + operationBarController.pauseButton.setDisable(false); + operationBarController.pauseButton.setText(AppVaribles.getMessage("Continue")); + operationBarController.pauseButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + startProcess(event); + } + }); + } else { + operationBarController.startButton.setText(AppVaribles.getMessage("Start")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + startProcess(event); + } + }); + operationBarController.pauseButton.setVisible(false); + operationBarController.pauseButton.setDisable(true); + operationBarController.progressBar.setProgress(1); + dirsBox.setDisable(false); + conditionsBox.setDisable(false); + } showCost(); - operationBarController.progressBar.setProgress(1); - dirsBox.setDisable(false); - conditionsBox.setDisable(false); - logsTextArea.appendText(newLogs.toString()); - logsTextArea.appendText(AppVaribles.getMessage("TotalCheckedFiles") + ": " + copyAttr.getTotalFilesNumber() + " "); - logsTextArea.appendText(AppVaribles.getMessage("TotalCheckedDirectories") + ": " + copyAttr.getTotalDirectoriesNumber() + " "); - logsTextArea.appendText(AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize2(copyAttr.getTotalSize()) + "\n"); - logsTextArea.appendText(AppVaribles.getMessage("TotalCopiedFiles") + ": " + copyAttr.getCopiedFilesNumber() + " "); - logsTextArea.appendText(AppVaribles.getMessage("TotalCopiedDirectories") + ": " + copyAttr.getCopiedDirectoriesNumber() + " "); - logsTextArea.appendText(AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize2(copyAttr.getCopiedSize()) + "\n"); + updateLogs(AppVaribles.getMessage("TotalCheckedFiles") + ": " + copyAttr.getTotalFilesNumber() + " " + + AppVaribles.getMessage("TotalCheckedDirectories") + ": " + copyAttr.getTotalDirectoriesNumber() + " " + + AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize2(copyAttr.getTotalSize()), false, true); + updateLogs(AppVaribles.getMessage("TotalCopiedFiles") + ": " + copyAttr.getCopiedFilesNumber() + " " + + AppVaribles.getMessage("TotalCopiedDirectories") + ": " + copyAttr.getCopiedDirectoriesNumber() + " " + + AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize2(copyAttr.getCopiedSize()), false, true); if (copyAttr.isConditionalCopy() && copyAttr.isDeleteNotExisteds()) { - logsTextArea.appendText(AppVaribles.getMessage("TotalDeletedFiles") + ": " + copyAttr.getDeletedFiles() + " "); - logsTextArea.appendText(AppVaribles.getMessage("TotalDeletedDirectories") + ": " + copyAttr.getDeletedDirectories() + " "); - logsTextArea.appendText(AppVaribles.getMessage("TotalDeletedSize") + ": " + FileTools.showFileSize2(copyAttr.getDeletedSize()) + "\n"); + updateLogs(AppVaribles.getMessage("TotalDeletedFiles") + ": " + copyAttr.getDeletedFiles() + " " + + AppVaribles.getMessage("TotalDeletedDirectories") + ": " + copyAttr.getDeletedDirectories() + " " + + AppVaribles.getMessage("TotalDeletedSize") + ": " + FileTools.showFileSize2(copyAttr.getDeletedSize()), false, true); } } @@ -441,26 +471,41 @@ protected void showCost() { operationBarController.statusLabel.setText(s); } - private void updateLogs(final String line) { - newLogs.append(DateTools.datetimeToString(new Date())).append(" ").append(line).append("\n"); - long past = new Date().getTime() - startTime.getTime(); - if (newlines++ > cacheLines || past > 5000) { - Platform.runLater(new Runnable() { - @Override - public void run() { - logsTextArea.appendText(newLogs.toString()); - totalLines += newlines; - if (totalLines > maxLines + cacheLines) { - logsTextArea.deleteText(0, newLogs.length()); + protected void updateLogs(final String line) { + updateLogs(line, true, false); + } + + protected void updateLogs(final String line, boolean immediate) { + updateLogs(line, true, false); + } + + protected void updateLogs(final String line, boolean showTime, boolean immediate) { + try { + if (showTime) { + newLogs.append(DateTools.datetimeToString(new Date())).append(" "); + } + newLogs.append(line).append("\n"); + long past = new Date().getTime() - startTime.getTime(); + if (immediate || newlines++ > cacheLines || past > 5000) { + Platform.runLater(new Runnable() { + @Override + public void run() { + logsTextArea.appendText(newLogs.toString()); + totalLines += newlines; + if (totalLines > maxLines + cacheLines) { + logsTextArea.deleteText(0, newLogs.length()); + } + newLogs = new StringBuffer(); + newlines = 0; } - newLogs = new StringBuffer(); - newlines = 0; - } - }); + }); + } + } catch (Exception e) { + } } - private void checkIsConditional() { + protected void checkIsConditional() { RadioButton sort = (RadioButton) copyGroup.getSelectedToggle(); if (!getMessage("CopyConditionally").equals(sort.getText())) { condBox.setDisable(true); @@ -471,7 +516,7 @@ private void checkIsConditional() { } } - private boolean conditionalCopy(File sourcePath, File targetPath) { + protected boolean conditionalCopy(File sourcePath, File targetPath) { try { if (sourcePath == null || !sourcePath.exists() || !sourcePath.isDirectory()) { return false; @@ -481,15 +526,29 @@ private boolean conditionalCopy(File sourcePath, File targetPath) { return false; } File[] files = sourcePath.listFiles(); + String srcFileName; + long len; for (File srcFile : files) { if (task.isCancelled()) { return false; } - copyAttr.setTotalSize(copyAttr.getTotalSize() + srcFile.length()); - if (srcFile.isFile()) { - copyAttr.setTotalFilesNumber(copyAttr.getTotalFilesNumber() + 1); + srcFileName = srcFile.getAbsolutePath(); + len = srcFile.length(); + if (!startHandle) { + if (lastFileName.equals(srcFileName)) { + startHandle = true; + updateLogs(getMessage("ReachFile") + " " + lastFileName, true); + } + if (srcFile.isFile()) { + continue; + } } else { - copyAttr.setTotalDirectoriesNumber(copyAttr.getTotalDirectoriesNumber() + 1); + if (srcFile.isFile()) { + copyAttr.setTotalFilesNumber(copyAttr.getTotalFilesNumber() + 1); + } else { + copyAttr.setTotalDirectoriesNumber(copyAttr.getTotalDirectoriesNumber() + 1); + } + copyAttr.setTotalSize(copyAttr.getTotalSize() + srcFile.length()); } if (srcFile.isHidden() && !copyAttr.isCopyHidden()) { continue; @@ -532,23 +591,30 @@ private boolean conditionalCopy(File sourcePath, File targetPath) { } if (copyFile(srcFile, targetFile)) { copyAttr.setCopiedFilesNumber(copyAttr.getCopiedFilesNumber() + 1); - copyAttr.setCopiedSize(copyAttr.getCopiedSize() + srcFile.length()); - updateLogs(strCopySuccessfully + srcFile.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); + copyAttr.setCopiedSize(copyAttr.getCopiedSize() + len); + updateLogs(copyAttr.getCopiedFilesNumber() + " " + strCopySuccessfully + + srcFileName + " -> " + targetFile.getAbsolutePath()); + lastFileName = srcFileName; } else if (!copyAttr.isContinueWhenError()) { - updateLogs(strFailedCopy + srcFile.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); + updateLogs(strFailedCopy + srcFileName + " -> " + targetFile.getAbsolutePath()); return false; } } else if (copyAttr.isCopySubdir()) { + updateLogs(getMessage("HandlingDirectory") + " " + srcFileName, true); if (srcFile.listFiles() == null && !copyAttr.isCopyEmpty()) { continue; } - if (!targetFile.exists()) { - targetFile.mkdir(); + if (startHandle && !targetFile.exists()) { + targetFile.mkdirs(); updateLogs(strCreatedSuccessfully + targetFile.getAbsolutePath()); } if (conditionalCopy(srcFile, targetFile)) { - copyAttr.setCopiedDirectoriesNumber(copyAttr.getCopiedDirectoriesNumber() + 1); - copyAttr.setCopiedSize(copyAttr.getCopiedSize() + srcFile.length()); + if (startHandle) { + copyAttr.setCopiedDirectoriesNumber(copyAttr.getCopiedDirectoriesNumber() + 1); + copyAttr.setCopiedSize(copyAttr.getCopiedSize() + len); + updateLogs(copyAttr.getCopiedDirectoriesNumber() + " " + strCopySuccessfully + + srcFileName + " -> " + targetFile.getAbsolutePath()); + } } else if (!copyAttr.isContinueWhenError()) { updateLogs(strFailedCopy + srcFile.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); return false; @@ -558,60 +624,87 @@ private boolean conditionalCopy(File sourcePath, File targetPath) { return true; } catch (Exception e) { logger.error(e.toString()); + updateLogs(strFailedCopy + sourcePath.getAbsolutePath() + "\n" + e.toString()); return false; } } - private boolean copyWholeDirectory(File sourcePath, File targetPath) { + protected boolean copyWholeDirectory(File sourcePath, File targetPath) { try { if (sourcePath == null || !sourcePath.exists() || !sourcePath.isDirectory()) { return false; } File[] files = sourcePath.listFiles(); - for (File file : files) { + String srcFileName; + long len; + for (File srcFile : files) { if (task.isCancelled()) { return false; } - copyAttr.setTotalSize(copyAttr.getTotalSize() + file.length()); - File targetFile = new File(targetPath + File.separator + file.getName()); - if (file.isFile()) { - copyAttr.setTotalFilesNumber(copyAttr.getTotalFilesNumber() + 1); - if (copyFile(file, targetFile)) { + srcFileName = srcFile.getAbsolutePath(); + len = srcFile.length(); + if (!startHandle) { + if (lastFileName.equals(srcFileName)) { + startHandle = true; + updateLogs(getMessage("ReachFile") + " " + lastFileName, true); + } + if (srcFile.isFile()) { + continue; + } + } else { + if (srcFile.isFile()) { + copyAttr.setTotalFilesNumber(copyAttr.getTotalFilesNumber() + 1); + } else { + copyAttr.setTotalDirectoriesNumber(copyAttr.getTotalDirectoriesNumber() + 1); + } + copyAttr.setTotalSize(copyAttr.getTotalSize() + srcFile.length()); + } + File targetFile = new File(targetPath + File.separator + srcFile.getName()); + if (srcFile.isFile()) { + if (copyFile(srcFile, targetFile)) { copyAttr.setCopiedFilesNumber(copyAttr.getCopiedFilesNumber() + 1); + copyAttr.setCopiedSize(copyAttr.getCopiedSize() + len); + updateLogs(copyAttr.getCopiedFilesNumber() + " " + strCopySuccessfully + + srcFileName + " -> " + targetFile.getAbsolutePath()); + lastFileName = srcFileName; } else if (!copyAttr.isContinueWhenError()) { - updateLogs(strFailedCopy + file.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); + updateLogs(strFailedCopy + srcFileName + " -> " + targetFile.getAbsolutePath()); return false; } } else { - copyAttr.setTotalDirectoriesNumber(copyAttr.getTotalDirectoriesNumber() + 1); - targetFile.mkdir(); - updateLogs(strCreatedSuccessfully + targetFile.getAbsolutePath()); - if (copyWholeDirectory(file, targetFile)) { - copyAttr.setCopiedDirectoriesNumber(copyAttr.getCopiedDirectoriesNumber() + 1); + updateLogs(getMessage("HandlingDirectory") + " " + srcFileName, true); + if (startHandle) { + targetFile.mkdirs(); + updateLogs(strCreatedSuccessfully + targetFile.getAbsolutePath()); + } + if (copyWholeDirectory(srcFile, targetFile)) { + if (startHandle) { + copyAttr.setCopiedDirectoriesNumber(copyAttr.getCopiedDirectoriesNumber() + 1); + copyAttr.setCopiedSize(copyAttr.getCopiedSize() + len); + updateLogs(copyAttr.getCopiedDirectoriesNumber() + " " + strCopySuccessfully + + srcFileName + " -> " + targetFile.getAbsolutePath()); + } } else if (!copyAttr.isContinueWhenError()) { - updateLogs(strFailedCopy + file.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); + updateLogs(strFailedCopy + srcFile.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); return false; } } - updateLogs(strCopySuccessfully + file.getAbsolutePath() + " -> " + targetFile.getAbsolutePath()); - copyAttr.setCopiedSize(copyAttr.getCopiedSize() + file.length()); } return true; } catch (Exception e) { logger.error(e.toString()); + updateLogs(strFailedCopy + sourcePath.getAbsolutePath() + "\n" + e.toString()); return false; } } - private boolean clearDir(File dir, boolean record) { - if (task.isCancelled() || dir.isFile()) { - return false; - } + // clearDir can not be paused to avoid logic messed. + protected boolean clearDir(File dir, boolean record) { File[] files = dir.listFiles(); + if (files == null) { + return true; + } for (File file : files) { - if (task.isCancelled()) { - return false; - } long len = file.length(); String filename = file.getAbsolutePath(); if (file.isDirectory()) { @@ -621,7 +714,7 @@ private boolean clearDir(File dir, boolean record) { if (record) { copyAttr.setDeletedDirectories(copyAttr.getDeletedDirectories() + 1); copyAttr.setDeletedSize(copyAttr.getDeletedSize() + len); - updateLogs(strDeleteSuccessfully + filename); + updateLogs(copyAttr.getDeletedDirectories() + " " + strDirectoryDeleteSuccessfully + filename); } } catch (Exception e) { if (record) { @@ -649,7 +742,7 @@ private boolean clearDir(File dir, boolean record) { if (record) { copyAttr.setDeletedFiles(copyAttr.getDeletedFiles() + 1); copyAttr.setDeletedSize(copyAttr.getDeletedSize() + len); - updateLogs(strDeleteSuccessfully + filename); + updateLogs(copyAttr.getDeletedFiles() + " " + strFileDeleteSuccessfully + filename); } } catch (Exception e) { if (record) { @@ -665,9 +758,9 @@ private boolean clearDir(File dir, boolean record) { return true; // When return true, it is not necessary that the dir is cleared. } - private boolean copyFile(File sourceFile, File targetFile) { + protected boolean copyFile(File sourceFile, File targetFile) { try { - if (sourceFile == null || !sourceFile.exists() || !sourceFile.isFile()) { + if (task.isCancelled() || sourceFile == null || !sourceFile.exists() || !sourceFile.isFile()) { return false; } if (!targetFile.exists()) { @@ -693,7 +786,7 @@ private boolean copyFile(File sourceFile, File targetFile) { } } - private boolean deleteNonExisted(File sourcePath, File targetPath) { + protected boolean deleteNonExisted(File sourcePath, File targetPath) { if (!copyAttr.isDeleteNotExisteds() || !targetPath.isDirectory()) { return true; } @@ -702,6 +795,9 @@ private boolean deleteNonExisted(File sourcePath, File targetPath) { return true; } for (File targetFile : files) { + if (task.isCancelled()) { + return false; + } File srcFile = new File(sourcePath + File.separator + targetFile.getName()); if (srcFile.exists()) { continue; @@ -714,7 +810,7 @@ private boolean deleteNonExisted(File sourcePath, File targetPath) { targetFile.delete(); copyAttr.setDeletedDirectories(copyAttr.getDeletedDirectories() + 1); copyAttr.setDeletedSize(copyAttr.getDeletedSize() + len); - updateLogs(strDeleteSuccessfully + filename); + updateLogs(strDirectoryDeleteSuccessfully + filename); } catch (Exception e) { copyAttr.setFailedDeletedDirectories(copyAttr.getFailedDeletedDirectories() + 1); copyAttr.setFailedDeletedSize(copyAttr.getFailedDeletedSize() + len); @@ -736,7 +832,7 @@ private boolean deleteNonExisted(File sourcePath, File targetPath) { targetFile.delete(); copyAttr.setDeletedFiles(copyAttr.getDeletedFiles() + 1); copyAttr.setDeletedSize(copyAttr.getDeletedSize() + len); - updateLogs(strDeleteSuccessfully + filename); + updateLogs(strFileDeleteSuccessfully + filename); } catch (Exception e) { copyAttr.setFailedDeletedFiles(copyAttr.getFailedDeletedFiles() + 1); copyAttr.setFailedDeletedSize(copyAttr.getFailedDeletedSize() + len); diff --git a/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java b/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java new file mode 100644 index 000000000..aacf87961 --- /dev/null +++ b/MyBox/src/main/java/mara/mybox/controller/FilesArrangeController.java @@ -0,0 +1,617 @@ +package mara.mybox.controller; + +import java.awt.Desktop; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import javafx.application.Platform; +import javafx.beans.binding.Bindings; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.concurrent.Task; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.RadioButton; +import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.VBox; +import javafx.stage.DirectoryChooser; +import javafx.stage.FileChooser; +import static mara.mybox.controller.BaseController.logger; +import mara.mybox.objects.AppVaribles; +import static mara.mybox.objects.AppVaribles.getMessage; +import mara.mybox.objects.FileSynchronizeAttributes; +import mara.mybox.tools.DateTools; +import mara.mybox.tools.FileTools; +import static mara.mybox.tools.FxmlTools.badStyle; +import mara.mybox.tools.ValueTools; + +/** + * @Author Mara + * @CreateDate 2018-7-9 + * @Description + * @License Apache License Version 2.0 + */ +public class FilesArrangeController extends BaseController { + + protected String lastFileName; + protected Date startTime; + private boolean startHandle, isCopy, byModifyTime, handleSubdir; + private int dirType, replaceType; + protected File sourcePath; + protected String renameAppdex = "-m"; + protected StringBuffer newLogs; + protected int newlines, maxLines, totalLines, cacheLines = 200; + protected String strFailedCopy, strCreatedSuccessfully, strCopySuccessfully, strDeleteSuccessfully, strFailedDelete; + protected FileSynchronizeAttributes copyAttr; + + private class DirType { + + private static final int Year = 0; + private static final int Month = 1; + private static final int Day = 2; + } + + private class ReplaceType { + + private static final int ReplaceModified = 0; + private static final int Replace = 1; + private static final int NotCopy = 2; + private static final int Rename = 3; + } + + @FXML + private ToggleGroup filesGroup, byGroup, dirGroup, replaceGroup; + @FXML + protected TextField sourcePathInput, maxLinesinput; + @FXML + protected VBox dirsBox, conditionsBox, logsBox; + @FXML + protected TextArea logsTextArea; + @FXML + protected Button clearButton; + + public FilesArrangeController() { + targetPathKey = "FilesArrageTargetPath"; + sourcePathKey = "FilesArrageSourcePath"; + + fileExtensionFilter = new ArrayList(); + fileExtensionFilter.add(new FileChooser.ExtensionFilter("*", "*.*")); + } + + @Override + protected void initializeNext() { + try { + + sourcePathInput.setText(AppVaribles.getConfigValue(sourcePathKey, System.getProperty("user.home"))); + sourcePathInput.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + final File file = new File(newValue); + if (!file.exists() || !file.isDirectory()) { + sourcePathInput.setStyle(badStyle); + return; + } + sourcePathInput.setStyle(null); + AppVaribles.setConfigValue("LastPath", newValue); + AppVaribles.setConfigValue(sourcePathKey, newValue); + } + }); + + targetPathInput.setText(AppVaribles.getConfigValue(targetPathKey, System.getProperty("user.home"))); + targetPathInput.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + final File file = new File(newValue); + if (!file.isDirectory()) { + targetPathInput.setStyle(badStyle); + return; + } + targetPathInput.setStyle(null); + AppVaribles.setConfigValue("LastPath", newValue); + AppVaribles.setConfigValue(targetPathKey, newValue); + } + }); + + operationBarController.startButton.disableProperty().bind( + Bindings.isEmpty(sourcePathInput.textProperty()) + .or(Bindings.isEmpty(targetPathInput.textProperty())) + .or(sourcePathInput.styleProperty().isEqualTo(badStyle)) + .or(targetPathInput.styleProperty().isEqualTo(badStyle)) + ); + + operationBarController.openTargetButton.disableProperty().bind( + operationBarController.startButton.disableProperty() + ); + + } catch (Exception e) { + logger.debug(e.toString()); + } + + } + + @FXML + protected void selectSourcePath(ActionEvent event) { + try { + DirectoryChooser chooser = new DirectoryChooser(); + File path = new File(AppVaribles.getConfigValue(sourcePathKey, System.getProperty("user.home"))); + if (!path.isDirectory()) { + path = new File(System.getProperty("user.home")); + } + chooser.setInitialDirectory(path); + File directory = chooser.showDialog(getMyStage()); + if (directory == null) { + return; + } + sourcePathInput.setText(directory.getPath()); + } catch (Exception e) { + logger.error(e.toString()); + } + } + + @FXML + @Override + protected void selectTargetPath(ActionEvent event) { + if (targetPathInput == null) { + return; + } + try { + DirectoryChooser chooser = new DirectoryChooser(); + File path = new File(AppVaribles.getConfigValue(targetPathKey, System.getProperty("user.home"))); + if (!path.isDirectory()) { + path = new File(System.getProperty("user.home")); + } + chooser.setInitialDirectory(path); + File directory = chooser.showDialog(getMyStage()); + if (directory == null) { + return; + } + targetPathInput.setText(directory.getPath()); + } catch (Exception e) { + logger.error(e.toString()); + } + } + + @FXML + @Override + protected void openTarget(ActionEvent event) { + try { + Desktop.getDesktop().browse(new File(targetPathInput.getText()).toURI()); + } catch (Exception e) { + logger.error(e.toString()); + } + } + + protected boolean initAttributes() { + try { + sourcePath = new File(sourcePathInput.getText()); + if (!paused || lastFileName == null) { + copyAttr = new FileSynchronizeAttributes(); + + RadioButton selected = (RadioButton) filesGroup.getSelectedToggle(); + isCopy = getMessage("Copy").equals(selected.getText()); + + selected = (RadioButton) byGroup.getSelectedToggle(); + byModifyTime = getMessage("ModifyTime").equals(selected.getText()); + + selected = (RadioButton) replaceGroup.getSelectedToggle(); + if (getMessage("ReplaceModified").equals(selected.getText())) { + replaceType = ReplaceType.ReplaceModified; + } else if (getMessage("NotCopy").equals(selected.getText())) { + replaceType = ReplaceType.NotCopy; + } else if (getMessage("Replace").equals(selected.getText())) { + replaceType = ReplaceType.Replace; + } else if (getMessage("Rename").equals(selected.getText())) { + replaceType = ReplaceType.Rename; + } else { + replaceType = ReplaceType.ReplaceModified; + } + + selected = (RadioButton) dirGroup.getSelectedToggle(); + if (getMessage("Year").equals(selected.getText())) { + dirType = DirType.Year; + } else if (getMessage("Month").equals(selected.getText())) { + dirType = DirType.Month; + } else if (getMessage("Day").equals(selected.getText())) { + dirType = DirType.Day; + } else { + dirType = DirType.Month; + } + + handleSubdir = subdirCheck.isSelected(); + + logsTextArea.setText(AppVaribles.getMessage("SourcePath") + ": " + sourcePathInput.getText() + "\n"); + logsTextArea.appendText(AppVaribles.getMessage("TargetPath") + ": " + targetPathInput.getText() + "\n"); + newLogs = new StringBuffer(); + newlines = 0; + totalLines = 0; + + try { + maxLines = Integer.parseInt(maxLinesinput.getText()); + } catch (Exception e) { + maxLines = 5000; + } + + strFailedCopy = AppVaribles.getMessage("FailedCopy") + ": "; + strCreatedSuccessfully = AppVaribles.getMessage("CreatedSuccessfully") + ": "; + strCopySuccessfully = AppVaribles.getMessage("CopySuccessfully") + ": "; + strDeleteSuccessfully = AppVaribles.getMessage("DeletedSuccessfully") + ": "; + strFailedDelete = AppVaribles.getMessage("FailedDelete") + ": "; + + targetPath = new File(targetPathInput.getText()); + if (!targetPath.exists()) { + targetPath.mkdirs(); + updateLogs(strCreatedSuccessfully + targetPath.getAbsolutePath(), true); + } + targetPath.setWritable(true); + targetPath.setExecutable(true); + + startHandle = true; + lastFileName = null; + + } else { + startHandle = false; + updateLogs(getMessage("LastHanldedFile") + " " + lastFileName, true); + } + + paused = false; + startTime = new Date(); + + return true; + + } catch (Exception e) { + logger.error(e.toString()); + return false; + } + } + + @FXML + @Override + protected void startProcess(ActionEvent event) { + try { + if (!initAttributes()) { + return; + } + + updateInterface("Started"); + task = new Task() { + + @Override + protected Void call() { + arranegFiles(sourcePath); + return null; + } + + @Override + protected void succeeded() { + super.succeeded(); + updateInterface("Done"); + } + + @Override + protected void cancelled() { + super.cancelled(); + updateInterface("Canceled"); + } + + @Override + protected void failed() { + super.failed(); + updateInterface("Failed"); + } + }; + Thread thread = new Thread(task); + thread.setDaemon(true); + thread.start(); + + } catch (Exception e) { + updateInterface("Failed"); + logger.error(e.toString()); + } + + } + + @Override + protected void updateInterface(final String newStatus) { + currentStatus = newStatus; + Platform.runLater(new Runnable() { + @Override + public void run() { + try { + if (paused) { + updateLogs(AppVaribles.getMessage("Paused"), true); + } else { + updateLogs(AppVaribles.getMessage(newStatus), true); + } + switch (newStatus) { + case "Started": + operationBarController.statusLabel.setText(getMessage("Handling...") + " " + + getMessage("StartTime") + + ": " + DateTools.datetimeToString(startTime)); + operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + cancelProcess(event); + } + }); + operationBarController.pauseButton.setVisible(true); + operationBarController.pauseButton.setDisable(false); + operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); + operationBarController.pauseButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + pauseProcess(event); + } + }); + operationBarController.progressBar.setProgress(-1); + dirsBox.setDisable(true); + conditionsBox.setDisable(true); + break; + + case "Done": + default: + + if (paused) { + operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + cancelProcess(event); + } + }); + operationBarController.pauseButton.setVisible(true); + operationBarController.pauseButton.setDisable(false); + operationBarController.pauseButton.setText(AppVaribles.getMessage("Continue")); + operationBarController.pauseButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + startProcess(event); + } + }); + + } else { + operationBarController.startButton.setText(AppVaribles.getMessage("Start")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + startProcess(event); + } + }); + operationBarController.pauseButton.setVisible(false); + operationBarController.pauseButton.setDisable(true); + operationBarController.progressBar.setProgress(1); + dirsBox.setDisable(false); + conditionsBox.setDisable(false); + } + + showCost(); + updateLogs(AppVaribles.getMessage("TotalCheckedFiles") + ": " + copyAttr.getTotalFilesNumber() + " " + + AppVaribles.getMessage("TotalCheckedDirectories") + ": " + copyAttr.getTotalDirectoriesNumber() + " " + + AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize2(copyAttr.getTotalSize()), false, true); + updateLogs(AppVaribles.getMessage("TotalCopiedFiles") + ": " + copyAttr.getCopiedFilesNumber() + " " + + AppVaribles.getMessage("TotalCopiedDirectories") + ": " + copyAttr.getCopiedDirectoriesNumber() + " " + + AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize2(copyAttr.getCopiedSize()), false, true); + if (!isCopy) { + updateLogs(AppVaribles.getMessage("TotalDeletedFiles") + ": " + copyAttr.getDeletedFiles() + " " + + AppVaribles.getMessage("TotalDeletedDirectories") + ": " + copyAttr.getDeletedDirectories() + " " + + AppVaribles.getMessage("TotalDeletedSize") + ": " + FileTools.showFileSize2(copyAttr.getDeletedSize()), false, true); + } + } + + } catch (Exception e) { + logger.error(e.toString()); + } + } + }); + + } + + protected void showCost() { + if (operationBarController.statusLabel == null) { + return; + } + long cost = (new Date().getTime() - startTime.getTime()) / 1000; + double avg = 0; + if (copyAttr.getCopiedFilesNumber() != 0) { + avg = ValueTools.roundDouble3((double) cost / copyAttr.getCopiedFilesNumber()); + } + String s = getMessage(currentStatus) + ". " + + getMessage("HandledThisTime") + ": " + copyAttr.getCopiedFilesNumber() + " " + + getMessage("Cost") + ": " + cost + " " + getMessage("Seconds") + ". " + + getMessage("Average") + ": " + avg + " " + getMessage("SecondsPerItem") + ". " + + getMessage("StartTime") + ": " + DateTools.datetimeToString(startTime) + ", " + + getMessage("EndTime") + ": " + DateTools.datetimeToString(new Date()); + operationBarController.statusLabel.setText(s); + } + + protected boolean arranegFiles(File sourcePath) { + try { + if (sourcePath == null || !sourcePath.exists() || !sourcePath.isDirectory()) { + return false; + } + File[] files = sourcePath.listFiles(); + String srcFileName; + long len; + for (File srcFile : files) { + if (task.isCancelled()) { + return false; + } + srcFileName = srcFile.getAbsolutePath(); + len = srcFile.length(); + if (!startHandle) { + if (lastFileName.equals(srcFileName)) { + startHandle = true; + updateLogs(getMessage("ReachFile") + " " + lastFileName, true); + } + if (srcFile.isFile()) { + continue; + } + } else { + if (srcFile.isFile()) { + copyAttr.setTotalFilesNumber(copyAttr.getTotalFilesNumber() + 1); + } else { + copyAttr.setTotalDirectoriesNumber(copyAttr.getTotalDirectoriesNumber() + 1); + } + copyAttr.setTotalSize(copyAttr.getTotalSize() + srcFile.length()); + } + if (srcFile.isDirectory()) { + if (handleSubdir) { + updateLogs(getMessage("HandlingDirectory") + " " + srcFileName, true); + arranegFiles(srcFile); + } + continue; + } else if (!startHandle) { + continue; + } + try { + Calendar c = Calendar.getInstance(); + if (byModifyTime) { + c.setTimeInMillis(srcFile.lastModified()); + } else { + c.setTimeInMillis(FileTools.getFileCreateTime(srcFileName)); + } + File path; + String month, day; + if (c.get(Calendar.MONTH) > 8) { + month = (c.get(Calendar.MONTH) + 1) + ""; + } else { + month = "0" + (c.get(Calendar.MONTH) + 1); + } + if (c.get(Calendar.DAY_OF_MONTH) > 9) { + day = c.get(Calendar.DAY_OF_MONTH) + ""; + } else { + day = "0" + c.get(Calendar.DAY_OF_MONTH); + } + switch (dirType) { + case DirType.Year: + path = new File(targetPath + File.separator + c.get(Calendar.YEAR)); + if (!path.exists()) { + path.mkdirs(); + updateLogs(strCreatedSuccessfully + path.getAbsolutePath()); + } + break; + case DirType.Day: + path = new File(targetPath + File.separator + c.get(Calendar.YEAR) + + File.separator + c.get(Calendar.YEAR) + "-" + month + + File.separator + c.get(Calendar.YEAR) + "-" + month + "-" + day); + if (!path.exists()) { + path.mkdirs(); + updateLogs(strCreatedSuccessfully + path.getAbsolutePath()); + } + break; + case DirType.Month: + default: + path = new File(targetPath + File.separator + c.get(Calendar.YEAR) + + File.separator + c.get(Calendar.YEAR) + "-" + month); + if (!path.exists()) { + path.mkdirs(); + updateLogs(strCreatedSuccessfully + path.getAbsolutePath()); + } + break; + } + File newFile = new File(path.getAbsolutePath() + File.separator + srcFile.getName()); + if (newFile.exists()) { + switch (replaceType) { + case ReplaceType.NotCopy: + continue; + case ReplaceType.Rename: + newFile = renameExistedFile(newFile); + break; + case ReplaceType.Replace: + break; + case ReplaceType.ReplaceModified: + if (srcFile.lastModified() <= newFile.lastModified()) { + continue; + } + } + } + Files.copy(Paths.get(srcFileName), Paths.get(newFile.getAbsolutePath()), + StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES); + + if (!isCopy) { + srcFile.delete(); + copyAttr.setDeletedSize(copyAttr.getDeletedSize() + len); + updateLogs(strDeleteSuccessfully + srcFileName); + } + copyAttr.setCopiedFilesNumber(copyAttr.getCopiedFilesNumber() + 1); + copyAttr.setCopiedSize(copyAttr.getCopiedSize() + len); + updateLogs(copyAttr.getCopiedFilesNumber() + " " + strCopySuccessfully + + srcFileName + " -> " + newFile.getAbsolutePath()); + lastFileName = srcFileName; + + } catch (Exception e) { + updateLogs(strFailedCopy + srcFileName + "\n" + e.toString()); + } + + } + + return true; + } catch (Exception e) { + logger.error(e.toString()); + return false; + } + + } + + private File renameExistedFile(File file) { + if (!file.exists()) { + return file; + } + String newName = FileTools.getFilePrefix(file.getName()) + renameAppdex + "." + FileTools.getFileSuffix(file.getName()); + File newFile = new File(file.getParent() + File.separator + newName); + if (!newFile.exists()) { + return newFile; + } + return renameExistedFile(newFile); + } + + protected void updateLogs(final String line) { + updateLogs(line, true, false); + } + + protected void updateLogs(final String line, boolean immediate) { + updateLogs(line, true, false); + } + + protected void updateLogs(final String line, boolean showTime, boolean immediate) { + try { + if (showTime) { + newLogs.append(DateTools.datetimeToString(new Date())).append(" "); + } + newLogs.append(line).append("\n"); + long past = new Date().getTime() - startTime.getTime(); + if (immediate || newlines++ > cacheLines || past > 5000) { + Platform.runLater(new Runnable() { + @Override + public void run() { + logsTextArea.appendText(newLogs.toString()); + totalLines += newlines; + if (totalLines > maxLines + cacheLines) { + logsTextArea.deleteText(0, newLogs.length()); + } + newLogs = new StringBuffer(); + newlines = 0; + } + }); + } + } catch (Exception e) { + + } + } + + @FXML + protected void clearLogs(ActionEvent event) { + logsTextArea.setText(""); + } + +} diff --git a/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java b/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java index b8473e53d..f9197dd8e 100644 --- a/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java +++ b/MyBox/src/main/java/mara/mybox/controller/FilesRenameController.java @@ -15,7 +15,6 @@ import javafx.fxml.FXML; import javafx.scene.control.CheckBox; import javafx.scene.control.RadioButton; -import javafx.scene.control.ScrollPane; import javafx.scene.control.TextField; import javafx.scene.control.ToggleGroup; import javafx.stage.FileChooser; @@ -38,14 +37,11 @@ public class FilesRenameController extends BaseController { protected List targetNames; - protected String currentStatus; protected Date startTime; protected int currentIndex, currentAccum, currentTotalHandled; protected int total, success, fail, digit; protected FilesTableController tableController; - @FXML - protected ScrollPane scrollPane; @FXML protected CheckBox originalCheck, stringCheck, accumCheck, suffixCheck, descentCheck; @FXML @@ -132,9 +128,8 @@ protected void startProcess(ActionEvent event) { return; } - handleSourceFiles(); - - if (!"Paused".equals(currentStatus)) { + if (!paused) { + handleSourceFiles(); currentIndex = 0; try { currentAccum = Integer.valueOf(acumFromInput.getText()); @@ -144,6 +139,7 @@ protected void startProcess(ActionEvent event) { success = fail = 0; } + paused = false; startTime = new Date(); currentTotalHandled = 0; updateInterface("Started"); @@ -235,22 +231,6 @@ protected String renameFile(File file) { } } - @FXML - @Override - protected void pauseProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Paused"); - } - - protected void cancelProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Canceled"); - } - @FXML @Override protected void openTarget(ActionEvent event) { @@ -270,6 +250,7 @@ protected void openTarget(ActionEvent event) { } } + @Override protected void updateInterface(final String newStatus) { currentStatus = newStatus; Platform.runLater(new Runnable() { @@ -278,32 +259,33 @@ public void run() { try { tableController.filesTableView.refresh(); - if (null != newStatus) { - switch (newStatus) { - case "Started": - operationBarController.statusLabel.setText(getMessage("Handling...") + " " - + getMessage("StartTime") - + ": " + DateTools.datetimeToString(startTime)); - operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); - operationBarController.startButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - cancelProcess(event); - } - }); - operationBarController.pauseButton.setVisible(true); - operationBarController.pauseButton.setDisable(false); - operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); - operationBarController.pauseButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - pauseProcess(event); - } - }); - paraBox.setDisable(true); - break; - - case "Paused": + switch (newStatus) { + case "Started": + operationBarController.statusLabel.setText(getMessage("Handling...") + " " + + getMessage("StartTime") + + ": " + DateTools.datetimeToString(startTime)); + operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + cancelProcess(event); + } + }); + operationBarController.pauseButton.setVisible(true); + operationBarController.pauseButton.setDisable(false); + operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); + operationBarController.pauseButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + pauseProcess(event); + } + }); + paraBox.setDisable(true); + break; + + case "Done": + default: + if (paused) { operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); operationBarController.startButton.setOnAction(new EventHandler() { @Override @@ -321,11 +303,7 @@ public void handle(ActionEvent event) { } }); paraBox.setDisable(true); - showCost(); - break; - - case "Done": - default: + } else { operationBarController.startButton.setText(AppVaribles.getMessage("Start")); operationBarController.startButton.setOnAction(new EventHandler() { @Override @@ -341,9 +319,9 @@ public void handle(ActionEvent event) { tableController.recoveryAllButton.setDisable(false); tableController.recoverySelectedButton.setDisable(false); paraBox.setDisable(false); - showCost(); + } + showCost(); - } } } catch (Exception e) { diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java b/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java index 4ea06a5f8..f4858ba45 100644 --- a/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java +++ b/MyBox/src/main/java/mara/mybox/controller/ImageBaseController.java @@ -95,6 +95,7 @@ protected void startProcess(ActionEvent event) { isPreview = false; makeActualParameters(); currentParameters = actualParameters; + paused = false; doCurrentProcess(); } @@ -144,7 +145,7 @@ protected void afterImageLoaded() { } protected void makeActualParameters() { - if (actualParameters != null && "Paused".equals(actualParameters.status)) { + if (actualParameters != null && paused) { actualParameters.startIndex = actualParameters.currentIndex; return; } @@ -238,6 +239,7 @@ protected ProcessParameters copyParameters(ProcessParameters theConversion) { return newConversion; } + @Override protected void updateInterface(final String newStatus) { currentParameters.status = newStatus; Platform.runLater(new Runnable() { @@ -249,40 +251,58 @@ public void run() { operationBarController.fileProgressBar.setProgress(currentParameters.currentIndex / sourceFiles.size()); operationBarController.fileProgressValue.setText(currentParameters.currentIndex + " / " + sourceFiles.size()); } - if (null != newStatus) { - switch (newStatus) { - case "StartFile": - operationBarController.statusLabel.setText(currentParameters.sourceFile.getName() + " " - + getMessage("Handling...") + " " - + getMessage("StartTime") - + ": " + DateTools.datetimeToString(currentParameters.startTime)); - if (operationBarController.fileProgressBar != null) { - operationBarController.fileProgressBar.setProgress(currentParameters.currentIndex / sourceFiles.size()); - operationBarController.fileProgressValue.setText(currentParameters.currentIndex + " / " + sourceFiles.size()); + switch (newStatus) { + case "StartFile": + operationBarController.statusLabel.setText(currentParameters.sourceFile.getName() + " " + + getMessage("Handling...") + " " + + getMessage("StartTime") + + ": " + DateTools.datetimeToString(currentParameters.startTime)); + if (operationBarController.fileProgressBar != null) { + operationBarController.fileProgressBar.setProgress(currentParameters.currentIndex / sourceFiles.size()); + operationBarController.fileProgressValue.setText(currentParameters.currentIndex + " / " + sourceFiles.size()); + } + break; + + case "Started": + operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + cancelProcess(event); } - break; - - case "Started": - operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); - operationBarController.startButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - cancelProcess(event); - } - }); - operationBarController.pauseButton.setVisible(true); - operationBarController.pauseButton.setDisable(false); - operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); - operationBarController.pauseButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - pauseProcess(event); - } - }); - paraBox.setDisable(true); - break; + }); + operationBarController.pauseButton.setVisible(true); + operationBarController.pauseButton.setDisable(false); + operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); + operationBarController.pauseButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + pauseProcess(event); + } + }); + paraBox.setDisable(true); + break; + + case "CompleteFile": + showCost(); + if (operationBarController.fileProgressBar != null) { + operationBarController.fileProgressBar.setProgress(currentParameters.currentIndex / sourceFiles.size()); + operationBarController.fileProgressValue.setText(currentParameters.currentIndex + " / " + sourceFiles.size()); + } + break; + + case "Done": + if (isPreview || !currentParameters.isBatch) { + if (currentParameters.finalTargetName == null + || !new File(currentParameters.finalTargetName).exists()) { + popInformation(AppVaribles.getMessage("NoDataNotSupported")); + } else { + showImageManufacture(currentParameters.finalTargetName); + } + } - case "Paused": + default: + if (paused) { operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); operationBarController.startButton.setOnAction(new EventHandler() { @Override @@ -300,28 +320,7 @@ public void handle(ActionEvent event) { } }); paraBox.setDisable(true); - showCost(); - break; - - case "CompleteFile": - showCost(); - if (operationBarController.fileProgressBar != null) { - operationBarController.fileProgressBar.setProgress(currentParameters.currentIndex / sourceFiles.size()); - operationBarController.fileProgressValue.setText(currentParameters.currentIndex + " / " + sourceFiles.size()); - } - break; - - case "Done": - if (isPreview || !currentParameters.isBatch) { - if (currentParameters.finalTargetName == null - || !new File(currentParameters.finalTargetName).exists()) { - popInformation(AppVaribles.getMessage("NoDataNotSupported")); - } else { - showImageManufacture(currentParameters.finalTargetName); - } - } - - default: + } else { operationBarController.startButton.setText(AppVaribles.getMessage("Start")); operationBarController.startButton.setOnAction(new EventHandler() { @Override @@ -332,9 +331,9 @@ public void handle(ActionEvent event) { operationBarController.pauseButton.setVisible(false); operationBarController.pauseButton.setDisable(true); paraBox.setDisable(false); - showCost(); + } + showCost(); - } } } catch (Exception e) { @@ -364,22 +363,6 @@ protected void showCost() { operationBarController.statusLabel.setText(s); } - @FXML - @Override - protected void pauseProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Paused"); - } - - protected void cancelProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Canceled"); - } - public ImageFileInformation getImageInformation() { return imageInformation; } diff --git a/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java b/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java index 56564fa2d..613640508 100644 --- a/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java +++ b/MyBox/src/main/java/mara/mybox/controller/ImageConverterController.java @@ -122,7 +122,7 @@ protected Void call() { currentParameters.targetPath = currentParameters.targetRootPath + "/" + currentParameters.targetPrefix; File Path = new File(currentParameters.targetPath + "/"); if (!Path.exists()) { - Path.mkdir(); + Path.mkdirs(); } } } diff --git a/MyBox/src/main/java/mara/mybox/controller/MainMenuController.java b/MyBox/src/main/java/mara/mybox/controller/MainMenuController.java index 451a58093..4c6c93d3c 100644 --- a/MyBox/src/main/java/mara/mybox/controller/MainMenuController.java +++ b/MyBox/src/main/java/mara/mybox/controller/MainMenuController.java @@ -152,6 +152,11 @@ private void openDirectorySynchronize(ActionEvent event) { reloadStage(CommonValues.DirectorySynchronizeFxml, AppVaribles.getMessage("DirectorySynchronize")); } + @FXML + private void openFilesArrangement(ActionEvent event) { + reloadStage(CommonValues.FilesArrangementFxml, AppVaribles.getMessage("FilesArrangement")); + } + @FXML private void showImageHelp(ActionEvent event) { try { diff --git a/MyBox/src/main/java/mara/mybox/controller/MyBoxController.java b/MyBox/src/main/java/mara/mybox/controller/MyBoxController.java index 68e630448..61da35700 100644 --- a/MyBox/src/main/java/mara/mybox/controller/MyBoxController.java +++ b/MyBox/src/main/java/mara/mybox/controller/MyBoxController.java @@ -148,8 +148,16 @@ public void handle(ActionEvent event) { reloadStage(CommonValues.DirectorySynchronizeFxml, AppVaribles.getMessage("DirectorySynchronize")); } }); + MenuItem filesArrangement = new MenuItem(AppVaribles.getMessage("FilesArrangement")); + filesArrangement.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + reloadStage(CommonValues.FilesArrangementFxml, AppVaribles.getMessage("FilesArrangement")); + } + }); fileMenu = new ContextMenu(); - fileMenu.getItems().addAll(filesRename, dirsRename, new SeparatorMenuItem(), dirSynchronize); + fileMenu.getItems().addAll(filesRename, dirsRename, new SeparatorMenuItem(), + dirSynchronize, filesArrangement); } @FXML diff --git a/MyBox/src/main/java/mara/mybox/controller/PdfBaseController.java b/MyBox/src/main/java/mara/mybox/controller/PdfBaseController.java index 4a52cb74b..4e4e04c42 100644 --- a/MyBox/src/main/java/mara/mybox/controller/PdfBaseController.java +++ b/MyBox/src/main/java/mara/mybox/controller/PdfBaseController.java @@ -99,6 +99,7 @@ protected void startProcess(ActionEvent event) { isPreview = false; makeActualParameters(); currentParameters = actualParameters; + paused = false; doCurrentProcess(); } @@ -126,7 +127,7 @@ protected void preview(ActionEvent event) { } protected void makeActualParameters() { - if (actualParameters != null && "Paused".equals(actualParameters.status)) { + if (actualParameters != null && paused) { actualParameters.startPage = actualParameters.currentPage; actualParameters.acumStart = actualParameters.currentNameNumber + 1; return; @@ -195,7 +196,7 @@ protected void makeSingleParameters() { if (targetSelectionController.subdirCheck != null && targetSelectionController.subdirCheck.isSelected()) { File finalPath = new File(actualParameters.targetPath + "/" + actualParameters.targetPrefix + "/"); if (!finalPath.exists()) { - finalPath.mkdir(); + finalPath.mkdirs(); } actualParameters.targetPath += "/" + actualParameters.targetPrefix; } @@ -261,6 +262,7 @@ protected void doCurrentProcess() { } + @Override protected void updateInterface(final String newStatus) { currentParameters.status = newStatus; Platform.runLater(new Runnable() { @@ -272,40 +274,62 @@ public void run() { operationBarController.fileProgressBar.setProgress(currentParameters.currentFileIndex / sourceFiles.size()); operationBarController.fileProgressValue.setText(currentParameters.currentFileIndex + " / " + sourceFiles.size()); } - if (null != newStatus) { - switch (newStatus) { - case "StartFile": - operationBarController.statusLabel.setText(currentParameters.sourceFile.getName() + " " - + getMessage("Handling...") + " " - + getMessage("StartTime") - + ": " + DateTools.datetimeToString(currentParameters.startTime)); - if (operationBarController.fileProgressBar != null) { - operationBarController.fileProgressBar.setProgress(currentParameters.currentFileIndex / sourceFiles.size()); - operationBarController.fileProgressValue.setText(currentParameters.currentFileIndex + " / " + sourceFiles.size()); - } - break; - case "Started": - operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); - operationBarController.startButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - cancelProcess(event); - } - }); - operationBarController.pauseButton.setVisible(true); - operationBarController.pauseButton.setDisable(false); - operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); - operationBarController.pauseButton.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - pauseProcess(event); - } - }); - paraBox.setDisable(true); - break; + switch (newStatus) { + case "StartFile": + operationBarController.statusLabel.setText(currentParameters.sourceFile.getName() + " " + + getMessage("Handling...") + " " + + getMessage("StartTime") + + ": " + DateTools.datetimeToString(currentParameters.startTime)); + if (operationBarController.fileProgressBar != null) { + operationBarController.fileProgressBar.setProgress(currentParameters.currentFileIndex / sourceFiles.size()); + operationBarController.fileProgressValue.setText(currentParameters.currentFileIndex + " / " + sourceFiles.size()); + } + break; + + case "Started": + operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); + operationBarController.startButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + cancelProcess(event); + } + }); + operationBarController.pauseButton.setVisible(true); + operationBarController.pauseButton.setDisable(false); + operationBarController.pauseButton.setText(AppVaribles.getMessage("Pause")); + operationBarController.pauseButton.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + pauseProcess(event); + } + }); + paraBox.setDisable(true); + break; + + case "CompleteFile": + showCost(); + if (operationBarController.fileProgressBar != null) { + operationBarController.fileProgressBar.setProgress(currentParameters.currentFileIndex / sourceFiles.size()); + operationBarController.fileProgressValue.setText(currentParameters.currentFileIndex + " / " + sourceFiles.size()); + } + break; + + case "Done": + if (isPreview) { + if (finalTargetName == null + || !new File(finalTargetName).exists()) { + popInformation(AppVaribles.getMessage("NoDataNotSupported")); + } else if (isTxt) { + File txtFile = new File(finalTargetName); + Desktop.getDesktop().browse(txtFile.toURI()); + } else { + showImageManufacture(finalTargetName); + } + } - case "Paused": + default: + if (paused) { operationBarController.startButton.setText(AppVaribles.getMessage("Cancel")); operationBarController.startButton.setOnAction(new EventHandler() { @Override @@ -323,31 +347,7 @@ public void handle(ActionEvent event) { } }); paraBox.setDisable(true); - showCost(); - break; - - case "CompleteFile": - showCost(); - if (operationBarController.fileProgressBar != null) { - operationBarController.fileProgressBar.setProgress(currentParameters.currentFileIndex / sourceFiles.size()); - operationBarController.fileProgressValue.setText(currentParameters.currentFileIndex + " / " + sourceFiles.size()); - } - break; - - case "Done": - if (isPreview) { - if (finalTargetName == null - || !new File(finalTargetName).exists()) { - popInformation(AppVaribles.getMessage("NoDataNotSupported")); - } else if (isTxt) { - File txtFile = new File(finalTargetName); - Desktop.getDesktop().browse(txtFile.toURI()); - } else { - showImageManufacture(finalTargetName); - } - } - - default: + } else { operationBarController.startButton.setText(AppVaribles.getMessage("Start")); operationBarController.startButton.setOnAction(new EventHandler() { @Override @@ -359,9 +359,8 @@ public void handle(ActionEvent event) { operationBarController.pauseButton.setDisable(true); // operationBarController.openTargetButton.setDisable(false); paraBox.setDisable(false); - showCost(); - - } + } + showCost(); } } catch (Exception e) { @@ -391,20 +390,4 @@ protected void showCost() { operationBarController.statusLabel.setText(s); } - @FXML - @Override - protected void pauseProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Paused"); - } - - protected void cancelProcess(ActionEvent event) { - if (task != null && task.isRunning()) { - task.cancel(); - } - updateInterface("Canceled"); - } - } diff --git a/MyBox/src/main/java/mara/mybox/controller/PdfConvertImagesController.java b/MyBox/src/main/java/mara/mybox/controller/PdfConvertImagesController.java index a1e63bc7b..166e6223a 100644 --- a/MyBox/src/main/java/mara/mybox/controller/PdfConvertImagesController.java +++ b/MyBox/src/main/java/mara/mybox/controller/PdfConvertImagesController.java @@ -95,7 +95,7 @@ protected Void call() { currentParameters.targetPath = currentParameters.targetRootPath + "/" + currentParameters.targetPrefix; File Path = new File(currentParameters.targetPath + "/"); if (!Path.exists()) { - Path.mkdir(); + Path.mkdirs(); } } } diff --git a/MyBox/src/main/java/mara/mybox/controller/PdfExtractImagesController.java b/MyBox/src/main/java/mara/mybox/controller/PdfExtractImagesController.java index ab6b8bb72..43aea2d52 100644 --- a/MyBox/src/main/java/mara/mybox/controller/PdfExtractImagesController.java +++ b/MyBox/src/main/java/mara/mybox/controller/PdfExtractImagesController.java @@ -108,7 +108,7 @@ protected Void call() { currentParameters.targetPath = currentParameters.targetRootPath + "/" + currentParameters.targetPrefix; File Path = new File(currentParameters.targetPath + "/"); if (!Path.exists()) { - Path.mkdir(); + Path.mkdirs(); } } } diff --git a/MyBox/src/main/java/mara/mybox/objects/CommonValues.java b/MyBox/src/main/java/mara/mybox/objects/CommonValues.java index cb648b5af..477860e43 100644 --- a/MyBox/src/main/java/mara/mybox/objects/CommonValues.java +++ b/MyBox/src/main/java/mara/mybox/objects/CommonValues.java @@ -16,8 +16,8 @@ */ public class CommonValues { - public static final double AppVersion = 2.1; - public static final String AppVersionDate = "2018-07-07"; + public static final double AppVersion = 2.2; + public static final String AppVersionDate = "2018-07-11"; public static final String UserFilePath = System.getProperty("user.home") + "/mybox"; public static final String UserConfigFile = UserFilePath + "/.conf.properties"; @@ -47,6 +47,7 @@ public class CommonValues { public static final String FilesRenameFxml = "/fxml/FilesRename.fxml"; public static final String DirectoriesRenameFxml = "/fxml/DirectoriesRename.fxml"; public static final String DirectorySynchronizeFxml = "/fxml/DirectorySynchronize.fxml"; + public static final String FilesArrangementFxml = "/fxml/FilesArrange.fxml"; public static final Locale LocaleZhCN = new Locale("zh", "CN"); public static final Locale LocaleEnUS = new Locale("en", "US"); diff --git a/MyBox/src/main/java/mara/mybox/tools/FileTools.java b/MyBox/src/main/java/mara/mybox/tools/FileTools.java index 544342f2c..9a537d010 100644 --- a/MyBox/src/main/java/mara/mybox/tools/FileTools.java +++ b/MyBox/src/main/java/mara/mybox/tools/FileTools.java @@ -250,7 +250,7 @@ public static boolean copyWholeDirectory(File sourcePath, File targetPath, FileS return false; } } - targetPath.mkdir(); + targetPath.mkdirs(); File[] files = sourcePath.listFiles(); for (File file : files) { File targetFile = new File(targetPath + File.separator + file.getName()); diff --git a/MyBox/src/main/resources/bundles/Messages.properties b/MyBox/src/main/resources/bundles/Messages.properties index c9449a427..a36c41cb2 100644 --- a/MyBox/src/main/resources/bundles/Messages.properties +++ b/MyBox/src/main/resources/bundles/Messages.properties @@ -116,9 +116,9 @@ ImageOrientation=Image Orientation BitDepth=Bit Depth AlphaChannel=Transparency Channel ImageInformation=Information -ZoomIn=ZoomIn -ZoomOut=ZoomOut -OriginalSize=OriginalSize +ZoomIn=+ +ZoomOut=- +OriginalSize=OrigSize Home=Home ImageViewer=Image Viewer Exit=Exit @@ -127,7 +127,7 @@ File=File InterfaceLanguage=Interface Language LeftRotate=Left Rotate RightRorate=Right Rorate -WindowSize=WindowSize +WindowSize=WinSize NotSupported=Not Supported true=true false=false @@ -204,9 +204,9 @@ CalculateOutputDensity=Calculate Output Density OutputDensity=Output Density OutputPixels=Output Pixels Ratio=Ratio -RotateLeft=RotateLeft -RotateRight=RotateRight -TurnOver=TurnOver +RotateLeft=RotateL +RotateRight=RotateR +TurnOver=Turn Return=Return Back=Back ImagesMostTips=Mostly 10 image files can be viewed @@ -229,8 +229,8 @@ InvertColor=Invert Window=Window Brightness=Brightness Zoom=Zoom -ZoomStep=Zoom Step -RotateAngle=Rotate Angle +ZoomStep=Step +RotateAngle=Angle Increase=Increase Reduce=Reduce AdjustmentStep=Adjustment Step @@ -274,10 +274,10 @@ DirRenameSummary=Include Files:{0} Renamed:{1} DirRecoverSummary=Renameds:{0} Recovered:{1} LatestRelease=Latest Release WelcomePR=Welcome to submit requirements and problem reports online -MoveRight=MoveRight -MoveLeft=MoveLeft -MoveUp=MoveUp -MoveDown=MoveDown +MoveRight=> +MoveLeft=< +MoveUp=^ +MoveDown=v Next=Next Last=Last Order=Order @@ -300,7 +300,7 @@ OnlyCopyModifiedFiles=Only Copy Modified Files OnlyCopyFilesAfter=Only Copy Files Modified After DeleteNotExistedinSource=Delete Files and Directories That Are Not Existed in Source Path SynchronizeConditions=Synchronize Conditions -CopyExistedComments=(Empty to copy all modified files) +CopyExistedComments=(Empty for Unlimited Time) NotCopyInclude=Not Copy Files or Directories Whose Names Include Strings SeparateComma=Separate by Comma CopyHiddenFiles=Copy Hidden Files @@ -338,3 +338,31 @@ TotalDeletedDirectories=Total Deleted Directories TotalDeletedSize=Total Deleted Size DeletedSuccessfully=Deleted Successfully FailedDelete=Failed to delete +ArrangeConditions=Arrange Conditions +By=By +CreateDirectories=Create Directories +YearMonth=Year and Month +Month=Month +Day=Day +Files=Files +Copy=Copy +Move=Move +ExistedFiles=Existed Files +NotReplace=Not Replace +Replace=Replace +ReplaceModified=Only Replace Modified +Previous=Previous +NotCopy=Not Copy +Rename=Rename +Suffix=Suffix +Append=Append +Category=Category +Year=Year +FilesArrangement=FilesArrangement +FileArrangeComments=(Notice: Directories' structure of source files will lose in target path and files will be rearraged by time) +SureCloseWindow=The task is still running. Are you sure to close the window and interrupt the task? +LastHanldedFile=Last Handled File +HandlingDirectory=Handling Directory +ReachFile=Reach File +FileDeletedSuccessfully=File Deleted Successfully +DirectoryDeletedSuccessfully=Directory Deleted Successfully diff --git a/MyBox/src/main/resources/bundles/Messages_en_US.properties b/MyBox/src/main/resources/bundles/Messages_en_US.properties index c16cf6dce..edd044909 100644 --- a/MyBox/src/main/resources/bundles/Messages_en_US.properties +++ b/MyBox/src/main/resources/bundles/Messages_en_US.properties @@ -116,9 +116,9 @@ ImageOrientation=Image Orientation BitDepth=Bit Depth AlphaChannel=Transparency Channel ImageInformation=Information -ZoomIn=ZoomIn -ZoomOut=ZoomOut -OriginalSize=OriginalSize +ZoomIn=+ +ZoomOut=- +OriginalSize=OrigSize Home=Home ImageViewer=Image Viewer Exit=Exit @@ -127,7 +127,7 @@ File=File InterfaceLanguage=Interface Language LeftRotate=Left Rotate RightRorate=Right Rorate -WindowSize=WindowSize +WindowSize=WinSize NotSupported=Not Supported true=true false=false @@ -204,9 +204,9 @@ CalculateOutputDensity=Calculate Output Density OutputDensity=Output Density OutputPixels=Output Pixels Ratio=Ratio -RotateLeft=RotateLeft -RotateRight=RotateRight -TurnOver=TurnOver +RotateLeft=RotateL +RotateRight=RotateR +TurnOver=Turn Return=Return Back=Back ImagesMostTips=Mostly 10 image files can be viewed @@ -229,8 +229,8 @@ InvertColor=Invert Window=Window Brightness=Brightness Zoom=Zoom -ZoomStep=Zoom Step -RotateAngle=Rotate Angle +ZoomStep=Step +RotateAngle=Angle Increase=Increase Reduce=Reduce AdjustmentStep=Adjustment Step @@ -274,10 +274,10 @@ DirRenameSummary=Include Files:{0} Renamed:{1} DirRecoverSummary=Renameds:{0} Recovered:{1} LatestRelease=Latest Release WelcomePR=Welcome to submit requirements and problem reports online -MoveRight=MoveRight -MoveLeft=MoveLeft -MoveUp=MoveUp -MoveDown=MoveDown +MoveRight=> +MoveLeft=< +MoveUp=^ +MoveDown=v Next=Next Last=Last Order=Order @@ -300,7 +300,7 @@ OnlyCopyModifiedFiles=Only Copy Modified Files OnlyCopyFilesAfter=Only Copy Files Modified After DeleteNotExistedinSource=Delete Files and Directories That Are Not Existed in Source Path SynchronizeConditions=Synchronize Conditions -CopyExistedComments=(Empty to copy all modified files) +CopyExistedComments=(Empty for Unlimited Time) NotCopyInclude=Not Copy Files or Directories Whose Names Include Strings SeparateComma=Separate by Comma CopyHiddenFiles=Copy Hidden Files @@ -338,3 +338,31 @@ TotalDeletedDirectories=Total Deleted Directories TotalDeletedSize=Total Deleted Size DeletedSuccessfully=Deleted Successfully FailedDelete=Failed to delete +ArrangeConditions=Arrange Conditions +By=By +CreateDirectories=Create Directories +YearMonth=Year and Month +Month=Month +Day=Day +Files=Files +Copy=Copy +Move=Move +ExistedFiles=Existed Files +NotReplace=Not Replace +Replace=Replace +ReplaceModified=Only Replace Modified +Previous=Previous +NotCopy=Not Copy +Rename=Rename +Suffix=Suffix +Append=Append +Category=Category +Year=Year +FilesArrangement=FilesArrangement +FileArrangeComments=(Notice: Directories' structure of source files will lose in target path and files will be rearraged by time) +SureCloseWindow=The task is still running. Are you sure to close the window and interrupt the task? +LastHanldedFile=Last Handled File +HandlingDirectory=Handling Directory +ReachFile=Reach File +FileDeletedSuccessfully=File Deleted Successfully +DirectoryDeletedSuccessfully=Directory Deleted Successfully diff --git a/MyBox/src/main/resources/bundles/Messages_zh_CN.properties b/MyBox/src/main/resources/bundles/Messages_zh_CN.properties index e24c022e8..6cc8f5fea 100644 --- a/MyBox/src/main/resources/bundles/Messages_zh_CN.properties +++ b/MyBox/src/main/resources/bundles/Messages_zh_CN.properties @@ -300,7 +300,7 @@ OnlyCopyModifiedFiles=\u53ea\u590d\u5236\u5df2\u4fee\u6539\u7684\u6587\u4ef6 OnlyCopyFilesAfter=\u53ea\u590d\u5236\u65e5\u671f\u4ee5\u540e\u4fee\u6539\u8fc7\u7684\u6587\u4ef6 DeleteNotExistedinSource=\u5220\u9664\u5728\u6e90\u76ee\u5f55\u4e0b\u4e0d\u5b58\u5728\u7684\u6587\u4ef6\u548c\u76ee\u5f55 SynchronizeConditions=\u540c\u6b65\u6761\u4ef6 -CopyExistedComments=\uff08\u7a7a\u767d\u4ee5\u590d\u5236\u6240\u6709\u4fee\u6539\u8fc7\u7684\u6587\u4ef6\uff09 +CopyExistedComments=\uff08\u7a7a\u767d\u4ee5\u4e0d\u9650\u5236\u65f6\u95f4\uff09 NotCopyInclude=\u4e0d\u590d\u5236\u540d\u5b57\u5305\u542b\u5b57\u4e32\u7684\u6587\u4ef6\u6216\u8005\u76ee\u5f55 SeparateComma=\u4ee5\u9017\u53f7\u5206\u5272 CopyHiddenFiles=\u590d\u5236\u9690\u85cf\u6587\u4ef6 @@ -338,3 +338,31 @@ TotalDeletedDirectories=\u5171\u5220\u9664\u76ee\u5f55 TotalDeletedSize=\u5171\u5220\u9664\u5927\u5c0f DeletedSuccessfully=\u5220\u9664\u6210\u529f FailedDelete=\u5220\u9664\u5931\u8d25 +ArrangeConditions=\u6574\u7406\u6761\u4ef6 +By=\u4f9d\u636e +CreateDirectories=\u521b\u5efa\u76ee\u5f55 +YearMonth=\u5e74\u548c\u6708 +Month=\u6708 +Day=\u65e5 +Files=\u6587\u4ef6 +Copy=\u590d\u5236 +Move=\u79fb\u52a8 +ExistedFiles=\u5df2\u5b58\u5728\u7684\u6587\u4ef6 +NotReplace=\u4e0d\u8986\u76d6 +Replace=\u8986\u76d6 +ReplaceModified=\u53ea\u8986\u76d6\u4fee\u6539\u8fc7\u7684 +Previous=\u4e0a\u4e00\u4e2a +NotCopy=\u4e0d\u590d\u5236 +Rename=\u91cd\u547d\u540d +Suffix=\u540e\u7f00 +Append=\u9644\u52a0 +Category=\u5f52\u7c7b +Year=\u5e74 +FilesArrangement=\u6587\u4ef6\u6574\u7406 +FileArrangeComments=\uff08\u6ce8\u610f\uff1a\u6e90\u6587\u4ef6\u7684\u76ee\u5f55\u7ed3\u6784\u5728\u76ee\u6807\u76ee\u5f55\u4e2d\u5c06\u88ab\u4e22\u5f03\uff0c\u6587\u4ef6\u5c06\u6309\u65f6\u95f4\u91cd\u65b0\u6574\u7406\uff09 +SureCloseWindow=\u4efb\u52a1\u4ecd\u5728\u6267\u884c\u3002\u786e\u5b9e\u8981\u5173\u95ed\u7a97\u53e3\u5e76\u4e14\u628a\u4efb\u52a1\u4e2d\u6b62\u5417\uff1f +LastHanldedFile=\u6700\u540e\u5904\u7406\u7684\u6587\u4ef6 +HandlingDirectory=\u6b63\u5728\u5904\u7406\u76ee\u5f55 +ReachFile=\u5904\u7406\u5230\u6587\u4ef6 +FileDeletedSuccessfully=\u6587\u4ef6\u88ab\u6210\u529f\u5220\u9664 +DirectoryDeletedSuccessfully=\u76ee\u5f55\u88ab\u6210\u529f\u5220\u9664 diff --git a/MyBox/src/main/resources/fxml/FilesArrange.fxml b/MyBox/src/main/resources/fxml/FilesArrange.fxml new file mode 100644 index 000000000..f1adc2cf6 --- /dev/null +++ b/MyBox/src/main/resources/fxml/FilesArrange.fxml @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + +