summaryrefslogtreecommitdiff
path: root/scripting/examples
diff options
context:
space:
mode:
authorRüdiger Timm <rt@openoffice.org>2005-01-27 14:26:10 +0000
committerRüdiger Timm <rt@openoffice.org>2005-01-27 14:26:10 +0000
commit09533d7849c21b7b692ea430779cbc04172a9020 (patch)
treeebc7a24b4b6db1ff3c34a7c7c0aaa02c6f0e52c4 /scripting/examples
parent9bd049763b6b866bb5b8218d39bdb30459bca77a (diff)
INTEGRATION: CWS scriptingf10 (1.5.16); FILE MERGED
2005/01/07 19:09:14 toconnor 1.5.16.1: #i39386# ship MemoryUsage macro without document
Diffstat (limited to 'scripting/examples')
-rw-r--r--scripting/examples/beanshell/MemoryUsage/memusage.bsh110
1 files changed, 91 insertions, 19 deletions
diff --git a/scripting/examples/beanshell/MemoryUsage/memusage.bsh b/scripting/examples/beanshell/MemoryUsage/memusage.bsh
index fd64eb525d4f..2200b7b29203 100644
--- a/scripting/examples/beanshell/MemoryUsage/memusage.bsh
+++ b/scripting/examples/beanshell/MemoryUsage/memusage.bsh
@@ -2,37 +2,107 @@ import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.Type;
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 com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.document.XEmbeddedObjectSupplier;
+import com.sun.star.awt.ActionEvent;
+import com.sun.star.awt.Rectangle;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+
+import com.sun.star.container.*;
+import com.sun.star.chart.*;
+import com.sun.star.table.*;
+import com.sun.star.sheet.*;
+
import com.sun.star.script.provider.XScriptContext;
-addEntry(date, total, free) {
+createSpreadsheet()
+{
+ loader = (XComponentLoader)
+ UnoRuntime.queryInterface(
+ XComponentLoader.class, XSCRIPTCONTEXT.getDesktop());
- // The XSCRIPTCONTEXT variable is of type XScriptContext and is available to
- // all BeanShell scripts executed by the Script Framework
- comp = XSCRIPTCONTEXT.getDocument();
+ comp = loader.loadComponentFromURL(
+ "private:factory/scalc", "_blank", 4, new PropertyValue[0]);
- // 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);
+ return sheet;
+}
+
+addData(sheet, date, total, free)
+{
+ // set the labels
+ sheet.getCellByPosition(0, 0).setFormula("Used");
+ sheet.getCellByPosition(0, 1).setFormula("Free");
+ sheet.getCellByPosition(0, 2).setFormula("Total");
+
+ // set the values in the cells
+ sheet.getCellByPosition(1, 0).setValue(total - free);
sheet.getCellByPosition(1, 1).setValue(free);
- sheet.getCellByPosition(2, 1).setValue(total);
- sheet.getCellByPosition(0, 2).setFormula(date);
+ sheet.getCellByPosition(1, 2).setValue(total);
+}
+
+addChart(sheet)
+{
+ rect = new Rectangle();
+ rect.X = 500;
+ rect.Y = 3000;
+ rect.Width = 10000;
+ rect.Height = 8000;
+
+ range = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, sheet);
+ myRange = range.getCellRangeByName("A1:B2");
+
+ rangeAddr = (XCellRangeAddressable)
+ UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
+
+ myAddr = rangeAddr.getRangeAddress();
+
+ CellRangeAddress[] addr = new CellRangeAddress[1];
+ addr[0] = myAddr;
+
+ supp = (XTableChartsSupplier)
+ UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);
+ charts = supp.getCharts();
+ charts.addNewByName("Example", rect, addr, false, true);
+
+ try { Thread.sleep(3000); } catch (java.lang.InterruptedException e) { }
+
+ // get the diagram and Change some of the properties
+ chartsAccess = (XNameAccess)
+ UnoRuntime.queryInterface( XNameAccess.class, charts);
+
+ tchart = (XTableChart)
+ UnoRuntime.queryInterface(
+ XTableChart.class, chartsAccess.getByName("Example"));
+
+ eos = (XEmbeddedObjectSupplier)
+ UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );
+ xifc = eos.getEmbeddedObject();
+
+ xChart = (XChartDocument)
+ UnoRuntime.queryInterface(XChartDocument.class, xifc);
+
+ xDocMSF = (XMultiServiceFactory)
+ UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
+
+ diagObject = xDocMSF.createInstance("com.sun.star.chart.PieDiagram");
+ xDiagram = (XDiagram)
+ UnoRuntime.queryInterface(XDiagram.class, diagObject);
+ xChart.setDiagram(xDiagram);
+
+ propset = (XPropertySet)
+ UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
+ propset.setPropertyValue("String", "JVM Memory Usage");
}
runtime = Runtime.getRuntime();
@@ -42,7 +112,9 @@ 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());
+
+sheet = createSpreadsheet();
+addData(sheet, date.toString(), runtime.totalMemory(), runtime.freeMemory());
+addChart(sheet);
return 0;