Changeset 36122 in osm for applications/editors/josm/plugins/geochat/src
- Timestamp:
- 2023-08-22T17:40:36+02:00 (23 months ago)
- Location:
- applications/editors/josm/plugins/geochat/src/geochat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java
r35978 r36122 15 15 import java.util.Set; 16 16 17 import ja vax.json.JsonArray;18 import ja vax.json.JsonException;19 import ja vax.json.JsonObject;17 import jakarta.json.JsonArray; 18 import jakarta.json.JsonException; 19 import jakarta.json.JsonObject; 20 20 21 21 import org.openstreetmap.josm.data.coor.ILatLon; … … 41 41 private String userName; 42 42 private static ChatServerConnection instance; 43 private Set<ChatServerConnectionListener> listeners; 44 private LogRequest requestThread; 43 private final Set<ChatServerConnectionListener> listeners; 44 private final LogRequest requestThread; 45 45 46 46 private ChatServerConnection() { … … 123 123 } 124 124 } catch (InterruptedException e) { 125 Thread.currentThread().interrupt(); 125 126 Logging.warn(e); 126 127 } … … 279 280 double l = lat / 180 * Math.PI; 280 281 double pf = Math.log(Math.tan(l) + (1 / Math.cos(l))); 281 return Math.pow(2.0, zoom - 1) * (Math.PI - pf) / Math.PI; 282 return Math.pow(2.0, zoom - 1d) * (Math.PI - pf) / Math.PI; 282 283 } 283 284 284 285 private static double lonToTileX(double lon, int zoom) { 285 return Math.pow(2.0, zoom - 3) * (lon + 180.0) / 45.0; 286 return Math.pow(2.0, zoom - 3d) * (lon + 180.0) / 45.0; 286 287 } 287 288 … … 305 306 double factor = screenPixels / tilePixels; 306 307 double result = Math.log(factor) / Math.log(2) / 2 + 1; 307 int intResult = (int) Math.floor(result); 308 return intResult; 308 return (int) Math.floor(result); 309 309 } 310 310 311 311 private class LogRequest implements Runnable { 312 312 private static final int MAX_JUMP = 20000; // in meters 313 private LatLon lastPosition = null;314 private long lastUserId = 0;315 private long lastId = 0;316 private boolean lastStatus = false;317 private boolean stopping = false;313 private LatLon lastPosition; 314 private long lastUserId; 315 private long lastId; 316 private boolean lastStatus; 317 private boolean stopping; 318 318 319 319 @Override … … 324 324 process(); 325 325 try { 326 Thread.sleep(interval * 1000); 326 Thread.sleep(interval * 1000L); 327 327 } catch (InterruptedException e) { 328 Thread.currentThread().interrupt(); 328 329 stopping = true; 330 Logging.trace(e); 329 331 } 330 332 } … … 367 369 json = JsonQueryUtil.query(query, true); 368 370 } catch (IOException ex) { 371 Logging.trace(ex); 369 372 json = null; // ? 370 373 } -
applications/editors/josm/plugins/geochat/src/geochat/JsonQueryCallback.java
r35161 r36122 2 2 package geochat; 3 3 4 import ja vax.json.JsonObject;4 import jakarta.json.JsonObject; 5 5 6 6 /** -
applications/editors/josm/plugins/geochat/src/geochat/JsonQueryUtil.java
r35162 r36122 5 5 import java.io.IOException; 6 6 import java.io.InputStream; 7 import java.net.UR L;7 import java.net.URI; 8 8 9 import javax.json.Json; 10 import javax.json.JsonException; 11 import javax.json.JsonObject; 9 import jakarta.json.Json; 10 import jakarta.json.JsonException; 11 import jakarta.json.JsonObject; 12 import jakarta.json.JsonReader; 12 13 13 14 import org.openstreetmap.josm.gui.MainApplication; … … 43 44 public static JsonObject query(String query, boolean logAtDebug) throws IOException { 44 45 String serverURL = Config.getPref().get("geochat.server", "https://zverik.dev.openstreetmap.org/osmochat.php?action="); 45 UR Lurl =new URL(serverURL + query);46 Response connection = HttpClient.create(url).setLogAtDebug(logAtDebug).connect(); 46 URI url = URI.create(serverURL + query); 47 Response connection = HttpClient.create(url.toURL()).setLogAtDebug(logAtDebug).connect(); 47 48 if (connection.getResponseCode() != 200) { 48 49 throw new IOException("HTTP Response code " + connection.getResponseCode() + " (" + connection.getResponseMessage() + ")"); … … 51 52 if (inp == null) 52 53 throw new IOException("Empty response"); 53 try { 54 return Json.createReader(inp).readObject();54 try (JsonReader reader = Json.createReader(inp)){ 55 return reader.readObject(); 55 56 } catch (JsonException e) { 56 57 throw new IOException("Failed to parse JSON: " + e.getMessage(), e);
Note:
See TracChangeset
for help on using the changeset viewer.