Coverage details for edu.uci.ics.jung.utils.DefaultChangeEventSupport

LineHitsSource
1 /*
2  * Copyright (c) 2005, the JUNG Project and the Regents of the University of
3  * California All rights reserved.
4  *
5  * This software is open-source under the BSD license; see either "license.txt"
6  * or http://jung.sourceforge.net/license.txt for a description.
7  *
8  * Created on Aug 18, 2005
9  */
10  
11 package edu.uci.ics.jung.utils;
12  
13 import javax.swing.event.ChangeEvent;
14 import javax.swing.event.ChangeListener;
15 import javax.swing.event.EventListenerList;
16  
17 public class DefaultChangeEventSupport implements ChangeEventSupport {
18     
19     Object eventSource;
20     /**
21      * holds the registered listeners
22      */
2318    protected EventListenerList listenerList = new EventListenerList();
24  
25     /**
26      * Only one <code>ChangeEvent</code> is needed
27      * instance since the
28      * event's only state is the source property. The source of events
29      * generated is always "this".
30      */
31     protected transient ChangeEvent changeEvent;
32     
3318    public DefaultChangeEventSupport(Object eventSource) {
3418        this.eventSource = eventSource;
3518    }
36  
37     /* (non-Javadoc)
38      * @see edu.uci.ics.jung.utils.ChangeEventSupport#addChangeListener(javax.swing.event.ChangeListener)
39      */
40     public void addChangeListener(ChangeListener l) {
410        listenerList.add(ChangeListener.class, l);
420    }
43     
44     /* (non-Javadoc)
45      * @see edu.uci.ics.jung.utils.ChangeEventSupport#removeChangeListener(javax.swing.event.ChangeListener)
46      */
47     public void removeChangeListener(ChangeListener l) {
480        listenerList.remove(ChangeListener.class, l);
490    }
50     
51     /* (non-Javadoc)
52      * @see edu.uci.ics.jung.utils.ChangeEventSupport#getChangeListeners()
53      */
54     public ChangeListener[] getChangeListeners() {
550        return (ChangeListener[])(listenerList.getListeners(
56             ChangeListener.class));
57     }
58  
59     /**
60      * Notifies all listeners that have registered interest for
61      * notification on this event type. The event instance
62      * is lazily created.
63      * The primary listeners will be views that need to be repainted
64      * because of changes in this model instance
65      * @see EventListenerList
66      */
67     public void fireStateChanged() {
68         // Guaranteed to return a non-null array
69100        Object[] listeners = listenerList.getListenerList();
70         // Process the listeners last to first, notifying
71         // those that are interested in this event
72100        for (int i = listeners.length-2; i>=0; i-=2) {
730            if (listeners[i]==ChangeListener.class) {
74                 // Lazily create the event:
750                if (changeEvent == null)
760                    changeEvent = new ChangeEvent(eventSource);
770                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
78             }
79         }
80100    }
81  
82 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.