1 7 8 9 package org.jdesktop.swing.util; 10 11 import java.beans.PropertyChangeEvent ; 12 import java.beans.PropertyChangeListener ; 13 import java.util.*; 14 15 21 public class PropertyChangeReport implements PropertyChangeListener { 22 23 26 protected List events = new LinkedList(); 27 28 30 public void propertyChange(PropertyChangeEvent 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 property) { 47 if (property == null) return getMultiCastEventCount(); 48 int count = 0; 49 for (Iterator iter = events.iterator(); iter.hasNext();) { 50 PropertyChangeEvent event = (PropertyChangeEvent ) 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 event = (PropertyChangeEvent ) 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 getLastEvent() { 72 return events.isEmpty() 73 ? null 74 : (PropertyChangeEvent ) events.get(0); 75 } 76 77 public Object getLastOldValue() { 78 return getLastEvent().getOldValue(); 79 } 80 81 public Object getLastNewValue() { 82 return getLastEvent().getNewValue(); 83 } 84 85 public boolean getLastOldBooleanValue() { 86 return ((Boolean ) getLastOldValue()).booleanValue(); 87 } 88 89 public boolean getLastNewBooleanValue() { 90 return ((Boolean ) getLastNewValue()).booleanValue(); 91 } 92 93 } 94 | Popular Tags |