1 29 30 package nextapp.echo2.app.button; 31 32 import java.util.EventListener ; 33 34 import nextapp.echo2.app.event.ActionEvent; 35 import nextapp.echo2.app.event.ActionListener; 36 import nextapp.echo2.app.event.EventListenerList; 37 38 41 public class DefaultButtonModel 42 implements ButtonModel { 43 44 private EventListenerList listenerList = new EventListenerList(); 45 private String actionCommand; 46 47 50 public void addActionListener(ActionListener l) { 51 listenerList.addListener(ActionListener.class, l); 52 } 53 54 57 public void doAction() { 58 fireActionPerformed(new ActionEvent(this, getActionCommand())); 59 } 60 61 67 public void fireActionPerformed(ActionEvent e) { 68 EventListener [] listeners = listenerList.getListeners(ActionListener.class); 69 for (int index = 0; index < listeners.length; ++index) { 70 ((ActionListener) listeners[index]).actionPerformed(e); 71 } 72 } 73 74 77 public String getActionCommand() { 78 return actionCommand; 79 } 80 81 86 protected EventListenerList getEventListenerList() { 87 return listenerList; 88 } 89 90 93 public void removeActionListener(ActionListener l) { 94 listenerList.removeListener(ActionListener.class, l); 95 } 96 97 100 public void setActionCommand(String actionCommand) { 101 this.actionCommand = actionCommand; 102 } 103 } 104 | Popular Tags |