From Apache OpenOffice Wiki
Jump to: navigation, search

There are several types of events. For example, all user dictionaries report their status changes as events to the DictionaryList, which collects and transforms their information into DictionaryList events, and passes those on to its own listeners.

Thus, it is possible to register to the DictionaryList as a listener to be informed about relevant changes in the dictionaries. There is no need to register as a listener for each dictionary.

The spell checker and hyphenator implementations monitor the changes in the LinguProperties for changes of their relevant properties. If such a property changes its value, the implementation launches an event that hints to its listeners that spelling or hyphenation should be reevaluated. For this purpose, those implementations support the interface.

The LinguServiceManager acts as a listener for and events. The respective interfaces are and The events from the DictionaryList are transformed into events and passed to the listeners of the LinguServiceManager, along with the received events from the spell checkers and hyphenators.

Therefore, a client that wants to be notified when spell checking or hyphenation changes, for example, when it features automatic spell checking or automatic hyphenation, needs to be registered as to the LinguServiceManager only.

Implementing the interface is similar to the following snippet:

  /** simple sample implementation of a clients XLinguServiceEventListener
   * interface implementation
  public class Client 
          implements XLinguServiceEventListener
      public void disposing ( EventObject aEventObj )
          //! any references to the EventObjects source have to be
          //! released here now!
          System.out.println("object listened to will be disposed");
      public void processLinguServiceEvent( LinguServiceEvent aServiceEvent )
          //! do here whatever you think needs to be done depending
          //! on the event recieved (e.g. trigger background spellchecking
          //! or hyphenation again.)
          System.out.println("Listener called");

After the client has been instantiated, it needs to register as For the sample client above, this looks like:

  XLinguServiceEventListener aClient = new Client();
  // now add the client as listener to the service manager to
  // get informed when spellchecking or hyphenation may produce
  // different results than before.
  mxLinguSvcMgr.addLinguServiceManagerListener( aClient );

This enables the sample client to receive and act accordingly. Before the sample client terminates, it has to stop listening for events from the LinguServiceManager:

  //! remove listener before programm termination.
  //! should not be omitted.

In the sample, a property is modified for the listener to be called.

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages