01: /*
02: * $Id: CellEditorReport.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.LinkedList;
11: import java.util.List;
12:
13: import javax.swing.event.CellEditorListener;
14: import javax.swing.event.ChangeEvent;
15:
16: /**
17: * A CellEditorListener that stores the received ChangeEvents.
18: *
19: */
20: public class CellEditorReport implements CellEditorListener {
21:
22: /**
23: * Holds a list of all canceled events.
24: */
25: protected List<ChangeEvent> canceledEvents = new LinkedList<ChangeEvent>();
26: protected List<ChangeEvent> stoppedEvents = new LinkedList<ChangeEvent>();
27: protected List<ChangeEvent> allEvents = new LinkedList<ChangeEvent>();
28:
29: //------------------------ implement CellEditorListener
30:
31: public void editingCanceled(ChangeEvent e) {
32: canceledEvents.add(0, e);
33: allEvents.add(0, e);
34: }
35:
36: public void editingStopped(ChangeEvent e) {
37: stoppedEvents.add(e);
38: allEvents.add(0, e);
39:
40: }
41:
42: //----------------------- utility methods to access all events
43: public void clear() {
44: canceledEvents.clear();
45: stoppedEvents.clear();
46: allEvents.clear();
47: }
48:
49: public int getEventCount() {
50: return allEvents.size();
51: }
52:
53: public boolean hasEvents() {
54: return !allEvents.isEmpty();
55: }
56:
57: public ChangeEvent getLastEvent() {
58: return allEvents.isEmpty() ? null : allEvents.get(0);
59: }
60:
61: //------------------ access canceled events
62: public int getCanceledEventCount() {
63: return canceledEvents.size();
64: }
65:
66: public boolean hasCanceledEvents() {
67: return !canceledEvents.isEmpty();
68: }
69:
70: public ChangeEvent getLastCanceledEvent() {
71: return canceledEvents.isEmpty() ? null : canceledEvents.get(0);
72: }
73:
74: //----------------- access stopped events
75:
76: public int getStoppedEventCount() {
77: return stoppedEvents.size();
78: }
79:
80: public boolean hasStoppedEvents() {
81: return !stoppedEvents.isEmpty();
82: }
83:
84: public ChangeEvent getLastStoppedEvent() {
85: return stoppedEvents.isEmpty() ? null : stoppedEvents.get(0);
86: }
87:
88: }
|