001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.widgets; 003 004import org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBox; 005 006/** 007 * A History ComboBox 008 * <p> 009 * A HistoryComboBox is an {@link AutoCompComboBox} specialized in {@code String}s. 010 */ 011public class HistoryComboBox extends AutoCompComboBox<String> { 012 013 /** 014 * Constructs a new {@code HistoryComboBox}. 015 */ 016 public HistoryComboBox() { 017 super(new HistoryComboBoxModel()); 018 setPrototypeDisplayValue("dummy"); 019 } 020 021 @Override 022 public HistoryComboBoxModel getModel() { 023 return (HistoryComboBoxModel) dataModel; 024 } 025 026 /** 027 * Adds the item in the editor to the top of the history. If the item is already present, don't 028 * add another but move it to the top. The item is then selected. 029 */ 030 public void addCurrentItemToHistory() { 031 String item = getEditorItemAsString(); 032 if (item != null) { 033 getModel().setSelectedItem(getModel().addTopElement(item)); 034 } 035 } 036}