This commit is contained in:
cir27
2017-05-21 16:05:37 +12:00
28 changed files with 1473 additions and 737 deletions
+7 -8
View File
@@ -9,8 +9,8 @@ import seng302.models.parsers.StreamParser;
import seng302.models.parsers.StreamReceiver; import seng302.models.parsers.StreamReceiver;
import seng302.server.ServerThread; import seng302.server.ServerThread;
public class App extends Application public class App extends Application {
{
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml")); Parent root = FXMLLoader.load(getClass().getResource("/views/MainView.fxml"));
@@ -39,15 +39,15 @@ public class App extends Application
e.printStackTrace(); e.printStackTrace();
} }
if (args.length == 1 && args[0].equals("-standalone")){ if (args.length == 1 && args[0].equals("-standalone")) {
return; return;
} }
if (args.length == 3 && args[0].equals("-server")){ if (args.length == 3 && args[0].equals("-server")) {
sr = new StreamReceiver(args[1], Integer.valueOf(args[2]), "RaceStream"); sr = new StreamReceiver(args[1], Integer.valueOf(args[2]), "RaceStream");
} else if(args.length == 2 && args[0].equals("-server")){ } else if (args.length == 2 && args[0].equals("-server")) {
switch (args[1]) { switch (args[1]) {
case "internal": case "internal":
sr = new StreamReceiver("localhost", 4949, "RaceStream"); sr = new StreamReceiver("localhost", 4949, "RaceStream");
@@ -62,7 +62,8 @@ public class App extends Application
} }
//Change the StreamReceiver in this else block to change the default data source. //Change the StreamReceiver in this else block to change the default data source.
else{ else{
sr = new StreamReceiver("localhost", 4949, "RaceStream"); //sr = new StreamReceiver("localhost", 4949, "RaceStream");
sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream");
} }
sr.start(); sr.start();
@@ -71,8 +72,6 @@ public class App extends Application
launch(args); launch(args);
} }
} }
@@ -1,31 +1,31 @@
package seng302.controllers; package seng302.controllers;
import javafx.animation.*; import javafx.animation.AnimationTimer;
import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleDoubleProperty;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.scene.text.Font; import javafx.scene.text.Font;
import javafx.stage.Stage; import seng302.models.BoatGroup;
import seng302.models.*; import seng302.models.Colors;
import seng302.models.RaceObject;
import seng302.models.Yacht;
import seng302.models.mark.*; import seng302.models.mark.*;
import seng302.models.parsers.StreamParser; import seng302.models.parsers.StreamParser;
import seng302.models.parsers.StreamReceiver;
import seng302.models.parsers.packets.BoatPositionPacket;
import seng302.models.parsers.XMLParser; import seng302.models.parsers.XMLParser;
import seng302.models.parsers.XMLParser.RaceXMLObject.CompoundMark; import seng302.models.parsers.XMLParser.RaceXMLObject.CompoundMark;
import seng302.models.parsers.XMLParser.RaceXMLObject.Limit; import seng302.models.parsers.XMLParser.RaceXMLObject.Limit;
import seng302.models.mark.Mark; import seng302.models.parsers.packets.BoatPositionPacket;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.PriorityBlockingQueue;
/** /**
@@ -240,6 +240,17 @@ public class CanvasController {
} }
} }
} }
checkForCourseChanges();
}
private void checkForCourseChanges() {
if (StreamParser.isNewRaceXmlReceived()){
gc.setFill(Color.SKYBLUE);
gc.fillRect(0,0, CANVAS_WIDTH, CANVAS_HEIGHT);
gc.restore();
addRaceBorder();
canvas.toBack();
}
} }
private void move(long id, RaceObject raceObject){ private void move(long id, RaceObject raceObject){
@@ -345,6 +356,8 @@ public class CanvasController {
* Calculates x and y location for every marker that fits it to the canvas the race will be drawn on. * Calculates x and y location for every marker that fits it to the canvas the race will be drawn on.
*/ */
private void fitMarksToCanvas() { private void fitMarksToCanvas() {
//Check is called once to avoid unnecessarily change the course limits once the race is running
StreamParser.isNewRaceXmlReceived();
findMinMaxPoint(); findMinMaxPoint();
double minLonToMaxLon = scaleRaceExtremities(); double minLonToMaxLon = scaleRaceExtremities();
calculateReferencePointLocation(minLonToMaxLon); calculateReferencePointLocation(minLonToMaxLon);
+10 -141
View File
@@ -1,168 +1,37 @@
package seng302.controllers; package seng302.controllers;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import seng302.models.Yacht;
import seng302.models.parsers.StreamParser;
import seng302.models.parsers.XMLParser;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
public class Controller implements Initializable { public class Controller implements Initializable {
@FXML @FXML
private AnchorPane contentPane; private AnchorPane contentPane;
@FXML
private Label timeTillLive;
@FXML
private Button streamButton;
@FXML
private Button switchToRaceViewButton;
@FXML
private TableView<Yacht> teamList;
@FXML
private TableColumn<Yacht, String> boatNameCol;
@FXML
private TableColumn<Yacht, String> shortNameCol;
@FXML
private TableColumn<Yacht, String> countryCol;
@FXML
private TableColumn<Yacht, String> posCol;
@FXML
private Label realTime;
private XMLParser xmlParser; private void setContentPane(String jfxUrl) {
try {
private void setContentPane(String jfxUrl){
try{
contentPane.getChildren().removeAll(); contentPane.getChildren().removeAll();
contentPane.getChildren().clear(); contentPane.getChildren().clear();
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl))); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
} contentPane.getChildren()
catch(javafx.fxml.LoadException e){ .addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
} catch (javafx.fxml.LoadException e) {
System.err.println(e.getCause()); System.err.println(e.getCause());
} } catch (IOException e) {
catch(IOException e){
System.err.println(e); System.err.println(e);
} }
} }
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
//DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
//format.setTimeZone(TimeZone.getTimeZone("GMT-8")); setContentPane("/views/StartScreenView.fxml");
//realTime.setText(format.format(new Date()));
}
/**
* Running a timer to update the livestream status on welcome screen. Update interval is 1 second.
*/
public void startStream() {
if (StreamParser.isStreamStatus()) {
xmlParser = StreamParser.getXmlObject();
streamButton.setVisible(false);
realTime.setVisible(true);
timeTillLive.setVisible(true);
timeTillLive.setTextFill(Color.GREEN);
timeTillLive.setText("Connecting...");
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> {
if (StreamParser.isRaceStarted()) {
switchToRaceView();
timer.cancel();
}
if (StreamParser.isRaceFinished()) {
realTime.setText(StreamParser.getCurrentTimeString());
timeTillLive.setTextFill(Color.RED);
timeTillLive.setText("Race finished! Waiting for new race...");
switchToRaceViewButton.setDisable(true);
} else if (StreamParser.getTimeSinceStart() > 0) {
realTime.setText(StreamParser.getCurrentTimeString());
updateTeamList();
timeTillLive.setTextFill(Color.RED);
switchToRaceViewButton.setDisable(false);
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long.toString(StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
String timerString = "-" + timerMinute + ":" + timerSecond;
timeTillLive.setText(timerString);
} else {
realTime.setText(StreamParser.getCurrentTimeString());
updateTeamList();
timeTillLive.setTextFill(Color.BLACK);
switchToRaceViewButton.setDisable(false);
String timerMinute = Long.toString(-1 * StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long.toString(-1 * StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
String timerString = timerMinute + ":" + timerSecond;
timeTillLive.setText(timerString);
}
});
}
}, 0, 1000);
} else {
timeTillLive.setText("Stream not available.");
timeTillLive.setTextFill(Color.RED);
}
}
public void switchToRaceView() {
setContentPane("/views/RaceView.fxml");
}
private void updateTeamList() {
ObservableList<Yacht> data = FXCollections.observableArrayList();
teamList.setItems(data);
boatNameCol.setCellValueFactory(
new PropertyValueFactory<>("boatName")
);
shortNameCol.setCellValueFactory(
new PropertyValueFactory<>("shortName")
);
countryCol.setCellValueFactory(
new PropertyValueFactory<>("country")
);
posCol.setCellValueFactory(
new PropertyValueFactory<>("position")
);
// if (StreamParser.isRaceStarted()) {
data.addAll(StreamParser.getBoatsPos().values());
// } else {
// for (Yacht boat : StreamParser.getBoats().values()) {
// boat.setPosition("-");
// data.add(boat);
// }
// }
teamList.refresh();
// posCol.setSortType(TableColumn.SortType.ASCENDING);
// teamList.getSortOrder().add(posCol);
// posCol.setSortable(false);
} }
} }
@@ -25,7 +25,7 @@ public class RaceController {
String teamsConfigFile = "/config/teams.xml"; String teamsConfigFile = "/config/teams.xml";
try { try {
race = createRace(raceConfigFile, teamsConfigFile); race = createRace(raceConfigFile, teamsConfigFile); //These config files arent actually used
} catch (Exception e) { } catch (Exception e) {
System.out.println("There was an error creating the race."); System.out.println("There was an error creating the race.");
} }
@@ -1,26 +1,31 @@
package seng302.controllers; package seng302.controllers;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import javafx.animation.Animation;
import javafx.animation.KeyFrame; import javafx.animation.KeyFrame;
import javafx.animation.Timeline; import javafx.animation.Timeline;
import javafx.beans.value.ChangeListener; import javafx.collections.FXCollections;
import javafx.beans.value.ObservableValue; import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox; import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Pane; import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox; import javafx.scene.layout.VBox;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.stage.Stage; import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration; import javafx.util.Duration;
import javafx.util.StringConverter; import javafx.util.StringConverter;
import seng302.controllers.annotations.Annotation;
import seng302.controllers.annotations.ImportantAnnotationController;
import seng302.controllers.annotations.ImportantAnnotationDelegate;
import seng302.controllers.annotations.ImportantAnnotationsState;
import seng302.models.*; import seng302.models.*;
import seng302.models.parsers.ConfigParser;
import seng302.models.parsers.StreamParser; import seng302.models.parsers.StreamParser;
import java.io.IOException; import java.io.IOException;
@@ -29,7 +34,8 @@ import java.util.*;
/** /**
* Created by ptg19 on 29/03/17. * Created by ptg19 on 29/03/17.
*/ */
public class RaceViewController extends Thread{ public class RaceViewController extends Thread implements ImportantAnnotationDelegate {
@FXML @FXML
private VBox positionVbox; private VBox positionVbox;
@FXML @FXML
@@ -43,64 +49,104 @@ public class RaceViewController extends Thread{
@FXML @FXML
private Slider annotationSlider; private Slider annotationSlider;
@FXML @FXML
private Button selectAnnotationBtn;
@FXML
private ComboBox boatSelectionComboBox;
@FXML
private CanvasController includedCanvasController; private CanvasController includedCanvasController;
private ArrayList<Yacht> startingBoats = new ArrayList<>(); private ArrayList<Yacht> startingBoats = new ArrayList<>();
private boolean displayFps; private boolean displayFps;
private Timeline timerTimeline; private Timeline timerTimeline;
private Map<Yacht, TimelineInfo> timelineInfos = new HashMap<>();
private ArrayList<Yacht> boatOrder = new ArrayList<>();
private Race race; private Race race;
private Stage stage; private Stage stage;
public void initialize() { private ImportantAnnotationsState importantAnnotations;
private Yacht selectedBoat;
public void initialize() {
// Load a default important annotation state
importantAnnotations = new ImportantAnnotationsState();
//Initialise race controller
RaceController raceController = new RaceController(); RaceController raceController = new RaceController();
raceController.initializeRace(); raceController.initializeRace();
race = raceController.getRace(); race = raceController.getRace();
for (Yacht boat : race.getBoats()) {
startingBoats.add(boat); startingBoats = new ArrayList<>(Arrays.asList(race.getBoats()));
}
// try{
// initializeTimelines();
// }
// catch (Exception e){
// e.printStackTrace();
// }
includedCanvasController.setup(this); includedCanvasController.setup(this);
includedCanvasController.initializeCanvas(); includedCanvasController.initializeCanvas();
initializeTimer(); initializeUpdateTimer();
initializeSettings(); initialiseFPSCheckBox();
initialiseWindDirection(); initialiseAnnotationSlider();
initialisePositionVBox(); initialiseBoatSelectionComboBox();
//set wind direction!!!!!!! can't find another place to put my code --haoming
// double windDirection = new ConfigParser("/config/config.xml").getWindDirection();
// windDirectionText.setText(String.format("%.1f°", windDirection));
// windArrowText.setRotate(windDirection);
includedCanvasController.timer.start(); includedCanvasController.timer.start();
}
selectAnnotationBtn.setOnAction(event -> {
loadSelectAnnotationView();
private void initializeSettings() {
displayFps = true;
toggleFps.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
displayFps = !displayFps;
}
}); });
}
//SLIFER STUFF BELOW /**
* The important annotations have been changed, update this view
* @param importantAnnotationsState The current state of the selected annotations
*/
public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState) {
this.importantAnnotations = importantAnnotationsState;
setAnnotations((int) annotationSlider.getValue()); // Refresh the displayed annotations
}
/**
* Loads the "select annotations" view in a new window
*/
private void loadSelectAnnotationView() {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
Stage stage = new Stage();
// Set controller
ImportantAnnotationController controller = new ImportantAnnotationController(this,
stage);
fxmlLoader.setController(controller);
// Load FXML and set CSS
fxmlLoader
.setLocation(getClass().getResource("/views/importantAnnotationSelectView.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 469, 248);
scene.getStylesheets().add(getClass().getResource("/css/master.css").toString());
stage.initStyle(StageStyle.UNDECORATED);
stage.setScene(scene);
stage.show();
controller.loadState(importantAnnotations);
} catch (IOException e) {
e.printStackTrace();
}
}
private void initialiseFPSCheckBox() {
displayFps = true;
toggleFps.selectedProperty().addListener(
(observable, oldValue, newValue) -> displayFps = !displayFps);
}
private void initialiseAnnotationSlider() {
annotationSlider.setLabelFormatter(new StringConverter<Double>() { annotationSlider.setLabelFormatter(new StringConverter<Double>() {
@Override @Override
public String toString(Double n) { public String toString(Double n) {
if (n == 0) return "None"; if (n == 0) {
if (n == 1) return "Low"; return "None";
if (n == 2) return "Medium"; }
if (n == 3) return "All"; if (n == 1) {
return "Important";
}
if (n == 2) {
return "All";
}
return "All"; return "All";
} }
@@ -110,38 +156,41 @@ public class RaceViewController extends Thread{
switch (s) { switch (s) {
case "None": case "None":
return 0d; return 0d;
case "Low": case "Important":
return 1d; return 1d;
case "Medium":
return 2d;
case "All": case "All":
return 3d; return 2d;
default: default:
return 3d; return 2d;
} }
} }
}); });
annotationSlider.valueProperty().addListener((obs, oldval, newVal) -> annotationSlider.valueProperty().addListener((obs, oldval, newVal) ->
setAnnotations((int)annotationSlider.getValue())); setAnnotations((int) annotationSlider.getValue()));
annotationSlider.setValue(3); annotationSlider.setValue(2);
} }
private void initializeTimer(){
/**
* Initalises a timer which updates elements of the RaceView such as wind direction, boat
* orderings etc.. which are dependent on the info from the stream parser constantly.
* Updates of each of these attributes are called ONCE EACH SECOND
*/
private void initializeUpdateTimer() {
timerTimeline = new Timeline(); timerTimeline = new Timeline();
timerTimeline.setCycleCount(Timeline.INDEFINITE); timerTimeline.setCycleCount(Timeline.INDEFINITE);
// Run timer update every second // Run timer update every second
timerTimeline.getKeyFrames().add( timerTimeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(1), new KeyFrame(Duration.seconds(1),
event -> { event -> {
if (StreamParser.isRaceFinished()) { updateRaceTime();
timerLabel.setFill(Color.RED); updateWindDirection();
timerLabel.setText("Race Finished!"); updateOrder();
} else { updateBoatSelectionComboBox();
timerLabel.setText(currentTimer());
}
}) })
); );
@@ -149,123 +198,84 @@ public class RaceViewController extends Thread{
timerTimeline.playFromStart(); timerTimeline.playFromStart();
} }
private void initialiseWindDirection() {
Timeline windDirTimeline = new Timeline();
windDirTimeline.setCycleCount(Timeline.INDEFINITE);
windDirTimeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(1),
event -> {
windDirectionText.setText(String.format("%.1f°", StreamParser.getWindDirection()));
windArrowText.setRotate(StreamParser.getWindDirection());
})
);
windDirTimeline.playFromStart();
}
private void initialisePositionVBox() {
Timeline posVBoxTimeline = new Timeline();
posVBoxTimeline.setCycleCount(Timeline.INDEFINITE);
posVBoxTimeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(1),
event -> {
showOrder();
})
);
posVBoxTimeline.playFromStart();
}
/** /**
* Generates time line for each boat, and stores time time into timelineInfos hash map * Updates the wind direction arrow and text as from info from the StreamParser
*/ */
private void initializeTimelines() { private void updateWindDirection() {
HashMap<Yacht, List> boat_events = race.getEvents(); windDirectionText.setText(String.format("%.1f°", StreamParser.getWindDirection()));
for (Yacht boat : boat_events.keySet()) { windArrowText.setRotate(StreamParser.getWindDirection());
startingBoats.add(boat);
// // x, y are the real time coordinates
// DoubleProperty x = new SimpleDoubleProperty();
// DoubleProperty y = new SimpleDoubleProperty();
//
// List<KeyFrame> keyFrames = new ArrayList<>();
// List<Event> events = boat_events.get(boat);
//
// // iterates all events and convert each event to keyFrame, then add them into a list
// for (Event event : events) {
// if (event.getIsFinishingEvent()) {
// keyFrames.add(
// new KeyFrame(Duration.seconds(event.getTime()),
// onFinished -> {race.setBoatFinished(boat); handleEvent(event);},
// new KeyValue(x, event.getThisMark().getLatitude()),
// new KeyValue(y, event.getThisMark().getLongitude())
// )
// );
// } else {
// keyFrames.add(
// new KeyFrame(Duration.seconds(event.getTime()),
// onFinished ->{
// handleEvent(event);
// boat.setHeading(event.getBoatHeading());
// },
// new KeyValue(x, event.getThisMark().getLatitude()),
// new KeyValue(y, event.getThisMark().getLongitude())
// )
// );
// }
// }
// timelineInfos.put(boat, new TimelineInfo(new Timeline(keyFrames.toArray(new KeyFrame[keyFrames.size()])), x, y));
}
setRaceDuration();
} }
private void setRaceDuration(){
Double maxDuration = 0.0;
Timeline maxTimeline = null;
for (TimelineInfo timelineInfo : timelineInfos.values()) { /**
* Updates the clock for the race
Timeline timeline = timelineInfo.getTimeline(); */
if (timeline.getTotalDuration().toMillis() >= maxDuration) { private void updateRaceTime() {
maxDuration = timeline.getTotalDuration().toMillis(); if (StreamParser.isRaceFinished()) {
maxTimeline = timeline; timerLabel.setFill(Color.RED);
timerLabel.setText("Race Finished!");
} else {
timerLabel.setText(getTimeSinceStartOfRace());
}
} }
// Timelines are paused by default
timeline.play(); /**
timeline.pause(); * Grabs the boats currently in the race as from the StreamParser and sets them to be selectable
* in the boat selection combo box
*/
private void updateBoatSelectionComboBox() {
ObservableList<Yacht> observableBoats = FXCollections
.observableArrayList(StreamParser.getBoatsPos().values());
boatSelectionComboBox.setItems(observableBoats);
} }
maxTimeline.setOnFinished(event -> {
race.setRaceFinished(); /**
loadRaceResultView(); * Updates the order of the boats as from the StreamParser and sets them in the boat order
* section
*/
private void updateOrder() {
positionVbox.getChildren().clear();
positionVbox.getChildren().removeAll();
positionVbox.getStylesheets().add(getClass().getResource("/css/master.css").toString());
for (Yacht boat : StreamParser.getBoatsPos().values()) {
if (boat.getBoatStatus() == 3) { // 3 is finish status
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " (Finished)");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
positionVbox.getChildren().add(textToAdd);
} else {
Text textToAdd = new Text(boat.getPosition() + ". " +
boat.getShortName() + " ");
textToAdd.setFill(Paint.valueOf("#d3d3d3"));
textToAdd.setStyle("");
positionVbox.getChildren().add(textToAdd);
}
}
}
/**
* Initialised the combo box with any boats currently in the race and adds the required listener
* for the combobox to take action upon selection
*/
private void initialiseBoatSelectionComboBox() {
updateBoatSelectionComboBox();
boatSelectionComboBox.valueProperty().addListener((observable, oldValue, newValue) -> {
//This listener is fired whenever the combo box changes. This means when the values are updated
//We dont want to set the selected value if the values are updated but nothing clicked (null)
if (newValue != null && newValue != selectedBoat) {
Yacht thisYacht = (Yacht) newValue;
setSelectedBoat(thisYacht);
}
}); });
} }
/**
* Play each boats timerTimeline
*/
public void playTimelines(){
for (TimelineInfo timelineInfo : timelineInfos.values()){
Timeline timeline = timelineInfo.getTimeline();
if (timeline.getStatus() == Animation.Status.PAUSED){
timeline.play();
}
}
}
/**
* Pause each boats timerTimeline
*/
public void pauseTimelines(){
for (TimelineInfo timelineInfo : timelineInfos.values()){
Timeline timeline = timelineInfo.getTimeline();
if (timeline.getStatus() == Animation.Status.RUNNING){
timeline.pause();
}
}
}
/** /**
* Display the list of boats in the order they finished the race * Display the list of boats in the order they finished the race
@@ -286,39 +296,6 @@ public class RaceViewController extends Thread{
} }
} }
public void handleEvent(Event event) {
Yacht boat = event.getBoat();
boatOrder.remove(boat);
boat.setMarkLastPast(event.getMarkPosInRace());
boatOrder.add(boat);
boatOrder.sort(new Comparator<Yacht>() {
@Override
public int compare(Yacht b1, Yacht b2) {
return b2.getMarkLastPast() - b1.getMarkLastPast();
}
});
showOrder();
}
private void showOrder() {
positionVbox.getChildren().clear();
positionVbox.getChildren().removeAll();
// for (Boat boat : boatOrder) {
// positionVbox.getChildren().add(new Text(boat.getShortName() + " " + boat.getSpeedInKnots() + " Knots"));
// }
for (Yacht boat : StreamParser.getBoatsPos().values()) {
if (boat.getBoatStatus() == 3) { // 3 is finish status
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
boat.getShortName() + " (Finished)"));
} else {
positionVbox.getChildren().add(new Text(boat.getPosition() + ". " +
boat.getShortName() + " "));
}
}
}
/** /**
* Convert seconds to a string of the format mm:ss * Convert seconds to a string of the format mm:ss
@@ -333,7 +310,7 @@ public class RaceViewController extends Thread{
return String.format("%02d:%02d", time / 60, time % 60); return String.format("%02d:%02d", time / 60, time % 60);
} }
private String currentTimer() { private String getTimeSinceStartOfRace() {
String timerString = "0:00"; String timerString = "0:00";
if (StreamParser.getTimeSinceStart() > 0) { if (StreamParser.getTimeSinceStart() > 0) {
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60); String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60);
@@ -353,12 +330,6 @@ public class RaceViewController extends Thread{
return timerString; return timerString;
} }
public void stopTimer() {
timerTimeline.stop();
}
public void startTimer() {
timerTimeline.play();
}
public boolean isDisplayFps() { public boolean isDisplayFps() {
return displayFps; return displayFps;
@@ -368,56 +339,83 @@ public class RaceViewController extends Thread{
return race; return race;
} }
public Map<Yacht, TimelineInfo> getTimelineInfos() {
return timelineInfos; /**
* Display the important annotations for a specific BoatGroup
* @param bg The boat group to set the annotations for
*/
private void setBoatGroupImportantAnnotations(BoatGroup bg) {
if (importantAnnotations.getAnnotationState(Annotation.NAME)) {
bg.setTeamNameObjectVisible(true);
} else {
bg.setTeamNameObjectVisible(false);
} }
public ArrayList<Yacht> getStartingBoats(){ if (importantAnnotations.getAnnotationState(Annotation.SPEED)) {
return startingBoats; bg.setVelocityObjectVisible(true);
} else {
bg.setVelocityObjectVisible(false);
} }
if (importantAnnotations.getAnnotationState(Annotation.TRACK)) {
bg.setLineGroupVisible(true);
} else {
bg.setLineGroupVisible(false);
}
if (importantAnnotations.getAnnotationState(Annotation.WAKE)) {
bg.setWakeVisible(true);
} else {
bg.setWakeVisible(false);
}
if (importantAnnotations.getAnnotationState(Annotation.ESTTIMETONEXTMARK)) {
bg.setEstTimeToNextMarkObjectVisible(true);
} else {
bg.setEstTimeToNextMarkObjectVisible(false);
}
if (importantAnnotations.getAnnotationState(Annotation.LEGTIME)) {
bg.setLegTimeObjectVisible(true);
} else {
bg.setLegTimeObjectVisible(false);
}
}
private void setAnnotations(Integer annotationLevel) { private void setAnnotations(Integer annotationLevel) {
switch (annotationLevel) { switch (annotationLevel) {
// No Annotations
case 0: case 0:
for (RaceObject ro : includedCanvasController.getRaceObjects()) { for (RaceObject ro : includedCanvasController.getRaceObjects()) {
if(ro instanceof BoatGroup) { if (ro instanceof BoatGroup) {
BoatGroup bg = (BoatGroup) ro; BoatGroup bg = (BoatGroup) ro;
bg.setTeamNameObjectVisible(false); bg.setTeamNameObjectVisible(false);
bg.setVelocityObjectVisible(false); bg.setVelocityObjectVisible(false);
bg.setEstTimeToNextMarkObjectVisible(false);
bg.setLegTimeObjectVisible(false);
bg.setLineGroupVisible(false); bg.setLineGroupVisible(false);
bg.setWakeVisible(false); bg.setWakeVisible(false);
} }
} }
break; break;
// Important Annotations
case 1: case 1:
for (RaceObject ro : includedCanvasController.getRaceObjects()) { for (RaceObject ro : includedCanvasController.getRaceObjects()) {
if(ro instanceof BoatGroup) { if (ro instanceof BoatGroup) {
BoatGroup bg = (BoatGroup) ro; BoatGroup bg = (BoatGroup) ro;
bg.setTeamNameObjectVisible(true); setBoatGroupImportantAnnotations(bg);
bg.setVelocityObjectVisible(false);
bg.setLineGroupVisible(false);
bg.setWakeVisible(false);
} }
} }
break; break;
// All Annotations
case 2: case 2:
for (RaceObject ro : includedCanvasController.getRaceObjects()) { for (RaceObject ro : includedCanvasController.getRaceObjects()) {
if(ro instanceof BoatGroup) { if (ro instanceof BoatGroup) {
BoatGroup bg = (BoatGroup) ro;
bg.setTeamNameObjectVisible(true);
bg.setVelocityObjectVisible(false);
bg.setLineGroupVisible(true);
bg.setWakeVisible(false);
}
}
break;
case 3:
for (RaceObject ro : includedCanvasController.getRaceObjects()) {
if(ro instanceof BoatGroup) {
BoatGroup bg = (BoatGroup) ro; BoatGroup bg = (BoatGroup) ro;
bg.setTeamNameObjectVisible(true); bg.setTeamNameObjectVisible(true);
bg.setVelocityObjectVisible(true); bg.setVelocityObjectVisible(true);
bg.setEstTimeToNextMarkObjectVisible(true);
bg.setLegTimeObjectVisible(true);
bg.setLineGroupVisible(true); bg.setLineGroupVisible(true);
bg.setWakeVisible(true); bg.setWakeVisible(true);
} }
@@ -426,11 +424,33 @@ public class RaceViewController extends Thread{
} }
} }
void setStage (Stage stage) {
/**
* Sets all the annotations of the selected boat to be visible and all others to be hidden
*
* @param yacht The yacht for which we want to view all annotations
*/
private void setSelectedBoat(Yacht yacht) {
for (RaceObject ro : includedCanvasController.getRaceObjects()) {
if (ro instanceof BoatGroup) {
BoatGroup bg = (BoatGroup) ro;
//We need to iterate over all race groups to get the matching boat group belonging to this boat if we
//are to toggle its annotations, there is no other backwards knowledge of a yacht to its boatgroup.
if (bg.getBoat().getHullID().equals(yacht.getHullID())) {
bg.setIsSelected(true);
selectedBoat = yacht;
} else {
bg.setIsSelected(false);
}
}
}
}
void setStage(Stage stage) {
this.stage = stage; this.stage = stage;
} }
Stage getStage () { Stage getStage() {
return stage; return stage;
} }
} }
@@ -0,0 +1,160 @@
package seng302.controllers;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import seng302.models.Yacht;
import seng302.models.parsers.StreamParser;
public class StartScreenController implements Initializable {
@FXML
private GridPane gridPane;
@FXML
private Label timeTillLive;
@FXML
private Button streamButton;
@FXML
private Button switchToRaceViewButton;
@FXML
private TableView<Yacht> teamList;
@FXML
private TableColumn<Yacht, String> boatNameCol;
@FXML
private TableColumn<Yacht, String> shortNameCol;
@FXML
private TableColumn<Yacht, String> countryCol;
@FXML
private TableColumn<Yacht, String> posCol;
@FXML
private Label realTime;
private boolean switchedToRaceView = false;
private void setContentPane(String jfxUrl){
try{
// get the main controller anchor pane (MainView.fxml)
AnchorPane contentPane = (AnchorPane) gridPane.getParent();
contentPane.getChildren().removeAll();
contentPane.getChildren().clear();
contentPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
contentPane.getChildren().addAll((Pane) FXMLLoader.load(getClass().getResource(jfxUrl)));
}
catch(javafx.fxml.LoadException e){
System.err.println(e.getCause());
}
catch(IOException e){
System.err.println(e);
}
}
@Override
public void initialize(URL location, ResourceBundle resources) {
gridPane.getStylesheets().add(getClass().getResource("/css/master.css").toString());
teamList.getStylesheets().add(getClass().getResource("/css/master.css").toString());
}
/**
* Running a timer to update the livestream status on welcome screen. Update interval is 1 second.
*/
public void startStream() {
if (StreamParser.isStreamStatus()) {
streamButton.setVisible(false);
realTime.setVisible(true);
timeTillLive.setVisible(true);
timeTillLive.setTextFill(Color.GREEN);
timeTillLive.setText("Connecting...");
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
Platform.runLater(() -> {
if (StreamParser.isRaceStarted()) {
if (!switchedToRaceView) {
switchToRaceView();
}
timer.cancel();
}
if (StreamParser.isRaceFinished()) {
realTime.setText(StreamParser.getCurrentTimeString());
timeTillLive.setTextFill(Color.RED);
timeTillLive.setText("Race finished! Waiting for new race...");
switchToRaceViewButton.setDisable(true);
} else if (StreamParser.getTimeSinceStart() > 0) {
realTime.setText(StreamParser.getCurrentTimeString());
updateTeamList();
timeTillLive.setTextFill(Color.RED);
switchToRaceViewButton.setDisable(false);
String timerMinute = Long.toString(StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long.toString(StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
String timerString = "-" + timerMinute + ":" + timerSecond;
timeTillLive.setText(timerString);
} else {
realTime.setText(StreamParser.getCurrentTimeString());
updateTeamList();
timeTillLive.setTextFill(Color.BLACK);
switchToRaceViewButton.setDisable(false);
String timerMinute = Long.toString(-1 * StreamParser.getTimeSinceStart() / 60);
String timerSecond = Long.toString(-1 * StreamParser.getTimeSinceStart() % 60);
if (timerSecond.length() == 1) {
timerSecond = "0" + timerSecond;
}
String timerString = timerMinute + ":" + timerSecond;
timeTillLive.setText(timerString);
}
});
}
}, 0, 1000);
} else {
timeTillLive.setText("Stream not available.");
timeTillLive.setTextFill(Color.RED);
}
}
public void switchToRaceView() {
switchedToRaceView = true;
setContentPane("/views/RaceView.fxml");
}
private void updateTeamList() {
ObservableList<Yacht> data = FXCollections.observableArrayList();
teamList.setItems(data);
boatNameCol.setCellValueFactory(
new PropertyValueFactory<>("boatName")
);
shortNameCol.setCellValueFactory(
new PropertyValueFactory<>("shortName")
);
countryCol.setCellValueFactory(
new PropertyValueFactory<>("country")
);
posCol.setCellValueFactory(
new PropertyValueFactory<>("position")
);
data.addAll(StreamParser.getBoatsPos().values());
teamList.refresh();
}
}
@@ -0,0 +1,13 @@
package seng302.controllers.annotations;
/**
* Annotations the user can select as important
*/
public enum Annotation {
SPEED,
WAKE,
TRACK,
NAME,
ESTTIMETONEXTMARK,
LEGTIME
}
@@ -0,0 +1,145 @@
package seng302.controllers.annotations;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import seng302.controllers.RaceViewController;
import seng302.controllers.annotations.Annotation;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
public class ImportantAnnotationController implements Initializable {
/*
* JavaFX Outlets
*/
@FXML
private CheckBox boatWakeSelect;
@FXML
private CheckBox boatSpeedSelect;
@FXML
private CheckBox boatTrackSelect;
@FXML
private CheckBox boatNameSelect;
@FXML
private CheckBox boatEstTimeToNextMarkSelect;
@FXML
private CheckBox boatElapsedTimeSelect;
@FXML
private AnchorPane annotationSelectWindow;
@FXML
private Button closeButton;
private ImportantAnnotationDelegate delegate;
private ImportantAnnotationsState importantAnnotationsState;
private Stage stage;
public ImportantAnnotationController(ImportantAnnotationDelegate delegate, Stage stage) {
this.delegate = delegate;
importantAnnotationsState = new ImportantAnnotationsState();
this.stage = stage;
}
/**
* Sets whether or not an annotation is considered important, then
* sends an update to the delegate
*
* @param annotation The annotation
* @param isSet True if annotation is important
*/
private void setAnnotation(Annotation annotation, Boolean isSet) {
importantAnnotationsState.setAnnotationState(annotation, isSet);
sendUpdate();
}
/**
* Sends an update to the delegate when the important
* annotations have changed
*/
private void sendUpdate() {
this.delegate.importantAnnotationsChanged(importantAnnotationsState);
}
/**
* Load the current state of the 'important annotations'
*
* @param currentState hashmap containing the states of each annotation
*/
public void loadState(ImportantAnnotationsState currentState) {
this.importantAnnotationsState = currentState;
// Initialise checkboxes
for (Annotation annotation : importantAnnotationsState.getAnnotations()) {
switch (annotation) {
case WAKE:
boatWakeSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case SPEED:
boatSpeedSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case TRACK:
boatTrackSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case NAME:
boatNameSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case ESTTIMETONEXTMARK:
boatEstTimeToNextMarkSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
break;
case LEGTIME:
boatElapsedTimeSelect
.setSelected(importantAnnotationsState.getAnnotationState(annotation));
default:
break;
}
}
}
/**
* View did load
*
* @param location .
* @param resources .
*/
@Override
public void initialize(URL location, ResourceBundle resources) {
boatWakeSelect
.setOnAction(event -> setAnnotation(Annotation.WAKE, boatWakeSelect.isSelected()));
boatSpeedSelect
.setOnAction(event -> setAnnotation(Annotation.SPEED, boatSpeedSelect.isSelected()));
boatTrackSelect
.setOnAction(event -> setAnnotation(Annotation.TRACK, boatTrackSelect.isSelected()));
boatNameSelect
.setOnAction(event -> setAnnotation(Annotation.NAME, boatNameSelect.isSelected()));
boatEstTimeToNextMarkSelect.setOnAction(event -> setAnnotation(Annotation.ESTTIMETONEXTMARK,
boatEstTimeToNextMarkSelect.isSelected()));
boatElapsedTimeSelect.setOnAction(
event -> setAnnotation(Annotation.LEGTIME, boatElapsedTimeSelect.isSelected()));
closeButton.setOnAction(event -> stage.close());
}
}
@@ -0,0 +1,16 @@
package seng302.controllers.annotations;
/**
* An ImportantAnnotationDelegate handles updating the important annotations
* displayed to the user on behalf of the ImportantAnnotationController
*/
public interface ImportantAnnotationDelegate {
/**
* The important annotations have been changed, update the
* annotations displayed to the user
* @param importantAnnotationsState The current state of the selected annotations
*/
void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState);
}
@@ -0,0 +1,52 @@
package seng302.controllers.annotations;
import java.util.HashMap;
import java.util.Map;
public class ImportantAnnotationsState {
public static final Boolean DEFAULT_ANNOTATION_STATE = true;
private Map<Annotation, Boolean> currentState;
/**
* Stores the users preference for the annotations
* they consider to be important
*/
public ImportantAnnotationsState(){
this.currentState = new HashMap<>();
initialiseState();
}
/**
* Set each annotation to the default annotation state
*/
private void initialiseState(){
for (Annotation annotation : getAnnotations()){
currentState.put(annotation, DEFAULT_ANNOTATION_STATE);
}
}
/**
* Sets the state (visibility) of an annotation
* @param annotation The annotation to set
* @param visible Whether or not the annotation should be visible
*/
public void setAnnotationState(Annotation annotation, Boolean visible){
this.currentState.put(annotation, visible);
}
/**
* Returns the state (visibility) of a specific annotation
* @param annotation The annotation to check
* @return True if visible, else false
*/
public Boolean getAnnotationState(Annotation annotation){
return this.currentState.containsKey(annotation) && this.currentState.get(annotation);
}
/**
* @return Return an array containing all defined annotations
*/
public Annotation[] getAnnotations(){
return Annotation.class.getEnumConstants();
}
}
+176 -83
View File
@@ -1,6 +1,7 @@
package seng302.models; package seng302.models;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Line; import javafx.scene.shape.Line;
@@ -8,24 +9,32 @@ import javafx.scene.shape.Polygon;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import javafx.stage.Stage; import javafx.stage.Stage;
import seng302.models.parsers.StreamParser;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
* BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat. * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2
* It contains a single polygon for the boat, a group of lines to show it's path, a wake object and two text labels to * dimensional boat. It contains a single polygon for the boat, a group of lines to show it's path,
* annotate the boat teams name and the boats velocity. The boat will update it's position onscreen everytime * a wake object and two text labels to annotate the boat teams name and the boats velocity. The
* UpdatePosition is called unless the window is minimized in which case it attempts to store animations and apply them * boat will update it's position onscreen everytime UpdatePosition is called unless the window is
* when the window is maximised. * minimized in which case it attempts to store animations and apply them when the window is
* maximised.
*/ */
public class BoatGroup extends RaceObject{ public class BoatGroup extends RaceObject {
//Constants for drawing //Constants for drawing
private static final double TEAMNAME_X_OFFSET = 10d; private static final double TEAMNAME_X_OFFSET = 10d;
private static final double TEAMNAME_Y_OFFSET = -15d; private static final double TEAMNAME_Y_OFFSET = -29d;
private static final double VELOCITY_X_OFFSET = 10d; private static final double VELOCITY_X_OFFSET = 10d;
private static final double VELOCITY_Y_OFFSET = -5d; private static final double VELOCITY_Y_OFFSET = -17d;
private static final double ESTTIMETONEXTMARK_X_OFFSET = 10d;
private static final double ESTTIMETONEXTMARK_Y_OFFSET = -5d;
private static final double LEGTIME_X_OFFSET = 10d;
private static final double LEGTIME_Y_OFFSET = 7d;
private static final double BOAT_HEIGHT = 15d; private static final double BOAT_HEIGHT = 15d;
private static final double BOAT_WIDTH = 10d; private static final double BOAT_WIDTH = 10d;
//Variables for boat logic. //Variables for boat logic.
@@ -38,51 +47,84 @@ public class BoatGroup extends RaceObject{
private Polygon boatPoly; private Polygon boatPoly;
private Text teamNameObject; private Text teamNameObject;
private Text velocityObject; private Text velocityObject;
private Text estTimeToNextMarkObject;
private Text legTimeObject;
private Wake wake; private Wake wake;
private boolean isSelected = true; //Boats annotations are visible by default at the start
//Handles boat moving when connecting to a stream //Handles boat moving when connecting to a stream
private boolean setToInitialLocation = false; private boolean setToInitialLocation = false;
private boolean destinationSet; private boolean destinationSet;
//Variables for handling minimization //Variables for handling minimization
private Stage stage; private Stage stage;
private boolean isMaximized= true; private boolean isMaximized = true;
private List<Line> lineStorage = new ArrayList<>(); private List<Line> lineStorage = new ArrayList<>();
private int setCallCount = 5; private int setCallCount = 5;
/** /**
* Creates a BoatGroup with the default triangular boat polygon. * Creates a BoatGroup with the default triangular boat polygon.
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used to tell which *
* BoatGroup to update. * @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used
* to tell which BoatGroup to update.
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
*/ */
public BoatGroup (Yacht boat, Color color){ public BoatGroup(Yacht boat, Color color) {
this.boat = boat; this.boat = boat;
initChildren(color); initChildren(color);
} }
/** /**
* Creates a BoatGroup with the boat being the default polygon. The head of the boat should be at point (0,0). * Creates a BoatGroup with the boat being the default polygon. The head of the boat should be
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used to tell which * at point (0,0).
* BoatGroup to update. *
* @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used
* to tell which BoatGroup to update.
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon. * @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat
* polygon.
*/ */
public BoatGroup (Yacht boat, Color color, double... points) public BoatGroup(Yacht boat, Color color, double... points) {
{
this.boat = boat; this.boat = boat;
initChildren(color, points); initChildren(color, points);
} }
/** /**
* Creates the javafx objects that will be the in the group by default. * Creates the javafx objects that will be the in the group by default.
*
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
* @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat polygon. * @param points An array of co-ordinates x1,y1,x2,y2,x3,y3... that will make up the boat
* polygon.
*/ */
private void initChildren (Color color, double... points) { private void initChildren(Color color, double... points) {
boatPoly = new Polygon(points); boatPoly = new Polygon(points);
boatPoly.setFill(color); boatPoly.setFill(color);
boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
boatPoly.setOnMouseExited(event -> boatPoly.setFill(color));
boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected));
boatPoly.setCache(true);
boatPoly.setCacheHint(CacheHint.SPEED);
teamNameObject = new Text(boat.getShortName()); teamNameObject = new Text(boat.getShortName());
teamNameObject.setCache(true);
teamNameObject.setCacheHint(CacheHint.SPEED);
velocityObject = new Text(String.valueOf(boat.getVelocity())); velocityObject = new Text(String.valueOf(boat.getVelocity()));
DateFormat format = new SimpleDateFormat("mm:ss");
// TODO: 21/05/17 make a nice way of checking for this to be null
estTimeToNextMarkObject = new Text("Next mark: null");
if (boat.getEstimateTimeAtNextMark() != null) {
String timeToNextMark = format
.format(boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject = new Text("Next mark: " + timeToNextMark);
}
if (boat.getMarkRoundingTime() != null) {
String elapsedTime = format
.format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundingTime());
legTimeObject = new Text("Last mark: " + elapsedTime);
} else {
legTimeObject = new Text("Last mark: -");
}
velocityObject.setCache(true);
velocityObject.setCacheHint(CacheHint.SPEED);
teamNameObject.setX(TEAMNAME_X_OFFSET); teamNameObject.setX(TEAMNAME_X_OFFSET);
teamNameObject.setY(TEAMNAME_Y_OFFSET); teamNameObject.setY(TEAMNAME_Y_OFFSET);
@@ -93,15 +135,27 @@ public class BoatGroup extends RaceObject{
velocityObject.relocate(velocityObject.getX(), velocityObject.getY()); velocityObject.relocate(velocityObject.getX(), velocityObject.getY());
destinationSet = false; destinationSet = false;
estTimeToNextMarkObject.setX(ESTTIMETONEXTMARK_X_OFFSET);
estTimeToNextMarkObject.setY(ESTTIMETONEXTMARK_Y_OFFSET);
estTimeToNextMarkObject
.relocate(estTimeToNextMarkObject.getX(), estTimeToNextMarkObject.getY());
legTimeObject.setX(LEGTIME_X_OFFSET);
legTimeObject.setY(LEGTIME_Y_OFFSET);
legTimeObject.relocate(legTimeObject.getX(), legTimeObject.getY());
wake = new Wake(0, -BOAT_HEIGHT); wake = new Wake(0, -BOAT_HEIGHT);
super.getChildren().addAll(teamNameObject, velocityObject, boatPoly); super.getChildren()
.addAll(teamNameObject, velocityObject, boatPoly, estTimeToNextMarkObject,
legTimeObject);
} }
/** /**
* Creates the javafx objects that will be the in the group by default. * Creates the javafx objects that will be the in the group by default.
*
* @param color The colour of the boat polygon and the trailing line. * @param color The colour of the boat polygon and the trailing line.
*/ */
private void initChildren (Color color) { private void initChildren(Color color) {
initChildren(color, initChildren(color,
-BOAT_WIDTH / 2, BOAT_HEIGHT / 2, -BOAT_WIDTH / 2, BOAT_HEIGHT / 2,
0.0, -BOAT_HEIGHT / 2, 0.0, -BOAT_HEIGHT / 2,
@@ -109,7 +163,9 @@ public class BoatGroup extends RaceObject{
} }
/** /**
* Moves the boat and its children annotations from its current coordinates by specified amounts. * Moves the boat and its children annotations from its current coordinates by specified
* amounts.
*
* @param dx The amount to move the X coordinate by * @param dx The amount to move the X coordinate by
* @param dy The amount to move the Y coordinate by * @param dy The amount to move the Y coordinate by
*/ */
@@ -120,6 +176,10 @@ public class BoatGroup extends RaceObject{
teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy); teamNameObject.setLayoutY(teamNameObject.getLayoutY() + dy);
velocityObject.setLayoutX(velocityObject.getLayoutX() + dx); velocityObject.setLayoutX(velocityObject.getLayoutX() + dx);
velocityObject.setLayoutY(velocityObject.getLayoutY() + dy); velocityObject.setLayoutY(velocityObject.getLayoutY() + dy);
estTimeToNextMarkObject.setLayoutX(estTimeToNextMarkObject.getLayoutX() + dx);
estTimeToNextMarkObject.setLayoutY(estTimeToNextMarkObject.getLayoutY() + dy);
legTimeObject.setLayoutX(legTimeObject.getLayoutX() + dx);
legTimeObject.setLayoutY(legTimeObject.getLayoutY() + dy);
wake.setLayoutX(wake.getLayoutX() + dx); wake.setLayoutX(wake.getLayoutX() + dx);
wake.setLayoutY(wake.getLayoutY() + dy); wake.setLayoutY(wake.getLayoutY() + dy);
rotateTo(rotation + currentRotation); rotateTo(rotation + currentRotation);
@@ -127,27 +187,33 @@ public class BoatGroup extends RaceObject{
/** /**
* Moves the boat and its children annotations to coordinates specified * Moves the boat and its children annotations to coordinates specified
*
* @param x The X coordinate to move the boat to * @param x The X coordinate to move the boat to
* @param y The Y coordinate to move the boat to * @param y The Y coordinate to move the boat to
* @param rotation The heading in degrees from north the boat should rotate to. * @param rotation The heading in degrees from north the boat should rotate to.
*/ */
public void moveTo (double x, double y, double rotation) { public void moveTo(double x, double y, double rotation) {
rotateTo(rotation); rotateTo(rotation);
moveTo(x, y); moveTo(x, y);
} }
/** /**
* Moves the boat and its children annotations to coordinates specified * Moves the boat and its children annotations to coordinates specified
*
* @param x The X coordinate to move the boat to * @param x The X coordinate to move the boat to
* @param y The Y coordinate to move the boat to * @param y The Y coordinate to move the boat to
*/ */
public void moveTo (double x, double y) { public void moveTo(double x, double y) {
boatPoly.setLayoutX(x); boatPoly.setLayoutX(x);
boatPoly.setLayoutY(y); boatPoly.setLayoutY(y);
teamNameObject.setLayoutX(x); teamNameObject.setLayoutX(x);
teamNameObject.setLayoutY(y); teamNameObject.setLayoutY(y);
velocityObject.setLayoutX(x); velocityObject.setLayoutX(x);
velocityObject.setLayoutY(y); velocityObject.setLayoutY(y);
estTimeToNextMarkObject.setLayoutX(x);
estTimeToNextMarkObject.setLayoutY(y);
legTimeObject.setLayoutX(x);
legTimeObject.setLayoutY(y);
wake.setLayoutX(x); wake.setLayoutX(x);
wake.setLayoutY(y); wake.setLayoutY(y);
wake.rotate(currentRotation); wake.rotate(currentRotation);
@@ -155,11 +221,11 @@ public class BoatGroup extends RaceObject{
/** /**
* Updates the position of all graphics in the BoatGroup based off of the given time interval. * Updates the position of all graphics in the BoatGroup based off of the given time interval.
* @param timeInterval The interval, in milliseconds, the boat should update it's position based on. *
* @param timeInterval The interval, in milliseconds, the boat should update it's position based
* on.
*/ */
public void updatePosition (long timeInterval) { public void updatePosition(long timeInterval) {
//Calculate the movement of the boat.
if (isMaximized) {
double dx = pixelVelocityX * timeInterval; double dx = pixelVelocityX * timeInterval;
double dy = pixelVelocityY * timeInterval; double dy = pixelVelocityY * timeInterval;
double rotation = rotationalVelocity * timeInterval; double rotation = rotationalVelocity * timeInterval;
@@ -176,7 +242,7 @@ public class BoatGroup extends RaceObject{
boatPoly.getLayoutY() boatPoly.getLayoutY()
); );
l.getStrokeDashArray().setAll(3d, 7d); l.getStrokeDashArray().setAll(3d, 7d);
l.setStroke(boatPoly.getFill()); l.setStroke(boat.getColour());
lineGroup.getChildren().add(l); lineGroup.getChildren().add(l);
} }
if (destinationSet) { //Only begin drawing after the first destination is set if (destinationSet) { //Only begin drawing after the first destination is set
@@ -185,45 +251,55 @@ public class BoatGroup extends RaceObject{
} }
wake.updatePosition(timeInterval); wake.updatePosition(timeInterval);
} }
}
/** /**
* Sets the destination of the boat and the headng it should have once it reaches * Sets the destination of the boat and the headng it should have once it reaches
*
* @param newXValue The X co-ordinate the boat needs to move to. * @param newXValue The X co-ordinate the boat needs to move to.
* @param newYValue The Y co-ordinate the boat needs to move to. * @param newYValue The Y co-ordinate the boat needs to move to.
* @param rotation Rotation to move graphics to. * @param rotation Rotation to move graphics to.
* @param raceIds RaceID of the object to move. * @param raceIds RaceID of the object to move.
*/ */
public void setDestination (double newXValue, double newYValue, double rotation, double groundSpeed, int... raceIds) { public void setDestination(double newXValue, double newYValue, double rotation,
double groundSpeed, int... raceIds) {
if (hasRaceId(raceIds)) { if (hasRaceId(raceIds)) {
if (setToInitialLocation) { if (setToInitialLocation) {
destinationSet = true; destinationSet = true;
boat.setVelocity(groundSpeed); boat.setVelocity(groundSpeed);
if (currentRotation < 0)
currentRotation = 360 - currentRotation;
double dx = newXValue - boatPoly.getLayoutX(); double dx = newXValue - boatPoly.getLayoutX();
double dy = newYValue - boatPoly.getLayoutY(); double dy = newYValue - boatPoly.getLayoutY();
//Check movement is reasonable. Assumes a 1000 * 1000 canvas
if (Math.abs(dx) > 50 || Math.abs(dy) > 50) {
dx = 0;
dy = 0;
moveTo(newXValue, newYValue);
}
pixelVelocityX = dx / expectedUpdateInterval; pixelVelocityX = dx / expectedUpdateInterval;
pixelVelocityY = dy / expectedUpdateInterval; pixelVelocityY = dy / expectedUpdateInterval;
rotationalGoal = rotation; rotationalGoal = rotation;
calculateRotationalVelocity(); calculateRotationalVelocity();
if (wakeGenerationDelay > 0) { if (Math.abs(rotationalVelocity) > 0.075) {
wake.rotate(rotationalGoal);
rotateTo(rotationalGoal); //Need to test with this removed.
rotationalVelocity = 0; rotationalVelocity = 0;
wakeGenerationDelay--; rotateTo(rotationalGoal);
} else { wake.rotate(rotationalGoal);
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity());
} }
wake.setRotationalVelocity(rotationalVelocity, boat.getVelocity());
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
DateFormat format = new SimpleDateFormat("mm:ss");
// estimate time to next mark
// TODO: 21/05/17 make a nice way of checking for this to be null
estTimeToNextMarkObject.setText("Next mark: null");
if (boat.getEstimateTimeAtNextMark() != null) {
String timeToNextMark = format
.format(
boat.getEstimateTimeAtNextMark() - StreamParser.getCurrentTimeLong());
estTimeToNextMarkObject.setText("Next mark: " + timeToNextMark);
}
// elapsed time
if (boat.getMarkRoundingTime() != null) {
String elapsedTime = format
.format(StreamParser.getCurrentTimeLong() - boat.getMarkRoundingTime());
legTimeObject.setText("Last mark: " + elapsedTime);
} else {
legTimeObject.setText("Last mark: -");
}
} else { } else {
setToInitialLocation = true; setToInitialLocation = true;
rotationalGoal = rotation; rotationalGoal = rotation;
@@ -231,30 +307,10 @@ public class BoatGroup extends RaceObject{
} }
} }
//If minimized generate lines every 5 calls to set destination. //If minimized generate lines every 5 calls to set destination.
if (!isMaximized) {
setToInitialLocation = false;
wakeGenerationDelay = 2;
if(setCallCount-- == 0) {
setCallCount = 5;
if (lastPoint != null) {
Line l = new Line(
lastPoint.getX(),
lastPoint.getY(),
newXValue,
newYValue
);
l.getStrokeDashArray().setAll(3d, 7d);
l.setStroke(boatPoly.getFill());
lineStorage.add(l);
}
if (destinationSet) { //Only begin drawing after the first destination is set
lastPoint = new Point2D(newXValue, newYValue);
}
}
}
} }
public void setDestination (double newXValue, double newYValue, double groundSpeed, int... raceIDs) { public void setDestination(double newXValue, double newYValue, double groundSpeed,
int... raceIDs) {
destinationSet = true; destinationSet = true;
if (hasRaceId(raceIDs)) { if (hasRaceId(raceIDs)) {
@@ -269,16 +325,20 @@ public class BoatGroup extends RaceObject{
} }
} }
public void rotateTo (double rotation) { public void rotateTo(double rotation) {
currentRotation = rotation; currentRotation = rotation;
boatPoly.getTransforms().setAll(new Rotate(rotation)); boatPoly.getTransforms().setAll(new Rotate(rotation));
} }
public void forceRotation () { public void forceRotation() {
rotateTo (rotationalGoal); rotateTo(rotationalGoal);
wake.rotate(rotationalGoal); wake.rotate(rotationalGoal);
} }
public void paintBoat(Color color) {
boatPoly.setFill(color);
}
public void setTeamNameObjectVisible(Boolean visible) { public void setTeamNameObjectVisible(Boolean visible) {
teamNameObject.setVisible(visible); teamNameObject.setVisible(visible);
} }
@@ -287,6 +347,14 @@ public class BoatGroup extends RaceObject{
velocityObject.setVisible(visible); velocityObject.setVisible(visible);
} }
public void setEstTimeToNextMarkObjectVisible(Boolean visible) {
estTimeToNextMarkObject.setVisible(visible);
}
public void setLegTimeObjectVisible(Boolean visible) {
legTimeObject.setVisible(visible);
}
public void setLineGroupVisible(Boolean visible) { public void setLineGroupVisible(Boolean visible) {
lineGroup.setVisible(visible); lineGroup.setVisible(visible);
} }
@@ -299,17 +367,36 @@ public class BoatGroup extends RaceObject{
return boat; return boat;
} }
/**
* This function sets the boats isSelected property AS WELL as actually acting upon the value of
* that selection. (Painting or not painting annotations)
*
* @param isSelected A Boolean indicating whether or not the boat is selected
*/
public void setIsSelected(Boolean isSelected) {
this.isSelected = isSelected;
setTeamNameObjectVisible(isSelected);
setVelocityObjectVisible(isSelected);
setLineGroupVisible(isSelected);
setWakeVisible(isSelected);
setEstTimeToNextMarkObjectVisible(isSelected);
setLegTimeObjectVisible(isSelected);
// TODO: 17/05/17 wmu16 - this should iterate over some list of annotations which we should make to easily make extensible
// paintBoat((isSelected) ? Color.WHITE : boat.getColour());
}
/** /**
* Returns true if this BoatGroup contains at least one of the given IDs. * Returns true if this BoatGroup contains at least one of the given IDs.
* *
* @param raceIds The ID's to check the BoatGroup for. * @param raceIds The ID's to check the BoatGroup for.
* @return True if the BoatGroup contains at east one of the given IDs, false otherwise. * @return True if the BoatGroup contains at east one of the given IDs, false otherwise.
*/ */
public boolean hasRaceId (int... raceIds) { public boolean hasRaceId(int... raceIds) {
for (int id : raceIds) { for (int id : raceIds) {
if (id == boat.getSourceID()) if (id == boat.getSourceID()) {
return true; return true;
} }
}
return false; return false;
} }
@@ -318,31 +405,32 @@ public class BoatGroup extends RaceObject{
* *
* @return An array containing all ID's associated with this RaceObject. * @return An array containing all ID's associated with this RaceObject.
*/ */
public int[] getRaceIds () { public int[] getRaceIds() {
return new int[] {boat.getSourceID()}; return new int[]{boat.getSourceID()};
} }
/** /**
* Due to javaFX limitations annotations associated with a boat that you want to appear below all boats in the * Due to javaFX limitations annotations associated with a boat that you want to appear below
* Z-axis need to be pulled out of the BoatGroup and added to the parent group of the BoatGroups. This function * all boats in the Z-axis need to be pulled out of the BoatGroup and added to the parent group
* returns these annotations as a group. * of the BoatGroups. This function returns these annotations as a group.
* *
* @return A group containing low priority annotations. * @return A group containing low priority annotations.
*/ */
public Group getLowPriorityAnnotations () { public Group getLowPriorityAnnotations() {
Group group = new Group(); Group group = new Group();
group.getChildren().addAll(wake, lineGroup); group.getChildren().addAll(wake, lineGroup);
return group; return group;
} }
/** /**
* Use this function to let the BoatGroup know about the stage it is in. If it knows about it's stage then it will * Use this function to let the BoatGroup know about the stage it is in. If it knows about it's
* listen to the iconified property of that stage and change it's behaviour upon minimization. Without setting the * stage then it will listen to the iconified property of that stage and change it's behaviour
* Stage there is guarantee that the BoatGroup will draw properly when the stage is minimized. * upon minimization. Without setting the Stage there is guarantee that the BoatGroup will draw
* properly when the stage is minimized.
* *
* @param stage The stage that the BoatGroup is added to. * @param stage The stage that the BoatGroup is added to.
*/ */
public void setStage (Stage stage) { public void setStage(Stage stage) {
/* TODO: 4/05/17 cir27 - Find a way to get the stage to this point. Need to pass it through multiple controllers. /* TODO: 4/05/17 cir27 - Find a way to get the stage to this point. Need to pass it through multiple controllers.
App.start() -> Controller.setContentPane -> RaceViewController -> CanvasController App.start() -> Controller.setContentPane -> RaceViewController -> CanvasController
*/ */
@@ -355,4 +443,9 @@ public class BoatGroup extends RaceObject{
} }
}); });
} }
@Override
public String toString() {
return boat.toString();
}
} }
+54 -47
View File
@@ -1,30 +1,34 @@
package seng302.models; package seng302.models;
import javafx.scene.CacheHint;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Arc; import javafx.scene.shape.Arc;
import javafx.scene.shape.ArcType; import javafx.scene.shape.ArcType;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
/** /**
* By default wake is a group containing 5 arcs. Each arc starts from the same point. Each arc is larger and more * A group containing objects used to represent wakes onscreen. Contains functionality for their animation.
* transparent than the last. On calling updatePositions() arcs rotate at velocities given by setRotationalVelocity().
* The larger and more transparent an arc is the longer the delay before it rotates at the latest velocity. It is
* assumed that rotationalVelocities() are set regularly as wakes do not stop rotating and an array of velocities needs
* to be populated for the class to work as expected.
*/ */
class Wake extends Group { class Wake extends Group {
private int numWakes = 5; //The number of wakes
private double[] velocities = new double[13]; private int numWakes = 8;
//The total possible difference between the first wake and the last. Increasing/Decreasing this will make wakes fan out more/less.
private final double MAX_DIFF = 75;
//Increasing/decreasing this will alter the speed that wakes converge when the heading stop changing. Anything over about 1500 may cause oscillation.
private final int UNIFICATION_SPEED = 750;
private Arc[] arcs = new Arc[numWakes]; private Arc[] arcs = new Arc[numWakes];
private double[] rotationalVelocities = new double[numWakes];
private double[] rotations = new double[numWakes]; private double[] rotations = new double[numWakes];
private int[] velocityIndices = new int[numWakes]; private double baseRad;
private double sum = 0;
private static double max;
/** /**
* Create a wake at the given location. * Create a wake at the given location.
*
* @param startingX x location where the tip of wake arcs will be. * @param startingX x location where the tip of wake arcs will be.
* @param startingY y location where the tip of wake arcs will be. * @param startingY y location where the tip of wake arcs will be.
*/ */
@@ -34,74 +38,77 @@ class Wake extends Group {
Arc arc; Arc arc;
for (int i = 0; i < numWakes; i++) { for (int i = 0; i < numWakes; i++) {
//Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg. //Default triangle is -110 deg out of phase with a default wake and has angle of 40 deg.
arc = new Arc(0,0,0,0,-110,40); arc = new Arc(0, 0, 0, 0, -110, 40);
//Opacity increases from 0.5 -> 0 evenly over the 5 wake arcs. arc.setCache(true);
arc.setFill(new Color(0.18, 0.7, 1.0, 1.0 + -0.175 * i)); arc.setCacheHint(CacheHint.SPEED);
arc.setType(ArcType.ROUND); arc.setType(ArcType.OPEN);
arc.setStroke(new Color(0.18, 0.7, 1.0, 1.0 + (-0.99 / numWakes * i)));
arc.setStrokeWidth(3.0);
arc.setStrokeLineCap(StrokeLineCap.ROUND);
arc.setFill(new Color(0.0, 0.0, 0.0, 0.0));
baseRad = (20 / numWakes);
arcs[i] = arc; arcs[i] = arc;
} }
super.getChildren().addAll(arcs); super.getChildren().addAll(arcs);
} }
/** /**
* Sets the rotationalVelocity of each arc. Each arc is 3 velocities behind the next smallest arc. The smallest uses * Sets the rotationalVelocity of each arc.
* the latest given velocity. *
* @param rotationalVelocity The rotationalVelocity the wake should move at. * @param rotationalVelocity The rotationalVelocity the wake should move at.
* @param rotationGoal Where the wake will rotate to if the wake is calculated to be on a straight section. This is
* used to prevent desynchronisation with the Boat polygon.
* @param velocity The real world velocity of the boat in m/s. * @param velocity The real world velocity of the boat in m/s.
*/ */
void setRotationalVelocity (double rotationalVelocity, double rotationGoal, double velocity) { void setRotationalVelocity(double rotationalVelocity, double velocity) {
sum -= Math.abs(velocities[(velocityIndices[0] + 10) % 13]); rotationalVelocities[0] = rotationalVelocity;
sum += Math.abs(rotationalVelocity); for (int i = 1; i < numWakes; i++) {
max = Math.max(max, rotationalVelocity); double wakeSeparationRad = Math.toRadians(rotations[i - 1] - rotations[i]);
if (sum < (max / 3)) double shortestDistance = Math.atan2(
rotate (rotationGoal); //In relatively straight segments the wake snaps to match the boats current position. Math.sin(wakeSeparationRad),
//This stops the wake from eventually becoming out of sync with the boat. Math.cos(wakeSeparationRad)
//This accounts for rogue rotations that are greater than what would be realistic. Value is kinda rough. );
//Basically just for our internal mock. double distDeg = Math.toDegrees(shortestDistance);
if (Math.abs(rotationalVelocity) > 0.05) {
rotationalVelocity = 0;
rotate(rotationGoal);
}
//Update the index of the array of recent velocities that each wake uses. Each wake is 3 velocities behind the
//next smallest wake.
velocityIndices[0] = (13 + (velocityIndices[0] - 1) % 13) % 13;
velocities[velocityIndices[0]] = rotationalVelocity;
for (int i = 1; i < numWakes; i++)
velocityIndices[i] = (velocityIndices[0] + 3 * i) % 13;
//Scale wakes based on velocity. if (rotationalVelocities[i - 1] < 0.01 && rotationalVelocities[i - 1] > -0.01) {
double baseRad = 20; rotationalVelocities[i] = distDeg / UNIFICATION_SPEED * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
double rad;
for (Arc arc :arcs) { } else {
rad = baseRad + velocity; if (distDeg < (MAX_DIFF / numWakes))
rotationalVelocities[i] = rotationalVelocities[i - 1] * Math.log(Math.abs(distDeg) + 1) / Math.log(MAX_DIFF / numWakes);
else
rotationalVelocities[i] = rotationalVelocities[i - 1];
}
}
double rad = baseRad + velocity;
for (Arc arc : arcs) {
arc.setRadiusX(rad); arc.setRadiusX(rad);
arc.setRadiusY(rad); arc.setRadiusY(rad);
baseRad += 5 + (velocity / 2); rad += (20 / numWakes) + (velocity / 2);
} }
} }
/** /**
* Arcs rotate based on the distance they would have travelled over the supplied time interval. * Arcs rotate based on the distance they would have travelled over the supplied time interval.
*
* @param timeInterval the time interval, in microseconds, that the wake should move. * @param timeInterval the time interval, in microseconds, that the wake should move.
*/ */
void updatePosition (long timeInterval) { void updatePosition(long timeInterval) {
for (int i = 0; i < numWakes; i++) { for (int i = 0; i < numWakes; i++) {
rotations[i] = rotations[i] + velocities[velocityIndices[i]] * timeInterval; rotations[i] = rotations[i] + rotationalVelocities[i] * timeInterval;
arcs[i].getTransforms().setAll(new Rotate(rotations[i])); arcs[i].getTransforms().setAll(new Rotate(rotations[i]));
} }
} }
/** /**
* Rotate all wakes to the given rotation. * Rotate all wakes to the given rotation.
*
* @param rotation the from north angle in degrees to rotate to. * @param rotation the from north angle in degrees to rotate to.
*/ */
void rotate (double rotation) { void rotate(double rotation) {
for (int i = 0; i < arcs.length; i++) { for (int i = 0; i < arcs.length; i++) {
rotations[i] = rotation; rotations[i] = rotation;
rotationalVelocities[i] = 0;
arcs[i].getTransforms().setAll(new Rotate(rotation)); arcs[i].getTransforms().setAll(new Rotate(rotation));
} }
} }
} }
+12 -5
View File
@@ -12,9 +12,9 @@ import java.text.SimpleDateFormat;
* also done outside Boat class because some old variables are not used anymore. * also done outside Boat class because some old variables are not used anymore.
*/ */
public class Yacht { public class Yacht {
// Used in boat group
private Color colour; private Color colour;
private double velocity; private double velocity;
private Integer markLastPast;
private String boatType; private String boatType;
private Integer sourceID; private Integer sourceID;
@@ -30,6 +30,8 @@ public class Yacht {
private Long estimateTimeAtNextMark; private Long estimateTimeAtNextMark;
private Long estimateTimeAtFinish; private Long estimateTimeAtFinish;
private String position; private String position;
// Mark rounding
private Long markRoundingTime;
/** /**
* Used in EventTest and RaceTest. * Used in EventTest and RaceTest.
@@ -157,11 +159,16 @@ public class Yacht {
this.velocity = velocity; this.velocity = velocity;
} }
public Integer getMarkLastPast() { public Long getMarkRoundingTime() {
return markLastPast; return markRoundingTime;
} }
public void setMarkLastPast(Integer markLastPast) { public void setMarkRoundingTime(Long markRoundingTime) {
this.markLastPast = markLastPast; this.markRoundingTime = markRoundingTime;
}
@Override
public String toString() {
return boatName;
} }
} }
@@ -1,6 +1,7 @@
package seng302.models.mark; package seng302.models.mark;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.CacheHint;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
@@ -1,53 +0,0 @@
package seng302.models.parsers;
/**
* Created by Kusal on 4/24/2017.
*/
public enum PacketType {
HEARTBEAT,
RACE_STATUS,
DISPLAY_TEXT_MESSAGE,
XML_MESSAGE,
RACE_START_STATUS,
YACHT_EVENT_CODE,
YACHT_ACTION_CODE,
CHATTER_TEXT,
BOAT_LOCATION,
MARK_ROUNDING,
COURSE_WIND,
AVG_WIND,
OTHER;
static PacketType assignPacketType(int packetType){
switch(packetType){
case 1:
return HEARTBEAT;
case 12:
return RACE_STATUS;
case 20:
return DISPLAY_TEXT_MESSAGE;
case 26:
return XML_MESSAGE;
case 27:
return RACE_START_STATUS;
case 29:
return YACHT_EVENT_CODE;
case 31:
return YACHT_ACTION_CODE;
case 36:
return CHATTER_TEXT;
case 37:
return BOAT_LOCATION;
case 38:
return MARK_ROUNDING;
case 44:
return COURSE_WIND;
case 47:
return AVG_WIND;
default:
}
return OTHER;
}
}
@@ -1,44 +0,0 @@
package seng302.models.parsers;
/**
* Created by kre39 on 23/04/17.
*/
public class StreamPacket {
//Change int to an ENUM for the type
private PacketType type;
private long messageLength;
private long timeStamp;
private byte[] payload;
StreamPacket(int type, long messageLength, long timeStamp, byte[] payload) {
this.type = PacketType.assignPacketType(type);
this.messageLength = messageLength;
this.timeStamp = timeStamp;
this.payload = payload;
// System.out.println("type = " + this.type.toString());
//switch the packet type to deal with what ever specific packet you want to deal with
// if (this.type == PacketType.XML_MESSAGE){
// //System.out.println("--------");
// System.out.println(new String(payload));
// //StreamParser.parsePacket(this);
// }
}
PacketType getType() {
return type;
}
public long getMessageLength() {
return messageLength;
}
byte[] getPayload() {
return payload;
}
long getTimeStamp() {
return timeStamp;
}
}
@@ -17,6 +17,7 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.PriorityBlockingQueue;
/** /**
@@ -24,21 +25,22 @@ import java.util.concurrent.PriorityBlockingQueue;
* and parsed in by turning the byte arrays into useful data. There are two public static hashmaps * and parsed in by turning the byte arrays into useful data. There are two public static hashmaps
* that are threadsafe so the visualiser can always access the latest speed and position available * that are threadsafe so the visualiser can always access the latest speed and position available
* Created by kre39 on 23/04/17. * Created by kre39 on 23/04/17.
*
*/ */
public class StreamParser extends Thread{ public class StreamParser extends Thread{
public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>(); public static ConcurrentHashMap<Long, PriorityBlockingQueue<BoatPositionPacket>> boatPositions = new ConcurrentHashMap<>();
private String threadName; private String threadName;
private Thread t; private Thread t;
private static boolean newRaceXmlReceived = false;
private static boolean raceStarted = false; private static boolean raceStarted = false;
private static XMLParser xmlObject; private static XMLParser xmlObject;
private static boolean raceFinished = false; private static boolean raceFinished = false;
private static boolean streamStatus = false; private static boolean streamStatus = false;
private static long timeSinceStart = -1; private static long timeSinceStart = -1;
private static Map<Integer, Yacht> boats = new HashMap<>(); private static Map<Integer, Yacht> boats = new ConcurrentHashMap<>();
private static Map<Long, Yacht> boatsPos = new TreeMap<>(); private static Map<Long, Yacht> boatsPos = new ConcurrentSkipListMap<>();
private static double windDirection = 0; private static double windDirection = 0;
private static Long currentTimeLong;
private static String currentTimeString; private static String currentTimeString;
private static boolean appRunning; private static boolean appRunning;
@@ -122,6 +124,7 @@ public class StreamParser extends Thread{
extractDisplayMessage(packet); extractDisplayMessage(packet);
break; break;
case XML_MESSAGE: case XML_MESSAGE:
newRaceXmlReceived = true;
extractXmlMessage(packet); extractXmlMessage(packet);
break; break;
case RACE_START_STATUS: case RACE_START_STATUS:
@@ -196,9 +199,11 @@ public class StreamParser extends Thread{
long currentTime = bytesToLong(Arrays.copyOfRange(payload,1,7)); long currentTime = bytesToLong(Arrays.copyOfRange(payload,1,7));
long raceId = bytesToLong(Arrays.copyOfRange(payload,7,11)); long raceId = bytesToLong(Arrays.copyOfRange(payload,7,11));
int raceStatus = payload[11]; int raceStatus = payload[11];
// System.out.println("raceStatus = " + raceStatus);
long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18)); long expectedStartTime = bytesToLong(Arrays.copyOfRange(payload,12,18));
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
currentTimeLong = currentTime;
DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
if (xmlObject.getRegattaXML() != null) { if (xmlObject.getRegattaXML() != null) {
format.setTimeZone(TimeZone.getTimeZone(getTimeZoneString())); format.setTimeZone(TimeZone.getTimeZone(getTimeZoneString()));
@@ -206,7 +211,6 @@ public class StreamParser extends Thread{
} }
long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000; long timeTillStart = ((new Date (expectedStartTime)).getTime() - (new Date (currentTime)).getTime())/1000;
if (timeTillStart > 0) { if (timeTillStart > 0) {
timeSinceStart = timeTillStart; timeSinceStart = timeTillStart;
//System.out.println("Time till start: " + timeTillStart + " Seconds"); //System.out.println("Time till start: " + timeTillStart + " Seconds");
@@ -223,10 +227,10 @@ public class StreamParser extends Thread{
//System.out.println("Time since start: " + -1 * timeTillStart + " Seconds"); //System.out.println("Time since start: " + -1 * timeTillStart + " Seconds");
timeSinceStart = timeTillStart; timeSinceStart = timeTillStart;
} }
long windDir = bytesToLong(Arrays.copyOfRange(payload,18,20));
double windDirFactor = 0x4000 / 90; //0x4000 is 90 degrees, 0x8000 is 180 degrees, etc... double windDirFactor = 0x4000 / 90; //0x4000 is 90 degrees, 0x8000 is 180 degrees, etc...
windDirection = windDir / windDirFactor; windDirection = windDir / windDirFactor;
long windSpeed = bytesToLong(Arrays.copyOfRange(payload,20,22));
int noBoats = payload[22]; int noBoats = payload[22];
int raceType = payload[23]; int raceType = payload[23];
// ArrayList<String> boatStatuses = new ArrayList<>(); // ArrayList<String> boatStatuses = new ArrayList<>();
@@ -236,11 +240,11 @@ public class StreamParser extends Thread{
Yacht boat = boats.get((int)(long) boatStatusSourceID); Yacht boat = boats.get((int)(long) boatStatusSourceID);
boat.setBoatStatus((int)payload[28 + (i * 20)]); boat.setBoatStatus((int)payload[28 + (i * 20)]);
boat.setLegNumber((int)payload[29 + (i * 20)]); boat.setLegNumber((int)payload[29 + (i * 20)]);
boat.setPenaltiesAwarded((int)payload[29 + (i * 20)]); boat.setPenaltiesAwarded((int)payload[30 + (i * 20)]);
boat.setPenaltiesServed((int)payload[30 + (i * 20)]); boat.setPenaltiesServed((int)payload[31 + (i * 20)]);
Long estTimeAtNextMark = bytesToLong(Arrays.copyOfRange(payload,31 + (i * 20),37+ (i * 20))); Long estTimeAtNextMark = bytesToLong(Arrays.copyOfRange(payload,32 + (i * 20),38+ (i * 20)));
boat.setEstimateTimeAtNextMark(estTimeAtNextMark); boat.setEstimateTimeAtNextMark(estTimeAtNextMark);
Long estTimeAtFinish = bytesToLong(Arrays.copyOfRange(payload,37 + (i * 20),43+ (i * 20))); Long estTimeAtFinish = bytesToLong(Arrays.copyOfRange(payload,38 + (i * 20),44+ (i * 20)));
boat.setEstimateTimeAtFinish(estTimeAtFinish); boat.setEstimateTimeAtFinish(estTimeAtFinish);
boatsPos.put(estTimeAtFinish, boat); boatsPos.put(estTimeAtFinish, boat);
// String boatStatus = "SourceID: " + boatStatusSourceID; // String boatStatus = "SourceID: " + boatStatusSourceID;
@@ -294,9 +298,8 @@ public class StreamParser extends Thread{
byte[] payload = packet.getPayload(); byte[] payload = packet.getPayload();
int messageType = payload[9]; int messageType = payload[9];
long messagelength = bytesToLong(Arrays.copyOfRange(payload,12,14)); long messageLength = bytesToLong(Arrays.copyOfRange(payload,12,14));
String xmlMessage = new String((Arrays.copyOfRange(payload,14,(int) (14 + messagelength)))).trim(); String xmlMessage = new String((Arrays.copyOfRange(payload,14,(int) (14 + messageLength)))).trim();
//System.out.println("xmlMessage2 = " + xmlMessage);
//Create XML document Object //Create XML document Object
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
@@ -313,6 +316,9 @@ public class StreamParser extends Thread{
if (messageType == 7) { //7 is the boat XML if (messageType == 7) { //7 is the boat XML
boats = xmlObject.getBoatXML().getCompetingBoats(); boats = xmlObject.getBoatXML().getCompetingBoats();
} }
if (messageType == 6) { //6 is race info xml
newRaceXmlReceived = true;
}
} }
/** /**
@@ -429,6 +435,9 @@ public class StreamParser extends Thread{
int roundingSide = payload[18]; int roundingSide = payload[18];
int markType = payload[19]; int markType = payload[19];
int markId = payload[20]; int markId = payload[20];
// assign mark rounding time to boat
boats.get((int)subjectId).setMarkRoundingTime(timeStamp);
} }
/** /**
@@ -575,9 +584,33 @@ public class StreamParser extends Thread{
return boatsPos; return boatsPos;
} }
/**
* returns current time in stream in long
*
* @return a long value of current time
*/
public static Long getCurrentTimeLong() {
return currentTimeLong;
}
public static void appClose(){ public static void appClose(){
appRunning = false; appRunning = false;
System.out.println("[CLIENT] Shutting down stream parser"); System.out.println("[CLIENT] Shutting down stream parser");
} }
/**
* Used to check if a new un-processed xml has been found, if so will return true before
* toggling off so that the next check will return false.
*
* @return the status of if new xml has been received
*/
public static boolean isNewRaceXmlReceived(){
if (newRaceXmlReceived){
newRaceXmlReceived = false;
return true;
} else {
return false;
}
}
} }
+25 -2
View File
@@ -235,6 +235,28 @@ public class ServerThread implements Runnable, Observer {
} }
} }
/**
* Send the post-start race course information
*/
private void sendPostStartCourseXml(){
Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
try {
Message raceData = getXmlMessage("/server_config/courseLimits.xml", XMLMessageSubType.RACE);
if (raceData != null) {
server.send(raceData);
serverLog("Sending race data", 0);
}
}catch (IOException e) {
serverLog("Couldn't send an XML Message: " + e.getMessage(), 0);
}
}
},25000);
//Delays the new course xml data for 25 seconds so the boats are able to pass the starting line
}
public void run() { public void run() {
try{ try{
server = new StreamingServerSocket(PORT_NUMBER); server = new StreamingServerSocket(PORT_NUMBER);
@@ -252,12 +274,13 @@ public class ServerThread implements Runnable, Observer {
sendXml(); sendXml();
startSendingRaceStartStatusMessages(); startSendingRaceStartStatusMessages();
startSendingRaceStatusMessages(); startSendingRaceStatusMessages();
sendPostStartCourseXml();
} }
/** /**
* Start sending static boat position updates when race has finished * Start sending static boat position updates when race has finished
*/ */
private void startSendingRaceFinishedBoatPostions(){ private void startSendingRaceFinishedBoatPositions(){
Timer t = new Timer(); Timer t = new Timer();
t.schedule(new TimerTask() { t.schedule(new TimerTask() {
@Override @Override
@@ -316,7 +339,7 @@ public class ServerThread implements Runnable, Observer {
} }
if (numOfBoatsFinished == ((List<Boat>) arg).size()) { if (numOfBoatsFinished == ((List<Boat>) arg).size()) {
startSendingRaceFinishedBoatPostions(); startSendingRaceFinishedBoatPositions();
} }
} }
@@ -1,10 +1,7 @@
package seng302.server.messages; package seng302.server.messages;
import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.Channels;
import java.nio.channels.SocketChannel; import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
public class BoatLocationMessage extends Message { public class BoatLocationMessage extends Message {
private final int MESSAGE_SIZE = 56; private final int MESSAGE_SIZE = 56;
@@ -44,7 +41,7 @@ public class BoatLocationMessage extends Message {
public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){ public BoatLocationMessage(int sourceId, int sequenceNum, double latitude, double longitude, double heading, long boatSpeed){
boatSpeed /= 10; boatSpeed /= 10;
messageVersionNumber = 1; messageVersionNumber = 1;
time = System.currentTimeMillis() / 1000L; time = System.currentTimeMillis();
this.sourceId = sourceId; this.sourceId = sourceId;
this.sequenceNum = sequenceNum; this.sequenceNum = sequenceNum;
this.deviceType = DeviceType.RACING_YACHT; this.deviceType = DeviceType.RACING_YACHT;
+184
View File
@@ -0,0 +1,184 @@
/**
Background colours
*/
.background-blue{
-fx-background-color: #119796;
}
.background-dark{
-fx-background-color: #2C2c36;
}
/**
Exit button with no background
*/
.clear-exit-btn{
-fx-background-insets: 0;
-fx-background-color: #119796;
-fx-border-style: none;
}
/**
Buttons
*/
.blue-ui-btn{
-fx-background-color: #119796;
-fx-text-fill: #fff;
}
.text-white {
-fx-text-fill: white !important;
-fx-fill:white !important;
}
/**
Sliders
*/
.ui-slider .thumb {
-fx-background-color: rgb(60, 60, 60);
-fx-border-radius: 10;
-fx-border-color: darkgray;
}
.ui-slider .track{
-fx-background-color: #119796;
}
.ui-slider .axis{
-fx-tick-label-fill: white;
}
.ui-slider .axis .axis-label{
-fx-text-fill: white;
}
/**
Checkbox
*/
.ui-checkbox .box{
-fx-background-color: white;
-fx-graphic:none;
-fx-shape: none;
}
.ui-checkbox .box .mark{
-fx-background-image: none;
-fx-image: none;
-fx-graphic: none;
-fx-shape: none;
}
.ui-checkbox:selected .box{
-fx-background-color: #119796;
-fx-shape: none;
}
.ui-checkbox:selected .box .mark{
-fx-background-color: #119796;
-fx-shape: none;
-fx-graphic: none;
}
/**
Table
*/
.ui-table{
-fx-background-color: transparent;
}
.ui-table:focused{
-fx-background-color: transparent;
}
.ui-table .column-header-background{
-fx-background-color: white
}
.ui-table .column-header-background .label{
-fx-background-color: transparent;
-fx-text-fill: black;
}
.ui-table .column-header {
-fx-background-color: transparent;
}
.ui-table .table-cell{
-fx-text-fill: white;
-fx-border-style: none;
}
.table-row-cell{
-fx-background-color: #119796;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.0em; /* 0 */
-fx-border-style: none;
}
.table-row-cell:odd{
-fx-background-color: #0e6d6c;
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.0em; /* 0 */
-fx-border-style: none;
}
.table-row-cell:selected {
-fx-background-color: #005797;
-fx-background-insets: 0;
-fx-border-style: none;
}
/**
Combo Box
*/
.combo-box-base {
-fx-background-color: #119796;
-fx-text-fill: white;
}
.combo-box-popup .list-view .list-cell:hover {
-fx-text-fill: white;
}
.combo-box .cell:selected {
-fx-text-fill: white;
}
/**
Remove scroll bars
*/
.ui-table *.scroll-bar:horizontal *.increment-button,
.ui-table *.scroll-bar:horizontal *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
.ui-table *.scroll-bar:horizontal *.increment-arrow,
.ui-table *.scroll-bar:horizontal *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
.ui-table *.scroll-bar:vertical *.increment-arrow,
.ui-table *.scroll-bar:vertical *.decrement-arrow {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
-fx-shape: null;
}
.ui-table *.scroll-bar:vertical *.increment-button,
.ui-table *.scroll-bar:vertical *.decrement-button {
-fx-background-color: null;
-fx-background-radius: 0;
-fx-background-insets: 0;
-fx-padding: 0;
}
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<Race>
<CreationTimeDate>2015-08-29T13:12:40+02:00</CreationTimeDate>
<RaceStartTime Start="2015-08-29T13:10:00+02:00" Postpone="False"/>
<RaceID>15082901</RaceID>
<RaceType>Fleet</RaceType>
<Participants>
<Yacht SourceID="101"/>
<Yacht SourceID="102"/>
<Yacht SourceID="103"/>
<Yacht SourceID="104"/>
<Yacht SourceID="105"/>
<Yacht SourceID="106"/>
</Participants>
<Course>
<CompoundMark CompoundMarkID="1" Name="Mark0">
<Mark SeqID="1" Name="Start Line 1" TargetLat="57.6703330" TargetLng="11.8278330"
SourceID="122"/>
<Mark SeqID="2" Name="Start Line 2" TargetLat="57.6703330" TargetLng="11.8278330"
SourceID="123"/>
</CompoundMark>
<CompoundMark CompoundMarkID="2" Name="Mark1">
<Mark SeqID="1" Name="Mark1" TargetLat="57.6675700" TargetLng="11.8359880" SourceID="131"/>
</CompoundMark>
<CompoundMark CompoundMarkID="3" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="4" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="5" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="6" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="7" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="8" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="9" Name="Mark2">
<Mark SeqID="1" Name="Lee Gate 1" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="124"/>
<Mark SeqID="2" Name="Lee Gate 2" TargetLat="57.6708220" TargetLng="11.8433900"
SourceID="125"/>
</CompoundMark>
<CompoundMark CompoundMarkID="10" Name="Mark3">
<Mark SeqID="1" Name="Wind Gate 1" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="126"/>
<Mark SeqID="2" Name="Wind Gate 2" TargetLat="57.6650170" TargetLng="11.8279170"
SourceID="127"/>
</CompoundMark>
<CompoundMark CompoundMarkID="11" Name="Mark4">
<Mark SeqID="1" Name="Finish Line 1" TargetLat="57.6715240" TargetLng="11.8444950"
SourceID="128"/>
<Mark SeqID="2" Name="Finish Line 2" TargetLat="57.6715240" TargetLng="11.8444950"
SourceID="129"/>
</CompoundMark>
</Course>
<CompoundMarkSequence>
<Corner SeqID="1" CompoundMarkID="1" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="2" CompoundMarkID="2" Rounding="Port" ZoneSize="3"/>
<Corner SeqID="3" CompoundMarkID="3" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="4" CompoundMarkID="4" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="5" CompoundMarkID="5" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="6" CompoundMarkID="6" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="7" CompoundMarkID="7" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="8" CompoundMarkID="8" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="9" CompoundMarkID="9" Rounding="SP" ZoneSize="3"/>
<Corner SeqID="10" CompoundMarkID="10" Rounding="PS" ZoneSize="3"/>
<Corner SeqID="11" CompoundMarkID="11" Rounding="PS" ZoneSize="3"/>
</CompoundMarkSequence>
<CourseLimit>
<Limit SeqID="1" Lat="57.6739450" Lon="11.8417100"/>
<Limit SeqID="2" Lat="57.6709520" Lon="11.8485010"/>
<Limit SeqID="3" Lat="57.6690260" Lon="11.8472790"/>
<Limit SeqID="4" Lat="57.6693140" Lon="11.8457610"/>
<Limit SeqID="5" Lat="57.6665370" Lon="11.8432910"/>
<Limit SeqID="6" Lat="57.6641400" Lon="11.8385840"/>
<Limit SeqID="7" Lat="57.6629430" Lon="11.8332030"/>
<Limit SeqID="8" Lat="57.6629480" Lon="11.8249660"/>
<Limit SeqID="9" Lat="57.6686890" Lon="11.8250920"/>
<Limit SeqID="10" Lat="57.6708220" Lon="11.8321340"/>
</CourseLimit>
</Race>
+4 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Race> <Race>
<CreationTimeDate>2015-08-29T13:12:40+02:00</CreationTimeDate> <CreationTimeDate>2015-08-29T11:27:15+02:00</CreationTimeDate>
<RaceStartTime Start="2015-08-29T13:10:00+02:00" Postpone="False" /> <RaceStartTime Start="2015-08-29T13:10:00+02:00" Postpone="False" />
<RaceID>15082901</RaceID> <RaceID>15082901</RaceID>
<RaceType>Fleet</RaceType> <RaceType>Fleet</RaceType>
@@ -80,6 +80,8 @@
<Limit SeqID="7" Lat="57.6629430" Lon="11.8332030" /> <Limit SeqID="7" Lat="57.6629430" Lon="11.8332030" />
<Limit SeqID="8" Lat="57.6629480" Lon="11.8249660" /> <Limit SeqID="8" Lat="57.6629480" Lon="11.8249660" />
<Limit SeqID="9" Lat="57.6686890" Lon="11.8250920" /> <Limit SeqID="9" Lat="57.6686890" Lon="11.8250920" />
<Limit SeqID="10" Lat="57.6708220" Lon="11.8321340" /> <Limit SeqID="10" Lat="57.6692230" Lon="11.8231430" />
<Limit SeqID="11" Lat="57.6725370" Lon="11.8272480" />
<Limit SeqID="12" Lat="57.6708220" Lon="11.8321340" />
</CourseLimit> </CourseLimit>
</Race> </Race>
+1 -55
View File
@@ -7,58 +7,4 @@
<?import java.lang.*?> <?import java.lang.*?>
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller"> <AnchorPane fx:id="contentPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.Controller" />
<children>
<GridPane nodeOrientation="LEFT_TO_RIGHT" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints percentHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="52.0" minHeight="52.0" prefHeight="52.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="0.0" percentHeight="8.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="28.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="55.0" minHeight="55.0" percentHeight="5.0" prefHeight="55.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="0.0" minHeight="0.0" percentHeight="23.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="93.0" minHeight="72.0" prefHeight="72.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="283.0" minHeight="262.0" prefHeight="283.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" text="Welcome to Race Vision" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
<font>
<Font size="40.0" />
</font>
</Label>
<Label text="Your live AC35 livestream" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="20.0" />
</font>
</Label>
<Label text="Livestream Status:" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
<font>
<Font size="28.0" />
</font>
</Label>
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="27.0" />
</font>
</Label>
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="7" GridPane.valignment="TOP" />
<TableView fx:id="teamList" maxWidth="500.0" prefHeight="200.0" prefWidth="210.0" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<columns>
<TableColumn fx:id="posCol" editable="false" maxWidth="74.0" minWidth="74.0" prefWidth="74.0" resizable="false" sortable="false" text="Position" />
<TableColumn fx:id="boatNameCol" editable="false" maxWidth="171.0" minWidth="171.0" prefWidth="171.0" resizable="false" sortable="false" text="Boat Name" />
<TableColumn fx:id="shortNameCol" editable="false" maxWidth="107.0" minWidth="107.0" prefWidth="107.0" resizable="false" sortable="false" text="Short Name" />
<TableColumn fx:id="countryCol" editable="false" maxWidth="147.0" minWidth="147.0" prefWidth="147.0" resizable="false" sortable="false" text="Country" />
</columns>
<GridPane.margin>
<Insets />
</GridPane.margin>
</TableView>
<Label fx:id="realTime" text="Local time" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="BOTTOM" />
</children>
</GridPane>
</children>
</AnchorPane>
+16 -13
View File
@@ -28,36 +28,39 @@
<RowConstraints /> <RowConstraints />
</rowConstraints> </rowConstraints>
<children> <children>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3"> <AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #2C2c36;" GridPane.rowSpan="3">
<children> <children>
<Label layoutX="11.0" layoutY="259.0" text="Team Position" /> <Label layoutX="11.0" layoutY="259.0" text="Team Position" textFill="WHITE" />
<Label layoutX="13.0" layoutY="432.0" text="Settings" /> <Label layoutX="13.0" layoutY="432.0" text="Settings" textFill="WHITE" />
<Label layoutX="11.0" layoutY="14.0" text="Timer" /> <Label layoutX="11.0" layoutY="14.0" text="Timer" textFill="WHITE" />
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" /> <Label layoutX="11.0" layoutY="88.0" text="Wind direction" textFill="WHITE" />
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" /> <Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#3dcdc8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#d7d7d7" strokeType="INSIDE" strokeWidth="3.0" />
<Text fx:id="windArrowText" fill="#686868" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="↑"> <Text fx:id="windArrowText" fill="#a8a8a8" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="↑">
<font> <font>
<Font name="AdobeArabic-Regular" size="55.0" /> <Font name="AdobeArabic-Regular" size="55.0" />
</font> </font>
</Text> </Text>
<Text fx:id="windDirectionText" fill="#a8a7a7" layoutX="171.0" layoutY="214.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0.0°" textAlignment="RIGHT"> <Text fx:id="windDirectionText" fill="#d3d3d3" layoutX="171.0" layoutY="214.0" strokeType="OUTSIDE" strokeWidth="0.0" text="0.0°" textAlignment="RIGHT">
<font> <font>
<Font name="System Bold" size="13.0" /> <Font name="System Bold" size="13.0" />
</font> </font>
</Text> </Text>
<CheckBox fx:id="toggleFps" layoutX="21.0" layoutY="453.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="143.0" selected="true" text="Show FPS" /> <CheckBox fx:id="toggleFps" graphicTextGap="0.0" layoutX="21.0" layoutY="453.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="143.0" selected="true" styleClass="ui-checkbox" text="Show FPS" textFill="WHITE" />
<VBox fx:id="positionVbox" layoutX="12.0" layoutY="280.0" prefHeight="140.0" prefWidth="200.0" /> <VBox fx:id="positionVbox" layoutX="12.0" layoutY="280.0" prefHeight="140.0" prefWidth="200.0" styleClass="text-white" />
<Pane layoutX="11.0" layoutY="30.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="51.0" prefWidth="193.0"> <Pane layoutX="11.0" layoutY="30.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="51.0" prefWidth="193.0">
<children> <children>
<Text fx:id="timerLabel" layoutX="-26.0" layoutY="34.0" strokeType="OUTSIDE" strokeWidth="0.0" text="00:00" textAlignment="CENTER" wrappingWidth="246.0"> <Text fx:id="timerLabel" fill="#f8f8f8" layoutX="-26.0" layoutY="34.0" strokeType="OUTSIDE" strokeWidth="0.0" text="00:00" textAlignment="CENTER" wrappingWidth="246.0">
<font> <font>
<Font size="25.0" /> <Font size="25.0" />
</font> </font>
</Text> </Text>
</children> </children>
</Pane> </Pane>
<Slider fx:id="annotationSlider" blockIncrement="1.0" layoutX="38.0" layoutY="527.0" majorTickUnit="1.0" max="3.0" minorTickCount="0" prefHeight="51.0" prefWidth="170.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" /> <Slider fx:id="annotationSlider" blockIncrement="1.0" layoutX="38.0" layoutY="527.0" majorTickUnit="1.0" max="2.0" minorTickCount="0" prefHeight="51.0" prefWidth="170.0" showTickLabels="true" showTickMarks="true" snapToTicks="true" styleClass="ui-slider" />
<Label layoutX="10.0" layoutY="499.0" text="Annotations" /> <Label layoutX="10.0" layoutY="499.0" text="Annotations" textFill="WHITE" />
<Button fx:id="selectAnnotationBtn" layoutX="35.0" layoutY="578.0" mnemonicParsing="false" prefHeight="18.0" prefWidth="170.0" styleClass="blue-ui-btn" text="Select Annotations" textFill="WHITE" />
<Text fill="WHITE" layoutX="11.0" layoutY="649.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Boat Selection" />
<ComboBox fx:id="boatSelectionComboBox" layoutX="37.0" layoutY="664.0" prefHeight="25.0" prefWidth="170.0" promptText="Select Boat" styleClass="combo-box-base" />
</children> </children>
</AnchorPane> </AnchorPane>
<AnchorPane fx:id="contentAnchorPane" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: skyblue;" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP"> <AnchorPane fx:id="contentAnchorPane" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: skyblue;" GridPane.columnIndex="1" GridPane.halignment="LEFT" GridPane.rowSpan="2147483647" GridPane.valignment="TOP">
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.canvas.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<GridPane fx:id="gridPane" nodeOrientation="LEFT_TO_RIGHT" prefWidth="800.0" style="-fx-background-color: #2C2c36;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.StartScreenController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints percentHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="52.0" minHeight="52.0" prefHeight="52.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="0.0" percentHeight="8.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="28.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="55.0" minHeight="55.0" percentHeight="9.0" prefHeight="55.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="0.0" minHeight="0.0" percentHeight="29.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="93.0" minHeight="72.0" prefHeight="72.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="283.0" minHeight="262.0" prefHeight="283.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label alignment="CENTER" text="Welcome to Race Vision" textFill="WHITE" GridPane.halignment="CENTER" GridPane.valignment="BOTTOM">
<font>
<Font size="40.0" />
</font>
</Label>
<Label text="Your live AC35 livestream" textFill="WHITE" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="20.0" />
</font>
</Label>
<Label text="Livestream Status:" textFill="WHITE" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="BOTTOM">
<font>
<Font size="28.0" />
</font>
</Label>
<Label fx:id="timeTillLive" text="0:00 minutes" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="27.0" />
</font>
</Label>
<Button fx:id="streamButton" mnemonicParsing="false" onAction="#startStream" styleClass="blue-ui-btn" text="Click to stream" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
<Button fx:id="switchToRaceViewButton" disable="true" mnemonicParsing="false" onAction="#switchToRaceView" styleClass="blue-ui-btn" text="Watch Race" GridPane.halignment="CENTER" GridPane.rowIndex="7" GridPane.valignment="TOP" />
<TableView fx:id="teamList" maxWidth="661.0" prefHeight="324.0" prefWidth="629.0" styleClass="ui-table" GridPane.halignment="CENTER" GridPane.hgrow="NEVER" GridPane.rowIndex="5" GridPane.vgrow="NEVER">
<columns>
<TableColumn fx:id="posCol" editable="false" maxWidth="74.0" minWidth="74.0" prefWidth="74.0" resizable="false" sortable="false" text="Position" />
<TableColumn fx:id="boatNameCol" editable="false" maxWidth="171.0" minWidth="171.0" prefWidth="171.0" resizable="false" sortable="false" text="Boat Name" />
<TableColumn fx:id="shortNameCol" editable="false" maxWidth="155.18472290039062" minWidth="107.0" prefWidth="155.18472290039062" resizable="false" sortable="false" text="Short Name" />
<TableColumn fx:id="countryCol" editable="false" maxWidth="258.9999694824219" minWidth="147.0" prefWidth="258.9999694824219" resizable="false" sortable="false" text="Country" />
</columns>
<GridPane.margin>
<Insets top="10.0" />
</GridPane.margin>
</TableView>
<Label fx:id="realTime" text="Local time" textFill="WHITE" visible="false" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="BOTTOM" />
</children>
</GridPane>
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane fx:id="annotationSelectWindow" maxHeight="270.0" maxWidth="469.0" minHeight="270.0" minWidth="469.0" prefHeight="270.0" prefWidth="469.0" styleClass="background-blue" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Text fill="WHITE" layoutX="26.0" layoutY="52.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Select important annotations">
<font>
<Font size="24.0" />
</font>
</Text>
<CheckBox fx:id="boatWakeSelect" layoutX="26.0" layoutY="80.0" mnemonicParsing="false" style="-fx-border-width: 0; -fx-background-insets: 0;" text="Boat Wakes" textFill="#e7e7e7" />
<CheckBox fx:id="boatSpeedSelect" layoutX="26.0" layoutY="111.0" mnemonicParsing="false" text="Boat Speed" textFill="#e7e7e7" />
<CheckBox fx:id="boatTrackSelect" layoutX="26.0" layoutY="142.0" mnemonicParsing="false" text="Boat Tracks" textFill="#e7e7e7" />
<CheckBox fx:id="boatNameSelect" layoutX="26.0" layoutY="173.0" mnemonicParsing="false" text="Boat Name" textFill="#e7e7e7" />
<CheckBox fx:id="boatEstTimeToNextMarkSelect" layoutX="26.0" layoutY="204.0" mnemonicParsing="false" text="Boat Estimated Time To Next Mark" textFill="#e7e7e7" />
<Button fx:id="closeButton" layoutX="424.0" layoutY="-1.0" mnemonicParsing="false" prefHeight="11.0" prefWidth="49.0" style=": 0;" text="X" textFill="#ffffff4e">
<font>
<Font size="24.0" />
</font>
<styleClass>
<String fx:value="background-blue" />
<String fx:value="clearExitButton" />
</styleClass>
</Button>
<CheckBox fx:id="boatElapsedTimeSelect" layoutX="26.0" layoutY="235.0" mnemonicParsing="false" text="Boat Elapsed Time Since Last Mark" textFill="#e7e7e7" />
</children>
</AnchorPane>
@@ -8,6 +8,7 @@ import java.lang.reflect.Method;
import java.net.Socket; import java.net.Socket;
import java.util.Comparator; import java.util.Comparator;
import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.PriorityBlockingQueue;
import seng302.models.parsers.packets.StreamPacket;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -0,0 +1,53 @@
package seng302.visualizer.annotations;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import seng302.controllers.annotations.Annotation;
import seng302.controllers.annotations.ImportantAnnotationsState;
import static org.junit.Assert.assertEquals;
public class TestImportantAnnotationState {
private ImportantAnnotationsState importantAnnotationsState;
@Before
public void setUpForTest(){
importantAnnotationsState = new ImportantAnnotationsState();
}
@After
public void tearDownAfterTest(){
importantAnnotationsState = null;
}
/**
* Check whether each annotation has its default value set to the default value when
* the class is initialized
*/
@Test
public void testDefaultValueSet(){
for (Annotation annotation : importantAnnotationsState.getAnnotations()){
assertEquals(ImportantAnnotationsState.DEFAULT_ANNOTATION_STATE,
importantAnnotationsState.getAnnotationState(annotation));
}
}
/**
* Check whether an annotations state can be changed
*/
@Test
public void testAnnotationStateChange(){
Annotation[] annotations = importantAnnotationsState.getAnnotations();
// do not run test if there are no annotations
if (annotations.length <= 0){
return;
}
Boolean currentAnnotationState = importantAnnotationsState.getAnnotationState(annotations[0]);
importantAnnotationsState.setAnnotationState(annotations[0], !currentAnnotationState);
assertEquals(!currentAnnotationState, importantAnnotationsState.getAnnotationState(annotations[0]));
}
}