01: /*
02: * $Id: ListSelectionReport.java,v 1.1 2006/11/01 16:23:06 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.beans.PropertyChangeEvent;
11: import java.util.Iterator;
12: import java.util.LinkedList;
13: import java.util.List;
14:
15: import javax.swing.event.ListSelectionEvent;
16: import javax.swing.event.ListSelectionListener;
17:
18: /**
19: * A PropertyChangeListener that stores the received PropertyChangeEvents.
20: *
21: * modified ("beanified") from JGoodies PropertyChangeReport.
22: *
23: */
24: public class ListSelectionReport implements ListSelectionListener {
25:
26: /**
27: * Holds a list of all received PropertyChangeEvents.
28: */
29: protected List<ListSelectionEvent> events = new LinkedList<ListSelectionEvent>();
30: protected List<ListSelectionEvent> notAdjustingEvents = new LinkedList<ListSelectionEvent>();
31:
32: //------------------------ implement ListSelectionListener
33:
34: public void valueChanged(ListSelectionEvent e) {
35: events.add(0, e);
36: if (!e.getValueIsAdjusting()) {
37: notAdjustingEvents.add(0, e);
38: }
39:
40: }
41:
42: public int getEventCount() {
43: return getEventCount(false);
44: }
45:
46: public void clear() {
47: events.clear();
48: notAdjustingEvents.clear();
49: }
50:
51: public boolean hasEvents() {
52: return !events.isEmpty();
53: }
54:
55: public int getEventCount(boolean notAdjusting) {
56: if (notAdjusting) {
57: return notAdjustingEvents.size();
58: }
59: return events.size();
60: }
61:
62: public ListSelectionEvent getLastEvent(boolean notAdjusting) {
63: if (notAdjusting) {
64: return getLastFrom(events);
65: }
66: return getLastFrom(notAdjustingEvents);
67:
68: }
69:
70: private ListSelectionEvent getLastFrom(List<ListSelectionEvent> list) {
71: return list.isEmpty() ? null : list.get(0);
72: }
73:
74: }
|