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

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

fix #12626 - Rename F3 search dialog and Shift+F3 dialog from "Presets"

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