KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: PropertyChangeReport.java,v 1.2 2004/12/16 17:04:13 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
9 package org.jdesktop.swing.util;
10
11 import java.beans.PropertyChangeEvent JavaDoc;
12 import java.beans.PropertyChangeListener JavaDoc;
13 import java.util.*;
14
15 /**
16  * A PropertyChangeListener that stores the received PropertyChangeEvents.
17  *
18  * modified ("beanified") from JGoodies PropertyChangeReport.
19  *
20  */

21 public class PropertyChangeReport implements PropertyChangeListener JavaDoc {
22     
23     /**
24      * Holds a list of all received PropertyChangeEvents.
25      */

26     protected List events = new LinkedList();
27     
28 //------------------------ implement PropertyChangeListener
29

30     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
31         events.add(0, evt);
32     }
33     
34     public int getEventCount() {
35         return events.size();
36     }
37  
38     public void clear() {
39         events.clear();
40     }
41     
42     public boolean hasEvents() {
43         return !events.isEmpty();
44     }
45  
46     public int getEventCount(String JavaDoc property) {
47         if (property == null) return getMultiCastEventCount();
48         int count = 0;
49         for (Iterator iter = events.iterator(); iter.hasNext();) {
50             PropertyChangeEvent JavaDoc event = (PropertyChangeEvent JavaDoc) iter.next();
51             if (property.equals(event.getPropertyName())) {
52                 count++;
53             }
54         }
55         return count;
56     }
57     public int getMultiCastEventCount() {
58         int count = 0;
59         for (Iterator i = events.iterator(); i.hasNext();) {
60             PropertyChangeEvent JavaDoc event = (PropertyChangeEvent JavaDoc) i.next();
61             if (event.getPropertyName() == null)
62                 count++;
63         }
64         return 0;
65     }
66     
67     public int getNamedEventCount() {
68         return getEventCount() - getMultiCastEventCount();
69     }
70     
71     public PropertyChangeEvent JavaDoc getLastEvent() {
72         return events.isEmpty()
73             ? null
74             : (PropertyChangeEvent JavaDoc) events.get(0);
75     }
76     
77     public Object JavaDoc getLastOldValue() {
78         return getLastEvent().getOldValue();
79     }
80     
81     public Object JavaDoc getLastNewValue() {
82         return getLastEvent().getNewValue();
83     }
84     
85     public boolean getLastOldBooleanValue() {
86         return ((Boolean JavaDoc) getLastOldValue()).booleanValue();
87     }
88
89     public boolean getLastNewBooleanValue() {
90         return ((Boolean JavaDoc) getLastNewValue()).booleanValue();
91     }
92
93 }
94
Popular Tags