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

Last change on this file since 7894 was 7894, checked in by Don-vip, 9 years ago

Enable CLDR and add support for Khmer language (km) for Java 8 users

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