UIAlert.java
package edu.ntnu.idi.idatt.view.components.ui;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
/**
* Class for creating UI confirmation alerts.
*/
public class UIAlert {
Alert alert = new Alert(AlertType.CONFIRMATION);
ButtonType confirm = new ButtonType("Confirm");
ButtonType cancel = new ButtonType("Cancel");
/**
* Constructor for UIAlert.
*
* @param title - Window name
* @param header - context
* @param content - description of context
*/
public UIAlert(String title, String header, String content) {
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(content);
alert.getButtonTypes().setAll(confirm, cancel);
}
/**
* Method for displaying and waiting for response from alert.
*
* <p>
* Waits for confirmation, turns to false in case of no response.
* </p>
*
* @return boolean Confirm/Cancelled.
*/
public boolean displayAwaitResponse() {
ButtonType type = alert.showAndWait().orElse(cancel);
return type == confirm ? true : false;
}
}