2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 import com.sun.star.uno.UnoRuntime;
19 import com.sun.star.uno.AnyConverter;
20 import com.sun.star.uno.Type;
21 import com.sun.star.lang.XComponent;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.frame.XComponentLoader;
24 import com.sun.star.document.XEmbeddedObjectSupplier;
25 import com.sun.star.awt.ActionEvent;
26 import com.sun.star.awt.Rectangle;
27 import com.sun.star.beans.XPropertySet;
28 import com.sun.star.beans.PropertyValue;
30 import com.sun.star.container.*;
31 import com.sun.star.chart.*;
32 import com.sun.star.table.*;
33 import com.sun.star.sheet.*;
35 import com.sun.star.script.provider.XScriptContext;
39 loader = (XComponentLoader)
40 UnoRuntime.queryInterface(
41 XComponentLoader.class, XSCRIPTCONTEXT.getDesktop());
43 comp = loader.loadComponentFromURL(
44 "private:factory/scalc", "_blank", 4, new PropertyValue[0]);
46 doc = (XSpreadsheetDocument)
47 UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
49 index = (XIndexAccess)
50 UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
52 sheet = (XSpreadsheet) AnyConverter.toObject(
53 new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
58 addData(sheet, date, total, free)
61 sheet.getCellByPosition(0, 0).setFormula("Used");
62 sheet.getCellByPosition(0, 1).setFormula("Free");
63 sheet.getCellByPosition(0, 2).setFormula("Total");
65 // set the values in the cells
66 sheet.getCellByPosition(1, 0).setValue(total - free);
67 sheet.getCellByPosition(1, 1).setValue(free);
68 sheet.getCellByPosition(1, 2).setValue(total);
73 rect = new Rectangle();
79 range = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, sheet);
80 myRange = range.getCellRangeByName("A1:B2");
82 rangeAddr = (XCellRangeAddressable)
83 UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
85 myAddr = rangeAddr.getRangeAddress();
87 CellRangeAddress[] addr = new CellRangeAddress[1];
90 supp = (XTableChartsSupplier)
91 UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);
92 charts = supp.getCharts();
93 charts.addNewByName("Example", rect, addr, false, true);
95 try { Thread.sleep(3000); } catch (java.lang.InterruptedException e) { }
97 // get the diagram and Change some of the properties
98 chartsAccess = (XNameAccess)
99 UnoRuntime.queryInterface( XNameAccess.class, charts);
101 tchart = (XTableChart)
102 UnoRuntime.queryInterface(
103 XTableChart.class, chartsAccess.getByName("Example"));
105 eos = (XEmbeddedObjectSupplier)
106 UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );
107 xifc = eos.getEmbeddedObject();
109 xChart = (XChartDocument)
110 UnoRuntime.queryInterface(XChartDocument.class, xifc);
112 xDocMSF = (XMultiServiceFactory)
113 UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
115 diagObject = xDocMSF.createInstance("com.sun.star.chart.PieDiagram");
116 xDiagram = (XDiagram)
117 UnoRuntime.queryInterface(XDiagram.class, diagObject);
118 xChart.setDiagram(xDiagram);
120 propset = (XPropertySet)
121 UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
122 propset.setPropertyValue("String", "JVM Memory Usage");
125 runtime = Runtime.getRuntime();
126 generator = new Random();
129 // allocate a random number of bytes so that the data changes
130 len = (int)(generator.nextFloat() * runtime.freeMemory() / 5);
131 bytes = new byte[len];
133 sheet = createSpreadsheet();
134 addData(sheet, date.toString(), runtime.totalMemory(), runtime.freeMemory());