summaryrefslogtreecommitdiff
path: root/src/main/java/com/benburwell/planes/gui/navigationaids/AirportsTableModel.java
blob: 28501960f67b6e9f9854bd8143525563b0bfdca0 (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
49
50
51
52
53
54
55
56
package com.benburwell.planes.gui.navigationaids;

import com.benburwell.planes.data.Airport;

import javax.swing.table.AbstractTableModel;
import java.util.List;

/**
 * Created by ben on 11/19/16.
 */
public class AirportsTableModel extends AbstractTableModel {
    public final String[] COLUMN_HEADERS = {"Identifier", "Name", "Country", "Municipality", "Scheduled Service", "IATA Code", "Local Code"};

    public List<Airport> airports;

    public AirportsTableModel(List<Airport> airports) {
        this.airports = airports;
    }

    @Override
    public String getColumnName(int columnIndex) {
        return COLUMN_HEADERS[columnIndex];
    }

    @Override
    public int getRowCount() {
        return airports.size();
    }

    @Override
    public int getColumnCount() {
        return COLUMN_HEADERS.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Airport airport = this.airports.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return airport.getIdent();
            case 1:
                return airport.getName();
            case 2:
                return airport.getIsoCountry();
            case 3:
                return airport.getMunicipality();
            case 4:
                return airport.isScheduledService();
            case 5:
                return airport.getIataCode();
            case 6:
                return airport.getLocalCode();
        }
        return null;
    }
}