1 33 package net.sf.jga.swing; 34 35 import java.awt.event.ActionEvent ; 36 import javax.swing.AbstractAction ; 37 import javax.swing.Icon ; 38 import net.sf.jga.fn.UnaryFunctor; 39 import net.sf.jga.fn.adaptor.Identity; 40 41 47 48 public class GenericAction extends AbstractAction { 49 50 static final long serialVersionUID = 7439713855391597694L; 51 52 private UnaryFunctor<ActionEvent ,?> _fn; 54 55 58 public GenericAction(UnaryFunctor<ActionEvent ,?> fn) { 59 super(); 60 setFunctor(fn); 61 } 62 63 66 public GenericAction(UnaryFunctor<ActionEvent ,?> fn, String name) { 67 super(name); 68 setFunctor(fn); 69 } 70 71 72 75 public GenericAction(UnaryFunctor<ActionEvent ,?> fn, String name, Icon icon) { 76 super(name, icon); 77 setFunctor(fn); 78 } 79 80 81 85 private final void setFunctor(UnaryFunctor<ActionEvent ,?> fn) { 86 if (fn == null) 87 _fn = new Identity<ActionEvent >(); 88 else 89 _fn = fn; 90 } 91 92 93 97 public void actionPerformed(ActionEvent e) { 98 _fn.fn(e); 99 } 100 } 101 102 103 | Popular Tags |