001 /* 002 * Copyright 2002-2006 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 005 * use this file except in compliance with the License. You may obtain a copy 006 * of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 013 * License for the specific language governing permissions and limitations 014 * under the License. 015 */ 016 package org.springframework.richclient.list; 017 018 import javax.swing.ComboBoxModel; 019 import javax.swing.ListModel; 020 021 /** 022 * Simple adapter to create a {@link ComboBoxModel} from an existing {@link ListModel} 023 * 024 * @author Mathias Broekelmann 025 */ 026 public class ComboBoxListModelAdapter extends AbstractFilteredListModel implements ComboBoxModel { 027 028 private Object selectedItem; 029 030 /** 031 * Constructs a new instance with a given listModel 032 * 033 * @param listModel 034 * the listmodel containing the elements 035 * 036 * @throws IllegalArgumentException 037 * if listModel is null 038 */ 039 public ComboBoxListModelAdapter(ListModel listModel) { 040 super(listModel); 041 } 042 043 public Object getSelectedItem() { 044 return selectedItem; 045 } 046 047 public void setSelectedItem(Object anItem) { 048 this.selectedItem = anItem; 049 fireContentsChanged(this, -1, -1); 050 } 051 052 }