diff options
author | Ben Burwell <ben.burwell@trifecta.com> | 2016-11-19 22:55:10 -0500 |
---|---|---|
committer | Ben Burwell <ben.burwell@trifecta.com> | 2016-11-19 22:55:10 -0500 |
commit | a448320cc4661f9304a8323d6c0e05f1f0fee2b3 (patch) | |
tree | 274310efc18316c48e0911a428a0f0bce7899033 /src/main/java/com/benburwell/planes/gui | |
parent | 70d15df43ea0d57c3fe237211098645733048c45 (diff) |
Use resources for data (for now)
At some point, it would be nice for this to be more configurable
Diffstat (limited to 'src/main/java/com/benburwell/planes/gui')
-rw-r--r-- | src/main/java/com/benburwell/planes/gui/Main1090.java | 22 | ||||
-rw-r--r-- | src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java | 10 | ||||
-rw-r--r-- | src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java (renamed from src/main/java/com/benburwell/planes/gui/AircraftTableComponent.java) | 5 | ||||
-rw-r--r-- | src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java (renamed from src/main/java/com/benburwell/planes/gui/AircraftTableModel.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java (renamed from src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java) | 8 | ||||
-rw-r--r-- | src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java (renamed from src/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java) | 12 |
6 files changed, 31 insertions, 28 deletions
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<NavigationAid> navaids = new CSVObjectStore<>(); + private CSVObjectStore<Airport> 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/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<NavigationAid> navaids; + private CSVObjectStore<Airport> airportStore; private AircraftMap mapPanel; private String focusedAircraftIdentifier = null; - public AircraftMapComponent(AircraftStore store, NavigationAidStore navaids, AirportStore airportStore) { + public AircraftMapComponent(AircraftStore store, CSVObjectStore<NavigationAid> navaids, CSVObjectStore<Airport> 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/AircraftTableComponent.java b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java index 221bdda..8f1e71d 100644 --- a/src/main/java/com/benburwell/planes/gui/AircraftTableComponent.java +++ b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java @@ -1,13 +1,14 @@ -package com.benburwell.planes.gui; +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{ +public class AircraftTableComponent implements ViewComponent { private JTable table; private AircraftTableModel tableModel; private JScrollPane scrollPane; diff --git a/src/main/java/com/benburwell/planes/gui/AircraftTableModel.java b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java index 3931893..66dc798 100644 --- a/src/main/java/com/benburwell/planes/gui/AircraftTableModel.java +++ b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableModel.java @@ -1,4 +1,4 @@ -package com.benburwell.planes.gui; +package com.benburwell.planes.gui.aircrafttable; import com.benburwell.planes.data.Aircraft; import com.benburwell.planes.data.AircraftStore; diff --git a/src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java index a1f97cf..1ad7e3e 100644 --- a/src/main/java/com/benburwell/planes/gui/NavigationAidComponent.java +++ b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java @@ -1,6 +1,8 @@ -package com.benburwell.planes.gui; +package com.benburwell.planes.gui.navigationaids; -import com.benburwell.planes.data.NavigationAidStore; +import com.benburwell.planes.data.CSVObjectStore; +import com.benburwell.planes.data.NavigationAid; +import com.benburwell.planes.gui.ViewComponent; import javax.swing.*; @@ -12,7 +14,7 @@ public class NavigationAidComponent implements ViewComponent { private NavigationAidsTableModel tableModel; private JScrollPane scrollPane; - public NavigationAidComponent(NavigationAidStore store) { + public NavigationAidComponent(CSVObjectStore<NavigationAid> store) { this.tableModel = new NavigationAidsTableModel(store); this.table = new JTable(this.tableModel); this.table.setFillsViewportHeight(true); diff --git a/src/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java index 064ca25..90b05eb 100644 --- a/src/main/java/com/benburwell/planes/gui/NavigationAidsTableModel.java +++ b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java @@ -1,7 +1,7 @@ -package com.benburwell.planes.gui; +package com.benburwell.planes.gui.navigationaids; +import com.benburwell.planes.data.CSVObjectStore; import com.benburwell.planes.data.NavigationAid; -import com.benburwell.planes.data.NavigationAidStore; import javax.swing.table.AbstractTableModel; @@ -10,15 +10,15 @@ import javax.swing.table.AbstractTableModel; */ public class NavigationAidsTableModel extends AbstractTableModel { private final String[] COLUMN_NAMES = { "Ident", "Type", "Frequency", "DME Frequency", "DME Channel", "Usage Type", "Power", "Airport" }; - private NavigationAidStore store; + private CSVObjectStore<NavigationAid> store; - public NavigationAidsTableModel(NavigationAidStore store) { + public NavigationAidsTableModel(CSVObjectStore<NavigationAid> store) { this.store = store; } @Override public int getRowCount() { - return this.store.getNavigationAids().size(); + return this.store.getObjects().size(); } @Override @@ -33,7 +33,7 @@ public class NavigationAidsTableModel extends AbstractTableModel { @Override public Object getValueAt(int rowIndex, int columnIndex) { - NavigationAid aid = this.store.getNavigationAids().get(rowIndex); + NavigationAid aid = this.store.getObjects().get(rowIndex); switch (columnIndex) { case 0: return aid.getIdent(); |