source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBox.java

Last change on this file was 18313, checked in by Don-vip, 16 months ago

fix #21509 - fix potential NPEs related to comboboxes

  • Property svn:eol-style set to native
File size: 1.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox;
5
6/**
7 * A History ComboBox
8 * <p>
9 * A HistoryComboBox is an {@link AutoCompComboBox} specialized in {@code String}s.
10 */
11public class HistoryComboBox extends AutoCompComboBox<String> {
12
13    /**
14     * Constructs a new {@code HistoryComboBox}.
15     */
16    public HistoryComboBox() {
17        super(new HistoryComboBoxModel());
18        setPrototypeDisplayValue("dummy");
19    }
20
21    @Override
22    public HistoryComboBoxModel getModel() {
23        return (HistoryComboBoxModel) dataModel;
24    }
25
26    /**
27     * Adds the item in the editor to the top of the history. If the item is already present, don't
28     * add another but move it to the top. The item is then selected.
29     */
30    public void addCurrentItemToHistory() {
31        String item = getEditorItemAsString();
32        if (item != null) {
33            getModel().setSelectedItem(getModel().addTopElement(item));
34        }
35    }
36}
Note: See TracBrowser for help on using the repository browser.