KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > util > ValueChangeReport


1 /*
2  * $Id: ValueChangeReport.java,v 1.1 2004/11/29 16:12:22 kleopatra Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.util;
9
10 import java.util.*;
11
12 import org.jdesktop.swing.data.ValueChangeEvent;
13 import org.jdesktop.swing.data.ValueChangeListener;
14
15 /**
16  * A ValueChangeListener that stores the received ValueChangeEvents.
17  */

18 public class ValueChangeReport implements ValueChangeListener {
19
20     /**
21      * Holds a list of all received ValueChangeEvents.
22      */

23     private List events = new LinkedList();
24
25     //---------------------- implement ValueChangeListener
26

27     public void valueChanged(ValueChangeEvent evt) {
28         events.add(0, evt);
29     }
30
31     public int getEventCount() {
32         return events.size();
33     }
34
35     public boolean hasEvents() {
36         return !events.isEmpty();
37     }
38
39     public ValueChangeEvent getLastEvent() {
40         return events.isEmpty() ? null : (ValueChangeEvent) events.get(0);
41     }
42
43     public String JavaDoc getLastFieldName() {
44         return getLastEvent().getFieldName();
45     }
46
47     public boolean gotEvent(Object JavaDoc fieldName) {
48         for (Iterator iter = events.iterator(); iter.hasNext();) {
49             ValueChangeEvent event = (ValueChangeEvent) iter.next();
50             if (fieldName.equals(event.getFieldName()))
51                 return true;
52         }
53         return false;
54     }
55
56     public void clear() {
57         events.clear();
58     }
59 }
Popular Tags