diff options
author | Ben Burwell <ben.burwell@trifecta.com> | 2016-11-19 22:14:13 -0500 |
---|---|---|
committer | Ben Burwell <ben.burwell@trifecta.com> | 2016-11-19 22:14:13 -0500 |
commit | 70d15df43ea0d57c3fe237211098645733048c45 (patch) | |
tree | a0337b61a1cf89e2c9391226fc10c661f8085373 /src/main/java/com/benburwell/planes/gui/aircraftmap/symbols | |
parent | 3c9729bd52dc24c0109a18d1924d30a9c14b3b06 (diff) |
Add airports
Diffstat (limited to 'src/main/java/com/benburwell/planes/gui/aircraftmap/symbols')
6 files changed, 329 insertions, 0 deletions
diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/AirportSymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/AirportSymbol.java new file mode 100644 index 0000000..5286f6f --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/AirportSymbol.java @@ -0,0 +1,48 @@ +package com.benburwell.planes.gui.aircraftmap.symbols; + +import com.benburwell.planes.data.Airport; +import com.benburwell.planes.gui.GraphicsTheme; +import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.Drawable; +import com.benburwell.planes.gui.aircraftmap.GeoPoint; + +import java.awt.*; + +/** + * Created by ben on 11/19/16. + */ +public class AirportSymbol extends GeoPoint implements Drawable { + private String name; + private String iataCode; + private String localCode; + + public AirportSymbol(Airport airport) { + super(airport.getLatitude(), airport.getLongitude(), airport.getElevation()); + this.name = airport.getName(); + this.iataCode = airport.getIataCode(); + this.localCode = airport.getLocalCode(); + } + + public String getDisplayName() { + if (this.iataCode != null && !this.iataCode.isEmpty()) { + return this.iataCode; + } + if (this.localCode != null && !this.localCode.isEmpty()) { + return this.localCode; + } + return this.name; + } + + @Override + public void drawOn(Graphics g, AircraftMap map) { + if (this.shouldDrawOn(map)) { + int x = this.getX(map); + int y = this.getY(map); + + g.setColor(GraphicsTheme.Colors.MAGENTA); + + g.drawRect(x - 2, y - 2, 4, 4); + g.drawString(this.getDisplayName(), x + 6, y); + } + } +} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/NDBSymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/NDBSymbol.java new file mode 100644 index 0000000..08793ec --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/NDBSymbol.java @@ -0,0 +1,42 @@ +package com.benburwell.planes.gui.aircraftmap.symbols; + +import com.benburwell.planes.data.Position; +import com.benburwell.planes.gui.GraphicsTheme; +import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.Drawable; +import com.benburwell.planes.gui.aircraftmap.GeoPoint; + +import java.awt.*; + +/** + * Created by ben on 11/19/16. + */ +public class NDBSymbol extends GeoPoint implements Drawable { + public static final int INNER_RADIUS = 3; + public static final int OUTER_RADIUS = 9; + public static final int TEXT_OFFSET = 4; + + private String name; + private int frequency; + + public NDBSymbol(String name, Position pos, int frequency) { + super(pos.getLatitude(), pos.getLongitude(), pos.getAltitude()); + this.name = name; + this.frequency = frequency; + } + + @Override + public void drawOn(Graphics g, AircraftMap map) { + if (this.shouldDrawOn(map)) { + g.setColor(GraphicsTheme.Colors.VIOLET); + + int x = this.getX(map); + int y = this.getY(map); + g.fillOval(x - INNER_RADIUS, y - INNER_RADIUS, INNER_RADIUS * 2, INNER_RADIUS * 2); + g.drawOval(x - OUTER_RADIUS, y - OUTER_RADIUS, OUTER_RADIUS * 2, OUTER_RADIUS * 2); + + g.drawString(this.name, x + OUTER_RADIUS + TEXT_OFFSET, y); + g.drawString("" + this.frequency, x + OUTER_RADIUS + TEXT_OFFSET, y + g.getFontMetrics().getHeight()); + } + } +} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/PlaneSymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/PlaneSymbol.java new file mode 100644 index 0000000..4e8ebc0 --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/PlaneSymbol.java @@ -0,0 +1,129 @@ +package com.benburwell.planes.gui.aircraftmap.symbols; + +import com.benburwell.planes.data.Aircraft; +import com.benburwell.planes.data.Position; +import com.benburwell.planes.gui.GraphicsTheme; +import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.Drawable; +import com.benburwell.planes.gui.aircraftmap.GeoPoint; + +import java.awt.*; +import java.awt.geom.AffineTransform; + +/** + * Created by ben on 11/19/16. + */ +public class PlaneSymbol extends GeoPoint implements Drawable { + public final int TRIANGLE_HEIGHT = 6; + 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; + private double speed; + private double verticalRate; + + public PlaneSymbol(Aircraft ac) { + this(ac.getCallsign(), ac.getCurrentPosition(), ac.getTrack(), ac.getGroundSpeed(), ac.getVerticalRate()); + } + + public PlaneSymbol(String name, Position position, double heading, double speed, double verticalRate) { + this(name, position.getLatitude(), position.getLongitude(), position.getAltitude(), heading, speed, verticalRate); + } + + public PlaneSymbol(String name, double latitude, double longitude, double altitude, double heading, double speed, double verticalRate) { + super(latitude, longitude, altitude); + this.name = name; + this.heading = heading; + this.speed = speed; + this.verticalRate = verticalRate; + } + + public int getFlightLevel() { + return (int) this.getAltitude() / 100; + } + + public Color getPlaneColor() { + Color minColor = GraphicsTheme.Colors.RED; + Color maxColor = GraphicsTheme.Colors.GREEN; + + float[] minHsb = Color.RGBtoHSB(minColor.getRed(), minColor.getGreen(), minColor.getBlue(), null); + float[] maxHsb = Color.RGBtoHSB(maxColor.getRed(), maxColor.getGreen(), maxColor.getBlue(), null); + + float minHue = minHsb[0]; + float maxHue = maxHsb[0]; + float minSat = minHsb[1]; + float maxSat = maxHsb[1]; + float minBright = minHsb[2]; + float maxBright = maxHsb[2]; + + double planePosition = (this.getAltitude() / (MAX_COLOR_HEIGHT - MIN_COLOR_HEIGHT)) + MIN_COLOR_HEIGHT; + float huePosition = (float) (planePosition * (maxHue - minHue) + minHue); + float satPosition = (float) (planePosition * (maxSat - minSat) + minSat); + float brightPosition = (float) (planePosition * (maxBright - minBright) + minBright); + + Color c = Color.getHSBColor(huePosition, satPosition, brightPosition); + return c; + } + + public double getAngle() { + return Math.toRadians(this.heading); + } + + public double getSpeed() { + return this.speed; + } + + public void drawTriangle(Graphics2D ctx, int x, int y, int predictionLength) { + AffineTransform at = new AffineTransform(); + 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.fillPolygon(xs, ys, 4); + ctx.drawLine(x, y, x, y - predictionLength); + } + + public String getVerticalRateIndicator() { + if (this.verticalRate > 0) { + return "\u2191"; // ↑ + } else if (this.verticalRate < 0) { + return "\u2193"; // ↓ + } + return ""; + } + + public String getDisplayName() { + if (this.name == null || this.name.isEmpty()) { + return "-----"; + } + return this.name; + } + + public int getPredictionLength(double pixelsPerNauticalMile) { + return (int) (this.speed / 60.0 * pixelsPerNauticalMile); + } + + public void drawOn(Graphics g, AircraftMap map) { + if (this.shouldDrawOn(map)) { + int x = this.getX(map); + int y = this.getY(map); + + // draw the plane dot + Graphics2D g2d = (Graphics2D) g.create(); + g2d.setColor(this.getPlaneColor()); + int predictedTrack = this.getPredictionLength(map.getPixelsPerNauticalMile()); + this.drawTriangle(g2d, x, y, predictedTrack); + g2d.dispose(); + + + // draw the name of the plane + g.setColor(GraphicsTheme.Colors.BASE_5); + g.drawString(this.getDisplayName(), x + TEXT_OFFSET_X, y + TEXT_OFFSET_Y); + String infoString = String.format("%d%s %.1f", this.getFlightLevel(), this.getVerticalRateIndicator(), this.getSpeed()); + g.drawString(infoString, x + TEXT_OFFSET_X, y + TEXT_OFFSET_Y + g.getFontMetrics().getHeight()); + } + } +} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORDMESymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORDMESymbol.java new file mode 100644 index 0000000..0b67989 --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORDMESymbol.java @@ -0,0 +1,29 @@ +package com.benburwell.planes.gui.aircraftmap.symbols; + +import com.benburwell.planes.data.Position; +import com.benburwell.planes.gui.GraphicsTheme; +import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.Drawable; +import com.benburwell.planes.gui.aircraftmap.symbols.VORSymbol; + +import java.awt.Graphics; + +/** + * Created by ben on 11/19/16. + */ +public class VORDMESymbol extends VORSymbol implements Drawable { + public VORDMESymbol(String name, Position pos, int frequency) { + super(name, pos, frequency); + } + + @Override + public void drawOn(Graphics graphicsContext, AircraftMap map) { + super.drawOn(graphicsContext, map); + if (this.shouldDrawOn(map)) { + int x = this.getX(map); + int y = this.getY(map); + graphicsContext.setColor(GraphicsTheme.Colors.VIOLET); + graphicsContext.drawRect(x - VORSymbol.RADIUS, y - VORSymbol.HEIGHT, VORSymbol.RADIUS * 2, VORSymbol.HEIGHT * 2); + } + } +} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORSymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORSymbol.java new file mode 100644 index 0000000..e854c2b --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORSymbol.java @@ -0,0 +1,49 @@ +package com.benburwell.planes.gui.aircraftmap.symbols; + +import com.benburwell.planes.data.Position; +import com.benburwell.planes.gui.GraphicsTheme; +import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.Drawable; +import com.benburwell.planes.gui.aircraftmap.GeoPoint; + +import java.awt.*; + +/** + * Created by ben on 11/19/16. + */ +public class VORSymbol extends GeoPoint implements Drawable { + public static final int RADIUS = 11; + public static final int HEIGHT = (int) (Math.sin(Math.toRadians(60)) * RADIUS); + public static final int X_OFFSET = (int) (Math.cos(Math.toRadians(60)) * RADIUS); + public static final int DOT_RADIUS = 3; + public static final int TEXT_OFFSET = 4; + + private String name; + private int frequency; + + public VORSymbol(String name, Position pos, int frequency) { + super(pos.getLatitude(), pos.getLongitude(), pos.getAltitude()); + this.name = name; + this.frequency = frequency; + } + + @Override + public void drawOn(Graphics graphicsContext, AircraftMap map) { + if (this.shouldDrawOn(map)) { + int x = this.getX(map); + int y = this.getY(map); + graphicsContext.setColor(GraphicsTheme.Colors.VIOLET); + + // center dot + graphicsContext.fillOval(x - DOT_RADIUS, y - DOT_RADIUS, DOT_RADIUS * 2, DOT_RADIUS * 2); + + // hexagon + int[] xs = { x - RADIUS, x - X_OFFSET, x + X_OFFSET, x + RADIUS, x + X_OFFSET, x - X_OFFSET, x - RADIUS }; + int[] ys = { y, y - HEIGHT, y - HEIGHT, y, y + HEIGHT, y + HEIGHT, y }; + graphicsContext.drawPolygon(xs, ys, 7); + + graphicsContext.drawString(this.name, x + RADIUS + TEXT_OFFSET, y); + graphicsContext.drawString(String.format("%.3f", this.frequency / 1000.0), x + RADIUS + TEXT_OFFSET, y + graphicsContext.getFontMetrics().getHeight()); + } + } +} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORTACSymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORTACSymbol.java new file mode 100644 index 0000000..3b0043f --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORTACSymbol.java @@ -0,0 +1,32 @@ +package com.benburwell.planes.gui.aircraftmap.symbols; + +import com.benburwell.planes.data.Position; +import com.benburwell.planes.gui.GraphicsTheme; +import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.Drawable; +import com.benburwell.planes.gui.aircraftmap.symbols.VORSymbol; + +import java.awt.*; + +/** + * Created by ben on 11/19/16. + */ +public class VORTACSymbol extends VORSymbol implements Drawable { + public VORTACSymbol(String name, Position pos, int frequency) { + super(name, pos, frequency); + } + + @Override + public void drawOn(Graphics graphicsContext, AircraftMap map) { + super.drawOn(graphicsContext, map); + if (this.shouldDrawOn(map)) { + int x = this.getX(map); + int y = this.getY(map); + graphicsContext.setColor(GraphicsTheme.Colors.VIOLET); + + int[] xs = { x - VORSymbol.X_OFFSET, x + VORSymbol.X_OFFSET, x + VORSymbol.X_OFFSET, x - VORSymbol.X_OFFSET, x - VORSymbol.X_OFFSET }; + int[] ys = { y + VORSymbol.RADIUS, y + VORSymbol.RADIUS, y + VORSymbol.RADIUS * 2, y + VORSymbol.RADIUS * 2, y + VORSymbol.RADIUS }; + graphicsContext.fillPolygon(xs, ys, 5); + } + } +} |