Search in sources :

Example 41 with ActionEvent

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();
}
Also used : TitledPane(javafx.scene.control.TitledPane) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) Scene(javafx.scene.Scene) StringWriter(java.io.StringWriter) Button(javafx.scene.control.Button) Stage(javafx.stage.Stage) VBox(javafx.scene.layout.VBox) PrintWriter(java.io.PrintWriter)

Aggregations

ActionEvent (javafx.event.ActionEvent)41 Label (javafx.scene.control.Label)13 List (java.util.List)11 Button (javafx.scene.control.Button)11 Stage (javafx.stage.Stage)11 File (java.io.File)10 ObservableList (javafx.collections.ObservableList)10 MenuItem (javafx.scene.control.MenuItem)10 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)9 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Optional (java.util.Optional)9 ResourceLoader (com.kyj.fx.voeditor.visual.momory.ResourceLoader)8 DialogUtil (com.kyj.fx.voeditor.visual.util.DialogUtil)8 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)8 MouseEvent (javafx.scene.input.MouseEvent)8 ConfigResourceLoader (com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader)7 Iterator (java.util.Iterator)7 FXCollections (javafx.collections.FXCollections)7 EventHandler (javafx.event.EventHandler)7