org.jdesktop.swingx.error.ErrorSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swingx-all Show documentation
Show all versions of swingx-all Show documentation
Fork of the inactive swingx-all library
/*
* $Id: ErrorSupport.java 3840 2010-10-09 03:25:17Z kschaefe $
*
* Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle,
* Santa Clara, California 95054, U.S.A. All rights reserved.
*
* This library 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 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
package org.jdesktop.swingx.error;
import javax.swing.SwingUtilities;
import java.util.ArrayList;
import java.util.List;
/**
* ErrorSupport provides support for managing error listeners.
*
* @author Joshua Marinacci [email protected]
* @see ErrorListener
* @see ErrorEvent
*/
public class ErrorSupport {
private final List listeners;
private final Object source;
/**
* Creates a new instance of ErrorSupport
*
* @param source The object which will fire the ErrorEvent
s
*/
public ErrorSupport(Object source) {
this.source = source;
listeners = new ArrayList<>();
}
/**
* Add an ErrorListener
*
* @param listener the listener to add
*/
public void addErrorListener(ErrorListener listener) {
listeners.add(listener);
}
/**
* Remove an error listener
*
* @param listener the listener to remove
*/
public void removeErrorListener(ErrorListener listener) {
listeners.remove(listener);
}
/**
* Returns an array of all the listeners which were added to the
* ErrorSupport
object with addErrorListener()
.
*
* @return all of the ErrorListener
s added or an empty array if no listeners have been
* added.
*/
public ErrorListener[] getErrorListeners() {
return listeners.toArray(new ErrorListener[0]);
}
/**
* Report that an error has occurred
*
* @param throwable The {@link Error}
or {@link Exception}
which occured.
*/
public void fireErrorEvent(Throwable throwable) {
ErrorEvent evt = new ErrorEvent(throwable, source);
SwingUtilities.invokeLater(() -> {
for (ErrorListener el : listeners) {
el.errorOccured(evt);
}
});
}
}