@ -1,9 +1,6 @@
package seng302.Model ;
package seng302.Model ;
import com.sun.corba.se.impl.orbutil.graph.Graph ;
import javafx.application.Platform ;
import javafx.beans.property.StringProperty ;
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 ;
@ -15,11 +12,7 @@ import seng302.GPSCoordinate;
import seng302.GraphCoordinate ;
import seng302.GraphCoordinate ;
import seng302.RaceMap ;
import seng302.RaceMap ;
import java.awt.* ;
import java.awt.geom.Rectangle2D ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Random ;
import java.util.concurrent.ThreadLocalRandom ;
/ * *
/ * *
* This creates a JavaFX Canvas that is fills it ' s parent .
* This creates a JavaFX Canvas that is fills it ' s parent .
@ -61,7 +54,7 @@ public class ResizableRaceCanvas extends Canvas {
setMap ( new RaceMap ( 32.278 , - 64.863 , 32.320989 , - 64.821 , ( int ) getWidth ( ) , ( int ) getHeight ( ) ) ) ;
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 ) {
public ResizableRaceCanvas ( double lat1 , double long1 , double lat2 , double long2 ) {
this ( null ) ;
this ( null ) ;
setMap ( new RaceMap ( lat1 , long1 , lat2 , long2 , ( int ) getWidth ( ) , ( int ) getHeight ( ) ) ) ;
setMap ( new RaceMap ( lat1 , long1 , lat2 , long2 , ( int ) getWidth ( ) , ( int ) getHeight ( ) ) ) ;
}
}
@ -77,16 +70,17 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Displays the mark of a race as a circle .
* Displays the mark of a race as a circle .
*
* @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as .
* @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as .
* @param paint Colour the mark is to be coloured .
* @param paint Colour the mark is to be coloured .
* @see GraphCoordinate
* @see GraphCoordinate
* @see Color
* @see Color
* @see Paint
* @see Paint
* /
* /
public void displayMark ( GraphCoordinate graphCoordinate , Paint paint ) {
public void displayMark ( GraphCoordinate graphCoordinate , Paint paint ) {
double d = 25 ;
double d = 25 ;
gc . setFill ( paint ) ;
gc . setFill ( paint ) ;
gc . fillOval ( graphCoordinate . getX ( ) - ( d / 2 ) , graphCoordinate . getY ( ) - ( d / 2 ) , d , d ) ;
gc . fillOval ( graphCoordinate . getX ( ) - ( d / 2 ) , graphCoordinate . getY ( ) - ( d / 2 ) , d , d ) ;
}
}
public void displayBoat ( BoatInRace boat , double angle ) {
public void displayBoat ( BoatInRace boat , double angle ) {
@ -105,9 +99,10 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Displays a line on the map with rectangles on the starting and ending point of the line .
* Displays a line on the map with rectangles on the starting and ending point of the line .
*
* @param graphCoordinateA Starting Point of the line in GraphCoordinate .
* @param graphCoordinateA Starting Point of the line in GraphCoordinate .
* @param graphCoordinateB End Point of the line in GraphCoordinate .
* @param graphCoordinateB End Point of the line in GraphCoordinate .
* @param paint Colour the line is to coloured .
* @param paint Colour the line is to coloured .
* @see GraphCoordinate
* @see GraphCoordinate
* @see Color
* @see Color
* @see Paint
* @see Paint
@ -122,8 +117,9 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Display a point on the Canvas
* Display a point on the Canvas
*
* @param graphCoordinate Coordinate that the point is to be displayed at .
* @param graphCoordinate Coordinate that the point is to be displayed at .
* @param paint Colour that the boat is to be coloured .
* @param paint Colour that the boat is to be coloured .
* @see GraphCoordinate
* @see GraphCoordinate
* @see Paint
* @see Paint
* @see Color
* @see Color
@ -136,8 +132,9 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Displays an arrow on the Canvas
* Displays an arrow on the Canvas
*
* @param coordinate Coordinate that the arrow is to be displayed at .
* @param coordinate Coordinate that the arrow is to be displayed at .
* @param angle Angle that the arrow is to be facing in degrees 0 degrees = North ( Up ) .
* @param angle Angle that the arrow is to be facing in degrees 0 degrees = North ( Up ) .
* @see GraphCoordinate
* @see GraphCoordinate
* /
* /
private void displayArrow ( GraphCoordinate coordinate , int angle ) {
private void displayArrow ( GraphCoordinate coordinate , int angle ) {
@ -152,9 +149,10 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Rotates things on the canvas Note : this must be called in between gc . save ( ) and gc . restore ( ) else they will rotate everything
* Rotates things on the canvas Note : this must be called in between gc . save ( ) and gc . restore ( ) else they will rotate everything
*
* @param angle Bearing angle to rotate at in degrees
* @param angle Bearing angle to rotate at in degrees
* @param px Pivot point x of rotation .
* @param px Pivot point x of rotation .
* @param py Pivot point y of rotation .
* @param py Pivot point y of rotation .
* /
* /
private void rotate ( double angle , double px , double py ) {
private void rotate ( double angle , double px , double py ) {
Rotate r = new Rotate ( angle , px , py ) ;
Rotate r = new Rotate ( angle , px , py ) ;
@ -163,18 +161,19 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Display given name and speed of boat at a graph coordinate
* Display given name and speed of boat at a graph coordinate
* @param name name of the boat
*
* @param speed speed of the boat
* @param name name of the boat
* @param speed speed of the boat
* @param coordinate coordinate the text appears
* @param coordinate coordinate the text appears
* /
* /
private void displayText ( String name , double speed , GraphCoordinate coordinate ) {
private void displayText ( String name , double speed , GraphCoordinate coordinate ) {
String text = String . format ( "%s, %2$.2fkn" , name , speed ) ;
String text = String . format ( "%s, %2$.2fkn" , name , speed ) ;
long xCoord = coordinate . getX ( ) + 20 ;
long xCoord = coordinate . getX ( ) + 20 ;
long yCoord = coordinate . getY ( ) ;
long yCoord = coordinate . getY ( ) ;
if ( xCoord + ( text . length ( ) * 7 ) > = getWidth ( ) ) {
if ( xCoord + ( text . length ( ) * 7 ) > = getWidth ( ) ) {
xCoord - = text . length ( ) * 7 ;
xCoord - = text . length ( ) * 7 ;
}
}
if ( yCoord - ( text . length ( ) * 2 ) < = 0 ) {
if ( yCoord - ( text . length ( ) * 2 ) < = 0 ) {
yCoord + = 30 ;
yCoord + = 30 ;
}
}
gc . fillText ( text , xCoord , yCoord ) ;
gc . fillText ( text , xCoord , yCoord ) ;
@ -188,8 +187,8 @@ public class ResizableRaceCanvas extends Canvas {
this . updateBoats ( ) ;
this . updateBoats ( ) ;
}
}
public void drawBoundaries ( ) {
public void drawBoundaries ( ) {
if ( this . raceBoundaries = = null ) {
if ( this . raceBoundaries = = null ) {
return ;
return ;
}
}
gc . setFill ( Color . AQUA ) ;
gc . setFill ( Color . AQUA ) ;
@ -210,8 +209,8 @@ public class ResizableRaceCanvas extends Canvas {
if ( map = = null ) {
if ( map = = null ) {
return ; //TODO this should return a exception in the future
return ; //TODO this should return a exception in the future
}
}
this . map . setHeight ( ( int ) height ) ;
this . map . setHeight ( ( int ) height ) ;
this . map . setWidth ( ( int ) width ) ;
this . map . setWidth ( ( int ) width ) ;
//finish line
//finish line
gc . setLineWidth ( 2 ) ;
gc . setLineWidth ( 2 ) ;
@ -237,12 +236,13 @@ public class ResizableRaceCanvas extends Canvas {
updateBoats ( ) ;
updateBoats ( ) ;
//display wind direction arrow - specify origin point and angle - angle now set to random angle
//display wind direction arrow - specify origin point and angle - angle now set to random angle
displayArrow ( new GraphCoordinate ( ( int ) getWidth ( ) - 40 , 40 ) , 150 ) ;
displayArrow ( new GraphCoordinate ( ( int ) getWidth ( ) - 40 , 40 ) , 150 ) ;
}
}
/ * *
/ * *
* Draws a boat at a certain GPSCoordinate
* Draws a boat at a certain GPSCoordinate
* @param colour Colour to colour boat .
*
* @param colour Colour to colour boat .
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at .
* @param gpsCoordinates GPScoordinate that the boat is to be drawn at .
* @see GPSCoordinate
* @see GPSCoordinate
* @see Color
* @see Color
@ -255,8 +255,8 @@ public class ResizableRaceCanvas extends Canvas {
/ * *
/ * *
* Toggle the raceAnno value
* Toggle the raceAnno value
* /
* /
public void toggleAnno ( ) {
public void toggleAnno tations ( ) {
if ( raceAnno ) {
if ( raceAnno ) {
raceAnno = false ;
raceAnno = false ;
} else {
} else {
raceAnno = true ;
raceAnno = true ;
@ -276,29 +276,30 @@ public class ResizableRaceCanvas extends Canvas {
GraphCoordinate wakeFrom = this . map . convertGPS ( boat . getCurrentPosition ( ) ) ;
GraphCoordinate wakeFrom = this . map . convertGPS ( boat . getCurrentPosition ( ) ) ;
GraphCoordinate wakeTo = this . map . convertGPS ( boat . getWake ( ) ) ;
GraphCoordinate wakeTo = this . map . convertGPS ( boat . getWake ( ) ) ;
displayLine ( wakeFrom , wakeTo , boat . getColour ( ) ) ;
displayLine ( wakeFrom , wakeTo , boat . getColour ( ) ) ;
} else if ( ! isStart ) {
} else if ( ! isStart ) {
displayBoat ( boat , boat . calculateHeading ( ) ) ;
displayBoat ( boat , boat . calculateHeading ( ) ) ;
} else {
} else {
displayBoat ( boat , 0 ) ;
displayBoat ( boat , 0 ) ;
}
}
if ( raceAnno ) displayText ( boat . getAbbrev ( ) , boat . getVelocity ( ) , this . map . convertGPS ( boat . getCurrentPosition ( ) ) ) ;
if ( raceAnno )
displayText ( boat . getAbbrev ( ) , boat . getVelocity ( ) , this . map . convertGPS ( boat . getCurrentPosition ( ) ) ) ;
}
}
}
}
}
}
public void setRaceBoundaries ( ArrayList < GPSCoordinate > boundaries ) {
public void setRaceBoundaries ( ArrayList < GPSCoordinate > boundaries ) {
this . raceBoundaries = new ArrayList < > ( ) ;
this . raceBoundaries = new ArrayList < > ( ) ;
for ( GPSCoordinate bound : boundaries ) {
for ( GPSCoordinate bound : boundaries ) {
raceBoundaries . add ( bound ) ;
raceBoundaries . add ( bound ) ;
}
}
setRaceBoundCoordinates ( ) ;
setRaceBoundCoordinates ( ) ;
}
}
public void setRaceBoundCoordinates ( ) {
public void setRaceBoundCoordinates ( ) {
xpoints = new double [ this . raceBoundaries . size ( ) ] ;
xpoints = new double [ this . raceBoundaries . size ( ) ] ;
ypoints = new double [ this . raceBoundaries . size ( ) ] ;
ypoints = new double [ this . raceBoundaries . size ( ) ] ;
for ( int i = 0 ; i < raceBoundaries . size ( ) ; i + + ) {
for ( int i = 0 ; i < raceBoundaries . size ( ) ; i + + ) {
GraphCoordinate coord = map . convertGPS ( raceBoundaries . get ( i ) ) ;
GraphCoordinate coord = map . convertGPS ( raceBoundaries . get ( i ) ) ;
xpoints [ i ] = coord . getX ( ) ;
xpoints [ i ] = coord . getX ( ) ;
ypoints [ i ] = coord . getY ( ) ;
ypoints [ i ] = coord . getY ( ) ;
@ -337,17 +338,4 @@ public class ResizableRaceCanvas extends Canvas {
return getHeight ( ) ;
return getHeight ( ) ;
}
}
/ * *
* Draws boats during race setup , when leg heading is not set .
* /
public void drawBoats ( ) {
if ( boats ! = null ) {
for ( BoatInRace boat : boats ) {
if ( boat ! = null ) {
displayBoat ( boat , 0 ) ;
if ( raceAnno ) displayText ( boat . getAbbrev ( ) , boat . getVelocity ( ) , this . map . convertGPS ( boat . getCurrentPosition ( ) ) ) ;
}
}
}
}
}
}