protected void validateCreateButton() {
   if (itemName.getText().isEmpty()) {
     btnCreate.setDisable(true);
   } else {
     btnCreate.setDisable(false);
   }
 }
Beispiel #2
0
  public OptionalEditor(PropertySheet.Item parameter) {

    if (!(parameter instanceof OptionalParameter)) throw new IllegalArgumentException();

    optionalParameter = (OptionalParameter<?>) parameter;
    embeddedParameter = optionalParameter.getEmbeddedParameter();

    // The checkbox
    checkBox = new CheckBox();

    setLeft(checkBox);

    // Add embedded editor
    try {
      Class<? extends PropertyEditor<?>> embeddedEditorClass =
          embeddedParameter.getPropertyEditorClass().get();
      embeddedEditor =
          embeddedEditorClass
              .getDeclaredConstructor(PropertySheet.Item.class)
              .newInstance(embeddedParameter);
      Node embeddedNode = embeddedEditor.getEditor();
      Boolean value = optionalParameter.getValue();
      if (value == null) value = false;
      embeddedNode.setDisable(!value);
      checkBox.setOnAction(
          e -> {
            embeddedNode.setDisable(!checkBox.isSelected());
          });

      setCenter(embeddedNode);
    } catch (Exception e) {
      throw (new IllegalStateException(e));
    }
  }
Beispiel #3
0
  private String showCreateOrRenameDialog(
      final String title,
      final String headerText,
      final File parent,
      final String name,
      final NameVerifier nameVerifier) {
    final Alert alert = new Alert(AlertType.CONFIRMATION);
    alert.setTitle(title);
    alert.setHeaderText(headerText);

    final GridPane contentContainer = new GridPane();
    contentContainer.setPadding(new Insets(8));
    contentContainer.setHgap(8);
    contentContainer.setVgap(8);

    contentContainer.add(new Label("Parent:"), 0, 0);
    final TextField parentTextField = new TextField();
    parentTextField.setEditable(false);

    parentTextField.setText(parent.getAbsolutePath());
    contentContainer.add(parentTextField, 1, 0);

    contentContainer.add(new Label("Name:"), 0, 1);

    final TextField dirNameTextField = new TextField();
    dirNameTextField.setText(name);
    GridPane.setHgrow(dirNameTextField, Priority.ALWAYS);
    contentContainer.add(dirNameTextField, 1, 1);

    final InvalidationListener updateDisableInvalidationListener =
        (observable) -> {
          final String dirName = dirNameTextField.getText();
          final Node okButton = alert.getDialogPane().lookupButton(ButtonType.OK);
          if (isEmpty(dirName)) okButton.setDisable(true);
          else {
            final boolean nameAcceptable = nameVerifier.isNameAcceptable(dirName);
            okButton.setDisable(!nameAcceptable);
          }
        };
    dirNameTextField.textProperty().addListener(updateDisableInvalidationListener);

    alert.getDialogPane().setContent(contentContainer);
    alert.setOnShowing(
        (event) -> {
          dirNameTextField.requestFocus();
          dirNameTextField.selectAll();
          updateDisableInvalidationListener.invalidated(null);
        });

    if (alert.showAndWait().get() == ButtonType.OK) return dirNameTextField.getText();
    else return null;
  }
Beispiel #4
0
 @Override
 protected Node createStart() {
   Node startButton = super.createStart();
   VBox startGroup = new VBox(10);
   ComboBox<String> levelChoice = new ComboBox<>();
   levelChoice.setOnAction(e -> levelFilename = levelChoice.getValue());
   levelChoice.getItems().addAll(getLevelFilenames());
   if (!levelChoice.getItems().isEmpty()) {
     levelChoice.getSelectionModel().clearAndSelect(0);
     levelFilename = levelChoice.getItems().get(0);
   } else {
     startButton.setDisable(true);
   }
   startGroup.getChildren().add(levelChoice);
   startGroup.getChildren().add(startButton);
   startGroup.setAlignment(Pos.CENTER);
   return startGroup;
 }
  public NewItemDialog(InventoryTab parent) {
    setTitle("Create New Item");

    getDialogPane().getButtonTypes().addAll(createButtonType, ButtonType.CANCEL);

    dialogContent.setHgap(10);
    dialogContent.setVgap(10);
    dialogContent.setPadding(new Insets(20, 100, 10, 10));

    itemName.setPromptText("Item Name");
    description.setPromptText("Description");
    imgUrl.setPromptText("Add a picture");
    // set spinner for the price
    SpinnerValueFactory<Double> spinnerFactory =
        new SpinnerValueFactory.DoubleSpinnerValueFactory(0.00, 100.00, 0.00, 0.01);
    priceSpinner.setValueFactory(spinnerFactory);
    priceSpinner.setEditable(true);
    // spinner for stock
    stockSpinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100, 0, 1));
    stockSpinner.setEditable(true);

    // add elements into grid
    dialogContent.add(img, 1, 0, 1, 4);
    dialogContent.add(imgUrl, 1, 4);
    dialogContent.add(browse, 2, 4);
    dialogContent.add(new Label("Item Name:"), 2, 0);
    dialogContent.add(itemName, 4, 0);
    dialogContent.add(new Label("Description:"), 2, 1);
    dialogContent.add(description, 4, 1);
    dialogContent.add(new Label("Price:"), 2, 2);
    dialogContent.add(new Label("$"), 3, 2);
    dialogContent.add(priceSpinner, 4, 2);
    dialogContent.add(new Label("No. of Stock:"), 2, 3);
    dialogContent.add(stockSpinner, 4, 3);

    // Enable/Disable Create button depending on whether info was entered.
    btnCreate = this.getDialogPane().lookupButton(createButtonType);
    btnCreate.setDisable(true);
    itemName
        .textProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              validateCreateButton();
            });
    description
        .textProperty()
        .addListener(
            (observable, oldValue, newValue) -> {
              validateCreateButton();
            });

    getDialogPane().setContent(dialogContent);

    // event handler for browse button
    browse.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(final ActionEvent e) {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Choose an Image");
            fileChooser.setInitialDirectory(new File(System.getProperty("user.dir") + "\\images"));
            fileChooser
                .getExtensionFilters()
                .addAll(new ExtensionFilter("Image Files", "*.png", "*.jpg", "*.gif"));

            File file = fileChooser.showOpenDialog(((InventoryTab) parent).getWindow());
            if (file != null) {
              imgUrl.setText(file.toString());
              // http://gamedev.stackexchange.com/questions/72924/how-do-i-add-an-image-inside-a-rectangle-or-a-circle-in-javafx
              Image image = new Image(file.toURI().toString());
              ImagePattern imagePattern = new ImagePattern(image);
              img.setFill(imagePattern);
              validateCreateButton();
            }
          }
        });

    // Convert the result to a MokuStockItem when the create button is clicked.
    setResultConverter(
        dialogButton -> {
          if (dialogButton == createButtonType) {
            // error handling
            String desc, url;
            if (description.getText().isEmpty()) {
              desc = "";
            } else {
              desc = description.getText();
            }
            if (imgUrl.getText().isEmpty()) {
              url = "";
            } else {
              url = imgUrl.getText();
            }
            return new MokuStockItem(
                parent,
                0,
                itemName.getText(),
                desc,
                Double.parseDouble(priceSpinner.getEditor().getText()),
                Integer.parseInt(stockSpinner.getEditor().getText()),
                url);
          }
          return null;
        });
  }
 private void toggleButtons(String current) {
   boolean valid = testAddr(current);
   for (Node n : nodes) n.setDisable(!valid);
 }
  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];
  }