Last change
on this file was 18313, checked in by Don-vip, 2 years 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.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import 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 | */
|
---|
11 | public 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.