source: src/main/java/genius/gui/panels/ExtendedComboBoxModel.java@ 345

Last change on this file since 345 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 1.1 KB
RevLine 
[127]1package genius.gui.panels;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import javax.swing.AbstractListModel;
7import javax.swing.ComboBoxModel;
8
9/**
10 * Extends the default ListModel by allowing it to be loaded afterwards with
11 * data.
12 *
13 * @author Mark Hendrikx (m.j.c.hendrikx@student.tudelft.nl)
14 * @version 05/12/11
15 */
16public class ExtendedComboBoxModel<A> extends AbstractListModel<A> implements ComboBoxModel<A> {
17 private static final long serialVersionUID = -8345719619830961700L;
18 private List<A> items = new ArrayList<A>();
19 private A selection;
20
21 public void setInitialContent(List<A> items) {
22 this.items = items;
23
24 }
25
26 public A getElementAt(int index) {
27 if (index >= 0) {
28 return items.get(index);
29 }
30 return null;
31 }
32
33 public int getSize() {
34 return items.size();
35 }
36
37 public void removeElementAt(int i) {
38 items.remove(i);
39 }
40
41 @Override
42 public A getSelectedItem() {
43 return selection;
44 }
45
46 @SuppressWarnings("unchecked")
47 @Override
48 public void setSelectedItem(Object anItem) {
49 selection = (A) anItem;
50 }
[1]51}
Note: See TracBrowser for help on using the repository browser.