package belotetime.core.dialog;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
@SuppressWarnings("rawtypes")
public class MessageBox extends Stage implements EventHandler{
private Button _okButton;
public static void Show(String title, String message){
(new MessageBox(title, message)).showAndWait();
}
@SuppressWarnings("unchecked")
public MessageBox(String title, String message){
setTitle(title);
initStyle(StageStyle.UTILITY);
initModality(Modality.APPLICATION_MODAL);
setResizable(false);
Insets insets = new Insets(5, 5, 5, 5);
BorderPane border = new BorderPane();
Label _messageLabel = new Label();
_messageLabel.setText(message);
border.setCenter(_messageLabel);
BorderPane.setMargin(_messageLabel, insets);
_okButton = new Button("OK");
_okButton.setOnAction(this);
BorderPane.setAlignment(_okButton, Pos.TOP_CENTER);
BorderPane.setMargin(_okButton, insets);
border.setBottom(_okButton);
Scene scene = new Scene(border);
setScene(scene);
}
public void showDialog() {
sizeToScene();
centerOnScreen();
showAndWait();
}
@Override
public void handle(Event arg0) {
if (arg0.getSource() == _okButton) {
hide();
}
}
}