/*
* KeyValueComboBox
*
* Copyright (C) 2010 Jaroslav Merxbauer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package notwa.gui.components;
import javax.swing.JComboBox;
/**
*
* @author Jaroslav Merxbauer
* @version %I% %G%
*/
public class KeyValueComboBox<TKey> extends JComboBox {
public void addItem(TKey key, String value) {
super.addItem(new KeyValueItem<TKey> (key, value));
}
public void removeByKey(TKey key) {
super.removeItem(new KeyValueItem<TKey>(key));
}
public void setSelectedKey(TKey key) {
super.setSelectedItem(new KeyValueItem<TKey>(key));
}
@Override
public KeyValueItem<TKey> getSelectedItem() {
return (KeyValueItem<TKey>) super.getSelectedItem();
}
public TKey getSelectedKey() {
return getSelectedItem() != null ? getSelectedItem().getKey() : null;
}
}