added functionality to autosave result and place if changed.

This commit is contained in:
schrom01 2022-05-08 22:13:03 +02:00
parent 53ffa90c69
commit b51a585167
3 changed files with 26 additions and 8 deletions

View File

@ -1,7 +1,8 @@
package ch.zhaw.projekt2.turnierverwaltung.main.gameScheduleView;
import ch.zhaw.projekt2.turnierverwaltung.*;
import javafx.event.ActionEvent;
import javafx.beans.value.ObservableValue;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
@ -32,8 +33,13 @@ public class GameController extends FXController{
private TextField pointsTeamTwo;
@FXML
void saveGamerResult(ActionEvent event) {
gameDecorator.saveGame(pointsTeamOne.getText(), pointsTeamTwo.getText(), placesChoiceBox.getValue());
void saveGameResult(Event event) {
gameDecorator.saveGameResult(pointsTeamOne.getText(), pointsTeamTwo.getText());
}
private void saveGamePlace(Place newPlace) {
gameDecorator.saveGamePlace(newPlace);
}
public double getGameBoxHeigth(){
@ -68,6 +74,7 @@ public class GameController extends FXController{
public void setup(TournamentDecorator tournamentDecorator, FileIO fileIO, FactoryDecorator factoryDecorator, Pane pane, GameDecorator gameDecorator) {
setTournamentDecorator(tournamentDecorator);
this.gameDecorator = gameDecorator;
placesChoiceBox.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends Place> observable, Place oldValue, Place newValue) -> saveGamePlace(newValue));
}
}

View File

@ -24,9 +24,17 @@ public class GameDecorator implements IsObservable{
listener.remove(observer);
}
public void saveGame(String points1, String points2, Place place){
public void saveGameResult(String points1, String points2){
if(points1.length() > 0){
game.setPoints1(Integer.parseInt(points1));
}
if(points2.length() > 0) {
game.setPoints2(Integer.parseInt(points2));
}
informListener();
}
public void saveGamePlace(Place place){
game.setPlace(place);
informListener();
}

View File

@ -20,10 +20,13 @@
</Button>
<Button fx:id="editLocBtn" mnemonicParsing="false" onAction="#openPlacesFormular" text="Orte bearbeiten">
<HBox.margin>
<Insets right="40.0" />
<Insets right="20.0" />
</HBox.margin>
</Button>
<Button fx:id="closeTournamentBtn" layoutX="470.0" layoutY="10.0" mnemonicParsing="false" onAction="#closeTournament" text="Close Tournament" />
<Button fx:id="closeTournamentBtn" layoutX="470.0" layoutY="10.0" mnemonicParsing="false" onAction="#closeTournament" text="Close Tournament">
<HBox.margin>
<Insets right="20.0" />
</HBox.margin></Button>
</children>
</HBox>
</top>