diff options
Diffstat (limited to 'odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java')
-rw-r--r-- | odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java index 60829600861f..b4c2cd1edf12 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java @@ -2,7 +2,7 @@ * * The Contents of this file are made available subject to the terms of * the BSD license. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * All rights reserved. * @@ -29,7 +29,7 @@ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * *************************************************************************/ // used interfaces @@ -84,14 +84,14 @@ public class LinguisticExamples protected XPropertySet mxLinguProps = null; - public static void main(String args[]) + public static void main(String args[]) { // Create an instance of the class and call it's begin method try { LinguisticExamples aExample = new LinguisticExamples(); aExample.Connect(); - aExample.Run(); - } catch (Exception e) { + aExample.Run(); + } catch (Exception e) { System.err.println("failed to run examples"); e.printStackTrace(); } @@ -119,12 +119,12 @@ public class LinguisticExamples if (mxRemoteContext != null && mxRemoteServiceManager != null) { Object aObj = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.linguistic2.LinguServiceManager", mxRemoteContext ); - mxLinguSvcMgr = (XLinguServiceManager) + mxLinguSvcMgr = (XLinguServiceManager) UnoRuntime.queryInterface(XLinguServiceManager.class, aObj); } return mxLinguSvcMgr != null; - } - + } + /** Get the SpellChecker to be used. */ @@ -175,9 +175,9 @@ public class LinguisticExamples // use american english as language Locale aLocale = new Locale("en","US",""); - - - + + + // another list of property values to used in function calls below. // Only properties with values different from the (default) values // in the LinguProperties property set need to be supllied. @@ -185,9 +185,9 @@ public class LinguisticExamples aProps[0] = new PropertyValue(); aProps[0].Name = "IsGermanPreReform"; aProps[0].Value = new Boolean( true ); - - - GetSpell(); + + + GetSpell(); if (mxSpell != null) { // test with correct word @@ -198,7 +198,7 @@ public class LinguisticExamples // test with incorrect word aWord = "course"; bIsCorrect = mxSpell.isValid( aWord, aLocale , aEmptyProps ); - System.out.println( aWord + ": " + bIsCorrect ); + System.out.println( aWord + ": " + bIsCorrect ); aWord = "house"; @@ -220,10 +220,10 @@ public class LinguisticExamples } - GetHyph(); + GetHyph(); if (mxHyph != null) { - // maximum number of characters to remain before the hyphen + // maximum number of characters to remain before the hyphen // character in the resulting word of the hyphenation short nMaxLeading = 6; @@ -235,16 +235,16 @@ public class LinguisticExamples else { System.out.println( "valid hyphenation pos found at " - + xHyphWord.getHyphenationPos() + + xHyphWord.getHyphenationPos() + " in " + xHyphWord.getWord() ); System.out.println( "hyphenation char will be after char " - + xHyphWord.getHyphenPos() + + xHyphWord.getHyphenPos() + " in " + xHyphWord.getHyphenatedWord() ); } //! Note: 'aProps' needs to have set 'IsGermanPreReform' to true! - xHyphWord = mxHyph.queryAlternativeSpelling( "Schiffahrt", + xHyphWord = mxHyph.queryAlternativeSpelling( "Schiffahrt", new Locale("de","DE",""), (short)4, aProps ); if (xHyphWord == null) System.out.println( "no alternative spelling found at specified position." ); @@ -253,10 +253,10 @@ public class LinguisticExamples if (xHyphWord.isAlternativeSpelling()) System.out.println( "alternative spelling detectetd!" ); System.out.println( "valid hyphenation pos found at " - + xHyphWord.getHyphenationPos() + + xHyphWord.getHyphenationPos() + " in " + xHyphWord.getWord() ); System.out.println( "hyphenation char will be after char " - + xHyphWord.getHyphenPos() + + xHyphWord.getHyphenPos() + " in " + xHyphWord.getHyphenatedWord() ); } @@ -267,12 +267,12 @@ public class LinguisticExamples if (xPossHyph == null) System.out.println( "no hyphenation positions found." ); else - System.out.println( xPossHyph.getPossibleHyphens() ); - } - - - GetThes(); - if (mxThes != null) + System.out.println( xPossHyph.getPossibleHyphens() ); + } + + + GetThes(); + if (mxThes != null) { XMeaning[] xMeanings = mxThes.queryMeanings("house", aLocale, aEmptyProps ); @@ -287,11 +287,11 @@ public class LinguisticExamples for (int k = 0; k < aSynonyms.length; ++k) System.out.println( " Synonym: " + aSynonyms[k] ); } - } - } - - - + } + } + + + XLinguServiceEventListener aClient = new Client(); // get access to LinguProperties property set @@ -299,18 +299,18 @@ public class LinguisticExamples "com.sun.star.linguistic2.LinguProperties", mxRemoteContext); XPropertySet aLinguProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class,aObj); - + // set a spellchecker and hyphenator property value to a defined state try { aLinguProps.setPropertyValue("IsGermanPreReform", new Boolean(true)); } catch (Exception e) { - } + } // now add the client as listener to the service manager to // get informed when spellchecking or hyphenation may produce // different results then before. mxLinguSvcMgr.addLinguServiceManagerListener(aClient); - + // change that property value in order to trigger a property change // event that eventually results in the listeners // 'processLinguServiceEvent' function being called @@ -318,9 +318,9 @@ public class LinguisticExamples aLinguProps.setPropertyValue("IsGermanPreReform", new Boolean(false)); } catch (Exception e) { } - + //! keep the listener and the program alive until the event will - //! be launched. + //! be launched. //! There is a voluntary delay before launching the event! // Of course this code would usually not be in a *real* client // its @@ -328,38 +328,38 @@ public class LinguisticExamples try { this.wait(4000); } catch(Exception e) { - + } } - + //! remove listener before programm termination. //! should not be omitted. mxLinguSvcMgr.removeLinguServiceManagerListener(aClient); - - + + System.exit(0); } /** simple sample implementation of a clients XLinguServiceEventListener * interface implementation */ - public class Client + 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"); } }; |