Esempio n. 1
0
  private void buildRight(ActionEvent event) {

    GridPane grdpn = new GridPane();

    SpinnerValueFactory svf = new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100);

    Spinner<Integer> numreserved = new Spinner<Integer>();
    numreserved.setValueFactory(svf);
    numreserved.setEditable(true);
    numreserved.setPrefWidth(80);

    Button buttonreserve = new Button("Seleziona numero prenotati");
    grdpn.add(numreserved, 0, 0);
    grdpn.add(buttonreserve, 1, 0);
    buttonreserve.setOnAction(this::buildUserCredentials);

    /*
    GridPane gp = new GridPane();

    Label nameL = new Label("Nome partecipante");
    Label surnameL = new Label("Cognome partecipante");
    Label birthdayL = new Label("Data Nascita");

    TextField txname = new TextField();
    TextField txsurname = new TextField();
    TextField txbirthday = new TextField();

    gp.add(nameL,0,0);
    gp.add(txname,1,0);
    gp.add(surnameL,0,1);
    gp.add(txsurname,1,1);
    gp.add(birthdayL,0,2);
    gp.add(txbirthday,1,2);
    gp.setVgap(10);
    gp.setHgap(3);*/

    sp2.getChildren().add(grdpn);

    gpMediator.send(grdpn, this);
  }
  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;
        });
  }
Esempio n. 3
0
  @FXML
  private void initialize() {
    m_combo.setItems(Person.DEFAULT_DATA);
    m_combo.setConverter(
        new StringConverter<Person>() {

          @Override
          public String toString(Person p) {
            return p.getFirstName().get()
                + " "
                + p.getLastName().get()
                + " ("
                + p.getAge().get()
                + ")";
          }

          @Override
          public Person fromString(String string) {
            for (Person p : m_combo.getItems()) {
              String current =
                  p.getFirstName().get()
                      + " "
                      + p.getLastName().get()
                      + " ("
                      + p.getAge().get()
                      + ")";
              if (current.equals(string)) {
                return p;
              }
            }
            return null;
          }
        });

    m_slider.setMin(0);
    m_slider.setMax(100);
    m_slider.setValue(50);

    m_spinner.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 100, 0, 1));

    m_list.setItems(Person.DEFAULT_DATA);
    m_list.setCellFactory(
        new Callback<ListView<Person>, ListCell<Person>>() {

          @Override
          public ListCell<Person> call(ListView<Person> p) {

            return new ListCell<Person>() {
              @Override
              protected void updateItem(Person p1, boolean bln) {
                super.updateItem(p1, bln);
                if (p1 != null) {
                  String current =
                      p1.getFirstName().get()
                          + " "
                          + p1.getLastName().get()
                          + " ("
                          + p1.getAge().get()
                          + ")";
                  setText(current);
                }
              }
            };
          }
        });
  }