Class EditBus


  • public class EditBus
    extends java.lang.Object
    jEdit's global event notification mechanism.

    Plugins register with the EditBus to receive messages reflecting changes in the application's state, including changes in buffers, views and edit panes, changes in the set of properties maintained by the application, and the closing of the application.

    The EditBus maintains a list of objects that have requested to receive messages. When a message is sent using this class, all registered components receive it in turn. Classes for objects that subscribe to the EditBus must implement the EBComponent interface, which defines the single method EBComponent.handleMessage(EBMessage).

    Alternatively, since jEdit4.3pre19, EditBus components can be any object. Handlers for EditBus messages are created by annotating methods with the EditBus.EBHandler annotation. Such methods should expect a single parameter - an edit bus message of any desired type. If a message matching the type (or any of its super-types, unless the annotation requests exact type matching) is being sent, the annotated method will be called instead of the default EBComponent.handleMessage(EBMessage). If a handler exists for a specific message type, the default handler will not be called.

    A plugin core class that extends the EBPlugin abstract class (and whose name ends with Plugin for identification purposes) will automatically be added to the EditBus during jEdit's startup routine. Any other class - for example, a dockable window that needs to receive notification of buffer changes - must perform its own registration by calling addToBus(Object) during its initialization. A convenient place to register in a class derived from JComponent would be in an implementation of the JComponent method addNotify().

    Message types sent by jEdit can be found in the org.gjt.sp.jedit.msg package.

    Plugins can also send their own messages - any object can send a message to the EditBus by calling the static method send(EBMessage). Most plugins, however, only concern themselves with receiving, not sending, messages.

    Since:
    jEdit 2.2pre6
    See Also:
    EBComponent, EBMessage
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  EditBus.EBHandler
      This annotation should be used in methods that are to be considered "edit bus message handlers".
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addToBus​(java.lang.Object comp)
      Adds a component to the bus.
      static void addToBus​(EBComponent comp)
      Adds a component to the bus.
      static void removeFromBus​(java.lang.Object comp)
      Removes a component from the bus.
      static void removeFromBus​(EBComponent comp)
      Removes a component from the bus.
      static void send​(EBMessage message)
      Sends a message to all components on the bus in turn.
      static void sendAsync​(EBMessage message)
      Schedules a message to be sent on the edit bus as soon as the AWT thread is done processing current events.
      • Methods inherited from class java.lang.Object

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

      • addToBus

        public static void addToBus​(EBComponent comp)
        Adds a component to the bus. It will receive all messages sent on the bus.
        Parameters:
        comp - The component to add
      • addToBus

        public static void addToBus​(java.lang.Object comp)
        Adds a component to the bus. Methods annotated with the EditBus.EBHandler annotation found in the component will be used as EditBus message handlers if a message of a matching type is sent on the bus.

        If the component implements EBComponent, then the EBComponent.handleMessage(EBMessage) method will be called for every message sent on the bus.

        Parameters:
        comp - The component to add
        Since:
        jEdit 4.3pre19
      • removeFromBus

        public static void removeFromBus​(EBComponent comp)
        Removes a component from the bus.
        Parameters:
        comp - The component to remove
      • removeFromBus

        public static void removeFromBus​(java.lang.Object comp)
        Removes a component from the bus.
        Parameters:
        comp - The component to remove
        Since:
        4.3pre19
      • send

        public static void send​(EBMessage message)
        Sends a message to all components on the bus in turn. The message is delivered to components in the AWT thread, and this method will wait until all handlers receive the message before returning.

        This method uses ThreadUtilities.runInDispatchThreadNow(java.lang.Runnable), read the notes there for possible deadlocks.

        NOTE: If the calling thread is not the AWT thread and the thread is interrupted before or while the call of this method, this method can return before completion of handlers. However, the interruption state is set in this case, so the caller can detect the interruption after the call. If you really need the completion of handlers, you should make sure the call is in the AWT thread or the calling thread is never interrupted. If you don't care about the completion of handlers, it is recommended to use sendAsync(EBMessage) instead.

        Parameters:
        message - The message
      • sendAsync

        public static void sendAsync​(EBMessage message)
        Schedules a message to be sent on the edit bus as soon as the AWT thread is done processing current events. The method returns immediately (i.e., before the message is sent).
        Parameters:
        message - The message
        Since:
        jEdit 4.4pre1