01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings;
14:
15: import javax.swing.*;
16: import java.util.List;
17:
18: /**
19: * Default implementation of a model for {@link SComboBox} components.
20: *
21: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
22: */
23: public class SDefaultComboBoxModel extends SDefaultListModel implements
24: MutableComboBoxModel {
25: protected Object selectedItem = null;
26:
27: public SDefaultComboBoxModel(List d) {
28: super (d);
29: }
30:
31: public SDefaultComboBoxModel(Object[] d) {
32: super (d);
33: }
34:
35: public SDefaultComboBoxModel() {
36: }
37:
38: public void setSelectedItem(Object anItem) {
39: selectedItem = anItem;
40: }
41:
42: public Object getSelectedItem() {
43: return selectedItem;
44: }
45:
46: public void addElement(Object obj) {
47: data.add(obj);
48: fireIntervalAdded(this , getSize() - 1, getSize() - 1);
49: }
50:
51: public void removeElement(Object obj) {
52: int index = data.indexOf(obj);
53: removeElementAt(index);
54: }
55:
56: public void insertElementAt(Object obj, int index) {
57: data.add(index, obj);
58: fireIntervalAdded(this , Math.min(index, getSize() - 1), Math
59: .min(index, getSize() - 1));
60: }
61:
62: public void removeElementAt(int index) {
63: if (index >= 0 && index < getSize()) {
64: data.remove(index);
65: fireIntervalRemoved(this, index, index);
66: }
67: }
68: }
|