1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.nio.file.InvalidPathException;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.Preferences;
|
---|
10 | import org.openstreetmap.josm.data.cache.JCSCacheManager;
|
---|
11 | import org.openstreetmap.josm.io.ChangesetUpdater;
|
---|
12 | import org.openstreetmap.josm.io.MessageNotifier;
|
---|
13 | import org.openstreetmap.josm.io.remotecontrol.RemoteControl;
|
---|
14 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
15 | import org.openstreetmap.josm.tools.Logging;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * JOSM termination sequence.
|
---|
19 | * @since 14140
|
---|
20 | */
|
---|
21 | public class MainTermination implements Runnable {
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public void run() {
|
---|
25 | ChangesetUpdater.stop();
|
---|
26 | MessageNotifier.stop();
|
---|
27 | RemoteControl.stop();
|
---|
28 |
|
---|
29 | try {
|
---|
30 | MainApplication.worker.shutdown();
|
---|
31 | } catch (SecurityException e) {
|
---|
32 | Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e);
|
---|
33 | }
|
---|
34 | JCSCacheManager.shutdown();
|
---|
35 |
|
---|
36 | if (MainApplication.getMainFrame() != null) {
|
---|
37 | MainApplication.getMainFrame().storeState();
|
---|
38 | }
|
---|
39 | if (MainApplication.getMap() != null) {
|
---|
40 | MainApplication.getMap().rememberToggleDialogWidth();
|
---|
41 | }
|
---|
42 | // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
|
---|
43 | MainApplication.getLayerManager().resetState();
|
---|
44 | ImageProvider.shutdown(false);
|
---|
45 | try {
|
---|
46 | Preferences.main().saveDefaults();
|
---|
47 | } catch (IOException | InvalidPathException ex) {
|
---|
48 | Logging.log(Logging.LEVEL_WARN, tr("Failed to save default preferences."), ex);
|
---|
49 | }
|
---|
50 | ImageProvider.shutdown(true);
|
---|
51 |
|
---|
52 | try {
|
---|
53 | // in case the current task still hasn't finished
|
---|
54 | MainApplication.worker.shutdownNow();
|
---|
55 | } catch (SecurityException e) {
|
---|
56 | Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e);
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|