mirror of
https://github.com/kekingcn/kkFileView.git
synced 2026-04-19 16:28:38 +00:00
集成OpenOffice替换为LibreOffice
This commit is contained in:
Binary file not shown.
@@ -1,23 +1,22 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*************************************************************/
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
package org.libreoffice.example.java_scripts;
|
||||
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
@@ -29,15 +28,15 @@ import com.sun.star.text.XText;
|
||||
*
|
||||
*/
|
||||
public class HelloWorld {
|
||||
public static void printHW(XScriptContext xSc) {
|
||||
public static void printHW(XScriptContext xSc) {
|
||||
|
||||
// getting the text document object
|
||||
XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
|
||||
XTextDocument.class, xSc.getDocument());
|
||||
XText xText = xtextdocument.getText();
|
||||
XTextRange xTextRange = xText.getEnd();
|
||||
xTextRange.setString( "Hello World (in Java)" );
|
||||
// getting the text document object
|
||||
XTextDocument xtextdocument = (XTextDocument) UnoRuntime.queryInterface(
|
||||
XTextDocument.class, xSc.getDocument());
|
||||
XText xText = xtextdocument.getText();
|
||||
XTextRange xTextRange = xText.getEnd();
|
||||
xTextRange.setString("Hello World (in Java)");
|
||||
|
||||
}// printHW
|
||||
}// printHW
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--***********************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
***********************************************************-->
|
||||
<!--
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
-->
|
||||
<parcel language="Java" xmlns:parcel="scripting.dtd">
|
||||
<script language="Java">
|
||||
<locale lang="en">
|
||||
<displayname value="HelloWorld.Java"/>
|
||||
<description>
|
||||
Prints "Helo World".
|
||||
Prints "Hello World".
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="HelloWorld.printHW"/>
|
||||
<functionname value="org.libreoffice.example.java_scripts.HelloWorld.printHW"/>
|
||||
<logicalname value="HelloWorld.printHW"/>
|
||||
<languagedepprops>
|
||||
<prop name="classpath" value="HelloWorld.jar"/>
|
||||
|
||||
Binary file not shown.
@@ -1,23 +1,22 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*************************************************************/
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
package org.libreoffice.example.java_scripts;
|
||||
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
@@ -55,88 +54,83 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
|
||||
args[0] = context.getDocument();
|
||||
|
||||
Object obj;
|
||||
|
||||
try {
|
||||
obj = xmcf.createInstanceWithArgumentsAndContext(
|
||||
"com.sun.star.awt.DialogProvider", args,
|
||||
context.getComponentContext());
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
"com.sun.star.awt.DialogProvider", args,
|
||||
context.getComponentContext());
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
System.err.println("Error getting DialogProvider object");
|
||||
return;
|
||||
}
|
||||
|
||||
XDialogProvider xDialogProvider = (XDialogProvider)
|
||||
UnoRuntime.queryInterface(XDialogProvider.class, obj);
|
||||
UnoRuntime.queryInterface(XDialogProvider.class, obj);
|
||||
|
||||
System.err.println("Got DialogProvider, now get dialog");
|
||||
|
||||
try {
|
||||
findDialog = xDialogProvider.createDialog(
|
||||
"vnd.sun.star.script:" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
}
|
||||
catch (java.lang.Exception e) {
|
||||
"vnd.sun.star.script:" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
} catch (java.lang.Exception e) {
|
||||
System.err.println("Got exception on first creating dialog: " +
|
||||
e.getMessage());
|
||||
e.getMessage());
|
||||
}
|
||||
|
||||
if (findDialog == null) {
|
||||
if (tryLoadingLibrary(xmcf, context, "Dialog") == false ||
|
||||
tryLoadingLibrary(xmcf, context, "Script") == false)
|
||||
{
|
||||
if (!tryLoadingLibrary(xmcf, context, "Dialog") ||
|
||||
!tryLoadingLibrary(xmcf, context, "Script")) {
|
||||
System.err.println("Error loading ScriptBindingLibrary");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
findDialog = xDialogProvider.createDialog(
|
||||
"vnd.sun.star.script://" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException iae) {
|
||||
"vnd.sun.star.script://" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
} catch (com.sun.star.lang.IllegalArgumentException iae) {
|
||||
System.err.println("Error loading ScriptBindingLibrary");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
XControlContainer controls = (XControlContainer)
|
||||
UnoRuntime.queryInterface(XControlContainer.class, findDialog);
|
||||
UnoRuntime.queryInterface(XControlContainer.class, findDialog);
|
||||
|
||||
XButton highlightButton = (XButton) UnoRuntime.queryInterface(
|
||||
XButton.class, controls.getControl("HighlightButton"));
|
||||
XButton.class, controls.getControl("HighlightButton"));
|
||||
highlightButton.setActionCommand("Highlight");
|
||||
|
||||
findTextBox = (XTextComponent) UnoRuntime.queryInterface(
|
||||
XTextComponent.class, controls.getControl("HighlightTextField"));
|
||||
XTextComponent.class, controls.getControl("HighlightTextField"));
|
||||
|
||||
XButton exitButton = (XButton) UnoRuntime.queryInterface(
|
||||
XButton.class, controls.getControl("ExitButton"));
|
||||
XButton.class, controls.getControl("ExitButton"));
|
||||
exitButton.setActionCommand("Exit");
|
||||
|
||||
theDocument = (XTextDocument) UnoRuntime.queryInterface(
|
||||
XTextDocument.class, context.getDocument());
|
||||
XTextDocument.class, context.getDocument());
|
||||
|
||||
highlightButton.addActionListener(this);
|
||||
exitButton.addActionListener(this);
|
||||
|
||||
findDialog.execute();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.ActionCommand.equals("Exit")) {
|
||||
findDialog.endExecute();
|
||||
return;
|
||||
}
|
||||
else if (e.ActionCommand.equals("Highlight")) {
|
||||
} else if (e.ActionCommand.equals("Highlight")) {
|
||||
searchKey = findTextBox.getText();
|
||||
|
||||
// highlight the text in red
|
||||
Color cRed = new Color(255, 0, 0);
|
||||
int red = cRed.getRGB();
|
||||
|
||||
|
||||
XReplaceable replaceable = (XReplaceable)
|
||||
UnoRuntime.queryInterface(XReplaceable.class, theDocument);
|
||||
UnoRuntime.queryInterface(XReplaceable.class, theDocument);
|
||||
|
||||
XReplaceDescriptor descriptor =
|
||||
(XReplaceDescriptor) replaceable.createReplaceDescriptor();
|
||||
@@ -144,89 +138,83 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
|
||||
// Gets a XPropertyReplace object for altering the properties
|
||||
// of the replaced text
|
||||
XPropertyReplace xPropertyReplace = (XPropertyReplace)
|
||||
UnoRuntime.queryInterface(XPropertyReplace.class, descriptor);
|
||||
UnoRuntime.queryInterface(XPropertyReplace.class, descriptor);
|
||||
|
||||
// Sets the replaced text property fontweight value to Bold
|
||||
PropertyValue wv = new PropertyValue("CharWeight", -1,
|
||||
new Float(com.sun.star.awt.FontWeight.BOLD),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
new Float(com.sun.star.awt.FontWeight.BOLD),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
|
||||
// Sets the replaced text property color value to RGB parameter
|
||||
PropertyValue cv = new PropertyValue("CharColor", -1,
|
||||
new Integer(red),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
Integer.valueOf(red),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
|
||||
// Apply the properties
|
||||
PropertyValue[] props = new PropertyValue[] { cv, wv };
|
||||
PropertyValue[] props = new PropertyValue[] { cv, wv };
|
||||
|
||||
try {
|
||||
xPropertyReplace.setReplaceAttributes(props);
|
||||
|
||||
// Only matches whole words and case sensitive
|
||||
descriptor.setPropertyValue(
|
||||
"SearchCaseSensitive", new Boolean(true));
|
||||
descriptor.setPropertyValue("SearchWords", new Boolean(true));
|
||||
}
|
||||
catch (com.sun.star.beans.UnknownPropertyException upe) {
|
||||
"SearchCaseSensitive", Boolean.TRUE);
|
||||
descriptor.setPropertyValue("SearchWords", Boolean.TRUE);
|
||||
} catch (com.sun.star.beans.UnknownPropertyException upe) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.beans.PropertyVetoException pve) {
|
||||
} catch (com.sun.star.beans.PropertyVetoException pve) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.lang.WrappedTargetException wte) {
|
||||
} catch (com.sun.star.lang.WrappedTargetException wte) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.lang.IllegalArgumentException iae) {
|
||||
} catch (com.sun.star.lang.IllegalArgumentException iae) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
|
||||
// Replaces all instances of searchKey with new Text properties
|
||||
// and gets the number of instances of the searchKey
|
||||
descriptor.setSearchString(searchKey);
|
||||
descriptor.setReplaceString(searchKey);
|
||||
// and gets the number of instances of the searchKey
|
||||
descriptor.setSearchString(searchKey);
|
||||
descriptor.setReplaceString(searchKey);
|
||||
replaceable.replaceAll(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void disposing(EventObject o)
|
||||
{
|
||||
public void disposing(EventObject o) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private boolean tryLoadingLibrary(
|
||||
XMultiComponentFactory xmcf, XScriptContext context, String name)
|
||||
{
|
||||
XMultiComponentFactory xmcf, XScriptContext context, String name) {
|
||||
System.err.println("Try to load ScriptBindingLibrary");
|
||||
|
||||
try {
|
||||
Object obj = xmcf.createInstanceWithContext(
|
||||
"com.sun.star.script.Application" + name + "LibraryContainer",
|
||||
context.getComponentContext());
|
||||
"com.sun.star.script.Application" + name + "LibraryContainer",
|
||||
context.getComponentContext());
|
||||
|
||||
XLibraryContainer xLibraryContainer = (XLibraryContainer)
|
||||
UnoRuntime.queryInterface(XLibraryContainer.class, obj);
|
||||
UnoRuntime.queryInterface(XLibraryContainer.class, obj);
|
||||
|
||||
System.err.println("Got XLibraryContainer");
|
||||
|
||||
Object serviceObj = context.getComponentContext().getValueByName(
|
||||
"/singletons/com.sun.star.util.theMacroExpander");
|
||||
|
||||
"/singletons/com.sun.star.util.theMacroExpander");
|
||||
|
||||
XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
|
||||
new Type(XMacroExpander.class), serviceObj);
|
||||
|
||||
new Type(XMacroExpander.class), serviceObj);
|
||||
|
||||
String bootstrapName = "bootstraprc";
|
||||
|
||||
if (System.getProperty("os.name").startsWith("Windows")) {
|
||||
bootstrapName = "bootstrap.ini";
|
||||
}
|
||||
|
||||
String libURL = xme.expandMacros(
|
||||
"${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
|
||||
"/share/basic/ScriptBindingLibrary/" +
|
||||
name.toLowerCase() + ".xlb/");
|
||||
"$BRAND_BASE_DIR/$BRAND_SHARE_SUBDIR/basic/ScriptBindingLibrary/" +
|
||||
name.toLowerCase() + ".xlb/");
|
||||
|
||||
System.err.println("libURL is: " + libURL);
|
||||
|
||||
@@ -239,6 +227,7 @@ public class HighlightText implements com.sun.star.awt.XActionListener {
|
||||
System.err.println("Got an exception loading lib: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--***********************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<!--
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
-->
|
||||
<parcel language="Java" xmlns:parcel="scripting.dtd">
|
||||
<script language="Java">
|
||||
<locale lang="en">
|
||||
@@ -28,7 +24,7 @@
|
||||
Text highlighting
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="HighlightText.showForm"/>
|
||||
<functionname value="org.libreoffice.example.java_scripts.HighlightText.showForm"/>
|
||||
<logicalname value="HighlightText.showForm"/>
|
||||
<languagedepprops>
|
||||
<prop name="classpath" value="Highlight.jar"/>
|
||||
|
||||
Binary file not shown.
@@ -1,23 +1,22 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
*************************************************************/
|
||||
/*
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
*/
|
||||
|
||||
package org.libreoffice.example.java_scripts;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Date;
|
||||
@@ -40,12 +39,9 @@ import com.sun.star.sheet.*;
|
||||
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
|
||||
public class MemoryUsage
|
||||
{
|
||||
// public void updateMemoryUsage(XScriptContext ctxt, ActionEvent evt)
|
||||
public class MemoryUsage {
|
||||
public void updateMemoryUsage(XScriptContext ctxt)
|
||||
throws Exception
|
||||
{
|
||||
throws Exception {
|
||||
XSpreadsheet sheet = createSpreadsheet(ctxt);
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
@@ -57,37 +53,35 @@ public class MemoryUsage
|
||||
byte[] bytes = new byte[len];
|
||||
|
||||
addData(sheet, date.toString(),
|
||||
runtime.totalMemory(), runtime.freeMemory());
|
||||
runtime.totalMemory(), runtime.freeMemory());
|
||||
|
||||
addChart(sheet);
|
||||
}
|
||||
|
||||
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
|
||||
throws Exception
|
||||
{
|
||||
throws Exception {
|
||||
XComponentLoader loader = (XComponentLoader)
|
||||
UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, ctxt.getDesktop());
|
||||
UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, ctxt.getDesktop());
|
||||
|
||||
XComponent comp = loader.loadComponentFromURL(
|
||||
"private:factory/scalc", "_blank", 4, new PropertyValue[0]);
|
||||
"private:factory/scalc", "_blank", 4, new PropertyValue[0]);
|
||||
|
||||
XSpreadsheetDocument doc = (XSpreadsheetDocument)
|
||||
UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
|
||||
UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
|
||||
|
||||
XIndexAccess index = (XIndexAccess)
|
||||
UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
|
||||
UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
|
||||
|
||||
XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
|
||||
new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
|
||||
new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
private void addData(
|
||||
XSpreadsheet sheet, String date, long total, long free)
|
||||
throws Exception
|
||||
{
|
||||
throws Exception {
|
||||
sheet.getCellByPosition(0, 0).setFormula("Used");
|
||||
sheet.getCellByPosition(0, 1).setFormula("Free");
|
||||
sheet.getCellByPosition(0, 2).setFormula("Total");
|
||||
@@ -98,8 +92,7 @@ public class MemoryUsage
|
||||
}
|
||||
|
||||
private void addChart(XSpreadsheet sheet)
|
||||
throws Exception
|
||||
{
|
||||
throws Exception {
|
||||
Rectangle rect = new Rectangle();
|
||||
rect.X = 500;
|
||||
rect.Y = 3000;
|
||||
@@ -107,13 +100,13 @@ public class MemoryUsage
|
||||
rect.Height = 8000;
|
||||
|
||||
XCellRange range = (XCellRange)
|
||||
UnoRuntime.queryInterface(XCellRange.class, sheet);
|
||||
UnoRuntime.queryInterface(XCellRange.class, sheet);
|
||||
|
||||
XCellRange myRange =
|
||||
range.getCellRangeByName("A1:B2");
|
||||
|
||||
XCellRangeAddressable rangeAddr = (XCellRangeAddressable)
|
||||
UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
|
||||
UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
|
||||
|
||||
CellRangeAddress myAddr = rangeAddr.getRangeAddress();
|
||||
|
||||
@@ -121,42 +114,44 @@ public class MemoryUsage
|
||||
addr[0] = myAddr;
|
||||
|
||||
XTableChartsSupplier supp = (XTableChartsSupplier)
|
||||
UnoRuntime.queryInterface( XTableChartsSupplier.class, sheet);
|
||||
UnoRuntime.queryInterface(XTableChartsSupplier.class, sheet);
|
||||
|
||||
XTableCharts charts = supp.getCharts();
|
||||
charts.addNewByName("Example", rect, addr, false, true);
|
||||
|
||||
try { Thread.sleep(3000); } catch (java.lang.InterruptedException e) { }
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
} catch (InterruptedException e) { }
|
||||
|
||||
// get the diagram and Change some of the properties
|
||||
XNameAccess chartsAccess = (XNameAccess)
|
||||
UnoRuntime.queryInterface( XNameAccess.class, charts);
|
||||
UnoRuntime.queryInterface(XNameAccess.class, charts);
|
||||
|
||||
XTableChart tchart = (XTableChart)
|
||||
UnoRuntime.queryInterface(
|
||||
XTableChart.class, chartsAccess.getByName("Example"));
|
||||
UnoRuntime.queryInterface(
|
||||
XTableChart.class, chartsAccess.getByName("Example"));
|
||||
|
||||
XEmbeddedObjectSupplier eos = (XEmbeddedObjectSupplier)
|
||||
UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );
|
||||
UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, tchart);
|
||||
|
||||
XInterface xifc = eos.getEmbeddedObject();
|
||||
|
||||
XChartDocument xChart = (XChartDocument)
|
||||
UnoRuntime.queryInterface(XChartDocument.class, xifc);
|
||||
UnoRuntime.queryInterface(XChartDocument.class, xifc);
|
||||
|
||||
XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
|
||||
UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
|
||||
UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
|
||||
|
||||
Object diagObject =
|
||||
xDocMSF.createInstance("com.sun.star.chart.PieDiagram");
|
||||
|
||||
XDiagram xDiagram = (XDiagram)
|
||||
UnoRuntime.queryInterface(XDiagram.class, diagObject);
|
||||
UnoRuntime.queryInterface(XDiagram.class, diagObject);
|
||||
|
||||
xChart.setDiagram(xDiagram);
|
||||
|
||||
XPropertySet propset = (XPropertySet)
|
||||
UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
|
||||
UnoRuntime.queryInterface(XPropertySet.class, xChart.getTitle());
|
||||
propset.setPropertyValue("String", "JVM Memory Usage");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--***********************************************************
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
***********************************************************-->
|
||||
<!--
|
||||
* This file is part of the LibreOffice project.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* This file incorporates work covered by the following license notice:
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed
|
||||
* with this work for additional information regarding copyright
|
||||
* ownership. The ASF licenses this file to you under the Apache
|
||||
* License, Version 2.0 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
||||
-->
|
||||
<parcel language="Java" xmlns:parcel="scripting.dtd">
|
||||
<script language="Java">
|
||||
<locale lang="en">
|
||||
@@ -27,7 +24,7 @@
|
||||
Text highlighting
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="MemoryUsage.updateMemoryUsage"/>
|
||||
<functionname value="org.libreoffice.example.java_scripts.MemoryUsage.updateMemoryUsage"/>
|
||||
<logicalname value="MemoryUtils.MemUsage"/>
|
||||
<languagedepprops>
|
||||
<prop name="classpath" value="MemoryUsage.jar"/>
|
||||
|
||||
Reference in New Issue
Block a user