Merge branch 'main' into testing

This commit is contained in:
Roman Schenk 2022-05-13 22:59:35 +02:00 committed by GitHub Enterprise
commit 4392fabc38
8 changed files with 154 additions and 33 deletions

BIN
ClassDiagram.png Normal file

Binary file not shown.

View File

@ -12,7 +12,7 @@ import java.io.IOException;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
* * Class to load the views from FXML Files and switch between the views.
*/ */
public class Factory { public class Factory {
private TournamentDecorator tournamentDecorator; private TournamentDecorator tournamentDecorator;
@ -21,16 +21,29 @@ public class Factory {
private static final Logger logger = Logger.getLogger(Factory.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(Factory.class.getCanonicalName());
/**
* Contructor to create Factory instance.
* @param fileIO the fileIO instance which saves and reads the tournament from files.
* @param tournamentDecorator the touramanetDecorator class to access the tournament.
*/
public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator, LanguageConfigurator languageConfigurator) { public Factory(FileIO fileIO, TournamentDecorator tournamentDecorator, LanguageConfigurator languageConfigurator) {
this.fileIO = fileIO; this.fileIO = fileIO;
this.tournamentDecorator = tournamentDecorator; this.tournamentDecorator = tournamentDecorator;
this.languageConfigurator = languageConfigurator; this.languageConfigurator = languageConfigurator;
} }
/**
* Setter Method of tournament
* @param tournament the new tournament Object.
*/
public void setTournament(Tournament tournament) { public void setTournament(Tournament tournament) {
this.tournamentDecorator.setTournament(tournament); this.tournamentDecorator.setTournament(tournament);
} }
/**
* Method to load the main Window (without the content in the center)
* @return the boarder Pane which is loaded.
*/
public BorderPane loadMainWindow() { public BorderPane loadMainWindow() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
try { try {
@ -45,6 +58,11 @@ public class Factory {
return null; return null;
} }
/**
* Class which loads all views of Enum View
* @param factoryDecorator the FactoryDecorator which is used to setup the controller.
* @param pane the pane where the loaded view will be visible
*/
public void loadAllViews(FactoryDecorator factoryDecorator, BorderPane pane){ public void loadAllViews(FactoryDecorator factoryDecorator, BorderPane pane){
for(View view : View.values()){ for(View view : View.values()){
try { try {
@ -56,32 +74,57 @@ public class Factory {
} }
} }
public void showTournamentList(BorderPane pane, FactoryDecorator factoryDecorator) { /**
* Method to show the view TournamentList
* @param pane the Pane where the View will be visible
*/
public void showTournamentList(BorderPane pane) {
tournamentDecorator.setTournament(null); tournamentDecorator.setTournament(null);
setCenterOfBorderPane(pane, View.tournamentList); setCenterOfBorderPane(pane, View.tournamentList);
} }
//Can be used to Open new Scene in same Stage. /**
//This way possible to later give object to Controller * Method to show the view ParticipantFormular
public void showParticipantFormular(BorderPane pane, FactoryDecorator factoryDecorator) { * @param pane the Pane where the View will be visible
*/
public void showParticipantFormular(BorderPane pane) {
setCenterOfBorderPane(pane, View.participantFormular); setCenterOfBorderPane(pane, View.participantFormular);
} }
public void showPlacesFormular(BorderPane pane, FactoryDecorator factoryDecorator) { /**
* Method to show the view PlacesFormular
* @param pane the Pane where the View will be visible
*/
public void showPlacesFormular(BorderPane pane) {
setCenterOfBorderPane(pane, View.placesFormular); setCenterOfBorderPane(pane, View.placesFormular);
} }
public void showGameScheduler(BorderPane pane, FactoryDecorator factoryDecorator) { /**
* Method to show the view GameScheduler
* @param pane the Pane where the View will be visible
*/
public void showGameScheduler(BorderPane pane) {
setCenterOfBorderPane(pane, View.gameScheduler); setCenterOfBorderPane(pane, View.gameScheduler);
} }
/**
* Method to change the view in the center of the boarder pane in the mainWindow
* @param pane the Pane where the View will be visible
* @param view the view which should be visible
*/
private void setCenterOfBorderPane(BorderPane pane, View view) { private void setCenterOfBorderPane(BorderPane pane, View view) {
FXController controller = null; FXController controller = null;
pane.setCenter(view.getPane()); pane.setCenter(view.getPane());
resetFooter(pane, true); resetFooter(pane, true);
} }
/**
* Method to load a Game View
* @param box the box where the game view should be added.
* @param gameDecorator the gameDecorator instance of the game.
* @param factoryDecorator the factoryDecorator instance.
* @return the controller of the GameView
*/
public GameController loadGameView(VBox box, GameDecorator gameDecorator, FactoryDecorator factoryDecorator) { public GameController loadGameView(VBox box, GameDecorator gameDecorator, FactoryDecorator factoryDecorator) {
try { try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
@ -96,6 +139,12 @@ public class Factory {
return null; return null;
} }
/**
* Method to print information for the user to the footer of mainwindow.
* @param pane the pane where the footer should be shown.
* @param msg the text to show.
* @param error true if it's a error message.
*/
public void printMessageToFooter(BorderPane pane, String msg, boolean error) { public void printMessageToFooter(BorderPane pane, String msg, boolean error) {
VBox bottom = (VBox) pane.getBottom(); VBox bottom = (VBox) pane.getBottom();
Label label = new Label(); Label label = new Label();
@ -122,9 +171,9 @@ public class Factory {
} }
/** /**
* * Method to remove the messages in the footer.
* @param pane * @param pane the pane were the footer should be reseted
* @param error * @param error true if the error message should be cleared.
*/ */
public void resetFooter(BorderPane pane,boolean error) { public void resetFooter(BorderPane pane,boolean error) {
VBox bottom = (VBox) pane.getBottom(); VBox bottom = (VBox) pane.getBottom();
@ -138,12 +187,13 @@ public class Factory {
vBox.setBorder(null); vBox.setBorder(null);
} }
public LanguageConfigurator getLanguageConfigurator() { public LanguageConfigurator getLanguageConfigurator() {
return languageConfigurator; return languageConfigurator;
} }
/** /**
* Enum for keeping the different fxml form views * Enum of all views which can be set to the center of the mainwindow.
*/ */
public enum View { public enum View {
tournamentList("tournamentList/tournamentList.fxml"), tournamentList("tournamentList/tournamentList.fxml"),
@ -154,6 +204,10 @@ public class Factory {
private String fxmlFileName; private String fxmlFileName;
private Pane pane; private Pane pane;
/**
* Constructor of View
* @param fxmlFileName The name of the FXML File to load.
*/
private View(String fxmlFileName) { private View(String fxmlFileName) {
this.fxmlFileName = fxmlFileName; this.fxmlFileName = fxmlFileName;
} }
@ -162,6 +216,14 @@ public class Factory {
return pane; return pane;
} }
/**
* Method to laod the view
* @param tournamentDecorator the tournamentDecorator object which will be passed to the controller.
* @param fileIO the fileIO object which will be passed to the controller.
* @param factoryDecorator the factoryDecorator object which will be passed to the controller.
* @param borderPane the borderPane object which will be passed to the controller.
* @throws IOException if the fxml file is not found or can not be loaded correctly.
*/
public void loadView(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, BorderPane borderPane) throws IOException { public void loadView(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, BorderPane borderPane) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName)); FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName));
this.pane = loader.load(); this.pane = loader.load();

View File

@ -106,6 +106,8 @@ public class FactoryDecorator implements IsObservable {
logger.fine("Opened tournament file successfully"); logger.fine("Opened tournament file successfully");
} catch (IOException | ClassNotFoundException e) { } catch (IOException | ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
logger.warning("Failed to open tournament file Error: " + e);
printMessageToFooter("Fehler beim lesen der Datei.", true);
String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException"); String msg = factory.getLanguageConfigurator().getSelectedLanguage("IOException");
logger.warning("Failed to open tournament file Error: " + e); logger.warning("Failed to open tournament file Error: " + e);
printMessageToFooter(msg, true); printMessageToFooter(msg, true);
@ -118,6 +120,7 @@ public class FactoryDecorator implements IsObservable {
public void openTournamentList() { public void openTournamentList() {
logger.fine("Showing TournamentList view"); logger.fine("Showing TournamentList view");
factory.showTournamentList((BorderPane) pane, this); factory.showTournamentList((BorderPane) pane, this);
informListener(); informListener();
} }
@ -126,7 +129,7 @@ public class FactoryDecorator implements IsObservable {
*/ */
public void openParticipantForm() { public void openParticipantForm() {
logger.fine("Showing participant form view"); logger.fine("Showing participant form view");
factory.showParticipantFormular((BorderPane) pane, this); factory.showParticipantFormular((BorderPane) pane);
informListener(); informListener();
} }
@ -135,12 +138,12 @@ public class FactoryDecorator implements IsObservable {
*/ */
public void openPlacesForm() { public void openPlacesForm() {
logger.fine("Showing places form view"); logger.fine("Showing places form view");
factory.showPlacesFormular((BorderPane) pane, this); factory.showPlacesFormular((BorderPane) pane);
informListener(); informListener();
} }
public void openScheduleView() { public void openScheduleView() {
factory.showGameScheduler((BorderPane) pane, this); factory.showGameScheduler((BorderPane) pane);
informListener(); informListener();
} }
@ -230,6 +233,7 @@ public class FactoryDecorator implements IsObservable {
* @return * @return
*/ */
public GameController openGameView(VBox vBox, GameDecorator gameDecorator) { public GameController openGameView(VBox vBox, GameDecorator gameDecorator) {
return factory.loadGameView(vBox, gameDecorator, this); return factory.loadGameView(vBox, gameDecorator, this);
} }
@ -253,6 +257,9 @@ public class FactoryDecorator implements IsObservable {
factory.resetFooter((BorderPane) pane, error); factory.resetFooter((BorderPane) pane, error);
} }
public LanguageConfigurator getLanguageConfigurator() { public LanguageConfigurator getLanguageConfigurator() {
return factory.getLanguageConfigurator(); return factory.getLanguageConfigurator();
} }
@ -261,6 +268,7 @@ public class FactoryDecorator implements IsObservable {
* Method that informs all listeners of an update. * Method that informs all listeners of an update.
*/ */
public void informListener() { public void informListener() {
for (IsObserver observer : listener) { for (IsObserver observer : listener) {
observer.update(); observer.update();
} }

View File

@ -5,6 +5,7 @@ import javafx.application.Application;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import java.util.logging.Logger; import java.util.logging.Logger;
/** /**
@ -27,7 +28,7 @@ public class MainWindow extends Application {
* @param primaryStage to be displayed * @param primaryStage to be displayed
*/ */
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) {
logger.fine("Starting up the main window with the primary Stage"); logger.fine("Starting up the main window with the primary Stage");
BorderPane pane = factory.loadMainWindow(); BorderPane pane = factory.loadMainWindow();
factoryDecorator = new FactoryDecorator(fileIO, factory, pane); factoryDecorator = new FactoryDecorator(fileIO, factory, pane);

View File

@ -3,13 +3,14 @@ package ch.zhaw.projekt2.turnierverwaltung.main;
import ch.zhaw.projekt2.turnierverwaltung.FXController; import ch.zhaw.projekt2.turnierverwaltung.FXController;
import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator; import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.Menu; import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem; import javafx.scene.control.MenuItem;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.logging.Logger;
/** /**
* Main WindowController Class in charge of the Controller Functions of it * Main WindowController Class in charge of the Controller Functions of it
@ -18,6 +19,9 @@ import java.util.logging.Logger;
*/ */
public class MainWindowController extends FXController { public class MainWindowController extends FXController {
private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName());
@FXML @FXML
private MenuItem closeBtn; private MenuItem closeBtn;
@ -27,19 +31,20 @@ public class MainWindowController extends FXController {
@FXML @FXML
private Menu menuItemLanguage; private Menu menuItemLanguage;
private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName()); private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName());
/**
* Method changes the language Setting to german * Method changes the language Setting to german
*/ */
@FXML @FXML
void changeLangToGerman(ActionEvent event) { void changeLangToGerman() {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN); getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN);
logger.fine("language setting changed to german"); logger.fine("language setting changed to german");
} }
@FXML @FXML
void changeLangToEnglish(ActionEvent event) { void changeLangToEnglish() {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH); getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH);
logger.fine("language setting changed to english"); logger.fine("language setting changed to english");
} }
@ -53,6 +58,9 @@ public class MainWindowController extends FXController {
Platform.exit(); Platform.exit();
} }
/**
* There is no content to load
*/
@Override @Override
public void shareGUIElementWithLanguageConfigurator() { public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(mainTitle); getLanguageConfigurator().recieveLabel(mainTitle);
@ -66,6 +74,5 @@ public class MainWindowController extends FXController {
*/ */
@Override @Override
public void loadContent() { public void loadContent() {
} }
} }

View File

@ -1,5 +1,7 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView; package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.FileIO;
import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator; import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar; import javafx.scene.control.ButtonBar;
@ -8,6 +10,12 @@ import javafx.scene.control.ButtonType;
* Class that is used to display the popup window to confirm a sensitive action of the user. * Class that is used to display the popup window to confirm a sensitive action of the user.
*/ */
import java.util.logging.Logger;
/**
* Class that is used to display the popup window to confirm a sensitive action of the user.
*/
public class AlertNewSchedule extends Alert { public class AlertNewSchedule extends Alert {
private ButtonType yesButton; private ButtonType yesButton;
private ButtonType noButton; private ButtonType noButton;

View File

@ -36,6 +36,7 @@ public class GameController extends FXController{
private TextField pointsTeamTwo; private TextField pointsTeamTwo;
@FXML @FXML
private Label locationLabel; private Label locationLabel;
@Override @Override

View File

@ -2,16 +2,22 @@ package ch.zhaw.projekt2.turnierverwaltung.main.placesAddFormular;
import ch.zhaw.projekt2.turnierverwaltung.FXController; import ch.zhaw.projekt2.turnierverwaltung.FXController;
import ch.zhaw.projekt2.turnierverwaltung.Place; import ch.zhaw.projekt2.turnierverwaltung.Place;
import ch.zhaw.projekt2.turnierverwaltung.Player;
import ch.zhaw.projekt2.turnierverwaltung.Tournament; import ch.zhaw.projekt2.turnierverwaltung.Tournament;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import java.util.logging.Logger;
/**
* Controller of the places form, in charge of its functionality.
*/
public class PlacesFormularController extends FXController { public class PlacesFormularController extends FXController {
@ -39,6 +45,10 @@ public class PlacesFormularController extends FXController {
@FXML @FXML
private Button saveBtn; private Button saveBtn;
private static final Logger logger = Logger.getLogger(PlacesFormularController.class.getCanonicalName());
@Override @Override
public void shareGUIElementWithLanguageConfigurator() { public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(placeListTitle); getLanguageConfigurator().recieveLabel(placeListTitle);
@ -50,35 +60,59 @@ public class PlacesFormularController extends FXController {
} }
/**
* Selects an item (place) from the List view
*/
@FXML @FXML
void changedSelection(MouseEvent event){ void changedSelection() {
Place place = placeListView.getSelectionModel().getSelectedItems().get(0); Place place = placeListView.getSelectionModel().getSelectedItems().get(0);
logger.finer("Selected new Place from list: " + place);
placeNameTextField.setText(place.getName()); placeNameTextField.setText(place.getName());
} }
/**
* Saves the name of a new place into the list and clears the form
*/
@FXML @FXML
void savePlace(ActionEvent event) { void savePlace() {
getTournamentDecorator().savePlace(placeNameTextField.getText()); getTournamentDecorator().savePlace(placeNameTextField.getText());
clearFormular(); logger.fine("Saved " + placeNameTextField + " to the list of places");
clearForm();
} }
private void clearFormular() { /**
* Method clears the input field
*/
private void clearForm() {
logger.finer("Clearing input text field");
placeNameTextField.clear(); placeNameTextField.clear();
} }
/**
* Method deletes the currently selected place from the list.
*/
@FXML @FXML
void delete(ActionEvent event) { void delete() {
Place place = placeListView.getSelectionModel().getSelectedItems().get(0); Place place = placeListView.getSelectionModel().getSelectedItems().get(0);
logger.fine("Deleting " + place + "from place list");
getTournamentDecorator().deletePlace(place); getTournamentDecorator().deletePlace(place);
} }
/**
* Closes the current Place view, going back to previous view
*/
@FXML @FXML
void close(ActionEvent event) { void close() {
logger.fine("Closing place form");
getFactoryDecorator().openScheduleView(); getFactoryDecorator().openScheduleView();
} }
/**
* Loads the already saved places and displays them on the places list.
*/
@Override @Override
public void loadContent() { public void loadContent() {
logger.fine("Getting the Saved tournaments into the Places list");
Tournament tournament = getTournamentDecorator().getTournament(); Tournament tournament = getTournamentDecorator().getTournament();
if (tournament != null) { if (tournament != null) {
placeListView.setItems(tournament.getPlaces()); placeListView.setItems(tournament.getPlaces());