Commit 18f24149 authored by Florian Schäfer's avatar Florian Schäfer

Combine the download actions of the WikipediaToggleDialog

The actions are now in a PopupMenu of one SideButton instead of in three separate buttons.
parent eb6a0e4f
// License: GPL. For details, see LICENSE file.
package org.wikipedia.actions;
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import javax.swing.Action;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import org.openstreetmap.josm.actions.JosmAction;
import org.openstreetmap.josm.gui.SideButton;
public class MultiAction extends JosmAction {
public static SideButton createButton(final String name, final String iconName, final String tooltip, final Action... actions) {
final MultiAction popupAction = new MultiAction(name, iconName, tooltip, actions);
final SideButton button = new SideButton(popupAction);
button.createArrow(it -> button.getAction().actionPerformed(it));
return button;
private final JPopupMenu popup;
private Component parent;
private MultiAction(final String name, final String iconName, final String tooltip, final Action... actions) {
// I18n: {0} is the number of available sources
super(name, iconName, tooltip, null, false, false);
popup = new ActionsPopup(actions);
public void actionPerformed(ActionEvent e) {
final Component finalParent = parent;
if (finalParent != null) {
final Rectangle parentBounds = finalParent.getBounds();, parentBounds.x - parentBounds.width, parentBounds.y);
} else {
Logging.error("The parent component of a MultiAction must not be null!");
private void setParent(final Component parent) {
this.parent = parent;
private static class ActionsPopup extends JPopupMenu {
private ActionsPopup(final Action... actions) {
for (final Action action : actions) {
add(new JMenuItem(action));
......@@ -15,6 +15,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultListCellRenderer;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;
......@@ -42,12 +43,14 @@ 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.wikipedia.WikipediaApp;
import org.wikipedia.actions.FetchWikidataAction;
import org.wikipedia.actions.MultiAction;
import org.wikipedia.actions.ToggleWikiLayerAction;
......@@ -56,11 +59,20 @@ public class WikipediaToggleDialog extends ToggleDialog implements ActiveLayerCh
public WikipediaToggleDialog() {
super(tr("Wikipedia"), "wikipedia", tr("Fetch Wikipedia articles with coordinates"), null, 150);
final Action[] downloadActions = {
new WikipediaLoadCoordinatesAction(false),
new WikipediaLoadCoordinatesAction(true),
new WikipediaLoadCategoryAction()
createLayout(list, true, Arrays.asList(
new SideButton(new ToggleWikiLayerAction(this)),
new SideButton(new WikipediaLoadCoordinatesAction(false)),
new SideButton(new WikipediaLoadCoordinatesAction(true)),
new SideButton(new WikipediaLoadCategoryAction()),
MultiAction.createButton("Download elements"),
"download","Download all elements in the current viewport from one of {0} sources", downloadActions.length),
new SideButton(new PasteWikipediaArticlesAction()),
new SideButton(new AddWikipediaTagAction(list)),
new SideButton(new WikipediaSettingsAction(), false)
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