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;
/**
*
* Class to load the views from FXML Files and switch between the views.
*/
public class Factory {
private TournamentDecorator tournamentDecorator;
@ -21,16 +21,29 @@ public class Factory {
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) {
this.fileIO = fileIO;
this.tournamentDecorator = tournamentDecorator;
this.languageConfigurator = languageConfigurator;
}
/**
* Setter Method of tournament
* @param tournament the new tournament Object.
*/
public void setTournament(Tournament 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() {
FXMLLoader loader = new FXMLLoader(getClass().getResource("MainWindow.fxml"));
try {
@ -45,6 +58,11 @@ public class Factory {
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){
for(View view : View.values()){
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);
setCenterOfBorderPane(pane, View.tournamentList);
}
//Can be used to Open new Scene in same Stage.
//This way possible to later give object to Controller
public void showParticipantFormular(BorderPane pane, FactoryDecorator factoryDecorator) {
/**
* Method to show the view ParticipantFormular
* @param pane the Pane where the View will be visible
*/
public void showParticipantFormular(BorderPane pane) {
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);
}
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);
}
/**
* 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) {
FXController controller = null;
pane.setCenter(view.getPane());
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) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("gameScheduleView/Game.fxml"));
@ -96,6 +139,12 @@ public class Factory {
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) {
VBox bottom = (VBox) pane.getBottom();
Label label = new Label();
@ -122,9 +171,9 @@ public class Factory {
}
/**
*
* @param pane
* @param error
* Method to remove the messages in the footer.
* @param pane the pane were the footer should be reseted
* @param error true if the error message should be cleared.
*/
public void resetFooter(BorderPane pane,boolean error) {
VBox bottom = (VBox) pane.getBottom();
@ -138,12 +187,13 @@ public class Factory {
vBox.setBorder(null);
}
public LanguageConfigurator getLanguageConfigurator() {
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 {
tournamentList("tournamentList/tournamentList.fxml"),
@ -154,6 +204,10 @@ public class Factory {
private String fxmlFileName;
private Pane pane;
/**
* Constructor of View
* @param fxmlFileName The name of the FXML File to load.
*/
private View(String fxmlFileName) {
this.fxmlFileName = fxmlFileName;
}
@ -162,6 +216,14 @@ public class Factory {
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 {
FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName));
this.pane = loader.load();

View File

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

View File

@ -5,6 +5,7 @@ import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.util.logging.Logger;
/**
@ -27,7 +28,7 @@ public class MainWindow extends Application {
* @param primaryStage to be displayed
*/
@Override
public void start(Stage primaryStage) throws Exception {
public void start(Stage primaryStage) {
logger.fine("Starting up the main window with the primary Stage");
BorderPane pane = factory.loadMainWindow();
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.LanguageConfigurator;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import java.util.logging.Logger;
import java.util.logging.Logger;
/**
* 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 {
private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName());
@FXML
private MenuItem closeBtn;
@ -27,19 +31,20 @@ public class MainWindowController extends FXController {
@FXML
private Menu menuItemLanguage;
private static final Logger logger = Logger.getLogger(MainWindowController.class.getCanonicalName());
/**
* Method changes the language Setting to german
*/
@FXML
void changeLangToGerman(ActionEvent event) {
void changeLangToGerman() {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.GERMAN);
logger.fine("language setting changed to german");
}
@FXML
void changeLangToEnglish(ActionEvent event) {
void changeLangToEnglish() {
getLanguageConfigurator().changeLanguage(LanguageConfigurator.Language.ENGLISH);
logger.fine("language setting changed to english");
}
@ -53,6 +58,9 @@ public class MainWindowController extends FXController {
Platform.exit();
}
/**
* There is no content to load
*/
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(mainTitle);
@ -66,6 +74,5 @@ public class MainWindowController extends FXController {
*/
@Override
public void loadContent() {
}
}

View File

@ -1,5 +1,7 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.FileIO;
import ch.zhaw.projekt2.turnierverwaltung.LanguageConfigurator;
import javafx.scene.control.Alert;
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.
*/
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 {
private ButtonType yesButton;
private ButtonType noButton;

View File

@ -36,6 +36,7 @@ public class GameController extends FXController{
private TextField pointsTeamTwo;
@FXML
private Label locationLabel;
@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.Place;
import ch.zhaw.projekt2.turnierverwaltung.Player;
import ch.zhaw.projekt2.turnierverwaltung.Tournament;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.VBox;
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 {
@ -39,6 +45,10 @@ public class PlacesFormularController extends FXController {
@FXML
private Button saveBtn;
private static final Logger logger = Logger.getLogger(PlacesFormularController.class.getCanonicalName());
@Override
public void shareGUIElementWithLanguageConfigurator() {
getLanguageConfigurator().recieveLabel(placeListTitle);
@ -50,37 +60,61 @@ public class PlacesFormularController extends FXController {
}
/**
* Selects an item (place) from the List view
*/
@FXML
void changedSelection(MouseEvent event){
void changedSelection() {
Place place = placeListView.getSelectionModel().getSelectedItems().get(0);
logger.finer("Selected new Place from list: " + place);
placeNameTextField.setText(place.getName());
}
/**
* Saves the name of a new place into the list and clears the form
*/
@FXML
void savePlace(ActionEvent event) {
void savePlace() {
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();
}
/**
* Method deletes the currently selected place from the list.
*/
@FXML
void delete(ActionEvent event) {
void delete() {
Place place = placeListView.getSelectionModel().getSelectedItems().get(0);
logger.fine("Deleting " + place + "from place list");
getTournamentDecorator().deletePlace(place);
}
/**
* Closes the current Place view, going back to previous view
*/
@FXML
void close(ActionEvent event) {
void close() {
logger.fine("Closing place form");
getFactoryDecorator().openScheduleView();
}
/**
* Loads the already saved places and displays them on the places list.
*/
@Override
public void loadContent() {
logger.fine("Getting the Saved tournaments into the Places list");
Tournament tournament = getTournamentDecorator().getTournament();
if(tournament != null){
if (tournament != null) {
placeListView.setItems(tournament.getPlaces());
} else {
placeListView.getItems().clear();