01: /*
02: * Copyright 2000-2004 The Apache Software Foundation
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: *
16: */
17: package org.apache.bcel.verifier;
18:
19: import javax.swing.event.ListDataEvent;
20:
21: /**
22: * This class implements an adapter; it implements both a Swing ListModel and
23: * a VerifierFactoryObserver.
24: *
25: * @version $Id: VerifierFactoryListModel.java 386056 2006-03-15 11:31:56Z tcurdt $
26: * @author Enver Haase
27: */
28: public class VerifierFactoryListModel implements
29: org.apache.bcel.verifier.VerifierFactoryObserver,
30: javax.swing.ListModel {
31:
32: private java.util.ArrayList listeners = new java.util.ArrayList();
33: private java.util.TreeSet cache = new java.util.TreeSet();
34:
35: public VerifierFactoryListModel() {
36: VerifierFactory.attach(this );
37: update(null); // fill cache.
38: }
39:
40: public synchronized void update(String s) {
41: int size = listeners.size();
42: Verifier[] verifiers = VerifierFactory.getVerifiers();
43: int num_of_verifiers = verifiers.length;
44: cache.clear();
45: for (int i = 0; i < num_of_verifiers; i++) {
46: cache.add(verifiers[i].getClassName());
47: }
48: for (int i = 0; i < size; i++) {
49: ListDataEvent e = new ListDataEvent(this ,
50: ListDataEvent.CONTENTS_CHANGED, 0,
51: num_of_verifiers - 1);
52: ((javax.swing.event.ListDataListener) (listeners.get(i)))
53: .contentsChanged(e);
54: }
55: }
56:
57: public synchronized void addListDataListener(
58: javax.swing.event.ListDataListener l) {
59: listeners.add(l);
60: }
61:
62: public synchronized void removeListDataListener(
63: javax.swing.event.ListDataListener l) {
64: listeners.remove(l);
65: }
66:
67: public synchronized int getSize() {
68: return cache.size();
69: }
70:
71: public synchronized Object getElementAt(int index) {
72: return (cache.toArray())[index];
73: }
74: }
|