134dd1e25SAndrew Rist /************************************************************** 2*ffea6052Smseidel * 334dd1e25SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 434dd1e25SAndrew Rist * or more contributor license agreements. See the NOTICE file 534dd1e25SAndrew Rist * distributed with this work for additional information 634dd1e25SAndrew Rist * regarding copyright ownership. The ASF licenses this file 734dd1e25SAndrew Rist * to you under the Apache License, Version 2.0 (the 834dd1e25SAndrew Rist * "License"); you may not use this file except in compliance 934dd1e25SAndrew Rist * with the License. You may obtain a copy of the License at 10*ffea6052Smseidel * 1134dd1e25SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ffea6052Smseidel * 1334dd1e25SAndrew Rist * Unless required by applicable law or agreed to in writing, 1434dd1e25SAndrew Rist * software distributed under the License is distributed on an 1534dd1e25SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1634dd1e25SAndrew Rist * KIND, either express or implied. See the License for the 1734dd1e25SAndrew Rist * specific language governing permissions and limitations 1834dd1e25SAndrew Rist * under the License. 19*ffea6052Smseidel * 2034dd1e25SAndrew Rist *************************************************************/ 2134dd1e25SAndrew Rist 2234dd1e25SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir import com.sun.star.lang.XComponent; 25cdf0e10cSrcweir import com.sun.star.uno.XComponentContext; 26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 27cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 28cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver; 29cdf0e10cSrcweir import com.sun.star.frame.XComponentLoader; 30cdf0e10cSrcweir import com.sun.star.lang.XMultiComponentFactory; 31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 32cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 34cdf0e10cSrcweir import com.sun.star.beans.XPropertySetInfo; 35cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 36cdf0e10cSrcweir import com.sun.star.beans.UnknownPropertyException; 37cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException; 38cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 39cdf0e10cSrcweir import com.sun.star.text.XText; 40cdf0e10cSrcweir import com.sun.star.text.XTextCursor; 41cdf0e10cSrcweir import com.sun.star.text.XWordCursor; 42cdf0e10cSrcweir import com.sun.star.text.XTextContent; 43cdf0e10cSrcweir import com.sun.star.text.XTextTable; 44cdf0e10cSrcweir import com.sun.star.text.XTextTableCursor; 45cdf0e10cSrcweir import com.sun.star.table.XTableRows; 46cdf0e10cSrcweir import com.sun.star.table.XCellRange; 47cdf0e10cSrcweir import com.sun.star.table.XCell; 48cdf0e10cSrcweir import com.sun.star.table.XCellCursor; 49cdf0e10cSrcweir import com.sun.star.table.TableBorder; 50cdf0e10cSrcweir import com.sun.star.table.BorderLine; 51cdf0e10cSrcweir import com.sun.star.drawing.XShape; 52cdf0e10cSrcweir import com.sun.star.awt.Size; 53cdf0e10cSrcweir import com.sun.star.awt.Point; 54cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheetDocument; 55cdf0e10cSrcweir import com.sun.star.sheet.XSpreadsheet; 56cdf0e10cSrcweir import com.sun.star.sheet.XSheetCellCursor; 57cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 58cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier; 59cdf0e10cSrcweir import com.sun.star.drawing.XDrawPageSupplier; 60cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage; 61cdf0e10cSrcweir 62cdf0e10cSrcweir import com.sun.star.text.XTextTablesSupplier; 63cdf0e10cSrcweir import com.sun.star.container.XNameAccess; 64cdf0e10cSrcweir import com.sun.star.container.XNamed; 65cdf0e10cSrcweir import com.sun.star.text.XBookmarksSupplier; 66cdf0e10cSrcweir import com.sun.star.text.XTextRange; 67cdf0e10cSrcweir 68cdf0e10cSrcweir /** 69cdf0e10cSrcweir * 70*ffea6052Smseidel * @author dschulten 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir public class HelloTextTableShape { 73cdf0e10cSrcweir 74cdf0e10cSrcweir private XComponentContext xRemoteContext = null; 75cdf0e10cSrcweir private XMultiComponentFactory xRemoteServiceManager = null; 76cdf0e10cSrcweir 77cdf0e10cSrcweir /** Creates a new instance of HelloTextTableShape */ HelloTextTableShape()78cdf0e10cSrcweir public HelloTextTableShape() { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir /** 82cdf0e10cSrcweir * @param args the command line arguments 83cdf0e10cSrcweir */ main(String[] args)84cdf0e10cSrcweir public static void main(String[] args) { 85cdf0e10cSrcweir HelloTextTableShape helloTextTableShape1 = new HelloTextTableShape(); 86cdf0e10cSrcweir try { 87cdf0e10cSrcweir helloTextTableShape1.useDocuments(); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir catch (java.lang.Exception e){ 90cdf0e10cSrcweir System.err.println(e.getMessage()); 91cdf0e10cSrcweir e.printStackTrace(); 92cdf0e10cSrcweir } 93cdf0e10cSrcweir finally { 94cdf0e10cSrcweir System.exit(0); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir } 98cdf0e10cSrcweir useDocuments()99*ffea6052Smseidel protected void useDocuments() throws java.lang.Exception { 100cdf0e10cSrcweir useWriter(); 101cdf0e10cSrcweir useCalc(); 102cdf0e10cSrcweir useDraw(); 103cdf0e10cSrcweir } 104cdf0e10cSrcweir useWriter()105cdf0e10cSrcweir protected void useWriter() throws java.lang.Exception { 106cdf0e10cSrcweir try { 107cdf0e10cSrcweir // create new writer document and get text, then manipulate text 108cdf0e10cSrcweir XComponent xWriterComponent = newDocComponent("swriter"); 109cdf0e10cSrcweir XTextDocument xTextDocument = (XTextDocument)UnoRuntime.queryInterface( 110cdf0e10cSrcweir XTextDocument.class, xWriterComponent); 111cdf0e10cSrcweir XText xText = xTextDocument.getText(); 112cdf0e10cSrcweir 113cdf0e10cSrcweir manipulateText(xText); 114cdf0e10cSrcweir 115cdf0e10cSrcweir // get internal service factory of the document 116cdf0e10cSrcweir XMultiServiceFactory xWriterFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( 117cdf0e10cSrcweir XMultiServiceFactory.class, xWriterComponent); 118cdf0e10cSrcweir 119cdf0e10cSrcweir // insert TextTable and get cell text, then manipulate text in cell 120cdf0e10cSrcweir Object table = xWriterFactory.createInstance("com.sun.star.text.TextTable"); 121cdf0e10cSrcweir XTextContent xTextContentTable = (XTextContent)UnoRuntime.queryInterface( 122cdf0e10cSrcweir XTextContent.class, table); 123cdf0e10cSrcweir 124cdf0e10cSrcweir xText.insertTextContent(xText.getEnd(), xTextContentTable, false); 125cdf0e10cSrcweir 126cdf0e10cSrcweir XCellRange xCellRange = (XCellRange)UnoRuntime.queryInterface( 127cdf0e10cSrcweir XCellRange.class, table); 128cdf0e10cSrcweir XCell xCell = xCellRange.getCellByPosition(0, 1); 129cdf0e10cSrcweir XText xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); 130cdf0e10cSrcweir 131cdf0e10cSrcweir manipulateText(xCellText); 132cdf0e10cSrcweir manipulateTable(xCellRange); 133cdf0e10cSrcweir 134cdf0e10cSrcweir // insert RectangleShape and get shape text, then manipulate text 135cdf0e10cSrcweir Object writerShape = xWriterFactory.createInstance( 136cdf0e10cSrcweir "com.sun.star.drawing.RectangleShape"); 137cdf0e10cSrcweir XShape xWriterShape = (XShape)UnoRuntime.queryInterface( 138cdf0e10cSrcweir XShape.class, writerShape); 139cdf0e10cSrcweir xWriterShape.setSize(new Size(10000, 10000)); 140cdf0e10cSrcweir XTextContent xTextContentShape = (XTextContent)UnoRuntime.queryInterface( 141cdf0e10cSrcweir XTextContent.class, writerShape); 142cdf0e10cSrcweir 143cdf0e10cSrcweir xText.insertTextContent(xText.getEnd(), xTextContentShape, false); 144cdf0e10cSrcweir 145cdf0e10cSrcweir XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface( 146cdf0e10cSrcweir XPropertySet.class, writerShape); 147cdf0e10cSrcweir // wrap text inside shape 148cdf0e10cSrcweir xShapeProps.setPropertyValue("TextContourFrame", new Boolean(true)); 149cdf0e10cSrcweir 150cdf0e10cSrcweir 151cdf0e10cSrcweir XText xShapeText = (XText)UnoRuntime.queryInterface(XText.class, writerShape); 152cdf0e10cSrcweir 153cdf0e10cSrcweir manipulateText(xShapeText); 154cdf0e10cSrcweir manipulateShape(xWriterShape); 155cdf0e10cSrcweir 156cdf0e10cSrcweir /* more code snippets used in the manual: 157cdf0e10cSrcweir 158cdf0e10cSrcweir Object bookmark = xWriterFactory.createInstance ( "com.sun.star.text.Bookmark" ); 159cdf0e10cSrcweir // name the bookmark 160cdf0e10cSrcweir XNamed xNamed = (XNamed) UnoRuntime.queryInterface ( 161cdf0e10cSrcweir XNamed.class, bookmark ); 162cdf0e10cSrcweir xNamed.setName("MyUniqueBookmarkName"); 163cdf0e10cSrcweir 164cdf0e10cSrcweir // get XTextContent interface and insert it at the end of the document 165cdf0e10cSrcweir XTextContent xTextContent = (XTextContent) UnoRuntime.queryInterface ( 166cdf0e10cSrcweir XTextContent.class, bookmark ); 167cdf0e10cSrcweir //mxDocText.insertTextContent ( mxDocText.getEnd(), xTextContent, false ); 168cdf0e10cSrcweir xText.insertTextContent ( xText.getEnd(), xTextContent, false ); 169cdf0e10cSrcweir 170cdf0e10cSrcweir //query BookmarksSupplier 171cdf0e10cSrcweir XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier)UnoRuntime.queryInterface( 172cdf0e10cSrcweir XBookmarksSupplier.class, xWriterComponent); 173cdf0e10cSrcweir XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks(); 174cdf0e10cSrcweir Object foundBookmark = xNamedBookmarks.getByName("MyUniqueBookmarkName"); 175cdf0e10cSrcweir XTextContent xFoundBookmark = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, foundBookmark); 176cdf0e10cSrcweir XTextRange xFound = xFoundBookmark.getAnchor(); 177cdf0e10cSrcweir xFound.setString(" The throat mike, glued to her neck, " 178cdf0e10cSrcweir + "looked as much as possible like an analgesic dermadisk."); 179cdf0e10cSrcweir 180cdf0e10cSrcweir 181cdf0e10cSrcweir 182cdf0e10cSrcweir 183cdf0e10cSrcweir // first query the XTextTablesSupplier interface from our document 184cdf0e10cSrcweir XTextTablesSupplier xTablesSupplier = (XTextTablesSupplier) UnoRuntime.queryInterface( 185cdf0e10cSrcweir XTextTablesSupplier.class, xWriterComponent); 186cdf0e10cSrcweir // get the tables collection 187cdf0e10cSrcweir XNameAccess xNamedTables = xTablesSupplier.getTextTables(); 188cdf0e10cSrcweir 189cdf0e10cSrcweir // now query the XIndexAccess from the tables collection 190cdf0e10cSrcweir XIndexAccess xIndexedTables = (XIndexAccess) UnoRuntime.queryInterface( 191cdf0e10cSrcweir XIndexAccess.class, xNamedTables); 192cdf0e10cSrcweir 193cdf0e10cSrcweir // we need properties 194cdf0e10cSrcweir XPropertySet xTableProps = null; 195cdf0e10cSrcweir 196cdf0e10cSrcweir // get the tables 197cdf0e10cSrcweir for (int i = 0; i < xIndexedTables.getCount(); i++) { 198cdf0e10cSrcweir //Object table = xIndexedTables.getByIndex(i); 199cdf0e10cSrcweir table = xIndexedTables.getByIndex(i); 200cdf0e10cSrcweir xTableProps = (XPropertySet) UnoRuntime.queryInterface( 201cdf0e10cSrcweir XPropertySet.class, table); 202cdf0e10cSrcweir xTableProps.setPropertyValue("BackColor", new Integer(0xC8FFB9)); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir */ 205cdf0e10cSrcweir } 206cdf0e10cSrcweir catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1 207cdf0e10cSrcweir xRemoteContext = null; 208cdf0e10cSrcweir throw e; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir } 212cdf0e10cSrcweir useCalc()213cdf0e10cSrcweir protected void useCalc() throws java.lang.Exception { 214cdf0e10cSrcweir try { 215cdf0e10cSrcweir // create new calc document and manipulate cell text 216cdf0e10cSrcweir XComponent xCalcComponent = newDocComponent("scalc"); 217*ffea6052Smseidel XSpreadsheetDocument xSpreadsheetDocument = 218cdf0e10cSrcweir (XSpreadsheetDocument)UnoRuntime.queryInterface( 219cdf0e10cSrcweir XSpreadsheetDocument .class, xCalcComponent); 220cdf0e10cSrcweir Object sheets = xSpreadsheetDocument.getSheets(); 221cdf0e10cSrcweir XIndexAccess xIndexedSheets = (XIndexAccess)UnoRuntime.queryInterface( 222cdf0e10cSrcweir XIndexAccess.class, sheets); 223*ffea6052Smseidel Object sheet = xIndexedSheets.getByIndex(0); 224cdf0e10cSrcweir 225cdf0e10cSrcweir //get cell A2 in first sheet 226cdf0e10cSrcweir XCellRange xSpreadsheetCells = (XCellRange)UnoRuntime.queryInterface( 227cdf0e10cSrcweir XCellRange.class, sheet); 228cdf0e10cSrcweir XCell xCell = xSpreadsheetCells.getCellByPosition(0,1); 229cdf0e10cSrcweir XPropertySet xCellProps = (XPropertySet)UnoRuntime.queryInterface( 230cdf0e10cSrcweir XPropertySet.class, xCell); 231cdf0e10cSrcweir xCellProps.setPropertyValue("IsTextWrapped", new Boolean(true)); 232cdf0e10cSrcweir 233cdf0e10cSrcweir XText xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); 234cdf0e10cSrcweir 235cdf0e10cSrcweir manipulateText(xCellText); 236cdf0e10cSrcweir manipulateTable(xSpreadsheetCells); 237cdf0e10cSrcweir 238cdf0e10cSrcweir // get internal service factory of the document 239cdf0e10cSrcweir XMultiServiceFactory xCalcFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( 240cdf0e10cSrcweir XMultiServiceFactory.class, xCalcComponent); 241cdf0e10cSrcweir // get Drawpage 242cdf0e10cSrcweir XDrawPageSupplier xDrawPageSupplier = (XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, sheet); 243cdf0e10cSrcweir XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage(); 244cdf0e10cSrcweir 245cdf0e10cSrcweir // create and insert RectangleShape and get shape text, then manipulate text 246cdf0e10cSrcweir Object calcShape = xCalcFactory.createInstance( 247cdf0e10cSrcweir "com.sun.star.drawing.RectangleShape"); 248cdf0e10cSrcweir XShape xCalcShape = (XShape)UnoRuntime.queryInterface( 249cdf0e10cSrcweir XShape.class, calcShape); 250cdf0e10cSrcweir xCalcShape.setSize(new Size(10000, 10000)); 251cdf0e10cSrcweir xCalcShape.setPosition(new Point(7000, 3000)); 252cdf0e10cSrcweir 253cdf0e10cSrcweir xDrawPage.add(xCalcShape); 254cdf0e10cSrcweir 255cdf0e10cSrcweir XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface( 256cdf0e10cSrcweir XPropertySet.class, calcShape); 257cdf0e10cSrcweir // wrap text inside shape 258cdf0e10cSrcweir xShapeProps.setPropertyValue("TextContourFrame", new Boolean(true)); 259cdf0e10cSrcweir 260cdf0e10cSrcweir 261cdf0e10cSrcweir XText xShapeText = (XText)UnoRuntime.queryInterface(XText.class, calcShape); 262cdf0e10cSrcweir 263cdf0e10cSrcweir manipulateText(xShapeText); 264cdf0e10cSrcweir manipulateShape(xCalcShape); 265cdf0e10cSrcweir 266cdf0e10cSrcweir } 267cdf0e10cSrcweir catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1 268cdf0e10cSrcweir xRemoteContext = null; 269cdf0e10cSrcweir throw e; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir } 273cdf0e10cSrcweir useDraw()274cdf0e10cSrcweir protected void useDraw() throws java.lang.Exception { 275cdf0e10cSrcweir try { 276*ffea6052Smseidel //create new draw document and insert rectangle shape 277cdf0e10cSrcweir XComponent xDrawComponent = newDocComponent("sdraw"); 278cdf0e10cSrcweir XDrawPagesSupplier xDrawPagesSupplier = 279cdf0e10cSrcweir (XDrawPagesSupplier)UnoRuntime.queryInterface( 280cdf0e10cSrcweir XDrawPagesSupplier.class, xDrawComponent); 281cdf0e10cSrcweir 282cdf0e10cSrcweir Object drawPages = xDrawPagesSupplier.getDrawPages(); 283cdf0e10cSrcweir XIndexAccess xIndexedDrawPages = (XIndexAccess)UnoRuntime.queryInterface( 284cdf0e10cSrcweir XIndexAccess.class, drawPages); 285cdf0e10cSrcweir Object drawPage = xIndexedDrawPages.getByIndex(0); 286cdf0e10cSrcweir XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage); 287cdf0e10cSrcweir 288cdf0e10cSrcweir // get internal service factory of the document 289cdf0e10cSrcweir XMultiServiceFactory xDrawFactory = 290cdf0e10cSrcweir (XMultiServiceFactory)UnoRuntime.queryInterface( 291cdf0e10cSrcweir XMultiServiceFactory.class, xDrawComponent); 292cdf0e10cSrcweir 293cdf0e10cSrcweir Object drawShape = xDrawFactory.createInstance( 294cdf0e10cSrcweir "com.sun.star.drawing.RectangleShape"); 295cdf0e10cSrcweir XShape xDrawShape = (XShape)UnoRuntime.queryInterface(XShape.class, drawShape); 296cdf0e10cSrcweir xDrawShape.setSize(new Size(10000, 20000)); 297cdf0e10cSrcweir xDrawShape.setPosition(new Point(5000, 5000)); 298cdf0e10cSrcweir xDrawPage.add(xDrawShape); 299cdf0e10cSrcweir 300cdf0e10cSrcweir XText xShapeText = (XText)UnoRuntime.queryInterface(XText.class, drawShape); 301cdf0e10cSrcweir XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface( 302cdf0e10cSrcweir XPropertySet.class, drawShape); 303cdf0e10cSrcweir 304cdf0e10cSrcweir // wrap text inside shape 305cdf0e10cSrcweir xShapeProps.setPropertyValue("TextContourFrame", new Boolean(true)); 306cdf0e10cSrcweir 307cdf0e10cSrcweir manipulateText(xShapeText); 308cdf0e10cSrcweir manipulateShape(xDrawShape); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir catch( com.sun.star.lang.DisposedException e ) { //works from Patch 1 311cdf0e10cSrcweir xRemoteContext = null; 312cdf0e10cSrcweir throw e; 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir 316cdf0e10cSrcweir } 317cdf0e10cSrcweir manipulateText(XText xText)318cdf0e10cSrcweir protected void manipulateText(XText xText) throws com.sun.star.uno.Exception { 319cdf0e10cSrcweir // simply set whole text as one string 320cdf0e10cSrcweir xText.setString("He lay flat on the brown, pine-needled floor of the forest, " 321cdf0e10cSrcweir + "his chin on his folded arms, and high overhead the wind blew in the tops " 322cdf0e10cSrcweir + "of the pine trees."); 323cdf0e10cSrcweir 324cdf0e10cSrcweir // create text cursor for selecting and formatting 325cdf0e10cSrcweir XTextCursor xTextCursor = xText.createTextCursor(); 326cdf0e10cSrcweir XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface( 327cdf0e10cSrcweir XPropertySet.class, xTextCursor); 328cdf0e10cSrcweir 329cdf0e10cSrcweir // use cursor to select "He lay" and apply bold italic 330cdf0e10cSrcweir xTextCursor.gotoStart(false); 331cdf0e10cSrcweir xTextCursor.goRight((short)6, true); 332cdf0e10cSrcweir // from CharacterProperties 333cdf0e10cSrcweir xCursorProps.setPropertyValue("CharPosture", 334cdf0e10cSrcweir com.sun.star.awt.FontSlant.ITALIC); 335cdf0e10cSrcweir xCursorProps.setPropertyValue("CharWeight", 336cdf0e10cSrcweir new Float(com.sun.star.awt.FontWeight.BOLD)); 337cdf0e10cSrcweir 338cdf0e10cSrcweir // add more text at the end of the text using insertString 339cdf0e10cSrcweir xTextCursor.gotoEnd(false); 340cdf0e10cSrcweir xText.insertString(xTextCursor, " The mountainside sloped gently where he lay; " 341cdf0e10cSrcweir + "but below it was steep and he could see the dark of the oiled road " 342cdf0e10cSrcweir + "winding through the pass. There was a stream alongside the road " 343cdf0e10cSrcweir + "and far down the pass he saw a mill beside the stream and the falling water " 344cdf0e10cSrcweir + "of the dam, white in the summer sunlight.", false); 345cdf0e10cSrcweir // after insertString the cursor is behind the inserted text, insert more text 346cdf0e10cSrcweir xText.insertString(xTextCursor, "\n \"Is that the mill?\" he asked.", false); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir manipulateTable(XCellRange xCellRange)349cdf0e10cSrcweir protected void manipulateTable(XCellRange xCellRange) throws com.sun.star.uno.Exception { 350cdf0e10cSrcweir 351cdf0e10cSrcweir String backColorPropertyName = ""; 352cdf0e10cSrcweir XPropertySet xTableProps = null; 353cdf0e10cSrcweir 354cdf0e10cSrcweir // enter column titles and a cell value 355cdf0e10cSrcweir XCell xCell = xCellRange.getCellByPosition(0,0); 356cdf0e10cSrcweir XText xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); 357cdf0e10cSrcweir xCellText.setString("Quotation"); 358cdf0e10cSrcweir xCell = xCellRange.getCellByPosition(1,0); 359cdf0e10cSrcweir xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); 360cdf0e10cSrcweir xCellText.setString("Year"); 361cdf0e10cSrcweir xCell = xCellRange.getCellByPosition(1,1); 362cdf0e10cSrcweir xCell.setValue(1940); 363cdf0e10cSrcweir XCellRange xSelectedCells = xCellRange.getCellRangeByName("A1:B1"); 364cdf0e10cSrcweir XPropertySet xCellProps = (XPropertySet)UnoRuntime.queryInterface( 365cdf0e10cSrcweir XPropertySet.class, xSelectedCells); 366cdf0e10cSrcweir 367cdf0e10cSrcweir // format table headers and table borders 368cdf0e10cSrcweir // we need to distinguish text and sheet tables: 369cdf0e10cSrcweir // property name for cell colors is different in text and sheet cells 370cdf0e10cSrcweir // we want to apply TableBorder to whole text table, but only to sheet cells with content 371cdf0e10cSrcweir XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( 372cdf0e10cSrcweir XServiceInfo.class, xCellRange); 373cdf0e10cSrcweir if (xServiceInfo.supportsService("com.sun.star.sheet.Spreadsheet")) { 374cdf0e10cSrcweir backColorPropertyName = "CellBackColor"; 375cdf0e10cSrcweir xSelectedCells = xCellRange.getCellRangeByName("A1:B2"); 376cdf0e10cSrcweir xTableProps = (XPropertySet)UnoRuntime.queryInterface( 377cdf0e10cSrcweir XPropertySet.class, xSelectedCells); 378cdf0e10cSrcweir } 379cdf0e10cSrcweir else if (xServiceInfo.supportsService("com.sun.star.text.TextTable")) { 380cdf0e10cSrcweir backColorPropertyName = "BackColor"; 381cdf0e10cSrcweir xTableProps = (XPropertySet)UnoRuntime.queryInterface( 382cdf0e10cSrcweir XPropertySet.class, xCellRange); 383cdf0e10cSrcweir } 384cdf0e10cSrcweir // set cell background color 385cdf0e10cSrcweir xCellProps.setPropertyValue(backColorPropertyName, new Integer(0x99CCFF)); 386cdf0e10cSrcweir 387cdf0e10cSrcweir // set table borders 388cdf0e10cSrcweir // create description for blue line, width 10 389cdf0e10cSrcweir BorderLine theLine = new BorderLine(); 390cdf0e10cSrcweir theLine.Color = 0x000099; 391cdf0e10cSrcweir theLine.OuterLineWidth = 10; 392cdf0e10cSrcweir // apply line description to all border lines and make them valid 393cdf0e10cSrcweir TableBorder bord = new TableBorder(); 394cdf0e10cSrcweir bord.VerticalLine = bord.HorizontalLine = 395cdf0e10cSrcweir bord.LeftLine = bord.RightLine = 396cdf0e10cSrcweir bord.TopLine = bord.BottomLine = 397cdf0e10cSrcweir theLine; 398cdf0e10cSrcweir bord.IsVerticalLineValid = bord.IsHorizontalLineValid = 399cdf0e10cSrcweir bord.IsLeftLineValid = bord.IsRightLineValid = 400cdf0e10cSrcweir bord.IsTopLineValid = bord.IsBottomLineValid = 401cdf0e10cSrcweir true; 402cdf0e10cSrcweir 403cdf0e10cSrcweir xTableProps.setPropertyValue("TableBorder", bord); 404cdf0e10cSrcweir 405cdf0e10cSrcweir bord = (TableBorder)xTableProps.getPropertyValue("TableBorder"); 406cdf0e10cSrcweir theLine = bord.TopLine; 407cdf0e10cSrcweir int col = theLine.Color; 408cdf0e10cSrcweir System.out.println(col); 409cdf0e10cSrcweir } 410*ffea6052Smseidel manipulateShape(XShape xShape)411cdf0e10cSrcweir protected void manipulateShape(XShape xShape) throws com.sun.star.uno.Exception { 412cdf0e10cSrcweir XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShape); 413cdf0e10cSrcweir xShapeProps.setPropertyValue("FillColor", new Integer(0x99CCFF)); 414cdf0e10cSrcweir xShapeProps.setPropertyValue("LineColor", new Integer(0x000099)); 415cdf0e10cSrcweir xShapeProps.setPropertyValue("RotateAngle", new Integer(3000)); 416cdf0e10cSrcweir 417cdf0e10cSrcweir xShapeProps.setPropertyValue("TextLeftDistance", new Integer(0)); 418cdf0e10cSrcweir xShapeProps.setPropertyValue("TextRightDistance", new Integer(0)); 419cdf0e10cSrcweir xShapeProps.setPropertyValue("TextUpperDistance", new Integer(0)); 420*ffea6052Smseidel xShapeProps.setPropertyValue("TextLowerDistance", new Integer(0)); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir newDocComponent(String docType)424cdf0e10cSrcweir protected XComponent newDocComponent(String docType) throws java.lang.Exception { 425cdf0e10cSrcweir String loadUrl = "private:factory/" + docType; 426cdf0e10cSrcweir xRemoteServiceManager = this.getRemoteServiceManager(); 427cdf0e10cSrcweir Object desktop = xRemoteServiceManager.createInstanceWithContext( 428cdf0e10cSrcweir "com.sun.star.frame.Desktop", xRemoteContext); 429cdf0e10cSrcweir XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface( 430cdf0e10cSrcweir XComponentLoader.class, desktop); 431cdf0e10cSrcweir PropertyValue[] loadProps = new PropertyValue[0]; 432cdf0e10cSrcweir return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps); 433cdf0e10cSrcweir } 434cdf0e10cSrcweir getRemoteServiceManager()435cdf0e10cSrcweir protected XMultiComponentFactory getRemoteServiceManager() throws java.lang.Exception { 436cdf0e10cSrcweir if (xRemoteContext == null && xRemoteServiceManager == null) { 437cdf0e10cSrcweir try { 438cdf0e10cSrcweir // First step: get the remote office component context 439cdf0e10cSrcweir xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); 440cdf0e10cSrcweir System.out.println("Connected to a running office ..."); 441*ffea6052Smseidel 442cdf0e10cSrcweir xRemoteServiceManager = xRemoteContext.getServiceManager(); 443cdf0e10cSrcweir } 444cdf0e10cSrcweir catch( Exception e) { 445cdf0e10cSrcweir e.printStackTrace(); 446cdf0e10cSrcweir System.exit(1); 447*ffea6052Smseidel } 448cdf0e10cSrcweir } 449cdf0e10cSrcweir return xRemoteServiceManager; 450cdf0e10cSrcweir } 451cdf0e10cSrcweir } 452