summaryrefslogtreecommitdiff
path: root/odk/examples/java/Text
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2013-04-17 14:59:35 +0200
committerFridrich Strba <fridrich@documentfoundation.org>2013-04-19 07:52:08 +0000
commit8d87758d65e4a03271f76e354dfc84c1fcd5fe21 (patch)
treebc8f4f0df6981ad10fe1333db1a2b015ea079709 /odk/examples/java/Text
parentd62425cc27e04a3237cfec2ea2663b8b11284ec8 (diff)
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>
Diffstat (limited to 'odk/examples/java/Text')
-rw-r--r--odk/examples/java/Text/BookmarkInsertion.java50
-rw-r--r--odk/examples/java/Text/GraphicsInserter.java27
-rw-r--r--odk/examples/java/Text/HardFormatting.java42
-rw-r--r--odk/examples/java/Text/SWriter.java42
-rw-r--r--odk/examples/java/Text/StyleCreation.java34
-rw-r--r--odk/examples/java/Text/StyleInitialization.java59
-rw-r--r--odk/examples/java/Text/TextDocumentStructure.java58
-rw-r--r--odk/examples/java/Text/TextReplace.java33
-rw-r--r--odk/examples/java/Text/WriterSelector.java48
9 files changed, 169 insertions, 224 deletions
diff --git a/odk/examples/java/Text/BookmarkInsertion.java b/odk/examples/java/Text/BookmarkInsertion.java
index ced4ddb4984c..fee990dc653c 100644
--- a/odk/examples/java/Text/BookmarkInsertion.java
+++ b/odk/examples/java/Text/BookmarkInsertion.java
@@ -84,14 +84,13 @@ public class BookmarkInsertion {
try {
for( iCounter = 0; iCounter < mList.length; iCounter++ ) {
// the findfirst returns a XInterface
- xSearchInterface = (com.sun.star.uno.XInterface)FindFirst(
+ xSearchInterface = FindFirst(
xTextDocument, mList[ iCounter ] );
if( xSearchInterface != null ) {
// get the TextRange form the XInterface
- xSearchTextRange = (com.sun.star.text.XTextRange)
- UnoRuntime.queryInterface(
- com.sun.star.text.XTextRange.class, xSearchInterface);
+ xSearchTextRange = UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class, xSearchInterface);
InsertBookmark(xTextDocument, xSearchTextRange,
sPrefix + iCounter);
@@ -112,9 +111,8 @@ public class BookmarkInsertion {
try {
// get the MultiServiceFactory from the text document
com.sun.star.lang.XMultiServiceFactory xDocMSF;
- xDocMSF = (com.sun.star.lang.XMultiServiceFactory)
- UnoRuntime.queryInterface(
- com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+ xDocMSF = UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
// the bookmark service is a context dependend service, you need
// the MultiServiceFactory from the document
@@ -122,17 +120,15 @@ public class BookmarkInsertion {
// set the name from the bookmark
com.sun.star.container.XNamed xNameAccess = null;
- xNameAccess = (com.sun.star.container.XNamed)
- UnoRuntime.queryInterface(
- com.sun.star.container.XNamed.class, xObject);
+ xNameAccess = UnoRuntime.queryInterface(
+ com.sun.star.container.XNamed.class, xObject);
xNameAccess.setName(sBookName);
// create a XTextContent, for the method 'insertTextContent'
com.sun.star.text.XTextContent xTextContent = null;
- xTextContent = (com.sun.star.text.XTextContent)
- UnoRuntime.queryInterface(
- com.sun.star.text.XTextContent.class, xNameAccess);
+ xTextContent = UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class, xNameAccess);
// insertTextContent need a TextRange not a cursor to specify the
// position from the bookmark
@@ -153,18 +149,15 @@ public class BookmarkInsertion {
com.sun.star.uno.XInterface xSearchInterface = null;
try {
- xSearchable = (com.sun.star.util.XSearchable)
- UnoRuntime.queryInterface(
- com.sun.star.util.XSearchable.class, xTextDocument);
- xSearchDescriptor = (com.sun.star.util.XSearchDescriptor)
- xSearchable.createSearchDescriptor();
+ xSearchable = UnoRuntime.queryInterface(
+ com.sun.star.util.XSearchable.class, xTextDocument);
+ xSearchDescriptor = xSearchable.createSearchDescriptor();
xSearchDescriptor.setSearchString(sSearchString);
com.sun.star.beans.XPropertySet xPropertySet = null;
- xPropertySet = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xSearchDescriptor);
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xSearchDescriptor);
xPropertySet.setPropertyValue("SearchRegularExpression",
new Boolean( true ) );
@@ -185,8 +178,7 @@ public class BookmarkInsertion {
com.sun.star.text.XTextCursor xTextCursor = null;
try {
- xTextCursor = (com.sun.star.text.XTextCursor)
- xTextDocument.getText().createTextCursor();
+ xTextCursor = xTextDocument.getText().createTextCursor();
xTextCursor.setString( "He heard quiet steps behind him. That didn't bode well. Who could be following him this late at night and in this deadbeat part of town? And at this particular moment, just after he pulled off the big time and was making off with the greenbacks. Was there another crook who'd had the same idea, and was now watching him and waiting for a chance to grab the fruit of his labor?" );
xTextCursor.collapseToEnd();
@@ -219,7 +211,7 @@ public class BookmarkInsertion {
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
@@ -242,9 +234,8 @@ public class BookmarkInsertion {
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);
@@ -268,9 +259,8 @@ public class BookmarkInsertion {
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);
diff --git a/odk/examples/java/Text/GraphicsInserter.java b/odk/examples/java/Text/GraphicsInserter.java
index 866da1c0849f..d2078f76b9db 100644
--- a/odk/examples/java/Text/GraphicsInserter.java
+++ b/odk/examples/java/Text/GraphicsInserter.java
@@ -68,14 +68,13 @@ public class GraphicsInserter {
frames in which components can be loaded. Desktop is the
environment for components which can instanciate within
frames. */
- com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
- UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
- xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
- xContext ) );
+ com.sun.star.frame.XDesktop xDesktop = UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
com.sun.star.frame.XComponentLoader xCompLoader =
- (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
- com.sun.star.frame.XComponentLoader.class, xDesktop);
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
// Load a Writer document, which will be automaticly displayed
com.sun.star.lang.XComponent xComp = xCompLoader.loadComponentFromURL(
@@ -84,13 +83,13 @@ public class GraphicsInserter {
// Querying for the interface XTextDocument on the xcomponent
com.sun.star.text.XTextDocument xTextDoc =
- (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface(
- com.sun.star.text.XTextDocument.class, xComp);
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextDocument.class, xComp);
// Querying for the interface XMultiServiceFactory on the xtextdocument
com.sun.star.lang.XMultiServiceFactory xMSFDoc =
- (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
- com.sun.star.lang.XMultiServiceFactory.class, xTextDoc);
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDoc);
// Providing a log file for output
PrintWriter printwriterLog = new PrintWriter(
@@ -115,8 +114,8 @@ public class GraphicsInserter {
// Querying for the interface XTextContent on the GraphicObject
com.sun.star.text.XTextContent xTextContent =
- (com.sun.star.text.XTextContent)UnoRuntime.queryInterface(
- com.sun.star.text.XTextContent.class, oGraphic );
+ UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class, oGraphic );
// Printing information to the log file
printwriterLog.println( "inserting graphic" );
@@ -133,8 +132,8 @@ public class GraphicsInserter {
// Querying for the interface XPropertySet on GraphicObject
com.sun.star.beans.XPropertySet xPropSet =
- (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, oGraphic);
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, oGraphic);
try {
// Creating a string for the graphic url
java.io.File sourceFile = new java.io.File(args[0]);
diff --git a/odk/examples/java/Text/HardFormatting.java b/odk/examples/java/Text/HardFormatting.java
index 9fff431acc52..b94f62064833 100644
--- a/odk/examples/java/Text/HardFormatting.java
+++ b/odk/examples/java/Text/HardFormatting.java
@@ -69,8 +69,7 @@ public class HardFormatting {
// you travel only at the model, not at the view. The cursor that you can
// see on the document doesn't change the position
com.sun.star.text.XTextCursor xTextCursor = null;
- xTextCursor = (com.sun.star.text.XTextCursor)
- xTextDocument.getText().createTextCursor();
+ xTextCursor = xTextDocument.getText().createTextCursor();
xText.insertString( xTextCursor, "Headline", false );
xText.insertControlCharacter(xTextCursor,
@@ -84,15 +83,13 @@ public class HardFormatting {
// BEGIN: 'Hard formating'
// the text range not the cursor contains the 'parastyle' property
xTextRange = xText.getEnd();
- xPropertySet = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xTextRange);
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange);
// create a paragraph cursor to travel throught the paragraphs
com.sun.star.text.XParagraphCursor xParagraphCursor = null;
- xParagraphCursor = (com.sun.star.text.XParagraphCursor)
- UnoRuntime.queryInterface(
- com.sun.star.text.XParagraphCursor.class, xTextRange);
+ xParagraphCursor = UnoRuntime.queryInterface(
+ com.sun.star.text.XParagraphCursor.class, xTextRange);
xParagraphCursor.gotoStart( false );
xParagraphCursor.gotoEndOfParagraph( true );
@@ -100,13 +97,12 @@ public class HardFormatting {
// create a WordCursor to travel into the paragraph
com.sun.star.text.XWordCursor xWordCursor = null;
- xWordCursor = (com.sun.star.text.XWordCursor) UnoRuntime.queryInterface(
+ xWordCursor = UnoRuntime.queryInterface(
com.sun.star.text.XWordCursor.class, xTextRange);
// the PropertySet from the cursor contains the text attributes
- xPropertySet = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xWordCursor);
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
System.out.println(
"Parastyle : "
+xPropertySet.getPropertyValue("ParaStyleName").toString()
@@ -119,9 +115,8 @@ public class HardFormatting {
xWordCursor.gotoNextWord(false);
xWordCursor.gotoEndOfWord(true);
- xPropertySet = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xWordCursor);
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xWordCursor);
xPropertySet.setPropertyValue("CharWeight",
new Float(com.sun.star.awt.FontWeight.BOLD));
xPropertySet.setPropertyValue("CharColor", new Integer( 255 ) );
@@ -137,9 +132,8 @@ public class HardFormatting {
// the PropertyState contains information where the attribute is set,
// is a text part hard formated or not.
com.sun.star.beans.XPropertyState xPropertyState = null;
- xPropertyState = (com.sun.star.beans.XPropertyState)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertyState.class, xWordCursor);
+ xPropertyState = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertyState.class, xWordCursor);
com.sun.star.beans.PropertyState xPropertyStateValue =
xPropertyState.getPropertyState("CharWeight");
@@ -221,7 +215,7 @@ public class HardFormatting {
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
@@ -244,9 +238,8 @@ public class HardFormatting {
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);
@@ -270,9 +263,8 @@ public class HardFormatting {
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);
diff --git a/odk/examples/java/Text/SWriter.java b/odk/examples/java/Text/SWriter.java
index 18ae35481189..7b79bc817997 100644
--- a/odk/examples/java/Text/SWriter.java
+++ b/odk/examples/java/Text/SWriter.java
@@ -116,16 +116,15 @@ public class SWriter {
//getting MSF of the document
com.sun.star.lang.XMultiServiceFactory xDocMSF =
- (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface(
- com.sun.star.lang.XMultiServiceFactory.class, myDoc);
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, myDoc);
//create instance of a text table
com.sun.star.text.XTextTable xTT = null;
try {
Object oInt = xDocMSF.createInstance("com.sun.star.text.TextTable");
- xTT = (com.sun.star.text.XTextTable)
- UnoRuntime.queryInterface(com.sun.star.text.XTextTable.class,oInt);
+ xTT = UnoRuntime.queryInterface(com.sun.star.text.XTextTable.class,oInt);
} catch (Exception e) {
System.err.println("Couldn't create instance "+ e);
e.printStackTrace(System.err);
@@ -141,7 +140,7 @@ public class SWriter {
xText.insertTextContent(xTCursor, xTT, false);
// get first Row
com.sun.star.container.XIndexAccess xTTRows = xTT.getRows();
- xTTRowPS = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
+ xTTRowPS = UnoRuntime.queryInterface(
com.sun.star.beans.XPropertySet.class, xTTRows.getByIndex(0));
} catch (Exception e) {
@@ -152,8 +151,7 @@ public class SWriter {
// get the property set of the text table
- com.sun.star.beans.XPropertySet xTTPS = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT);
+ com.sun.star.beans.XPropertySet xTTPS = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTT);
// Change the BackColor
try {
@@ -202,9 +200,8 @@ public class SWriter {
//*************************************************************************
// get the property set of the cursor
- com.sun.star.beans.XPropertySet xTCPS = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
- xTCursor);
+ com.sun.star.beans.XPropertySet xTCPS = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class,
+ xTCursor);
Object oldValue = null;
@@ -257,9 +254,9 @@ public class SWriter {
try {
Object oInt = xDocMSF.createInstance("com.sun.star.text.TextFrame");
- xTF = (com.sun.star.text.XTextFrame) UnoRuntime.queryInterface(
+ xTF = UnoRuntime.queryInterface(
com.sun.star.text.XTextFrame.class,oInt);
- xTFS = (com.sun.star.drawing.XShape) UnoRuntime.queryInterface(
+ xTFS = UnoRuntime.queryInterface(
com.sun.star.drawing.XShape.class,oInt);
com.sun.star.awt.Size aSize = new com.sun.star.awt.Size();
@@ -273,8 +270,7 @@ public class SWriter {
}
// get the property set of the text frame
- com.sun.star.beans.XPropertySet xTFPS = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTF);
+ com.sun.star.beans.XPropertySet xTFPS = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTF);
// Change the AnchorType
try {
@@ -352,16 +348,14 @@ public class SWriter {
Object oDesktop = xMCF.createInstanceWithContext(
"com.sun.star.frame.Desktop", xContext);
- xCLoader = (com.sun.star.frame.XComponentLoader)
- UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,
- oDesktop);
+ xCLoader = UnoRuntime.queryInterface(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";
xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs);
- xDoc = (com.sun.star.text.XTextDocument)
- UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
- xComp);
+ xDoc = UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComp);
} catch(Exception e){
System.err.println(" Exception " + e);
@@ -373,15 +367,13 @@ public class SWriter {
public static void insertIntoCell(String CellName, String theText,
com.sun.star.text.XTextTable xTTbl) {
- com.sun.star.text.XText xTableText = (com.sun.star.text.XText)
- UnoRuntime.queryInterface(com.sun.star.text.XText.class,
- xTTbl.getCellByName(CellName));
+ com.sun.star.text.XText xTableText = UnoRuntime.queryInterface(com.sun.star.text.XText.class,
+ xTTbl.getCellByName(CellName));
//create a cursor object
com.sun.star.text.XTextCursor xTC = xTableText.createTextCursor();
- com.sun.star.beans.XPropertySet xTPS = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC);
+ com.sun.star.beans.XPropertySet xTPS = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, xTC);
try {
xTPS.setPropertyValue("CharColor",new Integer(16777215));
diff --git a/odk/examples/java/Text/StyleCreation.java b/odk/examples/java/Text/StyleCreation.java
index 91cfb3f7a8c6..f32b6672dfae 100644
--- a/odk/examples/java/Text/StyleCreation.java
+++ b/odk/examples/java/Text/StyleCreation.java
@@ -60,8 +60,8 @@ public class StyleCreation {
// the service '..ParagraphStyle' is context dependend, you need
// the multi service factory from the document to use the service
com.sun.star.lang.XMultiServiceFactory xDocMSF =
- (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface(
- com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XMultiServiceFactory.class, xTextDocument);
// use the service 'com.sun.star.style.ParagraphStyle'
com.sun.star.uno.XInterface xInterface = (com.sun.star.uno.XInterface)
@@ -69,8 +69,8 @@ public class StyleCreation {
// create a supplier to get the Style family collection
com.sun.star.style.XStyleFamiliesSupplier xSupplier =
- (com.sun.star.style.XStyleFamiliesSupplier)UnoRuntime.queryInterface(
- com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
+ UnoRuntime.queryInterface(
+ com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
// get the NameAccess interface from the Style family collection
com.sun.star.container.XNameAccess xNameAccess =
@@ -78,14 +78,14 @@ public class StyleCreation {
// select the Paragraph styles, you get the Paragraph style collection
com.sun.star.container.XNameContainer xParaStyleCollection =
- (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(
- com.sun.star.container.XNameContainer.class,
- xNameAccess.getByName("ParagraphStyles"));
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XNameContainer.class,
+ xNameAccess.getByName("ParagraphStyles"));
// create a PropertySet to set the properties for the new Paragraphstyle
com.sun.star.beans.XPropertySet xPropertySet =
- (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xInterface );
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xInterface );
System.out.println( "create a PropertySet to set the properties for the new Paragraphstyle" );
// set some properties from the Paragraph style
@@ -122,8 +122,8 @@ public class StyleCreation {
// get the PropertySet from the current paragraph
com.sun.star.beans.XPropertySet xParagraphPropertySet =
- (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xTextRange );
+ UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
// change the value from the property 'ParaStyle' to apply the
// Paragraph style
// To run the sample with StarOffice 5.2 you'll have to change
@@ -160,7 +160,7 @@ public class StyleCreation {
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
@@ -183,9 +183,8 @@ public class StyleCreation {
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);
@@ -209,9 +208,8 @@ public class StyleCreation {
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);
diff --git a/odk/examples/java/Text/StyleInitialization.java b/odk/examples/java/Text/StyleInitialization.java
index c08243609499..e092a3634fb9 100644
--- a/odk/examples/java/Text/StyleInitialization.java
+++ b/odk/examples/java/Text/StyleInitialization.java
@@ -70,12 +70,10 @@ public class StyleInitialization {
// you travel only at the model, not at the view. The cursor that you can
// see on the document doesn't change the position
com.sun.star.text.XTextCursor xTextCursor = null;
- xTextCursor = (com.sun.star.text.XTextCursor)
- xTextDocument.getText().createTextCursor();
+ xTextCursor = xTextDocument.getText().createTextCursor();
- com.sun.star.beans.XPropertySet oCPS = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xTextCursor);
+ com.sun.star.beans.XPropertySet oCPS = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextCursor);
try {
oCPS.setPropertyValue("CharFontName","Helvetica");
}
@@ -101,9 +99,8 @@ public class StyleInitialization {
// the text range not the cursor contains the 'parastyle' property
xTextRange = xText.getEnd();
- xPropertySet = (com.sun.star.beans.XPropertySet)
- UnoRuntime.queryInterface(
- com.sun.star.beans.XPropertySet.class, xTextRange );
+ xPropertySet = UnoRuntime.queryInterface(
+ com.sun.star.beans.XPropertySet.class, xTextRange );
// To run the sample with StarOffice 5.2 you'll have to change
// 'ParaStyleName' to 'ParaStyle' in the next line
@@ -118,18 +115,16 @@ public class StyleInitialization {
// The first way, with the paragraph cursor
com.sun.star.text.XParagraphCursor xParagraphCursor = null;
- xParagraphCursor = (com.sun.star.text.XParagraphCursor)
- UnoRuntime.queryInterface(
- com.sun.star.text.XParagraphCursor.class, xTextRange );
+ xParagraphCursor = UnoRuntime.queryInterface(
+ com.sun.star.text.XParagraphCursor.class, xTextRange );
xParagraphCursor.gotoStart( false );
xParagraphCursor.gotoEndOfParagraph( true );
// The second way, with the paragraph enumeration
com.sun.star.container.XEnumerationAccess xEnumerationAccess = null;
- xEnumerationAccess = (com.sun.star.container.XEnumerationAccess)
- UnoRuntime.queryInterface(
- com.sun.star.container.XEnumerationAccess.class, xText );
+ xEnumerationAccess = UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xText );
// the enumeration contains all paragraph form the document
com.sun.star.container.XEnumeration xParagraphEnumeration = null;
@@ -144,10 +139,9 @@ public class StyleInitialization {
// check if a paragraph is available
while ( xParagraphEnumeration.hasMoreElements() ) {
// get the next paragraph
- xParagraph = (com.sun.star.text.XTextContent)
- UnoRuntime.queryInterface(
- com.sun.star.text.XTextContent.class,
- xParagraphEnumeration.nextElement());
+ xParagraph = UnoRuntime.queryInterface(
+ com.sun.star.text.XTextContent.class,
+ xParagraphEnumeration.nextElement());
// you need the method getAnchor to a TextRange -> to manipulate
// the paragraph
@@ -163,14 +157,13 @@ public class StyleInitialization {
// The enumeration from the paragraphs contain parts from the
// paragraph with a different attributes.
- xParaEnumerationAccess = (com.sun.star.container.XEnumerationAccess)
- UnoRuntime.queryInterface(
- com.sun.star.container.XEnumerationAccess.class, xParagraph);
+ xParaEnumerationAccess = UnoRuntime.queryInterface(
+ com.sun.star.container.XEnumerationAccess.class, xParagraph);
xPortionEnumeration = xParaEnumerationAccess.createEnumeration();
while ( xPortionEnumeration.hasMoreElements() ) {
// output of all parts from the paragraph with different attributes
- xWord = (com.sun.star.text.XTextRange) UnoRuntime.queryInterface(
+ xWord = UnoRuntime.queryInterface(
com.sun.star.text.XTextRange.class,
xPortionEnumeration.nextElement());
String sWordString = xWord.getString();
@@ -182,7 +175,7 @@ public class StyleInitialization {
// craete a supplier to get the styles-collection
com.sun.star.style.XStyleFamiliesSupplier xSupplier = null;
- xSupplier = ( com.sun.star.style.XStyleFamiliesSupplier ) UnoRuntime.queryInterface(
+ xSupplier = UnoRuntime.queryInterface(
com.sun.star.style.XStyleFamiliesSupplier.class, xTextDocument );
// use the name access from the collection
@@ -190,7 +183,7 @@ public class StyleInitialization {
xNameAccess = xSupplier.getStyleFamilies();
com.sun.star.container.XNameContainer xParaStyleCollection = null;
- xParaStyleCollection = (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface(
+ xParaStyleCollection = UnoRuntime.queryInterface(
com.sun.star.container.XNameContainer.class, xNameAccess.getByName( "ParagraphStyles" ));
// create a array from strings with the name of all paragraph styles from the text document
@@ -200,12 +193,12 @@ public class StyleInitialization {
for( int iCounter = 0; iCounter < iElementCount; iCounter++ ) {
// specify one paragraph style
com.sun.star.style.XStyle xStyle = null;
- xStyle = (com.sun.star.style.XStyle) UnoRuntime.queryInterface(
+ xStyle = UnoRuntime.queryInterface(
com.sun.star.style.XStyle.class,
xParaStyleCollection.getByName( sElementNames[iCounter] ));
// create a property set of all properties from the style
- xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ xPropertySet = UnoRuntime.queryInterface(
com.sun.star.beans.XPropertySet.class, xStyle );
AnyConverter aAnyConv = new AnyConverter();
@@ -215,7 +208,7 @@ public class StyleInitialization {
// if the style use the font 'Albany', apply it to the current paragraph
if( sFontname.compareTo("albany") == 0 ) {
// create a property set from the current paragraph, to change the paragraph style
- xPropertySet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(
+ xPropertySet = UnoRuntime.queryInterface(
com.sun.star.beans.XPropertySet.class, xTextRange );
// To run the sample with StarOffice 5.2 you'll have to change 'ParaStyleName'
@@ -255,7 +248,7 @@ public class StyleInitialization {
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
@@ -278,9 +271,8 @@ public class StyleInitialization {
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);
@@ -304,9 +296,8 @@ public class StyleInitialization {
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);
diff --git a/odk/examples/java/Text/TextDocumentStructure.java b/odk/examples/java/Text/TextDocumentStructure.java
index f60ce98c937d..74b2659ac9ee 100644
--- a/odk/examples/java/Text/TextDocumentStructure.java
+++ b/odk/examples/java/Text/TextDocumentStructure.java
@@ -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 ));
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);
diff --git a/odk/examples/java/Text/WriterSelector.java b/odk/examples/java/Text/WriterSelector.java
index 6fd00189d657..1343293a968a 100644
--- a/odk/examples/java/Text/WriterSelector.java
+++ b/odk/examples/java/Text/WriterSelector.java
@@ -57,32 +57,30 @@ public class WriterSelector {
xContext.getServiceManager();
// get a new instance of the desktop
- com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop)
- UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
- xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
- xContext ) );
+ com.sun.star.frame.XDesktop xDesktop = UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class,
+ xMCF.createInstanceWithContext("com.sun.star.frame.Desktop",
+ xContext ) );
com.sun.star.frame.XComponentLoader xCompLoader =
- (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface(
- com.sun.star.frame.XComponentLoader.class, xDesktop);
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XComponentLoader.class, xDesktop);
com.sun.star.lang.XComponent xComponent =
xCompLoader.loadComponentFromURL("private:factory/swriter",
"_blank", 0, new com.sun.star.beans.PropertyValue[0]);
{
- com.sun.star.text.XTextDocument xDoc =(com.sun.star.text.XTextDocument)
- UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
- xComponent);
+ com.sun.star.text.XTextDocument xDoc =UnoRuntime.queryInterface(com.sun.star.text.XTextDocument.class,
+ xComponent);
xDoc.getText().setString("Please select something in this text and press then \"return\" in the shell where you have started the example.\n");
// ensure that the document content is optimal visible
com.sun.star.frame.XModel xModel =
- (com.sun.star.frame.XModel)UnoRuntime.queryInterface(
- com.sun.star.frame.XModel.class, xDoc);
+ UnoRuntime.queryInterface(
+ com.sun.star.frame.XModel.class, xDoc);
com.sun.star.view.XViewSettingsSupplier xViewSettings =
- (com.sun.star.view.XViewSettingsSupplier)UnoRuntime.queryInterface(
- com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController());
+ UnoRuntime.queryInterface(
+ com.sun.star.view.XViewSettingsSupplier.class, xModel.getCurrentController());
xViewSettings.getViewSettings().setPropertyValue(
"ZoomType", new Short((short)0));
}
@@ -101,28 +99,27 @@ public class WriterSelector {
com.sun.star.frame.XController xController = xframe.getController();
com.sun.star.view.XSelectionSupplier xSelSupplier =
- (com.sun.star.view.XSelectionSupplier)UnoRuntime.queryInterface(
- com.sun.star.view.XSelectionSupplier.class, xController );
+ UnoRuntime.queryInterface(
+ com.sun.star.view.XSelectionSupplier.class, xController );
Object oSelection = xSelSupplier.getSelection();
com.sun.star.lang.XServiceInfo xServInfo =
- (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface(
- com.sun.star.lang.XServiceInfo.class, oSelection );
+ UnoRuntime.queryInterface(
+ com.sun.star.lang.XServiceInfo.class, oSelection );
if ( xServInfo.supportsService("com.sun.star.text.TextRanges") )
{
com.sun.star.container.XIndexAccess xIndexAccess =
- (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface(
- com.sun.star.container.XIndexAccess.class, oSelection);
+ UnoRuntime.queryInterface(
+ com.sun.star.container.XIndexAccess.class, oSelection);
int count = xIndexAccess.getCount();
com.sun.star.text.XTextRange xTextRange = null;
for ( int i = 0; i < count; i++ ) {
- xTextRange = (com.sun.star.text.XTextRange)
- UnoRuntime.queryInterface(
- com.sun.star.text.XTextRange.class,
- xIndexAccess.getByIndex(i));
+ xTextRange = UnoRuntime.queryInterface(
+ com.sun.star.text.XTextRange.class,
+ xIndexAccess.getByIndex(i));
System.out.println( "You have selected a text range: \""
+ xTextRange.getString() + "\"." );
@@ -141,9 +138,8 @@ public class WriterSelector {
// close test document
- com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable)
- UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
- xComponent );
+ com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class,
+ xComponent );
if (xCloseable != null ) {
xCloseable.close(false);