Skip to content
Snippets Groups Projects
Commit 6d28c76b authored by Carl Gützkow's avatar Carl Gützkow :computer:
Browse files

Merge branch 'fix/change-scene' into 'main'

fix(main...client): make stage static field and changescene

Closes #99

See merge request carljgu/tournament-service!67
parents bec5feaf a140d2d7
No related branches found
No related tags found
No related merge requests found
......@@ -13,18 +13,20 @@ import java.io.IOException;
* Class with the 'main' method
*
* @author Carl Gützkow, Nicolai H. Brand
* @version 0.2
* @version 0.3
*/
public class App extends Application {
private static final int DEFAULT_WIDTH = 1280;
private static final int DEFAULT_HEIGHT = 720;
private static Stage stage;
private static Model model;
@Override
public void start(Stage stage) throws IOException {
public void start(Stage startStage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getClassLoader().getResource("home.fxml"));
Scene scene = new Scene(fxmlLoader.load(), DEFAULT_WIDTH, DEFAULT_HEIGHT);
stage = startStage;
stage.setMinWidth(DEFAULT_WIDTH);
stage.setMinHeight(DEFAULT_HEIGHT);
......@@ -49,4 +51,8 @@ public class App extends Application {
public static int getDefaultHeight() {
return DEFAULT_HEIGHT;
}
public static Stage getStage() {
return stage;
}
}
......@@ -34,19 +34,18 @@ public class ViewUtil {
/**
* Change scene.
* Static method that can be called by the respective controllers.
* Uses the stage in App to change the scene
*
* @param fileName the file name
* @param event the event
*/
public static void changeScene(String fileName, ActionEvent event) {
stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
public static void changeScene(String fileName) {
FXMLLoader fxmlLoader = new FXMLLoader(HomeController.class.getClassLoader().getResource(fileName + ".fxml"));
try {
scene = new Scene(fxmlLoader.load(), getDefaultWidth(), getDefaultHeight());
} catch (IOException e) {
giveError(e.getCause().toString());
}
stage.setScene(scene);
App.getStage().setScene(scene);
}
/**
......
......@@ -39,28 +39,22 @@ public class CreateCupController implements Initializable {
/**
* Cancel creation of a cup and returns to the home page
*
* @param event - ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void cancelCreation(ActionEvent event) {
changeScene("home", event);
void cancelCreation() {
changeScene("home");
}
/**
* Create cup. Changes page to the cup overview
* Any exception that is thrown is handled by
* showing an alert to the user.
*
* @param event - ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void onCreateCup(ActionEvent event) {
void onCreateCup() {
boolean result = createCup(cupLocationField, startDateField, startTimeField, endDateField, endTimeField);
if (result) {
changeScene("cup-overview", event);
changeScene("cup-overview");
}
}
......
......@@ -31,27 +31,21 @@ public class CreateDivisionController implements Initializable {
/**
* Changes back to the cup overview scene
* without changing anything else.
*
* @param event ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void cancelCreation(ActionEvent event) {
changeScene("cup-overview", event);
void cancelCreation() {
changeScene("cup-overview");
}
/**
* Calls the model class to create a division
* from the combo box and spinner.
* If that succeeds, it will change scene.
*
* @param event ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void onCreateDivision(ActionEvent event) {
void onCreateDivision() {
boolean divisionCreated = createDivision(sexGroupBox, ageGroupSpinner);
if (divisionCreated) changeScene("division-overview", event);
if (divisionCreated) changeScene("division-overview");
}
/**
......
......@@ -30,24 +30,20 @@ public class CreateTeamController {
/**
* Cancel creation.
*
* @param event the event
*/
@FXML
void cancelCreation(ActionEvent event) {
changeScene("division-overview", event);
changeScene("division-overview");
}
/**
* On create team.
*
* @param event the event
*/
@FXML
void onCreateTeam(ActionEvent event) {
void onCreateTeam() {
boolean isTeamCreated = createTeam(teamNameField);
if (isTeamCreated)
changeScene("division-overview", event);
changeScene("division-overview");
// TODO if not create do we send an alert?
}
......
......@@ -4,7 +4,6 @@ import static edu.ntnu.idatt1002.k1g4.client.ViewUtil.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;
......@@ -34,36 +33,27 @@ public class CupOverviewController implements Initializable {
/**
* Add division. Changes page to the page for
* creating a division.
*
* @param event - ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void addDivision(ActionEvent event) {
changeScene("create-division", event);
void addDivision() {
changeScene("create-division");
}
/**
* Changes page to page for crating a match
*
* @param event - ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void createMatch(ActionEvent event) {
void createMatch() {
}
/**
* Changes page to the home-page
*
* @param event - ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void backToCups(ActionEvent event) {
changeScene("home", event);
void backToCups() {
changeScene("home");
}
/**
......
......@@ -40,51 +40,39 @@ public class DivisionOverviewController implements Initializable {
/**
* Changes page to page for creating team.
*
* @param event - ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void addTeam(ActionEvent event) {
changeScene("create-team", event);
void addTeam() {
changeScene("create-team");
}
/**
* Changes scene back to the cup
* overview scene without any changes
*
* @param event ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void backToCupOverview(ActionEvent event) {
changeScene("cup-overview", event);
void backToCupOverview() {
changeScene("cup-overview");
}
/**
* Creates a modal such that a match can be created.
* Works with Model to create the object.
*
* @param event ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void createMatch(ActionEvent event) {
void createMatch() {
//TODO: add modal for creating a match
}
/**
* Delete division.
*
* @param event ActionEvent that is derived from the page
* and contains information about an event
*/
@FXML
void deleteDivision(ActionEvent event) {
void deleteDivision() {
// TODO: delete division from current cup
boolean confimation = getConfirmation("Are you sure you want to delete this division?");
if (confimation) {
changeScene("cup-overview", event);
changeScene("cup-overview");
Model.setCurrentDivision(null);
}
}
......
......@@ -74,7 +74,7 @@ public class HomeController implements Initializable {
*/
@FXML
void goToCreateCup(ActionEvent event) {
changeScene("create-cup", event);
changeScene("create-cup");
}
/**
......@@ -107,7 +107,7 @@ public class HomeController implements Initializable {
@FXML
void getCup(ActionEvent event) {
changeScene("cup-overview", event);
changeScene("cup-overview");
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment