public void initProperties(Grain g) {
    int currentGridRow = FIRST_PROPERTY_ROW;

    propertiesGp.getChildren().remove(FIRST_PROPERTY_ROW + 1, propertiesGp.getChildren().size());
    propertiesCb.clear();
    propertiesTf.clear();

    for (Entry<String, Property> entry : g.getProperties().entrySet()) {
      Property property = entry.getValue();
      String propertyName = entry.getKey();

      propertiesCb.put(propertyName, new CheckBox(property.getDescription()));
      propertiesCb.get(propertyName).setOnAction(eh);
      GridPane.setConstraints(propertiesCb.get(propertyName), 0, currentGridRow);
      propertiesGp.getChildren().add(propertiesCb.get(propertyName));

      propertiesTf.put(propertyName, new TextField(Double.toString(property.getValue())));
      GridPane.setConstraints(propertiesTf.get(propertyName), 1, currentGridRow);
      propertiesGp.getChildren().add(propertiesTf.get(propertyName));

      if (property.isEnabled()) {
        propertiesCb.get(propertyName).setSelected(true);
      } else {
        propertiesTf.get(propertyName).setDisable(true);
      }

      currentGridRow++;
    }
  }
 public void add(String label, Node... nodes) {
   if (label == null) throw new IllegalArgumentException("label is null");
   if (nodes == null) throw new IllegalArgumentException("node is null");
   Label l = new Label(label);
   GridPane.setConstraints(l, 0, rowc);
   for (int i = 0; i < nodes.length; i++) GridPane.setConstraints(nodes[i], i + 1, rowc);
   GridPane.setHgrow(nodes[nodes.length - 1], Priority.SOMETIMES);
   grid.getChildren().add(l);
   grid.getChildren().addAll(nodes);
   rowc++;
 }
  public void createWallLine(int y) {
    PositionButton button;
    Pane wallRec;

    for (int x = 0; x < 8; x++) {
      wallRec = new Pane();
      wallRec.setPrefSize(30, 10);
      wallRec.setId("wallRec");

      horizontalWalls[x][y] = wallRec;
      gameGrid.setConstraints(horizontalWalls[x][y], column, row);
      gameGrid.getChildren().add(horizontalWalls[x][y]);

      column++;

      button = new WallPositionButton(new Position(x, y));
      button.setPrefSize(10, 10);
      button.setId("wallPosBtn");

      wallPositionButtons[x][y] = button;

      gameGrid.setConstraints(wallPositionButtons[x][y], column, row);
      gameGrid.getChildren().addAll(wallPositionButtons[x][y]);

      column++;
    }

    wallRec = new Pane();
    wallRec.setPrefSize(30, 10);
    wallRec.setId("wallRec");

    horizontalWalls[8][y] = wallRec;
    gameGrid.setConstraints(horizontalWalls[8][y], column, row);
    gameGrid.getChildren().add(horizontalWalls[8][y]);

    column = 0;
    row++;
  }
  public void createMoveLine(int y) {
    PositionButton button;
    Pane wallRec;

    button = new PlayerPositionButton(new Position(0, y));
    button.setPrefSize(60, 60);
    button.setId("board");

    playerPositionButtons[0][y] = button;
    gameGrid.setConstraints(button, column, row);
    gameGrid.getChildren().addAll(playerPositionButtons[0][y]);

    for (int x = 1; x < 9; x++) {
      column++;

      wallRec = new Pane();
      wallRec.setPrefSize(10, 30);
      wallRec.setId("wallRec");

      verticalWalls[x][y] = wallRec;
      gameGrid.setConstraints(wallRec, column, row);
      gameGrid.getChildren().add(verticalWalls[x][y]);

      column++;

      button = new PlayerPositionButton(new Position(x, y));
      button.setPrefSize(60, 60);

      button.setId("board");

      playerPositionButtons[x][y] = button;
      gameGrid.setConstraints(button, column, row);
      gameGrid.getChildren().addAll(playerPositionButtons[x][y]);
    }
    column = 0;
    row++;
  }
示例#5
0
  private GridPane getSubGrid() {
    subGrid = new GridPane();

    topPane = getTopPane();
    bottomPane = getBottomPane();

    topPane.setPadding(new Insets(50));
    bottomPane.setPadding(new Insets(50));
    subGrid.setPadding(new Insets(0, 100, 0, 100));

    // Css styling
    topPane.getStyleClass().add("TopPaneBorder");
    bottomPane.getStyleClass().add("TopPaneBorder");

    topTitleL.getStyleClass().add("topPaneTitle");
    bottomTitle.getStyleClass().add("topPaneTitle");

    bottomPane.setHgap(10);
    bottomPane.setVgap(5);
    bottomPane.setAlignment(Pos.CENTER_LEFT);

    topPane.setVgap(10);
    topPane.setHgap(10);
    topPane.setAlignment(Pos.CENTER);

    subGrid.setAlignment(Pos.CENTER);
    subGrid.setMargin(topPane, new Insets(10));
    subGrid.setMargin(bottomPane, new Insets(10));

    subGrid.setConstraints(topPane, 0, 1, 1, 1, HPos.CENTER, VPos.CENTER);
    subGrid.setConstraints(bottomPane, 0, 2, 1, 1, HPos.LEFT, VPos.CENTER);

    subGrid.getChildren().addAll(topPane, bottomPane);

    return subGrid;
  }
示例#6
0
  private GridPane getBottomPane() {

    // ======================================= BOTTOM PANE =======================================//

    bottomPane = new GridPane();

    // Labels
    Label underEmployedL = new Label("Under Employed");
    Label otherIncomeL = new Label("Other Income Resource");
    Label typeofOwnershipL = new Label("Ownership");
    Label below8kL = new Label("Below 8,000php");
    Label occupancyL = new Label("Occupancy");
    Label schoolage = new Label("Children in School");

    // Combobox

    underEmployedCBox = new ComboBox(getYesNo());
    otherIncomeCbox = new ComboBox(getYesNo());
    ownershipCbox = new ComboBox(getOwnerShip());
    below8kCbox = new ComboBox(getYesNo());
    occupancyCBox = new ComboBox(getOccupancy());
    childrenSchlCBox = new ComboBox(getChildrenSchool());

    ownershipCbox.setPrefWidth(115);
    childrenSchlCBox.setPrefWidth(115);
    childrenSchlCBox.setDisable(true);
    occupancyCBox.setPrefWidth(115);

    underEmployedCBox.setDisable(true);

    int indexY = 0;

    bottomPane.setConstraints(bottomTitle, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(otherIncomeL, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(otherIncomeCbox, 1, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(below8kL, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(below8kCbox, 1, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(typeofOwnershipL, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(ownershipCbox, 1, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(occupancyL, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(occupancyCBox, 1, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(underEmployedL, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(underEmployedCBox, 1, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(schoolage, 0, indexY, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(childrenSchlCBox, 1, indexY, 1, 1, HPos.LEFT, VPos.CENTER);

    indexY++;
    bottomPane.setConstraints(save, 0, indexY, 2, 1, HPos.CENTER, VPos.CENTER);
    bottomPane.setConstraints(cancel, 1, indexY, 2, 1, HPos.CENTER, VPos.CENTER);

    bottomPane.setMargin(save, new Insets(5, 65, 5, 0));
    bottomPane.setMargin(cancel, new Insets(5, 50, 5, 0));

    addBottomComponentListeners();

    bottomPane
        .getChildren()
        .addAll(
            bottomTitle,
            underEmployedL,
            underEmployedCBox,
            otherIncomeL,
            otherIncomeCbox,
            typeofOwnershipL,
            ownershipCbox,
            below8kL,
            below8kCbox,
            occupancyL,
            occupancyCBox,
            schoolage,
            childrenSchlCBox,
            save,
            cancel);

    return bottomPane;
  }
  public ColorPickerPopover() {

    getStyleClass().add("color-picker-popover");
    popup.setAutoHide(true);

    // add this to popup
    popup.getContent().add(this);

    // load stylesheet
    getStylesheets().add(ColorPicker.class.getResource("ColorPicker.css").toString());

    // create popover path for main shape
    final Path p = new Path();
    p.getElements()
        .addAll(
            new MoveTo(PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + RADIUS,
                PICKER_PADDING + ARROW_SIZE,
                false,
                true),
            new LineTo(PICKER_PADDING + ARROW_X - (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + ARROW_X, PICKER_PADDING),
            new LineTo(PICKER_PADDING + ARROW_X + (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + RADIUS,
                false,
                true),
            new LineTo(
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH - RADIUS,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT,
                false,
                true),
            new LineTo(PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS,
                false,
                true),
            new ClosePath());
    p.setFill(
        new LinearGradient(
            0,
            0,
            0,
            1,
            true,
            CycleMethod.NO_CYCLE,
            new Stop(0, Color.web("#313131")),
            new Stop(0.5, Color.web("#5f5f5f")),
            new Stop(1, Color.web("#313131"))));
    p.setStroke(null);
    p.setEffect(new DropShadow(15, 0, 1, Color.gray(0, 0.6)));
    p.setCache(true);

    // create rectangle to capture mouse events to hide
    Rectangle windowClickRect =
        RectangleBuilder.create()
            .width(PICKER_PADDING + PICKER_WIDTH + PICKER_PADDING)
            .height(PICKER_PADDING + PICKER_HEIGHT + PICKER_PADDING)
            .fill(Color.TRANSPARENT)
            .onMouseClicked(
                new EventHandler<MouseEvent>() {

                  @Override
                  public void handle(MouseEvent event) {

                    System.out.println("x= " + event.getX());
                    System.out.println(
                        "p.contains(event.getX(), event.getY()) = "
                            + p.contains(event.getX(), event.getY()));
                    if (!p.contains(event.getX(), event.getY())) {
                      hide();
                    }
                  }
                })
            .build();

    final Circle colorRectIndicator =
        CircleBuilder.create()
            .centerX(60)
            .centerY(60)
            .radius(5)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorRectIndicator
        .centerXProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(sat);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + 10) + (RECT_SIZE * (sat.get() / 100));
              }
            });

    colorRectIndicator
        .centerYProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(bright);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 10)
                    + (RECT_SIZE * (1 - (bright.get() / 100)));
              }
            });

    final Rectangle colorRect =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .build();
    colorRect
        .fillProperty()
        .bind(
            new ObjectBinding<Paint>() {

              {
                bind(color);
              }

              @Override
              protected Paint computeValue() {

                return Color.hsb(hue.getValue(), 1, 1);
              }
            });

    Rectangle colorRectOverlayOne =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    1,
                    0,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(255, 255, 255, 1)),
                    new Stop(1, Color.rgb(255, 255, 255, 0))))
            .build();

    EventHandler<MouseEvent> rectMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double x = event.getX() - colorRect.getX();
            final double y = event.getY() - colorRect.getY();
            sat.set(clamp(x / RECT_SIZE) * 100);
            bright.set(100 - (clamp(y / RECT_SIZE) * 100));
          }
        };

    Rectangle colorRectOverlayTwo =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    0,
                    1,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(0, 0, 0, 0)),
                    new Stop(1, Color.rgb(0, 0, 0, 1))))
            .onMouseDragged(rectMouseHandler)
            .onMouseClicked(rectMouseHandler)
            .build();
    final Rectangle colorBar =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 30)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(20)
            .height(RECT_SIZE)
            .fill(createHueGradient())
            .build();
    final Rectangle colorBarIndicator =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 32)
            .y(PICKER_PADDING + ARROW_SIZE + 15)
            .width(24)
            .height(10)
            .arcWidth(4)
            .arcHeight(4)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorBarIndicator
        .yProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(hue);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 5) + (RECT_SIZE * (hue.get() / 360));
              }
            });
    EventHandler<MouseEvent> barMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double y = event.getY() - colorBar.getY();
            hue.set(clamp(y / RECT_SIZE) * 360);
          }
        };
    colorBar.setOnMouseDragged(barMouseHandler);
    colorBar.setOnMouseClicked(barMouseHandler);

    Label brightnessLabel = new Label("Brightness:");
    brightnessLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(brightnessLabel, 0, 0);

    Slider brightnessSlider = SliderBuilder.create().min(0).max(100).id("BrightnessSlider").build();
    brightnessSlider.valueProperty().bindBidirectional(bright);
    GridPane.setConstraints(brightnessSlider, 1, 0);

    IntegerField brightnessField = new IntegerField();
    brightnessField.valueProperty().bindBidirectional(bright);
    brightnessField.setPrefColumnCount(7);
    GridPane.setConstraints(brightnessField, 2, 0);

    Label saturationLabel = new Label("Saturation:");
    saturationLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(saturationLabel, 0, 1);

    Slider saturationSlider = SliderBuilder.create().min(0).max(100).id("SaturationSlider").build();
    saturationSlider.valueProperty().bindBidirectional(sat);
    GridPane.setConstraints(saturationSlider, 1, 1);

    saturationSlider
        .styleProperty()
        .bind(
            new StringBinding() {

              {
                bind(color);
              }

              @Override
              protected String computeValue() {

                return "picker-color: hsb(" + hue.get() + ",100%,100%);";
              }
            });

    IntegerField saturationField = new IntegerField();
    saturationField.valueProperty().bindBidirectional(sat);
    saturationField.setPrefColumnCount(7);
    GridPane.setConstraints(saturationField, 2, 1);

    Label webLabel = new Label("Web:");
    webLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(webLabel, 0, 2);

    WebColorField webField = new WebColorField();
    webField.valueProperty().bindBidirectional(color);
    GridPane.setConstraints(webField, 1, 2, 2, 1);

    GridPane controls = new GridPane();
    controls.setVgap(5);
    controls.setHgap(5);
    controls
        .getChildren()
        .addAll(
            brightnessLabel,
            brightnessSlider,
            brightnessField,
            saturationLabel,
            saturationSlider,
            saturationField,
            webLabel,
            webField);
    controls.setManaged(false);
    controls.resizeRelocate(
        PICKER_PADDING + 10,
        PICKER_PADDING + ARROW_SIZE + 10 + 170 + 10,
        PICKER_WIDTH - 20,
        controls.getPrefHeight());

    getChildren()
        .addAll(
            windowClickRect,
            p,
            colorRect,
            colorRectOverlayOne,
            colorRectOverlayTwo,
            colorBar,
            colorRectIndicator,
            colorBarIndicator,
            controls);
  }
 public void add(Node... nodes) {
   for (int i = 0; i < nodes.length; i++) GridPane.setConstraints(nodes[i], i, rowc);
   GridPane.setHgrow(nodes[nodes.length - 1], Priority.SOMETIMES);
   grid.getChildren().addAll(nodes);
   rowc++;
 }
 public void add(String label) {
   Label l = new Label(label);
   GridPane.setConstraints(l, 0, rowc);
   grid.getChildren().add(l);
   rowc++;
 }
  public void start(Stage primaryStage) throws Exception {

    // Connecting to Access DB
    connect();

    // Declaration of variable window as primaryStage
    window = primaryStage;
    window.setTitle("Icooköp");
    primaryStage.setTitle("Icooköp");

    // Calls method closeProgram() also when terminating the program
    window.setOnCloseRequest(e -> closeProgram());

    // ---------------------SCENE1--------------------------

    // Scene 1 Welcome Label
    Label labelScene1 = new Label();
    labelScene1.setText("Välkommen till Icooköp beta v0.2!");
    labelScene1.setFont(Font.font("Verdana", 20));

    // Scene 1 left menu with spacing
    VBox scene1leftMenu = new VBox(15);
    scene1leftMenu.setPadding(new Insets(20, 20, 20, 20));

    // Calls closeProgram()
    Button s1q1 = new Button("Avsluta");
    s1q1.setOnAction(e -> closeProgram());

    // Displays all available product types
    Button s1b1 = new Button("Visa produkttyper");
    s1b1.setOnAction(e -> createStatement());

    // TableView object for displaying database data.
    tableview = new TableView();

    // TextField for user input of a selected product.
    Label s1l1 = new Label();
    s1l1.setText("Visa märken till produktgrupp");

    // Calls preparedStatement with product parameter
    choiceBox1 = new ChoiceBox<>();
    getProductTypes();
    choiceBox1
        .getSelectionModel()
        .selectedItemProperty()
        .addListener((v, oldValue, newValue) -> preparedStatement(newValue));

    // Button for switching to scene 2 (insertStamkund)
    Button s1b3 = new Button("Lägg till stamkund");
    s1b3.setOnAction(e -> window.setScene(scene2));

    // Label for drop down menu
    Label s1l2 = new Label();
    s1l2.setText("Se butiksaldo");

    // Creating ChoiceBox (drop down) with all the stores.
    // When choosing a store, storeStock() method is called for that store.
    choiceBox2 = new ChoiceBox<>();
    getStores();
    choiceBox2
        .getSelectionModel()
        .selectedItemProperty()
        .addListener((v, oldValue, newValue) -> storeStock(newValue));

    // Adding buttons, labels, text fields and choicebox (drop down) to left menu
    scene1leftMenu
        .getChildren()
        .addAll(labelScene1, s1q1, s1b1, s1l1, choiceBox1, s1b3, s1l2, choiceBox2);

    // Creating BorderPane object and aligning left and center content
    BorderPane Borderpane1 = new BorderPane();
    Borderpane1.setLeft(scene1leftMenu);
    Borderpane1.setCenter(tableview);

    // Setting scene 1 using BorderPane1. Both scenes have identical dimensions.
    scene1 = new Scene(Borderpane1, 700, 500);

    // ------------------- SCENE2 (insert Stamkund) --------------------

    // HBox for scene 2 created and a Label for it.
    HBox scene2topMenu = new HBox();
    Label labelScene2 = new Label();
    labelScene2.setText("Lägg till stamkund");
    labelScene2.setFont(Font.font("Verdana", 20));

    // Left menu VBox created.
    VBox scene2leftMenu = new VBox(15);

    // Scene 2 Main manu and Quit Button created
    Button s2b1 = new Button("Huvudmeny");
    s2b1.setOnAction(e -> window.setScene(scene1));
    Button s2q1 = new Button("Avsluta");
    s2q1.setOnAction(e -> closeProgram());

    // GridPane for scene 2 created with spacing
    GridPane s2grid = new GridPane();
    s2grid.setPadding(new Insets(10, 10, 10, 10));
    s2grid.setVgap(15);
    s2grid.setHgap(10);

    // Label displaying required input fields
    Label oblLabel = new Label("* = Obligatoriskt fält");
    GridPane.setConstraints(oblLabel, 0, 0);

    // Label for prnParam
    Label pnrLabel = new Label("*Personnummer:");
    GridPane.setConstraints(pnrLabel, 0, 1);

    // pnrParam is forced by regular expression to "6 digits"-"dash"-"4 digits"
    FormattedTextField pnrParam = new FormattedTextField("^\\d{6}-\\d{4}$");
    pnrParam.setPromptText("XXXXXX-XXXX");
    GridPane.setConstraints(pnrParam, 1, 1);

    // Label for fnameParam
    Label fnameLabel = new Label("*Förnamn:");
    GridPane.setConstraints(fnameLabel, 0, 2);

    // First name TextField
    TextField fnameParam = new TextField();
    fnameParam.setPromptText("t.ex. Arne");
    GridPane.setConstraints(fnameParam, 1, 2);

    // Label for snameParam
    Label snameLabel = new Label("*Efternamn:");
    GridPane.setConstraints(snameLabel, 0, 3);

    // Surname TextField
    TextField snameParam = new TextField();
    snameParam.setPromptText("t.ex. Andersson");
    GridPane.setConstraints(snameParam, 1, 3);

    // Label for addrParam
    Label addrLabel = new Label("*Adress:");
    GridPane.setConstraints(addrLabel, 0, 4);

    // Address TextField
    TextField addrParam = new TextField();
    addrParam.setPromptText("t.ex. Storgatan 1");
    GridPane.setConstraints(addrParam, 1, 4);

    // Label for mailParam
    Label mailLabel = new Label("E-post:");
    GridPane.setConstraints(mailLabel, 0, 5);

    // Mail TextField
    TextField mailParam = new TextField();
    mailParam.setPromptText("*****@*****.**");
    GridPane.setConstraints(mailParam, 1, 5);

    // Label for cellParam
    Label cellLabel = new Label("Mobilnummer:");
    GridPane.setConstraints(cellLabel, 0, 6);

    // cellParam is forced by regular expression to "3 digits"-"dash"-"7 digits"
    FormattedTextField cellParam = new FormattedTextField("^\\d{3}-\\d{7}$");
    cellParam.setPromptText("XXX-XXXXXXX");
    GridPane.setConstraints(cellParam, 1, 6);

    // This Label displays user information such as errors and confirmations.
    Label executeLabel = new Label();
    GridPane.setConstraints(executeLabel, 1, 8);

    // Adding Button "Registrera" with a lot of functionality
    Button s2b2 = new Button("Registrera");
    GridPane.setConstraints(s2b2, 1, 7);
    s2b2.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {

            // First if-statement checks for data in required fields.
            // Required: pnrParam, fnameParam, lnameParam and addrParam.
            if ((pnrParam.getText() != null && !pnrParam.getText().isEmpty())
                && (fnameParam.getText() != null && !fnameParam.getText().isEmpty())
                && (snameParam.getText() != null && !snameParam.getText().isEmpty())
                && (addrParam.getText() != null && !addrParam.getText().isEmpty())) {

              // Second if-statement calls checkPnr() to see if pnrParam (Personnummer)
              // is unique in database. If unique, checkPnr() returns False.
              // If !checkPnr = True, all data is valid and we run insertStamkund
              if (!checkPnr(pnrParam.getText())) {

                // Calls insertStamkund() with data from all TextFields.
                // Saves card number to integer cardParam.
                int cardParam =
                    insertStamkund(
                        pnrParam.getText(),
                        fnameParam.getText(),
                        snameParam.getText(),
                        addrParam.getText(),
                        mailParam.getText(),
                        cellParam.getText());

                // Converts cardParam value to String c.
                // Prints a welcoming and customer card number.
                String c = String.valueOf(cardParam);
                executeLabel.setText(
                    "Välkommen som stamkund hos Icooköp!\n" + "Ditt kortnummer är: " + c);

                // Clear TextFields
                pnrParam.clear();
                fnameParam.clear();
                snameParam.clear();
                addrParam.clear();
                mailParam.clear();
                cellParam.clear();
              }

              // If !checkPnr = False, pnrParam is already in database and user is notified.
              else {
                executeLabel.setText(
                    "Personnumret finns redan registrerat!\n" + "Välj ett annat tack.");
              }

            }

            // If any required fields are empty, user is notified.
            else {
              executeLabel.setText("Fyll i alla obligatoriska fält!");
            }
          }
        });

    // Button for clearing data in all TextFields and executeLabel
    Button s2b3 = new Button("Rensa fält");
    GridPane.setConstraints(s2b3, 0, 7);
    s2b3.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent event) {
            pnrParam.clear();
            fnameParam.clear();
            snameParam.clear();
            addrParam.clear();
            mailParam.clear();
            cellParam.clear();
            executeLabel.setText(null);
          }
        });

    // Adding buttons to left and top menus
    scene2leftMenu.getChildren().addAll(s2b1, s2q1);
    scene2topMenu.getChildren().add(labelScene2);

    // Adding Labels and TextFields to scene 2 center grid
    s2grid
        .getChildren()
        .addAll(
            oblLabel,
            pnrLabel,
            pnrParam,
            fnameLabel,
            fnameParam,
            snameLabel,
            snameParam,
            addrLabel,
            addrParam,
            mailLabel,
            mailParam,
            cellLabel,
            cellParam,
            s2b2,
            s2b3,
            executeLabel);

    // Creating BorderPane object and aligning left, top and center content
    BorderPane Borderpane2 = new BorderPane();
    Borderpane2.setLeft(scene2leftMenu);
    Borderpane2.setTop(scene2topMenu);
    Borderpane2.setCenter(s2grid);

    // Setting scene 2 using BorderPane2. Both scenes have identical dimensions.
    scene2 = new Scene(Borderpane2, 700, 500);

    // Setting primary scene and display window
    window.setScene(scene1);
    window.show();
  }
示例#11
0
  /**
   * Creates popup menu based on menu button selected
   *
   * @param type type of menu button selected
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  private void genericPopup(String type) {

    int length = 0;
    int width = 0;
    String title = new String();
    Stage secondaryStage = new Stage();

    // Create a GridPane container
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(5);
    grid.setHgap(5);
    Button submit = new Button("Submit");
    GridPane.setConstraints(submit, 1, 0);
    grid.getChildren().add(submit);

    if (type.equals("customer")) {
      final TextField name = new TextField();
      name.setPrefColumnCount(17);
      GridPane.setConstraints(name, 0, 0);
      grid.getChildren().add(name);

      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (!name.getText().isEmpty()) {
                if (myController.getRestClient().selectCustomer(name.getText(), name)) {
                  secondaryStage.close();
                }
              } else {
                name.setPromptText("Enter customer username.");
              }
              updateAccountsWindow();
            }
          });
      length = 50;
      width = 285;
      title = "Select Customer";
    } else if (type.equals("create")) {
      final ComboBox accountTypeCB = new ComboBox();
      accountTypeCB
          .getItems()
          .addAll("SELECT TYPE", "CHECKING", "SAVINGS", "MONEY MARKET", "MORTGAGE", "CREDIT");
      accountTypeCB.setValue("SELECT TYPE");

      GridPane.setConstraints(accountTypeCB, 0, 0);
      grid.getChildren().add(accountTypeCB);

      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (accountTypeCB.getValue().toString().equals("SELECT TYPE")) {
                accountTypeCB.setValue("SELECT TYPE");
              } else {
                Account.TYPE thisType = Account.TYPE.CHECKING;
                if (accountTypeCB.getValue().toString().equals("SAVINGS")) {
                  thisType = Account.TYPE.SAVINGS;
                } else if (accountTypeCB.getValue().toString().equals("MONEY MARKET")) {
                  thisType = Account.TYPE.MONEY_MARKET;
                } else if (accountTypeCB.getValue().toString().equals("MORTGAGE")) {
                  thisType = Account.TYPE.MORTGAGE;
                } else if (accountTypeCB.getValue().toString().equals("CREDIT")) {
                  thisType = Account.TYPE.CREDIT;
                }

                if (myController.getRestClient().addAccount(thisType, 0.0f, 0.0f)) {
                  secondaryStage.close();
                } else {
                  accountTypeCB.setValue("SELECT TYPE");
                }
              }
              updateAccountsWindow();
            }
          });

      length = 50;
      width = 285;
      title = "Create Account";

    } else if (type.equals("delete")) {
      final ComboBox accountsCB = new ComboBox();
      if (myController.getRestClient().getUserAccounts() != null) {
        Iterator it = myController.getRestClient().getUserAccounts().entrySet().iterator();
        while (it.hasNext()) {
          Map.Entry me = (Map.Entry) it.next();
          accountsCB.getItems().add(me.getKey());
        }
      }
      accountsCB.setValue("SELECT ACCOUNT");

      GridPane.setConstraints(accountsCB, 0, 0);
      grid.getChildren().add(accountsCB);

      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (accountsCB.getValue().equals("SELECT ACCOUNT")) {
                accountsCB.setValue("SELECT ACCOUNT");
              } else {
                if (myController.getRestClient().deleteAccount((int) accountsCB.getValue())) {
                  secondaryStage.close();
                } else {
                  accountsCB.setValue("SELECT ACCOUNT");
                }
              }
              updateAccountsWindow();
            }
          });

      length = 50;
      width = 285;
      title = "Delete Account";

    } else if (type.equals("deposit")) {
      final ComboBox accountsCB = new ComboBox();
      final TextField amount = new TextField();
      amount.setPrefColumnCount(10);
      amount.setPromptText("Deposit Amount");
      if (myController.getRestClient().getUserAccounts() != null) {
        Iterator it = myController.getRestClient().getUserAccounts().entrySet().iterator();
        while (it.hasNext()) {
          Map.Entry me = (Map.Entry) it.next();
          accountsCB.getItems().add(me.getKey());
        }
      }
      accountsCB.setValue("SELECT ACCOUNT");

      GridPane.setConstraints(accountsCB, 0, 0);
      grid.getChildren().add(accountsCB);
      GridPane.setConstraints(amount, 0, 1);
      grid.getChildren().add(amount);
      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (accountsCB.getValue().equals("SELECT ACCOUNT")) {
                accountsCB.setValue("SELECT ACCOUNT");
              } else if (!accountsCB.getValue().equals("SELECT ACCOUNT")
                  && !amount.getText().isEmpty()) {

                if (myController
                    .getRestClient()
                    .makeDeposit((int) accountsCB.getValue(), Float.valueOf(amount.getText()))) {
                  secondaryStage.close();
                } else {
                  accountsCB.setValue("SELECT ACCOUNT");
                  amount.setPromptText("Deposit Amount");
                }

              } else {
                accountsCB.setValue("SELECT ACCOUNT");
                amount.setPromptText("Deposit Amount");
              }
              updateAccountsWindow();
            }
          });

      length = 100;
      width = 285;
      title = "Make Deposit";
    } else if (type.equals("withdraw")) {
      final ComboBox accountsCB = new ComboBox();
      final TextField amount = new TextField();
      amount.setPrefColumnCount(10);
      amount.setPromptText("Withdraw Amount");
      if (myController.getRestClient().getUserAccounts() != null) {
        Iterator it = myController.getRestClient().getUserAccounts().entrySet().iterator();
        while (it.hasNext()) {
          Map.Entry me = (Map.Entry) it.next();
          accountsCB.getItems().add(me.getKey());
        }
      }
      accountsCB.setValue("SELECT ACCOUNT");

      GridPane.setConstraints(accountsCB, 0, 0);
      grid.getChildren().add(accountsCB);
      GridPane.setConstraints(amount, 0, 1);
      grid.getChildren().add(amount);
      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (accountsCB.getValue().equals("SELECT ACCOUNT")) {
                accountsCB.setValue("SELECT ACCOUNT");
              } else if (!accountsCB.getValue().equals("SELECT ACCOUNT")
                  && !amount.getText().isEmpty()) {

                if (myController
                    .getRestClient()
                    .makeWithdrawal((int) accountsCB.getValue(), Float.valueOf(amount.getText()))) {
                  secondaryStage.close();
                } else {
                  accountsCB.setValue("SELECT ACCOUNT");
                  amount.setPromptText("Withdraw Amount");
                }
              } else {
                accountsCB.setValue("SELECT ACCOUNT");
                amount.setPromptText("Withdraw Amount");
              }
              updateAccountsWindow();
            }
          });

      length = 100;
      width = 285;
      title = "Make Deposit";
    } else if (type.equals("transfer")) {
      final ComboBox srcAccountsCB = new ComboBox();
      final ComboBox dstAccountsCB = new ComboBox();
      final TextField amount = new TextField();
      amount.setPrefColumnCount(10);
      amount.setPromptText("Transfer Amount");
      if (myController.getRestClient().getUserAccounts() != null) {
        Iterator it = myController.getRestClient().getUserAccounts().entrySet().iterator();
        while (it.hasNext()) {
          Map.Entry me = (Map.Entry) it.next();
          srcAccountsCB.getItems().add(me.getKey());
          dstAccountsCB.getItems().add(me.getKey());
        }
      }
      srcAccountsCB.setValue("SELECT FROM ACCOUNT");
      dstAccountsCB.setValue("SELECT TO ACCOUNT");

      GridPane.setConstraints(srcAccountsCB, 0, 0);
      GridPane.setConstraints(srcAccountsCB, 0, 1);
      GridPane.setConstraints(amount, 0, 2);
      grid.getChildren().add(srcAccountsCB);
      grid.getChildren().add(dstAccountsCB);
      grid.getChildren().add(amount);
      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (srcAccountsCB.getValue().equals("SELECT FROM ACCOUNT")) {
                srcAccountsCB.setValue("SELECT FROM ACCOUNT");
              } else if (dstAccountsCB.getValue().equals("SELECT TO ACCOUNT")) {
                dstAccountsCB.setValue("SELECT TO ACCOUNT");
              } else if (!srcAccountsCB.getValue().equals("SELECT FROM ACCOUNT")
                  && !dstAccountsCB.getValue().equals("SELECT TO ACCOUNT")
                  && !amount.getText().isEmpty()) {

                if (myController
                    .getRestClient()
                    .makeTransfer(
                        (int) srcAccountsCB.getValue(),
                        (int) dstAccountsCB.getValue(),
                        Float.valueOf(amount.getText()))) {
                  secondaryStage.close();
                } else {
                  srcAccountsCB.setValue("SELECT FROM ACCOUNT");
                  dstAccountsCB.setValue("SELECT TO ACCOUNT");
                  amount.setPromptText("Transfer Amount");
                }
              } else {
                srcAccountsCB.setValue("SELECT FROM ACCOUNT");
                dstAccountsCB.setValue("SELECT TO ACCOUNT");
                amount.setPromptText("Transfer Amount");
              }
              updateAccountsWindow();
            }
          });

      length = 125;
      width = 285;
      title = "Transfer Funds";
    } else if (type.equals("transaction")) {
      final ComboBox accountsCB = new ComboBox();
      if (myController.getRestClient().getUserAccounts() != null) {
        Iterator it = myController.getRestClient().getUserAccounts().entrySet().iterator();
        while (it.hasNext()) {
          Map.Entry me = (Map.Entry) it.next();
          accountsCB.getItems().add(me.getKey());
        }
      }
      accountsCB.setValue("SELECT ACCOUNT");

      GridPane.setConstraints(accountsCB, 0, 0);
      grid.getChildren().add(accountsCB);
      submit.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent e) {
              if (accountsCB.getValue().equals("SELECT ACCOUNT")) {
                accountsCB.setValue("SELECT ACCOUNT");
              } else if (!accountsCB.getValue().equals("SELECT ACCOUNT")) {

                if (myController.getRestClient().getUserAccounts() != null) {
                  Iterator it =
                      myController.getRestClient().getUserAccounts().entrySet().iterator();
                  while (it.hasNext()) {
                    Map.Entry me = (Map.Entry) it.next();
                    if (accountsCB.getSelectionModel().getSelectedItem() == me.getKey()) {
                      updateTransactionWindow((Account) me.getValue());
                    }
                  }
                  secondaryStage.close();
                } else {
                  accountsCB.setValue("SELECT ACCOUNT");
                }

              } else {
                accountsCB.setValue("SELECT ACCOUNT");
              }
              updateAccountsWindow();
            }
          });

      length = 100;
      width = 285;
      title = "View Transactions";
    }

    Scene scene = new Scene(grid, width, length);
    secondaryStage.setScene(scene);
    secondaryStage.setTitle(title);
    secondaryStage.show();
  }
  /** Create and initialise the song panel. */
  public BasicSongPanel() {
    final VBox centrePanel = new VBox();
    transposeDialog = new TransposeDialog();
    GridPane topPanel = new GridPane();

    titleField = new TextField();
    GridPane.setHgrow(titleField, Priority.ALWAYS);
    Label titleLabel = new Label(LabelGrabber.INSTANCE.getLabel("title.label"));
    GridPane.setConstraints(titleLabel, 1, 1);
    topPanel.getChildren().add(titleLabel);
    titleLabel.setLabelFor(titleField);
    GridPane.setConstraints(titleField, 2, 1);
    topPanel.getChildren().add(titleField);

    authorField = new TextField();
    GridPane.setHgrow(authorField, Priority.ALWAYS);
    Label authorLabel = new Label(LabelGrabber.INSTANCE.getLabel("author.label"));
    GridPane.setConstraints(authorLabel, 1, 2);
    topPanel.getChildren().add(authorLabel);
    authorLabel.setLabelFor(authorField);
    GridPane.setConstraints(authorField, 2, 2);
    topPanel.getChildren().add(authorField);

    centrePanel.getChildren().add(topPanel);
    lyricsArea = new SpellTextArea();
    lyricsArea.setMaxHeight(Double.MAX_VALUE);

    final VBox mainPanel = new VBox();
    ToolBar lyricsToolbar = new ToolBar();
    transposeButton = getTransposeButton();
    nonBreakingLineButton = getNonBreakingLineButton();
    lyricsToolbar.getItems().add(transposeButton);
    lyricsToolbar.getItems().add(nonBreakingLineButton);
    lyricsToolbar.getItems().add(new Separator());
    Region spacer = new Region();
    HBox.setHgrow(spacer, Priority.ALWAYS);
    lyricsToolbar.getItems().add(spacer);
    dictSelector = new ComboBox<>();
    Tooltip.install(
        dictSelector, new Tooltip(LabelGrabber.INSTANCE.getLabel("dictionary.language.text")));
    for (Dictionary dict : DictionaryManager.INSTANCE.getDictionaries()) {
      dictSelector.getItems().add(dict);
    }
    dictSelector
        .selectionModelProperty()
        .get()
        .selectedItemProperty()
        .addListener(
            new ChangeListener<Dictionary>() {

              @Override
              public void changed(
                  ObservableValue<? extends Dictionary> ov, Dictionary t, Dictionary t1) {
                lyricsArea.setDictionary(dictSelector.getValue());
              }
            });

    dictSelector.getSelectionModel().select(QueleaProperties.get().getDictionary());
    lyricsToolbar.getItems().add(dictSelector);
    lyricsToolbar.getItems().add(getDictButton());
    VBox.setVgrow(mainPanel, Priority.ALWAYS);
    mainPanel.getChildren().add(lyricsToolbar);
    VBox.setVgrow(lyricsArea, Priority.ALWAYS);
    mainPanel.getChildren().add(lyricsArea);
    centrePanel.getChildren().add(mainPanel);
    setCenter(centrePanel);
  }
  private void updateStatisticsData(List<TaskWithWorklogs> displayResult) {

    if (!SettingsUtil.loadSettings().isShowStatistics()) {
      return;
    }

    statisticsView.getChildren().clear();

    WorklogStatistics statistics = new WorklogStatistics();

    // generic statistics
    displayResult.forEach(
        taskWithWorklogs -> {
          statistics.getTotalTimeSpent().addAndGet(taskWithWorklogs.getTotalInMinutes());

          for (WorklogItem worklogItem : taskWithWorklogs.getWorklogItemList()) {
            String employee = worklogItem.getUserDisplayname();

            // employee total time spent
            AtomicLong totalTimeSpent = statistics.getEmployeeToTotaltimeSpent().get(employee);
            if (totalTimeSpent == null) {
              totalTimeSpent = new AtomicLong(0);
              statistics.getEmployeeToTotaltimeSpent().put(employee, totalTimeSpent);
            }
            totalTimeSpent.addAndGet(worklogItem.getDurationInMinutes());

            // distinct tasks per employee
            Set<String> totalDistinctTasks =
                statistics.getEmployeeToTotalDistinctTasks().get(employee);
            if (totalDistinctTasks == null) {
              totalDistinctTasks = new HashSet<>();
              statistics.getEmployeeToTotalDistinctTasks().put(employee, totalDistinctTasks);
            }
            totalDistinctTasks.add(taskWithWorklogs.getIssue());

            // distinct tasks per employee per project
            Map<String, Set<String>> projectToDistinctTasks =
                statistics.getEmployeeToProjectToDistinctTasks().get(employee);
            if (projectToDistinctTasks == null) {
              projectToDistinctTasks = new HashMap<>();
              statistics
                  .getEmployeeToProjectToDistinctTasks()
                  .put(employee, projectToDistinctTasks);
            }

            Set<String> distinctTasks = projectToDistinctTasks.get(taskWithWorklogs.getProject());
            if (distinctTasks == null) {
              distinctTasks = new HashSet<>();
              projectToDistinctTasks.put(taskWithWorklogs.getProject(), distinctTasks);
            }

            distinctTasks.add(taskWithWorklogs.getIssue());

            // time spent per project
            Map<String, AtomicLong> projectToTimespent =
                statistics.getEmployeeToProjectToWorktime().get(employee);
            if (projectToTimespent == null) {
              projectToTimespent = new HashMap<>();
              statistics.getEmployeeToProjectToWorktime().put(employee, projectToTimespent);
            }

            AtomicLong timespentOnProject = projectToTimespent.get(taskWithWorklogs.getProject());
            if (timespentOnProject == null) {
              timespentOnProject = new AtomicLong(0);
              projectToTimespent.put(taskWithWorklogs.getProject(), timespentOnProject);
            }

            timespentOnProject.addAndGet(worklogItem.getDurationInMinutes());
          }
        });

    // render grid and bar graph
    final AtomicInteger currentGridRow = new AtomicInteger(0);

    GridPane employeeProjectSummaryGrid = new GridPane();
    employeeProjectSummaryGrid.setHgap(5);
    employeeProjectSummaryGrid.setVgap(5);

    NumberAxis projectEmployeeXAxis = new NumberAxis();
    projectEmployeeXAxis.setLabel(FormattingUtil.getFormatted("view.statistics.timespentinhours"));
    projectEmployeeXAxis.setTickLabelRotation(90);

    NumberAxis employeeProjectXAxis = new NumberAxis();
    employeeProjectXAxis.setLabel(FormattingUtil.getFormatted("view.statistics.timespentinhours"));
    employeeProjectXAxis.setTickLabelRotation(90);

    CategoryAxis projectEmployeeYAxis = new CategoryAxis();
    CategoryAxis employeeProjectYAxis = new CategoryAxis();

    StackedBarChart<Number, String> projectEmployeeBargraph =
        new StackedBarChart<>(projectEmployeeXAxis, projectEmployeeYAxis);
    StackedBarChart<Number, String> employeeProjectBargraph =
        new StackedBarChart<>(employeeProjectXAxis, employeeProjectYAxis);

    projectEmployeeBargraph.setTitle(
        FormattingUtil.getFormatted("view.statistics.byprojectandemployee"));
    employeeProjectBargraph.setTitle(
        FormattingUtil.getFormatted("view.statistics.byemployeeandproject"));

    Set<String> projectsToDisplay = new HashSet<>();
    displayResult.forEach(
        taskWithWorklogs -> {
          projectsToDisplay.add(taskWithWorklogs.getProject());
        });
    int projectEmployeeBargraphPreferedHeight =
        HEIGHT_PER_Y_AXIS_ELEMENT * projectsToDisplay.size()
            + HEIGHT_PER_X_AXIS_ELEMENT * statistics.getEmployeeToTotaltimeSpent().keySet().size()
            + ADDITIONAL_HEIGHT;
    projectEmployeeBargraph.setPrefHeight(projectEmployeeBargraphPreferedHeight);
    VBox.setVgrow(projectEmployeeBargraph, Priority.ALWAYS);

    int employeeProjectBargraphPreferedHeight =
        HEIGHT_PER_Y_AXIS_ELEMENT * statistics.getEmployeeToProjectToWorktime().keySet().size()
            + HEIGHT_PER_X_AXIS_ELEMENT * projectsToDisplay.size()
            + ADDITIONAL_HEIGHT;
    employeeProjectBargraph.setPrefHeight(employeeProjectBargraphPreferedHeight);
    VBox.setVgrow(employeeProjectBargraph, Priority.ALWAYS);

    Map<String, XYChart.Series<Number, String>> projectNameToSeries = Maps.newHashMap();

    statistics
        .getEmployeeToProjectToWorktime()
        .keySet()
        .stream()
        .sorted(COLLATOR::compare)
        .forEach(
            employee -> {

              // employee headline label
              Set<String> totalDistinctTasksOfEmployee =
                  statistics.getEmployeeToTotalDistinctTasks().get(employee);
              Label employeeLabel =
                  getBoldLabel(
                      FormattingUtil.getFormatted(
                          "view.statistics.somethingtoamountoftickets",
                          employee,
                          totalDistinctTasksOfEmployee.size()));
              employeeLabel.setPadding(new Insets(20, 0, 0, 0));
              GridPane.setConstraints(employeeLabel, 0, currentGridRow.getAndIncrement());
              GridPane.setColumnSpan(employeeLabel, 4);
              employeeProjectSummaryGrid.getChildren().addAll(employeeLabel);

              // bar graph data container
              XYChart.Series<Number, String> projectEmployeeSeries = new XYChart.Series<>();
              projectEmployeeSeries.setName(employee);
              projectEmployeeBargraph.getData().add(projectEmployeeSeries);

              // time spent per project
              Map<String, AtomicLong> projectToWorktime =
                  statistics.getEmployeeToProjectToWorktime().get(employee);
              Map<String, Label> projectToPercentageLabel = Maps.newHashMap();

              projectToWorktime
                  .keySet()
                  .stream()
                  .sorted(COLLATOR::compare)
                  .forEach(
                      projectName -> {
                        XYChart.Series<Number, String> employeeProjectSeries =
                            projectNameToSeries.get(projectName);
                        if (employeeProjectSeries == null) {
                          employeeProjectSeries = new XYChart.Series<>();
                          employeeProjectSeries.setName(projectName);
                          employeeProjectBargraph.getData().add(employeeProjectSeries);
                          projectNameToSeries.put(projectName, employeeProjectSeries);
                        }

                        // percentage label
                        Label percentageLabel = getBoldLabel("PLACEHOLDER");
                        percentageLabel.setAlignment(Pos.CENTER_RIGHT);
                        percentageLabel.setPadding(new Insets(0, 0, 0, 20));
                        GridPane.setConstraints(percentageLabel, 1, currentGridRow.get());
                        GridPane.setHalignment(percentageLabel, HPos.RIGHT);
                        projectToPercentageLabel.put(projectName, percentageLabel);

                        // project label
                        Set<String> distinctTasksPerProject =
                            statistics
                                .getEmployeeToProjectToDistinctTasks()
                                .get(employee)
                                .get(projectName);
                        Label projectLabel =
                            getBoldLabel(
                                FormattingUtil.getFormatted(
                                    "view.statistics.somethingtoamountoftickets",
                                    projectName,
                                    distinctTasksPerProject.size()));
                        GridPane.setConstraints(projectLabel, 2, currentGridRow.get());

                        // time spent for project label
                        long timespentInMinutes = projectToWorktime.get(projectName).longValue();
                        Label timespentLabel =
                            new Label(FormattingUtil.formatMinutes(timespentInMinutes, true));
                        GridPane.setConstraints(timespentLabel, 3, currentGridRow.get());
                        GridPane.setHgrow(timespentLabel, Priority.ALWAYS);
                        GridPane.setHalignment(timespentLabel, HPos.RIGHT);

                        employeeProjectSummaryGrid
                            .getChildren()
                            .addAll(percentageLabel, projectLabel, timespentLabel);
                        currentGridRow.incrementAndGet();

                        // bargraph data
                        projectEmployeeSeries
                            .getData()
                            .add(new XYChart.Data<>(timespentInMinutes / 60d, projectName));
                        employeeProjectSeries
                            .getData()
                            .addAll(new XYChart.Data<>(timespentInMinutes / 60d, employee));
                      });

              // total time spent
              Label totalLabel =
                  getBoldLabel(FormattingUtil.getFormatted("view.statistics.totaltimespent"));
              GridPane.setConstraints(totalLabel, 0, currentGridRow.get());
              GridPane.setColumnSpan(totalLabel, 4);

              Label timespentLabel =
                  new Label(
                      FormattingUtil.formatMinutes(
                          statistics.getEmployeeToTotaltimeSpent().get(employee).get(), true));
              GridPane.setConstraints(timespentLabel, 3, currentGridRow.get());
              GridPane.setHgrow(timespentLabel, Priority.ALWAYS);
              GridPane.setHalignment(timespentLabel, HPos.RIGHT);
              employeeProjectSummaryGrid.getChildren().addAll(totalLabel, timespentLabel);

              // set label now that we can calculate the percentage
              projectToWorktime
                  .keySet()
                  .forEach(
                      projectName -> {
                        Label percentageLabel = projectToPercentageLabel.get(projectName);

                        double totalSpentTime =
                            statistics.getEmployeeToTotaltimeSpent().get(employee).doubleValue();
                        double spentTimeOnProject =
                            projectToWorktime.get(projectName).doubleValue();

                        double percentage = spentTimeOnProject / totalSpentTime;
                        String percentageFormatted = FormattingUtil.formatPercentage(percentage);
                        percentageLabel.setText(percentageFormatted);
                      });

              currentGridRow.incrementAndGet();
            });

    // employeeProjectBargraph

    statisticsView
        .getChildren()
        .addAll(employeeProjectSummaryGrid, projectEmployeeBargraph, employeeProjectBargraph);

    // custom view statistics
    addAdditionalStatistics(statisticsView, statistics, displayResult);
  }
示例#14
0
 protected void setControls(PropDesc... properties) {
   GridPane grid = new GridPane();
   grid.getStyleClass().add("sample-control-grid");
   grid.setVgap(10);
   grid.setHgap(10);
   int row = 0;
   for (PropDesc property : properties) {
     final PropDesc prop = property;
     Label propName = new Label(prop.name + ":");
     propName.getStyleClass().add("sample-control-grid-prop-label");
     GridPane.setConstraints(propName, 0, row);
     grid.getChildren().add(propName);
     if (prop.valueModel instanceof DoubleProperty) {
       final Label valueLabel = new Label(twoDp.format(prop.initialValue));
       GridPane.setConstraints(valueLabel, 2, row);
       final Slider slider = new Slider();
       slider.setMin(prop.min);
       slider.setMax(prop.max);
       slider.setValue(((Number) prop.initialValue).doubleValue());
       GridPane.setConstraints(slider, 1, row);
       slider.setMaxWidth(Double.MAX_VALUE);
       slider
           .valueProperty()
           .addListener(
               new InvalidationListener() {
                 @Override
                 public void invalidated(Observable ov) {
                   set(prop.valueModel, slider.getValue());
                   valueLabel.setText(twoDp.format(slider.getValue()));
                 }
               });
       grid.getChildren().addAll(slider, valueLabel);
     } else { // if (prop.property.getType() == Color.class || prop.property.getType() ==
              // Paint.class) {
       // FIXME we assume anything that isn't a double property is now a colour property
       final Rectangle colorRect = new Rectangle(20, 20, (Color) prop.initialValue);
       colorRect.setStroke(Color.GRAY);
       final Label valueLabel = new Label(formatWebColor((Color) prop.initialValue));
       valueLabel.setGraphic(colorRect);
       valueLabel.setContentDisplay(ContentDisplay.LEFT);
       GridPane.setConstraints(valueLabel, 2, row);
       final ColorPicker colorPicker = new ColorPicker();
       GridPane.setConstraints(colorPicker, 1, row);
       colorPicker
           .getColor()
           .addListener(
               new InvalidationListener() {
                 @Override
                 public void invalidated(Observable valueModel) {
                   Color c = colorPicker.getColor().get();
                   set(prop.valueModel, c);
                   valueLabel.setText(formatWebColor(c));
                   colorRect.setFill(c);
                 }
               });
       grid.getChildren().addAll(colorPicker, valueLabel);
     }
     row++;
   }
   controls = grid;
 }
  private void drawMazeView(Group root) {
    Canvas canvas = new Canvas(800, 800);
    GraphicsContext gc = initialiseGraphicsContext(canvas);

    GridPane.setConstraints(canvas, 0, 4);

    GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(12);
    grid.setPadding(new Insets(10, 10, 10, 10));

    ColumnConstraints labelConstraints = new ColumnConstraints();
    labelConstraints.setMaxWidth(100);
    grid.getColumnConstraints().add(labelConstraints);

    grid.add(dimensionsLabel, 0, 0);
    grid.add(dimensionsTextField, 1, 0);

    final ComboBox mazeGenComboBox = addMazeGeneratorComboBox();
    final ComboBox<String> preGenComboBox = addPreGeneratedMazeTypes();

    grid.add(mazeGenComboBox, 2, 0);
    grid.add(preGenComboBox, 3, 0);

    Circle entranceMarker =
        new Circle(calculateTopLeftCellX(), calculateTopLeftCellY(), 5, Color.web("blue", 0.5));
    root.getChildren().add(entranceMarker);

    Circle exitMarker =
        new Circle(
            calculateTopLeftCellX() + calculateXOffsetForExit(),
            calculateTopLeftCellY() + calculateYOffsetForExit(),
            5,
            Color.web("red", 0.5));
    root.getChildren().add(exitMarker);

    // Create button that allows you to generate a new maze
    Button btn = new Button();
    btn.setText("Generate Maze");
    btn.setOnAction(
        event -> {
          System.out.println("Button clicked!");

          // default cell sizes
          CELL_LENGTH = 20;
          GAP = 5;

          removeBoxBlur(gc);
          // clear old maze

          root.getChildren().remove(exitMarker);

          timeline.stop();
          timeline.getKeyFrames().clear();

          gc.clearRect(0, 0, canvas.getHeight(), canvas.getWidth());
          setBoxBlur(gc);

          String preGenSelection = preGenComboBox.getValue().toString();

          if (preGenSelection.equals(DEFAULT_PRE_GEN_MAZE_TYPE)) {
            if (!"".equals(dimensionsTextField.getText())) {
              dimensions = Integer.valueOf(dimensionsTextField.getText());
              try {
                maze = new Maze(dimensions, mazeGenComboBox.getValue().toString());
              } catch (Throwable e) {
                e
                    .printStackTrace(); // To change body of catch statement use File | Settings |
                                        // File Templates.
              }
            }
          } else if (preGenSelection.equals(MAZE_ONE)) {
            maze = new Maze(Maze.BT_MAZE_PROBLEM_ONE);
          } else if (preGenSelection.equals(MAZE_TWO)) {
            maze = new Maze(Maze.BT_MAZE_PROBLEM_TWO);
          } else if (preGenSelection.equals(MAZE_THREE)) {
            maze = new Maze(Maze.BT_MAZE_PROBLEM_THREE);
          } else if (preGenSelection.equals(MAZE_FOUR)) {
            maze = new Maze(Maze.BT_MAZE_PROBLEM_FOUR);
          } else if (preGenSelection.equals(MAZE_FIVE)) {
            maze = new Maze(Maze.BT_MAZE_PROBLEM_FIVE);
          } else if (preGenSelection.equals(MAZE_SIX)) {
            maze = new Maze(Maze.BRAID_MAZE_PROBLEM_ONE);
          } else if (preGenSelection.equals(MAZE_SEVEN)) {
            maze = new Maze(Maze.BRAID_MAZE_PROBLEM_TWO);
          } else if (preGenSelection.equals(MAZE_EIGHT)) {
            maze = new Maze(Maze.BRAID_MAZE_PROBLEM_THREE);
          } else if (preGenSelection.equals(MAZE_NINE)) {
            maze = new Maze(Maze.BT_MAZE_COMP);
          } else if (preGenSelection.equals(MAZE_TEN)) {
            maze = new Maze(Maze.BRAID_MAZE_COMP);
          }

          if (maze.representation().length > 24) {
            CELL_LENGTH = 8;
            GAP = 2;
          }

          drawMaze(gc);
        });

    Button solveMazeBtn = new Button();
    solveMazeBtn.setText("Solve");
    solveMazeBtn.setOnAction(
        event -> {
          System.out.println("Solving maze...");

          MazeSolver solver = new MazeSolver(maze.representation());
          List<Path> solution;
          try {
            solution = solver.solve();
            animateRoute(solution, entranceMarker, gc);
            efficiencyLabel.setText("Efficiency: " + solution.size() + " steps");
          } catch (Throwable e) {
            e.printStackTrace();
          }
        });

    grid.add(btn, 0, 1);
    grid.add(solveMazeBtn, 2, 1);
    grid.add(efficiencyLabel, 3, 1);
    grid.add(canvas, 0, 2);
    root.getChildren().add(grid);
  }
示例#16
0
  private GridPane getTopPane() {
    topPane = new GridPane();

    // Top pane
    Label DateL = new Label("Date");
    Label surveyDateL = new Label("Surveyed Date");
    Label NameL = new Label("Name");
    Label spouseNameL = new Label("Spouse Name");
    Label addressL = new Label("Address");
    Label ageL = new Label("Age");
    Label yearofResidencyL = new Label("Year of Residency");
    Label numofChildrenL = new Label("Number of Children");

    // search nodes declaration

    // topPane nodes declaration
    dateField = new TextField(Utility.getCurrentDate());

    datePicker = new DatePicker();
    Name = new TextField();
    SpouseName = new TextField();
    agefield = new TextField();
    addressF = new TextField();
    yrResidency = new TextField();
    numofChildrenF = new TextField();

    // nodes initialization
    dateField.setAlignment(Pos.CENTER);
    dateField.setDisable(true);
    numofChildrenF.setText("0");

    Name.setPromptText("First Name");
    LastName.setPromptText("Last Name");
    MidlleName.setPromptText("Middle Name");

    SpouseName.setPromptText("Spouse Full Name");
    agefield.setPromptText("35");
    addressF.setPromptText("e.g 12345 Manga st. Mabalacat");
    yrResidency.setPromptText("e.g 2012");
    numofChildrenF.setPromptText("Number of children");

    SpouseName.setDisable(true);

    maritalCBox = new ComboBox(getMaritalStatus());
    barangayCb = new ComboBox(getBarangayListModel());
    genderCB = new ComboBox(getGender());

    maritalCBox.setPrefWidth(140);
    maritalCBox.setPromptText("Marital Status");
    maritalCBox.setEditable(false);

    genderCB.setPromptText("Gender");
    genderCB.setPrefWidth(140);

    barangayCb.setPromptText("Barangay");
    barangayCb.setEditable(false);

    // --------------------- Layouting ----------------------------///

    int indexYTop = 0;

    topPane.setConstraints(topTitleL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.TOP);

    indexYTop++;
    topPane.setConstraints(DateL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    topPane.setConstraints(dateField, 1, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);
    topPane.setConstraints(barangayCb, 5, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);

    indexYTop++;

    topPane.setConstraints(surveyDateL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    topPane.setConstraints(datePicker, 1, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);
    bottomPane.setConstraints(maritalCBox, 5, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);

    indexYTop++;
    bottomPane.setConstraints(yearofResidencyL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(yrResidency, 1, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(genderCB, 5, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);

    indexYTop++;
    bottomPane.setConstraints(numofChildrenL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    bottomPane.setConstraints(numofChildrenF, 1, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    topPane.setConstraints(ageL, 4, indexYTop, 1, 1, HPos.RIGHT, VPos.CENTER);
    topPane.setConstraints(agefield, 5, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);

    indexYTop++;
    topPane.setConstraints(NameL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    topPane.setConstraints(Name, 1, indexYTop, 3, 1, HPos.CENTER, VPos.CENTER);
    topPane.setConstraints(LastName, 4, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);
    topPane.setConstraints(MidlleName, 5, indexYTop, 1, 1, HPos.CENTER, VPos.CENTER);

    indexYTop++;
    topPane.setConstraints(spouseNameL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    topPane.setConstraints(SpouseName, 1, indexYTop, 5, 1, HPos.CENTER, VPos.CENTER);

    indexYTop++;
    topPane.setConstraints(addressL, 0, indexYTop, 1, 1, HPos.LEFT, VPos.CENTER);
    topPane.setConstraints(addressF, 1, indexYTop, 5, 1, HPos.CENTER, VPos.CENTER);

    dateField.setPrefColumnCount(6);
    agefield.setPrefColumnCount(6);

    // adding nodes to the top gridpane
    topPane
        .getChildren()
        .addAll(
            topTitleL,
            DateL,
            dateField,
            surveyDateL,
            datePicker,
            barangayCb,
            yearofResidencyL,
            yrResidency,
            maritalCBox,
            numofChildrenL,
            numofChildrenF,
            genderCB,
            NameL,
            Name,
            LastName,
            MidlleName,
            ageL,
            agefield,
            spouseNameL,
            SpouseName,
            addressL,
            addressF);

    addTopComponentListeners();

    return topPane;
  }
  public GridPaneSample() {

    VBox vbox = new VBox();

    // grid1 places the child by specifying the rows and columns in
    // GridPane.setContraints()
    Label grid1Caption =
        new Label(
            "The example below shows GridPane content placement by specifying rows and columns:");
    grid1Caption.setWrapText(true);
    GridPane grid1 = new GridPane();
    grid1.setHgap(4);
    grid1.setVgap(6);
    grid1.setPadding(new Insets(18, 18, 18, 18));
    ObservableList<Node> content = grid1.getChildren();

    Label label = new Label("Name:");
    GridPane.setConstraints(label, 0, 0);
    GridPane.setHalignment(label, HPos.RIGHT);
    content.add(label);

    label = new Label("John Q. Public");
    GridPane.setConstraints(label, 1, 0, 2, 1);
    GridPane.setHalignment(label, HPos.LEFT);
    content.add(label);

    label = new Label("Address:");
    GridPane.setConstraints(label, 0, 1);
    GridPane.setHalignment(label, HPos.RIGHT);
    content.add(label);

    label = new Label("12345 Main Street, Some City, CA");
    GridPane.setConstraints(label, 1, 1, 5, 1);
    GridPane.setHalignment(label, HPos.LEFT);
    content.add(label);

    vbox.getChildren().addAll(grid1Caption, grid1, new Separator());

    // grid2 places the child by influencing the rows and columns themselves
    // via GridRowInfo and GridColumnInfo. This grid uses the preferred
    // width/height and max/min width/height.
    Label grid2Caption =
        new Label(
            "The example below shows GridPane content placement by influencing the rows and columns themselves.");
    grid2Caption.setWrapText(true);
    grid2Caption.setWrapText(true);
    GridPane grid2 = new GridPane();
    grid2.setPadding(new Insets(18, 18, 18, 18));
    RowConstraints rowinfo = new RowConstraints(40, 40, 40);
    ColumnConstraints colinfo = new ColumnConstraints(90, 90, 90);

    for (int i = 0; i <= 2; i++) {
      grid2.getRowConstraints().add(rowinfo);
    }

    for (int j = 0; j <= 2; j++) {
      grid2.getColumnConstraints().add(colinfo);
    }

    Label category = new Label("Category:");
    GridPane.setHalignment(category, HPos.RIGHT);
    Label categoryValue = new Label("Wines");
    Label company = new Label("Company:");
    GridPane.setHalignment(company, HPos.RIGHT);
    Label companyValue = new Label("Acme Winery");
    Label rating = new Label("Rating:");
    GridPane.setHalignment(rating, HPos.RIGHT);
    Label ratingValue = new Label("Excellent");

    ImageView imageView = new ImageView(ICON_48);
    GridPane.setHalignment(imageView, HPos.CENTER);

    // Place content
    GridPane.setConstraints(category, 0, 0);
    GridPane.setConstraints(categoryValue, 1, 0);
    GridPane.setConstraints(company, 0, 1);
    GridPane.setConstraints(companyValue, 1, 1);
    GridPane.setConstraints(imageView, 2, 1);
    GridPane.setConstraints(rating, 0, 2);
    GridPane.setConstraints(ratingValue, 1, 2);
    grid2
        .getChildren()
        .addAll(category, categoryValue, company, companyValue, imageView, rating, ratingValue);

    vbox.getChildren().addAll(grid2Caption, grid2, new Separator());

    // grid3 places the child by influencing the rows and columns
    // via GridRowInfo and GridColumnInfo. This grid uses the percentages
    Label grid3Caption =
        new Label(
            "The example below shows GridPane content placement by influencing row and column percentages.  Also, grid lines are made visible in this example.  The lines can be helpful in debugging.");
    grid3Caption.setWrapText(true);
    GridPane grid3 = new GridPane();
    grid3.setPadding(new Insets(18, 18, 18, 18));
    grid3.setGridLinesVisible(true);
    RowConstraints rowinfo3 = new RowConstraints();
    rowinfo3.setPercentHeight(50);

    ColumnConstraints colInfo2 = new ColumnConstraints();
    colInfo2.setPercentWidth(25);

    ColumnConstraints colInfo3 = new ColumnConstraints();
    colInfo3.setPercentWidth(50);

    grid3.getRowConstraints().add(rowinfo3); // 2*50 percent
    grid3.getRowConstraints().add(rowinfo3);

    grid3.getColumnConstraints().add(colInfo2); // 25 percent
    grid3.getColumnConstraints().add(colInfo3); // 50 percent
    grid3.getColumnConstraints().add(colInfo2); // 25 percent

    Label condLabel = new Label(" Member Name:");
    GridPane.setHalignment(condLabel, HPos.RIGHT);
    GridPane.setConstraints(condLabel, 0, 0);
    Label condValue = new Label("MyName");
    GridPane.setMargin(condValue, new Insets(0, 0, 0, 10));
    GridPane.setConstraints(condValue, 1, 0);

    Label acctLabel = new Label("Member Number:");
    GridPane.setHalignment(acctLabel, HPos.RIGHT);
    GridPane.setConstraints(acctLabel, 0, 1);
    TextField textBox = new TextField("Your number");
    GridPane.setMargin(textBox, new Insets(10, 10, 10, 10));
    GridPane.setConstraints(textBox, 1, 1);

    Button button = new Button("Help");
    GridPane.setConstraints(button, 2, 1);
    GridPane.setMargin(button, new Insets(10, 10, 10, 10));
    GridPane.setHalignment(button, HPos.CENTER);

    GridPane.setConstraints(condValue, 1, 0);
    grid3.getChildren().addAll(condLabel, condValue, button, acctLabel, textBox);

    vbox.getChildren().addAll(grid3Caption, grid3);

    getChildren().add(vbox);
  }
  /**
   * Here is our whole stage with layout, </Br > ( Grid, TextField and Buttons)
   *
   * @author PatrikWebb
   */
  public void NameDisplay() {
    Stage nameWindow = new Stage();

    // Block events to other windows
    nameWindow.initModality(Modality.APPLICATION_MODAL);
    nameWindow.setTitle("Enter your name");
    nameWindow.setMinWidth(250);

    // GridPane Form
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(8);
    grid.setHgap(10);

    // Name Label
    Label nameLabel = new Label("Player Name:");
    GridPane.setConstraints(nameLabel, 0, 0);

    // Name Input
    nameInput = new TextField();
    nameInput.setPromptText("Name");
    nameInput.setFocusTraversable(false);
    GridPane.setConstraints(nameInput, 1, 0);

    // Betting Label
    Label bettingLabel = new Label("Betting amount: ");
    GridPane.setConstraints(bettingLabel, 0, 1);

    // Bett Input
    playerCashInput = new TextField();
    playerCashInput.setFocusTraversable(false);
    playerCashInput.setPromptText("Betting amount");
    GridPane.setConstraints(playerCashInput, 1, 1);

    // Enter button
    Button enterButton = new Button("Enter");
    enterButton.setFocusTraversable(false);
    // setPercentWidth(50);
    GridPane.setConstraints(enterButton, 1, 2);

    // Cancel button
    Button cancelButton = new Button("Demo Player");
    cancelButton.setFocusTraversable(false);
    GridPane.setConstraints(cancelButton, 2, 2);

    //
    enterButton.setOnAction(
        e -> {
          Platform.runLater(
              () -> {
                // Get the input from the nameInput TextField
                name = nameInput.getText();
                // Get the betting input from the bettsInput TextField
                playerCash = Integer.parseInt(playerCashInput.getText());
                // Add name and playerCash input to a new player
                Bank.getInstance().addPlayerToBank(name, playerCash);
                // Add the player to the table
                Bank.getInstance().addPlayersToTheTable();
                // Close the stage
                nameWindow.close();

                System.out.println("\nPlayer Name: " + name);
                System.out.println("Betting Amount: " + playerCash + "\n");
              });
        });

    cancelButton.setOnAction(
        e -> {
          // TODO
          Platform.runLater(
              () -> {

                /* * * * * * * * * * * * *
                 * If you press cancel you still want a player to join
                 * the table so I add a test player insted of
                 * getting the error, Exception JavaFX Application THREAD ;)
                 *  * * * * * * * * * * * */
                Bank.getInstance().addPlayerToBank("Demo Player", 500);
                // Add the player to the table
                Bank.getInstance().addPlayersToTheTable();
                nameWindow.close();
              });
        });

    // Add everything to grid
    grid.getChildren()
        .addAll(nameLabel, nameInput, bettingLabel, playerCashInput, enterButton, cancelButton);

    // Display window and wait for it to be closed before returning
    Scene scene = new Scene(grid, 450, 150);
    nameWindow.setScene(scene);
    nameWindow.showAndWait();
  }