1 36 37 import java.awt.event.ActionEvent ; 38 import java.awt.event.ActionListener ; 39 40 import java.net.URL ; 41 42 import javax.swing.AbstractAction ; 43 import javax.swing.Action ; 44 import javax.swing.ImageIcon ; 45 46 import javax.swing.event.EventListenerList ; 47 48 52 public abstract class JLFAbstractAction extends AbstractAction { 53 54 private EventListenerList listeners; 56 57 public static final String JLF_IMAGE_DIR = "/toolbarButtonGraphics/general/"; 59 60 66 public static final String LARGE_ICON = "LargeIcon"; 67 68 72 75 public String getActionCommand() { 76 return (String )getValue(Action.ACTION_COMMAND_KEY); 77 } 78 79 82 public String getShortDescription() { 83 return (String )getValue(Action.SHORT_DESCRIPTION); 84 } 85 86 89 public String getLongDescription() { 90 return (String )getValue(Action.LONG_DESCRIPTION); 91 } 92 93 101 102 103 105 108 public void actionPerformed(ActionEvent evt) { 109 if (listeners != null) { 110 Object [] listenerList = listeners.getListenerList(); 111 112 ActionEvent e = new ActionEvent (evt.getSource(), evt.getID(), 114 (String )getValue(Action.ACTION_COMMAND_KEY)); 115 for (int i = 0; i <= listenerList.length-2; i += 2) { 116 ((ActionListener )listenerList[i+1]).actionPerformed(e); 117 } 118 } 119 } 120 121 public void addActionListener(ActionListener l) { 122 if (listeners == null) { 123 listeners = new EventListenerList (); 124 } 125 listeners.add(ActionListener .class, l); 126 } 127 128 public void removeActionListener(ActionListener l) { 129 if (listeners == null) { 130 return; 131 } 132 listeners.remove(ActionListener .class, l); 133 } 134 135 141 public ImageIcon getIcon(String name) { 142 if (name != null) { 143 String imagePath = JLF_IMAGE_DIR + name; 144 URL url = this.getClass().getResource(imagePath); 145 if (url != null) return new ImageIcon (url); 146 } 147 return null; 148 } 149 } 150 151 152 | Popular Tags |