Skip to content
Snippets Groups Projects
Commit 99becaaf authored by jonas.stirnema's avatar jonas.stirnema
Browse files

FULL GFX REFACTOR

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 1183 additions and 0 deletions
{
"java.configuration.updateBuildConfiguration": "interactive"
}
\ No newline at end of file
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.hepia</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>ch.hepia.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>ch.hepia.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
package ch.hepia;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import java.io.IOException;
/**
* JavaFX App
*/
public class App extends Application {
private static Scene scene;
@Override
public void start(Stage stage) throws IOException {
scene = new Scene(loadFXML("main_form"), 1280, 800);
stage.setScene(scene);
stage.show();
}
static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}
private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}
public static void main(String[] args) {
launch();
}
}
\ No newline at end of file
package ch.hepia;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner; // Import the Scanner class
// CONTACT IS VOLUNTARILY NOT ABSTRACT BECAUSE
// A USER CAN BE OTHER THAN
// FAMILY, FRIEND OR PROFESSIONAL
// AND IT IS USED IN UNIT TESTS
public class Contact implements Serializable {
// --------------------------------------------------
// -------------------- ATTRIBUTES ------------------
// --------------------------------------------------
protected String fname;
protected List<String> names;
protected String address;
protected List<String> phoneNumbers;
protected List<String> emails;
protected List<String> socials;
protected String job;
protected String relation;
// --------------------------------------------------
// -------------------- CONSTRUCTORS ----------------
// --------------------------------------------------
public Contact() {
setFname(new String(""));
setNames(Arrays.asList(""));
setAddress(new String(""));
setPhoneNumbers(Arrays.asList(""));
setEmails(Arrays.asList(""));
setSocials(Arrays.asList(""));
setJob(new String(""));
}
// Only family name and one first name
public Contact(String fname, String name) {
setFname(new String(fname));
setNames(Arrays.asList(name));
setAddress(new String(""));
setPhoneNumbers(Arrays.asList(""));
setEmails(Arrays.asList(""));
setSocials(Arrays.asList(""));
setJob(new String(""));
}
public Contact(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job) {
setFname(name);
setNames(names);
setAddress(address);
setPhoneNumbers(phones);
setEmails(emails);
setSocials(socials);
setJob(job);
}
// Ask and get complete contact
protected static Contact createCompleteContact(Scanner sc)
{
System.out.print("Family name: ");
String fname = sc.nextLine();
System.out.print("Names (comma separated): ");
List<String> names = Arrays.asList(sc.nextLine().split(","));
System.out.print("Address: ");
String address = sc.nextLine();
System.out.print("Phones (comma separated): ");
List<String> phones = Arrays.asList(sc.nextLine().split(","));
System.out.print("Emails (comma separated): ");
List<String> emails = Arrays.asList(sc.nextLine().split(","));
System.out.print("Socials (comma separated): ");
List<String> socials = Arrays.asList(sc.nextLine().split(","));
System.out.print("Job: ");
String job = sc.nextLine();
return new Contact(fname, names, address, phones, emails, socials, job);
}
// --------------------------------------------------
// ----------------- GETTERS / SETTERS --------------
// --------------------------------------------------
public String getFname() {
return fname;
}
public String getRelation() {
return relation;
}
public void setRelation(String relation) {
if (!relation.isBlank()) {
this.relation = relation;
} else {
this.relation = "*";
}
}
public void setFname(String fname) {
if (!fname.isBlank()) {
this.fname = fname;
} else {
this.fname = "Anon";
}
}
public List<String> getNames() {
return names;
}
public String getName() {
return names.get(0);
}
public void setName(String name) {
// Change the first name in names list
names.set(0, name);
}
public void setNames(List<String> names) {
if (names.isEmpty() || (names.contains("") && (names.size() == 1))) {
this.names = new ArrayList<String>(Arrays.asList("Anoname"));
} else {
this.names = names;
}
}
public void setEmail(String email) {
emails.set(0, email);
}
public String getEmail() {
return emails.get(0);
}
public void setPhone(String phone) {
phoneNumbers.set(0, phone);
}
public String getPhone() {
return phoneNumbers.get(0);
}
public void setSocial(String social)
{
socials.set(0, social);
}
public String getSocial()
{
return socials.get(0);
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
if (address.isBlank()) {
this.address = "Nowhere";
} else {
this.address = address;
}
}
public List<String> getPhoneNumbers() {
return phoneNumbers;
}
public void setPhoneNumbers(List<String> phoneNumbers) {
if (phoneNumbers.isEmpty() || (phoneNumbers.contains("") && (phoneNumbers.size() == 1))) {
this.phoneNumbers = new ArrayList<String>(Arrays.asList("0102030405"));
} else {
this.phoneNumbers = phoneNumbers;
}
}
public List<String> getEmails() {
return emails;
}
public void setEmails(List<String> emails) {
if (emails.isEmpty() || (emails.contains("") && (emails.size() == 1))) {
this.emails = new ArrayList<String>(Arrays.asList("none@none.com"));
} else {
this.emails = emails;
}
}
public List<String> getSocials() {
return socials;
}
public void setSocials(List<String> socials) {
if (socials.isEmpty() || (socials.contains("") && (socials.size() == 1))) {
this.socials = new ArrayList<String>(Arrays.asList("@No_one"));
} else {
this.socials = socials;
}
}
public String getJob() {
return job;
}
public void setJob(String job) {
if (!job.isBlank()) {
this.job = job;
} else {
this.job = "none";
}
}
// SHOW-ERS
public void showFname() {
System.out.println("Last name : " + this.fname);
}
public void showNames() {
System.out.print("First names: ");
System.out.println(Arrays.toString(this.names.toArray()));
}
public void showAddress() {
System.out.println("Address : " + this.address);
}
public void showPhoneNumbers() {
System.out.println("Numbers : " + Arrays.toString(this.phoneNumbers.toArray()));
}
public void showEmails() {
System.out.println("Emails : " + Arrays.toString(this.emails.toArray()));
}
public void showSocials() {
System.out.println("Socials : " + Arrays.toString(this.socials.toArray()));
}
public void showJob() {
System.out.println("Job : " + this.job);
}
public String toShortString() {
return this.fname + " " + this.names.get(0);
}
public void showShort() {
System.out.println(this.toShortString());
}
public void showFull() {
showFname();
showNames();
showAddress();
showPhoneNumbers();
showEmails();
showSocials();
showJob();
}
public void showIndexed() {
System.out.println("(0) Family name - " + this.fname);
System.out.println("(1) Names - " + this.names.toString());
System.out.println("(2) Addresse - " + this.address.toString());
System.out.println("(3) Phone numbers - " + this.phoneNumbers.toString());
System.out.println("(4) Emails - " + this.emails.toString());
System.out.println("(5) Socials - " + this.socials.toString());
System.out.println("(6) Job - " + this.job);
}
public boolean attributesContain(String substr)
{
// Go through attributes by hand cause java is tr**h
List<String> lookinto = new ArrayList<String>(100);
lookinto.add(this.fname);
for (String string : this.names) {
lookinto.add(string);
}
lookinto.add(this.address);
for (String phoneNumber : this.phoneNumbers) {
lookinto.add(phoneNumber);
}
for (String email : this.emails) {
lookinto.add(email);
}
for (String social : this.socials) {
lookinto.add(social);
}
lookinto.add(this.job);
lookinto.add(this.relation);
// Return true when matched and false when not using streams
return lookinto.stream().anyMatch(s ->
{
if (s == null)
return false;
else
return s.toLowerCase().contains(substr);
});
}
@Override
public boolean equals(Object o)
{
// Source : https://www.geeksforgeeks.org/overriding-equals-method-in-java/
// Same object
if (o == this)
{
return true;
}
// If it's not the same type
if (!(o instanceof Contact)) {
return false;
}
// typecast o to Complex so that we can compare data members
Contact c = (Contact) o;
// Compare the data members and return accordingly
return
this.fname.equals(c.fname) &&
this.names.equals(c.names) &&
this.address.equals(c.address) &&
this.phoneNumbers.equals(c.phoneNumbers) &&
this.emails.equals(c.emails) &&
this.socials.equals(c.socials) &&
this.job.equals(c.job);
}
}
package ch.hepia;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.List;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.stage.FileChooser;
public abstract class Data_saving {
public static void saveListToFile(ObservableList<Contact> list) {
// Need regular list because ObservableList is not serializable
List<Contact> regularList = new ArrayList<>(list);
// Open file explorer and select where to save the file
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save contacts");
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
fileChooser.setInitialFileName("contacts.contacts");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Contact files", "*.contacts"));
var file = fileChooser.showSaveDialog(null);
if (file != null) {
try (FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(regularList);
} catch (IOException e) {
System.err.println("Error while saving data: " + e.getMessage());
}
}
}
public static ObservableList<Contact> readListFromFile()
{
List<Contact> loadedContacts = new ArrayList<>();
// Open file explorer and select where to save the file
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Load contacts");
fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Contact files", "*.contacts"));
var file = fileChooser.showOpenDialog(null);
if (file != null) {
try (FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis)) {
loadedContacts = (List<Contact>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
System.err.println("Error while loading data: " + e.getMessage());
}
}
return FXCollections.observableList(loadedContacts);
}
}
package ch.hepia.app;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner; // Import the Scanner class
public class Family extends Contact
{
private String relation;
// --------------------------------------------------
// ----------------- CONSTRUCTORS -------------------
// --------------------------------------------------
public Family()
{
super();
// Base relation is set to *
setRelation("");
}
public Family(String relation)
{
super();
// Base relation is set to *
setRelation(relation);
}
public Family(String fname, String name) {
super(fname, name);
this.relation = "*";
}
public Family(String fname, String name, String relation) {
super(fname, name);
setRelation(relation);
}
public Family(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job)
{
super(name, names, address, phones, emails, socials, job);
this.relation = "*";
}
public Family(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job, String relation)
{
super(name, names, address, phones, emails, socials, job);
setRelation(relation);
}
// Takes a basic contact and a relation to create a Family member
public Family(Contact c, String relation)
{
super(c.getFname(), c.getNames(), c.getAddress(), c.getPhoneNumbers(), c.getEmails(), c.getSocials(),
c.getJob());
setRelation(relation);
}
// --------------------------------------------------
// --------------- SETTER / GETTERS -----------------
// --------------------------------------------------
public String getRelation() {
return relation;
}
// Only settable by menu
public void setRelation(String relation) {
if (!relation.isBlank()) {
this.relation = relation;
} else {
this.relation = "*";
}
}
public void showRelation() {
System.out.println("Relation : " + this.relation);
}
// --------------------------------------------------
// ------------------- SPECIFICS --------------------
// --------------------------------------------------
@Override
public void showIndexed() {
super.showIndexed();
System.out.println("(7) - " + this.relation);
}
@Override
public void showFull()
{
super.showFull();
System.out.println("Relation : " + this.relation);
}
@Override
public String toShortString() {
return this.fname + " " + this.names.get(0) + "(FAMILY)";
}
protected static Family createCompleteFamily(Scanner sc)
{
Contact temp = createCompleteContact(sc);
System.out.print("Relation: ");
String relation = sc.nextLine();
return new Family(temp, relation);
}
}
package ch.hepia.app;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner; // Import the Scanner class
public class Friend extends Contact
{
private String relation;
// --------------------------------------------------
// ----------------- CONSTRUCTORS -------------------
// --------------------------------------------------
public Friend()
{
super();
// Base relation is set to *
setRelation("");
}
public Friend(String relation)
{
super();
// Base relation is set to *
setRelation(relation);
}
public Friend(String fname, String name) {
super(fname, name);
this.relation = "*";
}
public Friend(String fname, String name, String relation) {
super(fname, name);
setRelation(relation);
}
public Friend(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job)
{
super(name, names, address, phones, emails, socials, job);
this.relation = "*";
}
public Friend(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job, String relation)
{
super(name, names, address, phones, emails, socials, job);
setRelation(relation);
}
// Takes a basic contact and a relation to create a Friend member
public Friend(Contact c, String relation)
{
super(c.getFname(), c.getNames(), c.getAddress(), c.getPhoneNumbers(), c.getEmails(), c.getSocials(),
c.getJob());
setRelation(relation);
}
// --------------------------------------------------
// --------------- SETTER / GETTERS -----------------
// --------------------------------------------------
public String getRelation() {
return relation;
}
// Only settable by menu
public void setRelation(String relation) {
if (!relation.isBlank()) {
this.relation = relation;
} else {
this.relation = "*";
}
}
public void showRelation() {
System.out.println("Relation : " + this.relation);
}
// --------------------------------------------------
// ------------------- SPECIFICS --------------------
// --------------------------------------------------
@Override
public void showIndexed() {
super.showIndexed();
System.out.println("(7) - " + this.relation);
}
@Override
public void showFull()
{
super.showFull();
System.out.println("(7) - " + this.relation);
}
@Override
public String toShortString() {
return this.fname + " " + this.names.get(0) + "(FRIEND)";
}
protected static Friend createCompleteFriend(Scanner sc)
{
Contact temp = createCompleteContact(sc);
System.out.print("Relation: ");
String relation = sc.nextLine();
return new Friend(temp, relation);
}
}
package ch.hepia;
import javafx.scene.input.MouseEvent;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.FilteredList;
import javafx.collections.transformation.SortedList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
public class MainFormController implements Initializable {
@FXML
private TableView<Contact> grid_view;
@FXML
private TableColumn<Contact, String> first_name_col;
@FXML
private TableColumn<Contact, String> last_name_col;
@FXML
private TableColumn<Contact, String> address_col;
@FXML
private TableColumn<Contact, String> email_col;
@FXML
private TableColumn<Contact, String> phone_col;
@FXML
private TableColumn<Contact, String> socials_col;
@FXML
private TableColumn<Contact, String> job_col;
@FXML
private TableColumn<Contact, String> relation_col;
@FXML
private TextField tf_search;
ObservableList<Contact> contacts = Data_saving.readListFromFile();
FilteredList<Contact> filtered_contacts = new FilteredList<>(contacts, p -> true);
SortedList<Contact> sorted_contacts = new SortedList<>(filtered_contacts);
@Override
public void initialize(java.net.URL location, java.util.ResourceBundle resources) {
grid_view.setEditable(true);
first_name_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getName()));
first_name_col.setCellFactory(TextFieldTableCell.forTableColumn());
first_name_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setName(t.getNewValue());
}
);
last_name_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getFname()));
last_name_col.setCellFactory(TextFieldTableCell.forTableColumn());
last_name_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setFname(t.getNewValue());
}
);
address_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getAddress()));
address_col.setCellFactory(TextFieldTableCell.forTableColumn());
address_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setAddress(t.getNewValue());
}
);
email_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getEmail()));
email_col.setCellFactory(TextFieldTableCell.forTableColumn());
email_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setEmail(t.getNewValue());
}
);
phone_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getPhone()));
phone_col.setCellFactory(TextFieldTableCell.forTableColumn());
phone_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setPhone(t.getNewValue());
}
);
socials_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getSocial()));
socials_col.setCellFactory(TextFieldTableCell.forTableColumn());
socials_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setSocial(t.getNewValue());
}
);
job_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getJob()));
job_col.setCellFactory(TextFieldTableCell.forTableColumn());
job_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setJob(t.getNewValue());
}
);
relation_col.setCellValueFactory(cellData -> new SimpleStringProperty(cellData.getValue().getRelation()));
relation_col.setCellFactory(TextFieldTableCell.forTableColumn());
relation_col.setOnEditCommit(
(TableColumn.CellEditEvent<Contact, String> t) -> {
(t.getTableView().getItems().get(t.getTablePosition().getRow()))
.setRelation(t.getNewValue());
}
);
filtered_contacts.setPredicate(
contact -> {
if (tf_search.getText() == null || tf_search.getText().isEmpty()) {
return true;
}
String lowerCaseFilter = tf_search.getText().toLowerCase();
return contact.attributesContain(lowerCaseFilter);
}
);
sorted_contacts.comparatorProperty().bind(grid_view.comparatorProperty());
grid_view.setItems(sorted_contacts);
}
@FXML
void btn_add_pressed(MouseEvent event) {
try {
// Add new empty contact with ("SECOND NAME", "FIRST NAME"
contacts.add(new Contact("SECOND NAME", "FIRST NAME"));
} catch (Exception e) {
System.out.println("Error while adding new contact : " + e);
}
}
@FXML
void btn_modify_pressed(MouseEvent event) {
System.out.println("Modify button pressed");
}
@FXML
void btn_remove_pressed(MouseEvent event) {
System.out.println("Remove button pressed");
}
@FXML
void search_changed(KeyEvent event) {
filtered_contacts.setPredicate(
contact -> {
if (tf_search.getText() == null || tf_search.getText().isEmpty()) {
return true;
}
String lowerCaseFilter = tf_search.getText().toLowerCase();
return contact.attributesContain(lowerCaseFilter);
});
}
@FXML
void tbv_key_pressed(KeyEvent event) {
if (event.getCode() == KeyCode.DELETE) {
contacts.remove(grid_view.getSelectionModel().getSelectedItem());
}
}
@FXML
void btn_load(MouseEvent event) {
// Need to read from file and update contacts and grid_view
contacts = Data_saving.readListFromFile();
filtered_contacts = new FilteredList<>(contacts, p -> true);
sorted_contacts = new SortedList<>(filtered_contacts);
filtered_contacts.setPredicate(
contact -> {
if (tf_search.getText() == null || tf_search.getText().isEmpty()) {
return true;
}
String lowerCaseFilter = tf_search.getText().toLowerCase();
return contact.attributesContain(lowerCaseFilter);
}
);
sorted_contacts.comparatorProperty().bind(grid_view.comparatorProperty());
grid_view.setItems(sorted_contacts);
}
@FXML
void btn_save(MouseEvent event) {
Data_saving.saveListToFile(contacts);
}
}
package ch.hepia.app;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
//code for creating an OrderedList class that takes type Contact that extends List and with a custom add method
public class OrderedList<T extends Contact> extends ArrayList<T> {
// Create a List of Contacts with a customm add that inserts the new contact in the right place
// for the list to always be sorted
// The list is sorted by family name, then by first name
// Source https://stackoverflow.com/questions/4903611/java-list-sorting-is-there-a-way-to-keep-a-list-permantly-sorted-automatically
@Override
public boolean add(T c) {
// Binary search takes a custom comparator that compares the family name and then the first name
int index = Collections.binarySearch(this, c, (c1, c2) -> {
int res = c1.getFname().compareToIgnoreCase(c2.getFname());
if (res == 0) {
res = c1.getNames().get(0).compareToIgnoreCase(c2.getNames().get(0));
}
return res;
});
if (index < 0)
index = ~index; // ~ is unary bitwise NOT operator.
super.add(index, c);
return true;
}
}
\ No newline at end of file
package ch.hepia.app;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner; // Import the Scanner class
public class Professional extends Contact
{
private String relation;
// --------------------------------------------------
// ----------------- CONSTRUCTORS -------------------
// --------------------------------------------------
public Professional()
{
super();
// Base relation is set to *
setRelation("");
}
public Professional(String relation)
{
super();
// Base relation is set to *
setRelation(relation);
}
public Professional(String fname, String name) {
super(fname, name);
this.relation = "*";
}
public Professional(String fname, String name, String relation) {
super(fname, name);
setRelation(relation);
}
public Professional(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job)
{
super(name, names, address, phones, emails, socials, job);
this.relation = "*";
}
public Professional(String name, List<String> names, String address, List<String> phones, List<String> emails,
List<String> socials,
String job, String relation)
{
super(name, names, address, phones, emails, socials, job);
setRelation(relation);
}
// Takes a basic contact and a relation to create a Professional member
public Professional(Contact c, String relation)
{
super(c.getFname(), c.getNames(), c.getAddress(), c.getPhoneNumbers(), c.getEmails(), c.getSocials(),
c.getJob());
setRelation(relation);
}
// --------------------------------------------------
// --------------- SETTER / GETTERS -----------------
// --------------------------------------------------
public String getRelation() {
return relation;
}
// Only settable by menu
public void setRelation(String relation) {
if (!relation.isBlank()) {
this.relation = relation;
} else {
this.relation = "*";
}
}
public void showRelation() {
System.out.println("Relation : " + this.relation);
}
// --------------------------------------------------
// ------------------- SPECIFICS --------------------
// --------------------------------------------------
@Override
public void showIndexed() {
super.showIndexed();
System.out.println("(7) - " + this.relation);
}
@Override
public void showFull()
{
super.showFull();
System.out.println("(7) - " + this.relation);
}
@Override
public String toShortString() {
return this.fname + " " + this.names.get(0) + "(PROFESIONNAL)";
}
protected static Professional createCompleteProfessional(Scanner sc)
{
Contact temp = createCompleteContact(sc);
System.out.print("Relation: ");
String relation = sc.nextLine();
return new Professional(temp, relation);
}
}
module ch.hepia {
requires javafx.controls;
requires javafx.fxml;
opens ch.hepia to javafx.fxml;
exports ch.hepia;
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2015, 2019, Gluon and/or its affiliates.
All rights reserved. Use is subject to license terms.
This file is available and licensed under the following license:
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
- Neither the name of Oracle Corporation nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.hepia.MainFormController">
<children>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="796.0" prefWidth="849.0" VBox.vgrow="ALWAYS">
<children>
<Button layoutX="21.0" layoutY="709.0" mnemonicParsing="false" onMouseClicked="#btn_add_pressed" prefHeight="33.0" prefWidth="1240.0" text="ADD" textAlignment="CENTER">
<font>
<Font name="Monospaced Regular" size="13.0" />
</font>
</Button>
<TextField fx:id="tf_search" layoutX="109.0" layoutY="25.0" onKeyTyped="#search_changed" prefHeight="26.0" prefWidth="1124.0" />
<Label layoutX="45.0" layoutY="25.0" prefHeight="26.0" prefWidth="68.0" text="Search:" textAlignment="CENTER">
<font>
<Font size="15.0" />
</font>
</Label>
<TableView fx:id="grid_view" layoutX="20.0" layoutY="81.0" onKeyPressed="#tbv_key_pressed" prefHeight="622.0" prefWidth="1240.0">
<columns>
<TableColumn fx:id="first_name_col" prefWidth="155.0" text="First name" />
<TableColumn fx:id="last_name_col" prefWidth="155.0" text="Last name" />
<TableColumn fx:id="address_col" minWidth="100.0" prefWidth="155.0" text="Adress" />
<TableColumn fx:id="phone_col" prefWidth="155.0" text="Phone" />
<TableColumn fx:id="email_col" prefWidth="155.0" text="Email" />
<TableColumn fx:id="socials_col" minWidth="100.0" prefWidth="155.0" text="Socials" />
<TableColumn fx:id="job_col" minWidth="100.0" prefWidth="155.0" text="Job" />
<TableColumn fx:id="relation_col" minWidth="100.0" prefWidth="155.0" text="Relation" />
</columns>
</TableView>
<Button fx:id="btn_load" layoutX="21.0" layoutY="742.0" mnemonicParsing="false" onMouseClicked="#btn_load" prefHeight="33.0" prefWidth="620.0" text="Load" />
<Button fx:id="btn_save" layoutX="641.0" layoutY="742.0" mnemonicParsing="false" onMouseClicked="#btn_save" prefHeight="33.0" prefWidth="620.0" text="Save" />
</children>
</AnchorPane>
</children>
</VBox>
File added
File added
File added
File added
File added
File added
File added
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment