Skip to content

Commit

Permalink
v2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararsh committed Jul 24, 2018
1 parent f859aab commit 526a35b
Show file tree
Hide file tree
Showing 40 changed files with 1,749 additions and 298 deletions.
2 changes: 1 addition & 1 deletion MyBox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>mara</groupId>
<artifactId>MyBox</artifactId>
<version>2.3</version>
<version>2.4</version>
<packaging>jar</packaging>

<name>MyBox</name>
Expand Down
49 changes: 39 additions & 10 deletions MyBox/src/main/java/mara/mybox/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import mara.mybox.controller.BaseController;
import mara.mybox.controller.ImageManufactureController;
import mara.mybox.objects.AppVaribles;
import mara.mybox.objects.CommonValues;
import mara.mybox.image.ImageValueTools;
import mara.mybox.tools.FileTools;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -26,6 +28,7 @@
public class MainApp extends Application {

private static final Logger logger = LogManager.getLogger();
private static String imageFile;

@Override
public void start(Stage stage) throws Exception {
Expand All @@ -47,20 +50,41 @@ public void start(Stage stage) throws Exception {
AppVaribles.CurrentBundle = CommonValues.BundleDefault;
ImageValueTools.registrySupportedImageFormats();

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.MyboxFxml), AppVaribles.CurrentBundle);
Pane pane = fxmlLoader.load();
final BaseController controller = fxmlLoader.getController();
controller.setMyStage(stage);
FXMLLoader fxmlLoader;
Pane pane;
if (imageFile != null) {
fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.ImageManufactureFxml), AppVaribles.CurrentBundle);
pane = fxmlLoader.load();
final ImageManufactureController imageController = (ImageManufactureController) fxmlLoader.getController();
imageController.loadImage(imageFile);
imageController.setMyStage(stage);
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
if (!imageController.stageClosing()) {
event.consume();
}
}
});

} else {
fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.MyboxFxml), AppVaribles.CurrentBundle);
pane = fxmlLoader.load();
final BaseController controller = fxmlLoader.getController();
controller.setMyStage(stage);
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
if (!controller.stageClosing()) {
event.consume();
}
}
});
}

stage.getIcons().add(CommonValues.AppIcon);
stage.setTitle(AppVaribles.getMessage("AppTitle"));
stage.setScene(new Scene(pane));
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
controller.stageClosing(event);
}
});
stage.show();

// https://stackoverflow.com/questions/23527679/trying-to-open-a-javafx-stage-after-calling-platform-exit
Expand All @@ -79,6 +103,11 @@ public void handle(WindowEvent event) {
* @param args the command line arguments
*/
public static void main(String[] args) {
if (args.length > 0) {
if (CommonValues.SupportedImages.contains(FileTools.getFileSuffix(args[0]))) {
imageFile = args[0];
}
}
launch(args);
}

Expand Down
83 changes: 66 additions & 17 deletions MyBox/src/main/java/mara/mybox/controller/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.awt.Desktop;
import java.io.File;
import java.net.URL;
import java.text.MessageFormat;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
Expand All @@ -25,6 +24,7 @@
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
Expand Down Expand Up @@ -95,6 +95,8 @@ public class BaseController implements Initializable {
protected TextField previewInput, acumFromInput, digitInput;
@FXML
protected CheckBox fillZero, subdirCheck, appendDensity, appendColor, appendCompressionType, appendQuality, appendSize;
@FXML
protected Label bottomLabel;

public BaseController() {

Expand Down Expand Up @@ -460,7 +462,9 @@ public void openStage(String newFxml, String title, boolean isOwned, boolean mon
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
controller.stageClosing(event);
if (!controller.stageClosing()) {
event.consume();
}
}
});
}
Expand All @@ -470,9 +474,9 @@ public void handle(WindowEvent event) {
}
}

public void stageClosing(WindowEvent event) {
public boolean stageClosing() {
try {
// logger.debug("stageClosing");
// logger.debug("stageClosing:" + getMyStage().getWidth() + "," + myStage.getHeight());
// logger.debug(Platform.isImplicitExit());

if (task != null && task.isRunning()) {
Expand All @@ -483,20 +487,22 @@ public void stageClosing(WindowEvent event) {
if (result.get() == ButtonType.OK && task != null) {
task.cancel();
} else {
event.consume();
return;
return false;
}
}
if (AppVaribles.scheduledTasks != null && !AppVaribles.scheduledTasks.isEmpty()) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setTitle(AppVaribles.getMessage("AppTitle"));
alert.setContentText(MessageFormat.format(AppVaribles.getMessage("AlarmClocksStillRunning"), AppVaribles.scheduledTasks.size()));
ButtonType buttonYes = new ButtonType(AppVaribles.getMessage("Yes"));
ButtonType buttonNo = new ButtonType(AppVaribles.getMessage("No"));
alert.getButtonTypes().setAll(buttonYes, buttonNo);

Optional<ButtonType> result = alert.showAndWait();
if (result.get() == buttonYes) {
// Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
// alert.setTitle(AppVaribles.getMessage("AppTitle"));
// alert.setContentText(MessageFormat.format(AppVaribles.getMessage("AlarmClocksRunning"), AppVaribles.scheduledTasks.size()));
// ButtonType buttonStopAlarmsExit = new ButtonType(AppVaribles.getMessage("StopAlarmsExit"));
// ButtonType buttonKeepAlarmsExit = new ButtonType(AppVaribles.getMessage("KeepAlarmsExit"));
// ButtonType buttonCancel = new ButtonType(AppVaribles.getMessage("Cancel"));
// alert.getButtonTypes().setAll(buttonStopAlarmsExit, buttonKeepAlarmsExit, buttonCancel);
//
// Optional<ButtonType> result = alert.showAndWait();
// if (result.get() == buttonStopAlarmsExit) {

if (AppVaribles.getConfigBoolean("StopAlarmsWhenExit")) {
for (Long key : AppVaribles.scheduledTasks.keySet()) {
ScheduledFuture future = AppVaribles.scheduledTasks.get(key);
future.cancel(true);
Expand All @@ -507,6 +513,7 @@ public void stageClosing(WindowEvent event) {
AppVaribles.executorService = null;
}
}

} else {
if (AppVaribles.scheduledTasks != null) {
AppVaribles.scheduledTasks = null;
Expand All @@ -521,9 +528,11 @@ public void stageClosing(WindowEvent event) {
Platform.setImplicitExit(true);
}
// logger.debug(Platform.isImplicitExit());
return true;

} catch (Exception e) {
logger.debug(e.toString());
return false;
}

}
Expand Down Expand Up @@ -598,7 +607,7 @@ public void showImageManufacture(String filename) {
}
}

public void openLoadingStage(final Task<?> task, Modality block) {
public void openHandlingStage(final Task<?> task, Modality block) {
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(CommonValues.LoadingFxml), AppVaribles.CurrentBundle);
Pane pane = fxmlLoader.load();
Expand All @@ -607,7 +616,7 @@ public void openLoadingStage(final Task<?> task, Modality block) {

loadingStage = new Stage();
loadingStage.initModality(block);
loadingStage.initStyle(StageStyle.UNDECORATED);
// loadingStage.initStyle(StageStyle.UNDECORATED);
loadingStage.initStyle(StageStyle.TRANSPARENT);
loadingStage.initOwner(getMyStage());
loadingStage.setScene(new Scene(pane));
Expand Down Expand Up @@ -1043,4 +1052,44 @@ public void setTargetIsFile(boolean targetIsFile) {
this.targetIsFile = targetIsFile;
}

public String getCurrentStatus() {
return currentStatus;
}

public void setCurrentStatus(String currentStatus) {
this.currentStatus = currentStatus;
}

public Label getBottomLabel() {
return bottomLabel;
}

public void setBottomLabel(Label bottomLabel) {
this.bottomLabel = bottomLabel;
}

public boolean isPaused() {
return paused;
}

public void setPaused(boolean paused) {
this.paused = paused;
}

public Pane getDirsTable() {
return dirsTable;
}

public void setDirsTable(Pane dirsTable) {
this.dirsTable = dirsTable;
}

public DirectoriesTableController getDirsTableController() {
return dirsTableController;
}

public void setDirsTableController(DirectoriesTableController dirsTableController) {
this.dirsTableController = dirsTableController;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -433,14 +433,14 @@ public void handle(ActionEvent event) {
showCost();
updateLogs(AppVaribles.getMessage("TotalCheckedFiles") + ": " + copyAttr.getTotalFilesNumber() + " "
+ AppVaribles.getMessage("TotalCheckedDirectories") + ": " + copyAttr.getTotalDirectoriesNumber() + " "
+ AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize2(copyAttr.getTotalSize()), false, true);
+ AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize(copyAttr.getTotalSize()), false, true);
updateLogs(AppVaribles.getMessage("TotalCopiedFiles") + ": " + copyAttr.getCopiedFilesNumber() + " "
+ AppVaribles.getMessage("TotalCopiedDirectories") + ": " + copyAttr.getCopiedDirectoriesNumber() + " "
+ AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize2(copyAttr.getCopiedSize()), false, true);
+ AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize(copyAttr.getCopiedSize()), false, true);
if (copyAttr.isConditionalCopy() && copyAttr.isDeleteNotExisteds()) {
updateLogs(AppVaribles.getMessage("TotalDeletedFiles") + ": " + copyAttr.getDeletedFiles() + " "
+ AppVaribles.getMessage("TotalDeletedDirectories") + ": " + copyAttr.getDeletedDirectories() + " "
+ AppVaribles.getMessage("TotalDeletedSize") + ": " + FileTools.showFileSize2(copyAttr.getDeletedSize()), false, true);
+ AppVaribles.getMessage("TotalDeletedSize") + ": " + FileTools.showFileSize(copyAttr.getDeletedSize()), false, true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,14 @@ public void handle(ActionEvent event) {
showCost();
updateLogs(AppVaribles.getMessage("TotalCheckedFiles") + ": " + copyAttr.getTotalFilesNumber() + " "
+ AppVaribles.getMessage("TotalCheckedDirectories") + ": " + copyAttr.getTotalDirectoriesNumber() + " "
+ AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize2(copyAttr.getTotalSize()), false, true);
+ AppVaribles.getMessage("TotalCheckedSize") + ": " + FileTools.showFileSize(copyAttr.getTotalSize()), false, true);
updateLogs(AppVaribles.getMessage("TotalCopiedFiles") + ": " + copyAttr.getCopiedFilesNumber() + " "
+ AppVaribles.getMessage("TotalCopiedDirectories") + ": " + copyAttr.getCopiedDirectoriesNumber() + " "
+ AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize2(copyAttr.getCopiedSize()), false, true);
+ AppVaribles.getMessage("TotalCopiedSize") + ": " + FileTools.showFileSize(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);
+ AppVaribles.getMessage("TotalDeletedSize") + ": " + FileTools.showFileSize(copyAttr.getDeletedSize()), false, true);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -124,6 +125,7 @@ protected Void call() throws Exception {
String format = FileTools.getFileSuffix(fileName).toLowerCase();
if (!"raw".equals(format) && !onlyInformation) {
bufferImage = ImageIO.read(file);
image = SwingFXUtils.toFXImage(bufferImage, null);
}
Platform.runLater(new Runnable() {
@Override
Expand All @@ -134,7 +136,7 @@ public void run() {
return null;
}
};
openLoadingStage(task, Modality.WINDOW_MODAL);
openHandlingStage(task, Modality.WINDOW_MODAL);
Thread thread = new Thread(task);
thread.setDaemon(true);
thread.start();
Expand Down
Loading

0 comments on commit 526a35b

Please sign in to comment.