public abstract class WidgetWithListener extends Widget
This listener is set in the front panel file (*.fp
) using the method
setListenerClass(Class, String)
. This user listener (front panel project user class) is checked (exists,
implements right interface or extends right class, can be instanciated etc.) before using it.
The listener must be instanciated in Widget.start()
method calling the method newListener(Class)
. It
should not be instanciated earlier because user code may call Device.getDevice()
: this method throws an
exception until the device is fully created.
Setting an user class (using setListenerClass(Class, String)
is optional. When not set, this class asks to
subclass to create a default listener. This default listener cannot be null. At least, it should describes the widget
event printing something in the standard output stream (FrontPanel.out
).
Widget.WidgetAttribute, Widget.WidgetDescription
DEFAULT_LABEL
Constructor and Description |
---|
WidgetWithListener() |
Modifier and Type | Method and Description |
---|---|
protected Object |
newDefaultListener()
Lets subclass creates a default listener.
|
protected <T> T |
newListener(Class<T> expectedType)
Creates a new listener which has to implement / extend the given type.
|
void |
setListenerClass(Class<?> expectedType,
String listenerClassName)
Sets the listener class name (package + class).
|
dispose, finalizeConfiguration, getAbsoluteX, getAbsoluteY, getCurrentSkin, getFilter, getHeight, getLabel, getParent, getSkin, getWidth, getX, getY, isOver, repaint, repaint, setCurrentSkin, setFilter, setHeight, setLabel, setOverlay, setSkin, setWidth, setX, setY, showYourself, start
protected Object newDefaultListener()
protected <T> T newListener(Class<T> expectedType)
First, the implementation tries to create the listener whose class name has been set by
setListenerClass(Class, String)
. On class loading error, an exception is thrown: the user class must be
valid.
If the user class name has not been set, the implementation asks the subclass to create a default listener. This listener must not be null and has to implement / extend given class.
expectedType
- the class the listener has to implement / extend.public void setListenerClass(Class<?> expectedType, String listenerClassName)
IllegalArgumentException
is thrown.expectedType
- the class the listener has to implement or extends.listenerClassName
- the class name to load.