1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * A History ComboBox
|
---|
10 | * <p>
|
---|
11 | * A HistoryComboBox is an {@link AutoCompComboBox} specialized in {@code String}s.
|
---|
12 | */
|
---|
13 | public class HistoryComboBox extends AutoCompComboBox<String> {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Constructs a new {@code HistoryComboBox}.
|
---|
17 | */
|
---|
18 | public HistoryComboBox() {
|
---|
19 | super(new HistoryComboBoxModel());
|
---|
20 | setPrototypeDisplayValue("dummy");
|
---|
21 | }
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public HistoryComboBoxModel getModel() {
|
---|
25 | return (HistoryComboBoxModel) dataModel;
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Adds the item in the editor to the top of the history. If the item is already present, don't
|
---|
30 | * add another but move it to the top. The item is then selected.
|
---|
31 | */
|
---|
32 | public void addCurrentItemToHistory() {
|
---|
33 | String newItem = getModel().addTopElement(getEditor().getItem().toString());
|
---|
34 | getModel().setSelectedItem(newItem);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Returns the items as strings
|
---|
39 | * @return the items as strings
|
---|
40 | * @deprecated Has been moved to the model, where it belongs. Use
|
---|
41 | * {@link HistoryComboBoxModel#asStringList} instead. Probably you want to use
|
---|
42 | * {@link HistoryComboBoxModel.Preferences#load} and
|
---|
43 | * {@link HistoryComboBoxModel.Preferences#save}.
|
---|
44 | */
|
---|
45 | @Deprecated
|
---|
46 | public List<String> getHistory() {
|
---|
47 | return getModel().asStringList();
|
---|
48 | }
|
---|
49 | }
|
---|