@ -11,6 +11,8 @@ import seng302.GPSCoordinate;
import seng302.GraphCoordinate ;
import seng302.RaceMap ;
import java.awt.* ;
import java.awt.geom.Rectangle2D ;
import java.util.ArrayList ;
import java.util.Random ;
@ -23,6 +25,8 @@ public class ResizableRaceCanvas extends Canvas {
private GraphicsContext gc ;
private RaceMap map ;
private BoatInRace [ ] boats ;
private Graphics graphics ;
private Font font ;
/ * *
* Sets the boats that are to be displayed in this race .
@ -107,6 +111,7 @@ public class ResizableRaceCanvas extends Canvas {
public void displayArrow ( GraphCoordinate coordinate , int angle ) {
gc . save ( ) ;
rotate ( angle , coordinate . getX ( ) , coordinate . getY ( ) ) ;
gc . setFill ( Color . BLACK ) ;
gc . fillPolygon ( new double [ ] { coordinate . getX ( ) - 12 , coordinate . getX ( ) - 6 , coordinate . getX ( ) , coordinate . getX ( ) - 4 , coordinate . getX ( ) - 4 , coordinate . getX ( ) - 8 , coordinate . getX ( ) - 8 } ,
new double [ ] { coordinate . getY ( ) - 5 , coordinate . getY ( ) - 20 , coordinate . getY ( ) - 5 , coordinate . getY ( ) - 5 , coordinate . getY ( ) + 20 , coordinate . getY ( ) + 20 , coordinate . getY ( ) - 5 } ,
7 ) ;
@ -131,8 +136,17 @@ public class ResizableRaceCanvas extends Canvas {
* @param coordinate coordinate the text appears
* /
public void displayText ( String name , double speed , GraphCoordinate coordinate ) {
String text = name + ", " + speed + " knots" ;
gc . fillText ( text , coordinate . getX ( ) + 20 , coordinate . getY ( ) ) ;
String text = String . format ( "%s, %2$.2f knots" , name , speed ) ;
//System.out.println(text.length()*7);
long xCoord = coordinate . getX ( ) + 20 ;
long yCoord = coordinate . getY ( ) ;
if ( xCoord + ( text . length ( ) * 7 ) > = getWidth ( ) ) {
xCoord - = text . length ( ) * 7 ;
}
if ( yCoord - ( text . length ( ) * 2 ) < = 0 ) {
yCoord + = 30 ;
}
gc . fillText ( text , xCoord , yCoord ) ;
}
/ * *
@ -140,50 +154,51 @@ public class ResizableRaceCanvas extends Canvas {
* /
public void drawRaceMap ( ) {
double width = getWidth ( ) ;
double height = getHeight ( ) ;
gc . clearRect ( 0 , 0 , width , height ) ;
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
this . map = new RaceMap ( 32.278 , - 64.863 , 32.320989 , - 64.821 , ( int ) width , ( int ) height ) ;
if ( map = = null ) {
return ;
}
double width = getWidth ( ) ;
double height = getHeight ( ) ;
gc . clearRect ( 0 , 0 , width , height ) ;
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + height);
this . map = new RaceMap ( 32.278 , - 64.863 , 32.320989 , - 64.821 , ( int ) width , ( int ) height ) ;
//finish line
gc . setLineWidth ( 2 ) ;
GraphCoordinate finishLineCoord1 = this . map . convertGPS ( Constants . finishLineMarker1 ) ;
GraphCoordinate finishLineCoord2 = this . map . convertGPS ( Constants . finishLineMarker2 ) ;
displayLine ( finishLineCoord1 , finishLineCoord2 , Color . DARKRED ) ;
//marks
GraphCoordinate markCoord = this . map . convertGPS ( Constants . mark1 ) ;
GraphCoordinate windwardGate1 = this . map . convertGPS ( Constants . windwardGate1 ) ;
GraphCoordinate windwardGate2 = this . map . convertGPS ( Constants . windwardGate2 ) ;
GraphCoordinate leewardGate1 = this . map . convertGPS ( Constants . leewardGate1 ) ;
GraphCoordinate leewardGate2 = this . map . convertGPS ( Constants . leewardGate2 ) ;
displayMark ( markCoord , Color . GOLD ) ;
displayLine ( windwardGate1 , windwardGate2 , Color . DARKCYAN ) ;
displayLine ( leewardGate1 , leewardGate2 , Color . DARKVIOLET ) ;
//start line
GraphCoordinate startline1 = this . map . convertGPS ( Constants . startLineMarker1 ) ;
GraphCoordinate startline2 = this . map . convertGPS ( Constants . startLineMarker2 ) ;
displayLine ( startline1 , startline2 , Color . GREEN ) ;
if ( boats ! = null ) {
for ( BoatInRace boat : boats ) {
if ( boat ! = null ) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark ( this . map . convertGPS ( boat . getCurrentPosition ( ) ) , boat . getColour ( ) ) ;
displayText ( boat . getAbbrev ( ) , boat . getVelocity ( ) , this . map . convertGPS ( boat . getCurrentPosition ( ) ) ) ;
if ( map = = null ) {
return ;
}
//finish line
gc . setLineWidth ( 2 ) ;
GraphCoordinate finishLineCoord1 = this . map . convertGPS ( Constants . finishLineMarker1 ) ;
GraphCoordinate finishLineCoord2 = this . map . convertGPS ( Constants . finishLineMarker2 ) ;
displayLine ( finishLineCoord1 , finishLineCoord2 , Color . DARKRED ) ;
//marks
GraphCoordinate markCoord = this . map . convertGPS ( Constants . mark1 ) ;
GraphCoordinate windwardGate1 = this . map . convertGPS ( Constants . windwardGate1 ) ;
GraphCoordinate windwardGate2 = this . map . convertGPS ( Constants . windwardGate2 ) ;
GraphCoordinate leewardGate1 = this . map . convertGPS ( Constants . leewardGate1 ) ;
GraphCoordinate leewardGate2 = this . map . convertGPS ( Constants . leewardGate2 ) ;
displayMark ( markCoord , Color . GOLD ) ;
displayLine ( windwardGate1 , windwardGate2 , Color . DARKCYAN ) ;
displayLine ( leewardGate1 , leewardGate2 , Color . DARKVIOLET ) ;
//start line
GraphCoordinate startline1 = this . map . convertGPS ( Constants . startLineMarker1 ) ;
GraphCoordinate startline2 = this . map . convertGPS ( Constants . startLineMarker2 ) ;
displayLine ( startline1 , startline2 , Color . GREEN ) ;
if ( boats ! = null ) {
for ( BoatInRace boat : boats ) {
if ( boat ! = null ) {
// System.out.print("Drawing Boat At: " + boat.getCurrentPosition());
displayMark ( this . map . convertGPS ( boat . getCurrentPosition ( ) ) , boat . getColour ( ) ) ;
displayText ( boat . getName ( ) . getValue ( ) , boat . getVelocity ( ) * 1.94384 , this . map . convertGPS ( boat . getCurrentPosition ( ) ) ) ;
}
}
}
}
//display wind direction arrow - specify origin point and angle
displayArrow ( new GraphCoordinate ( 500 , 20 ) , 100 ) ;
//display wind direction arrow - specify origin point and angle
displayArrow ( new GraphCoordinate ( 500 , 20 ) , 100 ) ;
}
/ * *