01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package javax.swing;
19:
20: import java.io.Serializable;
21: import javax.swing.event.EventListenerList;
22: import javax.swing.event.ListDataEvent;
23: import javax.swing.event.ListDataListener;
24:
25: public abstract class AbstractListModel implements ListModel,
26: Serializable {
27: protected EventListenerList listenerList = new EventListenerList();
28:
29: public void addListDataListener(final ListDataListener l) {
30: listenerList.add(ListDataListener.class, l);
31: }
32:
33: public void removeListDataListener(final ListDataListener l) {
34: listenerList.remove(ListDataListener.class, l);
35: }
36:
37: public ListDataListener[] getListDataListeners() {
38: return getListeners(ListDataListener.class);
39: }
40:
41: public <T extends java.util.EventListener> T[] getListeners(
42: final Class<T> listenerType) {
43: return listenerList.getListeners(listenerType);
44: }
45:
46: protected void fireContentsChanged(final Object source,
47: final int index0, final int index1) {
48: ListDataEvent event = new ListDataEvent(source,
49: ListDataEvent.CONTENTS_CHANGED, index0, index1);
50: ListDataListener[] listeners = getListDataListeners();
51: for (int i = 0; i < listeners.length; i++) {
52: listeners[i].contentsChanged(event);
53: }
54: }
55:
56: protected void fireIntervalAdded(final Object source,
57: final int index0, final int index1) {
58: ListDataEvent event = new ListDataEvent(source,
59: ListDataEvent.INTERVAL_ADDED, index0, index1);
60: ListDataListener[] listeners = getListDataListeners();
61: for (int i = 0; i < listeners.length; i++) {
62: listeners[i].intervalAdded(event);
63: }
64: }
65:
66: protected void fireIntervalRemoved(final Object source,
67: final int index0, final int index1) {
68: ListDataEvent event = new ListDataEvent(source,
69: ListDataEvent.INTERVAL_REMOVED, index0, index1);
70: ListDataListener[] listeners = getListDataListeners();
71: for (int i = 0; i < listeners.length; i++) {
72: listeners[i].intervalRemoved(event);
73: }
74: }
75: }
|