diff options
author | Rüdiger Timm <rt@openoffice.org> | 2004-10-22 12:50:00 +0000 |
---|---|---|
committer | Rüdiger Timm <rt@openoffice.org> | 2004-10-22 12:50:00 +0000 |
commit | e570e3f680d5a4730e6c77280e2ade7b764f98f2 (patch) | |
tree | 8e9dd57ef2389d6e1c5377ff52011ee73630a116 /scripting/examples | |
parent | c159fe69d63f73bf0522621581f7940fa85db644 (diff) |
INTEGRATION: CWS scriptingf6 (1.4.40); FILE MERGED
2004/09/16 14:26:46 dfoster 1.4.40.3: #i33670#
Rename the context variable to XSCRIPTCONTEXT
2004/08/03 16:12:49 dfoster 1.4.40.2: #i32502#
2004/07/23 09:55:19 dfoster 1.4.40.1: #i30606#
Add descriptions to code in examples.
Diffstat (limited to 'scripting/examples')
-rw-r--r-- | scripting/examples/beanshell/MemoryUsage/memusage.bsh | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/scripting/examples/beanshell/MemoryUsage/memusage.bsh b/scripting/examples/beanshell/MemoryUsage/memusage.bsh index 809cb5c33e60..fd64eb525d4f 100644 --- a/scripting/examples/beanshell/MemoryUsage/memusage.bsh +++ b/scripting/examples/beanshell/MemoryUsage/memusage.bsh @@ -5,23 +5,30 @@ import com.sun.star.lang.XComponent; import com.sun.star.container.XIndexAccess; import com.sun.star.sheet.XSpreadsheetDocument; import com.sun.star.sheet.XSpreadsheet; -import drafts.com.sun.star.script.provider.XScriptContext; +import com.sun.star.script.provider.XScriptContext; addEntry(date, total, free) { - // The context variable is of type XScriptContext and is available to + // The XSCRIPTCONTEXT variable is of type XScriptContext and is available to // all BeanShell scripts executed by the Script Framework - comp = context.getDocument(); + comp = XSCRIPTCONTEXT.getDocument(); + // get the XSpreadsheetDocument interface which allows us to work on the + // document doc = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp); + // get the XIndexAccess interface from the document, so that we can + // get the first sheet index = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets()); + // get the XSpreadsheet interface corresponding to the first (zero-th) + // sheet in the document sheet = (XSpreadsheet) AnyConverter.toObject( new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0)); + // set the value in the cells sheet.getCellByPosition(0, 1).setValue(total - free); sheet.getCellByPosition(1, 1).setValue(free); sheet.getCellByPosition(2, 1).setValue(total); @@ -32,8 +39,10 @@ runtime = Runtime.getRuntime(); generator = new Random(); date = new Date(); +// allocate a random number of bytes so that the data changes len = (int)(generator.nextFloat() * runtime.freeMemory() / 5); bytes = new byte[len]; +//update the entry in the spreadsheet addEntry(date.toString(), runtime.totalMemory(), runtime.freeMemory()); return 0; |