Difference between revisions of "Documentation/DevGuide/OfficeDev/Events"
m (typos) |
|||
Line 10: | Line 10: | ||
There are several types of events. For example, all user dictionaries <idl>com.sun.star.linguistic2.XDictionary</idl> report their status changes as events <idl>com.sun.star.linguistic2.DictionaryEvent</idl> to the <code>DictionaryList</code>, which collects and transforms their information into <code>DictionaryList</code> events <idl>com.sun.star.linguistic2.DictionaryListEvent</idl>, and passes those on to its own listeners. | There are several types of events. For example, all user dictionaries <idl>com.sun.star.linguistic2.XDictionary</idl> report their status changes as events <idl>com.sun.star.linguistic2.DictionaryEvent</idl> to the <code>DictionaryList</code>, which collects and transforms their information into <code>DictionaryList</code> events <idl>com.sun.star.linguistic2.DictionaryListEvent</idl>, and passes those on to its own listeners. | ||
− | Thus, it is possible to register to the <code>DictionaryList</code> as a listener to be informed about relevant changes in the dictionaries. | + | 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. | ||
Line 20: | Line 20: | ||
Implementing the <idl>com.sun.star.linguistic2.XLinguServiceEventListener</idl> interface is similar to the following snippet: | Implementing the <idl>com.sun.star.linguistic2.XLinguServiceEventListener</idl> interface is similar to the following snippet: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
/** simple sample implementation of a clients XLinguServiceEventListener | /** simple sample implementation of a clients XLinguServiceEventListener | ||
* interface implementation | * interface implementation | ||
Line 44: | Line 44: | ||
} | } | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
After the client has been instantiated, it needs to register as <idl>com.sun.star.linguistic2.XLinguServiceEventListener</idl>. For the sample client above, this looks like: | After the client has been instantiated, it needs to register as <idl>com.sun.star.linguistic2.XLinguServiceEventListener</idl>. For the sample client above, this looks like: | ||
<!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | <!--[SOURCE:OfficeDev/Linguistic/LinguisticExamples.java]--> | ||
− | + | <syntaxhighlight lang="java"> | |
XLinguServiceEventListener aClient = new Client(); | XLinguServiceEventListener aClient = new Client(); | ||
Line 60: | Line 60: | ||
//! should not be omitted. | //! should not be omitted. | ||
mxLinguSvcMgr.removeLinguServiceManagerListener(aClient); | mxLinguSvcMgr.removeLinguServiceManagerListener(aClient); | ||
− | + | </syntaxhighlight> | |
In the ''LinguisticExamples.java'' sample, a property is modified for the listener to be called. | In the ''LinguisticExamples.java'' sample, a property is modified for the listener to be called. | ||
Revision as of 11:54, 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 <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). |