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;
|
package seng302.Controllers;
|
||||||
|
|
||||||
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
@@ -10,15 +12,16 @@ import javafx.scene.control.cell.PropertyValueFactory;
|
|||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.Paint;
|
import javafx.scene.paint.Paint;
|
||||||
|
import javafx.util.Callback;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
import seng302.Model.Boat;
|
import seng302.Model.*;
|
||||||
import seng302.Model.BoatInRace;
|
|
||||||
import seng302.Model.ConstantVelocityRace;
|
|
||||||
import seng302.Model.Leg;
|
|
||||||
import seng302.RaceMap;
|
import seng302.RaceMap;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Observable;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,16 +34,13 @@ public class RaceController extends Controller{
|
|||||||
TableView<BoatInRace> boatInfoTable;
|
TableView<BoatInRace> boatInfoTable;
|
||||||
@FXML
|
@FXML
|
||||||
AnchorPane canvasBase;
|
AnchorPane canvasBase;
|
||||||
/*
|
|
||||||
@FXML
|
@FXML
|
||||||
TableColumn<BoatInRace, String> boatPlacingColumn;
|
TableColumn<BoatInRace, String> boatPlacingColumn;
|
||||||
*/
|
|
||||||
@FXML
|
@FXML
|
||||||
TableColumn<BoatInRace, String> boatTeamColumn;
|
TableColumn<BoatInRace, String> boatTeamColumn;
|
||||||
/*
|
|
||||||
@FXML
|
@FXML
|
||||||
TableColumn<BoatInRace, String> boatMarkColumn;
|
TableColumn<BoatInRace, String> boatMarkColumn;
|
||||||
*/
|
|
||||||
private GraphicsContext gc;
|
private GraphicsContext gc;
|
||||||
private RaceMap map;
|
private RaceMap map;
|
||||||
|
|
||||||
@@ -63,6 +63,19 @@ public class RaceController extends Controller{
|
|||||||
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
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
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {/*
|
public void initialize(URL location, ResourceBundle resources) {/*
|
||||||
raceMap.widthProperty().bind(canvasBase.widthProperty());
|
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 leg1 = new Leg("first leg", 1, new GPSCoordinate(0, 0), new GPSCoordinate(1, 1), 0);
|
||||||
Leg[] legs = new Leg[] {leg1};
|
Leg[] legs = new Leg[] {leg1};
|
||||||
|
|
||||||
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs);
|
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this);
|
||||||
|
|
||||||
(new Thread(race)).start();
|
(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());
|
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;
|
package seng302.Model;
|
||||||
|
|
||||||
|
import seng302.Controllers.RaceController;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.GraphCoordinate;
|
import seng302.GraphCoordinate;
|
||||||
|
|
||||||
@@ -17,6 +18,10 @@ public class ConstantVelocityRace extends Race {
|
|||||||
* @see Leg
|
* @see Leg
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks, RaceController controller) {
|
||||||
|
super(startingBoats, marks, controller);
|
||||||
|
}
|
||||||
|
|
||||||
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks) {
|
public ConstantVelocityRace(BoatInRace[] startingBoats, Leg[] marks) {
|
||||||
super(startingBoats, marks);
|
super(startingBoats, marks);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ public class Leg {
|
|||||||
this.legNumber = number;
|
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
|
* @return the name of the Leg
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package seng302.Model;
|
package seng302.Model;
|
||||||
|
|
||||||
|
|
||||||
|
import seng302.Controllers.RaceController;
|
||||||
|
import seng302.GPSCoordinate;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -11,6 +14,7 @@ public abstract class Race implements Runnable {
|
|||||||
protected BoatInRace[] startingBoats;
|
protected BoatInRace[] startingBoats;
|
||||||
protected ArrayList<BoatInRace> finishingBoats = new ArrayList<>();
|
protected ArrayList<BoatInRace> finishingBoats = new ArrayList<>();
|
||||||
protected Leg[] legs;
|
protected Leg[] legs;
|
||||||
|
protected RaceController controller;
|
||||||
|
|
||||||
private int SLEEP_TIME = 1000; //time in milliseconds to pause in a paced loop
|
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 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.
|
* @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) {
|
public Race(BoatInRace[] boats, Leg[] marks) {
|
||||||
this.startingBoats = boats;
|
this.startingBoats = boats;
|
||||||
this.legs = marks;
|
this.legs = marks;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
preRace();
|
preRace();
|
||||||
simulateRace();
|
simulateRace();
|
||||||
System.out.println(System.currentTimeMillis() - time);
|
if(controller != null) controller.updateInfoTable(this);
|
||||||
System.out.println(finishingBoats.get(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preRace() {
|
private void preRace() {
|
||||||
@@ -81,6 +89,7 @@ public abstract class Race implements Runnable {
|
|||||||
if (boat.getCurrentLeg().getLegNumber() == legs.length - 1) {
|
if (boat.getCurrentLeg().getLegNumber() == legs.length - 1) {
|
||||||
//boat has finished
|
//boat has finished
|
||||||
boat.setTimeFinished(timeElapsed);
|
boat.setTimeFinished(timeElapsed);
|
||||||
|
boat.setCurrentLeg(new Leg("Finish"));
|
||||||
finishingBoats.add(boat);
|
finishingBoats.add(boat);
|
||||||
} else {
|
} else {
|
||||||
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
boat.setDistanceTravelledInLeg(boat.getDistanceTravelledInLeg() - boat.getCurrentLeg().getDistance());
|
||||||
|
|||||||
@@ -18,7 +18,9 @@
|
|||||||
<children>
|
<children>
|
||||||
<TableView fx:id="boatInfoTable" prefHeight="400.0" prefWidth="146.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
<TableView fx:id="boatInfoTable" prefHeight="400.0" prefWidth="146.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||||
<columns>
|
<columns>
|
||||||
<TableColumn fx:id="boatTeamColumn" prefWidth="150.0" text="Team" />
|
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
|
||||||
|
<TableColumn fx:id="boatTeamColumn" prefWidth="50.0" text="Team" />
|
||||||
|
<TableColumn fx:id="boatMarkColumn" prefWidth="50.0" text="Mark" />
|
||||||
</columns>
|
</columns>
|
||||||
</TableView>
|
</TableView>
|
||||||
</children>
|
</children>
|
||||||
|
|||||||
Reference in New Issue
Block a user