Ignore:
Timestamp:
2019-09-29T23:01:11+02:00 (5 years ago)
Author:
donvip
Message:

use JOSM HTTP client, fix EDT violation, fix javadoc warnings

Location:
applications/editors/josm/plugins/geochat
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/geochat/.settings/org.eclipse.jdt.core.prefs

    r32699 r35162  
    99org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
    1010org.eclipse.jdt.core.compiler.compliance=1.8
     11org.eclipse.jdt.core.compiler.doc.comment.support=enabled
    1112org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
    1213org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
     
    3233org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
    3334org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
     35org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
     36org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
     37org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
     38org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=disabled
     39org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=protected
    3440org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
    3541org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
     
    3844org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
    3945org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
     46org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
     47org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=disabled
     48org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
     49org.eclipse.jdt.core.compiler.problem.missingJavadocTagDescription=all_standard_tags
     50org.eclipse.jdt.core.compiler.problem.missingJavadocTags=warning
     51org.eclipse.jdt.core.compiler.problem.missingJavadocTagsMethodTypeParameters=disabled
     52org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=disabled
     53org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=protected
    4054org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
    4155org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
  • applications/editors/josm/plugins/geochat/build.xml

    r34512 r35162  
    55    <property name="commit.message" value="[josm_geochat] copypaste from keyboard, font size advanced parameters"/>
    66    <!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
    7     <property name="plugin.main.version" value="14153"/>
     7    <property name="plugin.main.version" value="15389"/>
    88
    99    <property name="plugin.author" value="Ilya Zverev"/>
  • applications/editors/josm/plugins/geochat/src/geochat/ChatMessage.java

    r35161 r35162  
    1111 * @author zverik
    1212 */
    13 public class ChatMessage implements Comparable<ChatMessage> {
     13public final class ChatMessage implements Comparable<ChatMessage> {
    1414    private LatLon pos;
    1515    private Date time;
     
    4646    /**
    4747     * Is only set when the message is not incoming, that is, author is the current user.
     48     * @return recipient
    4849     */
    4950    public String getRecipient() {
  • applications/editors/josm/plugins/geochat/src/geochat/ChatPaneManager.java

    r35161 r35162  
    8080        int idx = tabs.indexOfComponent(entry.component);
    8181        if (idx >= 0)
    82             ((ChatTabTitleComponent) tabs.getTabComponentAt(idx)).updateAlarm();
     82            GuiHelper.runInEDT(() -> ((ChatTabTitleComponent) tabs.getTabComponentAt(idx)).updateAlarm());
    8383    }
    8484
     
    171171     * Returns key in chatPanes hash map for the currently active
    172172     * chat pane, or null in case of an error.
     173     * @return key in chatPanes hash map for the currently active chat pane
    173174     */
    174175    public String getActiveChatPane() {
  • applications/editors/josm/plugins/geochat/src/geochat/ChatServerConnection.java

    r35161 r35162  
    8787     * Test that userId is still active, if not, tries to login with given user name.
    8888     * Does not autologin, if userName is null, obviously.
     89     * @param userName user name
    8990     */
    9091    public void autoLogin(final String userName) {
     
    107108     * Waits until {@link #getPosition()} is not null, then calls {@link #autoLogin(java.lang.String)}.
    108109     * If two seconds have passed, stops the waiting. Doesn't wait if userName is empty.
     110     * @param userName user name
    109111     */
    110112    public void autoLoginWithDelay(final String userName) {
     
    203205     * Unregister the current user and do not call listeners.
    204206     * Makes synchronous request to the server.
     207     * @throws IOException There was a problem connecting to the server or parsing JSON.
    205208     */
    206209    public void bruteLogout() throws IOException {
     
    260263    /**
    261264     * Returns current coordinates or null if there is no map, or zoom is too low.
     265     * @return current coordinates or null
    262266     */
    263267    private static LatLon getPosition() {
     
    360364            JsonObject json;
    361365            try {
    362                 json = JsonQueryUtil.query(query);
     366                json = JsonQueryUtil.query(query, true);
    363367            } catch (IOException ex) {
    364368                json = null; // ?
  • applications/editors/josm/plugins/geochat/src/geochat/JsonQueryUtil.java

    r35160 r35162  
    55import java.io.IOException;
    66import java.io.InputStream;
    7 import java.net.HttpURLConnection;
    8 import java.net.MalformedURLException;
    97import java.net.URL;
    108
     
    1513import org.openstreetmap.josm.gui.MainApplication;
    1614import org.openstreetmap.josm.spi.preferences.Config;
     15import org.openstreetmap.josm.tools.HttpClient;
     16import org.openstreetmap.josm.tools.HttpClient.Response;
    1717import org.openstreetmap.josm.tools.Logging;
    1818
     
    2626    /**
    2727     * Query the server synchronously.
    28      * @param query Query string, starting with action. Example: <tt>get&lat=1.0&lon=-2.0&uid=12345</tt>
     28     * @param query Query string, starting with action. Example: <tt>get&amp;lat=1.0&amp;lon=-2.0&amp;uid=12345</tt>
    2929     * @return Parsed JsonObject if the query was successful, <tt>null</tt> otherwise.
    3030     * @throws IOException There was a problem connecting to the server or parsing JSON.
    3131     */
    3232    public static JsonObject query(String query) throws IOException {
     33        return query(query, false);
     34    }
     35
     36    /**
     37     * Query the server synchronously.
     38     * @param query Query string, starting with action. Example: <tt>get&amp;lat=1.0&amp;lon=-2.0&amp;uid=12345</tt>
     39     * @param logAtDebug {@code true} to set http client connection log at DEBUG level instead of default INFO level
     40     * @return Parsed JsonObject if the query was successful, <tt>null</tt> otherwise.
     41     * @throws IOException There was a problem connecting to the server or parsing JSON.
     42     */
     43    public static JsonObject query(String query, boolean logAtDebug) throws IOException {
     44        String serverURL = Config.getPref().get("geochat.server", "https://zverik.dev.openstreetmap.org/osmochat.php?action=");
     45        URL url = new URL(serverURL + query);
     46        Response connection = HttpClient.create(url).setLogAtDebug(logAtDebug).connect();
     47        if (connection.getResponseCode() != 200) {
     48            throw new IOException("HTTP Response code " + connection.getResponseCode() + " (" + connection.getResponseMessage() + ")");
     49        }
     50        InputStream inp = connection.getContent();
     51        if (inp == null)
     52            throw new IOException("Empty response");
    3353        try {
    34             String serverURL = Config.getPref().get("geochat.server", "https://zverik.dev.openstreetmap.org/osmochat.php?action=");
    35             URL url = new URL(serverURL + query);
    36             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    37             connection.connect();
    38             if (connection.getResponseCode() != 200) {
    39                 throw new IOException("HTTP Response code " + connection.getResponseCode() + " (" + connection.getResponseMessage() + ")");
    40             }
    41             InputStream inp = connection.getInputStream();
    42             if (inp == null)
    43                 throw new IOException("Empty response");
    44             try {
    45                 return Json.createReader(inp).readObject();
    46             } catch (JsonException e) {
    47                 throw new IOException("Failed to parse JSON: " + e.getMessage());
    48             } finally {
    49                 connection.disconnect();
    50             }
    51         } catch (MalformedURLException ex) {
    52             throw new IOException("Malformed URL: " + ex.getMessage());
     54            return Json.createReader(inp).readObject();
     55        } catch (JsonException e) {
     56            throw new IOException("Failed to parse JSON: " + e.getMessage(), e);
     57        } finally {
     58            connection.disconnect();
    5359        }
    5460    }
Note: See TracChangeset for help on using the changeset viewer.