created Methods to show and add Players.
This commit is contained in:
parent
b09929da19
commit
ff6f2bd94e
|
@ -21,7 +21,7 @@ public class Factory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTournament(Tournament tournament) {
|
public void setTournament(Tournament tournament) {
|
||||||
this.tournamentDecorator = tournamentDecorator;
|
this.tournamentDecorator.setTournament(tournament);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BorderPane loadMainWindow(){
|
public BorderPane loadMainWindow(){
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung;
|
package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
public class Game {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Game implements Serializable {
|
||||||
private Participant participant1, Participant2;
|
private Participant participant1, Participant2;
|
||||||
private int points1, points2;
|
private int points1, points2;
|
||||||
private Location location;
|
private Location location;
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
|
public class InvalidNameException extends Exception {
|
||||||
|
public InvalidNameException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidNameException(String errorMessage) {
|
||||||
|
super(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung;
|
package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
public interface Participant {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public interface Participant extends Serializable {
|
||||||
String getName();
|
String getName();
|
||||||
void setName(String name);
|
void setName(String name);
|
||||||
boolean equals(Participant participant);
|
boolean equals(Participant participant);
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung;
|
package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
public class Person {
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Person implements Serializable {
|
||||||
private String name;
|
private String name;
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
|
|
||||||
public Person(String firstName, String name, String phoneNumber){
|
public Person(String firstName, String name, String phoneNumber) throws InvalidNameException, InvalidPhoneNumberException {
|
||||||
|
if(!firstName.matches("^[a-zA-Z][a-zA-Z][-',.][a-zA-Z]{1,20}$")){
|
||||||
|
throw new InvalidNameException("The First name is Invalid.");
|
||||||
|
} else if(!name.matches("^[a-zA-Z][a-zA-Z][-',.][a-zA-Z]{1,20}$")){
|
||||||
|
throw new InvalidNameException("The Last name is Invalid");
|
||||||
|
} else if(!phoneNumber.matches("[\\+0-9]+")){
|
||||||
|
throw new InvalidPhoneNumberException("The entered Phone Number is invalid.");
|
||||||
|
}
|
||||||
setFirstName(firstName);
|
setFirstName(firstName);
|
||||||
setName(name);
|
setName(name);
|
||||||
setPhoneNumber(phoneNumber);
|
setPhoneNumber(phoneNumber);
|
||||||
|
@ -34,4 +43,16 @@ public class Person {
|
||||||
public void setPhoneNumber(String phoneNumber) {
|
public void setPhoneNumber(String phoneNumber) {
|
||||||
this.phoneNumber = phoneNumber;
|
this.phoneNumber = phoneNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class InvalidPhoneNumberException extends Exception {
|
||||||
|
public InvalidPhoneNumberException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public InvalidPhoneNumberException(String errorMessage) {
|
||||||
|
super(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +1,23 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung;
|
package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
public class Player extends Person implements Participant{
|
public class Player extends Person implements Participant{
|
||||||
|
|
||||||
private Date dateOfBirth;
|
private GregorianCalendar dateOfBirth;
|
||||||
|
|
||||||
public Player(String firstName, String name, String phoneNumber, Date dateOfBirth){
|
public Player(String firstName, String name, String phoneNumber, String dateOfBirth) throws InvalidNameException, InvalidPhoneNumberException {
|
||||||
super(firstName, name, phoneNumber);
|
super(firstName, name, phoneNumber);
|
||||||
setDateOfBirth(dateOfBirth);
|
setDateOfBirth(dateOfBirth);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDateOfBirth() {
|
public GregorianCalendar getDateOfBirth() {
|
||||||
return dateOfBirth;
|
return dateOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateOfBirth(Date dateOfBirth) {
|
public void setDateOfBirth(String dateOfBirth) {
|
||||||
this.dateOfBirth = dateOfBirth;
|
String[] date = dateOfBirth.split("\\.");
|
||||||
|
this.dateOfBirth = new GregorianCalendar(Integer.valueOf(date[2]), Integer.valueOf(date[1]), Integer.valueOf(date[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -17,7 +18,7 @@ public class Tournament implements Serializable {
|
||||||
|
|
||||||
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
public Tournament(String name, Type type) throws InvalidNameException, InvalidTypeException {
|
||||||
if(!name.matches("[\\w]{1,20}")){
|
if(!name.matches("[\\w]{1,20}")){
|
||||||
throw new Tournament.InvalidNameException("Invalid Name entered"); //TODO handle en logging.
|
throw new InvalidNameException("Invalid Name entered"); //TODO handle en logging.
|
||||||
} else if(!Arrays.asList(Type.values()).contains(type)){
|
} else if(!Arrays.asList(Type.values()).contains(type)){
|
||||||
throw new InvalidTypeException("Invalid Type selected"); //TODO handle en logging.
|
throw new InvalidTypeException("Invalid Type selected"); //TODO handle en logging.
|
||||||
}
|
}
|
||||||
|
@ -42,6 +43,12 @@ public class Tournament implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObservableList<Participant> getParticipants() {
|
||||||
|
ObservableList<Participant> participantsObservable = FXCollections.observableArrayList();
|
||||||
|
participantsObservable.addAll(participants);
|
||||||
|
return participantsObservable;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -79,17 +86,6 @@ public class Tournament implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InvalidNameException extends Exception {
|
|
||||||
public InvalidNameException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public InvalidNameException(String errorMessage) {
|
|
||||||
super(errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class InvalidTypeException extends Exception {
|
public class InvalidTypeException extends Exception {
|
||||||
public InvalidTypeException() {
|
public InvalidTypeException() {
|
||||||
super();
|
super();
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TournamentDecorator implements IsObservable{
|
public class TournamentDecorator implements IsObservable{
|
||||||
|
@ -22,6 +23,10 @@ public class TournamentDecorator implements IsObservable{
|
||||||
this.tournament = tournament;
|
this.tournament = tournament;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Tournament getTournament() {
|
||||||
|
return tournament;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addListener(IsObserver observer) {
|
public void addListener(IsObserver observer) {
|
||||||
listener.add(observer);
|
listener.add(observer);
|
||||||
|
@ -41,7 +46,7 @@ public class TournamentDecorator implements IsObservable{
|
||||||
Tournament tournament = new Tournament(name, type);
|
Tournament tournament = new Tournament(name, type);
|
||||||
fileIO.saveTournament(tournament);
|
fileIO.saveTournament(tournament);
|
||||||
informListener();
|
informListener();
|
||||||
} catch (Tournament.InvalidNameException e) {
|
} catch (InvalidNameException e) {
|
||||||
e.printStackTrace(); //TODO handle and logging
|
e.printStackTrace(); //TODO handle and logging
|
||||||
} catch (Tournament.InvalidTypeException e) {
|
} catch (Tournament.InvalidTypeException e) {
|
||||||
e.printStackTrace(); //TODO handle and logging
|
e.printStackTrace(); //TODO handle and logging
|
||||||
|
@ -59,6 +64,19 @@ public class TournamentDecorator implements IsObservable{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
|
||||||
|
try {
|
||||||
|
tournament.addParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||||
|
informListener();
|
||||||
|
} catch (Tournament.ParticipantExistsException e) {
|
||||||
|
e.printStackTrace(); //TODO handle and logging
|
||||||
|
} catch (InvalidNameException e) {
|
||||||
|
e.printStackTrace(); //TODO handle and logging
|
||||||
|
} catch (Person.InvalidPhoneNumberException e) {
|
||||||
|
e.printStackTrace(); //TODO handle and logging
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void informListener() {
|
public void informListener() {
|
||||||
for(IsObserver observer : listener) {
|
for(IsObserver observer : listener) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular;
|
package ch.zhaw.projekt2.turnierverwaltung.main.participantAddFormular;
|
||||||
|
|
||||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
||||||
|
import ch.zhaw.projekt2.turnierverwaltung.Participant;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
|
@ -44,7 +45,7 @@ public class ParticipantFormularController extends FXController {
|
||||||
private Label participantListTitle;
|
private Label participantListTitle;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ListView<?> participantListView;
|
private ListView<Participant> participantListView;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Label participantNameLabel;
|
private Label participantNameLabel;
|
||||||
|
@ -63,7 +64,7 @@ public class ParticipantFormularController extends FXController {
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void addParticipant(ActionEvent event) {
|
void addParticipant(ActionEvent event) {
|
||||||
|
getTournamentDecorator().addPlayer(firstNameTextField.getText(), participantNameTextField.getText(), phoneNumberTextField.getText(), birthDateTextField.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -78,6 +79,6 @@ public class ParticipantFormularController extends FXController {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void loadContent() {
|
public void loadContent() {
|
||||||
|
participantListView.setItems(getTournamentDecorator().getTournament().getParticipants());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ class FileIOTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void saveTournament() throws IOException, Tournament.InvalidNameException, Tournament.InvalidTypeException {
|
void saveTournament() throws IOException, InvalidNameException, Tournament.InvalidTypeException {
|
||||||
Tournament tournament = null;
|
Tournament tournament = null;
|
||||||
tournament = new Tournament("test1", Tournament.Type.KO);
|
tournament = new Tournament("test1", Tournament.Type.KO);
|
||||||
io.saveTournament(tournament);
|
io.saveTournament(tournament);
|
||||||
|
|
Loading…
Reference in New Issue