Story 25 merged #Story[758]

main
Joseph Gardner 9 years ago
parent b07e881edc
commit af9d6769e5

@ -1,15 +1,14 @@
package seng302.Controllers;
import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.util.Callback;
import org.xml.sax.SAXException;
import seng302.Model.*;
import seng302.RaceXMLReader;
@ -27,12 +26,11 @@ public class RaceController extends Controller {
@FXML
GridPane canvasBase;
ResizableRaceCanvas raceMap;
//user saved data for annotation display
private ArrayList<Boolean> presetAnno;
@FXML
GridPane startScreen;
@FXML
SplitPane ongoingRacePane;
ResizableRaceCanvas raceMap;
@FXML SplitPane race;
@FXML
CheckBox showFPS;
@FXML
@ -41,6 +39,16 @@ public class RaceController extends Controller {
Label timer;
@FXML
Label FPS;
@FXML
CheckBox showName;
@FXML
CheckBox showAbbrev;
@FXML
CheckBox showSpeed;
@FXML
Button saveAnno;
@FXML
Button showSetAnno;
@FXML
TableView<BoatInRace> boatInfoTable;
@ -80,26 +88,6 @@ public class RaceController extends Controller {
boatPlacingColumn.setCellValueFactory(cellData -> cellData.getValue().positionProperty());
}
/**
* Begins the race with a scale factor of 15
*/
public void startRace1Min() {
startRace(15);
}
/**
* Begins the race with a scale factor of 3
*/
public void startRace5Min() {
startRace(3);
}
/**
* Begins the race with a scale factor of 1
*/
public void startRaceNoScaling() {
startRace(1);
}
@Override
public void initialize(URL location, ResourceBundle resources) {
@ -122,7 +110,8 @@ public class RaceController extends Controller {
*
* @param scaleFactor scale value of race
*/
private void startRace(int scaleFactor) {
public void startRace(int scaleFactor) {
RaceXMLReader raceXMLReader = null;
try {
raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml");
@ -143,12 +132,12 @@ public class RaceController extends Controller {
ArrayList<Leg> legs = raceXMLReader.getLegs();
ConstantVelocityRace race = new ConstantVelocityRace(boats, legs, this, scaleFactor);
race.initialiseBoats();
ConstantVelocityRace newRace = new ConstantVelocityRace(boats, legs, this, scaleFactor);
newRace.initialiseBoats();
BoatInRace[] startingBoats = new BoatInRace[race.getStartingBoats().size()];
BoatInRace[] startingBoats = new BoatInRace[newRace.getStartingBoats().size()];
int i = 0;
for (BoatInRace boat : race.getStartingBoats()) {
for (BoatInRace boat : newRace.getStartingBoats()) {
startingBoats[i] = boat;
i++;
}
@ -163,13 +152,13 @@ public class RaceController extends Controller {
raceMap.setVisible(true);
canvasBase.getChildren().add(raceMap);
startScreen.setVisible(false);
ongoingRacePane.setVisible(true);
race.setVisible(true);
//Initialize save annotation array, fps listener, and annotation listeners
initializeFPS();
initializeAnnotations();
new Thread((race)).start();
new Thread((newRace)).start();
}
@ -212,6 +201,7 @@ public class RaceController extends Controller {
* Set up boat annotations
*/
private void initializeAnnotations() {
presetAnno = new ArrayList<>();
//listener for annotation
showAnnotations.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
@ -220,6 +210,51 @@ public class RaceController extends Controller {
raceMap.update();
}
});
//listener for show name in annotation
showName.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) {
raceMap.toggleAnnoName();
raceMap.update();
}
});
//listener for show abbreviation for annotation
showAbbrev.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) {
raceMap.toggleAnnoAbbrev();
raceMap.update();
}
});
//listener to show speed for annotation
showSpeed.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) {
raceMap.toggleAnnoSpeed();
raceMap.update();
}
});
//listener to save currently selected annotation
saveAnno.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
presetAnno.clear();
presetAnno.add(showName.isSelected());
presetAnno.add(showAbbrev.isSelected());
presetAnno.add(showSpeed.isSelected());
}
});
//listener to show saved annotation
showSetAnno.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
if (presetAnno.size() > 0) {
showName.setSelected(presetAnno.get(0));
showAbbrev.setSelected(presetAnno.get(1));
showSpeed.setSelected(presetAnno.get(2));
raceMap.update();
}
}
});
}
}
}

@ -1,113 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="seng302.Controllers.RaceController">
<children>
<GridPane fx:id="startScreen" prefHeight="600.0" prefWidth="780.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="189.0" minWidth="10.0" prefWidth="93.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="372.0" minWidth="10.0" prefWidth="184.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="394.0" minWidth="10.0" prefWidth="192.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="273.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="416.0" minWidth="10.0" prefWidth="57.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="241.0" minHeight="10.0" prefHeight="102.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="383.0" minHeight="10.0" prefHeight="227.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="59.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="178.0" minHeight="10.0" prefHeight="178.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Select Your Race Scaling:" GridPane.columnIndex="1" GridPane.rowIndex="1">
<font>
<Font size="23.0" />
</font>
</Text>
<Button mnemonicParsing="false" onAction="#startRace1Min" text="15x faster" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Button mnemonicParsing="false" onAction="#startRaceNoScaling" text="No scaling" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Button mnemonicParsing="false" onAction="#startRace5Min" text="3x faster" GridPane.columnIndex="2" GridPane.rowIndex="2" />
<Label alignment="CENTER" text="Race will take ~1 minute" GridPane.columnIndex="1" GridPane.rowIndex="3">
<opaqueInsets>
<Insets />
</opaqueInsets>
<font>
<Font size="10.0" />
</font>
</Label>
<Label alignment="CENTER" layoutX="99.0" layoutY="407.0" text="Race will take ~5 minutes" GridPane.columnIndex="2" GridPane.rowIndex="3">
<font>
<Font size="10.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Label>
<Label alignment="CENTER" layoutX="279.0" layoutY="407.0" text="Race will take ~15 minutes" GridPane.columnIndex="3" GridPane.rowIndex="3">
<font>
<Font size="10.0" />
</font>
<opaqueInsets>
<Insets />
</opaqueInsets>
</Label>
</children>
</GridPane>
<SplitPane fx:id="ongoingRacePane" dividerPositions="0.7" visible="false" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<GridPane fx:id="canvasBase">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
<children>
<TitledPane fx:id="userControl" animated="false" prefHeight="128.0" prefWidth="202.0" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="0.0" prefWidth="200.0">
<children>
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</children>
</Pane>
<Label fx:id="timer" layoutX="45.0" layoutY="146.0" text="0:0" AnchorPane.bottomAnchor="0.0" AnchorPane.rightAnchor="0.0" GridPane.halignment="RIGHT" GridPane.valignment="BOTTOM">
<font>
<Font name="System Bold" size="15.0" />
</font>
</Label>
<Label fx:id="FPS" text="FPS: 0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" GridPane.halignment="LEFT" GridPane.valignment="BOTTOM">
<font>
<Font name="System Bold" size="15.0" />
</font>
</Label>
</children>
</GridPane>
<AnchorPane layoutX="450.0" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="200.0" GridPane.columnIndex="1">
<children>
<TableView fx:id="boatInfoTable" layoutX="-2.0" prefHeight="600.0" prefWidth="264.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="-2.0" AnchorPane.rightAnchor="-62.0" AnchorPane.topAnchor="0.0">
<columns>
<TableColumn fx:id="boatPlacingColumn" prefWidth="50.0" text="Place" />
<TableColumn fx:id="boatTeamColumn" prefWidth="100.0" text="Team" />
<TableColumn fx:id="boatMarkColumn" prefWidth="130.0" text="Mark" />
<TableColumn fx:id="boatSpeedColumn" prefWidth="75.0" text="Speed" />
</columns>
</TableView>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

@ -23,9 +23,9 @@
<RowConstraints maxHeight="241.0" minHeight="10.0" prefHeight="116.5" vgrow="SOMETIMES" />
<RowConstraints maxHeight="383.0" minHeight="10.0" prefHeight="257.5" vgrow="SOMETIMES" />
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="50.5" vgrow="SOMETIMES" />
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="369.0" minHeight="10.0" prefHeight="38.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="53.5" vgrow="SOMETIMES" />
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="82.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="191.5" minHeight="10.0" prefHeight="82.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome to RaceVision" GridPane.columnSpan="5" GridPane.halignment="CENTER">
@ -34,17 +34,17 @@
</font>
</Text>
<Button maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startRace1Min" prefWidth="100.0" text="1 Minute" GridPane.columnIndex="1" GridPane.halignment="RIGHT" GridPane.rowIndex="4">
<GridPane.margin>
<Insets />
</GridPane.margin></Button>
<GridPane.margin>
<Insets />
</GridPane.margin></Button>
<Button maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startRaceNoScaling" prefWidth="100.0" text="15 Minutes" GridPane.columnIndex="3" GridPane.halignment="LEFT" GridPane.rowIndex="4" />
<Button maxWidth="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#startRace5Min" prefWidth="100.0" text="5 Minutes" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="4" />
<Label text="Select Race Duration:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
<TableView fx:id="boatNameTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="boatNameColumn" prefWidth="360.0" style="-fx-font-size: 16;" text="Team Name" />
<TableColumn fx:id="boatCodeColumn" prefWidth="133.0" style="-fx-font-size: 16;" text="Code" />
</columns>
</TableView>
<Label text="Select Race Duration:" GridPane.columnIndex="2" GridPane.halignment="CENTER" GridPane.rowIndex="3" />
<TableView fx:id="boatNameTable" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.columnSpan="3" GridPane.rowIndex="1">
<columns>
<TableColumn fx:id="boatNameColumn" prefWidth="360.0" style="-fx-font-size: 16;" text="Team Name" />
<TableColumn fx:id="boatCodeColumn" prefWidth="133.0" style="-fx-font-size: 16;" text="Code" />
</columns>
</TableView>
</children>
</GridPane>
</GridPane>
Loading…
Cancel
Save