kopia lustrzana https://github.com/JOSM/MapWithAI
Decrease allocations from listing the layers
Signed-off-by: Taylor Smock <tsmock@meta.com>pull/35/head v810
rodzic
a2372c6e49
commit
dd3cb880a6
|
@ -648,6 +648,16 @@ public class MapWithAIInfo extends
|
|||
return this.categories != null ? Collections.unmodifiableList(this.categories) : Collections.emptyList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this layer has a specified category
|
||||
*
|
||||
* @param category The category to look for
|
||||
* @return {@code true} if this layer has the specified category
|
||||
*/
|
||||
public boolean hasCategory(MapWithAICategory category) {
|
||||
return this.category == category || (this.categories != null && this.categories.contains(category));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the key that indicates an object is already conflated, and if so, to what
|
||||
*
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.util.concurrent.ForkJoinPool;
|
|||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo;
|
||||
import org.openstreetmap.josm.actions.ExpertToggleAction;
|
||||
|
@ -32,6 +31,7 @@ import org.openstreetmap.josm.data.Preferences;
|
|||
import org.openstreetmap.josm.data.StructUtils;
|
||||
import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
||||
import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
||||
import org.openstreetmap.josm.data.preferences.CachingProperty;
|
||||
import org.openstreetmap.josm.gui.MainApplication;
|
||||
import org.openstreetmap.josm.gui.PleaseWaitRunnable;
|
||||
import org.openstreetmap.josm.gui.util.GuiHelper;
|
||||
|
@ -55,7 +55,8 @@ public class MapWithAILayerInfo {
|
|||
/**
|
||||
* A boolean preference used to determine if preview datasets should be shown
|
||||
*/
|
||||
public static final BooleanProperty SHOW_PREVIEW = new BooleanProperty("mapwithai.sources.preview", false);
|
||||
public static final CachingProperty<Boolean> SHOW_PREVIEW = new BooleanProperty("mapwithai.sources.preview", false)
|
||||
.cached();
|
||||
|
||||
/** Finish listeners */
|
||||
private ListenerList<FinishListener> finishListenerListenerList = ListenerList.create();
|
||||
|
@ -612,13 +613,25 @@ public class MapWithAILayerInfo {
|
|||
* not {@code true}.
|
||||
*/
|
||||
private static List<MapWithAIInfo> filterPreview(List<MapWithAIInfo> layers) {
|
||||
if (Boolean.TRUE.equals(SHOW_PREVIEW.get()) && ExpertToggleAction.isExpert()) {
|
||||
return layers;
|
||||
final var newList = new ArrayList<>(layers);
|
||||
newList.removeIf(MapWithAILayerInfo::isFiltered);
|
||||
return newList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the layer should be filtered out
|
||||
*
|
||||
* @param info The layer to check
|
||||
* @return {@code true} if the layer should be filtered
|
||||
*/
|
||||
public static boolean isFiltered(MapWithAIInfo info) {
|
||||
if (info == null || !info.hasValidUrl()) {
|
||||
return true;
|
||||
}
|
||||
return layers.stream()
|
||||
.filter(i -> i.getCategory() != MapWithAICategory.PREVIEW
|
||||
&& !i.getAdditionalCategories().contains(MapWithAICategory.PREVIEW))
|
||||
.filter(MapWithAIInfo::hasValidUrl).collect(Collectors.toList());
|
||||
if (ExpertToggleAction.isExpert() && Boolean.TRUE.equals(SHOW_PREVIEW.get())) {
|
||||
return false;
|
||||
}
|
||||
return info.hasCategory(MapWithAICategory.PREVIEW);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -4,6 +4,13 @@ package org.openstreetmap.josm.plugins.mapwithai.gui;
|
|||
import static org.openstreetmap.josm.tools.I18n.tr;
|
||||
import static org.openstreetmap.josm.tools.I18n.trc;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.event.MenuEvent;
|
||||
import javax.swing.event.MenuListener;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.MenuComponent;
|
||||
|
@ -16,14 +23,6 @@ import java.util.EnumMap;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.event.MenuEvent;
|
||||
import javax.swing.event.MenuListener;
|
||||
|
||||
import org.openstreetmap.josm.actions.JosmAction;
|
||||
import org.openstreetmap.josm.data.coor.LatLon;
|
||||
|
@ -31,7 +30,6 @@ import org.openstreetmap.josm.data.imagery.Shape;
|
|||
import org.openstreetmap.josm.data.sources.SourceInfo;
|
||||
import org.openstreetmap.josm.gui.ImageryMenu;
|
||||
import org.openstreetmap.josm.gui.MainApplication;
|
||||
import org.openstreetmap.josm.gui.MapView;
|
||||
import org.openstreetmap.josm.gui.MenuScroller;
|
||||
import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference;
|
||||
import org.openstreetmap.josm.plugins.mapwithai.actions.AddMapWithAILayerAction;
|
||||
|
@ -138,12 +136,12 @@ public class MapWithAIMenu extends JMenu {
|
|||
// list all imagery entries where the current map location is within the imagery
|
||||
// bounds
|
||||
if (MainApplication.isDisplayingMapView()) {
|
||||
MapView mv = MainApplication.getMap().mapView;
|
||||
LatLon pos = mv.getProjection().eastNorth2latlon(mv.getCenter());
|
||||
final List<MapWithAIInfo> inViewLayers = MapWithAILayerInfo.getInstance().getAllDefaultLayers().stream()
|
||||
final var mv = MainApplication.getMap().mapView;
|
||||
final var pos = mv.getProjection().eastNorth2latlon(mv.getCenter());
|
||||
final var inViewLayers = MapWithAILayerInfo.getInstance().getAllDefaultLayers().stream()
|
||||
.filter(i -> i.getBounds() != null && i.getBounds().contains(pos) && !alreadyInUse.contains(i)
|
||||
&& !savedLayers.contains(i) && isPosInOneShapeIfAny(i, pos))
|
||||
.sorted(alphabeticSourceComparator).collect(Collectors.toList());
|
||||
.sorted(alphabeticSourceComparator).toList();
|
||||
if (!inViewLayers.isEmpty()) {
|
||||
if (inViewLayers.stream().anyMatch(i -> i.getCategory() == i.getCategory().getDefault())) {
|
||||
addDynamicSeparator();
|
||||
|
|
Ładowanie…
Reference in New Issue