KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bcel > verifier > VerifierFactoryListModel


1 /*
2  * Copyright 2000-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 JavaDoc;
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 org.apache.bcel.verifier.VerifierFactoryObserver,
29         javax.swing.ListModel JavaDoc {
30
31     private java.util.ArrayList JavaDoc listeners = new java.util.ArrayList JavaDoc();
32     private java.util.TreeSet JavaDoc cache = new java.util.TreeSet JavaDoc();
33
34
35     public VerifierFactoryListModel() {
36         VerifierFactory.attach(this);
37         update(null); // fill cache.
38
}
39
40
41     public synchronized void update( String JavaDoc s ) {
42         int size = listeners.size();
43         Verifier[] verifiers = VerifierFactory.getVerifiers();
44         int num_of_verifiers = verifiers.length;
45         cache.clear();
46         for (int i = 0; i < num_of_verifiers; i++) {
47             cache.add(verifiers[i].getClassName());
48         }
49         for (int i = 0; i < size; i++) {
50             ListDataEvent JavaDoc e = new ListDataEvent JavaDoc(this, ListDataEvent.CONTENTS_CHANGED, 0,
51                     num_of_verifiers - 1);
52             ((javax.swing.event.ListDataListener JavaDoc) (listeners.get(i))).contentsChanged(e);
53         }
54     }
55
56
57     public synchronized void addListDataListener( javax.swing.event.ListDataListener JavaDoc l ) {
58         listeners.add(l);
59     }
60
61
62     public synchronized void removeListDataListener( javax.swing.event.ListDataListener JavaDoc l ) {
63         listeners.remove(l);
64     }
65
66
67     public synchronized int getSize() {
68         return cache.size();
69     }
70
71
72     public synchronized Object JavaDoc getElementAt( int index ) {
73         return (cache.toArray())[index];
74     }
75 }
76
Popular Tags