InfoAlert & ProcessBuilder

* we use an Alert now to display Info Messages
* use ProcessBuilder instead of Runtime.exec()
This commit is contained in:
Jannik 2018-06-12 16:01:21 +02:00
parent c6a40f8937
commit cc4e73c45d
4 changed files with 86 additions and 59 deletions

View File

@ -60,7 +60,7 @@ import com.cemu_UI.datatypes.CourseTableDataType;
import com.cemu_UI.datatypes.SmmdbApiDataType; import com.cemu_UI.datatypes.SmmdbApiDataType;
import com.cemu_UI.datatypes.UIROMDataType; import com.cemu_UI.datatypes.UIROMDataType;
import com.cemu_UI.uiElements.JFXEditGameDialog; 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.JFXOkayCancelDialog;
import com.cemu_UI.uiElements.JFXTextAreaInfoDialog; import com.cemu_UI.uiElements.JFXTextAreaInfoDialog;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
@ -810,8 +810,8 @@ public class MainWindowController {
saveSettings(); saveSettings();
} else { } else {
String bodyText = newValue + ": No such file or directory"; String bodyText = newValue + ": No such file or directory";
JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane()); JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, main.getPrimaryStage());
fileErrorDialog.show(); fileErrorDialog.showAndWait();
LOGGER.warn(newValue + ": No such file or directory"); LOGGER.warn(newValue + ": No such file or directory");
} }
} }
@ -826,8 +826,8 @@ public class MainWindowController {
reloadRoms(); reloadRoms();
} else { } else {
String bodyText = newValue + ": No such file or directory"; String bodyText = newValue + ": No such file or directory";
JFXInfoDialog fileErrorDialog = new JFXInfoDialog("Waring!", bodyText, dialogBtnStyle, 190, 150, main.getPane()); JFXInfoAlert fileErrorDialog = new JFXInfoAlert("Waring!", bodyText, dialogBtnStyle, main.getPrimaryStage());
fileErrorDialog.show(); fileErrorDialog.showAndWait();
LOGGER.warn(newValue + ": No such file or directory"); LOGGER.warn(newValue + ": No such file or directory");
} }
} }
@ -842,11 +842,12 @@ public class MainWindowController {
} }
@FXML @FXML
void aboutBtnAction() { private void aboutBtnAction() {
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n" String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (" + buildNumber + ") \"" + versionName + "\" \n"
+ aboutBtnBodyText; + 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 @FXML
@ -1069,9 +1070,9 @@ public class MainWindowController {
cloudSyncToggleBtn.setSelected(false); cloudSyncToggleBtn.setSelected(false);
// cloud sync init error dialog // cloud sync init error dialog
JFXInfoDialog cloudSyncErrorDialog = new JFXInfoDialog(cloudSyncErrorHeadingText, JFXInfoAlert cloudSyncErrorDialog = new JFXInfoAlert(cloudSyncErrorHeadingText,
cloudSyncErrorBodyText, dialogBtnStyle, 450, 170, main.getPane()); cloudSyncErrorBodyText, dialogBtnStyle, main.getPrimaryStage());
cloudSyncErrorDialog.show(); cloudSyncErrorDialog.showAndWait();
} }
} }
@ -1123,9 +1124,9 @@ public class MainWindowController {
LOGGER.info("No parameter set!"); LOGGER.info("No parameter set!");
//addGame error dialog //addGame error dialog
JFXInfoDialog errorDialog = new JFXInfoDialog(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText, JFXInfoAlert errorDialog = new JFXInfoAlert(addBtnReturnErrorHeadingText, addBtnReturnErrorBodyText,
dialogBtnStyle, 350, 170, main.getPane()); dialogBtnStyle, main.getPrimaryStage());
errorDialog.show(); errorDialog.showAndWait();
} else { } else {
File pictureCache = main.getPictureCache(); File pictureCache = main.getPictureCache();

View File

@ -147,7 +147,7 @@ public class UpdateController implements Runnable {
FileUtils.copyInputStreamToFile(pmis, new File("cemu_UI_update.jar")); // download update 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.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 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 System.exit(0); // finishes itself
} catch (IOException e) { } catch (IOException e) {
Platform.runLater(() -> { Platform.runLater(() -> {

View File

@ -117,8 +117,8 @@ public class JFXEditGameDialog {
// addGame error dialog // addGame error dialog
String headingTextError = mwc.getBundle().getString("editGameDialogHeadingTextError"); String headingTextError = mwc.getBundle().getString("editGameDialogHeadingTextError");
String bodyTextError = mwc.getBundle().getString("editGameDialogBodyTextError"); String bodyTextError = mwc.getBundle().getString("editGameDialogBodyTextError");
JFXInfoDialog errorDialog = new JFXInfoDialog(headingTextError, bodyTextError, dialogBtnStyle, 350,170, pane); JFXInfoAlert errorDialog = new JFXInfoAlert(headingTextError, bodyTextError, dialogBtnStyle, stage);
errorDialog.show(); errorDialog.showAndWait();
} else { } else {
switch (mode) { switch (mode) {
case 0: case 0:

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -20,66 +20,92 @@
*/ */
package com.cemu_UI.uiElements; package com.cemu_UI.uiElements;
import com.jfoenix.controls.JFXAlert;
import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialog;
import com.jfoenix.controls.JFXDialogLayout; import com.jfoenix.controls.JFXDialogLayout;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; 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.scene.text.Text;
import javafx.stage.Stage;
public class JFXInfoDialog { public class JFXInfoAlert {
private String headingText; private String headingText;
private String bodyText; private String bodyText;
private String dialogBtnStyle; private String btnStyle;
private int dialogWidth; private Stage stage;
private int dialogHeight;
private Pane pane;
/** /**
* Creates a new JFoenix Dialog to show some information * Creates a new JFoenix Alert to show some information
* @param headingText Heading Text, just the heading * @param headerText Heading text of the alert
* @param bodyText body Text, all other text belongs here * @param bodyText Content text of the alert
* @param dialogBtnStyle Style of the okay button * @param btnStyle Style of the okay button
* @param dialogWidth dialog width * @param stage stage to which the dialog belongs
* @param dialogHeight dialog height
* @param pane pane to which the dialog belongs
*/ */
public JFXInfoDialog(String headingText, String bodyText, String dialogBtnStyle, int dialogWidth, int dialogHeight, Pane pane) { public JFXInfoAlert(String headingText, String bodyText, String btnStyle, Stage stage) {
this.headingText = headingText; setHeadingText(headingText);
this.bodyText = bodyText; setBodyText(bodyText);
this.dialogBtnStyle = dialogBtnStyle; setBtnStyle(btnStyle);
this.dialogWidth = dialogWidth; setStage(stage);
this.dialogHeight = dialogHeight;
this.pane = pane;
} }
public void show() { public JFXInfoAlert() {
JFXDialogLayout content = new JFXDialogLayout(); // Auto-generated constructor stub
content.setHeading(new Text(headingText)); }
content.setBody(new Text(bodyText));
content.setPrefSize(dialogWidth, dialogHeight); public void showAndWait( ) {
StackPane stackPane = new StackPane(); JFXAlert<Void> alert = new JFXAlert<>(stage);
stackPane.autosize();
JFXDialog dialog = new JFXDialog(stackPane, content, JFXDialog.DialogTransition.LEFT, true);
JFXButton button = new JFXButton("Okay"); JFXButton button = new JFXButton("Okay");
button.setOnAction(new EventHandler<ActionEvent>() { button.setOnAction(new EventHandler<ActionEvent>() {
@Override @Override
public void handle(ActionEvent event) { public void handle(ActionEvent event) {
dialog.close(); alert.close();
} }
}); });
button.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED); button.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
button.setPrefHeight(32); button.setPrefHeight(32);
button.setStyle(dialogBtnStyle); button.setStyle(btnStyle);
JFXDialogLayout content = new JFXDialogLayout();
content.setActions(button); content.setActions(button);
pane.getChildren().add(stackPane); content.setHeading(new Text(headingText));
AnchorPane.setTopAnchor(stackPane, (pane.getHeight() - content.getPrefHeight()) / 2); content.setBody(new Text(bodyText));
AnchorPane.setLeftAnchor(stackPane, (pane.getWidth() - content.getPrefWidth()) / 2); alert.setContent(content);
dialog.show(); 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;
}
}