| 1 | /**
|
|---|
| 2 | *
|
|---|
| 3 | */
|
|---|
| 4 | package livegps;
|
|---|
| 5 |
|
|---|
| 6 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 7 |
|
|---|
| 8 | import java.awt.BorderLayout;
|
|---|
| 9 | import java.awt.Color;
|
|---|
| 10 | import java.awt.GridLayout;
|
|---|
| 11 | import java.awt.Point;
|
|---|
| 12 | import java.awt.event.KeyEvent;
|
|---|
| 13 | import java.beans.PropertyChangeEvent;
|
|---|
| 14 | import java.beans.PropertyChangeListener;
|
|---|
| 15 |
|
|---|
| 16 | import javax.swing.JLabel;
|
|---|
| 17 | import javax.swing.JPanel;
|
|---|
| 18 | import javax.swing.JScrollPane;
|
|---|
| 19 |
|
|---|
| 20 | import org.openstreetmap.josm.Main;
|
|---|
| 21 | import org.openstreetmap.josm.data.coor.EastNorth;
|
|---|
| 22 | import org.openstreetmap.josm.data.osm.Way;
|
|---|
| 23 | import org.openstreetmap.josm.gui.MapFrame;
|
|---|
| 24 | import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
|
|---|
| 25 |
|
|---|
| 26 | /**
|
|---|
| 27 | * @author cdaller
|
|---|
| 28 | *
|
|---|
| 29 | */
|
|---|
| 30 | public class LiveGpsDialog extends ToggleDialog implements PropertyChangeListener {
|
|---|
| 31 | private JLabel statusLabel;
|
|---|
| 32 | private JLabel wayLabel;
|
|---|
| 33 | private JLabel latLabel;
|
|---|
| 34 | private JLabel longLabel;
|
|---|
| 35 | private JLabel courseLabel;
|
|---|
| 36 | private JLabel speedLabel;
|
|---|
| 37 | private JPanel panel;
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * @param name
|
|---|
| 41 | * @param iconName
|
|---|
| 42 | * @param tooltip
|
|---|
| 43 | * @param shortCut
|
|---|
| 44 | * @param preferredHeight
|
|---|
| 45 | */
|
|---|
| 46 | public LiveGpsDialog(final MapFrame mapFrame) {
|
|---|
| 47 | super(tr("Live GPS"), "livegps", tr("Show GPS data."), KeyEvent.VK_G, 100);
|
|---|
| 48 | panel = new JPanel();
|
|---|
| 49 | panel.setLayout(new GridLayout(6,2));
|
|---|
| 50 | panel.add(new JLabel(tr("Status")));
|
|---|
| 51 | panel.add(statusLabel = new JLabel());
|
|---|
| 52 | panel.add(new JLabel(tr("Way Info")));
|
|---|
| 53 | panel.add(wayLabel = new JLabel());
|
|---|
| 54 | panel.add(new JLabel(tr("Latitude")));
|
|---|
| 55 | panel.add(latLabel = new JLabel());
|
|---|
| 56 | panel.add(new JLabel(tr("Longitude")));
|
|---|
| 57 | panel.add(longLabel = new JLabel());
|
|---|
| 58 | panel.add(new JLabel(tr("Speed")));
|
|---|
| 59 | panel.add(speedLabel = new JLabel());
|
|---|
| 60 | panel.add(new JLabel(tr("Course")));
|
|---|
| 61 | panel.add(courseLabel = new JLabel());
|
|---|
| 62 | add(new JScrollPane(panel), BorderLayout.CENTER);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | /* (non-Javadoc)
|
|---|
| 66 | * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
|---|
| 67 | */
|
|---|
| 68 | public void propertyChange(PropertyChangeEvent evt) {
|
|---|
| 69 | if (!isVisible())
|
|---|
| 70 | return;
|
|---|
| 71 | if("gpsdata".equals(evt.getPropertyName())) {
|
|---|
| 72 | LiveGpsData data = (LiveGpsData) evt.getNewValue();
|
|---|
| 73 | if(data.isFix()) {
|
|---|
| 74 | // fixLabel.setText("fix");
|
|---|
| 75 | panel.setBackground(Color.WHITE);
|
|---|
| 76 | latLabel.setText(data.getLatitude() + "deg");
|
|---|
| 77 | longLabel.setText(data.getLongitude() + "deg");
|
|---|
| 78 | speedLabel.setText((data.getSpeed() * 3.6f) + "km/h"); // m(s to km/h
|
|---|
| 79 | courseLabel.setText(data.getCourse() + "deg");
|
|---|
| 80 |
|
|---|
| 81 | EastNorth eastnorth = Main.proj.latlon2eastNorth(data.getLatLon());
|
|---|
| 82 | Point xy = Main.map.mapView.getPoint(eastnorth);
|
|---|
| 83 | Way way = Main.map.mapView.getNearestWay(xy);
|
|---|
| 84 | if(way != null) {
|
|---|
| 85 | String label = way.get("name") + " (" + way.get("highway") + ")";
|
|---|
| 86 | wayLabel.setText(label);
|
|---|
| 87 | } else {
|
|---|
| 88 | wayLabel.setText("unknown");
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | } else {
|
|---|
| 92 | // fixLabel.setText("no fix");
|
|---|
| 93 | latLabel.setText("");
|
|---|
| 94 | longLabel.setText("");
|
|---|
| 95 | speedLabel.setText("");
|
|---|
| 96 | courseLabel.setText("");
|
|---|
| 97 | panel.setBackground(Color.RED);
|
|---|
| 98 | }
|
|---|
| 99 | } else if ("gpsstatus".equals(evt.getPropertyName())) {
|
|---|
| 100 | LiveGpsStatus status = (LiveGpsStatus) evt.getNewValue();
|
|---|
| 101 | statusLabel.setText(status.getStatusMessage());
|
|---|
| 102 | if(status.getStatus() != LiveGpsStatus.GpsStatus.CONNECTED) {
|
|---|
| 103 | panel.setBackground(Color.RED);
|
|---|
| 104 | } else {
|
|---|
| 105 | panel.setBackground(Color.WHITE);
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 | }
|
|---|