summaryrefslogtreecommitdiff
path: root/src/main/java/com/benburwell/planes/gui/aircraftmap
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/benburwell/planes/gui/aircraftmap')
-rw-r--r--src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java14
-rw-r--r--src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java7
-rw-r--r--src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RunwaySymbol.java62
3 files changed, 82 insertions, 1 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 1e6181b..d98dc60 100644
--- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java
+++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java
@@ -3,6 +3,7 @@ package com.benburwell.planes.gui.aircraftmap;
import com.benburwell.planes.data.Airport;
import com.benburwell.planes.data.NavigationAid;
import com.benburwell.planes.data.Position;
+import com.benburwell.planes.data.Runway;
import com.benburwell.planes.graph.RouteGraph;
import com.benburwell.planes.gui.GraphicsTheme;
import com.benburwell.planes.gui.aircraftmap.symbols.*;
@@ -51,6 +52,7 @@ public class AircraftMap extends JPanel {
private List<Drawable> navaids = new ArrayList<>();
private List<Drawable> airports = new ArrayList<>();
private List<Drawable> routes = new ArrayList<>();
+ private List<Drawable> runways = new ArrayList<>();
private double centerLatitude;
private double centerLongitude;
private int pixelsPerNauticalMile = 10;
@@ -58,6 +60,7 @@ public class AircraftMap extends JPanel {
private DisplayMode navaidDisplayMode = DisplayMode.HIDDEN;
private DisplayMode airportDisplayMode = DisplayMode.HIDDEN;
private DisplayMode routeDisplayMode = DisplayMode.HIDDEN;
+ private DisplayMode runwayDisplayMode = DisplayMode.HIDDEN;
/**
* Construct a map
@@ -114,6 +117,10 @@ public class AircraftMap extends JPanel {
routes.getAirways().forEach(airway -> this.routes.add(new RouteSymbol(airway)));
}
+ public void addRunways(List<Runway> runways) {
+ runways.forEach(runway -> this.runways.add(new RunwaySymbol(runway)));
+ }
+
/**
* Paint the Tabbable on a Graphics instance
*
@@ -132,6 +139,8 @@ public class AircraftMap extends JPanel {
this.drawPositionAndScale(g2d);
this.drawRange(g2d);
+ this.runways.forEach(runway -> runway.drawOn(g2d, this, this.runwayDisplayMode));
+
// Aids to Navigation
this.navaids.forEach(aid -> aid.drawOn(g2d, this, this.navaidDisplayMode));
@@ -159,6 +168,11 @@ public class AircraftMap extends JPanel {
this.redraw();
}
+ public void toggleRunways() {
+ this.runwayDisplayMode = this.runwayDisplayMode.next();
+ this.redraw();
+ }
+
private void drawPositionAndScale(Graphics g) {
Font currentFont = g.getFont();
Font newFont = currentFont.deriveFont(FONT_SIZE);
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 0899543..733a948 100644
--- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
+++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
@@ -12,6 +12,7 @@ import java.util.List;
import javax.swing.JComponent;
import javax.swing.Timer;
import java.awt.event.KeyEvent;
+import java.util.stream.Collectors;
/**
* @author ben
@@ -24,7 +25,7 @@ public class AircraftMapComponent implements Tabbable {
private AircraftMap mapPanel;
private AircraftStoreListener aircraftStoreListener;
- public AircraftMapComponent(AircraftStore store, CSVObjectStore<NavigationAid> navaids, CSVObjectStore<Airport> airportStore, RouteGraph routeGraph) {
+ public AircraftMapComponent(AircraftStore store, CSVObjectStore<NavigationAid> navaids, CSVObjectStore<Airport> airportStore, RouteGraph routeGraph, CSVObjectStore<Runway> runwayStore) {
this.store = store;
this.setupMap();
@@ -35,6 +36,7 @@ public class AircraftMapComponent implements Tabbable {
this.mapPanel.addNavAids(navaids.getObjects());
this.mapPanel.addAirports(airportStore.getObjects());
this.mapPanel.addRoutes(routeGraph);
+ this.mapPanel.addRunways(runwayStore.getObjects().stream().filter(Runway::isDrawable).collect(Collectors.toList()));
final Timer t = new Timer(MAX_REFRESH_MILLIS, e -> {
AircraftMapComponent.this.aircraftStoreListener.aircraftStoreChanged();
@@ -63,6 +65,7 @@ public class AircraftMapComponent implements Tabbable {
* n toggle navaids
* v toggle routes
* f toggle airfields
+ * r toggle runways
*/
private void bindKeys() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> {
@@ -86,6 +89,8 @@ public class AircraftMapComponent implements Tabbable {
this.mapPanel.toggleAirports();
} else if (e.getKeyCode() == KeyEvent.VK_V && e.getID() == KeyEvent.KEY_PRESSED) {
this.mapPanel.toggleRoutes();
+ } else if (e.getKeyCode() == KeyEvent.VK_R && e.getID() == KeyEvent.KEY_PRESSED) {
+ this.mapPanel.toggleRunways();
}
return false;
});
diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RunwaySymbol.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RunwaySymbol.java
new file mode 100644
index 0000000..0f5fac1
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/RunwaySymbol.java
@@ -0,0 +1,62 @@
+package com.benburwell.planes.gui.aircraftmap.symbols;
+
+import com.benburwell.planes.data.Runway;
+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;
+
+import java.awt.*;
+import java.awt.geom.AffineTransform;
+
+/**
+ * @author ben
+ */
+public class RunwaySymbol implements Drawable {
+ public final double FEET_PER_MILE = 6076.12;
+ private Runway runway;
+
+ public RunwaySymbol(Runway r) {
+ this.runway = r;
+ }
+
+ @Override
+ public void drawOn(Graphics g, AircraftMap map, DisplayMode displayMode) {
+ if (!displayMode.equals(DisplayMode.HIDDEN)) {
+ GeoPoint he = new GeoPoint(this.runway.getHeLatitude(), this.runway.getHeLongitude(), 0);
+ int hex = he.getX(map);
+ int hey = he.getY(map);
+
+ GeoPoint le = new GeoPoint(this.runway.getLeLatitude(), this.runway.getLeLongitude(), 0);
+ int lex = le.getX(map);
+ int ley = le.getY(map);
+
+ if (he.shouldDrawOn(map) && le.shouldDrawOn(map)) {
+ //if (this.runway.getWidth() != null && this.runway.getLength() != null) {
+ // double dx = hex - lex;
+ // double dy = hey - ley;
+ // int width = (int) ((this.runway.getWidth() / FEET_PER_MILE) * map.getPixelsPerNauticalMile());
+ // int length = (int) ((this.runway.getLength() / FEET_PER_MILE) * map.getPixelsPerNauticalMile());
+
+ // AffineTransform at = new AffineTransform();
+ // at.setToRotation(Math.atan(dy / dx), lex, ley);
+ // Graphics2D g2d = (Graphics2D) g.create();
+ // g2d.setColor(GraphicsTheme.Styles.MAP_RUNWAY_BORDER_COLOR);
+ // g2d.setTransform(at);
+
+ // g2d.drawRect(lex - (width / 2), ley - (length / 2), width, length);
+ // g2d.dispose();
+ //}
+
+ g.setColor(GraphicsTheme.Styles.MAP_RUNWAY_BORDER_COLOR);
+ g.drawLine(lex, ley, hex, hey);
+
+ if (displayMode.equals(DisplayMode.DETAILED)) {
+ g.drawString(runway.getLeIdent(), lex, ley);
+ g.drawString(runway.getHeIdent(), hex, hey);
+ }
+ }
+ }
+ }
+}