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

Last change on this file was 18682, checked in by Klumbumbus, 17 months ago

fix #22784, fix #22785, fix #22786 - Add context sensitive help links, patches by gaben

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.tagging.presets;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.awt.event.KeyEvent;
9import java.util.HashSet;
10
11import org.openstreetmap.josm.actions.JosmAction;
12import org.openstreetmap.josm.data.osm.OsmData;
13import org.openstreetmap.josm.gui.ExtendedDialog;
14import org.openstreetmap.josm.gui.MainApplication;
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("Search for objects by their presets."),
37 Shortcut.registerShortcut("preset:search-objects", tr("Presets: {0}", tr("Search for objects by preset...")),
38 KeyEvent.VK_F3, Shortcut.SHIFT), true, "presets/search-objects", true);
39 setHelpId(ht("/Action/TaggingPresetSearchPrimitive"));
40 }
41
42 @Override
43 public void actionPerformed(ActionEvent e) {
44 if (MainApplication.getLayerManager().getActiveData() != null) {
45 TaggingPresetSearchPrimitiveDialog.getInstance().showDialog();
46 }
47 }
48
49 @Override
50 protected void updateEnabledState() {
51 setEnabled(getLayerManager().getActiveData() != null);
52 }
53 }
54
55 /**
56 * Returns the unique instance of {@code TaggingPresetSearchPrimitiveDialog}.
57 * @return the unique instance of {@code TaggingPresetSearchPrimitiveDialog}.
58 */
59 public static synchronized TaggingPresetSearchPrimitiveDialog getInstance() {
60 if (instance == null) {
61 instance = new TaggingPresetSearchPrimitiveDialog();
62 }
63 return instance;
64 }
65
66 TaggingPresetSearchPrimitiveDialog() {
67 super(MainApplication.getMainFrame(), tr("Search for objects by preset"), tr("Search"), tr("Cancel"));
68 setButtonIcons("dialogs/search", "cancel");
69 configureContextsensitiveHelp("/Action/TaggingPresetSearchPrimitive", true /* show help button */);
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 OsmData<?, ?, ?, ?> ds = MainApplication.getLayerManager().getActiveData();
90 ds.setSelected(new HashSet<>(ds.getPrimitives(preset)));
91 }
92 }
93 }
94}
Note: See TracBrowser for help on using the repository browser.