From 3c9729bd52dc24c0109a18d1924d30a9c14b3b06 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sat, 19 Nov 2016 19:04:20 -0500 Subject: Get gradle working --- build.gradle | 3 +- settings.gradle | 1 + .../com/benburwell/planes/data/NavigationAid.java | 68 ++++++++++++++++++++-- .../benburwell/planes/data/NavigationAidStore.java | 26 +++++++++ .../gui/aircraftmap/AircraftMapComponent.java | 14 +++++ 5 files changed, 106 insertions(+), 6 deletions(-) create mode 100644 settings.gradle create mode 100644 src/main/java/com/benburwell/planes/data/NavigationAidStore.java diff --git a/build.gradle b/build.gradle index db544da..d5e342e 100644 --- a/build.gradle +++ b/build.gradle @@ -2,8 +2,6 @@ apply plugin: 'java' apply plugin: 'application' compileJava.options.encoding = 'UTF-8' - - mainClassName = 'com.benburwell.planes.gui.Main1090' // In this section you declare where to find the dependencies of your project @@ -34,3 +32,4 @@ jar { ) } } + diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..4a9ab1d --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "Planes" 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 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() { -- cgit v1.2.3