From cc4e73c45d1afb12b8769be62c5673e793dacc0b Mon Sep 17 00:00:00 2001 From: Jannik Date: Tue, 12 Jun 2018 16:01:21 +0200 Subject: [PATCH] InfoAlert & ProcessBuilder * we use an Alert now to display Info Messages * use ProcessBuilder instead of Runtime.exec() --- .../application/MainWindowController.java | 29 ++--- .../cemu_UI/controller/UpdateController.java | 2 +- .../cemu_UI/uiElements/JFXEditGameDialog.java | 4 +- .../{JFXInfoDialog.java => JFXInfoAlert.java} | 110 +++++++++++------- 4 files changed, 86 insertions(+), 59 deletions(-) rename src/main/java/com/cemu_UI/uiElements/{JFXInfoDialog.java => JFXInfoAlert.java} (51%) diff --git a/src/main/java/com/cemu_UI/application/MainWindowController.java b/src/main/java/com/cemu_UI/application/MainWindowController.java index 7d00604..a675138 100644 --- a/src/main/java/com/cemu_UI/application/MainWindowController.java +++ b/src/main/java/com/cemu_UI/application/MainWindowController.java @@ -60,7 +60,7 @@ import com.cemu_UI.datatypes.CourseTableDataType; import com.cemu_UI.datatypes.SmmdbApiDataType; import com.cemu_UI.datatypes.UIROMDataType; import com.cemu_UI.uiElements.JFXEditGameDialog; -import com.cemu_UI.uiElements.JFXInfoDialog; +import com.cemu_UI.uiElements.JFXInfoAlert; import com.cemu_UI.uiElements.JFXOkayCancelDialog; import com.cemu_UI.uiElements.JFXTextAreaInfoDialog; import com.jfoenix.controls.JFXButton; @@ -810,8 +810,8 @@ public class MainWindowController { saveSettings(); } else { String bodyText = newValue + ": No such file or directory"; - JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane()); - fileErrorDialog.show(); + JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, main.getPrimaryStage()); + fileErrorDialog.showAndWait(); LOGGER.warn(newValue + ": No such file or directory"); } } @@ -826,8 +826,8 @@ public class MainWindowController { reloadRoms(); } else { String bodyText = newValue + ": No such file or directory"; - JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane()); - fileErrorDialog.show(); + JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, main.getPrimaryStage()); + fileErrorDialog.showAndWait(); LOGGER.warn(newValue + ": No such file or directory"); } } @@ -842,11 +842,12 @@ public class MainWindowController { } @FXML - void aboutBtnAction() { + private void aboutBtnAction() { String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n" + aboutBtnBodyText; - JFXInfoDialog aboutDialog = new JFXInfoDialog(aboutBtnHeadingText, bodyText, dialogBtnStyle, 350, 200, main.getPane()); - aboutDialog.show(); + + JFXInfoAlert infoAlert = new JFXInfoAlert(aboutBtnHeadingText, bodyText, dialogBtnStyle, main.getPrimaryStage()); + infoAlert.showAndWait(); } @FXML @@ -1069,9 +1070,9 @@ public class MainWindowController { cloudSyncToggleBtn.setSelected(false); // cloud sync init error dialog - JFXInfoDialog cloudSyncErrorDialog = new JFXInfoDialog(cloudSyncErrorHeadingText, - cloudSyncErrorBodyText, dialogBtnStyle, 450, 170, main.getPane()); - cloudSyncErrorDialog.show(); + JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(cloudSyncErrorHeadingText, + cloudSyncErrorBodyText, dialogBtnStyle, main.getPrimaryStage()); + cloudSyncErrorDialog.showAndWait(); } } @@ -1123,9 +1124,9 @@ public class MainWindowController { LOGGER.info("No parameter set!"); //addGame error dialog - JFXInfoDialog errorDialog = new JFXInfoDialog(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText, - dialogBtnStyle, 350, 170, main.getPane()); - errorDialog.show(); + JFXInfoAlert errorDialog = new JFXInfoAlert(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText, + dialogBtnStyle, main.getPrimaryStage()); + errorDialog.showAndWait(); } else { File pictureCache = main.getPictureCache(); diff --git a/src/main/java/com/cemu_UI/controller/UpdateController.java b/src/main/java/com/cemu_UI/controller/UpdateController.java index d214505..03aed13 100644 --- a/src/main/java/com/cemu_UI/controller/UpdateController.java +++ b/src/main/java/com/cemu_UI/controller/UpdateController.java @@ -147,7 +147,7 @@ public class UpdateController implements Runnable { FileUtils.copyInputStreamToFile(pmis, new File("cemu_UI_update.jar")); // download update org.apache.commons.io.FileUtils.copyFile(new File("cemu_UI_update.jar"), new File("cemu_UI.jar")); org.apache.commons.io.FileUtils.deleteQuietly(new File("cemu_UI_update.jar")); // delete update - Runtime.getRuntime().exec("java -jar cemu_UI.jar"); // start again TODO consider ProcessBuilder to execute + new ProcessBuilder("java", "-jar", "cemu_UI.jar").start(); // start the new application System.exit(0); // finishes itself } catch (IOException e) { Platform.runLater(() -> { diff --git a/src/main/java/com/cemu_UI/uiElements/JFXEditGameDialog.java b/src/main/java/com/cemu_UI/uiElements/JFXEditGameDialog.java index 0487b14..78ba990 100644 --- a/src/main/java/com/cemu_UI/uiElements/JFXEditGameDialog.java +++ b/src/main/java/com/cemu_UI/uiElements/JFXEditGameDialog.java @@ -117,8 +117,8 @@ public class JFXEditGameDialog { // addGame error dialog String headingTextError = mwc.getBundle().getString("editGameDialogHeadingTextError"); String bodyTextError = mwc.getBundle().getString("editGameDialogBodyTextError"); - JFXInfoDialog errorDialog = new JFXInfoDialog(headingTextError, bodyTextError, dialogBtnStyle, 350,170, pane); - errorDialog.show(); + JFXInfoAlert errorDialog = new JFXInfoAlert(headingTextError, bodyTextError, dialogBtnStyle, stage); + errorDialog.showAndWait(); } else { switch (mode) { case 0: diff --git a/src/main/java/com/cemu_UI/uiElements/JFXInfoDialog.java b/src/main/java/com/cemu_UI/uiElements/JFXInfoAlert.java similarity index 51% rename from src/main/java/com/cemu_UI/uiElements/JFXInfoDialog.java rename to src/main/java/com/cemu_UI/uiElements/JFXInfoAlert.java index ee2513a..04399aa 100644 --- a/src/main/java/com/cemu_UI/uiElements/JFXInfoDialog.java +++ b/src/main/java/com/cemu_UI/uiElements/JFXInfoAlert.java @@ -1,7 +1,7 @@ /** - * cemu_UI + * Kellerkinder Framework Alerts * - * Copyright 2017-2018 <@Seil0> + * Copyright 2018 <@Seil0> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,66 +20,92 @@ */ package com.cemu_UI.uiElements; +import com.jfoenix.controls.JFXAlert; import com.jfoenix.controls.JFXButton; -import com.jfoenix.controls.JFXDialog; import com.jfoenix.controls.JFXDialogLayout; import javafx.event.ActionEvent; import javafx.event.EventHandler; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.Pane; -import javafx.scene.layout.StackPane; import javafx.scene.text.Text; +import javafx.stage.Stage; -public class JFXInfoDialog { - +public class JFXInfoAlert { + private String headingText; private String bodyText; - private String dialogBtnStyle; - private int dialogWidth; - private int dialogHeight; - private Pane pane; + private String btnStyle; + private Stage stage; /** - * Creates a new JFoenix Dialog to show some information - * @param headingText Heading Text, just the heading - * @param bodyText body Text, all other text belongs here - * @param dialogBtnStyle Style of the okay button - * @param dialogWidth dialog width - * @param dialogHeight dialog height - * @param pane pane to which the dialog belongs + * Creates a new JFoenix Alert to show some information + * @param headerText Heading text of the alert + * @param bodyText Content text of the alert + * @param btnStyle Style of the okay button + * @param stage stage to which the dialog belongs */ - public JFXInfoDialog(String headingText, String bodyText, String dialogBtnStyle, int dialogWidth, int dialogHeight, Pane pane) { - this.headingText = headingText; - this.bodyText = bodyText; - this.dialogBtnStyle = dialogBtnStyle; - this.dialogWidth = dialogWidth; - this.dialogHeight = dialogHeight; - this.pane = pane; + public JFXInfoAlert(String headingText, String bodyText, String btnStyle, Stage stage) { + setHeadingText(headingText); + setBodyText(bodyText); + setBtnStyle(btnStyle); + setStage(stage); } - - public void show() { - JFXDialogLayout content = new JFXDialogLayout(); - content.setHeading(new Text(headingText)); - content.setBody(new Text(bodyText)); - content.setPrefSize(dialogWidth, dialogHeight); - StackPane stackPane = new StackPane(); - stackPane.autosize(); - JFXDialog dialog = new JFXDialog(stackPane, content, JFXDialog.DialogTransition.LEFT, true); + + public JFXInfoAlert() { + // Auto-generated constructor stub + } + + public void showAndWait( ) { + JFXAlert alert = new JFXAlert<>(stage); + JFXButton button = new JFXButton("Okay"); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { - dialog.close(); + alert.close(); } }); button.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED); button.setPrefHeight(32); - button.setStyle(dialogBtnStyle); + button.setStyle(btnStyle); + + JFXDialogLayout content = new JFXDialogLayout(); content.setActions(button); - pane.getChildren().add(stackPane); - AnchorPane.setTopAnchor(stackPane, (pane.getHeight() - content.getPrefHeight()) / 2); - AnchorPane.setLeftAnchor(stackPane, (pane.getWidth() - content.getPrefWidth()) / 2); - dialog.show(); + content.setHeading(new Text(headingText)); + content.setBody(new Text(bodyText)); + alert.setContent(content); + alert.showAndWait(); } -} + + public String getHeadingText() { + return headingText; + } + + public void setHeadingText(String headingText) { + this.headingText = headingText; + } + + public String getBodyText() { + return bodyText; + } + + public void setBodyText(String bodyText) { + this.bodyText = bodyText; + } + + public String getBtnStyle() { + return btnStyle; + } + + public void setBtnStyle(String btnStyle) { + this.btnStyle = btnStyle; + } + + public Stage getStage() { + return stage; + } + + public void setStage(Stage stage) { + this.stage = stage; + } + +} \ No newline at end of file