KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > AbstractListModel


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: AbstractListModel.java,v $
11    Revision 1.4 2004/01/27 09:05:09 bobintetley
12    ListModel and List Selection implemented. ScrollPane fix so all components
13       scrollable
14
15    Revision 1.3 2003/12/15 17:41:16 bobintetley
16    Missing return value fixed
17
18    Revision 1.2 2003/12/15 17:39:11 bobintetley
19    Missing implementations completed
20
21    Revision 1.1 2003/12/15 17:37:18 bobintetley
22    ComboBox model interfaces and support
23
24
25 */

26
27 package swingwtx.swing;
28
29 import java.util.*;
30 import swingwtx.swing.event.*;
31
32 public abstract class AbstractListModel implements ListModel {
33     
34     protected Vector listenerList = new Vector();
35
36     public void addListDataListener(ListDataListener l) {
37     listenerList.add(l);
38     }
39
40     public void removeListDataListener(ListDataListener l) {
41     listenerList.remove(l);
42     }
43
44     public Object JavaDoc[] getListDataListeners() {
45         return listenerList.toArray();
46     }
47     
48     protected void fireContentsChanged(Object JavaDoc source, int index0, int index1) {
49     ListDataEvent e = new ListDataEvent(source, ListDataEvent.CONTENTS_CHANGED, index0, index1);
50     for (int i = 0; i < listenerList.size(); i++) {
51             ((ListDataListener) listenerList.get(i)).contentsChanged(e);
52     }
53     }
54
55     protected void fireIntervalAdded(Object JavaDoc source, int index0, int index1) {
56     ListDataEvent e = new ListDataEvent(source, ListDataEvent.INTERVAL_ADDED, index0, index1);
57     for (int i = 0; i < listenerList.size(); i++) {
58             ((ListDataListener) listenerList.get(i)).intervalAdded(e);
59     }
60     }
61
62     protected void fireIntervalRemoved(Object JavaDoc source, int index0, int index1) {
63     ListDataEvent e = new ListDataEvent(source, ListDataEvent.INTERVAL_REMOVED, index0, index1);
64     for (int i = 0; i < listenerList.size(); i++) {
65             ((ListDataListener) listenerList.get(i)).intervalRemoved(e);
66     }
67     }
68
69     public Object JavaDoc[] getListeners(Class JavaDoc listenerType) {
70     return listenerList.toArray();
71     }
72 }
73
74
Popular Tags