Source code: ledestin/swing/ListComboBoxModel.java
1 /*
2 * Copyright (C) 2000-2001 Dmitry Macsema. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted under the terms of the following
6 * Open Source license:
7 *
8 * The GNU General Public License, version 2, or any later version, as
9 * published by the Free Software Foundation
10 * (http://www.fsf.org/copyleft/gpl.html);
11 */
12
13 package ledestin.swing;
14
15 import javax.swing.*;
16 import java.util.*;
17
18 public class ListComboBoxModel extends AbstractListModel implements ComboBoxModel {
19 List data;
20 Object selected = null;
21 public ListComboBoxModel(List data) {
22 this.data = data;
23 }
24 public int getSize() {
25 return data.size();
26 }
27 /**
28 This method must be overriden depending on the type of the objects
29 in the data.
30 */
31 protected String getElementText(Object element) {
32 return element.toString();
33 }
34 public Object getElementAt(int index) {
35 return getElementText(data.get(index));
36 }
37 public Object getSelectedItem() {
38 return selected;
39 }
40 public void setSelectedItem(Object anItem) {
41 selected = anItem;
42 }
43 public void fireContentsChanged() {
44 super.fireContentsChanged(this, 0, data.size()-1);
45 }
46 }