001 /* 002 * Copyright (c) 2003, The Regents of the University of California, through 003 * Lawrence Berkeley National Laboratory (subject to receipt of any required 004 * approvals from the U.S. Dept. of Energy). All rights reserved. 005 */ 006 package gov.lbl.dsd.sea; 007 008 /** 009 * The abstract base class of all asynchronous event handlers. 010 * 011 * @author whoschek@lbl.gov 012 * @author $Author: gegles $ 013 * @version $Revision: 1.9 $, $Date: 2004/09/16 16:57:15 $ 014 */ 015 public abstract class EventHandler { 016 017 protected Stage stage = null; // the stage associated with this event handler 018 019 protected EventHandler() {} // make constructor invisible in javadoc 020 021 /** 022 * Sets the stage associated with this event handler. 023 */ 024 protected void setStage(Stage stage) { 025 if (this.stage != null && this.stage != stage) 026 throw new IllegalArgumentException("Can't change immutable stage"); 027 028 this.stage = stage; 029 } 030 031 /** 032 * Returns the stage associated with this event handler. 033 */ 034 protected Stage getStage() { 035 return this.stage; 036 } 037 038 /** 039 * Main entry point; called when an event handler should handle the given event. 040 */ 041 public abstract void handle(Object event); 042 043 /** 044 * Called when the event handler's stage is started. This method should perform 045 * any initialization operations as required by the application. 046 * The default implementation does nothing. 047 */ 048 public void onStart() {} 049 050 /** 051 * Called when the event handler's stage is stopped. 052 * The default implementation does nothing. 053 */ 054 public void onStop() {} 055 056 }