@ -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 ( ) ) ) ;
}
}
}