summaryrefslogtreecommitdiff
path: root/src/main/java/com/benburwell/planes/gui/aircraftmap/symbols/AirportSymbol.java
blob: 7467a0f762ef49201755bbc039ec9c509a3af218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.benburwell.planes.gui.aircraftmap.symbols;

import com.benburwell.planes.data.Airport;
import com.benburwell.planes.gui.GraphicsTheme;
import com.benburwell.planes.gui.aircraftmap.AircraftMap;
import com.benburwell.planes.gui.aircraftmap.Drawable;
import com.benburwell.planes.gui.aircraftmap.GeoPoint;

import java.awt.Graphics;

/**
 * @author ben
 */
public class AirportSymbol extends GeoPoint implements Drawable {
    private String name;
    private String iataCode;
    private String localCode;

    public AirportSymbol(Airport airport) {
        super(airport.getLatitude(), airport.getLongitude(), airport.getElevation());
        this.name = airport.getName();
        this.iataCode = airport.getIataCode();
        this.localCode = airport.getLocalCode();
    }

    public String getDisplayName() {
        if (this.iataCode != null && !this.iataCode.isEmpty()) {
            return this.iataCode;
        }
        if (this.localCode != null && !this.localCode.isEmpty()) {
            return this.localCode;
        }
        return this.name;
    }

    @Override
    public void drawOn(Graphics g, AircraftMap map) {
        if (this.shouldDrawOn(map)) {
            int x = this.getX(map);
            int y = this.getY(map);

            g.setColor(GraphicsTheme.Styles.MAP_AIRPORT_COLOR);

            g.drawRect(x - 2, y - 2, 4, 4);
            g.drawString(this.getDisplayName(), x + 6, y);
        }
    }
}