diff options
author | Duncan Foster <dfoster@openoffice.org> | 2003-03-31 09:50:50 +0000 |
---|---|---|
committer | Duncan Foster <dfoster@openoffice.org> | 2003-03-31 09:50:50 +0000 |
commit | 33a6649fe95458d365a8d0e1bbe7436b9f7539f5 (patch) | |
tree | b251c42bb412cb44698400384228b458eb90bae1 /scripting/examples/beanshell | |
parent | 00b722f8b9ccba1b43c36b2a68b165d2a381cfa0 (diff) |
Tidy up layout & add comments
Diffstat (limited to 'scripting/examples/beanshell')
-rw-r--r-- | scripting/examples/beanshell/WordCount/wordcount.bsh | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/scripting/examples/beanshell/WordCount/wordcount.bsh b/scripting/examples/beanshell/WordCount/wordcount.bsh index 014ad89e3dff..8006f4fed5af 100644 --- a/scripting/examples/beanshell/WordCount/wordcount.bsh +++ b/scripting/examples/beanshell/WordCount/wordcount.bsh @@ -15,10 +15,12 @@ void doDisplay(numWords) { frame.setVisible(false); } }); - frame.getContentPane().setLayout(new GridLayout(2,1)); - frame.getContentPane().add(wordsLabel); - frame.getContentPane().add(closeButton); + frame.getContentPane().setLayout(new BorderLayout()); + frame.getContentPane().add(wordsLabel, BorderLayout.CENTER); + frame.getContentPane().add(closeButton, BorderLayout.SOUTH); frame.pack(); + frame.setSize(190,90); + frame.setLocation(430,430); frame.setVisible(true); } @@ -26,11 +28,15 @@ int wordcount() { result = 0; + // iterate through each of the selections count = xIndexAccess.getCount(); for(i=0;i<count;i++) { + // get the XTextRange of the selection xTextRange = (XTextRange) UnoRuntime.queryInterface(XTextRange.class, xIndexAccess.getByIndex(i)); - System.out.println("string: "+xTextRange.getString()); + //System.out.println("string: "+xTextRange.getString()); + // use the standard J2SE delimiters to tokenize the string + // obtained from the XTextRange strTok = new StringTokenizer(xTextRange.getString()); result += strTok.countTokens(); } @@ -47,6 +53,7 @@ xModel = (XModel) xSelectionSupplier = (XSelectionSupplier) UnoRuntime.queryInterface(XSelectionSupplier.class, xModel.getCurrentController()); //see section 7.5.1 of developers' guide +// the getSelection provides an XIndexAccess to the one or more selections xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, xSelectionSupplier.getSelection()); |