1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.tagging.presets;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
10 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * The tagging presets search dialog (F3).
|
---|
14 | * @since 3388
|
---|
15 | */
|
---|
16 | public final class TaggingPresetSearchDialog extends ExtendedDialog {
|
---|
17 |
|
---|
18 | private static TaggingPresetSearchDialog instance;
|
---|
19 |
|
---|
20 | private final TaggingPresetSelector selector;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Returns the unique instance of {@code TaggingPresetSearchDialog}.
|
---|
24 | * @return the unique instance of {@code TaggingPresetSearchDialog}.
|
---|
25 | */
|
---|
26 | public static synchronized TaggingPresetSearchDialog getInstance() {
|
---|
27 | if (instance == null) {
|
---|
28 | instance = new TaggingPresetSearchDialog();
|
---|
29 | }
|
---|
30 | return instance;
|
---|
31 | }
|
---|
32 |
|
---|
33 | private TaggingPresetSearchDialog() {
|
---|
34 | super(Main.parent, tr("Presets"), new String[] {tr("Select"), tr("Cancel")});
|
---|
35 | selector = new TaggingPresetSelector(true, true);
|
---|
36 | setContent(selector, false);
|
---|
37 | DataSet.addSelectionListener(selector);
|
---|
38 | selector.setDblClickListener(e -> buttonAction(0, null));
|
---|
39 | }
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public ExtendedDialog showDialog() {
|
---|
43 | selector.init();
|
---|
44 | super.showDialog();
|
---|
45 | selector.clearSelection();
|
---|
46 | return this;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Override
|
---|
50 | protected void buttonAction(int buttonIndex, ActionEvent evt) {
|
---|
51 | super.buttonAction(buttonIndex, evt);
|
---|
52 | if (buttonIndex == 0) {
|
---|
53 | TaggingPreset preset = selector.getSelectedPresetAndUpdateClassification();
|
---|
54 | if (preset != null) {
|
---|
55 | preset.actionPerformed(null);
|
---|
56 | }
|
---|
57 | }
|
---|
58 | selector.savePreferences();
|
---|
59 | }
|
---|
60 | }
|
---|