- Timestamp:
- 2018-08-12T13:08:27+02:00 (6 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r14139 r14140 2 2 package org.openstreetmap.josm; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr;5 6 4 import java.awt.Component; 7 import java.io.IOException;8 5 import java.net.URL; 9 import java.nio.file.InvalidPathException;10 6 import java.util.Collection; 11 7 import java.util.Collections; … … 15 11 import org.openstreetmap.josm.data.Preferences; 16 12 import org.openstreetmap.josm.data.UndoRedoHandler; 17 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager;18 import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat;19 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat;20 13 import org.openstreetmap.josm.data.osm.DataSet; 21 14 import org.openstreetmap.josm.data.osm.IPrimitive; … … 29 22 import org.openstreetmap.josm.io.NetworkManager; 30 23 import org.openstreetmap.josm.io.OnlineResource; 24 import org.openstreetmap.josm.spi.lifecycle.Lifecycle; 31 25 import org.openstreetmap.josm.spi.preferences.Config; 32 26 import org.openstreetmap.josm.spi.preferences.IUrls; 33 import org.openstreetmap.josm.tools.ImageProvider;34 import org.openstreetmap.josm.tools.Logging;35 27 import org.openstreetmap.josm.tools.PlatformHook; 36 28 import org.openstreetmap.josm.tools.PlatformManager; … … 148 140 149 141 /** 150 * Should be called before the main constructor to setup some parameter stuff151 */152 public static void preConstructorInit() {153 // init default coordinate format154 ICoordinateFormat fmt = CoordinateFormatManager.getCoordinateFormat(Config.getPref().get("coordinates"));155 if (fmt == null) {156 fmt = DecimalDegreesCoordinateFormat.INSTANCE;157 }158 CoordinateFormatManager.setCoordinateFormat(fmt);159 }160 161 /**162 142 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM). 163 143 * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code. … … 165 145 * @return {@code true} 166 146 * @since 12636 167 */ 147 * @deprecated Use {@link Lifecycle#exitJosm} 148 */ 149 @Deprecated 168 150 public static boolean exitJosm(boolean exit, int exitCode) { 169 if (Main.main != null) { 170 Main.main.shutdown(); 171 } 172 173 if (exit) { 174 System.exit(exitCode); 175 } 176 return true; 177 } 178 179 /** 180 * Shutdown JOSM. 181 */ 182 protected void shutdown() { 183 ImageProvider.shutdown(false); 184 try { 185 pref.saveDefaults(); 186 } catch (IOException | InvalidPathException ex) { 187 Logging.log(Logging.LEVEL_WARN, tr("Failed to save default preferences."), ex); 188 } 189 ImageProvider.shutdown(true); 151 return Lifecycle.exitJosm(exit, exitCode); 190 152 } 191 153 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r14139 r14140 87 87 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; 88 88 import org.openstreetmap.josm.data.Version; 89 import org.openstreetmap.josm.data.cache.JCSCacheManager;90 89 import org.openstreetmap.josm.data.oauth.OAuthAccessTokenHolder; 91 90 import org.openstreetmap.josm.data.osm.DataSet; … … 347 346 getLayerManager().addLayerChangeListener(undoRedoCleaner); 348 347 ProjectionRegistry.setboundsProvider(mainBoundsProvider); 348 Lifecycle.setShutdownSequence(new MainTermination(this)); 349 349 } 350 350 … … 409 409 } 410 410 411 @Override 412 protected void shutdown() { 413 try { 414 worker.shutdown(); 415 } catch (SecurityException e) { 416 Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e); 417 } 418 JCSCacheManager.shutdown(); 419 420 if (mainFrame != null) { 421 mainFrame.storeState(); 422 } 423 if (map != null) { 424 map.rememberToggleDialogWidth(); 425 } 426 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) 427 layerManager.resetState(); 428 super.shutdown(); 429 430 try { 431 // in case the current task still hasn't finished 432 worker.shutdownNow(); 433 } catch (SecurityException e) { 434 Logging.log(Logging.LEVEL_ERROR, "Unable to shutdown worker", e); 435 } 411 /** 412 * Returns the JOSM main frame. 413 * @return the JOSM main frame 414 * @since 14140 415 */ 416 public final MainFrame getMainFrame() { 417 return mainFrame; 436 418 } 437 419 … … 566 548 reason != null ? reason : SaveLayersDialog.Reason.EXIT))); 567 549 if (proceed) { 568 return Main.exitJosm(exit, exitCode);550 return Lifecycle.exitJosm(exit, exitCode); 569 551 } 570 552 return false; … … 980 962 setupNadGridSources(); 981 963 GuiHelper.translateJavaInternalMessages(); 982 preConstructorInit();983 964 984 965 monitor.indeterminateSubTask(tr("Creating main GUI")); -
trunk/src/org/openstreetmap/josm/gui/MainInitialization.java
r14139 r14140 14 14 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 15 15 import org.openstreetmap.josm.data.UndoRedoHandler; 16 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 17 import org.openstreetmap.josm.data.coor.conversion.DecimalDegreesCoordinateFormat; 18 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat; 16 19 import org.openstreetmap.josm.data.validation.OsmValidator; 17 20 import org.openstreetmap.josm.gui.layer.ImageryLayer; … … 28 31 import org.openstreetmap.josm.spi.lifecycle.InitializationSequence; 29 32 import org.openstreetmap.josm.spi.lifecycle.InitializationTask; 33 import org.openstreetmap.josm.spi.preferences.Config; 30 34 import org.openstreetmap.josm.tools.I18n; 31 35 import org.openstreetmap.josm.tools.Logging; … … 57 61 public List<InitializationTask> beforeInitializationTasks() { 58 62 return Arrays.asList( 63 new InitializationTask(tr("Initializing coordinate format"), () -> { 64 ICoordinateFormat fmt = CoordinateFormatManager.getCoordinateFormat(Config.getPref().get("coordinates")); 65 if (fmt == null) { 66 fmt = DecimalDegreesCoordinateFormat.INSTANCE; 67 } 68 CoordinateFormatManager.setCoordinateFormat(fmt); 69 }), 59 70 new InitializationTask(tr("Starting file watcher"), FileWatcher.getDefaultInstance()::start), 60 71 new InitializationTask(tr("Executing platform startup hook"), -
trunk/src/org/openstreetmap/josm/spi/lifecycle/Lifecycle.java
r14139 r14140 9 9 import java.util.concurrent.Future; 10 10 11 import org.openstreetmap.josm.tools.JosmRuntimeException; 11 12 import org.openstreetmap.josm.tools.Logging; 12 13 import org.openstreetmap.josm.tools.Utils; … … 20 21 21 22 private static volatile InitStatusListener initStatusListener; 23 24 private static volatile Runnable shutdownSequence; 22 25 23 26 private Lifecycle() { … … 39 42 public static void setInitStatusListener(InitStatusListener listener) { 40 43 initStatusListener = Objects.requireNonNull(listener); 44 } 45 46 /** 47 * Gets shutdown sequence. 48 * @return shutdown sequence 49 * @since 14140 50 */ 51 public static Runnable getShutdownSequence() { 52 return shutdownSequence; 53 } 54 55 /** 56 * Sets shutdown sequence. 57 * @param sequence shutdown sequence. Must not be null 58 * @since 14140 59 */ 60 public static void setShutdownSequence(Runnable sequence) { 61 shutdownSequence = Objects.requireNonNull(sequence); 41 62 } 42 63 … … 66 87 } 67 88 } catch (InterruptedException | ExecutionException ex) { 68 throw new RuntimeException(ex);89 throw new JosmRuntimeException(ex); 69 90 } 70 91 … … 77 98 try { 78 99 task.call(); 79 } catch ( RuntimeException e) {100 } catch (JosmRuntimeException e) { 80 101 // Can happen if the current projection needs NTV2 grid which is not available 81 102 // In this case we want the user be able to change his projection … … 84 105 } 85 106 } 107 108 /** 109 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM). 110 * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code. 111 * @param exitCode The return code 112 * @return {@code true} 113 * @since 14140 114 */ 115 public static boolean exitJosm(boolean exit, int exitCode) { 116 if (shutdownSequence != null) { 117 shutdownSequence.run(); 118 } 119 120 if (exit) { 121 System.exit(exitCode); 122 } 123 return true; 124 } 86 125 }
Note:
See TracChangeset
for help on using the changeset viewer.