mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-03-17 14:43:47 +08:00
优化项目结构、优化 maven 结构
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
// Change the case of a selection, or current word from upper case,
|
||||
// to first char upper case, to all lower case to upper case...
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.view.XSelectionSupplier;
|
||||
import com.sun.star.container.XIndexAccess;
|
||||
import com.sun.star.text.XText;
|
||||
import com.sun.star.text.XTextRange;
|
||||
import com.sun.star.text.XWordCursor;
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
|
||||
// return the new string based on the string passed in
|
||||
String getNewString( theString ) {
|
||||
String newString;
|
||||
if(theString==null || theString.length()==0) {
|
||||
return newString;
|
||||
}
|
||||
// should we tokenize on "."?
|
||||
if(Character.isUpperCase(theString.charAt(0)) && theString.length()>=2 && Character.isUpperCase(theString.charAt(1))) { // first two chars are UC => first UC, rest LC
|
||||
newString=theString.substring(0,1).toUpperCase()+theString.substring(1).toLowerCase();
|
||||
} else if (Character.isUpperCase(theString.charAt(0))) { // first char UC => all to LC
|
||||
newString=theString.toLowerCase();
|
||||
} else { // all to UC.
|
||||
newString=theString.toUpperCase();
|
||||
}
|
||||
return newString;
|
||||
}
|
||||
|
||||
//the method that does the work
|
||||
void capitalise() {
|
||||
|
||||
// get the number of regions selected
|
||||
count = xIndexAccess.getCount();
|
||||
if(count>=1) { //ie we have a selection
|
||||
for(i=0;i<count;i++) {
|
||||
// get the i-th region selected
|
||||
xTextRange = (XTextRange)
|
||||
UnoRuntime.queryInterface(XTextRange.class, xIndexAccess.getByIndex(i));
|
||||
System.out.println("string: "+xTextRange.getString());
|
||||
// get the selected string
|
||||
theString = xTextRange.getString();
|
||||
if(theString.length()==0) {
|
||||
// sadly we can have a selection where nothing is selected
|
||||
// in this case we get the XWordCursor and make a selection!
|
||||
xText = (XText)
|
||||
UnoRuntime.queryInterface(XText.class, xTextRange.getText());
|
||||
xWordCursor = (XWordCursor)
|
||||
UnoRuntime.queryInterface(XWordCursor.class, xText.createTextCursorByRange(xTextRange));
|
||||
// move the Word cursor to the start of the word if its not
|
||||
// already there
|
||||
if(!xWordCursor.isStartOfWord()) {
|
||||
xWordCursor.gotoStartOfWord(false);
|
||||
}
|
||||
// move the cursor to the next word, selecting all chars
|
||||
// in between
|
||||
xWordCursor.gotoNextWord(true);
|
||||
// get the selected string
|
||||
theString = xWordCursor.getString();
|
||||
// get the new string
|
||||
newString = getNewString(theString);
|
||||
if(newString!=null) {
|
||||
// set the new string
|
||||
xWordCursor.setString(newString);
|
||||
// keep the current selection
|
||||
xSelectionSupplier.select(xWordCursor);
|
||||
}
|
||||
} else {
|
||||
newString = getNewString( theString );
|
||||
if(newString!=null) {
|
||||
// set the new string
|
||||
xTextRange.setString(newString);
|
||||
// keep the current selection
|
||||
xSelectionSupplier.select(xTextRange);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The XSCRIPTCONTEXT variable is of type XScriptContext and is available to
|
||||
// all BeanShell scripts executed by the Script Framework
|
||||
xModel = (XModel)
|
||||
UnoRuntime.queryInterface(XModel.class, XSCRIPTCONTEXT.getDocument());
|
||||
//the writer controller impl supports the css.view.XSelectionSupplier interface
|
||||
xSelectionSupplier = (XSelectionSupplier)
|
||||
UnoRuntime.queryInterface(XSelectionSupplier.class, xModel.getCurrentController());
|
||||
//see section 7.5.1 of developers' guide
|
||||
xIndexAccess = (XIndexAccess)
|
||||
UnoRuntime.queryInterface(XIndexAccess.class, xSelectionSupplier.getSelection());
|
||||
|
||||
//call the method that does the work
|
||||
capitalise();
|
||||
return 0;
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="BeanShell" xmlns:parcel="scripting.dtd">
|
||||
|
||||
<script language="BeanShell">
|
||||
<locale lang="en">
|
||||
<displayname value="Capitalise"/>
|
||||
<description>
|
||||
Change the case of a selection, or current word from upper case, to first char upper case, to all lower case to upper case...
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="capitalise.bsh"/>
|
||||
<logicalname value="Capitalise.BeanShell"/>
|
||||
</script>
|
||||
|
||||
</parcel>
|
||||
@@ -0,0 +1,37 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
// Hello World in BeanShell
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.text.XText;
|
||||
import com.sun.star.text.XTextRange;
|
||||
|
||||
// get the document from the scripting context which is made available to all
|
||||
// scripts
|
||||
oDoc = XSCRIPTCONTEXT.getDocument();
|
||||
//get the XTextDocument interface
|
||||
xTextDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class,oDoc);
|
||||
//get the XText interface
|
||||
xText = xTextDoc.getText();
|
||||
// get an (empty) XTextRange at the end of the document
|
||||
xTextRange = xText.getEnd();
|
||||
// set the string
|
||||
xTextRange.setString( "Hello World (in BeanShell)" );
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="BeanShell" xmlns:parcel="scripting.dtd">
|
||||
|
||||
<script language="BeanShell">
|
||||
<locale lang="en">
|
||||
<displayname value="Hello World"/>
|
||||
<description>
|
||||
Adds the the string "Hello World" into the current text doc.
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="helloworld.bsh"/>
|
||||
<logicalname value="HelloWorld.BeanShell"/>
|
||||
</script>
|
||||
|
||||
</parcel>
|
||||
@@ -0,0 +1,126 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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 code is bound to the events generated by the buttons in the dialog
|
||||
// it will close the dialog or find and highlight the text entered in the
|
||||
// dialog (depending on the button pressed)
|
||||
import com.sun.star.uno.*;
|
||||
import com.sun.star.awt.*;
|
||||
import com.sun.star.lang.*;
|
||||
import com.sun.star.beans.*;
|
||||
import com.sun.star.util.*;
|
||||
import com.sun.star.script.framework.browse.DialogFactory;
|
||||
|
||||
// Get the ActionEvent object from the ARGUMENTS list
|
||||
ActionEvent event = (ActionEvent) ARGUMENTS[0];
|
||||
|
||||
// Each argument is of type Any so we must use the AnyConverter class to
|
||||
// convert it into the interface or primitive type we expect
|
||||
XButton button = (XButton)AnyConverter.toObject(
|
||||
new Type(XButton.class), event.Source);
|
||||
|
||||
// We can now query for the model of the button and get its properties
|
||||
XControl control = (XControl)UnoRuntime.queryInterface(XControl.class, button);
|
||||
XControlModel cmodel = control.getModel();
|
||||
XPropertySet pset = (XPropertySet)UnoRuntime.queryInterface(
|
||||
XPropertySet.class, cmodel);
|
||||
|
||||
if (pset.getPropertyValue("Label").equals("Exit"))
|
||||
{
|
||||
// We can get the XDialog in which this control appears by calling
|
||||
// getContext() on the XControl interface
|
||||
XDialog xDialog = (XDialog)UnoRuntime.queryInterface(
|
||||
XDialog.class, control.getContext());
|
||||
|
||||
// Close the dialog
|
||||
xDialog.endExecute();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can get the list of controls for this dialog by calling
|
||||
// getContext() on the XControl interface of the button
|
||||
XControlContainer controls = (XControlContainer)UnoRuntime.queryInterface(
|
||||
XControlContainer.class, control.getContext());
|
||||
|
||||
// Now get the text field control from the list
|
||||
XTextComponent textField = (XTextComponent)
|
||||
UnoRuntime.queryInterface(
|
||||
XTextComponent.class, controls.getControl("HighlightTextField"));
|
||||
|
||||
String searchKey = textField.getText();
|
||||
|
||||
// highlight the text in red
|
||||
java.awt.Color cRed = new java.awt.Color(255, 0, 0);
|
||||
int red = cRed.getRGB();
|
||||
|
||||
XReplaceable replaceable = (XReplaceable)
|
||||
UnoRuntime.queryInterface(XReplaceable.class, XSCRIPTCONTEXT.getDocument());
|
||||
|
||||
XReplaceDescriptor descriptor =
|
||||
(XReplaceDescriptor) replaceable.createReplaceDescriptor();
|
||||
|
||||
// Gets a XPropertyReplace object for altering the properties
|
||||
// of the replaced text
|
||||
XPropertyReplace xPropertyReplace = (XPropertyReplace)
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Apply the properties
|
||||
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) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.beans.PropertyVetoException pve) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.lang.WrappedTargetException wte) {
|
||||
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);
|
||||
replaceable.replaceAll(descriptor);
|
||||
}
|
||||
|
||||
// BeanShell OpenOffice.org scripts should always return 0
|
||||
return 0;
|
||||
@@ -0,0 +1,144 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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 script serves as an example of how to launch a Basic Dialog
|
||||
// from a script
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.lang.EventObject;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.script.XLibraryContainer;
|
||||
import com.sun.star.awt.*;
|
||||
import com.sun.star.util.*;
|
||||
|
||||
boolean tryLoadingLibrary( xmcf, context, name )
|
||||
{
|
||||
try
|
||||
{
|
||||
obj = xmcf.createInstanceWithContext(
|
||||
"com.sun.star.script.Application" + name + "LibraryContainer",
|
||||
context.getComponentContext());
|
||||
|
||||
xLibraryContainer = (XLibraryContainer)
|
||||
UnoRuntime.queryInterface(XLibraryContainer.class, obj);
|
||||
|
||||
System.err.println("Got XLibraryContainer");
|
||||
|
||||
serviceObj = context.getComponentContext().getValueByName(
|
||||
"/singletons/com.sun.star.util.theMacroExpander");
|
||||
|
||||
xme = (XMacroExpander) AnyConverter.toObject(
|
||||
new Type(XMacroExpander.class), serviceObj);
|
||||
|
||||
bootstrapName = "bootstraprc";
|
||||
if (System.getProperty("os.name").startsWith("Windows"))
|
||||
{
|
||||
bootstrapName = "bootstrap.ini";
|
||||
}
|
||||
|
||||
libURL = xme.expandMacros(
|
||||
"${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
|
||||
"/share/basic/ScriptBindingLibrary/" +
|
||||
name.toLowerCase() + ".xlb/");
|
||||
|
||||
System.err.println("libURL is: " + libURL);
|
||||
|
||||
xLibraryContainer.createLibraryLink(
|
||||
"ScriptBindingLibrary", libURL, false);
|
||||
|
||||
System.err.println("liblink created");
|
||||
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e)
|
||||
{
|
||||
System.err.println("Got an exception loading lib: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// get the XMultiComponentFactory from the XSCRIPTCONTEXT
|
||||
XMultiComponentFactory xmcf =
|
||||
XSCRIPTCONTEXT.getComponentContext().getServiceManager();
|
||||
|
||||
Object[] args = new Object[1];
|
||||
args[0] = XSCRIPTCONTEXT.getDocument();
|
||||
|
||||
Object obj;
|
||||
try {
|
||||
// try to create an instance of the DialogProvider
|
||||
obj = xmcf.createInstanceWithArgumentsAndContext(
|
||||
"com.sun.star.awt.DialogProvider", args,
|
||||
XSCRIPTCONTEXT.getComponentContext());
|
||||
/*
|
||||
obj = xmcf.createInstanceWithContext(
|
||||
"com.sun.star.awt.DialogProvider",
|
||||
XSCRIPTCONTEXT.getComponentContext());
|
||||
*/
|
||||
}
|
||||
catch (com.sun.star.uno.Exception e) {
|
||||
System.err.println("Error getting DialogProvider object");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get the XDialogProvider interface from the object created above
|
||||
XDialogProvider xDialogProvider = (XDialogProvider)
|
||||
UnoRuntime.queryInterface(XDialogProvider.class, obj);
|
||||
|
||||
System.err.println("Got DialogProvider, now get dialog");
|
||||
|
||||
try {
|
||||
// try to create the Highlight dialog (found in the ScriptBindingLibrary)
|
||||
findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
if( findDialog == null )
|
||||
{
|
||||
if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
|
||||
tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
|
||||
{
|
||||
System.err.println("Error loading ScriptBindingLibrary");
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to create the Highlight dialog (found in the ScriptBindingLibrary)
|
||||
findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (java.lang.Exception e) {
|
||||
System.err.println("Got exception on first creating dialog: " +
|
||||
e.getMessage());
|
||||
}
|
||||
|
||||
// execute the dialog in a new thread (so that this script can finish)
|
||||
Thread t = new Thread() {
|
||||
public void run() {
|
||||
findDialog.execute();
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
|
||||
return 0;
|
||||
@@ -0,0 +1,169 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.util.XReplaceable;
|
||||
import com.sun.star.util.XReplaceDescriptor;
|
||||
import com.sun.star.util.XPropertyReplace;
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
|
||||
int replaceText(searchKey, color, bold) {
|
||||
|
||||
result = 0;
|
||||
|
||||
try {
|
||||
// Create an XReplaceable object and an XReplaceDescriptor
|
||||
replaceable = (XReplaceable)
|
||||
UnoRuntime.queryInterface(XReplaceable.class, xTextDocument);
|
||||
|
||||
descriptor =
|
||||
(XReplaceDescriptor) replaceable.createReplaceDescriptor();
|
||||
|
||||
// Gets a XPropertyReplace object for altering the properties
|
||||
// of the replaced text
|
||||
xPropertyReplace = (XPropertyReplace)
|
||||
UnoRuntime.queryInterface(XPropertyReplace.class, descriptor);
|
||||
|
||||
// Sets the replaced text property fontweight value to Bold or Normal
|
||||
wv = null;
|
||||
if (bold) {
|
||||
wv = new PropertyValue("CharWeight", -1,
|
||||
new Float(com.sun.star.awt.FontWeight.BOLD),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
}
|
||||
else {
|
||||
wv = new PropertyValue("CharWeight", -1,
|
||||
new Float(com.sun.star.awt.FontWeight.NORMAL),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
}
|
||||
|
||||
// Sets the replaced text property color value to RGB color parameter
|
||||
cv = new PropertyValue("CharColor", -1, new Integer(color),
|
||||
com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
|
||||
// Apply the properties
|
||||
PropertyValue[] props = { cv, wv };
|
||||
xPropertyReplace.setReplaceAttributes(props);
|
||||
|
||||
// Only matches whole words and case sensitive
|
||||
descriptor.setPropertyValue("SearchCaseSensitive", new Boolean(true));
|
||||
descriptor.setPropertyValue("SearchWords", new Boolean(true));
|
||||
|
||||
// Replaces all instances of searchKey with new Text properties
|
||||
// and gets the number of instances of the searchKey
|
||||
descriptor.setSearchString(searchKey);
|
||||
descriptor.setReplaceString(searchKey);
|
||||
result = replaceable.replaceAll(descriptor);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
searchKey = "";
|
||||
|
||||
// The XSCRIPTCONTEXT variable is of type XScriptContext and is available to
|
||||
// all BeanShell scripts executed by the Script Framework
|
||||
xTextDocument = (XTextDocument)
|
||||
UnoRuntime.queryInterface(XTextDocument.class, XSCRIPTCONTEXT.getDocument());
|
||||
|
||||
// Create a JButton and add an ActionListener
|
||||
// When clicked the value for the searchKey is read and passed to replaceText
|
||||
myListener = new ActionListener() {
|
||||
actionPerformed(ActionEvent e) {
|
||||
searchKey = findTextBox.getText();
|
||||
|
||||
if(searchKey.equalsIgnoreCase("")) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"No text entered for search",
|
||||
"No text", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
else {
|
||||
// highlight the text in red
|
||||
cRed = new Color(255, 0, 0);
|
||||
red = cRed.getRGB();
|
||||
num = replaceText(searchKey, red, true);
|
||||
|
||||
if(num > 0) {
|
||||
int response = JOptionPane.showConfirmDialog(null,
|
||||
searchKey + " was found " + num +
|
||||
" times\nDo you wish to keep the text highlighted?",
|
||||
"Confirm highlight", JOptionPane.YES_NO_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if (response == 1) {
|
||||
cBlack = new Color(255, 255, 255);
|
||||
black = cBlack.getRGB();
|
||||
replaceText(searchKey, black, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"No matches were found", "Not found",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exitListener = new ActionListener() {
|
||||
actionPerformed(ActionEvent e) {
|
||||
frame.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
searchButton = new JButton("Highlight");
|
||||
searchButton.addActionListener(myListener);
|
||||
|
||||
exitButton = new JButton("Exit");
|
||||
exitButton.addActionListener(exitListener);
|
||||
|
||||
buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new FlowLayout());
|
||||
buttonPanel.add(searchButton);
|
||||
buttonPanel.add(exitButton);
|
||||
|
||||
|
||||
// Create a JPanel containing one JTextField for the search text.
|
||||
searchPanel = new JPanel();
|
||||
searchPanel.setLayout(new FlowLayout());
|
||||
findTextBox = new JTextField(20);
|
||||
findWhat = new JLabel("Find What: ");
|
||||
searchPanel.add(findWhat);
|
||||
searchPanel.add(findTextBox);
|
||||
|
||||
// Create frame and add a window listener
|
||||
frame = new JFrame("Highlight Text");
|
||||
frame.setSize(350,130);
|
||||
frame.setLocation(430,430);
|
||||
frame.setResizable(false);
|
||||
// Add the panel and button to the frame
|
||||
frame.getContentPane().setLayout(new GridLayout(2,1,10,10));
|
||||
frame.getContentPane().add(searchPanel);
|
||||
frame.getContentPane().add(buttonPanel);
|
||||
|
||||
frame.setVisible(true);
|
||||
frame.pack();
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="BeanShell" xmlns:parcel="scripting.dtd">
|
||||
<script language="BeanShell">
|
||||
<locale lang="en">
|
||||
<displayname value="ShowDialog" />
|
||||
<description>
|
||||
Example of how to show a dialog from BeanShell
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="ShowDialog.bsh" />
|
||||
<logicalname value="ShowDialog.BeanShell" />
|
||||
</script>
|
||||
<script language="BeanShell">
|
||||
<locale lang="en">
|
||||
<displayname value="ButtonPressHandler" />
|
||||
<description>
|
||||
Example of handle button press events for the Dialog
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="ButtonPressHandler.bsh" />
|
||||
<logicalname value="ButtonPressHandler.BeanShell" />
|
||||
</script>
|
||||
</parcel>
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
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.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;
|
||||
|
||||
createSpreadsheet()
|
||||
{
|
||||
loader = (XComponentLoader)
|
||||
UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, XSCRIPTCONTEXT.getDesktop());
|
||||
|
||||
comp = loader.loadComponentFromURL(
|
||||
"private:factory/scalc", "_blank", 4, new PropertyValue[0]);
|
||||
|
||||
doc = (XSpreadsheetDocument)
|
||||
UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
|
||||
|
||||
index = (XIndexAccess)
|
||||
UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
|
||||
|
||||
sheet = (XSpreadsheet) AnyConverter.toObject(
|
||||
new Type(com.sun.star.sheet.XSpreadsheet.class), index.getByIndex(0));
|
||||
|
||||
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(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();
|
||||
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];
|
||||
|
||||
sheet = createSpreadsheet();
|
||||
addData(sheet, date.toString(), runtime.totalMemory(), runtime.freeMemory());
|
||||
addChart(sheet);
|
||||
|
||||
return 0;
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="BeanShell" xmlns:parcel="scripting.dtd">
|
||||
|
||||
<script language="BeanShell">
|
||||
<locale lang="en">
|
||||
<displayname value="BeanShell JVM Usage"/>
|
||||
<description>
|
||||
Updates a spreadsheet with the current memory usage statistics for the Java Virtual Machine
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="memusage.bsh"/>
|
||||
<logicalname value="MemoryUsage.BeanShell"/>
|
||||
</script>
|
||||
|
||||
</parcel>
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="BeanShell" xmlns:parcel="scripting.dtd">
|
||||
|
||||
<script language="BeanShell">
|
||||
<locale lang="en">
|
||||
<displayname value="Word Count"/>
|
||||
<description>
|
||||
Provides a word count of the selected text in A Writer document.
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="wordcount.bsh"/>
|
||||
<logicalname value="WordCount.BeanShell"/>
|
||||
</script>
|
||||
|
||||
</parcel>
|
||||
@@ -0,0 +1,84 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
//Provides a word count of the selected text in A Writer document.
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.frame.XModel;
|
||||
import com.sun.star.view.XSelectionSupplier;
|
||||
import com.sun.star.container.XIndexAccess;
|
||||
import com.sun.star.text.XText;
|
||||
import com.sun.star.text.XTextRange;
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
|
||||
// display the count in a Swing dialog
|
||||
void doDisplay(numWords) {
|
||||
wordsLabel = new JLabel("Word count = " + numWords);
|
||||
closeButton = new JButton("Close");
|
||||
frame = new JFrame("Word Count");
|
||||
closeButton.addActionListener(new ActionListener() {
|
||||
actionPerformed(ActionEvent e) {
|
||||
frame.setVisible(false);
|
||||
}
|
||||
});
|
||||
frame.getContentPane().setLayout(new BorderLayout());
|
||||
frame.getContentPane().add(wordsLabel, BorderLayout.CENTER);
|
||||
frame.getContentPane().add(closeButton, BorderLayout.SOUTH);
|
||||
frame.pack();
|
||||
frame.setSize(190,90);
|
||||
frame.setLocation(430,430);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
int wordcount() {
|
||||
|
||||
result = 0;
|
||||
|
||||
// iterate through each of the selections
|
||||
count = xIndexAccess.getCount();
|
||||
for(i=0;i<count;i++) {
|
||||
// get the XTextRange of the selection
|
||||
xTextRange = (XTextRange)
|
||||
UnoRuntime.queryInterface(XTextRange.class, xIndexAccess.getByIndex(i));
|
||||
//System.out.println("string: "+xTextRange.getString());
|
||||
// use the standard J2SE delimiters to tokenize the string
|
||||
// obtained from the XTextRange
|
||||
strTok = new StringTokenizer(xTextRange.getString());
|
||||
result += strTok.countTokens();
|
||||
}
|
||||
|
||||
doDisplay(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
// The XSCRIPTCONTEXT variable is of type XScriptContext and is available to
|
||||
// all BeanShell scripts executed by the Script Framework
|
||||
xModel = (XModel)
|
||||
UnoRuntime.queryInterface(XModel.class, XSCRIPTCONTEXT.getDocument());
|
||||
//the writer controller impl supports the css.view.XSelectionSupplier interface
|
||||
xSelectionSupplier = (XSelectionSupplier)
|
||||
UnoRuntime.queryInterface(XSelectionSupplier.class, xModel.getCurrentController());
|
||||
//see section 7.5.1 of developers' guide
|
||||
// the getSelection provides an XIndexAccess to the one or more selections
|
||||
xIndexAccess = (XIndexAccess)
|
||||
UnoRuntime.queryInterface(XIndexAccess.class, xSelectionSupplier.getSelection());
|
||||
|
||||
count = wordcount();
|
||||
System.out.println("count = "+count);
|
||||
return 0;
|
||||
Binary file not shown.
@@ -0,0 +1,43 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.text.XTextRange;
|
||||
import com.sun.star.text.XText;
|
||||
/**
|
||||
* HelloWorld class
|
||||
*
|
||||
*/
|
||||
public class HelloWorld {
|
||||
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)" );
|
||||
|
||||
}// printHW
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
<parcel language="Java" xmlns:parcel="scripting.dtd">
|
||||
<script language="Java">
|
||||
<locale lang="en">
|
||||
<displayname value="HelloWorld.Java"/>
|
||||
<description>
|
||||
Prints "Helo World".
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="HelloWorld.printHW"/>
|
||||
<logicalname value="HelloWorld.printHW"/>
|
||||
<languagedepprops>
|
||||
<prop name="classpath" value="HelloWorld.jar"/>
|
||||
</languagedepprops>
|
||||
</script>
|
||||
</parcel>
|
||||
Binary file not shown.
@@ -0,0 +1,244 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.script.provider.XScriptContext;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.lang.EventObject;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.script.XLibraryContainer;
|
||||
import com.sun.star.awt.*;
|
||||
import com.sun.star.util.*;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
public class HighlightText implements com.sun.star.awt.XActionListener {
|
||||
|
||||
// UNO awt components of the Highlight dialog
|
||||
XDialog findDialog = null;
|
||||
XTextComponent findTextBox;
|
||||
|
||||
// The document being searched
|
||||
XTextDocument theDocument;
|
||||
|
||||
// The text to be searched for
|
||||
private String searchKey = "";
|
||||
|
||||
public void showForm(XScriptContext context) {
|
||||
System.err.println("Starting showForm");
|
||||
|
||||
XMultiComponentFactory xmcf =
|
||||
context.getComponentContext().getServiceManager();
|
||||
|
||||
Object[] args = new Object[1];
|
||||
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) {
|
||||
System.err.println("Error getting DialogProvider object");
|
||||
return;
|
||||
}
|
||||
|
||||
XDialogProvider xDialogProvider = (XDialogProvider)
|
||||
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) {
|
||||
System.err.println("Got exception on first creating dialog: " +
|
||||
e.getMessage());
|
||||
}
|
||||
|
||||
if (findDialog == null) {
|
||||
if (tryLoadingLibrary(xmcf, context, "Dialog") == false ||
|
||||
tryLoadingLibrary(xmcf, context, "Script") == false)
|
||||
{
|
||||
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) {
|
||||
System.err.println("Error loading ScriptBindingLibrary");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
XControlContainer controls = (XControlContainer)
|
||||
UnoRuntime.queryInterface(XControlContainer.class, findDialog);
|
||||
|
||||
XButton highlightButton = (XButton) UnoRuntime.queryInterface(
|
||||
XButton.class, controls.getControl("HighlightButton"));
|
||||
highlightButton.setActionCommand("Highlight");
|
||||
|
||||
findTextBox = (XTextComponent) UnoRuntime.queryInterface(
|
||||
XTextComponent.class, controls.getControl("HighlightTextField"));
|
||||
|
||||
XButton exitButton = (XButton) UnoRuntime.queryInterface(
|
||||
XButton.class, controls.getControl("ExitButton"));
|
||||
exitButton.setActionCommand("Exit");
|
||||
|
||||
theDocument = (XTextDocument) UnoRuntime.queryInterface(
|
||||
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")) {
|
||||
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);
|
||||
|
||||
XReplaceDescriptor descriptor =
|
||||
(XReplaceDescriptor) replaceable.createReplaceDescriptor();
|
||||
|
||||
// Gets a XPropertyReplace object for altering the properties
|
||||
// of the replaced text
|
||||
XPropertyReplace xPropertyReplace = (XPropertyReplace)
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
// Apply the properties
|
||||
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) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.beans.PropertyVetoException pve) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
catch (com.sun.star.lang.WrappedTargetException wte) {
|
||||
System.err.println("Error setting up search properties");
|
||||
return;
|
||||
}
|
||||
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);
|
||||
replaceable.replaceAll(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public void disposing(EventObject o)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
private boolean tryLoadingLibrary(
|
||||
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());
|
||||
|
||||
XLibraryContainer xLibraryContainer = (XLibraryContainer)
|
||||
UnoRuntime.queryInterface(XLibraryContainer.class, obj);
|
||||
|
||||
System.err.println("Got XLibraryContainer");
|
||||
|
||||
Object serviceObj = context.getComponentContext().getValueByName(
|
||||
"/singletons/com.sun.star.util.theMacroExpander");
|
||||
|
||||
XMacroExpander xme = (XMacroExpander) AnyConverter.toObject(
|
||||
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/");
|
||||
|
||||
System.err.println("libURL is: " + libURL);
|
||||
|
||||
xLibraryContainer.createLibraryLink(
|
||||
"ScriptBindingLibrary", libURL, false);
|
||||
|
||||
System.err.println("liblink created");
|
||||
|
||||
} catch (com.sun.star.uno.Exception e) {
|
||||
System.err.println("Got an exception loading lib: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="Java" xmlns:parcel="scripting.dtd">
|
||||
<script language="Java">
|
||||
<locale lang="en">
|
||||
<displayname value="HighlightText.showForm"/>
|
||||
<description>
|
||||
Text highlighting
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="HighlightText.showForm"/>
|
||||
<logicalname value="HighlightText.showForm"/>
|
||||
<languagedepprops>
|
||||
<prop name="classpath" value="Highlight.jar"/>
|
||||
</languagedepprops>
|
||||
</script>
|
||||
</parcel>
|
||||
Binary file not shown.
@@ -0,0 +1,162 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*************************************************************/
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Date;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.AnyConverter;
|
||||
import com.sun.star.uno.Type;
|
||||
import com.sun.star.uno.XInterface;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiServiceFactory;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.document.XEmbeddedObjectSupplier;
|
||||
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;
|
||||
|
||||
public class MemoryUsage
|
||||
{
|
||||
// public void updateMemoryUsage(XScriptContext ctxt, ActionEvent evt)
|
||||
public void updateMemoryUsage(XScriptContext ctxt)
|
||||
throws Exception
|
||||
{
|
||||
XSpreadsheet sheet = createSpreadsheet(ctxt);
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
Random generator = new Random();
|
||||
Date date = new Date();
|
||||
|
||||
// allocate a random amount of memory
|
||||
int len = (int)(generator.nextFloat() * runtime.freeMemory() / 5);
|
||||
byte[] bytes = new byte[len];
|
||||
|
||||
addData(sheet, date.toString(),
|
||||
runtime.totalMemory(), runtime.freeMemory());
|
||||
|
||||
addChart(sheet);
|
||||
}
|
||||
|
||||
private XSpreadsheet createSpreadsheet(XScriptContext ctxt)
|
||||
throws Exception
|
||||
{
|
||||
XComponentLoader loader = (XComponentLoader)
|
||||
UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, ctxt.getDesktop());
|
||||
|
||||
XComponent comp = loader.loadComponentFromURL(
|
||||
"private:factory/scalc", "_blank", 4, new PropertyValue[0]);
|
||||
|
||||
XSpreadsheetDocument doc = (XSpreadsheetDocument)
|
||||
UnoRuntime.queryInterface(XSpreadsheetDocument.class, comp);
|
||||
|
||||
XIndexAccess index = (XIndexAccess)
|
||||
UnoRuntime.queryInterface(XIndexAccess.class, doc.getSheets());
|
||||
|
||||
XSpreadsheet sheet = (XSpreadsheet) AnyConverter.toObject(
|
||||
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
|
||||
{
|
||||
sheet.getCellByPosition(0, 0).setFormula("Used");
|
||||
sheet.getCellByPosition(0, 1).setFormula("Free");
|
||||
sheet.getCellByPosition(0, 2).setFormula("Total");
|
||||
|
||||
sheet.getCellByPosition(1, 0).setValue(total - free);
|
||||
sheet.getCellByPosition(1, 1).setValue(free);
|
||||
sheet.getCellByPosition(1, 2).setValue(total);
|
||||
}
|
||||
|
||||
private void addChart(XSpreadsheet sheet)
|
||||
throws Exception
|
||||
{
|
||||
Rectangle rect = new Rectangle();
|
||||
rect.X = 500;
|
||||
rect.Y = 3000;
|
||||
rect.Width = 10000;
|
||||
rect.Height = 8000;
|
||||
|
||||
XCellRange range = (XCellRange)
|
||||
UnoRuntime.queryInterface(XCellRange.class, sheet);
|
||||
|
||||
XCellRange myRange =
|
||||
range.getCellRangeByName("A1:B2");
|
||||
|
||||
XCellRangeAddressable rangeAddr = (XCellRangeAddressable)
|
||||
UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange);
|
||||
|
||||
CellRangeAddress myAddr = rangeAddr.getRangeAddress();
|
||||
|
||||
CellRangeAddress[] addr = new CellRangeAddress[1];
|
||||
addr[0] = myAddr;
|
||||
|
||||
XTableChartsSupplier supp = (XTableChartsSupplier)
|
||||
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) { }
|
||||
|
||||
// get the diagram and Change some of the properties
|
||||
XNameAccess chartsAccess = (XNameAccess)
|
||||
UnoRuntime.queryInterface( XNameAccess.class, charts);
|
||||
|
||||
XTableChart tchart = (XTableChart)
|
||||
UnoRuntime.queryInterface(
|
||||
XTableChart.class, chartsAccess.getByName("Example"));
|
||||
|
||||
XEmbeddedObjectSupplier eos = (XEmbeddedObjectSupplier)
|
||||
UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, tchart );
|
||||
|
||||
XInterface xifc = eos.getEmbeddedObject();
|
||||
|
||||
XChartDocument xChart = (XChartDocument)
|
||||
UnoRuntime.queryInterface(XChartDocument.class, xifc);
|
||||
|
||||
XMultiServiceFactory xDocMSF = (XMultiServiceFactory)
|
||||
UnoRuntime.queryInterface(XMultiServiceFactory.class, xChart);
|
||||
|
||||
Object diagObject =
|
||||
xDocMSF.createInstance("com.sun.star.chart.PieDiagram");
|
||||
|
||||
XDiagram xDiagram = (XDiagram)
|
||||
UnoRuntime.queryInterface(XDiagram.class, diagObject);
|
||||
|
||||
xChart.setDiagram(xDiagram);
|
||||
|
||||
XPropertySet propset = (XPropertySet)
|
||||
UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() );
|
||||
propset.setPropertyValue("String", "JVM Memory Usage");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
<parcel language="Java" xmlns:parcel="scripting.dtd">
|
||||
<script language="Java">
|
||||
<locale lang="en">
|
||||
<displayname value="MemoryUtils.MemUsage"/>
|
||||
<description>
|
||||
Text highlighting
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="MemoryUsage.updateMemoryUsage"/>
|
||||
<logicalname value="MemoryUtils.MemUsage"/>
|
||||
<languagedepprops>
|
||||
<prop name="classpath" value="MemoryUsage.jar"/>
|
||||
</languagedepprops>
|
||||
</script>
|
||||
</parcel>
|
||||
@@ -0,0 +1,91 @@
|
||||
// *************************************************************
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// *************************************************************
|
||||
// When this script is run on an existing, saved, spreadsheet,
|
||||
// eg. /home/testuser/myspreadsheet.sxc, the script will export
|
||||
// each sheet to a separate html file,
|
||||
// eg. /home/testuser/myspreadsheet_sheet1.html,
|
||||
// /home/testuser/myspreadsheet_sheet2.html etc
|
||||
importClass(Packages.com.sun.star.uno.UnoRuntime);
|
||||
importClass(Packages.com.sun.star.sheet.XSpreadsheetDocument);
|
||||
importClass(Packages.com.sun.star.container.XIndexAccess);
|
||||
importClass(Packages.com.sun.star.beans.XPropertySet);
|
||||
importClass(Packages.com.sun.star.beans.PropertyValue);
|
||||
importClass(Packages.com.sun.star.util.XModifiable);
|
||||
importClass(Packages.com.sun.star.frame.XStorable);
|
||||
importClass(Packages.com.sun.star.frame.XModel);
|
||||
importClass(Packages.com.sun.star.uno.AnyConverter);
|
||||
importClass(Packages.com.sun.star.uno.Type);
|
||||
|
||||
importClass(java.lang.System);
|
||||
|
||||
//get the document object from the scripting context
|
||||
oDoc = XSCRIPTCONTEXT.getDocument();
|
||||
//get the XSpreadsheetDocument interface from the document
|
||||
xSDoc = UnoRuntime.queryInterface(XSpreadsheetDocument, oDoc);
|
||||
//get the XModel interface from the document
|
||||
xModel = UnoRuntime.queryInterface(XModel,oDoc);
|
||||
//get the XIndexAccess interface used to access each sheet
|
||||
xSheetsIndexAccess = UnoRuntime.queryInterface(XIndexAccess, xSDoc.getSheets());
|
||||
//get the XStorable interface used to save the document
|
||||
xStorable = UnoRuntime.queryInterface(XStorable,xSDoc);
|
||||
//get the XModifiable interface used to indicate if the document has been
|
||||
//changed
|
||||
xModifiable = UnoRuntime.queryInterface(XModifiable,xSDoc);
|
||||
|
||||
//set up an array of PropertyValue objects used to save each sheet in the
|
||||
//document
|
||||
storeProps = new Array;//PropertyValue[1];
|
||||
storeProps[0] = new PropertyValue();
|
||||
storeProps[0].Name = "FilterName";
|
||||
storeProps[0].Value = "HTML (StarCalc)";
|
||||
storeUrl = xModel.getURL();
|
||||
storeUrl = storeUrl.substring(0,storeUrl.lastIndexOf('.'));
|
||||
|
||||
//set only one sheet visible, and store to HTML doc
|
||||
for(var i=0;i<xSheetsIndexAccess.getCount();i++)
|
||||
{
|
||||
setAllButOneHidden(xSheetsIndexAccess,i);
|
||||
xModifiable.setModified(false);
|
||||
xStorable.storeToURL(storeUrl+"_sheet"+(i+1)+".html", storeProps);
|
||||
}
|
||||
|
||||
// now set all visible again
|
||||
for(var i=0;i<xSheetsIndexAccess.getCount();i++)
|
||||
{
|
||||
xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i));
|
||||
xPropSet.setPropertyValue("IsVisible", true);
|
||||
}
|
||||
|
||||
function setAllButOneHidden(xSheetsIndexAccess,vis) {
|
||||
//System.err.println("count="+xSheetsIndexAccess.getCount());
|
||||
//get an XPropertySet interface for the vis-th sheet
|
||||
xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(vis));
|
||||
//set the vis-th sheet to be visible
|
||||
xPropSet.setPropertyValue("IsVisible", true);
|
||||
// set all other sheets to be invisible
|
||||
for(var i=0;i<xSheetsIndexAccess.getCount();i++)
|
||||
{
|
||||
xPropSet = AnyConverter.toObject( new Type(XPropertySet), xSheetsIndexAccess.getByIndex(i));
|
||||
if(i!=vis) {
|
||||
xPropSet.setPropertyValue("IsVisible", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="JavaScript" xmlns:parcel="scripting.dtd">
|
||||
|
||||
<script language="JavaScript">
|
||||
<locale lang="en">
|
||||
<displayname value="ExportSheetsToHTML"/>
|
||||
<description>
|
||||
Saves each sheet in the current Calc document as a separate HTML file in the same directory as the original Calc document.
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="exportsheetstohtml.js"/>
|
||||
<logicalname value="ExportSheetsToHTML.JavaScript"/>
|
||||
</script>
|
||||
|
||||
</parcel>
|
||||
@@ -0,0 +1,36 @@
|
||||
// *************************************************************
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// *************************************************************
|
||||
// Hello World in JavaScript
|
||||
importClass(Packages.com.sun.star.uno.UnoRuntime);
|
||||
importClass(Packages.com.sun.star.text.XTextDocument);
|
||||
importClass(Packages.com.sun.star.text.XText);
|
||||
importClass(Packages.com.sun.star.text.XTextRange);
|
||||
|
||||
//get the document from the scripting context
|
||||
oDoc = XSCRIPTCONTEXT.getDocument();
|
||||
//get the XTextDocument interface
|
||||
xTextDoc = UnoRuntime.queryInterface(XTextDocument,oDoc);
|
||||
//get the XText interface
|
||||
xText = xTextDoc.getText();
|
||||
//get an (empty) XTextRange interface at the end of the text
|
||||
xTextRange = xText.getEnd();
|
||||
//set the text in the XTextRange
|
||||
xTextRange.setString( "Hello World (in JavaScript)" );
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="JavaScript" xmlns:parcel="scripting.dtd">
|
||||
|
||||
<script language="JavaScript">
|
||||
<locale lang="en">
|
||||
<displayname value="Hello World"/>
|
||||
<description>
|
||||
Adds the the string "Hello World" into the current text doc.
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="helloworld.js"/>
|
||||
<logicalname value="HelloWorld.JavaScript"/>
|
||||
</script>
|
||||
|
||||
</parcel>
|
||||
@@ -0,0 +1,125 @@
|
||||
// *************************************************************
|
||||
//
|
||||
// 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 script acts as a handler for the buttons in the Highlight dialog
|
||||
importClass(Packages.com.sun.star.uno.UnoRuntime);
|
||||
importClass(Packages.com.sun.star.uno.Type);
|
||||
importClass(Packages.com.sun.star.uno.AnyConverter);
|
||||
|
||||
importClass(Packages.com.sun.star.awt.XButton);
|
||||
importClass(Packages.com.sun.star.awt.XControl);
|
||||
importClass(Packages.com.sun.star.awt.ActionEvent);
|
||||
importClass(Packages.com.sun.star.awt.XControlModel);
|
||||
importClass(Packages.com.sun.star.awt.XControlContainer);
|
||||
importClass(Packages.com.sun.star.awt.XDialog);
|
||||
importClass(Packages.com.sun.star.awt.XTextComponent);
|
||||
|
||||
importClass(Packages.com.sun.star.util.XReplaceable);
|
||||
importClass(Packages.com.sun.star.util.XReplaceDescriptor);
|
||||
importClass(Packages.com.sun.star.util.XPropertyReplace);
|
||||
|
||||
importClass(Packages.com.sun.star.beans.XPropertySet);
|
||||
importClass(Packages.com.sun.star.beans.PropertyValue);
|
||||
|
||||
// Scripting Framework DialogFactory class
|
||||
importClass(Packages.com.sun.star.script.framework.browse.DialogFactory);
|
||||
|
||||
// Get the ActionEvent object from the ARGUMENTS list
|
||||
event = ARGUMENTS[0];
|
||||
|
||||
// Each argument is of type Any so we must use the AnyConverter class to
|
||||
// convert it into the interface or primitive type we expect
|
||||
button = AnyConverter.toObject(new Type(XButton), event.Source);
|
||||
|
||||
// We can now query for the model of the button and get its properties
|
||||
control = UnoRuntime.queryInterface(XControl, button);
|
||||
cmodel = control.getModel();
|
||||
pset = UnoRuntime.queryInterface(XPropertySet, cmodel);
|
||||
|
||||
if (pset.getPropertyValue("Label").equals("Exit"))
|
||||
{
|
||||
// We can get the XDialog in which this control appears by calling
|
||||
// getContext() on the XControl interface
|
||||
xDialog = UnoRuntime.queryInterface(
|
||||
XDialog, control.getContext());
|
||||
|
||||
// Close the dialog
|
||||
xDialog.endExecute();
|
||||
}
|
||||
else
|
||||
{
|
||||
// We can get the list of controls for this dialog by calling
|
||||
// getContext() on the XControl interface of the button
|
||||
controls = UnoRuntime.queryInterface(
|
||||
XControlContainer, control.getContext());
|
||||
|
||||
// Now get the text field control from the list
|
||||
textField =
|
||||
UnoRuntime.queryInterface(
|
||||
XTextComponent, controls.getControl("HighlightTextField"));
|
||||
|
||||
searchKey = textField.getText();
|
||||
|
||||
// highlight the text in red
|
||||
red = java.awt.Color.red.getRGB();
|
||||
|
||||
replaceable =
|
||||
UnoRuntime.queryInterface(XReplaceable, XSCRIPTCONTEXT.getDocument());
|
||||
|
||||
descriptor = replaceable.createReplaceDescriptor();
|
||||
|
||||
// Gets a XPropertyReplace object for altering the properties
|
||||
// of the replaced text
|
||||
xPropertyReplace = UnoRuntime.queryInterface(XPropertyReplace, descriptor);
|
||||
|
||||
// Sets the replaced text property fontweight value to Bold
|
||||
wv = new PropertyValue("CharWeight", -1,
|
||||
new java.lang.Float(Packages.com.sun.star.awt.FontWeight.BOLD),
|
||||
Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
|
||||
// Sets the replaced text property color value to RGB parameter
|
||||
cv = new PropertyValue("CharColor", -1,
|
||||
new java.lang.Integer(red),
|
||||
Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
|
||||
|
||||
// Apply the properties
|
||||
props = new Array;
|
||||
props[0] = cv;
|
||||
props[1] = wv;
|
||||
|
||||
try {
|
||||
xPropertyReplace.setReplaceAttributes(props);
|
||||
|
||||
// Only matches whole words and case sensitive
|
||||
descriptor.setPropertyValue(
|
||||
"SearchCaseSensitive", new java.lang.Boolean(true));
|
||||
descriptor.setPropertyValue("SearchWords", new java.lang.Boolean(true));
|
||||
|
||||
// Replaces all instances of searchKey with new Text properties
|
||||
// and gets the number of instances of the searchKey
|
||||
descriptor.setSearchString(searchKey);
|
||||
descriptor.setReplaceString(searchKey);
|
||||
replaceable.replaceAll(descriptor);
|
||||
}
|
||||
catch (e) {
|
||||
java.lang.System.err.println("Error setting up search properties"
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
// *************************************************************
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// *************************************************************
|
||||
importClass(Packages.com.sun.star.uno.UnoRuntime);
|
||||
importClass(Packages.com.sun.star.lang.XMultiComponentFactory);
|
||||
importClass(Packages.com.sun.star.awt.XDialogProvider);
|
||||
importClass(Packages.com.sun.star.awt.XDialog);
|
||||
importClass(Packages.com.sun.star.uno.Exception);
|
||||
importClass(Packages.com.sun.star.script.provider.XScriptContext);
|
||||
|
||||
importClass(java.lang.Thread);
|
||||
importClass(java.lang.System);
|
||||
|
||||
function tryLoadingLibrary( xmcf, context, name )
|
||||
{
|
||||
try
|
||||
{
|
||||
obj = xmcf.createInstanceWithContext(
|
||||
"com.sun.star.script.Application" + name + "LibraryContainer",
|
||||
context.getComponentContext());
|
||||
|
||||
xLibraryContainer = UnoRuntime.queryInterface(XLibraryContainer, obj);
|
||||
|
||||
System.err.println("Got XLibraryContainer");
|
||||
|
||||
serviceObj = context.getComponentContext().getValueByName(
|
||||
"/singletons/com.sun.star.util.theMacroExpander");
|
||||
|
||||
xme = AnyConverter.toObject(new Type(XMacroExpander), serviceObj);
|
||||
|
||||
bootstrapName = "bootstraprc";
|
||||
if (System.getProperty("os.name").startsWith("Windows"))
|
||||
{
|
||||
bootstrapName = "bootstrap.ini";
|
||||
}
|
||||
|
||||
libURL = xme.expandMacros(
|
||||
"${$OOO_BASE_DIR/program/" + bootstrapName + "::BaseInstallation}" +
|
||||
"/share/basic/ScriptBindingLibrary/" +
|
||||
name.toLowerCase() + ".xlb/");
|
||||
|
||||
System.err.println("libURL is: " + libURL);
|
||||
|
||||
xLibraryContainer.createLibraryLink(
|
||||
"ScriptBindingLibrary", libURL, false);
|
||||
|
||||
System.err.println("liblink created");
|
||||
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
System.err.println("Got an exception loading lib: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getDialogProvider()
|
||||
{
|
||||
// UNO awt components of the Highlight dialog
|
||||
//get the XMultiServiceFactory
|
||||
xmcf = XSCRIPTCONTEXT.getComponentContext().getServiceManager();
|
||||
|
||||
args = new Array;
|
||||
//get the XDocument from the context
|
||||
args[0] = XSCRIPTCONTEXT.getDocument();
|
||||
|
||||
//try to create the DialogProvider
|
||||
try {
|
||||
obj = xmcf.createInstanceWithArgumentsAndContext(
|
||||
"com.sun.star.awt.DialogProvider", args,
|
||||
XSCRIPTCONTEXT.getComponentContext());
|
||||
}
|
||||
catch (e) {
|
||||
System.err.println("Error getting DialogProvider object");
|
||||
return null;
|
||||
}
|
||||
|
||||
return UnoRuntime.queryInterface(XDialogProvider, obj);
|
||||
}
|
||||
|
||||
//get the DialogProvider
|
||||
xDialogProvider = getDialogProvider();
|
||||
|
||||
if (xDialogProvider != null)
|
||||
{
|
||||
//try to create the Highlight dialog (found in the ScriptBinding library)
|
||||
try
|
||||
{
|
||||
findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
if( findDialog == null )
|
||||
{
|
||||
if (tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Dialog") == false ||
|
||||
tryLoadingLibrary(xmcf, XSCRIPTCONTEXT, "Script") == false)
|
||||
{
|
||||
System.err.println("Error loading ScriptBindingLibrary");
|
||||
}
|
||||
else
|
||||
{
|
||||
// try to create the Highlight dialog (found in the
|
||||
// ScriptBindingLibrary)
|
||||
findDialog = xDialogProvider.createDialog("vnd.sun.star.script:" +
|
||||
"ScriptBindingLibrary.Highlight?location=application");
|
||||
}
|
||||
}
|
||||
|
||||
//launch the dialog
|
||||
if ( findDialog != null )
|
||||
{
|
||||
findDialog.execute();
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
System.err.println("Got exception on first creating dialog: " +
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?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.
|
||||
*
|
||||
***********************************************************-->
|
||||
|
||||
<parcel language="JavaScript" xmlns:parcel="scripting.dtd">
|
||||
<script language="JavaScript">
|
||||
<locale lang="en">
|
||||
<displayname value="ShowDialog" />
|
||||
<description>
|
||||
Example of how to show a dialog from JavaScript
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="ShowDialog.js" />
|
||||
<logicalname value="ShowDialog.JavaScript" />
|
||||
</script>
|
||||
<script language="JavaScript">
|
||||
<locale lang="en">
|
||||
<displayname value="ButtonPressHandler" />
|
||||
<description>
|
||||
Example of handle button press events for the Dialog
|
||||
</description>
|
||||
</locale>
|
||||
<functionname value="ButtonPressHandler.js" />
|
||||
<logicalname value="ButtonPressHandler.JavaScript" />
|
||||
</script>
|
||||
</parcel>
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
# *************************************************************
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# *************************************************************
|
||||
|
||||
|
||||
# helper function
|
||||
def getNewString( theString ) :
|
||||
if( not theString or len(theString) ==0) :
|
||||
return ""
|
||||
# should we tokenize on "."?
|
||||
if theString[0].isupper() and len(theString)>=2 and theString[1].isupper() :
|
||||
# first two chars are UC => first UC, rest LC
|
||||
newString=theString[0:1].upper() + theString[1:].lower();
|
||||
elif theString[0].isupper():
|
||||
# first char UC => all to LC
|
||||
newString=theString.lower()
|
||||
else: # all to UC.
|
||||
newString=theString.upper()
|
||||
return newString;
|
||||
|
||||
def capitalisePython( ):
|
||||
"""Change the case of a selection, or current word from upper case, to first char upper case, to all lower case to upper case..."""
|
||||
import string
|
||||
|
||||
# The context variable is of type XScriptContext and is available to
|
||||
# all BeanShell scripts executed by the Script Framework
|
||||
xModel = XSCRIPTCONTEXT.getDocument()
|
||||
|
||||
#the writer controller impl supports the css.view.XSelectionSupplier interface
|
||||
xSelectionSupplier = xModel.getCurrentController()
|
||||
|
||||
#see section 7.5.1 of developers' guide
|
||||
xIndexAccess = xSelectionSupplier.getSelection()
|
||||
count = xIndexAccess.getCount();
|
||||
if(count>=1): #ie we have a selection
|
||||
i=0
|
||||
while i < count :
|
||||
xTextRange = xIndexAccess.getByIndex(i);
|
||||
#print "string: " + xTextRange.getString();
|
||||
theString = xTextRange.getString();
|
||||
if len(theString)==0 :
|
||||
# sadly we can have a selection where nothing is selected
|
||||
# in this case we get the XWordCursor and make a selection!
|
||||
xText = xTextRange.getText();
|
||||
xWordCursor = xText.createTextCursorByRange(xTextRange);
|
||||
if not xWordCursor.isStartOfWord():
|
||||
xWordCursor.gotoStartOfWord(False);
|
||||
xWordCursor.gotoNextWord(True);
|
||||
theString = xWordCursor.getString();
|
||||
newString = getNewString(theString);
|
||||
if newString :
|
||||
xWordCursor.setString(newString);
|
||||
xSelectionSupplier.select(xWordCursor);
|
||||
else :
|
||||
|
||||
newString = getNewString( theString );
|
||||
if newString:
|
||||
xTextRange.setString(newString);
|
||||
xSelectionSupplier.select(xTextRange);
|
||||
i+= 1
|
||||
|
||||
|
||||
# lists the scripts, that shall be visible inside OOo. Can be omited, if
|
||||
# all functions shall be visible, however here getNewString shall be surpressed
|
||||
g_exportedScripts = capitalisePython,
|
||||
@@ -0,0 +1,34 @@
|
||||
# *************************************************************
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# *************************************************************
|
||||
|
||||
# HelloWorld python script for the scripting framework
|
||||
|
||||
def HelloWorldPython( ):
|
||||
"""Prints the string 'Hello World(in Python)' into the current document"""
|
||||
#get the doc from the scripting context which is made available to all scripts
|
||||
model = XSCRIPTCONTEXT.getDocument()
|
||||
#get the XText interface
|
||||
text = model.Text
|
||||
#create an XTextRange at the end of the document
|
||||
tRange = text.End
|
||||
#and set the string
|
||||
tRange.String = "Hello World (in Python)"
|
||||
return None
|
||||
@@ -0,0 +1,117 @@
|
||||
# *************************************************************
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# *************************************************************
|
||||
|
||||
import uno
|
||||
|
||||
# a UNO struct later needed to create a document
|
||||
from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
|
||||
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
|
||||
from com.sun.star.awt import Size
|
||||
|
||||
from com.sun.star.lang import XMain
|
||||
|
||||
def insertTextIntoCell( table, cellName, text, color ):
|
||||
tableText = table.getCellByName( cellName )
|
||||
cursor = tableText.createTextCursor()
|
||||
cursor.setPropertyValue( "CharColor", color )
|
||||
tableText.setString( text )
|
||||
|
||||
|
||||
def createTable():
|
||||
"""creates a new writer document and inserts a table with some data (also known as the SWriter sample)"""
|
||||
ctx = uno.getComponentContext()
|
||||
smgr = ctx.ServiceManager
|
||||
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",ctx)
|
||||
|
||||
# open a writer document
|
||||
doc = desktop.loadComponentFromURL( "private:factory/swriter","_blank", 0, () )
|
||||
|
||||
text = doc.Text
|
||||
cursor = text.createTextCursor()
|
||||
text.insertString( cursor, "The first line in the newly created text document.\n", 0 )
|
||||
text.insertString( cursor, "Now we are in the second line\n" , 0 )
|
||||
|
||||
# create a text table
|
||||
table = doc.createInstance( "com.sun.star.text.TextTable" )
|
||||
|
||||
# with 4 rows and 4 columns
|
||||
table.initialize( 4,4)
|
||||
|
||||
text.insertTextContent( cursor, table, 0 )
|
||||
rows = table.Rows
|
||||
|
||||
table.setPropertyValue( "BackTransparent", uno.Bool(0) )
|
||||
table.setPropertyValue( "BackColor", 13421823 )
|
||||
row = rows.getByIndex(0)
|
||||
row.setPropertyValue( "BackTransparent", uno.Bool(0) )
|
||||
row.setPropertyValue( "BackColor", 6710932 )
|
||||
|
||||
textColor = 16777215
|
||||
|
||||
insertTextIntoCell( table, "A1", "FirstColumn", textColor )
|
||||
insertTextIntoCell( table, "B1", "SecondColumn", textColor )
|
||||
insertTextIntoCell( table, "C1", "ThirdColumn", textColor )
|
||||
insertTextIntoCell( table, "D1", "SUM", textColor )
|
||||
|
||||
values = ( (22.5,21.5,121.5),
|
||||
(5615.3,615.3,-615.3),
|
||||
(-2315.7,315.7,415.7) )
|
||||
table.getCellByName("A2").setValue(22.5)
|
||||
table.getCellByName("B2").setValue(5615.3)
|
||||
table.getCellByName("C2").setValue(-2315.7)
|
||||
table.getCellByName("D2").setFormula("sum <A2:C2>")
|
||||
|
||||
table.getCellByName("A3").setValue(21.5)
|
||||
table.getCellByName("B3").setValue(615.3)
|
||||
table.getCellByName("C3").setValue(-315.7)
|
||||
table.getCellByName("D3").setFormula("sum <A3:C3>")
|
||||
|
||||
table.getCellByName("A4").setValue(121.5)
|
||||
table.getCellByName("B4").setValue(-615.3)
|
||||
table.getCellByName("C4").setValue(415.7)
|
||||
table.getCellByName("D4").setFormula("sum <A4:C4>")
|
||||
|
||||
|
||||
cursor.setPropertyValue( "CharColor", 255 )
|
||||
cursor.setPropertyValue( "CharShadowed", uno.Bool(1) )
|
||||
|
||||
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
||||
text.insertString( cursor, " This is a colored Text - blue with shadow\n" , 0 )
|
||||
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
||||
|
||||
textFrame = doc.createInstance( "com.sun.star.text.TextFrame" )
|
||||
textFrame.setSize( Size(15000,400))
|
||||
textFrame.setPropertyValue( "AnchorType" , AS_CHARACTER )
|
||||
|
||||
text.insertTextContent( cursor, textFrame, 0 )
|
||||
|
||||
textInTextFrame = textFrame.getText()
|
||||
cursorInTextFrame = textInTextFrame.createTextCursor()
|
||||
textInTextFrame.insertString( cursorInTextFrame, "The first line in the newly created text frame.", 0 )
|
||||
textInTextFrame.insertString( cursorInTextFrame, "\nWith this second line the height of the rame raises.",0)
|
||||
text.insertControlCharacter( cursor, PARAGRAPH_BREAK, 0 )
|
||||
|
||||
cursor.setPropertyValue( "CharColor", 65536 )
|
||||
cursor.setPropertyValue( "CharShadowed", uno.Bool(0) )
|
||||
|
||||
text.insertString( cursor, " That's all for now !!" , 0 )
|
||||
|
||||
g_exportedScripts = createTable,
|
||||
Reference in New Issue
Block a user