/** Shows this Notifications popup */
  public void show() {
    // Use a gridpane to display the component
    GridPane pane = new GridPane();
    // Need a new scene to display the popup
    Scene scene = new Scene(pane);

    // Set the padding and gaps to 5px
    pane.setPadding(new Insets(5));
    pane.setHgap(5);
    pane.setVgap(5);

    // Add the message as a label if there is one
    if (message != null) {
      Label lblMsg = new Label(message);

      lblMsg.setPadding(new Insets(20));
      pane.add(lblMsg, 0, 0, 3, 1);
    }

    // Add the yes/no buttons if there are any
    if (yesNoBtns) {
      Button btnYes = new Button("Yes");
      Button btnNo = new Button("No");

      // Add the events and set as default/cancel buttons
      btnYes.setDefaultButton(true);
      btnYes.setOnAction(yesNoEvent);
      btnNo.setCancelButton(true);
      btnNo.setOnAction(yesNoEvent);

      // Align them to the right
      GridPane.setHalignment(btnNo, HPos.RIGHT);
      GridPane.setHalignment(btnYes, HPos.RIGHT);

      // Push the buttons to the right
      Region spacer = new Region();
      GridPane.setHgrow(spacer, Priority.ALWAYS);

      pane.add(spacer, 0, 1);
      pane.add(btnNo, 1, 1);
      pane.add(btnYes, 2, 1);
    }

    // Create a new stage to show the scene
    Stage stage = new Stage();

    stage.setScene(scene);
    // Don't want the popup to be resizable
    stage.setResizable(false);
    // Set the title if there is one
    if (title != null) {
      stage.setTitle(title);
    }
    // Resize it and show it
    stage.sizeToScene();
    stage.showAndWait();
  }
Ejemplo n.º 2
0
 @Override
 public void initialize(URL url, ResourceBundle rb) {
   backButton.setCancelButton(true);
   Config.getInstance().playerList = new Player[Config.getInstance().maxPlayers];
   adjustPlayerCount();
   assert raceCombo != null
       : "fx:id=\"myChoices\" was not injected: check your FXML file 'foo.fxml'.";
   raceCombo.setItems(FXCollections.observableArrayList());
   raceCombo.getItems().add("FOLD");
   raceCombo.getItems().add("FAULT-BLOCK");
   raceCombo.getItems().add("DOME");
   raceCombo.getItems().add("VOLCANIC");
   raceCombo.getItems().add("PLATEAU");
   updateValues();
 }
Ejemplo n.º 3
0
  /**
   * Constructs an exit button.
   *
   * @return constructed button
   */
  private Button getBackButton() {
    Button exitButton = new Button("BACK");
    exitButton.setMinSize(100, 50);
    exitButton.setCancelButton(true);

    exitButton.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("Back to Network Menu");
            PaperSoccer.getMainWindow().showNetworkWindow();
          }
        });

    return exitButton;
  }
  @FXML
  void initialize() {
    assert syncUserName != null
        : "fx:id=\"syncUserName\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert cancelButton != null
        : "fx:id=\"cancelButton\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert password != null
        : "fx:id=\"password\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert fullNameUnique != null
        : "fx:id=\"fullNameUnique\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert roles != null : "fx:id=\"roles\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert layoutPane != null
        : "fx:id=\"layoutPane\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert fullName != null
        : "fx:id=\"fullName\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert okButton != null
        : "fx:id=\"okButton\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert userName != null
        : "fx:id=\"userName\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert workflowUserName != null
        : "fx:id=\"workflowUserName\" was not injected: check your FXML file 'AddUser.fxml'.";
    assert uuid != null : "fx:id=\"uuid\" was not injected: check your FXML file 'AddUser.fxml'.";

    for (RoleOption ro : RoleOption.values()) {
      roles.getItems().add(ro.value());
    }

    upm_ = AppContext.getService(UserProfileManager.class);

    uuidValid_ =
        new ValidBooleanBinding() {
          {
            bind(uuid.textProperty());
          }

          @Override
          protected boolean computeValue() {
            if (uuid.getText().length() == 0 || Utility.isUUID(uuid.getText())) {
              if (uuid.getText().length() > 0
                  && AppContext.getService(TerminologyStoreDI.class)
                      .hasUuid(UUID.fromString(uuid.getText()))) {
                setInvalidReason("If a UUID is specified, it must be unique");
                return false;
              } else {
                clearInvalidReason();
                return true;
              }
            } else {
              setInvalidReason("Invalid uuid");
              return false;
            }
          }
        };

    ErrorMarkerUtils.setupErrorMarkerAndSwap(uuid, layoutPane, uuidValid_);

    userNameValid_ =
        new ValidBooleanBinding() {
          {
            bind(userName.textProperty());
          }

          @Override
          protected boolean computeValue() {
            if (userName.getText().length() > 0 && !upm_.doesProfileExist(userName.getText())) {
              clearInvalidReason();
              return true;
            } else {
              setInvalidReason("The user name is required, and must be unique");
              return false;
            }
          }
        };

    ErrorMarkerUtils.setupErrorMarkerAndSwap(userName, layoutPane, userNameValid_);

    fullNameUniqueValid_ =
        new ValidBooleanBinding() {
          {
            bind(fullNameUnique.textProperty(), uuid.textProperty());
          }

          @Override
          protected boolean computeValue() {
            if (fullNameUnique.getText().length() > 0) {
              UUID userUuid;
              if (uuid.getText().length() > 0) {
                if (uuidValid_.get()) {
                  userUuid = UUID.fromString(uuid.getText());
                } else {
                  setInvalidReason("If a UUID is specified, it must be valid.");
                  return false;
                }
              } else {
                userUuid = GenerateUsers.calculateUserUUID(fullNameUnique.getText());
              }

              if (AppContext.getService(TerminologyStoreDI.class).hasUuid(userUuid)) {
                setInvalidReason("The full name must be unique");
                return false;
              } else {
                clearInvalidReason();
                return true;
              }
            } else {
              setInvalidReason(
                  "The Full Name is required, and must be unique.  If a UUID is specified, it must be valid, and unique");
              return false;
            }
          }
        };

    ErrorMarkerUtils.setupErrorMarkerAndSwap(fullNameUnique, layoutPane, fullNameUniqueValid_);

    okButton.disableProperty().bind(fullNameUniqueValid_.and(userNameValid_).and(uuidValid_).not());

    cancelButton.setCancelButton(true);
    // JavaFX is silly:  https://javafx-jira.kenai.com/browse/RT-39145#comment-434189
    cancelButton.setOnKeyPressed(
        new EventHandler<KeyEvent>() {
          @Override
          public void handle(KeyEvent event) {
            if (event.getCode() == KeyCode.ENTER) {
              event.consume();
              cancelButton.fire();
            }
          }
        });
    cancelButton.setOnAction(
        (event) -> {
          layoutPane.getScene().getWindow().hide();
        });

    okButton.setDefaultButton(true);
    okButton.setOnAction(
        (event) -> {
          try {
            User u = new User();
            u.setFullName(fullName.getText());
            u.setPassword(password.getText());
            u.setSyncUserName(syncUserName.getText());
            u.setWorkflowUserName(workflowUserName.getText());
            u.setUniqueFullName(fullNameUnique.getText());
            u.setUniqueLogonName(userName.getText());
            u.setUUID(uuid.getText());
            for (String roleName : roles.getSelectionModel().getSelectedItems()) {
              u.getRoles().add(RoleOption.fromValue(roleName));
            }
            upm_.createNewUser(u);
            layoutPane.getScene().getWindow().hide();
          } catch (Exception e) {
            logger.error("Error creating user", e);
            AppContext.getCommonDialogs().showErrorDialog("Unexpected error adding user", e);
          }
        });
  }
  @Override
  public void start(Stage stage) {

    stage.setTitle("FX Keyboard (" + System.getProperty("javafx.runtime.version") + ")");
    stage.setResizable(true);

    popup =
        KeyBoardPopupBuilder.create()
            .initLocale(Locale.ENGLISH)
            .addIRobot(RobotFactory.createFXRobot())
            .build();
    popup
        .getKeyBoard()
        .setOnKeyboardCloseButton(
            new EventHandler<Event>() {
              public void handle(Event event) {
                setPopupVisible(false, null);
              }
            });

    FlowPane pane = new FlowPane();
    pane.setVgap(20);
    pane.setHgap(20);
    pane.setPrefWrapLength(100);

    final TextField tf = new TextField("");
    final TextArea ta = new TextArea("");

    Button okButton = new Button("Ok");
    okButton.setDefaultButton(true);

    Button cancelButton = new Button("Cancel");
    cancelButton.setCancelButton(true);

    pane.getChildren().add(new Label("Text1"));
    pane.getChildren().add(tf);
    pane.getChildren().add(new Label("Text2"));
    pane.getChildren().add(ta);
    pane.getChildren().add(okButton);
    pane.getChildren().add(cancelButton);
    // pane.getChildren().add(KeyBoardBuilder.create().addIRobot(RobotFactory.createFXRobot()).build());
    Scene scene = new Scene(pane, 200, 300);

    // add keyboard scene listener to all text components
    scene
        .focusOwnerProperty()
        .addListener(
            new ChangeListener<Node>() {
              @Override
              public void changed(ObservableValue<? extends Node> value, Node n1, Node n2) {
                if (n2 != null && n2 instanceof TextInputControl) {
                  setPopupVisible(true, (TextInputControl) n2);

                } else {
                  setPopupVisible(false, null);
                }
              }
            });

    String css = this.getClass().getResource("/css/KeyboardButtonStyle.css").toExternalForm();
    scene.getStylesheets().add(css);
    stage.setOnCloseRequest(
        new EventHandler<WindowEvent>() {

          public void handle(WindowEvent event) {
            System.exit(0);
          }
        });
    popup.show(stage);
    stage.setScene(scene);
    stage.show();
  }
Ejemplo n.º 6
0
  public void buildForm() {
    try {
      URL location = getClass().getResource("/com/webfront/app/fxml/LedgerEntryForm.fxml");
      ResourceBundle resources = ResourceBundle.getBundle("com.webfront.app.bank");
      FXMLLoader loader = new FXMLLoader(location, resources);

      btnOk.setDefaultButton(true);
      btnCancel.setCancelButton(true);

      stage = new Stage();
      scene = new Scene(this);
      stage.setScene(scene);
      stage.setTitle("Item Detail");

      loader.setRoot(this);
      loader.setController(this);
      loader.load();

      ObservableList<Category> cList = view.getCategoryManager().getCategories();

      ObservableList<Account> accountList =
          javafx.collections.FXCollections.observableArrayList(Bank.accountList);
      accountList
          .stream()
          .forEach(
              (acct) -> {
                accountNum.getItems().add(acct.getId());
              });

      for (Category c : cList) {
        // Category parent = c.getParent();
        Integer parent = c.getParent();
        categoryMap.put(c.getDescription(), c);
        if (parent == 0) {
          primaryCat.getItems().add(c.getDescription());
        } else if (oldItem != null) {
          if (oldItem.getPrimaryCat() != null) {
            if (parent == oldItem.getPrimaryCat().getId()) {
              subCat.getItems().add(c.getDescription());
            }
          }
        }
      }

      if (oldItem != null) {
        if (oldItem.getSubCat() != null) {
          Category c = oldItem.getSubCat();
          if (c != null) {
            String desc = c.getDescription();
            if (!subCat.getItems().contains(desc)) {
              subCat.getItems().add(desc);
            }
            subCat.setValue(c.getDescription());
          }
        }
      }

      primaryCat
          .getSelectionModel()
          .selectedItemProperty()
          .addListener(
              new ChangeListener() {
                @Override
                public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                  String newCat = newValue.toString();
                  if (categoryMap.containsKey(newCat)) {
                    if (oldItem.getId() != null) {
                      Category c = categoryMap.get(newCat);
                      String sqlStmt =
                          "SELECT * FROM categories WHERE parent = " + Integer.toString(c.getId());
                      sqlStmt += " order by description";
                      ObservableList<Category> subCatList =
                          view.getCategoryManager().getCategories(sqlStmt);
                      subCat.getItems().clear();
                      subCatMap.clear();
                      for (Category cat2 : subCatList) {
                        subCatMap.put(cat2.getDescription(), cat2);
                      }
                      subCat.getItems().addAll(subCatMap.keySet());
                      if (oldItem.getPrimaryCat() == null) {
                        oldItem.setPrimaryCat(c);
                        btnOk.setDisable(false);
                      }
                      if (!oldItem.getPrimaryCat().getDescription().equals(primaryCat.getValue())) {
                        oldItem.setPrimaryCat(c);
                        btnOk.setDisable(false);
                      }
                    }
                  }
                }
              });

      subCat
          .getSelectionModel()
          .selectedItemProperty()
          .addListener(
              new ChangeListener() {
                @Override
                public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                  if (newValue != null) {
                    String newCat = newValue.toString();
                    if (subCatMap.containsKey(newCat)) {
                      if (oldItem != null) {
                        oldItem.setSubCat(subCatMap.get(newCat));
                        btnOk.setDisable(false);
                      }
                    }
                  }
                }
              });

      transDescription.setOnKeyPressed(
          new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
              if (!transDescription.getText().equals(oldItem.getTransDesc())) {
                oldItem.setTransDesc(transDescription.getText());
                btnOk.setDisable(false);
              }
            }
          });

      transDescription
          .textProperty()
          .addListener(
              new ChangeListener() {
                @Override
                public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                  if (!oldValue.equals(newValue)) {
                    btnOk.setDisable(false);
                  }
                }
              });

      checkNum.setOnKeyPressed(
          new EventHandler<KeyEvent>() {
            @Override
            public void handle(KeyEvent event) {
              if (event.getCode() == KeyCode.TAB) {
                if (!checkNum.getText().equals(oldItem.getCheckNum())) {
                  oldItem.setCheckNum(checkNum.getText());
                  btnOk.setDisable(false);
                }
              }
            }
          });

      transAmt
          .textProperty()
          .addListener(
              new ChangeListener() {
                @Override
                public void changed(ObservableValue observable, Object oldValue, Object newValue) {
                  if (!oldValue.equals(newValue)) {
                    btnOk.setDisable(false);
                  }
                }
              });

      distView.setPrefSize(857.0, 175.0);
      paymentDetail.setPrefSize(857.0, 175.0);
      distView.getChildren().add(paymentDetail);
      stage.show();

    } catch (IOException ex) {
      Logger.getLogger(LedgerForm.class.getName()).log(Level.SEVERE, null, ex);
    }
  }