You are on page 1of 3

/*

* Decompiled with CFR 0_110.


*
* Could not load the following classes:
* javafx.event.ActionEvent
* javafx.fxml.FXML
* javafx.fxml.Initializable
* javafx.scene.control.DatePicker
* javafx.scene.control.Label
* javafx.scene.control.TextField
*/
package fp.demo03.controllers;
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

fp.demo03.Person;
java.net.URL;
java.time.LocalDate;
java.time.format.DateTimeFormatter;
java.util.ArrayList;
java.util.ResourceBundle;
java.util.function.Consumer;
java.util.stream.Stream;
javafx.event.ActionEvent;
javafx.fxml.FXML;
javafx.fxml.Initializable;
javafx.scene.control.DatePicker;
javafx.scene.control.Label;
javafx.scene.control.TextField;
util.file.MyFile;
util.fx.ConfirmDlg;
util.fx.MsgDlg;
util.io.Out;

public class PersonUIController


implements Initializable {
private static final String URI = "person.csv";
private ArrayList<Person> ppl;
private int currentPointer;
@FXML
private TextField fnTF;
@FXML
private TextField lnTF;
@FXML
private DatePicker dobDP;
@FXML
private Label statusLbl;
@FXML
private void saveRecord(ActionEvent event) {
if (!MyFile.exists("person.csv")) {
MyFile.bufferedWriteLine("person.csv", "First Name, Last Name, DOB, Civil Status");
MsgDlg.show("Creating the file ..", "Information");
} else {
MsgDlg.show("File exists, appending ..", "Information");
}
LocalDate dob = (LocalDate)this.dobDP.getValue();
StringBuilder record = new StringBuilder(this.fnTF.getText().trim());

record.append(",");
record.append(this.lnTF.getText().trim());
record.append(",");
record.append(dob.format(DateTimeFormatter.ISO_DATE));
if (MyFile.bufferedWriteLine("person.csv", record.toString())) {
this.fnTF.setText("");
this.lnTF.setText("");
this.statusLbl.setText("Record saved ...");
this.statusLbl.setStyle("-fx-text-fill: blue;");
} else {
this.statusLbl.setText("Record NOT saved ...");
this.statusLbl.setStyle("-fx-text-fill: red;");
}
}
@FXML
private void quitApp(ActionEvent event) {
int choice = ConfirmDlg.show("Are you sure you want to leave this demo?", "Confirmation",
false);
if (choice == 1) {
System.exit(0);
}
}
@FXML
private void firstAction(ActionEvent event) {
if (!this.isEmpty()) {
this.currentPointer = 0;
}
this.assignObjectToUI(this.ppl.get(this.currentPointer));
}
@FXML
void previousAction(ActionEvent event) {
if (!this.isEmpty()) {
this.currentPointer = --this.currentPointer < 0 ? 0 : this.currentPointer;
this.assignObjectToUI(this.ppl.get(this.currentPointer));
}
}
@FXML
void nextAction(ActionEvent event) {
if (!this.isEmpty()) {
this.currentPointer = ++this.currentPointer >= this.ppl.size() ? this.ppl.size() - 1 :
this.currentPointer;
this.assignObjectToUI(this.ppl.get(this.currentPointer));
Out.sopln(this.currentPointer);
}
}
@FXML
void lastAction(ActionEvent event) {
if (!this.isEmpty()) {
this.currentPointer = this.ppl.size() - 1;
}
this.assignObjectToUI(this.ppl.get(this.currentPointer));

}
private void assignObjectToUI(Person p) {
this.fnTF.setText(p.getFirstName());
this.lnTF.setText(p.getLastName());
this.dobDP.setValue((Object)p.getDob());
}
private boolean isEmpty() {
return this.ppl.size() < 1;
}
private void loadFileContent() {
ArrayList<String> records = MyFile.bufferedRead("person.csv");
if (records.size() > 0) {
for (int index = 1; index < records.size(); ++index) {
String[] rec = records.get(index).split(",");
String fn = !rec[0].isEmpty() ? rec[0].trim() : "Dummy";
String ln = !rec[1].isEmpty() ? rec[1].trim() : "Dummy";
LocalDate dob = !rec[2].isEmpty() ? LocalDate.parse(rec[2]) : LocalDate.now();
Person.CivilStatus cv = Person.CivilStatus.SINGLE;
this.ppl.add(new Person(fn, ln, dob, cv));
}
int n = this.currentPointer = this.ppl.size() > 0 ? 1 : -1;
}
if (this.ppl.size() > 0) {
this.ppl.stream().forEach(p -> {
Out.sopln(p);
}
);
}
}
public void initialize(URL url, ResourceBundle rb) {
this.dobDP.setValue((Object)LocalDate.now());
this.ppl = new ArrayList();
if (MyFile.exists("person.csv")) {
this.loadFileContent();
} else {
this.currentPointer = -1;
}
}
}

You might also like