Difference between revisions of "Documentation/DevGuide/OfficeDev/Events"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
m (typos)
Line 12: Line 12:
 
Thus, it is possible to register to the <code>DictionaryList</code> as a listener to be informed about relevant changes in the dictionaries., There is no need to register as a listener for each dictionary.
 
Thus, it is possible to register to the <code>DictionaryList</code> 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 <code>LinguProperties</code> for changes of their relevant properties. If such a property changes its value, the implementation launches an event <idl>com.sun.star.linguistic2.LinguServiceEvent</idl>that hints to its listeners that spelling or hyphenation should be reevaluated. For this purpose, those implementations support the <idl>com.sun.star.linguistic2.XLinguServiceEventBroadcaster</idl> interface.
+
The spell checker and hyphenator implementations monitor the changes in the <code>LinguProperties</code> for changes of their relevant properties. If such a property changes its value, the implementation launches an event <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> that hints to its listeners that spelling or hyphenation should be reevaluated. For this purpose, those implementations support the <idl>com.sun.star.linguistic2.XLinguServiceEventBroadcaster</idl> interface.
  
 
The <code>LinguServiceManager</code> acts as a listener for <idl>com.sun.star.linguistic2.DictionaryListEvent</idl> and <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> events. The respective interfaces are <idl>com.sun.star.linguistic2.XDictionaryListEventListener</idl> and <idl>com.sun.star.linguistic2.XLinguServiceEventListener</idl>. The events from the DictionaryList are transformed into <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> events and passed to the listeners of the <code>LinguServiceManager</code>, along with the received events from the spell checkers and hyphenators.
 
The <code>LinguServiceManager</code> acts as a listener for <idl>com.sun.star.linguistic2.DictionaryListEvent</idl> and <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> events. The respective interfaces are <idl>com.sun.star.linguistic2.XDictionaryListEventListener</idl> and <idl>com.sun.star.linguistic2.XLinguServiceEventListener</idl>. The events from the DictionaryList are transformed into <idl>com.sun.star.linguistic2.LinguServiceEvent</idl> events and passed to the listeners of the <code>LinguServiceManager</code>, along with the received events from the spell checkers and hyphenators.
Line 52: Line 52:
 
   // now add the client as listener to the service manager to
 
   // now add the client as listener to the service manager to
 
   // get informed when spellchecking or hyphenation may produce
 
   // get informed when spellchecking or hyphenation may produce
   // different results then before.
+
   // different results than before.
 
   mxLinguSvcMgr.addLinguServiceManagerListener( aClient );
 
   mxLinguSvcMgr.addLinguServiceManagerListener( aClient );
  

Revision as of 19:08, 21 January 2010



There are several types of events. For example, all user dictionaries com.sun.star.linguistic2.XDictionary report their status changes as events com.sun.star.linguistic2.DictionaryEvent to the DictionaryList, which collects and transforms their information into DictionaryList events com.sun.star.linguistic2.DictionaryListEvent, 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 com.sun.star.linguistic2.LinguServiceEvent that hints to its listeners that spelling or hyphenation should be reevaluated. For this purpose, those implementations support the com.sun.star.linguistic2.XLinguServiceEventBroadcaster interface.

The LinguServiceManager acts as a listener for com.sun.star.linguistic2.DictionaryListEvent and com.sun.star.linguistic2.LinguServiceEvent events. The respective interfaces are com.sun.star.linguistic2.XDictionaryListEventListener and com.sun.star.linguistic2.XLinguServiceEventListener. The events from the DictionaryList are transformed into com.sun.star.linguistic2.LinguServiceEvent 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 com.sun.star.linguistic2.XLinguServiceEventListener to the LinguServiceManager only.

Implementing the com.sun.star.linguistic2.XLinguServiceEventListener 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 com.sun.star.linguistic2.XLinguServiceEventListener. 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 <idl>com.sun.star.linguistic2.LinguServiceEvent</idl>s and act accordingly. Before the sample client terminates, it has to stop listening for events from the <code>LinguServiceManager</code>:
 
  //! remove listener before programm termination.
  //! should not be omitted.
  mxLinguSvcMgr.removeLinguServiceManagerListener(aClient);

In the LinguisticExamples.java 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