Hi  

I am already working with XStyle. See my code below:

  protected void Example (XComponent xComp)
  {
      try
      {
        
        
        XTextDocument xTextDocument = (XTextDocument)
        UnoRuntime.queryInterface(XTextDocument.class, xComp);

        XText xText = xTextDocument.getText();
        XTextCursor curText = xText.createTextCursor();
        
          // Go to the end of the document
        //curText.gotoEnd( false );
        curText.gotoEnd( false );
          
        XMultiServiceFactory mxDocFactory = (XMultiServiceFactory)
UnoRuntime
        .queryInterface(XMultiServiceFactory.class,xTextDocument); 

          
          // Create a new style from the document's factory
          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));
          xStyleProps.setPropertyValue("ParaLeftMargin", new Integer(200));
          xStyleProps.setPropertyValue("ParaFirstLineIndent", new
Integer(2500));
          xStyleProps.setPropertyValue("ParaLineNumberCount",Boolean.TRUE);     
    
          LineSpacing linha = new LineSpacing();
          linha.Height = 150;
          linha.Mode = LineSpacingMode.PROP;
          xStyleProps.setPropertyValue("ParaLineSpacing", linha);
          xStyleProps.setPropertyValue("ParaAdjust", ParagraphAdjust.BLOCK);
          xStyleProps.setPropertyValue("ParaRightMargin", new Integer(100));
          
          // Get the StyleFamiliesSupplier interface of the document
          XStyleFamiliesSupplier xSupplier = (XStyleFamiliesSupplier)
              UnoRuntime.queryInterface(XStyleFamiliesSupplier.class,
xTextDocument);

          // Use the StyleFamiliesSupplier interface to get the XNameAccess
          // interface of the actual style families
          XNameAccess xFamilies = ( XNameAccess ) UnoRuntime.queryInterface
( 
              XNameAccess.class, xSupplier.getStyleFamilies() );

          // Access the 'ParagraphStyles' Family
          XNameContainer xFamily = (XNameContainer )
UnoRuntime.queryInterface ( 
                      XNameContainer.class,
                      xFamilies.getByName ( "ParagraphStyles" ) );

          // Insert the newly created style into the ParagraphStyles family
          xFamily.insertByName ( "All-Singing All-Dancing Style", xStyle );

          // Get the XParagraphCursor interface of the document cursor
          XParagraphCursor xParaCursor = (XParagraphCursor) 
              UnoRuntime.queryInterface( XParagraphCursor.class, curText );
          
          curText.gotoEnd ( false );
          xParaCursor.gotoPreviousParagraph ( false );
          xParaCursor.gotoPreviousParagraph ( true );
          xParaCursor.gotoPreviousParagraph ( true );

          
          // Select the first paragraph inserted
          //xParaCursor.gotoPreviousParagraph ( false );
          //xParaCursor.gotoPreviousParagraph ( true );
          
          // Access the property set of the cursor selection
          XPropertySet xCursorProps = (XPropertySet)
UnoRuntime.queryInterface(
              XPropertySet.class, curText );         

          // Set the style of the cursor selection to our newly created
style
          xCursorProps.setPropertyValue ( "ParaStyleName",
                                          "All-Singing All-Dancing Style" );

          // Go back to the end
          //curText.gotoEnd ( false );
          curText.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", "All-Singing
All-Dancing Style" );
      }
      catch (Exception e) 
      {
          e.printStackTrace();
      }
  }



Cor Nouws wrote:
> 
> Hi Aloizio,
> 
> aloizio wrote:
> 
>> I am trying to select all paragraph into the document. I am using the
>> following:
>> 
>>           // Get the XParagraphCursor interface of the document cursor
>>           XParagraphCursor xParaCursor = (XParagraphCursor) 
>>               UnoRuntime.queryInterface( XParagraphCursor.class, curText
>> );
>> 
>>           // Select all  paragraphs inserted
>>           xParaCursor. ?????????? 
> 
> I do not work with Java. I know in the Basic libraries under Tools, 
> there are some useful examples.
> If you stil do not work with the praragraph style ;-) you could create a 
> viewcursor at the start, and extend it to the end of the doc. Pls see 
> the examples.
> 
> Greetings,
> Cor
> 
> -- 
> 
> Cor Nouws
> Arnhem - Netherlands
> nl.OpenOffice.org - marketing contact
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-can-I-select-all-paragraphs-from-a-Text--tf2624653.html#a7324848
Sent from the openoffice - api dev mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to