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

Last change on this file since 2936 was 2936, checked in by christofd, 18 years ago

Initial import.

File size: 3.8 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 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}
Note: See TracBrowser for help on using the repository browser.