ns-usbloader/src/main/java/nsusbloader/ServiceWindow.java

71 lines
2.9 KiB
Java
Raw Normal View History

2019-02-10 04:59:54 +03:00
package nsusbloader;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;
2019-02-10 04:59:54 +03:00
import javafx.scene.layout.Region;
import javafx.stage.Stage;
2019-02-10 04:59:54 +03:00
import java.util.Optional;
public class ServiceWindow {
/** Create window with error notification */
2019-02-15 05:44:39 +03:00
public static void getErrorNotification(String title, String body){
getNotification(title, body, Alert.AlertType.ERROR);
}
/** Create window with information notification */
public static void getInfoNotification(String title, String body){
getNotification(title, body, Alert.AlertType.INFORMATION);
}
/** Real window creator */
private static void getNotification(String title, String body, Alert.AlertType type){
Alert alertBox = new Alert(type);
2019-02-10 04:59:54 +03:00
alertBox.setTitle(title);
alertBox.setHeaderText(null);
alertBox.setContentText(body);
alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alertBox.setResizable(true); // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
2019-03-19 05:06:18 +03:00
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
dialogStage.setAlwaysOnTop(true);
dialogStage.getIcons().addAll(
new Image("/res/warn_ico32x32.png"),
new Image("/res/warn_ico48x48.png"),
new Image("/res/warn_ico64x64.png"),
new Image("/res/warn_ico128x128.png")
);
dialogStage.toFront();
2019-02-10 04:59:54 +03:00
alertBox.show();
}
2019-02-11 17:33:53 +03:00
/**
* Create notification window with confirm/deny
* */
2019-02-15 05:44:39 +03:00
public static boolean getConfirmationWindow(String title, String body){
2019-02-10 04:59:54 +03:00
Alert alertBox = new Alert(Alert.AlertType.CONFIRMATION);
alertBox.setTitle(title);
alertBox.setHeaderText(null);
alertBox.setContentText(body);
alertBox.getDialogPane().setMinWidth(Region.USE_PREF_SIZE);
alertBox.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
alertBox.setResizable(true); // Java bug workaround for JDR11/OpenJFX. TODO: nothing. really.
2019-02-18 03:06:49 +03:00
alertBox.getDialogPane().getStylesheets().add(AppPreferences.getInstance().getTheme());
Stage dialogStage = (Stage) alertBox.getDialogPane().getScene().getWindow();
dialogStage.setAlwaysOnTop(true);
dialogStage.getIcons().addAll(
new Image("/res/ask_ico32x32.png"),
new Image("/res/ask_ico48x48.png"),
new Image("/res/ask_ico64x64.png"),
new Image("/res/ask_ico128x128.png")
);
dialogStage.toFront();
2019-02-10 04:59:54 +03:00
Optional<ButtonType> result = alertBox.showAndWait();
2019-02-18 03:06:49 +03:00
return (result.isPresent() && result.get() == ButtonType.OK);
2019-02-10 04:59:54 +03:00
}
}