mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Issue 66: client side error pop ups use default javaFx style
- created JFeonix style pop up to replace the default one tags: #story[1273]
This commit is contained in:
@@ -14,8 +14,6 @@ import javafx.application.Platform;
|
|||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.control.Alert;
|
|
||||||
import javafx.scene.control.Alert.AlertType;
|
|
||||||
import javafx.scene.input.KeyCode;
|
import javafx.scene.input.KeyCode;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
@@ -46,6 +44,7 @@ import seng302.utilities.XMLParser;
|
|||||||
import seng302.visualiser.controllers.LobbyController;
|
import seng302.visualiser.controllers.LobbyController;
|
||||||
import seng302.visualiser.controllers.RaceViewController;
|
import seng302.visualiser.controllers.RaceViewController;
|
||||||
import seng302.visualiser.controllers.ViewManager;
|
import seng302.visualiser.controllers.ViewManager;
|
||||||
|
import seng302.visualiser.controllers.dialogs.PopupDialogController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is a client side instance of a yacht racing game in JavaFX. The game is instantiated
|
* This class is a client side instance of a yacht racing game in JavaFX. The game is instantiated
|
||||||
@@ -169,10 +168,12 @@ public class GameClient {
|
|||||||
|
|
||||||
private void showConnectionError (String message) {
|
private void showConnectionError (String message) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
Alert alert = new Alert(AlertType.ERROR);
|
PopupDialogController controller = ViewManager.getInstance().showPopupDialog();
|
||||||
alert.setHeaderText("Connection Error");
|
controller.setHeader("Oops");
|
||||||
alert.setContentText(message);
|
controller.setContent(message);
|
||||||
alert.showAndWait();
|
controller.setOptionButtonText("GO HOME");
|
||||||
|
controller
|
||||||
|
.setOptionButtonEventHandler(event -> ViewManager.getInstance().goToStartView());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import seng302.utilities.BonjourInstallChecker;
|
|||||||
import seng302.utilities.Sounds;
|
import seng302.utilities.Sounds;
|
||||||
import seng302.visualiser.GameClient;
|
import seng302.visualiser.GameClient;
|
||||||
import seng302.visualiser.controllers.dialogs.KeyBindingDialogController;
|
import seng302.visualiser.controllers.dialogs.KeyBindingDialogController;
|
||||||
|
import seng302.visualiser.controllers.dialogs.PopupDialogController;
|
||||||
|
|
||||||
public class ViewManager {
|
public class ViewManager {
|
||||||
|
|
||||||
@@ -229,6 +230,26 @@ public class ViewManager {
|
|||||||
keyBindingDialog.close();
|
keyBindingDialog.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PopupDialogController showPopupDialog() {
|
||||||
|
FXMLLoader dialogContent = new FXMLLoader(
|
||||||
|
getClass().getResource("/views/dialogs/PopupDialog.fxml"));
|
||||||
|
for (Node node : decorator.getChildren()) {
|
||||||
|
if (node instanceof StackPane) {
|
||||||
|
try {
|
||||||
|
JFXDialog dialog = new JFXDialog((StackPane) node, dialogContent.load(),
|
||||||
|
DialogTransition.CENTER);
|
||||||
|
PopupDialogController popupDialogController = dialogContent.getController();
|
||||||
|
popupDialogController.setPopupDialog(dialog);
|
||||||
|
dialog.show();
|
||||||
|
return popupDialogController;
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Cannot load Popup dialog");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a snackbar at the bottom of the app for 1 second.
|
* Show a snackbar at the bottom of the app for 1 second.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package seng302.visualiser.controllers.dialogs;
|
||||||
|
|
||||||
|
import com.jfoenix.controls.JFXButton;
|
||||||
|
import com.jfoenix.controls.JFXDialog;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.fxml.Initializable;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
|
||||||
|
public class PopupDialogController implements Initializable {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label headerLabel;
|
||||||
|
@FXML
|
||||||
|
private Label contentLabel;
|
||||||
|
@FXML
|
||||||
|
private Label closeLabel;
|
||||||
|
@FXML
|
||||||
|
private JFXButton optionButton;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private JFXDialog popupDialog;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.contentLabel.setText(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHeader(String header) {
|
||||||
|
this.headerLabel.setText(header);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOptionButton(JFXButton jfxButton) {
|
||||||
|
this.optionButton = jfxButton;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOptionButtonText(String text) {
|
||||||
|
this.optionButton.setText(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOptionButtonEventHandler(EventHandler<? super MouseEvent> eventHandler) {
|
||||||
|
this.optionButton.setOnMouseClicked(eventHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPopupDialog(JFXDialog popupDialog) {
|
||||||
|
this.popupDialog = popupDialog;
|
||||||
|
this.closeLabel.setOnMouseClicked(event -> this.popupDialog.close());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#headerLabel {
|
||||||
|
-fx-font-size: 20px;
|
||||||
|
-fx-text-fill: -fx-pp-dark-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
#closeLabel {
|
||||||
|
-fx-font-size: 22px;
|
||||||
|
-fx-text-fill: -fx-pp-dark-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
#closeLabel:hover {
|
||||||
|
-fx-font-size: 24px;
|
||||||
|
-fx-text-fill: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
#contentLabel {
|
||||||
|
-fx-font-size: 22px;
|
||||||
|
-fx-text-fill: -fx-pp-dark-text-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
#optionButton {
|
||||||
|
-fx-background-color: -fx-pp-theme-color;
|
||||||
|
-fx-text-fill: -fx-pp-light-text-color;
|
||||||
|
-fx-font-size: 18px;
|
||||||
|
-fx-effect: -fx-pp-dropshadow-light;
|
||||||
|
-fx-max-height: 55;
|
||||||
|
-fx-focus-traversable: false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#optionButton:hover {
|
||||||
|
-fx-font-size: 20px !important;
|
||||||
|
-fx-background-color: -fx-pp-light-theme-color;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
|
||||||
|
<?import com.jfoenix.controls.JFXButton?>
|
||||||
|
<?import com.jfoenix.controls.JFXDialogLayout?>
|
||||||
|
<?import java.net.URL?>
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
<JFXDialogLayout maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
|
||||||
|
minWidth="-Infinity" prefWidth="550.0" xmlns="http://javafx.com/javafx/8"
|
||||||
|
xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="seng302.visualiser.controllers.dialogs.PopupDialogController">
|
||||||
|
<children>
|
||||||
|
<GridPane>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" maxWidth="1.7976931348623157E308"/>
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints maxHeight="-Infinity" minHeight="30.0" prefHeight="30.0"
|
||||||
|
vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints maxHeight="1.7976931348623157E308" minHeight="80.0"
|
||||||
|
prefHeight="80.0" vgrow="SOMETIMES"/>
|
||||||
|
<RowConstraints minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES"/>
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<JFXButton fx:id="optionButton" buttonType="RAISED" prefHeight="55.0"
|
||||||
|
prefWidth="150.0" GridPane.halignment="RIGHT" GridPane.rowIndex="2"
|
||||||
|
GridPane.valignment="CENTER">
|
||||||
|
<GridPane.margin>
|
||||||
|
<Insets/>
|
||||||
|
</GridPane.margin>
|
||||||
|
</JFXButton>
|
||||||
|
<Label fx:id="contentLabel" text="Popup content goes here ..."
|
||||||
|
GridPane.rowIndex="1"/>
|
||||||
|
<Label fx:id="headerLabel" text="Popup header"/>
|
||||||
|
<Label fx:id="closeLabel" text="✖" translateY="-10.0" GridPane.halignment="RIGHT"/>
|
||||||
|
</children>
|
||||||
|
</GridPane>
|
||||||
|
</children>
|
||||||
|
<stylesheets>
|
||||||
|
<URL value="@../../css/dialogs/Popup.css"/>
|
||||||
|
<URL value="@../../css/Master.css"/>
|
||||||
|
</stylesheets>
|
||||||
|
</JFXDialogLayout>
|
||||||
Reference in New Issue
Block a user