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

Last change on this file since 20431 was 16933, checked in by stoecker, 15 years ago

minor cleanup, removed config file

  • Property svn:eol-style set to native
File size: 3.7 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.event.KeyEvent;
12import java.beans.PropertyChangeEvent;
13import java.beans.PropertyChangeListener;
14
15import javax.swing.JLabel;
16import javax.swing.JPanel;
17import javax.swing.JScrollPane;
18
19import org.openstreetmap.josm.gui.MapFrame;
20import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
21import org.openstreetmap.josm.tools.Shortcut;
22
23/**
24 * @author cdaller
25 *
26 */
27public class LiveGpsDialog extends ToggleDialog implements PropertyChangeListener {
28 private static final long serialVersionUID = 6183400754671501117L;
29 private JLabel statusLabel;
30 private JLabel wayLabel;
31 private JLabel latLabel;
32 private JLabel longLabel;
33 private JLabel courseLabel;
34 private JLabel speedLabel;
35 private JPanel panel;
36
37 /**
38 * @param name
39 * @param iconName
40 * @param tooltip
41 * @param shortcut
42 * @param preferredHeight
43 */
44 public LiveGpsDialog(final MapFrame mapFrame) {
45 super(tr("Live GPS"), "livegps", tr("Show GPS data."),
46 Shortcut.registerShortcut("subwindow:livegps", tr("Toggle: {0}", tr("Live GPS")),
47 KeyEvent.VK_G, Shortcut.GROUP_LAYER, Shortcut.SHIFT_DEFAULT), 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 double mySpeed = data.getSpeed() * 3.6f;
79 speedLabel.setText((Math.round(mySpeed*100)/100) + "km/h"); // m(s to km/h
80 courseLabel.setText(data.getCourse() + "deg");
81
82 String wayString = data.getWayInfo();
83 if(wayString.length() > 0) {
84 wayLabel.setText(wayString);
85 } else {
86 wayLabel.setText(tr("unknown"));
87 }
88
89 } else {
90// fixLabel.setText("no fix");
91 latLabel.setText("");
92 longLabel.setText("");
93 speedLabel.setText("");
94 courseLabel.setText("");
95 panel.setBackground(Color.RED);
96 }
97 } else if ("gpsstatus".equals(evt.getPropertyName())) {
98 LiveGpsStatus status = (LiveGpsStatus) evt.getNewValue();
99 statusLabel.setText(status.getStatusMessage());
100 if(status.getStatus() != LiveGpsStatus.GpsStatus.CONNECTED) {
101 panel.setBackground(Color.RED);
102 } else {
103 panel.setBackground(Color.WHITE);
104 }
105 }
106
107 }
108}
Note: See TracBrowser for help on using the repository browser.