Esempio n. 1
0
 private void inicialitzarDialog() {
   // Definició d'un diàleg usant la classe Dialog
   dialog = new Dialog();
   dialog.setTitle("Diàleg");
   dialog.setHeaderText("This is a custom dialog");
   dialog.setResizable(true);
   ButtonType buttonTypeOk = new ButtonType("Okay", ButtonBar.ButtonData.OK_DONE);
   dialog.getDialogPane().getButtonTypes().add(buttonTypeOk);
   // Definició d'un diàleg usant la classe Dialog
   mitjas = new Dialog();
   mitjas.setTitle("Diàleg");
   mitjas.setResizable(true);
   mitjas.getDialogPane().getButtonTypes().add(buttonTypeOk);
 }
  private void initDialog() {
    dialog.initOwner(mainApp.getPrimaryStage());
    dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.initStyle(StageStyle.DECORATED);
    dialog.setResizable(true);
    dialog.setTitle("Recordings Already Exist");
    dialog.setHeaderText("Replace or rename recordings?");
    dialog.getDialogPane().setPadding(new Insets(10));

    VBox vbox = new VBox();
    vbox.setSpacing(10);
    dialog.getDialogPane().setContent(vbox);

    Label label =
        new Label(
            "Archiving the following recordings will replace files on your computer unless you rename them:");
    vbox.getChildren().add(label);

    VBox recordingBox = new VBox();
    recordingBox.setSpacing(20);
    for (Recording recording : recordingsToDisplay) {
      recording.setFileExistsAction(Recording.FileExistsAction.REPLACE);
      recordingBox.getChildren().add(buildRecordingGrid(recording));
    }

    ScrollPane scrollPane = new ScrollPane();
    scrollPane.getStyleClass().add("recording-exists-list");
    scrollPane.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
    scrollPane.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED);
    scrollPane.setFitToWidth(true);
    scrollPane.setFitToHeight(true);
    scrollPane.setContent(recordingBox);
    scrollPane.setPadding(new Insets(10));
    vbox.getChildren().add(scrollPane);

    dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
  }
Esempio n. 3
0
 /**
  * Updates component language-dependant variables.
  *
  * @param c component
  * @param key language key
  * @param value language value
  * @param data formatting data
  */
 public void update(Dialog c, String key, Value value, Object... data) {
   String title = getDefaultText(value, data);
   if (title != null) {
     c.setTitle(title);
   }
 }
Esempio n. 4
0
  public static Range showRangeDialog(String title, String header) {
    final Range[] retVal = {null};

    Dialog<Range> dialog = new Dialog<>();
    dialog.setTitle(title);
    dialog.setHeaderText(header);

    IntegerProperty fromFieldProperty = new SimpleIntegerProperty(),
        toFieldProperty = new SimpleIntegerProperty();

    //        dialog.setGraphic(new ImageView(this.getClass().getResource("login.png").toString()));

    // Set the button types.
    ButtonType generateButtonType =
        new ButtonType(ResourceManager.getMessage("label.button.ok"), ButtonBar.ButtonData.OK_DONE);
    dialog.getDialogPane().getButtonTypes().addAll(generateButtonType, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 150, 10, 10));

    TextField fromTextField = new TextField();
    fromTextField.textProperty().bindBidirectional(fromFieldProperty, new NumberStringConverter());

    TextField toTextField = new TextField();
    toTextField.textProperty().bindBidirectional(toFieldProperty, new NumberStringConverter());

    grid.add(new Label("From:"), 0, 0);
    grid.add(fromTextField, 1, 0);
    grid.add(new Label("To:"), 0, 1);
    grid.add(toTextField, 1, 1);

    // Enable/Disable login button depending on whether a username was entered.
    Node loginButton = dialog.getDialogPane().lookupButton(generateButtonType);
    loginButton.setDisable(true);

    // Do some validation (using the Java 8 lambda syntax).
    fromTextField
        .textProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              loginButton.setDisable(
                  newValue.trim().isEmpty()
                      || toTextField.getText().trim().isEmpty()
                      || Integer.valueOf(newValue.trim())
                              .compareTo(Integer.valueOf(toTextField.getText().trim()))
                          > 0);
            });

    toTextField
        .textProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              loginButton.setDisable(
                  fromTextField.getText().trim().isEmpty()
                      || newValue.trim().isEmpty()
                      || Integer.valueOf(fromTextField.getText().trim())
                              .compareTo(Integer.valueOf(newValue.trim()))
                          > 0);
            });

    dialog.getDialogPane().setContent(grid);

    // Request focus on the username field by default.
    Platform.runLater(() -> fromTextField.requestFocus());

    // Convert the result to a username-password-pair when the login button is clicked.
    dialog.setResultConverter(
        dialogButton -> {
          if (dialogButton == generateButtonType) {
            return new IntegerRange(fromFieldProperty.get(), toFieldProperty.get());
          }
          return null;
        });

    Optional<Range> result = dialog.showAndWait();

    result.ifPresent(range -> retVal[0] = range);

    return retVal[0];
  }