source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSearchPrimitiveDialog.java@ 8338

Last change on this file since 8338 was 8338, checked in by Don-vip, 9 years ago

fix squid:S1319 - Declarations should use Java collection interfaces rather than specific implementation classes

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