Ignore:
Timestamp:
2017-08-24T22:53:50+02:00 (9 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate Main.getLayerManager(). Replacement: gui.MainApplication.getLayerManager()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12634 r12636  
    6363import org.openstreetmap.josm.data.Bounds;
    6464import org.openstreetmap.josm.data.Version;
     65import org.openstreetmap.josm.data.osm.DataSet;
    6566import org.openstreetmap.josm.data.osm.OsmPrimitive;
    6667import org.openstreetmap.josm.data.validation.OsmValidator;
     
    6970import org.openstreetmap.josm.gui.download.DownloadDialog;
    7071import org.openstreetmap.josm.gui.io.CustomConfigurator.XMLCommandProcessor;
     72import org.openstreetmap.josm.gui.io.SaveLayersDialog;
    7173import org.openstreetmap.josm.gui.layer.AutosaveTask;
     74import org.openstreetmap.josm.gui.layer.MainLayerManager;
    7275import org.openstreetmap.josm.gui.layer.TMSLayer;
    7376import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
     
    7881import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    7982import org.openstreetmap.josm.gui.util.GuiHelper;
     83import org.openstreetmap.josm.gui.util.RedirectInputMap;
    8084import org.openstreetmap.josm.io.CertificateAmendment;
    8185import org.openstreetmap.josm.io.DefaultProxySelector;
     
    134138
    135139    /**
     140     * Provides access to the layers displayed in the main view.
     141     */
     142    private static final MainLayerManager layerManager = new MainLayerManager();
     143
     144    /**
    136145     * Constructs a new {@code MainApplication} without a window.
    137146     */
     
    228237        } else {
    229238            // required for running some tests.
    230             panel = new MainPanel(Main.getLayerManager());
     239            panel = new MainPanel(MainApplication.getLayerManager());
    231240            menu = new MainMenu();
    232241        }
     
    246255            map.rememberToggleDialogWidth();
    247256        }
     257        // Remove all layers because somebody may rely on layerRemoved events (like AutosaveTask)
     258        getLayerManager().resetState();
    248259        super.shutdown();
    249260        if (!GraphicsEnvironment.isHeadless()) {
     
    264275    }
    265276
     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     */
    266286    @Override
    267287    public Collection<OsmPrimitive> getInProgressSelection() {
     
    269289            return ((DrawAction) map.mapMode).getInProgressSelection();
    270290        } else {
    271             return super.getInProgressSelection();
     291            DataSet ds = getLayerManager().getEditDataSet();
     292            if (ds == null) return null;
     293            return ds.getSelected();
    272294        }
    273295    }
     
    280302    public static List<String> getCommandLineArgs() {
    281303        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;
    282314    }
    283315
     
    306338    public static boolean isDisplayingMapView() {
    307339        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);
    308363    }
    309364
Note: See TracChangeset for help on using the changeset viewer.