diff options
Diffstat (limited to 'src/main')
11 files changed, 117 insertions, 67 deletions
diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java index cb8ed3c..1e6181b 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java @@ -54,9 +54,10 @@ public class AircraftMap extends JPanel { private double centerLatitude; private double centerLongitude; private int pixelsPerNauticalMile = 10; - private boolean showNavAids = true; - private boolean showAirports = true; - private boolean showRoutes = true; + + private DisplayMode navaidDisplayMode = DisplayMode.HIDDEN; + private DisplayMode airportDisplayMode = DisplayMode.HIDDEN; + private DisplayMode routeDisplayMode = DisplayMode.HIDDEN; /** * Construct a map @@ -125,42 +126,36 @@ public class AircraftMap extends JPanel { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Base layer -- Routes - if (this.showRoutes) { - this.routes.forEach(route -> route.drawOn(g2d, this)); - } + this.routes.forEach(route -> route.drawOn(g2d, this, this.routeDisplayMode)); // Compass rose this.drawPositionAndScale(g2d); this.drawRange(g2d); // Aids to Navigation - if (this.showNavAids) { - this.navaids.forEach(aid -> aid.drawOn(g2d, this)); - } + this.navaids.forEach(aid -> aid.drawOn(g2d, this, this.navaidDisplayMode)); // Airports - if (this.showAirports) { - this.airports.forEach(airport -> airport.drawOn(g2d, this)); - } + this.airports.forEach(airport -> airport.drawOn(g2d, this, this.airportDisplayMode)); // Planes - this.planes.forEach(item -> item.drawOn(g2d, this)); + this.planes.forEach(item -> item.drawOn(g2d, this, DisplayMode.DETAILED)); g2d.dispose(); } public void toggleNavAids() { - this.showNavAids = !this.showNavAids; + this.navaidDisplayMode = this.navaidDisplayMode.next(); this.redraw(); } public void toggleAirports() { - this.showAirports = !this.showAirports; + this.airportDisplayMode = this.airportDisplayMode.next(); this.redraw(); } public void toggleRoutes() { - this.showRoutes = !this.showRoutes; + this.routeDisplayMode = this.routeDisplayMode.next(); this.redraw(); } diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java index db3e603..0899543 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java @@ -47,6 +47,23 @@ public class AircraftMapComponent implements Tabbable { this.mapPanel.setCenter(40.6188942, -75.4947205); } + /** + * Handle keyboard shortcuts + * + * Key Function + * === ======== + * h pan west + * j pan south + * k pan north + * l pan east + * + zoom in + * - zoom out + * 0 reset lat/lon to home + * + * n toggle navaids + * v toggle routes + * f toggle airfields + */ private void bindKeys() { KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> { if (e.getKeyCode() == KeyEvent.VK_EQUALS && e.isShiftDown() && e.getID() == KeyEvent.KEY_PRESSED) { @@ -65,9 +82,9 @@ public class AircraftMapComponent implements Tabbable { this.mapPanel.setCenter(40.6188942, -75.4947205); } else if (e.getKeyCode() == KeyEvent.VK_N && e.getID() == KeyEvent.KEY_PRESSED) { this.mapPanel.toggleNavAids(); - } else if (e.getKeyCode() == KeyEvent.VK_A && e.getID() == KeyEvent.KEY_PRESSED) { + } else if (e.getKeyCode() == KeyEvent.VK_F && e.getID() == KeyEvent.KEY_PRESSED) { this.mapPanel.toggleAirports(); - } else if (e.getKeyCode() == KeyEvent.VK_R && e.getID() == KeyEvent.KEY_PRESSED) { + } else if (e.getKeyCode() == KeyEvent.VK_V && e.getID() == KeyEvent.KEY_PRESSED) { this.mapPanel.toggleRoutes(); } return false; diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/DisplayMode.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/DisplayMode.java new file mode 100644 index 0000000..aeb8bb1 --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/DisplayMode.java @@ -0,0 +1,14 @@ +package com.benburwell.planes.gui.aircraftmap; + +/** + * @author ben + */ +public enum DisplayMode { + HIDDEN, + DETAILED, + BASIC; + + public DisplayMode next() { + return values()[(this.ordinal() + 1) % values().length]; + } +} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/Drawable.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/Drawable.java index 4b3aa5e..b92a332 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/Drawable.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/Drawable.java @@ -6,5 +6,5 @@ import java.awt.Graphics; * @author ben */ public interface Drawable { - void drawOn(Graphics graphicsContext, AircraftMap map); + void drawOn(Graphics graphicsContext, AircraftMap map, DisplayMode displayMode); } 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 index 7467a0f..7b79e80 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/AirportSymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/AirportSymbol.java @@ -3,6 +3,7 @@ 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.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import com.benburwell.planes.gui.aircraftmap.GeoPoint; @@ -34,15 +35,18 @@ public class AirportSymbol extends GeoPoint implements Drawable { } @Override - public void drawOn(Graphics g, AircraftMap map) { - if (this.shouldDrawOn(map)) { + public void drawOn(Graphics g, AircraftMap map, DisplayMode displayMode) { + if (this.shouldDrawOn(map) && !displayMode.equals(DisplayMode.HIDDEN)) { int x = this.getX(map); int y = this.getY(map); g.setColor(GraphicsTheme.Styles.MAP_AIRPORT_COLOR); g.drawRect(x - 2, y - 2, 4, 4); - g.drawString(this.getDisplayName(), x + 6, y); + + if (displayMode.equals(DisplayMode.DETAILED)) { + 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 index e3b23f5..a40a5e4 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/NDBSymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/NDBSymbol.java @@ -3,6 +3,7 @@ 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.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import com.benburwell.planes.gui.aircraftmap.GeoPoint; @@ -26,8 +27,8 @@ public class NDBSymbol extends GeoPoint implements Drawable { } @Override - public void drawOn(Graphics g, AircraftMap map) { - if (this.shouldDrawOn(map)) { + public void drawOn(Graphics g, AircraftMap map, DisplayMode displayMode) { + if (this.shouldDrawOn(map) && !displayMode.equals(DisplayMode.HIDDEN)) { g.setColor(GraphicsTheme.Styles.MAP_NAVAID_COLOR); int x = this.getX(map); @@ -35,8 +36,10 @@ public class NDBSymbol extends GeoPoint implements Drawable { 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()); + if (displayMode.equals(DisplayMode.DETAILED)) { + 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 index a522b04..fdf9737 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/PlaneSymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/PlaneSymbol.java @@ -4,6 +4,7 @@ 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.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import com.benburwell.planes.gui.aircraftmap.GeoPoint; @@ -110,8 +111,9 @@ public class PlaneSymbol extends GeoPoint implements Drawable { return (int) (this.speed / 60.0 * pixelsPerNauticalMile); } - public void drawOn(Graphics g, AircraftMap map) { - if (this.shouldDrawOn(map)) { + @Override + public void drawOn(Graphics g, AircraftMap map, DisplayMode displayMode) { + if (this.shouldDrawOn(map) && !displayMode.equals(DisplayMode.HIDDEN)) { int x = this.getX(map); int y = this.getY(map); @@ -130,10 +132,12 @@ public class PlaneSymbol extends GeoPoint implements Drawable { }); // draw the name of the plane - g.setColor(GraphicsTheme.Styles.MAP_LABEL_COLOR); - 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()); + if (displayMode.equals(DisplayMode.DETAILED)) { + g.setColor(GraphicsTheme.Styles.MAP_LABEL_COLOR); + 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/RouteSymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RouteSymbol.java index edd622a..7221d86 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RouteSymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RouteSymbol.java @@ -3,6 +3,7 @@ package com.benburwell.planes.gui.aircraftmap.symbols; import com.benburwell.planes.graph.Airway; import com.benburwell.planes.gui.GraphicsTheme; import com.benburwell.planes.gui.aircraftmap.AircraftMap; +import com.benburwell.planes.gui.aircraftmap.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import com.benburwell.planes.gui.aircraftmap.GeoPoint; @@ -14,6 +15,7 @@ import java.util.stream.Collectors; * @author ben */ public class RouteSymbol implements Drawable { + public final int VERTEX_RADIUS = 3; private final Airway airway; public RouteSymbol(Airway airway) { @@ -25,32 +27,38 @@ public class RouteSymbol implements Drawable { } @Override - public void drawOn(Graphics graphicsContext, AircraftMap map) { - int w = map.getWidth(); - int h = map.getHeight(); - graphicsContext.setColor(GraphicsTheme.Styles.MAP_ROUTE_COLOR); - List<GeoPoint> points = this.airway.getPoints().stream().map(GeoPoint::new).collect(Collectors.toList()); - for (int i = 0; i < points.size() - 1; i++) { - GeoPoint p1 = points.get(i); - int p1x = p1.getX(map); - int p1y = p1.getY(map); - - GeoPoint p2 = points.get(i + 1); - int p2x = p2.getX(map); - int p2y = p2.getY(map); - - boolean p1OnMap = inRange(0, p1x, w) && inRange(0, p1y, h); - boolean p2OnMap = inRange(0, p2x, w) && inRange(0, p2y, h); - boolean showEdge = p1OnMap || p2OnMap; - if (showEdge) { - graphicsContext.drawLine(p1x, p1y, p2x, p2y); - graphicsContext.fillOval(p1x - 2, p1y - 2, 4, 4); + public void drawOn(Graphics graphicsContext, AircraftMap map, DisplayMode displayMode) { + if (!displayMode.equals(DisplayMode.HIDDEN)) { + int w = map.getWidth(); + int h = map.getHeight(); + graphicsContext.setColor(GraphicsTheme.Styles.MAP_ROUTE_COLOR); + List<GeoPoint> points = this.airway.getPoints().stream().map(GeoPoint::new).collect(Collectors.toList()); + for (int i = 0; i < points.size() - 1; i++) { + GeoPoint p1 = points.get(i); + int p1x = p1.getX(map); + int p1y = p1.getY(map); + + GeoPoint p2 = points.get(i + 1); + int p2x = p2.getX(map); + int p2y = p2.getY(map); + + boolean p1OnMap = inRange(0, p1x, w) && inRange(0, p1y, h); + boolean p2OnMap = inRange(0, p2x, w) && inRange(0, p2y, h); + boolean showEdge = p1OnMap || p2OnMap; + if (showEdge) { + graphicsContext.drawLine(p1x, p1y, p2x, p2y); + if (displayMode.equals(DisplayMode.DETAILED)) { + graphicsContext.fillOval(p1x - VERTEX_RADIUS, p1y - VERTEX_RADIUS, VERTEX_RADIUS * 2, VERTEX_RADIUS * 2); + } + } + } + int pnx = points.get(points.size() - 1).getX(map); + int pny = points.get(points.size() - 1).getY(map); + if (inRange(0, pnx, w) && inRange(0, pny, h)) { + if (displayMode.equals(DisplayMode.DETAILED)) { + graphicsContext.fillOval(pnx - VERTEX_RADIUS, pny - VERTEX_RADIUS, VERTEX_RADIUS * 2, VERTEX_RADIUS * 2); + } } - } - int pnx = points.get(points.size() - 1).getX(map); - int pny = points.get(points.size() - 1).getY(map); - if (inRange(0, pnx, w) && inRange(0, pny, h)) { - graphicsContext.fillOval(pnx - 2, pny - 2, 4, 4); } } } 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 index 6b12260..b8a754c 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORDMESymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORDMESymbol.java @@ -3,6 +3,7 @@ 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.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import java.awt.Graphics; @@ -16,9 +17,9 @@ public class VORDMESymbol extends VORSymbol implements Drawable { } @Override - public void drawOn(Graphics graphicsContext, AircraftMap map) { - super.drawOn(graphicsContext, map); - if (this.shouldDrawOn(map)) { + public void drawOn(Graphics graphicsContext, AircraftMap map, DisplayMode displayMode) { + super.drawOn(graphicsContext, map, displayMode); + if (this.shouldDrawOn(map) && !displayMode.equals(DisplayMode.HIDDEN)) { int x = this.getX(map); int y = this.getY(map); graphicsContext.setColor(GraphicsTheme.Styles.MAP_NAVAID_COLOR); 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 index f4a73dc..70d90bd 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORSymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORSymbol.java @@ -3,6 +3,7 @@ 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.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import com.benburwell.planes.gui.aircraftmap.GeoPoint; @@ -28,8 +29,8 @@ public class VORSymbol extends GeoPoint implements Drawable { } @Override - public void drawOn(Graphics graphicsContext, AircraftMap map) { - if (this.shouldDrawOn(map)) { + public void drawOn(Graphics graphicsContext, AircraftMap map, DisplayMode displayMode) { + if (this.shouldDrawOn(map) && !displayMode.equals(DisplayMode.HIDDEN)) { int x = this.getX(map); int y = this.getY(map); graphicsContext.setColor(GraphicsTheme.Styles.MAP_NAVAID_COLOR); @@ -42,8 +43,10 @@ public class VORSymbol extends GeoPoint implements Drawable { 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()); + if (displayMode.equals(DisplayMode.DETAILED)) { + 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 index 1ca1290..9a1814e 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORTACSymbol.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/VORTACSymbol.java @@ -3,6 +3,7 @@ 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.DisplayMode; import com.benburwell.planes.gui.aircraftmap.Drawable; import java.awt.Graphics; @@ -16,9 +17,9 @@ public class VORTACSymbol extends VORSymbol implements Drawable { } @Override - public void drawOn(Graphics graphicsContext, AircraftMap map) { - super.drawOn(graphicsContext, map); - if (this.shouldDrawOn(map)) { + public void drawOn(Graphics graphicsContext, AircraftMap map, DisplayMode displayMode) { + super.drawOn(graphicsContext, map, displayMode); + if (this.shouldDrawOn(map) && !displayMode.equals(DisplayMode.HIDDEN)) { int x = this.getX(map); int y = this.getY(map); graphicsContext.setColor(GraphicsTheme.Styles.MAP_NAVAID_COLOR); |