source: josm/trunk/src/org/openstreetmap/josm/Main.java@ 12630

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

see #15182 - deprecate Main.map and Main.isDisplayingMapView(). Replacements: gui.MainApplication.getMap() / gui.MainApplication.isDisplayingMapView()

  • Property svn:eol-style set to native
File size: 50.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Component;
7import java.awt.GraphicsEnvironment;
8import java.io.File;
9import java.io.IOException;
10import java.lang.ref.WeakReference;
11import java.net.URI;
12import java.net.URISyntaxException;
13import java.net.URL;
14import java.text.MessageFormat;
15import java.util.ArrayList;
16import java.util.Arrays;
17import java.util.Collection;
18import java.util.Collections;
19import java.util.EnumSet;
20import java.util.HashMap;
21import java.util.Iterator;
22import java.util.List;
23import java.util.Locale;
24import java.util.Map;
25import java.util.Objects;
26import java.util.Set;
27import java.util.StringTokenizer;
28import java.util.concurrent.Callable;
29import java.util.concurrent.ExecutionException;
30import java.util.concurrent.ExecutorService;
31import java.util.concurrent.Executors;
32import java.util.concurrent.Future;
33
34import javax.swing.Action;
35import javax.swing.InputMap;
36import javax.swing.JComponent;
37import javax.swing.JOptionPane;
38import javax.swing.KeyStroke;
39import javax.swing.LookAndFeel;
40import javax.swing.UIManager;
41import javax.swing.UnsupportedLookAndFeelException;
42
43import org.openstreetmap.josm.actions.JosmAction;
44import org.openstreetmap.josm.actions.OpenFileAction;
45import org.openstreetmap.josm.actions.OpenLocationAction;
46import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
47import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
48import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
49import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
50import org.openstreetmap.josm.actions.mapmode.DrawAction;
51import org.openstreetmap.josm.actions.search.SearchAction;
52import org.openstreetmap.josm.data.Bounds;
53import org.openstreetmap.josm.data.Preferences;
54import org.openstreetmap.josm.data.UndoRedoHandler;
55import org.openstreetmap.josm.data.cache.JCSCacheManager;
56import org.openstreetmap.josm.data.coor.CoordinateFormat;
57import org.openstreetmap.josm.data.coor.LatLon;
58import org.openstreetmap.josm.data.osm.DataSet;
59import org.openstreetmap.josm.data.osm.OsmPrimitive;
60import org.openstreetmap.josm.data.projection.Projection;
61import org.openstreetmap.josm.data.projection.ProjectionChangeListener;
62import org.openstreetmap.josm.gui.MainApplication;
63import org.openstreetmap.josm.gui.MainMenu;
64import org.openstreetmap.josm.gui.MainPanel;
65import org.openstreetmap.josm.gui.MapFrame;
66import org.openstreetmap.josm.gui.MapFrameListener;
67import org.openstreetmap.josm.gui.ProgramArguments;
68import org.openstreetmap.josm.gui.ProgramArguments.Option;
69import org.openstreetmap.josm.gui.io.SaveLayersDialog;
70import org.openstreetmap.josm.gui.layer.MainLayerManager;
71import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
72import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
73import org.openstreetmap.josm.gui.preferences.display.LafPreference;
74import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference;
75import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor;
76import org.openstreetmap.josm.gui.progress.ProgressMonitorExecutor;
77import org.openstreetmap.josm.gui.util.GuiHelper;
78import org.openstreetmap.josm.gui.util.RedirectInputMap;
79import org.openstreetmap.josm.io.FileWatcher;
80import org.openstreetmap.josm.io.OnlineResource;
81import org.openstreetmap.josm.io.OsmApi;
82import org.openstreetmap.josm.plugins.PluginHandler;
83import org.openstreetmap.josm.tools.CheckParameterUtil;
84import org.openstreetmap.josm.tools.I18n;
85import org.openstreetmap.josm.tools.ImageProvider;
86import org.openstreetmap.josm.tools.JosmRuntimeException;
87import org.openstreetmap.josm.tools.Logging;
88import org.openstreetmap.josm.tools.OsmUrlToBounds;
89import org.openstreetmap.josm.tools.PlatformHook;
90import org.openstreetmap.josm.tools.PlatformHookOsx;
91import org.openstreetmap.josm.tools.PlatformHookUnixoid;
92import org.openstreetmap.josm.tools.PlatformHookWindows;
93import org.openstreetmap.josm.tools.Shortcut;
94import org.openstreetmap.josm.tools.Utils;
95import org.openstreetmap.josm.tools.bugreport.BugReport;
96
97/**
98 * Abstract class holding various static global variables and methods used in large parts of JOSM application.
99 * @since 98
100 */
101public abstract class Main {
102
103 /**
104 * The JOSM website URL.
105 * @since 6897 (was public from 6143 to 6896)
106 */
107 private static final String JOSM_WEBSITE = "https://josm.openstreetmap.de";
108
109 /**
110 * The OSM website URL.
111 * @since 6897 (was public from 6453 to 6896)
112 */
113 private static final String OSM_WEBSITE = "https://www.openstreetmap.org";
114
115 /**
116 * Replies true if JOSM currently displays a map view. False, if it doesn't, i.e. if
117 * it only shows the MOTD panel.
118 * <p>
119 * You do not need this when accessing the layer manager. The layer manager will be empty if no map view is shown.
120 *
121 * @return <code>true</code> if JOSM currently displays a map view
122 * @deprecated use {@link org.openstreetmap.josm.gui.MainApplication#isDisplayingMapView()}
123 */
124 @Deprecated
125 public static boolean isDisplayingMapView() {
126 return map != null && map.mapView != null;
127 }
128
129 /**
130 * Global parent component for all dialogs and message boxes
131 */
132 public static Component parent;
133
134 /**
135 * Global application.
136 */
137 public static volatile Main main;
138
139 /**
140 * The worker thread slave. This is for executing all long and intensive
141 * calculations. The executed runnables are guaranteed to be executed separately
142 * and sequential.
143 */
144 public static final ExecutorService worker = new ProgressMonitorExecutor("main-worker-%d", Thread.NORM_PRIORITY);
145
146 /**
147 * Global application preferences
148 */
149 public static final Preferences pref = new Preferences();
150
151 /**
152 * The MapFrame.
153 * <p>
154 * There should be no need to access this to access any map data. Use {@link #layerManager} instead.
155 *
156 * @deprecated Use {@link org.openstreetmap.josm.gui.MainApplication#getMap()} instead
157 * @see MainPanel
158 */
159 @Deprecated
160 public static MapFrame map;
161
162 /**
163 * Provides access to the layers displayed in the main view.
164 * @since 10271
165 */
166 private static final MainLayerManager layerManager = new MainLayerManager();
167
168 /**
169 * The toolbar preference control to register new actions.
170 */
171 public static volatile ToolbarPreferences toolbar;
172
173 /**
174 * The commands undo/redo handler.
175 */
176 public final UndoRedoHandler undoRedo = new UndoRedoHandler();
177
178 /**
179 * The progress monitor being currently displayed.
180 */
181 public static PleaseWaitProgressMonitor currentProgressMonitor;
182
183 /**
184 * The main menu bar at top of screen.
185 */
186 public MainMenu menu;
187
188 /**
189 * The main panel.
190 * @since 12125
191 */
192 public MainPanel panel;
193
194 /**
195 * The same main panel, required to be static for {@code MapFrameListener} handling.
196 */
197 protected static MainPanel mainPanel;
198
199 /**
200 * The private content pane of {@code MainFrame}, required to be static for shortcut handling.
201 */
202 protected static JComponent contentPanePrivate;
203
204 /**
205 * The file watcher service.
206 */
207 public static final FileWatcher fileWatcher = new FileWatcher();
208
209 private static final Map<String, Throwable> NETWORK_ERRORS = new HashMap<>();
210
211 private static final Set<OnlineResource> OFFLINE_RESOURCES = EnumSet.noneOf(OnlineResource.class);
212
213 /**
214 * Logging level (5 = trace, 4 = debug, 3 = info, 2 = warn, 1 = error, 0 = none).
215 * @since 6248
216 * @deprecated Use {@link Logging} class.
217 */
218 @Deprecated
219 public static int logLevel = 3;
220
221 /**
222 * Replies the first lines of last 5 error and warning messages, used for bug reports
223 * @return the first lines of last 5 error and warning messages
224 * @since 7420
225 * @deprecated Use {@link Logging#getLastErrorAndWarnings}.
226 */
227 @Deprecated
228 public static final Collection<String> getLastErrorAndWarnings() {
229 return Logging.getLastErrorAndWarnings();
230 }
231
232 /**
233 * Clears the list of last error and warning messages.
234 * @since 8959
235 * @deprecated Use {@link Logging#clearLastErrorAndWarnings}.
236 */
237 @Deprecated
238 public static void clearLastErrorAndWarnings() {
239 Logging.clearLastErrorAndWarnings();
240 }
241
242 /**
243 * Prints an error message if logging is on.
244 * @param msg The message to print.
245 * @since 6248
246 * @deprecated Use {@link Logging#error(String)}.
247 */
248 @Deprecated
249 public static void error(String msg) {
250 Logging.error(msg);
251 }
252
253 /**
254 * Prints a warning message if logging is on.
255 * @param msg The message to print.
256 * @deprecated Use {@link Logging#warn(String)}.
257 */
258 @Deprecated
259 public static void warn(String msg) {
260 Logging.warn(msg);
261 }
262
263 /**
264 * Prints an informational message if logging is on.
265 * @param msg The message to print.
266 * @deprecated Use {@link Logging#info(String)}.
267 */
268 @Deprecated
269 public static void info(String msg) {
270 Logging.info(msg);
271 }
272
273 /**
274 * Prints a debug message if logging is on.
275 * @param msg The message to print.
276 * @deprecated Use {@link Logging#debug(String)}.
277 */
278 @Deprecated
279 public static void debug(String msg) {
280 Logging.debug(msg);
281 }
282
283 /**
284 * Prints a trace message if logging is on.
285 * @param msg The message to print.
286 * @deprecated Use {@link Logging#trace(String)}.
287 */
288 @Deprecated
289 public static void trace(String msg) {
290 Logging.trace(msg);
291 }
292
293 /**
294 * Determines if debug log level is enabled.
295 * Useful to avoid costly construction of debug messages when not enabled.
296 * @return {@code true} if log level is at least debug, {@code false} otherwise
297 * @since 6852
298 * @deprecated Use {@link Logging#isDebugEnabled}.
299 */
300 @Deprecated
301 public static boolean isDebugEnabled() {
302 return Logging.isDebugEnabled();
303 }
304
305 /**
306 * Determines if trace log level is enabled.
307 * Useful to avoid costly construction of trace messages when not enabled.
308 * @return {@code true} if log level is at least trace, {@code false} otherwise
309 * @since 6852
310 * @deprecated Use {@link Logging#isTraceEnabled}.
311 */
312 @Deprecated
313 public static boolean isTraceEnabled() {
314 return Logging.isTraceEnabled();
315 }
316
317 /**
318 * Prints a formatted error message if logging is on. Calls {@link MessageFormat#format}
319 * function to format text.
320 * @param msg The formatted message to print.
321 * @param objects The objects to insert into format string.
322 * @since 6248
323 * @deprecated Use {@link Logging#error(String, Object...)}.
324 */
325 @Deprecated
326 public static void error(String msg, Object... objects) {
327 Logging.error(msg, objects);
328 }
329
330 /**
331 * Prints a formatted warning message if logging is on. Calls {@link MessageFormat#format}
332 * function to format text.
333 * @param msg The formatted message to print.
334 * @param objects The objects to insert into format string.
335 * @deprecated Use {@link Logging#warn(String, Object...)}.
336 */
337 @Deprecated
338 public static void warn(String msg, Object... objects) {
339 Logging.warn(msg, objects);
340 }
341
342 /**
343 * Prints a formatted informational message if logging is on. Calls {@link MessageFormat#format}
344 * function to format text.
345 * @param msg The formatted message to print.
346 * @param objects The objects to insert into format string.
347 * @deprecated Use {@link Logging#info(String, Object...)}.
348 */
349 @Deprecated
350 public static void info(String msg, Object... objects) {
351 Logging.info(msg, objects);
352 }
353
354 /**
355 * Prints a formatted debug message if logging is on. Calls {@link MessageFormat#format}
356 * function to format text.
357 * @param msg The formatted message to print.
358 * @param objects The objects to insert into format string.
359 * @deprecated Use {@link Logging#debug(String, Object...)}.
360 */
361 @Deprecated
362 public static void debug(String msg, Object... objects) {
363 Logging.debug(msg, objects);
364 }
365
366 /**
367 * Prints a formatted trace message if logging is on. Calls {@link MessageFormat#format}
368 * function to format text.
369 * @param msg The formatted message to print.
370 * @param objects The objects to insert into format string.
371 * @deprecated Use {@link Logging#trace(String, Object...)}.
372 */
373 @Deprecated
374 public static void trace(String msg, Object... objects) {
375 Logging.trace(msg, objects);
376 }
377
378 /**
379 * Prints an error message for the given Throwable.
380 * @param t The throwable object causing the error
381 * @since 6248
382 * @deprecated Use {@link Logging#error(Throwable)}.
383 */
384 @Deprecated
385 public static void error(Throwable t) {
386 Logging.error(t);
387 }
388
389 /**
390 * Prints a warning message for the given Throwable.
391 * @param t The throwable object causing the error
392 * @since 6248
393 * @deprecated Use {@link Logging#warn(Throwable)}.
394 */
395 @Deprecated
396 public static void warn(Throwable t) {
397 Logging.warn(t);
398 }
399
400 /**
401 * Prints a debug message for the given Throwable. Useful for exceptions usually ignored
402 * @param t The throwable object causing the error
403 * @since 10420
404 * @deprecated Use {@link Logging#debug(Throwable)}.
405 */
406 @Deprecated
407 public static void debug(Throwable t) {
408 Logging.debug(t);
409 }
410
411 /**
412 * Prints a trace message for the given Throwable. Useful for exceptions usually ignored
413 * @param t The throwable object causing the error
414 * @since 10420
415 * @deprecated Use {@link Logging#trace(Throwable)}.
416 */
417 @Deprecated
418 public static void trace(Throwable t) {
419 Logging.trace(t);
420 }
421
422 /**
423 * Prints an error message for the given Throwable.
424 * @param t The throwable object causing the error
425 * @param stackTrace {@code true}, if the stacktrace should be displayed
426 * @since 6642
427 * @deprecated Use {@link Logging#log(java.util.logging.Level, Throwable)}
428 * or {@link Logging#logWithStackTrace(java.util.logging.Level, Throwable)}.
429 */
430 @Deprecated
431 public static void error(Throwable t, boolean stackTrace) {
432 if (stackTrace) {
433 Logging.log(Logging.LEVEL_ERROR, t);
434 } else {
435 Logging.logWithStackTrace(Logging.LEVEL_ERROR, t);
436 }
437 }
438
439 /**
440 * Prints an error message for the given Throwable.
441 * @param t The throwable object causing the error
442 * @param message additional error message
443 * @since 10420
444 * @deprecated Use {@link Logging#log(java.util.logging.Level, String, Throwable)}.
445 */
446 @Deprecated
447 public static void error(Throwable t, String message) {
448 Logging.log(Logging.LEVEL_ERROR, message, t);
449 }
450
451 /**
452 * Prints a warning message for the given Throwable.
453 * @param t The throwable object causing the error
454 * @param stackTrace {@code true}, if the stacktrace should be displayed
455 * @since 6642
456 * @deprecated Use {@link Logging#log(java.util.logging.Level, Throwable)}
457 * or {@link Logging#logWithStackTrace(java.util.logging.Level, Throwable)}.
458 */
459 @Deprecated
460 public static void warn(Throwable t, boolean stackTrace) {
461 if (stackTrace) {
462 Logging.log(Logging.LEVEL_WARN, t);
463 } else {
464 Logging.logWithStackTrace(Logging.LEVEL_WARN, t);
465 }
466 }
467
468 /**
469 * Prints a warning message for the given Throwable.
470 * @param t The throwable object causing the error
471 * @param message additional error message
472 * @since 10420
473 * @deprecated Use {@link Logging#log(java.util.logging.Level, String, Throwable)}.
474 */
475 @Deprecated
476 public static void warn(Throwable t, String message) {
477 Logging.log(Logging.LEVEL_WARN, message, t);
478 }
479
480 /**
481 * Returns a human-readable message of error, also usable for developers.
482 * @param t The error
483 * @return The human-readable error message
484 * @since 6642
485 * @deprecated Use {@link Logging#getErrorMessage}.
486 */
487 @Deprecated
488 public static String getErrorMessage(Throwable t) {
489 if (t == null) {
490 return null;
491 } else {
492 return Logging.getErrorMessage(t);
493 }
494 }
495
496 /**
497 * Platform specific code goes in here.
498 * Plugins may replace it, however, some hooks will be called before any plugins have been loeaded.
499 * So if you need to hook into those early ones, split your class and send the one with the early hooks
500 * to the JOSM team for inclusion.
501 */
502 public static volatile PlatformHook platform;
503
504 private static volatile InitStatusListener initListener;
505
506 /**
507 * Initialization task listener.
508 */
509 public interface InitStatusListener {
510
511 /**
512 * Called when an initialization task updates its status.
513 * @param event task name
514 * @return new status
515 */
516 Object updateStatus(String event);
517
518 /**
519 * Called when an initialization task completes.
520 * @param status final status
521 */
522 void finish(Object status);
523 }
524
525 /**
526 * Sets initialization task listener.
527 * @param listener initialization task listener
528 */
529 public static void setInitStatusListener(InitStatusListener listener) {
530 CheckParameterUtil.ensureParameterNotNull(listener);
531 initListener = listener;
532 }
533
534 /**
535 * Constructs new {@code Main} object.
536 * @see #initialize()
537 */
538 protected Main() {
539 setInstance(this);
540 }
541
542 private static void setInstance(Main instance) {
543 main = instance;
544 }
545
546 /**
547 * Initializes the main object. A lot of global variables are initialized here.
548 * @since 10340
549 */
550 public void initialize() {
551 // Initializes tasks that must be run before parallel tasks
552 runInitializationTasks(beforeInitializationTasks());
553
554 // Initializes tasks to be executed (in parallel) by a ExecutorService
555 try {
556 ExecutorService service = Executors.newFixedThreadPool(
557 Runtime.getRuntime().availableProcessors(), Utils.newThreadFactory("main-init-%d", Thread.NORM_PRIORITY));
558 for (Future<Void> i : service.invokeAll(parallelInitializationTasks())) {
559 i.get();
560 }
561 // asynchronous initializations to be completed eventually
562 asynchronousRunnableTasks().forEach(service::submit);
563 asynchronousCallableTasks().forEach(service::submit);
564 service.shutdown();
565 } catch (InterruptedException | ExecutionException ex) {
566 throw new JosmRuntimeException(ex);
567 }
568
569 // Initializes tasks that must be run after parallel tasks
570 runInitializationTasks(afterInitializationTasks());
571 }
572
573 private static void runInitializationTasks(List<InitializationTask> tasks) {
574 for (InitializationTask task : tasks) {
575 try {
576 task.call();
577 } catch (JosmRuntimeException e) {
578 // Can happen if the current projection needs NTV2 grid which is not available
579 // In this case we want the user be able to change his projection
580 BugReport.intercept(e).warn();
581 }
582 }
583 }
584
585 /**
586 * Returns tasks that must be run before parallel tasks.
587 * @return tasks that must be run before parallel tasks
588 * @see #afterInitializationTasks
589 * @see #parallelInitializationTasks
590 */
591 protected List<InitializationTask> beforeInitializationTasks() {
592 return Collections.emptyList();
593 }
594
595 /**
596 * Returns tasks to be executed (in parallel) by a ExecutorService.
597 * @return tasks to be executed (in parallel) by a ExecutorService
598 */
599 protected Collection<InitializationTask> parallelInitializationTasks() {
600 return Collections.emptyList();
601 }
602
603 /**
604 * Returns asynchronous callable initializations to be completed eventually
605 * @return asynchronous callable initializations to be completed eventually
606 */
607 protected List<Callable<?>> asynchronousCallableTasks() {
608 return Collections.emptyList();
609 }
610
611 /**
612 * Returns asynchronous runnable initializations to be completed eventually
613 * @return asynchronous runnable initializations to be completed eventually
614 */
615 protected List<Runnable> asynchronousRunnableTasks() {
616 return Collections.emptyList();
617 }
618
619 /**
620 * Returns tasks that must be run after parallel tasks.
621 * @return tasks that must be run after parallel tasks
622 * @see #beforeInitializationTasks
623 * @see #parallelInitializationTasks
624 */
625 protected List<InitializationTask> afterInitializationTasks() {
626 return Collections.emptyList();
627 }
628
629 /**
630 * Called once at startup to initialize the main window content.
631 * Should set {@link #menu} and {@link #panel}
632 */
633 protected abstract void initializeMainWindow();
634
635 protected static final class InitializationTask implements Callable<Void> {
636
637 private final String name;
638 private final Runnable task;
639
640 /**
641 * Constructs a new {@code InitializationTask}.
642 * @param name translated name to be displayed to user
643 * @param task runnable initialization task
644 */
645 public InitializationTask(String name, Runnable task) {
646 this.name = name;
647 this.task = task;
648 }
649
650 @Override
651 public Void call() {
652 Object status = null;
653 if (initListener != null) {
654 status = initListener.updateStatus(name);
655 }
656 task.run();
657 if (initListener != null) {
658 initListener.finish(status);
659 }
660 return null;
661 }
662 }
663
664 /**
665 * Returns the main layer manager that is used by the map view.
666 * @return The layer manager. The value returned will never change.
667 * @since 10279
668 */
669 public static MainLayerManager getLayerManager() {
670 return layerManager;
671 }
672
673 /**
674 * Replies the current selected primitives, from a end-user point of view.
675 * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}.
676 * Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned,
677 * see {@link DrawAction#getInProgressSelection()}.
678 *
679 * @return The current selected primitives, from a end-user point of view. Can be {@code null}.
680 * @since 6546
681 */
682 public Collection<OsmPrimitive> getInProgressSelection() {
683 if (map != null && map.mapMode instanceof DrawAction) {
684 return ((DrawAction) map.mapMode).getInProgressSelection();
685 } else {
686 DataSet ds = getLayerManager().getEditDataSet();
687 if (ds == null) return null;
688 return ds.getSelected();
689 }
690 }
691
692 public static void redirectToMainContentPane(JComponent source) {
693 RedirectInputMap.redirect(source, contentPanePrivate);
694 }
695
696 /**
697 * Registers a {@code JosmAction} and its shortcut.
698 * @param action action defining its own shortcut
699 */
700 public static void registerActionShortcut(JosmAction action) {
701 registerActionShortcut(action, action.getShortcut());
702 }
703
704 /**
705 * Registers an action and its shortcut.
706 * @param action action to register
707 * @param shortcut shortcut to associate to {@code action}
708 */
709 public static void registerActionShortcut(Action action, Shortcut shortcut) {
710 KeyStroke keyStroke = shortcut.getKeyStroke();
711 if (keyStroke == null)
712 return;
713
714 InputMap inputMap = contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
715 Object existing = inputMap.get(keyStroke);
716 if (existing != null && !existing.equals(action)) {
717 Logging.info(String.format("Keystroke %s is already assigned to %s, will be overridden by %s", keyStroke, existing, action));
718 }
719 inputMap.put(keyStroke, action);
720
721 contentPanePrivate.getActionMap().put(action, action);
722 }
723
724 /**
725 * Unregisters a shortcut.
726 * @param shortcut shortcut to unregister
727 */
728 public static void unregisterShortcut(Shortcut shortcut) {
729 contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(shortcut.getKeyStroke());
730 }
731
732 /**
733 * Unregisters a {@code JosmAction} and its shortcut.
734 * @param action action to unregister
735 */
736 public static void unregisterActionShortcut(JosmAction action) {
737 unregisterActionShortcut(action, action.getShortcut());
738 }
739
740 /**
741 * Unregisters an action and its shortcut.
742 * @param action action to unregister
743 * @param shortcut shortcut to unregister
744 */
745 public static void unregisterActionShortcut(Action action, Shortcut shortcut) {
746 unregisterShortcut(shortcut);
747 contentPanePrivate.getActionMap().remove(action);
748 }
749
750 /**
751 * Replies the registered action for the given shortcut
752 * @param shortcut The shortcut to look for
753 * @return the registered action for the given shortcut
754 * @since 5696
755 */
756 public static Action getRegisteredActionShortcut(Shortcut shortcut) {
757 KeyStroke keyStroke = shortcut.getKeyStroke();
758 if (keyStroke == null)
759 return null;
760 Object action = contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).get(keyStroke);
761 if (action instanceof Action)
762 return (Action) action;
763 return null;
764 }
765
766 ///////////////////////////////////////////////////////////////////////////
767 // Implementation part
768 ///////////////////////////////////////////////////////////////////////////
769
770 /**
771 * Listener that sets the enabled state of undo/redo menu entries.
772 */
773 protected final CommandQueueListener redoUndoListener = (queueSize, redoSize) -> {
774 menu.undo.setEnabled(queueSize > 0);
775 menu.redo.setEnabled(redoSize > 0);
776 };
777
778 /**
779 * Should be called before the main constructor to setup some parameter stuff
780 */
781 public static void preConstructorInit() {
782 ProjectionPreference.setProjection();
783
784 String defaultlaf = platform.getDefaultStyle();
785 String laf = LafPreference.LAF.get();
786 try {
787 UIManager.setLookAndFeel(laf);
788 } catch (final NoClassDefFoundError | ClassNotFoundException e) {
789 // Try to find look and feel in plugin classloaders
790 Logging.trace(e);
791 Class<?> klass = null;
792 for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) {
793 try {
794 klass = cl.loadClass(laf);
795 break;
796 } catch (ClassNotFoundException ex) {
797 Logging.trace(ex);
798 }
799 }
800 if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) {
801 try {
802 UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance());
803 } catch (ReflectiveOperationException ex) {
804 Logging.log(Logging.LEVEL_WARN, "Cannot set Look and Feel: " + laf + ": "+ex.getMessage(), ex);
805 } catch (UnsupportedLookAndFeelException ex) {
806 Logging.info("Look and Feel not supported: " + laf);
807 LafPreference.LAF.put(defaultlaf);
808 Logging.trace(ex);
809 }
810 } else {
811 Logging.info("Look and Feel not found: " + laf);
812 LafPreference.LAF.put(defaultlaf);
813 }
814 } catch (UnsupportedLookAndFeelException e) {
815 Logging.info("Look and Feel not supported: " + laf);
816 LafPreference.LAF.put(defaultlaf);
817 Logging.trace(e);
818 } catch (InstantiationException | IllegalAccessException e) {
819 Logging.error(e);
820 }
821 toolbar = new ToolbarPreferences();
822
823 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok"));
824 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon"));
825 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel"));
826 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon"));
827 // Ensures caret color is the same than text foreground color, see #12257
828 // See http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html
829 for (String p : Arrays.asList(
830 "EditorPane", "FormattedTextField", "PasswordField", "TextArea", "TextField", "TextPane")) {
831 UIManager.put(p+".caretForeground", UIManager.getColor(p+".foreground"));
832 }
833
834 I18n.translateJavaInternalMessages();
835
836 // init default coordinate format
837 //
838 try {
839 CoordinateFormat.setCoordinateFormat(CoordinateFormat.valueOf(Main.pref.get("coordinates")));
840 } catch (IllegalArgumentException iae) {
841 Logging.trace(iae);
842 CoordinateFormat.setCoordinateFormat(CoordinateFormat.DECIMAL_DEGREES);
843 }
844 }
845
846 /**
847 * Handle command line instructions after GUI has been initialized.
848 * @param args program arguments
849 * @return the list of submitted tasks
850 */
851 protected static List<Future<?>> postConstructorProcessCmdLine(ProgramArguments args) {
852 List<Future<?>> tasks = new ArrayList<>();
853 List<File> fileList = new ArrayList<>();
854 for (String s : args.get(Option.DOWNLOAD)) {
855 tasks.addAll(DownloadParamType.paramType(s).download(s, fileList));
856 }
857 if (!fileList.isEmpty()) {
858 tasks.add(OpenFileAction.openFiles(fileList, true));
859 }
860 for (String s : args.get(Option.DOWNLOADGPS)) {
861 tasks.addAll(DownloadParamType.paramType(s).downloadGps(s));
862 }
863 final Collection<String> selectionArguments = args.get(Option.SELECTION);
864 if (!selectionArguments.isEmpty()) {
865 tasks.add(Main.worker.submit(() -> {
866 for (String s : selectionArguments) {
867 SearchAction.search(s, SearchAction.SearchMode.add);
868 }
869 }));
870 }
871 return tasks;
872 }
873
874 /**
875 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
876 * If there are some unsaved data layers, asks first for user confirmation.
877 * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code.
878 * @param exitCode The return code
879 * @param reason the reason for exiting
880 * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation.
881 * @since 11093 (3378 with a different function signature)
882 */
883 public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) {
884 final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() ->
885 SaveLayersDialog.saveUnsavedModifications(getLayerManager().getLayers(),
886 reason != null ? reason : SaveLayersDialog.Reason.EXIT)));
887 if (proceed) {
888 if (Main.main != null) {
889 Main.main.shutdown();
890 }
891
892 if (exit) {
893 System.exit(exitCode);
894 }
895 return true;
896 }
897 return false;
898 }
899
900 /**
901 * Shutdown JOSM.
902 */
903 protected void shutdown() {
904 if (!GraphicsEnvironment.isHeadless()) {
905 worker.shutdown();
906 ImageProvider.shutdown(false);
907 JCSCacheManager.shutdown();
908 }
909 if (map != null) {
910 map.rememberToggleDialogWidth();
911 }
912 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
913 getLayerManager().resetState();
914 try {
915 pref.saveDefaults();
916 } catch (IOException ex) {
917 Logging.log(Logging.LEVEL_WARN, tr("Failed to save default preferences."), ex);
918 }
919 if (!GraphicsEnvironment.isHeadless()) {
920 worker.shutdownNow();
921 ImageProvider.shutdown(true);
922 }
923 }
924
925 /**
926 * The type of a command line parameter, to be used in switch statements.
927 * @see #paramType
928 */
929 enum DownloadParamType {
930 httpUrl {
931 @Override
932 List<Future<?>> download(String s, Collection<File> fileList) {
933 return new OpenLocationAction().openUrl(false, s);
934 }
935
936 @Override
937 List<Future<?>> downloadGps(String s) {
938 final Bounds b = OsmUrlToBounds.parse(s);
939 if (b == null) {
940 JOptionPane.showMessageDialog(
941 Main.parent,
942 tr("Ignoring malformed URL: \"{0}\"", s),
943 tr("Warning"),
944 JOptionPane.WARNING_MESSAGE
945 );
946 return Collections.emptyList();
947 }
948 return downloadFromParamBounds(true, b);
949 }
950 }, fileUrl {
951 @Override
952 List<Future<?>> download(String s, Collection<File> fileList) {
953 File f = null;
954 try {
955 f = new File(new URI(s));
956 } catch (URISyntaxException e) {
957 Logging.warn(e);
958 JOptionPane.showMessageDialog(
959 Main.parent,
960 tr("Ignoring malformed file URL: \"{0}\"", s),
961 tr("Warning"),
962 JOptionPane.WARNING_MESSAGE
963 );
964 }
965 if (f != null) {
966 fileList.add(f);
967 }
968 return Collections.emptyList();
969 }
970 }, bounds {
971
972 /**
973 * Download area specified on the command line as bounds string.
974 * @param rawGps Flag to download raw GPS tracks
975 * @param s The bounds parameter
976 * @return the complete download task (including post-download handler), or {@code null}
977 */
978 private List<Future<?>> downloadFromParamBounds(final boolean rawGps, String s) {
979 final StringTokenizer st = new StringTokenizer(s, ",");
980 if (st.countTokens() == 4) {
981 return Main.downloadFromParamBounds(rawGps, new Bounds(
982 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())),
983 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()))
984 ));
985 }
986 return Collections.emptyList();
987 }
988
989 @Override
990 List<Future<?>> download(String param, Collection<File> fileList) {
991 return downloadFromParamBounds(false, param);
992 }
993
994 @Override
995 List<Future<?>> downloadGps(String param) {
996 return downloadFromParamBounds(true, param);
997 }
998 }, fileName {
999 @Override
1000 List<Future<?>> download(String s, Collection<File> fileList) {
1001 fileList.add(new File(s));
1002 return Collections.emptyList();
1003 }
1004 };
1005
1006 /**
1007 * Performs the download
1008 * @param param represents the object to be downloaded
1009 * @param fileList files which shall be opened, should be added to this collection
1010 * @return the download task, or {@code null}
1011 */
1012 abstract List<Future<?>> download(String param, Collection<File> fileList);
1013
1014 /**
1015 * Performs the GPS download
1016 * @param param represents the object to be downloaded
1017 * @return the download task, or {@code null}
1018 */
1019 List<Future<?>> downloadGps(String param) {
1020 if (!GraphicsEnvironment.isHeadless()) {
1021 JOptionPane.showMessageDialog(
1022 Main.parent,
1023 tr("Parameter \"downloadgps\" does not accept file names or file URLs"),
1024 tr("Warning"),
1025 JOptionPane.WARNING_MESSAGE
1026 );
1027 }
1028 return Collections.emptyList();
1029 }
1030
1031 /**
1032 * Guess the type of a parameter string specified on the command line with --download= or --downloadgps.
1033 *
1034 * @param s A parameter string
1035 * @return The guessed parameter type
1036 */
1037 static DownloadParamType paramType(String s) {
1038 if (s.startsWith("http:") || s.startsWith("https:")) return DownloadParamType.httpUrl;
1039 if (s.startsWith("file:")) return DownloadParamType.fileUrl;
1040 String coorPattern = "\\s*[+-]?[0-9]+(\\.[0-9]+)?\\s*";
1041 if (s.matches(coorPattern + "(," + coorPattern + "){3}")) return DownloadParamType.bounds;
1042 // everything else must be a file name
1043 return DownloadParamType.fileName;
1044 }
1045 }
1046
1047 /**
1048 * Download area specified as Bounds value.
1049 * @param rawGps Flag to download raw GPS tracks
1050 * @param b The bounds value
1051 * @return the complete download task (including post-download handler)
1052 */
1053 private static List<Future<?>> downloadFromParamBounds(final boolean rawGps, Bounds b) {
1054 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask();
1055 // asynchronously launch the download task ...
1056 Future<?> future = task.download(true, b, null);
1057 // ... and the continuation when the download is finished (this will wait for the download to finish)
1058 return Collections.singletonList(Main.worker.submit(new PostDownloadHandler(task, future)));
1059 }
1060
1061 /**
1062 * Identifies the current operating system family and initializes the platform hook accordingly.
1063 * @since 1849
1064 */
1065 public static void determinePlatformHook() {
1066 String os = System.getProperty("os.name");
1067 if (os == null) {
1068 Logging.warn("Your operating system has no name, so I'm guessing its some kind of *nix.");
1069 platform = new PlatformHookUnixoid();
1070 } else if (os.toLowerCase(Locale.ENGLISH).startsWith("windows")) {
1071 platform = new PlatformHookWindows();
1072 } else if ("Linux".equals(os) || "Solaris".equals(os) ||
1073 "SunOS".equals(os) || "AIX".equals(os) ||
1074 "FreeBSD".equals(os) || "NetBSD".equals(os) || "OpenBSD".equals(os)) {
1075 platform = new PlatformHookUnixoid();
1076 } else if (os.toLowerCase(Locale.ENGLISH).startsWith("mac os x")) {
1077 platform = new PlatformHookOsx();
1078 } else {
1079 Logging.warn("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix.");
1080 platform = new PlatformHookUnixoid();
1081 }
1082 }
1083
1084 /* ----------------------------------------------------------------------------------------- */
1085 /* projection handling - Main is a registry for a single, global projection instance */
1086 /* */
1087 /* TODO: For historical reasons the registry is implemented by Main. An alternative approach */
1088 /* would be a singleton org.openstreetmap.josm.data.projection.ProjectionRegistry class. */
1089 /* ----------------------------------------------------------------------------------------- */
1090 /**
1091 * The projection method used.
1092 * use {@link #getProjection()} and {@link #setProjection(Projection)} for access.
1093 * Use {@link #setProjection(Projection)} in order to trigger a projection change event.
1094 */
1095 private static volatile Projection proj;
1096
1097 /**
1098 * Replies the current projection.
1099 *
1100 * @return the currently active projection
1101 */
1102 public static Projection getProjection() {
1103 return proj;
1104 }
1105
1106 /**
1107 * Sets the current projection
1108 *
1109 * @param p the projection
1110 */
1111 public static void setProjection(Projection p) {
1112 CheckParameterUtil.ensureParameterNotNull(p);
1113 Projection oldValue = proj;
1114 Bounds b = isDisplayingMapView() ? map.mapView.getRealBounds() : null;
1115 proj = p;
1116 fireProjectionChanged(oldValue, proj, b);
1117 }
1118
1119 /*
1120 * Keep WeakReferences to the listeners. This relieves clients from the burden of
1121 * explicitly removing the listeners and allows us to transparently register every
1122 * created dataset as projection change listener.
1123 */
1124 private static final List<WeakReference<ProjectionChangeListener>> listeners = new ArrayList<>();
1125
1126 private static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds) {
1127 if ((newValue == null ^ oldValue == null)
1128 || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
1129 synchronized (Main.class) {
1130 Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
1131 while (it.hasNext()) {
1132 WeakReference<ProjectionChangeListener> wr = it.next();
1133 ProjectionChangeListener listener = wr.get();
1134 if (listener == null) {
1135 it.remove();
1136 continue;
1137 }
1138 listener.projectionChanged(oldValue, newValue);
1139 }
1140 }
1141 if (newValue != null && oldBounds != null) {
1142 MainApplication.getMap().mapView.zoomTo(oldBounds);
1143 }
1144 /* TODO - remove layers with fixed projection */
1145 }
1146 }
1147
1148 /**
1149 * Register a projection change listener.
1150 * The listener is registered to be weak, so keep a reference of it if you want it to be preserved.
1151 *
1152 * @param listener the listener. Ignored if <code>null</code>.
1153 */
1154 public static void addProjectionChangeListener(ProjectionChangeListener listener) {
1155 if (listener == null) return;
1156 synchronized (Main.class) {
1157 for (WeakReference<ProjectionChangeListener> wr : listeners) {
1158 // already registered ? => abort
1159 if (wr.get() == listener) return;
1160 }
1161 listeners.add(new WeakReference<>(listener));
1162 }
1163 }
1164
1165 /**
1166 * Removes a projection change listener.
1167 *
1168 * @param listener the listener. Ignored if <code>null</code>.
1169 */
1170 public static void removeProjectionChangeListener(ProjectionChangeListener listener) {
1171 if (listener == null) return;
1172 synchronized (Main.class) {
1173 // remove the listener - and any other listener which got garbage
1174 // collected in the meantime
1175 listeners.removeIf(wr -> wr.get() == null || wr.get() == listener);
1176 }
1177 }
1178
1179 /**
1180 * Listener for window switch events.
1181 *
1182 * These are events, when the user activates a window of another application
1183 * or comes back to JOSM. Window switches from one JOSM window to another
1184 * are not reported.
1185 */
1186 public interface WindowSwitchListener {
1187 /**
1188 * Called when the user activates a window of another application.
1189 */
1190 void toOtherApplication();
1191
1192 /**
1193 * Called when the user comes from a window of another application back to JOSM.
1194 */
1195 void fromOtherApplication();
1196 }
1197
1198 /**
1199 * Registers a new {@code MapFrameListener} that will be notified of MapFrame changes.
1200 * <p>
1201 * It will fire an initial mapFrameInitialized event when the MapFrame is present.
1202 * Otherwise will only fire when the MapFrame is created or destroyed.
1203 * @param listener The MapFrameListener
1204 * @return {@code true} if the listeners collection changed as a result of the call
1205 * @see #addMapFrameListener
1206 * @since 11904
1207 */
1208 public static boolean addAndFireMapFrameListener(MapFrameListener listener) {
1209 return mainPanel != null && mainPanel.addAndFireMapFrameListener(listener);
1210 }
1211
1212 /**
1213 * Registers a new {@code MapFrameListener} that will be notified of MapFrame changes
1214 * @param listener The MapFrameListener
1215 * @return {@code true} if the listeners collection changed as a result of the call
1216 * @see #addAndFireMapFrameListener
1217 * @since 5957
1218 */
1219 public static boolean addMapFrameListener(MapFrameListener listener) {
1220 return mainPanel != null && mainPanel.addMapFrameListener(listener);
1221 }
1222
1223 /**
1224 * Unregisters the given {@code MapFrameListener} from MapFrame changes
1225 * @param listener The MapFrameListener
1226 * @return {@code true} if the listeners collection changed as a result of the call
1227 * @since 5957
1228 */
1229 public static boolean removeMapFrameListener(MapFrameListener listener) {
1230 return mainPanel != null && mainPanel.removeMapFrameListener(listener);
1231 }
1232
1233 /**
1234 * Adds a new network error that occur to give a hint about broken Internet connection.
1235 * Do not use this method for errors known for sure thrown because of a bad proxy configuration.
1236 *
1237 * @param url The accessed URL that caused the error
1238 * @param t The network error
1239 * @return The previous error associated to the given resource, if any. Can be {@code null}
1240 * @since 6642
1241 */
1242 public static Throwable addNetworkError(URL url, Throwable t) {
1243 if (url != null && t != null) {
1244 Throwable old = addNetworkError(url.toExternalForm(), t);
1245 if (old != null) {
1246 Logging.warn("Already here "+old);
1247 }
1248 return old;
1249 }
1250 return null;
1251 }
1252
1253 /**
1254 * Adds a new network error that occur to give a hint about broken Internet connection.
1255 * Do not use this method for errors known for sure thrown because of a bad proxy configuration.
1256 *
1257 * @param url The accessed URL that caused the error
1258 * @param t The network error
1259 * @return The previous error associated to the given resource, if any. Can be {@code null}
1260 * @since 6642
1261 */
1262 public static Throwable addNetworkError(String url, Throwable t) {
1263 if (url != null && t != null) {
1264 return NETWORK_ERRORS.put(url, t);
1265 }
1266 return null;
1267 }
1268
1269 /**
1270 * Returns the network errors that occured until now.
1271 * @return the network errors that occured until now, indexed by URL
1272 * @since 6639
1273 */
1274 public static Map<String, Throwable> getNetworkErrors() {
1275 return new HashMap<>(NETWORK_ERRORS);
1276 }
1277
1278 /**
1279 * Clears the network errors cache.
1280 * @since 12011
1281 */
1282 public static void clearNetworkErrors() {
1283 NETWORK_ERRORS.clear();
1284 }
1285
1286 /**
1287 * Returns the JOSM website URL.
1288 * @return the josm website URL
1289 * @since 6897
1290 */
1291 public static String getJOSMWebsite() {
1292 if (Main.pref != null)
1293 return Main.pref.get("josm.url", JOSM_WEBSITE);
1294 return JOSM_WEBSITE;
1295 }
1296
1297 /**
1298 * Returns the JOSM XML URL.
1299 * @return the josm XML URL
1300 * @since 6897
1301 */
1302 public static String getXMLBase() {
1303 // Always return HTTP (issues reported with HTTPS)
1304 return "http://josm.openstreetmap.de";
1305 }
1306
1307 /**
1308 * Returns the OSM website URL.
1309 * @return the OSM website URL
1310 * @since 6897
1311 */
1312 public static String getOSMWebsite() {
1313 if (Main.pref != null)
1314 return Main.pref.get("osm.url", OSM_WEBSITE);
1315 return OSM_WEBSITE;
1316 }
1317
1318 /**
1319 * Returns the OSM website URL depending on the selected {@link OsmApi}.
1320 * @return the OSM website URL depending on the selected {@link OsmApi}
1321 */
1322 private static String getOSMWebsiteDependingOnSelectedApi() {
1323 final String api = OsmApi.getOsmApi().getServerUrl();
1324 if (OsmApi.DEFAULT_API_URL.equals(api)) {
1325 return getOSMWebsite();
1326 } else {
1327 return api.replaceAll("/api$", "");
1328 }
1329 }
1330
1331 /**
1332 * Replies the base URL for browsing information about a primitive.
1333 * @return the base URL, i.e. https://www.openstreetmap.org
1334 * @since 7678
1335 */
1336 public static String getBaseBrowseUrl() {
1337 if (Main.pref != null)
1338 return Main.pref.get("osm-browse.url", getOSMWebsiteDependingOnSelectedApi());
1339 return getOSMWebsiteDependingOnSelectedApi();
1340 }
1341
1342 /**
1343 * Replies the base URL for browsing information about a user.
1344 * @return the base URL, i.e. https://www.openstreetmap.org/user
1345 * @since 7678
1346 */
1347 public static String getBaseUserUrl() {
1348 if (Main.pref != null)
1349 return Main.pref.get("osm-user.url", getOSMWebsiteDependingOnSelectedApi() + "/user");
1350 return getOSMWebsiteDependingOnSelectedApi() + "/user";
1351 }
1352
1353 /**
1354 * Determines if we are currently running on OSX.
1355 * @return {@code true} if we are currently running on OSX
1356 * @since 6957
1357 */
1358 public static boolean isPlatformOsx() {
1359 return Main.platform instanceof PlatformHookOsx;
1360 }
1361
1362 /**
1363 * Determines if we are currently running on Windows.
1364 * @return {@code true} if we are currently running on Windows
1365 * @since 7335
1366 */
1367 public static boolean isPlatformWindows() {
1368 return Main.platform instanceof PlatformHookWindows;
1369 }
1370
1371 /**
1372 * Determines if the given online resource is currently offline.
1373 * @param r the online resource
1374 * @return {@code true} if {@code r} is offline and should not be accessed
1375 * @since 7434
1376 */
1377 public static boolean isOffline(OnlineResource r) {
1378 return OFFLINE_RESOURCES.contains(r) || OFFLINE_RESOURCES.contains(OnlineResource.ALL);
1379 }
1380
1381 /**
1382 * Sets the given online resource to offline state.
1383 * @param r the online resource
1384 * @return {@code true} if {@code r} was not already offline
1385 * @since 7434
1386 */
1387 public static boolean setOffline(OnlineResource r) {
1388 return OFFLINE_RESOURCES.add(r);
1389 }
1390
1391 /**
1392 * Sets the given online resource to online state.
1393 * @param r the online resource
1394 * @return {@code true} if {@code r} was offline
1395 * @since 8506
1396 */
1397 public static boolean setOnline(OnlineResource r) {
1398 return OFFLINE_RESOURCES.remove(r);
1399 }
1400
1401 /**
1402 * Replies the set of online resources currently offline.
1403 * @return the set of online resources currently offline
1404 * @since 7434
1405 */
1406 public static Set<OnlineResource> getOfflineResources() {
1407 return EnumSet.copyOf(OFFLINE_RESOURCES);
1408 }
1409}
Note: See TracBrowser for help on using the repository browser.