Package 

Class Listeners

  • All Implemented Interfaces:
    java.io.Serializable

    
    public final class Listeners<T extends Serializable>
     implements Serializable
                        

    Allows you to add listeners for a particular event into your component.

    Say that you have a click listener:

    interface OnClickListener { fun onClick(button: Int) }

    You can add support for click listeners into your Button component easily:

    class Button {
        val onClickListeners = listeners<OnClickListener>()
    }

    The clients can then simply register their listeners as follows:

    val button = Button()
    button.onClickListeners.add(object : OnClickListener {})

    The button can fire an event for all listeners as follows:

    onClickListeners.fire.onClick(2)

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final T fire
    • Constructor Summary

      Constructors 
      Constructor Description
      Listeners(Class<T> listenerType)
    • Method Summary

      Modifier and Type Method Description
      final Unit add(T listener) Registers a new listener.
      final Unit remove(T listener) Removes the listener.
      String toString()
      final T getFire()
      • Methods inherited from class java.io.Serializable

        equals, hashCode
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Listeners

        Listeners(Class<T> listenerType)
    • Method Detail

      • add

         final Unit add(T listener)

        Registers a new listener. Registering same listener multiple times has no further effect.

        The equality of the listener is measured by using the standard Any.equals and Any.hashCode.

      • remove

         final Unit remove(T listener)

        Removes the listener. Removing same listener multiple times has no further effect. Does nothing if the listener has not yet been registered.

        The equality of the listener is measured by using the standard Any.equals and Any.hashCode.