org.nuiton.jaxx.widgets.file.BaseActionPanel Maven / Gradle / Ivy
/*
* #%L
* JAXX :: Widgets
* %%
* Copyright (C) 2008 - 2024 Code Lutin, Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
package org.nuiton.jaxx.widgets.file;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* TODO sletellier 15/06/2012 : find a better way to add onActionPerform on custom components
*
* @author Sylvain Lletellier
*/
public abstract class BaseActionPanel extends JPanel {
private static final long serialVersionUID = -1256033335371614476L;
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @see javax.swing.event.EventListenerList
*/
protected void fireActionEvent() {
ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "actionPerformed");
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (Object listener : listeners) {
if (ActionListener.class.isInstance(listener)) {
((ActionListener) listener).actionPerformed(e);
}
}
}
/**
* Adds an ActionListener
.
*
* The ActionListener
will receive an ActionEvent
* when a selection has been made. If the combo box is editable, then
* an ActionEvent
will be fired when editing has stopped.
*
* @param l the ActionListener
that is to be notified
*/
public void addActionListener(ActionListener l) {
listenerList.add(ActionListener.class, l);
}
/**
* Removes an ActionListener
.
*
* @param l the ActionListener
to remove
*/
public void removeActionListener(ActionListener l) {
listenerList.remove(ActionListener.class, l);
}
}