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

Line | Hits | Source
--- | --- | ---
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 |  | `*/`
23 | 18 | `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 |  | ``
33 | 18 | `public DefaultChangeEventSupport(Object eventSource) {`
34 | 18 | `this.eventSource = eventSource;`
35 | 18 | `}`
36 |  | ``
37 |  | `/* (non-Javadoc)`
38 |  | `* @see edu.uci.ics.jung.utils.ChangeEventSupport#addChangeListener(javax.swing.event.ChangeListener)`
39 |  | `*/`
40 |  | `public void addChangeListener(ChangeListener l) {`
41 | 0 | `listenerList.add(ChangeListener.class, l);`
42 | 0 | `}`
43 |  | ``
44 |  | `/* (non-Javadoc)`
45 |  | `* @see edu.uci.ics.jung.utils.ChangeEventSupport#removeChangeListener(javax.swing.event.ChangeListener)`
46 |  | `*/`
47 |  | `public void removeChangeListener(ChangeListener l) {`
48 | 0 | `listenerList.remove(ChangeListener.class, l);`
49 | 0 | `}`
50 |  | ``
51 |  | `/* (non-Javadoc)`
52 |  | `* @see edu.uci.ics.jung.utils.ChangeEventSupport#getChangeListeners()`
53 |  | `*/`
54 |  | `public ChangeListener[] getChangeListeners() {`
55 | 0 | `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`
69 | 100 | `Object[] listeners = listenerList.getListenerList();`
70 |  | `// Process the listeners last to first, notifying`
71 |  | `// those that are interested in this event`
72 | 100 | `for (int i = listeners.length-2; i>=0; i-=2) {`
73 | 0 | `if (listeners[i]==ChangeListener.class) {`
74 |  | `// Lazily create the event:`
75 | 0 | `if (changeEvent == null)`
76 | 0 | `changeEvent = new ChangeEvent(eventSource);`
77 | 0 | `((ChangeListener)listeners[i+1]).stateChanged(changeEvent);`
78 |  | `}`
79 |  | `}`
80 | 100 | `}`
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.