source: josm/trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetSearchDialog.java@ 9422

Last change on this file since 9422 was 9422, checked in by simon04, 8 years ago

see #12237 - Preset search: fix NPE when having selected a preset which is no longer shown after filtering

To reproduce: Select a primitive, open the preset search, select the first preset, type nonsense in the filter box

  • Property svn:eol-style set to native
File size: 2.0 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;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.DataSet;
11import org.openstreetmap.josm.gui.ExtendedDialog;
12
13/**
14 * The tagging presets search dialog (F3).
15 * @since 3388
16 */
17public final class TaggingPresetSearchDialog extends ExtendedDialog {
18
19 private static TaggingPresetSearchDialog instance;
20
21 private final TaggingPresetSelector selector;
22
23 /**
24 * Returns the unique instance of {@code TaggingPresetSearchDialog}.
25 * @return the unique instance of {@code TaggingPresetSearchDialog}.
26 */
27 public static synchronized TaggingPresetSearchDialog getInstance() {
28 if (instance == null) {
29 instance = new TaggingPresetSearchDialog();
30 }
31 return instance;
32 }
33
34 private TaggingPresetSearchDialog() {
35 super(Main.parent, tr("Presets"), new String[] {tr("Select"), tr("Cancel")});
36 selector = new TaggingPresetSelector(true, true);
37 setContent(selector, false);
38 DataSet.addSelectionListener(selector);
39 selector.setDblClickListener(new ActionListener() {
40 @Override
41 public void actionPerformed(ActionEvent e) {
42 buttonAction(0, null);
43 }
44 });
45 }
46
47 @Override
48 public ExtendedDialog showDialog() {
49 selector.init();
50 super.showDialog();
51 selector.clearSelection();
52 return this;
53 }
54
55 @Override
56 protected void buttonAction(int buttonIndex, ActionEvent evt) {
57 super.buttonAction(buttonIndex, evt);
58 if (buttonIndex == 0) {
59 TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
60 if (preset != null) {
61 preset.actionPerformed(null);
62 }
63 }
64 selector.savePreferences();
65 }
66}
Note: See TracBrowser for help on using the repository browser.