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

Last change on this file since 16282 was 16281, checked in by simon04, 4 years ago

Checkstyle

  • Property svn:eol-style set to native
File size: 3.4 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;
9
10import org.openstreetmap.josm.actions.JosmAction;
11import org.openstreetmap.josm.data.osm.OsmData;
12import org.openstreetmap.josm.gui.ExtendedDialog;
13import org.openstreetmap.josm.gui.MainApplication;
14import org.openstreetmap.josm.tools.Shortcut;
15
16/**
17 * A dialog that allows to select a preset and then selects all matching OSM objects.
18 * @see org.openstreetmap.josm.gui.tagging.presets.TaggingPresetSearchDialog
19 */
20public final class TaggingPresetSearchPrimitiveDialog extends ExtendedDialog {
21
22 private static TaggingPresetSearchPrimitiveDialog instance;
23
24 private final TaggingPresetSelector selector;
25
26 /**
27 * An action executing {@link TaggingPresetSearchPrimitiveDialog}.
28 */
29 public static class Action extends JosmAction {
30
31 /**
32 * Constructs a new {@link TaggingPresetSearchPrimitiveDialog.Action}.
33 */
34 public Action() {
35 super(tr("Search for objects by preset..."), "dialogs/search", tr("Search for objects by their presets."),
36 Shortcut.registerShortcut("preset:search-objects", tr("Search for objects by preset"), KeyEvent.VK_F3, Shortcut.SHIFT),
37 false);
38 putValue("toolbar", "presets/search-objects");
39 MainApplication.getToolbar().register(this);
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/TaggingPresetSearchPrimitiveDialog", 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.