Develop footer #35

Merged
fassband merged 3 commits from develop_footer into main 2022-05-12 22:09:40 +02:00
8 changed files with 119 additions and 32 deletions
Showing only changes of commit 298d61eeca - Show all commits

View File

@ -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.gameScheduleView.GameDecorator;
import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController; import ch.zhaw.projekt2.turnierverwaltung.main.tournamentList.TournamentListController;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.layout.BorderPane; import javafx.scene.control.Label;
import javafx.scene.layout.VBox; import javafx.scene.control.TextArea;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
@ -79,6 +82,8 @@ public class Factory {
pane.setCenter(loader.load()); pane.setCenter(loader.load());
controller = loader.getController(); controller = loader.getController();
controller.setup(tournamentDecorator, fileIO, factoryDecorator, pane); controller.setup(tournamentDecorator, fileIO, factoryDecorator, pane);
VBox bottom = (VBox) pane.getBottom();
resetFooter(pane, true);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
//TODO handle and logging? //TODO handle and logging?
@ -87,6 +92,42 @@ 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));
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);
}
}

View File

@ -3,7 +3,6 @@ package ch.zhaw.projekt2.turnierverwaltung;
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController; import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameController;
import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator; import ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView.GameDecorator;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox; import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
@ -158,6 +157,13 @@ public class FactoryDecorator implements IsObservable{
return factory.loadGameView(vBox ,gameDecorator, this); 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() { public void informListener() {
for(IsObserver observer : listener) { for(IsObserver observer : listener) {

View File

@ -2,8 +2,6 @@ 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.*; import java.util.*;
@ -29,7 +27,7 @@ public class Tournament implements Serializable {
gameList = new ArrayList<>(); gameList = new ArrayList<>();
} }
public void saveParticipant(Participant newParticipant) throws ParticipantExistsException { public void saveParticipant(Participant newParticipant) {
for(Participant participant: participants){ for(Participant participant: participants){
if(participant.equals(newParticipant)){ if(participant.equals(newParticipant)){
participant.change(newParticipant); participant.change(newParticipant);

View File

@ -1,5 +1,7 @@
package ch.zhaw.projekt2.turnierverwaltung; package ch.zhaw.projekt2.turnierverwaltung;
import javafx.application.Platform;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -11,6 +13,7 @@ public class TournamentDecorator implements IsObservable{
private FileIO fileIO; private FileIO fileIO;
private List<IsObserver> listener = new ArrayList<>(); private List<IsObserver> listener = new ArrayList<>();
private ExecutorService executorService; private ExecutorService executorService;
private FactoryDecorator factoryDecorator;
public TournamentDecorator(FileIO fileIO){ public TournamentDecorator(FileIO fileIO){
setFileIO(fileIO); setFileIO(fileIO);
@ -26,6 +29,10 @@ public class TournamentDecorator implements IsObservable{
executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
} }
public void setFactoryDecorator(FactoryDecorator factoryDecorator) {
this.factoryDecorator = factoryDecorator;
}
public void setFileIO(FileIO fileIO) { public void setFileIO(FileIO fileIO) {
this.fileIO = fileIO; this.fileIO = fileIO;
} }
@ -56,76 +63,106 @@ public class TournamentDecorator implements IsObservable{
public void createTournament(String name, Tournament.Type type){ 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 { try {
if(fileIO.tournamentExists(name)){
//TODO:Logger
factoryDecorator.printMessageToFooter("Turniername existiert bereits",true);
return;
}
Tournament tournament = new Tournament(name, type); Tournament tournament = new Tournament(name, type);
fileIO.saveTournament(tournament); fileIO.saveTournament(tournament);
factoryDecorator.clearMessage(true);
informListener(); informListener();
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace();
//TODO: Logger
factoryDecorator.printMessageToFooter("Invalider Turniername",true);
} catch (Tournament.InvalidTypeException e) { } catch (Tournament.InvalidTypeException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace();
//TODO: Logger
factoryDecorator.printMessageToFooter("Turniermodus nicht möglich",true);
} catch (IOException e) { } 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){ public void deleteTournament(FileIO.TournamentFile tournamentFile){
try { try {
fileIO.deleteTournament(tournamentFile); fileIO.deleteTournament(tournamentFile);
factoryDecorator.clearMessage(true);
informListener(); informListener();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Fehler bei Dateizugriff",true);
} }
} }
public void createNewGameSchedule() throws Tournament.NumberOfParticipantInvalidException { public void createNewGameSchedule() {
//TODO: logging
try {
tournament.createGameSchedule(); tournament.createGameSchedule();
factoryDecorator.clearMessage(true);
} catch (Tournament.NumberOfParticipantInvalidException e) {
e.printStackTrace();
factoryDecorator.printMessageToFooter("Anzahl Teilnehmer nicht vielfaches von 2",true);
}
informListener(); informListener();
} }
public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){ public void savePlayer(String firstName, String name, String phoneNumber, String dateOfBirth){
try { try {
tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth)); tournament.saveParticipant(new Player(firstName, name, phoneNumber, dateOfBirth));
factoryDecorator.clearMessage(true);
informListener(); informListener();
} catch (Tournament.ParticipantExistsException e) {
e.printStackTrace(); //TODO handle and logging
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalider Teilnehmername",true);
} catch (Person.InvalidPhoneNumberException e) { } catch (Person.InvalidPhoneNumberException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalide Telefonnummer",true);
} }
} }
public void deleteParticipant(Participant participant){ public void deleteParticipant(Participant participant){
try { try {
tournament.removeParticipant(participant); tournament.removeParticipant(participant);
factoryDecorator.clearMessage(true);
informListener(); informListener();
} catch (Tournament.ParticipantNotExistsException e) { } catch (Tournament.ParticipantNotExistsException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Teilnehmer existiert nicht",true);
} }
} }
public void savePlace(String name){ public void savePlace(String name){
try { try {
tournament.addPlace(new Place(name)); tournament.addPlace(new Place(name));
factoryDecorator.clearMessage(true);
informListener(); informListener();
} catch (Tournament.PlaceExistsException e) { } catch (Tournament.PlaceExistsException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Ort existiert bereits",true);
} catch (InvalidNameException e) { } catch (InvalidNameException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Invalider Ortsname",true);
} }
} }
public void deletePlace(Place place){ public void deletePlace(Place place){
try { try {
tournament.removePlace(place); tournament.removePlace(place);
factoryDecorator.clearMessage(true);
informListener(); informListener();
} catch (Tournament.PlaceNotExistsException e) { } catch (Tournament.PlaceNotExistsException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace(); //TODO handle and logging
factoryDecorator.printMessageToFooter("Ort existiert nicht",true);
} }
} }
@ -143,7 +180,10 @@ public class TournamentDecorator implements IsObservable{
try { try {
fileIO.saveTournament(tournament); fileIO.saveTournament(tournament);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); //TODO handle and logging e.printStackTrace();
Platform.runLater(() -> {
factoryDecorator.printMessageToFooter("Datenzugriff nicht moeglich",true);
});
} }
} }
} }

View File

@ -8,23 +8,21 @@ import javafx.application.Application;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.awt.*;
import java.io.IOException;
public class MainWindow extends Application { public class MainWindow extends Application {
private FileIO fileIO = new FileIO(System.getProperty("user.dir") + System.getProperty("file.separator") + "tournierverwaltung_angrynerds"); 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 TournamentDecorator tournamentDecorator = new TournamentDecorator(fileIO);
private Factory factory = new Factory(fileIO, tournamentDecorator); //TODO make it private! private Factory factory = new Factory(fileIO, tournamentDecorator); //TODO make it private!
private FactoryDecorator factoryDecorator;
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
BorderPane pane = factory.loadMainWindow(); BorderPane pane = factory.loadMainWindow();
factoryDecorator = new FactoryDecorator(fileIO, factory, pane); factoryDecorator = new FactoryDecorator(fileIO, factory, pane);
tournamentDecorator.setFactoryDecorator(factoryDecorator);
factoryDecorator.openTournamentList(); factoryDecorator.openTournamentList();

View File

@ -30,12 +30,7 @@ public class GameScheduleController extends FXController {
@FXML @FXML
void createNewSchedule(ActionEvent event) { void createNewSchedule(ActionEvent event) {
try {
getTournamentDecorator().createNewGameSchedule(); getTournamentDecorator().createNewGameSchedule();
} catch (Tournament.NumberOfParticipantInvalidException e) {
//TODO Method in FactoryDecorater to show msg
e.printStackTrace();
}
} }
@FXML @FXML

View File

@ -2,6 +2,7 @@ package ch.zhaw.projekt2.turnierverwaltung.main.tournamentList;
import ch.zhaw.projekt2.turnierverwaltung.FXController; import ch.zhaw.projekt2.turnierverwaltung.FXController;
import ch.zhaw.projekt2.turnierverwaltung.FileIO; import ch.zhaw.projekt2.turnierverwaltung.FileIO;
import ch.zhaw.projekt2.turnierverwaltung.InvalidNameException;
import ch.zhaw.projekt2.turnierverwaltung.Tournament; import ch.zhaw.projekt2.turnierverwaltung.Tournament;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;

View File

@ -8,7 +8,7 @@
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?> <?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> <top>
<VBox alignment="TOP_CENTER" prefHeight="86.0" prefWidth="600.0" BorderPane.alignment="CENTER"> <VBox alignment="TOP_CENTER" prefHeight="86.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children> <children>
@ -34,4 +34,12 @@
</children> </children>
</VBox> </VBox>
</top> </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> </BorderPane>