From 51f090324a1758d5b7539ef3a780570c67150e13 Mon Sep 17 00:00:00 2001 From: William Muir Date: Mon, 15 May 2017 16:44:28 +1200 Subject: [PATCH] CSS on annotation selection and minor bug fixes. Changed annotation slider to only have None, important and All #story[955] --- src/main/java/seng302/App.java | 2 + .../controllers/RaceViewController.java | 35 ++-- src/main/java/seng302/models/BoatGroup.java | 151 ++++++++++-------- src/main/resources/css/master.css | 18 +++ src/main/resources/views/RaceView.fxml | 4 +- 5 files changed, 117 insertions(+), 93 deletions(-) diff --git a/src/main/java/seng302/App.java b/src/main/java/seng302/App.java index 1a400afd..3b88fd00 100644 --- a/src/main/java/seng302/App.java +++ b/src/main/java/seng302/App.java @@ -63,6 +63,8 @@ public class App extends Application //Change the StreamReceiver in this else block to change the default data source. else{ sr = new StreamReceiver("localhost", 4949, "RaceStream"); +// sr = new StreamReceiver("livedata.americascup.com", 4941, "RaceStream"); + } sr.start(); diff --git a/src/main/java/seng302/controllers/RaceViewController.java b/src/main/java/seng302/controllers/RaceViewController.java index 438f972b..1f015913 100644 --- a/src/main/java/seng302/controllers/RaceViewController.java +++ b/src/main/java/seng302/controllers/RaceViewController.java @@ -75,9 +75,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel raceController.initializeRace(); race = raceController.getRace(); - for (Yacht boat : race.getBoats()) { - startingBoats.add(boat); - } + startingBoats = new ArrayList<>(Arrays.asList(race.getBoats())); includedCanvasController.setup(this); includedCanvasController.initializeCanvas(); @@ -149,9 +147,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel @Override public String toString(Double n) { if (n == 0) return "None"; - if (n == 1) return "Low"; - if (n == 2) return "Important"; - if (n == 3) return "All"; + if (n == 1) return "Important"; + if (n == 2) return "All"; return "All"; } @@ -161,15 +158,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel switch (s) { case "None": return 0d; - case "Low": - return 1d; case "Important": - return 2d; + return 1d; case "All": - return 3d; + return 2d; default: - return 3d; + return 2d; } } }); @@ -177,7 +172,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel annotationSlider.valueProperty().addListener((obs, oldval, newVal) -> setAnnotations((int)annotationSlider.getValue())); - annotationSlider.setValue(3); + annotationSlider.setValue(2); } private void initializeTimer(){ @@ -492,20 +487,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel } } break; - // Low Annotations - case 1: - for (RaceObject ro : includedCanvasController.getRaceObjects()) { - if(ro instanceof BoatGroup) { - BoatGroup bg = (BoatGroup) ro; - bg.setTeamNameObjectVisible(true); - bg.setVelocityObjectVisible(false); - bg.setLineGroupVisible(false); - bg.setWakeVisible(false); - } - } - break; // Important Annotations - case 2: + case 1: for (RaceObject ro : includedCanvasController.getRaceObjects()) { if(ro instanceof BoatGroup) { BoatGroup bg = (BoatGroup) ro; @@ -514,7 +497,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel } break; // All Annotations - case 3: + case 2: for (RaceObject ro : includedCanvasController.getRaceObjects()) { if(ro instanceof BoatGroup) { BoatGroup bg = (BoatGroup) ro; diff --git a/src/main/java/seng302/models/BoatGroup.java b/src/main/java/seng302/models/BoatGroup.java index a2831c52..ea30bc47 100644 --- a/src/main/java/seng302/models/BoatGroup.java +++ b/src/main/java/seng302/models/BoatGroup.java @@ -16,13 +16,14 @@ import java.util.ArrayList; import java.util.List; /** - * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 dimensional boat. - * 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 - * annotate the boat teams name and the boats velocity. The boat will update it's position onscreen everytime - * UpdatePosition is called unless the window is minimized in which case it attempts to store animations and apply them - * when the window is maximised. + * BoatGroup is a javafx group that by default contains a graphical objects for representing a 2 + * dimensional boat. 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 annotate the boat teams name and the boats velocity. The + * boat will update it's position onscreen everytime UpdatePosition is called unless the window is + * 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 private static final double TEAMNAME_X_OFFSET = 10d; @@ -42,51 +43,56 @@ public class BoatGroup extends RaceObject{ private Text teamNameObject; private Text velocityObject; private Wake wake; - private boolean isSelected = false; + private boolean isSelected = true; //Boats annotations are visible by default at the start //Handles boat moving when connecting to a stream private boolean setToInitialLocation = false; private boolean destinationSet; //Variables for handling minimization private Stage stage; - private boolean isMaximized= true; + private boolean isMaximized = true; private List lineStorage = new ArrayList<>(); private int setCallCount = 5; /** * 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. */ - public BoatGroup (Yacht boat, Color color){ + public BoatGroup(Yacht boat, Color color) { this.boat = boat; initChildren(color); } /** - * Creates a BoatGroup with the boat being the default polygon. The head of the boat should be at point (0,0). - * @param boat The boat that the BoatGroup will represent. Must contain an ID which will be used to tell which - * BoatGroup to update. + * Creates a BoatGroup with the boat being the default polygon. The head of the boat should be + * at point (0,0). + * + * @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 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; initChildren(color, points); } /** * 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 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.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 + boatPoly.setOnMouseClicked(event -> setIsSelected(!isSelected)); teamNameObject = new Text(boat.getShortName()); velocityObject = new Text(String.valueOf(boat.getVelocity())); @@ -106,17 +112,20 @@ public class BoatGroup extends RaceObject{ /** * 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. */ - private void initChildren (Color color) { + private void initChildren(Color color) { initChildren(color, - -BOAT_WIDTH / 2, BOAT_HEIGHT / 2, - 0.0, -BOAT_HEIGHT / 2, - BOAT_WIDTH / 2, BOAT_HEIGHT / 2); + -BOAT_WIDTH / 2, BOAT_HEIGHT / 2, + 0.0, -BOAT_HEIGHT / 2, + BOAT_WIDTH / 2, BOAT_HEIGHT / 2); } /** - * 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 dy The amount to move the Y coordinate by */ @@ -134,21 +143,23 @@ public class BoatGroup extends RaceObject{ /** * Moves the boat and its children annotations to coordinates specified + * * @param x The X 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. */ - public void moveTo (double x, double y, double rotation) { + public void moveTo(double x, double y, double rotation) { rotateTo(rotation); moveTo(x, y); } /** * Moves the boat and its children annotations to coordinates specified + * * @param x The X 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.setLayoutY(y); teamNameObject.setLayoutX(x); @@ -162,9 +173,11 @@ public class BoatGroup extends RaceObject{ /** * 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; @@ -177,10 +190,10 @@ public class BoatGroup extends RaceObject{ distanceTravelled = 0; if (lastPoint != null) { Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - boatPoly.getLayoutX(), - boatPoly.getLayoutY() + lastPoint.getX(), + lastPoint.getY(), + boatPoly.getLayoutX(), + boatPoly.getLayoutY() ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boat.getColour()); @@ -196,18 +209,21 @@ public class BoatGroup extends RaceObject{ /** * 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 newYValue The Y co-ordinate the boat needs to move to. * @param rotation Rotation to move graphics to. * @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 (setToInitialLocation) { destinationSet = true; boat.setVelocity(groundSpeed); - if (currentRotation < 0) + if (currentRotation < 0) { currentRotation = 360 - currentRotation; + } double dx = newXValue - boatPoly.getLayoutX(); double dy = newYValue - boatPoly.getLayoutY(); //Check movement is reasonable. Assumes a 1000 * 1000 canvas @@ -228,7 +244,8 @@ public class BoatGroup extends RaceObject{ rotationalVelocity = 0; wakeGenerationDelay--; } else { - wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity()); + wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, + boat.getVelocity()); } velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); } else { @@ -241,14 +258,14 @@ public class BoatGroup extends RaceObject{ if (!isMaximized) { setToInitialLocation = false; wakeGenerationDelay = 2; - if(setCallCount-- == 0) { + if (setCallCount-- == 0) { setCallCount = 5; if (lastPoint != null) { Line l = new Line( - lastPoint.getX(), - lastPoint.getY(), - newXValue, - newYValue + lastPoint.getX(), + lastPoint.getY(), + newXValue, + newYValue ); l.getStrokeDashArray().setAll(3d, 7d); l.setStroke(boatPoly.getFill()); @@ -261,32 +278,33 @@ public class BoatGroup extends RaceObject{ } } - public void setDestination (double newXValue, double newYValue, double groundSpeed, int... raceIDs) { + public void setDestination(double newXValue, double newYValue, double groundSpeed, + int... raceIDs) { destinationSet = true; if (hasRaceId(raceIDs)) { double rotation = Math.abs( - Math.toDegrees( - Math.atan( - (newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX()) - ) + Math.toDegrees( + Math.atan( + (newYValue - boatPoly.getLayoutY()) / (newXValue - boatPoly.getLayoutX()) ) + ) ); setDestination(newXValue, newYValue, rotation, groundSpeed, raceIDs); } } - public void rotateTo (double rotation) { + public void rotateTo(double rotation) { currentRotation = rotation; boatPoly.getTransforms().setAll(new Rotate(rotation)); } - public void forceRotation () { - rotateTo (rotationalGoal); + public void forceRotation() { + rotateTo(rotationalGoal); wake.rotate(rotationalGoal); } - public void paintBoat (Color color) { + public void paintBoat(Color color) { boatPoly.setFill(color); } @@ -311,8 +329,9 @@ public class BoatGroup extends RaceObject{ } /** - * This function sets the boats isSelected property AS WELL as actually acting upon the value of that selection. - * (Painting or not painting annotations) + * 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) { @@ -330,10 +349,11 @@ public class BoatGroup extends RaceObject{ * @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. */ - public boolean hasRaceId (int... raceIds) { + public boolean hasRaceId(int... raceIds) { for (int id : raceIds) { - if (id == boat.getSourceID()) + if (id == boat.getSourceID()) { return true; + } } return false; } @@ -343,31 +363,32 @@ public class BoatGroup extends RaceObject{ * * @return An array containing all ID's associated with this RaceObject. */ - public int[] getRaceIds () { - return new int[] {boat.getSourceID()}; + public int[] getRaceIds() { + return new int[]{boat.getSourceID()}; } /** - * Due to javaFX limitations annotations associated with a boat that you want to appear below all boats in the - * Z-axis need to be pulled out of the BoatGroup and added to the parent group of the BoatGroups. This function - * returns these annotations as a group. + * Due to javaFX limitations annotations associated with a boat that you want to appear below + * all boats in the Z-axis need to be pulled out of the BoatGroup and added to the parent group + * of the BoatGroups. This function returns these annotations as a group. * * @return A group containing low priority annotations. */ - public Group getLowPriorityAnnotations () { + public Group getLowPriorityAnnotations() { Group group = new Group(); - group.getChildren().addAll(wake, lineGroup); + group.getChildren().addAll(wake, lineGroup, teamNameObject, velocityObject); 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 - * listen to the iconified property of that stage and change it's behaviour upon minimization. Without setting the - * Stage there is guarantee that the BoatGroup will draw properly when the stage is minimized. + * Use this function to let the BoatGroup know about the stage it is in. If it knows about it's + * stage then it will listen to the iconified property of that stage and change it's behaviour + * 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. */ - 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. App.start() -> Controller.setContentPane -> RaceViewController -> CanvasController */ diff --git a/src/main/resources/css/master.css b/src/main/resources/css/master.css index 81661bfe..8223fc00 100644 --- a/src/main/resources/css/master.css +++ b/src/main/resources/css/master.css @@ -128,6 +128,24 @@ Table -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 */ diff --git a/src/main/resources/views/RaceView.fxml b/src/main/resources/views/RaceView.fxml index 3dc8bf9c..cfb36f23 100644 --- a/src/main/resources/views/RaceView.fxml +++ b/src/main/resources/views/RaceView.fxml @@ -56,11 +56,11 @@ - +