source: osm/applications/editors/josm/plugins/surveyor/src/livegps/LiveGpsDialog.java@ 2974

Last change on this file since 2974 was 2974, checked in by christofd, 19 years ago

removed unused imports, added serial ids for all classes that needed it, etc. so only a couple of warnings remain

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