summaryrefslogtreecommitdiff
path: root/src/com/benburwell
diff options
context:
space:
mode:
authorBen Burwell <ben.burwell@trifecta.com>2016-11-19 13:06:00 -0500
committerBen Burwell <ben.burwell@trifecta.com>2016-11-19 13:06:00 -0500
commit603d7e015bb60eeafa49bf42c2c747c8846e6c46 (patch)
tree7b5efd06f51ccb9eb60eae3c903aa57d90045e4c /src/com/benburwell
parentb8c30e5edd18fc830b944431fda32334af1f9801 (diff)
Use altitude to color planes
Diffstat (limited to 'src/com/benburwell')
-rw-r--r--src/com/benburwell/planes/gui/Main1090.java3
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java12
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java8
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/Plane.java49
4 files changed, 57 insertions, 15 deletions
diff --git a/src/com/benburwell/planes/gui/Main1090.java b/src/com/benburwell/planes/gui/Main1090.java
index 16c03d6..d7fc830 100644
--- a/src/com/benburwell/planes/gui/Main1090.java
+++ b/src/com/benburwell/planes/gui/Main1090.java
@@ -6,6 +6,7 @@ package com.benburwell.planes.gui;
import com.benburwell.planes.sbs.*;
import com.benburwell.planes.data.*;
+import com.benburwell.planes.gui.aircraftmap.*;
import java.awt.*;
import javax.swing.*;
@@ -43,6 +44,8 @@ public class Main1090 extends JFrame {
this.add(this.tabbedPane);
this.tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
+
+ this.tabbedPane.setSelectedIndex(1);
}
private void createMenuBar() {
diff --git a/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java b/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
index c1478b3..b7f8aab 100644
--- a/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
+++ b/src/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java
@@ -27,10 +27,10 @@ public class AircraftMapComponent implements ViewComponent {
this.subscribeToChanges();
List<Drawable> planes = new ArrayList<>();
- planes.add(new Plane("JBU1111", 40.6188942, -75.4947205));
- planes.add(new Plane("JBU1112", 40.6178942, -75.4347205));
- planes.add(new Plane("JBU1114", 40.5178942, -75.5347205));
- planes.add(new Plane("JBU1115", 40.3178942, -75.1347205));
+ planes.add(new Plane("JBU1111", 40.6188942, -75.4947205, 36000));
+ planes.add(new Plane("JBU1112", 40.6178942, -75.4347205, 42000));
+ planes.add(new Plane("JBU1114", 40.5178942, -75.5347205, 3500));
+ planes.add(new Plane("JBU1115", 40.3178942, -75.1347205, 0));
this.mapPanel.setPlanes(planes);
}
@@ -94,9 +94,7 @@ public class AircraftMapComponent implements ViewComponent {
List<Drawable> planes = new ArrayList<>();
store.getAircraft().values().forEach(aircraft -> {
String name = !aircraft.getCallsign().isEmpty() ? aircraft.getCallsign() : aircraft.getHexIdent();
- double lat = aircraft.getCurrentPosition().getLatitude();
- double lon = aircraft.getCurrentPosition().getLongitude();
- planes.add(new Plane(name, lat, lon));
+ planes.add(new Plane(name, aircraft.getCurrentPosition()));
});
mapPanel.setPlanes(planes);
mapPanel.validate();
diff --git a/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java b/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java
index 5cd5535..d3eda40 100644
--- a/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java
+++ b/src/com/benburwell/planes/gui/aircraftmap/GeoPoint.java
@@ -6,10 +6,12 @@ package com.benburwell.planes.gui.aircraftmap;
public class GeoPoint {
private double latitude;
private double longitude;
+ private double altitude;
- public GeoPoint(double latitude, double longitude) {
+ public GeoPoint(double latitude, double longitude, double altitude) {
this.latitude = latitude;
this.longitude = longitude;
+ this.altitude = altitude;
}
public int getX(AircraftMap map) {
@@ -27,4 +29,8 @@ public class GeoPoint {
int yPosition = (int) (centerPixels + pixelsFromCenter);
return yPosition;
}
+
+ public double getAltitude() {
+ return this.altitude;
+ }
}
diff --git a/src/com/benburwell/planes/gui/aircraftmap/Plane.java b/src/com/benburwell/planes/gui/aircraftmap/Plane.java
index 8c3c8c1..911623f 100644
--- a/src/com/benburwell/planes/gui/aircraftmap/Plane.java
+++ b/src/com/benburwell/planes/gui/aircraftmap/Plane.java
@@ -1,5 +1,6 @@
package com.benburwell.planes.gui.aircraftmap;
+import com.benburwell.planes.data.Position;
import com.benburwell.planes.gui.GraphicsTheme;
import java.awt.*;
@@ -8,28 +9,62 @@ import java.awt.*;
* Created by ben on 11/19/16.
*/
public class Plane extends GeoPoint implements Drawable {
+ public final int DOT_DIMENSION = 4;
+ public final int TEXT_OFFSET_X = 10;
+ public final int TEXT_OFFSET_Y = 15;
+ public final int MIN_COLOR_HEIGHT = 0;
+ public final int MAX_COLOR_HEIGHT = 50000;
private String name;
- private final int DOT_DIMENSION = 4;
- private final int TEXT_OFFSET_X = 10;
- private final int TEXT_OFFSET_Y = 15;
- public Plane(String name, double latitude, double longitude) {
- super(latitude, longitude);
+ public Plane(String name, Position position) {
+ this(name, position.getLatitude(), position.getLongitude(), position.getAltitude());
+ }
+
+ public Plane(String name, double latitude, double longitude, double altitude) {
+ super(latitude, longitude, altitude);
this.name = name;
}
+ public int getFlightLevel() {
+ return (int) this.getAltitude() / 100;
+ }
+
+ public Color getPlaneColor() {
+ Color minColor = GraphicsTheme.Colors.RED;
+ Color maxColor = GraphicsTheme.Colors.GREEN;
+
+ float[] minHsb = Color.RGBtoHSB(minColor.getRed(), minColor.getGreen(), minColor.getBlue(), null);
+ float[] maxHsb = Color.RGBtoHSB(maxColor.getRed(), maxColor.getGreen(), maxColor.getBlue(), null);
+
+ float minHue = minHsb[0];
+ float maxHue = maxHsb[0];
+ float minSat = minHsb[1];
+ float maxSat = maxHsb[1];
+ float minBright = minHsb[2];
+ float maxBright = maxHsb[2];
+
+ double planePosition = (this.getAltitude() / (MAX_COLOR_HEIGHT - MIN_COLOR_HEIGHT)) + MIN_COLOR_HEIGHT;
+ float huePosition = (float) (planePosition * (maxHue - minHue) + minHue);
+ float satPosition = (float) (planePosition * (maxSat - minSat) + minSat);
+ float brightPosition = (float) (planePosition * (maxBright - minBright) + minBright);
+
+ Color c = Color.getHSBColor(huePosition, satPosition, brightPosition);
+ return c;
+ }
+
public void drawOn(Graphics g, AircraftMap map) {
int x = this.getX(map);
int y = this.getY(map);
if (x >= 0 && x <= map.getSize().getWidth() && y >= 0 && y <= map.getSize().getHeight()) {
// draw the plane dot
- g.setColor(GraphicsTheme.Colors.ORANGE);
+ g.setColor(this.getPlaneColor());
g.drawRect(x - (DOT_DIMENSION / 2), y - (DOT_DIMENSION / 2), DOT_DIMENSION, DOT_DIMENSION);
// draw the name of the plane
g.setColor(GraphicsTheme.Colors.BLUE);
- g.drawString(this.name, this.getX(map) + TEXT_OFFSET_X, this.getY(map) + TEXT_OFFSET_Y);
+ g.drawString(this.name, x + TEXT_OFFSET_X, y + TEXT_OFFSET_Y);
+ g.drawString("" + this.getFlightLevel(), x + TEXT_OFFSET_X, y + TEXT_OFFSET_Y + g.getFontMetrics().getHeight());
} else {
System.out.println("Skipping drawing plane at " + x + "," + y + " which is not within bounds");
}