Changeset 12636 in josm for trunk/src/org/openstreetmap/josm/gui/MainApplication.java
- Timestamp:
- 2017-08-24T22:53:50+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12634 r12636 63 63 import org.openstreetmap.josm.data.Bounds; 64 64 import org.openstreetmap.josm.data.Version; 65 import org.openstreetmap.josm.data.osm.DataSet; 65 66 import org.openstreetmap.josm.data.osm.OsmPrimitive; 66 67 import org.openstreetmap.josm.data.validation.OsmValidator; … … 69 70 import org.openstreetmap.josm.gui.download.DownloadDialog; 70 71 import org.openstreetmap.josm.gui.io.CustomConfigurator.XMLCommandProcessor; 72 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 71 73 import org.openstreetmap.josm.gui.layer.AutosaveTask; 74 import org.openstreetmap.josm.gui.layer.MainLayerManager; 72 75 import org.openstreetmap.josm.gui.layer.TMSLayer; 73 76 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; … … 78 81 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 79 82 import org.openstreetmap.josm.gui.util.GuiHelper; 83 import org.openstreetmap.josm.gui.util.RedirectInputMap; 80 84 import org.openstreetmap.josm.io.CertificateAmendment; 81 85 import org.openstreetmap.josm.io.DefaultProxySelector; … … 134 138 135 139 /** 140 * Provides access to the layers displayed in the main view. 141 */ 142 private static final MainLayerManager layerManager = new MainLayerManager(); 143 144 /** 136 145 * Constructs a new {@code MainApplication} without a window. 137 146 */ … … 228 237 } else { 229 238 // required for running some tests. 230 panel = new MainPanel(Main.getLayerManager()); 239 panel = new MainPanel(MainApplication.getLayerManager()); 231 240 menu = new MainMenu(); 232 241 } … … 246 255 map.rememberToggleDialogWidth(); 247 256 } 257 // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask) 258 getLayerManager().resetState(); 248 259 super.shutdown(); 249 260 if (!GraphicsEnvironment.isHeadless()) { … … 264 275 } 265 276 277 /** 278 * Replies the current selected primitives, from a end-user point of view. 279 * It is not always technically the same collection of primitives than {@link DataSet#getSelected()}. 280 * Indeed, if the user is currently in drawing mode, only the way currently being drawn is returned, 281 * see {@link DrawAction#getInProgressSelection()}. 282 * 283 * @return The current selected primitives, from a end-user point of view. Can be {@code null}. 284 * @since 6546 285 */ 266 286 @Override 267 287 public Collection<OsmPrimitive> getInProgressSelection() { … … 269 289 return ((DrawAction) map.mapMode).getInProgressSelection(); 270 290 } else { 271 return super.getInProgressSelection(); 291 DataSet ds = getLayerManager().getEditDataSet(); 292 if (ds == null) return null; 293 return ds.getSelected(); 272 294 } 273 295 } … … 280 302 public static List<String> getCommandLineArgs() { 281 303 return Collections.unmodifiableList(COMMAND_LINE_ARGS); 304 } 305 306 /** 307 * Returns the main layer manager that is used by the map view. 308 * @return The layer manager. The value returned will never change. 309 * @since 12636 (as a replacement to {@code MainApplication.getLayerManager()}) 310 */ 311 @SuppressWarnings("deprecation") 312 public static MainLayerManager getLayerManager() { 313 return layerManager; 282 314 } 283 315 … … 306 338 public static boolean isDisplayingMapView() { 307 339 return map != null && map.mapView != null; 340 } 341 342 /** 343 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM). 344 * If there are some unsaved data layers, asks first for user confirmation. 345 * @param exit If {@code true}, the JVM is terminated by running {@link System#exit} with a given return code. 346 * @param exitCode The return code 347 * @param reason the reason for exiting 348 * @return {@code true} if JOSM has been closed, {@code false} if the user has cancelled the operation. 349 * @since 12636 (specialized version of {@link Main#exitJosm}) 350 */ 351 public static boolean exitJosm(boolean exit, int exitCode, SaveLayersDialog.Reason reason) { 352 final boolean proceed = Boolean.TRUE.equals(GuiHelper.runInEDTAndWaitAndReturn(() -> 353 SaveLayersDialog.saveUnsavedModifications(MainApplication.getLayerManager().getLayers(), 354 reason != null ? reason : SaveLayersDialog.Reason.EXIT))); 355 if (proceed) { 356 return Main.exitJosm(exit, exitCode); 357 } 358 return false; 359 } 360 361 public static void redirectToMainContentPane(JComponent source) { 362 RedirectInputMap.redirect(source, contentPanePrivate); 308 363 } 309 364
Note:
See TracChangeset
for help on using the changeset viewer.
