Skip to content
Snippets Groups Projects
Commit 0fb4c0f8 authored by Eilert Werner Hansen's avatar Eilert Werner Hansen :spaghetti:
Browse files

Merge branch 'main' into feat/create-match-button

parents 43e6b669 b910bc22
No related branches found
No related tags found
No related merge requests found
......@@ -29,13 +29,13 @@ import java.util.HashMap;
* for how this class relates to the Controllers and ViewUtil.
*
* @author Carl Gützkow, Nicolai H. Brand, Runar Indahl.
* @version 0.4
* @version 0.5
*/
public class Model {
private static ArrayList<Cup> cups = new ArrayList<>();
private static Cup currentCup;
private static Division currentDivision;
private static Cup currentCup = null;
private static Division currentDivision = null;
/**
* Returns the static list of cups
......@@ -91,7 +91,6 @@ public class Model {
currentDivision = newDivision;
}
/**
* Delete division.
*/
......@@ -100,6 +99,10 @@ public class Model {
getCurrentCup().removeDivision(getCurrentDivision());
}
public static void deleteSelectedCup() {
cups.remove(getCurrentCup());
}
/**
* Sets no current division.
*/
......@@ -179,7 +182,6 @@ public class Model {
try {
String divisionCategory = textFieldDivisionCategory.getText();
System.out.println(divisionCategory);
Division division = new Division(divisionCategory);
if (currentCup.addDivision(division))
setCurrentDivision(division);
......
......@@ -11,6 +11,7 @@ import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.TextField;
import javafx.scene.input.MouseButton;
import javafx.scene.text.Text;
import java.net.URL;
......@@ -163,18 +164,10 @@ public class CupOverviewController implements Initializable {
}
/**
* Run when the page is loaded in.
* Fills in listviews for divisions,
* matches and teams.
* Adds a change listener to the division list.
*
* @param url URL - represents a Uniform Resource Locator
* @param resourceBundle ResourceBundle - contains locale-specific objects
* Helper method that initializes javafx fields
* @param currentCup cup
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
Cup currentCup = getCurrentCup();
private void initScene(Cup currentCup) {
cupNameField.setPrefWidth(0);
cupNameField.setText(currentCup.getName());
cupName.setText(currentCup.getName());
......@@ -182,7 +175,12 @@ public class CupOverviewController implements Initializable {
editCupNameButton.setScaleX(1);
updateNameButton.setScaleX(0);
cancelUpdateNameButton.setScaleX(0);
}
/**
* Helper method that initializes javafx fields
*/
private void initLists(Cup currentCup) {
divisionListView.getItems().clear();
matchListView.getItems().clear();
teamListView.getItems().clear();
......@@ -190,11 +188,34 @@ public class CupOverviewController implements Initializable {
currentCup.getDivisions().forEach(n -> divisionListView.getItems().add(n));
currentCup.getDivisions().forEach(n -> n.getMatches().forEach(m -> matchListView.getItems().add(m)));
currentCup.getDivisions().forEach(n -> n.getCompetingTeams().values().forEach(m -> teamListView.getItems().add(m)));
}
/**
* Run when the page is loaded in.
* Fills in listviews for divisions,
* matches and teams.
* Adds a change listener to the division list.
*
* @param url URL - represents a Uniform Resource Locator
* @param resourceBundle ResourceBundle - contains locale-specific objects
*/
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
Cup currentCup = getCurrentCup();
initScene(currentCup);
initLists(currentCup);
divisionListView.getSelectionModel().selectedItemProperty().addListener((a,b,selected) -> {
setCurrentDivision(selected);
//changeScene("division-overview");
});
/* doubleclick on a division takes you straight into the division */
divisionListView.setOnMouseClicked(click -> {
if (click.getButton() == MouseButton.PRIMARY && click.getClickCount() == 2) {
Division selectedDivision = divisionListView.getSelectionModel().getSelectedItem();
setCurrentDivision(selectedDivision);
changeScene("division-overview");
}
});
}
}
\ No newline at end of file
package edu.ntnu.idatt1002.k1g4.client.controllers;
import static edu.ntnu.idatt1002.k1g4.client.Model.openBrowser;
import static edu.ntnu.idatt1002.k1g4.client.Model.setCurrentCup;
import static edu.ntnu.idatt1002.k1g4.client.Model.*;
import static edu.ntnu.idatt1002.k1g4.client.ViewUtil.*;
import edu.ntnu.idatt1002.k1g4.Cup;
import edu.ntnu.idatt1002.k1g4.client.Model;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
......@@ -31,7 +28,7 @@ import java.util.ResourceBundle;
* the cup creation page, help and rules.
*
* @author Carl Gützkow, Nicolai H. Brand.
* @version 0.3
* @version 0.5
*/
public class HomeController implements Initializable {
......@@ -41,7 +38,7 @@ public class HomeController implements Initializable {
@FXML
private RowConstraints gridPanelRow1;
private final static int CUP_LIST_SCALE_FACTOR = 39;
private final static int CUP_LIST_SCALE_FACTOR = 40;
private final static int MAX_CUP_BEFORE_SCROLL = 5;
@FXML
......@@ -50,6 +47,12 @@ public class HomeController implements Initializable {
@FXML
private GridPane gridPane;
@FXML
private Button deleteCupField;
@FXML
private Button goToCupField;
/**
* Overridden method from Initializable
* that will run each time this controller is loaded.
......@@ -63,79 +66,126 @@ public class HomeController implements Initializable {
currentCupsList.getItems().clear();
gridPanelRow1.setMinHeight(10);
gridPanelRow1.fillHeightProperty();
/* make delete button RED */
deleteCupField.setStyle("-fx-background-color: #ff0000;");
if (!Model.getCups().isEmpty()) {
gridPane.setVgap(50);
currentCupsList.setScaleX(1);
currentCupsList.setScaleY(1);
showInfoWhenCups();
if (currentCupsList.getItems().size() == 1)
infoText.setText("This is the current cup:");
else
infoText.setText("These are the current cups:");
currentCupsList.getSelectionModel().selectedItemProperty().addListener((a,b,c) -> {
setCurrentCup(c);
changeScene("cup-overview");
});
currentCupsList.getSelectionModel().selectedItemProperty().addListener((a, b, c) -> setCurrentCup(c));
/*
/* if double click on cup, go straight into it */
currentCupsList.setOnMouseClicked(click -> {
if (click.getButton() == MouseButton.SECONDARY) {
if (click.getButton() == MouseButton.PRIMARY && click.getClickCount() == 2) {
Cup selectedCup = currentCupsList.getSelectionModel().getSelectedItem();
Model.removeCup(selectedCup);
boolean res = getConfirmation("Are you sure you want to delete the Cup " + selectedCup.getLocation());
if (res)
changeScene("home");
setCurrentCup(selectedCup);
changeScene("cup-overview");
}
});
*/
currentCupsList.setCellFactory(cell -> new ListCell<>() {
@Override
protected void updateItem(Cup item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(String.valueOf(item));
setFont(Font.font(22));
}
}
});
/* Take all current active cups and put into the listview */
Model.getCups().forEach(cup -> currentCupsList.getItems().add(cup));
updateListOfCups();
if (Model.getCups().size() > MAX_CUP_BEFORE_SCROLL)
gridPanelRow1.setMinHeight(MAX_CUP_BEFORE_SCROLL * CUP_LIST_SCALE_FACTOR);
else
gridPanelRow1.setMinHeight(Model.getCups().size() * CUP_LIST_SCALE_FACTOR);
} else {
infoText.setText("No previous cups. Click \"New cup\" to start.");
hideInfoWhenNoCups();
}
}
gridPanelRow1.fillHeightProperty();
/**
* Helper method to update list of cups.
*/
public void updateListOfCups() {
/* Take all current active cups and put into the listview */
Model.getCups().forEach(cup -> currentCupsList.getItems().add(cup));
// TODO Clicked cup should be current cup
//Cup currentCup = Model.getCups().get(0);
//Model.setCurrentCup(currentCup);
if (Model.getCups().size() > MAX_CUP_BEFORE_SCROLL)
gridPanelRow1.setMinHeight(MAX_CUP_BEFORE_SCROLL * CUP_LIST_SCALE_FACTOR);
else
gridPanelRow1.setMinHeight(Model.getCups().size() * CUP_LIST_SCALE_FACTOR);
}
} else {
gridPane.setVgap(0);
infoText.setText("No previous cups. Click \"New cup\" to start.");
/**
* Helper method to show info when cups.
*/
public void showInfoWhenCups() {
gridPane.setVgap(50);
currentCupsList.setScaleX(1);
currentCupsList.setScaleY(1);
deleteCupField.setVisible(true);
goToCupField.setVisible(true);
/* update font size */
currentCupsList.setCellFactory(cell -> new ListCell<>() {
@Override
protected void updateItem(Cup item, boolean empty) {
super.updateItem(item, empty);
if (item != null) {
setText(String.valueOf(item));
setFont(Font.font(22));
}
}
});
/* Hide current listview since there are none */
currentCupsList.setScaleX(0);
currentCupsList.setScaleY(0);
}
gridPanelRow1.fillHeightProperty();
}
/**
* Helper method to hide info when no cups.
*/
public void hideInfoWhenNoCups() {
gridPane.setVgap(0);
/* Hide current listview and buttons since there are no cups */
currentCupsList.setScaleX(0);
currentCupsList.setScaleY(0);
deleteCupField.setVisible(false);
goToCupField.setVisible(false);
}
/**
* Changes page to the create cup page
*
* @param event - ActionEvent that is derived from the page and contains information about an event
*/
@FXML
void goToCreateCup(ActionEvent event) {
void goToCreateCup() {
changeScene("create-cup");
}
/**
* Delete cup.
*/
@FXML
void deleteCup() {
if (getCurrentCup() == null) {
giveError("There is no cup selected. Click on a cup to select it.");
} else {
boolean res = getConfirmation("Are you sure you want to delete the cup " + getCurrentCup().getName() + " ?");
if (res) {
deleteSelectedCup();
/* refresh scene as the list view needs to be updated */
changeScene("home");
}
}
}
/**
* Go to cup.
*/
@FXML
void goToCup() {
if (getCurrentCup() != null)
changeScene("cup-overview");
else
giveError("There is no cup selected. Click on a cup to select it.");
}
/**
* Takes the user to the documentation about how to use the product
* if it finds a browser to open the link in.
......@@ -158,6 +208,11 @@ public class HomeController implements Initializable {
} catch (Exception e) {}
}
/**
* Gets cup.
*
* @param event the event
*/
@FXML
void getCup(ActionEvent event) {
changeScene("cup-overview");
......
......@@ -19,17 +19,17 @@
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0" VBox.vgrow="ALWAYS">
<top>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Floorball tournament manager" wrappingWidth="796.9375" BorderPane.alignment="CENTER">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Floorball tournament manager" wrappingWidth="798.9375" BorderPane.alignment="CENTER">
<font>
<Font size="36.0" />
</font>
<BorderPane.margin>
<Insets bottom="15.0" left="15.0" right="15.0" top="15.0" />
<Insets left="15.0" right="15.0" top="15.0" />
</BorderPane.margin>
</Text>
</top>
<center>
<GridPane fx:id="gridPane" alignment="BOTTOM_CENTER" prefHeight="546.0" prefWidth="1038.0" scaleX="0.8" scaleY="0.8" BorderPane.alignment="CENTER">
<GridPane fx:id="gridPane" alignment="BOTTOM_CENTER" prefHeight="516.0" prefWidth="1080.0" scaleX="0.8" scaleY="0.8" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
......@@ -47,6 +47,28 @@
<Insets />
</opaqueInsets>
</Button>
<HBox prefHeight="100.0" prefWidth="200.0" GridPane.rowIndex="1">
<children>
<ListView fx:id="currentCupsList" onMouseClicked="#getCup" prefHeight="50.0" prefWidth="992.0" HBox.hgrow="ALWAYS" />
<VBox alignment="CENTER" prefHeight="50.0" prefWidth="75.0" HBox.hgrow="ALWAYS">
<children>
<Button fx:id="goToCupField" alignment="CENTER" minHeight="32.0" minWidth="0.0" mnemonicParsing="false" onAction="#goToCup" prefHeight="100.0" prefWidth="150.0" text="Go to cup" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
<font>
<Font size="18.0" />
</font>
</Button>
<Button fx:id="deleteCupField" alignment="CENTER" minHeight="32.0" minWidth="0.0" mnemonicParsing="false" onAction="#deleteCup" prefHeight="100.0" prefWidth="150.0" text="Delete cup" textFill="WHITE" VBox.vgrow="ALWAYS">
<font>
<Font size="18.0" />
</font>
</Button>
</children>
</VBox>
</children>
</HBox>
<Text id="cupStatus" fx:id="infoText" strokeType="OUTSIDE" strokeWidth="0.0" text="No previous cups. Click &quot;New cup&quot; to start." wrappingWidth="637.5390625" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
<font>
<Font size="22.0" />
......@@ -55,7 +77,6 @@
<Insets bottom="20.0" />
</GridPane.margin>
</Text>
<ListView fx:id="currentCupsList" onMouseClicked="#getCup" prefHeight="49.0" prefWidth="1080.0" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
</children>
</GridPane>
</center>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment