|
|
|
@ -14,13 +14,19 @@ import seng302.RaceMap;
|
|
|
|
import java.util.Random;
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This creates a JavaFX Canvas that is fills it's parent.
|
|
|
|
|
|
|
|
* Cannot be downsized.
|
|
|
|
* Created by fwy13 on 17/03/17.
|
|
|
|
* Created by fwy13 on 17/03/17.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class ResizableRaceCanvas extends Canvas {
|
|
|
|
public class ResizableRaceCanvas extends Canvas {
|
|
|
|
GraphicsContext gc;
|
|
|
|
private GraphicsContext gc;
|
|
|
|
RaceMap map;
|
|
|
|
private RaceMap map;
|
|
|
|
private BoatInRace[] boats;
|
|
|
|
private BoatInRace[] boats;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sets the boats that are to be displayed in this race.
|
|
|
|
|
|
|
|
* @param boats
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setBoats(BoatInRace[] boats) {
|
|
|
|
public void setBoats(BoatInRace[] boats) {
|
|
|
|
this.boats = boats;
|
|
|
|
this.boats = boats;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -33,19 +39,43 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
heightProperty().addListener(evt -> drawRaceMap());
|
|
|
|
heightProperty().addListener(evt -> drawRaceMap());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Constructor
|
|
|
|
|
|
|
|
*/
|
|
|
|
public ResizableRaceCanvas(){
|
|
|
|
public ResizableRaceCanvas(){
|
|
|
|
this(null);
|
|
|
|
this(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Sets the RaceMap that the RaceCanvas is to be displaying for.
|
|
|
|
|
|
|
|
* @param map
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void setMap (RaceMap map) {
|
|
|
|
public void setMap (RaceMap map) {
|
|
|
|
this.map = map;
|
|
|
|
this.map = map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Displays the mark of a race as a circle.
|
|
|
|
|
|
|
|
* @param graphCoordinate Latitude and Logintude in GraphCoordinate that it is to be displayed as.
|
|
|
|
|
|
|
|
* @param paint Colour the mark is to be coloured.
|
|
|
|
|
|
|
|
* @see GraphCoordinate
|
|
|
|
|
|
|
|
* @see Color
|
|
|
|
|
|
|
|
* @see Paint
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
public void displayMark(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 15, 15);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 15, 15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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 graphCoordinateB End Point of the line in GraphCoordinate.
|
|
|
|
|
|
|
|
* @param paint Colour the line is to coloured.
|
|
|
|
|
|
|
|
* @see GraphCoordinate
|
|
|
|
|
|
|
|
* @see Color
|
|
|
|
|
|
|
|
* @see Paint
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void displayLine(GraphCoordinate graphCoordinateA, GraphCoordinate graphCoordinateB, Paint paint){
|
|
|
|
public void displayLine(GraphCoordinate graphCoordinateA, GraphCoordinate graphCoordinateB, Paint paint){
|
|
|
|
gc.setStroke(paint);
|
|
|
|
gc.setStroke(paint);
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.setFill(paint);
|
|
|
|
@ -54,11 +84,25 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
gc.strokeLine(graphCoordinateA.getX(), graphCoordinateA.getY(), graphCoordinateB.getX(), graphCoordinateB.getY());
|
|
|
|
gc.strokeLine(graphCoordinateA.getX(), graphCoordinateA.getY(), graphCoordinateB.getX(), graphCoordinateB.getY());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Display a point on the Canvas
|
|
|
|
|
|
|
|
* @param graphCoordinate Coordinate that the point is to be displayed at.
|
|
|
|
|
|
|
|
* @param paint Colour that the boat is to be coloured.
|
|
|
|
|
|
|
|
* @see GraphCoordinate
|
|
|
|
|
|
|
|
* @see Paint
|
|
|
|
|
|
|
|
* @see Color
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void displayPoint(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
public void displayPoint(GraphCoordinate graphCoordinate, Paint paint){
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.setFill(paint);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
|
|
|
gc.fillOval(graphCoordinate.getX(), graphCoordinate.getY(), 10, 10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Displays an arrow on the Canvas
|
|
|
|
|
|
|
|
* @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).
|
|
|
|
|
|
|
|
* @see GraphCoordinate
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void displayArrow(GraphCoordinate coordinate, int angle){
|
|
|
|
public void displayArrow(GraphCoordinate coordinate, int angle){
|
|
|
|
gc.save();
|
|
|
|
gc.save();
|
|
|
|
rotate(angle, coordinate.getX(),coordinate.getY());
|
|
|
|
rotate(angle, coordinate.getX(),coordinate.getY());
|
|
|
|
@ -68,13 +112,20 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
gc.restore();
|
|
|
|
gc.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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 px Pivot point x 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);
|
|
|
|
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
|
|
|
|
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Draws the Race Map
|
|
|
|
|
|
|
|
*/
|
|
|
|
public void drawRaceMap() {
|
|
|
|
public void drawRaceMap() {
|
|
|
|
|
|
|
|
|
|
|
|
double width = getWidth();
|
|
|
|
double width = getWidth();
|
|
|
|
@ -120,24 +171,45 @@ public class ResizableRaceCanvas extends Canvas {
|
|
|
|
displayArrow(new GraphCoordinate(500, 20), 100);
|
|
|
|
displayArrow(new GraphCoordinate(500, 20), 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 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) {
|
|
|
|
public void drawBoat(Color colour, GPSCoordinate gpsCoordinates) {
|
|
|
|
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
|
|
|
|
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
|
|
|
|
System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
|
|
|
|
System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
|
|
|
|
displayPoint(graphCoordinate, colour);
|
|
|
|
displayPoint(graphCoordinate, colour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Set the Canvas to resizable.
|
|
|
|
|
|
|
|
* @return That the Canvas is resizable.
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean isResizable() {
|
|
|
|
public boolean isResizable() {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the preferred width of the Canvas
|
|
|
|
|
|
|
|
* @param width
|
|
|
|
|
|
|
|
* @return Returns the width of the Canvas
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public double prefWidth(double height) {
|
|
|
|
public double prefWidth(double width) {
|
|
|
|
return getWidth();
|
|
|
|
return getWidth();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Returns the preferred height of the Canvas
|
|
|
|
|
|
|
|
* @param height
|
|
|
|
|
|
|
|
* @return Returns the height of the Canvas
|
|
|
|
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public double prefHeight(double width) {
|
|
|
|
public double prefHeight(double height) {
|
|
|
|
return getHeight();
|
|
|
|
return getHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|