Difference between revisions of "Documentation/DevGuide/OfficeDev/Events"
Line 54: | Line 54: | ||
// different results than before. | // different results than before. | ||
mxLinguSvcMgr.addLinguServiceManagerListener( aClient ); | mxLinguSvcMgr.addLinguServiceManagerListener( aClient ); | ||
− | + | </syntaxhighlight> | |
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>: | 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>: | ||
− | + | <syntaxhighlight lang="java"> | |
//! remove listener before programm termination. | //! remove listener before programm termination. | ||
//! should not be omitted. | //! should not be omitted. |
Latest revision as of 11:56, 3 January 2021
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 com.sun.star.linguistic2.LinguServiceEvents 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. 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). |