package textbender.g.util; // Copyright 2006, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Textbender Software"), to deal in the Textbender Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Textbender Software, and to permit persons to whom the Textbender Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Textbender Software. THE TEXTBENDER SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE TEXTBENDER SOFTWARE OR THE USE OR OTHER DEALINGS IN THE TEXTBENDER SOFTWARE. import textbender.g.lang.ThreadSafe; /** An event generated by a change to a collection. */ public abstract class CollectionEvent extends java.util.EventObject { /** Constructs a CollectionEvent. * * @param source typically the CollectionListener.Registry * where the listener originally registered * (not necessarily the collection itself) * @param element per {@linkplain #getElement() getElement}() */ protected CollectionEvent( Object source, E element ) // would prefer to pass in source as CollectionListener.Registry, but cannot { super( source ); this.element = element; } // ------------------------------------------------------------------------------------ /** Returns the element that is the object of this event. */ public E getElement() { return element; } protected final E element; // ==================================================================================== /** An event generated by addition to a collection. */ public static @ThreadSafe final class ElementAdded extends CollectionEvent { /** Constructs an ElementAdded event. * * @param source of the event, * per {@linkplain CollectionEvent#CollectionEvent CollectionEvent} * @param element per {@linkplain CollectionEvent#getElement() getElement}() */ public ElementAdded( Object source, E element ) { super( source, element ); } } // ==================================================================================== /** An event generated by removal from a collection. */ public static @ThreadSafe final class ElementRemoved extends CollectionEvent { /** Constructs an ElementRemoved event. * * @param source of the event, * per {@linkplain CollectionEvent#CollectionEvent CollectionEvent} * @param element per {@linkplain CollectionEvent#getElement() getElement}() */ public ElementRemoved( Object source, E element ) { super( source, element ); } } }