View Javadoc
1   /*
2    * #%L
3    * JRst :: Api
4    * %%
5    * Copyright (C) 2008 - 2012 CodeLutin
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 3 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
20   * #L%
21   */
22  package org.nuiton.jrst.ui;
23  
24  import javax.swing.JPanel;
25  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;
27  
28  /**
29   * TODO sletellier 15/06/2012 : find a better way to add onActionPerform on custom components
30   *
31   * @author sletellier <letellier@codelutin.com>
32   */
33  public abstract class BaseActionPanel
34          extends JPanel {
35  
36      /**
37       * Notifies all listeners that have registered interest for
38       * notification on this event type.
39       *
40       * @see javax.swing.event.EventListenerList
41       */
42      protected void fireActionEvent() {
43          ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "actionPerformed");
44  
45          // Guaranteed to return a non-null array
46          Object[] listeners = listenerList.getListenerList();
47          // Process the listeners last to first, notifying
48          // those that are interested in this event
49          for (Object listener : listeners) {
50              if (ActionListener.class.isInstance(listener)) {
51                  ((ActionListener) listener).actionPerformed(e);
52              }
53          }
54      }
55  
56      /**
57       * Adds an <code>ActionListener</code>.
58       * <p/>
59       * The <code>ActionListener</code> will receive an <code>ActionEvent</code>
60       * when a selection has been made. If the combo box is editable, then
61       * an <code>ActionEvent</code> will be fired when editing has stopped.
62       *
63       * @param l the <code>ActionListener</code> that is to be notified
64       */
65      public void addActionListener(ActionListener l) {
66          listenerList.add(ActionListener.class, l);
67      }
68  
69      /**
70       * Removes an <code>ActionListener</code>.
71       *
72       * @param l the <code>ActionListener</code> to remove
73       */
74      public void removeActionListener(ActionListener l) {
75          listenerList.remove(ActionListener.class, l);
76      }
77  }