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/AircraftTableModel.java65
-rw-r--r--src/com/benburwell/planes/gui/Main1090.java61
2 files changed, 119 insertions, 7 deletions
diff --git a/src/com/benburwell/planes/gui/AircraftTableModel.java b/src/com/benburwell/planes/gui/AircraftTableModel.java
new file mode 100644
index 0000000..72be372
--- /dev/null
+++ b/src/com/benburwell/planes/gui/AircraftTableModel.java
@@ -0,0 +1,65 @@
+package com.benburwell.planes.gui;
+
+import com.benburwell.planes.data.Aircraft;
+
+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", "Packets" };
+
+ public AircraftTableModel(Map<String,Aircraft> aircraftMap) {
+ this.aircraftMap = aircraftMap;
+ }
+
+ @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.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/Main1090.java b/src/com/benburwell/planes/gui/Main1090.java
index 5393dc0..02ef2bf 100644
--- a/src/com/benburwell/planes/gui/Main1090.java
+++ b/src/com/benburwell/planes/gui/Main1090.java
@@ -5,14 +5,19 @@
package com.benburwell.planes.gui;
import com.benburwell.planes.sbs.*;
+import com.benburwell.planes.data.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
+import java.util.Map;
+import java.util.HashMap;
public class Main1090 extends JFrame {
private AggregateDataSource sbsDataSource = new AggregateDataSource();
+ private Map<String,Aircraft> aircraftMap = new HashMap<>();
+ private int currentTcpConnection = 0;
+ private AircraftTableModel aircraftTableModel = new AircraftTableModel(this.aircraftMap);
public Main1090() {
this.initUI();
@@ -21,6 +26,8 @@ public class Main1090 extends JFrame {
private void initUI() {
this.createMenuBar();
+ this.createTable();
+
this.setTitle("1090");
this.setSize(100, 100);
this.setLocationRelativeTo(null);
@@ -29,27 +36,67 @@ public class Main1090 extends JFrame {
this.openDataSource();
}
+ private void createTable() {
+ JTable table = new JTable(this.aircraftTableModel);
+ table.setFillsViewportHeight(true);
+ JScrollPane scrollPane = new JScrollPane(table);
+ this.add(scrollPane);
+ }
+
private void createMenuBar() {
JMenuBar menubar = new JMenuBar();
JMenu file = new JMenu("1090");
- file.setMnemonic(KeyEvent.VK_F);
JMenuItem eMenuItem = new JMenuItem("Quit");
- eMenuItem.setMnemonic(KeyEvent.VK_E);
- eMenuItem.setToolTipText("Exit 1090");
+ JMenu data = new JMenu("Data");
+ JMenuItem dataConnectItem = new JMenuItem("Connect...");
+ JMenuItem dataDisconnectItem = new JMenuItem("Disconnect");
+
eMenuItem.addActionListener((ActionEvent event) -> {
System.exit(0);
});
file.add(eMenuItem);
menubar.add(file);
+
+ dataConnectItem.addActionListener((ActionEvent event) -> {
+ if (this.currentTcpConnection == 0) {
+ this.currentTcpConnection = this.addTcpSource("10.0.0.111", 30003);
+ dataConnectItem.setEnabled(false);
+ dataDisconnectItem.setEnabled(true);
+ }
+ });
+ dataDisconnectItem.addActionListener((ActionEvent event) -> {
+ if (this.currentTcpConnection != 0) {
+ this.sbsDataSource.closeSource(this.currentTcpConnection);
+ dataConnectItem.setEnabled(true);
+ dataDisconnectItem.setEnabled(false);
+ this.currentTcpConnection = 0;
+ }
+ });
+ dataDisconnectItem.setEnabled(false);
+ data.add(dataConnectItem);
+ data.add(dataDisconnectItem);
+ menubar.add(data);
+
this.setJMenuBar(menubar);
}
private void openDataSource() {
- System.out.println("asdfasdfasdfasdfasdf");
- this.sbsDataSource.addSource(new TCPDataSource("10.0.0.111", 30003));
this.sbsDataSource.subscribe((SBSPacket packet) -> {
- System.out.println("Got message: " + packet.toString());
+ if (packet.getHexIdent() != null) {
+ if (!this.aircraftMap.containsKey(packet.getHexIdent())) {
+ this.aircraftMap.put(packet.getHexIdent(), new Aircraft(packet.getHexIdent()));
+ }
+ this.aircraftMap.get(packet.getHexIdent()).handleUpdate(packet);
+ this.aircraftTableModel.fireTableDataChanged();
+ }
});
+ 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) {