diff options
5 files changed, 64 insertions, 36 deletions
diff --git a/src/com/benburwell/planes/data/Aircraft.java b/src/com/benburwell/planes/data/Aircraft.java index 71ee5b5..e0ca449 100644 --- a/src/com/benburwell/planes/data/Aircraft.java +++ b/src/com/benburwell/planes/data/Aircraft.java @@ -15,6 +15,8 @@ public class Aircraft implements Comparable<Aircraft> { private String callsign = ""; private String squawk = ""; private long packetCount = 0; + private double track; + private double groundSpeed; public Aircraft(String hexIdent) { this.hexIdent = hexIdent; @@ -37,6 +39,12 @@ public class Aircraft implements Comparable<Aircraft> { if (packet.getSquawk() != null && !packet.getSquawk().isEmpty()) { this.callsign = packet.getSquawk(); } + if (packet.getTrack() != null) { + this.track = packet.getTrack(); + } + if (packet.getGroundSpeed() != null) { + this.groundSpeed = packet.getGroundSpeed(); + } } public Position getCurrentPosition() { @@ -59,6 +67,14 @@ public class Aircraft implements Comparable<Aircraft> { return this.hexIdent; } + public double getTrack() { + return this.track; + } + + public double getGroundSpeed() { + return this.groundSpeed; + } + @Override public int compareTo(Aircraft that) { return this.getHexIdent().compareTo(that.getHexIdent()); diff --git a/src/com/benburwell/planes/gui/AircraftTableModel.java b/src/com/benburwell/planes/gui/AircraftTableModel.java index a2b40de..2ee6742 100644 --- a/src/com/benburwell/planes/gui/AircraftTableModel.java +++ b/src/com/benburwell/planes/gui/AircraftTableModel.java @@ -15,7 +15,7 @@ import java.util.Collections; */ public class AircraftTableModel extends AbstractTableModel { private Map<String,Aircraft> aircraftMap; - private String[] columnNames = { "Hex", "Callsign", "Squawk", "Latitude", "Longitude", "Altitude", "Packets" }; + private String[] columnNames = { "Hex", "Callsign", "Squawk", "Latitude", "Longitude", "Altitude", "Track", "Ground Speed", "Packets" }; public AircraftTableModel(AircraftStore store) { this.aircraftMap = store.getAircraft(); @@ -66,6 +66,10 @@ public class AircraftTableModel extends AbstractTableModel { case 5: return aircraft.getCurrentPosition().getAltitude(); case 6: + return aircraft.getTrack(); + case 7: + return aircraft.getGroundSpeed(); + case 8: return aircraft.getPacketCount(); } return ""; diff --git a/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java b/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java index 2d2a669..fad1082 100644 --- a/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java +++ b/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java @@ -52,9 +52,9 @@ public class AircraftMap extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); - this.planes.forEach(item -> item.drawOn(g, this)); this.drawPositionAndScale(g); this.drawRange(g); + this.planes.forEach(item -> item.drawOn(g, this)); } public void drawPositionAndScale(Graphics g) { @@ -98,12 +98,19 @@ public class AircraftMap extends JPanel { public void setPlanes(List<Drawable> planes) { this.planes = planes; + this.redraw(); + } + + public void redraw() { this.invalidate(); + this.validate(); + this.repaint(); } public void setCenter(double latitude, double longitude) { this.centerLatitude = latitude; this.centerLongitude = longitude; + this.redraw(); } public double getCenterLatitude() { @@ -133,47 +140,35 @@ public class AircraftMap extends JPanel { public void zoomIn() { this.pixelsPerNauticalMile = Math.min(MAX_ZOOM_PIXELS_PER_MILE, this.pixelsPerNauticalMile * 2); - this.invalidate(); - this.validate(); - this.repaint(); + this.redraw(); } public void zoomOut() { this.pixelsPerNauticalMile = Math.max(MIN_ZOOM_PIXELS_PER_MILE, this.pixelsPerNauticalMile / 2); - this.invalidate(); - this.validate(); - this.repaint(); + this.redraw(); } public void moveEast() { double degreesToMove = PAN_INTERVAL_MILES / this.getNauticalMilesPerDegreeLongitude(); this.centerLongitude = Math.min(this.centerLongitude + degreesToMove, MAX_LONGITUDE); - this.invalidate(); - this.validate(); - this.repaint(); + this.redraw(); } public void moveWest() { double degreesToMove = PAN_INTERVAL_MILES / this.getNauticalMilesPerDegreeLongitude(); this.centerLongitude = Math.max(this.centerLongitude - degreesToMove, MIN_LONGITUDE); - this.invalidate(); - this.validate(); - this.repaint(); + this.redraw(); } public void moveNorth() { double degreesToMove = PAN_INTERVAL_MILES / NAUTICAL_MILES_PER_DEGREE_LATITUDE; this.centerLatitude = Math.min(this.centerLatitude + degreesToMove, MAX_LATITUDE); - this.invalidate(); - this.validate(); - this.repaint(); + this.redraw(); } public void moveSouth() { double degreesToMove = PAN_INTERVAL_MILES / NAUTICAL_MILES_PER_DEGREE_LATITUDE; this.centerLatitude = Math.max(this.centerLatitude - degreesToMove, MIN_LATITUDE); - this.invalidate(); - this.validate(); - this.repaint(); + this.redraw(); } } diff --git a/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java b/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java index 4bb13e8..50ddb13 100644 --- a/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java +++ b/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java @@ -25,13 +25,6 @@ public class AircraftMapComponent implements ViewComponent { this.setupMap(); this.bindKeys(); this.subscribeToChanges(); - - List<Drawable> planes = new ArrayList<>(); - planes.add(new Plane("JBU1111", 40.6188942, -75.4947205, 36000)); - planes.add(new Plane("JBU1112", 40.6178942, -75.4347205, 42000)); - planes.add(new Plane("JBU1114", 40.5178942, -75.5347205, 3500)); - planes.add(new Plane("JBU1115", 40.3178942, -75.1347205, 0)); - this.mapPanel.setPlanes(planes); } public void focusNextAircraft() { @@ -61,7 +54,6 @@ public class AircraftMapComponent implements ViewComponent { if (e.getKeyCode() == KeyEvent.VK_EQUALS && e.isShiftDown() && e.getID() == KeyEvent.KEY_PRESSED) { this.mapPanel.zoomIn(); } else if (e.getKeyCode() == KeyEvent.VK_MINUS && e.getID() == KeyEvent.KEY_PRESSED) { - System.out.println("Zooming out"); this.mapPanel.zoomOut(); } else if (e.getKeyCode() == KeyEvent.VK_L && e.getID() == KeyEvent.KEY_PRESSED) { this.mapPanel.moveEast(); @@ -95,7 +87,7 @@ public class AircraftMapComponent implements ViewComponent { List<Drawable> planes = new ArrayList<>(); store.getAircraft().values().forEach(aircraft -> { String name = !aircraft.getCallsign().isEmpty() ? aircraft.getCallsign() : aircraft.getHexIdent(); - planes.add(new Plane(name, aircraft.getCurrentPosition())); + planes.add(new Plane(name, aircraft.getCurrentPosition(), aircraft.getTrack())); }); mapPanel.setPlanes(planes); mapPanel.validate(); diff --git a/src/com/benburwell/planes/gui/aircraftmap/Plane.java b/src/com/benburwell/planes/gui/aircraftmap/Plane.java index c7f774e..8575334 100644 --- a/src/com/benburwell/planes/gui/aircraftmap/Plane.java +++ b/src/com/benburwell/planes/gui/aircraftmap/Plane.java @@ -4,25 +4,29 @@ import com.benburwell.planes.data.Position; import com.benburwell.planes.gui.GraphicsTheme; import java.awt.*; +import java.awt.geom.AffineTransform; /** * Created by ben on 11/19/16. */ public class Plane extends GeoPoint implements Drawable { - public final int DOT_DIMENSION = 4; + public final int TRIANGLE_HEIGHT = 8; + public final int TRIANGLE_WIDTH = 4; public final int TEXT_OFFSET_X = 10; public final int TEXT_OFFSET_Y = 15; public final int MIN_COLOR_HEIGHT = 0; public final int MAX_COLOR_HEIGHT = 50000; private String name; + private double heading; - public Plane(String name, Position position) { - this(name, position.getLatitude(), position.getLongitude(), position.getAltitude()); + public Plane(String name, Position position, double heading) { + this(name, position.getLatitude(), position.getLongitude(), position.getAltitude(), heading); } - public Plane(String name, double latitude, double longitude, double altitude) { + public Plane(String name, double latitude, double longitude, double altitude, double heading) { super(latitude, longitude, altitude); this.name = name; + this.heading = heading; } public int getFlightLevel() { @@ -52,17 +56,34 @@ public class Plane extends GeoPoint implements Drawable { return c; } + public double getAngle() { + return Math.toRadians(this.heading); + } + + public void drawTriangle(Graphics2D ctx, int x, int y) { + AffineTransform at = new AffineTransform(); + //at.setToRotation(this.getAngle(), x, y); + at.setToRotation(this.getAngle(), x, y); + ctx.setTransform(at); + int[] xs = new int[]{ x - TRIANGLE_WIDTH, x, x + TRIANGLE_WIDTH, x - TRIANGLE_WIDTH }; + int[] ys = new int[]{ y + TRIANGLE_HEIGHT, y - TRIANGLE_HEIGHT, y + TRIANGLE_HEIGHT, y + TRIANGLE_HEIGHT }; + ctx.drawPolyline(xs, ys, 4); + } + public void drawOn(Graphics g, AircraftMap map) { int x = this.getX(map); int y = this.getY(map); if (x >= 0 && x <= map.getSize().getWidth() && y >= 0 && y <= map.getSize().getHeight()) { // draw the plane dot - g.setColor(this.getPlaneColor()); - g.drawRect(x - (DOT_DIMENSION / 2), y - (DOT_DIMENSION / 2), DOT_DIMENSION, DOT_DIMENSION); + Graphics2D g2d = (Graphics2D) g.create(); + g2d.setColor(this.getPlaneColor()); + this.drawTriangle(g2d, x, y); + g2d.dispose(); + // draw the name of the plane - g.setColor(GraphicsTheme.Colors.BLUE); + g.setColor(GraphicsTheme.Colors.BASE_5); g.drawString(this.name, x + TEXT_OFFSET_X, y + TEXT_OFFSET_Y); g.drawString("" + this.getFlightLevel(), x + TEXT_OFFSET_X, y + TEXT_OFFSET_Y + g.getFontMetrics().getHeight()); } |