1 package be
.nikiroo
.fanfix_swing
.gui
.utils
;
3 import java
.awt
.event
.ActionEvent
;
4 import java
.awt
.event
.ActionListener
;
6 import javax
.swing
.JPanel
;
8 import be
.nikiroo
.fanfix_swing
.gui
.SearchBar
;
11 * A {@link JPanel} with the default {@link ActionListener} add/remove/fire
16 public class ListenerPanel
extends JPanel
{
17 private static final long serialVersionUID
= 1L;
20 * Adds the specified action listener to receive action events from this
23 * @param listener the action listener to be added
25 public synchronized void addActionListener(ActionListener listener
) {
26 listenerList
.add(ActionListener
.class, listener
);
30 * Removes the specified action listener so that it no longer receives action
31 * events from this {@link SearchBar}.
33 * @param listener the action listener to be removed
35 public synchronized void removeActionListener(ActionListener listener
) {
36 listenerList
.remove(ActionListener
.class, listener
);
40 * Notify the listeners of an action.
42 * @param listenerCommand A string that may specify a command (possibly one of
43 * several) associated with the event
45 protected void fireActionPerformed(String listenerCommand
) {
46 ActionEvent e
= new ActionEvent(this, ActionEvent
.ACTION_PERFORMED
, listenerCommand
);
47 Object
[] listeners
= listenerList
.getListenerList();
48 for (int i
= listeners
.length
- 2; i
>= 0; i
-= 2) {
49 if (listeners
[i
] == ActionListener
.class) {
50 ((ActionListener
) listeners
[i
+ 1]).actionPerformed(e
);