01: /*
02: * $Id: ChangeReport.java,v 1.1 2006/11/01 16:23:07 kleopatra Exp $
03: *
04: * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
05: * Santa Clara, California 95054, U.S.A. All rights reserved.
06: */
07:
08: package org.jdesktop.test;
09:
10: import java.util.HashMap;
11: import java.util.LinkedList;
12: import java.util.List;
13: import java.util.Map;
14:
15: import javax.swing.event.ChangeEvent;
16: import javax.swing.event.ChangeListener;
17:
18: /**
19: * A ChangeListener that stores the received ChangeEvents.
20: *
21: */
22: public class ChangeReport implements ChangeListener {
23:
24: /**
25: * Holds a list of all received PropertyChangeEvents.
26: */
27: protected List events = new LinkedList();
28: protected Map eventMap = new HashMap();
29:
30: //------------------------ implement PropertyChangeListener
31:
32: public void stateChanged(ChangeEvent evt) {
33: events.add(0, evt);
34: if (evt.getSource() != null) {
35: eventMap.put(evt.getSource(), evt);
36: }
37: }
38:
39: public int getEventCount() {
40: return events.size();
41: }
42:
43: public void clear() {
44: events.clear();
45: eventMap.clear();
46: }
47:
48: public boolean hasEvents() {
49: return !events.isEmpty();
50: }
51:
52: public ChangeEvent getLastEvent() {
53: return events.isEmpty() ? null : (ChangeEvent) events.get(0);
54: }
55:
56: public ChangeEvent getEvent(Object source) {
57: return (ChangeEvent) eventMap.get(source);
58: }
59:
60: }
|