| 1 | package org.openstreetmap.josm.gui.tagging;
|
|---|
| 2 |
|
|---|
| 3 | import org.openstreetmap.josm.Main;
|
|---|
| 4 | import org.openstreetmap.josm.actions.JosmAction;
|
|---|
| 5 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 6 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
|---|
| 7 | import org.openstreetmap.josm.tools.Shortcut;
|
|---|
| 8 | import org.openstreetmap.josm.tools.Utils;
|
|---|
| 9 |
|
|---|
| 10 | import java.awt.event.ActionEvent;
|
|---|
| 11 | import java.awt.event.ActionListener;
|
|---|
| 12 | import java.awt.event.KeyEvent;
|
|---|
| 13 | import java.util.HashSet;
|
|---|
| 14 |
|
|---|
| 15 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 16 |
|
|---|
| 17 | /**
|
|---|
| 18 | * A dialog that allows to select a preset and then selects all matching OSM objects.
|
|---|
| 19 | * @see org.openstreetmap.josm.gui.tagging.TaggingPresetSearchDialog
|
|---|
| 20 | */
|
|---|
| 21 | public final class TaggingPresetSearchPrimitiveDialog extends ExtendedDialog {
|
|---|
| 22 |
|
|---|
| 23 | private TaggingPresetSelector selector;
|
|---|
| 24 |
|
|---|
| 25 | private static TaggingPresetSearchPrimitiveDialog instance;
|
|---|
| 26 |
|
|---|
| 27 | /**
|
|---|
| 28 | * Returns the unique instance of {@code TaggingPresetSearchPrimitiveDialog}.
|
|---|
| 29 | * @return the unique instance of {@code TaggingPresetSearchPrimitiveDialog}.
|
|---|
| 30 | */
|
|---|
| 31 | public static TaggingPresetSearchPrimitiveDialog getInstance() {
|
|---|
| 32 | if (instance == null) {
|
|---|
| 33 | instance = new TaggingPresetSearchPrimitiveDialog();
|
|---|
| 34 | }
|
|---|
| 35 | return instance;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | TaggingPresetSearchPrimitiveDialog() {
|
|---|
| 39 | super(Main.parent, tr("Presets"), new String[] {tr("Search"), tr("Cancel")});
|
|---|
| 40 | selector = new TaggingPresetSelector(false, false);
|
|---|
| 41 | setContent(selector);
|
|---|
| 42 | selector.setDblClickListener(new ActionListener() {
|
|---|
| 43 | @Override
|
|---|
| 44 | public void actionPerformed(ActionEvent e) {
|
|---|
| 45 | buttonAction(0, null);
|
|---|
| 46 | }
|
|---|
| 47 | });
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | @Override
|
|---|
| 51 | public ExtendedDialog showDialog() {
|
|---|
| 52 | selector.init();
|
|---|
| 53 | super.showDialog();
|
|---|
| 54 | selector.clearSelection();
|
|---|
| 55 | return this;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | @Override
|
|---|
| 59 | protected void buttonAction(int buttonIndex, ActionEvent evt) {
|
|---|
| 60 | super.buttonAction(buttonIndex, evt);
|
|---|
| 61 | if (buttonIndex == 0) {
|
|---|
| 62 | TaggingPreset preset = selector.getSelectedPreset();
|
|---|
| 63 | if (preset != null) {
|
|---|
| 64 | final HashSet<OsmPrimitive> matching = new HashSet<>(Utils.filter(Main.main.getCurrentDataSet().allPrimitives(), preset));
|
|---|
| 65 | Main.main.getCurrentDataSet().setSelected(matching);
|
|---|
| 66 | }
|
|---|
| 67 | }
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | /**
|
|---|
| 71 | * An action executing {@link TaggingPresetSearchPrimitiveDialog}.
|
|---|
| 72 | */
|
|---|
| 73 | public static class Action extends JosmAction {
|
|---|
| 74 |
|
|---|
| 75 | /**
|
|---|
| 76 | * Constructs a new {@link TaggingPresetSearchPrimitiveDialog.Action}.
|
|---|
| 77 | */
|
|---|
| 78 | public Action() {
|
|---|
| 79 | super(tr("Search for objects by preset"), "dialogs/search", tr("Show preset search dialog"),
|
|---|
| 80 | Shortcut.registerShortcut("preset:search-objects", tr("Search for objects by preset"), KeyEvent.VK_F3, Shortcut.SHIFT), false);
|
|---|
| 81 | putValue("toolbar", "presets/search-objects");
|
|---|
| 82 | Main.toolbar.register(this);
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | @Override
|
|---|
| 86 | public void actionPerformed(ActionEvent e) {
|
|---|
| 87 | if (Main.main.hasEditLayer()) {
|
|---|
| 88 | TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
|
|---|
| 89 | }
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | }
|
|---|