Added checkbox to change visibility of annotation to GUI

-Checkbox is used to toggle the text displayed beside boats
-Race Clock is now scaled using the scale factor

#story [23]
main
David Wu 9 years ago
parent 0df8235a28
commit 073bcaa4a3

@ -39,6 +39,8 @@ public class RaceController extends Controller{
@FXML @FXML
CheckBox showFPS; CheckBox showFPS;
@FXML
public CheckBox showAnno;
@FXML @FXML
Label timer; Label timer;
@ -152,6 +154,13 @@ public class RaceController extends Controller{
} }
}); });
showAnno.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) {
raceMap.toggleAnno();
}
});
new Thread((race)).start(); new Thread((race)).start();
} }

@ -96,7 +96,7 @@ public abstract class Race implements Runnable {
System.out.println("===================="); System.out.println("====================");
for (int i = 0; i < startingBoats.size(); i++) { for (int i = 0; i < startingBoats.size(); i++) {
if (startingBoats.get(i) != null) { if (startingBoats.get(i) != null) {
System.out.println(i + 1 + ". " + startingBoats.get(i).toString() + ", Speed: " System.out.println(i + 1 + ". " + startingBoats.get(i).getName() + ", Speed: "
+ Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn"); + Math.round(startingBoats.get(i).getVelocity() * 1.94384) + "kn");
startingBoats.get(i).setCurrentLeg(legs.get(0)); startingBoats.get(i).setCurrentLeg(legs.get(0));
} }
@ -117,6 +117,7 @@ public abstract class Race implements Runnable {
long timeLoopEnded; long timeLoopEnded;
while (currentTime <= startTime) { while (currentTime <= startTime) {
if (controller != null) controller.updateMap(startingBoats);
timeLeft = startTime - currentTime; timeLeft = startTime - currentTime;
currentTimeInSeconds = timeLeft / 1000; currentTimeInSeconds = timeLeft / 1000;
minutes = currentTimeInSeconds / 60; minutes = currentTimeInSeconds / 60;
@ -146,7 +147,7 @@ public abstract class Race implements Runnable {
long remainingSeconds; long remainingSeconds;
long hours; long hours;
currentTimeInSeconds = totalTimeElapsed / 1000; currentTimeInSeconds = (totalTimeElapsed / 1000) * scaleFactor;
minutes = currentTimeInSeconds / 60; minutes = currentTimeInSeconds / 60;
remainingSeconds = currentTimeInSeconds % 60; remainingSeconds = currentTimeInSeconds % 60;
hours = minutes / 60; hours = minutes / 60;
@ -186,7 +187,7 @@ public abstract class Race implements Runnable {
/*long timeLoopStarted; /*long timeLoopStarted;
long timeLoopEnded; long timeLoopEnded;
int fps = 0;*/ int fps = 0;*/
if (controller != null) controller.updateMap(startingBoats);
if (boatsFinished < startingBoats.size()) { if (boatsFinished < startingBoats.size()) {
//timeLoopStarted = System.currentTimeMillis(); //timeLoopStarted = System.currentTimeMillis();
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted; totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
@ -198,7 +199,7 @@ public abstract class Race implements Runnable {
} }
} }
if (controller != null) controller.updateMap(startingBoats); //if (controller != null) controller.updateMap(startingBoats);
if (timerEnabled) if (timerEnabled)
updateTime(calcTimer()); updateTime(calcTimer());
} }

@ -1,12 +1,14 @@
package seng302.Model; package seng302.Model;
import javafx.application.Platform;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import javafx.scene.paint.Paint; import javafx.scene.paint.Paint;
import javafx.scene.transform.Rotate; import javafx.scene.transform.Rotate;
import seng302.Constants; import seng302.Constants;
import seng302.Controllers.RaceController;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import seng302.GraphCoordinate; import seng302.GraphCoordinate;
import seng302.RaceMap; import seng302.RaceMap;
@ -25,6 +27,8 @@ public class ResizableRaceCanvas extends Canvas {
private GraphicsContext gc; private GraphicsContext gc;
private RaceMap map; private RaceMap map;
private BoatInRace[] boats; private BoatInRace[] boats;
private RaceController controller;
private boolean raceAnno = true;
/** /**
* Sets the boats that are to be displayed in this race. * Sets the boats that are to be displayed in this race.
@ -191,7 +195,8 @@ public class ResizableRaceCanvas extends Canvas {
if (boat != null) { if (boat != null) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition()); // System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour()); displayMark(this.map.convertGPS(boat.getCurrentPosition()), boat.getColour());
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition())); if (raceAnno){
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));}
} }
} }
} }
@ -213,6 +218,14 @@ public class ResizableRaceCanvas extends Canvas {
displayPoint(graphCoordinate, colour); displayPoint(graphCoordinate, colour);
} }
public void toggleAnno(){
if (raceAnno){
raceAnno = false;
} else {
raceAnno = true;
}
}
/** /**
* Set the Canvas to resizable. * Set the Canvas to resizable.
* *

@ -70,6 +70,7 @@
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children> <children>
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" /> <CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<CheckBox fx:id="showAnno" mnemonicParsing="false" selected="true" text="Show Annotations" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="25.0" />
</children> </children>
</AnchorPane> </AnchorPane>
</content> </content>

Loading…
Cancel
Save