Esempio n. 1
0
  @FXML
  private void initialize() {
    personTableNameColumn.setCellValueFactory(
        (dataFeatures) -> dataFeatures.getValue().nameProperty());
    personTableNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
    personTableNameColumn.setOnEditCommit(
        (cellEditEvent) -> {
          int row = cellEditEvent.getTablePosition().getRow();
          Person person = cellEditEvent.getTableView().getItems().get(row);
          person.setName(cellEditEvent.getNewValue());
        });

    personTableEmailColumn.setCellValueFactory(
        (dataFeatures) -> dataFeatures.getValue().emailProperty());
    personTableEmailColumn.setCellFactory(TextFieldTableCell.forTableColumn());
    personTableNameColumn.setOnEditCommit(
        (cellEditEvent) -> {
          int row = cellEditEvent.getTablePosition().getRow();
          Person person = cellEditEvent.getTableView().getItems().get(row);
          person.setEmail(cellEditEvent.getNewValue());
        });

    ReadOnlyObjectProperty<Person> selectionProperty =
        personTableView.getSelectionModel().selectedItemProperty();
    selectionProperty.addListener(
        (observable, oldValue, newValue) -> {
          personPaneController.setModel(newValue);
        });
    personList = personTableView.getItems();
  }
  /** Initializes the controller class. */
  @Override
  public void initialize(URL url, ResourceBundle rb) {
    resultTable.setItems(searchResults);

    titleC.setCellFactory(
        (TableColumn<SearchResult, String> p) -> {
          TextFieldTableCell<SearchResult, String> cell = new TextFieldTableCell<>();
          cell.setOnMouseClicked(
              t -> {
                if (t.getClickCount() == 2 && (!cell.isEmpty())) {
                  try {
                    String file = cell.getTableView().getItems().get(cell.getIndex()).getId().get();
                    Runtime.getRuntime()
                        .exec(
                            "open /Users/Luxin/Documents/UTC/LO17/SearchEngine/TD/TD01/BULLETINS/"
                                + file
                                + ".htm");
                  } catch (IOException ex) {
                    Logger.getLogger(SearchEngineInterfaceController.class.getName())
                        .log(Level.SEVERE, null, ex);
                  }
                }
              });
          return cell;
        });

    scoreC.setCellValueFactory(cell -> cell.getValue().getScore());
    idC.setCellValueFactory(cell -> cell.getValue().getId());
    titleC.setCellValueFactory(cell -> cell.getValue().getTitle());
  }
  /**
   * Initializes the controller class. This method is automatically called after fxml file has been
   * loaded.
   */
  @FXML
  private void initialize() {

    // setting up the radioButtons
    final ToggleGroup timeIntervalGroup = new ToggleGroup();
    monthlyRadioButton.setToggleGroup(timeIntervalGroup);
    dailyRadioButton.setToggleGroup(timeIntervalGroup);
    hourlyRadioButton.setToggleGroup(timeIntervalGroup);
    fifteenMinRadioButton.setToggleGroup(timeIntervalGroup);
    fifteenMinRadioButton.setSelected(true);

    final ToggleGroup typOfChartGroup = new ToggleGroup();
    regularTimeSeriesRadioButton.setToggleGroup(typOfChartGroup);
    scatterRadioButton.setToggleGroup(typOfChartGroup);
    dailyTypeOfDayRadioButton.setToggleGroup(typOfChartGroup);
    regularTimeSeriesRadioButton.setSelected(true);

    final ToggleGroup typeOfDayGroup = new ToggleGroup();
    schoolDayRadioButton.setToggleGroup(typeOfDayGroup);
    summerDayRadioButton.setToggleGroup(typeOfDayGroup);
    holidayRadioButton.setToggleGroup(typeOfDayGroup);
    weekendRadioButton.setToggleGroup(typeOfDayGroup);
    everyDayRadioButton.setToggleGroup(typeOfDayGroup);
    everyDayRadioButton.setSelected(true);

    updateEnabledButtons();

    // initialize a unique instance of the database
    database = Database.getInstance();
    // initialize the meter table with all the columns.
    meterNumberColumn.setCellValueFactory(cellData -> cellData.getValue().getMeterNumber());
    meterTable.setEditable(true);
    meterNumberColumn.setCellFactory(TextFieldTableCell.forTableColumn());
    meterNumberColumn.setOnEditCommit(
        new EventHandler<TableColumn.CellEditEvent<Meter, String>>() {
          @Override
          public void handle(CellEditEvent<Meter, String> event) {
            event
                .getTableView()
                .getItems()
                .get(event.getTablePosition().getRow())
                .setMeterNumber(Assistant.parsePropertiesString(event.getNewValue()));
          }
        });
    startDateColumn.setCellValueFactory(
        cellData -> Assistant.parsePropertiesString(cellData.getValue().getStartDate().toString()));
    endDateColumn.setCellValueFactory(
        cellData -> Assistant.parsePropertiesString(cellData.getValue().getEndDate().toString()));

    activatedColumn.setCellFactory(cellData -> new CheckBoxCell());

    colorColumn.setCellFactory(cellData -> new ColorButtonCell(java.awt.Color.GREEN));

    initializeDateTable();
  }
 @Override
 public void initialize(URL location, ResourceBundle resources) {
   // cellvaluefactory
   checkedColumn.setCellValueFactory(new PropertyValueFactory<>("checked"));
   columnNameColumn.setCellValueFactory(new PropertyValueFactory<>("columnName"));
   jdbcTypeColumn.setCellValueFactory(new PropertyValueFactory<>("jdbcType"));
   propertyNameColumn.setCellValueFactory(new PropertyValueFactory<>("propertyName"));
   typeHandlerColumn.setCellValueFactory(new PropertyValueFactory<>("typeHandler"));
   // Cell Factory that customize how the cell should render
   checkedColumn.setCellFactory(CheckBoxTableCell.forTableColumn(checkedColumn));
   javaTypeColumn.setCellFactory(TextFieldTableCell.forTableColumn());
   // handle commit event to save the user input data
   javaTypeColumn.setOnEditCommit(
       event -> {
         event
             .getTableView()
             .getItems()
             .get(event.getTablePosition().getRow())
             .setJavaType(event.getNewValue());
       });
   propertyNameColumn.setCellFactory(TextFieldTableCell.forTableColumn());
   propertyNameColumn.setOnEditCommit(
       event -> {
         event
             .getTableView()
             .getItems()
             .get(event.getTablePosition().getRow())
             .setPropertyName(event.getNewValue());
       });
   typeHandlerColumn.setCellFactory(TextFieldTableCell.forTableColumn());
   typeHandlerColumn.setOnEditCommit(
       event -> {
         event
             .getTableView()
             .getItems()
             .get(event.getTablePosition().getRow())
             .setTypeHandle(event.getNewValue());
       });
 }
Esempio n. 5
0
  @Override
  public void initialize(URL url, ResourceBundle rb) {

    Sql.loadSql();

    total.setText("$" + expenseTotal);

    name.setCellValueFactory(new PropertyValueFactory<Expense, String>("name"));
    name.setCellFactory(TextFieldTableCell.<String>forTableColumn());
    vendor.setCellValueFactory(new PropertyValueFactory<Expense, String>("vendor"));
    vendor.setCellFactory(TextFieldTableCell.<String>forTableColumn());
    date.setCellValueFactory(new PropertyValueFactory<Expense, String>("date"));
    date.setCellFactory(TextFieldTableCell.<String>forTableColumn());
    cost.setCellValueFactory(new PropertyValueFactory<Expense, Double>("cost"));
    cost.setCellFactory(
        TextFieldTableCell.forTableColumn(
            new StringConverter<Double>() {

              @Override
              public String toString(Double object) {
                return object.toString();
              }

              @Override
              public Double fromString(String string) {
                return Double.parseDouble(string);
              }
            }));

    add.setOnAction(e -> Action.addExpense());
    delete.setOnAction(e -> Action.deleteExpense());

    if (tableList.size() > 0) emptyLabel.setText("");

    table.setItems(tableList);
    pieChart.setData(pieChartList);
  }
 public void populateDataTable(final SoapServiceVirtualizeDto srv) {
   // dataTableModel.removeActionListeners();
   populateServiceData(
       srv.getSoapServiceVirtualizeName(),
       srv.getCreationTimeStamp(),
       srv.getLastUpdatedTimeStamp(),
       srv.getResponseStub(),
       srv.getRequesStub());
   elementValue.setCellFactory(TextFieldTableCell.forTableColumn());
   elementValue.setOnEditCommit(
       (final TableColumn.CellEditEvent<TableEntry, String> t) -> {
         updateTableDetails(
             srv, t.getTableView().getItems().get(t.getTablePosition().getRow()), t.getNewValue());
       });
 }
 public void populateDataTable(final RestServiceVirtualizeDto rstDto) {
   populateServiceData(
       rstDto.getRestServiceVirtualName(),
       rstDto.getCreationTimeStamp(),
       rstDto.getLastUpdatedTimeStamp(),
       rstDto.getResponseStub(),
       rstDto.getRequesStub());
   elementValue.setCellFactory(TextFieldTableCell.forTableColumn());
   elementValue.setOnEditCommit(
       (final TableColumn.CellEditEvent<TableEntry, String> t) -> {
         updateTableDetails(
             rstDto,
             t.getTableView().getItems().get(t.getTablePosition().getRow()),
             t.getNewValue());
       });
 }
 public void populateDataTableModel(final ProjectDetailsDto projectDetailsDto) {
   removeEntries();
   TableEntry projectName = new TableEntry(PROJECT_NAME, projectDetailsDto.getProjectName());
   TableEntry projectShortName =
       new TableEntry(PROJECT_SHORT_NAME, projectDetailsDto.getProjectShortName());
   TableEntry projectDescription =
       new TableEntry(PROJECT_DETAILS, projectDetailsDto.getProjectDescription());
   dataTable.getItems().add(projectName);
   dataTable.getItems().add(projectShortName);
   dataTable.getItems().add(projectDescription);
   elementValue.setCellFactory(TextFieldTableCell.forTableColumn());
   elementValue.setOnEditCommit(
       (final TableColumn.CellEditEvent<TableEntry, String> t) -> {
         updateTableDetails(
             projectDetailsDto,
             t.getTableView().getItems().get(t.getTablePosition().getRow()),
             t.getNewValue());
       });
 }
Esempio n. 9
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();
  }
  /** @return Top-level {@link Node} */
  public Node create() {
    // Layout:
    //
    // | table |  [Add]
    // | table |  [Remove]
    // | table |
    // | table |

    // Create table with editable columns for type Double (supported as Number)
    final TableColumn<Point, Number> x_col = new TableColumn<>(Messages.PointsTable_X);
    x_col.setCellValueFactory(
        new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {
          @Override
          public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getX());
          }
        });
    x_col.setCellFactory(
        TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    x_col.setOnEditCommit(
        event -> {
          final int row = event.getTablePosition().getRow();
          points.setX(row, event.getNewValue().doubleValue());
        });

    final TableColumn<Point, Number> y_col = new TableColumn<>(Messages.PointsTable_Y);
    y_col.setCellValueFactory(
        new Callback<TableColumn.CellDataFeatures<Point, Number>, ObservableValue<Number>>() {
          @Override
          public ObservableValue<Number> call(CellDataFeatures<Point, Number> param) {
            return new SimpleDoubleProperty(param.getValue().getY());
          }
        });
    y_col.setCellFactory(
        TextFieldTableCell.<Point, Number>forTableColumn(new NumberStringConverter()));
    y_col.setOnEditCommit(
        event -> {
          final int row = event.getTablePosition().getRow();
          points.setY(row, event.getNewValue().doubleValue());
        });

    final ObservableList<Point> data = new PointsAdapter(points);
    final TableView<Point> table = new TableView<>(data);
    table.getColumns().add(x_col);
    table.getColumns().add(y_col);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    table.setPlaceholder(new Label(Messages.PointsTable_Empty));
    table.setEditable(true);

    // Buttons
    final Button add = new Button(Messages.Add, JFXUtil.getIcon("add.png"));
    add.setMaxWidth(Double.MAX_VALUE);
    add.setOnAction(event -> data.add(new Point(0, 0)));

    final Button remove = new Button(Messages.Remove, JFXUtil.getIcon("delete.png"));
    remove.setMaxWidth(Double.MAX_VALUE);
    remove.setOnAction(
        event -> {
          final int sel = table.getSelectionModel().getSelectedIndex();
          if (sel >= 0) data.remove(sel);
        });

    final VBox buttons = new VBox(10, add, remove);
    final HBox content = new HBox(10, table, buttons);
    HBox.setHgrow(table, Priority.ALWAYS);
    return content;
  }
Esempio n. 11
0
  /**
   * createTable is static to allow Army to define a table without having any Actor objects present.
   */
  public static TableView<Actor> createTable() {
    TableView<Actor> table = new TableView<Actor>();
    final double PREF_WIDTH_DOUBLE = 80.0;
    table.setPrefWidth(
        PREF_WIDTH_DOUBLE
            * 7.5); // 7.0 because there are 6 individual columns, but one of those is DOUBLE-WIDTH,
                    // and there is some inter-column spacing
    table.setEditable(true);

    TableColumn<Actor, String> nameCol = new TableColumn<>("Name");
    nameCol.setCellValueFactory(new PropertyValueFactory<Actor, String>("name"));
    nameCol.setPrefWidth(PREF_WIDTH_DOUBLE * 2.0);
    TableColumn<Actor, Number> healthCol = new TableColumn<>("Health");
    healthCol.setCellValueFactory(cell -> cell.getValue().health);
    healthCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> strengthCol = new TableColumn<>("Strength");
    strengthCol.setCellValueFactory(cell -> cell.getValue().strength);
    strengthCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> speedCol = new TableColumn<>("Speed");
    speedCol.setCellValueFactory(cell -> cell.getValue().speed);
    speedCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> locationXCol = new TableColumn<>("X");
    locationXCol.setCellValueFactory(cell -> cell.getValue().getAvatar().translateXProperty());
    locationXCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    TableColumn<Actor, Number> locationYCol = new TableColumn<>("Y");
    locationYCol.setCellValueFactory(cell -> cell.getValue().getAvatar().translateYProperty());
    locationYCol.setPrefWidth(PREF_WIDTH_DOUBLE);
    ObservableList<TableColumn<Actor, ?>> c = table.getColumns();
    c.add(nameCol);
    c.add(healthCol);
    c.add(strengthCol);
    c.add(speedCol);
    c.add(locationXCol);
    c.add(locationYCol);
    // Compare line ABOVE with line BELOW: The BELOW line looks cleaner and does actually work . . .
    // but the compiler spits out a warning. The ABOVE line accomplishes the same thing, less
    // elegantly, but without warnings.
    // table.getColumns().addAll(nameCol, healthCol, strengthCol, speedCol, locationXCol,
    // locationYCol);

    // The following code makes each cell in the selected columns editable (Name, Health, Strength,
    // Speed)
    // We CANNOT implement edit capabilities on the X/Y columns since they are READ-ONLY.
    nameCol.setCellFactory(TextFieldTableCell.<Actor>forTableColumn());
    nameCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setName(event.getNewValue());
          a.resetAvatarAttributes();
        });

    healthCol.setCellFactory(
        TextFieldTableCell.<Actor, Number>forTableColumn(new NumberStringConverter()));
    healthCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setHealth((Double) event.getNewValue());
          a.resetAvatarAttributes();
        });

    strengthCol.setCellFactory(
        TextFieldTableCell.<Actor, Number>forTableColumn(new NumberStringConverter()));
    strengthCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setStrength((Double) event.getNewValue());
          a.resetAvatarAttributes();
        });

    speedCol.setCellFactory(
        TextFieldTableCell.<Actor, Number>forTableColumn(new NumberStringConverter()));
    speedCol.setOnEditCommit(
        event -> {
          Actor a = (event.getTableView().getItems().get(event.getTablePosition().getRow()));
          a.setSpeed((Double) event.getNewValue());
          a.resetAvatarAttributes();
        });

    return table;
  } // end createTable()
Esempio n. 12
0
  @Override
  public void start(Stage primaryStage) throws Exception {
    primaryStage.setTitle("JavaFX Demo");

    /* create the menu (for the top of the user interface) */
    Menu fileMenu = new Menu("File");
    MenuItem newMenuItem = new MenuItem("New", imageFile("images/new.png"));
    newMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+N"));
    fileMenu.getItems().add(newMenuItem);
    fileMenu.getItems().add(new SeparatorMenuItem());
    fileMenu.getItems().add(new MenuItem("Open...", imageFile("images/open.png")));
    fileMenu.getItems().add(new SeparatorMenuItem());
    fileMenu.getItems().add(new MenuItem("Save", imageFile("images/save.png")));
    fileMenu.getItems().add(new MenuItem("Save As...", imageFile("images/save_as.png")));
    fileMenu.getItems().add(new SeparatorMenuItem());
    MenuItem exitMenuItem = new MenuItem("Exit", imageFile("images/exit.png"));
    fileMenu.getItems().add(exitMenuItem);
    exitMenuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+Q"));
    exitMenuItem.setOnAction(e -> System.exit(0));

    Menu editMenu = new Menu("Edit");
    editMenu.getItems().add(new MenuItem("Cut", imageFile("images/cut.png")));
    editMenu.getItems().add(new MenuItem("Copy", imageFile("images/copy.png")));
    editMenu.getItems().add(new MenuItem("Paste", imageFile("images/paste.png")));

    Menu helpMenu = new Menu("Help");
    helpMenu.getItems().add(new MenuItem("About...", imageFile("images/about.png")));
    helpMenu.getItems().add(new SeparatorMenuItem());
    helpMenu.getItems().add(new MenuItem("Help...", imageFile("images/help.png")));

    MenuBar menuBar = new MenuBar();
    menuBar.getMenus().add(fileMenu);
    menuBar.getMenus().add(editMenu);
    menuBar.getMenus().add(helpMenu);

    /* create the table (for the center of the user interface) */
    table = new TableView<>();
    table.setItems(DataSource.getAllStudents());
    table.setEditable(true);

    /* create the table's columns */
    TableColumn<Student, Integer> sidColumn = null;
    sidColumn = new TableColumn<>("SID");
    sidColumn.setMinWidth(100);
    sidColumn.setCellValueFactory(new PropertyValueFactory<>("sid"));

    TableColumn<Student, String> firstNameColumn = null;
    firstNameColumn = new TableColumn<>("First Name");
    firstNameColumn.setMinWidth(200);
    firstNameColumn.setCellValueFactory(new PropertyValueFactory<>("firstName"));
    firstNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn());
    firstNameColumn.setOnEditCommit(
        (CellEditEvent<Student, String> event) -> {
          ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow()))
              .setFirstName(event.getNewValue());
        });

    TableColumn<Student, String> lastNameColumn = null;
    lastNameColumn = new TableColumn<>("Last Name");
    lastNameColumn.setMinWidth(200);
    lastNameColumn.setCellValueFactory(new PropertyValueFactory<>("lastName"));
    lastNameColumn.setCellFactory(TextFieldTableCell.<Student>forTableColumn());
    lastNameColumn.setOnEditCommit(
        (CellEditEvent<Student, String> event) -> {
          ((Student) event.getTableView().getItems().get(event.getTablePosition().getRow()))
              .setLastName(event.getNewValue());
        });

    TableColumn<Student, Double> gpaColumn = null;
    gpaColumn = new TableColumn<>("GPA");
    gpaColumn.setMinWidth(100);
    gpaColumn.setCellValueFactory(new PropertyValueFactory<>("gpa"));

    table.getColumns().add(sidColumn);
    table.getColumns().add(lastNameColumn);
    table.getColumns().add(firstNameColumn);
    table.getColumns().add(gpaColumn);

    /* create an edit form (for the bottom of the user interface) */
    GridPane editArea = new GridPane();
    editArea.setPadding(new Insets(10, 10, 10, 10));
    editArea.setVgap(10);
    editArea.setHgap(10);

    Label sidLabel = new Label("SID:");
    editArea.add(sidLabel, 0, 0);
    TextField sidField = new TextField();
    sidField.setPromptText("SID");
    editArea.add(sidField, 1, 0);

    Label fnameLabel = new Label("First name:");
    editArea.add(fnameLabel, 0, 1);
    TextField fnameField = new TextField();
    fnameField.setPromptText("First Name");
    editArea.add(fnameField, 1, 1);

    Label lnameLabel = new Label("Last name:");
    editArea.add(lnameLabel, 0, 2);
    TextField lnameField = new TextField();
    lnameField.setPromptText("Last Name");
    editArea.add(lnameField, 1, 2);

    Label gpaLabel = new Label("GPA:");
    editArea.add(gpaLabel, 0, 3);
    TextField gpaField = new TextField();
    gpaField.setPromptText("GPA");
    editArea.add(gpaField, 1, 3);

    Button addButton = new Button("Add");
    addButton.setOnAction(
        new EventHandler<ActionEvent>() {
          @Override
          public void handle(ActionEvent e) {
            int sid = Integer.parseInt(sidField.getText());
            String firstName = fnameField.getText();
            String lastName = lnameField.getText();
            double gpa = Double.parseDouble(gpaField.getText());

            table.getItems().add(new Student(sid, firstName, lastName, gpa));

            sidField.setText("");
            fnameField.setText("");
            lnameField.setText("");
            gpaField.setText("");
          }
        });
    editArea.add(addButton, 1, 4);

    /* arrange all components in the main user interface */
    layout = new BorderPane();
    layout.setTop(menuBar);
    layout.setCenter(table);
    layout.setBottom(editArea);

    Scene scene = new Scene(layout, 600, 600);
    primaryStage.setScene(scene);
    primaryStage.show();
  }
Esempio n. 13
0
 @Override
 public void updateItem(BigDecimal number, boolean empty) {
   super.updateItem(number, empty);
   if (!empty) DIS.format4Place(number);
 }
  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();
  }
  @Override
  public void handle(MouseEvent click) {
    @SuppressWarnings("rawtypes")
    TablePosition pos = groupsTable.getSelectionModel().getSelectedCells().get(0);
    if (click.getClickCount() == 2) {
      groupsTable.getSelectionModel().setCellSelectionEnabled(true);
      if (pos.getColumn() == 1) {
        try {
          TableColumn<GroupModel, String> firstNameCol = pos.getTableColumn();
          firstNameCol.setCellFactory(TextFieldTableCell.<GroupModel>forTableColumn());
          firstNameCol.setOnEditCommit(
              (TableColumn.CellEditEvent<GroupModel, String> t) -> {
                GroupModel model =
                    ((GroupModel) t.getTableView().getItems().get(t.getTablePosition().getRow()));
                if (t.getNewValue().isEmpty()) {
                  emptyCheckingError();
                } else {
                  model.setGroupName(t.getNewValue());
                  DBConnector.getInstance().updateGroupModel(model);

                  dbUpdatable.onDBUpdated();
                }
              });
        } catch (ClassCastException exc) {
          System.out.println("ClassCastException ");
        }
      } else if (pos.getColumn() == 2 || pos.getColumn() == 3) {
        TableColumn<GroupModel, Integer> firstNameCol = pos.getTableColumn();
        firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn(new EditStringConverter()));
        try {
          firstNameCol.setOnEditCommit(
              new EventHandler<TableColumn.CellEditEvent<GroupModel, Integer>>() {
                @Override
                public void handle(TableColumn.CellEditEvent<GroupModel, Integer> tt) {
                  int row = tt.getTablePosition().getRow();
                  int column = tt.getTablePosition().getColumn();
                  GroupModel rowModel = ((GroupModel) tt.getTableView().getItems().get(row));
                  Integer rowNewValue = tt.getNewValue().intValue();
                  if (tt.getNewValue() == 0) {
                    emptyCheckingError();
                  } else if ((tt.getNewValue().getClass().isPrimitive())) {
                    // TODO: 1/4/2016
                    invalidDigitValue(tt.getNewValue().toString());
                  } else {
                    switch (column) {
                      case 2:
                        rowModel.setGroupYearGraduate(rowNewValue);
                        break;
                      case 3:
                        rowModel.setVillageElderId(rowNewValue);
                        break;
                    }
                    DBConnector.getInstance().updateGroupModel(rowModel);

                    dbUpdatable.onDBUpdated();
                  }
                }
              });
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }