Changeset 12805 in josm for trunk


Ignore:
Timestamp:
2017-09-09T17:12:43+02:00 (2 years ago)
Author:
Don-vip
Message:

see #15229 - see #15182 - remove GUI references from DefaultProxySelector

Location:
trunk/src/org/openstreetmap/josm
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/CredentialDialog.java

    r12678 r12805  
    3232import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
    3333import org.openstreetmap.josm.gui.help.HelpUtil;
    34 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
    3534import org.openstreetmap.josm.gui.util.WindowGeometry;
    3635import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    3736import org.openstreetmap.josm.gui.widgets.JosmPasswordField;
    3837import org.openstreetmap.josm.gui.widgets.JosmTextField;
     38import org.openstreetmap.josm.io.DefaultProxySelector;
    3939import org.openstreetmap.josm.io.OsmApi;
    4040import org.openstreetmap.josm.tools.ImageProvider;
     
    323323            lblHeading.setText(
    324324                    "<html>" + tr("Authenticating at the HTTP proxy ''{0}'' failed. Please enter a valid username and a valid password.",
    325                             Main.pref.get(ProxyPreferencesPanel.PROXY_HTTP_HOST) + ':' +
    326                             Main.pref.get(ProxyPreferencesPanel.PROXY_HTTP_PORT)) + "</html>");
     325                            Main.pref.get(DefaultProxySelector.PROXY_HTTP_HOST) + ':' +
     326                            Main.pref.get(DefaultProxySelector.PROXY_HTTP_PORT)) + "</html>");
    327327            lblWarning.setText("<html>" +
    328328                    tr("Warning: depending on the authentication method the proxy server uses the password may be transferred unencrypted.")
  • trunk/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java

    r12620 r12805  
    1616import java.net.ProxySelector;
    1717import java.util.EnumMap;
    18 import java.util.Locale;
    1918import java.util.Map;
    2019import java.util.Optional;
     
    3332import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel;
    3433import org.openstreetmap.josm.io.DefaultProxySelector;
     34import org.openstreetmap.josm.io.ProxyPolicy;
    3535import org.openstreetmap.josm.io.auth.CredentialsAgent;
    3636import org.openstreetmap.josm.io.auth.CredentialsAgentException;
     
    5454        }
    5555    }
    56 
    57     /**
    58      * The proxy policy is how JOSM will use proxy information.
    59      */
    60     public enum ProxyPolicy {
    61         /** No proxy: JOSM will access Internet resources directly */
    62         NO_PROXY("no-proxy"),
    63         /** Use system settings: JOSM will use system proxy settings */
    64         USE_SYSTEM_SETTINGS("use-system-settings"),
    65         /** Use HTTP proxy: JOSM will use the given HTTP proxy, configured manually */
    66         USE_HTTP_PROXY("use-http-proxy"),
    67         /** Use HTTP proxy: JOSM will use the given SOCKS proxy */
    68         USE_SOCKS_PROXY("use-socks-proxy");
    69 
    70         private final String policyName;
    71 
    72         ProxyPolicy(String policyName) {
    73             this.policyName = policyName;
    74         }
    75 
    76         /**
    77          * Replies the policy name, to be stored in proxy preferences.
    78          * @return the policy unique name
    79          */
    80         public String getName() {
    81             return policyName;
    82         }
    83 
    84         /**
    85          * Retrieves a proxy policy from its name found in preferences.
    86          * @param policyName The policy name
    87          * @return The proxy policy matching the given name, or {@code null}
    88          */
    89         public static ProxyPolicy fromName(String policyName) {
    90             if (policyName == null) return null;
    91             policyName = policyName.trim().toLowerCase(Locale.ENGLISH);
    92             for (ProxyPolicy pp: values()) {
    93                 if (pp.getName().equals(policyName))
    94                     return pp;
    95             }
    96             return null;
    97         }
    98     }
    99 
    100     /** Property key for proxy policy */
    101     public static final String PROXY_POLICY = "proxy.policy";
    102     /** Property key for HTTP proxy host */
    103     public static final String PROXY_HTTP_HOST = "proxy.http.host";
    104     /** Property key for HTTP proxy port */
    105     public static final String PROXY_HTTP_PORT = "proxy.http.port";
    106     /** Property key for SOCKS proxy host */
    107     public static final String PROXY_SOCKS_HOST = "proxy.socks.host";
    108     /** Property key for SOCKS proxy port */
    109     public static final String PROXY_SOCKS_PORT = "proxy.socks.port";
    110     /** Property key for proxy username */
    111     public static final String PROXY_USER = "proxy.user";
    112     /** Property key for proxy password */
    113     public static final String PROXY_PASS = "proxy.pass";
    114     /** Property key for proxy exceptions list */
    115     public static final String PROXY_EXCEPTIONS = "proxy.exceptions";
    11656
    11757    private transient Map<ProxyPolicy, JRadioButton> rbProxyPolicy;
     
    324264     */
    325265    public final void initFromPreferences() {
    326         ProxyPolicy pp = Optional.ofNullable(ProxyPolicy.fromName(Main.pref.get(PROXY_POLICY, null))).orElse(ProxyPolicy.NO_PROXY);
     266        ProxyPolicy pp = Optional.ofNullable(ProxyPolicy.fromName(Main.pref.get(DefaultProxySelector.PROXY_POLICY, null)))
     267                .orElse(ProxyPolicy.NO_PROXY);
    327268        rbProxyPolicy.get(pp).setSelected(true);
    328269        String value = Main.pref.get("proxy.host", null);
     
    332273            Main.pref.put("proxy.host", null);
    333274        } else {
    334             tfProxyHttpHost.setText(Main.pref.get(PROXY_HTTP_HOST, ""));
     275            tfProxyHttpHost.setText(Main.pref.get(DefaultProxySelector.PROXY_HTTP_HOST, ""));
    335276        }
    336277        value = Main.pref.get("proxy.port", null);
     
    340281            Main.pref.put("proxy.port", null);
    341282        } else {
    342             tfProxyHttpPort.setText(Main.pref.get(PROXY_HTTP_PORT, ""));
    343         }
    344         tfProxySocksHost.setText(Main.pref.get(PROXY_SOCKS_HOST, ""));
    345         tfProxySocksPort.setText(Main.pref.get(PROXY_SOCKS_PORT, ""));
     283            tfProxyHttpPort.setText(Main.pref.get(DefaultProxySelector.PROXY_HTTP_PORT, ""));
     284        }
     285        tfProxySocksHost.setText(Main.pref.get(DefaultProxySelector.PROXY_SOCKS_HOST, ""));
     286        tfProxySocksPort.setText(Main.pref.get(DefaultProxySelector.PROXY_SOCKS_PORT, ""));
    346287
    347288        if (pp.equals(ProxyPolicy.USE_SYSTEM_SETTINGS) && !DefaultProxySelector.willJvmRetrieveSystemProxies()) {
     
    417358            }
    418359        }
    419         Main.pref.put(PROXY_POLICY, Optional.ofNullable(policy).orElse(ProxyPolicy.NO_PROXY).getName());
    420         Main.pref.put(PROXY_HTTP_HOST, tfProxyHttpHost.getText());
    421         Main.pref.put(PROXY_HTTP_PORT, tfProxyHttpPort.getText());
    422         Main.pref.put(PROXY_SOCKS_HOST, tfProxySocksHost.getText());
    423         Main.pref.put(PROXY_SOCKS_PORT, tfProxySocksPort.getText());
     360        Main.pref.put(DefaultProxySelector.PROXY_POLICY, Optional.ofNullable(policy).orElse(ProxyPolicy.NO_PROXY).getName());
     361        Main.pref.put(DefaultProxySelector.PROXY_HTTP_HOST, tfProxyHttpHost.getText());
     362        Main.pref.put(DefaultProxySelector.PROXY_HTTP_PORT, tfProxyHttpPort.getText());
     363        Main.pref.put(DefaultProxySelector.PROXY_SOCKS_HOST, tfProxySocksHost.getText());
     364        Main.pref.put(DefaultProxySelector.PROXY_SOCKS_PORT, tfProxySocksPort.getText());
    424365
    425366        // update the proxy selector
  • trunk/src/org/openstreetmap/josm/io/DefaultProxySelector.java

    r12620 r12805  
    1919
    2020import org.openstreetmap.josm.Main;
    21 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
    22 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel.ProxyPolicy;
    2321import org.openstreetmap.josm.tools.Logging;
    2422
    2523/**
    2624 * This is the default proxy selector used in JOSM.
    27  *
     25 * @since 2641
    2826 */
    2927public class DefaultProxySelector extends ProxySelector {
     28
     29    /** Property key for proxy policy */
     30    public static final String PROXY_POLICY = "proxy.policy";
     31    /** Property key for HTTP proxy host */
     32    public static final String PROXY_HTTP_HOST = "proxy.http.host";
     33    /** Property key for HTTP proxy port */
     34    public static final String PROXY_HTTP_PORT = "proxy.http.port";
     35    /** Property key for SOCKS proxy host */
     36    public static final String PROXY_SOCKS_HOST = "proxy.socks.host";
     37    /** Property key for SOCKS proxy port */
     38    public static final String PROXY_SOCKS_PORT = "proxy.socks.port";
     39    /** Property key for proxy username */
     40    public static final String PROXY_USER = "proxy.user";
     41    /** Property key for proxy password */
     42    public static final String PROXY_PASS = "proxy.pass";
     43    /** Property key for proxy exceptions list */
     44    public static final String PROXY_EXCEPTIONS = "proxy.exceptions";
    3045
    3146    private static final List<Proxy> NO_PROXY_LIST = Collections.singletonList(Proxy.NO_PROXY);
     
    111126     */
    112127    public final void initFromPreferences() {
    113         String value = Main.pref.get(ProxyPreferencesPanel.PROXY_POLICY);
     128        String value = Main.pref.get(PROXY_POLICY);
    114129        if (value.isEmpty()) {
    115130            proxyPolicy = ProxyPolicy.NO_PROXY;
     
    118133            if (proxyPolicy == null) {
    119134                Logging.warn(tr("Unexpected value for preference ''{0}'' found. Got ''{1}''. Will use no proxy.",
    120                         ProxyPreferencesPanel.PROXY_POLICY, value));
     135                        PROXY_POLICY, value));
    121136                proxyPolicy = ProxyPolicy.NO_PROXY;
    122137            }
    123138        }
    124         String host = Main.pref.get(ProxyPreferencesPanel.PROXY_HTTP_HOST, null);
    125         int port = parseProxyPortValue(ProxyPreferencesPanel.PROXY_HTTP_PORT, Main.pref.get(ProxyPreferencesPanel.PROXY_HTTP_PORT, null));
     139        String host = Main.pref.get(PROXY_HTTP_HOST, null);
     140        int port = parseProxyPortValue(PROXY_HTTP_PORT, Main.pref.get(PROXY_HTTP_PORT, null));
    126141        httpProxySocketAddress = null;
    127142        if (proxyPolicy.equals(ProxyPolicy.USE_HTTP_PROXY)) {
     
    134149        }
    135150
    136         host = Main.pref.get(ProxyPreferencesPanel.PROXY_SOCKS_HOST, null);
    137         port = parseProxyPortValue(ProxyPreferencesPanel.PROXY_SOCKS_PORT, Main.pref.get(ProxyPreferencesPanel.PROXY_SOCKS_PORT, null));
     151        host = Main.pref.get(PROXY_SOCKS_HOST, null);
     152        port = parseProxyPortValue(PROXY_SOCKS_PORT, Main.pref.get(PROXY_SOCKS_PORT, null));
    138153        socksProxySocketAddress = null;
    139154        if (proxyPolicy.equals(ProxyPolicy.USE_SOCKS_PROXY)) {
     
    146161        }
    147162        proxyExceptions = new HashSet<>(
    148             Main.pref.getCollection(ProxyPreferencesPanel.PROXY_EXCEPTIONS,
     163            Main.pref.getCollection(PROXY_EXCEPTIONS,
    149164                    Arrays.asList("localhost", IPV4_LOOPBACK, IPV6_LOOPBACK))
    150165        );
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r12804 r12805  
    5050 * It is conceivable to extract this into an interface later and create various
    5151 * classes implementing the interface, to be able to talk to various kinds of servers.
    52  * @ince 1523
     52 * @since 1523
    5353 */
    5454public class OsmApi extends OsmConnection {
  • trunk/src/org/openstreetmap/josm/io/auth/JosmPreferencesCredentialAgent.java

    r8510 r12805  
    1313import org.openstreetmap.josm.Main;
    1414import org.openstreetmap.josm.data.oauth.OAuthToken;
    15 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;
    1615import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     16import org.openstreetmap.josm.io.DefaultProxySelector;
    1717import org.openstreetmap.josm.io.OsmApi;
    1818
     
    2020 * This is the default credentials agent in JOSM. It keeps username and password for both
    2121 * the OSM API and an optional HTTP proxy in the JOSM preferences file.
    22  *
     22 * @since 2641
    2323 */
    2424public class JosmPreferencesCredentialAgent extends AbstractCredentialsAgent {
     
    4949            return new PasswordAuthentication(user, password == null ? new char[0] : password.toCharArray());
    5050        case PROXY:
    51             user = Main.pref.get(ProxyPreferencesPanel.PROXY_USER, null);
    52             password = Main.pref.get(ProxyPreferencesPanel.PROXY_PASS, null);
     51            user = Main.pref.get(DefaultProxySelector.PROXY_USER, null);
     52            password = Main.pref.get(DefaultProxySelector.PROXY_PASS, null);
    5353            if (user == null)
    5454                return null;
     
    8484            break;
    8585        case PROXY:
    86             Main.pref.put(ProxyPreferencesPanel.PROXY_USER, credentials.getUserName());
     86            Main.pref.put(DefaultProxySelector.PROXY_USER, credentials.getUserName());
    8787            if (credentials.getPassword() == null) {
    88                 Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, null);
     88                Main.pref.put(DefaultProxySelector.PROXY_PASS, null);
    8989            } else {
    90                 Main.pref.put(ProxyPreferencesPanel.PROXY_PASS, String.valueOf(credentials.getPassword()));
     90                Main.pref.put(DefaultProxySelector.PROXY_PASS, String.valueOf(credentials.getPassword()));
    9191            }
    9292            break;
Note: See TracChangeset for help on using the changeset viewer.