use alerts instead of dialogs

* the first start alert is now material styled
* the info dialog is now a alert
This commit is contained in:
Jannik 2018-03-29 18:15:57 +02:00
parent 34371bb2b5
commit 22df604093
5 changed files with 305 additions and 334 deletions

View File

@ -1,194 +0,0 @@
package com.cemu_UI.uiElements;
import java.util.ResourceBundle;
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;
public class JFXDirStrmCancelDialog {
private String headingText;
private String bodyText;
private String dialogBtnStyle;
private String btn1Text;
private String btn2Text;
private String cancelText;
private int dialogWidth;
private int dialogHeight;
private EventHandler<ActionEvent> btn1Action;
private EventHandler<ActionEvent> btn2Action;
private Pane pane;
/**
* Creates a new JFoenix Dialog to show some information with okay and cancel
* option
*
* @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 btn1Action action which is performed if btn1 is clicked
* @param btn2Action action which is performed if btn2 is clicked
* @param cancelAction action which is performed if the cancel button is clicked
* @param pane pane to which the dialog belongs
*/
public JFXDirStrmCancelDialog(String headingText, String bodyText, String dialogBtnStyle, int dialogWidth,
int dialogHeight, EventHandler<ActionEvent> btn1Action, EventHandler<ActionEvent> btn2Action,
Pane pane, ResourceBundle bundle) {
setHeadingText(headingText);
setBodyText(bodyText);
setDialogBtnStyle(dialogBtnStyle);
setDialogWidth(dialogWidth);
setDialogHeight(dialogHeight);
setBtn1Action(btn1Action);
setBtn2Action(btn2Action);
setPane(pane);
btn1Text = bundle.getString("addDirectory");
btn2Text = bundle.getString("addStreamSource");
cancelText = bundle.getString("cancelBtnText");
}
public JFXDirStrmCancelDialog() {
// Auto-generated constructor stub
}
public void show() {
JFXDialogLayout content = new JFXDialogLayout();
content.setHeading(new Text(headingText));
content.setBody(new Text(bodyText));
StackPane stackPane = new StackPane();
stackPane.autosize();
JFXDialog dialog = new JFXDialog(stackPane, content, JFXDialog.DialogTransition.LEFT, true);
JFXButton btn1 = new JFXButton(btn1Text);
btn1.addEventHandler(ActionEvent.ACTION, (e) -> {
dialog.close();
});
btn1.addEventHandler(ActionEvent.ACTION, btn1Action);
btn1.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
btn1.setPrefHeight(32);
btn1.setStyle(dialogBtnStyle);
JFXButton btn2 = new JFXButton(btn2Text);
btn2.addEventHandler(ActionEvent.ACTION, (e) -> {
dialog.close();
});
btn2.addEventHandler(ActionEvent.ACTION, btn2Action);
btn2.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
btn2.setPrefHeight(32);
btn2.setStyle(dialogBtnStyle);
JFXButton cancelBtn = new JFXButton(cancelText);
cancelBtn.addEventHandler(ActionEvent.ACTION, (e) -> {
dialog.close();
});
cancelBtn.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
cancelBtn.setPrefHeight(32);
cancelBtn.setStyle(dialogBtnStyle);
content.setActions(cancelBtn, btn1, btn2);
content.setPrefSize(dialogWidth, dialogHeight);
pane.getChildren().add(stackPane);
AnchorPane.setTopAnchor(stackPane, (pane.getHeight() - content.getPrefHeight()) / 2);
AnchorPane.setLeftAnchor(stackPane, (pane.getWidth() - content.getPrefWidth()) / 2);
dialog.show();
}
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 getDialogBtnStyle() {
return dialogBtnStyle;
}
public void setDialogBtnStyle(String dialogBtnStyle) {
this.dialogBtnStyle = dialogBtnStyle;
}
public String getBtn1Text() {
return btn1Text;
}
public void setBtn1Text(String btn1Text) {
this.btn1Text = btn1Text;
}
public String getBtn2Text() {
return btn2Text;
}
public void setBtn2Text(String btn2Text) {
this.btn2Text = btn2Text;
}
public String getCancelText() {
return cancelText;
}
public void setCancelText(String cancelText) {
this.cancelText = cancelText;
}
public int getDialogWidth() {
return dialogWidth;
}
public void setDialogWidth(int dialogWidth) {
this.dialogWidth = dialogWidth;
}
public int getDialogHeight() {
return dialogHeight;
}
public void setDialogHeight(int dialogHeight) {
this.dialogHeight = dialogHeight;
}
public EventHandler<ActionEvent> getBtn1Action() {
return btn1Action;
}
public void setBtn1Action(EventHandler<ActionEvent> btn1Action) {
this.btn1Action = btn1Action;
}
public EventHandler<ActionEvent> getBtn2Action() {
return btn2Action;
}
public void setBtn2Action(EventHandler<ActionEvent> btn2Action) {
this.btn2Action = btn2Action;
}
public Pane getPane() {
return pane;
}
public void setPane(Pane pane) {
this.pane = pane;
}
}

View File

@ -25,35 +25,25 @@ package kellerkinder.HomeFlix.application;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.Optional;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.kellerkinder.Alerts.JFX2BtnCancelAlert;
import com.jfoenix.controls.JFXAlert;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialogLayout;
import javafx.application.Application; import javafx.application.Application;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonBar.ButtonData;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.text.Text;
import javafx.stage.DirectoryChooser; import javafx.stage.DirectoryChooser;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Stage; import javafx.stage.Stage;
public class Main extends Application { public class Main extends Application {
private Stage primaryStage; private Stage primaryStage;
private Scene scene; private Scene scene;
private AnchorPane pane; private AnchorPane pane;
@ -64,29 +54,29 @@ public class Main extends Application {
private static String osArch = System.getProperty("os.arch"); private static String osArch = System.getProperty("os.arch");
private static String osVers = System.getProperty("os.version"); private static String osVers = System.getProperty("os.version");
private static String javaVers = System.getProperty("java.version"); private static String javaVers = System.getProperty("java.version");
private static String javaVend= System.getProperty("java.vendor"); private static String javaVend = System.getProperty("java.vendor");
private String dirWin = userHome + "/Documents/HomeFlix"; //Windows: C:/Users/"User"/Documents/HomeFlix private String dirWin = userHome + "/Documents/HomeFlix"; // Windows: C:/Users/"User"/Documents/HomeFlix
private String dirLinux = userHome + "/HomeFlix"; //Linux: /home/"User"/HomeFlix private String dirLinux = userHome + "/HomeFlix"; // Linux: /home/"User"/HomeFlix
private File directory; private File directory;
private File configFile; private File configFile;
private File posterCache; private File posterCache;
private String FONT_FAMILY = "System"; private String FONT_FAMILY = "System";
private String local = System.getProperty("user.language")+"_"+System.getProperty("user.country"); private String local = System.getProperty("user.language") + "_" + System.getProperty("user.country");
private double FONT_SIZE = 17; private double FONT_SIZE = 17;
private ResourceBundle bundle; private ResourceBundle bundle;
private static Logger LOGGER; private static Logger LOGGER;
@Override @Override
public void start(Stage primaryStage) throws IOException { public void start(Stage primaryStage) throws IOException {
LOGGER.info("OS: " + osName + " " + osVers + " " + osArch); LOGGER.info("OS: " + osName + " " + osVers + " " + osArch);
LOGGER.info("Java: " + javaVend + " " + javaVers); LOGGER.info("Java: " + javaVend + " " + javaVers);
LOGGER.info("User: " + userName + " " + userHome); LOGGER.info("User: " + userName + " " + userHome);
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
mainWindow(); mainWindow();
} }
private void mainWindow(){ private void mainWindow(){
try { try {
FXMLLoader loader = new FXMLLoader(); FXMLLoader loader = new FXMLLoader();
@ -133,12 +123,6 @@ public class Main extends Application {
posterCache.mkdir(); posterCache.mkdir();
} }
// // generate window
// scene = new Scene(pane); // create new scene, append pane to scene
// scene.getStylesheets().add(getClass().getResource("/css/MainWindow.css").toExternalForm());
// primaryStage.setScene(scene); // append scene to stage
// primaryStage.show(); // show stage
// init here as it loads the games to the mwc and the gui, therefore the window must exist // init here as it loads the games to the mwc and the gui, therefore the window must exist
mainWindowController.init(); mainWindowController.init();
mainWindowController.getDbController().init(); mainWindowController.getDbController().init();
@ -146,11 +130,12 @@ public class Main extends Application {
LOGGER.error(e); LOGGER.error(e);
} }
} }
/** TODO add option to add streaming as first source /**
* when there i no config.xml we need to get the path for the first source from the user * TODO add option to add streaming as first source when there i no config.xml
* we need to get the path for the first source from the user
*/ */
private void getFirstSource(){ private void getFirstSource() {
switch (System.getProperty("user.language") + "_" + System.getProperty("user.country")) { switch (System.getProperty("user.language") + "_" + System.getProperty("user.country")) {
case "en_US": case "en_US":
bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english bundle = ResourceBundle.getBundle("locals.HomeFlix-Local", Locale.US); // us_english
@ -163,85 +148,56 @@ public class Main extends Application {
break; break;
} }
// // directory action JFX2BtnCancelAlert selectFirstSource = new JFX2BtnCancelAlert(bundle.getString("addSourceHeader"),
// EventHandler<ActionEvent> btn1Action = new EventHandler<ActionEvent>() { bundle.getString("addSourceBody"),
// @Override "-fx-button-type: RAISED; -fx-background-color: #ee3523; -fx-text-fill: BLACK;",
// public void handle(ActionEvent event) { bundle.getString("addDirectory"), bundle.getString("addStreamSource"),
// DirectoryChooser directoryChooser = new DirectoryChooser(); bundle.getString("cancelBtnText"), primaryStage);
// directoryChooser.setTitle(bundle.getString("addDirectory"));
// File selectedFolder = directoryChooser.showDialog(primaryStage);
// if (selectedFolder != null && selectedFolder.exists()) {
// mainWindowController.addSource(selectedFolder.getPath(), "local");
// } else {
// LOGGER.error("The selected folder dosen't exist!");
// }
// }
// };
//
// // streaming action
// EventHandler<ActionEvent> btn2Action = new EventHandler<ActionEvent>() {
// @Override
// public void handle(ActionEvent event) {
// FileChooser fileChooser = new FileChooser();
// fileChooser.setTitle("addStreamSource");
// File selectedFile = fileChooser.showOpenDialog(getPrimaryStage());
// if (selectedFile != null && selectedFile.exists()) {
// mainWindowController.addSource(selectedFile.getPath(), "stream");
// } else {
// LOGGER.error("The selected file dosen't exist!");
// }
// }
// };
//
// JFXDirStrmCancelDialog selectFirstSource = new JFXDirStrmCancelDialog(bundle.getString("addSourceHeader"),
// bundle.getString("addSourceBody"), "", 200, 100, btn1Action, btn2Action, pane, bundle);
// selectFirstSource.show();
Alert alert = new Alert(AlertType.CONFIRMATION); //new alert with DirectoryChooser
alert.setTitle("Project HomeFlix");
alert.setHeaderText(bundle.getString("addSourceHeader"));
alert.setContentText(bundle.getString("addSourceBody"));
alert.setResizable(true);
ButtonType buttonDirectory = new ButtonType(bundle.getString("addDirectory"));
ButtonType buttonStreaming = new ButtonType(bundle.getString("addStreamSource"));
ButtonType buttonCancel = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE);
alert.getButtonTypes().setAll(buttonDirectory, buttonStreaming, buttonCancel); // directory action
EventHandler<ActionEvent> btn1Action = new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
DirectoryChooser directoryChooser = new DirectoryChooser();
directoryChooser.setTitle(bundle.getString("addDirectory"));
File selectedFolder = directoryChooser.showDialog(primaryStage);
if (selectedFolder != null && selectedFolder.exists()) {
mainWindowController.addSource(selectedFolder.getPath(), "local");
selectFirstSource.getAlert().close();
} else {
LOGGER.error("The selected folder dosen't exist!");
System.exit(1);
}
}
};
Optional<ButtonType> result = alert.showAndWait(); // streaming action
if (result.get() == buttonDirectory) { EventHandler<ActionEvent> btn2Action = new EventHandler<ActionEvent>() {
DirectoryChooser directoryChooser = new DirectoryChooser(); @Override
directoryChooser.setTitle(bundle.getString("addDirectory")); public void handle(ActionEvent event) {
File selectedFolder = directoryChooser.showDialog(primaryStage); FileChooser fileChooser = new FileChooser();
if (selectedFolder != null && selectedFolder.exists()) { fileChooser.setTitle("addStreamSource");
mainWindowController.addSource(selectedFolder.getPath(), "local"); File selectedFile = fileChooser.showOpenDialog(getPrimaryStage());
} else { if (selectedFile != null && selectedFile.exists()) {
LOGGER.error("The selected folder dosen't exist!"); mainWindowController.addSource(selectedFile.getPath(), "stream");
System.exit(1); selectFirstSource.getAlert().close();
} else {
LOGGER.error("The selected file dosen't exist!");
System.exit(1);
}
} }
} else if (result.get() == buttonStreaming) { };
FileChooser fileChooser = new FileChooser(); selectFirstSource.setBtn1Action(btn1Action);
fileChooser.setTitle("addStreamSource"); selectFirstSource.setBtn2Action(btn2Action);
File selectedFile = fileChooser.showOpenDialog(getPrimaryStage()); selectFirstSource.showAndWait();
if (selectedFile != null && selectedFile.exists()) {
mainWindowController.addSource(selectedFile.getPath(), "stream");
} else {
LOGGER.error("The selected file dosen't exist!");
System.exit(1);
}
} else {
LOGGER.warn("No source selected!");
System.exit(1);
}
} }
public static void main(String[] args) { public static void main(String[] args) {
if(System.getProperty("os.name").equals("Windows")){ if (System.getProperty("os.name").equals("Windows")) {
System.setProperty("logFilename", userHome + "/Documents/HomeFlix/app.log"); System.setProperty("logFilename", userHome + "/Documents/HomeFlix/app.log");
File logFile = new File(userHome + "/Documents/HomeFlix/app.log"); File logFile = new File(userHome + "/Documents/HomeFlix/app.log");
logFile.delete(); logFile.delete();
}else{ } else {
System.setProperty("logFilename", userHome + "/HomeFlix/app.log"); System.setProperty("logFilename", userHome + "/HomeFlix/app.log");
File logFile = new File(userHome + "/HomeFlix/app.log"); File logFile = new File(userHome + "/HomeFlix/app.log");
logFile.delete(); logFile.delete();
@ -257,8 +213,8 @@ public class Main extends Application {
public void setPrimaryStage(Stage primaryStage) { public void setPrimaryStage(Stage primaryStage) {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
} }
public AnchorPane getPane( ) { public AnchorPane getPane() {
return pane; return pane;
} }
@ -269,7 +225,7 @@ public class Main extends Application {
public void setFONT_FAMILY(String FONT_FAMILY) { public void setFONT_FAMILY(String FONT_FAMILY) {
this.FONT_FAMILY = FONT_FAMILY; this.FONT_FAMILY = FONT_FAMILY;
} }
public File getDirectory() { public File getDirectory() {
return directory; return directory;
} }

View File

@ -44,6 +44,7 @@ import java.util.ResourceBundle;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.kellerkinder.Alerts.JFXInfoAlert;
import com.cemu_UI.uiElements.JFXInfoDialog; import com.cemu_UI.uiElements.JFXInfoDialog;
import com.eclipsesource.json.Json; import com.eclipsesource.json.Json;
@ -231,9 +232,9 @@ public class MainWindowController {
private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName()); private static final Logger LOGGER = LogManager.getLogger(MainWindowController.class.getName());
private int hashA = -647380320; private int hashA = -647380320;
private String version = "0.6.0"; private String version = "0.6.1";
private String buildNumber = "141"; private String buildNumber = "145";
private String versionName = "plasma vampire"; private String versionName = "glowing vampire";
private String dialogBtnStyle; private String dialogBtnStyle;
private String color; private String color;
private String title; private String title;
@ -609,8 +610,8 @@ public class MainWindowController {
private void aboutBtnAction() { private void aboutBtnAction() {
String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (Build: " + buildNumber + ") \"" String bodyText = "cemu_UI by @Seil0 \nVersion: " + version + " (Build: " + buildNumber + ") \""
+ versionName + "\" \n" + infoText; + versionName + "\" \n" + infoText;
JFXInfoDialog aboutDialog = new JFXInfoDialog("Project HomeFlix", bodyText, dialogBtnStyle, 350, 200, main.getPane()); JFXInfoAlert infoAlert = new JFXInfoAlert("Project HomeFlix", bodyText, dialogBtnStyle, main.getPrimaryStage());
aboutDialog.show(); infoAlert.showAndWait();
} }
@FXML @FXML

View File

@ -0,0 +1,190 @@
/**
* Kellerkinder Framework Alerts
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.kellerkinder.Alerts;
import com.jfoenix.controls.JFXAlert;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialogLayout;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class JFX2BtnCancelAlert {
private String headingText;
private String bodyText;
private String btnStyle;
private String btn1Text;
private String btn2Text;
private String cancelText;
private EventHandler<ActionEvent> btn1Action;
private EventHandler<ActionEvent> btn2Action;
private Stage stage;
private JFXAlert<Void> alert;
/**
* Creates a new JFoenix Alert with 2 buttons and one cancel button
* @param titleText Title text of the alert
* @param headerText Heading text of the alert
* @param contentText Content text of the alert
* @param btnStyle Style of the okay button
* @param btn1Text btn1 text
* @param btn2Text btn2 text
* @param cancelText cancel button text
* @param stage stage to which the dialog belongs
*/
public JFX2BtnCancelAlert(String headingText, String bodyText, String btnStyle, String btn1Text, String btn2Text,
String cancelText, Stage stage) {
setHeadingText(headingText);
setBodyText(bodyText);
setBtnStyle(btnStyle);
setBtn1Text(btn1Text);
setBtn2Text(btn2Text);
setCancelText(cancelText);
setStage(stage);
}
public JFX2BtnCancelAlert() {
// Auto-generated constructor stub
}
public void showAndWait() {
alert = new JFXAlert<>(stage);
JFXButton btnOne = new JFXButton();
btnOne.setText(btn1Text);
btnOne.setOnAction(btn1Action);
btnOne.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
btnOne.setPrefHeight(32);
btnOne.setStyle(btnStyle);
JFXButton btnTwo = new JFXButton();
btnTwo.setText(btn2Text);
btnTwo.setOnAction(btn2Action);
btnTwo.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
btnTwo.setPrefHeight(32);
btnTwo.setStyle(btnStyle);
JFXButton cancelBtn = new JFXButton();
cancelBtn.setText(cancelText);
cancelBtn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
alert.close();
System.exit(1);
}
});
cancelBtn.setButtonType(com.jfoenix.controls.JFXButton.ButtonType.RAISED);
cancelBtn.setPrefHeight(32);
cancelBtn.setStyle(btnStyle);
JFXDialogLayout content = new JFXDialogLayout();
content.setActions(btnOne, btnTwo, cancelBtn);
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 String getBtn1Text() {
return btn1Text;
}
public void setBtn1Text(String btn1Text) {
this.btn1Text = btn1Text;
}
public String getBtn2Text() {
return btn2Text;
}
public void setBtn2Text(String btn2Text) {
this.btn2Text = btn2Text;
}
public String getCancelText() {
return cancelText;
}
public void setCancelText(String cancelText) {
this.cancelText = cancelText;
}
public EventHandler<ActionEvent> getBtn1Action() {
return btn1Action;
}
public void setBtn1Action(EventHandler<ActionEvent> btn1Action) {
this.btn1Action = btn1Action;
}
public EventHandler<ActionEvent> getBtn2Action() {
return btn2Action;
}
public void setBtn2Action(EventHandler<ActionEvent> btn2Action) {
this.btn2Action = btn2Action;
}
public Stage getStage() {
return stage;
}
public void setStage(Stage stage) {
this.stage = stage;
}
public JFXAlert<Void> getAlert() {
return alert;
}
public void setAlert(JFXAlert<Void> alert) {
this.alert = alert;
}
}

View File

@ -1,3 +1,24 @@
/**
* Kellerkinder Framework Alerts
*
* 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
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
package org.kellerkinder.Alerts; package org.kellerkinder.Alerts;
import com.jfoenix.controls.JFXAlert; import com.jfoenix.controls.JFXAlert;
@ -6,33 +27,36 @@ import com.jfoenix.controls.JFXDialogLayout;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler; import javafx.event.EventHandler;
import javafx.scene.text.Text;
import javafx.stage.Stage; import javafx.stage.Stage;
public class JFXInfoAlert { public class JFXInfoAlert {
private String titleText; private String headingText;
private String headerText; private String bodyText;
private String contentText;
private String btnStyle; private String btnStyle;
private Stage stage; private Stage stage;
/**
* 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 JFXInfoAlert(String headingText, String bodyText, String btnStyle, Stage stage) {
setHeadingText(headingText);
setBodyText(bodyText);
setBtnStyle(btnStyle);
setStage(stage);
}
public JFXInfoAlert() { public JFXInfoAlert() {
// Auto-generated constructor stub // Auto-generated constructor stub
} }
public JFXInfoAlert(String titleText, String headerText, String contentText, String btnStyle, Stage stage) {
setTitleText(titleText);
setHeaderText(headerText);
setContentText(contentText);
setBtnStyle(btnStyle);
setStage(stage);
}
public void showAndWait( ) { public void showAndWait( ) {
JFXAlert<Void> alert = new JFXAlert<>(stage); JFXAlert<Void> alert = new JFXAlert<>(stage);
alert.setTitle(titleText);
alert.setHeaderText(headerText);
alert.setContentText(contentText);
JFXButton button = new JFXButton("Okay"); JFXButton button = new JFXButton("Okay");
button.setOnAction(new EventHandler<ActionEvent>() { button.setOnAction(new EventHandler<ActionEvent>() {
@ -47,32 +71,26 @@ public class JFXInfoAlert {
JFXDialogLayout content = new JFXDialogLayout(); JFXDialogLayout content = new JFXDialogLayout();
content.setActions(button); content.setActions(button);
content.setHeading(new Text(headingText));
content.setBody(new Text(bodyText));
alert.setContent(content); alert.setContent(content);
alert.showAndWait(); alert.showAndWait();
} }
public String getTitleText() { public String getHeadingText() {
return titleText; return headingText;
} }
public void setTitleText(String titleText) { public void setHeadingText(String headingText) {
this.titleText = titleText; this.headingText = headingText;
} }
public String getHeaderText() { public String getBodyText() {
return headerText; return bodyText;
} }
public void setHeaderText(String headerText) { public void setBodyText(String bodyText) {
this.headerText = headerText; this.bodyText = bodyText;
}
public String getContentText() {
return contentText;
}
public void setContentText(String contentText) {
this.contentText = contentText;
} }
public String getBtnStyle() { public String getBtnStyle() {
@ -91,4 +109,4 @@ public class JFXInfoAlert {
this.stage = stage; this.stage = stage;
} }
} }