Java Code Examples for javafx.scene.control.Button#setCancelButton()

The following examples show how to use javafx.scene.control.Button#setCancelButton() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DialogControl.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private Button createButton(ButtonType buttonType) {
  LOGGER.trace("Create Button: " + buttonType.getText());
  String buttonText;
  if (isButtonTextUppercase()) {
    buttonText = buttonType.getText().toUpperCase();
  } else {
    buttonText = buttonType.getText();
  }
  final Button button = new Button(buttonText);
  final ButtonBar.ButtonData buttonData = buttonType.getButtonData();
  ButtonBar.setButtonData(button, buttonData);
  button.setDefaultButton(buttonData.isDefaultButton());
  button.setCancelButton(buttonData.isCancelButton());
  return button;
}
 
Example 2
Source File: CommentsPresenter.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a Dialog for getting deletion confirmation
 * @param item Item to be deleted
 */
private void showDialog(Comment item) {
    Alert alert = new Alert(javafx.scene.control.Alert.AlertType.CONFIRMATION);
    alert.setTitleText("Confirm deletion");
    alert.setContentText("This comment will be deleted permanently.\nDo you want to continue?");
    
    Button yes = new Button("Yes, delete permanently");
    yes.setOnAction(e -> {
        alert.setResult(ButtonType.YES); 
        alert.hide();
    });
    yes.setDefaultButton(true);
    
    Button no = new Button("No");
    no.setCancelButton(true);
    no.setOnAction(e -> {
        alert.setResult(ButtonType.NO); 
        alert.hide();
    });
    alert.getButtons().setAll(yes,no);
    
    Optional result = alert.showAndWait();
    if(result.isPresent() && result.get().equals(ButtonType.YES)){
        /*
        With confirmation, delete the item from the ListView. This will be
        propagated to the Cloud, and from here to the rest of the clients
        */
        commentsList.getItems().remove(item);
    }    
}
 
Example 3
Source File: CommentListCell.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a Dialog for getting deletion confirmation
 * @param item Item to be deleted
 */
private void showDialog(Comment item) {
    Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitleText("Confirm deletion");
    alert.setContentText("This comment will be deleted permanently.\nDo you want to continue?");
    
    Button yes = new Button("Yes, delete permanently");
    yes.setOnAction(e -> {
        alert.setResult(ButtonType.YES); 
        alert.hide();
    });
    yes.setDefaultButton(true);
    
    Button no = new Button("No");
    no.setCancelButton(true);
    no.setOnAction(e -> {
        alert.setResult(ButtonType.NO); 
        alert.hide();
    });
    alert.getButtons().setAll(yes, no);
    
    Optional result = alert.showAndWait();
    if (result.isPresent() && result.get().equals(ButtonType.YES)) {
        /*
        With confirmation, delete the item from the ListView. This will be
        propagated to the Cloud, and from there to the rest of the clients
        */
        listViewProperty().get().getItems().remove(item);
    }
}
 
Example 4
Source File: GamePresenter.java    From Game2048FX with GNU General Public License v3.0 5 votes vote down vote up
private void showSignInDialog(String message) {
    // force login view
    HBox title = new HBox(10);
    title.setAlignment(Pos.CENTER_LEFT);
    title.getChildren().add(new ImageView());
    title.getChildren().add(new Label("Sign in required"));
    Dialog<ButtonType> dialog = new Dialog();
    dialog.setContent(new Label(message + ", you have to sign in\nwith your social network profile. \nDo you want to continue?"));
    dialog.setTitle(title);
    Button yes = new Button("Yes");
    yes.setOnAction(e -> {
        dialog.setResult(ButtonType.YES);
        dialog.hide();
    });
    yes.setDefaultButton(true);
    Button no = new Button("No");
    no.setCancelButton(true);
    no.setOnAction(e -> {
        dialog.setResult(ButtonType.NO);
        dialog.hide();
    });
    dialog.getButtons().addAll(yes, no);
    Platform.runLater(() -> {
        Optional result = dialog.showAndWait();
        if (result.isPresent() && result.get().equals(ButtonType.YES)) {
            cloud.forceLogin();
        }
    });
}
 
Example 5
Source File: SettingsPresenter.java    From Game2048FX with GNU General Public License v3.0 5 votes vote down vote up
private void showAlertDialog(GameMode mode) {
    HBox title = new HBox(10);
    title.setAlignment(Pos.CENTER_LEFT);
    title.getChildren().add(new ImageView());
    title.getChildren().add(new Label("Game will be restarted"));
    Dialog<ButtonType> dialog = new Dialog();
    dialog.setContent(new Label("The game will be restarted and non saved data will be lost. \nDo you want to continue?"));
    dialog.setTitle(title);
    Button yes = new Button("Yes");
    yes.setOnAction(e -> {
        dialog.setResult(ButtonType.YES);
        dialog.hide();
    });
    yes.setDefaultButton(true);
    Button no = new Button("No");
    no.setCancelButton(true);
    no.setOnAction(e -> {
        dialog.setResult(ButtonType.NO);
        dialog.hide();
    });
    dialog.getButtons().addAll(yes, no);
    Platform.runLater(() -> {
        Optional result = dialog.showAndWait();
        if (result.isPresent() && result.get().equals(ButtonType.YES)) {
            gameModel.setGameMode(mode);
        } else {
            gameMode.set(gameModel.getGameMode());
        }
        getApp().switchToPreviousView();
    });
}
 
Example 6
Source File: DialogControl.java    From WorkbenchFX with Apache License 2.0 4 votes vote down vote up
private void updateButtons(WorkbenchDialog dialog) {
  LOGGER.trace("Updating buttons");

  buttons.clear();
  cancelButton = null;
  cancelButtonType = null;
  defaultButton = null;
  defaultButtonType = null;
  buttonNodes.clear();

  if (Objects.isNull(dialog)) {
    return;
  }

  boolean hasDefault = false;
  for (ButtonType cmd : dialog.getButtonTypes()) {
    Button button = buttonNodes.computeIfAbsent(cmd, dialogButton -> createButton(cmd));

    // keep only first default button
    ButtonBar.ButtonData buttonType = cmd.getButtonData();

    boolean isFirstDefaultButton =
        !hasDefault && buttonType != null && buttonType.isDefaultButton();
    button.setDefaultButton(isFirstDefaultButton);
    if (isFirstDefaultButton) {
      defaultButton = button;
      defaultButtonType = cmd;
    }
    // take last cancel button
    boolean isCancelButton = buttonType != null && buttonType.isCancelButton();
    button.setCancelButton(isCancelButton);
    if (isCancelButton) {
      cancelButton = button;
      cancelButtonType = cmd;
    }
    button.setOnAction(evt -> completeDialog(cmd));

    hasDefault |= buttonType != null && buttonType.isDefaultButton();

    buttons.add(button);

    LOGGER.trace("updateButtons finished");
  }

  updateKeyboardBehavior();
}
 
Example 7
Source File: WidgetColorPopOverController.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void updateButton ( final Button button, final ButtonType buttonType ) {
    button.setText(buttonType.getText());
    ButtonBar.setButtonData(button, buttonType.getButtonData());
    button.setDefaultButton(buttonType.getButtonData().isDefaultButton());
    button.setCancelButton(buttonType.getButtonData().isCancelButton());
}
 
Example 8
Source File: WidgetFontPopOverController.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
private void updateButton ( final Button button, final ButtonType buttonType ) {
    button.setText(buttonType.getText());
    ButtonBar.setButtonData(button, buttonType.getButtonData());
    button.setDefaultButton(buttonType.getButtonData().isDefaultButton());
    button.setCancelButton(buttonType.getButtonData().isCancelButton());
}
 
Example 9
Source File: ConfirmationDialog.java    From pdfsam with GNU Affero General Public License v3.0 4 votes vote down vote up
private Button buildCancelButton(String text, boolean response) {
    Button button = buildButton(text, response);
    button.setCancelButton(true);
    return button;
}