diff options
| author | Ben Burwell <ben.burwell@trifecta.com> | 2016-11-19 00:32:22 -0500 | 
|---|---|---|
| committer | Ben Burwell <ben.burwell@trifecta.com> | 2016-11-19 00:32:22 -0500 | 
| commit | 963f5dabe12e78a1464d5374779b71825c3cf470 (patch) | |
| tree | 3e291e32737042d36c6aa8ffa2fe20cdd0224117 /src | |
| parent | 44ac0ca64197a9e21ed78e128ef816a6c85e05fe (diff) | |
Implement basic focusing of planes
Diffstat (limited to 'src')
| -rw-r--r-- | src/com/benburwell/planes/gui/AircraftMapComponent.java | 32 | 
1 files changed, 32 insertions, 0 deletions
| diff --git a/src/com/benburwell/planes/gui/AircraftMapComponent.java b/src/com/benburwell/planes/gui/AircraftMapComponent.java index 780f1db..268b524 100644 --- a/src/com/benburwell/planes/gui/AircraftMapComponent.java +++ b/src/com/benburwell/planes/gui/AircraftMapComponent.java @@ -2,12 +2,14 @@ package com.benburwell.planes.gui;  import com.benburwell.planes.data.AircraftStore;  import com.benburwell.planes.data.AircraftStoreListener; +import com.benburwell.planes.data.Position;  import javax.swing.*;  import java.awt.*;  import java.awt.event.KeyEvent;  import java.util.List;  import java.util.ArrayList; +import java.util.Collections;  /**   * Created by ben on 11/18/16. @@ -15,6 +17,7 @@ import java.util.ArrayList;  public class AircraftMapComponent implements ViewComponent {      private AircraftStore store;      private AircraftMap mapPanel; +    private String focusedAircraftIdentifier = null;      public AircraftMapComponent(AircraftStore store) {          this.store = store; @@ -23,6 +26,23 @@ public class AircraftMapComponent implements ViewComponent {          this.subscribeToChanges();      } +    public void focusNextAircraft() { +        List<String> aircraftIdentifiers = new ArrayList<>(this.store.getAircraft().keySet()); +        Collections.sort(aircraftIdentifiers); +        if (this.focusedAircraftIdentifier == null && aircraftIdentifiers.size() > 0) { +            this.focusedAircraftIdentifier = aircraftIdentifiers.get(0); +        } else { +            int idx = aircraftIdentifiers.indexOf(this.focusedAircraftIdentifier); +            if (idx > 0 && idx < aircraftIdentifiers.size() - 1) { +                this.focusedAircraftIdentifier = aircraftIdentifiers.get(idx++); +            } else if (aircraftIdentifiers.size() > 0) { +                this.focusedAircraftIdentifier = aircraftIdentifiers.get(0); +            } else { +                this.focusedAircraftIdentifier = null; +            } +        } +    } +      private void setupMap() {          this.mapPanel = new AircraftMap();          this.mapPanel.setCenter(40.6188942, -75.4947205); @@ -42,11 +62,23 @@ public class AircraftMapComponent implements ViewComponent {                  this.mapPanel.moveSouth();              } else if (e.getKeyCode() == KeyEvent.VK_K && e.getID() == KeyEvent.KEY_PRESSED) {                  this.mapPanel.moveNorth(); +            } else if (e.getKeyCode() == KeyEvent.VK_0 && e.getID() == KeyEvent.KEY_PRESSED) { +                this.mapPanel.setCenter(40.6188942, -75.4947205); +            } else if (e.getKeyCode() == KeyEvent.VK_TAB && e.getID() == KeyEvent.KEY_PRESSED) { +                this.focusNextAircraft(); +                this.centerMapOnPlane(this.focusedAircraftIdentifier);              }              return false;          });      } +    private void centerMapOnPlane(String identifier) { +        if (identifier != null) { +            Position pos = this.store.getAircraft().get(identifier).getCurrentPosition(); +            this.mapPanel.setCenter(pos.getLatitude(), pos.getLongitude()); +        } +    } +      private void subscribeToChanges() {          this.store.subscribe(new AircraftStoreListener() {              @Override | 
