@ -1,6 +1,7 @@
package seng302.Model ;
package seng302.Model ;
import com.sun.corba.se.impl.orbutil.graph.Graph ;
import javafx.application.Platform ;
import javafx.application.Platform ;
import javafx.beans.property.StringProperty ;
import javafx.beans.property.StringProperty ;
import javafx.scene.canvas.Canvas ;
import javafx.scene.canvas.Canvas ;
@ -29,7 +30,10 @@ 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 ;
private boolean raceAnno = true ;
private ArrayList < GPSCoordinate > raceBoundaries ;
double [ ] xpoints = { } , ypoints = { } ;
/ * *
/ * *
* Sets the boats that are to be displayed in this race .
* Sets the boats that are to be displayed in this race .
@ -41,6 +45,7 @@ public class ResizableRaceCanvas extends Canvas {
}
}
public ResizableRaceCanvas ( RaceMap map ) {
public ResizableRaceCanvas ( RaceMap map ) {
super ( ) ;
this . map = map ;
this . map = map ;
gc = this . getGraphicsContext2D ( ) ;
gc = this . getGraphicsContext2D ( ) ;
// Redraw canvas when size changes.
// Redraw canvas when size changes.
@ -53,6 +58,12 @@ public class ResizableRaceCanvas extends Canvas {
* /
* /
public ResizableRaceCanvas ( ) {
public ResizableRaceCanvas ( ) {
this ( null ) ;
this ( null ) ;
setMap ( new RaceMap ( 32.278 , - 64.863 , 32.320989 , - 64.821 , ( int ) getWidth ( ) , ( int ) getHeight ( ) ) ) ;
}
public ResizableRaceCanvas ( double lat1 , double long1 , double lat2 , double long2 ) {
this ( null ) ;
setMap ( new RaceMap ( lat1 , long1 , lat2 , long2 , ( int ) getWidth ( ) , ( int ) getHeight ( ) ) ) ;
}
}
/ * *
/ * *
@ -178,6 +189,15 @@ public class ResizableRaceCanvas extends Canvas {
this . updateBoats ( ) ;
this . updateBoats ( ) ;
}
}
public void drawBoundaries ( ) {
if ( this . raceBoundaries = = null ) {
return ;
}
gc . setFill ( Color . AQUA ) ;
setRaceBoundCoordinates ( ) ;
gc . fillPolygon ( xpoints , ypoints , xpoints . length ) ;
}
/ * *
/ * *
* Draws the Race Map
* Draws the Race Map
* /
* /
@ -188,10 +208,15 @@ public class ResizableRaceCanvas extends Canvas {
gc . clearRect ( 0 , 0 , width , height ) ;
gc . clearRect ( 0 , 0 , width , height ) ;
//System.out.println("Race Map Canvas Width: "+ width + ", Height:" + 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 ; //TODO this should return a exception in the future
}
this . map . setHeight ( ( int ) height ) ;
this . map . setWidth ( ( int ) width ) ;
//finish line
//finish line
gc . setLineWidth ( 2 ) ;
gc . setLineWidth ( 2 ) ;
drawBoundaries ( ) ;
GraphCoordinate finishLineCoord1 = this . map . convertGPS ( Constants . finishLineMarker1 ) ;
GraphCoordinate finishLineCoord1 = this . map . convertGPS ( Constants . finishLineMarker1 ) ;
GraphCoordinate finishLineCoord2 = this . map . convertGPS ( Constants . finishLineMarker2 ) ;
GraphCoordinate finishLineCoord2 = this . map . convertGPS ( Constants . finishLineMarker2 ) ;
displayLine ( finishLineCoord1 , finishLineCoord2 , Color . DARKRED ) ;
displayLine ( finishLineCoord1 , finishLineCoord2 , Color . DARKRED ) ;
@ -216,11 +241,24 @@ public class ResizableRaceCanvas extends Canvas {
displayArrow ( new GraphCoordinate ( ( int ) getWidth ( ) - 40 , 40 ) , 150 ) ;
displayArrow ( new GraphCoordinate ( ( int ) getWidth ( ) - 40 , 40 ) , 150 ) ;
}
}
/ * *
* Draws a boat at a certain GPSCoordinate
* @param colour Colour to colour boat .
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at .
* @see GPSCoordinate
* @see Color
* /
public void drawBoat ( Color colour , GPSCoordinate gpsCoordinates ) {
GraphCoordinate graphCoordinate = this . map . convertGPS ( gpsCoordinates ) ;
//System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
displayPoint ( graphCoordinate , colour ) ;
}
/ * *
/ * *
* Toggle the raceAnno value
* Toggle the raceAnno value
* /
* /
public void toggleAnno ( ) {
public void toggleAnno ( ) {
if ( raceAnno ) {
if ( raceAnno ) {
raceAnno = false ;
raceAnno = false ;
} else {
} else {
raceAnno = true ;
raceAnno = true ;
@ -251,6 +289,24 @@ public class ResizableRaceCanvas extends Canvas {
}
}
}
}
public void setRaceBoundaries ( ArrayList < GPSCoordinate > boundaries ) {
this . raceBoundaries = new ArrayList < > ( ) ;
for ( GPSCoordinate bound : boundaries ) {
raceBoundaries . add ( bound ) ;
}
setRaceBoundCoordinates ( ) ;
}
public void setRaceBoundCoordinates ( ) {
xpoints = new double [ this . raceBoundaries . size ( ) ] ;
ypoints = new double [ this . raceBoundaries . size ( ) ] ;
for ( int i = 0 ; i < raceBoundaries . size ( ) ; i + + ) {
GraphCoordinate coord = map . convertGPS ( raceBoundaries . get ( i ) ) ;
xpoints [ i ] = coord . getX ( ) ;
ypoints [ i ] = coord . getY ( ) ;
}
}
/ * *
/ * *
* Set the Canvas to resizable .
* Set the Canvas to resizable .
*
*