forked from amazingfate/loongoffice
Java cleanup, remove the rest of the unnecessary casts
Change-Id: Ia61d250f6b3711abc29569c5ece38a6f87e38daa Reviewed-on: https://gerrit.libreoffice.org/3432 Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org> Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
This commit is contained in:
committed by
Fridrich Strba
parent
d62425cc27
commit
8d87758d65
@ -62,9 +62,8 @@ public class TextDocumentStructure {
|
||||
// get the component laoder from the desktop to create a new
|
||||
// text document
|
||||
com.sun.star.frame.XComponentLoader xCLoader =
|
||||
(com.sun.star.frame.XComponentLoader)
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.frame.XComponentLoader.class,oDesktop);
|
||||
com.sun.star.frame.XComponentLoader.class,oDesktop);
|
||||
com.sun.star.beans.PropertyValue [] szEmptyArgs =
|
||||
new com.sun.star.beans.PropertyValue [0];
|
||||
String strDoc = "private:factory/swriter";
|
||||
@ -76,8 +75,8 @@ public class TextDocumentStructure {
|
||||
|
||||
// query the new document for the XTextDocument interface
|
||||
com.sun.star.text.XTextDocument xTextDocument =
|
||||
(com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XTextDocument.class, xComp);
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XTextDocument.class, xComp);
|
||||
|
||||
// create some example data
|
||||
com.sun.star.text.XText xText = xTextDocument.getText();
|
||||
@ -94,20 +93,18 @@ public class TextDocumentStructure {
|
||||
System.out.println("create an enumeration of all paragraphs");
|
||||
// create an enumeration access of all paragraphs of a document
|
||||
com.sun.star.container.XEnumerationAccess xEnumerationAccess =
|
||||
(com.sun.star.container.XEnumerationAccess)
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.container.XEnumerationAccess.class, xText);
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.container.XEnumerationAccess.class, xText);
|
||||
xParagraphEnumeration = xEnumerationAccess.createEnumeration();
|
||||
|
||||
// Loop through all paragraphs of the document
|
||||
while ( xParagraphEnumeration.hasMoreElements() ) {
|
||||
xTextElement = (com.sun.star.text.XTextContent)
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XTextContent.class,
|
||||
xParagraphEnumeration.nextElement());
|
||||
xTextElement = UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XTextContent.class,
|
||||
xParagraphEnumeration.nextElement());
|
||||
com.sun.star.lang.XServiceInfo xServiceInfo =
|
||||
(com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
|
||||
com.sun.star.lang.XServiceInfo.class, xTextElement);
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.lang.XServiceInfo.class, xTextElement);
|
||||
|
||||
// check ifs the current paragraph really a paragraph or an
|
||||
// anchor of a frame or picture
|
||||
@ -119,34 +116,31 @@ public class TextDocumentStructure {
|
||||
// create another enumeration to get all text portions of
|
||||
// the paragraph
|
||||
xParaEnumerationAccess =
|
||||
(com.sun.star.container.XEnumerationAccess)
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.container.XEnumerationAccess.class,
|
||||
xTextElement);
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.container.XEnumerationAccess.class,
|
||||
xTextElement);
|
||||
xTextPortionEnum = xParaEnumerationAccess.createEnumeration();
|
||||
|
||||
while ( xTextPortionEnum.hasMoreElements() ) {
|
||||
com.sun.star.text.XTextRange xTextPortion =
|
||||
(com.sun.star.text.XTextRange)UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XTextRange.class,
|
||||
xTextPortionEnum.nextElement());
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XTextRange.class,
|
||||
xTextPortionEnum.nextElement());
|
||||
System.out.println( "Text from the portion : "
|
||||
+ xTextPortion.getString() );
|
||||
|
||||
com.sun.star.beans.XPropertySet xPropertySet =
|
||||
(com.sun.star.beans.XPropertySet)
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.beans.XPropertySet.class,
|
||||
xTextPortion);
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.beans.XPropertySet.class,
|
||||
xTextPortion);
|
||||
System.out.println( "Name of the font : "
|
||||
+ xPropertySet.getPropertyValue( "CharFontName" ) );
|
||||
|
||||
// PropertyState status of each text portion.
|
||||
com.sun.star.beans.XPropertyState xPropertyState =
|
||||
(com.sun.star.beans.XPropertyState)
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.beans.XPropertyState.class,
|
||||
xTextPortion);
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.beans.XPropertyState.class,
|
||||
xTextPortion);
|
||||
|
||||
if( xPropertyState.getPropertyState("CharWeight").equals(
|
||||
com.sun.star.beans.PropertyState.AMBIGUOUS_VALUE) )
|
||||
@ -181,16 +175,16 @@ public class TextDocumentStructure {
|
||||
xText.setString( "This is an example sentence" );
|
||||
|
||||
com.sun.star.text.XWordCursor xWordCursor =
|
||||
(com.sun.star.text.XWordCursor)UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XWordCursor.class, xText.getStart());
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.text.XWordCursor.class, xText.getStart());
|
||||
|
||||
xWordCursor.gotoNextWord(false);
|
||||
xWordCursor.gotoNextWord(false);
|
||||
xWordCursor.gotoEndOfWord(true);
|
||||
|
||||
com.sun.star.beans.XPropertySet xPropertySet =
|
||||
(com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
|
||||
com.sun.star.beans.XPropertySet.class, xWordCursor );
|
||||
UnoRuntime.queryInterface(
|
||||
com.sun.star.beans.XPropertySet.class, xWordCursor );
|
||||
xPropertySet.setPropertyValue("CharWeight",
|
||||
new Float( com.sun.star.awt.FontWeight.BOLD ));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user