summaryrefslogtreecommitdiff
path: root/src/com/benburwell/planes/gui/aircraftmap/Plane.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/benburwell/planes/gui/aircraftmap/Plane.java')
-rw-r--r--src/com/benburwell/planes/gui/aircraftmap/Plane.java35
1 files changed, 28 insertions, 7 deletions
diff --git a/src/com/benburwell/planes/gui/aircraftmap/Plane.java b/src/com/benburwell/planes/gui/aircraftmap/Plane.java
index c7f774e..8575334 100644
--- a/src/com/benburwell/planes/gui/aircraftmap/Plane.java
+++ b/src/com/benburwell/planes/gui/aircraftmap/Plane.java
@@ -4,25 +4,29 @@ import com.benburwell.planes.data.Position;
import com.benburwell.planes.gui.GraphicsTheme;
import java.awt.*;
+import java.awt.geom.AffineTransform;
/**
* Created by ben on 11/19/16.
*/
public class Plane extends GeoPoint implements Drawable {
- public final int DOT_DIMENSION = 4;
+ public final int TRIANGLE_HEIGHT = 8;
+ public final int TRIANGLE_WIDTH = 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 double heading;
- public Plane(String name, Position position) {
- this(name, position.getLatitude(), position.getLongitude(), position.getAltitude());
+ public Plane(String name, Position position, double heading) {
+ this(name, position.getLatitude(), position.getLongitude(), position.getAltitude(), heading);
}
- public Plane(String name, double latitude, double longitude, double altitude) {
+ public Plane(String name, double latitude, double longitude, double altitude, double heading) {
super(latitude, longitude, altitude);
this.name = name;
+ this.heading = heading;
}
public int getFlightLevel() {
@@ -52,17 +56,34 @@ public class Plane extends GeoPoint implements Drawable {
return c;
}
+ public double getAngle() {
+ return Math.toRadians(this.heading);
+ }
+
+ public void drawTriangle(Graphics2D ctx, int x, int y) {
+ AffineTransform at = new AffineTransform();
+ //at.setToRotation(this.getAngle(), x, y);
+ at.setToRotation(this.getAngle(), x, y);
+ ctx.setTransform(at);
+ int[] xs = new int[]{ x - TRIANGLE_WIDTH, x, x + TRIANGLE_WIDTH, x - TRIANGLE_WIDTH };
+ int[] ys = new int[]{ y + TRIANGLE_HEIGHT, y - TRIANGLE_HEIGHT, y + TRIANGLE_HEIGHT, y + TRIANGLE_HEIGHT };
+ ctx.drawPolyline(xs, ys, 4);
+ }
+
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(this.getPlaneColor());
- g.drawRect(x - (DOT_DIMENSION / 2), y - (DOT_DIMENSION / 2), DOT_DIMENSION, DOT_DIMENSION);
+ Graphics2D g2d = (Graphics2D) g.create();
+ g2d.setColor(this.getPlaneColor());
+ this.drawTriangle(g2d, x, y);
+ g2d.dispose();
+
// draw the name of the plane
- g.setColor(GraphicsTheme.Colors.BLUE);
+ g.setColor(GraphicsTheme.Colors.BASE_5);
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());
}