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

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

see #13001 - replace calls to Main.main.getCurrentDataSet() by Main.getLayerManager().getEditDataSet()

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