1 package net.sf.jga.swing; 33 34 import java.awt.event.ActionEvent ; 35 import java.awt.event.ActionListener ; 36 import net.sf.jga.fn.UnaryFunctor; 37 import net.sf.jga.fn.adaptor.ConstantUnary; 38 import net.sf.jga.fn.property.ArrayUnary; 39 import net.sf.jga.fn.property.InvokeMethod; 40 import net.sf.jga.fn.property.InvokeNoArgMethod; 41 42 48 49 public class GenericActionListener implements ActionListener { 50 51 55 56 static public <T> GenericActionListener 57 buildListener(Class <T> type, T object, String methodName) { 58 return new GenericActionListener( 59 new InvokeNoArgMethod<T,Object >(type,methodName) 60 .compose(new ConstantUnary<ActionEvent ,T>(object))); 61 } 62 63 67 68 static public <T> GenericActionListener 69 buildEventListener(Class <T> type, T object, String methodName) { 70 return new GenericActionListener( 71 new InvokeMethod<T,Object >(type,methodName,ActionEvent .class) 72 .compose(new ConstantUnary<ActionEvent ,T>(object), 73 new ArrayUnary<ActionEvent >())); 74 } 75 76 private UnaryFunctor<ActionEvent ,?> _fn; 78 79 83 public GenericActionListener(UnaryFunctor<ActionEvent ,?> fn) { 84 _fn = fn; 85 } 86 87 91 95 public void actionPerformed(ActionEvent actionEvent) { 96 _fn.fn(actionEvent); 97 } 98 } 99 | Popular Tags |