001 package sale; 002 003 import java.awt.event.ActionListener; 004 import java.awt.event.ActionEvent; 005 006 /** 007 * A special ActionListener that allows to associate Actions with buttons that are not 008 * in a FormSheet's button bar or a MenuSheet. 009 * 010 * <p>You can use subclasses of this class as ActionListeners on any button in a FormSheet 011 * that is not in the button bar. You can then think of it as of an {@link Action} 012 * associated with that button. The {@link #doAction} method will be called with the same 013 * parameters as for an Action associated with a button in the FormSheet's button bar.</p> 014 * 015 * <p>If you do not override {@link #doAction} in subclasses, it will defer event handling 016 * to the Action object handed in on creation. Thus, you can create chains of responsibility 017 * which allow for, e.g., a {@link users.Capability capability} to be associated with any 018 * {@link java.awt.event.ActionEvent} in the FormSheet.</p> 019 * 020 * @see FormSheet 021 * 022 * @author Steffen Zschaler 023 * @version 2.0 07/06/1999 024 * @since v2.0 025 */ 026 public class ActionActionListener extends Object implements Action, ActionListener { 027 028 /** 029 * ID for serialization. 030 */ 031 private static final long serialVersionUID = -8348113432791736610L; 032 033 /** 034 * The FormSheet that contains this Action's button. 035 * 036 * @serial 037 */ 038 protected FormSheet m_fsOwner; 039 040 /** 041 * The action to be performed, when the listener is triggered. 042 * 043 * @serial 044 */ 045 protected Action m_aAction; 046 047 /** 048 * Create a new ActionActionListener. You must override {@link #doAction} when using this constructor. 049 * 050 * @param fsOwner the FormSheet that contains this Action's button. 051 */ 052 public ActionActionListener(FormSheet fsOwner) { 053 this(fsOwner, null); 054 } 055 056 /** 057 * Create a new ActionActionListener. You should not override {@link #doAction} when using this constructor. 058 * 059 * @param fsOwner the FormSheet that contains this Action's button. 060 * @param aAction the Action to perform when the listener is triggered. 061 */ 062 public ActionActionListener(FormSheet fsOwner, Action aAction) { 063 super(); 064 065 m_fsOwner = fsOwner; 066 m_aAction = aAction; 067 } 068 069 /** 070 * ActionListener interface method. Will redirect the event to the {@link #doAction} 071 * method. 072 * 073 * @override Never 074 */ 075 public final void actionPerformed(ActionEvent e) { 076 new Thread("ActionActionListener event handler") { 077 public void run() { 078 try { 079 doAction(m_fsOwner.getProcess(), m_fsOwner.getSalesPoint()); 080 } 081 catch (ThreadDeath td) { 082 throw td; 083 } 084 catch (Throwable t) { 085 System.err.println("Exception occured during event handling:"); 086 t.printStackTrace(); 087 } 088 } 089 } 090 091 .start(); 092 } 093 094 /** 095 * Action interface method. Unless you override it, it will redirect the event to the 096 * {@link Action#doAction doAction()} method of the Action that is associated with this 097 * listener. 098 * 099 * @override Sometimes Override this method when you used 100 * {@link #ActionActionListener(sale.FormSheet)} as a constructor and want the listener to be the 101 *{@link Action Action object} at the same time. 102 * 103 * @exception Throwable on any error that shall be reported and lead to cancellation of 104 * the action. 105 * 106 * @see #ActionActionListener(sale.FormSheet, sale.Action) 107 */ 108 public void doAction(SaleProcess p, SalesPoint sp) throws Throwable { 109 m_aAction.doAction(p, sp); 110 } 111 }