01: /*
02: * $Id: TreeSelectionReport.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.util.LinkedList;
11: import java.util.List;
12:
13: import javax.swing.event.TreeSelectionEvent;
14: import javax.swing.event.TreeSelectionListener;
15:
16: /**
17: * A TreeSelectionListener that stores the received TreeSelectionEvents.
18: *
19: *
20: */
21: public class TreeSelectionReport implements TreeSelectionListener {
22:
23: /**
24: * Holds a list of all received PropertyChangeEvents.
25: */
26: protected List<TreeSelectionEvent> events = new LinkedList<TreeSelectionEvent>();
27:
28: //------------------------ implement ListSelectionListener
29:
30: public void valueChanged(TreeSelectionEvent e) {
31: events.add(0, e);
32:
33: }
34:
35: public void clear() {
36: events.clear();
37: }
38:
39: public boolean hasEvents() {
40: return !events.isEmpty();
41: }
42:
43: public int getEventCount() {
44: return events.size();
45: }
46:
47: public TreeSelectionEvent getLastEvent() {
48: return getLastFrom(events);
49:
50: }
51:
52: private TreeSelectionEvent getLastFrom(List<TreeSelectionEvent> list) {
53: return list.isEmpty() ? null : list.get(0);
54: }
55:
56: }
|