Commit 6cfeb920 authored by Florian Schäfer's avatar Florian Schäfer

Replace deprecated classes/methods with newer JOSM API

parent 098420a5
Pipeline #30418522 passed with stages
in 8 minutes and 10 seconds
# The minimum JOSM version this plugin is compatible with (can be any numeric version)
plugin.main.version = 14140
plugin.main.version = 14149
# The JOSM version this plugin is currently compiled against
# Please make sure this version is available at https://josm.openstreetmap.de/download
# The special values "latest" and "tested" are also possible here, but not recommended.
......
......@@ -4,23 +4,23 @@ package org.wikipedia.actions;
import static org.openstreetmap.josm.tools.I18n.tr;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.io.remotecontrol.AddTagsDialog;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
import org.wikipedia.WikipediaApp;
import org.wikipedia.WikipediaPlugin;
import org.wikipedia.data.WikipediaEntry;
import org.wikipedia.tools.WikiProperties;
public class WikipediaAddNamesAction extends JosmAction {
......@@ -38,11 +38,10 @@ public class WikipediaAddNamesAction extends JosmAction {
.setIcon(WikipediaPlugin.W_IMAGE.setMaxSize(ImageProvider.ImageSizes.LARGEICON).get())
.show();
} else {
List<String[]> tags = new ArrayList<>();
WikipediaApp.forLanguage(wp.lang).getInterwikiArticles(wp.article).stream()
List<String[]> tags = WikipediaApp.forLanguage(wp.lang).getInterwikiArticles(wp.article).stream()
.filter(this::useWikipediaLangArticle)
.map(i -> new String[]{"name:" + i.lang, i.article})
.forEach(tags::add);
.collect(Collectors.toList());
if (Logging.isDebugEnabled()) {
Logging.debug(tags.toString());
}
......@@ -51,19 +50,17 @@ public class WikipediaAddNamesAction extends JosmAction {
}
private boolean useWikipediaLangArticle(WikipediaEntry i) {
return (!Config.getPref().getBoolean("wikipedia.filter-iso-languages", true)
|| Arrays.asList(Locale.getISOLanguages()).contains(i.lang))
&& (!Config.getPref().getBoolean("wikipedia.filter-same-names", true)
|| !i.article.equals(getLayerManager().getEditDataSet().getSelected().iterator().next().get("name")));
return
(!WikiProperties.FILTER_ISO_LANGUAGES.get() || Arrays.asList(Locale.getISOLanguages()).contains(i.lang)) &&
(!WikiProperties.FILTER_SAME_NAMES.get() || !i.article.equals(getLayerManager().getEditDataSet().getSelected().iterator().next().get("name")));
}
private String getWikipediaValue() {
DataSet ds = getLayerManager().getEditDataSet();
final DataSet ds = getLayerManager().getEditDataSet();
if (ds == null || ds.getSelected() == null || ds.getSelected().size() != 1) {
return null;
} else {
return ds.getSelected().iterator().next().get("wikipedia");
}
return ds.getSelected().iterator().next().get("wikipedia");
}
@Override
......
......@@ -18,19 +18,18 @@ import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.MainMenu;
import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
import org.openstreetmap.josm.spi.preferences.Config;
public class WikipediaCopyTemplate {
private static final List<CoordCopyTemplateEntry> DEFAULT_TEMPLATES = Arrays.asList(
new CoordCopyTemplateEntry("{{Coordinate}}", "wikipedia-coordinate", "{{Coordinate|NS={lat}|EW={lon}|type=landmark|region=}}"),
new CoordCopyTemplateEntry("{{Coord}}", "wikipedia-coord", "{{Coord|{lat}|{lon}}}"),
new CoordCopyTemplateEntry("{{Location dec}}", "wikipedia-location-dec", "{{Location dec|{lat}|{lon}}}"),
new CoordCopyTemplateEntry("{{Object location dec}}", "wikipedia-object-location-dec", "{{Object location dec|{lat}|{lon}}}")
new CoordCopyTemplateEntry("{{Coordinate}}", "wikipedia-coordinate", "{{Coordinate|NS={lat}|EW={lon}|type=landmark|region=}}"),
new CoordCopyTemplateEntry("{{Coord}}", "wikipedia-coord", "{{Coord|{lat}|{lon}}}"),
new CoordCopyTemplateEntry("{{Location dec}}", "wikipedia-location-dec", "{{Location dec|{lat}|{lon}}}"),
new CoordCopyTemplateEntry("{{Object location dec}}", "wikipedia-object-location-dec", "{{Object location dec|{lat}|{lon}}}")
);
private static final List<CoordCopyTemplateEntry> TEMPLATE_ENTRIES =
StructUtils.getListOfStructs(Config.getPref(), "wikipedia.copytemplates", DEFAULT_TEMPLATES, CoordCopyTemplateEntry.class);
StructUtils.getListOfStructs(Preferences.main(), "wikipedia.copytemplates", DEFAULT_TEMPLATES, CoordCopyTemplateEntry.class);
public WikipediaCopyTemplate() {
JosmAction previous = MainApplication.getMenu().copyCoordinates;
......
......@@ -19,7 +19,7 @@ final class WikipediaCategorySearchDialog extends ExtendedDialog {
private static final WikipediaCategorySearchDialog INSTANCE = new WikipediaCategorySearchDialog();
private WikipediaCategorySearchDialog() {
super(MainApplication.getMainFrame(), tr("Search Wikipedia category"), new String[]{tr("Load category"), tr("Cancel")});
super(MainApplication.getMainFrame(), tr("Search Wikipedia category"), tr("Load category"), tr("Cancel"));
this.selector = new Selector();
this.selector.setDblClickListener(e -> buttonAction(0, null));
......
......@@ -43,7 +43,6 @@ import org.openstreetmap.josm.gui.SideButton;
import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeEvent;
import org.openstreetmap.josm.gui.layer.MainLayerManager.ActiveLayerChangeListener;
import org.openstreetmap.josm.spi.preferences.Config;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
......@@ -256,8 +255,9 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
new UpdateWikipediaArticlesSwingWorker() {
@Override
List<WikipediaEntry> getEntries() {
return WikipediaApp.forLanguage(WikiProperties.WIKIPEDIA_LANGUAGE.get())
.getEntriesFromCategory(category, Config.getPref().getInt("wikipedia.depth", 3));
return WikipediaApp
.forLanguage(WikiProperties.WIKIPEDIA_LANGUAGE.get())
.getEntriesFromCategory(category, WikiProperties.WIKIPEDIA_DEPTH.get());
}
}.execute();
}
......@@ -370,10 +370,11 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
protected void updateWikipediaArticles() {
final WikipediaApp app = newWikipediaApp();
articles.clear();
if (MainApplication.getLayerManager().getEditDataSet() != null) {
MainApplication.getLayerManager().getEditDataSet().allPrimitives().stream()
.flatMap(app::getWikipediaArticles)
.forEach(articles::add);
final DataSet editDataset = MainApplication.getLayerManager().getEditDataSet();
if (editDataset != null) {
editDataset.allPrimitives().stream()
.flatMap(app::getWikipediaArticles)
.forEach(articles::add);
}
}
......
......@@ -2,7 +2,9 @@
package org.wikipedia.tools;
import java.util.Arrays;
import org.openstreetmap.josm.data.preferences.BooleanProperty;
import org.openstreetmap.josm.data.preferences.DoubleProperty;
import org.openstreetmap.josm.data.preferences.IntegerProperty;
import org.openstreetmap.josm.data.preferences.ListProperty;
import org.openstreetmap.josm.data.preferences.StringProperty;
import org.openstreetmap.josm.tools.LanguageInfo;
......@@ -33,6 +35,12 @@ public final class WikiProperties {
)
);
public static final IntegerProperty WIKIPEDIA_DEPTH = new IntegerProperty("wikipedia.depth", 3);
public static final BooleanProperty FILTER_ISO_LANGUAGES = new BooleanProperty("wikipedia.filter-iso-languages", true);
public static final BooleanProperty FILTER_SAME_NAMES = new BooleanProperty("wikipedia.filter-same-names", true);
private WikiProperties() {
// Private constructor to avoid instantiation
}
......
......@@ -6,7 +6,6 @@ import static org.junit.Assert.assertFalse;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
import org.junit.Test;
import org.wikipedia.api.ApiQueryClient;
import org.wikipedia.testutils.ResourceFileLoader;
......
......@@ -6,8 +6,8 @@ import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.net.URISyntaxException;
import org.junit.Test;
import org.wikipedia.api.wikidata_action.WikidataActionApiTestAbstract;
import org.wikipedia.api.wikidata_action.WikidataActionApiQueryTest;
import org.wikipedia.api.wikidata_action.WikidataActionApiTestAbstract;
import org.wikipedia.testutils.ResourceFileLoader;
public class WikipediaSiteTest extends WikidataActionApiTestAbstract {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment