summaryrefslogtreecommitdiff
path: root/src/com/benburwell/planes/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/benburwell/planes/gui')
-rw-r--r--src/com/benburwell/planes/gui/AircraftTableComponent.java26
-rw-r--r--src/com/benburwell/planes/gui/AircraftTableModel.java85
-rw-r--r--src/com/benburwell/planes/gui/GraphicsTheme.java27
-rw-r--r--src/com/benburwell/planes/gui/Main1090.java93
-rw-r--r--src/com/benburwell/planes/gui/MenuBarProvider.java41
-rw-r--r--src/com/benburwell/planes/gui/TCPConnectionOptionDialog.java45
-rw-r--r--src/com/benburwell/planes/gui/ViewComponent.java10
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java174
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java106
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/Drawable.java10
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java36
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/Plane.java126
12 files changed, 0 insertions, 779 deletions
diff --git a/src/com/benburwell/planes/gui/AircraftTableComponent.java b/src/com/benburwell/planes/gui/AircraftTableComponent.java
deleted file mode 100644
index 221bdda..0000000
--- a/src/com/benburwell/planes/gui/AircraftTableComponent.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.benburwell.planes.gui;
-
-import com.benburwell.planes.data.AircraftStore;
-
-import javax.swing.*;
-
-/**
- * Created by ben on 11/17/16.
- */
-public class AircraftTableComponent implements ViewComponent{
- private JTable table;
- private AircraftTableModel tableModel;
- private JScrollPane scrollPane;
-
- public AircraftTableComponent(AircraftStore store) {
- this.tableModel = new AircraftTableModel(store);
- this.table = new JTable(this.tableModel);
- this.table.setFillsViewportHeight(true);
- this.scrollPane = new JScrollPane(table);
- }
-
- @Override
- public JComponent getComponent() {
- return this.scrollPane;
- }
-}
diff --git a/src/com/benburwell/planes/gui/AircraftTableModel.java b/src/com/benburwell/planes/gui/AircraftTableModel.java
deleted file mode 100644
index 3931893..0000000
--- a/src/com/benburwell/planes/gui/AircraftTableModel.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.benburwell.planes.gui;
-
-import com.benburwell.planes.data.Aircraft;
-import com.benburwell.planes.data.AircraftStore;
-import com.benburwell.planes.data.AircraftStoreListener;
-
-import javax.swing.table.AbstractTableModel;
-import java.util.Map;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-
-/**
- * Created by ben on 11/15/16.
- */
-public class AircraftTableModel extends AbstractTableModel {
- private Map<String,Aircraft> aircraftMap;
- private String[] columnNames = { "Hex", "Callsign", "Squawk", "Latitude", "Longitude", "Altitude", "Vertical Rate", "Track", "Ground Speed", "Packets" };
-
- public AircraftTableModel(AircraftStore store) {
- this.aircraftMap = store.getAircraft();
- store.subscribe(new AircraftStoreListener() {
- @Override
- public void aircraftStoreChanged() {
- AircraftTableModel.super.fireTableDataChanged();
- }
-
- @Override
- public boolean respondTo(String aircraftId) {
- // listen for all changes
- return true;
- }
- });
- }
-
- @Override
- public int getRowCount() {
- return this.aircraftMap.keySet().size();
- }
-
- @Override
- public int getColumnCount() {
- return this.columnNames.length;
- }
-
- @Override
- public String getColumnName(int col) {
- return this.columnNames[col];
- }
-
- @Override
- public Object getValueAt(int rowIndex, int columnIndex) {
- List<Aircraft> aircraftList = this.getAircraftList();
- Aircraft aircraft = aircraftList.get(rowIndex);
- switch (columnIndex) {
- case 0:
- return aircraft.getHexIdent();
- case 1:
- return aircraft.getCallsign();
- case 2:
- return aircraft.getSquawk();
- case 3:
- return aircraft.getCurrentPosition().getLatitude();
- case 4:
- return aircraft.getCurrentPosition().getLongitude();
- case 5:
- return aircraft.getCurrentPosition().getAltitude();
- case 6:
- return aircraft.getVerticalRate();
- case 7:
- return aircraft.getTrack();
- case 8:
- return aircraft.getGroundSpeed();
- case 9:
- return aircraft.getPacketCount();
- }
- return "";
- }
-
- private List<Aircraft> getAircraftList() {
- List<Aircraft> aircraftList = new ArrayList<>(this.aircraftMap.values());
- Collections.sort(aircraftList);
- return aircraftList;
- }
-}
diff --git a/src/com/benburwell/planes/gui/GraphicsTheme.java b/src/com/benburwell/planes/gui/GraphicsTheme.java
deleted file mode 100644
index cece138..0000000
--- a/src/com/benburwell/planes/gui/GraphicsTheme.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.benburwell.planes.gui;
-
-import java.awt.*;
-
-/**
- * Created by ben on 11/18/16.
- */
-public class GraphicsTheme {
- public static class Colors {
- public static final Color BASE_0 = new Color(12, 16, 20);
- public static final Color BASE_1 = new Color(17, 21, 28);
- public static final Color BASE_2 = new Color(9, 31, 46);
- public static final Color BASE_3 = new Color(10, 55, 73);
- public static final Color BASE_4 = new Color(36, 83, 97);
- public static final Color BASE_5 = new Color(89, 156, 171);
- public static final Color BASE_6 = new Color(153, 209, 206);
- public static final Color BASE_7 = new Color(211, 235, 233);
- public static final Color RED = new Color(194, 49, 39);
- public static final Color ORANGE = new Color(210, 105, 55);
- public static final Color YELLOW = new Color(237, 180, 67);
- public static final Color MAGENTA = new Color(136, 140, 166);
- public static final Color VIOLET = new Color(78, 81, 102);
- public static final Color BLUE = new Color(25, 84, 102);
- public static final Color CYAN = new Color(51, 133, 158);
- public static final Color GREEN = new Color(42, 168, 137);
- }
-}
diff --git a/src/com/benburwell/planes/gui/Main1090.java b/src/com/benburwell/planes/gui/Main1090.java
deleted file mode 100644
index d7fc830..0000000
--- a/src/com/benburwell/planes/gui/Main1090.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Created by ben on 11/15/16.
- */
-
-package com.benburwell.planes.gui;
-
-import com.benburwell.planes.sbs.*;
-import com.benburwell.planes.data.*;
-import com.benburwell.planes.gui.aircraftmap.*;
-
-import java.awt.*;
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-
-public class Main1090 extends JFrame {
- private AggregateDataSource sbsDataSource = new AggregateDataSource();
- private AircraftStore aircraft = new AircraftStore();
- private int currentTcpConnection = 0;
- private JTabbedPane tabbedPane = new JTabbedPane();
-
- public Main1090() {
- this.initUI();
- }
-
- private void initUI() {
- this.createMenuBar();
-
- this.setTitle("1090");
- this.setSize(600, 400);
- this.setLocationRelativeTo(null);
- this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
-
- this.openDataSource();
-
- this.createTabs();
- }
-
- private void createTabs() {
- AircraftTableComponent aircraftData = new AircraftTableComponent(this.aircraft);
- this.tabbedPane.addTab("Aircraft Data", aircraftData.getComponent());
-
- AircraftMapComponent aircraftMap = new AircraftMapComponent(this.aircraft);
- this.tabbedPane.addTab("Live Map", aircraftMap.getComponent());
-
- this.add(this.tabbedPane);
- this.tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
-
- this.tabbedPane.setSelectedIndex(1);
- }
-
- private void createMenuBar() {
- MenuBarProvider provider = new MenuBarProvider();
- this.setJMenuBar(provider.getMenuBar());
-
- provider.getDataConnectItem().addActionListener((ActionEvent event) -> {
- if (this.currentTcpConnection == 0) {
- TCPConnectionOptionDialog dialog = new TCPConnectionOptionDialog();
- JOptionPane.showMessageDialog(this, dialog.getComponent(), "New Network Data Source", JOptionPane.PLAIN_MESSAGE);
- this.currentTcpConnection = this.addTcpSource(dialog.getHost(), dialog.getPort());
- provider.getDataConnectItem().setEnabled(false);
- provider.getDataDisconnectItem().setEnabled(true);
- }
- });
- provider.getDataDisconnectItem().addActionListener((ActionEvent event) -> {
- if (this.currentTcpConnection != 0) {
- this.sbsDataSource.closeSource(this.currentTcpConnection);
- provider.getDataConnectItem().setEnabled(true);
- provider.getDataDisconnectItem().setEnabled(false);
- this.currentTcpConnection = 0;
- }
- });
- }
-
- private void openDataSource() {
- this.sbsDataSource.subscribe((SBSPacket packet) -> {
- this.aircraft.addPacket(packet);
- });
- this.sbsDataSource.open();
- }
-
- private int addTcpSource(String host, int port) {
- TCPDataSource source = new TCPDataSource(host, port);
- source.open();
- return this.sbsDataSource.addSource(source);
- }
-
- public static void main(String[] args) {
- EventQueue.invokeLater(() -> {
- Main1090 app = new Main1090();
- app.setVisible(true);
- });
- }
-}
diff --git a/src/com/benburwell/planes/gui/MenuBarProvider.java b/src/com/benburwell/planes/gui/MenuBarProvider.java
deleted file mode 100644
index add77ce..0000000
--- a/src/com/benburwell/planes/gui/MenuBarProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.benburwell.planes.gui;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-
-/**
- * Created by ben on 11/17/16.
- */
-public class MenuBarProvider {
- private JMenuBar menubar = new JMenuBar();
- private JMenu file = new JMenu("1090");
- private JMenuItem fileQuitMenuItem = new JMenuItem("Quit");
- private JMenu data = new JMenu("Data Source");
- private JMenuItem dataConnectItem = new JMenuItem("Connect to Remote...");
- private JMenuItem dataDisconnectItem = new JMenuItem("Disconnect");
-
- public MenuBarProvider() {
- fileQuitMenuItem.addActionListener((ActionEvent event) -> {
- System.exit(0);
- });
- file.add(fileQuitMenuItem);
- menubar.add(file);
-
- dataDisconnectItem.setEnabled(false);
- data.add(dataConnectItem);
- data.add(dataDisconnectItem);
- menubar.add(data);
- }
-
- public JMenuBar getMenuBar() {
- return this.menubar;
- }
-
- public JMenuItem getDataConnectItem() {
- return this.dataConnectItem;
- }
-
- public JMenuItem getDataDisconnectItem() {
- return this.dataDisconnectItem;
- }
-}
diff --git a/src/com/benburwell/planes/gui/TCPConnectionOptionDialog.java b/src/com/benburwell/planes/gui/TCPConnectionOptionDialog.java
deleted file mode 100644
index 609a70a..0000000
--- a/src/com/benburwell/planes/gui/TCPConnectionOptionDialog.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.benburwell.planes.gui;
-
-import javax.swing.*;
-
-/**
- * Created by ben on 11/17/16.
- */
-public class TCPConnectionOptionDialog implements ViewComponent {
- public static final String DEFAULT_HOSTNAME = "10.0.0.111";
- public static final int DEFAULT_TCP_PORT = 30003;
-
- private JPanel dialog = new JPanel();
- private JTextField hostField = new JTextField(10);
- private JTextField portField = new JTextField(5);
- private JLabel descriptionLabel = new JLabel("Add a network data source that provides data in the SBS-1 format");
-
- @Override
- public JComponent getComponent() {
- // set properties
- hostField.setText(DEFAULT_HOSTNAME);
- hostField.setToolTipText("Hostname or IP address");
-
- portField.setText(String.valueOf(DEFAULT_TCP_PORT));
- portField.setToolTipText("Port number");
-
- // create layout
- dialog.add(descriptionLabel);
- dialog.add(hostField);
- dialog.add(portField);
-
- return dialog;
- }
-
- public String getHost() {
- return this.hostField.getText();
- }
-
- public int getPort() {
- try {
- return Integer.valueOf(this.portField.getText());
- } catch (NumberFormatException e) {
- return DEFAULT_TCP_PORT;
- }
- }
-}
diff --git a/src/com/benburwell/planes/gui/ViewComponent.java b/src/com/benburwell/planes/gui/ViewComponent.java
deleted file mode 100644
index 91c21cd..0000000
--- a/src/com/benburwell/planes/gui/ViewComponent.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.benburwell.planes.gui;
-
-import javax.swing.*;
-
-/**
- * Created by ben on 11/17/16.
- */
-public interface ViewComponent {
- JComponent getComponent();
-}
diff --git a/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java b/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java
deleted file mode 100644
index fad1082..0000000
--- a/src/com/benburwell/planes/gui/aircraftmap/AircraftMap.java
+++ /dev/null
@@ -1,174 +0,0 @@
-package com.benburwell.planes.gui.aircraftmap;
-
-import com.benburwell.planes.gui.GraphicsTheme;
-
-import javax.swing.*;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by ben on 11/19/16.
- */
-public class AircraftMap extends JPanel {
- // geographic constants
- public final double MAX_LATITUDE = 90.0;
- public final double MIN_LATITUDE = -90.0;
- public final double MAX_LONGITUDE = 180.0;
- public final double MIN_LONGITUDE = -180.0;
- public final double NAUTICAL_MILES_PER_DEGREE_LATITUDE = 60.0;
-
- // drawing constants
- public final float FONT_SIZE = 12;
- public final int TEXT_PADDING = 5;
- public final int NUMBER_OF_RANGE_RINGS = 5;
-
- // map manipulation constants
- public final int MIN_ZOOM_PIXELS_PER_MILE = 1;
- public final int MAX_ZOOM_PIXELS_PER_MILE = 2000;
- public final double PAN_INTERVAL_MILES = 1.0;
-
- // instance fields
- private List<Drawable> planes = new ArrayList<>();
- private double centerLatitude;
- private double centerLongitude;
- private int pixelsPerNauticalMile = 10;
-
- /**
- * Construct a map
- */
- public AircraftMap() {
- super();
- this.setBackground(GraphicsTheme.Colors.BASE_1);
- this.setBorder(BorderFactory.createEmptyBorder());
- this.setCenter(0, 0);
- }
-
- /**
- * Paint the ViewComponent on a Graphics instance
- *
- * @param g the graphics context to paint on
- */
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- this.drawPositionAndScale(g);
- this.drawRange(g);
- this.planes.forEach(item -> item.drawOn(g, this));
- }
-
- public void drawPositionAndScale(Graphics g) {
- Font currentFont = g.getFont();
- Font newFont = currentFont.deriveFont(FONT_SIZE);
- g.setFont(newFont);
- g.setColor(GraphicsTheme.Colors.BLUE);
- g.drawString(String.format("%08.5f N", this.centerLatitude), TEXT_PADDING, (int) FONT_SIZE + TEXT_PADDING);
- g.drawString(String.format("%08.5f E", this.centerLongitude), TEXT_PADDING, (int) FONT_SIZE * 2 + TEXT_PADDING);
- g.drawString(String.format("%d nm", this.getRangeRadius()), TEXT_PADDING, (int) FONT_SIZE * 3 + TEXT_PADDING);
- }
-
- public int getRangeRadius() {
- double milesHigh = this.getHeight() / this.getPixelsPerNauticalMile();
- double milesWide = this.getWidth() / this.getPixelsPerNauticalMile();
- double screenMiles = Math.min(milesHigh, milesWide);
- int milesPerRing = (int) screenMiles / NUMBER_OF_RANGE_RINGS;
- return milesPerRing;
- }
-
- public List<Integer> getRangeRadii() {
- int rangeRadius = this.getRangeRadius();
- List<Integer> radii = new ArrayList<>();
- for (int ringNumber = 1; ringNumber <= NUMBER_OF_RANGE_RINGS; ringNumber++) {
- radii.add(rangeRadius * ringNumber);
- }
- return radii;
- }
-
- public void drawRange(Graphics g) {
- int centerX = this.getWidth() / 2;
- int centerY = this.getHeight() / 2;
- g.setColor(GraphicsTheme.Colors.BASE_3);
- for (Integer radius : this.getRangeRadii()) {
- int pixelRadius = (int) (this.getPixelsPerNauticalMile() * radius);
- g.drawOval(centerX - pixelRadius, centerY - pixelRadius, pixelRadius * 2, pixelRadius * 2);
- }
- g.drawLine(centerX, 0, centerX, this.getHeight());
- g.drawLine(0, centerY, this.getWidth(), centerY);
- }
-
- 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() {
- return this.centerLatitude;
- }
-
- public double getCenterLongitude() {
- return this.centerLongitude;
- }
-
- public double getPixelsPerDegreeLatitude() {
- return this.pixelsPerNauticalMile * NAUTICAL_MILES_PER_DEGREE_LATITUDE;
- }
-
- public double getPixelsPerDegreeLongitude() {
- return this.pixelsPerNauticalMile * this.getNauticalMilesPerDegreeLongitude();
- }
-
- public double getNauticalMilesPerDegreeLongitude() {
- double milesPerDegree = Math.abs(Math.cos(Math.toRadians(this.centerLatitude)) * NAUTICAL_MILES_PER_DEGREE_LATITUDE);
- return milesPerDegree;
- }
-
- public double getPixelsPerNauticalMile() {
- return this.pixelsPerNauticalMile;
- }
-
- public void zoomIn() {
- this.pixelsPerNauticalMile = Math.min(MAX_ZOOM_PIXELS_PER_MILE, this.pixelsPerNauticalMile * 2);
- this.redraw();
- }
-
- public void zoomOut() {
- this.pixelsPerNauticalMile = Math.max(MIN_ZOOM_PIXELS_PER_MILE, this.pixelsPerNauticalMile / 2);
- this.redraw();
- }
-
- public void moveEast() {
- double degreesToMove = PAN_INTERVAL_MILES / this.getNauticalMilesPerDegreeLongitude();
- this.centerLongitude = Math.min(this.centerLongitude + degreesToMove, MAX_LONGITUDE);
- this.redraw();
- }
-
- public void moveWest() {
- double degreesToMove = PAN_INTERVAL_MILES / this.getNauticalMilesPerDegreeLongitude();
- this.centerLongitude = Math.max(this.centerLongitude - degreesToMove, MIN_LONGITUDE);
- 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.redraw();
- }
-
- public void moveSouth() {
- double degreesToMove = PAN_INTERVAL_MILES / NAUTICAL_MILES_PER_DEGREE_LATITUDE;
- this.centerLatitude = Math.max(this.centerLatitude - degreesToMove, MIN_LATITUDE);
- this.redraw();
- }
-}
diff --git a/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java b/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
deleted file mode 100644
index e490dae..0000000
--- a/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package com.benburwell.planes.gui.aircraftmap;
-
-import com.benburwell.planes.data.AircraftStore;
-import com.benburwell.planes.data.AircraftStoreListener;
-import com.benburwell.planes.data.Position;
-import com.benburwell.planes.gui.ViewComponent;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.KeyEvent;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Collections;
-
-/**
- * Created by ben on 11/18/16.
- */
-public class AircraftMapComponent implements ViewComponent {
- private AircraftStore store;
- private AircraftMap mapPanel;
- private String focusedAircraftIdentifier = null;
-
- public AircraftMapComponent(AircraftStore store) {
- this.store = store;
- this.setupMap();
- this.bindKeys();
- this.subscribeToChanges();
- }
-
- public void focusNextAircraft() {
- // List<String> aircraftIdentifiers = new ArrayList<>(this.store.getAircraft().keySet());
- // Collections.sort(aircraftIdentifiers);
- // if (this.focusedAircraftIdentifier == null && aircraftIdentifiers.size() > 0) {
- // this.focusedAircraftIdentifier = aircraftIdentifiers.get(0);
- // } else {
- // int idx = aircraftIdentifiers.indexOf(this.focusedAircraftIdentifier);
- // if (idx > 0 && idx < aircraftIdentifiers.size() - 1) {
- // this.focusedAircraftIdentifier = aircraftIdentifiers.get(idx++);
- // } else if (aircraftIdentifiers.size() > 0) {
- // this.focusedAircraftIdentifier = aircraftIdentifiers.get(0);
- // } else {
- // this.focusedAircraftIdentifier = null;
- // }
- // }
- }
-
- private void setupMap() {
- this.mapPanel = new AircraftMap();
- this.mapPanel.setCenter(40.6188942, -75.4947205);
- }
-
- private void bindKeys() {
- KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(e -> {
- 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) {
- this.mapPanel.zoomOut();
- } else if (e.getKeyCode() == KeyEvent.VK_L && e.getID() == KeyEvent.KEY_PRESSED) {
- this.mapPanel.moveEast();
- } else if (e.getKeyCode() == KeyEvent.VK_H && e.getID() == KeyEvent.KEY_PRESSED) {
- this.mapPanel.moveWest();
- } else if (e.getKeyCode() == KeyEvent.VK_J && e.getID() == KeyEvent.KEY_PRESSED) {
- this.mapPanel.moveSouth();
- } else if (e.getKeyCode() == KeyEvent.VK_K && e.getID() == KeyEvent.KEY_PRESSED) {
- this.mapPanel.moveNorth();
- } else if (e.getKeyCode() == KeyEvent.VK_0 && e.getID() == KeyEvent.KEY_PRESSED) {
- this.mapPanel.setCenter(40.6188942, -75.4947205);
- } else if (e.getKeyCode() == KeyEvent.VK_TAB && e.getID() == KeyEvent.KEY_PRESSED) {
- this.focusNextAircraft();
- this.centerMapOnPlane(this.focusedAircraftIdentifier);
- }
- return false;
- });
- }
-
- private void centerMapOnPlane(String identifier) {
- if (identifier != null) {
- Position pos = this.store.getAircraft().get(identifier).getCurrentPosition();
- this.mapPanel.setCenter(pos.getLatitude(), pos.getLongitude());
- }
- }
-
- private void subscribeToChanges() {
- this.store.subscribe(new AircraftStoreListener() {
- @Override
- public void aircraftStoreChanged() {
- List<Drawable> planes = new ArrayList<>();
- store.getAircraft().values().forEach(aircraft -> planes.add(new Plane(aircraft)));
- mapPanel.setPlanes(planes);
- mapPanel.validate();
- mapPanel.repaint();
- }
-
- @Override
- public boolean respondTo(String aircraftId) {
- return true;
- }
- });
- }
-
- @Override
- public JComponent getComponent() {
- return this.mapPanel;
- }
-
-}
diff --git a/src/com/benburwell/planes/gui/aircraftmap/Drawable.java b/src/com/benburwell/planes/gui/aircraftmap/Drawable.java
deleted file mode 100644
index 01c16ba..0000000
--- a/src/com/benburwell/planes/gui/aircraftmap/Drawable.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.benburwell.planes.gui.aircraftmap;
-
-import java.awt.*;
-
-/**
- * Created by ben on 11/19/16.
- */
-public interface Drawable {
- void drawOn(Graphics graphicsContext, AircraftMap map);
-}
diff --git a/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java b/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java
deleted file mode 100644
index d3eda40..0000000
--- a/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.benburwell.planes.gui.aircraftmap;
-
-/**
- * Created by ben on 11/19/16.
- */
-public class GeoPoint {
- private double latitude;
- private double longitude;
- private double altitude;
-
- public GeoPoint(double latitude, double longitude, double altitude) {
- this.latitude = latitude;
- this.longitude = longitude;
- this.altitude = altitude;
- }
-
- public int getX(AircraftMap map) {
- double degreesFromCenter = map.getCenterLongitude() - this.longitude;
- double pixelsFromCenter = degreesFromCenter * map.getPixelsPerDegreeLongitude();
- double centerPixels = map.getSize().getWidth() / 2;
- int xPosition = (int) (centerPixels - pixelsFromCenter);
- return xPosition;
- }
-
- public int getY(AircraftMap map) {
- double degreesFromCenter = map.getCenterLatitude() - this.latitude;
- double pixelsFromCenter = degreesFromCenter * map.getPixelsPerDegreeLatitude();
- double centerPixels = map.getSize().getHeight() / 2;
- int yPosition = (int) (centerPixels + pixelsFromCenter);
- return yPosition;
- }
-
- public double getAltitude() {
- return this.altitude;
- }
-}
diff --git a/src/com/benburwell/planes/gui/aircraftmap/Plane.java b/src/com/benburwell/planes/gui/aircraftmap/Plane.java
deleted file mode 100644
index 2f98bab..0000000
--- a/src/com/benburwell/planes/gui/aircraftmap/Plane.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.benburwell.planes.gui.aircraftmap;
-
-import com.benburwell.planes.data.Aircraft;
-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 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 Plane(Aircraft ac) {
- this(ac.getCallsign(), ac.getCurrentPosition(), ac.getTrack(), ac.getGroundSpeed(), ac.getVerticalRate());
- }
-
- public Plane(String name, Position position, double heading, double speed, double verticalRate) {
- this(name, position.getLatitude(), position.getLongitude(), position.getAltitude(), heading, speed, verticalRate);
- }
-
- public Plane(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) {
- 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
- 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());
- }
- }
-}