Filled in missing documentation.

- Added Documentation for all Classes.
#documentation
main
Fan-Wu Yang 9 years ago
parent 91861eb5cb
commit dffd77f7a7

@ -3,6 +3,7 @@ package seng302;
import seng302.Model.Leg;
/**
* Constants that are used throughout the program
* Created by Erika on 19-Mar-17.
*/
public class Constants {

@ -7,19 +7,34 @@ import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by Gondr on 15/03/2017.
* Controller parent for app controllers.
* Created by fwy13 on 15/03/2017.
*/
public abstract class Controller implements Initializable{
protected App parent;
/**
* Sets the parent of the application
* @param parent
*/
public void setParent(App parent){
this.parent = parent;
}
/**
* Sets the loads a pane into the parent.
* @param fxmlName
* @throws Exception
*/
public void loadPane(String fxmlName) throws Exception {
this.parent.loadPane(fxmlName);
}
/**
* Initialisation class that is run on start up.
* @param location
* @param resources
*/
@Override
public abstract void initialize(URL location, ResourceBundle resources);
}

@ -6,10 +6,15 @@ import java.net.URL;
import java.util.ResourceBundle;
/**
* Created by Gondr on 15/03/2017.
* Created by fwy13 on 15/03/2017.
*/
public class MainController extends Controller {
/**
* Main Controller for the applications will house the menu and the displayed pane.
* @param location
* @param resources
*/
@Override
public void initialize(URL location, ResourceBundle resources) {

@ -26,14 +26,13 @@ import java.util.ArrayList;
import java.util.ResourceBundle;
/**
* Created by Gondr on 15/03/2017.
* Created by fwy13 on 15/03/2017.
*/
public class RaceController extends Controller{
@FXML
AnchorPane canvasBase;
@FXML
ResizableRaceCanvas raceMap;
ResizableRaceCanvas raceMap;
@FXML
TableView boatInfoTable;
@ -44,10 +43,11 @@ public class RaceController extends Controller{
@FXML
TableColumn<BoatInRace, String> boatMarkColumn;
private GraphicsContext gc;
private RaceMap map;
/**
* updates the ResizableRaceCanvas (raceMap) with most recent data
* @param boats boats that are to be displayed in the race
* @see ResizableRaceCanvas
*/
public void updateMap(ObservableList<BoatInRace> boats) {
BoatInRace[] boatInRaces = new BoatInRace[boats.size()];
raceMap.setBoats(boats.toArray(boatInRaces));
@ -55,6 +55,10 @@ public class RaceController extends Controller{
}
/**
* Updates the array listened by the TableView (boatInfoTable) that displays the boat information.
* @param race Race to listen to.
*/
public void updateInfoTable(Race race) {
boatInfoTable.getItems().clear();
boatInfoTable.setItems(race.getStartingBoats());
@ -91,6 +95,10 @@ public class RaceController extends Controller{
(new Thread(race)).start();
}
/**
* Function for the Bermuda Race.
* @return legs in the Bermuda Race.
*/
private ArrayList<Leg> bermudaCourseLegs() {
ArrayList<Leg> legs = new ArrayList<>();

@ -1,6 +1,7 @@
package seng302;
/**
* GPS Coordinate for the world map.
* Created by esa46 on 15/03/17.
*/
public class GPSCoordinate {
@ -8,18 +9,35 @@ public class GPSCoordinate {
private double latitude;
private double longitude;
/**
* Constructor Method
* @param latitude latitude the coordinate is located at.
* @param longitude Longitude that the coordinate is located at.
*/
public GPSCoordinate(double latitude, double longitude) { this.latitude = latitude; this.longitude = longitude; }
/**
* Gets the Latitude that the Coordinate is at.
* @return Returns the latitude of the Coordinate.
*/
public double getLatitude() {
return latitude;
}
/**
* Gets the Longitude that the Coordinate is at.
* @return Returns the longitude of the Coordinate.
*/
public double getLongitude() {
return longitude;
}
/**
* To String method of the Coordinate in the form Latitude: $f, Longitude: $f.
* @return A String representation of the GPSCoordinate Class.
*/
public String toString() {
return String.format("Latitude: %f Longitude: %f", latitude, longitude);
return String.format("Latitude: %f, Longitude: %f", latitude, longitude);
}
}

@ -1,18 +1,32 @@
package seng302;
/**
* Graph Coordinate that is to be displayed on the Canvas
* Created by cbt24 on 15/03/17.
*/
public class GraphCoordinate {
private int x;
private int y;
/**
* Constructor method.
* @param x X coordinate.
* @param y Y coordinate.
*/
public GraphCoordinate(int x, int y) { this.x = x; this.y = y; }
/**
* Returns the X coordinate.
* @return x axis Coordinate.
*/
public int getX() {
return x;
}
/**
* Returns the Y coordinate.
* @return y axis Coordinate.
*/
public int getY() {
return y;
}

@ -7,6 +7,7 @@ import seng302.GPSCoordinate;
/**
* Boat in the Race extends Boat.
* Created by esa46 on 15/03/17.
*/
public class BoatInRace extends Boat {
@ -17,47 +18,96 @@ public class BoatInRace extends Boat {
private long timeFinished;
private Color colour;
/**
*
* @return Returns the current position of the boat in a GPSCoordinate Class.
* @see GPSCoordinate
*/
public GPSCoordinate getCurrentPosition() {
return currentPosition;
}
/**
*
* @return Returns the time that the boat finished the race.
*/
public long getTimeFinished() {
return timeFinished;
}
/**
*
* @return Returns the colour of the boat.
*/
public Color getColour() {
return colour;
}
/**
* Sets the colour that boat will be shown as when drawn on the ResizableRaceCanvas.
* @param colour Colour that the boat is to be set to.
* @see ResizableRaceCanvas
*/
public void setColour(Color colour) {
this.colour = colour;
}
/**
* Sets the time that the boat finished the race.
* @param timeFinished Time the boat finished the race.
*/
public void setTimeFinished(long timeFinished) {
this.timeFinished = timeFinished;
}
/**
* Constructor method.
* @param name Name of the boat.
* @param velocity Speed that the boat travels.
*/
public BoatInRace(String name, double velocity) {
super(name, velocity);
}
/**
* Gets the current leg that the boat is on.
* @return returns the leg the boat is on in a Leg class
* @see Leg
*/
public Leg getCurrentLeg() {
return currentLeg;
}
/**
* Sets the current Leg of that the boat is on.
* @param currentLeg Leg class that the boat is currently on.
* @see Leg
*/
public void setCurrentLeg(Leg currentLeg) {
this.currentLeg = currentLeg;
}
/**
* Gets the distance travelled by the boat in the leg.
* @return Returns the value in nautical miles (1.852km) that the boat has traversed.
*/
public double getDistanceTravelledInLeg() {
return distanceTravelledInLeg;
}
/**
* Sets the current position on the GPS that the boat.
* @param position GPSCoordinate of the position that the boat is currently on.
* @see GPSCoordinate
*/
public void setCurrentPosition(GPSCoordinate position) {
this.currentPosition = position;
}
/**
* Sets the distance travelled by the boat in the leg in nautical miles (1.852km)
* @param distanceTravelledInLeg Distance travelled by the boat in nautical miles.
*/
public void setDistanceTravelledInLeg(double distanceTravelledInLeg) {
this.distanceTravelledInLeg = distanceTravelledInLeg;
}
@ -65,7 +115,7 @@ public class BoatInRace extends Boat {
/**
* Calculates the bearing of the travel via map coordinates of the raceMarkers
* @return
* @return the heading that the boat is heading towards in degrees.
*/
public double calculateHeading(){
//to be changed to coordinates when used to match reality.

@ -30,21 +30,25 @@ public class Leg {
this.distance = calculateDistance();
}
/**
* Construction Method
* @param name Name of the Leg
*/
public Leg(String name) {
this.name = name;
}
/**
*
* @return the name of the Leg
* Returns the name of the Leg
* @return Returns the name of the Leg
*/
public String getName() {
return name;
}
/**
*
* @return the total distance of the leg.
* Get the distance in nautical miles
* @return Returns the total distance of the leg.
*/
public double getDistance() {
return distance;
@ -53,32 +57,43 @@ public class Leg {
/**
*
* @return the name of the Leg
* @return Returns the name of the Leg
*/
public String toString() {
return name;
}
/**
*
* @return the coordinate of the start of the leg )
* Returns the coordinates in GPSCoordinate class of the boats starting coordinate.
* @return Returns the coordinate of the start of the leg.
* @see GPSCoordinate
*/
public GPSCoordinate getStartGraphCoordinate() {
return startGPSCoordinate;
}
/**
*
* @return the coordinate of the end of the leg
* Returns the coordinates in a GPSCoordinate class that the boat ends on.
* @return Returns the coordinate of the end of the leg.
* @see GPSCoordinate
*/
public GPSCoordinate getEndGraphCoordinate() {
return endGPSCoordinate;
}
/**
* Returns the leg number that the leg exists in the Race
* @return Returns the Leg
* @see Race
*/
public int getLegNumber() {
return legNumber;
}
/**
* Calculates the distance that the legs are in nautical miles (1.852 km).
* @return Returns the leg distance.
*/
private double calculateDistance() {
GeodeticCalculator calc = new GeodeticCalculator();

@ -35,16 +35,27 @@ public abstract class Race implements Runnable {
this.controller = controller;
}
/**
* Constructor for Race class
* @param boats boats participating in the race.
* @param marks legs that there are in the race.
*/
public Race(BoatInRace[] boats, ArrayList<Leg> marks) {
this(boats, marks, null);
}
/**
* Runnable for the thread.
*/
public void run() {
updateController();
preRace();
simulateRace();
}
/**
* Set up the state in waiting for the race starts.
*/
private void preRace() {
//show the boats participating.
System.out.println("Boats Participating:");
@ -96,10 +107,15 @@ public abstract class Race implements Runnable {
}
}
/**
* Checks the position of the boat, this updates the boats current position.
* @param boat Boat that the postion is to be updated for.
* @param timeElapsed Time that has elapse since the start of the the race.
* @see BoatInRace
*/
protected void checkPosition(BoatInRace boat, long timeElapsed) {
if (boat.getDistanceTravelledInLeg() > boat.getCurrentLeg().getDistance()){
//updateController();
//updateController(); removed as we do not update the table every time anymore.
//boat has passed onto new leg
if (boat.getCurrentLeg().getName().equals("Finish")) {
//boat has finished
@ -114,11 +130,19 @@ public abstract class Race implements Runnable {
}
}
/**
* Update call for the controller.
*/
protected void updateController() {
if(controller != null) controller.updateInfoTable(this);
}
/**
* Returns the boats that have started the race.
* @return ObservableList of BoatInRace class that participated in the race.
* @see ObservableList
* @see BoatInRace
*/
public ObservableList<BoatInRace> getStartingBoats() {
return startingBoats;
}

@ -14,13 +14,19 @@ import seng302.RaceMap;
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.
*/
public class ResizableRaceCanvas extends Canvas {
GraphicsContext gc;
RaceMap map;
private GraphicsContext gc;
private RaceMap map;
private BoatInRace[] boats;
/**
* Sets the boats that are to be displayed in this race.
* @param boats
*/
public void setBoats(BoatInRace[] boats) {
this.boats = boats;
}
@ -33,19 +39,43 @@ public class ResizableRaceCanvas extends Canvas {
heightProperty().addListener(evt -> drawRaceMap());
}
/**
* Constructor
*/
public ResizableRaceCanvas(){
this(null);
}
/**
* Sets the RaceMap that the RaceCanvas is to be displaying for.
* @param map
*/
public void setMap (RaceMap 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){
gc.setFill(paint);
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){
gc.setStroke(paint);
gc.setFill(paint);
@ -54,11 +84,25 @@ public class ResizableRaceCanvas extends Canvas {
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){
gc.setFill(paint);
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){
gc.save();
rotate(angle, coordinate.getX(),coordinate.getY());
@ -68,13 +112,20 @@ public class ResizableRaceCanvas extends Canvas {
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) {
Rotate r = new Rotate(angle, px, py);
gc.setTransform(r.getMxx(), r.getMyx(), r.getMxy(), r.getMyy(), r.getTx(), r.getTy());
}
/**
* Draws the Race Map
*/
public void drawRaceMap() {
double width = getWidth();
@ -120,24 +171,45 @@ public class ResizableRaceCanvas extends Canvas {
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) {
GraphCoordinate graphCoordinate = this.map.convertGPS(gpsCoordinates);
System.out.println("DrawingBoat" + gpsCoordinates.getLongitude());
displayPoint(graphCoordinate, colour);
}
/**
* Set the Canvas to resizable.
* @return That the Canvas is resizable.
*/
@Override
public boolean isResizable() {
return true;
}
/**
* Returns the preferred width of the Canvas
* @param width
* @return Returns the width of the Canvas
*/
@Override
public double prefWidth(double height) {
public double prefWidth(double width) {
return getWidth();
}
/**
* Returns the preferred height of the Canvas
* @param height
* @return Returns the height of the Canvas
*/
@Override
public double prefHeight(double width) {
public double prefHeight(double height) {
return getHeight();
}
}

@ -22,6 +22,13 @@ public class RaceMap {
return new GraphCoordinate((int) ((height * (lon - y1) / (y2 - y1))),(int) (width * (lat - x1) / (x2 - x1)));
}
/**
* Converts the GPS Coordinate to GraphCoordinates
* @param coordinate GPSCoordinate representation of Latitude and Longitude.
* @return GraphCoordinate that the GPS is coordinates are to be displayed on the map.
* @see GraphCoordinate
* @see GPSCoordinate
*/
public GraphCoordinate convertGPS(GPSCoordinate coordinate) {
return convertGPS(coordinate.getLatitude(), coordinate.getLongitude());
}

Loading…
Cancel
Save