Implemented Table Refresh Function

- Made refreshTable() in RaceController that refresh the boatInfoTable
- Made checkPosition() in Race call controller.refreshTable()
- Result is that the table now updates
#story [15]
main
Fan-Wu Yang 9 years ago
parent e04fdc79c9
commit 12a9205ded

@ -2,7 +2,6 @@ package seng302.Controllers;
import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.StringProperty;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@ -40,7 +39,7 @@ public class RaceController extends Controller{
Label timer; Label timer;
@FXML @FXML
TableView boatInfoTable; TableView<BoatInRace> boatInfoTable;
@FXML @FXML
TableColumn<BoatInRace, String> boatPlacingColumn; TableColumn<BoatInRace, String> boatPlacingColumn;
@FXML @FXML
@ -65,7 +64,7 @@ public class RaceController extends Controller{
* @param race Race to listen to. * @param race Race to listen to.
*/ */
public void updateInfoTable(Race race) { public void updateInfoTable(Race race) {
boatInfoTable.getItems().clear(); //boatInfoTable.getItems().clear();
boatInfoTable.setItems(race.getStartingBoats()); boatInfoTable.setItems(race.getStartingBoats());
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name")); boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
@ -78,6 +77,10 @@ public class RaceController extends Controller{
}); });
} }
public void refreshTable(){
boatInfoTable.refresh();
}
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
@ -119,7 +122,7 @@ public class RaceController extends Controller{
boat1.setColour(Color.DARKVIOLET); boat1.setColour(Color.DARKVIOLET);
boat1.setCurrentPosition(new GPSCoordinate(0, 0)); boat1.setCurrentPosition(new GPSCoordinate(0, 0));
BoatInRace boat2 = new BoatInRace("TEST", 400); BoatInRace boat2 = new BoatInRace("TEST", 300);
boat2.setColour(Color.DARKRED); boat2.setColour(Color.DARKRED);
boat2.setCurrentPosition(new GPSCoordinate(0, 0)); boat2.setCurrentPosition(new GPSCoordinate(0, 0));

@ -135,7 +135,6 @@ public abstract class Race implements Runnable {
*/ */
protected void checkPosition(BoatInRace boat, long timeElapsed) { protected void checkPosition(BoatInRace boat, long timeElapsed) {
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){ if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
//updateController(); removed as we do not update the table every time anymore.
//boat has passed onto new leg //boat has passed onto new leg
if (boat.getCurrentLeg().getName().equals("Finish")) { if (boat.getCurrentLeg().getName().equals("Finish")) {
//boat has finished //boat has finished
@ -147,6 +146,7 @@ public abstract class Race implements Runnable {
boat.setCurrentLeg(nextLeg); boat.setCurrentLeg(nextLeg);
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg()); boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
} }
controller.refreshTable();
} }
} }

Loading…
Cancel
Save