View Javadoc
1 /* 2 * Angkor Web Framework 3 * 4 * Distributable under LGPL license. 5 * See terms of license at gnu.org. 6 */ 7 8 package com.tirsen.angkor.event; 9 10 import com.tirsen.angkor.Debug; 11 import com.tirsen.angkor.Multicaster; 12 import com.tirsen.angkor.RenderContext; 13 import org.apache.log4j.Category; 14 15 import java.io.Serializable; 16 17 /*** 18 * Utility class for sending action events. 19 * 20 * <!-- $Id: ActionSourceHelper.java,v 1.3 2002/10/09 21:37:37 tirsen Exp $ --> 21 * 22 * @author $Author: tirsen $ 23 * @version $Revision: 1.3 $ 24 */ 25 public class ActionSourceHelper implements ActionSource, Serializable 26 { 27 private static final Category logger = Category.getInstance(Debug.LOGGER_NAME); 28 private Action action; 29 private Object source; 30 private ActionListener listeners; 31 32 public ActionSourceHelper(Object source) 33 { 34 this.source = source; 35 } 36 37 public Action getAction() 38 { 39 return action; 40 } 41 42 public void setAction(Action action) 43 { 44 this.action = action; 45 } 46 47 public void addActionListener(ActionListener listener) 48 { 49 if (listeners == null) listeners = (ActionListener) Multicaster.create(ActionListener.class, true); 50 Multicaster.add(listeners, listener); 51 } 52 53 public void removeActionListener(ActionListener listener) 54 { 55 Multicaster.remove(listeners, listener); 56 if (Multicaster.isEmpty(listeners)) listeners = null; 57 } 58 59 public void signalActionEvent(RenderContext context) 60 { 61 if (hasListeners()) 62 { 63 ActionEvent evt = new ActionEvent(source); 64 if (action != null) 65 { 66 logger.info("invoking action " + action); 67 context.getEventQueue().postEvent(ActionListener.class, action, evt, "actionPerformed"); 68 } 69 if (!Multicaster.isEmpty(listeners)) context.getEventQueue().postEvent(ActionListener.class, listeners, evt, "actionPerformed"); 70 } 71 } 72 73 public void signalActionEvent() 74 { 75 if (hasListeners()) 76 { 77 signalActionEvent(RenderContext.getRenderContext()); 78 } 79 } 80 81 public boolean hasListeners() 82 { 83 return !Multicaster.isEmpty(listeners) || action != null; 84 } 85 }

This page was automatically generated by Maven