/** Initializer */ protected void init() { mFossilUpgradesPane = new FossilUpgradePane(mModel); EventHandler<ActionEvent> upgradeEvent = new PanelChangeEvent(mFossilUpgradesPane); mFossilUpgrades = new ImageButton("fossilfuelupgrade.png", upgradeEvent); mApply = new Button("Apply"); EventHandler<ActionEvent> applyEvent = new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { mModel .getEnergyManager() .getFossil() .setAmount(Integer.parseInt(mValues.get("Plants in Operation").getText())); } }; EventHandler<ActionEvent> upEvent = new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { mValues .get("Plants in Operation") .setText("" + (Integer.parseInt(mValues.get("Plants in Operation").getText()) + 1)); } }; EventHandler<ActionEvent> downEvent = new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { if (Integer.parseInt(mValues.get("Plants in Operation").getText()) != 0) { mValues .get("Plants in Operation") .setText( "" + (Integer.parseInt(mValues.get("Plants in Operation").getText()) - 1)); } } }; mApply.setOnAction(applyEvent); mUp = new ImageButton("up.png", upEvent); mDown = new ImageButton("down.png", downEvent); mUp.setPrefSize(0, 0); mDown.setPrefSize(0, 0); setHalignment(mDown, HPos.CENTER); setHalignment(mUp, HPos.CENTER); setHalignment(mApply, HPos.CENTER); setHalignment(mFossilUpgrades, HPos.RIGHT); }
@FXML private void archiveButtonClicked(ActionEvent event) { configureButtons(); archiveButton.setGraphic(archiveSelectedIMV); // clear old content contentPane.getChildren().clear(); // ask for archive date titleLabel.setText("Archiving"); // create text and textfield VBox mainBox = new VBox(); mainBox.setSpacing(20); mainBox.setAlignment(Pos.CENTER); HBox box = new HBox(); contentPane.getChildren().add(mainBox); box.setSpacing(5); box.setAlignment(Pos.CENTER); Label dateLabel = new Label("Cut Off Date:"); dateLabel.setFont(new Font("System", 24)); TextField dateTF = new TextField(); dateTF.setPromptText("YYYY-MM-DD"); Label errorLabel = new Label(); errorLabel.setTextFill(Paint.valueOf("#f5515f")); errorLabel.setFont(new Font("System", 14)); Button confirmButton = new Button("Confirm"); confirmButton.setStyle( "-fx-background-color: #e63347;" + "-fx-background-radius: 7;" + "-fx-text-fill: white"); confirmButton.setPrefSize(130, 40); confirmButton.setOnAction( e -> { if (dateTF.getText() != null) { String cutoffDate = dateTF.getText().trim(); if (cutoffDate.length() > 10) { errorLabel.setText("Too long"); return; } else if (!isDate(cutoffDate)) { errorLabel.setText("Wrong date format"); return; } boolean success = operation.archive(cutoffDate); if (success) { // set up content contentPane.getChildren().clear(); TableView table = new TableView(); TableColumn fnCol = new TableColumn("First Name"); fnCol.setCellValueFactory(new PropertyValueFactory<>("firstName")); TableColumn lnCol = new TableColumn("Last Name"); lnCol.setCellValueFactory(new PropertyValueFactory<>("lastName")); TableColumn emailCol = new TableColumn("Email"); emailCol.setCellValueFactory(new PropertyValueFactory<>("email")); TableColumn lvCol = new TableColumn("Updated At"); lvCol.setCellValueFactory(new PropertyValueFactory<>("updatedAt")); TableColumn discountCol = new TableColumn("Discount"); discountCol.setCellValueFactory(new PropertyValueFactory<>("discount")); table.getColumns().addAll(fnCol, lnCol, emailCol, lvCol, discountCol); ObservableList<Customer> data = FXCollections.observableArrayList(operation.getArchivedCustomers()); table.setItems(data); contentPane.getChildren().add(table); titleLabel.setText("Archived Customers"); } else { titleLabel.setText("Can't archive"); return; } } else { errorLabel.setText("Please enter a date"); return; } }); box.getChildren().addAll(dateLabel, dateTF, errorLabel); mainBox.getChildren().addAll(box, confirmButton); }