Commit 9458dd92 authored by Vincent Privat's avatar Vincent Privat

update to JOSM 12663

git-svn-id: https://svn.openstreetmap.org/applications/editors/josm/plugins/wikipedia@33541 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
parent 80b25aa9
......@@ -4,7 +4,7 @@
<!-- enter the SVN commit message -->
<property name="commit.message" value="Commit message"/>
<!-- enter the *lowest* JOSM version this plugin is currently compatible with -->
<property name="plugin.main.version" value="10580"/>
<property name="plugin.main.version" value="12663"/>
<property name="plugin.canloadatruntime" value="true"/>
<property name="plugin.author" value="simon04"/>
......
......@@ -33,6 +33,7 @@ import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
import org.openstreetmap.josm.tools.HttpClient;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
......@@ -192,7 +193,7 @@ public final class WikipediaApp {
if (x.length == 2) {
status.put(x[0], "1".equals(x[1]));
} else {
Main.error("Unknown element " + line);
Logging.error("Unknown element " + line);
}
});
}
......@@ -482,8 +483,8 @@ public final class WikipediaApp {
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder();
} catch (ParserConfigurationException e) {
Main.warn("Cannot create DocumentBuilder");
Main.warn(e);
Logging.warn("Cannot create DocumentBuilder");
Logging.warn(e);
throw new RuntimeException(e);
}
}
......
// License: GPL. For details, see LICENSE file.
package org.wikipedia;
import org.openstreetmap.josm.Main;
import javax.swing.JMenu;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.MainMenu;
import org.openstreetmap.josm.gui.MapFrame;
import org.openstreetmap.josm.plugins.Plugin;
......@@ -18,9 +20,10 @@ public class WikipediaPlugin extends Plugin {
public WikipediaPlugin(PluginInformation info) {
super(info);
new WikipediaCopyTemplate();
MainMenu.add(Main.main.menu.dataMenu, new WikipediaAddNamesAction());
MainMenu.add(Main.main.menu.dataMenu, new FetchWikidataAction());
MainMenu.add(Main.main.menu.dataMenu, new WikidataItemSearchDialog.Action());
JMenu dataMenu = MainApplication.getMenu().dataMenu;
MainMenu.add(dataMenu, new WikipediaAddNamesAction());
MainMenu.add(dataMenu, new FetchWikidataAction());
MainMenu.add(dataMenu, new WikidataItemSearchDialog.Action());
}
@Override
......
......@@ -22,9 +22,11 @@ import org.openstreetmap.josm.command.SequenceCommand;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.PleaseWaitRunnable;
import org.openstreetmap.josm.gui.progress.ProgressMonitor;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.MultiMap;
import org.openstreetmap.josm.tools.Utils;
import org.wikipedia.WikipediaApp;
......@@ -44,7 +46,7 @@ public class FetchWikidataAction extends JosmAction {
if (ds == null) {
return;
}
Main.worker.submit(new Fetcher(ds.getSelected()));
MainApplication.worker.submit(new Fetcher(ds.getSelected()));
}
public static class Fetcher extends PleaseWaitRunnable {
......@@ -98,7 +100,7 @@ public class FetchWikidataAction extends JosmAction {
@Override
protected void finish() {
if (!canceled && !commands.isEmpty()) {
Main.main.undoRedo.add(commands.size() == 1 ? commands.get(0) : new SequenceCommand(tr("Add Wikidata"), commands));
MainApplication.undoRedo.add(commands.size() == 1 ? commands.get(0) : new SequenceCommand(tr("Add Wikidata"), commands));
}
if (!canceled && !notFound.isEmpty()) {
new Notification(tr("No Wikidata ID found for: {0}", Utils.joinAsHtmlUnorderedList(notFound)))
......@@ -139,7 +141,7 @@ public class FetchWikidataAction extends JosmAction {
}
} else {
final WikipediaEntry article = new WikipediaEntry(lang, wikipedia);
Main.warn(tr("No Wikidata ID found for: {0}", article));
Logging.warn(tr("No Wikidata ID found for: {0}", article));
notFound.add(article);
}
}
......
......@@ -15,6 +15,7 @@ import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.io.remotecontrol.AddTagsDialog;
import org.openstreetmap.josm.tools.Logging;
import org.wikipedia.WikipediaApp;
import org.wikipedia.data.WikipediaEntry;
......@@ -34,8 +35,8 @@ public class WikipediaAddNamesAction extends JosmAction {
.filter(this::useWikipediaLangArticle)
.map(i -> new String[]{"name:" + i.lang, i.article})
.forEach(tags::add);
if (Main.isDebugEnabled()) {
Main.debug(tags.toString());
if (Logging.isDebugEnabled()) {
Logging.debug(tags.toString());
}
AddTagsDialog.addTags(tags.toArray(new String[tags.size()][]), "Wikipedia", getLayerManager().getEditDataSet().getSelected());
}
......
......@@ -17,6 +17,7 @@ import org.openstreetmap.josm.data.Preferences.pref;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Node;
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;
......@@ -33,10 +34,10 @@ public class WikipediaCopyTemplate {
Main.pref.getListOfStructs("wikipedia.copytemplates", DEFAULT_TEMPLATES, CoordCopyTemplateEntry.class);
public WikipediaCopyTemplate() {
JosmAction previous = Main.main.menu.copyCoordinates;
JosmAction previous = MainApplication.getMenu().copyCoordinates;
for (final CoordCopyTemplateEntry templateEntry : TEMPLATE_ENTRIES) {
CoordCopyTemplate t = new CoordCopyTemplate(templateEntry);
final JMenuItem menu = MainMenu.addAfter(Main.main.menu.editMenu, t, false, previous);
final JMenuItem menu = MainMenu.addAfter(MainApplication.getMenu().editMenu, t, false, previous);
menu.setToolTipText(tr("Copies the {0} template to the system clipboard instantiated with the coordinates of the first selected node", templateEntry.name));
previous = t;
}
......
......@@ -2,9 +2,9 @@
package org.wikipedia.gui;
import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.data.osm.DefaultNameFormatter;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.ConditionalOptionPaneUtil;
import org.openstreetmap.josm.gui.DefaultNameFormatter;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.tools.AlphanumComparator;
import org.openstreetmap.josm.tools.Utils;
......
......@@ -24,6 +24,7 @@ import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.data.osm.DataSet;
import org.openstreetmap.josm.data.osm.Tag;
import org.openstreetmap.josm.gui.ExtendedDialog;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionListItem;
import org.openstreetmap.josm.gui.util.GuiHelper;
......@@ -73,7 +74,7 @@ public final class WikidataItemSearchDialog extends ExtendedDialog {
}
private void initTargetKeys() {
final DataSet editDataSet = Main.getLayerManager().getEditDataSet();
final DataSet editDataSet = MainApplication.getLayerManager().getEditDataSet();
if (editDataSet == null) {
return;
}
......
......@@ -20,6 +20,7 @@ import javax.swing.table.DefaultTableCellRenderer;
import org.openstreetmap.josm.Main;
import org.openstreetmap.josm.gui.util.GuiHelper;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Utils;
import org.wikipedia.WikipediaApp;
import org.wikipedia.data.WikidataEntry;
......@@ -69,8 +70,8 @@ public class WikidataTagCellRenderer extends DefaultTableCellRenderer {
try {
label = labelCache.get(id).get();
} catch (InterruptedException | ExecutionException e) {
Main.warn("Could not fetch Wikidata label for " + id);
Main.warn(e);
Logging.warn("Could not fetch Wikidata label for " + id);
Logging.warn(e);
return null;
}
if (label == null) {
......
......@@ -31,14 +31,18 @@ import org.openstreetmap.josm.data.osm.event.AbstractDatasetChangedEvent;
import org.openstreetmap.josm.data.osm.event.DataSetListenerAdapter;
import org.openstreetmap.josm.data.osm.event.DatasetEventManager;
import org.openstreetmap.josm.data.osm.event.DatasetEventManager.FireMode;
import org.openstreetmap.josm.data.osm.search.SearchMode;
import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor;
import org.openstreetmap.josm.data.preferences.StringProperty;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.MapView;
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.tools.ImageProvider;
import org.openstreetmap.josm.tools.LanguageInfo;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.OpenBrowser;
import org.wikipedia.WikipediaApp;
import org.wikipedia.actions.FetchWikidataAction;
......@@ -70,15 +74,15 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && getSelectedValue() != null && Main.getLayerManager().getEditDataSet() != null) {
if (e.getClickCount() == 2 && getSelectedValue() != null && MainApplication.getLayerManager().getEditDataSet() != null) {
final WikipediaEntry entry = getSelectedValue();
if (entry.coordinate != null) {
BoundingXYVisitor bbox = new BoundingXYVisitor();
bbox.visit(entry.coordinate);
Main.map.mapView.zoomTo(bbox);
MainApplication.getMap().mapView.zoomTo(bbox);
}
final String search = entry.getSearchText().replaceAll("\\(.*\\)", "");
SearchAction.search(search, SearchAction.SearchMode.replace);
SearchAction.search(search, SearchMode.replace);
}
}
});
......@@ -145,8 +149,9 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
public void actionPerformed(ActionEvent e) {
try {
// determine bbox
final LatLon min = Main.map.mapView.getLatLon(0, Main.map.mapView.getHeight());
final LatLon max = Main.map.mapView.getLatLon(Main.map.mapView.getWidth(), 0);
MapView mapView = MainApplication.getMap().mapView;
final LatLon min = mapView.getLatLon(0, mapView.getHeight());
final LatLon max = mapView.getLatLon(mapView.getWidth(), 0);
// add entries to list model
titleContext = tr("coordinates");
updateTitle();
......@@ -257,7 +262,7 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
public void actionPerformed(ActionEvent e) {
if (list.getSelectedValue() != null) {
final String url = list.getSelectedValue().getBrowserUrl();
Main.info("Wikipedia: opening " + url);
Logging.info("Wikipedia: opening " + url);
OpenBrowser.displayUrl(url);
}
}
......@@ -312,15 +317,15 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
if (tag == null) {
return;
}
final Collection<OsmPrimitive> selected = Main.getLayerManager().getEditDataSet().getSelected();
final Collection<OsmPrimitive> selected = MainApplication.getLayerManager().getEditDataSet().getSelected();
if (!GuiUtils.confirmOverwrite(tag.getKey(), tag.getValue(), selected)) {
return;
}
ChangePropertyCommand cmd = new ChangePropertyCommand(
selected,
tag.getKey(), tag.getValue());
Main.main.undoRedo.add(cmd);
Main.worker.submit(new FetchWikidataAction.Fetcher(selected));
MainApplication.undoRedo.add(cmd);
MainApplication.worker.submit(new FetchWikidataAction.Fetcher(selected));
}
}
......@@ -344,15 +349,15 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
if (latLon == null) {
return;
}
Main.map.mapView.zoomTo(latLon);
MainApplication.getMap().mapView.zoomTo(latLon);
}
}
protected void updateWikipediaArticles() {
final String language = getLanguageOfFirstItem();
articles.clear();
if (Main.main != null && Main.getLayerManager().getEditDataSet() != null) {
Main.getLayerManager().getEditDataSet().allPrimitives().stream()
if (Main.main != null && MainApplication.getLayerManager().getEditDataSet() != null) {
MainApplication.getLayerManager().getEditDataSet().allPrimitives().stream()
.flatMap(p -> WikipediaApp.forLanguage(language).getWikipediaArticles(p))
.forEach(articles::add);
}
......@@ -363,14 +368,14 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
@Override
public void showNotify() {
DatasetEventManager.getInstance().addDatasetListener(dataChangedAdapter, FireMode.IN_EDT_CONSOLIDATED);
Main.getLayerManager().addActiveLayerChangeListener(this);
MainApplication.getLayerManager().addActiveLayerChangeListener(this);
updateWikipediaArticles();
}
@Override
public void hideNotify() {
DatasetEventManager.getInstance().removeDatasetListener(dataChangedAdapter);
Main.getLayerManager().removeActiveLayerChangeListener(this);
MainApplication.getLayerManager().removeActiveLayerChangeListener(this);
articles.clear();
}
......
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