KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TabularValueChangeReport.java,v 1.1 2005/02/25 17:52:59 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.TabularValueChangeEvent;
13 import org.jdesktop.swing.data.TabularValueChangeListener;
14 import org.jdesktop.swing.data.ValueChangeEvent;
15 import org.jdesktop.swing.data.ValueChangeListener;
16
17 /**
18  * A ValueChangeListener that stores the received ValueChangeEvents.
19  */

20 public class TabularValueChangeReport implements TabularValueChangeListener {
21
22     /**
23      * Holds a list of all received ValueChangeEvents.
24      */

25     private List events = new LinkedList();
26
27     //---------------------- implement ValueChangeListener
28

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