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.tools.ImageProvider;
|
---|
12 | import org.openstreetmap.josm.tools.Logging;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * JOSM termination sequence.
|
---|
16 | * @since 14140
|
---|
17 | */
|
---|
18 | public class MainTermination implements Runnable {
|
---|
19 |
|
---|
20 | @Override
|
---|
21 | public void run() {
|
---|
22 | try {
|
---|
23 | MainApplication.worker.shutdown();
|
---|
24 | } catch (SecurityException e) {
|
---|
25 | Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e);
|
---|
26 | }
|
---|
27 | JCSCacheManager.shutdown();
|
---|
28 |
|
---|
29 | if (MainApplication.getMainFrame() != null) {
|
---|
30 | MainApplication.getMainFrame().storeState();
|
---|
31 | }
|
---|
32 | if (MainApplication.getMap() != null) {
|
---|
33 | MainApplication.getMap().rememberToggleDialogWidth();
|
---|
34 | }
|
---|
35 | // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
|
---|
36 | MainApplication.getLayerManager().resetState();
|
---|
37 | ImageProvider.shutdown(false);
|
---|
38 | try {
|
---|
39 | Preferences.main().saveDefaults();
|
---|
40 | } catch (IOException | InvalidPathException ex) {
|
---|
41 | Logging.log(Logging.LEVEL_WARN, tr("Failed to save default preferences."), ex);
|
---|
42 | }
|
---|
43 | ImageProvider.shutdown(true);
|
---|
44 |
|
---|
45 | try {
|
---|
46 | // in case the current task still hasn't finished
|
---|
47 | MainApplication.worker.shutdownNow();
|
---|
48 | } catch (SecurityException e) {
|
---|
49 | Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e);
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|