summaryrefslogtreecommitdiffstats
path: root/odk/examples/DevelopersGuide/FirstSteps
diff options
context:
space:
mode:
Diffstat (limited to 'odk/examples/DevelopersGuide/FirstSteps')
-rw-r--r--odk/examples/DevelopersGuide/FirstSteps/FirstConnection.java61
-rw-r--r--odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java162
-rw-r--r--odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact.java61
-rw-r--r--odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java439
-rw-r--r--odk/examples/DevelopersGuide/FirstSteps/Makefile100
-rw-r--r--odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml81
6 files changed, 904 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstConnection.java b/odk/examples/DevelopersGuide/FirstSteps/FirstConnection.java
new file mode 100644
index 000000000..9506b0070
--- /dev/null
+++ b/odk/examples/DevelopersGuide/FirstSteps/FirstConnection.java
@@ -0,0 +1,61 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+public class FirstConnection {
+
+ public static void main(String[] args) {
+ try {
+ // get the remote office component context
+ com.sun.star.uno.XComponentContext xContext =
+ com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ System.out.println("Connected to a running office ...");
+
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ String available = (null != xMCF ? "available" : "not available");
+ System.out.println( "remote ServiceManager is " + available );
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java
new file mode 100644
index 000000000..70e531df3
--- /dev/null
+++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java
@@ -0,0 +1,162 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.comp.helper.Bootstrap;
+import com.sun.star.container.XEnumeration;
+import com.sun.star.container.XEnumerationAccess;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XModel;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.sheet.XCellAddressable;
+import com.sun.star.sheet.XCellRangesQuery;
+import com.sun.star.sheet.XSheetCellRanges;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.sheet.XSpreadsheetView;
+import com.sun.star.sheet.XSpreadsheets;
+import com.sun.star.table.XCell;
+import com.sun.star.uno.UnoRuntime;
+
+public class FirstLoadComponent {
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ try {
+ // get the remote office component context
+ XComponentContext xRemoteContext = Bootstrap.bootstrap();
+ if (xRemoteContext == null) {
+ System.err.println("ERROR: Could not bootstrap default Office.");
+ }
+
+ XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager();
+
+ Object desktop = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xRemoteContext);
+ XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop);
+
+ PropertyValue[] loadProps = new PropertyValue[0];
+ XComponent xSpreadsheetComponent = xComponentLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, loadProps);
+
+ XSpreadsheetDocument xSpreadsheetDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class,
+ xSpreadsheetComponent);
+
+ XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
+ xSpreadsheets.insertNewByName("MySheet", (short)0);
+ com.sun.star.uno.Type elemType = xSpreadsheets.getElementType();
+
+ System.out.println(elemType.getTypeName());
+ Object sheet = xSpreadsheets.getByName("MySheet");
+ XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface(
+ XSpreadsheet.class, sheet);
+
+ XCell xCell = xSpreadsheet.getCellByPosition(0, 0);
+ xCell.setValue(21);
+ xCell = xSpreadsheet.getCellByPosition(0, 1);
+ xCell.setValue(21);
+ xCell = xSpreadsheet.getCellByPosition(0, 2);
+ xCell.setFormula("=sum(A1:A2)");
+
+ XPropertySet xCellProps = UnoRuntime.queryInterface(
+ XPropertySet.class, xCell);
+ xCellProps.setPropertyValue("CellStyle", "Result");
+
+ XModel xSpreadsheetModel = UnoRuntime.queryInterface(
+ XModel.class, xSpreadsheetComponent);
+ XController xSpreadsheetController = xSpreadsheetModel.getCurrentController();
+ XSpreadsheetView xSpreadsheetView = UnoRuntime.queryInterface(XSpreadsheetView.class,
+ xSpreadsheetController);
+ xSpreadsheetView.setActiveSheet(xSpreadsheet);
+
+ // *********************************************************
+ // example for use of enum types
+ xCellProps.setPropertyValue("VertJustify",
+ com.sun.star.table.CellVertJustify.TOP);
+
+
+ // *********************************************************
+ // example for a sequence of PropertyValue structs
+ // create an array with one PropertyValue struct, it contains
+ // references only
+ loadProps = new PropertyValue[1];
+
+ // instantiate PropertyValue struct and set its member fields
+ PropertyValue asTemplate = new PropertyValue();
+ asTemplate.Name = "AsTemplate";
+ asTemplate.Value = Boolean.TRUE;
+
+ // assign PropertyValue struct to array of references for PropertyValue
+ // structs
+ loadProps[0] = asTemplate;
+
+ // load calc file as template
+ //xSpreadsheetComponent = xComponentLoader.loadComponentFromURL(
+ // "file:///c:/temp/DataAnalysys.ods", "_blank", 0, loadProps);
+
+ // *********************************************************
+ // example for use of XEnumerationAccess
+ XCellRangesQuery xCellQuery = UnoRuntime.queryInterface(XCellRangesQuery.class, sheet);
+ XSheetCellRanges xFormulaCells = xCellQuery.queryContentCells(
+ (short)com.sun.star.sheet.CellFlags.FORMULA);
+ XEnumerationAccess xFormulas = xFormulaCells.getCells();
+ XEnumeration xFormulaEnum = xFormulas.createEnumeration();
+
+ while (xFormulaEnum.hasMoreElements()) {
+ Object formulaCell = xFormulaEnum.nextElement();
+ xCell = UnoRuntime.queryInterface(XCell.class, formulaCell);
+ XCellAddressable xCellAddress = UnoRuntime.queryInterface(XCellAddressable.class, xCell);
+ System.out.println("Formula cell in column " +
+ xCellAddress.getCellAddress().Column
+ + ", row " + xCellAddress.getCellAddress().Row
+ + " contains " + xCell.getFormula());
+ }
+
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit( 0 );
+ }
+ }
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact.java b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact.java
new file mode 100644
index 000000000..9f4de1a6e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/FirstSteps/FirstUnoContact.java
@@ -0,0 +1,61 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+public class FirstUnoContact {
+
+ public static void main(String[] args) {
+ try {
+ // get the remote office component context
+ com.sun.star.uno.XComponentContext xContext =
+ com.sun.star.comp.helper.Bootstrap.bootstrap();
+
+ System.out.println("Connected to a running office ...");
+
+ com.sun.star.lang.XMultiComponentFactory xMCF =
+ xContext.getServiceManager();
+
+ String available = (xMCF != null ? "available" : "not available");
+ System.out.println( "remote ServiceManager is " + available );
+ }
+ catch (java.lang.Exception e){
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java
new file mode 100644
index 000000000..2dd4e9c0e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java
@@ -0,0 +1,439 @@
+/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * The Contents of this file are made available subject to the terms of
+ * the BSD license.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *************************************************************************/
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.uno.XComponentContext;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.lang.XMultiComponentFactory;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceInfo;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.text.XText;
+import com.sun.star.text.XTextCursor;
+import com.sun.star.text.XTextContent;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XCell;
+import com.sun.star.table.TableBorder;
+import com.sun.star.table.BorderLine;
+import com.sun.star.drawing.XShape;
+import com.sun.star.awt.Size;
+import com.sun.star.awt.Point;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.container.XIndexAccess;
+import com.sun.star.drawing.XDrawPagesSupplier;
+import com.sun.star.drawing.XDrawPageSupplier;
+import com.sun.star.drawing.XDrawPage;
+
+public class HelloTextTableShape {
+
+ private XComponentContext xRemoteContext = null;
+ private XMultiComponentFactory xRemoteServiceManager = null;
+
+ /**
+ * @param args the command line arguments
+ */
+ public static void main(String[] args) {
+ HelloTextTableShape helloTextTableShape1 = new HelloTextTableShape();
+ try {
+ helloTextTableShape1.useDocuments();
+ }
+ catch (java.lang.Exception e){
+ System.err.println(e.getMessage());
+ e.printStackTrace();
+ }
+ finally {
+ System.exit(0);
+ }
+
+ }
+
+ protected void useDocuments() throws java.lang.Exception {
+ useWriter();
+ useCalc();
+ useDraw();
+ }
+
+ protected void useWriter() throws java.lang.Exception {
+ try {
+ // create new writer document and get text, then manipulate text
+ XComponent xWriterComponent = newDocComponent("swriter");
+ XTextDocument xTextDocument = UnoRuntime.queryInterface(
+ XTextDocument.class, xWriterComponent);
+ XText xText = xTextDocument.getText();
+
+ manipulateText(xText);
+
+ // get internal service factory of the document
+ XMultiServiceFactory xWriterFactory = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, xWriterComponent);
+
+ // insert TextTable and get cell text, then manipulate text in cell
+ Object table = xWriterFactory.createInstance("com.sun.star.text.TextTable");
+ XTextContent xTextContentTable = UnoRuntime.queryInterface(
+ XTextContent.class, table);
+
+ xText.insertTextContent(xText.getEnd(), xTextContentTable, false);
+
+ XCellRange xCellRange = UnoRuntime.queryInterface(
+ XCellRange.class, table);
+ XCell xCell = xCellRange.getCellByPosition(0, 1);
+ XText xCellText = UnoRuntime.queryInterface(XText.class, xCell);
+
+ manipulateText(xCellText);
+ manipulateTable(xCellRange);
+
+ // insert RectangleShape and get shape text, then manipulate text
+ Object writerShape = xWriterFactory.createInstance(
+ "com.sun.star.drawing.RectangleShape");
+ XShape xWriterShape = UnoRuntime.queryInterface(
+ XShape.class, writerShape);
+ xWriterShape.setSize(new Size(10000, 10000));
+ XTextContent xTextContentShape = UnoRuntime.queryInterface(
+ XTextContent.class, writerShape);
+
+ xText.insertTextContent(xText.getEnd(), xTextContentShape, false);
+
+ XPropertySet xShapeProps = UnoRuntime.queryInterface(
+ XPropertySet.class, writerShape);
+ // wrap text inside shape
+ xShapeProps.setPropertyValue("TextContourFrame", Boolean.TRUE);
+
+
+ XText xShapeText = UnoRuntime.queryInterface(XText.class, writerShape);
+
+ manipulateText(xShapeText);
+ manipulateShape(xWriterShape);
+
+/* more code snippets used in the manual:
+
+ Object bookmark = xWriterFactory.createInstance ( "com.sun.star.text.Bookmark" );
+ // name the bookmark
+ XNamed xNamed = (XNamed) UnoRuntime.queryInterface (
+ XNamed.class, bookmark );
+ xNamed.setName("MyUniqueBookmarkName");
+
+ // get XTextContent interface and insert it at the end of the document
+ XTextContent xTextContent = (XTextContent) UnoRuntime.queryInterface (
+ XTextContent.class, bookmark );
+ //mxDocText.insertTextContent ( mxDocText.getEnd(), xTextContent, false );
+ xText.insertTextContent ( xText.getEnd(), xTextContent, false );
+
+ //query BookmarksSupplier
+ XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)UnoRuntime.queryInterface(
+ XBookmarksSupplier.class, xWriterComponent);
+ XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks();
+ Object foundBookmark = xNamedBookmarks.getByName("MyUniqueBookmarkName");
+ XTextContent xFoundBookmark = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, foundBookmark);
+ XTextRange xFound = xFoundBookmark.getAnchor();
+ xFound.setString(" The throat mike, glued to her neck, "
+ + "looked as much as possible like an analgesic dermadisk.");
+
+
+
+
+ // first query the XTextTablesSupplier interface from our document
+ XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface(
+ XTextTablesSupplier.class, xWriterComponent);
+ // get the tables collection
+ XNameAccess xNamedTables = xTablesSupplier.getTextTables();
+
+ // now query the XIndexAccess from the tables collection
+ XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface(
+ XIndexAccess.class, xNamedTables);
+
+ // we need properties
+ XPropertySet xTableProps = null;
+
+ // get the tables
+ for (int i = 0; i < xIndexedTables.getCount(); i++) {
+ //Object table = xIndexedTables.getByIndex(i);
+ table = xIndexedTables.getByIndex(i);
+ xTableProps = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, table);
+ xTableProps.setPropertyValue("BackColor", Integer.valueOf(0xC8FFB9));
+ }
+ */
+ }
+ catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1
+ xRemoteContext = null;
+ throw e;
+ }
+
+ }
+
+ protected void useCalc() throws java.lang.Exception {
+ try {
+ // create new calc document and manipulate cell text
+ XComponent xCalcComponent = newDocComponent("scalc");
+ XSpreadsheetDocument xSpreadsheetDocument =
+ UnoRuntime.queryInterface(
+ XSpreadsheetDocument .class, xCalcComponent);
+ Object sheets = xSpreadsheetDocument.getSheets();
+ XIndexAccess xIndexedSheets = UnoRuntime.queryInterface(
+ XIndexAccess.class, sheets);
+ Object sheet = xIndexedSheets.getByIndex(0);
+
+ //get cell A2 in first sheet
+ XCellRange xSpreadsheetCells = UnoRuntime.queryInterface(
+ XCellRange.class, sheet);
+ XCell xCell = xSpreadsheetCells.getCellByPosition(0,1);
+ XPropertySet xCellProps = UnoRuntime.queryInterface(
+ XPropertySet.class, xCell);
+ xCellProps.setPropertyValue("IsTextWrapped", Boolean.TRUE);
+
+ XText xCellText = UnoRuntime.queryInterface(XText.class, xCell);
+
+ manipulateText(xCellText);
+ manipulateTable(xSpreadsheetCells);
+
+ // get internal service factory of the document
+ XMultiServiceFactory xCalcFactory = UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, xCalcComponent);
+ // get Drawpage
+ XDrawPageSupplier xDrawPageSupplier = UnoRuntime.queryInterface(XDrawPageSupplier.class, sheet);
+ XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage();
+
+ // create and insert RectangleShape and get shape text, then manipulate text
+ Object calcShape = xCalcFactory.createInstance(
+ "com.sun.star.drawing.RectangleShape");
+ XShape xCalcShape = UnoRuntime.queryInterface(
+ XShape.class, calcShape);
+ xCalcShape.setSize(new Size(10000, 10000));
+ xCalcShape.setPosition(new Point(7000, 3000));
+
+ xDrawPage.add(xCalcShape);
+
+ XPropertySet xShapeProps = UnoRuntime.queryInterface(
+ XPropertySet.class, calcShape);
+ // wrap text inside shape
+ xShapeProps.setPropertyValue("TextContourFrame", Boolean.TRUE);
+
+
+ XText xShapeText = UnoRuntime.queryInterface(XText.class, calcShape);
+
+ manipulateText(xShapeText);
+ manipulateShape(xCalcShape);
+
+ }
+ catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1
+ xRemoteContext = null;
+ throw e;
+ }
+
+ }
+
+ protected void useDraw() throws java.lang.Exception {
+ try {
+ //create new draw document and insert ractangle shape
+ XComponent xDrawComponent = newDocComponent("sdraw");
+ XDrawPagesSupplier xDrawPagesSupplier =
+ UnoRuntime.queryInterface(
+ XDrawPagesSupplier.class, xDrawComponent);
+
+ Object drawPages = xDrawPagesSupplier.getDrawPages();
+ XIndexAccess xIndexedDrawPages = UnoRuntime.queryInterface(
+ XIndexAccess.class, drawPages);
+ Object drawPage = xIndexedDrawPages.getByIndex(0);
+ XDrawPage xDrawPage = UnoRuntime.queryInterface(XDrawPage.class, drawPage);
+
+ // get internal service factory of the document
+ XMultiServiceFactory xDrawFactory =
+ UnoRuntime.queryInterface(
+ XMultiServiceFactory.class, xDrawComponent);
+
+ Object drawShape = xDrawFactory.createInstance(
+ "com.sun.star.drawing.RectangleShape");
+ XShape xDrawShape = UnoRuntime.queryInterface(XShape.class, drawShape);
+ xDrawShape.setSize(new Size(10000, 20000));
+ xDrawShape.setPosition(new Point(5000, 5000));
+ xDrawPage.add(xDrawShape);
+
+ XText xShapeText = UnoRuntime.queryInterface(XText.class, drawShape);
+ XPropertySet xShapeProps = UnoRuntime.queryInterface(
+ XPropertySet.class, drawShape);
+
+ // wrap text inside shape
+ xShapeProps.setPropertyValue("TextContourFrame", Boolean.TRUE);
+
+ manipulateText(xShapeText);
+ manipulateShape(xDrawShape);
+ }
+ catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1
+ xRemoteContext = null;
+ throw e;
+ }
+
+
+ }
+
+ protected void manipulateText(XText xText) throws com.sun.star.uno.Exception {
+ // simply set whole text as one string
+ xText.setString("He lay flat on the brown, pine-needled floor of the forest, "
+ + "his chin on his folded arms, and high overhead the wind blew in the tops "
+ + "of the pine trees.");
+
+ // create text cursor for selecting and formatting
+ XTextCursor xTextCursor = xText.createTextCursor();
+ XPropertySet xCursorProps = UnoRuntime.queryInterface(
+ XPropertySet.class, xTextCursor);
+
+ // use cursor to select "He lay" and apply bold italic
+ xTextCursor.gotoStart(false);
+ xTextCursor.goRight((short)6, true);
+ // from CharacterProperties
+ xCursorProps.setPropertyValue("CharPosture",
+ com.sun.star.awt.FontSlant.ITALIC);
+ xCursorProps.setPropertyValue("CharWeight",
+ new Float(com.sun.star.awt.FontWeight.BOLD));
+
+ // add more text at the end of the text using insertString
+ xTextCursor.gotoEnd(false);
+ xText.insertString(xTextCursor, " The mountainside sloped gently where he lay; "
+ + "but below it was steep and he could see the dark of the oiled road "
+ + "winding through the pass. There was a stream alongside the road "
+ + "and far down the pass he saw a mill beside the stream and the falling water "
+ + "of the dam, white in the summer sunlight.", false);
+ // after insertString the cursor is behind the inserted text, insert more text
+ xText.insertString(xTextCursor, "\n \"Is that the mill?\" he asked.", false);
+ }
+
+ protected void manipulateTable(XCellRange xCellRange) throws com.sun.star.uno.Exception {
+
+ String backColorPropertyName = "";
+ XPropertySet xTableProps = null;
+
+ // enter column titles and a cell value
+ XCell xCell = xCellRange.getCellByPosition(0,0);
+ XText xCellText = UnoRuntime.queryInterface(XText.class, xCell);
+ xCellText.setString("Quotation");
+ xCell = xCellRange.getCellByPosition(1,0);
+ xCellText = UnoRuntime.queryInterface(XText.class, xCell);
+ xCellText.setString("Year");
+ xCell = xCellRange.getCellByPosition(1,1);
+ xCell.setValue(1940);
+ XCellRange xSelectedCells = xCellRange.getCellRangeByName("A1:B1");
+ XPropertySet xCellProps = UnoRuntime.queryInterface(
+ XPropertySet.class, xSelectedCells);
+
+ // format table headers and table borders
+ // we need to distinguish text and sheet tables:
+ // property name for cell colors is different in text and sheet cells
+ // we want to apply TableBorder to whole text table, but only to sheet cells with content
+ XServiceInfo xServiceInfo = UnoRuntime.queryInterface(
+ XServiceInfo.class, xCellRange);
+ if (xServiceInfo.supportsService("com.sun.star.sheet.Spreadsheet")) {
+ backColorPropertyName = "CellBackColor";
+ xSelectedCells = xCellRange.getCellRangeByName("A1:B2");
+ xTableProps = UnoRuntime.queryInterface(
+ XPropertySet.class, xSelectedCells);
+ }
+ else if (xServiceInfo.supportsService("com.sun.star.text.TextTable")) {
+ backColorPropertyName = "BackColor";
+ xTableProps = UnoRuntime.queryInterface(
+ XPropertySet.class, xCellRange);
+ }
+ // set cell background color
+ xCellProps.setPropertyValue(backColorPropertyName, Integer.valueOf(0x99CCFF));
+
+ // set table borders
+ // create description for blue line, width 10
+ BorderLine theLine = new BorderLine();
+ theLine.Color = 0x000099;
+ theLine.OuterLineWidth = 10;
+ // apply line description to all border lines and make them valid
+ TableBorder bord = new TableBorder();
+ bord.VerticalLine = bord.HorizontalLine =
+ bord.LeftLine = bord.RightLine =
+ bord.TopLine = bord.BottomLine =
+ theLine;
+ bord.IsVerticalLineValid = bord.IsHorizontalLineValid =
+ bord.IsLeftLineValid = bord.IsRightLineValid =
+ bord.IsTopLineValid = bord.IsBottomLineValid =
+ true;
+
+ xTableProps.setPropertyValue("TableBorder", bord);
+
+ bord = (TableBorder)xTableProps.getPropertyValue("TableBorder");
+ theLine = bord.TopLine;
+ int col = theLine.Color;
+ System.out.println(col);
+ }
+
+ protected void manipulateShape(XShape xShape) throws com.sun.star.uno.Exception {
+ XPropertySet xShapeProps = UnoRuntime.queryInterface(XPropertySet.class, xShape);
+ xShapeProps.setPropertyValue("FillColor", Integer.valueOf(0x99CCFF));
+ xShapeProps.setPropertyValue("LineColor", Integer.valueOf(0x000099));
+ xShapeProps.setPropertyValue("RotateAngle", Integer.valueOf(3000));
+
+ xShapeProps.setPropertyValue("TextLeftDistance", Integer.valueOf(0));
+ xShapeProps.setPropertyValue("TextRightDistance", Integer.valueOf(0));
+ xShapeProps.setPropertyValue("TextUpperDistance", Integer.valueOf(0));
+ xShapeProps.setPropertyValue("TextLowerDistance", Integer.valueOf(0));
+ }
+
+
+ protected XComponent newDocComponent(String docType) throws java.lang.Exception {
+ String loadUrl = "private:factory/" + docType;
+ xRemoteServiceManager = this.getRemoteServiceManager();
+ Object desktop = xRemoteServiceManager.createInstanceWithContext(
+ "com.sun.star.frame.Desktop", xRemoteContext);
+ XComponentLoader xComponentLoader = UnoRuntime.queryInterface(
+ XComponentLoader.class, desktop);
+ PropertyValue[] loadProps = new PropertyValue[0];
+ return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps);
+ }
+
+ protected XMultiComponentFactory getRemoteServiceManager() throws java.lang.Exception {
+ if (xRemoteContext == null && xRemoteServiceManager == null) {
+ try {
+ // First step: get the remote office component context
+ xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
+ System.out.println("Connected to a running office ...");
+
+ xRemoteServiceManager = xRemoteContext.getServiceManager();
+ }
+ catch( Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+ return xRemoteServiceManager;
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/odk/examples/DevelopersGuide/FirstSteps/Makefile b/odk/examples/DevelopersGuide/FirstSteps/Makefile
new file mode 100644
index 000000000..53077d093
--- /dev/null
+++ b/odk/examples/DevelopersGuide/FirstSteps/Makefile
@@ -0,0 +1,100 @@
+#*************************************************************************
+#
+# The Contents of this file are made available subject to the terms of
+# the BSD license.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+# 3. Neither the name of Sun Microsystems, Inc. nor the names of its
+# contributors may be used to endorse or promote products derived
+# from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+#**************************************************************************
+
+# Builds the FirstSteps examples of the Developers Guide.
+
+PRJ=../../..
+SETTINGS=$(PRJ)/settings
+
+include $(SETTINGS)/settings.mk
+include $(SETTINGS)/std.mk
+
+# Define non-platform/compiler specific settings
+EXAMPLE_NAME=FirstStepsExamples
+OUT_APP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
+
+APP1_NAME=FirstUnoContact
+APP1_JAR=$(OUT_APP_CLASS)/$(APP1_NAME).jar
+APP2_NAME=FirstLoadComponent
+APP2_JAR=$(OUT_APP_CLASS)/$(APP2_NAME).jar
+APP3_NAME=HelloTextTableShape
+APP3_JAR=$(OUT_APP_CLASS)/$(APP3_NAME).jar
+
+SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
+ $(PATH_SEPARATOR)$(OUT_APP_CLASS))
+
+
+# Targets
+.PHONY: ALL
+ALL : \
+ $(EXAMPLE_NAME)
+
+include $(SETTINGS)/stdtarget.mk
+
+$(OUT_APP_CLASS)/%.class : %.java
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_APP_CLASS) $<
+
+$(OUT_APP_CLASS)/%.mf :
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ @echo Main-Class: com.sun.star.lib.loader.Loader> $@
+ $(ECHOLINE)>> $@
+ @echo Name: com/sun/star/lib/loader/Loader.class>> $@
+ @echo Application-Class: $*>> $@
+
+$(OUT_APP_CLASS)/%.jar : $(OUT_APP_CLASS)/%.mf $(OUT_APP_CLASS)/%.class
+ -$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
+ -$(MKDIR) $(subst /,$(PS),$(@D))
+ +cd $(subst /,$(PS),$(OUT_APP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
+ +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
+
+$(APP1_JAR) : $(OUT_APP_CLASS)/$(APP1_NAME).mf $(OUT_APP_CLASS)/$(APP1_NAME).class
+$(APP2_JAR) : $(OUT_APP_CLASS)/$(APP2_NAME).mf $(OUT_APP_CLASS)/$(APP2_NAME).class
+$(APP3_JAR) : $(OUT_APP_CLASS)/$(APP3_NAME).mf $(OUT_APP_CLASS)/$(APP3_NAME).class
+
+$(EXAMPLE_NAME) : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR)
+ @echo --------------------------------------------------------------------------------
+ @echo Please use one of the following commands to execute the examples!
+ @echo -
+ @echo $(MAKE) $(APP1_NAME).run
+ @echo $(MAKE) $(APP2_NAME).run
+ @echo $(MAKE) $(APP3_NAME).run
+ @echo --------------------------------------------------------------------------------
+
+%.run: $(OUT_APP_CLASS)/%.jar
+ $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
+
+.PHONY: clean
+clean :
+ -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_APP_CLASS))
diff --git a/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml b/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml
new file mode 100644
index 000000000..4dec9aa7e
--- /dev/null
+++ b/odk/examples/DevelopersGuide/FirstSteps/build_FirstUnoContact.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+-->
+<project basedir="." default="all" name="FirstUnoContact">
+
+ <property environment="env"/>
+ <property name="OFFICE_HOME" value="${env.OFFICE_HOME}"/>
+ <property name="OO_SDK_HOME" value="${env.OO_SDK_HOME}"/>
+
+ <target name="init">
+ <property name="OUTDIR" value="${OO_SDK_HOME}/WINExample.out/class/FirstUnoContact"/>
+ </target>
+
+ <path id="office.class.path">
+ <filelist dir="${OFFICE_HOME}/program/classes"
+ files="libreoffice.jar"/>
+ </path>
+
+ <fileset id="bootstrap.glue.code" dir="${OO_SDK_HOME}/classes">
+ <patternset>
+ <include name="com/sun/star/lib/loader/*.class"/>
+ <include name="win/unowinreg.dll"/>
+ </patternset>
+ </fileset>
+
+ <target name="compile" depends="init">
+ <mkdir dir="${OUTDIR}"/>
+ <javac debug="true" deprecation="true" destdir="${OUTDIR}" srcdir=".">
+ <classpath refid="office.class.path"/>
+ </javac>
+ </target>
+
+ <target name="jar" depends="init,compile">
+ <jar basedir="${OUTDIR}" compress="true"
+ jarfile="${OUTDIR}/FirstUnoContact.jar">
+ <exclude name="**/*.java"/>
+ <exclude name="*.jar"/>
+ <fileset refid="bootstrap.glue.code"/>
+ <manifest>
+ <attribute name="Main-Class" value="com.sun.star.lib.loader.Loader"/>
+ <section name="com/sun/star/lib/loader/Loader.class">
+ <attribute name="Application-Class" value="FirstUnoContact"/>
+ </section>
+ </manifest>
+ </jar>
+ </target>
+
+ <target name="all" description="Build everything." depends="init,compile,jar">
+ <echo message="Application built. FirstUnoContact!"/>
+ </target>
+
+ <target name="run" description="Try running it." depends="init,all">
+ <java jar="${OUTDIR}/FirstUnoContact.jar" failonerror="true" fork="true">
+ </java>
+ </target>
+
+ <target name="clean" description="Clean all build products." depends="init">
+ <delete>
+ <fileset dir="${OUTDIR}">
+ <include name="**/*.class"/>
+ </fileset>
+ </delete>
+ <delete file="${OUTDIR}/FirstUnoContact.jar"/>
+ </target>
+
+</project>