Skip to content

Commit

Permalink
v2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mararsh committed Jul 11, 2018
1 parent 8cfeb5e commit ef42c50
Show file tree
Hide file tree
Showing 33 changed files with 1,427 additions and 430 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.1</version>
<version>2.2</version>
<packaging>jar</packaging>

<name>MyBox</name>
Expand Down
2 changes: 1 addition & 1 deletion MyBox/src/main/java/mara/mybox/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
62 changes: 60 additions & 2 deletions MyBox/src/main/java/mara/mybox/controller/BaseController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -50,13 +53,13 @@ public class BaseController implements Initializable {

protected List<FileChooser.ExtensionFilter> fileExtensionFilter;

protected String myFxml, parentFxml;
protected String myFxml, parentFxml, currentStatus;
protected Stage myStage, loadingStage;
protected Alert loadingAlert;
protected Task<Void> task;
protected BaseController parentController;

protected boolean isPreview, targetIsFile;
protected boolean isPreview, targetIsFile, paused;
protected File sourceFile, targetPath;
protected List<File> sourceFiles;
protected ObservableList<FileInformation> sourceFilesInformation;
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand All @@ -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<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
stageClosing(event);
}
});
} catch (Exception e) {
logger.error(e.toString());
}
Expand Down Expand Up @@ -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<WindowEvent>() {
@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<ButtonType> 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);
Expand Down
Loading

0 comments on commit ef42c50

Please sign in to comment.