java doc and logging added to class Tournament #37
|
@ -4,8 +4,11 @@ import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController;
|
|||
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.text.Font;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
@ -15,7 +18,7 @@ public class Factory {
|
|||
private FileIO fileIO;
|
||||
//TODO save views instead of recreate them.
|
||||
|
||||
public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator){
|
||||
public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator) {
|
||||
this.fileIO = fileIO;
|
||||
this.tournamentDecorator = tournamentDecorator;
|
||||
}
|
||||
|
@ -28,7 +31,7 @@ public class Factory {
|
|||
this.tournamentDecorator.setTournament(tournament);
|
||||
}
|
||||
|
||||
public BorderPane loadMainWindow(){
|
||||
public BorderPane loadMainWindow() {
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("mainWindow.fxml"));
|
||||
try {
|
||||
return loader.load();
|
||||
|
@ -39,7 +42,7 @@ public class Factory {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void loadTournamentList(BorderPane pane, FactoryDecorator factoryDecorator){
|
||||
public void loadTournamentList(BorderPane pane, FactoryDecorator factoryDecorator) {
|
||||
tournamentDecorator.setTournament(null);
|
||||
TournamentListController controller = (TournamentListController) setCenterOfBorderPane(pane, getClass().getResource("tournamentList/tournamentList.fxml"), factoryDecorator);
|
||||
}
|
||||
|
@ -79,6 +82,8 @@ public class Factory {
|
|||
pane.setCenter(loader.load());
|
||||
controller = loader.getController();
|
||||
controller.setup(tournamentDecorator, fileIO, factoryDecorator, pane);
|
||||
VBox bottom = (VBox) pane.getBottom();
|
||||
resetFooter(pane, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
//TODO handle and logging?
|
||||
|
@ -87,6 +92,43 @@ public class Factory {
|
|||
}
|
||||
|
||||
|
||||
public void printMessageToFooter(BorderPane pane, String msg, boolean error) {
|
||||
VBox bottom = (VBox) pane.getBottom();
|
||||
Label label = new Label();
|
||||
VBox innerVbox;
|
||||
label.setText(msg);
|
||||
|
||||
if (error) {
|
||||
innerVbox = (VBox) bottom.getChildren().get(0);
|
||||
resetFooter(pane, true);
|
||||
label.setTextFill(Color.RED);
|
||||
label.setFont(new Font(20));
|
||||
innerVbox.setBorder(new Border(new BorderStroke(Color.valueOf("#FF0000"), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
|
||||
innerVbox.getChildren().add(label);
|
||||
|
||||
} else {
|
||||
innerVbox = (VBox) bottom.getChildren().get(1);
|
||||
resetFooter(pane,false);
|
||||
label.setTextFill(Color.GREEN);
|
||||
label.setFont(new Font(10));
|
||||
label.setPadding(new Insets(0,10,0,0));
|
||||
innerVbox.getChildren().add(label);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void resetFooter(BorderPane pane,boolean error) {
|
||||
VBox bottom = (VBox) pane.getBottom();
|
||||
VBox vBox;
|
||||
if (error) {
|
||||
vBox = (VBox) bottom.getChildren().get(0);
|
||||
} else {
|
||||
vBox = (VBox) bottom.getChildren().get(1);
|
||||
}
|
||||
vBox.getChildren().clear();
|
||||
vBox.setBorder(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.Pane;
|
||||
|
@ -158,6 +157,13 @@ public class FactoryDecorator implements IsObservable{
|
|||
return factory.loadGameView(vBox ,gameDecorator, this);
|
||||
}
|
||||
|
||||
public void printMessageToFooter(String msg, boolean error) {
|
||||
factory.printMessageToFooter((BorderPane) pane,msg,error);
|
||||
}
|
||||
|
||||
public void clearMessage(boolean error){
|
||||
factory.resetFooter((BorderPane) pane, error);
|
||||
}
|
||||
|
||||
public void informListener() {
|
||||
for(IsObserver observer : listener) {
|
||||
|
|
|
@ -2,8 +2,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
|
|||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package ch.zhaw.projekt2.turnierverwaltung;
|
||||
|
||||
import javafx.application.Platform;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -11,6 +14,7 @@ public class TournamentDecorator implements IsObservable{
|
|||
private FileIO fileIO;
|
||||
private List<IsObserver> listener = new ArrayList<>();
|
||||
private ExecutorService executorService;
|
||||
private FactoryDecorator factoryDecorator;
|
||||
|
||||
public TournamentDecorator(FileIO fileIO){
|
||||
setFileIO(fileIO);
|
||||
|
@ -26,6 +30,10 @@ public class TournamentDecorator implements IsObservable{
|
|||
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||
}
|
||||
|
||||
public void setFactoryDecorator(FactoryDecorator factoryDecorator) {
|
||||
this.factoryDecorator = factoryDecorator;
|
||||
}
|
||||
|
||||
public void setFileIO(FileIO fileIO) {
|
||||
this.fileIO = fileIO;
|
||||
}
|
||||
|
@ -51,79 +59,113 @@ public class TournamentDecorator implements IsObservable{
|
|||
|
||||
public void saveTournament(){
|
||||
executorService.execute(new saveTask());
|
||||
factoryDecorator.clearMessage(false);
|
||||
factoryDecorator.printMessageToFooter("Zuletzt gespeichert: " + new Date().toString(),false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void createTournament(String name, Tournament.Type type){
|
||||
if(fileIO.tournamentExists(name)){
|
||||
System.out.println("Tournament with same name exists already.");
|
||||
return; //TODO handle and logging
|
||||
}
|
||||
|
||||
try {
|
||||
if(fileIO.tournamentExists(name)){
|
||||
//TODO:Logger
|
||||
factoryDecorator.printMessageToFooter("Turniername existiert bereits",true);
|
||||
return;
|
||||
}
|
||||
Tournament tournament = new Tournament(name, type);
|
||||
fileIO.saveTournament(tournament);
|
||||
factoryDecorator.clearMessage(true);
|
||||
informListener();
|
||||
} catch (InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
e.printStackTrace();
|
||||
//TODO: Logger
|
||||
factoryDecorator.printMessageToFooter("Invalider Turniername",true);
|
||||
} catch (Tournament.InvalidTypeException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
e.printStackTrace();
|
||||
//TODO: Logger
|
||||
factoryDecorator.printMessageToFooter("Turniermodus nicht möglich",true);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
e.printStackTrace();
|
||||
//TODO: Logger
|
||||
factoryDecorator.printMessageToFooter("Fehler bei Dateizugriff",true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteTournament(FileIO.TournamentFile tournamentFile){
|
||||
try {
|
||||
fileIO.deleteTournament(tournamentFile);
|
||||
factoryDecorator.clearMessage(true);
|
||||
informListener();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Fehler bei Dateizugriff",true);
|
||||
}
|
||||
}
|
||||
|
||||
public void createNewGameSchedule() throws Tournament.NumberOfParticipantInvalidException {
|
||||
tournament.createGameSchedule();
|
||||
public void createNewGameSchedule() {
|
||||
//TODO: logging
|
||||
try {
|
||||
tournament.createGameSchedule();
|
||||
factoryDecorator.clearMessage(true);
|
||||
} catch (Tournament.NumberOfParticipantInvalidException e) {
|
||||
e.printStackTrace();
|
||||
factoryDecorator.printMessageToFooter("Anzahl Teilnehmer nicht vielfaches von 2",true);
|
||||
}
|
||||
informListener();
|
||||
}
|
||||
|
||||
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
|
||||
try {
|
||||
tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
|
||||
factoryDecorator.clearMessage(true);
|
||||
informListener();
|
||||
} catch (InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Invalider Teilnehmername",true);
|
||||
} catch (Person.InvalidPhoneNumberException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Invalide Telefonnummer",true);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteParticipant(Participant participant){
|
||||
try {
|
||||
tournament.removeParticipant(participant);
|
||||
factoryDecorator.clearMessage(true);
|
||||
informListener();
|
||||
} catch (Tournament.ParticipantNotExistsException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Teilnehmer existiert nicht",true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void savePlace(String name){
|
||||
try {
|
||||
tournament.addPlace(new Place(name));
|
||||
factoryDecorator.clearMessage(true);
|
||||
informListener();
|
||||
} catch (Tournament.PlaceExistsException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Ort existiert bereits",true);
|
||||
|
||||
} catch (InvalidNameException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Invalider Ortsname",true);
|
||||
}
|
||||
}
|
||||
|
||||
public void deletePlace(Place place){
|
||||
try {
|
||||
tournament.removePlace(place);
|
||||
factoryDecorator.clearMessage(true);
|
||||
informListener();
|
||||
} catch (Tournament.PlaceNotExistsException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
factoryDecorator.printMessageToFooter("Ort existiert nicht",true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +183,10 @@ public class TournamentDecorator implements IsObservable{
|
|||
try {
|
||||
fileIO.saveTournament(tournament);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace(); //TODO handle and logging
|
||||
e.printStackTrace();
|
||||
Platform.runLater(() -> {
|
||||
factoryDecorator.printMessageToFooter("Datenzugriff nicht moeglich",true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,23 +8,21 @@ import javafx.application.Application;
|
|||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class MainWindow extends Application {
|
||||
private FileIO fileIO = new FileIO(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds");
|
||||
private FactoryDecorator factoryDecorator;
|
||||
private TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO);
|
||||
private Factory factory = new Factory(fileIO, tournamentDecorator); //TODO make it private!
|
||||
private FactoryDecorator factoryDecorator;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws Exception {
|
||||
|
||||
BorderPane pane = factory.loadMainWindow();
|
||||
factoryDecorator = new FactoryDecorator(fileIO, factory, pane);
|
||||
tournamentDecorator.setFactoryDecorator(factoryDecorator);
|
||||
factoryDecorator.openTournamentList();
|
||||
|
||||
|
||||
|
|
|
@ -30,12 +30,7 @@ public class GameScheduleController extends FXController {
|
|||
|
||||
@FXML
|
||||
void createNewSchedule(ActionEvent event) {
|
||||
try {
|
||||
getTournamentDecorator().createNewGameSchedule();
|
||||
} catch (Tournament.NumberOfParticipantInvalidException e) {
|
||||
//TODO Method in FactoryDecorater to show msg
|
||||
e.printStackTrace();
|
||||
}
|
||||
getTournamentDecorator().createNewGameSchedule();
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
|
|
@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList;
|
|||
|
||||
import ch.zhaw.projekt2.turnierverwaltung.FXController;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.FileIO;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.InvalidNameException;
|
||||
import ch.zhaw.projekt2.turnierverwaltung.Tournament;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.MainWindowController">
|
||||
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.zhaw.projekt2.turnierverwaltung.main.MainWindowController">
|
||||
<top>
|
||||
<VBox alignment="TOP_CENTER" prefHeight="86.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
|
@ -34,4 +34,12 @@
|
|||
</children>
|
||||
</VBox>
|
||||
</top>
|
||||
<bottom>
|
||||
<VBox prefHeight="49.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||
<children>
|
||||
<VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" />
|
||||
<VBox alignment="CENTER_RIGHT" prefHeight="200.0" prefWidth="100.0" />
|
||||
</children>
|
||||
</VBox>
|
||||
</bottom>
|
||||
</BorderPane>
|
||||
|
|
Loading…
Reference in New Issue