Improve MapWithAI menu

Signed-off-by: Taylor Smock <taylor.smock@kaart.com>
pull/1/head
Taylor Smock 2020-07-01 09:52:31 -06:00
rodzic 0b43172d3f
commit 0bc1f03848
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 625F6A74A3E4311A
2 zmienionych plików z 29 dodań i 5 usunięć

Wyświetl plik

@ -68,6 +68,7 @@ public class DownloadMapWithAITask extends DownloadOsmTask {
class DownloadTask extends AbstractInternalTask {
BoundingBoxMapWithAIDownloader downloader;
final Bounds bounds;
private List<MapWithAIInfo> relevantUrls;
DownloadTask(DownloadParams settings, String title, boolean ignoreException, boolean zoomAfterDownload,
Bounds bounds) {
@ -90,8 +91,7 @@ public class DownloadMapWithAITask extends DownloadOsmTask {
@Override
protected void realRun() throws SAXException, IOException, OsmTransferException {
Collection<MapWithAIInfo> relevantUrls = urls.stream()
.filter(i -> i.getBounds() == null || i.getBounds().intersects(bounds))
relevantUrls = urls.stream().filter(i -> i.getBounds() == null || i.getBounds().intersects(bounds))
.collect(Collectors.toList());
ProgressMonitor monitor = getProgressMonitor();
if (relevantUrls.size() < 5) {
@ -114,7 +114,9 @@ public class DownloadMapWithAITask extends DownloadOsmTask {
protected void finish() {
if (!isCanceled() && !isFailed()) {
synchronized (DownloadMapWithAITask.DownloadTask.class) {
MapWithAIDataUtils.getLayer(true).getDataSet().mergeFrom(downloadedData);
MapWithAILayer layer = MapWithAIDataUtils.getLayer(true);
layer.getDataSet().mergeFrom(downloadedData);
relevantUrls.forEach(layer::addDownloadedInfo);
}
GetDataRunnable.cleanup(MapWithAIDataUtils.getLayer(true).getDataSet(), null, null);
}

Wyświetl plik

@ -1,12 +1,16 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai.gui;
import static org.openstreetmap.josm.tools.I18n.tr;
import static org.openstreetmap.josm.tools.I18n.trc;
import java.awt.Component;
import java.awt.GraphicsEnvironment;
import java.awt.MenuComponent;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumMap;
import java.util.List;
@ -32,6 +36,8 @@ 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;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAIDataUtils;
import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAILayer;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
@ -109,10 +115,15 @@ public class MapWithAIMenu extends JMenu {
removeDynamicItems();
addDynamicSeparator();
// Get layers in use
MapWithAILayer layer = MapWithAIDataUtils.getLayer(false);
final Collection<MapWithAIInfo> alreadyInUse = layer == null ? Collections.emptyList()
: layer.getDownloadedInfo();
// for each configured ImageryInfo, add a menu entry.
final List<MapWithAIInfo> savedLayers = new ArrayList<>(MapWithAILayerInfo.getInstance().getLayers());
savedLayers.sort(alphabeticSourceComparator);
savedLayers.removeIf(alreadyInUse::contains);
for (final MapWithAIInfo u : savedLayers) {
addDynamic(trackJosmAction(new AddMapWithAILayerAction(u)), null);
}
@ -122,10 +133,9 @@ public class MapWithAIMenu extends JMenu {
if (MainApplication.isDisplayingMapView()) {
MapView mv = MainApplication.getMap().mapView;
LatLon pos = mv.getProjection().eastNorth2latlon(mv.getCenter());
final List<MapWithAIInfo> alreadyInUse = MapWithAILayerInfo.getInstance().getLayers();
final List<MapWithAIInfo> inViewLayers = MapWithAILayerInfo.getInstance().getDefaultLayers().stream()
.filter(i -> i.getBounds() != null && i.getBounds().contains(pos) && !alreadyInUse.contains(i)
&& isPosInOneShapeIfAny(i, pos))
&& !savedLayers.contains(i) && isPosInOneShapeIfAny(i, pos))
.sorted(alphabeticSourceComparator).collect(Collectors.toList());
if (!inViewLayers.isEmpty()) {
if (inViewLayers.stream().anyMatch(i -> i.getCategory() == i.getCategory().getDefault())) {
@ -152,6 +162,18 @@ public class MapWithAIMenu extends JMenu {
}
}
}
if (dynamicNonPhotoItems.isEmpty()) {
JosmAction infoAction = new JosmAction() {
@Override
public void actionPerformed(ActionEvent e) {
// Do nothing
}
};
infoAction.putValue(Action.NAME, tr("No futher download options"));
infoAction.setEnabled(false);
infoAction.setTooltip(tr("No further download actions possible in this area"));
addDynamic(infoAction, null);
}
}
}