diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java index 9f4309e..e460685 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/data/mapwithai/MapWithAIInfo.java @@ -3,12 +3,12 @@ package org.openstreetmap.josm.plugins.mapwithai.data.mapwithai; import static org.openstreetmap.josm.tools.I18n.marktr; import static org.openstreetmap.josm.tools.I18n.tr; - import java.awt.Image; import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.EnumMap; import java.util.HashMap; import java.util.List; @@ -17,13 +17,11 @@ import java.util.Map; import java.util.Objects; import java.util.TreeSet; import java.util.stream.Collectors; - import javax.json.Json; import javax.json.JsonArray; import javax.json.JsonObject; import javax.json.stream.JsonParser; import javax.swing.ImageIcon; - import org.openstreetmap.gui.jmapviewer.interfaces.Attributed; import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate; import org.openstreetmap.gui.jmapviewer.tilesources.TileSourceInfo; @@ -40,6 +38,7 @@ import org.openstreetmap.josm.tools.Logging; import org.openstreetmap.josm.tools.Utils; public class MapWithAIInfo extends TileSourceInfo implements Comparable, Attributed { + /** * Type of MapWithAI entry */ @@ -66,7 +65,8 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable { + BUILDING("data/closedway", "buildings", marktr("Buildings")), HIGHWAY("presets/transport/way/way_road", "highways", marktr("Roads")), ADDRESS("presets/misc/housenumber_small", "addresses", marktr("Addresses")), @@ -105,16 +105,26 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable { + + @Override + public int compare(MapWithAICategory o1, MapWithAICategory o2) { + return (o1 == null || o2 == null) ? 1 : o1.getDescription().compareTo(o2.getDescription()); + } + } } /** @@ -191,6 +201,7 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable { + + @Override + public int compare(MapWithAIInfo o1, MapWithAIInfo o2) { + return (Objects.nonNull(o1.getCategory()) || Objects.nonNull(o2.getCategory()) ? 1 + : Objects.compare(o1.getCategory(), o2.getCategory(), + new MapWithAICategory.DescriptionComparator())); + } + } + public MapWithAIInfo() { this((String) null); } @@ -529,6 +550,14 @@ public class MapWithAIInfo extends TileSourceInfo implements Comparable comparator = new Comparator() { + + @Override + public int compare(MapWithAIInfo o1, MapWithAIInfo o2) { + return o1.getCategory().getDescription().compareTo(o2.getCategory().getDescription()); + } + }; + if (information != null) { + information = information.stream().sorted(comparator).collect(Collectors.toSet()); + } return information; } @@ -321,8 +342,8 @@ public class MapWithAILayerInfo { JsonReader reader = Json.createReader(br)) { JsonObject info = reader.readObject(); - return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream().collect(Collectors.toMap( - o -> o.getString("name"), o -> o.getBoolean("editable", true) ? o.getString("alias", "") : "")); + return info.getJsonArray("fields").getValuesAs(JsonObject.class).stream() + .collect(Collectors.toMap(o -> o.getString("name"), o -> o.getString("alias", null))); } catch (IOException e) { Logging.error(e); } @@ -569,6 +590,7 @@ public class MapWithAILayerInfo { } public static interface FinishListener { + public void onFinish(); } } diff --git a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java index b55a847..eb0f576 100644 --- a/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java +++ b/src/main/java/org/openstreetmap/josm/plugins/mapwithai/gui/download/MapWithAIDownloadOptions.java @@ -4,10 +4,8 @@ package org.openstreetmap.josm.plugins.mapwithai.gui.download; import static org.openstreetmap.josm.tools.I18n.tr; import java.awt.GridBagLayout; - import javax.swing.JLabel; import javax.swing.JPanel; - import org.openstreetmap.josm.data.Bounds; import org.openstreetmap.josm.gui.bbox.JosmMapViewer; import org.openstreetmap.josm.gui.download.DownloadDialog; @@ -29,7 +27,7 @@ public class MapWithAIDownloadOptions extends JPanel implements DownloadSelectio favorites.add(new JLabel("TODO: Favorites go here!")); // TODO optionPanel.add(favorites, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTH)); mapwithaiProvidersPanel = new MapWithAIProvidersPanel(this, MapWithAILayerInfo.getInstance()); - optionPanel.add(mapwithaiProvidersPanel); + optionPanel.add(mapwithaiProvidersPanel, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.CENTER)); } @Override