Refactored the refreshTable into propeties that listen.
- Added currentLegName as a String Property - Refactored Name of the Boat as a StringProperty #story[15]
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import seng302.Model.BoatInRace;
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,5 +24,13 @@ public class Constants {
|
|||||||
public static final GPSCoordinate finishLineMarker1 = new GPSCoordinate(32.317379, -64.839291);
|
public static final GPSCoordinate finishLineMarker1 = new GPSCoordinate(32.317379, -64.839291);
|
||||||
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
public static final GPSCoordinate finishLineMarker2 = new GPSCoordinate(32.317257, -64.836260);
|
||||||
|
|
||||||
|
public static final BoatInRace[] OFFICIAL_AC35_COMPETITORS = new BoatInRace[]
|
||||||
|
{new BoatInRace("Oracle Team USA", 200.0, Color.BLUEVIOLET),
|
||||||
|
new BoatInRace("Land Rover BAR", 180.0, Color.BLACK),
|
||||||
|
new BoatInRace("SoftBank Team Japan", 190.0, Color.RED),
|
||||||
|
new BoatInRace("Groupama Team France", 210.0, Color.ORANGE),
|
||||||
|
new BoatInRace("Artemis Racing", 220.0, Color.DARKOLIVEGREEN),
|
||||||
|
new BoatInRace("Emirates Team New Zealand", 310, Color.LIMEGREEN)};
|
||||||
|
|
||||||
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
//public static final Leg bermudaCourseStartToMark1 = new Leg(0, , new )
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ public class RaceController extends Controller{
|
|||||||
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
|
||||||
* @param race Race to listen to.
|
* @param race Race to listen to.
|
||||||
*/
|
*/
|
||||||
public void updateInfoTable(Race race) {
|
public void setInfoTable(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(cellData -> cellData.getValue().getName());
|
||||||
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
boatMarkColumn.setCellValueFactory(cellData -> cellData.getValue().getCurrentLegName());
|
||||||
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
||||||
@@ -77,10 +77,6 @@ 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) {
|
||||||
|
|
||||||
@@ -118,18 +114,17 @@ public class RaceController extends Controller{
|
|||||||
|
|
||||||
private BoatInRace[] generateAC35Competitors() {
|
private BoatInRace[] generateAC35Competitors() {
|
||||||
|
|
||||||
BoatInRace boat1 = new BoatInRace("NZ", 500);
|
BoatInRace[] boats = new BoatInRace[6];
|
||||||
boat1.setColour(Color.DARKVIOLET);
|
|
||||||
boat1.setCurrentPosition(new GPSCoordinate(0, 0));
|
|
||||||
|
|
||||||
BoatInRace boat2 = new BoatInRace("TEST", 300);
|
|
||||||
boat2.setColour(Color.DARKRED);
|
|
||||||
boat2.setCurrentPosition(new GPSCoordinate(0, 0));
|
|
||||||
|
|
||||||
BoatInRace boat3 = new BoatInRace("TEST2", 350);
|
int i = 0;
|
||||||
boat3.setColour(Color.FUCHSIA);
|
for (BoatInRace boat : Constants.OFFICIAL_AC35_COMPETITORS) {
|
||||||
boat3.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat.setCurrentPosition(Constants.startLineMarker1);
|
||||||
return new BoatInRace[] {boat1, boat2, boat3};
|
boats[i] = boat;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return boats;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by fwy13 on 3/03/17.
|
* Created by fwy13 on 3/03/17.
|
||||||
*/
|
*/
|
||||||
public class Boat {
|
public class Boat {
|
||||||
private String name;
|
private StringProperty name;
|
||||||
private double velocity;
|
private double velocity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,19 +19,19 @@ public class Boat {
|
|||||||
*/
|
*/
|
||||||
public Boat(String name, double velocity){
|
public Boat(String name, double velocity){
|
||||||
this.velocity = velocity;
|
this.velocity = velocity;
|
||||||
this.name = name;
|
this.name = new SimpleStringProperty(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return The name of the boat
|
* @return The name of the boat
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public StringProperty getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name.setValue(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,7 +47,7 @@ public class Boat {
|
|||||||
* @return The Name of the boat.
|
* @return The Name of the boat.
|
||||||
*/
|
*/
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return getName();
|
return getName().getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import org.geotools.referencing.GeodeticCalculator;
|
import org.geotools.referencing.GeodeticCalculator;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
@@ -18,6 +20,19 @@ public class BoatInRace extends Boat {
|
|||||||
private long timeFinished;
|
private long timeFinished;
|
||||||
private Color colour;
|
private Color colour;
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
private StringProperty currentLegName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
* @param name Name of the boat.
|
||||||
|
* @param velocity Speed that the boat travels.
|
||||||
|
* @param colour Colour the boat will be displayed as on the map
|
||||||
|
*/
|
||||||
|
public BoatInRace(String name, double velocity, Color colour) {
|
||||||
|
super(name, velocity);
|
||||||
|
setColour(colour);
|
||||||
|
currentLegName = new SimpleStringProperty("");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -61,15 +76,6 @@ public class BoatInRace extends Boat {
|
|||||||
this.timeFinished = timeFinished;
|
this.timeFinished = timeFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor method.
|
|
||||||
* @param name Name of the boat.
|
|
||||||
* @param velocity Speed that the boat travels.
|
|
||||||
*/
|
|
||||||
public BoatInRace(String name, double velocity) {
|
|
||||||
super(name, velocity);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current leg that the boat is on.
|
* Gets the current leg that the boat is on.
|
||||||
* @return returns the leg the boat is on in a Leg class
|
* @return returns the leg the boat is on in a Leg class
|
||||||
@@ -86,6 +92,11 @@ public class BoatInRace extends Boat {
|
|||||||
*/
|
*/
|
||||||
public void setCurrentLeg(Leg currentLeg) {
|
public void setCurrentLeg(Leg currentLeg) {
|
||||||
this.currentLeg = currentLeg;
|
this.currentLeg = currentLeg;
|
||||||
|
this.currentLegName.setValue(currentLeg.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringProperty getCurrentLegName(){
|
||||||
|
return currentLegName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public abstract class Race implements Runnable {
|
|||||||
protected long totalTimeElapsed;
|
protected long totalTimeElapsed;
|
||||||
|
|
||||||
|
|
||||||
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
private int SLEEP_TIME = 100; //time in milliseconds to pause in a paced loop
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initailiser for Race
|
* Initailiser for Race
|
||||||
@@ -51,7 +51,7 @@ public abstract class Race implements Runnable {
|
|||||||
* Runnable for the thread.
|
* Runnable for the thread.
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
updateController();
|
setControllerListeners();
|
||||||
preRace();
|
preRace();
|
||||||
simulateRace();
|
simulateRace();
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,8 @@ public abstract class Race implements Runnable {
|
|||||||
System.out.println("====================");
|
System.out.println("====================");
|
||||||
for (int i = 0; i < startingBoats.size(); i++) {
|
for (int i = 0; i < startingBoats.size(); i++) {
|
||||||
if (startingBoats.get(i) != null) {
|
if (startingBoats.get(i) != null) {
|
||||||
System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: " + Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn");
|
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));
|
startingBoats.get(i).setCurrentLeg(legs.get(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,18 +144,18 @@ public abstract class Race implements Runnable {
|
|||||||
} else {
|
} else {
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
Leg nextLeg = legs.get(boat.getCurrentLeg().getLegNumber() + 1);
|
||||||
|
|
||||||
boat.setCurrentLeg(nextLeg);
|
boat.setCurrentLeg(nextLeg);
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg());
|
||||||
}
|
}
|
||||||
controller.refreshTable();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update call for the controller.
|
* Update call for the controller.
|
||||||
*/
|
*/
|
||||||
protected void updateController() {
|
protected void setControllerListeners() {
|
||||||
if(controller != null) controller.updateInfoTable(this);
|
if(controller != null) controller.setInfoTable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user