Kaydet (Commit) 09533d78 authored tarafından Rüdiger Timm's avatar Rüdiger Timm

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
üst 9bd04976
......@@ -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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment