1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.aequo;
14
15 import java.util.ArrayList;
16
17 import javax.swing.ListModel;
18 import javax.swing.event.ListDataEvent;
19 import javax.swing.event.ListDataListener;
20
21
22
23
24
25
26
27
28 public class ListModelAdapter implements ListModel, ListDataListener {
29
30
31 protected final CompareModel<?, ?> model;
32
33
34 protected ArrayList<ListDataListener> listeners = new ArrayList<ListDataListener>();
35
36
37
38
39
40
41 public ListModelAdapter(CompareModel<?, ?> compareModel) {
42 this.model = compareModel;
43 }
44
45
46
47
48
49 public int getSize() {
50 return this.model.getSize();
51 }
52
53
54
55
56
57
58 public void addListDataListener(ListDataListener l) {
59 listeners.add(l);
60 if (listeners.size() == 1) {
61 this.model.addListDataListener(this);
62 }
63 }
64
65
66
67
68
69
70 public void removeListDataListener(ListDataListener l) {
71 listeners.remove(l);
72 if (listeners.size() == 0) {
73 this.model.removeListDataListener(this);
74 }
75 }
76
77
78
79
80
81 public void contentsChanged(ListDataEvent e) {
82 for (ListDataListener listener : listeners) {
83 listener.contentsChanged(e);
84 }
85 }
86
87
88
89
90
91 public void intervalAdded(ListDataEvent e) {
92 for (ListDataListener listener : listeners) {
93 listener.intervalAdded(e);
94 }
95 }
96
97
98
99
100
101 public void intervalRemoved(ListDataEvent e) {
102 for (ListDataListener listener : listeners) {
103 listener.intervalRemoved(e);
104 }
105 }
106
107
108
109
110
111 public Object getElementAt(int index) {
112 return model.getElementAt(index);
113 }
114 }