Refactoring

#story[24]
main
Erika Savell 9 years ago
parent e2f9a710aa
commit ec9574fd9d

@ -18,6 +18,7 @@ public class App extends Application {
/** /**
* Entry point for running the programme * Entry point for running the programme
*
* @param args * @param args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
@ -26,6 +27,7 @@ public class App extends Application {
/** /**
* Loads and sets up the GUI elements * Loads and sets up the GUI elements
*
* @param primaryStage * @param primaryStage
* @throws Exception * @throws Exception
*/ */
@ -55,6 +57,7 @@ public class App extends Application {
/** /**
* Loads panes for use in the GUI * Loads panes for use in the GUI
*
* @param fxmlName * @param fxmlName
* @throws Exception * @throws Exception
*/ */

@ -5,27 +5,16 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue; import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.util.Callback; import javafx.util.Callback;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
import seng302.GPSCoordinate;
import seng302.Model.*; import seng302.Model.*;
import seng302.RaceXMLReader; import seng302.RaceXMLReader;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException; import java.io.IOException;
import java.awt.geom.Point2D;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ResourceBundle; import java.util.ResourceBundle;
@ -43,16 +32,12 @@ public class RaceController extends Controller{
GridPane startScreen; GridPane startScreen;
@FXML @FXML
SplitPane ongoingRacePane; SplitPane ongoingRacePane;
@FXML @FXML
CheckBox showFPS; CheckBox showFPS;
@FXML @FXML
CheckBox showAnno; CheckBox showAnnotations;
@FXML @FXML
Label timer; Label timer;
@FXML @FXML
Label FPS; Label FPS;
@ -123,8 +108,6 @@ public class RaceController extends Controller{
@Override @Override
public void initialize(URL location, ResourceBundle resources) { public void initialize(URL location, ResourceBundle resources) {
//listener for fps //listener for fps
/*Tooltip tp = new Tooltip("");
tp.install(timer, tp);*/
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() { showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov, public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) { Boolean old_val, Boolean new_val) {
@ -154,9 +137,9 @@ public class RaceController extends Controller{
} catch (ParserConfigurationException e) { } catch (ParserConfigurationException e) {
e.printStackTrace(); e.printStackTrace();
} }
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()]; BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
boats = raceXMLReader.getBoats().toArray(boats); boats = raceXMLReader.getBoats().toArray(boats);
//BoatInRace[] boats = generateAC35Competitors();
double lat1 = raceXMLReader.getMapTopLeft().getLatitude(); double lat1 = raceXMLReader.getMapTopLeft().getLatitude();
double long1 = raceXMLReader.getMapTopLeft().getLongitude(); double long1 = raceXMLReader.getMapTopLeft().getLongitude();
double lat2 = raceXMLReader.getMapBottomRight().getLatitude(); double lat2 = raceXMLReader.getMapBottomRight().getLatitude();
@ -174,14 +157,12 @@ public class RaceController extends Controller{
i++; i++;
} }
raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2); raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2);
raceMap.setMouseTransparent(true); raceMap.setMouseTransparent(true);
raceMap.widthProperty().bind(canvasBase.widthProperty()); raceMap.widthProperty().bind(canvasBase.widthProperty());
raceMap.heightProperty().bind(canvasBase.heightProperty()); raceMap.heightProperty().bind(canvasBase.heightProperty());
raceMap.setBoats(startingBoats); raceMap.setBoats(startingBoats);
raceMap.setRaceBoundaries(raceXMLReader.getBoundary()); raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
//raceMap.drawBoats();
raceMap.drawRaceMap(); raceMap.drawRaceMap();
raceMap.setVisible(true); raceMap.setVisible(true);
@ -190,7 +171,35 @@ public class RaceController extends Controller{
ongoingRacePane.setVisible(true); ongoingRacePane.setVisible(true);
initializeFPS();
initializeAnnotations();
new Thread((race)).start();
}
/**
* Set the value for the race clock label
*
* @param time time that the label will be updated to
*/
public void setTimer(String time) {
timer.setText(time);
}
/**
* Set the value for the fps label
*
* @param fps fps that the label will be updated to
*/
public void setFrames(String fps) {
FPS.setText((fps));
}
/**
* Set up FPS display at bottom of screen
*/
private void initializeFPS() {
showFPS.setVisible(true); showFPS.setVisible(true);
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() { showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov, public void changed(ObservableValue<? extends Boolean> ov,
@ -202,32 +211,20 @@ public class RaceController extends Controller{
} }
} }
}); });
}
/**
* Set up boat annotations
*/
private void initializeAnnotations() {
//listener for annotation //listener for annotation
showAnno.selectedProperty().addListener(new ChangeListener<Boolean>() { showAnnotations.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov, public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) { Boolean old_val, Boolean new_val) {
raceMap.toggleAnno(); raceMap.toggleAnnotations();
raceMap.update(); raceMap.update();
} }
}); });
new Thread((race)).start();
} }
/**
* Set the value for the race clock label
* @param time time that the label will be updated to
*/
public void setTimer(String time) {
timer.setText(time);
}
/**
* Set the value for the fps label
* @param fps fps that the label will be updated to
*/
public void setFrames(String fps) { FPS.setText((fps)); }
} }

@ -35,6 +35,7 @@ public class Boat {
/** /**
* Sets the boat name * Sets the boat name
*
* @param name * @param name
*/ */
public void setName(String name) { public void setName(String name) {
@ -50,6 +51,7 @@ public class Boat {
/** /**
* Sets the speed of the boat in knots. * Sets the speed of the boat in knots.
*
* @param velocity speed in knots * @param velocity speed in knots
*/ */
public void setVelocity(double velocity) { public void setVelocity(double velocity) {
@ -59,6 +61,7 @@ public class Boat {
/** /**
* Print method prints the name of the boat * Print method prints the name of the boat
*
* @return Name of the boat. * @return Name of the boat.
*/ */
public String toString() { public String toString() {

@ -83,6 +83,7 @@ public class BoatInRace extends Boat {
* Returns the position of the end of the boat's wake, which is 180 degrees * Returns the position of the end of the boat's wake, which is 180 degrees
* from the boat's heading, and whose length is proportional to the boat's * from the boat's heading, and whose length is proportional to the boat's
* speed. * speed.
*
* @return GPSCoordinate of wake endpoint. * @return GPSCoordinate of wake endpoint.
*/ */
public GPSCoordinate getWake() { public GPSCoordinate getWake() {
@ -107,6 +108,7 @@ public class BoatInRace extends Boat {
/** /**
* Sets the boat's scaled velocity * Sets the boat's scaled velocity
*
* @param velocity * @param velocity
*/ */
public void setScaledVelocity(double velocity) { public void setScaledVelocity(double velocity) {
@ -219,6 +221,7 @@ public class BoatInRace extends Boat {
/** /**
* Sets whether boat is finished or not * Sets whether boat is finished or not
*
* @param bool * @param bool
*/ */
public void setFinished(boolean bool) { public void setFinished(boolean bool) {

@ -28,6 +28,7 @@ public class ConstantVelocityRace extends Race {
/** /**
* Calculates the distance a boat has travelled and updates its current position according to this value. * Calculates the distance a boat has travelled and updates its current position according to this value.
*
* @param boat * @param boat
* @param millisecondsElapsed * @param millisecondsElapsed
*/ */
@ -50,6 +51,7 @@ public class ConstantVelocityRace extends Race {
/** /**
* Calculates the boats next GPS position based on its distance travelled and heading * Calculates the boats next GPS position based on its distance travelled and heading
*
* @param oldCoordinates GPS coordinates of the boat's starting position * @param oldCoordinates GPS coordinates of the boat's starting position
* @param distanceTravelled distance in nautical miles * @param distanceTravelled distance in nautical miles
* @param azimuth boat's current direction. Value between -180 and 180 * @param azimuth boat's current direction. Value between -180 and 180

@ -1,6 +1,5 @@
package seng302.Model; package seng302.Model;
import com.oracle.xmlns.internal.webservices.jaxws_databinding.SoapBindingUse;
import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants; import seng302.Constants;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
@ -102,5 +101,4 @@ public class Leg {
} }
} }

@ -2,7 +2,6 @@ package seng302.Model;
import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.GeodeticCalculator;
import seng302.GPSCoordinate; import seng302.GPSCoordinate;
import sun.java2d.loops.GeneralRenderer;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;

@ -3,9 +3,7 @@ package seng302.Model;
import javafx.animation.AnimationTimer; import javafx.animation.AnimationTimer;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import org.geotools.referencing.GeodeticCalculator; import org.geotools.referencing.GeodeticCalculator;
import seng302.Controllers.RaceController; import seng302.Controllers.RaceController;
@ -38,6 +36,7 @@ public abstract class Race implements Runnable {
/** /**
* Initailiser for Race * Initailiser for Race
*
* @param boats Takes in an array of boats that are participating in the race. * @param boats Takes in an array of boats that are participating in the race.
* @param legs Number of marks in order that the boats pass in order to complete the race. * @param legs Number of marks in order that the boats pass in order to complete the race.
*/ */
@ -134,6 +133,7 @@ public abstract class Race implements Runnable {
/** /**
* Takes total time elapsed and format to hour:minute:second * Takes total time elapsed and format to hour:minute:second
*
* @return Formatted time as string * @return Formatted time as string
*/ */
protected String calcTimer() { protected String calcTimer() {
@ -152,18 +152,24 @@ public abstract class Race implements Runnable {
/** /**
* Updates the calculated time to the timer label * Updates the calculated time to the timer label
*
* @param time The calculated time from calcTimer() method * @param time The calculated time from calcTimer() method
*/ */
protected void updateTime(String time) { protected void updateTime(String time) {
Platform.runLater(() -> {controller.setTimer(time);}); Platform.runLater(() -> {
controller.setTimer(time);
});
} }
/** /**
* Update the calculated fps to the fps label * Update the calculated fps to the fps label
*
* @param fps The new calculated fps value * @param fps The new calculated fps value
*/ */
private void updateFPS(int fps) { private void updateFPS(int fps) {
Platform.runLater(() -> {controller.setFrames("FPS: " + fps);}); Platform.runLater(() -> {
controller.setFrames("FPS: " + fps);
});
} }
private boolean doNotFinish() { private boolean doNotFinish() {
@ -192,11 +198,7 @@ public abstract class Race implements Runnable {
@Override @Override
public void handle(long arg0) { public void handle(long arg0) {
/*long timeLoopStarted;
long timeLoopEnded;
int fps = 0;*/
if (boatsFinished < startingBoats.size()) { if (boatsFinished < startingBoats.size()) {
//timeLoopStarted = System.currentTimeMillis();
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted; totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
for (BoatInRace boat : startingBoats) { for (BoatInRace boat : startingBoats) {
@ -230,6 +232,7 @@ public abstract class Race implements Runnable {
/** /**
* Checks the position of the boat, this updates the boats current position. * Checks the position of the boat, this updates the boats current position.
*
* @param boat Boat that the postion is to be updated for. * @param boat Boat that the postion is to be updated for.
* @param timeElapsed Time that has elapse since the start of the the race. * @param timeElapsed Time that has elapse since the start of the the race.
* @see BoatInRace * @see BoatInRace
@ -272,6 +275,7 @@ public abstract class Race implements Runnable {
/** /**
* Returns the boats that have started the race. * Returns the boats that have started the race.
*
* @return ObservableList of BoatInRace class that participated in the race. * @return ObservableList of BoatInRace class that participated in the race.
* @see ObservableList * @see ObservableList
* @see BoatInRace * @see BoatInRace
@ -282,6 +286,7 @@ public abstract class Race implements Runnable {
/** /**
* Updates the boat's gps coordinates depending on time elapsed * Updates the boat's gps coordinates depending on time elapsed
*
* @param boat * @param boat
* @param millisecondsElapsed * @param millisecondsElapsed
*/ */
@ -289,7 +294,8 @@ public abstract class Race implements Runnable {
/** /**
* Creates a list of starting positions for the different boats, so they do not appear cramped at the start line * Creates a list of starting positions for the different boats, so they do not appear cramped at the start line
* @return *
* @return list of starting positions
*/ */
public ArrayList<Marker> getSpreadStartingPositions() { public ArrayList<Marker> getSpreadStartingPositions() {

@ -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.
@ -77,6 +70,7 @@ 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
@ -105,6 +99,7 @@ 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.
@ -122,6 +117,7 @@ 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
@ -136,6 +132,7 @@ 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
@ -152,6 +149,7 @@ 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.
@ -163,6 +161,7 @@ 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 name name of the boat
* @param speed speed of the boat * @param speed speed of the boat
* @param coordinate coordinate the text appears * @param coordinate coordinate the text appears
@ -242,6 +241,7 @@ public class ResizableRaceCanvas extends Canvas {
/** /**
* 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
@ -255,7 +255,7 @@ public class ResizableRaceCanvas extends Canvas {
/** /**
* Toggle the raceAnno value * Toggle the raceAnno value
*/ */
public void toggleAnno(){ public void toggleAnnotations() {
if (raceAnno) { if (raceAnno) {
raceAnno = false; raceAnno = false;
} else { } else {
@ -282,7 +282,8 @@ public class ResizableRaceCanvas extends Canvas {
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()));
} }
} }
} }
@ -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()));
}
}
}
}
} }

@ -1,9 +1,9 @@
package seng302; package seng302;
import javafx.scene.paint.Color; import javafx.scene.paint.Color;
import org.w3c.dom.*; import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import seng302.Model.Boat;
import seng302.Model.BoatInRace; import seng302.Model.BoatInRace;
import seng302.Model.Leg; import seng302.Model.Leg;
import seng302.Model.Marker; import seng302.Model.Marker;
@ -140,7 +140,9 @@ public class RaceXMLReader extends XMLReader{
finishPt2 = getCoordinates(nMarks, 4, 1); finishPt2 = getCoordinates(nMarks, 4, 1);
} }
private Marker getMarker(NodeList start) { return getMarker(start, 0); } private Marker getMarker(NodeList start) {
return getMarker(start, 0);
}
private Marker getMarker(NodeList start, int startIndex) { private Marker getMarker(NodeList start, int startIndex) {
return getMarker(start, startIndex, 0); return getMarker(start, startIndex, 0);
@ -183,6 +185,7 @@ public class RaceXMLReader extends XMLReader{
/** /**
* Returns the coordinate TODO raise exception that runs when the XML is formatted wrongly. * Returns the coordinate TODO raise exception that runs when the XML is formatted wrongly.
*
* @param coordNode * @param coordNode
* @return * @return
*/ */

@ -1,10 +1,14 @@
package seng302; package seng302;
import org.w3c.dom.*; import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.xml.parsers.*; import javax.xml.parsers.DocumentBuilder;
import java.io.*; import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.io.InputStream;
/** /**
* Created by fwy13 on 26/03/2017. * Created by fwy13 on 26/03/2017.

@ -76,7 +76,7 @@
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
<children> <children>
<CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" /> <CheckBox fx:id="showFPS" mnemonicParsing="false" selected="true" text="Show FPS" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
<CheckBox fx:id="showAnno" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" /> <CheckBox fx:id="showAnnotations" mnemonicParsing="false" selected="true" text="Show Annotation" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="30.0" />
</children> </children>
</AnchorPane> </AnchorPane>
</content> </content>

Loading…
Cancel
Save