From 764ae37ce47feca584f6cfcec3b56db7577337d7 Mon Sep 17 00:00:00 2001 From: William Muir Date: Mon, 15 May 2017 14:09:09 +1200 Subject: [PATCH] Gave the boatgroups a selection attribute, allowing them to be highlighted upon clicking Boats can be clicked on canvas or from selection drop down on the side #story[955] --- .../controllers/RaceViewController.java | 37 +++++++++++++++++++ src/main/java/seng302/models/BoatGroup.java | 32 +++++++++++++++- src/main/java/seng302/models/Yacht.java | 5 +++ src/main/resources/views/RaceView.fxml | 2 + 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 24ff0163..438f972b 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -5,11 +5,15 @@ import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableArray; +import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.CheckBox; +import javafx.scene.control.ComboBox; import javafx.scene.control.Slider; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.Pane; @@ -50,6 +54,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel @FXML private Button selectAnnotationBtn; @FXML + private ComboBox boatSelectionComboBox; + @FXML private CanvasController includedCanvasController; private ArrayList startingBoats = new ArrayList<>(); @@ -79,6 +85,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel initializeSettings(); initialiseWindDirection(); 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)); @@ -220,6 +227,16 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel } + private void initialiseBoatSelectionComboBox() { + + ObservableList observableBoats = FXCollections.observableArrayList(startingBoats); + boatSelectionComboBox.setItems(observableBoats); + boatSelectionComboBox.valueProperty().addListener((observable, oldValue, newValue) -> { + Yacht thisYacht = (Yacht) newValue; + setSelectedBoat(thisYacht); + }); + } + /** * Generates time line for each boat, and stores time time into timelineInfos hash map */ @@ -511,6 +528,26 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel } } + + /** + * 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); + } else { + bg.setIsSelected(false); + } + } + } + } + void setStage (Stage stage) { this.stage = stage; } diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index 57dd48db..a2831c52 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -1,13 +1,16 @@ package seng302.models; +import javafx.event.EventHandler; import javafx.geometry.Point2D; import javafx.scene.Group; +import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.shape.Line; import javafx.scene.shape.Polygon; import javafx.scene.text.Text; import javafx.scene.transform.Rotate; import javafx.stage.Stage; +import seng302.controllers.RaceViewController; import java.util.ArrayList; import java.util.List; @@ -39,6 +42,7 @@ public class BoatGroup extends RaceObject{ private Text teamNameObject; private Text velocityObject; private Wake wake; + private boolean isSelected = false; //Handles boat moving when connecting to a stream private boolean setToInitialLocation = false; private boolean destinationSet; @@ -80,6 +84,9 @@ public class BoatGroup extends RaceObject{ private void initChildren (Color color, double... points) { boatPoly = new Polygon(points); boatPoly.setFill(color); + boatPoly.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE)); + boatPoly.setOnMouseExited(event -> boatPoly.setFill(color)); + boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected)); //Toggle the selection of the boat teamNameObject = new Text(boat.getShortName()); velocityObject = new Text(String.valueOf(boat.getVelocity())); @@ -176,7 +183,7 @@ public class BoatGroup extends RaceObject{ boatPoly.getLayoutY() ); l.getStrokeDashArray().setAll(3d, 7d); - l.setStroke(boatPoly.getFill()); + l.setStroke(boat.getColour()); lineGroup.getChildren().add(l); } if (destinationSet) { //Only begin drawing after the first destination is set @@ -279,6 +286,10 @@ public class BoatGroup extends RaceObject{ wake.rotate(rotationalGoal); } + public void paintBoat (Color color) { + boatPoly.setFill(color); + } + public void setTeamNameObjectVisible(Boolean visible) { teamNameObject.setVisible(visible); } @@ -299,6 +310,20 @@ public class BoatGroup extends RaceObject{ 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); + paintBoat((isSelected) ? Color.WHITE : boat.getColour()); + } + /** * Returns true if this BoatGroup contains at least one of the given IDs. * @@ -355,4 +380,9 @@ public class BoatGroup extends RaceObject{ } }); } + + @Override + public String toString() { + return boat.toString(); + } } diff --git a/src/main/java/seng302/models/Yacht.java b/src/main/java/seng302/models/Yacht.java index 68970268..64509882 100644 --- a/src/main/java/seng302/models/Yacht.java +++ b/src/main/java/seng302/models/Yacht.java @@ -164,4 +164,9 @@ public class Yacht { public void setMarkLastPast(Integer markLastPast) { this.markLastPast = markLastPast; } + + @Override + public String toString() { + return boatName; + } } diff --git a/src/main/resources/views/RaceView.fxml b/src/main/resources/views/RaceView.fxml index 32d6f710..3dc8bf9c 100644 --- a/src/main/resources/views/RaceView.fxml +++ b/src/main/resources/views/RaceView.fxml @@ -59,6 +59,8 @@