diff options
Diffstat (limited to 'odk/examples/DevelopersGuide/Text/TextDocuments.java')
-rw-r--r-- | odk/examples/DevelopersGuide/Text/TextDocuments.java | 588 |
1 files changed, 294 insertions, 294 deletions
diff --git a/odk/examples/DevelopersGuide/Text/TextDocuments.java b/odk/examples/DevelopersGuide/Text/TextDocuments.java index 4696b41ffe59..fad1be9c0e4a 100644 --- a/odk/examples/DevelopersGuide/Text/TextDocuments.java +++ b/odk/examples/DevelopersGuide/Text/TextDocuments.java @@ -2,7 +2,7 @@ * * 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. * @@ -29,7 +29,7 @@ * 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.awt.Point; @@ -144,9 +144,9 @@ public class TextDocuments { private static String sOutputDir; private String aPrinterName = "\\\\so-print\\xml3sof"; - + private XComponentContext mxRemoteContext = null; - private XMultiComponentFactory mxRemoteServiceManager = null; + private XMultiComponentFactory mxRemoteServiceManager = null; private XTextDocument mxDoc = null; private XMultiServiceFactory mxDocFactory = null; private XMultiServiceFactory mxFactory = null; @@ -155,11 +155,11 @@ public class TextDocuments { private XTextCursor mxDocCursor = null; private XTextContent mxFishSection = null; private Random maRandom = null; - + /** Creates a new instance of TextDocuments */ public TextDocuments() { } - + /** * @param args the command line arguments */ @@ -168,7 +168,7 @@ public class TextDocuments { try { // output directory for store test; sOutputDir = args[0]; - + textDocuments1.runDemo(); } catch (java.lang.Exception e){ @@ -179,15 +179,15 @@ public class TextDocuments { System.exit(0); } } - + protected void runDemo() throws java.lang.Exception { storePrintExample(); // depends on printer name - templateExample(); + templateExample(); viewCursorExample(); // makes changes to the current document, // use with care editingExample(); } - + /** Sample for use of templates * This sample uses the file TextTemplateWithUserFields.odt from the Samples * folder. The file contains a number of User text fields (Variables - User) @@ -201,40 +201,40 @@ public class TextDocuments { recipient.put("ZIP", "34567"); recipient.put("City", "Fort Lauderdale"); recipient.put("State", "Florida"); - + // load template with User fields and bookmark java.io.File sourceFile = new java.io.File("TextTemplateWithUserFields.odt"); StringBuffer sTemplateFileUrl = new StringBuffer("file:///"); sTemplateFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); - XComponent xTemplateComponent = + XComponent xTemplateComponent = newDocComponentFromTemplate( sTemplateFileUrl.toString() ); - + // get XTextFieldsSupplier, XBookmarksSupplier interfaces XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) UnoRuntime.queryInterface(XTextFieldsSupplier.class, xTemplateComponent); XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier) UnoRuntime.queryInterface(XBookmarksSupplier.class, xTemplateComponent); - + // access the TextFields and the TextFieldMasters collections XNameAccess xNamedFieldMasters = xTextFieldsSupplier.getTextFieldMasters(); XEnumerationAccess xEnumeratedFields = xTextFieldsSupplier.getTextFields(); - + // iterate over hashtable and insert values into field masters java.util.Enumeration keys = recipient.keys(); while(keys.hasMoreElements()) { // get column name String key = (String)keys.nextElement(); - + // access corresponding field master Object fieldMaster = xNamedFieldMasters.getByName( "com.sun.star.text.fieldmaster.User." + key); - + // query the XPropertySet interface, we need to set the Content property XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, fieldMaster); - + // insert the column value into field master xPropertySet.setPropertyValue("Content", recipient.get(key)); } @@ -245,10 +245,10 @@ public class TextDocuments { // accessing the Bookmarks collection of the document XNameAccess xNamedBookmarks = xBookmarksSupplier.getBookmarks(); - + // find the bookmark named "Subscription" Object bookmark = xNamedBookmarks.getByName("Subscription"); - // we need its XTextRange which is available from getAnchor(), + // we need its XTextRange which is available from getAnchor(), // so query for XTextContent XTextContent xBookmarkContent = (XTextContent)UnoRuntime.queryInterface( XTextContent.class, bookmark); @@ -256,14 +256,14 @@ public class TextDocuments { XTextRange xBookmarkRange = xBookmarkContent.getAnchor(); // set string at the bookmark position xBookmarkRange.setString("subscription for the Manatee Journal"); - + } - + /** Sample for document changes, starting at the current view cursor position * The sample changes the paragraph style and the character style at the * current view cursor selection Open the sample file ViewCursorExampleFile, * select some text and run the example. - * The current paragraph will be set to Quotations paragraph style. + * The current paragraph will be set to Quotations paragraph style. * The selected text will be set to Quotation character style. */ private void viewCursorExample() throws java.lang.Exception { @@ -281,11 +281,11 @@ public class TextDocuments { xCurrentComponent); XController xController = xModel.getCurrentController(); // the controller gives us the TextViewCursor - XTextViewCursorSupplier xViewCursorSupplier = + XTextViewCursorSupplier xViewCursorSupplier = (XTextViewCursorSupplier)UnoRuntime.queryInterface( XTextViewCursorSupplier.class, xController); XTextViewCursor xViewCursor = xViewCursorSupplier.getViewCursor(); - + // query its XPropertySet interface, we want to set character and paragraph // properties XPropertySet xCursorPropertySet = (XPropertySet)UnoRuntime.queryInterface( @@ -297,7 +297,7 @@ public class TextDocuments { XPageCursor xPageCursor = (XPageCursor)UnoRuntime.queryInterface( XPageCursor.class, xViewCursor); System.out.println("The current page number is " + xPageCursor.getPage()); - // the model cursor is much more powerful, so + // the model cursor is much more powerful, so // we create a model cursor at the current view cursor position with the // following steps: // get the Text service from the TextViewCursor, it is an XTextRange: @@ -315,8 +315,8 @@ public class TextDocuments { xParagraphCursor.gotoEndOfParagraph(false); xParagraphCursor.setString(" ***** Fin de semana! ******"); } - - + + /** Sample for the various editing facilities described in the * developer's manual */ @@ -326,49 +326,49 @@ public class TextDocuments { // query its XTextDocument interface to get the text mxDoc = (XTextDocument)UnoRuntime.queryInterface( XTextDocument.class, xEmptyWriterComponent); - + // get a reference to the body text of the document mxDocText = mxDoc.getText(); - + // Get a reference to the document's property set. This contains document // information like the current word count mxDocProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, mxDoc ); - + // Simple text insertion example BodyTextExample (); // Example using text ranges to insert strings at the beginning or end // of a text range - TextRangeExample (); + TextRangeExample (); // Create a document cursor and remember it, it will be used in most // of the following examples - mxDocCursor = mxDocText.createTextCursor(); + mxDocCursor = mxDocText.createTextCursor(); // Demonstrate some of the different cursor types (word, sentence) TextCursorExample (); - + // Access the text document's multi service factory, which we will need // for most of the following examples mxDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, mxDoc ); - + // Examples of text fields, dependant text fields and field masters TextFieldExample (); - + // Example of using an XEnumerationAccess to iterate over paragraphs and // set properties of each paragraph as we do so - ParagraphExample (); - + ParagraphExample (); + // Example of creating and manipulating a text frame TextFrameExample (); - + // Example of creating and manipulating a text table, text table rows // and text table cells get a new random generator maRandom = new Random(); TextTableExample (); - + // Example of creating, inserting and manipulating text sections, as // well as an example of how to refresh the document - TextSectionExample (); + TextSectionExample (); // Example of creating a text section over a block of text and formatting // the text section into columns, as well as how to insert an empty @@ -383,7 +383,7 @@ public class TextDocuments { // document and how to create, insert and apply styles StylesExample (); IndexExample (); - + // Example of how to create and manipulate reference marks and GetReference // text fields ReferenceExample (); @@ -396,15 +396,15 @@ public class TextDocuments { // and how to access the draw page of the document using the // XDrawPageSupplier interface DrawPageExample (); - + mxFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( XMultiServiceFactory.class, mxRemoteServiceManager); // This example demonstrates the use of the AutoTextContainer, // AutoTextGroup and AutoTextEntry services and shows how to create, // insert and modify auto text blocks - AutoTextExample (); + AutoTextExample (); } - + protected void storePrintExample() throws java.lang.Exception { // get the remote service manager mxRemoteServiceManager = this.getRemoteServiceManager(); @@ -418,7 +418,7 @@ public class TextDocuments { java.io.File sourceFile = new java.io.File("PrintDemo.odt"); StringBuffer sLoadFileUrl = new StringBuffer("file:///"); sLoadFileUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); - + XComponent xDoc = xComponentLoader.loadComponentFromURL( sLoadFileUrl.toString(), "_blank", 0, loadProps); @@ -432,10 +432,10 @@ public class TextDocuments { printDocComponent(xDoc); } } - + private XMultiComponentFactory getRemoteServiceManager() throws java.lang.Exception - { + { if (mxRemoteContext == null && mxRemoteServiceManager == null) { // get the remote office context. If necessary a new office // process is started @@ -444,8 +444,8 @@ public class TextDocuments { mxRemoteServiceManager = mxRemoteContext.getServiceManager(); } return mxRemoteServiceManager; - } - + } + protected XComponent newDocComponent(String docType) throws java.lang.Exception { @@ -457,9 +457,9 @@ public class TextDocuments { UnoRuntime.queryInterface(XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", - 0, loadProps); + 0, loadProps); } - + /** Load a document as template */ protected XComponent newDocComponentFromTemplate(String loadUrl) @@ -472,17 +472,17 @@ public class TextDocuments { "com.sun.star.frame.Desktop", mxRemoteContext); XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop); - + // define load properties according to com.sun.star.document.MediaDescriptor // the boolean property AsTemplate tells the office to create a new document // from the given file PropertyValue[] loadProps = new PropertyValue[1]; loadProps[0] = new PropertyValue(); loadProps[0].Name = "AsTemplate"; - loadProps[0].Value = new Boolean(true); + loadProps[0].Value = new Boolean(true); // load return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", - 0, loadProps); + 0, loadProps); } /** Load a document with arguments (text purposes) @@ -490,18 +490,18 @@ public class TextDocuments { protected void storeDocComponent(XComponent xDoc, String storeUrl) throws java.lang.Exception { - + XStorable xStorable = (XStorable)UnoRuntime.queryInterface( XStorable.class, xDoc); PropertyValue[] storeProps = new PropertyValue[1]; storeProps[0] = new PropertyValue(); storeProps[0].Name = "FilterName"; - storeProps[0].Value = "MS Word 97"; + storeProps[0].Value = "MS Word 97"; System.out.println("... store \"PrintDemo.odt\" to \"" + storeUrl + "\"."); - xStorable.storeAsURL(storeUrl, storeProps); + xStorable.storeAsURL(storeUrl, storeProps); } - + protected void printDocComponent(XComponent xDoc) throws java.lang.Exception { XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface( XPrintable.class, xDoc); @@ -510,16 +510,16 @@ public class TextDocuments { printerDesc[0].Name = "Name"; printerDesc[0].Value = aPrinterName; - xPrintable.setPrinter(printerDesc); - + xPrintable.setPrinter(printerDesc); + PropertyValue[] printOpts = new PropertyValue[1]; printOpts[0] = new PropertyValue(); printOpts[0].Name = "Pages"; - printOpts[0].Value = "1"; - - xPrintable.print(printOpts); + printOpts[0].Value = "1"; + + xPrintable.print(printOpts); } - + // Setting the whole text of a document as one string protected void BodyTextExample () { @@ -527,7 +527,7 @@ public class TextDocuments { try { // demonstrate simple text insertion - mxDocText.setString ( "This is the new body text of the document." + mxDocText.setString ( "This is the new body text of the document." + "\n\nThis is on the second line.\n\n" ); } catch ( Exception e ) @@ -535,7 +535,7 @@ public class TextDocuments { e.printStackTrace(); } } - + // Adding a string at the end or the beginning of text protected void TextRangeExample () { @@ -555,7 +555,7 @@ public class TextDocuments { e.printStackTrace(); } } - + /** moving a text cursor, selecting text and overwriting it */ protected void TextCursorExample () @@ -591,14 +591,14 @@ public class TextDocuments { // replace the '.' at the end of the sentence with a new string xSentenceCursor.gotoEndOfSentence( false ); xWordCursor.gotoPreviousWord( true ); - mxDocText.insertString (xWordCursor, + mxDocText.insertString (xWordCursor, ", which has been changed with text cursors!", true); } catch ( Exception e ) { e.printStackTrace(); - } + } } /** This method inserts both a date field and a user field containing the @@ -608,7 +608,7 @@ public class TextDocuments { { try { - // Use the text document's factory to create a DateTime text field, + // Use the text document's factory to create a DateTime text field, // and access it's XTextField interface XTextField xDateField = (XTextField) UnoRuntime.queryInterface ( XTextField.class, mxDocFactory.createInstance ( @@ -617,9 +617,9 @@ public class TextDocuments { // Insert it at the end of the document mxDocText.insertTextContent ( mxDocText.getEnd(), xDateField, false ); - // Use the text document's factory to create a user text field, + // Use the text document's factory to create a user text field, // and access it's XDependentTextField interface - XDependentTextField xUserField = + XDependentTextField xUserField = (XDependentTextField) UnoRuntime.queryInterface ( XDependentTextField.class, mxDocFactory.createInstance ( "com.sun.star.text.TextField.User" ) ); @@ -633,16 +633,16 @@ public class TextDocuments { // Set the name and value of the FieldMaster xMasterPropSet.setPropertyValue ( "Name", "UserEmperor" ); xMasterPropSet.setPropertyValue ( "Value", new Integer ( 42 ) ); - + // Attach the field master to the user field xUserField.attachTextFieldMaster ( xMasterPropSet ); - + // Move the cursor to the end of the document mxDocCursor.gotoEnd( false ); // insert a paragraph break using the XSimpleText interface - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - + // Insert the user field at the end of the document mxDocText.insertTextContent ( mxDocText.getEnd(), xUserField, false ); } @@ -650,8 +650,8 @@ public class TextDocuments { { e.printStackTrace(); } - } - + } + /** This method demonstrates how to iterate over paragraphs */ protected void ParagraphExample () @@ -660,7 +660,7 @@ public class TextDocuments { { // The service 'com.sun.star.text.Text' supports the XEnumerationAccess // interface to provide an enumeration of the paragraphs contained by - // the text the service refers to. + // the text the service refers to. // Here, we access this interface XEnumerationAccess xParaAccess = (XEnumerationAccess) @@ -697,80 +697,80 @@ public class TextDocuments { e.printStackTrace(); } } - + /** This method returns a random double which isn't too high or too low */ protected double getRandomDouble () { return ( ( maRandom.nextInt() % 1000 ) * maRandom.nextDouble () ); } - + /** This method sets the text colour of the cell refered to by sCellName to white and inserts the string sText in it */ protected static void insertIntoCell(String sCellName, String sText, - XTextTable xTable) + XTextTable xTable) { - // Access the XText interface of the cell referred to by sCellName + // Access the XText interface of the cell referred to by sCellName XText xCellText = (XText) UnoRuntime.queryInterface( XText.class, xTable.getCellByName ( sCellName ) ); - + // create a text cursor from the cells XText interface XTextCursor xCellCursor = xCellText.createTextCursor(); // Get the property set of the cell's TextCursor XPropertySet xCellCursorProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xCellCursor ); - - try + + try { // Set the colour of the text to white xCellCursorProps.setPropertyValue( "CharColor", new Integer(16777215)); - } - catch ( Exception e) + } + catch ( Exception e) { e.printStackTrace(); } // Set the text in the cell to sText xCellText.setString( sText ); } - + /** This method shows how to create and insert a text table, as well as insert text and formulae into the cells of the table */ protected void TextTableExample () { - try + try { // Create a new table from the document's factory - XTextTable xTable = (XTextTable) UnoRuntime.queryInterface( + XTextTable xTable = (XTextTable) UnoRuntime.queryInterface( XTextTable.class, mxDocFactory .createInstance( "com.sun.star.text.TextTable" ) ); - + // Specify that we want the table to have 4 rows and 4 columns xTable.initialize( 4, 4 ); - + // Insert the table into the document mxDocText.insertTextContent( mxDocCursor, xTable, false); // Get an XIndexAccess of the table rows XIndexAccess xRows = xTable.getRows(); - + // Access the property set of the first row (properties listed in // service description: com.sun.star.text.TextTableRow) - XPropertySet xRow = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xRow = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xRows.getByIndex ( 0 ) ); // If BackTransparant is false, then the background color is visible xRow.setPropertyValue( "BackTransparent", new Boolean(false)); // Specify the color of the background to be dark blue xRow.setPropertyValue( "BackColor", new Integer(6710932)); - + // Access the property set of the whole table - XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xTable ); // We want visible background colors xTableProps.setPropertyValue( "BackTransparent", new Boolean(false)); // Set the background colour to light blue xTableProps.setPropertyValue( "BackColor", new Integer(13421823)); - + // set the text (and text colour) of all the cells in the first row // of the table insertIntoCell( "A1", "First Column", xTable ); @@ -783,22 +783,22 @@ public class TextDocuments { xTable.getCellByName( "A2" ).setValue( getRandomDouble() ); xTable.getCellByName( "B2" ).setValue( getRandomDouble() ); xTable.getCellByName( "C2" ).setValue( getRandomDouble() ); - + xTable.getCellByName( "A3" ).setValue( getRandomDouble() ); xTable.getCellByName( "B3" ).setValue( getRandomDouble() ); xTable.getCellByName( "C3" ).setValue( getRandomDouble() ); - + xTable.getCellByName( "A4" ).setValue( getRandomDouble() ); xTable.getCellByName( "B4" ).setValue( getRandomDouble() ); xTable.getCellByName( "C4" ).setValue( getRandomDouble() ); - + // Set the last cell in each row to be a formula that calculates // the sum of the first three cells xTable.getCellByName( "D2" ).setFormula( "sum <A2:C2>" ); xTable.getCellByName( "D3" ).setFormula( "sum <A3:C3>" ); xTable.getCellByName( "D4" ).setFormula( "sum <A4:C4>" ); - } - catch (Exception e) + } + catch (Exception e) { e.printStackTrace(); } @@ -807,20 +807,20 @@ public class TextDocuments { */ protected void TextFrameExample () { - try + try { // Use the document's factory to create a new text frame and // immediately access it's XTextFrame interface XTextFrame xFrame = (XTextFrame) UnoRuntime.queryInterface ( XTextFrame.class, mxDocFactory.createInstance ( "com.sun.star.text.TextFrame" ) ); - + // Access the XShape interface of the TextFrame XShape xShape = (XShape)UnoRuntime.queryInterface(XShape.class, xFrame); // Access the XPropertySet interface of the TextFrame XPropertySet xFrameProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xFrame ); - + // Set the size of the new Text Frame using the XShape's 'setSize' // method Size aSize = new Size(); @@ -834,31 +834,31 @@ public class TextDocuments { // Go to the end of the text document mxDocCursor.gotoEnd( false ); // Insert a new paragraph - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // Then insert the new frame mxDocText.insertTextContent(mxDocCursor, xFrame, false); - + // Access the XText interface of the text contained within the frame XText xFrameText = xFrame.getText(); // Create a TextCursor over the frame's contents XTextCursor xFrameCursor = xFrameText.createTextCursor(); // Insert some text into the frame - xFrameText.insertString( + xFrameText.insertString( xFrameCursor, "The first line in the newly created text frame.", false ); - xFrameText.insertString( + xFrameText.insertString( xFrameCursor, "\nThe second line in the new text frame.", false ); // Insert a paragraph break into the document (not the frame) - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - } - catch (Exception e) + } + catch (Exception e) { e.printStackTrace(); } } - + /** This example demonstrates the use of the AutoTextContainer, AutoTextGroup and AutoTextEntry services and shows how to create, insert and modify auto text blocks @@ -870,9 +870,9 @@ public class TextDocuments { // Go to the end of the document mxDocCursor.gotoEnd( false ); // Insert two paragraphs - mxDocText.insertControlCharacter ( mxDocCursor, + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - mxDocText.insertControlCharacter ( mxDocCursor, + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // Position the cursor in the second paragraph XParagraphCursor xParaCursor = (XParagraphCursor) @@ -881,29 +881,29 @@ public class TextDocuments { // Get an XNameAccess interface to all auto text groups from the // document factory - XNameAccess xContainer = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess xContainer = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, mxFactory.createInstance ( "com.sun.star.text.AutoTextContainer" ) ); - // Create a new table at the document factory - XTextTable xTable = (XTextTable) UnoRuntime.queryInterface( - XTextTable.class, mxDocFactory .createInstance( + // Create a new table at the document factory + XTextTable xTable = (XTextTable) UnoRuntime.queryInterface( + XTextTable.class, mxDocFactory .createInstance( "com.sun.star.text.TextTable" ) ); - + // Store the names of all auto text groups in an array of strings String[] aGroupNames = xContainer.getElementNames(); // Make sure we have at least one group name - if ( aGroupNames.length > 0 ) + if ( aGroupNames.length > 0 ) { - // initialise the table to have a row for every autotext group + // initialise the table to have a row for every autotext group // in a single column + one additional row for a header xTable.initialize( aGroupNames.length+1,1); // Access the XPropertySet of the table XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xTable ); - + // We want a visible background xTableProps.setPropertyValue( "BackTransparent", new Boolean(false)); @@ -916,20 +916,20 @@ public class TextDocuments { // Get an XIndexAccess to all table rows XIndexAccess xRows = xTable.getRows(); - + // Get the first row in the table XPropertySet xRow = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xRows.getByIndex ( 0 ) ); // We want the background of the first row to be visible too xRow.setPropertyValue( "BackTransparent", new Boolean(false)); - + // And let's make it dark blue xRow.setPropertyValue( "BackColor", new Integer(6710932)); - + // Put a description of the table contents into the first cell insertIntoCell( "A1", "AutoText Groups", xTable); - + // Create a table cursor pointing at the second cell in the first // column XTextTableCursor xTableCursor = xTable.createCursorByCellName("A2"); @@ -939,15 +939,15 @@ public class TextDocuments { { // Get the name of the current cell String sCellName = xTableCursor.getRangeName (); - + // Get the XText interface of the current cell - XText xCellText = (XText) UnoRuntime.queryInterface ( + XText xCellText = (XText) UnoRuntime.queryInterface ( XText.class, xTable.getCellByName ( sCellName ) ); - - // Set the cell contents of the current cell to be + + // Set the cell contents of the current cell to be //the name of the of an autotext group xCellText.setString ( aGroupNames[i] ); - + // Access the autotext group with this name XAutoTextGroup xGroup = (XAutoTextGroup) UnoRuntime.queryInterface (XAutoTextGroup.class, @@ -955,23 +955,23 @@ public class TextDocuments { // Get the titles of each autotext block in this group String [] aBlockNames = xGroup.getTitles(); - + // Make sure that the autotext group contains at least one block if ( aBlockNames.length > 0 ) { // Split the current cell vertically into two seperate cells xTableCursor.splitRange ( (short) 1, false ); - - // Put the cursor in the newly created right hand cell + + // Put the cursor in the newly created right hand cell // and select it xTableCursor.goRight ( (short) 1, false ); - - // Split this cell horizontally to make a seperate cell + + // Split this cell horizontally to make a seperate cell // for each Autotext block if ( ( aBlockNames.length -1 ) > 0 ) - xTableCursor.splitRange ( + xTableCursor.splitRange ( (short) (aBlockNames.length - 1), true ); - + // loop over the block names for ( int j = 0 ; j < aBlockNames.length ; j ++ ) { @@ -979,44 +979,44 @@ public class TextDocuments { xCellText = (XText) UnoRuntime.queryInterface ( XText.class, xTable.getCellByName ( xTableCursor.getRangeName() ) ); - + // Set the text contents of the current cell to the // title of an Autotext block xCellText.setString ( aBlockNames[j] ); - + // Move the cursor down one cell xTableCursor.goDown( (short)1, false); } } // Go back to the cell we originally split xTableCursor.gotoCellByName ( sCellName, false ); - + // Go down one cell xTableCursor.goDown( (short)1, false); } - + XAutoTextGroup xGroup; String [] aBlockNames; - + // Add a depth so that we only generate 200 numbers before giving up // on finding a random autotext group that contains autotext blocks int nDepth = 0; do { - // Generate a random, positive number which is lower than + // Generate a random, positive number which is lower than // the number of autotext groups int nRandom = Math.abs ( maRandom.nextInt() % aGroupNames.length ); - + // Get the autotext group at this name - xGroup = ( XAutoTextGroup ) UnoRuntime.queryInterface ( + xGroup = ( XAutoTextGroup ) UnoRuntime.queryInterface ( XAutoTextGroup.class, xContainer.getByName ( aGroupNames[ nRandom ] ) ); // Fill our string array with the names of all the blocks in // this group aBlockNames = xGroup.getElementNames(); - + // increment our depth counter ++nDepth; } @@ -1026,26 +1026,26 @@ public class TextDocuments { { // Pick a random block in this group and get it's // XAutoTextEntry interface - int nRandom = Math.abs ( maRandom.nextInt() + int nRandom = Math.abs ( maRandom.nextInt() % aBlockNames.length ); XAutoTextEntry xEntry = ( XAutoTextEntry ) - UnoRuntime.queryInterface ( + UnoRuntime.queryInterface ( XAutoTextEntry.class, xGroup.getByName ( aBlockNames[ nRandom ] ) ); // insert the modified autotext block at the end of the document xEntry.applyTo ( mxDocCursor ); - + // Get the titles of all text blocks in this AutoText group String [] aBlockTitles = xGroup.getTitles(); - + // Get the XNamed interface of the autotext group XNamed xGroupNamed = ( XNamed ) UnoRuntime.queryInterface ( XNamed.class, xGroup ); - - // Output the short cut and title of the random block + + // Output the short cut and title of the random block //and the name of the group it's from System.out.println ( "Inserted the Autotext '" + - aBlockTitles[nRandom] + aBlockTitles[nRandom] + "', shortcut '" + aBlockNames[nRandom] + "' from group '" + xGroupNamed.getName()); @@ -1055,9 +1055,9 @@ public class TextDocuments { // Go to the end of the document mxDocCursor.gotoEnd( false ); // Insert new paragraph - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - + // Position cursor in new paragraph xParaCursor.gotoPreviousParagraph ( false ); @@ -1068,12 +1068,12 @@ public class TextDocuments { // Go to the end of the document mxDocCursor.gotoEnd( false ); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - + /** This method demonstrates how to insert indexes and index marks */ protected void IndexExample () @@ -1085,25 +1085,25 @@ public class TextDocuments { // Insert a new paragraph and position the cursor in it mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - XParagraphCursor xParaCursor = (XParagraphCursor) + XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); xParaCursor.gotoPreviousParagraph ( false ); - + // Create a new ContentIndexMark and get it's XPropertySet interface XPropertySet xEntry = (XPropertySet)UnoRuntime.queryInterface( - XPropertySet.class, + XPropertySet.class, mxDocFactory.createInstance("com.sun.star.text.ContentIndexMark")); // Set the text to be displayed in the index xEntry.setPropertyValue( "AlternativeText", "Big dogs! Falling on my head!"); - + // The Level property _must_ be set xEntry.setPropertyValue ( "Level", new Short ( (short) 1 ) ); - + // Create a ContentIndex and access it's XPropertySet interface XPropertySet xIndex = (XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, + XPropertySet.class, mxDocFactory.createInstance ( "com.sun.star.text.ContentIndex" ) ); // Again, the Level property _must_ be set @@ -1111,28 +1111,28 @@ public class TextDocuments { // Access the XTextContent interfaces of both the Index and the // IndexMark - XTextContent xIndexContent = (XTextContent) UnoRuntime.queryInterface( + XTextContent xIndexContent = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xIndex ); - XTextContent xEntryContent = (XTextContent) UnoRuntime.queryInterface( + XTextContent xEntryContent = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xEntry ); - + // Insert both in the document mxDocText.insertTextContent ( mxDocCursor, xEntryContent, false ); mxDocText.insertTextContent ( mxDocCursor, xIndexContent, false ); - + // Get the XDocumentIndex interface of the Index - XDocumentIndex xDocIndex = (XDocumentIndex) UnoRuntime.queryInterface( + XDocumentIndex xDocIndex = (XDocumentIndex) UnoRuntime.queryInterface( XDocumentIndex.class, xIndex ); - + // And call it's update method xDocIndex.update(); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - + /** This method demonstrates how to create and insert reference marks, and * GetReference Text Fields */ @@ -1142,25 +1142,25 @@ public class TextDocuments { { // Go to the end of the document mxDocCursor.gotoEnd( false ); - + // Insert a paragraph break - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - + // Get the Paragraph cursor - XParagraphCursor xParaCursor = (XParagraphCursor) + XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); - + // Move the cursor into the new paragraph xParaCursor.gotoPreviousParagraph ( false ); - + // Create a new ReferenceMark and get it's XNamed interface XNamed xRefMark = (XNamed) UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance ("com.sun.star.text.ReferenceMark")); // Set the name to TableHeader xRefMark.setName ( "TableHeader" ); - + // Get the TextTablesSupplier interface of the document XTextTablesSupplier xTableSupplier = ( XTextTablesSupplier ) UnoRuntime.queryInterface(XTextTablesSupplier.class, mxDoc); @@ -1176,10 +1176,10 @@ public class TextDocuments { // Get the first cell from the table XText xTableText = (XText) UnoRuntime.queryInterface( XText.class, xTable.getCellByName ( "A1" ) ); - + // Get a text cursor for the first cell XTextCursor xTableCursor = xTableText.createTextCursor(); - + // Get the XTextContent interface of the reference mark so we can // insert it XTextContent xContent = ( XTextContent ) UnoRuntime.queryInterface ( @@ -1187,7 +1187,7 @@ public class TextDocuments { // Insert the reference mark into the first cell of the table xTableText.insertTextContent ( xTableCursor, xContent, false ); - + // Create a 'GetReference' text field to refer to the reference mark // we just inserted, and get it's XPropertySet interface XPropertySet xFieldProps = (XPropertySet) UnoRuntime.queryInterface( @@ -1204,16 +1204,16 @@ public class TextDocuments { // Put the names of each reference mark into an array of strings String[] aNames = xMarks.getElementNames(); - - // Make sure that at least 1 reference mark actually exists + + // Make sure that at least 1 reference mark actually exists // (well, we just inserted one!) if ( aNames.length > 0 ) { // Output the name of the first reference mark ('TableHeader') System.out.println ( - "GetReference text field inserted for ReferenceMark : " + "GetReference text field inserted for ReferenceMark : " + aNames[0] ); - + // Set the SourceName of the GetReference text field to // 'TableHeader' xFieldProps.setPropertyValue ( "SourceName", aNames[0] ); @@ -1224,17 +1224,17 @@ public class TextDocuments { new Short(ReferenceFieldSource.REFERENCE_MARK)); // We want the reference displayed as 'above' or 'below' - xFieldProps.setPropertyValue ( "ReferenceFieldPart", + xFieldProps.setPropertyValue ( "ReferenceFieldPart", new Short(ReferenceFieldPart.UP_DOWN)); - + // Get the XTextContent interface of the GetReference text field XTextContent xRefContent = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xFieldProps ); // Go to the end of the document mxDocCursor.gotoEnd( false ); - + // Make some text to precede the reference mxDocText.insertString(mxDocText.getEnd(), "The table ", false); @@ -1242,7 +1242,7 @@ public class TextDocuments { mxDocText.insertTextContent(mxDocText.getEnd(), xRefContent, false); // And some text after the reference.. - mxDocText.insertString(mxDocText.getEnd(), + mxDocText.insertString(mxDocText.getEnd(), " contains the sum of some random numbers.", false ); // Refresh the document @@ -1251,12 +1251,12 @@ public class TextDocuments { xRefresh.refresh(); } } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - + /** This method demonstrates how to create and insert footnotes, and how to access the XFootnotesSupplier interface of the document */ @@ -1272,14 +1272,14 @@ public class TextDocuments { // Set the label to 'Numbers' xFootnote.setLabel ( "Numbers" ); - + // Get the footnotes XTextContent interface so we can... - XTextContent xContent = ( XTextContent ) UnoRuntime.queryInterface ( + XTextContent xContent = ( XTextContent ) UnoRuntime.queryInterface ( XTextContent.class, xFootnote ); - + // ...insert it into the document mxDocText.insertTextContent ( mxDocCursor, xContent, false ); - + // Get the XFootnotesSupplier interface of the document XFootnotesSupplier xFootnoteSupplier = (XFootnotesSupplier) UnoRuntime.queryInterface(XFootnotesSupplier.class, mxDoc ); @@ -1289,27 +1289,27 @@ public class TextDocuments { XIndexAccess.class, xFootnoteSupplier.getFootnotes() ); // Get the XFootnote interface to the first footnote inserted ('Numbers') - XFootnote xNumbers = ( XFootnote ) UnoRuntime.queryInterface ( + XFootnote xNumbers = ( XFootnote ) UnoRuntime.queryInterface ( XFootnote.class, xFootnotes.getByIndex( 0 ) ); // Get the XSimpleText interface to the Footnote XSimpleText xSimple = (XSimpleText ) UnoRuntime.queryInterface ( XSimpleText.class, xNumbers ); - + // Create a text cursor for the foot note text XTextRange xRange = (XTextRange ) UnoRuntime.queryInterface ( XTextRange.class, xSimple.createTextCursor() ); - + // And insert the actual text of the footnote. - xSimple.insertString ( + xSimple.insertString ( xRange, " The numbers were generated by using java.util.Random", false ); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - + /** This method demonstrates how to create and manipulate shapes, and how to access the draw page of the document to insert shapes */ @@ -1326,22 +1326,22 @@ public class TextDocuments { ControlCharacter.PARAGRAPH_BREAK, false); // Get the XParagraphCursor interface of our document cursor - XParagraphCursor xParaCursor = (XParagraphCursor) + XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // Position the cursor in the 2nd paragraph xParaCursor.gotoPreviousParagraph ( false ); - + // Create a RectangleShape using the document factory - XShape xRect = (XShape) UnoRuntime.queryInterface( + XShape xRect = (XShape) UnoRuntime.queryInterface( XShape.class, mxDocFactory.createInstance ( "com.sun.star.drawing.RectangleShape" ) ); - + // Create an EllipseShape using the document factory - XShape xEllipse = (XShape) UnoRuntime.queryInterface( - XShape.class, mxDocFactory.createInstance ( + XShape xEllipse = (XShape) UnoRuntime.queryInterface( + XShape.class, mxDocFactory.createInstance ( "com.sun.star.drawing.EllipseShape" ) ); - + // Set the size of both the ellipse and the rectangle Size aSize = new Size(); aSize.Height = 4000; @@ -1350,19 +1350,19 @@ public class TextDocuments { aSize.Height = 3000; aSize.Width = 6000; xEllipse.setSize ( aSize ); - + // Set the position of the Rectangle to the right of the ellipse Point aPoint = new Point(); aPoint.X = 6100; aPoint.Y = 0; xRect.setPosition ( aPoint ); - + // Get the XPropertySet interfaces of both shapes - XPropertySet xRectProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xRectProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xRect ); XPropertySet xEllipseProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xEllipse ); - + // And set the AnchorTypes of both shapes to 'AT_PARAGRAPH' xRectProps.setPropertyValue ( "AnchorType", TextContentAnchorType.AT_PARAGRAPH ); @@ -1374,20 +1374,20 @@ public class TextDocuments { UnoRuntime.queryInterface (XDrawPageSupplier.class, mxDoc ); // Get the XShapes interface of the draw page - XShapes xShapes = ( XShapes ) UnoRuntime.queryInterface ( + XShapes xShapes = ( XShapes ) UnoRuntime.queryInterface ( XShapes.class, xDrawPageSupplier.getDrawPage () ); - + // Add both shapes xShapes.add ( xEllipse ); xShapes.add ( xRect ); /* This doesn't work, I am assured that FME and AMA are fixing it. - - XShapes xGrouper = (XShapes) UnoRuntime.queryInterface( - XShapes.class, mxDocFactory.createInstance ( + + XShapes xGrouper = (XShapes) UnoRuntime.queryInterface( + XShapes.class, mxDocFactory.createInstance ( "com.sun.star.drawing.GroupShape" ) ); - + XShape xGrouperShape = (XShape) UnoRuntime.queryInterface( XShape.class, xGrouper ); xShapes.add ( xGrouperShape ); @@ -1399,14 +1399,14 @@ public class TextDocuments { UnoRuntime.queryInterface(XShapeGrouper.class, xShapes); xShapeGrouper.group ( xGrouper ); */ - + } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } - } - + } + /** This method demonstrates how to create, insert and apply styles */ protected void StylesExample () @@ -1415,36 +1415,36 @@ public class TextDocuments { { // Go to the end of the document mxDocCursor.gotoEnd( false ); - + // Insert two paragraph breaks - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - + // Create a new style from the document's factory - XStyle xStyle = (XStyle) UnoRuntime.queryInterface( - XStyle.class, mxDocFactory.createInstance( + XStyle xStyle = (XStyle) UnoRuntime.queryInterface( + XStyle.class, mxDocFactory.createInstance( "com.sun.star.style.ParagraphStyle" ) ); - + // Access the XPropertySet interface of the new style XPropertySet xStyleProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStyle ); - + // Give the new style a light blue background xStyleProps.setPropertyValue ( "ParaBackColor", new Integer (13421823)); - + // Get the StyleFamiliesSupplier interface of the document XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, mxDoc); // Use the StyleFamiliesSupplier interface to get the XNameAccess // interface of the actual style families - XNameAccess xFamilies = ( XNameAccess ) UnoRuntime.queryInterface ( + XNameAccess xFamilies = ( XNameAccess ) UnoRuntime.queryInterface ( XNameAccess.class, xSupplier.getStyleFamilies() ); // Access the 'ParagraphStyles' Family - XNameContainer xFamily = (XNameContainer ) UnoRuntime.queryInterface ( + XNameContainer xFamily = (XNameContainer ) UnoRuntime.queryInterface ( XNameContainer.class, xFamilies.getByName ( "ParagraphStyles" ) ); @@ -1452,7 +1452,7 @@ public class TextDocuments { xFamily.insertByName ( "All-Singing All-Dancing Style", xStyle ); // Get the XParagraphCursor interface of the document cursor - XParagraphCursor xParaCursor = (XParagraphCursor) + XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // Select the first paragraph inserted @@ -1469,20 +1469,20 @@ public class TextDocuments { // Go back to the end mxDocCursor.gotoEnd ( false ); - + // Select the last paragraph in the document xParaCursor.gotoNextParagraph ( true ); - + // And reset it's style to 'Standard' (the programmatic name for // the default style) xCursorProps.setPropertyValue ( "ParaStyleName", "Standard" ); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - + /** This method demonstrates how to set numbering types and numbering levels using the com.sun.star.text.NumberingRules service */ @@ -1493,7 +1493,7 @@ public class TextDocuments { // Go to the end of the document mxDocCursor.gotoEnd( false ); // Get the RelativeTextContentInsert interface of the document - XRelativeTextContentInsert xRelative = + XRelativeTextContentInsert xRelative = (XRelativeTextContentInsert ) UnoRuntime.queryInterface ( XRelativeTextContentInsert.class, mxDocText ); @@ -1516,10 +1516,10 @@ public class TextDocuments { XTextContent xNewPara = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, mxDocFactory.createInstance( "com.sun.star.text.Paragraph" ) ); - + // Get the XPropertySet interface of the new paragraph and put // it in our array - xParas[i] = (XPropertySet) UnoRuntime.queryInterface( + xParas[i] = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xNewPara ); // Insert the new paragraph into the document after the fish @@ -1538,44 +1538,44 @@ public class TextDocuments { { if ( aProps[j].Name.equals ( "NumberingType" ) ) { - // Once we find it, set it's value to a new type, + // Once we find it, set it's value to a new type, // dependent on which numbering level we're currently on switch ( i ) { - case 0 : aProps[j].Value = + case 0 : aProps[j].Value = new Short(NumberingType.ROMAN_UPPER); break; - case 1 : aProps[j].Value = + case 1 : aProps[j].Value = new Short(NumberingType.CHARS_UPPER_LETTER); break; - case 2 : aProps[j].Value = + case 2 : aProps[j].Value = new Short(NumberingType.ARABIC); break; } // Put the updated PropertyValue sequence back into the // NumberingRules service - xReplace.replaceByIndex ( i, aProps ); + xReplace.replaceByIndex ( i, aProps ); break; } } } // Get the XParagraphCursor interface of our text cursro - XParagraphCursor xParaCursor = (XParagraphCursor) + XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // Go to the end of the document, then select the preceding paragraphs mxDocCursor.gotoEnd ( false ); xParaCursor.gotoPreviousParagraph ( false ); xParaCursor.gotoPreviousParagraph ( true ); xParaCursor.gotoPreviousParagraph ( true ); - + // Get the XPropertySet of the cursor's currently selected text XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, mxDocCursor ); - + // Set the updated Numbering rules to the cursor's property set xCursorProps.setPropertyValue ( "NumberingRules", xNum ); mxDocCursor.gotoEnd( false ); - + // Set the first paragraph that was inserted to a numbering level of // 2 (thus it will have Arabic style numbering) xParas[0].setPropertyValue ( "NumberingLevel", new Short((short) 2)); @@ -1588,13 +1588,13 @@ public class TextDocuments { // 0 (thus it will have 'Chars Upper Letter' style numbering) xParas[2].setPropertyValue ( "NumberingLevel", new Short((short) 0)); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - - /** This method demonstrates how to create linked and unlinked sections + + /** This method demonstrates how to create linked and unlinked sections */ protected void TextSectionExample () { @@ -1603,11 +1603,11 @@ public class TextDocuments { // Go to the end of the document mxDocCursor.gotoEnd( false ); // Insert two paragraph breaks - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, true ); - + // Create a new TextSection from the document factory and access // it's XNamed interface XNamed xChildNamed = (XNamed) UnoRuntime.queryInterface( @@ -1615,7 +1615,7 @@ public class TextDocuments { "com.sun.star.text.TextSection" ) ); // Set the new sections name to 'Child_Section' xChildNamed.setName ( "Child_Section" ); - + // Access the Child_Section's XTextContent interface and insert it // into the document XTextContent xChildSection = (XTextContent) UnoRuntime.queryInterface( @@ -1628,10 +1628,10 @@ public class TextDocuments { // Go back one paragraph (into Child_Section) xParaCursor.gotoPreviousParagraph ( false ); - + // Insert a string into the Child_Section mxDocText.insertString ( mxDocCursor, "This is a test", false ); - + // Go to the end of the document mxDocCursor.gotoEnd( false ); @@ -1640,63 +1640,63 @@ public class TextDocuments { xParaCursor.gotoPreviousParagraph ( false ); // Go to the end of the document, selecting the two paragraphs mxDocCursor.gotoEnd ( true ); - + // Create another text section and access it's XNamed interface XNamed xParentNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); // Set this text section's name to Parent_Section xParentNamed.setName ( "Parent_Section" ); - + // Access the Parent_Section's XTextContent interface ... XTextContent xParentSection = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xParentNamed ); // ...and insert it into the document mxDocText.insertTextContent ( mxDocCursor, xParentSection, false ); - + // Go to the end of the document mxDocCursor.gotoEnd ( false ); // Insert a new paragraph - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // And select the new pargraph xParaCursor.gotoPreviousParagraph ( true ); - + // Create a new Text Section and access it's XNamed interface XNamed xLinkNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); // Set the new text section's name to Linked_Section xLinkNamed.setName ( "Linked_Section" ); - + // Access the Linked_Section's XTextContent interface XTextContent xLinkedSection = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xLinkNamed ); // And insert the Linked_Section into the document mxDocText.insertTextContent ( mxDocCursor, xLinkedSection, false ); - + // Access the Linked_Section's XPropertySet interface - XPropertySet xLinkProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xLinkProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, xLinkNamed ); // Set the linked section to be linked to the Child_Section xLinkProps.setPropertyValue ( "LinkRegion", "Child_Section" ); - + // Access the XPropertySet interface of the Child_Section XPropertySet xChildProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xChildNamed ); // Set the Child_Section's background colour to blue xChildProps.setPropertyValue( "BackColor", new Integer(13421823)); - + // Refresh the document, so the linked section matches the Child_Section - XRefreshable xRefresh = (XRefreshable) UnoRuntime.queryInterface( + XRefreshable xRefresh = (XRefreshable) UnoRuntime.queryInterface( XRefreshable.class, mxDoc ); xRefresh.refresh(); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } } - + /** This method demonstrates the XTextColumns interface and how to insert a blank paragraph using the XRelativeTextContentInsert interface */ @@ -1707,36 +1707,36 @@ public class TextDocuments { // Go to the end of the doucment mxDocCursor.gotoEnd( false ); // insert a new paragraph - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - + // insert the string 'I am a fish.' 100 times for ( int i = 0 ; i < 100 ; ++i ) { mxDocText.insertString ( mxDocCursor, "I am a fish.", false ); } // insert a paragraph break after the text - mxDocText.insertControlCharacter ( + mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - + // Get the XParagraphCursor interface of our text cursor - XParagraphCursor xParaCursor = (XParagraphCursor) + XParagraphCursor xParaCursor = (XParagraphCursor) UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // Jump back before all the text we just inserted xParaCursor.gotoPreviousParagraph ( false ); xParaCursor.gotoPreviousParagraph ( false ); - + // Insert a string at the beginning of the block of text mxDocText.insertString ( mxDocCursor, "Fish section begins:", false ); - + // Then select all of the text xParaCursor.gotoNextParagraph ( true ); xParaCursor.gotoNextParagraph ( true ); - + // Create a new text section and get it's XNamed interface XNamed xSectionNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); - + // Set the name of our new section (appropiately) to 'Fish' xSectionNamed.setName ( "Fish" ); @@ -1747,7 +1747,7 @@ public class TextDocuments { // We want three columns xColumns.setColumnCount ( (short) 3 ); - + // Get the TextColumns, and make the middle one narrow with a larger // margin on the left than the right TextColumn[] aSequence = xColumns.getColumns (); @@ -1756,26 +1756,26 @@ public class TextDocuments { aSequence[1].RightMargin = 200; // Set the updated TextColumns back to the XTextColumns xColumns.setColumns ( aSequence ); - + // Get the property set interface of our 'Fish' section XPropertySet xSectionProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSectionNamed ); - + // Set the columns to the Text Section xSectionProps.setPropertyValue ( "TextColumns", xColumns ); - + // Get the XTextContent interface of our 'Fish' section mxFishSection = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, xSectionNamed ); - + // Insert the 'Fish' section over the currently selected text mxDocText.insertTextContent ( mxDocCursor, mxFishSection, true ); - + // Get the wonderful XRelativeTextContentInsert interface XRelativeTextContentInsert xRelative = (XRelativeTextContentInsert ) UnoRuntime.queryInterface ( XRelativeTextContentInsert.class, mxDocText ); - + // Create a new empty paragraph and get it's XTextContent interface XTextContent xNewPara = (XTextContent) UnoRuntime.queryInterface( XTextContent.class, @@ -1784,9 +1784,9 @@ public class TextDocuments { // Insert the empty paragraph after the fish Text Section xRelative.insertTextContentAfter ( xNewPara, mxFishSection ); } - catch (Exception e) + catch (Exception e) { e.printStackTrace(); } - } + } } |