source: josm/trunk/src/org/openstreetmap/josm/gui/MainApplication.java@ 12077

Last change on this file since 12077 was 11925, checked in by Don-vip, 7 years ago

drop Main.MasterWindowListener (unused)

  • Property svn:eol-style set to native
File size: 26.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5import static org.openstreetmap.josm.tools.I18n.trn;
6
7import java.awt.Dimension;
8import java.io.File;
9import java.io.IOException;
10import java.io.InputStream;
11import java.net.Authenticator;
12import java.net.Inet6Address;
13import java.net.InetAddress;
14import java.net.ProxySelector;
15import java.net.URL;
16import java.security.AllPermission;
17import java.security.CodeSource;
18import java.security.GeneralSecurityException;
19import java.security.KeyStoreException;
20import java.security.NoSuchAlgorithmException;
21import java.security.PermissionCollection;
22import java.security.Permissions;
23import java.security.Policy;
24import java.security.cert.CertificateException;
25import java.util.ArrayList;
26import java.util.Arrays;
27import java.util.Collection;
28import java.util.Collections;
29import java.util.List;
30import java.util.Locale;
31import java.util.Map;
32import java.util.Optional;
33import java.util.Set;
34import java.util.TreeSet;
35import java.util.logging.Level;
36import java.util.stream.Collectors;
37import java.util.stream.Stream;
38
39import javax.net.ssl.SSLSocketFactory;
40import javax.swing.JOptionPane;
41import javax.swing.RepaintManager;
42import javax.swing.SwingUtilities;
43
44import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager;
45import org.openstreetmap.josm.Main;
46import org.openstreetmap.josm.actions.PreferencesAction;
47import org.openstreetmap.josm.actions.RestartAction;
48import org.openstreetmap.josm.data.AutosaveTask;
49import org.openstreetmap.josm.data.CustomConfigurator;
50import org.openstreetmap.josm.data.Version;
51import org.openstreetmap.josm.gui.ProgramArguments.Option;
52import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor;
53import org.openstreetmap.josm.gui.download.DownloadDialog;
54import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder;
55import org.openstreetmap.josm.gui.preferences.server.ProxyPreference;
56import org.openstreetmap.josm.gui.util.GuiHelper;
57import org.openstreetmap.josm.io.CertificateAmendment;
58import org.openstreetmap.josm.io.DefaultProxySelector;
59import org.openstreetmap.josm.io.MessageNotifier;
60import org.openstreetmap.josm.io.OnlineResource;
61import org.openstreetmap.josm.io.auth.CredentialsManager;
62import org.openstreetmap.josm.io.auth.DefaultAuthenticator;
63import org.openstreetmap.josm.io.protocols.data.Handler;
64import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
65import org.openstreetmap.josm.plugins.PluginHandler;
66import org.openstreetmap.josm.plugins.PluginInformation;
67import org.openstreetmap.josm.tools.FontsManager;
68import org.openstreetmap.josm.tools.HttpClient;
69import org.openstreetmap.josm.tools.I18n;
70import org.openstreetmap.josm.tools.Logging;
71import org.openstreetmap.josm.tools.OsmUrlToBounds;
72import org.openstreetmap.josm.tools.PlatformHookWindows;
73import org.openstreetmap.josm.tools.Utils;
74import org.openstreetmap.josm.tools.WindowGeometry;
75import org.openstreetmap.josm.tools.bugreport.BugReport;
76import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
77
78/**
79 * Main window class application.
80 *
81 * @author imi
82 */
83public class MainApplication extends Main {
84
85 /**
86 * Command-line arguments used to run the application.
87 */
88 private static final List<String> COMMAND_LINE_ARGS = new ArrayList<>();
89
90 private MainFrame mainFrame;
91
92 /**
93 * Constructs a new {@code MainApplication} without a window.
94 */
95 public MainApplication() {
96 // Allow subclassing (see JOSM.java)
97 this(null);
98 }
99
100 /**
101 * Constructs a main frame, ready sized and operating. Does not display the frame.
102 * @param mainFrame The main JFrame of the application
103 * @since 10340
104 */
105 public MainApplication(MainFrame mainFrame) {
106 this.mainFrame = mainFrame;
107 }
108
109 @Override
110 protected void initializeMainWindow() {
111 mainPanel.reAddListeners();
112 if (mainFrame != null) {
113 mainFrame.initialize();
114
115 menu = mainFrame.getMenu();
116 } else {
117 // required for running some tests.
118 menu = new MainMenu();
119 }
120 }
121
122 @Override
123 protected void shutdown() {
124 if (mainFrame != null) {
125 mainFrame.storeState();
126 }
127 super.shutdown();
128 }
129
130 /**
131 * Returns the command-line arguments used to run the application.
132 * @return the command-line arguments used to run the application
133 * @since 11650
134 */
135 public static List<String> getCommandLineArgs() {
136 return Collections.unmodifiableList(COMMAND_LINE_ARGS);
137 }
138
139 /**
140 * Displays help on the console
141 * @since 2748
142 */
143 public static void showHelp() {
144 // TODO: put in a platformHook for system that have no console by default
145 System.out.println(getHelp());
146 }
147
148 static String getHelp() {
149 return tr("Java OpenStreetMap Editor")+" ["
150 +Version.getInstance().getAgentString()+"]\n\n"+
151 tr("usage")+":\n"+
152 "\tjava -jar josm.jar <options>...\n\n"+
153 tr("options")+":\n"+
154 "\t--help|-h "+tr("Show this help")+'\n'+
155 "\t--geometry=widthxheight(+|-)x(+|-)y "+tr("Standard unix geometry argument")+'\n'+
156 "\t[--download=]minlat,minlon,maxlat,maxlon "+tr("Download the bounding box")+'\n'+
157 "\t[--download=]<URL> "+tr("Download the location at the URL (with lat=x&lon=y&zoom=z)")+'\n'+
158 "\t[--download=]<filename> "+tr("Open a file (any file type that can be opened with File/Open)")+'\n'+
159 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw GPS")+'\n'+
160 "\t--downloadgps=<URL> "+tr("Download the location at the URL (with lat=x&lon=y&zoom=z) as raw GPS")+'\n'+
161 "\t--selection=<searchstring> "+tr("Select with the given search")+'\n'+
162 "\t--[no-]maximize "+tr("Launch in maximized mode")+'\n'+
163 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+
164 "\t--load-preferences=<url-to-xml> "+tr("Changes preferences according to the XML file")+"\n\n"+
165 "\t--set=<key>=<value> "+tr("Set preference key to value")+"\n\n"+
166 "\t--language=<language> "+tr("Set the language")+"\n\n"+
167 "\t--version "+tr("Displays the JOSM version and exits")+"\n\n"+
168 "\t--debug "+tr("Print debugging messages to console")+"\n\n"+
169 "\t--skip-plugins "+tr("Skip loading plugins")+"\n\n"+
170 "\t--offline=<osm_api|josm_website|all> "+tr("Disable access to the given resource(s), separated by comma")+"\n\n"+
171 tr("options provided as Java system properties")+":\n"+
172 align("\t-Djosm.dir.name=JOSM") + tr("Change the JOSM directory name") + "\n\n" +
173 align("\t-Djosm.pref=" + tr("/PATH/TO/JOSM/PREF ")) + tr("Set the preferences directory") + "\n" +
174 align("\t") + tr("Default: {0}", platform.getDefaultPrefDirectory()) + "\n\n" +
175 align("\t-Djosm.userdata=" + tr("/PATH/TO/JOSM/USERDATA")) + tr("Set the user data directory") + "\n" +
176 align("\t") + tr("Default: {0}", platform.getDefaultUserDataDirectory()) + "\n\n" +
177 align("\t-Djosm.cache=" + tr("/PATH/TO/JOSM/CACHE ")) + tr("Set the cache directory") + "\n" +
178 align("\t") + tr("Default: {0}", platform.getDefaultCacheDirectory()) + "\n\n" +
179 align("\t-Djosm.home=" + tr("/PATH/TO/JOSM/HOMEDIR ")) +
180 tr("Set the preferences+data+cache directory (cache directory will be josm.home/cache)")+"\n\n"+
181 tr("-Djosm.home has lower precedence, i.e. the specific setting overrides the general one")+"\n\n"+
182 tr("note: For some tasks, JOSM needs a lot of memory. It can be necessary to add the following\n" +
183 " Java option to specify the maximum size of allocated memory in megabytes")+":\n"+
184 "\t-Xmx...m\n\n"+
185 tr("examples")+":\n"+
186 "\tjava -jar josm.jar track1.gpx track2.gpx london.osm\n"+
187 "\tjava -jar josm.jar "+OsmUrlToBounds.getURL(43.2, 11.1, 13)+'\n'+
188 "\tjava -jar josm.jar london.osm --selection=http://www.ostertag.name/osm/OSM_errors_node-duplicate.xml\n"+
189 "\tjava -jar josm.jar 43.2,11.1,43.4,11.4\n"+
190 "\tjava -Djosm.pref=$XDG_CONFIG_HOME -Djosm.userdata=$XDG_DATA_HOME -Djosm.cache=$XDG_CACHE_HOME -jar josm.jar\n"+
191 "\tjava -Djosm.dir.name=josm_dev -jar josm.jar\n"+
192 "\tjava -Djosm.home=/home/user/.josm_dev -jar josm.jar\n"+
193 "\tjava -Xmx1024m -jar josm.jar\n\n"+
194 tr("Parameters --download, --downloadgps, and --selection are processed in this order.")+'\n'+
195 tr("Make sure you load some data if you use --selection.")+'\n';
196 }
197
198 private static String align(String str) {
199 return str + Stream.generate(() -> " ").limit(Math.max(0, 43 - str.length())).collect(Collectors.joining(""));
200 }
201
202 /**
203 * Main application Startup
204 * @param argArray Command-line arguments
205 */
206 public static void main(final String[] argArray) {
207 I18n.init();
208
209 // construct argument table
210 ProgramArguments args = null;
211 try {
212 args = new ProgramArguments(argArray);
213 } catch (IllegalArgumentException e) {
214 System.err.println(e.getMessage());
215 System.exit(1);
216 return;
217 }
218
219 Level logLevel = args.getLogLevel();
220 Logging.setLogLevel(logLevel);
221 if (!args.showVersion() && !args.showHelp()) {
222 Main.info(tr("Log level is at {0} ({1}, {2})", logLevel.getLocalizedName(), logLevel.getName(), logLevel.intValue()));
223 }
224
225 Optional<String> language = args.getSingle(Option.LANGUAGE);
226 I18n.set(language.orElse(null));
227
228 Policy.setPolicy(new Policy() {
229 // Permissions for plug-ins loaded when josm is started via webstart
230 private PermissionCollection pc;
231
232 {
233 pc = new Permissions();
234 pc.add(new AllPermission());
235 }
236
237 @Override
238 public PermissionCollection getPermissions(CodeSource codesource) {
239 return pc;
240 }
241 });
242
243 Thread.setDefaultUncaughtExceptionHandler(new BugReportExceptionHandler());
244
245 // initialize the platform hook, and
246 Main.determinePlatformHook();
247 // call the really early hook before we do anything else
248 Main.platform.preStartupHook();
249
250 if (args.showVersion()) {
251 System.out.println(Version.getInstance().getAgentString());
252 return;
253 } else if (args.showHelp()) {
254 showHelp();
255 return;
256 }
257
258 COMMAND_LINE_ARGS.addAll(Arrays.asList(argArray));
259
260 boolean skipLoadingPlugins = args.hasOption(Option.SKIP_PLUGINS);
261 if (skipLoadingPlugins) {
262 Main.info(tr("Plugin loading skipped"));
263 }
264
265 if (Logging.isLoggingEnabled(Logging.LEVEL_TRACE)) {
266 // Enable debug in OAuth signpost via system preference, but only at trace level
267 Utils.updateSystemProperty("debug", "true");
268 Main.info(tr("Enabled detailed debug level (trace)"));
269 }
270
271 Main.pref.init(args.hasOption(Option.RESET_PREFERENCES));
272
273 args.getPreferencesToSet().forEach(Main.pref::put);
274
275 if (!language.isPresent()) {
276 I18n.set(Main.pref.get("language", null));
277 }
278 Main.pref.updateSystemProperties();
279
280 checkIPv6();
281
282 processOffline(args);
283
284 Main.platform.afterPrefStartupHook();
285
286 FontsManager.initialize();
287
288 I18n.setupLanguageFonts();
289
290 Handler.install();
291
292 WindowGeometry geometry = WindowGeometry.mainWindow("gui.geometry",
293 args.getSingle(Option.GEOMETRY).orElse(null),
294 !args.hasOption(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false));
295 final MainFrame mainFrame = new MainFrame(contentPanePrivate, geometry);
296 Main.parent = mainFrame;
297
298 if (args.hasOption(Option.LOAD_PREFERENCES)) {
299 CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
300 for (String i : args.get(Option.LOAD_PREFERENCES)) {
301 info("Reading preferences from " + i);
302 try (InputStream is = openStream(new URL(i))) {
303 config.openAndReadXML(is);
304 } catch (IOException ex) {
305 throw BugReport.intercept(ex).put("file", i);
306 }
307 }
308 }
309
310 try {
311 CertificateAmendment.addMissingCertificates();
312 } catch (IOException | GeneralSecurityException ex) {
313 Main.warn(ex);
314 Main.warn(getErrorMessage(Utils.getRootCause(ex)));
315 }
316 Authenticator.setDefault(DefaultAuthenticator.getInstance());
317 DefaultProxySelector proxySelector = new DefaultProxySelector(ProxySelector.getDefault());
318 ProxySelector.setDefault(proxySelector);
319 OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance());
320
321 final SplashScreen splash = GuiHelper.runInEDTAndWaitAndReturn(SplashScreen::new);
322 final SplashScreen.SplashProgressMonitor monitor = splash.getProgressMonitor();
323 monitor.beginTask(tr("Initializing"));
324 GuiHelper.runInEDT(() -> splash.setVisible(Main.pref.getBoolean("draw.splashscreen", true)));
325 Main.setInitStatusListener(new InitStatusListener() {
326
327 @Override
328 public Object updateStatus(String event) {
329 monitor.beginTask(event);
330 return event;
331 }
332
333 @Override
334 public void finish(Object status) {
335 if (status instanceof String) {
336 monitor.finishTask((String) status);
337 }
338 }
339 });
340
341 Collection<PluginInformation> pluginsToLoad = null;
342
343 if (!skipLoadingPlugins) {
344 pluginsToLoad = updateAndLoadEarlyPlugins(splash, monitor);
345 }
346
347 monitor.indeterminateSubTask(tr("Setting defaults"));
348 preConstructorInit();
349
350 monitor.indeterminateSubTask(tr("Creating main GUI"));
351 final Main main = new MainApplication(mainFrame);
352 main.initialize();
353
354 if (!skipLoadingPlugins) {
355 loadLatePlugins(splash, monitor, pluginsToLoad);
356 }
357
358 // Wait for splash disappearance (fix #9714)
359 GuiHelper.runInEDTAndWait(() -> {
360 splash.setVisible(false);
361 splash.dispose();
362 mainFrame.setVisible(true);
363 });
364
365 boolean maximized = Main.pref.getBoolean("gui.maximized", false);
366 if ((!args.hasOption(Option.NO_MAXIMIZE) && maximized) || args.hasOption(Option.MAXIMIZE)) {
367 mainFrame.setMaximized(true);
368 }
369 if (main.menu.fullscreenToggleAction != null) {
370 main.menu.fullscreenToggleAction.initial();
371 }
372
373 SwingUtilities.invokeLater(new GuiFinalizationWorker(args, proxySelector));
374
375 if (Main.isPlatformWindows()) {
376 try {
377 // Check for insecure certificates to remove.
378 // This is Windows-dependant code but it can't go to preStartupHook (need i18n)
379 // neither startupHook (need to be called before remote control)
380 PlatformHookWindows.removeInsecureCertificates();
381 } catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException e) {
382 error(e);
383 }
384 }
385
386 if (RemoteControl.PROP_REMOTECONTROL_ENABLED.get()) {
387 RemoteControl.start();
388 }
389
390 if (MessageNotifier.PROP_NOTIFIER_ENABLED.get()) {
391 MessageNotifier.start();
392 }
393
394 if (Main.pref.getBoolean("debug.edt-checker.enable", Version.getInstance().isLocalBuild())) {
395 // Repaint manager is registered so late for a reason - there is lots of violation during startup process
396 // but they don't seem to break anything and are difficult to fix
397 info("Enabled EDT checker, wrongful access to gui from non EDT thread will be printed to console");
398 RepaintManager.setCurrentManager(new CheckThreadViolationRepaintManager());
399 }
400 }
401
402 private static InputStream openStream(URL url) throws IOException {
403 if ("file".equals(url.getProtocol())) {
404 return url.openStream();
405 } else {
406 return HttpClient.create(url).connect().getContent();
407 }
408 }
409
410 static Collection<PluginInformation> updateAndLoadEarlyPlugins(SplashScreen splash, SplashProgressMonitor monitor) {
411 Collection<PluginInformation> pluginsToLoad;
412 pluginsToLoad = PluginHandler.buildListOfPluginsToLoad(splash, monitor.createSubTaskMonitor(1, false));
413 if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) {
414 monitor.subTask(tr("Updating plugins"));
415 pluginsToLoad = PluginHandler.updatePlugins(splash, null, monitor.createSubTaskMonitor(1, false), false);
416 }
417
418 monitor.indeterminateSubTask(tr("Installing updated plugins"));
419 PluginHandler.installDownloadedPlugins(true);
420
421 monitor.indeterminateSubTask(tr("Loading early plugins"));
422 PluginHandler.loadEarlyPlugins(splash, pluginsToLoad, monitor.createSubTaskMonitor(1, false));
423 return pluginsToLoad;
424 }
425
426 static void loadLatePlugins(SplashScreen splash, SplashProgressMonitor monitor, Collection<PluginInformation> pluginsToLoad) {
427 monitor.indeterminateSubTask(tr("Loading plugins"));
428 PluginHandler.loadLatePlugins(splash, pluginsToLoad, monitor.createSubTaskMonitor(1, false));
429 toolbar.refreshToolbarControl();
430 }
431
432 private static void processOffline(ProgramArguments args) {
433 for (String offlineNames : args.get(Option.OFFLINE)) {
434 for (String s : offlineNames.split(",")) {
435 try {
436 Main.setOffline(OnlineResource.valueOf(s.toUpperCase(Locale.ENGLISH)));
437 } catch (IllegalArgumentException e) {
438 Main.error(e, tr("''{0}'' is not a valid value for argument ''{1}''. Possible values are {2}, possibly delimited by commas.",
439 s.toUpperCase(Locale.ENGLISH), Option.OFFLINE.getName(), Arrays.toString(OnlineResource.values())));
440 System.exit(1);
441 return;
442 }
443 }
444 }
445 Set<OnlineResource> offline = Main.getOfflineResources();
446 if (!offline.isEmpty()) {
447 Main.warn(trn("JOSM is running in offline mode. This resource will not be available: {0}",
448 "JOSM is running in offline mode. These resources will not be available: {0}",
449 offline.size(), offline.size() == 1 ? offline.iterator().next() : Arrays.toString(offline.toArray())));
450 }
451 }
452
453 /**
454 * Check if IPv6 can be safely enabled and do so. Because this cannot be done after network activation,
455 * disabling or enabling IPV6 may only be done with next start.
456 */
457 private static void checkIPv6() {
458 if ("auto".equals(Main.pref.get("prefer.ipv6", "auto"))) {
459 new Thread((Runnable) () -> { /* this may take some time (DNS, Connect) */
460 boolean hasv6 = false;
461 boolean wasv6 = Main.pref.getBoolean("validated.ipv6", false);
462 try {
463 /* Use the check result from last run of the software, as after the test, value
464 changes have no effect anymore */
465 if (wasv6) {
466 Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
467 }
468 for (InetAddress a : InetAddress.getAllByName("josm.openstreetmap.de")) {
469 if (a instanceof Inet6Address) {
470 if (a.isReachable(1000)) {
471 /* be sure it REALLY works */
472 SSLSocketFactory.getDefault().createSocket(a, 443).close();
473 Utils.updateSystemProperty("java.net.preferIPv6Addresses", "true");
474 if (!wasv6) {
475 Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4 after next restart."));
476 } else {
477 Main.info(tr("Detected useable IPv6 network, prefering IPv6 over IPv4."));
478 }
479 hasv6 = true;
480 }
481 break; /* we're done */
482 }
483 }
484 } catch (IOException | SecurityException e) {
485 if (Main.isDebugEnabled()) {
486 Main.debug("Exception while checking IPv6 connectivity: "+e);
487 }
488 Main.trace(e);
489 }
490 if (wasv6 && !hasv6) {
491 Main.info(tr("Detected no useable IPv6 network, prefering IPv4 over IPv6 after next restart."));
492 Main.pref.put("validated.ipv6", hasv6); // be sure it is stored before the restart!
493 new RestartAction().actionPerformed(null);
494 }
495 Main.pref.put("validated.ipv6", hasv6);
496 }, "IPv6-checker").start();
497 }
498 }
499
500 private static class GuiFinalizationWorker implements Runnable {
501
502 private final ProgramArguments args;
503 private final DefaultProxySelector proxySelector;
504
505 GuiFinalizationWorker(ProgramArguments args, DefaultProxySelector proxySelector) {
506 this.args = args;
507 this.proxySelector = proxySelector;
508 }
509
510 @Override
511 public void run() {
512
513 // Handle proxy/network errors early to inform user he should change settings to be able to use JOSM correctly
514 if (!handleProxyErrors()) {
515 handleNetworkErrors();
516 }
517
518 // Restore autosave layers after crash and start autosave thread
519 handleAutosave();
520
521 // Handle command line instructions
522 postConstructorProcessCmdLine(args);
523
524 // Show download dialog if autostart is enabled
525 DownloadDialog.autostartIfNeeded();
526 }
527
528 private static void handleAutosave() {
529 if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) {
530 AutosaveTask autosaveTask = new AutosaveTask();
531 List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles();
532 if (!unsavedLayerFiles.isEmpty()) {
533 ExtendedDialog dialog = new ExtendedDialog(
534 Main.parent,
535 tr("Unsaved osm data"),
536 new String[] {tr("Restore"), tr("Cancel"), tr("Discard")}
537 );
538 dialog.setContent(
539 trn("JOSM found {0} unsaved osm data layer. ",
540 "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) +
541 tr("It looks like JOSM crashed last time. Would you like to restore the data?"));
542 dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/delete"});
543 int selection = dialog.showDialog().getValue();
544 if (selection == 1) {
545 autosaveTask.recoverUnsavedLayers();
546 } else if (selection == 3) {
547 autosaveTask.discardUnsavedLayers();
548 }
549 }
550 autosaveTask.schedule();
551 }
552 }
553
554 private static boolean handleNetworkOrProxyErrors(boolean hasErrors, String title, String message) {
555 if (hasErrors) {
556 ExtendedDialog ed = new ExtendedDialog(
557 Main.parent, title,
558 new String[]{tr("Change proxy settings"), tr("Cancel")});
559 ed.setButtonIcons(new String[]{"dialogs/settings", "cancel"}).setCancelButton(2);
560 ed.setMinimumSize(new Dimension(460, 260));
561 ed.setIcon(JOptionPane.WARNING_MESSAGE);
562 ed.setContent(message);
563
564 if (ed.showDialog().getValue() == 1) {
565 PreferencesAction.forPreferenceSubTab(null, null, ProxyPreference.class).run();
566 }
567 }
568 return hasErrors;
569 }
570
571 private boolean handleProxyErrors() {
572 return handleNetworkOrProxyErrors(proxySelector.hasErrors(), tr("Proxy errors occurred"),
573 tr("JOSM tried to access the following resources:<br>" +
574 "{0}" +
575 "but <b>failed</b> to do so, because of the following proxy errors:<br>" +
576 "{1}" +
577 "Would you like to change your proxy settings now?",
578 Utils.joinAsHtmlUnorderedList(proxySelector.getErrorResources()),
579 Utils.joinAsHtmlUnorderedList(proxySelector.getErrorMessages())
580 ));
581 }
582
583 private static boolean handleNetworkErrors() {
584 Map<String, Throwable> networkErrors = Main.getNetworkErrors();
585 boolean condition = !networkErrors.isEmpty();
586 if (condition) {
587 Set<String> errors = new TreeSet<>();
588 for (Throwable t : networkErrors.values()) {
589 errors.add(t.toString());
590 }
591 return handleNetworkOrProxyErrors(condition, tr("Network errors occurred"),
592 tr("JOSM tried to access the following resources:<br>" +
593 "{0}" +
594 "but <b>failed</b> to do so, because of the following network errors:<br>" +
595 "{1}" +
596 "It may be due to a missing proxy configuration.<br>" +
597 "Would you like to change your proxy settings now?",
598 Utils.joinAsHtmlUnorderedList(networkErrors.keySet()),
599 Utils.joinAsHtmlUnorderedList(errors)
600 ));
601 }
602 return false;
603 }
604 }
605}
Note: See TracBrowser for help on using the repository browser.