From 91861eb5cbe0f36e948b056eccfa575e861667b5 Mon Sep 17 00:00:00 2001 From: Fan-Wu Yang Date: Sun, 19 Mar 2017 21:21:21 +1300 Subject: [PATCH 1/2] Refactored BoatinRace to observable list - Changed starting Boats into ObservableList from array - stopped checkPosition in Race abstract class from updating the table as everytime as it is checked by a listener - Changed array methods .length to .size() and [i] to .get() to reflect the type change. #refactor #story[9] --- .idea/copyright/profiles_settings.xml | 3 +++ .idea/modules.xml | 1 + .../seng302/Controllers/RaceController.java | 8 +++++--- src/main/java/seng302/Model/Race.java | 20 +++++++++++-------- 4 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index efca357c..6e70c25d 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java index a2dbf45b..f3552de9 100644 --- a/src/main/java/seng302/Controllers/RaceController.java +++ b/src/main/java/seng302/Controllers/RaceController.java @@ -4,6 +4,7 @@ package seng302.Controllers; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.canvas.GraphicsContext; import javafx.scene.control.TableColumn; @@ -47,15 +48,16 @@ public class RaceController extends Controller{ private RaceMap map; - public void updateMap(BoatInRace[] boats) { - raceMap.setBoats(boats); + public void updateMap(ObservableList boats) { + BoatInRace[] boatInRaces = new BoatInRace[boats.size()]; + raceMap.setBoats(boats.toArray(boatInRaces)); raceMap.drawRaceMap(); } public void updateInfoTable(Race race) { boatInfoTable.getItems().clear(); - boatInfoTable.setItems(FXCollections.observableArrayList(race.getStartingBoats())); + boatInfoTable.setItems(race.getStartingBoats()); boatTeamColumn.setCellValueFactory(new PropertyValueFactory("Name")); boatMarkColumn.setCellValueFactory(new PropertyValueFactory("CurrentLeg")); diff --git a/src/main/java/seng302/Model/Race.java b/src/main/java/seng302/Model/Race.java index d8c89d79..75b710cb 100644 --- a/src/main/java/seng302/Model/Race.java +++ b/src/main/java/seng302/Model/Race.java @@ -1,6 +1,9 @@ package seng302.Model; +import javafx.collections.FXCollections; +import javafx.collections.ObservableArray; +import javafx.collections.ObservableList; import seng302.Controllers.RaceController; import seng302.GPSCoordinate; @@ -11,7 +14,8 @@ import java.util.*; * Created by fwy13 on 3/03/17. */ public abstract class Race implements Runnable { - protected BoatInRace[] startingBoats; + //protected BoatInRace[] startingBoats; + protected ObservableList startingBoats; protected ArrayList legs; protected RaceController controller; protected int boatsFinished = 0; @@ -25,7 +29,7 @@ public abstract class Race implements Runnable { * @param legs Number of marks in order that the boats pass in order to complete the race. */ public Race(BoatInRace[] boats, ArrayList legs, RaceController controller) { - this.startingBoats = boats; + this.startingBoats = FXCollections.observableArrayList(boats); this.legs = legs; this.legs.add(new Leg("Finish")); this.controller = controller; @@ -45,9 +49,9 @@ public abstract class Race implements Runnable { //show the boats participating. System.out.println("Boats Participating:"); System.out.println("===================="); - for (int i = 0; i < startingBoats.length; i++) { - System.out.println(i + 1 + ". " + startingBoats[i].getName() + ", Speed: " + Math.round(startingBoats[i].getVelocity() * 1.94384) + "kn"); - startingBoats[i].setCurrentLeg(legs.get(0)); + for (int i = 0; i < startingBoats.size(); i++) { + System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " + Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn"); + startingBoats.get(i).setCurrentLeg(legs.get(0)); } } @@ -68,7 +72,7 @@ public abstract class Race implements Runnable { long remainingSeconds; - while (boatsFinished < startingBoats.length) { + while (boatsFinished < startingBoats.size()) { timeLoopStarted = System.currentTimeMillis(); totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted; long currentTime = System.currentTimeMillis() - timeRaceStarted; @@ -95,7 +99,7 @@ public abstract class Race implements Runnable { protected void checkPosition(BoatInRace boat, long timeElapsed) { if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){ - updateController(); + //updateController(); //boat has passed onto new leg if (boat.getCurrentLeg().getName().equals("Finish")) { //boat has finished @@ -115,7 +119,7 @@ public abstract class Race implements Runnable { } - public BoatInRace[] getStartingBoats() { + public ObservableList getStartingBoats() { return startingBoats; } From ccaee9131d355f08e5edaaf371f9beba0dd01ecf Mon Sep 17 00:00:00 2001 From: Erika Date: Sun, 19 Mar 2017 22:44:00 +1300 Subject: [PATCH 2/2] Fixing Maven issues #chore --- .idea/compiler.xml | 18 +++++++++++++++++- .idea/modules.xml | 1 - 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 12dfecd9..57e4c6ca 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,11 +1,27 @@ + + + + + + + + + + + + - + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml index 6e70c25d..09c81627 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,7 +3,6 @@ - \ No newline at end of file