Don't show preview sources, unless expert preference has been modified

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-06-26 07:58:34 -06:00
rodzic aa4d2d58cc
commit 97dc67abc1
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 28 dodań i 5 usunięć

Wyświetl plik

@ -17,7 +17,7 @@ import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
/**
* The category for a MapWithAI source
* The category for a MapWithAI source (i.e., buildings/highways/addresses/etc.)
*
* @author Taylor Smock
*
@ -29,7 +29,7 @@ public enum MapWithAICategory implements ISourceCategory<MapWithAICategory> {
ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")),
POWER("presets/power/pole", "pole", marktr("Power")), PRESET("dialogs/search", "presets", marktr("Presets")),
FEATURED("presets/service/network-wireless.svg", "featured", marktr("Featured")),
OTHER(null, "other", marktr("Other"));
PREVIEW("presets/misc/fixme", "preview", marktr("Preview")), OTHER(null, "other", marktr("Other"));
private static final Map<ImageSizes, Map<MapWithAICategory, ImageIcon>> iconCache = Collections
.synchronizedMap(new EnumMap<>(ImageSizes.class));

Wyświetl plik

@ -17,9 +17,11 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
import org.openstreetmap.josm.data.StructUtils;
import org.openstreetmap.josm.data.imagery.ImageryInfo;
import org.openstreetmap.josm.data.preferences.BooleanProperty;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.PleaseWaitRunnable;
import org.openstreetmap.josm.gui.util.GuiHelper;
@ -38,6 +40,10 @@ import org.openstreetmap.josm.tools.Utils;
* Manages the list of imagery entries that are shown in the imagery menu.
*/
public class MapWithAILayerInfo {
/**
* A boolean preference used to determine if preview datasets should be shown
*/
private static final BooleanProperty SHOW_PREVIEW = new BooleanProperty("mapwithai.sources.preview", false);
/** List of all usable layers */
private final List<MapWithAIInfo> layers = Collections.synchronizedList(new ArrayList<>());
@ -456,7 +462,7 @@ public class MapWithAILayerInfo {
* @return unmodifiable list containing usable layers
*/
public List<MapWithAIInfo> getLayers() {
return Collections.unmodifiableList(layers);
return Collections.unmodifiableList(filterPreview(layers));
}
/**
@ -465,7 +471,7 @@ public class MapWithAILayerInfo {
* @return unmodifiable list containing available default layers
*/
public List<MapWithAIInfo> getDefaultLayers() {
return Collections.unmodifiableList(defaultLayers);
return Collections.unmodifiableList(filterPreview(defaultLayers));
}
/**
@ -475,7 +481,24 @@ public class MapWithAILayerInfo {
* @since 11570
*/
public List<MapWithAIInfo> getAllDefaultLayers() {
return Collections.unmodifiableList(allDefaultLayers);
return Collections.unmodifiableList(filterPreview(allDefaultLayers));
}
/**
* Remove preview layers, if {@link SHOW_PREVIEW} is not {@code true}
*
* @param layers The layers to filter
* @return The layers without any preview layers, if {@link SHOW_PREVIEW} is not
* {@code true}.
*/
private static List<MapWithAIInfo> filterPreview(List<MapWithAIInfo> layers) {
if (SHOW_PREVIEW.get()) {
return layers;
}
return layers.stream()
.filter(i -> i.getCategory() != MapWithAICategory.PREVIEW
&& !i.getAdditionalCategories().contains(MapWithAICategory.PREVIEW))
.collect(Collectors.toList());
}
public static void addLayer(MapWithAIInfo info) {