use of javafx.event.ActionEvent in project arquivoProject by fader-azevedo.
the class PdfViewerController method showErrorMessage.
private void showErrorMessage(String message, Throwable exception) {
// TODO: move to fxml (or better, use ControlsFX)
final Stage dialog = new Stage();
dialog.initOwner(pagination.getScene().getWindow());
dialog.initStyle(StageStyle.UNDECORATED);
final VBox root = new VBox(10);
root.setPadding(new Insets(10));
StringWriter errorMessage = new StringWriter();
exception.printStackTrace(new PrintWriter(errorMessage));
final Label detailsLabel = new Label(errorMessage.toString());
TitledPane details = new TitledPane();
details.setText("Details:");
Label briefMessageLabel = new Label(message);
final HBox detailsLabelHolder = new HBox();
Button closeButton = new Button("OK");
closeButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
dialog.hide();
}
});
HBox closeButtonHolder = new HBox();
closeButtonHolder.getChildren().add(closeButton);
closeButtonHolder.setAlignment(Pos.CENTER);
closeButtonHolder.setPadding(new Insets(5));
root.getChildren().addAll(briefMessageLabel, details, detailsLabelHolder, closeButtonHolder);
details.setExpanded(false);
details.setAnimated(false);
details.expandedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if (newValue) {
detailsLabelHolder.getChildren().add(detailsLabel);
} else {
detailsLabelHolder.getChildren().remove(detailsLabel);
}
dialog.sizeToScene();
}
});
final Scene scene = new Scene(root);
dialog.setScene(scene);
dialog.show();
}
Aggregations