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

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

sonar - squid:S3878 - Arrays should not be created for varargs parameters

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
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;
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.presets.TaggingPresetSearchDialog
20 */
21public final class TaggingPresetSearchPrimitiveDialog extends ExtendedDialog {
22
23 private static TaggingPresetSearchPrimitiveDialog instance;
24
25 private final TaggingPresetSelector selector;
26
27 /**
28 * An action executing {@link TaggingPresetSearchPrimitiveDialog}.
29 */
30 public static class Action extends JosmAction {
31
32 /**
33 * Constructs a new {@link TaggingPresetSearchPrimitiveDialog.Action}.
34 */
35 public Action() {
36 super(tr("Search for objects by preset..."), "dialogs/search", tr("Show preset search dialog"),
37 Shortcut.registerShortcut("preset:search-objects", tr("Search for objects by preset"), KeyEvent.VK_F3, Shortcut.SHIFT),
38 false);
39 putValue("toolbar", "presets/search-objects");
40 Main.toolbar.register(this);
41 }
42
43 @Override
44 public void actionPerformed(ActionEvent e) {
45 if (Main.getLayerManager().getEditLayer() != null) {
46 TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
47 }
48 }
49
50 @Override
51 protected void updateEnabledState() {
52 setEnabled(getLayerManager().getEditLayer() != null);
53 }
54 }
55
56 /**
57 * Returns the unique instance of {@code TaggingPresetSearchPrimitiveDialog}.
58 * @return the unique instance of {@code TaggingPresetSearchPrimitiveDialog}.
59 */
60 public static synchronized TaggingPresetSearchPrimitiveDialog getInstance() {
61 if (instance == null) {
62 instance = new TaggingPresetSearchPrimitiveDialog();
63 }
64 return instance;
65 }
66
67 TaggingPresetSearchPrimitiveDialog() {
68 super(Main.parent, tr("Presets"), tr("Search"), tr("Cancel"));
69 selector = new TaggingPresetSelector(false, false);
70 setContent(selector, false);
71 selector.setDblClickListener(e -> buttonAction(0, null));
72 }
73
74 @Override
75 public ExtendedDialog showDialog() {
76 selector.init();
77 super.showDialog();
78 selector.clearSelection();
79 return this;
80 }
81
82 @Override
83 protected void buttonAction(int buttonIndex, ActionEvent evt) {
84 super.buttonAction(buttonIndex, evt);
85 if (buttonIndex == 0) {
86 TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
87 if (preset != null) {
88 final Set<OsmPrimitive> matching = new HashSet<>(Main.getLayerManager().getEditDataSet().getPrimitives(preset));
89 Main.getLayerManager().getEditDataSet().setSelected(matching);
90 }
91 }
92 }
93}
Note: See TracBrowser for help on using the repository browser.