CSS on annotation selection and minor bug fixes. Changed annotation slider to only have None, important and All

#story[955]
This commit is contained in:
William Muir
2017-05-15 16:44:28 +12:00
parent 764ae37ce4
commit 51f090324a
5 changed files with 117 additions and 93 deletions
+2
View File
@@ -63,6 +63,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();
@@ -75,9 +75,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
raceController.initializeRace(); raceController.initializeRace();
race = raceController.getRace(); race = raceController.getRace();
for (Yacht boat : race.getBoats()) { startingBoats = new ArrayList<>(Arrays.asList(race.getBoats()));
startingBoats.add(boat);
}
includedCanvasController.setup(this); includedCanvasController.setup(this);
includedCanvasController.initializeCanvas(); includedCanvasController.initializeCanvas();
@@ -149,9 +147,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
@Override @Override
public String toString(Double n) { public String toString(Double n) {
if (n == 0) return "None"; if (n == 0) return "None";
if (n == 1) return "Low"; if (n == 1) return "Important";
if (n == 2) return "Important"; if (n == 2) return "All";
if (n == 3) return "All";
return "All"; return "All";
} }
@@ -161,15 +158,13 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
switch (s) { switch (s) {
case "None": case "None":
return 0d; return 0d;
case "Low":
return 1d;
case "Important": case "Important":
return 2d; return 1d;
case "All": case "All":
return 3d; return 2d;
default: default:
return 3d; return 2d;
} }
} }
}); });
@@ -177,7 +172,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
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(){ private void initializeTimer(){
@@ -492,20 +487,8 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
} }
} }
break; 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 // Important Annotations
case 2: 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;
@@ -514,7 +497,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
} }
break; break;
// All Annotations // All Annotations
case 3: case 2:
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;
+71 -50
View File
@@ -16,13 +16,14 @@ 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;
@@ -42,51 +43,56 @@ public class BoatGroup extends RaceObject{
private Text teamNameObject; private Text teamNameObject;
private Text velocityObject; private Text velocityObject;
private Wake wake; 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 //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.setOnMouseEntered(event -> boatPoly.setFill(Color.FLORALWHITE));
boatPoly.setOnMouseExited(event -> boatPoly.setFill(color)); 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()); teamNameObject = new Text(boat.getShortName());
velocityObject = new Text(String.valueOf(boat.getVelocity())); velocityObject = new Text(String.valueOf(boat.getVelocity()));
@@ -106,9 +112,10 @@ public class BoatGroup extends RaceObject{
/** /**
* 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,
@@ -116,7 +123,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
*/ */
@@ -134,21 +143,23 @@ 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);
@@ -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. * 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. //Calculate the movement of the boat.
if (isMaximized) { if (isMaximized) {
double dx = pixelVelocityX * timeInterval; double dx = pixelVelocityX * timeInterval;
@@ -196,18 +209,21 @@ public class BoatGroup extends RaceObject{
/** /**
* 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) if (currentRotation < 0) {
currentRotation = 360 - currentRotation; 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 //Check movement is reasonable. Assumes a 1000 * 1000 canvas
@@ -228,7 +244,8 @@ public class BoatGroup extends RaceObject{
rotationalVelocity = 0; rotationalVelocity = 0;
wakeGenerationDelay--; wakeGenerationDelay--;
} else { } else {
wake.setRotationalVelocity(rotationalVelocity, rotationalGoal, boat.getVelocity()); wake.setRotationalVelocity(rotationalVelocity, rotationalGoal,
boat.getVelocity());
} }
velocityObject.setText(String.format("%.2f m/s", boat.getVelocity())); velocityObject.setText(String.format("%.2f m/s", boat.getVelocity()));
} else { } else {
@@ -241,7 +258,7 @@ public class BoatGroup extends RaceObject{
if (!isMaximized) { if (!isMaximized) {
setToInitialLocation = false; setToInitialLocation = false;
wakeGenerationDelay = 2; wakeGenerationDelay = 2;
if(setCallCount-- == 0) { if (setCallCount-- == 0) {
setCallCount = 5; setCallCount = 5;
if (lastPoint != null) { if (lastPoint != null) {
Line l = new Line( Line l = new Line(
@@ -261,7 +278,8 @@ 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; destinationSet = true;
if (hasRaceId(raceIDs)) { if (hasRaceId(raceIDs)) {
@@ -276,17 +294,17 @@ 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) { public void paintBoat(Color color) {
boatPoly.setFill(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. * This function sets the boats isSelected property AS WELL as actually acting upon the value of
* (Painting or not painting annotations) * that selection. (Painting or not painting annotations)
*
* @param isSelected A Boolean indicating whether or not the boat is selected * @param isSelected A Boolean indicating whether or not the boat is selected
*/ */
public void setIsSelected(Boolean isSelected) { public void setIsSelected(Boolean isSelected) {
@@ -330,11 +349,12 @@ public class BoatGroup extends RaceObject{
* @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;
} }
@@ -343,31 +363,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, teamNameObject, velocityObject);
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
*/ */
+18
View File
@@ -128,6 +128,24 @@ Table
-fx-border-style: none; -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 Remove scroll bars
*/ */
+2 -2
View File
@@ -56,11 +56,11 @@
</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" styleClass="ui-slider" /> <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" textFill="WHITE" /> <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" /> <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" /> <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="blue" /> <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">