diff options
Diffstat (limited to 'odk/examples/java/Text/TextReplace.java')
-rw-r--r-- | odk/examples/java/Text/TextReplace.java | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/odk/examples/java/Text/TextReplace.java b/odk/examples/java/Text/TextReplace.java index 980b955e990f..86ce7a4d2e18 100644 --- a/odk/examples/java/Text/TextReplace.java +++ b/odk/examples/java/Text/TextReplace.java @@ -66,13 +66,11 @@ public class TextReplace { com.sun.star.util.XSearchDescriptor xSearchDescriptor = null; com.sun.star.util.XReplaceable xReplaceable = null; - xReplaceable = (com.sun.star.util.XReplaceable) - UnoRuntime.queryInterface( - com.sun.star.util.XReplaceable.class, xTextDocument); + xReplaceable = UnoRuntime.queryInterface( + com.sun.star.util.XReplaceable.class, xTextDocument); // You need a descriptor to set properies for Replace - xReplaceDescr = (com.sun.star.util.XReplaceDescriptor) - xReplaceable.createReplaceDescriptor(); + xReplaceDescr = xReplaceable.createReplaceDescriptor(); System.out.println("Change all occurrences of ..."); for( int iArrayCounter = 0; iArrayCounter < mBritishWords.length; @@ -106,18 +104,15 @@ public class TextReplace { com.sun.star.text.XTextCursor xTextCursor = null; try { - xTextCursor = (com.sun.star.text.XTextCursor) - xTextDocument.getText().createTextCursor(); - com.sun.star.text.XText xText = (com.sun.star.text.XText) - xTextDocument.getText(); + xTextCursor = xTextDocument.getText().createTextCursor(); + com.sun.star.text.XText xText = xTextDocument.getText(); xText.insertString( xTextCursor, "He nervously looked all around. Suddenly he saw his ", false ); xText.insertString( xTextCursor, "neighbour ", true ); - com.sun.star.beans.XPropertySet xCPS = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, xTextCursor); + com.sun.star.beans.XPropertySet xCPS = UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xTextCursor); // Set the word blue xCPS.setPropertyValue( "CharColor", new Integer( 255 ) ); // Go to last character @@ -127,7 +122,7 @@ public class TextReplace { xText.insertString( xTextCursor, "in the alley. Like lightening he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the ", false ); xText.insertString( xTextCursor, "centre ", true ); - xCPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + xCPS = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xTextCursor); // Set the word blue xCPS.setPropertyValue( "CharColor", new Integer( 255 ) ); @@ -166,7 +161,7 @@ public class TextReplace { Object oDesktop = xMCF.createInstanceWithContext( "com.sun.star.frame.Desktop", xContext); - xDesktop = (com.sun.star.frame.XDesktop) UnoRuntime.queryInterface( + xDesktop = UnoRuntime.queryInterface( com.sun.star.frame.XDesktop.class, oDesktop); } else @@ -189,9 +184,8 @@ public class TextReplace { try { com.sun.star.lang.XComponent xComponent = CreateNewDocument(xDesktop, "swriter"); - aTextDocument = (com.sun.star.text.XTextDocument) - UnoRuntime.queryInterface( - com.sun.star.text.XTextDocument.class, xComponent); + aTextDocument = UnoRuntime.queryInterface( + com.sun.star.text.XTextDocument.class, xComponent); } catch( Exception e) { e.printStackTrace(System.err); @@ -215,9 +209,8 @@ public class TextReplace { new com.sun.star.beans.PropertyValue[0]; try { - xComponentLoader = (com.sun.star.frame.XComponentLoader) - UnoRuntime.queryInterface( - com.sun.star.frame.XComponentLoader.class, xDesktop); + xComponentLoader = UnoRuntime.queryInterface( + com.sun.star.frame.XComponentLoader.class, xDesktop); xComponent = xComponentLoader.loadComponentFromURL( sURL, "_blank", 0, xEmptyArgs); |