//[skeleton1.

/**
 * An abstract EventHandler in an event bubbling system
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public abstract class AbstractEventHandler implements 
                                           EventGenerator, 
                                           EventHandler
{
//]skeleton1.
    /**
     * Default Constructor
     */
    public AbstractEventHandler()
    {
    }

    
    /**
     * Get the parent of this EventHandler
     *
     * @return  The parent
     */
    public abstract EventHandler getParent();

//[skeleton2.

    /**
     * Handle an event
     *
     * @param event                The event to handle
     * @param bubbleHandledEvents  true if handled events should be bubbled
     * @return                     true if the event was handled
     */
    public boolean handleEvent(BubblingEvent   event, 
                               boolean bubbleHandledEvents)
    {
       boolean                    handled;
       EventHandler               parent;       
       
       
       // Try and handle the Event locally
       handled = handleEvent(event);

       // Bubble the Event as necessary
       if (bubbleHandledEvents || !handled) 
       {
          parent  = getParent();
          if (parent != null)
          {
             handled = parent.handleEvent(event, 
                                          bubbleHandledEvents);
          }          
       }
       return handled;       
    }


    /**
     * Handle an event
     *
     * @param event   The event to handle
     * @return        true if the event was handled
     */
    public abstract boolean handleEvent(BubblingEvent event);
    
}
//]skeleton2.
