From c893302e307b6471b8c3c7f57f46b6c92e7a55ef Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Sat, 19 Nov 2016 23:13:49 -0500 Subject: Refactor tabbing --- .../java/com/benburwell/planes/gui/Main1090.java | 19 ++++---- .../planes/gui/TCPConnectionOptionDialog.java | 3 +- .../java/com/benburwell/planes/gui/Tabbable.java | 11 +++++ .../com/benburwell/planes/gui/ViewComponent.java | 10 ---- .../planes/gui/aircraftmap/AircraftMap.java | 2 +- .../gui/aircraftmap/AircraftMapComponent.java | 8 ++- .../gui/aircrafttable/AircraftTableComponent.java | 9 +++- .../gui/airportstable/AirportsComponent.java | 34 +++++++++++++ .../airportstable/NavigationAidsTableModel.java | 57 ++++++++++++++++++++++ .../gui/navigationaids/AirportsTableModel.java | 56 +++++++++++++++++++++ .../gui/navigationaids/NavigationAidComponent.java | 10 +++- .../navigationaids/NavigationAidsTableModel.java | 57 ---------------------- 12 files changed, 191 insertions(+), 85 deletions(-) create mode 100644 src/main/java/com/benburwell/planes/gui/Tabbable.java delete mode 100644 src/main/java/com/benburwell/planes/gui/ViewComponent.java create mode 100644 src/main/java/com/benburwell/planes/gui/airportstable/AirportsComponent.java create mode 100644 src/main/java/com/benburwell/planes/gui/airportstable/NavigationAidsTableModel.java create mode 100644 src/main/java/com/benburwell/planes/gui/navigationaids/AirportsTableModel.java delete mode 100644 src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java (limited to 'src/main/java') diff --git a/src/main/java/com/benburwell/planes/gui/Main1090.java b/src/main/java/com/benburwell/planes/gui/Main1090.java index b0847bd..e3624ff 100644 --- a/src/main/java/com/benburwell/planes/gui/Main1090.java +++ b/src/main/java/com/benburwell/planes/gui/Main1090.java @@ -5,11 +5,15 @@ package com.benburwell.planes.gui; import com.benburwell.planes.gui.aircrafttable.AircraftTableComponent; +import com.benburwell.planes.gui.airportstable.AirportsComponent; import com.benburwell.planes.gui.navigationaids.NavigationAidComponent; import com.benburwell.planes.sbs.*; import com.benburwell.planes.data.*; import com.benburwell.planes.gui.aircraftmap.*; + +import java.util.List; +import java.util.ArrayList; import java.awt.*; import javax.swing.*; import java.awt.event.ActionEvent; @@ -53,15 +57,12 @@ public class Main1090 extends JFrame { } private void createTabs() { - AircraftMapComponent aircraftMap = new AircraftMapComponent(this.aircraft, this.navaids, this.airports); - this.tabbedPane.addTab("Live Map", aircraftMap.getComponent()); - - AircraftTableComponent aircraftData = new AircraftTableComponent(this.aircraft); - this.tabbedPane.addTab("Aircraft Data", aircraftData.getComponent()); - - NavigationAidComponent navaids = new NavigationAidComponent(this.navaids); - this.tabbedPane.addTab("Navigation Aids", navaids.getComponent()); - + List tabs = new ArrayList<>(); + tabs.add(new AircraftMapComponent(this.aircraft, this.navaids, this.airports)); + tabs.add(new AircraftTableComponent(this.aircraft)); + tabs.add(new NavigationAidComponent(this.navaids)); + tabs.add(new AirportsComponent(this.airports)); + tabs.forEach(tab -> this.tabbedPane.addTab(tab.getName(), tab.getComponent())); this.add(this.tabbedPane); this.tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); } diff --git a/src/main/java/com/benburwell/planes/gui/TCPConnectionOptionDialog.java b/src/main/java/com/benburwell/planes/gui/TCPConnectionOptionDialog.java index 609a70a..a8d7eea 100644 --- a/src/main/java/com/benburwell/planes/gui/TCPConnectionOptionDialog.java +++ b/src/main/java/com/benburwell/planes/gui/TCPConnectionOptionDialog.java @@ -5,7 +5,7 @@ import javax.swing.*; /** * Created by ben on 11/17/16. */ -public class TCPConnectionOptionDialog implements ViewComponent { +public class TCPConnectionOptionDialog { public static final String DEFAULT_HOSTNAME = "10.0.0.111"; public static final int DEFAULT_TCP_PORT = 30003; @@ -14,7 +14,6 @@ public class TCPConnectionOptionDialog implements ViewComponent { private JTextField portField = new JTextField(5); private JLabel descriptionLabel = new JLabel("Add a network data source that provides data in the SBS-1 format"); - @Override public JComponent getComponent() { // set properties hostField.setText(DEFAULT_HOSTNAME); diff --git a/src/main/java/com/benburwell/planes/gui/Tabbable.java b/src/main/java/com/benburwell/planes/gui/Tabbable.java new file mode 100644 index 0000000..e7b5f3f --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/Tabbable.java @@ -0,0 +1,11 @@ +package com.benburwell.planes.gui; + +import javax.swing.*; + +/** + * Created by ben on 11/17/16. + */ +public interface Tabbable { + String getName(); + JComponent getComponent(); +} diff --git a/src/main/java/com/benburwell/planes/gui/ViewComponent.java b/src/main/java/com/benburwell/planes/gui/ViewComponent.java deleted file mode 100644 index 91c21cd..0000000 --- a/src/main/java/com/benburwell/planes/gui/ViewComponent.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.benburwell.planes.gui; - -import javax.swing.*; - -/** - * Created by ben on 11/17/16. - */ -public interface ViewComponent { - JComponent getComponent(); -} diff --git a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java index 64d86e9..09663fe 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMap.java @@ -92,7 +92,7 @@ public class AircraftMap extends JPanel { } /** - * Paint the ViewComponent on a Graphics instance + * Paint the Tabbable on a Graphics instance * * @param g the graphics context to paint on */ 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 b4bb7e2..305df99 100644 --- a/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java +++ b/src/main/java/com/benburwell/planes/gui/aircraftmap/AircraftMapComponent.java @@ -1,7 +1,7 @@ package com.benburwell.planes.gui.aircraftmap; import com.benburwell.planes.data.*; -import com.benburwell.planes.gui.ViewComponent; +import com.benburwell.planes.gui.Tabbable; import com.benburwell.planes.gui.aircraftmap.symbols.PlaneSymbol; import javax.swing.*; @@ -13,7 +13,7 @@ import java.util.ArrayList; /** * Created by ben on 11/18/16. */ -public class AircraftMapComponent implements ViewComponent { +public class AircraftMapComponent implements Tabbable { private AircraftStore store; private CSVObjectStore navaids; private CSVObjectStore airportStore; @@ -112,4 +112,8 @@ public class AircraftMapComponent implements ViewComponent { return this.mapPanel; } + @Override + public String getName() { + return "Map"; + } } diff --git a/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java index 8f1e71d..2bd6586 100644 --- a/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java +++ b/src/main/java/com/benburwell/planes/gui/aircrafttable/AircraftTableComponent.java @@ -1,14 +1,14 @@ package com.benburwell.planes.gui.aircrafttable; import com.benburwell.planes.data.AircraftStore; -import com.benburwell.planes.gui.ViewComponent; +import com.benburwell.planes.gui.Tabbable; import javax.swing.*; /** * Created by ben on 11/17/16. */ -public class AircraftTableComponent implements ViewComponent { +public class AircraftTableComponent implements Tabbable { private JTable table; private AircraftTableModel tableModel; private JScrollPane scrollPane; @@ -24,4 +24,9 @@ public class AircraftTableComponent implements ViewComponent { public JComponent getComponent() { return this.scrollPane; } + + @Override + public String getName() { + return "Aircraft"; + } } diff --git a/src/main/java/com/benburwell/planes/gui/airportstable/AirportsComponent.java b/src/main/java/com/benburwell/planes/gui/airportstable/AirportsComponent.java new file mode 100644 index 0000000..8739de7 --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/airportstable/AirportsComponent.java @@ -0,0 +1,34 @@ +package com.benburwell.planes.gui.airportstable; + +import com.benburwell.planes.data.Airport; +import com.benburwell.planes.data.CSVObjectStore; +import com.benburwell.planes.gui.Tabbable; +import com.benburwell.planes.gui.navigationaids.AirportsTableModel; + +import javax.swing.*; + +/** + * Created by ben on 11/19/16. + */ +public class AirportsComponent implements Tabbable { + private JScrollPane scrollPane = new JScrollPane(); + private JTable table = new JTable(); + private AirportsTableModel tableModel; + + public AirportsComponent(CSVObjectStore airportStore) { + this.tableModel = new AirportsTableModel(airportStore.getObjects()); + this.table = new JTable(this.tableModel); + this.table.setFillsViewportHeight(true); + this.scrollPane = new JScrollPane(table); + } + + @Override + public JComponent getComponent() { + return this.scrollPane; + } + + @Override + public String getName() { + return "Airports"; + } +} diff --git a/src/main/java/com/benburwell/planes/gui/airportstable/NavigationAidsTableModel.java b/src/main/java/com/benburwell/planes/gui/airportstable/NavigationAidsTableModel.java new file mode 100644 index 0000000..3ce098f --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/airportstable/NavigationAidsTableModel.java @@ -0,0 +1,57 @@ +package com.benburwell.planes.gui.airportstable; + +import com.benburwell.planes.data.CSVObjectStore; +import com.benburwell.planes.data.NavigationAid; + +import javax.swing.table.AbstractTableModel; + +/** + * Created by ben on 11/19/16. + */ +public class NavigationAidsTableModel extends AbstractTableModel { + private final String[] COLUMN_NAMES = { "Ident", "Type", "Frequency", "DME Frequency", "DME Channel", "Usage Type", "Power", "Airport" }; + private CSVObjectStore store; + + public NavigationAidsTableModel(CSVObjectStore store) { + this.store = store; + } + + @Override + public int getRowCount() { + return this.store.getObjects().size(); + } + + @Override + public String getColumnName(int col) { + return COLUMN_NAMES[col]; + } + + @Override + public int getColumnCount() { + return this.COLUMN_NAMES.length; + } + + @Override + public Object getValueAt(int rowIndex, int columnIndex) { + NavigationAid aid = this.store.getObjects().get(rowIndex); + switch (columnIndex) { + case 0: + return aid.getIdent(); + case 1: + return aid.getType(); + case 2: + return aid.getFrequency(); + case 3: + return aid.getDmeFrequency(); + case 4: + return aid.getDmeChannel(); + case 5: + return aid.getUsageType(); + case 6: + return aid.getPower(); + case 7: + return aid.getAssociatedAirport(); + } + return null; + } +} diff --git a/src/main/java/com/benburwell/planes/gui/navigationaids/AirportsTableModel.java b/src/main/java/com/benburwell/planes/gui/navigationaids/AirportsTableModel.java new file mode 100644 index 0000000..2850196 --- /dev/null +++ b/src/main/java/com/benburwell/planes/gui/navigationaids/AirportsTableModel.java @@ -0,0 +1,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 airports; + + public AirportsTableModel(List 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; + } +} diff --git a/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java index 1ad7e3e..1238873 100644 --- a/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java +++ b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidComponent.java @@ -2,14 +2,15 @@ package com.benburwell.planes.gui.navigationaids; import com.benburwell.planes.data.CSVObjectStore; import com.benburwell.planes.data.NavigationAid; -import com.benburwell.planes.gui.ViewComponent; +import com.benburwell.planes.gui.Tabbable; +import com.benburwell.planes.gui.airportstable.NavigationAidsTableModel; import javax.swing.*; /** * Created by ben on 11/19/16. */ -public class NavigationAidComponent implements ViewComponent { +public class NavigationAidComponent implements Tabbable { private JTable table; private NavigationAidsTableModel tableModel; private JScrollPane scrollPane; @@ -25,4 +26,9 @@ public class NavigationAidComponent implements ViewComponent { public JComponent getComponent() { return this.scrollPane; } + + @Override + public String getName() { + return "Navigation Aids"; + } } diff --git a/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java b/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java deleted file mode 100644 index 90b05eb..0000000 --- a/src/main/java/com/benburwell/planes/gui/navigationaids/NavigationAidsTableModel.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.benburwell.planes.gui.navigationaids; - -import com.benburwell.planes.data.CSVObjectStore; -import com.benburwell.planes.data.NavigationAid; - -import javax.swing.table.AbstractTableModel; - -/** - * Created by ben on 11/19/16. - */ -public class NavigationAidsTableModel extends AbstractTableModel { - private final String[] COLUMN_NAMES = { "Ident", "Type", "Frequency", "DME Frequency", "DME Channel", "Usage Type", "Power", "Airport" }; - private CSVObjectStore store; - - public NavigationAidsTableModel(CSVObjectStore store) { - this.store = store; - } - - @Override - public int getRowCount() { - return this.store.getObjects().size(); - } - - @Override - public String getColumnName(int col) { - return COLUMN_NAMES[col]; - } - - @Override - public int getColumnCount() { - return this.COLUMN_NAMES.length; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - NavigationAid aid = this.store.getObjects().get(rowIndex); - switch (columnIndex) { - case 0: - return aid.getIdent(); - case 1: - return aid.getType(); - case 2: - return aid.getFrequency(); - case 3: - return aid.getDmeFrequency(); - case 4: - return aid.getDmeChannel(); - case 5: - return aid.getUsageType(); - case 6: - return aid.getPower(); - case 7: - return aid.getAssociatedAirport(); - } - return null; - } -} -- cgit v1.2.3