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

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

see #15182 - remove last calls to Main.map

  • Property svn:eol-style set to native
File size: 50.4 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 MainApplication.isDisplayingMapView();
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 DataSet ds = getLayerManager().getEditDataSet();
684 if (ds == null) return null;
685 return ds.getSelected();
686 }
687
688 public static void redirectToMainContentPane(JComponent source) {
689 RedirectInputMap.redirect(source, contentPanePrivate);
690 }
691
692 /**
693 * Registers a {@code JosmAction} and its shortcut.
694 * @param action action defining its own shortcut
695 */
696 public static void registerActionShortcut(JosmAction action) {
697 registerActionShortcut(action, action.getShortcut());
698 }
699
700 /**
701 * Registers an action and its shortcut.
702 * @param action action to register
703 * @param shortcut shortcut to associate to {@code action}
704 */
705 public static void registerActionShortcut(Action action, Shortcut shortcut) {
706 KeyStroke keyStroke = shortcut.getKeyStroke();
707 if (keyStroke == null)
708 return;
709
710 InputMap inputMap = contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
711 Object existing = inputMap.get(keyStroke);
712 if (existing != null && !existing.equals(action)) {
713 Logging.info(String.format("Keystroke %s is already assigned to %s, will be overridden by %s", keyStroke, existing, action));
714 }
715 inputMap.put(keyStroke, action);
716
717 contentPanePrivate.getActionMap().put(action, action);
718 }
719
720 /**
721 * Unregisters a shortcut.
722 * @param shortcut shortcut to unregister
723 */
724 public static void unregisterShortcut(Shortcut shortcut) {
725 contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(shortcut.getKeyStroke());
726 }
727
728 /**
729 * Unregisters a {@code JosmAction} and its shortcut.
730 * @param action action to unregister
731 */
732 public static void unregisterActionShortcut(JosmAction action) {
733 unregisterActionShortcut(action, action.getShortcut());
734 }
735
736 /**
737 * Unregisters an action and its shortcut.
738 * @param action action to unregister
739 * @param shortcut shortcut to unregister
740 */
741 public static void unregisterActionShortcut(Action action, Shortcut shortcut) {
742 unregisterShortcut(shortcut);
743 contentPanePrivate.getActionMap().remove(action);
744 }
745
746 /**
747 * Replies the registered action for the given shortcut
748 * @param shortcut The shortcut to look for
749 * @return the registered action for the given shortcut
750 * @since 5696
751 */
752 public static Action getRegisteredActionShortcut(Shortcut shortcut) {
753 KeyStroke keyStroke = shortcut.getKeyStroke();
754 if (keyStroke == null)
755 return null;
756 Object action = contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).get(keyStroke);
757 if (action instanceof Action)
758 return (Action) action;
759 return null;
760 }
761
762 ///////////////////////////////////////////////////////////////////////////
763 // Implementation part
764 ///////////////////////////////////////////////////////////////////////////
765
766 /**
767 * Listener that sets the enabled state of undo/redo menu entries.
768 */
769 protected final CommandQueueListener redoUndoListener = (queueSize, redoSize) -> {
770 menu.undo.setEnabled(queueSize > 0);
771 menu.redo.setEnabled(redoSize > 0);
772 };
773
774 /**
775 * Should be called before the main constructor to setup some parameter stuff
776 */
777 public static void preConstructorInit() {
778 ProjectionPreference.setProjection();
779
780 String defaultlaf = platform.getDefaultStyle();
781 String laf = LafPreference.LAF.get();
782 try {
783 UIManager.setLookAndFeel(laf);
784 } catch (final NoClassDefFoundError | ClassNotFoundException e) {
785 // Try to find look and feel in plugin classloaders
786 Logging.trace(e);
787 Class<?> klass = null;
788 for (ClassLoader cl : PluginHandler.getResourceClassLoaders()) {
789 try {
790 klass = cl.loadClass(laf);
791 break;
792 } catch (ClassNotFoundException ex) {
793 Logging.trace(ex);
794 }
795 }
796 if (klass != null && LookAndFeel.class.isAssignableFrom(klass)) {
797 try {
798 UIManager.setLookAndFeel((LookAndFeel) klass.getConstructor().newInstance());
799 } catch (ReflectiveOperationException ex) {
800 Logging.log(Logging.LEVEL_WARN, "Cannot set Look and Feel: " + laf + ": "+ex.getMessage(), ex);
801 } catch (UnsupportedLookAndFeelException ex) {
802 Logging.info("Look and Feel not supported: " + laf);
803 LafPreference.LAF.put(defaultlaf);
804 Logging.trace(ex);
805 }
806 } else {
807 Logging.info("Look and Feel not found: " + laf);
808 LafPreference.LAF.put(defaultlaf);
809 }
810 } catch (UnsupportedLookAndFeelException e) {
811 Logging.info("Look and Feel not supported: " + laf);
812 LafPreference.LAF.put(defaultlaf);
813 Logging.trace(e);
814 } catch (InstantiationException | IllegalAccessException e) {
815 Logging.error(e);
816 }
817 toolbar = new ToolbarPreferences();
818
819 UIManager.put("OptionPane.okIcon", ImageProvider.get("ok"));
820 UIManager.put("OptionPane.yesIcon", UIManager.get("OptionPane.okIcon"));
821 UIManager.put("OptionPane.cancelIcon", ImageProvider.get("cancel"));
822 UIManager.put("OptionPane.noIcon", UIManager.get("OptionPane.cancelIcon"));
823 // Ensures caret color is the same than text foreground color, see #12257
824 // See http://docs.oracle.com/javase/8/docs/api/javax/swing/plaf/synth/doc-files/componentProperties.html
825 for (String p : Arrays.asList(
826 "EditorPane", "FormattedTextField", "PasswordField", "TextArea", "TextField", "TextPane")) {
827 UIManager.put(p+".caretForeground", UIManager.getColor(p+".foreground"));
828 }
829
830 I18n.translateJavaInternalMessages();
831
832 // init default coordinate format
833 //
834 try {
835 CoordinateFormat.setCoordinateFormat(CoordinateFormat.valueOf(Main.pref.get("coordinates")));
836 } catch (IllegalArgumentException iae) {
837 Logging.trace(iae);
838 CoordinateFormat.setCoordinateFormat(CoordinateFormat.DECIMAL_DEGREES);
839 }
840 }
841
842 /**
843 * Handle command line instructions after GUI has been initialized.
844 * @param args program arguments
845 * @return the list of submitted tasks
846 */
847 protected static List<Future<?>> postConstructorProcessCmdLine(ProgramArguments args) {
848 List<Future<?>> tasks = new ArrayList<>();
849 List<File> fileList = new ArrayList<>();
850 for (String s : args.get(Option.DOWNLOAD)) {
851 tasks.addAll(DownloadParamType.paramType(s).download(s, fileList));
852 }
853 if (!fileList.isEmpty()) {
854 tasks.add(OpenFileAction.openFiles(fileList, true));
855 }
856 for (String s : args.get(Option.DOWNLOADGPS)) {
857 tasks.addAll(DownloadParamType.paramType(s).downloadGps(s));
858 }
859 final Collection<String> selectionArguments = args.get(Option.SELECTION);
860 if (!selectionArguments.isEmpty()) {
861 tasks.add(Main.worker.submit(() -> {
862 for (String s : selectionArguments) {
863 SearchAction.search(s, SearchAction.SearchMode.add);
864 }
865 }));
866 }
867 return tasks;
868 }
869
870 /**
871 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM).
872 * If there are some unsaved data layers, asks first for user confirmation.
873 * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code.
874 * @param exitCode The return code
875 * @param reason the reason for exiting
876 * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation.
877 * @since 11093 (3378 with a different function signature)
878 */
879 public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) {
880 final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() ->
881 SaveLayersDialog.saveUnsavedModifications(getLayerManager().getLayers(),
882 reason != null ? reason : SaveLayersDialog.Reason.EXIT)));
883 if (proceed) {
884 if (Main.main != null) {
885 Main.main.shutdown();
886 }
887
888 if (exit) {
889 System.exit(exitCode);
890 }
891 return true;
892 }
893 return false;
894 }
895
896 /**
897 * Shutdown JOSM.
898 */
899 protected void shutdown() {
900 if (!GraphicsEnvironment.isHeadless()) {
901 worker.shutdown();
902 ImageProvider.shutdown(false);
903 JCSCacheManager.shutdown();
904 }
905 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
906 getLayerManager().resetState();
907 try {
908 pref.saveDefaults();
909 } catch (IOException ex) {
910 Logging.log(Logging.LEVEL_WARN, tr("Failed to save default preferences."), ex);
911 }
912 if (!GraphicsEnvironment.isHeadless()) {
913 worker.shutdownNow();
914 ImageProvider.shutdown(true);
915 }
916 }
917
918 /**
919 * The type of a command line parameter, to be used in switch statements.
920 * @see #paramType
921 */
922 enum DownloadParamType {
923 httpUrl {
924 @Override
925 List<Future<?>> download(String s, Collection<File> fileList) {
926 return new OpenLocationAction().openUrl(false, s);
927 }
928
929 @Override
930 List<Future<?>> downloadGps(String s) {
931 final Bounds b = OsmUrlToBounds.parse(s);
932 if (b == null) {
933 JOptionPane.showMessageDialog(
934 Main.parent,
935 tr("Ignoring malformed URL: \"{0}\"", s),
936 tr("Warning"),
937 JOptionPane.WARNING_MESSAGE
938 );
939 return Collections.emptyList();
940 }
941 return downloadFromParamBounds(true, b);
942 }
943 }, fileUrl {
944 @Override
945 List<Future<?>> download(String s, Collection<File> fileList) {
946 File f = null;
947 try {
948 f = new File(new URI(s));
949 } catch (URISyntaxException e) {
950 Logging.warn(e);
951 JOptionPane.showMessageDialog(
952 Main.parent,
953 tr("Ignoring malformed file URL: \"{0}\"", s),
954 tr("Warning"),
955 JOptionPane.WARNING_MESSAGE
956 );
957 }
958 if (f != null) {
959 fileList.add(f);
960 }
961 return Collections.emptyList();
962 }
963 }, bounds {
964
965 /**
966 * Download area specified on the command line as bounds string.
967 * @param rawGps Flag to download raw GPS tracks
968 * @param s The bounds parameter
969 * @return the complete download task (including post-download handler), or {@code null}
970 */
971 private List<Future<?>> downloadFromParamBounds(final boolean rawGps, String s) {
972 final StringTokenizer st = new StringTokenizer(s, ",");
973 if (st.countTokens() == 4) {
974 return Main.downloadFromParamBounds(rawGps, new Bounds(
975 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())),
976 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()))
977 ));
978 }
979 return Collections.emptyList();
980 }
981
982 @Override
983 List<Future<?>> download(String param, Collection<File> fileList) {
984 return downloadFromParamBounds(false, param);
985 }
986
987 @Override
988 List<Future<?>> downloadGps(String param) {
989 return downloadFromParamBounds(true, param);
990 }
991 }, fileName {
992 @Override
993 List<Future<?>> download(String s, Collection<File> fileList) {
994 fileList.add(new File(s));
995 return Collections.emptyList();
996 }
997 };
998
999 /**
1000 * Performs the download
1001 * @param param represents the object to be downloaded
1002 * @param fileList files which shall be opened, should be added to this collection
1003 * @return the download task, or {@code null}
1004 */
1005 abstract List<Future<?>> download(String param, Collection<File> fileList);
1006
1007 /**
1008 * Performs the GPS download
1009 * @param param represents the object to be downloaded
1010 * @return the download task, or {@code null}
1011 */
1012 List<Future<?>> downloadGps(String param) {
1013 if (!GraphicsEnvironment.isHeadless()) {
1014 JOptionPane.showMessageDialog(
1015 Main.parent,
1016 tr("Parameter \"downloadgps\" does not accept file names or file URLs"),
1017 tr("Warning"),
1018 JOptionPane.WARNING_MESSAGE
1019 );
1020 }
1021 return Collections.emptyList();
1022 }
1023
1024 /**
1025 * Guess the type of a parameter string specified on the command line with --download= or --downloadgps.
1026 *
1027 * @param s A parameter string
1028 * @return The guessed parameter type
1029 */
1030 static DownloadParamType paramType(String s) {
1031 if (s.startsWith("http:") || s.startsWith("https:")) return DownloadParamType.httpUrl;
1032 if (s.startsWith("file:")) return DownloadParamType.fileUrl;
1033 String coorPattern = "\\s*[+-]?[0-9]+(\\.[0-9]+)?\\s*";
1034 if (s.matches(coorPattern + "(," + coorPattern + "){3}")) return DownloadParamType.bounds;
1035 // everything else must be a file name
1036 return DownloadParamType.fileName;
1037 }
1038 }
1039
1040 /**
1041 * Download area specified as Bounds value.
1042 * @param rawGps Flag to download raw GPS tracks
1043 * @param b The bounds value
1044 * @return the complete download task (including post-download handler)
1045 */
1046 private static List<Future<?>> downloadFromParamBounds(final boolean rawGps, Bounds b) {
1047 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask();
1048 // asynchronously launch the download task ...
1049 Future<?> future = task.download(true, b, null);
1050 // ... and the continuation when the download is finished (this will wait for the download to finish)
1051 return Collections.singletonList(Main.worker.submit(new PostDownloadHandler(task, future)));
1052 }
1053
1054 /**
1055 * Identifies the current operating system family and initializes the platform hook accordingly.
1056 * @since 1849
1057 */
1058 public static void determinePlatformHook() {
1059 String os = System.getProperty("os.name");
1060 if (os == null) {
1061 Logging.warn("Your operating system has no name, so I'm guessing its some kind of *nix.");
1062 platform = new PlatformHookUnixoid();
1063 } else if (os.toLowerCase(Locale.ENGLISH).startsWith("windows")) {
1064 platform = new PlatformHookWindows();
1065 } else if ("Linux".equals(os) || "Solaris".equals(os) ||
1066 "SunOS".equals(os) || "AIX".equals(os) ||
1067 "FreeBSD".equals(os) || "NetBSD".equals(os) || "OpenBSD".equals(os)) {
1068 platform = new PlatformHookUnixoid();
1069 } else if (os.toLowerCase(Locale.ENGLISH).startsWith("mac os x")) {
1070 platform = new PlatformHookOsx();
1071 } else {
1072 Logging.warn("I don't know your operating system '"+os+"', so I'm guessing its some kind of *nix.");
1073 platform = new PlatformHookUnixoid();
1074 }
1075 }
1076
1077 /* ----------------------------------------------------------------------------------------- */
1078 /* projection handling - Main is a registry for a single, global projection instance */
1079 /* */
1080 /* TODO: For historical reasons the registry is implemented by Main. An alternative approach */
1081 /* would be a singleton org.openstreetmap.josm.data.projection.ProjectionRegistry class. */
1082 /* ----------------------------------------------------------------------------------------- */
1083 /**
1084 * The projection method used.
1085 * Use {@link #getProjection()} and {@link #setProjection(Projection)} for access.
1086 * Use {@link #setProjection(Projection)} in order to trigger a projection change event.
1087 */
1088 private static volatile Projection proj;
1089
1090 /**
1091 * Replies the current projection.
1092 *
1093 * @return the currently active projection
1094 */
1095 public static Projection getProjection() {
1096 return proj;
1097 }
1098
1099 /**
1100 * Sets the current projection
1101 *
1102 * @param p the projection
1103 */
1104 public static void setProjection(Projection p) {
1105 CheckParameterUtil.ensureParameterNotNull(p);
1106 Projection oldValue = proj;
1107 Bounds b = main != null ? main.getRealBounds() : null;
1108 proj = p;
1109 fireProjectionChanged(oldValue, proj, b);
1110 }
1111
1112 /**
1113 * Returns the bounds for the current projection. Used for projection events.
1114 * @return the bounds for the current projection
1115 * @see #restoreOldBounds
1116 */
1117 protected Bounds getRealBounds() {
1118 // To be overriden
1119 return null;
1120 }
1121
1122 /**
1123 * Restore clean state corresponding to old bounds after a projection change event.
1124 * @param oldBounds bounds previously returned by {@link #getRealBounds}, before the change of projection
1125 * @see #getRealBounds
1126 */
1127 protected void restoreOldBounds(Bounds oldBounds) {
1128 // To be overriden
1129 }
1130
1131 /*
1132 * Keep WeakReferences to the listeners. This relieves clients from the burden of
1133 * explicitly removing the listeners and allows us to transparently register every
1134 * created dataset as projection change listener.
1135 */
1136 private static final List<WeakReference<ProjectionChangeListener>> listeners = new ArrayList<>();
1137
1138 private static void fireProjectionChanged(Projection oldValue, Projection newValue, Bounds oldBounds) {
1139 if ((newValue == null ^ oldValue == null)
1140 || (newValue != null && oldValue != null && !Objects.equals(newValue.toCode(), oldValue.toCode()))) {
1141 synchronized (Main.class) {
1142 Iterator<WeakReference<ProjectionChangeListener>> it = listeners.iterator();
1143 while (it.hasNext()) {
1144 WeakReference<ProjectionChangeListener> wr = it.next();
1145 ProjectionChangeListener listener = wr.get();
1146 if (listener == null) {
1147 it.remove();
1148 continue;
1149 }
1150 listener.projectionChanged(oldValue, newValue);
1151 }
1152 }
1153 if (newValue != null && oldBounds != null && main != null) {
1154 main.restoreOldBounds(oldBounds);
1155 }
1156 /* TODO - remove layers with fixed projection */
1157 }
1158 }
1159
1160 /**
1161 * Register a projection change listener.
1162 * The listener is registered to be weak, so keep a reference of it if you want it to be preserved.
1163 *
1164 * @param listener the listener. Ignored if <code>null</code>.
1165 */
1166 public static void addProjectionChangeListener(ProjectionChangeListener listener) {
1167 if (listener == null) return;
1168 synchronized (Main.class) {
1169 for (WeakReference<ProjectionChangeListener> wr : listeners) {
1170 // already registered ? => abort
1171 if (wr.get() == listener) return;
1172 }
1173 listeners.add(new WeakReference<>(listener));
1174 }
1175 }
1176
1177 /**
1178 * Removes a projection change listener.
1179 *
1180 * @param listener the listener. Ignored if <code>null</code>.
1181 */
1182 public static void removeProjectionChangeListener(ProjectionChangeListener listener) {
1183 if (listener == null) return;
1184 synchronized (Main.class) {
1185 // remove the listener - and any other listener which got garbage
1186 // collected in the meantime
1187 listeners.removeIf(wr -> wr.get() == null || wr.get() == listener);
1188 }
1189 }
1190
1191 /**
1192 * Listener for window switch events.
1193 *
1194 * These are events, when the user activates a window of another application
1195 * or comes back to JOSM. Window switches from one JOSM window to another
1196 * are not reported.
1197 */
1198 public interface WindowSwitchListener {
1199 /**
1200 * Called when the user activates a window of another application.
1201 */
1202 void toOtherApplication();
1203
1204 /**
1205 * Called when the user comes from a window of another application back to JOSM.
1206 */
1207 void fromOtherApplication();
1208 }
1209
1210 /**
1211 * Registers a new {@code MapFrameListener} that will be notified of MapFrame changes.
1212 * <p>
1213 * It will fire an initial mapFrameInitialized event when the MapFrame is present.
1214 * Otherwise will only fire when the MapFrame is created or destroyed.
1215 * @param listener The MapFrameListener
1216 * @return {@code true} if the listeners collection changed as a result of the call
1217 * @see #addMapFrameListener
1218 * @since 11904
1219 */
1220 public static boolean addAndFireMapFrameListener(MapFrameListener listener) {
1221 return mainPanel != null && mainPanel.addAndFireMapFrameListener(listener);
1222 }
1223
1224 /**
1225 * Registers a new {@code MapFrameListener} that will be notified of MapFrame changes
1226 * @param listener The MapFrameListener
1227 * @return {@code true} if the listeners collection changed as a result of the call
1228 * @see #addAndFireMapFrameListener
1229 * @since 5957
1230 */
1231 public static boolean addMapFrameListener(MapFrameListener listener) {
1232 return mainPanel != null && mainPanel.addMapFrameListener(listener);
1233 }
1234
1235 /**
1236 * Unregisters the given {@code MapFrameListener} from MapFrame changes
1237 * @param listener The MapFrameListener
1238 * @return {@code true} if the listeners collection changed as a result of the call
1239 * @since 5957
1240 */
1241 public static boolean removeMapFrameListener(MapFrameListener listener) {
1242 return mainPanel != null && mainPanel.removeMapFrameListener(listener);
1243 }
1244
1245 /**
1246 * Adds a new network error that occur to give a hint about broken Internet connection.
1247 * Do not use this method for errors known for sure thrown because of a bad proxy configuration.
1248 *
1249 * @param url The accessed URL that caused the error
1250 * @param t The network error
1251 * @return The previous error associated to the given resource, if any. Can be {@code null}
1252 * @since 6642
1253 */
1254 public static Throwable addNetworkError(URL url, Throwable t) {
1255 if (url != null && t != null) {
1256 Throwable old = addNetworkError(url.toExternalForm(), t);
1257 if (old != null) {
1258 Logging.warn("Already here "+old);
1259 }
1260 return old;
1261 }
1262 return null;
1263 }
1264
1265 /**
1266 * Adds a new network error that occur to give a hint about broken Internet connection.
1267 * Do not use this method for errors known for sure thrown because of a bad proxy configuration.
1268 *
1269 * @param url The accessed URL that caused the error
1270 * @param t The network error
1271 * @return The previous error associated to the given resource, if any. Can be {@code null}
1272 * @since 6642
1273 */
1274 public static Throwable addNetworkError(String url, Throwable t) {
1275 if (url != null && t != null) {
1276 return NETWORK_ERRORS.put(url, t);
1277 }
1278 return null;
1279 }
1280
1281 /**
1282 * Returns the network errors that occured until now.
1283 * @return the network errors that occured until now, indexed by URL
1284 * @since 6639
1285 */
1286 public static Map<String, Throwable> getNetworkErrors() {
1287 return new HashMap<>(NETWORK_ERRORS);
1288 }
1289
1290 /**
1291 * Clears the network errors cache.
1292 * @since 12011
1293 */
1294 public static void clearNetworkErrors() {
1295 NETWORK_ERRORS.clear();
1296 }
1297
1298 /**
1299 * Returns the JOSM website URL.
1300 * @return the josm website URL
1301 * @since 6897
1302 */
1303 public static String getJOSMWebsite() {
1304 if (Main.pref != null)
1305 return Main.pref.get("josm.url", JOSM_WEBSITE);
1306 return JOSM_WEBSITE;
1307 }
1308
1309 /**
1310 * Returns the JOSM XML URL.
1311 * @return the josm XML URL
1312 * @since 6897
1313 */
1314 public static String getXMLBase() {
1315 // Always return HTTP (issues reported with HTTPS)
1316 return "http://josm.openstreetmap.de";
1317 }
1318
1319 /**
1320 * Returns the OSM website URL.
1321 * @return the OSM website URL
1322 * @since 6897
1323 */
1324 public static String getOSMWebsite() {
1325 if (Main.pref != null)
1326 return Main.pref.get("osm.url", OSM_WEBSITE);
1327 return OSM_WEBSITE;
1328 }
1329
1330 /**
1331 * Returns the OSM website URL depending on the selected {@link OsmApi}.
1332 * @return the OSM website URL depending on the selected {@link OsmApi}
1333 */
1334 private static String getOSMWebsiteDependingOnSelectedApi() {
1335 final String api = OsmApi.getOsmApi().getServerUrl();
1336 if (OsmApi.DEFAULT_API_URL.equals(api)) {
1337 return getOSMWebsite();
1338 } else {
1339 return api.replaceAll("/api$", "");
1340 }
1341 }
1342
1343 /**
1344 * Replies the base URL for browsing information about a primitive.
1345 * @return the base URL, i.e. https://www.openstreetmap.org
1346 * @since 7678
1347 */
1348 public static String getBaseBrowseUrl() {
1349 if (Main.pref != null)
1350 return Main.pref.get("osm-browse.url", getOSMWebsiteDependingOnSelectedApi());
1351 return getOSMWebsiteDependingOnSelectedApi();
1352 }
1353
1354 /**
1355 * Replies the base URL for browsing information about a user.
1356 * @return the base URL, i.e. https://www.openstreetmap.org/user
1357 * @since 7678
1358 */
1359 public static String getBaseUserUrl() {
1360 if (Main.pref != null)
1361 return Main.pref.get("osm-user.url", getOSMWebsiteDependingOnSelectedApi() + "/user");
1362 return getOSMWebsiteDependingOnSelectedApi() + "/user";
1363 }
1364
1365 /**
1366 * Determines if we are currently running on OSX.
1367 * @return {@code true} if we are currently running on OSX
1368 * @since 6957
1369 */
1370 public static boolean isPlatformOsx() {
1371 return Main.platform instanceof PlatformHookOsx;
1372 }
1373
1374 /**
1375 * Determines if we are currently running on Windows.
1376 * @return {@code true} if we are currently running on Windows
1377 * @since 7335
1378 */
1379 public static boolean isPlatformWindows() {
1380 return Main.platform instanceof PlatformHookWindows;
1381 }
1382
1383 /**
1384 * Determines if the given online resource is currently offline.
1385 * @param r the online resource
1386 * @return {@code true} if {@code r} is offline and should not be accessed
1387 * @since 7434
1388 */
1389 public static boolean isOffline(OnlineResource r) {
1390 return OFFLINE_RESOURCES.contains(r) || OFFLINE_RESOURCES.contains(OnlineResource.ALL);
1391 }
1392
1393 /**
1394 * Sets the given online resource to offline state.
1395 * @param r the online resource
1396 * @return {@code true} if {@code r} was not already offline
1397 * @since 7434
1398 */
1399 public static boolean setOffline(OnlineResource r) {
1400 return OFFLINE_RESOURCES.add(r);
1401 }
1402
1403 /**
1404 * Sets the given online resource to online state.
1405 * @param r the online resource
1406 * @return {@code true} if {@code r} was offline
1407 * @since 8506
1408 */
1409 public static boolean setOnline(OnlineResource r) {
1410 return OFFLINE_RESOURCES.remove(r);
1411 }
1412
1413 /**
1414 * Replies the set of online resources currently offline.
1415 * @return the set of online resources currently offline
1416 * @since 7434
1417 */
1418 public static Set<OnlineResource> getOfflineResources() {
1419 return EnumSet.copyOf(OFFLINE_RESOURCES);
1420 }
1421}
Note: See TracBrowser for help on using the repository browser.