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
*
* @param args
*/
public static void main(String[] args) {
@ -26,6 +27,7 @@ public class App extends Application {
/**
* Loads and sets up the GUI elements
*
* @param primaryStage
* @throws Exception
*/
@ -55,6 +57,7 @@ public class App extends Application {
/**
* Loads panes for use in the GUI
*
* @param fxmlName
* @throws Exception
*/

@ -5,27 +5,16 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
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.util.Callback;
import org.xml.sax.SAXException;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Constants;
import seng302.GPSCoordinate;
import seng302.Model.*;
import seng302.RaceXMLReader;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.awt.geom.Point2D;
import java.net.URL;
import java.util.ArrayList;
import java.util.ResourceBundle;
@ -43,16 +32,12 @@ public class RaceController extends Controller{
GridPane startScreen;
@FXML
SplitPane ongoingRacePane;
@FXML
CheckBox showFPS;
@FXML
CheckBox showAnno;
CheckBox showAnnotations;
@FXML
Label timer;
@FXML
Label FPS;
@ -123,8 +108,6 @@ public class RaceController extends Controller{
@Override
public void initialize(URL location, ResourceBundle resources) {
//listener for fps
/*Tooltip tp = new Tooltip("");
tp.install(timer, tp);*/
showFPS.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) {
@ -154,9 +137,9 @@ public class RaceController extends Controller{
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
BoatInRace[] boats = new BoatInRace[raceXMLReader.getBoats().size()];
boats = raceXMLReader.getBoats().toArray(boats);
//BoatInRace[] boats = generateAC35Competitors();
double lat1 = raceXMLReader.getMapTopLeft().getLatitude();
double long1 = raceXMLReader.getMapTopLeft().getLongitude();
double lat2 = raceXMLReader.getMapBottomRight().getLatitude();
@ -174,14 +157,12 @@ public class RaceController extends Controller{
i++;
}
raceMap = new ResizableRaceCanvas(lat1, long1, lat2, long2);
raceMap.setMouseTransparent(true);
raceMap.widthProperty().bind(canvasBase.widthProperty());
raceMap.heightProperty().bind(canvasBase.heightProperty());
raceMap.setBoats(startingBoats);
raceMap.setRaceBoundaries(raceXMLReader.getBoundary());
//raceMap.drawBoats();
raceMap.drawRaceMap();
raceMap.setVisible(true);
@ -190,7 +171,35 @@ public class RaceController extends Controller{
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.selectedProperty().addListener(new ChangeListener<Boolean>() {
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
showAnno.selectedProperty().addListener(new ChangeListener<Boolean>() {
showAnnotations.selectedProperty().addListener(new ChangeListener<Boolean>() {
public void changed(ObservableValue<? extends Boolean> ov,
Boolean old_val, Boolean new_val) {
raceMap.toggleAnno();
raceMap.toggleAnnotations();
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
*
* @param name
*/
public void setName(String name) {
@ -50,6 +51,7 @@ public class Boat {
/**
* Sets the speed of the boat in knots.
*
* @param velocity speed in knots
*/
public void setVelocity(double velocity) {
@ -59,6 +61,7 @@ public class Boat {
/**
* Print method prints the name of the boat
*
* @return Name of the boat.
*/
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
* from the boat's heading, and whose length is proportional to the boat's
* speed.
*
* @return GPSCoordinate of wake endpoint.
*/
public GPSCoordinate getWake() {
@ -107,6 +108,7 @@ public class BoatInRace extends Boat {
/**
* Sets the boat's scaled velocity
*
* @param velocity
*/
public void setScaledVelocity(double velocity) {
@ -219,6 +221,7 @@ public class BoatInRace extends Boat {
/**
* Sets whether boat is finished or not
*
* @param 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.
*
* @param boat
* @param millisecondsElapsed
*/
@ -50,6 +51,7 @@ public class ConstantVelocityRace extends Race {
/**
* Calculates the boats next GPS position based on its distance travelled and heading
*
* @param oldCoordinates GPS coordinates of the boat's starting position
* @param distanceTravelled distance in nautical miles
* @param azimuth boat's current direction. Value between -180 and 180

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

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

@ -3,9 +3,7 @@ package seng302.Model;
import javafx.animation.AnimationTimer;
import javafx.application.Platform;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import org.geotools.referencing.GeodeticCalculator;
import seng302.Controllers.RaceController;
@ -38,6 +36,7 @@ public abstract class Race implements Runnable {
/**
* Initailiser for 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.
*/
@ -134,6 +133,7 @@ public abstract class Race implements Runnable {
/**
* Takes total time elapsed and format to hour:minute:second
*
* @return Formatted time as string
*/
protected String calcTimer() {
@ -152,18 +152,24 @@ public abstract class Race implements Runnable {
/**
* Updates the calculated time to the timer label
*
* @param time The calculated time from calcTimer() method
*/
protected void updateTime(String time) {
Platform.runLater(() -> {controller.setTimer(time);});
Platform.runLater(() -> {
controller.setTimer(time);
});
}
/**
* Update the calculated fps to the fps label
*
* @param fps The new calculated fps value
*/
private void updateFPS(int fps) {
Platform.runLater(() -> {controller.setFrames("FPS: " + fps);});
Platform.runLater(() -> {
controller.setFrames("FPS: " + fps);
});
}
private boolean doNotFinish() {
@ -192,11 +198,7 @@ public abstract class Race implements Runnable {
@Override
public void handle(long arg0) {
/*long timeLoopStarted;
long timeLoopEnded;
int fps = 0;*/
if (boatsFinished < startingBoats.size()) {
//timeLoopStarted = System.currentTimeMillis();
totalTimeElapsed = System.currentTimeMillis() - timeRaceStarted;
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.
*
* @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
@ -272,6 +275,7 @@ public abstract class Race implements Runnable {
/**
* Returns the boats that have started the race.
*
* @return ObservableList of BoatInRace class that participated in the race.
* @see ObservableList
* @see BoatInRace
@ -282,6 +286,7 @@ public abstract class Race implements Runnable {
/**
* Updates the boat's gps coordinates depending on time elapsed
*
* @param boat
* @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
* @return
*
* @return list of starting positions
*/
public ArrayList<Marker> getSpreadStartingPositions() {

@ -1,9 +1,6 @@
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.GraphicsContext;
import javafx.scene.paint.Color;
@ -15,11 +12,7 @@ import seng302.GPSCoordinate;
import seng302.GraphCoordinate;
import seng302.RaceMap;
import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
* 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.
*
* @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
@ -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.
*
* @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.
@ -122,6 +117,7 @@ public class ResizableRaceCanvas extends Canvas {
/**
* 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
@ -136,6 +132,7 @@ public class ResizableRaceCanvas extends Canvas {
/**
* 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
@ -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
*
* @param angle Bearing angle to rotate at in degrees
* @param px Pivot point x 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
*
* @param name name of the boat
* @param speed speed of the boat
* @param coordinate coordinate the text appears
@ -242,6 +241,7 @@ public class ResizableRaceCanvas extends Canvas {
/**
* 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
@ -255,7 +255,7 @@ public class ResizableRaceCanvas extends Canvas {
/**
* Toggle the raceAnno value
*/
public void toggleAnno(){
public void toggleAnnotations() {
if (raceAnno) {
raceAnno = false;
} else {
@ -282,7 +282,8 @@ public class ResizableRaceCanvas extends Canvas {
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();
}
/**
* 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;
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 seng302.Model.Boat;
import seng302.Model.BoatInRace;
import seng302.Model.Leg;
import seng302.Model.Marker;
@ -140,7 +140,9 @@ public class RaceXMLReader extends XMLReader{
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) {
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.
*
* @param coordNode
* @return
*/

@ -1,10 +1,14 @@
package seng302;
import org.w3c.dom.*;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
import javax.xml.parsers.*;
import java.io.*;
import javax.xml.parsers.DocumentBuilder;
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.

@ -76,7 +76,7 @@
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="77.0" prefWidth="200.0">
<children>
<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>
</AnchorPane>
</content>

Loading…
Cancel
Save