Ignore:
Timestamp:
2014-01-06T15:57:41+01:00 (10 years ago)
Author:
Don-vip
Message:

Improve handling of network errors at startup, suggest to change proxy settings

File:
1 edited

Legend:

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

    r6578 r6642  
    2727import java.util.List;
    2828import java.util.Map;
     29import java.util.Set;
     30import java.util.TreeSet;
    2931
    3032import javax.swing.JFrame;
     
    8789        mainFrame.setIconImages(l);
    8890        mainFrame.addWindowListener(new WindowAdapter(){
    89             @Override public void windowClosing(final WindowEvent arg0) {
     91            @Override
     92            public void windowClosing(final WindowEvent arg0) {
    9093                Main.exitJosm(true, 0);
    9194            }
     
    297300
    298301        Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
    299         // http://stuffthathappens.com/blog/2007/10/15/one-more-note-on-uncaught-exception-handlers/
     302        // http://stackoverflow.com/q/75218/2257172
     303        // To be replaced with official API when switching to Java 7: https://bugs.openjdk.java.net/browse/JDK-4714232
    300304        System.setProperty("sun.awt.exception.handler", BugReportExceptionHandler.class.getName());
    301305
     
    441445        public void run() {
    442446
    443             // Handle proxy errors early to inform user he should change settings to be able to use JOSM correctly
    444             handleProxyErrors();
     447            // Handle proxy/network errors early to inform user he should change settings to be able to use JOSM correctly
     448            if (!handleProxyErrors()) {
     449                handleNetworkErrors();
     450            }
    445451
    446452            // Restore autosave layers after crash and start autosave thread
     
    480486        }
    481487
    482         private void handleProxyErrors() {
    483             if (proxySelector.hasErrors()) {
     488        private boolean handleNetworkOrProxyErrors(boolean hasErrors, String title, String message) {
     489            if (hasErrors) {
    484490                ExtendedDialog ed = new ExtendedDialog(
    485                         Main.parent, tr("Proxy errors occurred"),
     491                        Main.parent, title,
    486492                        new String[]{tr("Change proxy settings"), tr("Cancel")});
    487493                ed.setButtonIcons(new String[]{"dialogs/settings.png", "cancel.png"}).setCancelButton(2);
    488494                ed.setMinimumSize(new Dimension(460, 260));
    489495                ed.setIcon(JOptionPane.WARNING_MESSAGE);
    490                 ed.setContent(tr("JOSM tried to access the following resources:<br>" +
    491                         "{0}" +
    492                         "but <b>failed</b> to do so, because of the following proxy errors:<br>" +
    493                         "{1}" +
    494                         "Would you like to change your proxy settings now?",
    495                         Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()),
    496                         Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages())
    497                 ));
     496                ed.setContent(message);
    498497
    499498                if (ed.showDialog().getValue() == 1) {
     
    501500                }
    502501            }
     502            return hasErrors;
     503        }
     504
     505        private boolean handleProxyErrors() {
     506            return handleNetworkOrProxyErrors(proxySelector.hasErrors(), tr("Proxy errors occurred"),
     507                    tr("JOSM tried to access the following resources:<br>" +
     508                            "{0}" +
     509                            "but <b>failed</b> to do so, because of the following proxy errors:<br>" +
     510                            "{1}" +
     511                            "Would you like to change your proxy settings now?",
     512                            Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()),
     513                            Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages())
     514                    ));
     515        }
     516
     517        private boolean handleNetworkErrors() {
     518            boolean condition = !networkErrors.isEmpty();
     519            if (condition) {
     520                Set<String> errors = new TreeSet<String>();
     521                for (Throwable t : networkErrors.values()) {
     522                    errors.add(t.toString());
     523                }
     524                return handleNetworkOrProxyErrors(condition, tr("Network errors occurred"),
     525                        tr("JOSM tried to access the following resources:<br>" +
     526                                "{0}" +
     527                                "but <b>failed</b> to do so, because of the following network errors:<br>" +
     528                                "{1}" +
     529                                "It may result of a missing proxy configuration.<br>" +
     530                                "Would you like to change your proxy settings now?",
     531                                Utils.joinAsHtmlUnorderedList(networkErrors.keySet()),
     532                                Utils.joinAsHtmlUnorderedList(errors)
     533                        ));
     534            }
     535            return false;
    503536        }
    504537    }
Note: See TracChangeset for help on using the changeset viewer.