1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm;
|
---|
3 |
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.Optional;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.actions.mapmode.DrawAction;
|
---|
9 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
10 | import org.openstreetmap.josm.gui.MapFrame;
|
---|
11 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Global OSM dataset registry.
|
---|
15 | * @since 14143
|
---|
16 | */
|
---|
17 | public final class OsmDataManager implements IOsmDataManager {
|
---|
18 |
|
---|
19 | private OsmDataManager() {
|
---|
20 | // hide constructor
|
---|
21 | }
|
---|
22 |
|
---|
23 | private static class InstanceHolder {
|
---|
24 | static final OsmDataManager INSTANCE = new OsmDataManager();
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * Returns the unique instance.
|
---|
29 | * @return the unique instance
|
---|
30 | */
|
---|
31 | public static OsmDataManager getInstance() {
|
---|
32 | return InstanceHolder.INSTANCE;
|
---|
33 | }
|
---|
34 |
|
---|
35 | @Override
|
---|
36 | public Collection<OsmPrimitive> getInProgressSelection() {
|
---|
37 | MapFrame map = MainApplication.getMap();
|
---|
38 | if (map != null && map.mapMode instanceof DrawAction) {
|
---|
39 | return ((DrawAction) map.mapMode).getInProgressSelection();
|
---|
40 | } else {
|
---|
41 | DataSet ds = MainApplication.getLayerManager().getActiveDataSet();
|
---|
42 | if (ds == null) return Collections.emptyList();
|
---|
43 | return ds.getSelected();
|
---|
44 | }
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public Collection<? extends IPrimitive> getInProgressISelection() {
|
---|
49 | MapFrame map = MainApplication.getMap();
|
---|
50 | if (map != null && map.mapMode instanceof DrawAction) {
|
---|
51 | return ((DrawAction) map.mapMode).getInProgressSelection();
|
---|
52 | } else {
|
---|
53 | OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
|
---|
54 | if (ds == null) return Collections.emptyList();
|
---|
55 | return ds.getSelected();
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Override
|
---|
60 | public DataSet getEditDataSet() {
|
---|
61 | return MainApplication.getLayerManager().getEditDataSet();
|
---|
62 | }
|
---|
63 |
|
---|
64 | @Override
|
---|
65 | public DataSet getActiveDataSet() {
|
---|
66 | return MainApplication.getLayerManager().getActiveDataSet();
|
---|
67 | }
|
---|
68 |
|
---|
69 | @Override
|
---|
70 | public void setActiveDataSet(DataSet ds) {
|
---|
71 | Optional<OsmDataLayer> layer = MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream()
|
---|
72 | .filter(l -> l.data.equals(ds)).findFirst();
|
---|
73 | layer.ifPresent(osmDataLayer -> MainApplication.getLayerManager().setActiveLayer(osmDataLayer));
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public boolean containsDataSet(DataSet ds) {
|
---|
78 | return MainApplication.getLayerManager().getLayersOfType(OsmDataLayer.class).stream().anyMatch(l -> l.data.equals(ds));
|
---|
79 | }
|
---|
80 | }
|
---|