Implemented table view for finishing list
- Added auto-numbered placing, team name, and last mark columns - Added dummy 'Finish' mark to race - Added callback for race to update controller #story [13]
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package seng302.Controllers;
|
||||
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.canvas.Canvas;
|
||||
@@ -10,15 +12,16 @@ import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.Paint;
|
||||
import javafx.util.Callback;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.BoatInRace;
|
||||
import seng302.Model.ConstantVelocityRace;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.*;
|
||||
import seng302.RaceMap;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
@@ -31,16 +34,13 @@ public class RaceController extends Controller{
|
||||
TableView<BoatInRace> boatInfoTable;
|
||||
@FXML
|
||||
AnchorPane canvasBase;
|
||||
/*
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatPlacingColumn;
|
||||
*/
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatTeamColumn;
|
||||
/*
|
||||
@FXML
|
||||
TableColumn<BoatInRace, String> boatMarkColumn;
|
||||
*/
|
||||
|
||||
private GraphicsContext gc;
|
||||
private RaceMap map;
|
||||
|
||||
@@ -63,6 +63,19 @@ public class RaceController extends Controller{
|
||||
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
||||
}
|
||||
|
||||
public void updateInfoTable(Race race) {
|
||||
boatInfoTable.setItems(FXCollections.observableArrayList(race.getFinishingBoats()));
|
||||
|
||||
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
||||
boatMarkColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace, String>("CurrentLeg"));
|
||||
boatPlacingColumn.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<BoatInRace, String>, ObservableValue<String>>() {
|
||||
@Override
|
||||
public ObservableValue<String> call(TableColumn.CellDataFeatures<BoatInRace, String> table) {
|
||||
return new ReadOnlyObjectWrapper(boatInfoTable.getItems().indexOf(table.getValue()) + 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(URL location, ResourceBundle resources) {/*
|
||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
||||
@@ -73,12 +86,9 @@ public class RaceController extends Controller{
|
||||
Leg leg1 = new Leg("first leg", 1, new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||
Leg[] legs = new Leg[] {leg1};
|
||||
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
|
||||
|
||||
(new Thread(race)).start();
|
||||
//table view
|
||||
boatTeamColumn.setCellValueFactory(new PropertyValueFactory<BoatInRace,String>("Name"));
|
||||
boatInfoTable.setItems(FXCollections.observableArrayList(race.getFinishingBoats()));
|
||||
|
||||
this.map = new RaceMap(32.321989, -64.8553, 32.246, -64.831, (int)raceMap.getWidth(), (int)raceMap.getHeight());
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package seng302.Model;
|
||||
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
import seng302.GraphCoordinate;
|
||||
|
||||
@@ -17,6 +18,10 @@ public class ConstantVelocityRace extends Race {
|
||||
* @see Leg
|
||||
*/
|
||||
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks, RaceController controller) {
|
||||
super(startingBoats, marks, controller);
|
||||
}
|
||||
|
||||
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks) {
|
||||
super(startingBoats, marks);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,14 @@ public class Leg {
|
||||
this.legNumber = number;
|
||||
}
|
||||
|
||||
public Leg(String name) {
|
||||
this.name = name;
|
||||
this.distance = 0;
|
||||
this.startGPSCoordinate = new GPSCoordinate(0,0);
|
||||
this.endGPSCoordinate = new GPSCoordinate(0,0);
|
||||
this.legNumber = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the name of the Leg
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package seng302.Model;
|
||||
|
||||
|
||||
import seng302.Controllers.RaceController;
|
||||
import seng302.GPSCoordinate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -11,6 +14,7 @@ public abstract class Race implements Runnable {
|
||||
protected BoatInRace[] startingBoats;
|
||||
protected ArrayList<BoatInRace> finishingBoats = new ArrayList<>();
|
||||
protected Leg[] legs;
|
||||
protected RaceController controller;
|
||||
|
||||
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
||||
|
||||
@@ -19,18 +23,22 @@ public abstract class Race implements Runnable {
|
||||
* @param boats Takes in an array of boats that are participating in the race.
|
||||
* @param marks Number of marks in order that the boats pass in order to complete the race.
|
||||
*/
|
||||
public Race(BoatInRace[] boats, Leg[] marks, RaceController controller) {
|
||||
this.startingBoats = boats;
|
||||
this.legs = marks;
|
||||
this.controller = controller;
|
||||
}
|
||||
|
||||
public Race(BoatInRace[] boats, Leg[] marks) {
|
||||
this.startingBoats = boats;
|
||||
this.legs = marks;
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
long time = System.currentTimeMillis();
|
||||
preRace();
|
||||
simulateRace();
|
||||
System.out.println(System.currentTimeMillis() - time);
|
||||
System.out.println(finishingBoats.get(0));
|
||||
if(controller != null) controller.updateInfoTable(this);
|
||||
}
|
||||
|
||||
private void preRace() {
|
||||
@@ -81,6 +89,7 @@ public abstract class Race implements Runnable {
|
||||
if (boat.getCurrentLeg().getLegNumber() == legs.length - 1) {
|
||||
//boat has finished
|
||||
boat.setTimeFinished(timeElapsed);
|
||||
boat.setCurrentLeg(new Leg("Finish"));
|
||||
finishingBoats.add(boat);
|
||||
} else {
|
||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||
|
||||
Reference in New Issue
Block a user