1 17 package org.apache.bcel.verifier; 18 19 import javax.swing.event.ListDataEvent ; 20 21 28 public class VerifierFactoryListModel implements org.apache.bcel.verifier.VerifierFactoryObserver, 29 javax.swing.ListModel { 30 31 private java.util.ArrayList listeners = new java.util.ArrayList (); 32 private java.util.TreeSet cache = new java.util.TreeSet (); 33 34 35 public VerifierFactoryListModel() { 36 VerifierFactory.attach(this); 37 update(null); } 39 40 41 public synchronized void update( String 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 e = new ListDataEvent (this, ListDataEvent.CONTENTS_CHANGED, 0, 51 num_of_verifiers - 1); 52 ((javax.swing.event.ListDataListener ) (listeners.get(i))).contentsChanged(e); 53 } 54 } 55 56 57 public synchronized void addListDataListener( javax.swing.event.ListDataListener l ) { 58 listeners.add(l); 59 } 60 61 62 public synchronized void removeListDataListener( javax.swing.event.ListDataListener l ) { 63 listeners.remove(l); 64 } 65 66 67 public synchronized int getSize() { 68 return cache.size(); 69 } 70 71 72 public synchronized Object getElementAt( int index ) { 73 return (cache.toArray())[index]; 74 } 75 } 76 | Popular Tags |