diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 433e47a2..24ff0163 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -21,6 +21,10 @@ import javafx.stage.Stage; import javafx.stage.StageStyle; import javafx.util.Duration; 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.parsers.StreamParser; @@ -30,7 +34,7 @@ import java.util.*; /** * Created by ptg19 on 29/03/17. */ -public class RaceViewController extends Thread{ +public class RaceViewController extends Thread implements ImportantAnnotationDelegate{ @FXML private VBox positionVbox; @FXML @@ -55,23 +59,19 @@ public class RaceViewController extends Thread{ private ArrayList boatOrder = new ArrayList<>(); private Race race; private Stage stage; - private Integer annotationLevel; - private Map importantAnnotations = new HashMap<>(); + private ImportantAnnotationsState importantAnnotations; public void initialize() { + // Load a default important annotation state + importantAnnotations = new ImportantAnnotationsState(); RaceController raceController = new RaceController(); raceController.initializeRace(); race = raceController.getRace(); + for (Yacht boat : race.getBoats()) { startingBoats.add(boat); } -// try{ -// initializeTimelines(); -// } -// catch (Exception e){ -// e.printStackTrace(); -// } includedCanvasController.setup(this); includedCanvasController.initializeCanvas(); @@ -91,13 +91,12 @@ public class RaceViewController extends Thread{ } /** - * Important annotations have been changed, update this view - * @param newImportantAnnotations HashMap containing whether or not annotations - * are important + * The important annotations have been changed, update this view + * @param importantAnnotationsState The current state of the selected annotations */ - void importantAnnotationsChanged(Map newImportantAnnotations){ - this.importantAnnotations = newImportantAnnotations; - setAnnotations((int)annotationSlider.getValue()); + public void importantAnnotationsChanged(ImportantAnnotationsState importantAnnotationsState){ + this.importantAnnotations = importantAnnotationsState; + setAnnotations((int)annotationSlider.getValue()); // Refresh the displayed annotations } /** @@ -128,10 +127,6 @@ public class RaceViewController extends Thread{ } } - Map getImportantAnnotations(){ - return importantAnnotations; - } - private void initializeSettings() { displayFps = true; @@ -432,9 +427,43 @@ public class RaceViewController extends Thread{ return startingBoats; } + /** + * 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); + } + + if (importantAnnotations.getAnnotationState(Annotation.SPEED)){ + 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); + } + } private void setAnnotations(Integer annotationLevel) { switch (annotationLevel) { + // No Annotations case 0: for (RaceObject ro : includedCanvasController.getRaceObjects()) { if(ro instanceof BoatGroup) { @@ -446,6 +475,7 @@ public class RaceViewController extends Thread{ } } break; + // Low Annotations case 1: for (RaceObject ro : includedCanvasController.getRaceObjects()) { if(ro instanceof BoatGroup) { @@ -462,37 +492,11 @@ public class RaceViewController extends Thread{ for (RaceObject ro : includedCanvasController.getRaceObjects()) { if(ro instanceof BoatGroup) { BoatGroup bg = (BoatGroup) ro; - - if (importantAnnotations.containsKey("BoatName") && importantAnnotations.get("BoatName")){ - bg.setTeamNameObjectVisible(true); - } - else{ - bg.setTeamNameObjectVisible(false); - } - - if (importantAnnotations.containsKey("BoatSpeed") && importantAnnotations.get("BoatSpeed")){ - bg.setVelocityObjectVisible(true); - } - else{ - bg.setTeamNameObjectVisible(false); - } - - if (importantAnnotations.containsKey("BoatTrack") && importantAnnotations.get("BoatTrack")){ - bg.setLineGroupVisible(true); - } - else{ - bg.setLineGroupVisible(false); - } - - if (importantAnnotations.containsKey("BoatWake") && importantAnnotations.get("BoatWake")){ - bg.setWakeVisible(true); - } - else{ - bg.setWakeVisible(false); - } + setBoatGroupImportantAnnotations(bg); } } break; + // All Annotations case 3: for (RaceObject ro : includedCanvasController.getRaceObjects()) { if(ro instanceof BoatGroup) { diff --git a/src/main/java/seng302/controllers/annotations/Annotation.java b/src/main/java/seng302/controllers/annotations/Annotation.java new file mode 100644 index 00000000..eed70162 --- /dev/null +++ b/src/main/java/seng302/controllers/annotations/Annotation.java @@ -0,0 +1,11 @@ +package seng302.controllers.annotations; + +/** + * Annotations the user can select as important + */ +public enum Annotation { + SPEED, + WAKE, + TRACK, + NAME +} diff --git a/src/main/java/seng302/controllers/ImportantAnnotationController.java b/src/main/java/seng302/controllers/annotations/ImportantAnnotationController.java similarity index 51% rename from src/main/java/seng302/controllers/ImportantAnnotationController.java rename to src/main/java/seng302/controllers/annotations/ImportantAnnotationController.java index e1a031cf..0d1585af 100644 --- a/src/main/java/seng302/controllers/ImportantAnnotationController.java +++ b/src/main/java/seng302/controllers/annotations/ImportantAnnotationController.java @@ -1,4 +1,4 @@ -package seng302.controllers; +package seng302.controllers.annotations; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -6,6 +6,8 @@ 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; @@ -34,57 +36,59 @@ public class ImportantAnnotationController implements Initializable { @FXML private Button closeButton; - private RaceViewController parent; - private Map importantAnnotations; + private ImportantAnnotationDelegate delegate; + private ImportantAnnotationsState importantAnnotationsState; private Stage stage; - ImportantAnnotationController(RaceViewController parent, Stage stage){ - this.parent = parent; - importantAnnotations = new HashMap<>(); + public ImportantAnnotationController(ImportantAnnotationDelegate delegate, Stage stage){ + this.delegate = delegate; + importantAnnotationsState = new ImportantAnnotationsState(); this.stage = stage; } /** - * Sets whether or not an annotation is considered important - * @param name The annotation name + * 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(String name, Boolean isSet){ - importantAnnotations.put(name, isSet); + private void setAnnotation(Annotation annotation, Boolean isSet){ + importantAnnotationsState.setAnnotationState(annotation, isSet); + sendUpdate(); } /** - * Sends an update to the parent controller when the important + * Sends an update to the delegate when the important * annotations have changed */ private void sendUpdate(){ - this.parent.importantAnnotationsChanged(this.importantAnnotations); + this.delegate.importantAnnotationsChanged(importantAnnotationsState); } /** * Load the current state of the 'important annotations' * @param currentState hashmap containing the states of each annotation */ - void loadState(Map currentState){ - this.importantAnnotations = currentState; + public void loadState(ImportantAnnotationsState currentState){ + this.importantAnnotationsState = currentState; // Initialise checkboxes - for (String key : importantAnnotations.keySet()){ - switch (key){ - case "BoatWake": - boatWakeSelect.setSelected(importantAnnotations.get(key)); + for (Annotation annotation : importantAnnotationsState.getAnnotations()){ + switch (annotation){ + case WAKE: + boatWakeSelect.setSelected(importantAnnotationsState.getAnnotationState(annotation)); break; - case "BoatSpeed": - boatSpeedSelect.setSelected(importantAnnotations.get(key)); + case SPEED: + boatSpeedSelect.setSelected(importantAnnotationsState.getAnnotationState(annotation)); break; - case "BoatTrack": - boatTrackSelect.setSelected(importantAnnotations.get(key)); + case TRACK: + boatTrackSelect.setSelected(importantAnnotationsState.getAnnotationState(annotation)); break; - case "BoatName": - boatNameSelect.setSelected(importantAnnotations.get(key)); + case NAME: + boatNameSelect.setSelected(importantAnnotationsState.getAnnotationState(annotation)); break; default: @@ -100,25 +104,10 @@ public class ImportantAnnotationController implements Initializable { */ @Override public void initialize(URL location, ResourceBundle resources) { - boatWakeSelect.setOnAction(event -> { - setAnnotation("BoatWake", boatWakeSelect.isSelected()); - sendUpdate(); - }); - - boatSpeedSelect.setOnAction(event -> { - setAnnotation("BoatSpeed", boatSpeedSelect.isSelected()); - sendUpdate(); - }); - - boatTrackSelect.setOnAction(event -> { - setAnnotation("BoatTrack", boatTrackSelect.isSelected()); - sendUpdate(); - }); - - boatNameSelect.setOnAction(event -> { - setAnnotation("BoatName", boatNameSelect.isSelected()); - sendUpdate(); - }); + 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())); closeButton.setOnAction(event -> stage.close()); } diff --git a/src/main/java/seng302/controllers/annotations/ImportantAnnotationDelegate.java b/src/main/java/seng302/controllers/annotations/ImportantAnnotationDelegate.java new file mode 100644 index 00000000..ba50726e --- /dev/null +++ b/src/main/java/seng302/controllers/annotations/ImportantAnnotationDelegate.java @@ -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); + + +} diff --git a/src/main/java/seng302/controllers/annotations/ImportantAnnotationsState.java b/src/main/java/seng302/controllers/annotations/ImportantAnnotationsState.java new file mode 100644 index 00000000..5cc97a7f --- /dev/null +++ b/src/main/java/seng302/controllers/annotations/ImportantAnnotationsState.java @@ -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 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(); + } +} diff --git a/src/main/resources/views/MainView.fxml b/src/main/resources/views/MainView.fxml index 65e7ee7b..054dd6cd 100644 --- a/src/main/resources/views/MainView.fxml +++ b/src/main/resources/views/MainView.fxml @@ -57,7 +57,7 @@ -