Search in sources :

Example 16 with ButtonType

use of javafx.scene.control.ButtonType in project jgnash by ccavanaugh.

the class Alert method setButtons.

private void setButtons(final ButtonType... buttons) {
    for (final ButtonType buttonType : buttons) {
        final Button button = new Button(buttonType.getText());
        ButtonBar.setButtonData(button, buttonType.getButtonData());
        button.setOnAction(event -> {
            Alert.this.buttonType = buttonType;
            ((Stage) parent.get().getWindow()).close();
        });
        buttonBar.getButtons().add(button);
    }
}
Also used : Button(javafx.scene.control.Button) Stage(javafx.stage.Stage) ButtonType(javafx.scene.control.ButtonType)

Example 17 with ButtonType

use of javafx.scene.control.ButtonType in project trex-stateless-gui by cisco-system-traffic-generator.

the class Util method isConfirmed.

/**
     * Confirm deletion message window
     *
     * @param deleteMsg
     * @return
     */
public static boolean isConfirmed(String deleteMsg) {
    Alert confirmMsgBox = Util.getAlert(Alert.AlertType.CONFIRMATION);
    confirmMsgBox.getButtonTypes().clear();
    confirmMsgBox.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO);
    confirmMsgBox.setContentText(deleteMsg);
    Optional<ButtonType> result = confirmMsgBox.showAndWait();
    return result.get() == ButtonType.YES;
}
Also used : Alert(javafx.scene.control.Alert) ButtonType(javafx.scene.control.ButtonType)

Example 18 with ButtonType

use of javafx.scene.control.ButtonType in project jgnash by ccavanaugh.

the class NetworkAuthenticator method getPasswordAuthentication.

@Override
protected PasswordAuthentication getPasswordAuthentication() {
    final Preferences auth = Preferences.userRoot().node(NODEHTTP);
    final ResourceBundle resources = ResourceUtils.getBundle();
    final char[][] pass = { null };
    final String[] user = new String[1];
    // get the password
    if (auth.get(HTTPPASS, null) != null && !auth.get(HTTPPASS, null).isEmpty()) {
        pass[0] = auth.get(HTTPPASS, null).toCharArray();
    }
    // get the user
    user[0] = auth.get(HTTPUSER, null);
    if (user[0] != null) {
        if (user[0].length() <= 0) {
            user[0] = null;
        }
    }
    // if either returns null, pop a dialog
    if (user[0] == null || pass[0] == null) {
        final Dialog<Pair<String, String>> dialog = new Dialog<>();
        dialog.setTitle(resources.getString("Title.HTTPProxy"));
        dialog.setHeaderText(resources.getString("Message.EnterNetworkAuth"));
        // Set the button types.
        final ButtonType loginButtonType = new ButtonType(resources.getString("Button.Ok"), ButtonBar.ButtonData.OK_DONE);
        dialog.getDialogPane().getStylesheets().addAll(MainView.DEFAULT_CSS);
        dialog.getDialogPane().getStyleClass().addAll("dialog");
        dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);
        // Create the username and password labels and fields.
        final GridPane grid = new GridPane();
        grid.getStylesheets().addAll(MainView.DEFAULT_CSS);
        grid.getStyleClass().addAll("form");
        final TextField userNameField = new TextField();
        final PasswordField passwordField = new PasswordField();
        grid.add(new Label(resources.getString("Label.UserName")), 0, 0);
        grid.add(userNameField, 1, 0);
        grid.add(new Label(resources.getString("Label.Password")), 0, 1);
        grid.add(passwordField, 1, 1);
        // Enable/Disable login button depending on whether a username was entered.
        final Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType);
        loginButton.setDisable(true);
        // bind the button, must not be empty
        loginButton.disableProperty().bind(userNameField.textProperty().isEmpty());
        dialog.getDialogPane().setContent(grid);
        // Request focus on the username field by default.
        Platform.runLater(userNameField::requestFocus);
        dialog.setResultConverter(dialogButton -> {
            if (dialogButton == loginButtonType) {
                return new Pair<>(userNameField.getText(), passwordField.getText());
            }
            return null;
        });
        final Optional<Pair<String, String>> result = dialog.showAndWait();
        result.ifPresent(usernamePassword -> {
            user[0] = usernamePassword.getKey();
            pass[0] = usernamePassword.getValue().toCharArray();
        });
    }
    return new PasswordAuthentication(user[0], pass[0]);
}
Also used : GridPane(javafx.scene.layout.GridPane) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Dialog(javafx.scene.control.Dialog) TextField(javafx.scene.control.TextField) ResourceBundle(java.util.ResourceBundle) PasswordField(javafx.scene.control.PasswordField) Preferences(java.util.prefs.Preferences) ButtonType(javafx.scene.control.ButtonType) Pair(javafx.util.Pair) PasswordAuthentication(java.net.PasswordAuthentication)

Aggregations

ButtonType (javafx.scene.control.ButtonType)18 Alert (javafx.scene.control.Alert)9 Dialog (javafx.scene.control.Dialog)5 File (java.io.File)4 Label (javafx.scene.control.Label)4 GridPane (javafx.scene.layout.GridPane)4 Pair (javafx.util.Pair)4 TextField (javafx.scene.control.TextField)3 FileChooser (javafx.stage.FileChooser)3 Dimension (java.awt.Dimension)2 ArrayList (java.util.ArrayList)2 FXML (javafx.fxml.FXML)2 Insets (javafx.geometry.Insets)2 Node (javafx.scene.Node)2 DialogPane (javafx.scene.control.DialogPane)2 PasswordField (javafx.scene.control.PasswordField)2 DirectoryChooser (javafx.stage.DirectoryChooser)2 EntityAttribute (aimax.osm.data.entities.EntityAttribute)1 MapEntity (aimax.osm.data.entities.MapEntity)1 MapNode (aimax.osm.data.entities.MapNode)1