Index: applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
===================================================================
--- applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java	(revision 30197)
+++ applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java	(revision 30234)
@@ -2,5 +2,4 @@
 
 import static org.openstreetmap.josm.tools.I18n.tr;
-
 
 import java.beans.PropertyChangeEvent;
@@ -9,4 +8,5 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.StringReader;
 import java.net.InetAddress;
 import java.net.Socket;
@@ -14,8 +14,10 @@
 import java.util.List;
 
+import javax.json.Json;
+import javax.json.JsonException;
+import javax.json.JsonNumber;
+import javax.json.JsonObject;
+
 import org.openstreetmap.josm.Main;
-
-import org.json.JSONObject;
-import org.json.JSONException;
 
 public class LiveGpsAcquirer implements Runnable {
@@ -41,5 +43,4 @@
      */
     public LiveGpsAcquirer() {
-        super();
 
         gpsdHost = Main.pref.get(C_HOST, DEFAULT_HOST);
@@ -77,6 +78,5 @@
      * @param statusMessage the status message.
      */
-    public void fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus status,
-            String statusMessage) {
+    public void fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus status, String statusMessage) {
         PropertyChangeEvent event = new PropertyChangeEvent(this, "gpsstatus",
                 null, new LiveGpsStatus(status, statusMessage));
@@ -97,6 +97,5 @@
      */
     public void fireGpsDataChangeEvent(LiveGpsData oldData, LiveGpsData newData) {
-        PropertyChangeEvent event = new PropertyChangeEvent(this, "gpsdata",
-                oldData, newData);
+        PropertyChangeEvent event = new PropertyChangeEvent(this, "gpsdata", oldData, newData);
 
         if (!event.equals(lastDataEvent)) {
@@ -124,44 +123,46 @@
         while (!shutdownFlag) {
 
-	    while (!connected) {
-		try {
+            while (!connected) {
+                try {
                     connect();
-		} catch (IOException iox) {
-		    fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed"));
-                    try {
-                        Thread.sleep(1000);
-                    } catch (InterruptedException ignore) {}
-		}
-	    }
-
-	    assert (connected);
-
-	    try {
-                    String line;
-
-                    // <FIXXME date="23.06.2007" author="cdaller">
-                    // TODO this read is blocking if gps is connected but has no
-                    // fix, so gpsd does not send positions
-                    line = gpsdReader.readLine();
-                    // </FIXXME>
-                    if (line == null)
-                        throw new IOException();
-
-                    if (JSONProtocol == true)
-                        gpsData = ParseJSON(line);
-                    else
-                        gpsData = ParseOld(line);
-
-                    if (gpsData == null)
-                        continue;
-
-                    fireGpsDataChangeEvent(oldGpsData, gpsData);
-                    oldGpsData = gpsData;
+                } catch (IOException iox) {
+                    fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed"));
+	                try {
+	                    Thread.sleep(1000);
+	                } catch (InterruptedException ignore) {
+	                	
+	                }
+	            }
+            }
+
+            assert (connected);
+
+            try {
+                String line;
+
+                // <FIXXME date="23.06.2007" author="cdaller">
+                // TODO this read is blocking if gps is connected but has no
+                // fix, so gpsd does not send positions
+                line = gpsdReader.readLine();
+                // </FIXXME>
+                if (line == null)
+                    throw new IOException();
+
+                if (JSONProtocol == true)
+                    gpsData = ParseJSON(line);
+                else
+                    gpsData = ParseOld(line);
+
+                if (gpsData == null)
+                    continue;
+
+                fireGpsDataChangeEvent(oldGpsData, gpsData);
+                oldGpsData = gpsData;
             } catch (IOException iox) {
-                System.out.println("LiveGps: lost connection to gpsd");
+                Main.warn("LiveGps: lost connection to gpsd");
                 fireGpsStatusChangeEvent(
                         LiveGpsStatus.GpsStatus.CONNECTION_FAILED,
                         tr("Connection Failed"));
-		disconnect();
+                disconnect();
                 try {
                     Thread.sleep(1000);
@@ -171,8 +172,8 @@
         }
 
-	System.out.println("LiveGps: Disconnected from gpsd");
+        Main.info("LiveGps: Disconnected from gpsd");
         fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.DISCONNECTED,
                 tr("Not connected"));
-	disconnect();
+        disconnect();
     }
 
@@ -182,8 +183,8 @@
 
     private void connect() throws IOException {
-        JSONObject greeting;
+        JsonObject greeting;
         String line, type, release;
 
-        System.out.println("LiveGps: trying to connect to gpsd at " + gpsdHost + ":" + gpsdPort);
+        Main.info("LiveGps: trying to connect to gpsd at " + gpsdHost + ":" + gpsdPort);
         fireGpsStatusChangeEvent( LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting"));
 
@@ -194,5 +195,5 @@
                 break;
             } catch (IOException e) {
-                System.out.println("LiveGps: Could not open connection to gpsd: " + e);
+            	Main.warn("LiveGps: Could not open connection to gpsd: " + e);
                 gpsdSocket = null;
             }
@@ -213,16 +214,16 @@
 
         try {
-            greeting = new JSONObject(line);
+            greeting = Json.createReader(new StringReader(line)).readObject();
             type = greeting.getString("class");
             if (type.equals("VERSION")) {
                 release = greeting.getString("release");
-                System.out.println("LiveGps: Connected to gpsd " + release);
+                Main.info("LiveGps: Connected to gpsd " + release);
             } else
-                System.out.println("LiveGps: Unexpected JSON in gpsd greeting: " + line);
-        } catch (JSONException jex) {
+            	Main.info("LiveGps: Unexpected JSON in gpsd greeting: " + line);
+        } catch (JsonException jex) {
             if (line.startsWith("GPSD,")) {
                 connected = true;
                 JSONProtocol = false;
-                System.out.println("LiveGps: Connected to old gpsd protocol version.");
+                Main.info("LiveGps: Connected to old gpsd protocol version.");
                 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTED, tr("Connected"));
             }
@@ -230,9 +231,8 @@
 
         if (JSONProtocol == true) {
-            JSONObject Watch = new JSONObject();
-            try {
-                Watch.put("enable", true);
-                Watch.put("json", true);
-            } catch (JSONException je) {}
+        	JsonObject Watch = Json.createObjectBuilder()
+        			.add("enable", true)
+        			.add("json", true)
+        			.build();
 
             String Request = "?WATCH=" + Watch.toString() + ";\n";
@@ -245,18 +245,18 @@
 
     private void disconnect() {
-	assert(gpsdSocket != null);
-
-	connected = false;
+        assert(gpsdSocket != null);
+
+        connected = false;
 
         try {
-		gpsdSocket.close();
-		gpsdSocket = null;
-	} catch (Exception e) {
-		System.out.println("LiveGps: Unable to close socket; reconnection may not be possible");
-	}
+            gpsdSocket.close();
+            gpsdSocket = null;
+        } catch (Exception e) {
+        	Main.warn("LiveGps: Unable to close socket; reconnection may not be possible");
+        }
     }
 
     private LiveGpsData ParseJSON(String line) {
-        JSONObject report;
+        JsonObject report;
         String type;
         double lat = 0;
@@ -268,8 +268,8 @@
 
         try {
-            report = new JSONObject(line);
+            report = Json.createReader(new StringReader(line)).readObject();
             type = report.getString("class");
-        } catch (JSONException jex) {
-            System.out.println("LiveGps: line read from gpsd is not a JSON object:" + line);
+        } catch (JsonException jex) {
+        	Main.warn("LiveGps: line read from gpsd is not a JSON object:" + line);
             return null;
         }
@@ -278,15 +278,19 @@
 
         try {
-            lat = report.getDouble("lat");
-            lon = report.getDouble("lon");
-            speed = (new Float(report.getDouble("speed"))).floatValue();
-            course = (new Float(report.getDouble("track"))).floatValue();
-	    if (report.has("epx"))
-		epx = (new Float(report.getDouble("epx"))).floatValue();
-	    if (report.has("epy"))
-		epy = (new Float(report.getDouble("epy"))).floatValue();
+            lat = report.getJsonNumber("lat").doubleValue();
+            lon = report.getJsonNumber("lon").doubleValue();
+            speed = (new Float(report.getJsonNumber("speed").doubleValue())).floatValue();
+            course = (new Float(report.getJsonNumber("track").doubleValue())).floatValue();
+            JsonNumber epxJson = report.getJsonNumber("epx");
+            if (epxJson != null)
+                epx = (new Float(epxJson.doubleValue())).floatValue();
+            JsonNumber epyJson = report.getJsonNumber("epy");
+            if (epyJson != null)
+                epy = (new Float(epyJson.doubleValue())).floatValue();
 
             return new LiveGpsData(lat, lon, course, speed, epx, epy);
-        } catch (JSONException je) {}
+        } catch (JsonException je) {
+        	Main.debug(je.getMessage());
+        }
 
         return null;
