diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java index 20b85b77..57f96474 100644 --- a/src/main/java/seng302/Controllers/RaceController.java +++ b/src/main/java/seng302/Controllers/RaceController.java @@ -2,7 +2,6 @@ package seng302.Controllers; import javafx.beans.property.ReadOnlyObjectWrapper; -import javafx.beans.property.StringProperty; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -40,7 +39,7 @@ public class RaceController extends Controller{ Label timer; @FXML - TableView boatInfoTable; + TableView boatInfoTable; @FXML TableColumn boatPlacingColumn; @FXML @@ -64,12 +63,12 @@ public class RaceController extends Controller{ * Updates the array listened by the TableView (boatInfoTable) that displays the boat information. * @param race Race to listen to. */ - public void updateInfoTable(Race race) { - boatInfoTable.getItems().clear(); + public void setInfoTable(Race race) { + //boatInfoTable.getItems().clear(); boatInfoTable.setItems(race.getStartingBoats()); - boatTeamColumn.setCellValueFactory(new PropertyValueFactory("Name")); - boatMarkColumn.setCellValueFactory(new PropertyValueFactory("CurrentLeg")); + boatTeamColumn.setCellValueFactory(cellData -> cellData.getValue().getName()); + boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName()); boatPlacingColumn.setCellValueFactory(new Callback, ObservableValue>() { @Override public ObservableValue call(TableColumn.CellDataFeatures table) { diff --git a/src/main/java/seng302/Model/Boat.java b/src/main/java/seng302/Model/Boat.java index 1c4d0484..12ed8279 100644 --- a/src/main/java/seng302/Model/Boat.java +++ b/src/main/java/seng302/Model/Boat.java @@ -1,12 +1,15 @@ package seng302.Model; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import java.util.ArrayList; /** * Created by fwy13 on 3/03/17. */ public class Boat { - private String name; + private StringProperty name; private double velocity; private String abbrev; @@ -17,18 +20,22 @@ public class Boat { */ public Boat(String name, double velocity, String abbrev){ this.velocity = velocity; - this.name = name; this.abbrev = abbrev; + this.name = new SimpleStringProperty(name); } /** * * @return The name of the boat */ - public String getName() { + public StringProperty getName() { return name; } + public void setName(String name) { + this.name.setValue(name); + } + /** * * @return returns the speed of the boat. @@ -42,7 +49,7 @@ public class Boat { * @return The Name of the boat. */ public String toString(){ - return getName(); + return getName().getValue(); } public String getAbbrev() { return abbrev; } diff --git a/src/main/java/seng302/Model/BoatInRace.java b/src/main/java/seng302/Model/BoatInRace.java index c7ae531a..560feb21 100644 --- a/src/main/java/seng302/Model/BoatInRace.java +++ b/src/main/java/seng302/Model/BoatInRace.java @@ -1,5 +1,7 @@ package seng302.Model; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; import javafx.scene.paint.Color; import org.geotools.referencing.GeodeticCalculator; import seng302.GPSCoordinate; @@ -18,6 +20,7 @@ public class BoatInRace extends Boat { private long timeFinished; private Color colour; private boolean finished = false; + private StringProperty currentLegName; /** * Constructor method. @@ -28,6 +31,7 @@ public class BoatInRace extends Boat { public BoatInRace(String name, double velocity, Color colour, String abbrev) { super(name, velocity, abbrev); setColour(colour); + currentLegName = new SimpleStringProperty(""); } /** @@ -88,6 +92,11 @@ public class BoatInRace extends Boat { */ public void setCurrentLeg(Leg currentLeg) { this.currentLeg = currentLeg; + this.currentLegName.setValue(currentLeg.getName()); + } + + public StringProperty getCurrentLegName(){ + return currentLegName; } /** diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index e6105d78..d2a03c07 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -52,7 +52,7 @@ public abstract class Race implements Runnable { * Runnable for the thread. */ public void run() { - updateController(); + setControllerListeners(); preRace(); countdownTimer(); simulateRace(); @@ -165,7 +165,6 @@ public abstract class Race implements Runnable { */ protected void checkPosition(BoatInRace boat, long timeElapsed) { if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){ -// updateController(); //boat has passed onto new leg if (boat.getCurrentLeg().getName().equals("Finish")) { //boat has finished @@ -184,8 +183,8 @@ public abstract class Race implements Runnable { /** * Update call for the controller. */ - protected void updateController() { - if(controller != null) controller.updateInfoTable(this); + protected void setControllerListeners() { + if(controller != null) controller.setInfoTable(this); } /**