-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to download additional tasks from a specific challenge
Signed-off-by: Taylor Smock <tsmock@meta.com>
- Loading branch information
Showing
5 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/main/java/org/openstreetmap/josm/plugins/maproulette/actions/DownloadTasks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// License: GPL. For details, see LICENSE file. | ||
package org.openstreetmap.josm.plugins.maproulette.actions; | ||
|
||
import static org.openstreetmap.josm.tools.I18n.tr; | ||
|
||
import java.awt.event.ActionEvent; | ||
import java.awt.event.KeyEvent; | ||
import java.util.ArrayDeque; | ||
import java.util.List; | ||
|
||
import javax.swing.JMenuItem; | ||
import javax.swing.JPopupMenu; | ||
|
||
import org.openstreetmap.josm.actions.JosmAction; | ||
import org.openstreetmap.josm.actions.downloadtasks.DownloadParams; | ||
import org.openstreetmap.josm.gui.progress.NullProgressMonitor; | ||
import org.openstreetmap.josm.plugins.maproulette.actions.downloadtasks.MapRouletteDownloadTask; | ||
import org.openstreetmap.josm.plugins.maproulette.api.model.TaskClusteredPoint; | ||
import org.openstreetmap.josm.tools.Shortcut; | ||
|
||
/** | ||
* Download additional nearby tasks for that challenge | ||
*/ | ||
public class DownloadTasks extends JosmAction { | ||
/** | ||
* Create a new action for downloading tasks | ||
*/ | ||
public DownloadTasks() { | ||
super(tr("Download additional tasks"), "download", tr("Download additional tasks from challenge"), | ||
Shortcut.registerShortcut("maproulette:download_additional_tasks_from_challenge", | ||
tr("MapRoulette: Download additional tasks from challenge"), KeyEvent.CHAR_UNDEFINED, | ||
Shortcut.NONE), | ||
false); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
final var component = ((JPopupMenu) ((JMenuItem) e.getSource()).getParent()).getInvoker(); | ||
final List<?> objects = ActionUtils.getSelectedItems(component); | ||
final var locations = new ArrayDeque<TaskClusteredPoint>(objects.size()); | ||
for (var obj : objects) { | ||
if (obj instanceof TaskClusteredPoint t) { | ||
locations.add(t); | ||
} | ||
} | ||
while (!locations.isEmpty()) { | ||
final var t = locations.pop(); | ||
new MapRouletteDownloadTask(t.parentId(), t.id()).loadUrl(new DownloadParams(), "", | ||
NullProgressMonitor.INSTANCE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters