From a448320cc4661f9304a8323d6c0e05f1f0fee2b3 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sat, 19 Nov 2016 22:55:10 -0500 Subject: Use resources for data (for now) At some point, it would be nice for this to be more configurable --- .../benburwell/planes/data/AbstractCSVReader.java | 10 +++ .../java/com/benburwell/planes/data/Airport.java | 4 +- .../com/benburwell/planes/data/AirportStore.java | 30 -------- .../com/benburwell/planes/data/CSVObjectStore.java | 42 +++++++++++ .../com/benburwell/planes/data/NavigationAid.java | 4 +- .../benburwell/planes/data/NavigationAidStore.java | 30 -------- .../planes/gui/AircraftTableComponent.java | 26 ------- .../benburwell/planes/gui/AircraftTableModel.java | 85 ---------------------- .../java/com/benburwell/planes/gui/Main1090.java | 22 +++--- .../planes/gui/NavigationAidComponent.java | 26 ------- .../planes/gui/NavigationAidsTableModel.java | 57 --------------- .../gui/aircraftmap/AircraftMapComponent.java | 10 +-- .../gui/aircrafttable/AircraftTableComponent.java | 27 +++++++ .../gui/aircrafttable/AircraftTableModel.java | 85 ++++++++++++++++++++++ .../gui/navigationaids/NavigationAidComponent.java | 28 +++++++ .../navigationaids/NavigationAidsTableModel.java | 57 +++++++++++++++ 16 files changed, 269 insertions(+), 274 deletions(-) create mode 100644 src/main/java/com/benburwell/planes/data/AbstractCSVReader.java delete mode 100644 src/main/java/com/benburwell/planes/data/AirportStore.java create mode 100644 src/main/java/com/benburwell/planes/data/CSVObjectStore.java delete mode 100644 src/main/java/com/benburwell/planes/data/NavigationAidStore.java delete mode 100644 src/main/java/com/benburwell/planes/gui/AircraftTableComponent.java delete mode 100644 src/main/java/com/benburwell/planes/gui/AircraftTableModel.java delete mode 100644 src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java delete mode 100644 src/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java create mode 100644 src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java create mode 100644 src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java create mode 100644 src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java create mode 100644 src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java (limited to 'src/main/java') diff --git a/src/main/java/com/benburwell/planes/data/AbstractCSVReader.java b/src/main/java/com/benburwell/planes/data/AbstractCSVReader.java new file mode 100644 index 0000000..66084ed --- /dev/null +++ b/src/main/java/com/benburwell/planes/data/AbstractCSVReader.java @@ -0,0 +1,10 @@ +package com.benburwell.planes.data; + +import org.apache.commons.csv.CSVRecord; + +/** + * Created by ben on 11/19/16. + */ +public abstract class AbstractCSVReader { + public abstract void readRecord(CSVRecord record); +} diff --git a/src/main/java/com/benburwell/planes/data/Airport.java b/src/main/java/com/benburwell/planes/data/Airport.java index 92e43bc..ab16248 100644 --- a/src/main/java/com/benburwell/planes/data/Airport.java +++ b/src/main/java/com/benburwell/planes/data/Airport.java @@ -5,7 +5,7 @@ import org.apache.commons.csv.CSVRecord; /** * Created by ben on 11/19/16. */ -public class Airport { +public class Airport extends AbstractCSVReader { private int id; private String ident; private String type; @@ -25,7 +25,7 @@ public class Airport { private String wikipediaLink; private String keywords; - public Airport(CSVRecord record) { + public void readRecord(CSVRecord record) { this.setId(Integer.valueOf(record.get("id"))); this.setIdent(record.get("ident")); this.setType(record.get("type")); diff --git a/src/main/java/com/benburwell/planes/data/AirportStore.java b/src/main/java/com/benburwell/planes/data/AirportStore.java deleted file mode 100644 index 93f1ccc..0000000 --- a/src/main/java/com/benburwell/planes/data/AirportStore.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.benburwell.planes.data; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVRecord; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by ben on 11/19/16. - */ -public class AirportStore { - private List airports = new ArrayList<>(); - - public void readFromFile(String filename) throws IOException { - File csvData = new File(filename); - CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180.withFirstRecordAsHeader()); - for (CSVRecord record : parser) { - this.airports.add(new Airport(record)); - } - } - - public List getAirports() { - return this.airports; - } -} diff --git a/src/main/java/com/benburwell/planes/data/CSVObjectStore.java b/src/main/java/com/benburwell/planes/data/CSVObjectStore.java new file mode 100644 index 0000000..a92e0a2 --- /dev/null +++ b/src/main/java/com/benburwell/planes/data/CSVObjectStore.java @@ -0,0 +1,42 @@ +package com.benburwell.planes.data; + +import org.apache.commons.csv.CSVFormat; +import org.apache.commons.csv.CSVParser; +import org.apache.commons.csv.CSVRecord; + +import java.io.*; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by ben on 11/19/16. + */ +public class CSVObjectStore { + private List objects = new ArrayList<>(); + + public void readFromFile(String fileName, Class klass) throws IOException, IllegalAccessException, InstantiationException { + File csvData = new File(fileName); + CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180.withFirstRecordAsHeader()); + for (CSVRecord record : parser) { + T obj = klass.newInstance(); + obj.readRecord(record); + this.objects.add(obj); + } + } + + public void readFromResource(String resourceName, Class klass) throws IOException, IllegalAccessException, InstantiationException { + InputStream stream = this.getClass().getResourceAsStream(resourceName); + Reader csvData = new BufferedReader(new InputStreamReader(stream)); + CSVParser parser = new CSVParser(csvData, CSVFormat.RFC4180.withFirstRecordAsHeader()); + for (CSVRecord record : parser) { + T obj = klass.newInstance(); + obj.readRecord(record); + this.objects.add(obj); + } + } + + public List getObjects() { + return this.objects; + } +} diff --git a/src/main/java/com/benburwell/planes/data/NavigationAid.java b/src/main/java/com/benburwell/planes/data/NavigationAid.java index 85219ba..d730e7e 100644 --- a/src/main/java/com/benburwell/planes/data/NavigationAid.java +++ b/src/main/java/com/benburwell/planes/data/NavigationAid.java @@ -7,7 +7,7 @@ import org.apache.commons.csv.CSVRecord; * * Created by ben on 11/19/16. */ -public class NavigationAid { +public class NavigationAid extends AbstractCSVReader { private int id; private String filename; private String ident; @@ -29,7 +29,7 @@ public class NavigationAid { private String power; private String associatedAirport; - public NavigationAid(CSVRecord record) { + public void readRecord(CSVRecord record) { this.setId(Integer.valueOf(record.get("id"))); this.setFilename(record.get("filename")); this.setIdent(record.get("ident")); diff --git a/src/main/java/com/benburwell/planes/data/NavigationAidStore.java b/src/main/java/com/benburwell/planes/data/NavigationAidStore.java deleted file mode 100644 index 6f0ce9c..0000000 --- a/src/main/java/com/benburwell/planes/data/NavigationAidStore.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.benburwell.planes.data; - -import org.apache.commons.csv.CSVFormat; -import org.apache.commons.csv.CSVParser; -import org.apache.commons.csv.CSVRecord; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.io.File; - -/** - * Created by ben on 11/19/16. - */ -public class NavigationAidStore { - private List aids = new ArrayList<>(); - - public void readFromFile(String fileName) throws IOException { - File csvData = new File(fileName); - CSVParser parser = CSVParser.parse(csvData, Charset.defaultCharset(), CSVFormat.RFC4180.withFirstRecordAsHeader()); - for (CSVRecord record : parser) { - this.aids.add(new NavigationAid(record)); - } - } - - public List getNavigationAids() { - return this.aids; - } -} diff --git a/src/main/java/com/benburwell/planes/gui/AircraftTableComponent.java b/src/main/java/com/benburwell/planes/gui/AircraftTableComponent.java deleted file mode 100644 index 221bdda..0000000 --- a/src/main/java/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/main/java/com/benburwell/planes/gui/AircraftTableModel.java b/src/main/java/com/benburwell/planes/gui/AircraftTableModel.java deleted file mode 100644 index 3931893..0000000 --- a/src/main/java/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 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 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 getAircraftList() { - List aircraftList = new ArrayList<>(this.aircraftMap.values()); - Collections.sort(aircraftList); - return aircraftList; - } -} diff --git a/src/main/java/com/benburwell/planes/gui/Main1090.java b/src/main/java/com/benburwell/planes/gui/Main1090.java index 962e428..b0847bd 100644 --- a/src/main/java/com/benburwell/planes/gui/Main1090.java +++ b/src/main/java/com/benburwell/planes/gui/Main1090.java @@ -4,6 +4,8 @@ package com.benburwell.planes.gui; +import com.benburwell.planes.gui.aircrafttable.AircraftTableComponent; +import com.benburwell.planes.gui.navigationaids.NavigationAidComponent; import com.benburwell.planes.sbs.*; import com.benburwell.planes.data.*; import com.benburwell.planes.gui.aircraftmap.*; @@ -16,8 +18,8 @@ import java.io.IOException; public class Main1090 extends JFrame { private AggregateDataSource sbsDataSource = new AggregateDataSource(); private AircraftStore aircraft = new AircraftStore(); - private NavigationAidStore navaids = new NavigationAidStore(); - private AirportStore airports = new AirportStore(); + private CSVObjectStore navaids = new CSVObjectStore<>(); + private CSVObjectStore airports = new CSVObjectStore<>(); private int currentTcpConnection = 0; private JTabbedPane tabbedPane = new JTabbedPane(); @@ -36,14 +38,14 @@ public class Main1090 extends JFrame { this.openDataSource(); try { - this.navaids.readFromFile("/home/ben/.airdata/navaids.csv"); - } catch (IOException e) { + this.navaids.readFromResource("/navaids.csv", NavigationAid.class); + } catch (IOException | InstantiationException | IllegalAccessException e) { System.out.println("Could not read navaid file: " + e.getMessage()); } try { - this.airports.readFromFile("/home/ben/.airdata/airports.csv"); - } catch (IOException e) { + this.airports.readFromResource("/airports.csv", Airport.class); + } catch (IOException | InstantiationException | IllegalAccessException e) { System.out.println("Could not read airport file: " + e.getMessage()); } @@ -51,19 +53,17 @@ public class Main1090 extends JFrame { } private void createTabs() { - AircraftTableComponent aircraftData = new AircraftTableComponent(this.aircraft); - this.tabbedPane.addTab("Aircraft Data", aircraftData.getComponent()); - AircraftMapComponent aircraftMap = new AircraftMapComponent(this.aircraft, this.navaids, this.airports); this.tabbedPane.addTab("Live Map", aircraftMap.getComponent()); + AircraftTableComponent aircraftData = new AircraftTableComponent(this.aircraft); + this.tabbedPane.addTab("Aircraft Data", aircraftData.getComponent()); + NavigationAidComponent navaids = new NavigationAidComponent(this.navaids); this.tabbedPane.addTab("Navigation Aids", navaids.getComponent()); this.add(this.tabbedPane); this.tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); - - this.tabbedPane.setSelectedIndex(1); } private void createMenuBar() { diff --git a/src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java b/src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java deleted file mode 100644 index a1f97cf..0000000 --- a/src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.benburwell.planes.gui; - -import com.benburwell.planes.data.NavigationAidStore; - -import javax.swing.*; - -/** - * Created by ben on 11/19/16. - */ -public class NavigationAidComponent implements ViewComponent { - private JTable table; - private NavigationAidsTableModel tableModel; - private JScrollPane scrollPane; - - public NavigationAidComponent(NavigationAidStore store) { - this.tableModel = new NavigationAidsTableModel(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/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java b/src/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java deleted file mode 100644 index 064ca25..0000000 --- a/src/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.benburwell.planes.gui; - -import com.benburwell.planes.data.NavigationAid; -import com.benburwell.planes.data.NavigationAidStore; - -import javax.swing.table.AbstractTableModel; - -/** - * Created by ben on 11/19/16. - */ -public class NavigationAidsTableModel extends AbstractTableModel { - private final String[] COLUMN_NAMES = { "Ident", "Type", "Frequency", "DME Frequency", "DME Channel", "Usage Type", "Power", "Airport" }; - private NavigationAidStore store; - - public NavigationAidsTableModel(NavigationAidStore store) { - this.store = store; - } - - @Override - public int getRowCount() { - return this.store.getNavigationAids().size(); - } - - @Override - public String getColumnName(int col) { - return COLUMN_NAMES[col]; - } - - @Override - public int getColumnCount() { - return this.COLUMN_NAMES.length; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - NavigationAid aid = this.store.getNavigationAids().get(rowIndex); - switch (columnIndex) { - case 0: - return aid.getIdent(); - case 1: - return aid.getType(); - case 2: - return aid.getFrequency(); - case 3: - return aid.getDmeFrequency(); - case 4: - return aid.getDmeChannel(); - case 5: - return aid.getUsageType(); - case 6: - return aid.getPower(); - case 7: - return aid.getAssociatedAirport(); - } - return null; - } -} 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 24dfc94..b4bb7e2 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java @@ -15,12 +15,12 @@ import java.util.ArrayList; */ public class AircraftMapComponent implements ViewComponent { private AircraftStore store; - private NavigationAidStore navaids; - private AirportStore airportStore; + private CSVObjectStore navaids; + private CSVObjectStore airportStore; private AircraftMap mapPanel; private String focusedAircraftIdentifier = null; - public AircraftMapComponent(AircraftStore store, NavigationAidStore navaids, AirportStore airportStore) { + public AircraftMapComponent(AircraftStore store, CSVObjectStore navaids, CSVObjectStore airportStore) { this.store = store; this.navaids = navaids; this.airportStore = airportStore; @@ -28,8 +28,8 @@ public class AircraftMapComponent implements ViewComponent { this.setupMap(); this.bindKeys(); this.subscribeToChanges(); - this.mapPanel.addNavAids(this.navaids.getNavigationAids()); - this.mapPanel.addAirports(this.airportStore.getAirports()); + this.mapPanel.addNavAids(this.navaids.getObjects()); + this.mapPanel.addAirports(this.airportStore.getObjects()); } public void focusNextAircraft() { diff --git a/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java new file mode 100644 index 0000000..8f1e71d --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java @@ -0,0 +1,27 @@ +package com.benburwell.planes.gui.aircrafttable; + +import com.benburwell.planes.data.AircraftStore; +import com.benburwell.planes.gui.ViewComponent; + +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/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java new file mode 100644 index 0000000..66dc798 --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java @@ -0,0 +1,85 @@ +package com.benburwell.planes.gui.aircrafttable; + +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 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 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 getAircraftList() { + List aircraftList = new ArrayList<>(this.aircraftMap.values()); + Collections.sort(aircraftList); + return aircraftList; + } +} diff --git a/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java new file mode 100644 index 0000000..1ad7e3e --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java @@ -0,0 +1,28 @@ +package com.benburwell.planes.gui.navigationaids; + +import com.benburwell.planes.data.CSVObjectStore; +import com.benburwell.planes.data.NavigationAid; +import com.benburwell.planes.gui.ViewComponent; + +import javax.swing.*; + +/** + * Created by ben on 11/19/16. + */ +public class NavigationAidComponent implements ViewComponent { + private JTable table; + private NavigationAidsTableModel tableModel; + private JScrollPane scrollPane; + + public NavigationAidComponent(CSVObjectStore store) { + this.tableModel = new NavigationAidsTableModel(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/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java new file mode 100644 index 0000000..90b05eb --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java @@ -0,0 +1,57 @@ +package com.benburwell.planes.gui.navigationaids; + +import com.benburwell.planes.data.CSVObjectStore; +import com.benburwell.planes.data.NavigationAid; + +import javax.swing.table.AbstractTableModel; + +/** + * Created by ben on 11/19/16. + */ +public class NavigationAidsTableModel extends AbstractTableModel { + private final String[] COLUMN_NAMES = { "Ident", "Type", "Frequency", "DME Frequency", "DME Channel", "Usage Type", "Power", "Airport" }; + private CSVObjectStore store; + + public NavigationAidsTableModel(CSVObjectStore store) { + this.store = store; + } + + @Override + public int getRowCount() { + return this.store.getObjects().size(); + } + + @Override + public String getColumnName(int col) { + return COLUMN_NAMES[col]; + } + + @Override + public int getColumnCount() { + return this.COLUMN_NAMES.length; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + NavigationAid aid = this.store.getObjects().get(rowIndex); + switch (columnIndex) { + case 0: + return aid.getIdent(); + case 1: + return aid.getType(); + case 2: + return aid.getFrequency(); + case 3: + return aid.getDmeFrequency(); + case 4: + return aid.getDmeChannel(); + case 5: + return aid.getUsageType(); + case 6: + return aid.getPower(); + case 7: + return aid.getAssociatedAirport(); + } + return null; + } +} -- cgit v1.2.3