summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorBen Burwell <ben.burwell@trifecta.com>2016-11-19 19:04:20 -0500
committerBen Burwell <ben.burwell@trifecta.com>2016-11-19 19:04:20 -0500
commit3c9729bd52dc24c0109a18d1924d30a9c14b3b06 (patch)
tree9992d75ba28542c5f1bb20814424b280c99239a4 /src/main/java
parent380f579d9e49a0dfbde32e9141f5edf0a9a4d088 (diff)
Get gradle working
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/benburwell/planes/data/NavigationAid.java68
-rw-r--r--src/main/java/com/benburwell/planes/data/NavigationAidStore.java26
-rw-r--r--src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java14
3 files changed, 104 insertions, 4 deletions
diff --git a/src/main/java/com/benburwell/planes/data/NavigationAid.java b/src/main/java/com/benburwell/planes/data/NavigationAid.java
index 09521a0..85219ba 100644
--- a/src/main/java/com/benburwell/planes/data/NavigationAid.java
+++ b/src/main/java/com/benburwell/planes/data/NavigationAid.java
@@ -1,5 +1,7 @@
package com.benburwell.planes.data;
+import org.apache.commons.csv.CSVRecord;
+
/**
* Frequencies in kHz, elevations in ft
*
@@ -9,6 +11,7 @@ public class NavigationAid {
private int id;
private String filename;
private String ident;
+ private String name;
private String type;
private int frequency;
private double latitude;
@@ -26,11 +29,60 @@ public class NavigationAid {
private String power;
private String associatedAirport;
- public NavigationAid() {}
+ public NavigationAid(CSVRecord record) {
+ this.setId(Integer.valueOf(record.get("id")));
+ this.setFilename(record.get("filename"));
+ this.setIdent(record.get("ident"));
+ this.setName(record.get("name"));
+ this.setType(record.get("type"));
+
+ try {
+ this.setFrequency(Integer.valueOf(record.get("frequency_khz")));
+ } catch (NumberFormatException ignored) {}
+
+ try {
+ this.setLatitude(Double.valueOf(record.get("latitude_deg")));
+ } catch (NumberFormatException ignored) {}
+
+ try {
+ this.setLongitude(Double.valueOf(record.get("longitude_deg")));
+ } catch (NumberFormatException ignored) {}
+
+ try {
+ this.setElevation(Integer.valueOf(record.get("elevation_ft")));
+ } catch (NumberFormatException ignored) {}
+
+ this.setIsoCountry(record.get("iso_country"));
+
+ try {
+ this.setDmeFrequency(Double.valueOf(record.get("dme_frequency_khz")));
+ } catch (NumberFormatException ignored) {}
+
+ this.setDmeChannel(record.get("dme_channel"));
+
+ try {
+ this.setDmeLatitude(Double.valueOf(record.get("dme_latitude_deg")));
+ } catch (NumberFormatException ignored) {}
- public static NavigationAid fromCSV(String row) {
- NavigationAid aid = new NavigationAid();
- return aid;
+ try {
+ this.setDmeLongitude(Double.valueOf(record.get("dme_longitude_deg")));
+ } catch (NumberFormatException ignored) {}
+
+ try {
+ this.setDmeElevation(Integer.valueOf(record.get("dme_elevation_ft")));
+ } catch (NumberFormatException ignored) {}
+
+ try {
+ this.setSlavedVariation(Double.valueOf(record.get("slaved_variation_deg")));
+ } catch (NumberFormatException ignored) {}
+
+ try {
+ this.setMagneticVariation(Double.valueOf(record.get("magnetic_variation_deg")));
+ } catch (NumberFormatException ignored) {}
+
+ this.setUsageType(record.get("usageType"));
+ this.setPower(record.get("power"));
+ this.setAssociatedAirport(record.get("associated_airport"));
}
public int getId() {
@@ -184,4 +236,12 @@ public class NavigationAid {
public void setAssociatedAirport(String associatedAirport) {
this.associatedAirport = associatedAirport;
}
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
}
diff --git a/src/main/java/com/benburwell/planes/data/NavigationAidStore.java b/src/main/java/com/benburwell/planes/data/NavigationAidStore.java
new file mode 100644
index 0000000..3bc06d9
--- /dev/null
+++ b/src/main/java/com/benburwell/planes/data/NavigationAidStore.java
@@ -0,0 +1,26 @@
+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<NavigationAid> 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));
+ }
+ }
+}
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 e490dae..f45071b 100644
--- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
+++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
@@ -2,12 +2,14 @@ package com.benburwell.planes.gui.aircraftmap;
import com.benburwell.planes.data.AircraftStore;
import com.benburwell.planes.data.AircraftStoreListener;
+import com.benburwell.planes.data.NavigationAidStore;
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.io.IOException;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
@@ -17,14 +19,26 @@ import java.util.Collections;
*/
public class AircraftMapComponent implements ViewComponent {
private AircraftStore store;
+ private NavigationAidStore navaids;
private AircraftMap mapPanel;
private String focusedAircraftIdentifier = null;
public AircraftMapComponent(AircraftStore store) {
this.store = store;
+ this.navaids = new NavigationAidStore();
+
this.setupMap();
this.bindKeys();
this.subscribeToChanges();
+ this.readNavAids();
+ }
+
+ public void readNavAids() {
+ try {
+ this.navaids.readFromFile("/home/ben/.airdata/navaids.csv");
+ } catch (IOException e) {
+ System.out.println("Could not read navaid file: " + e.getMessage());
+ }
}
public void focusNextAircraft() {