Changeset 36111 in osm for applications/editors/josm
- Timestamp:
- 2023-08-10T13:26:23+02:00 (19 months ago)
- Location:
- applications/editors/josm/plugins/livegps/src/livegps
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGPSPreferences.java
r36107 r36111 8 8 9 9 import javax.swing.Box; 10 import javax.swing.JCheckBox; 10 11 import javax.swing.JLabel; 11 12 import javax.swing.JPanel; … … 24 25 private final JTextField gpsdPort = new JTextField(30); 25 26 private final JTextField serialDevice = new JTextField(30); 27 private final JCheckBox disableGPSD = new JCheckBox(tr("Disable GPSD")); 26 28 27 29 public LiveGPSPreferences() { … … 48 50 panel.add(serialDevice, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 49 51 52 disableGPSD.setSelected(Config.getPref().getBoolean(LiveGpsAcquirer.C_DISABLED)); 53 panel.add(disableGPSD, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5)); 54 50 55 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL)); 51 56 createPreferenceTabWithScrollPane(gui, panel); … … 57 62 Config.getPref().put(LiveGpsAcquirer.C_PORT, gpsdPort.getText()); 58 63 Config.getPref().put(LiveGpsAcquirerNMEA.C_SERIAL, serialDevice.getText()); 64 Config.getPref().putBoolean(LiveGpsAcquirer.C_DISABLED, disableGPSD.isSelected()); 59 65 return false; 60 66 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r36107 r36111 33 33 /* option to use specify gpsd port number */ 34 34 public static final String C_PORT = "livegps.gpsd.port"; 35 /* option to use specify gpsd disabling */ 36 public static final String C_DISABLED = "livegps.gpsd.disabled"; 35 37 private String gpsdHost; 36 38 private int gpsdPort; … … 132 134 while (!shutdownFlag) { 133 135 134 while (!connected) { 136 while (!connected && !shutdownFlag) { 135 137 try { 136 138 connect(); … … 144 146 } 145 147 } 148 if (shutdownFlag) 149 break; 146 150 147 151 assert connected; … … 190 194 191 195 public void shutdown() { 196 Logging.info("LiveGps: Shutdown gpsd"); 192 197 shutdownFlag = true; 193 198 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirerNMEA.java
r36107 r36111 115 115 shutdownFlag = false; 116 116 while (!shutdownFlag) { 117 while (!connected) { 117 while (!connected && !shutdownFlag) { 118 118 try { 119 119 connect(); … … 123 123 Thread.sleep(1000); 124 124 } catch (InterruptedException ignore) { 125 Logging. trace(ignore);125 Logging.info(ignore); 126 126 } 127 127 } … … 137 137 sb.append((char) loopstartChar); 138 138 Instant lasttime = null; 139 while ( true) {139 while (!shutdownFlag) { 140 140 // handle long useless data 141 141 if (sb.length() >= 1020) { … … 144 144 int c = serReader.read(); 145 145 if (c == '$') { 146 Logging.trace("Parsing NMEA: " + sb.toString().replaceAll("[\r\n]","")); 146 147 parser.parseNMEASentence(sb.toString()); 147 148 sb.delete(0, sb.length()); … … 151 152 } else { 152 153 sb.append((char) c); 153 }154 if (!serReader.ready()) {155 try {156 Thread.sleep(50);157 } catch (InterruptedException ignore) {158 Logging.trace(ignore);159 }160 154 } 161 155 if (!serReader.ready()) { … … 175 169 if (w.getString("speed") != null) 176 170 speed = Float.valueOf(w.getString("speed")); 171 Logging.trace("New LiveGPS entry: " + w); 177 172 LiveGpsData gpsData = new LiveGpsData(w.lat(), w.lon(), course, speed, 0.0f, 0.0f); 178 173 gpsData.setWaypoint(w); … … 183 178 if (last != null) { 184 179 lasttime = last.getInstant(); 180 } 181 if (!serReader.ready()) { 182 try { 183 Thread.sleep(50); 184 } catch (InterruptedException ignore) { 185 Logging.info(ignore); 186 } 185 187 } 186 188 } … … 195 197 Thread.sleep(1000); 196 198 } catch (InterruptedException ignore) { 197 Logging. trace(ignore);199 Logging.info(ignore); 198 200 } 199 201 } catch (IllegalDataException ex) { … … 209 211 210 212 public void shutdown() { 213 Logging.info("LiveGps: Shutdown NMEA"); 211 214 shutdownFlag = true; 212 215 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDialog.java
r36107 r36111 27 27 public class LiveGpsDialog extends ToggleDialog implements PropertyChangeListener { 28 28 private static final long serialVersionUID = 6183400754671501117L; 29 private boolean statusGPSD; 30 private boolean statusNMEA; 31 private JLabel statusText; 29 32 private JLabel statusLabel; 33 private JLabel nmeaStatusText; 30 34 private JLabel nmeaStatusLabel; 31 35 private JLabel wayLabel; … … 45 49 panel = new JPanel(); 46 50 panel.setLayout(new GridLayout(7, 2)); 47 panel.add(new JLabel(tr("Status gpsd"))); 51 panel.add(statusText = new JLabel(tr("Status gpsd"))); 48 52 panel.add(statusLabel = new JLabel()); 49 if (!Config.getPref().get(LiveGpsAcquirerNMEA.C_SERIAL).isEmpty()) { 50 panel.add(new JLabel(tr("Status NMEA"))); 51 panel.add(nmeaStatusLabel = new JLabel()); 52 } 53 panel.add(nmeaStatusText = new JLabel(tr("Status NMEA"))); 54 panel.add(nmeaStatusLabel = new JLabel()); 53 55 panel.add(new JLabel(tr("Way Info"))); 54 56 panel.add(wayLabel = new JLabel()); … … 61 63 panel.add(new JLabel(tr("Course"))); 62 64 panel.add(courseLabel = new JLabel()); 65 setStatusVisibility(true); 63 66 createLayout(panel, true, null); 67 } 68 69 /** 70 * Set the visibility of the status fields 71 * @param init initialize the values (don't check previous state) 72 */ 73 private void setStatusVisibility(boolean init) { 74 boolean statusGPSDNew = !Config.getPref().getBoolean(LiveGpsAcquirer.C_DISABLED); 75 if (init || statusGPSD != statusGPSDNew) { 76 statusText.setVisible(statusGPSDNew); 77 statusLabel.setVisible(statusGPSDNew); 78 statusGPSD = statusGPSDNew; 79 } 80 boolean statusNMEANew = !Config.getPref().get(LiveGpsAcquirerNMEA.C_SERIAL).isEmpty(); 81 if (init || statusNMEA != statusNMEANew) { 82 nmeaStatusText.setVisible(statusNMEANew); 83 nmeaStatusLabel.setVisible(statusNMEANew); 84 statusNMEA = statusNMEANew; 85 } 64 86 } 65 87 … … 102 124 status = (LiveGpsStatus) evt.getNewValue(); 103 125 126 setStatusVisibility(false); 127 104 128 SwingUtilities.invokeLater(new Runnable() { 105 129 @Override … … 117 141 nmeaStatus = (LiveGpsStatus) evt.getNewValue(); 118 142 143 setStatusVisibility(false); 144 119 145 SwingUtilities.invokeLater(new Runnable() { 120 146 @Override -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r36107 r36111 42 42 WayPoint lastPoint; 43 43 private final AppendableGpxTrackSegment trackSegment; 44 private final GpxData gpxData; 44 45 boolean autocenter; 45 46 private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); … … 54 55 IGpxTrack trackBeingWritten = new SingleSegmentGpxTrack(trackSegment, attr); 55 56 data.tracks.add(trackBeingWritten); 57 gpxData = data; 56 58 57 59 initIntervals(); … … 78 80 } 79 81 trackSegment.addWaypoint(lastPoint); 82 gpxData.invalidate(); 80 83 81 84 if (autocenter) -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
r36107 r36111 169 169 170 170 if (enable && !enabled) { 171 assert (acquirer == null);172 assert (acquirerThread == null);173 174 acquirer = new LiveGpsAcquirer();175 acquirerThread = new Thread(acquirer);176 177 171 if (lgpslayer == null) { 178 172 lgpslayer = new LiveGpsLayer(data); … … 182 176 } 183 177 184 acquirer.addPropertyChangeListener(lgpslayer); 185 acquirer.addPropertyChangeListener(lgpsdialog); 186 for (PropertyChangeListener listener : listenerQueue) { 187 acquirer.addPropertyChangeListener(listener); 188 } 189 190 acquirerThread.start(); 178 assert (acquirer == null); 179 assert (acquirerThread == null); 180 181 if (!Config.getPref().getBoolean(LiveGpsAcquirer.C_DISABLED)) { 182 183 acquirer = new LiveGpsAcquirer(); 184 acquirerThread = new Thread(acquirer); 185 186 acquirer.addPropertyChangeListener(lgpslayer); 187 acquirer.addPropertyChangeListener(lgpsdialog); 188 for (PropertyChangeListener listener : listenerQueue) { 189 acquirer.addPropertyChangeListener(listener); 190 } 191 192 acquirerThread.start(); 193 } 191 194 192 195 assert (acquirerNMEA == null); … … 212 215 assert (acquirerThread != null); 213 216 214 acquirer.shutdown(); 215 acquirer = null; 216 acquirerThread = null; 217 if (acquirerThread != null) { 218 acquirer.shutdown(); 219 acquirer = null; 220 acquirerThread = null; 221 } 217 222 218 223 if (acquirerNMEAThread != null) {
Note:
See TracChangeset
for help on using the changeset viewer.