From 5c89c1aeb7b6e851c37e6e287600c39f8c979256 Mon Sep 17 00:00:00 2001 From: David Wu Date: Thu, 6 Apr 2017 16:37:00 +1200 Subject: [PATCH] Implemented functionality to select which annotations to display. Selected annotations can be temporarily saved and then displayed on a button press. -Added checkboxes to display name, abbreviation, and speed in annotation. -Changed single titlepane to an accordion. -Moved all annotation controls to separate titlepane in accordion. -Added buttons to save and load saved annotation settings. #story[26] --- .idea/copyright/profiles_settings.xml | 3 - .../seng302/Controllers/RaceController.java | 61 +++++++++++++++++++ .../seng302/Model/ResizableRaceCanvas.java | 60 +++++++++++++++++- src/main/resources/scenes/racepane.fxml | 37 ++++++++--- 4 files changed, 145 insertions(+), 16 deletions(-) delete mode 100644 .idea/copyright/profiles_settings.xml diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf33..00000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/src/main/java/seng302/Controllers/RaceController.java b/src/main/java/seng302/Controllers/RaceController.java index 7fb037d2..3ea94788 100644 --- a/src/main/java/seng302/Controllers/RaceController.java +++ b/src/main/java/seng302/Controllers/RaceController.java @@ -5,6 +5,8 @@ import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.fxml.FXML; import javafx.scene.control.*; import javafx.scene.layout.GridPane; @@ -26,6 +28,9 @@ public class RaceController extends Controller { @FXML GridPane canvasBase; + //user saved data for annotation display + private ArrayList presetAnno = new ArrayList<>(); + ResizableRaceCanvas raceMap; @FXML @@ -40,6 +45,16 @@ public class RaceController extends Controller { Label timer; @FXML Label FPS; + @FXML + CheckBox showName; + @FXML + CheckBox showAbbrev; + @FXML + CheckBox showSpeed; + @FXML + Button saveAnno; + @FXML + Button showSetAnno; @FXML TableView boatInfoTable; @@ -220,6 +235,52 @@ public class RaceController extends Controller { raceMap.update(); } }); + //listener for show name in annotation + showName.selectedProperty().addListener(new ChangeListener() { + public void changed(ObservableValue ov, + Boolean old_val, Boolean new_val) { + raceMap.toggleAnnoName(); + raceMap.update(); + } + }); + //listener for show abbreviation for annotation + showAbbrev.selectedProperty().addListener(new ChangeListener() { + public void changed(ObservableValue ov, + Boolean old_val, Boolean new_val) { + raceMap.toggleAnnoAbbrev(); + raceMap.update(); + } + }); + //listener to show speed for annotation + showSpeed.selectedProperty().addListener(new ChangeListener() { + public void changed(ObservableValue ov, + Boolean old_val, Boolean new_val) { + raceMap.toggleAnnoSpeed(); + raceMap.update(); + } + }); + //listener to save currently selected annotation + saveAnno.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + presetAnno.clear(); + presetAnno.add(showName.isSelected()); + presetAnno.add(showAbbrev.isSelected()); + presetAnno.add(showSpeed.isSelected()); + } + }); + //listener to show saved annotation + showSetAnno.setOnAction(new EventHandler() { + @Override + public void handle(ActionEvent event) { + if (presetAnno.size() > 0) { + showName.setSelected(presetAnno.get(0)); + showAbbrev.setSelected(presetAnno.get(1)); + showSpeed.setSelected(presetAnno.get(2)); + raceMap.update(); + } + } + }); } } diff --git a/src/main/java/seng302/Model/ResizableRaceCanvas.java b/src/main/java/seng302/Model/ResizableRaceCanvas.java index 00a0d8e1..e40731f7 100644 --- a/src/main/java/seng302/Model/ResizableRaceCanvas.java +++ b/src/main/java/seng302/Model/ResizableRaceCanvas.java @@ -13,6 +13,7 @@ import seng302.GraphCoordinate; import seng302.RaceMap; import java.util.ArrayList; +import java.util.Arrays; /** * This creates a JavaFX Canvas that is fills it's parent. @@ -25,6 +26,9 @@ public class ResizableRaceCanvas extends Canvas { private BoatInRace[] boats; private RaceController controller; private boolean raceAnno = true; + private boolean annoName = true; + private boolean annoAbbrev = true; + private boolean annoSpeed = true; private ArrayList raceBoundaries; double[] xpoints = {}, ypoints = {}; @@ -163,11 +167,25 @@ public class ResizableRaceCanvas extends Canvas { * Display given name and speed of boat at a graph coordinate * * @param name name of the boat + * @param abbrev abbreviation of the boat name * @param speed speed of the boat * @param coordinate coordinate the text appears */ - private void displayText(String name, double speed, GraphCoordinate coordinate) { - String text = String.format("%s, %2$.2fkn", name, speed); + private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) { + String text = ""; + //Check name toggle value + if (annoName){ + text += String.format("%s ", name); + } + //Check abbreviation toggle value + if (annoAbbrev){ + text += String.format("%s ", abbrev); + } + //Check speed toggle value + if (annoSpeed){ + text += String.format("%.2fkn", speed); + } + //String text = String.format("%s, %2$.2fkn", name, speed); long xCoord = coordinate.getX() + 20; long yCoord = coordinate.getY(); if (xCoord + (text.length() * 7) >= getWidth()) { @@ -187,6 +205,9 @@ public class ResizableRaceCanvas extends Canvas { this.updateBoats(); } + /** + * Draw boundary of the race. + */ public void drawBoundaries() { if (this.raceBoundaries == null) { return; @@ -263,6 +284,39 @@ public class ResizableRaceCanvas extends Canvas { } } + /** + * Toggle name display in annotation + */ + public void toggleAnnoName() { + if (annoName) { + annoName = false; + } else { + annoName = true; + } + } + + /** + * Toggle abbreviation display in annotation + */ + public void toggleAnnoAbbrev() { + if (annoAbbrev) { + annoAbbrev = false; + } else { + annoAbbrev = true; + } + } + + /** + * Toggle speed display in annotation + */ + public void toggleAnnoSpeed() { + if (annoSpeed) { + annoSpeed = false; + } else { + annoSpeed = true; + } + } + /** * Draws boats while race in progress, when leg heading is set. */ @@ -283,7 +337,7 @@ public class ResizableRaceCanvas extends Canvas { } if (raceAnno) - displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); + displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); } } } diff --git a/src/main/resources/scenes/racepane.fxml b/src/main/resources/scenes/racepane.fxml index f7e5c19f..496af431 100644 --- a/src/main/resources/scenes/racepane.fxml +++ b/src/main/resources/scenes/racepane.fxml @@ -71,16 +71,33 @@ - - - - - - - - - - + + + + + + + + + + +