Exemplo n.º 1
0
  /** Starts the Gui applicaiton. */
  public void start(Stage myStage) {

    System.out.println("Inside the start() method.");

    table = new TableView<PersonBean>();
    table.setEditable(true);
    // Give the stage a title.
    myStage.setTitle("Person Spam App");
    filteredData = new FilteredList<>(personData, p -> true);
    sortedData = new SortedList<>(filteredData);
    sortedData.comparatorProperty().bind(table.comparatorProperty());

    table.setItems(sortedData);
    table.setPrefWidth(500);
    table.getStylesheets().add("resource/style.css");

    table.setColumnResizePolicy(TableView.UNCONSTRAINED_RESIZE_POLICY);

    // My edition:
    TableColumn<PersonBean, String> wholeNameCol = new TableColumn<PersonBean, String>("Full name");
    wholeNameCol.setCellValueFactory(new PropertyValueFactory("firstAndLastName"));
    wholeNameCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn());
    wholeNameCol.setOnEditCommit(
        (CellEditEvent<PersonBean, String> t) -> { // Start on line below
          ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow()))
              .setFirstAndLastName(t.getNewValue());
        });

    //		TableColumn<PersonBean, String> firstNameCol = new TableColumn<PersonBean, String>("First
    // Name");
    //		firstNameCol.setCellValueFactory(new PropertyValueFactory("firstName"));
    //		firstNameCol.setCellFactory(TextFieldTableCell.<PersonBean> forTableColumn());
    //		firstNameCol.setOnEditCommit((CellEditEvent<PersonBean, String> t) -> {
    //
    //	((PersonBean)t.getTableView().getItems().get(t.getTablePosition().getRow())).setFirstName(t.getNewValue());
    //		});
    //
    //		TableColumn<PersonBean, String> lastNameCol = new TableColumn<PersonBean, String>("Last
    // Name");
    //		lastNameCol.setCellValueFactory(new PropertyValueFactory("lastName"));
    //		lastNameCol.setCellFactory(TextFieldTableCell.<PersonBean> forTableColumn());
    //		lastNameCol.setOnEditCommit((CellEditEvent<PersonBean, String> t) -> {
    //			((PersonBean)
    // t.getTableView().getItems().get(t.getTablePosition().getRow())).setLastName(t.getNewValue());
    //		});

    TableColumn<PersonBean, String> emailCol = new TableColumn<PersonBean, String>("Email");
    emailCol.setCellValueFactory(new PropertyValueFactory("email"));
    emailCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn());
    emailCol.setOnEditCommit(
        (CellEditEvent<PersonBean, String> t) -> {
          ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow()))
              .setEmail(t.getNewValue());
        });

    TableColumn<PersonBean, String> genderCol = new TableColumn<PersonBean, String>("Gender");
    genderCol.setCellValueFactory(new PropertyValueFactory("gender"));
    genderCol.setCellFactory(TextFieldTableCell.<PersonBean>forTableColumn());
    genderCol.setOnEditCommit(
        (CellEditEvent<PersonBean, String> t) -> {
          ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow()))
              .setGender(t.getNewValue());
        });

    TableColumn<PersonBean, Integer> ageCol = new TableColumn<PersonBean, Integer>("Age");
    ageCol.setCellValueFactory(new PropertyValueFactory("age"));
    ageCol.setCellFactory(
        TextFieldTableCell.<PersonBean, Integer>forTableColumn(new IntegerStringConverter()));
    ageCol.setOnEditCommit(
        (CellEditEvent<PersonBean, Integer> t) -> {
          ((PersonBean) t.getTableView().getItems().get(t.getTablePosition().getRow()))
              .setAge(t.getNewValue());
        });
    table.getColumns().setAll(wholeNameCol, emailCol, genderCol, ageCol);
    ageCol.setId("white");

    Button allButton = new Button("All");
    allButton.setMinSize(100, 10);
    allButton.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("Show all!");
            filteredData.setPredicate(showAll());
          }
        });

    Button maleButton = new Button("Male");
    maleButton.setMinSize(100, 10);
    maleButton.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("Show male");
            // printIt();
            filteredData.setPredicate(isMale());
          }
        });
    Button femaleButton = new Button("Female");
    femaleButton.setMinSize(100, 10);
    femaleButton.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("Show female");
            filteredData.setPredicate(isFemale());
          }
        });

    Button over18Button = new Button("Over 18");
    over18Button.setMinSize(100, 10);
    over18Button.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("Above 18");
            // filteredData.setPredicate(over18());
            filteredData.setPredicate(
                new Predicate<PersonBean>() {
                  public boolean test(PersonBean p) {
                    return p.getAge() > 17;
                  }
                });
          }
        });

    Button addButton = new Button("Add row");
    addButton.setMinSize(100, 10);
    addButton.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("Add me!");
            filteredData.setPredicate(showAll());
            addRow();
          }
        });

    Button removeButton = new Button("Delete row");
    removeButton.setMinSize(100, 10);
    removeButton.setOnAction(
        new EventHandler<ActionEvent>() {

          @Override
          public void handle(ActionEvent event) {
            System.out.println("delete me!");
            List items = new ArrayList(table.getSelectionModel().getSelectedItems());
            personData.removeAll(items);
            table.getSelectionModel().clearSelection();
          }
        });

    // Create a root node. In this case, a flow layout
    // is used, but several alternatives exist.
    FlowPane rootNode = new FlowPane();

    rootNode.getStylesheets().add("resource/style.css");

    rootNode
        .getChildren()
        .addAll(table, allButton, maleButton, femaleButton, over18Button, addButton, removeButton);
    // Create a scene.
    Scene myScene = new Scene(rootNode, 800, 800);

    // Set the scene on the stage.
    myStage.setScene(myScene);

    // Show the stage and its scene.
    myStage.show();
  }
  public Veld1RijtechniekKijktechniek(
      SchermController schermCtrl, EvaController evaCtrl, LeerlingController llnCtrl) {
    evaController = evaCtrl;
    schermController = schermCtrl;
    llnController = llnCtrl;

    this.llnController.getLeerling().addView(this);

    aandachtBtn = new Button("Aandachtspunt");
    aandachtBtn.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            aandacht();
          }
        });

    commentaarCol = new TableColumn("Commentaar");
    commentaarCol.setCellValueFactory(new PropertyValueFactory<Rijtechniek, String>("commentaar"));
    commentaarCol.setCellFactory(TextFieldTableCell.forTableColumn());
    commentaarCol.setOnEditCommit(
        new EventHandler<CellEditEvent<Rijtechniek, String>>() {
          @Override
          public void handle(CellEditEvent<Rijtechniek, String> t) {
            ((Rijtechniek) t.getTableView().getItems().get(t.getTablePosition().getRow()))
                .setCommentaar(t.getNewValue());
          }
        });

    table.setItems(data);
    table.getColumns().addAll(commentaarCol);

    commentaarFld = new TextField();
    commentaarFld.setPromptText("Commentaar");

    addButton = new Button("Voeg toe");
    addButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            resetAandachtBtn();
            if (!"".equals(commentaarFld.getText())) {
              data.add(new Rijtechniek(commentaarFld.getText()));
              commentaarFld.clear();
            }
          }
        });
    table.setItems(data);
    table.setOnMouseClicked(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent e) {
            resetAandachtBtn();
          }
        });
    table.setEditable(true);

    vBox2.getChildren().addAll(table, commentaarFld);
    exit = new Button("Ga terug");

    exit.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            evaController.saveListDataRijtechniek("Stuurtechniek", data);
            Veld1RijtechniekKijktechniek.this.schermController.setScherm(MainApp.RIJTECHNIEK_ID);
            resetAandachtBtn();
          }
        });
    delBtn = new Button("Verwijder");
    delBtn.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            resetAandachtBtn();

            table.getItems().remove(table.getSelectionModel().getSelectedItem());
          }
        });
    delBtn.setMinHeight(30);
    delBtn.setMaxHeight(30);
    delBtn.setMinWidth(125);
    delBtn.setMaxWidth(125);
    delBtn.setAlignment(Pos.CENTER);
    delBtn.setTranslateX(-47);
    delBtn.setStyle("-fx-background-color: #5F6A95; -fx-text-fill:white");
    table.getStylesheets().add("resource/tableView.css");
    commentaarFld.setStyle("-fx-background-color:#789EBF; -fx-text-fill:white");
    commentaarCol.setMaxWidth(496);
    commentaarCol.setMinWidth(496);
    hBox1.getChildren().addAll(titelAfb, titel);
    hBox1.setMinHeight(50);
    hBox1.setMaxHeight(50);
    hBox1.setMinWidth(600);
    hBox1.setMaxWidth(600);
    hBox1.setSpacing(15);
    hBox1.setAlignment(Pos.CENTER);
    titelAfb.setFitHeight(50);
    titelAfb.setFitWidth(50);
    titel.setStyle("-fx-font: 40px Tahoma; -fx-text-fill:white");

    table.setMinWidth(500);
    table.setMaxWidth(500);
    table.setMinHeight(400);
    table.setMaxHeight(400);
    addButton.setMinHeight(30);
    addButton.setMaxHeight(30);
    addButton.setMinWidth(150);
    addButton.setMaxWidth(150);
    addButton.setAlignment(Pos.CENTER);
    aandachtBtn.setMinHeight(30);
    aandachtBtn.setMaxHeight(30);
    aandachtBtn.setMinWidth(150);
    aandachtBtn.setMaxWidth(150);
    aandachtBtn.setAlignment(Pos.CENTER);
    exit.setMinHeight(30);
    exit.setMaxHeight(30);
    exit.setMinWidth(150);
    exit.setMaxWidth(150);
    exit.setAlignment(Pos.CENTER);
    commentaarFld.setMinHeight(30);
    commentaarFld.setMaxHeight(30);
    commentaarFld.setMinWidth(250);
    commentaarFld.setMaxWidth(250);
    commentaarFld.setAlignment(Pos.CENTER);
    table.setTranslateX(70);
    commentaarFld.setTranslateX(90);
    addButton.setTranslateX(90);
    aandachtBtn.setTranslateX(90);
    exit.setTranslateX(90);

    addButton.setStyle("-fx-background-color: #5F6A95; -fx-text-fill:white");
    exit.setStyle("-fx-background-color: #5F6A95; -fx-text-fill:white");
    aandachtBtn.setStyle("-fx-background-color: #5F6A95; -fx-text-fill:white");

    gp.setStyle(
        "-fx-border-color: #282E54; -fx-border-radius:10 10 10 10;"
            + "-fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.8), 10, 0, 0, 0);"
            + "-fx-background-color: #282B3A;"
            + "-fx-background-radius: 5;");
    gp.setMaxWidth(900);
    gp.setMinWidth(900);
    gp.setMinHeight(600);
    gp.setMaxHeight(600);
    gp.setHgap(50);
    gp.setVgap(20);
    gp.setAlignment(Pos.CENTER);
    gp.add(hBox1, 0, 0, 2, 1);
    gp.add(table, 0, 1, 2, 1);
    gp.add(commentaarFld, 0, 2);
    gp.add(addButton, 1, 2);
    gp.add(aandachtBtn, 0, 3);
    gp.add(exit, 1, 3);
    gp.add(delBtn, 1, 3);

    this.setAlignment(Pos.CENTER);
    this.getChildren().add(gp);
    this.setStyle("-fx-background-image: url('resource/achtergrondStandaard.png')");

    update();
  }