Implemented functionality to select which annotations to display. Selected annotations can be temporarily saved and then displayed on a button press.
-Added checkboxes to display name, abbreviation, and speed in annotation. -Changed single titlepane to an accordion. -Moved all annotation controls to separate titlepane in accordion. -Added buttons to save and load saved annotation settings. #story[26]
This commit is contained in:
Generated
-3
@@ -1,3 +0,0 @@
|
||||
<component name="CopyrightManager">
|
||||
<settings default="" />
|
||||
</component>
|
||||
@@ -5,6 +5,8 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
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;
|
||||
@@ -26,6 +28,9 @@ public class RaceController extends Controller {
|
||||
@FXML
|
||||
GridPane canvasBase;
|
||||
|
||||
//user saved data for annotation display
|
||||
private ArrayList<Boolean> presetAnno = new ArrayList<>();
|
||||
|
||||
ResizableRaceCanvas raceMap;
|
||||
|
||||
@FXML
|
||||
@@ -40,6 +45,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;
|
||||
@@ -220,6 +235,52 @@ 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();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import seng302.GraphCoordinate;
|
||||
import seng302.RaceMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* This creates a JavaFX Canvas that is fills it's parent.
|
||||
@@ -25,6 +26,9 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
private BoatInRace[] boats;
|
||||
private RaceController controller;
|
||||
private boolean raceAnno = true;
|
||||
private boolean annoName = true;
|
||||
private boolean annoAbbrev = true;
|
||||
private boolean annoSpeed = true;
|
||||
private ArrayList<GPSCoordinate> raceBoundaries;
|
||||
double[] xpoints = {}, ypoints = {};
|
||||
|
||||
@@ -163,11 +167,25 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
* Display given name and speed of boat at a graph coordinate
|
||||
*
|
||||
* @param name name of the boat
|
||||
* @param abbrev abbreviation of the boat name
|
||||
* @param speed speed of the boat
|
||||
* @param coordinate coordinate the text appears
|
||||
*/
|
||||
private void displayText(String name, double speed, GraphCoordinate coordinate) {
|
||||
String text = String.format("%s, %2$.2fkn", name, speed);
|
||||
private void displayText(String name, String abbrev, double speed, GraphCoordinate coordinate) {
|
||||
String text = "";
|
||||
//Check name toggle value
|
||||
if (annoName){
|
||||
text += String.format("%s ", name);
|
||||
}
|
||||
//Check abbreviation toggle value
|
||||
if (annoAbbrev){
|
||||
text += String.format("%s ", abbrev);
|
||||
}
|
||||
//Check speed toggle value
|
||||
if (annoSpeed){
|
||||
text += String.format("%.2fkn", speed);
|
||||
}
|
||||
//String text = String.format("%s, %2$.2fkn", name, speed);
|
||||
long xCoord = coordinate.getX() + 20;
|
||||
long yCoord = coordinate.getY();
|
||||
if (xCoord + (text.length() * 7) >= getWidth()) {
|
||||
@@ -187,6 +205,9 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
this.updateBoats();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw boundary of the race.
|
||||
*/
|
||||
public void drawBoundaries() {
|
||||
if (this.raceBoundaries == null) {
|
||||
return;
|
||||
@@ -263,6 +284,39 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle name display in annotation
|
||||
*/
|
||||
public void toggleAnnoName() {
|
||||
if (annoName) {
|
||||
annoName = false;
|
||||
} else {
|
||||
annoName = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle abbreviation display in annotation
|
||||
*/
|
||||
public void toggleAnnoAbbrev() {
|
||||
if (annoAbbrev) {
|
||||
annoAbbrev = false;
|
||||
} else {
|
||||
annoAbbrev = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle speed display in annotation
|
||||
*/
|
||||
public void toggleAnnoSpeed() {
|
||||
if (annoSpeed) {
|
||||
annoSpeed = false;
|
||||
} else {
|
||||
annoSpeed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws boats while race in progress, when leg heading is set.
|
||||
*/
|
||||
@@ -283,7 +337,7 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
}
|
||||
|
||||
if (raceAnno)
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
displayText(boat.toString(), boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,16 +71,33 @@
|
||||
<children>
|
||||
<Pane prefHeight="200.0" prefWidth="400.0" GridPane.halignment="LEFT" GridPane.valignment="TOP">
|
||||
<children>
|
||||
<TitledPane fx:id="userControl" animated="false" text="User Control" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<Accordion>
|
||||
<panes>
|
||||
<TitledPane animated="false" text="Annotation Control">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.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" />
|
||||
<CheckBox fx:id="showAnnotations" layoutX="-2.0" layoutY="14.0" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<CheckBox fx:id="showName" layoutY="39.0" mnemonicParsing="false" selected="true" text="Show Boat Name" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="26.0" />
|
||||
<CheckBox fx:id="showAbbrev" layoutY="61.0" mnemonicParsing="false" selected="true" text="Show Boat Abbreviation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="52.0" />
|
||||
<CheckBox fx:id="showSpeed" layoutY="90.0" mnemonicParsing="false" selected="true" text="Show Boat Speed" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="78.0" />
|
||||
<Button fx:id="saveAnno" layoutX="11.0" layoutY="106.0" maxWidth="154.0" mnemonicParsing="false" prefWidth="154.0" text="Save Annotation" AnchorPane.topAnchor="104.0" />
|
||||
<Button fx:id="showSetAnno" layoutX="11.0" layoutY="139.0" mnemonicParsing="false" text="Show Set Annotation" AnchorPane.topAnchor="139.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
<TitledPane animated="false" text="FPS Control">
|
||||
<content>
|
||||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<CheckBox fx:id="showFPS" layoutX="-14.0" layoutY="13.0" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
</TitledPane>
|
||||
</panes>
|
||||
</Accordion>
|
||||
</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">
|
||||
|
||||
Reference in New Issue
Block a user