changed raceView javafx structure and added an example of how the handle function works with keyframes #story[426]

This commit is contained in:
Peter
2017-03-22 14:44:40 +13:00
parent 29a0b23670
commit 54d329c5cf
3 changed files with 75 additions and 28 deletions
@@ -6,9 +6,12 @@ import javafx.animation.KeyValue;
import javafx.animation.Timeline;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextArea;
import javafx.scene.paint.Color;
import javafx.util.Duration;
import seng302.models.Boat;
@@ -33,6 +36,8 @@ import static java.lang.Math.abs;
public class CanvasController {
@FXML
private Canvas canvas;
@FXML
TextArea boatOrder;
private Race race;
private GraphicsContext gc;
@@ -83,10 +88,18 @@ public class CanvasController {
List<KeyFrame> keyFrames = new ArrayList<>();
List<Event> events = boat_events.get(boat);
EventHandler onFinished = new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
boat.getTeamName();
}
};
// iterates all events and convert each event to keyFrame, then add them into a list
for (Event event : events) {
keyFrames.add(
new KeyFrame(Duration.seconds(event.getTime() / 60 / 60 / 5),
onFinished,
new KeyValue(x, event.getThisMark().getLatitude()),
new KeyValue(y, event.getThisMark().getLongitude())
)
+13 -18
View File
@@ -7,23 +7,11 @@
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.layout.AnchorPane?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="220.0" minWidth="220.0" prefWidth="273.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="1007.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
</rowConstraints>
<AnchorPane prefHeight="960.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController">
<children>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: lightblue;" GridPane.columnIndex="1" GridPane.rowSpan="3">
<children>
<Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" />
</children>
</AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
<SplitPane dividerPositions="0.17683881064162754" prefHeight="160.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<Label layoutX="11.0" layoutY="259.0" text="Team Position" />
<Label layoutX="11.0" layoutY="617.0" text="Race Log" />
@@ -32,8 +20,15 @@
<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" />
<TextArea editable="false" layoutX="11.0" layoutY="280.0" prefHeight="141.0" prefWidth="200.0" />
<TextArea fx:id="boatOrder" editable="false" layoutX="11.0" layoutY="280.0" prefHeight="141.0" prefWidth="200.0" />
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" />
</children>
</GridPane>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
+39
View File
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.canvas.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.layout.AnchorPane?>
<GridPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.controllers.CanvasController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="220.0" minWidth="220.0" prefWidth="273.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="1007.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="320.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="960.0" prefWidth="1280.0" style="-fx-background-color: lightblue;" GridPane.columnIndex="1" GridPane.rowSpan="3">
<children>
<Canvas fx:id="canvas" height="960.0" style="-fx-background-color: Aqua;" width="1007.0" />
</children>
</AnchorPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowSpan="3">
<children>
<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="11.0" layoutY="14.0" text="Timer" />
<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" />
<TextArea editable="false" layoutX="11.0" layoutY="280.0" prefHeight="141.0" prefWidth="200.0" />
</children>
</AnchorPane>
</children>
</GridPane>