mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Created a toggle checkbox to show and hide all annotation
#story[477]
This commit is contained in:
@@ -3,10 +3,13 @@ package seng302.controllers;
|
|||||||
import javafx.animation.*;
|
import javafx.animation.*;
|
||||||
import javafx.beans.property.DoubleProperty;
|
import javafx.beans.property.DoubleProperty;
|
||||||
import javafx.beans.property.SimpleDoubleProperty;
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
|
import javafx.beans.value.ChangeListener;
|
||||||
|
import javafx.beans.value.ObservableValue;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.canvas.Canvas;
|
import javafx.scene.canvas.Canvas;
|
||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
import javafx.scene.layout.AnchorPane;
|
import javafx.scene.layout.AnchorPane;
|
||||||
import javafx.scene.layout.Pane;
|
import javafx.scene.layout.Pane;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
@@ -36,6 +39,16 @@ import java.util.List;
|
|||||||
public class CanvasController {
|
public class CanvasController {
|
||||||
@FXML
|
@FXML
|
||||||
private Canvas canvas;
|
private Canvas canvas;
|
||||||
|
@FXML
|
||||||
|
private AnchorPane contentAnchorPane;
|
||||||
|
@FXML
|
||||||
|
private Text windArrowText, windDirectionText;
|
||||||
|
@FXML
|
||||||
|
private Pane raceTimer;
|
||||||
|
@FXML
|
||||||
|
private BoatPositionController teamPositionsController;
|
||||||
|
@FXML
|
||||||
|
private CheckBox toggleAnnotation;
|
||||||
|
|
||||||
private Race race;
|
private Race race;
|
||||||
private GraphicsContext gc;
|
private GraphicsContext gc;
|
||||||
@@ -46,86 +59,11 @@ public class CanvasController {
|
|||||||
private final double ORIGIN_LAT = 32.320504;
|
private final double ORIGIN_LAT = 32.320504;
|
||||||
private final double ORIGIN_LON = -64.857063;
|
private final double ORIGIN_LON = -64.857063;
|
||||||
|
|
||||||
@FXML
|
|
||||||
private AnchorPane contentAnchorPane;
|
|
||||||
@FXML
|
|
||||||
private Text windArrowText, windDirectionText;
|
|
||||||
|
|
||||||
@FXML Pane raceTimer;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
BoatPositionController teamPositionsController;
|
|
||||||
|
|
||||||
private Animation.Status raceStatus = Animation.Status.PAUSED;
|
private Animation.Status raceStatus = Animation.Status.PAUSED;
|
||||||
|
|
||||||
private final int SCALE = 16000;
|
private final int SCALE = 16000;
|
||||||
|
|
||||||
/**
|
private boolean annotationCheck = true;
|
||||||
* Display the list of boats in the order they finished the race
|
|
||||||
*/
|
|
||||||
private void loadRaceResultView() {
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/FinishView.fxml"));
|
|
||||||
loader.setController(new RaceResultController(race));
|
|
||||||
|
|
||||||
try {
|
|
||||||
contentAnchorPane.getChildren().removeAll();
|
|
||||||
contentAnchorPane.getChildren().clear();
|
|
||||||
contentAnchorPane.getChildren().addAll((Pane) loader.load());
|
|
||||||
|
|
||||||
} catch (javafx.fxml.LoadException e) {
|
|
||||||
System.err.println(e.getCause());
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load the race timer
|
|
||||||
*/
|
|
||||||
private void loadTimerView(){
|
|
||||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/raceTimer.fxml"));
|
|
||||||
loader.setController(new RaceTimerController(race));
|
|
||||||
|
|
||||||
try{
|
|
||||||
raceTimer.getChildren().clear();
|
|
||||||
raceTimer.getChildren().removeAll();
|
|
||||||
raceTimer.getChildren().addAll((Pane) loader.load());
|
|
||||||
}
|
|
||||||
catch(javafx.fxml.LoadException e){
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
catch(IOException e){
|
|
||||||
System.out.println(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Play each boats timeline
|
|
||||||
*/
|
|
||||||
private void playTimelines(){
|
|
||||||
for (TimelineInfo timelineInfo : timelineInfos.values()){
|
|
||||||
Timeline timeline = timelineInfo.getTimeline();
|
|
||||||
|
|
||||||
if (timeline.getStatus() == Animation.Status.PAUSED){
|
|
||||||
timeline.play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raceStatus = Animation.Status.RUNNING;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pause each boats timeline
|
|
||||||
*/
|
|
||||||
private void pauseTimelines(){
|
|
||||||
for (TimelineInfo timelineInfo : timelineInfos.values()){
|
|
||||||
Timeline timeline = timelineInfo.getTimeline();
|
|
||||||
|
|
||||||
if (timeline.getStatus() == Animation.Status.RUNNING){
|
|
||||||
timeline.pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
raceStatus = Animation.Status.PAUSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the controller
|
* Initialize the controller
|
||||||
@@ -196,12 +134,86 @@ public class CanvasController {
|
|||||||
loadRaceResultView();
|
loadRaceResultView();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
toggleAnnotation.selectedProperty().addListener(new ChangeListener<Boolean>() {
|
||||||
|
@Override
|
||||||
|
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
|
||||||
|
annotationCheck = !annotationCheck;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
//set wind direction!!!!!!! can't find another place to put my code --haoming
|
||||||
double windDirection = new ConfigParser("doc/examples/config.xml").getWindDirection();
|
double windDirection = new ConfigParser("doc/examples/config.xml").getWindDirection();
|
||||||
windDirectionText.setText(String.format("%.1f°", windDirection));
|
windDirectionText.setText(String.format("%.1f°", windDirection));
|
||||||
windArrowText.setRotate(windDirection);
|
windArrowText.setRotate(windDirection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the list of boats in the order they finished the race
|
||||||
|
*/
|
||||||
|
private void loadRaceResultView() {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/FinishView.fxml"));
|
||||||
|
loader.setController(new RaceResultController(race));
|
||||||
|
|
||||||
|
try {
|
||||||
|
contentAnchorPane.getChildren().removeAll();
|
||||||
|
contentAnchorPane.getChildren().clear();
|
||||||
|
contentAnchorPane.getChildren().addAll((Pane) loader.load());
|
||||||
|
|
||||||
|
} catch (javafx.fxml.LoadException e) {
|
||||||
|
System.err.println(e.getCause());
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the race timer
|
||||||
|
*/
|
||||||
|
private void loadTimerView(){
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/raceTimer.fxml"));
|
||||||
|
loader.setController(new RaceTimerController(race));
|
||||||
|
|
||||||
|
try{
|
||||||
|
raceTimer.getChildren().clear();
|
||||||
|
raceTimer.getChildren().removeAll();
|
||||||
|
raceTimer.getChildren().addAll((Pane) loader.load());
|
||||||
|
}
|
||||||
|
catch(javafx.fxml.LoadException e){
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
catch(IOException e){
|
||||||
|
System.out.println(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play each boats timeline
|
||||||
|
*/
|
||||||
|
private void playTimelines(){
|
||||||
|
for (TimelineInfo timelineInfo : timelineInfos.values()){
|
||||||
|
Timeline timeline = timelineInfo.getTimeline();
|
||||||
|
|
||||||
|
if (timeline.getStatus() == Animation.Status.PAUSED){
|
||||||
|
timeline.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raceStatus = Animation.Status.RUNNING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pause each boats timeline
|
||||||
|
*/
|
||||||
|
private void pauseTimelines(){
|
||||||
|
for (TimelineInfo timelineInfo : timelineInfos.values()){
|
||||||
|
Timeline timeline = timelineInfo.getTimeline();
|
||||||
|
|
||||||
|
if (timeline.getStatus() == Animation.Status.RUNNING){
|
||||||
|
timeline.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
raceStatus = Animation.Status.PAUSED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates time line for each boat, and stores time time into timelineInfos hash map
|
* Generates time line for each boat, and stores time time into timelineInfos hash map
|
||||||
*/
|
*/
|
||||||
@@ -258,6 +270,8 @@ public class CanvasController {
|
|||||||
* @param lat
|
* @param lat
|
||||||
* @param lon
|
* @param lon
|
||||||
* @param color
|
* @param color
|
||||||
|
* @param name
|
||||||
|
* @param speed
|
||||||
*/
|
*/
|
||||||
private void drawBoat(double lat, double lon, Color color, String name, double speed) {
|
private void drawBoat(double lat, double lon, Color color, String name, double speed) {
|
||||||
// Latitude
|
// Latitude
|
||||||
@@ -266,12 +280,15 @@ public class CanvasController {
|
|||||||
|
|
||||||
double diameter = 9;
|
double diameter = 9;
|
||||||
|
|
||||||
|
gc.setFill(color);
|
||||||
|
|
||||||
|
if (annotationCheck) {
|
||||||
// Set boat text
|
// Set boat text
|
||||||
gc.setFont(new Font(14));
|
gc.setFont(new Font(14));
|
||||||
gc.setFill(color);
|
|
||||||
gc.setLineWidth(3);
|
gc.setLineWidth(3);
|
||||||
gc.setFontSmoothingType(FontSmoothingType.GRAY);
|
gc.setFontSmoothingType(FontSmoothingType.GRAY);
|
||||||
gc.fillText(name + ", " + speed + " knots", x + 15, y + 15);
|
gc.fillText(name + ", " + speed + " knots", x + 15, y + 15);
|
||||||
|
}
|
||||||
|
|
||||||
gc.fillOval(x, y, diameter, diameter);
|
gc.fillOval(x, y, diameter, diameter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,9 @@
|
|||||||
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
|
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
|
||||||
<children>
|
<children>
|
||||||
<Label layoutX="11.0" layoutY="259.0" text="Team Position" />
|
<Label layoutX="11.0" layoutY="259.0" text="Team Position" />
|
||||||
<Label layoutX="11.0" layoutY="617.0" text="Race Log" />
|
|
||||||
<Label layoutX="13.0" layoutY="432.0" text="Annotation toggle" />
|
<Label layoutX="13.0" layoutY="432.0" text="Annotation toggle" />
|
||||||
<Label layoutX="11.0" layoutY="14.0" text="Timer" />
|
<Label layoutX="11.0" layoutY="14.0" text="Timer" />
|
||||||
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" />
|
<Label layoutX="11.0" layoutY="88.0" text="Wind direction" />
|
||||||
<Button layoutX="18.0" layoutY="468.0" mnemonicParsing="false" text="Button" />
|
|
||||||
<TextArea editable="false" layoutX="11.0" layoutY="640.0" prefHeight="306.0" prefWidth="200.0" />
|
|
||||||
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" />
|
<Circle fx:id="windBackgroundCircle" blendMode="DARKEN" fill="#76baf8" layoutX="110.0" layoutY="166.0" radius="35.0" stroke="#686868" strokeType="INSIDE" strokeWidth="3.0" />
|
||||||
<Text fx:id="windArrowText" fill="#686868" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="↑">
|
<Text fx:id="windArrowText" fill="#686868" layoutX="86.0" layoutY="186.0" strokeType="OUTSIDE" strokeWidth="0.0" text="↑">
|
||||||
<font>
|
<font>
|
||||||
@@ -48,6 +45,7 @@
|
|||||||
<fx:include fx:id="teamPositions" source="TeamPositions.fxml" />
|
<fx:include fx:id="teamPositions" source="TeamPositions.fxml" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
|
<CheckBox fx:id="toggleAnnotation" layoutX="27.0" layoutY="462.0" mnemonicParsing="false" text="Toggle annotation" />
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</AnchorPane>
|
||||||
<AnchorPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" GridPane.columnIndex="1" GridPane.rowSpan="3">
|
<AnchorPane fx:id="contentAnchorPane" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" GridPane.columnIndex="1" GridPane.rowSpan="3">
|
||||||
|
|||||||
Reference in New Issue
Block a user