diff options
author | Noel Grandin <noel@peralex.com> | 2013-04-17 14:59:35 +0200 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2013-04-19 07:52:08 +0000 |
commit | 8d87758d65e4a03271f76e354dfc84c1fcd5fe21 (patch) | |
tree | bc8f4f0df6981ad10fe1333db1a2b015ea079709 /odk/examples | |
parent | d62425cc27e04a3237cfec2ea2663b8b11284ec8 (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')
97 files changed, 1329 insertions, 1663 deletions
diff --git a/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java b/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java index 758835579bb5..86d58da4ba0d 100644 --- a/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java +++ b/odk/examples/DevelopersGuide/Components/Addons/ProtocolHandlerAddon_java/ProtocolHandlerAddon.java @@ -100,12 +100,12 @@ public class ProtocolHandlerAddon { if ( object.length > 0 ) { - m_xFrame = ( XFrame ) UnoRuntime.queryInterface( + m_xFrame = UnoRuntime.queryInterface( XFrame.class, object[ 0 ] ); } // Create the toolkit to have access to it later - m_xToolkit = (XToolkit) UnoRuntime.queryInterface( + m_xToolkit = UnoRuntime.queryInterface( XToolkit.class, m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xCmpCtx)); @@ -210,7 +210,7 @@ public class ProtocolHandlerAddon { aDescriptor.Type = WindowClass.MODALTOP; aDescriptor.WindowServiceName = new String( "infobox" ); aDescriptor.ParentIndex = -1; - aDescriptor.Parent = (XWindowPeer)UnoRuntime.queryInterface( + aDescriptor.Parent = UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow()); aDescriptor.Bounds = new Rectangle(0,0,300,200); aDescriptor.WindowAttributes = WindowAttribute.BORDER | @@ -219,7 +219,7 @@ public class ProtocolHandlerAddon { XWindowPeer xPeer = m_xToolkit.createWindow( aDescriptor ); if ( null != xPeer ) { - XMessageBox xMsgBox = (XMessageBox)UnoRuntime.queryInterface( + XMessageBox xMsgBox = UnoRuntime.queryInterface( XMessageBox.class, xPeer); if ( null != xMsgBox ) { diff --git a/odk/examples/DevelopersGuide/Components/JavaComponent/TestJavaComponent.java b/odk/examples/DevelopersGuide/Components/JavaComponent/TestJavaComponent.java index 147473573c82..489e4c3ad45d 100644 --- a/odk/examples/DevelopersGuide/Components/JavaComponent/TestJavaComponent.java +++ b/odk/examples/DevelopersGuide/Components/JavaComponent/TestJavaComponent.java @@ -52,7 +52,7 @@ public class TestJavaComponent XMultiComponentFactory serviceManager, Object singleFactory ) throws com.sun.star.uno.Exception { - XSet set = (XSet ) UnoRuntime.queryInterface( XSet.class, serviceManager ); + XSet set = UnoRuntime.queryInterface( XSet.class, serviceManager ); set.insert( singleFactory ); } @@ -60,7 +60,7 @@ public class TestJavaComponent XMultiComponentFactory serviceManager, Object singleFactory ) throws com.sun.star.uno.Exception { - XSet set = (XSet ) UnoRuntime.queryInterface( XSet.class, serviceManager ); + XSet set = UnoRuntime.queryInterface( XSet.class, serviceManager ); set.remove( singleFactory ); } diff --git a/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java b/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java index 146aef4cf342..513cc1af4058 100644 --- a/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java +++ b/odk/examples/DevelopersGuide/Components/dialogcomponent/DialogComponent.java @@ -82,7 +82,7 @@ public class DialogComponent { try { // Create the toolkit to have access to it later - m_xToolkit = (XToolkit) UnoRuntime.queryInterface( + m_xToolkit = UnoRuntime.queryInterface( XToolkit.class, m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xCmpCtx)); @@ -113,8 +113,7 @@ public class DialogComponent { "com.sun.star.awt.DialogProvider2", m_xCmpCtx ); } - XDialogProvider2 xDialogProvider = (XDialogProvider2) - UnoRuntime.queryInterface( XDialogProvider2.class, obj ); + XDialogProvider2 xDialogProvider = UnoRuntime.queryInterface( XDialogProvider2.class, obj ); XDialog xDialog = xDialogProvider.createDialogWithHandler( DialogURL, this ); if( xDialog != null ) @@ -127,13 +126,13 @@ public class DialogComponent { } public void copyText( XDialog xDialog, Object aEventObject ) { - XControlContainer xControlContainer = (XControlContainer)UnoRuntime.queryInterface( + XControlContainer xControlContainer = UnoRuntime.queryInterface( XControlContainer.class, xDialog ); String aTextPropertyStr = "Text"; String aText = ""; XControl xTextField1Control = xControlContainer.getControl( "TextField1" ); XControlModel xControlModel1 = xTextField1Control.getModel(); - XPropertySet xPropertySet1 = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropertySet1 = UnoRuntime.queryInterface( XPropertySet.class, xControlModel1 ); try { @@ -145,7 +144,7 @@ public class DialogComponent { XControl xTextField2Control = xControlContainer.getControl( "TextField2" ); XControlModel xControlModel2 = xTextField2Control.getModel(); - XPropertySet xPropertySet2 = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropertySet2 = UnoRuntime.queryInterface( XPropertySet.class, xControlModel2 ); try { @@ -257,7 +256,7 @@ public class DialogComponent { aDescriptor.Type = WindowClass.MODALTOP; aDescriptor.WindowServiceName = new String( "infobox" ); aDescriptor.ParentIndex = -1; - aDescriptor.Parent = (XWindowPeer)UnoRuntime.queryInterface( + aDescriptor.Parent = UnoRuntime.queryInterface( XWindowPeer.class, m_xFrame.getContainerWindow()); aDescriptor.Bounds = new Rectangle(0,0,300,200); aDescriptor.WindowAttributes = WindowAttribute.BORDER | @@ -266,7 +265,7 @@ public class DialogComponent { XWindowPeer xPeer = m_xToolkit.createWindow( aDescriptor ); if ( null != xPeer ) { - XMessageBox xMsgBox = (XMessageBox)UnoRuntime.queryInterface( + XMessageBox xMsgBox = UnoRuntime.queryInterface( XMessageBox.class, xPeer); if ( null != xMsgBox ) { diff --git a/odk/examples/DevelopersGuide/Config/ConfigExamples.java b/odk/examples/DevelopersGuide/Config/ConfigExamples.java index 979075e82d52..0281dca8324a 100644 --- a/odk/examples/DevelopersGuide/Config/ConfigExamples.java +++ b/odk/examples/DevelopersGuide/Config/ConfigExamples.java @@ -179,7 +179,7 @@ public class ConfigExamples { // check the provider implementation XServiceInfo xProviderServices = - (XServiceInfo) UnoRuntime.queryInterface( XServiceInfo.class, xProvider ); + UnoRuntime.queryInterface( XServiceInfo.class, xProvider ); if (xProviderServices == null || !xProviderServices.supportsService("com.sun.star.configuration.ConfigurationProvider")) @@ -217,10 +217,9 @@ public class ConfigExamples final String sProviderService = "com.sun.star.configuration.ConfigurationProvider"; // create the provider and return it as a XMultiServiceFactory - XMultiServiceFactory xProvider = (XMultiServiceFactory) - UnoRuntime.queryInterface(XMultiServiceFactory.class, - mxServiceManager.createInstanceWithContext(sProviderService, - mxContext)); + XMultiServiceFactory xProvider = UnoRuntime.queryInterface(XMultiServiceFactory.class, + mxServiceManager.createInstanceWithContext(sProviderService, + mxContext)); return xProvider; } @@ -389,7 +388,7 @@ public class ConfigExamples // accessing a single nested value XHierarchicalPropertySet xProperties = - (XHierarchicalPropertySet)UnoRuntime.queryInterface(XHierarchicalPropertySet.class, xViewRoot); + UnoRuntime.queryInterface(XHierarchicalPropertySet.class, xViewRoot); Object aVisible = xProperties.getHierarchicalPropertyValue("Option/VisibleGrid"); options.visible = ((Boolean) aVisible).booleanValue(); @@ -398,7 +397,7 @@ public class ConfigExamples Object xSubdivision = xProperties.getHierarchicalPropertyValue("Subdivision"); XMultiPropertySet xSubdivProperties = - (XMultiPropertySet)UnoRuntime.queryInterface(XMultiPropertySet.class, xSubdivision); + UnoRuntime.queryInterface(XMultiPropertySet.class, xSubdivision); // variables for multi-element access String[] aElementNames = new String[2]; @@ -415,8 +414,7 @@ public class ConfigExamples Object xResolution = xProperties.getHierarchicalPropertyValue("Resolution"); XMultiHierarchicalPropertySet xResolutionProperties = - (XMultiHierarchicalPropertySet) - UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xResolution); + UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xResolution); aElementNames[0] = "XAxis/Metric"; aElementNames[1] = "YAxis/Metric"; @@ -429,7 +427,7 @@ public class ConfigExamples // all options have been retrieved - clean up and return // we are done with the view - dispose it - ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose(); return options; } @@ -450,7 +448,7 @@ public class ConfigExamples { // First process this as an element (preorder traversal) XHierarchicalName xElementPath = - (XHierarchicalName) UnoRuntime.queryInterface(XHierarchicalName.class, xElement); + UnoRuntime.queryInterface(XHierarchicalName.class, xElement); String sPath = xElementPath.getHierarchicalName(); @@ -458,7 +456,7 @@ public class ConfigExamples // now process this as a container XNameAccess xChildAccess = - (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, xElement); + UnoRuntime.queryInterface(XNameAccess.class, xElement); // get a list of child elements String[] aElementNames = xChildAccess.getElementNames(); @@ -472,7 +470,7 @@ public class ConfigExamples if ( aAnyConv.isObject(aChild) && !aAnyConv.isArray(aChild) ) { // then get an interface - XInterface xChildElement = (XInterface)UnoRuntime.queryInterface(XInterface.class, aChild); + XInterface xChildElement = UnoRuntime.queryInterface(XInterface.class, aChild); // and continue processing child elements recursively browseElementRecursively( xChildElement, aProcessor ); @@ -510,7 +508,7 @@ public class ConfigExamples // This assumes that the processor // does not keep a reference to the elements in processStructuralElement - ((XComponent) UnoRuntime.queryInterface(XComponent.class,xViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class,xViewRoot).dispose(); xViewRoot = null; } @@ -549,11 +547,11 @@ public class ConfigExamples public void processStructuralElement( String sPath_, XInterface xElement_) { // get template information, to detect instances of the 'Filter' template XTemplateInstance xInstance = - ( XTemplateInstance )UnoRuntime.queryInterface( XTemplateInstance .class,xElement_); + UnoRuntime.queryInterface( XTemplateInstance .class,xElement_); // only select the Filter entries if (xInstance != null && xInstance.getTemplateName().endsWith("Filter")) { - XNamed xNamed = (XNamed)UnoRuntime.queryInterface(XNamed.class,xElement_); + XNamed xNamed = UnoRuntime.queryInterface(XNamed.class,xElement_); System.out.println("Filter " + xNamed.getName() + " (" + sPath_ + ")"); } } @@ -579,8 +577,7 @@ public class ConfigExamples // set up the initial values and register listeners // get a data access interface, to supply the view with a model XMultiHierarchicalPropertySet xProperties = - (XMultiHierarchicalPropertySet) - UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xViewRoot); + UnoRuntime.queryInterface(XMultiHierarchicalPropertySet.class, xViewRoot); dialog.setModel( xProperties ); @@ -589,7 +586,7 @@ public class ConfigExamples XChangesListener xListener = dialog.createChangesListener( ); XChangesNotifier xNotifier = - (XChangesNotifier)UnoRuntime.queryInterface(XChangesNotifier.class, xViewRoot); + UnoRuntime.queryInterface(XChangesNotifier.class, xViewRoot); xNotifier.addChangesListener( xListener ); @@ -600,7 +597,7 @@ public class ConfigExamples { // changes have been applied to the view here XChangesBatch xUpdateControl = - (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot); + UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot); try { @@ -617,7 +614,7 @@ public class ConfigExamples xNotifier.removeChangesListener( xListener ); // we are done with the view - dispose it - ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose(); } /** A class that changes some grid options settings @@ -721,7 +718,7 @@ public class ConfigExamples try { XHierarchicalPropertySet xHPS = - (XHierarchicalPropertySet)UnoRuntime.queryInterface(XHierarchicalPropertySet.class, mxModel); + UnoRuntime.queryInterface(XHierarchicalPropertySet.class, mxModel); final String sSetting = "Option/VisibleGrid"; @@ -749,7 +746,7 @@ public class ConfigExamples { Object xOtherViewRoot = createUpdatableView(xKey); - XNameReplace aReplace = (XNameReplace)UnoRuntime.queryInterface(XNameReplace.class, xOtherViewRoot); + XNameReplace aReplace = UnoRuntime.queryInterface(XNameReplace.class, xOtherViewRoot); String aItemNames [] = aReplace.getElementNames(); for (int i=0; i < aItemNames.length; ++i) { @@ -778,12 +775,12 @@ public class ConfigExamples // commit the changes XChangesBatch xUpdateControl = - (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xOtherViewRoot); + UnoRuntime.queryInterface(XChangesBatch.class,xOtherViewRoot); xUpdateControl.commitChanges(); // we are done with the view - dispose it - ((XComponent)UnoRuntime.queryInterface(XComponent.class, xOtherViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class, xOtherViewRoot).dispose(); } catch (Exception e) { @@ -805,13 +802,13 @@ public class ConfigExamples // resetting a single nested value XHierarchicalNameAccess xHierarchicalAccess = - (XHierarchicalNameAccess)UnoRuntime.queryInterface(XHierarchicalNameAccess.class, xViewRoot); + UnoRuntime.queryInterface(XHierarchicalNameAccess.class, xViewRoot); // get using absolute name Object xOptions = xHierarchicalAccess.getByHierarchicalName(cGridOptionsPath + "/Option"); XPropertyState xOptionState = - (XPropertyState)UnoRuntime.queryInterface(XPropertyState.class, xOptions); + UnoRuntime.queryInterface(XPropertyState.class, xOptions); xOptionState.setPropertyToDefault("VisibleGrid"); @@ -820,9 +817,9 @@ public class ConfigExamples Object xResolutionY = xHierarchicalAccess.getByHierarchicalName("Resolution/YAxis"); XPropertyState xResolutionStateX = - (XPropertyState)UnoRuntime.queryInterface(XPropertyState.class, xResolutionX); + UnoRuntime.queryInterface(XPropertyState.class, xResolutionX); XPropertyState xResolutionStateY = - (XPropertyState)UnoRuntime.queryInterface(XPropertyState.class, xResolutionY); + UnoRuntime.queryInterface(XPropertyState.class, xResolutionY); xResolutionStateX.setPropertyToDefault("Metric"); xResolutionStateY.setPropertyToDefault("Metric"); @@ -831,18 +828,18 @@ public class ConfigExamples Object xSubdivision = xHierarchicalAccess.getByHierarchicalName("Subdivision"); XMultiPropertyStates xSubdivisionStates = - (XMultiPropertyStates)UnoRuntime.queryInterface(XMultiPropertyStates.class, xSubdivision); + UnoRuntime.queryInterface(XMultiPropertyStates.class, xSubdivision); xSubdivisionStates.setAllPropertiesToDefault(); // commit the changes XChangesBatch xUpdateControl = - (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot); + UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot); xUpdateControl.commitChanges(); // we are done with the view - dispose it - ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose(); } @@ -900,7 +897,7 @@ public class ConfigExamples // set the values XPropertySet xDataSourceProperties = - (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xDataSource); + UnoRuntime.queryInterface(XPropertySet.class, xDataSource); xDataSourceProperties.setPropertyValue("URL", sDataSourceURL ); xDataSourceProperties.setPropertyValue("User", sUser ); @@ -923,12 +920,12 @@ public class ConfigExamples // commit the changes XChangesBatch xUpdateControl = - (XChangesBatch) UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot); + UnoRuntime.queryInterface(XChangesBatch.class,xViewRoot); xUpdateControl.commitChanges(); // now clean up - ((XComponent) UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose(); } /** This method gets the DataSourceDescription for a data source. @@ -956,7 +953,7 @@ public class ConfigExamples xProvider.createInstanceWithArguments(cUpdatableView, aArguments); XNameAccess xSetOfDataSources = - (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class,xViewRoot); + UnoRuntime.queryInterface(XNameAccess.class,xViewRoot); Object xDataSourceDescriptor = null; // the result if ( xSetOfDataSources .hasByName( sDataSourceName )) @@ -965,8 +962,7 @@ public class ConfigExamples try { // the view should point to the element directly, so we need to extend the path - XHierarchicalName xComposePath = (XHierarchicalName) - UnoRuntime.queryInterface(XHierarchicalName.class, xSetOfDataSources ); + XHierarchicalName xComposePath = UnoRuntime.queryInterface(XHierarchicalName.class, xSetOfDataSources ); String sElementPath = xComposePath.composeHierarchicalName( sDataSourceName ); @@ -984,7 +980,7 @@ public class ConfigExamples if ( xDataSourceDescriptor != null) // all went fine { // dispose the other view - ((XComponent)UnoRuntime.queryInterface(XComponent.class, xViewRoot)).dispose(); + UnoRuntime.queryInterface(XComponent.class, xViewRoot).dispose(); xViewRoot = null; } } @@ -1001,11 +997,11 @@ public class ConfigExamples { // get the container XNameContainer xSetUpdate = - (XNameContainer)UnoRuntime.queryInterface(XNameContainer.class, xViewRoot); + UnoRuntime.queryInterface(XNameContainer.class, xViewRoot); // create a new detached set element (instance of DataSourceDescription) XSingleServiceFactory xElementFactory = - (XSingleServiceFactory)UnoRuntime.queryInterface(XSingleServiceFactory.class, xSetUpdate); + UnoRuntime.queryInterface(XSingleServiceFactory.class, xSetUpdate); // the new element is the result ! xDataSourceDescriptor = xElementFactory.createInstance(); @@ -1026,17 +1022,16 @@ public class ConfigExamples // get the settings set as a container XNameContainer xSettingsContainer = - (XNameContainer) UnoRuntime.queryInterface( XNameContainer.class, xSettingsSet); + UnoRuntime.queryInterface( XNameContainer.class, xSettingsSet); // and get a factory interface for creating the entries XSingleServiceFactory xSettingsFactory = - (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class, xSettingsSet); + UnoRuntime.queryInterface(XSingleServiceFactory.class, xSettingsSet); // now insert the individual settings for (int i = 0; i < aSettings.length; ++i) { // create a DataSourceSetting object - XPropertySet xSetting = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xSettingsFactory.createInstance() ); + XPropertySet xSetting = UnoRuntime.queryInterface( XPropertySet.class, xSettingsFactory.createInstance() ); // can set the value before inserting xSetting.setPropertyValue( "Value", aSettings[i].Value ); @@ -1061,7 +1056,7 @@ public class ConfigExamples do { XChild xParentAccess = - (XChild) UnoRuntime.queryInterface(XChild.class,xResult); + UnoRuntime.queryInterface(XChild.class,xResult); if (xParentAccess != null) xParent = xParentAccess.getParent(); @@ -1082,11 +1077,9 @@ public class ConfigExamples void renameSetItem(XNamed xNamedItem, String sNewName) throws com.sun.star.uno.Exception { - XChild xChildItem = (XChild) - UnoRuntime.queryInterface(XChild.class, xNamedItem); + XChild xChildItem = UnoRuntime.queryInterface(XChild.class, xNamedItem); - XNameContainer xParentSet = (XNameContainer) - UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() ); + XNameContainer xParentSet = UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() ); String sOldName = xNamedItem.getName(); @@ -1099,11 +1092,9 @@ public class ConfigExamples void moveSetItem(XChild xChildItem, XNameContainer xNewParent) throws com.sun.star.uno.Exception { - XNamed xNamedItem = (XNamed) - UnoRuntime.queryInterface(XNamed.class, xChildItem); + XNamed xNamedItem = UnoRuntime.queryInterface(XNamed.class, xChildItem); - XNameContainer xOldParent = (XNameContainer) - UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() ); + XNameContainer xOldParent = UnoRuntime.queryInterface( XNameContainer.class, xChildItem.getParent() ); String sItemName = xNamedItem.getName(); diff --git a/odk/examples/DevelopersGuide/Database/CodeSamples.java b/odk/examples/DevelopersGuide/Database/CodeSamples.java index 7d4cac1b6f71..58458c6f1535 100644 --- a/odk/examples/DevelopersGuide/Database/CodeSamples.java +++ b/odk/examples/DevelopersGuide/Database/CodeSamples.java @@ -119,7 +119,7 @@ public class CodeSamples { System.out.println("Connection was created!"); // now we dispose the connection to close it - XComponent xComponent = (XComponent)UnoRuntime.queryInterface(XComponent.class,con); + XComponent xComponent = UnoRuntime.queryInterface(XComponent.class,con); if(xComponent != null) { // connections must be disposed @@ -141,7 +141,7 @@ public class CodeSamples xContext); // query for the interface com.sun.star.sdbc.XDriverManager xDriverManager; - xDriverManager = (XDriverManager)UnoRuntime.queryInterface(XDriverManager.class,driverManager); + xDriverManager = UnoRuntime.queryInterface(XDriverManager.class,driverManager); if(xDriverManager != null) { // first create the needed url @@ -169,7 +169,7 @@ public class CodeSamples xContext); // query for the interface com.sun.star.sdbc.XDriver xDriver; - xDriver = (XDriver)UnoRuntime.queryInterface(XDriver.class,aDriver); + xDriver = UnoRuntime.queryInterface(XDriver.class,aDriver); if(xDriver != null) { // first create the needed url @@ -191,7 +191,7 @@ public class CodeSamples public static void printDataSources() throws com.sun.star.uno.Exception { // create a DatabaseContext and print all DataSource names - XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( + XNameAccess xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, xMCF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext", xContext)); @@ -205,7 +205,7 @@ public class CodeSamples { XDatabaseMetaData dm = con.getMetaData(); XResultSet rsTables = dm.getTables(null,"%","SALES",null); - XRow rowTB = (XRow)UnoRuntime.queryInterface(XRow.class, rsTables); + XRow rowTB = UnoRuntime.queryInterface(XRow.class, rsTables); while ( rsTables.next() ) { String catalog = rowTB.getString( 1 ); @@ -221,7 +221,7 @@ public class CodeSamples System.out.println("Catalog: " + catalog + " Schema: " + schema + " Table: " + table + " Type: " + type); System.out.println("------------------ Columns ------------------"); XResultSet rsColumns = dm.getColumns(catalog,schema,table,"%"); - XRow rowCL = (XRow)UnoRuntime.queryInterface(XRow.class, rsColumns); + XRow rowCL = UnoRuntime.queryInterface(XRow.class, rsColumns); while ( rsColumns.next() ) { System.out.println("Column: " + rowCL.getString( 4 ) + " Type: " + rowCL.getInt( 5 ) + " TypeName: " + rowCL.getString( 6 ) ); @@ -264,25 +264,23 @@ public class CodeSamples // creates a new query definition public static void createQuerydefinition() throws com.sun.star.uno.Exception { - XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( + XNameAccess xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, xMCF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext", xContext)); // we use the first datasource - XQueryDefinitionsSupplier xQuerySup = (XQueryDefinitionsSupplier) - UnoRuntime.queryInterface(XQueryDefinitionsSupplier.class, - xNameAccess.getByName( "Bibliography" )); + XQueryDefinitionsSupplier xQuerySup = UnoRuntime.queryInterface(XQueryDefinitionsSupplier.class, + xNameAccess.getByName( "Bibliography" )); XNameAccess xQDefs = xQuerySup.getQueryDefinitions(); // create new query definition - XSingleServiceFactory xSingleFac = (XSingleServiceFactory) - UnoRuntime.queryInterface(XSingleServiceFactory.class, xQDefs); + XSingleServiceFactory xSingleFac = UnoRuntime.queryInterface(XSingleServiceFactory.class, xQDefs); - XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xProp = UnoRuntime.queryInterface( XPropertySet.class,xSingleFac.createInstance()); xProp.setPropertyValue("Command","SELECT * FROM biblio"); xProp.setPropertyValue("EscapeProcessing",new Boolean(true)); - XNameContainer xCont = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xQDefs); + XNameContainer xCont = UnoRuntime.queryInterface(XNameContainer.class, xQDefs); try { if ( xCont.hasByName("Query1") ) @@ -291,29 +289,28 @@ public class CodeSamples catch(com.sun.star.uno.Exception e) {} xCont.insertByName("Query1",xProp); - XDocumentDataSource xDs = (XDocumentDataSource)UnoRuntime.queryInterface(XDocumentDataSource.class, xQuerySup); + XDocumentDataSource xDs = UnoRuntime.queryInterface(XDocumentDataSource.class, xQuerySup); - XStorable xStore = (XStorable)UnoRuntime.queryInterface(XStorable.class,xDs.getDatabaseDocument()); + XStorable xStore = UnoRuntime.queryInterface(XStorable.class,xDs.getDatabaseDocument()); xStore.store(); } // prints all column names from Query1 public static void printQueryColumnNames() throws com.sun.star.uno.Exception { - XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( + XNameAccess xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, xMCF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext", xContext)); // we use the first datasource - XDataSource xDS = (XDataSource)UnoRuntime.queryInterface( + XDataSource xDS = UnoRuntime.queryInterface( XDataSource.class, xNameAccess.getByName( "Bibliography" )); XConnection con = xDS.getConnection("",""); - XQueriesSupplier xQuerySup = (XQueriesSupplier) - UnoRuntime.queryInterface(XQueriesSupplier.class, con); + XQueriesSupplier xQuerySup = UnoRuntime.queryInterface(XQueriesSupplier.class, con); XNameAccess xQDefs = xQuerySup.getQueries(); - XColumnsSupplier xColsSup = (XColumnsSupplier) UnoRuntime.queryInterface( + XColumnsSupplier xColsSup = UnoRuntime.queryInterface( XColumnsSupplier.class,xQDefs.getByName("Query1")); XNameAccess xCols = xColsSup.getColumns(); String aNames [] = xCols.getElementNames(); diff --git a/odk/examples/DevelopersGuide/Database/OpenQuery.java b/odk/examples/DevelopersGuide/Database/OpenQuery.java index 765079b779b3..a460b769f15e 100644 --- a/odk/examples/DevelopersGuide/Database/OpenQuery.java +++ b/odk/examples/DevelopersGuide/Database/OpenQuery.java @@ -87,11 +87,10 @@ public class OpenQuery { Object rowSet = xMCF.createInstanceWithContext( "com.sun.star.sdb.RowSet", xContext); - com.sun.star.sdbc.XRowSet xRowSet = (com.sun.star.sdbc.XRowSet) - UnoRuntime.queryInterface(com.sun.star.sdbc.XRowSet.class, rowSet); + com.sun.star.sdbc.XRowSet xRowSet = UnoRuntime.queryInterface(com.sun.star.sdbc.XRowSet.class, rowSet); // set the properties needed to connect to a database - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xRowSet); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, xRowSet); // the DataSourceName can be a data source registered with [PRODUCTNAME], among other possibilities xProp.setPropertyValue("DataSourceName","Bibliography"); @@ -110,12 +109,11 @@ public class OpenQuery { // prepare the XRow and XColumnLocate interface for column access // XRow gets column values - com.sun.star.sdbc.XRow xRow = (com.sun.star.sdbc.XRow)UnoRuntime.queryInterface( + com.sun.star.sdbc.XRow xRow = UnoRuntime.queryInterface( com.sun.star.sdbc.XRow.class, xRowSet); // XColumnLocate finds columns by name - com.sun.star.sdbc.XColumnLocate xLoc = (com.sun.star.sdbc.XColumnLocate) - UnoRuntime.queryInterface( - com.sun.star.sdbc.XColumnLocate.class, xRowSet); + com.sun.star.sdbc.XColumnLocate xLoc = UnoRuntime.queryInterface( + com.sun.star.sdbc.XColumnLocate.class, xRowSet); // print output header System.out.println("Identifier\tAuthor"); @@ -129,14 +127,12 @@ public class OpenQuery { } // XResultSetUpdate for insertRow handling - com.sun.star.sdbc.XResultSetUpdate xResultSetUpdate = (com.sun.star.sdbc.XResultSetUpdate) - UnoRuntime.queryInterface( - com.sun.star.sdbc.XResultSetUpdate.class, xRowSet); + com.sun.star.sdbc.XResultSetUpdate xResultSetUpdate = UnoRuntime.queryInterface( + com.sun.star.sdbc.XResultSetUpdate.class, xRowSet); // XRowUpdate for row updates - com.sun.star.sdbc.XRowUpdate xRowUpdate = (com.sun.star.sdbc.XRowUpdate) - UnoRuntime.queryInterface( - com.sun.star.sdbc.XRowUpdate.class, xRowSet); + com.sun.star.sdbc.XRowUpdate xRowUpdate = UnoRuntime.queryInterface( + com.sun.star.sdbc.XRowUpdate.class, xRowSet); // move to insertRow buffer xResultSetUpdate.moveToInsertRow(); @@ -149,7 +145,7 @@ public class OpenQuery { xResultSetUpdate.insertRow(); // throw away the row set - com.sun.star.lang.XComponent xComp = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface( + com.sun.star.lang.XComponent xComp = UnoRuntime.queryInterface( com.sun.star.lang.XComponent.class, xRowSet); xComp.dispose(); } diff --git a/odk/examples/DevelopersGuide/Database/RowSet.java b/odk/examples/DevelopersGuide/Database/RowSet.java index 780aaedf9370..c19dcdc681b7 100644 --- a/odk/examples/DevelopersGuide/Database/RowSet.java +++ b/odk/examples/DevelopersGuide/Database/RowSet.java @@ -77,7 +77,7 @@ public class RowSet public static void printDataSources() throws com.sun.star.uno.Exception { // create a DatabaseContext and print all DataSource names - XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( + XNameAccess xNameAccess = UnoRuntime.queryInterface( XNameAccess.class, xMCF.createInstanceWithContext("com.sun.star.sdb.DatabaseContext", xContext)); @@ -89,13 +89,13 @@ public class RowSet public static void useRowSet() throws com.sun.star.uno.Exception { // first we create our RowSet object - XRowSet xRowRes = (XRowSet)UnoRuntime.queryInterface( + XRowSet xRowRes = UnoRuntime.queryInterface( XRowSet.class, xMCF.createInstanceWithContext("com.sun.star.sdb.RowSet", xContext)); System.out.println("RowSet created!"); // set the properties needed to connect to a database - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xRowRes); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,xRowRes); xProp.setPropertyValue("DataSourceName","Bibliography"); xProp.setPropertyValue("Command","biblio"); xProp.setPropertyValue("CommandType",new Integer(com.sun.star.sdb.CommandType.TABLE)); @@ -104,7 +104,7 @@ public class RowSet System.out.println("RowSet executed!"); - XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,xRowRes); + XComponent xComp = UnoRuntime.queryInterface(XComponent.class,xRowRes); xComp.dispose(); System.out.println("RowSet destroyed!"); } @@ -112,13 +112,13 @@ public class RowSet public static void showRowSetPrivileges() throws com.sun.star.uno.Exception { // first we create our RowSet object - XRowSet xRowRes = (XRowSet)UnoRuntime.queryInterface( + XRowSet xRowRes = UnoRuntime.queryInterface( XRowSet.class, xMCF.createInstanceWithContext("com.sun.star.sdb.RowSet", xContext)); System.out.println("RowSet created!"); // set the properties needed to connect to a database - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xRowRes); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,xRowRes); xProp.setPropertyValue("DataSourceName","Bibliography"); xProp.setPropertyValue("Command","biblio"); xProp.setPropertyValue("CommandType",new Integer(com.sun.star.sdb.CommandType.TABLE)); @@ -138,7 +138,7 @@ public class RowSet System.out.println("DELETE"); // now destroy the RowSet - XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,xRowRes); + XComponent xComp = UnoRuntime.queryInterface(XComponent.class,xRowRes); xComp.dispose(); System.out.println("RowSet destroyed!"); } @@ -146,13 +146,13 @@ public class RowSet public static void showRowSetRowCount() throws com.sun.star.uno.Exception { // first we create our RowSet object - XRowSet xRowRes = (XRowSet)UnoRuntime.queryInterface( + XRowSet xRowRes = UnoRuntime.queryInterface( XRowSet.class, xMCF.createInstanceWithContext("com.sun.star.sdb.RowSet", xContext)); System.out.println("RowSet created!"); // set the properties needed to connect to a database - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xRowRes); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,xRowRes); xProp.setPropertyValue("DataSourceName","Bibliography"); xProp.setPropertyValue("Command","biblio"); xProp.setPropertyValue("CommandType",new Integer(com.sun.star.sdb.CommandType.TABLE)); @@ -163,14 +163,14 @@ public class RowSet // now look if the RowCount is already final System.out.println("The RowCount is final: " + xProp.getPropertyValue("IsRowCountFinal")); - XResultSet xRes = (XResultSet)UnoRuntime.queryInterface(XResultSet.class,xRowRes); + XResultSet xRes = UnoRuntime.queryInterface(XResultSet.class,xRowRes); xRes.last(); System.out.println("The RowCount is final: " + xProp.getPropertyValue("IsRowCountFinal")); System.out.println("There are " + xProp.getPropertyValue("RowCount") + " rows!"); // now destroy the RowSet - XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,xRowRes); + XComponent xComp = UnoRuntime.queryInterface(XComponent.class,xRowRes); xComp.dispose(); System.out.println("RowSet destroyed!"); } @@ -178,7 +178,7 @@ public class RowSet public static void showRowSetEvents() throws com.sun.star.uno.Exception { // first we create our RowSet object - XRowSet xRowRes = (XRowSet)UnoRuntime.queryInterface( + XRowSet xRowRes = UnoRuntime.queryInterface( XRowSet.class, xMCF.createInstanceWithContext("com.sun.star.sdb.RowSet", xContext)); @@ -186,12 +186,12 @@ public class RowSet // add our Listener System.out.println("Append our Listener!"); RowSetEventListener pRow = new RowSetEventListener(); - XRowSetApproveBroadcaster xApBroad = (XRowSetApproveBroadcaster)UnoRuntime.queryInterface(XRowSetApproveBroadcaster.class,xRowRes); + XRowSetApproveBroadcaster xApBroad = UnoRuntime.queryInterface(XRowSetApproveBroadcaster.class,xRowRes); xApBroad.addRowSetApproveListener(pRow); xRowRes.addRowSetListener(pRow); // set the properties needed to connect to a database - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,xRowRes); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,xRowRes); xProp.setPropertyValue("DataSourceName","Bibliography"); xProp.setPropertyValue("Command","biblio"); xProp.setPropertyValue("CommandType",new Integer(com.sun.star.sdb.CommandType.TABLE)); @@ -200,7 +200,7 @@ public class RowSet System.out.println("RowSet executed!"); // do some movements to check if we got all notifications - XResultSet xRes = (XResultSet)UnoRuntime.queryInterface(XResultSet.class,xRowRes); + XResultSet xRes = UnoRuntime.queryInterface(XResultSet.class,xRowRes); System.out.println("beforeFirst"); xRes.beforeFirst(); // this should lead to no notifications because @@ -226,7 +226,7 @@ public class RowSet System.out.println("We stand after the last row: " + xRes.isAfterLast()); // now destroy the RowSet - XComponent xComp = (XComponent)UnoRuntime.queryInterface(XComponent.class,xRowRes); + XComponent xComp = UnoRuntime.queryInterface(XComponent.class,xRowRes); xComp.dispose(); System.out.println("RowSet destroyed!"); } diff --git a/odk/examples/DevelopersGuide/Database/Sales.java b/odk/examples/DevelopersGuide/Database/Sales.java index 7e7c310b117f..c90ae134b3b1 100644 --- a/odk/examples/DevelopersGuide/Database/Sales.java +++ b/odk/examples/DevelopersGuide/Database/Sales.java @@ -99,7 +99,7 @@ public class Sales String query = "SELECT NAME, PRICE FROM SALES " + "WHERE SALENR = 1"; XResultSet rs = stmt.executeQuery(query); - XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, rs); + XRow row = UnoRuntime.queryInterface(XRow.class, rs); while (rs.next()) { String s = row.getString(1); float n = row.getFloat(2); @@ -112,13 +112,13 @@ public class Sales { // example for a programmatic way to do updates. XStatement stmt = con.createStatement(); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,stmt); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,stmt); xProp.setPropertyValue("ResultSetType", new java.lang.Integer(ResultSetType.SCROLL_INSENSITIVE)); xProp.setPropertyValue("ResultSetConcurrency", new java.lang.Integer(ResultSetConcurrency.UPDATABLE)); XResultSet srs = stmt.executeQuery("SELECT NAME, PRICE FROM SALES"); - XRow row = (XRow)UnoRuntime.queryInterface(XRow.class,srs); + XRow row = UnoRuntime.queryInterface(XRow.class,srs); srs.afterLast(); while (srs.previous()) { @@ -128,10 +128,10 @@ public class Sales } srs.last(); - XRowUpdate updateRow = (XRowUpdate)UnoRuntime.queryInterface(XRowUpdate.class,srs); + XRowUpdate updateRow = UnoRuntime.queryInterface(XRowUpdate.class,srs); updateRow.updateFloat(2, (float)0.69); - XResultSetUpdate updateRs = ( XResultSetUpdate )UnoRuntime.queryInterface( + XResultSetUpdate updateRs = UnoRuntime.queryInterface( XResultSetUpdate.class,srs); updateRs.updateRow(); // this call updates the data in DBMS @@ -151,15 +151,15 @@ public class Sales // "VALUES (4, 102, 5, 'FTOP Darjeeling tea', '2002-01-02',150)"); // // stmt = con.createStatement(); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,stmt); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,stmt); xProp.setPropertyValue("ResultSetType", new java.lang.Integer(ResultSetType.SCROLL_INSENSITIVE)); xProp.setPropertyValue("ResultSetConcurrency", new java.lang.Integer(ResultSetConcurrency.UPDATABLE)); XResultSet rs = stmt.executeQuery("SELECT * FROM SALES"); - XRow row = (XRow)UnoRuntime.queryInterface(XRow.class,rs); + XRow row = UnoRuntime.queryInterface(XRow.class,rs); // insert a new row - XRowUpdate updateRow = (XRowUpdate)UnoRuntime.queryInterface(XRowUpdate.class,rs); - XResultSetUpdate updateRs = ( XResultSetUpdate )UnoRuntime. queryInterface(XResultSetUpdate.class,rs); + XRowUpdate updateRow = UnoRuntime.queryInterface(XRowUpdate.class,rs); + XResultSetUpdate updateRs = UnoRuntime. queryInterface(XResultSetUpdate.class,rs); updateRs.moveToInsertRow(); updateRow.updateInt(1, 4); updateRow.updateInt(2, 102); @@ -175,13 +175,13 @@ public class Sales { // example for a programmatic way to do updates. XStatement stmt = con.createStatement(); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,stmt); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,stmt); xProp.setPropertyValue("ResultSetType", new java.lang.Integer(ResultSetType.SCROLL_INSENSITIVE)); xProp.setPropertyValue("ResultSetConcurrency", new java.lang.Integer(ResultSetConcurrency.UPDATABLE)); XResultSet rs = stmt.executeQuery("SELECT * FROM SALES"); - XRow row = (XRow)UnoRuntime.queryInterface(XRow.class,rs); + XRow row = UnoRuntime.queryInterface(XRow.class,rs); - XResultSetUpdate updateRs = ( XResultSetUpdate )UnoRuntime. queryInterface(XResultSetUpdate.class,rs); + XResultSetUpdate updateRs = UnoRuntime. queryInterface(XResultSetUpdate.class,rs); // move to the inserted row rs.absolute(4); updateRs.deleteRow(); @@ -195,17 +195,17 @@ public class Sales insertRow(); XStatement stmt = con.createStatement(); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,stmt); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,stmt); xProp.setPropertyValue("ResultSetType", new java.lang.Integer(ResultSetType.SCROLL_INSENSITIVE)); xProp.setPropertyValue("ResultSetConcurrency", new java.lang.Integer(ResultSetConcurrency.READ_ONLY)); XResultSet rs = stmt.executeQuery("SELECT NAME, PRICE FROM SALES"); - XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, rs); + XRow row = UnoRuntime.queryInterface(XRow.class, rs); rs.absolute(4); float price1 = row.getFloat(2); // modifiy the 4 row - XRowUpdate updateRow = (XRowUpdate)UnoRuntime.queryInterface(XRowUpdate.class,rs); - XResultSetUpdate updateRs = ( XResultSetUpdate )UnoRuntime. queryInterface(XResultSetUpdate.class,rs); + XRowUpdate updateRow = UnoRuntime.queryInterface(XRowUpdate.class,rs); + XResultSetUpdate updateRs = UnoRuntime. queryInterface(XResultSetUpdate.class,rs); updateRow.updateFloat(2, 150); updateRs.updateRow(); // repositioning @@ -224,12 +224,11 @@ public class Sales public void displayColumnNames() throws com.sun.star.uno.Exception { XStatement stmt = con.createStatement(); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,stmt); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,stmt); xProp.setPropertyValue("ResultSetType", new java.lang.Integer(ResultSetType.SCROLL_INSENSITIVE)); xProp.setPropertyValue("ResultSetConcurrency", new java.lang.Integer(ResultSetConcurrency.READ_ONLY)); XResultSet rs = stmt.executeQuery("SELECT NAME, PRICE FROM SALES"); - XResultSetMetaDataSupplier xRsMetaSup = (XResultSetMetaDataSupplier) - UnoRuntime.queryInterface(XResultSetMetaDataSupplier.class,rs); + XResultSetMetaDataSupplier xRsMetaSup = UnoRuntime.queryInterface(XResultSetMetaDataSupplier.class,rs); XResultSetMetaData xRsMetaData = xRsMetaSup.getMetaData(); int nColumnCount = xRsMetaData.getColumnCount(); for(int i=1 ; i <= nColumnCount ; ++i) diff --git a/odk/examples/DevelopersGuide/Database/SalesMan.java b/odk/examples/DevelopersGuide/Database/SalesMan.java index ee1171a7f26a..0eaa3cdab070 100644 --- a/odk/examples/DevelopersGuide/Database/SalesMan.java +++ b/odk/examples/DevelopersGuide/Database/SalesMan.java @@ -96,7 +96,7 @@ public class SalesMan { XPreparedStatement updateStreet = con.prepareStatement( "UPDATE SALESMAN SET STREET = ? WHERE SNR = ?"); - XParameters setPara = (XParameters)UnoRuntime.queryInterface(XParameters.class,updateStreet); + XParameters setPara = UnoRuntime.queryInterface(XParameters.class,updateStreet); setPara.setString(1, "34 Main Road"); setPara.setInt(2, 1); updateStreet.executeUpdate(); @@ -124,7 +124,7 @@ public class SalesMan { XStatement stmt = con.createStatement(); XResultSet rs = stmt.executeQuery("SELECT FIRSTNAME, LASTNAME, BIRTHDATE FROM SALESMAN"); - XRow row = (XRow)UnoRuntime.queryInterface(XRow.class,rs); + XRow row = UnoRuntime.queryInterface(XRow.class,rs); while ( rs != null && rs.next() ) { String fn = row.getString( 1 ); String ln = row.getString( 2 ); diff --git a/odk/examples/DevelopersGuide/Database/sdbcx.java b/odk/examples/DevelopersGuide/Database/sdbcx.java index 01677c7b8a84..696857b0344e 100644 --- a/odk/examples/DevelopersGuide/Database/sdbcx.java +++ b/odk/examples/DevelopersGuide/Database/sdbcx.java @@ -57,7 +57,7 @@ public class sdbcx test.createConnection(); test.displayTableProperties(); // now we dispose the connection to close it - XComponent xComponent = (XComponent)UnoRuntime.queryInterface(XComponent.class,con); + XComponent xComponent = UnoRuntime.queryInterface(XComponent.class,con); if(xComponent != null) { xComponent.dispose(); @@ -81,12 +81,12 @@ public class sdbcx // create a connector, so that it can contact the office Object xUrlResolver = xLocalServiceManager.createInstance( "com.sun.star.bridge.UnoUrlResolver" ); - XUnoUrlResolver urlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( + XUnoUrlResolver urlResolver = UnoRuntime.queryInterface( XUnoUrlResolver.class, xUrlResolver ); Object rInitialObject = urlResolver.resolve( "uno:" + connectStr + ";urp;StarOffice.NamingService" ); - XNamingService rName = (XNamingService)UnoRuntime.queryInterface( + XNamingService rName = UnoRuntime.queryInterface( XNamingService.class, rInitialObject ); XMultiServiceFactory xMSF = null; @@ -94,8 +94,7 @@ public class sdbcx System.err.println( "got the remote naming service !" ); Object rXsmgr = rName.getRegisteredObject("StarOffice.ServiceManager" ); - xMSF = (XMultiServiceFactory) - UnoRuntime.queryInterface( XMultiServiceFactory.class, rXsmgr ); + xMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, rXsmgr ); } return ( xMSF ); @@ -113,7 +112,7 @@ public class sdbcx Object aDriver = xORB.createInstance("com.sun.star.comp.sdbcx.adabas.ODriver"); // query for the interface com.sun.star.sdbc.XDriver xDriver; - xDriver = (XDriver)UnoRuntime.queryInterface(XDriver.class,aDriver); + xDriver = UnoRuntime.queryInterface(XDriver.class,aDriver); if(xDriver != null) { // first create the needed url @@ -132,7 +131,7 @@ public class sdbcx { System.out.println("Connection could be created!"); // we the XDatabaseDefinitionSupplier interface from the driver to get the XTablesSupplier - XDataDefinitionSupplier xDDSup = (XDataDefinitionSupplier)UnoRuntime.queryInterface( + XDataDefinitionSupplier xDDSup = UnoRuntime.queryInterface( XDataDefinitionSupplier.class,xDriver); if(xDDSup != null) { @@ -162,7 +161,7 @@ public class sdbcx if(0 != aTableNames.length) { Object table = xTables.getByName(aTableNames[0]); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,table); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,table); System.out.println("Name: " + xProp.getPropertyValue("Name")); System.out.println("CatalogName: " + xProp.getPropertyValue("CatalogName")); System.out.println("SchemaName: " + xProp.getPropertyValue("SchemaName")); @@ -194,7 +193,7 @@ public class sdbcx public static void printKeys(XColumnsSupplier xColumnsSup) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example printKeys"); - XKeysSupplier xKeysSup = (XKeysSupplier)UnoRuntime.queryInterface(XKeysSupplier.class,xColumnsSup); + XKeysSupplier xKeysSup = UnoRuntime.queryInterface(XKeysSupplier.class,xColumnsSup); if(xKeysSup != null) { System.out.println("--- Keys ---"); @@ -202,9 +201,9 @@ public class sdbcx for ( int i =0; i < xKeys.getCount(); i++) { Object key = xKeys.getByIndex(i); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,key); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,key); System.out.println(" " + xProp.getPropertyValue("Name")); - XColumnsSupplier xKeyColumnsSup = ( XColumnsSupplier ) UnoRuntime.queryInterface(XColumnsSupplier.class,xProp); + XColumnsSupplier xKeyColumnsSup = UnoRuntime.queryInterface(XColumnsSupplier.class,xProp); printColumns(xKeyColumnsSup); } } @@ -216,7 +215,7 @@ public class sdbcx public static void printIndexes(XColumnsSupplier xColumnsSup) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example printIndexes"); - XIndexesSupplier xIndexesSup = (XIndexesSupplier)UnoRuntime.queryInterface(XIndexesSupplier.class,xColumnsSup); + XIndexesSupplier xIndexesSup = UnoRuntime.queryInterface(XIndexesSupplier.class,xColumnsSup); if(xIndexesSup != null) { System.out.println("--- Indexes ---"); @@ -226,7 +225,7 @@ public class sdbcx { System.out.println(" " + aIndexNames[i]); Object index = xIndexs.getByName(aIndexNames[i]); - XColumnsSupplier xIndexColumnsSup = (XColumnsSupplier)UnoRuntime.queryInterface(XColumnsSupplier.class,index); + XColumnsSupplier xIndexColumnsSup = UnoRuntime.queryInterface(XColumnsSupplier.class,index); printColumns(xIndexColumnsSup); } } @@ -239,7 +238,7 @@ public class sdbcx public static void printColumnProperties(Object column) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example printColumnProperties"); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,column); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,column); System.out.println("Name: " + xProp.getPropertyValue("Name")); System.out.println("Type: " + xProp.getPropertyValue("Type")); System.out.println("TypeName: " + xProp.getPropertyValue("TypeName")); @@ -264,7 +263,7 @@ public class sdbcx public static void printIndexProperties(Object index) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example printIndexProperties"); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,index); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,index); System.out.println("Name: " + xProp.getPropertyValue("Name")); System.out.println("Catalog: " + xProp.getPropertyValue("Catalog")); System.out.println("IsUnique: " + xProp.getPropertyValue("IsUnique")); @@ -279,7 +278,7 @@ public class sdbcx public static void printKeyProperties(Object key) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example printKeyProperties"); - XPropertySet xProp = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,key); + XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class,key); System.out.println("Name: " + xProp.getPropertyValue("Name")); System.out.println("Type: " + xProp.getPropertyValue("Type")); System.out.println("ReferencedTable: " + xProp.getPropertyValue("ReferencedTable")); @@ -294,7 +293,7 @@ public class sdbcx public static void printGroups(XTablesSupplier xTabSup) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example printGroups"); - XGroupsSupplier xGroupsSup = (XGroupsSupplier)UnoRuntime.queryInterface(XGroupsSupplier.class,xTabSup); + XGroupsSupplier xGroupsSup = UnoRuntime.queryInterface(XGroupsSupplier.class,xTabSup); if(xGroupsSup != null) { // the table must be at least support a XColumnsSupplier interface @@ -304,10 +303,10 @@ public class sdbcx for ( int i =0; i < aGroupNames.length; i++) { System.out.println(" " + aGroupNames[i]); - XUsersSupplier xUsersSup = (XUsersSupplier)UnoRuntime.queryInterface(XUsersSupplier.class,xGroups.getByName(aGroupNames[i])); + XUsersSupplier xUsersSup = UnoRuntime.queryInterface(XUsersSupplier.class,xGroups.getByName(aGroupNames[i])); if(xUsersSup != null) { - XAuthorizable xAuth = (XAuthorizable)UnoRuntime.queryInterface(XAuthorizable.class,xUsersSup); + XAuthorizable xAuth = UnoRuntime.queryInterface(XAuthorizable.class,xUsersSup); // the table must be at least support a XColumnsSupplier interface System.out.println("\t--- Users ---"); XNameAccess xUsers = xUsersSup.getUsers(); @@ -328,7 +327,7 @@ public class sdbcx public static void createTableSalesMen(XNameAccess xTables) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example createTableSalesMen"); - XDataDescriptorFactory xTabFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(XDataDescriptorFactory.class,xTables); + XDataDescriptorFactory xTabFac = UnoRuntime.queryInterface(XDataDescriptorFactory.class,xTables); if(xTabFac != null) { // create the new table @@ -336,9 +335,9 @@ public class sdbcx // set the name of the new table xTable.setPropertyValue("Name","SALESMAN"); // append the columns - XColumnsSupplier xColumSup = (XColumnsSupplier)UnoRuntime.queryInterface(XColumnsSupplier.class,xTable); - XDataDescriptorFactory xColFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(XDataDescriptorFactory.class,xColumSup.getColumns()); - XAppend xAppend = (XAppend)UnoRuntime.queryInterface(XAppend.class,xColFac); + XColumnsSupplier xColumSup = UnoRuntime.queryInterface(XColumnsSupplier.class,xTable); + XDataDescriptorFactory xColFac = UnoRuntime.queryInterface(XDataDescriptorFactory.class,xColumSup.getColumns()); + XAppend xAppend = UnoRuntime.queryInterface(XAppend.class,xColFac); // we only need one descriptor XPropertySet xCol = xColFac.createDataDescriptor(); // create first column and append @@ -374,15 +373,15 @@ public class sdbcx xCol.setPropertyValue("Precision",new Integer(10)); // default value integer xAppend.appendByDescriptor(xCol); // now we create the primary key - XKeysSupplier xKeySup = (XKeysSupplier)UnoRuntime.queryInterface(XKeysSupplier.class,xTable); - XDataDescriptorFactory xKeyFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(XDataDescriptorFactory.class,xKeySup.getKeys()); - XAppend xKeyAppend = (XAppend)UnoRuntime.queryInterface(XAppend.class,xKeyFac); + XKeysSupplier xKeySup = UnoRuntime.queryInterface(XKeysSupplier.class,xTable); + XDataDescriptorFactory xKeyFac = UnoRuntime.queryInterface(XDataDescriptorFactory.class,xKeySup.getKeys()); + XAppend xKeyAppend = UnoRuntime.queryInterface(XAppend.class,xKeyFac); XPropertySet xKey = xKeyFac.createDataDescriptor(); xKey.setPropertyValue("Type",new Integer(KeyType.PRIMARY)); // now append the columns to key - XColumnsSupplier xKeyColumSup = (XColumnsSupplier)UnoRuntime.queryInterface(XColumnsSupplier.class,xKey); - XDataDescriptorFactory xKeyColFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(XDataDescriptorFactory.class,xKeyColumSup.getColumns()); - XAppend xKeyColAppend = (XAppend)UnoRuntime.queryInterface(XAppend.class,xKeyColFac); + XColumnsSupplier xKeyColumSup = UnoRuntime.queryInterface(XColumnsSupplier.class,xKey); + XDataDescriptorFactory xKeyColFac = UnoRuntime.queryInterface(XDataDescriptorFactory.class,xKeyColumSup.getColumns()); + XAppend xKeyColAppend = UnoRuntime.queryInterface(XAppend.class,xKeyColFac); // we only need one descriptor XPropertySet xKeyCol = xKeyColFac.createDataDescriptor(); xKeyCol.setPropertyValue("Name","SNR"); @@ -391,7 +390,7 @@ public class sdbcx // apend the key xKeyAppend.appendByDescriptor(xKey); // the last step is to append the new table to the tables collection - XAppend xTableAppend = (XAppend)UnoRuntime.queryInterface(XAppend.class,xTabFac); + XAppend xTableAppend = UnoRuntime.queryInterface(XAppend.class,xTabFac); xTableAppend.appendByDescriptor(xTable); } } @@ -403,7 +402,7 @@ public class sdbcx public static void createUser(XNameAccess xUsers) throws com.sun.star.uno.Exception,SQLException { System.out.println("Example createUser"); - XDataDescriptorFactory xUserFac = (XDataDescriptorFactory)UnoRuntime.queryInterface(XDataDescriptorFactory.class,xUsers); + XDataDescriptorFactory xUserFac = UnoRuntime.queryInterface(XDataDescriptorFactory.class,xUsers); if(xUserFac != null) { // create the new table @@ -411,7 +410,7 @@ public class sdbcx // set the name of the new table xUser.setPropertyValue("Name","BOSS"); xUser.setPropertyValue("Password","BOSSWIFENAME"); - XAppend xAppend = (XAppend)UnoRuntime.queryInterface(XAppend.class,xUserFac); + XAppend xAppend = UnoRuntime.queryInterface(XAppend.class,xUserFac); xAppend.appendByDescriptor(xUser); } } diff --git a/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java b/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java index fd407358a00a..0518e327bba3 100644 --- a/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java @@ -77,8 +77,7 @@ public class ChangeOrderDemo // create two rectangles XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xShape1 = ShapeHelper.createShape( xDrawDoc, new Point( 1000, 1000 ), new Size( 5000, 5000 ), @@ -93,10 +92,8 @@ public class ChangeOrderDemo ShapeHelper.addPortion( xShape1, "by changing the ZOrder it lie now on top", true ); xShapes.add( xShape2 ); - XPropertySet xPropSet1 = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape1 ); - XPropertySet xPropSet2 = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape2 ); + XPropertySet xPropSet1 = UnoRuntime.queryInterface( XPropertySet.class, xShape1 ); + XPropertySet xPropSet2 = UnoRuntime.queryInterface( XPropertySet.class, xShape2 ); int nOrderOfShape1 = ((Integer)xPropSet1.getPropertyValue( "ZOrder" )).intValue(); int nOrderOfShape2 = ((Integer)xPropSet2.getPropertyValue( "ZOrder" )).intValue(); diff --git a/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java b/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java index 2af75e409c63..654c3b2feae1 100644 --- a/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java @@ -88,46 +88,45 @@ public class ControlAndSelectDemo "private:factory/sdraw", "_blank", 0, pPropValues ); XMultiServiceFactory xFactory = - (XMultiServiceFactory )UnoRuntime.queryInterface( - XMultiServiceFactory.class, xComponent ); + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xComponent ); XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface( + XDrawPage xDrawPage = UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex( 0 )); - XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, xDrawPage ); // create and insert the ControlShape Object xObj = xFactory.createInstance( "com.sun.star.drawing.ControlShape" ); - XShape xShape = (XShape)UnoRuntime.queryInterface( XShape.class, xObj ); + XShape xShape = UnoRuntime.queryInterface( XShape.class, xObj ); xShape.setPosition( new Point( 1000, 1000 ) ); xShape.setSize( new Size( 2000, 2000 ) ); xShapes.add( xShape ); // create and set the control - XControlModel xControlModel = (XControlModel)UnoRuntime.queryInterface( + XControlModel xControlModel = UnoRuntime.queryInterface( XControlModel.class, xFactory.createInstance( "com.sun.star.form.component.GroupBox" ) ); - XControlShape xControlShape = (XControlShape)UnoRuntime.queryInterface( + XControlShape xControlShape = UnoRuntime.queryInterface( XControlShape.class, xShape ); xControlShape.setControl( xControlModel ); // the following code will demonstrate how to // make a selection that contains our new created ControlShape - XModel xModel = (XModel)UnoRuntime.queryInterface( XModel.class, + XModel xModel = UnoRuntime.queryInterface( XModel.class, xComponent ); XController xController = xModel.getCurrentController(); - XSelectionSupplier xSelectionSupplier =(XSelectionSupplier) - UnoRuntime.queryInterface( XSelectionSupplier.class, xController ); + XSelectionSupplier xSelectionSupplier =UnoRuntime.queryInterface( XSelectionSupplier.class, xController ); // take care to use the global service factory only and not the one // that is provided by the component if you create the ShapeColletion - XShapes xSelection = (XShapes)UnoRuntime.queryInterface( XShapes.class, + XShapes xSelection = UnoRuntime.queryInterface( XShapes.class, xOfficeContext.getServiceManager().createInstanceWithContext( "com.sun.star.drawing.ShapeCollection", xOfficeContext ) ); xSelection.add( xShape ); diff --git a/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java b/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java index 88b09888eab3..322868efdd8d 100644 --- a/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java @@ -89,11 +89,11 @@ public class CustomShowDemo pPropValues[ 0 ].Value = new Boolean( true ); xDrawDoc = Helper.createDocument( xOfficeContext, - "private:factory/simpress", "_blank", 0, pPropValues ); + "private:factory/simpress", "_blank", 0, pPropValues ); XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xDrawDoc ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xDrawDoc ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); // take care that this document has ten pages @@ -106,9 +106,9 @@ public class CustomShowDemo int i; for ( i = 0; i < 10; i++ ) { - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface( + XDrawPage xDrawPage = UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex( i )); - XNamed xPageName = (XNamed)UnoRuntime.queryInterface( + XNamed xPageName = UnoRuntime.queryInterface( XNamed.class, xDrawPage ); xPageName.setName( aNameArray[ i ] ); @@ -116,22 +116,19 @@ public class CustomShowDemo XShape xTextObj = ShapeHelper.createShape( xDrawDoc, new Point( 10000, 9000 ), new Size( 10000, 5000 ), "com.sun.star.drawing.TextShape" ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapes.add( xTextObj ); ShapeHelper.addPortion( xTextObj, aNameArray[ i ], true ); } /* create two custom shows, one will play slide 6 to 10 and is named "ShortVersion" the other one will play slide 2 til 10 and is named "LongVersion" */ - XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier) - UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc ); + XCustomPresentationSupplier xCustPresSupplier = UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc ); /* the following container is a container for further container which concludes the list of pages that are to play within a custom show */ XNameContainer xNameContainer = xCustPresSupplier.getCustomPresentations(); - XSingleServiceFactory xFactory = (XSingleServiceFactory) - UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer ); + XSingleServiceFactory xFactory = UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer ); Object xObj; XIndexContainer xContainer; @@ -139,7 +136,7 @@ public class CustomShowDemo /* instanciate an IndexContainer that will take a list of draw pages for the first custom show */ xObj = xFactory.createInstance(); - xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj ); + xContainer = UnoRuntime.queryInterface( XIndexContainer.class, xObj ); for ( i = 5; i < 10; i++ ) xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) ); xNameContainer.insertByName( "ShortVersion", xContainer ); @@ -147,7 +144,7 @@ public class CustomShowDemo /* instanciate an IndexContainer that will take a list of draw page for the second custom show */ xObj = xFactory.createInstance(); - xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj ); + xContainer = UnoRuntime.queryInterface( XIndexContainer.class, xObj ); for ( i = 1; i < 10; i++ ) xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) ); xNameContainer.insertByName( "LongVersion", xContainer ); @@ -155,11 +152,9 @@ public class CustomShowDemo /* which custom show is to use can been set in the presentation settings */ - XPresentationSupplier xPresSupplier = (XPresentationSupplier) - UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); + XPresentationSupplier xPresSupplier = UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); XPresentation xPresentation = xPresSupplier.getPresentation(); - XPropertySet xPresPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); + XPropertySet xPresPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); xPresPropSet.setPropertyValue( "CustomShow", "ShortVersion" ); } catch( Exception ex ) diff --git a/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java b/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java index 41780cfb6786..efea885c8693 100644 --- a/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java @@ -88,15 +88,15 @@ public class DrawViewDemo sUrl.toString(), "_blank", 0, pPropValues ); XModel xModel = - (XModel)UnoRuntime.queryInterface( - XModel.class, xComponent ); + UnoRuntime.queryInterface( + XModel.class, xComponent ); // print all available properties of first view System.out.println("*** print all available properties of first view"); XViewDataSupplier xViewDataSupplier = - (XViewDataSupplier)UnoRuntime.queryInterface( - XViewDataSupplier.class, xModel ); + UnoRuntime.queryInterface( + XViewDataSupplier.class, xModel ); XIndexAccess xIndexAccess = xViewDataSupplier.getViewData(); if ( xIndexAccess.getCount() != 0 ) { @@ -116,8 +116,8 @@ public class DrawViewDemo System.out.println("*** print all properties that are supported by the controller"); XController xController = xModel.getCurrentController(); XPropertySet xPropSet = - (XPropertySet)UnoRuntime.queryInterface( - XPropertySet.class, xController ); + UnoRuntime.queryInterface( + XPropertySet.class, xController ); XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo(); Property[] aPropSeq = xPropSetInfo.getProperties(); for( int i = 0; i < aPropSeq.length; i++ ) diff --git a/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java b/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java index 15cf5775b12b..28d91600500f 100644 --- a/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java @@ -166,7 +166,7 @@ public class DrawingDemo PageHelper.getDrawPageCount( xDrawDoc ) - 1 ); // each drawpage is supporting an XNamed interface - XNamed xNamed = (XNamed)UnoRuntime.queryInterface( + XNamed xNamed = UnoRuntime.queryInterface( XNamed.class, xLastPage ); // beware, the page must have an unique name @@ -249,8 +249,7 @@ public class DrawingDemo int nRndObjPosY = aRndGen.nextInt( nHalfHeight - nRndObjHeight ) + nHalfHeight; - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, pPages[ i ] ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, pPages[ i ] ); ShapeHelper.createAndInsertShape( xDrawDoc, xShapes, new Point( nRndObjPosX, nRndObjPosY ), new Size( nRndObjWidth, nRndObjHeight ), @@ -283,16 +282,13 @@ public class DrawingDemo xDrawPage = PageHelper.getMasterPageByIndex( xDrawDoc, 0 ); else xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapes.add( xPolyPolygonBezier ); - XPropertySet xShapeProperties = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPolyPolygonBezier ); + XPropertySet xShapeProperties = UnoRuntime.queryInterface( XPropertySet.class, xPolyPolygonBezier ); // get pagesize - XPropertySet xPageProperties = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); + XPropertySet xPageProperties = UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); int nPageWidth = ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue() / 2; int nPageHeight = ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() / 2; @@ -369,12 +365,10 @@ public class DrawingDemo // before it is possible to insert shapes, // the group must have been added to the page XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapes.add( xGroup ); - XShapes xShapesGroup = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xGroup ); + XShapes xShapesGroup = UnoRuntime.queryInterface( XShapes.class, xGroup ); Size aPageSize = PageHelper.getPageSize( xDrawPage ); @@ -408,11 +402,9 @@ public class DrawingDemo try { XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapeGrouper xShapeGrouper = (XShapeGrouper) - UnoRuntime.queryInterface( XShapeGrouper.class, xDrawPage ); + XShapeGrouper xShapeGrouper = UnoRuntime.queryInterface( XShapeGrouper.class, xDrawPage ); - XShapes xShapesPage = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapesPage = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapeGrouper.group( xShapesPage ); } diff --git a/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java b/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java index be32f589106b..472ae81c6340 100644 --- a/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java @@ -84,12 +84,10 @@ public class FillAndLineStyleDemo new Size( 15000, 12000 ), "com.sun.star.drawing.RectangleShape" ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); xShapes.add( xRectangle ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); /* apply a gradient fill style that goes from top left to bottom right and is changing its color from green to yellow */ diff --git a/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java b/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java index 4b9b08f07b9b..5f1a32e06493 100644 --- a/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java @@ -84,8 +84,7 @@ public class GluePointDemo XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); // create two rectangles XShape xShape1 = ShapeHelper.createShape( xDrawDoc, @@ -106,8 +105,7 @@ public class GluePointDemo xShapes.add( xShape2 ); xShapes.add( xConnector ); - XPropertySet xConnectorPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xConnector ); + XPropertySet xConnectorPropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector ); // Index value of 0 : the shape is connected at the top // Index value of 1 : the shape is connected at the left @@ -140,21 +138,17 @@ public class GluePointDemo aGluePoint.Position.Y = 0; // create and insert a glue point at shape1 - xGluePointsSupplier = (XGluePointsSupplier) - UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 ); + xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 ); xIndexContainer = xGluePointsSupplier.getGluePoints(); - xIdentifierContainer = (XIdentifierContainer) - UnoRuntime.queryInterface( XIdentifierContainer.class, - xIndexContainer ); + xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class, + xIndexContainer ); int nIndexOfGluePoint1 = xIdentifierContainer.insert( aGluePoint ); // create and insert a glue point at shape2 - xGluePointsSupplier = (XGluePointsSupplier) - UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 ); + xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 ); xIndexContainer = xGluePointsSupplier.getGluePoints(); - xIdentifierContainer = (XIdentifierContainer) - UnoRuntime.queryInterface( XIdentifierContainer.class, - xIndexContainer ); + xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class, + xIndexContainer ); int nIndexOfGluePoint2 = xIdentifierContainer.insert( aGluePoint ); // create and add a connector @@ -164,8 +158,7 @@ public class GluePointDemo "com.sun.star.drawing.ConnectorShape" ); xShapes.add( xConnector2 ); - XPropertySet xConnector2PropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xConnector2 ); + XPropertySet xConnector2PropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector2 ); xConnector2PropSet.setPropertyValue( "StartShape", xShape1 ); xConnector2PropSet.setPropertyValue( "StartGluePointIndex", diff --git a/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java b/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java index 25aa1b3ed771..dc93c75b28c2 100644 --- a/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java @@ -84,8 +84,7 @@ public class GraphicExportDemo Object GraphicExportFilter = xOfficeContext.getServiceManager().createInstanceWithContext( "com.sun.star.drawing.GraphicExportFilter", xOfficeContext); - XExporter xExporter = (XExporter) - UnoRuntime.queryInterface( XExporter.class, GraphicExportFilter ); + XExporter xExporter = UnoRuntime.queryInterface( XExporter.class, GraphicExportFilter ); PropertyValue aProps[] = new PropertyValue[2]; aProps[0] = new PropertyValue(); @@ -110,11 +109,9 @@ public class GraphicExportDemo { XDrawPage xPage = PageHelper.getDrawPageByIndex( xComponent, nPageIndex ); - XComponent xComp = (XComponent) - UnoRuntime.queryInterface( XComponent.class, xPage ); + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, xPage ); xExporter.setSourceDocument( xComp ); - XFilter xFilter = (XFilter) - UnoRuntime.queryInterface( XFilter.class, xExporter ); + XFilter xFilter = UnoRuntime.queryInterface( XFilter.class, xExporter ); xFilter.filter( aProps ); System.out.println( "*** graphics on page \"" + nPageIndex + "\" from file \"" + args[0] @@ -127,9 +124,8 @@ public class GraphicExportDemo // close the 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); diff --git a/odk/examples/DevelopersGuide/Drawing/Helper.java b/odk/examples/DevelopersGuide/Drawing/Helper.java index efd952ac0ce9..a232e9418be4 100644 --- a/odk/examples/DevelopersGuide/Drawing/Helper.java +++ b/odk/examples/DevelopersGuide/Drawing/Helper.java @@ -35,6 +35,9 @@ // __________ Imports __________ import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XComponent; +import com.sun.star.frame.XComponentLoader; public class Helper { @@ -44,11 +47,11 @@ public class Helper * A new connection is established and the service manger from the running * offic eis returned. */ - static public com.sun.star.uno.XComponentContext connect() + static public XComponentContext connect() throws Exception { // get the remote office component context - com.sun.star.uno.XComponentContext xOfficeContext = + XComponentContext xOfficeContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); // if connection fails an exception is thrown @@ -65,15 +68,15 @@ public class Helper com.sun.star.beans.PropertyValue[] aArgs ) throws Exception { - com.sun.star.lang.XComponent xComponent = null; - com.sun.star.frame.XComponentLoader aLoader = - (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface( - com.sun.star.frame.XComponentLoader.class, - xOfficeContext.getServiceManager().createInstanceWithContext( - "com.sun.star.frame.Desktop", xOfficeContext)); + XComponentLoader aLoader = + UnoRuntime.queryInterface( + XComponentLoader.class, + xOfficeContext.getServiceManager().createInstanceWithContext( + "com.sun.star.frame.Desktop", xOfficeContext)); - xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface( - com.sun.star.lang.XComponent.class, aLoader.loadComponentFromURL( + XComponent xComponent = + UnoRuntime.queryInterface( + XComponent.class, aLoader.loadComponentFromURL( sURL, sTargetFrame, nSearchFlags, aArgs ) ); if ( xComponent == null ) diff --git a/odk/examples/DevelopersGuide/Drawing/LayerDemo.java b/odk/examples/DevelopersGuide/Drawing/LayerDemo.java index eec7171d5525..cbf66354ba14 100644 --- a/odk/examples/DevelopersGuide/Drawing/LayerDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/LayerDemo.java @@ -84,8 +84,7 @@ public class LayerDemo // create two rectangles XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xRect1 = ShapeHelper.createShape( xDrawDoc, new Point( 1000, 1000 ), new Size( 5000, 5000 ), @@ -109,12 +108,10 @@ public class LayerDemo // query for the XLayerManager - XLayerSupplier xLayerSupplier = (XLayerSupplier) - (XLayerSupplier)UnoRuntime.queryInterface( + XLayerSupplier xLayerSupplier = UnoRuntime.queryInterface( XLayerSupplier.class, xDrawDoc ); XNameAccess xNameAccess = xLayerSupplier.getLayerManager(); - XLayerManager xLayerManager = (XLayerManager) - (XLayerManager)UnoRuntime.queryInterface( + XLayerManager xLayerManager = UnoRuntime.queryInterface( XLayerManager.class, xNameAccess ); // create a layer and set its properties @@ -122,8 +119,7 @@ public class LayerDemo XLayer xNotVisibleAndEditable = xLayerManager.insertNewByIndex( xLayerManager.getCount() ); - xLayerPropSet = (XPropertySet) - (XPropertySet)UnoRuntime.queryInterface( + xLayerPropSet = UnoRuntime.queryInterface( XPropertySet.class, xNotVisibleAndEditable ); xLayerPropSet.setPropertyValue( "Name", "NotVisibleAndEditable" ); xLayerPropSet.setPropertyValue( "IsVisible", new Boolean( false ) ); @@ -133,8 +129,7 @@ public class LayerDemo XLayer xNotEditable = xLayerManager.insertNewByIndex( xLayerManager.getCount() ); - xLayerPropSet = (XPropertySet) - (XPropertySet)UnoRuntime.queryInterface( + xLayerPropSet = UnoRuntime.queryInterface( XPropertySet.class, xNotEditable ); xLayerPropSet.setPropertyValue( "Name", "NotEditable" ); xLayerPropSet.setPropertyValue( "IsVisible", new Boolean( true ) ); diff --git a/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java b/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java index 4b09ea0ec72b..f45326a185b9 100644 --- a/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java @@ -77,11 +77,9 @@ public class ObjectTransformationDemo "private:factory/simpress", "_blank", 0, pPropValues ); XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XPropertySet xPagePropSet= (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPage ); + XPropertySet xPagePropSet= UnoRuntime.queryInterface( XPropertySet.class, xPage ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xShape = ShapeHelper.createShape( xDrawDoc, @@ -89,8 +87,7 @@ public class ObjectTransformationDemo "com.sun.star.drawing.RectangleShape" ); xShapes.add( xShape ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3) xPropSet.getPropertyValue( "Transformation" ); diff --git a/odk/examples/DevelopersGuide/Drawing/Organigram.java b/odk/examples/DevelopersGuide/Drawing/Organigram.java index 5b0bdf0f8b39..362f38a2e6f8 100644 --- a/odk/examples/DevelopersGuide/Drawing/Organigram.java +++ b/odk/examples/DevelopersGuide/Drawing/Organigram.java @@ -82,8 +82,7 @@ public class Organigram { Object desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, desktop); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; XComponent xDrawComponent = xComponentLoader.loadComponentFromURL( @@ -91,22 +90,21 @@ public class Organigram { // get draw page by index com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier = - (com.sun.star.drawing.XDrawPagesSupplier)UnoRuntime.queryInterface( - com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent ); + UnoRuntime.queryInterface( + com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent ); com.sun.star.drawing.XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); Object drawPage = xDrawPages.getByIndex(0); - com.sun.star.drawing.XDrawPage xDrawPage = (com.sun.star.drawing.XDrawPage) - UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, - drawPage); + com.sun.star.drawing.XDrawPage xDrawPage = UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, + drawPage); com.sun.star.lang.XMultiServiceFactory xDocumentFactory = - (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent); + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent); com.sun.star.beans.XPropertySet xPageProps = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, xDrawPage); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xDrawPage); int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width")); int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height")); @@ -144,15 +142,13 @@ public class Organigram { (levelCount[level] - 1) * horSpace) / 2 + i * shapeWidth + i * horSpace; Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape"); - com.sun.star.drawing.XShape xShape = (com.sun.star.drawing.XShape) - UnoRuntime.queryInterface( + com.sun.star.drawing.XShape xShape = UnoRuntime.queryInterface( com.sun.star.drawing.XShape.class, shape); xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY)); xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight)); xDrawPage.add(xShape); - com.sun.star.text.XText xText = (com.sun.star.text.XText) - UnoRuntime.queryInterface( + com.sun.star.text.XText xText = UnoRuntime.queryInterface( com.sun.star.text.XText.class, xShape); xText.setString(orgUnits[level][i]); @@ -164,11 +160,11 @@ public class Organigram { if (level == 1) { Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape"); com.sun.star.beans.XPropertySet xConnectorProps = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, connector); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, connector); com.sun.star.drawing.XShape xConnector = - (com.sun.star.drawing.XShape)UnoRuntime.queryInterface( - com.sun.star.drawing.XShape.class, connector); + UnoRuntime.queryInterface( + com.sun.star.drawing.XShape.class, connector); xDrawPage.add(xConnector); xConnectorProps.setPropertyValue("StartShape", xStartShape); xConnectorProps.setPropertyValue("EndShape", xShape); diff --git a/odk/examples/DevelopersGuide/Drawing/PageHelper.java b/odk/examples/DevelopersGuide/Drawing/PageHelper.java index c612afa4e61b..b6bb684453ed 100644 --- a/odk/examples/DevelopersGuide/Drawing/PageHelper.java +++ b/odk/examples/DevelopersGuide/Drawing/PageHelper.java @@ -63,8 +63,8 @@ public class PageHelper static public int getDrawPageCount( XComponent xComponent ) { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); return xDrawPages.getCount(); } @@ -76,10 +76,10 @@ public class PageHelper com.sun.star.lang.WrappedTargetException { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); - return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); + return UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); } /** creates and inserts a draw page into the giving position, @@ -89,8 +89,8 @@ public class PageHelper throws Exception { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); return xDrawPages.insertNewByIndex( nIndex ); } @@ -100,8 +100,8 @@ public class PageHelper static public void removeDrawPage( XComponent xComponent, XDrawPage xDrawPage ) { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); xDrawPages.remove( xDrawPage ); } @@ -112,8 +112,7 @@ public class PageHelper throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { - XPropertySet xPageProperties = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); + XPropertySet xPageProperties = UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); return new Size( ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue(), ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() ); @@ -126,8 +125,8 @@ public class PageHelper static public int getMasterPageCount( XComponent xComponent ) { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); return xDrawPages.getCount(); } @@ -139,10 +138,10 @@ public class PageHelper com.sun.star.lang.WrappedTargetException { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); - return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); + return UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); } /** creates and inserts a new master page into the giving position, @@ -151,8 +150,8 @@ public class PageHelper static public XDrawPage insertNewMasterPageByIndex( XComponent xComponent, int nIndex ) { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); return xDrawPages.insertNewByIndex( nIndex ); } @@ -162,8 +161,8 @@ public class PageHelper static public void removeMasterPage( XComponent xComponent, XDrawPage xDrawPage ) { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); xDrawPages.remove( xDrawPage ); } @@ -173,8 +172,8 @@ public class PageHelper static public XDrawPage getMasterPage( XDrawPage xDrawPage ) { XMasterPageTarget xMasterPageTarget = - (XMasterPageTarget)UnoRuntime.queryInterface( - XMasterPageTarget.class, xDrawPage ); + UnoRuntime.queryInterface( + XMasterPageTarget.class, xDrawPage ); return xMasterPageTarget.getMasterPage(); } @@ -183,8 +182,8 @@ public class PageHelper static public void setMasterPage( XDrawPage xDrawPage, XDrawPage xMasterPage ) { XMasterPageTarget xMasterPageTarget = - (XMasterPageTarget)UnoRuntime.queryInterface( - XMasterPageTarget.class, xDrawPage ); + UnoRuntime.queryInterface( + XMasterPageTarget.class, xDrawPage ); xMasterPageTarget.setMasterPage( xMasterPage ); } @@ -196,7 +195,7 @@ public class PageHelper */ static public boolean isImpressDocument( XComponent xComponent ) { - XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo xInfo = UnoRuntime.queryInterface( XServiceInfo.class, xComponent ); return xInfo.supportsService( "com.sun.star.presentation.PresentationDocument" ); } @@ -206,8 +205,8 @@ public class PageHelper static public XDrawPage getNotesPage( XDrawPage xDrawPage ) { XPresentationPage aPresentationPage = - (XPresentationPage)UnoRuntime.queryInterface( - XPresentationPage.class, xDrawPage ); + UnoRuntime.queryInterface( + XPresentationPage.class, xDrawPage ); return aPresentationPage.getNotesPage(); } @@ -216,8 +215,8 @@ public class PageHelper static public XDrawPage getHandoutMasterPage( XComponent xComponent ) { XHandoutMasterSupplier aHandoutMasterSupplier = - (XHandoutMasterSupplier)UnoRuntime.queryInterface( - XHandoutMasterSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XHandoutMasterSupplier.class, xComponent ); return aHandoutMasterSupplier.getHandoutMasterPage(); } } diff --git a/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java b/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java index 652d8b51a0e8..61e62d2cfadf 100644 --- a/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java @@ -99,8 +99,7 @@ public class PresentationDemo // set the slide transition for the first page xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); // set slide transition effect setSlideTransition( xPage, com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, @@ -124,8 +123,7 @@ public class PresentationDemo // set the slide transition for the second page xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 1 ); - xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); setSlideTransition( xPage, com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, com.sun.star.presentation.AnimationSpeed.SLOW, @@ -145,8 +143,7 @@ public class PresentationDemo // the second object lets the presentation jump to page two // by using a ClickAction.BOOKMARK; xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 2 ); - xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); setSlideTransition( xPage, com.sun.star.presentation.FadeEffect.ROLL_FROM_LEFT, com.sun.star.presentation.AnimationSpeed.MEDIUM, @@ -157,8 +154,7 @@ public class PresentationDemo xShapes.add( xShape ); ShapeHelper.addPortion( xShape, "click to go", false ); ShapeHelper.addPortion( xShape, "to first page", true ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); xShapePropSet.setPropertyValue("Effect", com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM ); xShapePropSet.setPropertyValue( @@ -171,15 +167,14 @@ public class PresentationDemo xShapes.add( xShape ); ShapeHelper.addPortion( xShape, "click to go", false ); ShapeHelper.addPortion( xShape, "to the second page", true ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); xShapePropSet.setPropertyValue("Effect", com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM ); xShapePropSet.setPropertyValue( "OnClick", com.sun.star.presentation.ClickAction.BOOKMARK ); // set the name of page two, and use it with the bookmark action - XNamed xPageName = (XNamed)UnoRuntime.queryInterface( + XNamed xPageName = UnoRuntime.queryInterface( XNamed.class, PageHelper.getDrawPageByIndex( xDrawDoc, 1 ) ); xPageName.setName( "page two" ); xShapePropSet.setPropertyValue( @@ -189,11 +184,9 @@ public class PresentationDemo /* start an endless presentation which is displayed in full-screen mode and placed on top */ - XPresentationSupplier xPresSupplier = (XPresentationSupplier) - UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); + XPresentationSupplier xPresSupplier = UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); XPresentation xPresentation = xPresSupplier.getPresentation(); - XPropertySet xPresPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); + XPropertySet xPresPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); xPresPropSet.setPropertyValue( "IsEndless", new Boolean( true ) ); xPresPropSet.setPropertyValue( "IsAlwaysOnTop", new Boolean( true ) ); xPresPropSet.setPropertyValue( "Pause", new Integer( 0 ) ); @@ -216,14 +209,13 @@ public class PresentationDemo // the following test is only sensible if you do not exactly know // what type of page xPage is, for this purpose it can been tested // if the com.sun.star.presentation.DrawPage service is supported - XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo xInfo = UnoRuntime.queryInterface( XServiceInfo.class, xPage ); if ( xInfo.supportsService( "com.sun.star.presentation.DrawPage" ) == true ) { try { - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPage ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPage ); xPropSet.setPropertyValue( "Effect", eEffect ); xPropSet.setPropertyValue( "Speed", eSpeed ); xPropSet.setPropertyValue( "Change", new Integer( nChange ) ); diff --git a/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java b/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java index 7959b642fe0f..6f1d4aff680c 100644 --- a/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java +++ b/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java @@ -66,8 +66,7 @@ public class ShapeHelper { XShape xShape = createShape( xDrawDoc, aPos, aSize, sShapeType ); xShapes.add( xShape ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); return xPropSet; } @@ -79,10 +78,10 @@ public class ShapeHelper { XShape xShape = null; XMultiServiceFactory xFactory = - (XMultiServiceFactory )UnoRuntime.queryInterface( - XMultiServiceFactory.class, xDrawDoc ); + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xDrawDoc ); Object xObj = xFactory.createInstance( sShapeType ); - xShape = (XShape)UnoRuntime.queryInterface( + xShape = UnoRuntime.queryInterface( XShape.class, xObj ); xShape.setPosition( aPos ); xShape.setSize( aSize ); @@ -96,8 +95,7 @@ public class ShapeHelper public static XPropertySet addPortion( XShape xShape, String sText, boolean bNewParagraph ) throws com.sun.star.lang.IllegalArgumentException { - XText xText = (XText) - UnoRuntime.queryInterface( XText.class, xShape ); + XText xText = UnoRuntime.queryInterface( XText.class, xShape ); XTextCursor xTextCursor = xText.createTextCursor(); xTextCursor.gotoEnd( false ); @@ -106,12 +104,10 @@ public class ShapeHelper xText.insertControlCharacter( xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false ); xTextCursor.gotoEnd( false ); } - XTextRange xTextRange = (XTextRange) - UnoRuntime.queryInterface( XTextRange.class, xTextCursor ); + XTextRange xTextRange = UnoRuntime.queryInterface( XTextRange.class, xTextCursor ); xTextRange.setString( sText ); xTextCursor.gotoEnd( true ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xTextRange ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextRange ); return xPropSet; } @@ -123,8 +119,7 @@ public class ShapeHelper com.sun.star.lang.WrappedTargetException, com.sun.star.container.NoSuchElementException { - XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) - UnoRuntime.queryInterface( XEnumerationAccess.class, xText ); + XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface( XEnumerationAccess.class, xText ); if ( xEnumerationAccess.hasElements() ) { XEnumeration xEnumeration = xEnumerationAccess.createEnumeration(); @@ -133,10 +128,9 @@ public class ShapeHelper Object xObj = xEnumeration.nextElement(); if ( xEnumeration.hasMoreElements() == false ) { - XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface( + XTextContent xTextContent = UnoRuntime.queryInterface( XTextContent.class, xObj ); - XPropertySet xParaPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xTextContent ); + XPropertySet xParaPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextContent ); xParaPropSet.setPropertyValue( sPropName, aValue ); } } diff --git a/odk/examples/DevelopersGuide/Drawing/StyleDemo.java b/odk/examples/DevelopersGuide/Drawing/StyleDemo.java index 6196ad1d0727..2fe07f62efbf 100644 --- a/odk/examples/DevelopersGuide/Drawing/StyleDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/StyleDemo.java @@ -89,12 +89,11 @@ public class StyleDemo that is available within the styles of the document to red. It will also print each family and style name to the standard output */ XModel xModel = - (XModel)UnoRuntime.queryInterface( - XModel.class, xComponent ); + UnoRuntime.queryInterface( + XModel.class, xComponent ); com.sun.star.style.XStyleFamiliesSupplier xSFS = - (com.sun.star.style.XStyleFamiliesSupplier) UnoRuntime.queryInterface( - com.sun.star.style.XStyleFamiliesSupplier.class, xModel ); + com.sun.star.style.XStyleFamiliesSupplier.class, xModel ); com.sun.star.container.XNameAccess xFamilies = xSFS.getStyleFamilies(); @@ -109,21 +108,18 @@ public class StyleDemo // and now all available styles Object aFamilyObj = xFamilies.getByName( Families[ i ] ); com.sun.star.container.XNameAccess xStyles = - (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface( - com.sun.star.container.XNameAccess.class, aFamilyObj ); + com.sun.star.container.XNameAccess.class, aFamilyObj ); String[] Styles = xStyles.getElementNames(); for( int j = 0; j < Styles.length; j++ ) { System.out.println( " " + Styles[ j ] ); Object aStyleObj = xStyles.getByName( Styles[ j ] ); - com.sun.star.style.XStyle xStyle = (com.sun.star.style.XStyle) - UnoRuntime.queryInterface( + com.sun.star.style.XStyle xStyle = UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, aStyleObj ); // now we have the XStyle Interface and the CharColor for // all styles is exemplary be set to red. - XPropertySet xStylePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xStyle ); + XPropertySet xStylePropSet = UnoRuntime.queryInterface( XPropertySet.class, xStyle ); XPropertySetInfo xStylePropSetInfo = xStylePropSet.getPropertySetInfo(); if ( xStylePropSetInfo.hasPropertyByName( "CharColor" ) ) @@ -140,26 +136,21 @@ public class StyleDemo the "graphics" family */ Object obj = xFamilies.getByName( "graphics" ); - com.sun.star.container.XNameAccess xStyles = (XNameAccess) - UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, - obj ); + com.sun.star.container.XNameAccess xStyles = UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, + obj ); obj = xStyles.getByName( "title1" ); - com.sun.star.style.XStyle xTitle1Style = (com.sun.star.style.XStyle) - UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, obj ); + com.sun.star.style.XStyle xTitle1Style = UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, obj ); - XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + XDrawPagesSupplier xDrawPagesSupplier = UnoRuntime.queryInterface( XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface( + XDrawPage xDrawPage = UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex( 0 )); - XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, xDrawPage ); XShape xShape = ShapeHelper.createShape( xComponent, new Point( 0, 0 ), new Size( 5000, 5000 ), "com.sun.star.drawing.RectangleShape" ); xShapes.add( xShape ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); xPropSet.setPropertyValue( "Style", xTitle1Style ); } diff --git a/odk/examples/DevelopersGuide/Drawing/TextDemo.java b/odk/examples/DevelopersGuide/Drawing/TextDemo.java index 9d97b0aea29a..82b9abfc338d 100644 --- a/odk/examples/DevelopersGuide/Drawing/TextDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/TextDemo.java @@ -81,8 +81,7 @@ public class TextDemo "private:factory/sdraw", "_blank", 0, pPropValues ); XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xRectangle; @@ -98,8 +97,7 @@ public class TextDemo new Size( 15000, 7500 ), "com.sun.star.drawing.RectangleShape" ); xShapes.add( xRectangle ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); // first paragraph @@ -126,8 +124,7 @@ public class TextDemo new Size( 21000, 12500 ), "com.sun.star.drawing.RectangleShape" ); xShapes.add( xRectangle ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); xShapePropSet.setPropertyValue( "TextFitToSize", TextFitToSizeType.PROPORTIONAL ); xShapePropSet.setPropertyValue( "TextLeftDistance", new Integer(2500)); diff --git a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java index 56a5447853f1..0bc329cd26a7 100644 --- a/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java +++ b/odk/examples/DevelopersGuide/FirstSteps/FirstLoadComponent.java @@ -73,15 +73,13 @@ public class FirstLoadComponent { Object desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, desktop); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; XComponent xSpreadsheetComponent = xComponentLoader.loadComponentFromURL("private:factory/scalc", "_blank", 0, loadProps); - XSpreadsheetDocument xSpreadsheetDocument = (XSpreadsheetDocument) - UnoRuntime.queryInterface(XSpreadsheetDocument.class, - xSpreadsheetComponent); + XSpreadsheetDocument xSpreadsheetDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, + xSpreadsheetComponent); XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets(); xSpreadsheets.insertNewByName("MySheet", (short)0); @@ -89,7 +87,7 @@ public class FirstLoadComponent { System.out.println(elemType.getTypeName()); Object sheet = xSpreadsheets.getByName("MySheet"); - XSpreadsheet xSpreadsheet = (XSpreadsheet)UnoRuntime.queryInterface( + XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface( XSpreadsheet.class, sheet); XCell xCell = xSpreadsheet.getCellByPosition(0, 0); @@ -99,16 +97,15 @@ public class FirstLoadComponent { xCell = xSpreadsheet.getCellByPosition(0, 2); xCell.setFormula("=sum(A1:A2)"); - XPropertySet xCellProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCellProps = UnoRuntime.queryInterface( XPropertySet.class, xCell); xCellProps.setPropertyValue("CellStyle", "Result"); - XModel xSpreadsheetModel = (XModel)UnoRuntime.queryInterface( + XModel xSpreadsheetModel = UnoRuntime.queryInterface( XModel.class, xSpreadsheetComponent); XController xSpreadsheetController = xSpreadsheetModel.getCurrentController(); - XSpreadsheetView xSpreadsheetView = (XSpreadsheetView) - UnoRuntime.queryInterface(XSpreadsheetView.class, - xSpreadsheetController); + XSpreadsheetView xSpreadsheetView = UnoRuntime.queryInterface(XSpreadsheetView.class, + xSpreadsheetController); xSpreadsheetView.setActiveSheet(xSpreadsheet); // ********************************************************* @@ -138,8 +135,7 @@ public class FirstLoadComponent { // ********************************************************* // example for use of XEnumerationAccess - XCellRangesQuery xCellQuery = (XCellRangesQuery) - UnoRuntime.queryInterface(XCellRangesQuery.class, sheet); + XCellRangesQuery xCellQuery = UnoRuntime.queryInterface(XCellRangesQuery.class, sheet); XSheetCellRanges xFormulaCells = xCellQuery.queryContentCells( (short)com.sun.star.sheet.CellFlags.FORMULA); XEnumerationAccess xFormulas = xFormulaCells.getCells(); @@ -147,9 +143,8 @@ public class FirstLoadComponent { while (xFormulaEnum.hasMoreElements()) { Object formulaCell = xFormulaEnum.nextElement(); - xCell = (XCell)UnoRuntime.queryInterface(XCell.class, formulaCell); - XCellAddressable xCellAddress = (XCellAddressable) - UnoRuntime.queryInterface(XCellAddressable.class, xCell); + xCell = UnoRuntime.queryInterface(XCell.class, formulaCell); + XCellAddressable xCellAddress = UnoRuntime.queryInterface(XCellAddressable.class, xCell); System.out.println("Formula cell in column " + xCellAddress.getCellAddress().Column + ", row " + xCellAddress.getCellAddress().Row diff --git a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java index 6d8ebd25fabe..301db58a2c6f 100644 --- a/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java +++ b/odk/examples/DevelopersGuide/FirstSteps/HelloTextTableShape.java @@ -95,27 +95,27 @@ public class HelloTextTableShape { try { // create new writer document and get text, then manipulate text XComponent xWriterComponent = newDocComponent("swriter"); - XTextDocument xTextDocument = (XTextDocument)UnoRuntime.queryInterface( + XTextDocument xTextDocument = UnoRuntime.queryInterface( XTextDocument.class, xWriterComponent); XText xText = xTextDocument.getText(); manipulateText(xText); // get internal service factory of the document - XMultiServiceFactory xWriterFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory xWriterFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, xWriterComponent); // insert TextTable and get cell text, then manipulate text in cell Object table = xWriterFactory.createInstance("com.sun.star.text.TextTable"); - XTextContent xTextContentTable = (XTextContent)UnoRuntime.queryInterface( + XTextContent xTextContentTable = UnoRuntime.queryInterface( XTextContent.class, table); xText.insertTextContent(xText.getEnd(), xTextContentTable, false); - XCellRange xCellRange = (XCellRange)UnoRuntime.queryInterface( + XCellRange xCellRange = UnoRuntime.queryInterface( XCellRange.class, table); XCell xCell = xCellRange.getCellByPosition(0, 1); - XText xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); + XText xCellText = UnoRuntime.queryInterface(XText.class, xCell); manipulateText(xCellText); manipulateTable(xCellRange); @@ -123,21 +123,21 @@ public class HelloTextTableShape { // insert RectangleShape and get shape text, then manipulate text Object writerShape = xWriterFactory.createInstance( "com.sun.star.drawing.RectangleShape"); - XShape xWriterShape = (XShape)UnoRuntime.queryInterface( + XShape xWriterShape = UnoRuntime.queryInterface( XShape.class, writerShape); xWriterShape.setSize(new Size(10000, 10000)); - XTextContent xTextContentShape = (XTextContent)UnoRuntime.queryInterface( + XTextContent xTextContentShape = UnoRuntime.queryInterface( XTextContent.class, writerShape); xText.insertTextContent(xText.getEnd(), xTextContentShape, false); - XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xShapeProps = UnoRuntime.queryInterface( XPropertySet.class, writerShape); // wrap text inside shape xShapeProps.setPropertyValue("TextContourFrame", new Boolean(true)); - XText xShapeText = (XText)UnoRuntime.queryInterface(XText.class, writerShape); + XText xShapeText = UnoRuntime.queryInterface(XText.class, writerShape); manipulateText(xShapeText); manipulateShape(xWriterShape); @@ -204,50 +204,50 @@ public class HelloTextTableShape { // create new calc document and manipulate cell text XComponent xCalcComponent = newDocComponent("scalc"); XSpreadsheetDocument xSpreadsheetDocument = - (XSpreadsheetDocument)UnoRuntime.queryInterface( - XSpreadsheetDocument .class, xCalcComponent); + UnoRuntime.queryInterface( + XSpreadsheetDocument .class, xCalcComponent); Object sheets = xSpreadsheetDocument.getSheets(); - XIndexAccess xIndexedSheets = (XIndexAccess)UnoRuntime.queryInterface( + XIndexAccess xIndexedSheets = UnoRuntime.queryInterface( XIndexAccess.class, sheets); Object sheet = xIndexedSheets.getByIndex(0); //get cell A2 in first sheet - XCellRange xSpreadsheetCells = (XCellRange)UnoRuntime.queryInterface( + XCellRange xSpreadsheetCells = UnoRuntime.queryInterface( XCellRange.class, sheet); XCell xCell = xSpreadsheetCells.getCellByPosition(0,1); - XPropertySet xCellProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCellProps = UnoRuntime.queryInterface( XPropertySet.class, xCell); xCellProps.setPropertyValue("IsTextWrapped", new Boolean(true)); - XText xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); + XText xCellText = UnoRuntime.queryInterface(XText.class, xCell); manipulateText(xCellText); manipulateTable(xSpreadsheetCells); // get internal service factory of the document - XMultiServiceFactory xCalcFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( + XMultiServiceFactory xCalcFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, xCalcComponent); // get Drawpage - XDrawPageSupplier xDrawPageSupplier = (XDrawPageSupplier)UnoRuntime.queryInterface(XDrawPageSupplier.class, sheet); + XDrawPageSupplier xDrawPageSupplier = UnoRuntime.queryInterface(XDrawPageSupplier.class, sheet); XDrawPage xDrawPage = xDrawPageSupplier.getDrawPage(); // create and insert RectangleShape and get shape text, then manipulate text Object calcShape = xCalcFactory.createInstance( "com.sun.star.drawing.RectangleShape"); - XShape xCalcShape = (XShape)UnoRuntime.queryInterface( + XShape xCalcShape = UnoRuntime.queryInterface( XShape.class, calcShape); xCalcShape.setSize(new Size(10000, 10000)); xCalcShape.setPosition(new Point(7000, 3000)); xDrawPage.add(xCalcShape); - XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xShapeProps = UnoRuntime.queryInterface( XPropertySet.class, calcShape); // wrap text inside shape xShapeProps.setPropertyValue("TextContourFrame", new Boolean(true)); - XText xShapeText = (XText)UnoRuntime.queryInterface(XText.class, calcShape); + XText xShapeText = UnoRuntime.queryInterface(XText.class, calcShape); manipulateText(xShapeText); manipulateShape(xCalcShape); @@ -265,29 +265,29 @@ public class HelloTextTableShape { //create new draw document and insert ractangle shape XComponent xDrawComponent = newDocComponent("sdraw"); XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xDrawComponent); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xDrawComponent); Object drawPages = xDrawPagesSupplier.getDrawPages(); - XIndexAccess xIndexedDrawPages = (XIndexAccess)UnoRuntime.queryInterface( + XIndexAccess xIndexedDrawPages = UnoRuntime.queryInterface( XIndexAccess.class, drawPages); Object drawPage = xIndexedDrawPages.getByIndex(0); - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage); + XDrawPage xDrawPage = UnoRuntime.queryInterface(XDrawPage.class, drawPage); // get internal service factory of the document XMultiServiceFactory xDrawFactory = - (XMultiServiceFactory)UnoRuntime.queryInterface( - XMultiServiceFactory.class, xDrawComponent); + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xDrawComponent); Object drawShape = xDrawFactory.createInstance( "com.sun.star.drawing.RectangleShape"); - XShape xDrawShape = (XShape)UnoRuntime.queryInterface(XShape.class, drawShape); + XShape xDrawShape = UnoRuntime.queryInterface(XShape.class, drawShape); xDrawShape.setSize(new Size(10000, 20000)); xDrawShape.setPosition(new Point(5000, 5000)); xDrawPage.add(xDrawShape); - XText xShapeText = (XText)UnoRuntime.queryInterface(XText.class, drawShape); - XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface( + XText xShapeText = UnoRuntime.queryInterface(XText.class, drawShape); + XPropertySet xShapeProps = UnoRuntime.queryInterface( XPropertySet.class, drawShape); // wrap text inside shape @@ -312,7 +312,7 @@ public class HelloTextTableShape { // create text cursor for selecting and formatting XTextCursor xTextCursor = xText.createTextCursor(); - XPropertySet xCursorProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCursorProps = UnoRuntime.queryInterface( XPropertySet.class, xTextCursor); // use cursor to select "He lay" and apply bold italic @@ -342,32 +342,32 @@ public class HelloTextTableShape { // enter column titles and a cell value XCell xCell = xCellRange.getCellByPosition(0,0); - XText xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); + XText xCellText = UnoRuntime.queryInterface(XText.class, xCell); xCellText.setString("Quotation"); xCell = xCellRange.getCellByPosition(1,0); - xCellText = (XText)UnoRuntime.queryInterface(XText.class, xCell); + xCellText = UnoRuntime.queryInterface(XText.class, xCell); xCellText.setString("Year"); xCell = xCellRange.getCellByPosition(1,1); xCell.setValue(1940); XCellRange xSelectedCells = xCellRange.getCellRangeByName("A1:B1"); - XPropertySet xCellProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCellProps = UnoRuntime.queryInterface( XPropertySet.class, xSelectedCells); // format table headers and table borders // we need to distinguish text and sheet tables: // property name for cell colors is different in text and sheet cells // we want to apply TableBorder to whole text table, but only to sheet cells with content - XServiceInfo xServiceInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, xCellRange); if (xServiceInfo.supportsService("com.sun.star.sheet.Spreadsheet")) { backColorPropertyName = "CellBackColor"; xSelectedCells = xCellRange.getCellRangeByName("A1:B2"); - xTableProps = (XPropertySet)UnoRuntime.queryInterface( + xTableProps = UnoRuntime.queryInterface( XPropertySet.class, xSelectedCells); } else if (xServiceInfo.supportsService("com.sun.star.text.TextTable")) { backColorPropertyName = "BackColor"; - xTableProps = (XPropertySet)UnoRuntime.queryInterface( + xTableProps = UnoRuntime.queryInterface( XPropertySet.class, xCellRange); } // set cell background color @@ -398,7 +398,7 @@ public class HelloTextTableShape { } protected void manipulateShape(XShape xShape) throws com.sun.star.uno.Exception { - XPropertySet xShapeProps = (XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, xShape); + XPropertySet xShapeProps = UnoRuntime.queryInterface(XPropertySet.class, xShape); xShapeProps.setPropertyValue("FillColor", new Integer(0x99CCFF)); xShapeProps.setPropertyValue("LineColor", new Integer(0x000099)); xShapeProps.setPropertyValue("RotateAngle", new Integer(3000)); @@ -415,7 +415,7 @@ public class HelloTextTableShape { xRemoteServiceManager = this.getRemoteServiceManager(); Object desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader)UnoRuntime.queryInterface( + XComponentLoader xComponentLoader = UnoRuntime.queryInterface( XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps); diff --git a/odk/examples/DevelopersGuide/GUI/DialogDocument.java b/odk/examples/DevelopersGuide/GUI/DialogDocument.java index 27d3d80f3348..9db851852006 100644 --- a/odk/examples/DevelopersGuide/GUI/DialogDocument.java +++ b/odk/examples/DevelopersGuide/GUI/DialogDocument.java @@ -68,7 +68,7 @@ public class DialogDocument extends UnoDialogSample { new Object[] { new Integer(400), Boolean.TRUE, "Dialog1", new Integer(102),new Integer(41), new Integer(1), new Short((short) 0), "Document-Dialog", new Integer(300)}); oDialogDocument.createWindowPeer(); Object oFTHeaderModel = oDialogDocument.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); + XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); xFTHeaderModelMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, new Object[] { new Integer(8), "This code-sample demonstrates how to display an office document in a dialog window", "HeaderLabel", new Integer(6), new Integer(6), new Integer(300)}); @@ -96,7 +96,7 @@ public class DialogDocument extends UnoDialogSample { try { // The Toolkit is the creator of all windows... Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); - XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, oToolkit); + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, oToolkit); // set up a window description and create the window. A parent window is always necessary for this... com.sun.star.awt.WindowDescriptor aWindowDescriptor = new com.sun.star.awt.WindowDescriptor(); @@ -112,17 +112,17 @@ public class DialogDocument extends UnoDialogSample { // The attribute CLIPCHILDREN causes the parent to not repaint the areas of the children... aWindowDescriptor.WindowAttributes = VclWindowPeerAttribute.CLIPCHILDREN + WindowAttribute.BORDER + WindowAttribute.SHOW; XWindowPeer xWindowPeer = xToolkit.createWindow(aWindowDescriptor); - XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xWindowPeer); - XView xView = (XView) UnoRuntime.queryInterface(XView.class, xWindow); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xWindowPeer); + XView xView = UnoRuntime.queryInterface(XView.class, xWindow); // create a frame and initialize it with the created window... Object oFrame = m_xMCF.createInstanceWithContext("com.sun.star.frame.Frame", m_xContext); // The frame should be of global scope because it's within the responsibility to dispose it after usage - m_xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, oFrame); + m_xFrame = UnoRuntime.queryInterface(XFrame.class, oFrame); m_xFrame.initialize(xWindow); // load the document and open it in preview mode - XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, m_xFrame); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, m_xFrame); PropertyValue[] aPropertyValues = new PropertyValue[2]; PropertyValue aPropertyValue = new PropertyValue(); aPropertyValue.Name = "Preview"; diff --git a/odk/examples/DevelopersGuide/GUI/ImageControlSample.java b/odk/examples/DevelopersGuide/GUI/ImageControlSample.java index ac890e8aee1a..2e61fb25622d 100644 --- a/odk/examples/DevelopersGuide/GUI/ImageControlSample.java +++ b/odk/examples/DevelopersGuide/GUI/ImageControlSample.java @@ -71,7 +71,7 @@ public class ImageControlSample extends UnoDialogSample{ oImageControlSample.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"}, new Object[] { new Integer(100), Boolean.TRUE, "MyTestDialog", new Integer(102),new Integer(41), new Integer(0), new Short((short) 0), "OpenOffice", new Integer(230)}); Object oFTHeaderModel = oImageControlSample.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); + XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); xFTHeaderModelMPSet.setPropertyValues( new String[] {"Height", "Label", "MultiLine", "Name", "PositionX", "PositionY", "Width"}, new Object[] { new Integer(16), "This code-sample demonstrates how to create an ImageControlSample within a dialog", Boolean.TRUE, "HeaderLabel", new Integer(6), new Integer(6), new Integer(210)}); @@ -84,7 +84,7 @@ public class ImageControlSample extends UnoDialogSample{ // may not be set before the peer of the dialog has been created. XGraphic xGraphic = oImageControlSample.getGraphic(oImageControlSample.m_xMCF, args[0]); xICModelPropertySet.setPropertyValue("Graphic", xGraphic); - oImageControlSample.xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, oImageControlSample.m_xDialogControl); + oImageControlSample.xDialog = UnoRuntime.queryInterface(XDialog.class, oImageControlSample.m_xDialogControl); oImageControlSample.executeDialog(); }catch( Exception e ) { System.err.println( e + e.getMessage()); @@ -110,8 +110,8 @@ public class ImageControlSample extends UnoDialogSample{ // create a controlmodel at the multiservicefactory of the dialog model... Object oICModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlImageControlModel"); - XMultiPropertySet xICModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oICModel); - xICModelPropertySet =(XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oICModel); + XMultiPropertySet xICModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oICModel); + xICModelPropertySet =UnoRuntime.queryInterface(XPropertySet.class, oICModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! // The image is not scaled xICModelMPSet.setPropertyValues( @@ -143,12 +143,12 @@ public class ImageControlSample extends UnoDialogSample{ try{ java.io.File oFile = new java.io.File(_sImageSystemPath); Object oFCProvider = _xMCF.createInstanceWithContext("com.sun.star.ucb.FileContentProvider", this.m_xContext); - XFileIdentifierConverter xFileIdentifierConverter = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider); + XFileIdentifierConverter xFileIdentifierConverter = UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider); String sImageUrl = xFileIdentifierConverter.getFileURLFromSystemPath(_sImageSystemPath, oFile.getAbsolutePath()); // create a GraphicProvider at the global service manager... Object oGraphicProvider = m_xMCF.createInstanceWithContext("com.sun.star.graphic.GraphicProvider", m_xContext); - XGraphicProvider xGraphicProvider = (XGraphicProvider) UnoRuntime.queryInterface(XGraphicProvider.class, oGraphicProvider); + XGraphicProvider xGraphicProvider = UnoRuntime.queryInterface(XGraphicProvider.class, oGraphicProvider); // create the graphic object PropertyValue[] aPropertyValues = new PropertyValue[1]; PropertyValue aPropertyValue = new PropertyValue(); diff --git a/odk/examples/DevelopersGuide/GUI/MessageBox.java b/odk/examples/DevelopersGuide/GUI/MessageBox.java index b9b3903e5b54..90cf5c862315 100644 --- a/odk/examples/DevelopersGuide/GUI/MessageBox.java +++ b/odk/examples/DevelopersGuide/GUI/MessageBox.java @@ -77,7 +77,7 @@ public class MessageBox { XWindowPeer xWindowPeer = oMessageBox.getWindowPeerOfFrame(xComp); if (xWindowPeer != null) { - XVclWindowPeer xVclWindowPeer = (XVclWindowPeer) UnoRuntime.queryInterface(XVclWindowPeer.class, xWindowPeer); + XVclWindowPeer xVclWindowPeer = UnoRuntime.queryInterface(XVclWindowPeer.class, xWindowPeer); boolean bisHighContrast = oMessageBox.isHighContrastModeActivated(xVclWindowPeer); oMessageBox.showErrorMessageBox(xWindowPeer, "My Sampletitle", "HighContrastMode is enabled: " + bisHighContrast); } else{ @@ -90,7 +90,7 @@ public class MessageBox { } finally { if (xComp != null) { try { - XCloseable xClose = (XCloseable)UnoRuntime.queryInterface(XCloseable.class, xComp); + XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, xComp); if (xClose != null) { xClose.close(false); } else { @@ -114,21 +114,21 @@ public class MessageBox { XFrame xFrame = null; if (xComp != null) { - XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, xComp); + XModel xModel = UnoRuntime.queryInterface(XModel.class, xComp); xFrame = xModel.getCurrentController().getFrame(); } else { // Note: This method is potentially dangerous and should only be used for debugging // purposes as it relies on the platform dependent window handler.. Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext); - XFramesSupplier xFramesSupplier = (XFramesSupplier) UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop); + XFramesSupplier xFramesSupplier = UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop); xFrame = xFramesSupplier.getActiveFrame(); } if (xFrame != null){ XWindow xWindow = xFrame.getContainerWindow(); if (xWindow != null){ - XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xWindow); + XWindowPeer xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, xWindow); return xWindowPeer; } } @@ -147,8 +147,7 @@ public class MessageBox { // 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 xCLoader =UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class,oDesktop); com.sun.star.beans.PropertyValue[] args = new com.sun.star.beans.PropertyValue [1]; args[0] = new com.sun.star.beans.PropertyValue(); @@ -173,11 +172,11 @@ public class MessageBox { XComponent xComponent = null; try { Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); - XMessageBoxFactory xMessageBoxFactory = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); + XMessageBoxFactory xMessageBoxFactory = UnoRuntime.queryInterface(XMessageBoxFactory.class, oToolkit); // rectangle may be empty if position is in the center of the parent peer Rectangle aRectangle = new Rectangle(); XMessageBox xMessageBox = xMessageBoxFactory.createMessageBox(_xParentWindowPeer, aRectangle, "errorbox", com.sun.star.awt.MessageBoxButtons.BUTTONS_OK, _sTitle, _sMessage); - xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xMessageBox); + xComponent = UnoRuntime.queryInterface(XComponent.class, xMessageBox); if (xMessageBox != null){ short nResult = xMessageBox.execute(); } @@ -217,25 +216,25 @@ public class MessageBox { } public static int getRedColorShare(int _nColor) { - int nRed = (int) _nColor/65536; + int nRed = _nColor/65536; int nRedModulo = _nColor % 65536; - int nGreen = (int) (nRedModulo / 256); + int nGreen = nRedModulo / 256; int nGreenModulo = (nRedModulo % 256); int nBlue = nGreenModulo; return nRed; } public static int getGreenColorShare(int _nColor) { - int nRed = (int) _nColor/65536; + int nRed = _nColor/65536; int nRedModulo = _nColor % 65536; - int nGreen = (int) (nRedModulo / 256); + int nGreen = nRedModulo / 256; return nGreen; } public static int getBlueColorShare(int _nColor) { - int nRed = (int) _nColor/65536; + int nRed = _nColor/65536; int nRedModulo = _nColor % 65536; - int nGreen = (int) (nRedModulo / 256); + int nGreen = nRedModulo / 256; int nGreenModulo = (nRedModulo % 256); int nBlue = nGreenModulo; return nBlue; diff --git a/odk/examples/DevelopersGuide/GUI/RoadmapItemStateChangeListener.java b/odk/examples/DevelopersGuide/GUI/RoadmapItemStateChangeListener.java index 6f2a82453d62..69a7f77d4cab 100644 --- a/odk/examples/DevelopersGuide/GUI/RoadmapItemStateChangeListener.java +++ b/odk/examples/DevelopersGuide/GUI/RoadmapItemStateChangeListener.java @@ -49,7 +49,7 @@ public class RoadmapItemStateChangeListener implements XItemListener { try { // get the new ID of the roadmap that is supposed to refer to the new step of the dialogmodel int nNewID = itemEvent.ItemId; - XPropertySet xDialogModelPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_xMSFDialogModel); + XPropertySet xDialogModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, m_xMSFDialogModel); int nOldStep = ((Integer) xDialogModelPropertySet.getPropertyValue("Step")).intValue(); // in the following line "ID" and "Step" are mixed together. // In fact in this case they denot the same diff --git a/odk/examples/DevelopersGuide/GUI/SystemDialog.java b/odk/examples/DevelopersGuide/GUI/SystemDialog.java index 861d075a1df2..bad6a8f0db9f 100644 --- a/odk/examples/DevelopersGuide/GUI/SystemDialog.java +++ b/odk/examples/DevelopersGuide/GUI/SystemDialog.java @@ -80,36 +80,36 @@ public class SystemDialog { try { // the filepicker is instantiated with the global Multicomponentfactory... Object oFilePicker = m_xMCF.createInstanceWithContext("com.sun.star.ui.dialogs.FilePicker", m_xContext); - XFilePicker xFilePicker = (XFilePicker) UnoRuntime.queryInterface(XFilePicker.class, oFilePicker); + XFilePicker xFilePicker = UnoRuntime.queryInterface(XFilePicker.class, oFilePicker); // the defaultname is the initially proposed filename.. xFilePicker.setDefaultName("MyExampleDocument"); // set the initial displaydirectory. In this example the user template directory is used Object oPathSettings = m_xMCF.createInstanceWithContext("com.sun.star.util.PathSettings",m_xContext); - XPropertySet xPropertySet = (XPropertySet) com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); + XPropertySet xPropertySet = com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); String sTemplateUrl = (String) xPropertySet.getPropertyValue("Template_writable"); xFilePicker.setDisplayDirectory(sTemplateUrl); // set the filters of the dialog. The filternames may be retrieved from // http://wiki.services.openoffice.org/wiki/Framework/Article/Filter - XFilterManager xFilterManager = (XFilterManager) UnoRuntime.queryInterface(XFilterManager.class, xFilePicker); + XFilterManager xFilterManager = UnoRuntime.queryInterface(XFilterManager.class, xFilePicker); xFilterManager.appendFilter("OpenDocument Text Template", "writer8_template"); xFilterManager.appendFilter("OpenDocument Text", "writer8"); // choose the template that defines the capabilities of the filepicker dialog - XInitialization xInitialize = (XInitialization) UnoRuntime.queryInterface(XInitialization.class, xFilePicker); + XInitialization xInitialize = UnoRuntime.queryInterface(XInitialization.class, xFilePicker); Short[] listAny = new Short[] { new Short(com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION)}; xInitialize.initialize(listAny); // add a control to the dialog to add the extension automatically to the filename... - XFilePickerControlAccess xFilePickerControlAccess = (XFilePickerControlAccess) UnoRuntime.queryInterface(XFilePickerControlAccess.class, xFilePicker); + XFilePickerControlAccess xFilePickerControlAccess = UnoRuntime.queryInterface(XFilePickerControlAccess.class, xFilePicker); xFilePickerControlAccess.setValue(com.sun.star.ui.dialogs.ExtendedFilePickerElementIds.CHECKBOX_AUTOEXTENSION, (short) 0, new Boolean(true)); - xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, xFilePicker); + xComponent = UnoRuntime.queryInterface(XComponent.class, xFilePicker); // execute the dialog... - XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, xFilePicker); + XExecutableDialog xExecutable = UnoRuntime.queryInterface(XExecutableDialog.class, xFilePicker); short nResult = xExecutable.execute(); // query the resulting path of the dialog... @@ -135,7 +135,7 @@ public class SystemDialog { try{ // retrieve the configured Work path... Object oPathSettings = m_xMCF.createInstanceWithContext("com.sun.star.util.PathSettings",m_xContext); - XPropertySet xPropertySet = (XPropertySet) com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); + XPropertySet xPropertySet = com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); sWorkUrl = (String) xPropertySet.getPropertyValue("Work"); } catch (com.sun.star.uno.Exception exception) { exception.printStackTrace(); @@ -158,8 +158,8 @@ public class SystemDialog { // instantiate the folder picker and retrieve the necessary interfaces... Object oFolderPicker = m_xMCF.createInstanceWithContext("com.sun.star.ui.dialogs.FolderPicker", m_xContext); XFolderPicker2 xFolderPicker = UnoRuntime.queryInterface(XFolderPicker2.class, oFolderPicker); - XExecutableDialog xExecutable = (XExecutableDialog) UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker); - xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, oFolderPicker); + XExecutableDialog xExecutable = UnoRuntime.queryInterface(XExecutableDialog.class, oFolderPicker); + xComponent = UnoRuntime.queryInterface(XComponent.class, oFolderPicker); xFolderPicker.setDisplayDirectory(_sDisplayDirectory); // set the dialog title... xFolderPicker.setTitle(_sTitle); diff --git a/odk/examples/DevelopersGuide/GUI/UnoDialogSample.java b/odk/examples/DevelopersGuide/GUI/UnoDialogSample.java index 6db2ef162e63..2b47e82e8975 100644 --- a/odk/examples/DevelopersGuide/GUI/UnoDialogSample.java +++ b/odk/examples/DevelopersGuide/GUI/UnoDialogSample.java @@ -139,7 +139,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis oUnoDialogSample.initialize( new String[] {"Height", "Moveable", "Name","PositionX","PositionY", "Step", "TabIndex","Title","Width"}, new Object[] { new Integer(380), Boolean.TRUE, "MyTestDialog", new Integer(102),new Integer(41), new Integer(0), new Short((short) 0), "OpenOffice", new Integer(380)}); Object oFTHeaderModel = oUnoDialogSample.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); + XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); xFTHeaderModelMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, new Object[] { new Integer(8), "This code-sample demonstrates how to create various controls in a dialog", "HeaderLabel", new Integer(106), new Integer(6), new Integer(300)}); @@ -167,7 +167,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis oUnoDialogSample.addRoadmap(oUnoDialogSample.getRoadmapItemStateChangeListener()); oUnoDialogSample.insertRoadmapItem(0, true, "Introduction", 1); oUnoDialogSample.insertRoadmapItem(1, true, "Documents", 2); - oUnoDialogSample.xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, oUnoDialogSample.m_xDialogControl); + oUnoDialogSample.xDialog = UnoRuntime.queryInterface(XDialog.class, oUnoDialogSample.m_xDialogControl); oUnoDialogSample.executeDialog(); }catch( Exception e ) { System.err.println( e + e.getMessage()); @@ -197,9 +197,9 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis aNodePath[0] = new PropertyValue(); aNodePath[0].Name = "nodepath"; aNodePath[0].Value = _sKeyName; - XMultiServiceFactory xMSFConfig = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oConfigProvider); + XMultiServiceFactory xMSFConfig = UnoRuntime.queryInterface(XMultiServiceFactory.class, oConfigProvider); Object oNode = xMSFConfig.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath); - XNameAccess xNameAccess = (XNameAccess) UnoRuntime.queryInterface(XNameAccess.class, oNode); + XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oNode); return xNameAccess; } catch (Exception exception) { exception.printStackTrace(System.err); @@ -222,7 +222,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // get the Image Url and process the Url by the macroexpander... sImageUrl = (String) xNameAccess.getByName(_sImageName); Object oMacroExpander = this.m_xContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander"); - XMacroExpander xMacroExpander = (XMacroExpander) UnoRuntime.queryInterface(XMacroExpander.class, oMacroExpander); + XMacroExpander xMacroExpander = UnoRuntime.queryInterface(XMacroExpander.class, oMacroExpander); sImageUrl = xMacroExpander.expandMacros(sImageUrl); sImageUrl = sImageUrl.substring(new String("vnd.sun.star.expand:").length(), sImageUrl.length()); sImageUrl = sImageUrl.trim(); @@ -245,22 +245,22 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis Object oDialogModel = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialogModel", m_xContext); // The XMultiServiceFactory of the dialogmodel is needed to instantiate the controls... - m_xMSFDialogModel = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel); + m_xMSFDialogModel = UnoRuntime.queryInterface(XMultiServiceFactory.class, oDialogModel); // The named container is used to insert the created controls into... - m_xDlgModelNameContainer = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, oDialogModel); + m_xDlgModelNameContainer = UnoRuntime.queryInterface(XNameContainer.class, oDialogModel); // create the dialog... Object oUnoDialog = _xMCF.createInstanceWithContext("com.sun.star.awt.UnoControlDialog", m_xContext); - m_xDialogControl = (XControl) UnoRuntime.queryInterface(XControl.class, oUnoDialog); + m_xDialogControl = UnoRuntime.queryInterface(XControl.class, oUnoDialog); // The scope of the control container is public... - m_xDlgContainer = (XControlContainer) UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog); + m_xDlgContainer = UnoRuntime.queryInterface(XControlContainer.class, oUnoDialog); - m_xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, m_xDlgContainer); + m_xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, m_xDlgContainer); // link the dialog and its model... - XControlModel xControlModel = (XControlModel) UnoRuntime.queryInterface(XControlModel.class, oDialogModel); + XControlModel xControlModel = UnoRuntime.queryInterface(XControlModel.class, oDialogModel); m_xDialogControl.setModel(xControlModel); } catch (com.sun.star.uno.Exception exception) { exception.printStackTrace(System.err); @@ -276,7 +276,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis addRoadmap(getRoadmapItemStateChangeListener()); insertRoadmapItem(0, true, "Introduction", 1); insertRoadmapItem(1, true, "Documents", 2); - xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, m_xDialogControl); + xDialog = UnoRuntime.queryInterface(XDialog.class, m_xDialogControl); return xDialog.execute(); } @@ -285,8 +285,8 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis if (m_xWindowPeer == null) { createWindowPeer(); } - xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, m_xDialogControl); - m_xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, m_xDialogControl); + xDialog = UnoRuntime.queryInterface(XDialog.class, m_xDialogControl); + m_xComponent = UnoRuntime.queryInterface(XComponent.class, m_xDialogControl); return xDialog.execute(); } @@ -300,7 +300,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public void initialize(String[] PropertyNames, Object[] PropertyValues) throws com.sun.star.script.BasicErrorException{ try{ - XMultiPropertySet xMultiPropertySet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, m_xDlgModelNameContainer); + XMultiPropertySet xMultiPropertySet = UnoRuntime.queryInterface(XMultiPropertySet.class, m_xDlgModelNameContainer); xMultiPropertySet.setPropertyValues(PropertyNames, PropertyValues); } catch (com.sun.star.uno.Exception ex) { ex.printStackTrace(System.err); @@ -319,11 +319,11 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public XWindowPeer createWindowPeer(XWindowPeer _xWindowParentPeer) throws com.sun.star.script.BasicErrorException{ try{ if (_xWindowParentPeer == null){ - XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer); xWindow.setVisible(false); Object tk = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); - XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, tk); - mxReschedule = (XReschedule) UnoRuntime.queryInterface(XReschedule.class, xToolkit); + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, tk); + mxReschedule = UnoRuntime.queryInterface(XReschedule.class, xToolkit); m_xDialogControl.createPeer(xToolkit, _xWindowParentPeer); m_xWindowPeer = m_xDialogControl.getPeer(); return m_xWindowPeer; @@ -368,7 +368,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public Object insertControlModel(String ServiceName, String sName, String[] sProperties, Object[] sValues) throws com.sun.star.script.BasicErrorException{ try { Object oControlModel = m_xMSFDialogModel.createInstance(ServiceName); - XMultiPropertySet xControlMultiPropertySet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oControlModel); + XMultiPropertySet xControlMultiPropertySet = UnoRuntime.queryInterface(XMultiPropertySet.class, oControlModel); xControlMultiPropertySet.setPropertyValues(sProperties, sValues); m_xDlgModelNameContainer.insertByName(sName, oControlModel); return oControlModel; @@ -387,7 +387,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); + XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFTModelMPSet.setPropertyValues( @@ -398,13 +398,13 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration - XPropertySet xFTPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFTModel); + XPropertySet xFTPSet = UnoRuntime.queryInterface(XPropertySet.class, oFTModel); xFTPSet.setPropertyValue("Label", _sLabel); // reference the control by the Name XControl xFTControl = m_xDlgContainer.getControl(sName); - xFixedText = (XFixedText) UnoRuntime.queryInterface(XFixedText.class, xFTControl); - XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xFTControl); + xFixedText = UnoRuntime.queryInterface(XFixedText.class, xFTControl); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xFTControl); xWindow.addMouseListener(_xMouseListener); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -430,7 +430,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oCFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCurrencyFieldModel"); - XMultiPropertySet xCFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oCFModel); + XMultiPropertySet xCFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oCFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xCFModelMPSet.setPropertyValues( @@ -439,7 +439,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oCFModel); - XPropertySet xCFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oCFModel); + XPropertySet xCFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oCFModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration @@ -449,7 +449,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // add a textlistener that is notified on each change of the controlvalue... Object oCFControl = m_xDlgContainer.getControl(sName); - xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, oCFControl); + xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, oCFControl); xTextComponent.addTextListener(_xTextListener); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -477,7 +477,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oPBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlProgressBarModel"); - XMultiPropertySet xPBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oPBModel); + XMultiPropertySet xPBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oPBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xPBModelMPSet.setPropertyValues( new String[] {"Height", "Name", "PositionX", "PositionY", "Width"}, @@ -485,7 +485,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oPBModel); - xPBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oPBModel); + xPBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oPBModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration @@ -515,7 +515,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oFLModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedLineModel"); - XMultiPropertySet xFLModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFLModel); + XMultiPropertySet xFLModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFLModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFLModelMPSet.setPropertyValues( @@ -527,7 +527,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration - XPropertySet xFLPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFLModel); + XPropertySet xFLPSet = UnoRuntime.queryInterface(XPropertySet.class, oFLModel); xFLPSet.setPropertyValue("Label", _sLabel); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -552,7 +552,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oGBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlGroupBoxModel"); - XMultiPropertySet xGBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oGBModel); + XMultiPropertySet xGBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oGBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xGBModelMPSet.setPropertyValues( @@ -564,7 +564,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration - XPropertySet xGBPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oGBModel); + XPropertySet xGBPSet = UnoRuntime.queryInterface(XPropertySet.class, oGBModel); xGBPSet.setPropertyValue("Label", "~My GroupBox"); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -590,7 +590,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlEditModel"); - XMultiPropertySet xTFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel); + XMultiPropertySet xTFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xTFModelMPSet.setPropertyValues( @@ -599,7 +599,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oTFModel); - XPropertySet xTFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTFModel); + XPropertySet xTFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oTFModel); // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration @@ -607,8 +607,8 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis XControl xTFControl = m_xDlgContainer.getControl(sName); // add a textlistener that is notified on each change of the controlvalue... - xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xTFControl); - XWindow xTFWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xTFControl); + xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xTFControl); + XWindow xTFWindow = UnoRuntime.queryInterface(XWindow.class, xTFControl); xTFWindow.addFocusListener(_xFocusListener); xTextComponent.addTextListener(_xTextListener); xTFWindow.addKeyListener(this); @@ -635,7 +635,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oTFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlTimeFieldModel"); - XMultiPropertySet xTFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel); + XMultiPropertySet xTFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oTFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xTFModelMPSet.setPropertyValues( @@ -644,7 +644,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oTFModel); - xTFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTFModel); + xTFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oTFModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration @@ -677,7 +677,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oDFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlDateFieldModel"); - XMultiPropertySet xDFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oDFModel); + XMultiPropertySet xDFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oDFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xDFModelMPSet.setPropertyValues( @@ -686,7 +686,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oDFModel); - xDFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oDFModel); + xDFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oDFModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration @@ -697,7 +697,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis Object oDFControl = m_xDlgContainer.getControl(sName); // add a SpinListener that is notified on each change of the controlvalue... - XSpinField xSpinField = (XSpinField) UnoRuntime.queryInterface(XSpinField.class, oDFControl); + XSpinField xSpinField = UnoRuntime.queryInterface(XSpinField.class, oDFControl); xSpinField.addSpinListener(_xSpinListener); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -723,7 +723,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oPFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlPatternFieldModel"); - XMultiPropertySet xPFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oPFModel); + XMultiPropertySet xPFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oPFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xPFModelMPSet.setPropertyValues( @@ -732,7 +732,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oPFModel); - xPFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oPFModel); + xPFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oPFModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration @@ -767,7 +767,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oNFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlNumericFieldModel"); - XMultiPropertySet xNFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oNFModel); + XMultiPropertySet xNFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oNFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xNFModelMPSet.setPropertyValues( new String[] {"Height", "Name", "PositionX", "PositionY", "Spin", "StrictFormat", "Width"}, @@ -775,7 +775,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oNFModel); - xNFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oNFModel); + xNFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oNFModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration xNFModelPSet.setPropertyValue("ValueMin", new Double(_fValueMin)); @@ -811,7 +811,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oSBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlScrollBarModel"); - XMultiPropertySet xSBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oSBModel); + XMultiPropertySet xSBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oSBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xSBModelMPSet.setPropertyValues( new String[] {"Height", "Name", "Orientation", "PositionX", "PositionY", "Width"}, @@ -820,7 +820,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oSBModel); - xSBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oSBModel); + xSBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oSBModel); // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration xSBModelPSet.setPropertyValue("ScrollValueMin", new Integer(0)); @@ -831,7 +831,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // Add an Adjustment that will listen to changes of the scrollbar... XControl xSBControl = m_xDlgContainer.getControl(sName); - XScrollBar xScrollBar = (XScrollBar) UnoRuntime.queryInterface(XScrollBar.class, xSBControl); + XScrollBar xScrollBar = UnoRuntime.queryInterface(XScrollBar.class, xSBControl); xScrollBar.addAdjustmentListener(_xAdjustmentListener); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -880,21 +880,21 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis Object oCBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlCheckBoxModel"); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! - XMultiPropertySet xCBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oCBModel); + XMultiPropertySet xCBMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oCBModel); xCBMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width" } , new Object[] {new Integer(8), "~Include page number", sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nWidth)}); // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration - XPropertySet xCBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCBMPSet); + XPropertySet xCBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, xCBMPSet); xCBModelPSet.setPropertyValue("TriState", Boolean.TRUE); xCBModelPSet.setPropertyValue("State", new Short((short) 1)); // add the model to the NameContainer of the dialog model m_xDlgModelNameContainer.insertByName(sName, oCBModel); XControl xCBControl = m_xDlgContainer.getControl(sName); - xCheckBox = (XCheckBox) UnoRuntime.queryInterface(XCheckBox.class, xCBControl); + xCheckBox = UnoRuntime.queryInterface(XCheckBox.class, xCBControl); // An ActionListener will be notified on the activation of the button... xCheckBox.addItemListener(_xItemListener); } catch (com.sun.star.uno.Exception ex) { @@ -922,7 +922,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel"); - XMultiPropertySet xRBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); + XMultiPropertySet xRBMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xRBMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "State", "TabIndex", "Width" } , @@ -934,7 +934,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis sName = createUniqueName(m_xDlgModelNameContainer, "OptionButton"); oRBModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRadioButtonModel"); - xRBMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); + xRBMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oRBModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xRBMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "TabIndex", "Width" } , @@ -964,14 +964,14 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oListBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel"); - XMultiPropertySet xLBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oListBoxModel); + XMultiPropertySet xLBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oListBoxModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xLBModelMPSet.setPropertyValues( new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "Step", "StringItemList", "Width" } , new Object[] {Boolean.TRUE, new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), new Integer(_nStep), _sStringItemList, new Integer(_nWidth)}); // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration - XPropertySet xLBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xLBModelMPSet); + XPropertySet xLBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, xLBModelMPSet); xLBModelPSet.setPropertyValue("MultiSelection", Boolean.TRUE); short[] nSelItems = new short[] {(short) 1, (short) 3}; xLBModelPSet.setPropertyValue("SelectedItems", nSelItems); @@ -979,7 +979,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis m_xDlgModelNameContainer.insertByName(sName, xLBModelMPSet); XControl xControl = m_xDlgContainer.getControl(sName); // retrieve a ListBox that is more convenient to work with than the Model of the ListBox... - xListBox = (XListBox) UnoRuntime.queryInterface(XListBox.class, xControl); + xListBox = UnoRuntime.queryInterface(XListBox.class, xControl); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. * Possible exception types are: @@ -1006,7 +1006,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oComboBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlComboBoxModel"); - XMultiPropertySet xCbBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oComboBoxModel); + XMultiPropertySet xCbBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oComboBoxModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xCbBModelMPSet.setPropertyValues( new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "StringItemList", "Width" } , @@ -1014,7 +1014,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration - XPropertySet xCbBModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xCbBModelMPSet); + XPropertySet xCbBModelPSet = UnoRuntime.queryInterface(XPropertySet.class, xCbBModelMPSet); xCbBModelPSet.setPropertyValue("MaxTextLen", new Short((short) 10)); xCbBModelPSet.setPropertyValue("ReadOnly", Boolean.FALSE); @@ -1023,7 +1023,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis XControl xControl = m_xDlgContainer.getControl(sName); // retrieve a ListBox that is more convenient to work with than the Model of the ListBox... - xComboBox = (XComboBox) UnoRuntime.queryInterface(XComboBox.class, xControl); + xComboBox = UnoRuntime.queryInterface(XComboBox.class, xControl); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. * Possible exception types are: @@ -1049,13 +1049,13 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oFFModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFormattedFieldModel"); - XMultiPropertySet xFFModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFFModel); + XMultiPropertySet xFFModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFFModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFFModelMPSet.setPropertyValues( new String[] {"EffectiveValue", "Height", "Name", "PositionX", "PositionY", "StrictFormat", "Spin", "Width"}, new Object[] { new Double(12348), new Integer(12), sName, new Integer(_nPosX), new Integer(_nPosY), Boolean.TRUE, Boolean.TRUE, new Integer(_nWidth)}); - xFFModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFFModel); + xFFModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oFFModel); // to define a numberformat you always need a locale... com.sun.star.lang.Locale aLocale = new com.sun.star.lang.Locale(); aLocale.Country = "US"; @@ -1065,7 +1065,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // a NumberFormatsSupplier has to be created first "in the open countryside"... Object oNumberFormatsSupplier = m_xMCF.createInstanceWithContext("com.sun.star.util.NumberFormatsSupplier", m_xContext); - XNumberFormatsSupplier xNumberFormatsSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface(XNumberFormatsSupplier.class, oNumberFormatsSupplier); + XNumberFormatsSupplier xNumberFormatsSupplier = UnoRuntime.queryInterface(XNumberFormatsSupplier.class, oNumberFormatsSupplier); XNumberFormats xNumberFormats = xNumberFormatsSupplier.getNumberFormats(); // is the numberformat already defined? int nFormatKey = xNumberFormats.queryKey(sFormatString, aLocale, true); @@ -1085,7 +1085,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // finally we add a Spin-Listener to the control XControl xFFControl = m_xDlgContainer.getControl(sName); // add a SpinListener that is notified on each change of the controlvalue... - XSpinField xSpinField = (XSpinField) UnoRuntime.queryInterface(XSpinField.class, xFFControl); + XSpinField xSpinField = UnoRuntime.queryInterface(XSpinField.class, xFFControl); xSpinField.addSpinListener(_xSpinListener); } catch (com.sun.star.uno.Exception ex) { @@ -1116,31 +1116,31 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // retrieve the configured Work path... Object oPathSettings = m_xMCF.createInstanceWithContext("com.sun.star.util.PathSettings",m_xContext); - XPropertySet xPropertySet = (XPropertySet) com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); + XPropertySet xPropertySet = com.sun.star.uno.UnoRuntime.queryInterface(XPropertySet.class, oPathSettings); String sWorkUrl = (String) xPropertySet.getPropertyValue("Work"); // convert the Url to a system path that is "human readable"... Object oFCProvider = m_xMCF.createInstanceWithContext("com.sun.star.ucb.FileContentProvider", m_xContext); - XFileIdentifierConverter xFileIdentifierConverter = (XFileIdentifierConverter) UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider); + XFileIdentifierConverter xFileIdentifierConverter = UnoRuntime.queryInterface(XFileIdentifierConverter.class, oFCProvider); String sSystemWorkPath = xFileIdentifierConverter.getSystemPathFromFileURL(sWorkUrl); // create a controlmodel at the multiservicefactory of the dialog model... Object oFCModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFileControlModel"); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! - XMultiPropertySet xFCModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFCModel); + XMultiPropertySet xFCModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFCModel); xFCModelMPSet.setPropertyValues( new String[] {"Height", "Name", "PositionX", "PositionY", "Text", "Width"}, new Object[] { new Integer(14), sName, new Integer(_nPosX), new Integer(_nPosY), sSystemWorkPath, new Integer(_nWidth)}); // The controlmodel is not really available until inserted to the Dialog container m_xDlgModelNameContainer.insertByName(sName, oFCModel); - XPropertySet xFCModelPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oFCModel); + XPropertySet xFCModelPSet = UnoRuntime.queryInterface(XPropertySet.class, oFCModel); // add a textlistener that is notified on each change of the controlvalue... XControl xFCControl = m_xDlgContainer.getControl(sName); - xTextComponent = (XTextComponent) UnoRuntime.queryInterface(XTextComponent.class, xFCControl); - XWindow xFCWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xFCControl); + xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xFCControl); + XWindow xFCWindow = UnoRuntime.queryInterface(XWindow.class, xFCControl); xTextComponent.addTextListener(_xTextListener); } catch (com.sun.star.uno.Exception ex) { /* perform individual exception handling here. @@ -1166,7 +1166,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a controlmodel at the multiservicefactory of the dialog model... Object oButtonModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel"); - XMultiPropertySet xButtonMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oButtonModel); + XMultiPropertySet xButtonMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oButtonModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xButtonMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "PushButtonType", "Width" } , @@ -1175,7 +1175,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // add the model to the NameContainer of the dialog model m_xDlgModelNameContainer.insertByName(sName, oButtonModel); XControl xButtonControl = m_xDlgContainer.getControl(sName); - xButton = (XButton) UnoRuntime.queryInterface(XButton.class, xButtonControl); + xButton = UnoRuntime.queryInterface(XButton.class, xButtonControl); // An ActionListener will be notified on the activation of the button... xButton.addActionListener(_xActionListener); } catch (com.sun.star.uno.Exception ex) { @@ -1198,10 +1198,10 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis * @return the windowpeer of the frame */ public XWindowPeer getWindowPeer(XTextDocument _xTextDocument){ - XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, _xTextDocument); + XModel xModel = UnoRuntime.queryInterface(XModel.class, _xTextDocument); XFrame xFrame = xModel.getCurrentController().getFrame(); XWindow xWindow = xFrame.getContainerWindow(); - XWindowPeer xWindowPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xWindow); + XWindowPeer xWindowPeer = UnoRuntime.queryInterface(XWindowPeer.class, xWindow); return xWindowPeer; } @@ -1209,7 +1209,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis XFrame xRetFrame = null; try { Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext); - XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop); + XDesktop xDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop); xRetFrame = xDesktop.getCurrentFrame(); } catch (com.sun.star.uno.Exception ex) { ex.printStackTrace(); @@ -1221,9 +1221,9 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public void textChanged(TextEvent textEvent) { try { // get the control that has fired the event, - XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, textEvent.Source); + XControl xControl = UnoRuntime.queryInterface(XControl.class, textEvent.Source); XControlModel xControlModel = xControl.getModel(); - XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel); String sName = (String) xPSet.getPropertyValue("Name"); // just in case the listener has been added to several controls, // we make sure we refer to the right one @@ -1248,9 +1248,9 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public void up(SpinEvent spinEvent) { try { // get the control that has fired the event, - XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, spinEvent.Source); + XControl xControl = UnoRuntime.queryInterface(XControl.class, spinEvent.Source); XControlModel xControlModel = xControl.getModel(); - XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel); String sName = (String) xPSet.getPropertyValue("Name"); // just in case the listener has been added to several controls, // we make sure we refer to the right one @@ -1287,9 +1287,9 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public void actionPerformed(ActionEvent rEvent) { try{ // get the control that has fired the event, - XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, rEvent.Source); + XControl xControl = UnoRuntime.queryInterface(XControl.class, rEvent.Source); XControlModel xControlModel = xControl.getModel(); - XPropertySet xPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControlModel); + XPropertySet xPSet = UnoRuntime.queryInterface(XPropertySet.class, xControlModel); String sName = (String) xPSet.getPropertyValue("Name"); // just in case the listener has been added to several controls, // we make sure we refer to the right one @@ -1315,7 +1315,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // get the window of the Window that has gained the Focus... // Note that the xWindow is just a representation of the controlwindow // but not of the control itself - XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, _focusEvent.NextFocus); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, _focusEvent.NextFocus); } } @@ -1335,15 +1335,15 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public void mouseEntered(MouseEvent _mouseEvent) { try { // retrieve the control that the event has been invoked at... - XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, _mouseEvent.Source); + XControl xControl = UnoRuntime.queryInterface(XControl.class, _mouseEvent.Source); Object tk = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); - XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, tk); + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, tk); // create the peer of the control by passing the windowpeer of the parent // in this case the windowpeer of the control xControl.createPeer(xToolkit, m_xWindowPeer); // create a pointer object "in the open countryside" and set the type accordingly... Object oPointer = this.m_xMCF.createInstanceWithContext("com.sun.star.awt.Pointer", this.m_xContext); - XPointer xPointer = (XPointer) UnoRuntime.queryInterface(XPointer.class, oPointer); + XPointer xPointer = UnoRuntime.queryInterface(XPointer.class, oPointer); xPointer.setType(com.sun.star.awt.SystemPointer.REFHAND); // finally set the created pointer at the windowpeer of the control xControl.getPeer().setPointer(xPointer); @@ -1357,10 +1357,10 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis public void itemStateChanged(ItemEvent itemEvent) { try{ // retrieve the control that the event has been invoked at... - XCheckBox xCheckBox = (XCheckBox) UnoRuntime.queryInterface(XCheckBox.class, itemEvent.Source); + XCheckBox xCheckBox = UnoRuntime.queryInterface(XCheckBox.class, itemEvent.Source); // retrieve the control that we want to disable or enable - XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, m_xDlgContainer.getControl("CommandButton1")); - XPropertySet xModelPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel()); + XControl xControl = UnoRuntime.queryInterface(XControl.class, m_xDlgContainer.getControl("CommandButton1")); + XPropertySet xModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, xControl.getModel()); short nState = xCheckBox.getState(); boolean bdoEnable = true; switch (nState){ @@ -1417,7 +1417,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // create a unique name by means of an own implementation... String sRoadmapName = createUniqueName(m_xDlgModelNameContainer, "Roadmap"); - xDialogModelPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, m_xMSFDialogModel); + xDialogModelPropertySet = UnoRuntime.queryInterface(XPropertySet.class, m_xMSFDialogModel); // Similar to the office assistants the roadmap is adjusted to the height of the dialog // where a certain space is left at the bottom for the buttons... int nDialogHeight = ((Integer) xDialogModelPropertySet.getPropertyValue("Height")).intValue(); @@ -1426,21 +1426,21 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis Object oRoadmapModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlRoadmapModel"); // define the properties of the roadmapmodel - XMultiPropertySet xRMMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oRoadmapModel); + XMultiPropertySet xRMMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oRoadmapModel); xRMMPSet.setPropertyValues( new String[] {"Complete", "Height", "Name", "PositionX", "PositionY", "Text", "Width" }, new Object[] {Boolean.FALSE, new Integer(nDialogHeight - 26), sRoadmapName, new Integer(0), new Integer(0), "Steps", new Integer(85)}); - m_xRMPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmapModel); + m_xRMPSet = UnoRuntime.queryInterface(XPropertySet.class, oRoadmapModel); // add the roadmapmodel to the dialog container.. m_xDlgModelNameContainer.insertByName(sRoadmapName, oRoadmapModel); // the roadmapmodel is a SingleServiceFactory to instantiate the roadmapitems... - m_xSSFRoadmap = (XSingleServiceFactory) UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmapModel); - m_xRMIndexCont = (XIndexContainer) UnoRuntime.queryInterface(XIndexContainer.class, oRoadmapModel); + m_xSSFRoadmap = UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmapModel); + m_xRMIndexCont = UnoRuntime.queryInterface(XIndexContainer.class, oRoadmapModel); // add the itemlistener to the control... XControl xRMControl = this.m_xDlgContainer.getControl(sRoadmapName); - XItemEventBroadcaster xRMBroadcaster = (XItemEventBroadcaster) UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRMControl); + XItemEventBroadcaster xRMBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRMControl); xRMBroadcaster.addItemListener( getRoadmapItemStateChangeListener() ); } catch (java.lang.Exception jexception) { jexception.printStackTrace(System.err); @@ -1457,7 +1457,7 @@ public class UnoDialogSample implements XTextListener, XSpinListener, XActionLis // a roadmap is a SingleServiceFactory that can only create roadmapitems that are the only possible // element types of the container Object oRoadmapItem = m_xSSFRoadmap.createInstance(); - XPropertySet xRMItemPSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oRoadmapItem); + XPropertySet xRMItemPSet = UnoRuntime.queryInterface(XPropertySet.class, oRoadmapItem); xRMItemPSet.setPropertyValue("Label", _sLabel); // sometimes steps are supposed to be set disabled depending on the program logic... xRMItemPSet.setPropertyValue("Enabled", new Boolean(_bEnabled)); diff --git a/odk/examples/DevelopersGuide/GUI/UnoDialogSample2.java b/odk/examples/DevelopersGuide/GUI/UnoDialogSample2.java index a410a16de40c..a48e46956826 100644 --- a/odk/examples/DevelopersGuide/GUI/UnoDialogSample2.java +++ b/odk/examples/DevelopersGuide/GUI/UnoDialogSample2.java @@ -70,7 +70,7 @@ public class UnoDialogSample2 extends UnoDialogSample { try { m_oUnoObject = _oUnoObject; Object o = m_xMCF.createInstanceWithContext("com.sun.star.beans.Introspection", m_xContext); - XIntrospection m_xIntrospection = ( XIntrospection ) UnoRuntime.queryInterface(XIntrospection.class, o ); + XIntrospection m_xIntrospection = UnoRuntime.queryInterface(XIntrospection.class, o ); // the variable m_xIntrospectionAccess offers functionality to access all methods and properties // of a variable m_xIntrospectionAccess = m_xIntrospection.inspect(_oUnoObject); @@ -89,11 +89,11 @@ public class UnoDialogSample2 extends UnoDialogSample { PropertyValue[] aPropertyValues = new PropertyValue[]{}; // create an arbitrary Uno-Object - in this case an empty writer document.. Object oDesktop =xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext); - XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); Object oUnoObject = xComponentLoader.loadComponentFromURL("private:factory/swriter", "_default", 0, aPropertyValues); // define some coordinates where to position the controls - final int nButtonPosX = (int)((nDialogWidth/2) - (nButtonWidth/2)); + final int nButtonPosX = (nDialogWidth/2) - (nButtonWidth/2); final int nButtonPosY = nDialogHeight - nButtonHeight - nControlMargin; final int nControlPosX = nRoadmapWidth + 2*nControlMargin; final int nControlWidth = nDialogWidth - 3*nControlMargin - nRoadmapWidth; @@ -129,7 +129,7 @@ public class UnoDialogSample2 extends UnoDialogSample { oUnoDialogSample2.insertRoadmapItem(4, true, "Properties", 5); oUnoDialogSample2.m_xRMPSet.setPropertyValue("CurrentItemID", new Short((short) 1)); oUnoDialogSample2.m_xRMPSet.setPropertyValue("Complete", Boolean.TRUE); - oUnoDialogSample2.xDialog = (XDialog) UnoRuntime.queryInterface(XDialog.class, oUnoDialogSample2.m_xDialogControl); + oUnoDialogSample2.xDialog = UnoRuntime.queryInterface(XDialog.class, oUnoDialogSample2.m_xDialogControl); oUnoDialogSample2.xDialog.execute(); }catch( Exception ex ) { ex.printStackTrace(System.err); @@ -167,7 +167,7 @@ public class UnoDialogSample2 extends UnoDialogSample { String[] sSupportedServiceNames = new String[]{}; // If the Uno-Object supports "com.sun.star.lang.XServiceInfo" // this will give access to all supported servicenames - XServiceInfo xServiceInfo = ( XServiceInfo ) UnoRuntime.queryInterface( XServiceInfo.class, m_oUnoObject); + XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, m_oUnoObject); if ( xServiceInfo != null ) { sSupportedServiceNames = xServiceInfo.getSupportedServiceNames(); } @@ -196,7 +196,7 @@ public class UnoDialogSample2 extends UnoDialogSample { Type[] aTypes = new Type[]{}; String[] sTypeNames = new String[]{}; // The XTypeProvider interfaces offers access to all exported interfaces - XTypeProvider xTypeProvider = ( XTypeProvider ) UnoRuntime.queryInterface( XTypeProvider.class, m_oUnoObject); + XTypeProvider xTypeProvider = UnoRuntime.queryInterface( XTypeProvider.class, m_oUnoObject); if ( xTypeProvider != null ) { aTypes = xTypeProvider.getTypes(); sTypeNames = new String[aTypes.length]; @@ -216,7 +216,7 @@ public class UnoDialogSample2 extends UnoDialogSample { String sName = createUniqueName(m_xDlgModelNameContainer, "ListBox"); // create a controlmodel at the multiservicefactory of the dialog model... Object oListBoxModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel"); - XMultiPropertySet xLBModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oListBoxModel); + XMultiPropertySet xLBModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oListBoxModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xLBModelMPSet.setPropertyValues( new String[] {"Dropdown", "Height", "Name", "PositionX", "PositionY", "ReadOnly", "Step", "StringItemList", "Width" } , @@ -236,7 +236,7 @@ public class UnoDialogSample2 extends UnoDialogSample { int nHeight = _nLineCount * nFixedTextHeight; // create a controlmodel at the multiservicefactory of the dialog model... Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); + XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFTModelMPSet.setPropertyValues( new String[] {"Height", "Label", "MultiLine", "Name", "PositionX", "PositionY", "Step", "Width"}, diff --git a/odk/examples/DevelopersGuide/GUI/UnoMenu.java b/odk/examples/DevelopersGuide/GUI/UnoMenu.java index c5fdbe218350..86942f91c0d6 100644 --- a/odk/examples/DevelopersGuide/GUI/UnoMenu.java +++ b/odk/examples/DevelopersGuide/GUI/UnoMenu.java @@ -65,8 +65,8 @@ public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) { try{ // create a popup menu Object oPopupMenu = m_xMCF.createInstanceWithContext("stardiv.Toolkit.VCLXPopupMenu", m_xContext); - xPopupMenu = (XPopupMenu) UnoRuntime.queryInterface(XPopupMenu.class, oPopupMenu); - XMenuExtended xMenuExtended = (XMenuExtended) UnoRuntime.queryInterface(XMenuExtended.class, xPopupMenu); + xPopupMenu = UnoRuntime.queryInterface(XPopupMenu.class, oPopupMenu); + XMenuExtended xMenuExtended = UnoRuntime.queryInterface(XMenuExtended.class, xPopupMenu); xPopupMenu.insertItem((short) 0, "~First Entry", MenuItemStyle.AUTOCHECK, (short) 0); xPopupMenu.insertItem((short) 1, "First ~Radio Entry", (short) (MenuItemStyle.RADIOCHECK + MenuItemStyle.AUTOCHECK), (short) 1); @@ -92,7 +92,7 @@ public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) { // create a menubar at the global MultiComponentFactory... Object oMenuBar = m_xMCF.createInstanceWithContext("stardiv.Toolkit.VCLXMenuBar", m_xContext); // add the menu items... - XMenuBar xMenuBar = (XMenuBar) UnoRuntime.queryInterface(XMenuBar.class, oMenuBar); + XMenuBar xMenuBar = UnoRuntime.queryInterface(XMenuBar.class, oMenuBar); xMenuBar.insertItem((short) 0, "~First MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 0); xMenuBar.insertItem((short) 1, "~Second MenuBar Item", com.sun.star.awt.MenuItemStyle.AUTOCHECK, (short) 1); xMenuBar.setPopupMenu((short) 0, getPopupMenu()); @@ -103,7 +103,7 @@ public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) { }} protected void closeDialog(){ - XComponent xComponent = (XComponent) UnoRuntime.queryInterface(XComponent.class, mxTopWindow); + XComponent xComponent = UnoRuntime.queryInterface(XComponent.class, mxTopWindow); if (xComponent != null){ xComponent.dispose(); } @@ -117,7 +117,7 @@ public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) { try { // The Toolkit is the creator of all windows... Object oToolkit = m_xMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", m_xContext); - XToolkit xToolkit = (XToolkit) UnoRuntime.queryInterface(XToolkit.class, oToolkit); + XToolkit xToolkit = UnoRuntime.queryInterface(XToolkit.class, oToolkit); // set up a window description and create the window. A parent window is always necessary for this... com.sun.star.awt.WindowDescriptor aWindowDescriptor = new com.sun.star.awt.WindowDescriptor(); @@ -130,17 +130,17 @@ public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) { // create the window... XWindowPeer xWindowPeer = xToolkit.createWindow(aWindowDescriptor); - XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, xWindowPeer); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, xWindowPeer); // create a frame and initialize it with the created window... Object oFrame = m_xMCF.createInstanceWithContext("com.sun.star.frame.Frame", m_xContext); - m_xFrame = (XFrame) UnoRuntime.queryInterface(XFrame.class, oFrame); + m_xFrame = UnoRuntime.queryInterface(XFrame.class, oFrame); Object oDesktop = m_xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", m_xContext); - XFramesSupplier xFramesSupplier = (XFramesSupplier) UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop); + XFramesSupplier xFramesSupplier = UnoRuntime.queryInterface(XFramesSupplier.class, oDesktop); m_xFrame.setCreator(xFramesSupplier); // get the XTopWindow interface.. - xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, xWindow); + xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, xWindow); } catch (com.sun.star.lang.IllegalArgumentException ex) { ex.printStackTrace(); } catch (com.sun.star.uno.Exception ex) { @@ -150,7 +150,7 @@ public UnoMenu(XComponentContext _xContext, XMultiComponentFactory _xMCF) { } public void addMenuBar(XWindow _xWindow){ - XTopWindow xTopWindow = (XTopWindow) UnoRuntime.queryInterface(XTopWindow.class, _xWindow); + XTopWindow xTopWindow = UnoRuntime.queryInterface(XTopWindow.class, _xWindow); addMenuBar(xTopWindow, this); } diff --git a/odk/examples/DevelopersGuide/GUI/UnoMenu2.java b/odk/examples/DevelopersGuide/GUI/UnoMenu2.java index 89643415c24e..0edae176bd71 100644 --- a/odk/examples/DevelopersGuide/GUI/UnoMenu2.java +++ b/odk/examples/DevelopersGuide/GUI/UnoMenu2.java @@ -46,7 +46,7 @@ public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) { new Object[] { new Integer(140), Boolean.TRUE, "Dialog1", new Integer(102),new Integer(41), new Integer(1), new Short((short) 0), "Menu-Dialog", new Integer(200)}); Object oFTHeaderModel = oUnoMenu2.m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTHeaderModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); + XMultiPropertySet xFTHeaderModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTHeaderModel); xFTHeaderModelMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, new Object[] { new Integer(8), "This code-sample demonstrates the creation of a popup-menu", "HeaderLabel", new Integer(6), new Integer(6), new Integer(200)}); @@ -72,14 +72,14 @@ public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) { try{ String sName = "lblPopup"; Object oFTModel = m_xMSFDialogModel.createInstance("com.sun.star.awt.UnoControlFixedTextModel"); - XMultiPropertySet xFTModelMPSet = (XMultiPropertySet) UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); + XMultiPropertySet xFTModelMPSet = UnoRuntime.queryInterface(XMultiPropertySet.class, oFTModel); // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFTModelMPSet.setPropertyValues( new String[] {"Height", "Label", "Name", "PositionX", "PositionY", "Width"}, new Object[] { new Integer(8), "Right-click here", sName, new Integer(50), new Integer(50), new Integer(100)}); // add the model to the NameContainer of the dialog model m_xDlgModelNameContainer.insertByName(sName, oFTModel); - XWindow xWindow = (XWindow) UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName)); + XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, m_xDlgContainer.getControl(sName)); xWindow.addMouseListener(this); }catch( Exception e ) { System.err.println( e + e.getMessage()); @@ -96,7 +96,7 @@ public UnoMenu2(XComponentContext _xContext, XMultiComponentFactory _xMCF) { public void mousePressed(MouseEvent mouseEvent) { if (mouseEvent.PopupTrigger){ Rectangle aRectangle = new Rectangle(mouseEvent.X, mouseEvent.Y, 0, 0); - XControl xControl = (XControl) UnoRuntime.queryInterface(XControl.class, mouseEvent.Source); + XControl xControl = UnoRuntime.queryInterface(XControl.class, mouseEvent.Source); getPopupMenu().execute( xControl.getPeer(), aRectangle, com.sun.star.awt.PopupMenuDirection.DEFAULT); } } diff --git a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java index b4f6a469cc9f..9ad119e0bc7d 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Clipboard/Clipboard.java @@ -67,29 +67,27 @@ public class Clipboard Object oDesktop = xServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xOfficeContext); - XComponentLoader xCompLoader =(XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); + XComponentLoader xCompLoader =UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); com.sun.star.lang.XComponent xComponent = xCompLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new com.sun.star.beans.PropertyValue[0]); { - XTextDocument xDoc =(XTextDocument) - UnoRuntime.queryInterface(XTextDocument.class, xComponent); + XTextDocument xDoc =UnoRuntime.queryInterface(XTextDocument.class, xComponent); xDoc.getText().setString("In the first step, paste the current content of the clipboard in the document!\nThe text \"Hello world!\" shall be insert at the current cursor position below.\n\nIn the second step, please select some words and put it into the clipboard! ...\n\nCurrent clipboard content = "); // 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); // get the frame for later usage com.sun.star.frame.XFrame xFrame = xModel.getCurrentController().getFrame(); 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)); } @@ -99,15 +97,13 @@ public class Clipboard "com.sun.star.datatransfer.clipboard.SystemClipboard", xOfficeContext); - XClipboard xClipboard = (XClipboard) - UnoRuntime.queryInterface(XClipboard.class, oClipboard); + XClipboard xClipboard = UnoRuntime.queryInterface(XClipboard.class, oClipboard); //--------------------------------------------------- // registering as clipboard listener //--------------------------------------------------- - XClipboardNotifier xClipNotifier = (XClipboardNotifier) - UnoRuntime.queryInterface(XClipboardNotifier.class, oClipboard); + XClipboardNotifier xClipNotifier = UnoRuntime.queryInterface(XClipboardNotifier.class, oClipboard); ClipboardListener aClipListener= new ClipboardListener(); @@ -152,9 +148,8 @@ public class Clipboard xClipNotifier.removeClipboardListener(aClipListener); // 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); diff --git a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java index d0d2c5756daf..67d0331b2c29 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java +++ b/odk/examples/DevelopersGuide/OfficeDev/ContextMenuInterceptor.java @@ -57,8 +57,8 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { // create a new test document 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", @@ -67,23 +67,22 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { // intialize the test document com.sun.star.frame.XFrame xFrame = null; { - 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); String infoMsg = new String("All context menus of the created document frame contains now a 'Help' entry with the submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' in the shell to remove the context menu interceptor and finish the example!"); xDoc.getText().setString(infoMsg); // 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); // get the frame for later usage xFrame = xModel.getCurrentController().getFrame(); 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)); } @@ -93,13 +92,13 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { com.sun.star.frame.XController xController = xFrame.getController(); if ( xController != null ) { com.sun.star.ui.XContextMenuInterception xContextMenuInterception = - (com.sun.star.ui.XContextMenuInterception)UnoRuntime.queryInterface( - com.sun.star.ui.XContextMenuInterception.class, xController ); + UnoRuntime.queryInterface( + com.sun.star.ui.XContextMenuInterception.class, xController ); if( xContextMenuInterception != null ) { ContextMenuInterceptor aContextMenuInterceptor = new ContextMenuInterceptor(); com.sun.star.ui.XContextMenuInterceptor xContextMenuInterceptor = - (com.sun.star.ui.XContextMenuInterceptor)UnoRuntime.queryInterface( - com.sun.star.ui.XContextMenuInterceptor.class, aContextMenuInterceptor ); + UnoRuntime.queryInterface( + com.sun.star.ui.XContextMenuInterceptor.class, aContextMenuInterceptor ); xContextMenuInterception.registerContextMenuInterceptor( xContextMenuInterceptor ); System.out.println( "\n ... all context menus of the created document frame contains now a 'Help' entry with the\n submenus 'Content', 'Help Agent' and 'Tips'.\n\nPress 'Return' to remove the context menu interceptor and finish the example!"); @@ -115,9 +114,8 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { } // 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); @@ -156,41 +154,41 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { // create sub menus, menu entries and separators com.sun.star.container.XIndexContainer xContextMenu = aEvent.ActionTriggerContainer; com.sun.star.lang.XMultiServiceFactory xMenuElementFactory = - (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, xContextMenu ); + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, xContextMenu ); if ( xMenuElementFactory != null ) { // create root menu entry and sub menu com.sun.star.beans.XPropertySet xRootMenuEntry = - (XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, - xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, + xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); // create a line separator for our new help sub menu com.sun.star.beans.XPropertySet xSeparator = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, - xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTriggerSeparator" )); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, + xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTriggerSeparator" )); Short aSeparatorType = new Short( ActionTriggerSeparatorType.LINE ); - xSeparator.setPropertyValue( "SeparatorType", (Object)aSeparatorType ); + xSeparator.setPropertyValue( "SeparatorType", aSeparatorType ); // query sub menu for index container to get access com.sun.star.container.XIndexContainer xSubMenuContainer = - (com.sun.star.container.XIndexContainer)UnoRuntime.queryInterface( - com.sun.star.container.XIndexContainer.class, - xMenuElementFactory.createInstance( - "com.sun.star.ui.ActionTriggerContainer" )); + UnoRuntime.queryInterface( + com.sun.star.container.XIndexContainer.class, + xMenuElementFactory.createInstance( + "com.sun.star.ui.ActionTriggerContainer" )); // intialize root menu entry xRootMenuEntry.setPropertyValue( "Text", new String( "Help" )); xRootMenuEntry.setPropertyValue( "CommandURL", new String( "slot:5410" )); xRootMenuEntry.setPropertyValue( "HelpURL", new String( "5410" )); - xRootMenuEntry.setPropertyValue( "SubContainer", (Object)xSubMenuContainer ); + xRootMenuEntry.setPropertyValue( "SubContainer", xSubMenuContainer ); // create menu entries for the new sub menu // intialize help/content menu entry - XPropertySet xMenuEntry = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xMenuEntry = UnoRuntime.queryInterface( XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); @@ -199,10 +197,10 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { xMenuEntry.setPropertyValue( "HelpURL", new String( "5401" )); // insert menu entry to sub menu - xSubMenuContainer.insertByIndex( 0, (Object)xMenuEntry ); + xSubMenuContainer.insertByIndex( 0, xMenuEntry ); // intialize help/help agent - xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + xMenuEntry = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); @@ -211,10 +209,10 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { xMenuEntry.setPropertyValue( "HelpURL", new String( "5962" )); // insert menu entry to sub menu - xSubMenuContainer.insertByIndex( 1, (Object)xMenuEntry ); + xSubMenuContainer.insertByIndex( 1, xMenuEntry ); // intialize help/tips - xMenuEntry = (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( + xMenuEntry = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xMenuElementFactory.createInstance( "com.sun.star.ui.ActionTrigger" )); @@ -223,13 +221,13 @@ public class ContextMenuInterceptor implements XContextMenuInterceptor { xMenuEntry.setPropertyValue( "HelpURL", new String( "5404" )); // insert menu entry to sub menu - xSubMenuContainer.insertByIndex( 2, (Object)xMenuEntry ); + xSubMenuContainer.insertByIndex( 2, xMenuEntry ); // add separator into the given context menu - xContextMenu.insertByIndex( 0, (Object)xSeparator ); + xContextMenu.insertByIndex( 0, xSeparator ); // add new sub menu into the given context menu - xContextMenu.insertByIndex( 0, (Object)xRootMenuEntry ); + xContextMenu.insertByIndex( 0, xRootMenuEntry ); // The controller should execute the modified context menu and stop notifying other // interceptors. diff --git a/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java b/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java index 963ced576d43..f81c59afca31 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java +++ b/odk/examples/DevelopersGuide/OfficeDev/DisableCommands/DisableCommandsTest.java @@ -76,30 +76,26 @@ public class DisableCommandsTest extends java.lang.Object { Object transformer = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.util.URLTransformer", xRemoteContext ); - xTransformer = (com.sun.star.util.XURLTransformer) - UnoRuntime.queryInterface(com.sun.star.util.XURLTransformer.class, - transformer ); + xTransformer = UnoRuntime.queryInterface(com.sun.star.util.XURLTransformer.class, + transformer ); Object configProvider = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.configuration.ConfigurationProvider", xRemoteContext ); - xConfigProvider = (com.sun.star.lang.XMultiServiceFactory) - UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, configProvider ); + xConfigProvider = UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, configProvider ); // create a new test document Object oDesktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); - XComponentLoader xCompLoader =(XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); + XComponentLoader xCompLoader =UnoRuntime.queryInterface(XComponentLoader.class, oDesktop); com.sun.star.lang.XComponent xComponent = xCompLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, new com.sun.star.beans.PropertyValue[0]); { - XTextDocument xDoc =(XTextDocument) - UnoRuntime.queryInterface(XTextDocument.class, xComponent); + XTextDocument xDoc =UnoRuntime.queryInterface(XTextDocument.class, xComponent); xDoc.getText().setString("You can now check the disabled commands. The " +"following commands are disabled:\n\n" +" Open...\n Exit\n Select All\n " @@ -112,16 +108,16 @@ public class DisableCommandsTest extends java.lang.Object { // 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); // get the frame for later usage com.sun.star.frame.XFrame xFrame = xModel.getCurrentController().getFrame(); 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)); } @@ -157,9 +153,8 @@ public class DisableCommandsTest extends java.lang.Object { waitForUserInput(); // 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); @@ -196,15 +191,14 @@ public class DisableCommandsTest extends java.lang.Object { // We need the desktop to get access to the current frame Object desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext ); - com.sun.star.frame.XDesktop xDesktop = (com.sun.star.frame.XDesktop) - UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop ); + com.sun.star.frame.XDesktop xDesktop = UnoRuntime.queryInterface(com.sun.star.frame.XDesktop.class, desktop ); com.sun.star.frame.XFrame xFrame = xDesktop.getCurrentFrame(); com.sun.star.frame.XDispatchProvider xDispatchProvider = null; if ( xFrame != null ) { // We have a frame. Now we need access to the dispatch provider. xDispatchProvider = - (com.sun.star.frame.XDispatchProvider)UnoRuntime.queryInterface( + UnoRuntime.queryInterface( com.sun.star.frame.XDispatchProvider.class, xFrame ); if ( xDispatchProvider != null ) { @@ -272,15 +266,14 @@ public class DisableCommandsTest extends java.lang.Object { lParams ); com.sun.star.container.XNameAccess xNameAccess = - (com.sun.star.container.XNameAccess)UnoRuntime.queryInterface( - com.sun.star.container.XNameAccess.class, xAccess ); + UnoRuntime.queryInterface( + com.sun.star.container.XNameAccess.class, xAccess ); if ( xNameAccess != null ) { // We need the XNameContainer interface to remove the nodes by name com.sun.star.container.XNameContainer xNameContainer = - (com.sun.star.container.XNameContainer) UnoRuntime.queryInterface( - com.sun.star.container.XNameContainer.class, xAccess ); + com.sun.star.container.XNameContainer.class, xAccess ); // Retrieves the names of all Disabled nodes String[] aCommandsSeq = xNameAccess.getElementNames(); @@ -298,8 +291,8 @@ public class DisableCommandsTest extends java.lang.Object { // Commit our changes com.sun.star.util.XChangesBatch xFlush = - (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface( - com.sun.star.util.XChangesBatch.class, xAccess); + UnoRuntime.queryInterface( + com.sun.star.util.XChangesBatch.class, xAccess); xFlush.commitChanges(); } @@ -329,12 +322,12 @@ public class DisableCommandsTest extends java.lang.Object { lParams ); com.sun.star.lang.XSingleServiceFactory xSetElementFactory = - (com.sun.star.lang.XSingleServiceFactory)UnoRuntime.queryInterface( - com.sun.star.lang.XSingleServiceFactory.class, xAccess ); + UnoRuntime.queryInterface( + com.sun.star.lang.XSingleServiceFactory.class, xAccess ); com.sun.star.container.XNameContainer xNameContainer = - (com.sun.star.container.XNameContainer)UnoRuntime.queryInterface( - com.sun.star.container.XNameContainer.class, xAccess ); + UnoRuntime.queryInterface( + com.sun.star.container.XNameContainer.class, xAccess ); if ( xSetElementFactory != null && xNameContainer != null ) { Object[] aArgs = new Object[0]; @@ -349,10 +342,9 @@ public class DisableCommandsTest extends java.lang.Object { // We have a new node. To set the properties of the node // we need the XPropertySet interface. com.sun.star.beans.XPropertySet xPropertySet = - (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, - xNewElement ); + com.sun.star.beans.XPropertySet.class, + xNewElement ); if ( xPropertySet != null ) { // Create a unique node name. @@ -370,8 +362,8 @@ public class DisableCommandsTest extends java.lang.Object { // Commit our changes com.sun.star.util.XChangesBatch xFlush = - (com.sun.star.util.XChangesBatch)UnoRuntime.queryInterface( - com.sun.star.util.XChangesBatch.class, xAccess); + UnoRuntime.queryInterface( + com.sun.star.util.XChangesBatch.class, xAccess); xFlush.commitChanges(); } } diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java index 6d6db31ebe58..f62c2e54991a 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/AsciiReplaceFilter.java @@ -257,7 +257,7 @@ public class AsciiReplaceFilter if (xDocument==null) throw new com.sun.star.lang.IllegalArgumentException("null reference detected"); - com.sun.star.lang.XServiceInfo xInfo = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface( + com.sun.star.lang.XServiceInfo xInfo = UnoRuntime.queryInterface( com.sun.star.lang.XServiceInfo.class, xDocument); if ( ! xInfo.supportsService("com.sun.star.text.TextDocument") ) throw new com.sun.star.lang.IllegalArgumentException( "wrong document type" ); @@ -266,7 +266,7 @@ public class AsciiReplaceFilter // Don't forget to mark this filter used for importing too synchronized(this) { - m_xDocument = (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface( + m_xDocument = UnoRuntime.queryInterface( com.sun.star.text.XTextDocument.class, xDocument); m_bImport = true; } @@ -293,7 +293,7 @@ public class AsciiReplaceFilter if (xDocument==null) throw new com.sun.star.lang.IllegalArgumentException( "null reference given" ); - com.sun.star.lang.XServiceInfo xInfo = (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface( + com.sun.star.lang.XServiceInfo xInfo = UnoRuntime.queryInterface( com.sun.star.lang.XServiceInfo.class, xDocument); if ( ! xInfo.supportsService("com.sun.star.text.TextDocument") ) throw new com.sun.star.lang.IllegalArgumentException( "wrong document type" ); @@ -302,7 +302,7 @@ public class AsciiReplaceFilter // Don't forget to mark this filter used for exporting too synchronized(this) { - m_xDocument = (com.sun.star.text.XTextDocument)UnoRuntime.queryInterface( + m_xDocument = UnoRuntime.queryInterface( com.sun.star.text.XTextDocument.class, xDocument); m_bImport = false; } @@ -413,7 +413,7 @@ public class AsciiReplaceFilter { measure("implts_import {"); - com.sun.star.text.XSimpleText xText = (com.sun.star.text.XSimpleText)UnoRuntime.queryInterface( + com.sun.star.text.XSimpleText xText = UnoRuntime.queryInterface( com.sun.star.text.XSimpleText.class, xTarget.getText()); @@ -463,7 +463,7 @@ public class AsciiReplaceFilter int nEnd = -1; int nLength = sText.length(); - com.sun.star.text.XTextRange xCursor = (com.sun.star.text.XTextRange)UnoRuntime.queryInterface( + com.sun.star.text.XTextRange xCursor = UnoRuntime.queryInterface( com.sun.star.text.XTextRange.class, xText.createTextCursor()); @@ -498,7 +498,7 @@ public class AsciiReplaceFilter measure("set on model"); // with refreshing the document we are on the safe-side, otherwise the first time the filter is used the document is not fully shown (flaw!). - com.sun.star.util.XRefreshable xRefresh = (com.sun.star.util.XRefreshable)UnoRuntime.queryInterface( + com.sun.star.util.XRefreshable xRefresh = UnoRuntime.queryInterface( com.sun.star.util.XRefreshable.class, xTarget); xRefresh.refresh(); @@ -545,7 +545,7 @@ public class AsciiReplaceFilter { measure("implts_export {"); - com.sun.star.text.XTextRange xText = (com.sun.star.text.XSimpleText)UnoRuntime.queryInterface( + com.sun.star.text.XTextRange xText = UnoRuntime.queryInterface( com.sun.star.text.XSimpleText.class, xSource.getText()); diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java index e882e089b0e4..bec6966999c2 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/AsciiFilter/FilterOptions.java @@ -203,7 +203,7 @@ public class FilterOptions private void impl_openStreams( boolean bImport ) { try{ - com.sun.star.ucb.XSimpleFileAccess xHelper = (com.sun.star.ucb.XSimpleFileAccess)UnoRuntime.queryInterface( + com.sun.star.ucb.XSimpleFileAccess xHelper = UnoRuntime.queryInterface( com.sun.star.ucb.XSimpleFileAccess.class, m_xMCF.createInstanceWithContext("com.sun.star.ucb.SimpleFileAccess", m_Ctx)); if (xHelper!=null) diff --git a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java index ea62ae19754d..3bb11f322136 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java +++ b/odk/examples/DevelopersGuide/OfficeDev/FilterDevelopment/FlatXmlFilter_java/FlatXml.java @@ -133,7 +133,7 @@ public class FlatXml implements XImportFilter, XExportFilter, XServiceName, Object tmpObj=m_xServiceFactory.createInstance("com.sun.star.xml.sax.Parser"); if (tmpObj == null) return false; - XParser xParser = (XParser)UnoRuntime.queryInterface(XParser.class , tmpObj); + XParser xParser = UnoRuntime.queryInterface(XParser.class , tmpObj); if (xParser == null) return false; InputSource aInput = new InputSource(); @@ -174,13 +174,13 @@ public class FlatXml implements XImportFilter, XExportFilter, XServiceName, { tmpObj = m_xServiceFactory.createInstance("com.sun.star.xml.sax.Writer"); if (tmpObj != null) - m_xHandler = (XExtendedDocumentHandler)UnoRuntime.queryInterface(XExtendedDocumentHandler.class, tmpObj); + m_xHandler = UnoRuntime.queryInterface(XExtendedDocumentHandler.class, tmpObj); } if (m_xHandler == null) return false; // Connect the provided output stream to the writer - XActiveDataSource xADSource = (XActiveDataSource)UnoRuntime.queryInterface( + XActiveDataSource xADSource = UnoRuntime.queryInterface( XActiveDataSource.class, m_xHandler); if (xADSource != null && xos != null) diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java index b21190d173aa..7cdf7f68b381 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/LinguisticExamples.java @@ -113,8 +113,7 @@ public class LinguisticExamples if (mxRemoteContext != null && mxRemoteServiceManager != null) { Object aObj = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.linguistic2.LinguServiceManager", mxRemoteContext ); - mxLinguSvcMgr = (XLinguServiceManager) - UnoRuntime.queryInterface(XLinguServiceManager.class, aObj); + mxLinguSvcMgr = UnoRuntime.queryInterface(XLinguServiceManager.class, aObj); } return mxLinguSvcMgr != null; } @@ -291,7 +290,7 @@ public class LinguisticExamples // get access to LinguProperties property set Object aObj = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.linguistic2.LinguProperties", mxRemoteContext); - XPropertySet aLinguProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aLinguProps = UnoRuntime.queryInterface( XPropertySet.class,aObj); // set a spellchecker and hyphenator property value to a defined state diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java index 05f34cc6ab85..114d1bda2e94 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/OneInstanceFactory.java @@ -90,14 +90,14 @@ public class OneInstanceFactory implements //!! workaround for services not always being created //!! via 'createInstanceWithArguments' - XInitialization xIni = (XInitialization) UnoRuntime.queryInterface( + XInitialization xIni = UnoRuntime.queryInterface( XInitialization.class, createInstance()); if (xIni != null) { Object[] aArguments = new Object[]{ null, null }; if (xMultiFactory != null) { - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class , xMultiFactory.createInstance( "com.sun.star.linguistic2.LinguProperties" ) ); aArguments[0] = xPropSet; @@ -114,7 +114,7 @@ public class OneInstanceFactory implements { if (xInstantiatedService == null) { - XInitialization xIni = (XInitialization) UnoRuntime.queryInterface( + XInitialization xIni = UnoRuntime.queryInterface( XInitialization.class, createInstance()); if (xIni != null) xIni.initialize( aArguments ); diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java index 498a8919b20c..2932a7791367 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/PropChgHelper.java @@ -83,7 +83,7 @@ public class PropChgHelper implements for (int i = 0; i < nCnt; ++i) { XLinguServiceEventListener xLstnr = - (XLinguServiceEventListener) aLngSvcEvtListeners.get(i); + aLngSvcEvtListeners.get(i); if (xLstnr != null) xLstnr.processLinguServiceEvent( aEvt ); } @@ -105,7 +105,7 @@ public class PropChgHelper implements { try { xPropSet.addPropertyChangeListener( - aPropNames[i], (XPropertyChangeListener) this ); + aPropNames[i], this ); } catch( Exception e ) { } @@ -125,7 +125,7 @@ public class PropChgHelper implements { try { xPropSet.removePropertyChangeListener( - aPropNames[i], (XPropertyChangeListener) this ); + aPropNames[i], this ); } catch( Exception e ) { } diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java index a81aad0e1ab6..d786d0ad98b3 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleHyphenator.java @@ -84,7 +84,7 @@ public class SampleHyphenator extends ComponentBase implements "HyphMinTrailing", "HyphMinWordLength" }; - aPropChgHelper = new PropChgHelper_Hyph( (XHyphenator) this, aProps ); + aPropChgHelper = new PropChgHelper_Hyph( this, aProps ); aEvtListeners = new ArrayList<Object>();; bDisposing = false; } @@ -442,7 +442,7 @@ public class SampleHyphenator extends ComponentBase implements int nLen = aArguments.length; if (2 == nLen) { - XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, aArguments[0]); // start listening to property changes aPropChgHelper.AddAsListenerTo( xPropSet ); diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java index 10ec0aa9f46e..c4c61eb73beb 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleSpellChecker.java @@ -84,7 +84,7 @@ public class SampleSpellChecker extends ComponentBase implements "IsSpellWithDigits", "IsSpellCapitalization" }; - aPropChgHelper = new PropChgHelper_Spell( (XSpellChecker) this, aProps ); + aPropChgHelper = new PropChgHelper_Spell( this, aProps ); aEvtListeners = new ArrayList<Object>(); bDisposing = false; } @@ -386,7 +386,7 @@ public class SampleSpellChecker extends ComponentBase implements int nLen = aArguments.length; if (2 == nLen) { - XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, aArguments[0]); // start listening to property changes aPropChgHelper.AddAsListenerTo( xPropSet ); diff --git a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java index e33929a4b77a..fb8c96f3bcfe 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Linguistic/SampleThesaurus.java @@ -80,7 +80,7 @@ public class SampleThesaurus extends ComponentBase implements // which is here basically used only to keep track of the // property set (and it's lifetime) since it gets used in the // 'GetValueToUse' function - aPropChgHelper = new PropChgHelper( (XThesaurus) this, aProps ); + aPropChgHelper = new PropChgHelper( this, aProps ); aEvtListeners = new ArrayList<Object>(); bDisposing = false; @@ -222,7 +222,7 @@ public class SampleThesaurus extends ComponentBase implements int nLen = aArguments.length; if (2 == nLen) { - XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, aArguments[0]); // start listening to property changes aPropChgHelper.AddAsListenerTo( xPropSet ); diff --git a/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java b/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java index 6d695d5e2002..fa351f1c7f5e 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java +++ b/odk/examples/DevelopersGuide/OfficeDev/MenuElement.java @@ -39,16 +39,16 @@ public class MenuElement { static public boolean IsMenuEntry( com.sun.star.beans.XPropertySet xMenuElement ) { com.sun.star.lang.XServiceInfo xServiceInfo = - (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface( - com.sun.star.lang.XServiceInfo.class, xMenuElement ); + UnoRuntime.queryInterface( + com.sun.star.lang.XServiceInfo.class, xMenuElement ); return xServiceInfo.supportsService( "com.sun.star.ui.ActionTrigger" ); } static public boolean IsMenuSeparator( com.sun.star.beans.XPropertySet xMenuElement ) { com.sun.star.lang.XServiceInfo xServiceInfo = - (com.sun.star.lang.XServiceInfo)UnoRuntime.queryInterface( - com.sun.star.lang.XServiceInfo.class, xMenuElement ); + UnoRuntime.queryInterface( + com.sun.star.lang.XServiceInfo.class, xMenuElement ); return xServiceInfo.supportsService( "com.sun.star.ui.ActionTriggerSeparator" ); } diff --git a/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java b/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java index f3369c3e0d14..eb536ce02b15 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java +++ b/odk/examples/DevelopersGuide/OfficeDev/Number_Formats.java @@ -86,9 +86,8 @@ public class Number_Formats // Query the number formats supplier of the spreadsheet document com.sun.star.util.XNumberFormatsSupplier xNumberFormatsSupplier = - (com.sun.star.util.XNumberFormatsSupplier) UnoRuntime.queryInterface( - com.sun.star.util.XNumberFormatsSupplier.class, maSpreadsheetDoc ); + com.sun.star.util.XNumberFormatsSupplier.class, maSpreadsheetDoc ); // Get the number formats from the supplier com.sun.star.util.XNumberFormats xNumberFormats = @@ -96,9 +95,8 @@ public class Number_Formats // Query the XNumberFormatTypes interface com.sun.star.util.XNumberFormatTypes xNumberFormatTypes = - (com.sun.star.util.XNumberFormatTypes) UnoRuntime.queryInterface( - com.sun.star.util.XNumberFormatTypes.class, xNumberFormats ); + com.sun.star.util.XNumberFormatTypes.class, xNumberFormats ); // Get the number format index key of the default currency format, // note the empty locale for default locale @@ -112,9 +110,8 @@ public class Number_Formats // Query the property set of the cell range com.sun.star.beans.XPropertySet xCellProp = - (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, xCellRange ); + com.sun.star.beans.XPropertySet.class, xCellRange ); // Set number format to default currency xCellProp.setPropertyValue( "NumberFormat", new Integer(nCurrencyKey) ); @@ -123,9 +120,8 @@ public class Number_Formats com.sun.star.table.XCell xCell = maSheet.getCellByPosition( 1, 2 ); // Query the property set of the cell - xCellProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, xCell ); + xCellProp = UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xCell ); // Get the number format index key of the cell's properties int nIndexKey = ((Integer) xCellProp.getPropertyValue( "NumberFormat" )).intValue(); @@ -168,19 +164,16 @@ public class Number_Formats // Set column containing the example values to optimal width to show // the new format of cell B3 com.sun.star.table.XColumnRowRange xColRowRange = - (com.sun.star.table.XColumnRowRange) UnoRuntime.queryInterface(com.sun.star.table.XColumnRowRange.class, - maSheet); + maSheet); com.sun.star.container.XIndexAccess xIndexAccess = - (com.sun.star.container.XIndexAccess) UnoRuntime.queryInterface(com.sun.star.container.XIndexAccess.class, - xColRowRange.getColumns()); + xColRowRange.getColumns()); com.sun.star.beans.XPropertySet xColPropSet = - (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, - xIndexAccess.getByIndex(1)); + xIndexAccess.getByIndex(1)); xColPropSet.setPropertyValue( "OptimalWidth", new Boolean(true) ); } @@ -196,11 +189,11 @@ public class Number_Formats maServiceManager = maOfficeContext.getServiceManager(); // create a new spreadsheet document - XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface( + XComponentLoader aLoader = UnoRuntime.queryInterface( XComponentLoader.class, maServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", maOfficeContext) ); - maSpreadsheetDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( + maSpreadsheetDoc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, aLoader.loadComponentFromURL( "private:factory/scalc", "_blank", @@ -231,14 +224,14 @@ public class Number_Formats XSpreadsheets aSheets = maSpreadsheetDoc.getSheets(); try { - XIndexAccess aSheetsIA = (XIndexAccess) UnoRuntime.queryInterface( XIndexAccess.class, aSheets ); - maSheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, aSheetsIA.getByIndex( 0 )); + XIndexAccess aSheetsIA = UnoRuntime.queryInterface( XIndexAccess.class, aSheets ); + maSheet = UnoRuntime.queryInterface(XSpreadsheet.class, aSheetsIA.getByIndex( 0 )); // enter some values in B3:B11 for( int iCounter=1; iCounter < 10; iCounter++ ) { XCell aCell = maSheet.getCellByPosition( 1, 1 + iCounter ); - aCell.setValue( (double) iCounter ); + aCell.setValue( iCounter ); } } catch( Exception ex ) diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java index 34858994f369..5fff201ef552 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java +++ b/odk/examples/DevelopersGuide/OfficeDev/PathSettings/PathSettingsTest.java @@ -92,7 +92,7 @@ public class PathSettingsTest extends java.lang.Object { Object pathSubst = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.comp.framework.PathSettings", xRemoteContext ); - xPathSettingsService = (XPropertySet)UnoRuntime.queryInterface( + xPathSettingsService = UnoRuntime.queryInterface( XPropertySet.class, pathSubst); /* Work with path settings */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java index e878b479813a..f326a55a133e 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java +++ b/odk/examples/DevelopersGuide/OfficeDev/PathSubstitution/PathSubstitutionTest.java @@ -66,7 +66,7 @@ public class PathSubstitutionTest extends java.lang.Object { Object pathSubst = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.comp.framework.PathSubstitution", xRemoteContext ); - xPathSubstService = (XStringSubstitution)UnoRuntime.queryInterface( + xPathSubstService = UnoRuntime.queryInterface( XStringSubstitution.class, pathSubst); /* Work with path variables */ diff --git a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java index 7ee55ab85bd4..a01fb242c9de 100644 --- a/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java +++ b/odk/examples/DevelopersGuide/OfficeDev/TerminationTest/TerminationTest.java @@ -58,7 +58,7 @@ public class TerminationTest extends java.lang.Object { Object desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); - xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, desktop); + xDesktop = UnoRuntime.queryInterface(XDesktop.class, desktop); TerminateListener terminateListener = new TerminateListener(); xDesktop.addTerminateListener(terminateListener); diff --git a/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/ConnectionAwareClient.java b/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/ConnectionAwareClient.java index a7bb8a29f24c..e50e1fde75b6 100644 --- a/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/ConnectionAwareClient.java +++ b/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/ConnectionAwareClient.java @@ -165,8 +165,7 @@ public class ConnectionAwareClient extends java.awt.Frame Object x = _ctx.getServiceManager().createInstanceWithContext( "com.sun.star.connection.Connector", _ctx ); - XConnector xConnector = (XConnector ) - UnoRuntime.queryInterface(XConnector.class, x); + XConnector xConnector = UnoRuntime.queryInterface(XConnector.class, x); String a[] = parseUnoUrl( _url ); if( null == a ) @@ -180,7 +179,7 @@ public class ConnectionAwareClient extends java.awt.Frame x = _ctx.getServiceManager().createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", _ctx ); - XBridgeFactory xBridgeFactory = (XBridgeFactory) UnoRuntime.queryInterface( + XBridgeFactory xBridgeFactory = UnoRuntime.queryInterface( XBridgeFactory.class , x ); // create a nameless bridge with no instance provider @@ -188,7 +187,7 @@ public class ConnectionAwareClient extends java.awt.Frame XBridge bridge = xBridgeFactory.createBridge( "" , a[1] , connection , null ); // query for the XComponent interface and add this as event listener - XComponent xComponent = (XComponent) UnoRuntime.queryInterface( + XComponent xComponent = UnoRuntime.queryInterface( XComponent.class, bridge ); xComponent.addEventListener( this ); @@ -203,13 +202,11 @@ public class ConnectionAwareClient extends java.awt.Frame } // Query the initial object for its main factory interface - XMultiComponentFactory xOfficeMultiComponentFactory = ( XMultiComponentFactory ) - UnoRuntime.queryInterface( XMultiComponentFactory.class, x ); + XMultiComponentFactory xOfficeMultiComponentFactory = UnoRuntime.queryInterface( XMultiComponentFactory.class, x ); // retrieve the component context (it's not yet exported from the office) // Query for the XPropertySet interface. - XPropertySet xProperySet = ( XPropertySet ) - UnoRuntime.queryInterface( XPropertySet.class, xOfficeMultiComponentFactory ); + XPropertySet xProperySet = UnoRuntime.queryInterface( XPropertySet.class, xOfficeMultiComponentFactory ); // Get the default context from the office server. Object oDefaultContext = @@ -217,8 +214,8 @@ public class ConnectionAwareClient extends java.awt.Frame // Query for the interface XComponentContext. XComponentContext xOfficeComponentContext = - ( XComponentContext ) UnoRuntime.queryInterface( - XComponentContext.class, oDefaultContext ); + UnoRuntime.queryInterface( + XComponentContext.class, oDefaultContext ); // now create the desktop service @@ -226,8 +223,7 @@ public class ConnectionAwareClient extends java.awt.Frame Object oDesktop = xOfficeMultiComponentFactory.createInstanceWithContext( "com.sun.star.frame.Desktop", xOfficeComponentContext ); - officeComponentLoader = ( XComponentLoader ) - UnoRuntime.queryInterface( XComponentLoader.class, oDesktop ); + officeComponentLoader = UnoRuntime.queryInterface( XComponentLoader.class, oDesktop ); if( officeComponentLoader == null ) { diff --git a/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/UrlResolver.java b/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/UrlResolver.java index aaa83d4bddca..0c07c7237227 100644 --- a/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/UrlResolver.java +++ b/odk/examples/DevelopersGuide/ProfUNO/InterprocessConn/UrlResolver.java @@ -65,7 +65,7 @@ class UrlResolver // query for the XUnoUrlResolver interface XUnoUrlResolver xUrlResolver = - (XUnoUrlResolver) UnoRuntime.queryInterface( XUnoUrlResolver.class, urlResolver ); + UnoRuntime.queryInterface( XUnoUrlResolver.class, urlResolver ); try { diff --git a/odk/examples/DevelopersGuide/ProfUNO/SimpleBootstrap_java/SimpleBootstrap_java.java b/odk/examples/DevelopersGuide/ProfUNO/SimpleBootstrap_java/SimpleBootstrap_java.java index 262653dfa564..8121e9c63391 100644 --- a/odk/examples/DevelopersGuide/ProfUNO/SimpleBootstrap_java/SimpleBootstrap_java.java +++ b/odk/examples/DevelopersGuide/ProfUNO/SimpleBootstrap_java/SimpleBootstrap_java.java @@ -57,8 +57,8 @@ public class SimpleBootstrap_java { // query the XComponentLoader interface from the desktop XComponentLoader xComponentLoader = - (XComponentLoader)UnoRuntime.queryInterface( - XComponentLoader.class, desktop ); + UnoRuntime.queryInterface( + XComponentLoader.class, desktop ); // load a spreadsheet document String loadURL = "private:factory/scalc"; diff --git a/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java index 11bc3bf6e1fa..5f2f7aac920b 100644 --- a/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java +++ b/odk/examples/DevelopersGuide/ScriptingFramework/SayHello/SayHello/SayHello.java @@ -49,15 +49,13 @@ public class SayHello private static XTextDocument createDocument(XScriptContext ctxt) throws Exception { - XComponentLoader loader = (XComponentLoader) - UnoRuntime.queryInterface( - XComponentLoader.class, ctxt.getDesktop()); + XComponentLoader loader = UnoRuntime.queryInterface( + XComponentLoader.class, ctxt.getDesktop()); XComponent comp = loader.loadComponentFromURL( "private:factory/swriter", "_blank", 4, new PropertyValue[0]); - XTextDocument doc = (XTextDocument) - UnoRuntime.queryInterface( XTextDocument.class, comp); + XTextDocument doc = UnoRuntime.queryInterface( XTextDocument.class, comp); return doc; } diff --git a/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/ScriptSelector/ScriptSelector.java b/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/ScriptSelector/ScriptSelector.java index 5cbd401c941b..7382a7d42762 100644 --- a/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/ScriptSelector/ScriptSelector.java +++ b/odk/examples/DevelopersGuide/ScriptingFramework/ScriptSelector/ScriptSelector/ScriptSelector.java @@ -64,8 +64,7 @@ public class ScriptSelector { Object obj = ctxt.getComponentContext().getValueByName(MSP_FACTORY); - XScriptProviderFactory fac = (XScriptProviderFactory) - UnoRuntime.queryInterface(XScriptProviderFactory.class, obj); + XScriptProviderFactory fac = UnoRuntime.queryInterface(XScriptProviderFactory.class, obj); final XScriptProvider msp = fac.createScriptProvider(new Any(new Type(), null)); @@ -94,8 +93,7 @@ public class ScriptSelector { new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { XBrowseNode xbn = selectorPanel.getSelection(); - XPropertySet props = (XPropertySet) - UnoRuntime.queryInterface(XPropertySet.class, xbn); + XPropertySet props = UnoRuntime.queryInterface(XPropertySet.class, xbn); if (xbn != null && xbn.getType() == BrowseNodeTypes.SCRIPT) @@ -219,11 +217,10 @@ public class ScriptSelector { XBrowseNode result = null; XComponentContext xcc = ctxt.getComponentContext(); - XBrowseNodeFactory xBrowseFac = (XBrowseNodeFactory) - UnoRuntime.queryInterface( - XBrowseNodeFactory.class, xcc.getValueByName(BROWSE_FACTORY)); + XBrowseNodeFactory xBrowseFac = UnoRuntime.queryInterface( + XBrowseNodeFactory.class, xcc.getValueByName(BROWSE_FACTORY)); - result = (XBrowseNode)UnoRuntime.queryInterface( + result = UnoRuntime.queryInterface( XBrowseNode.class, xBrowseFac.createView( BrowseNodeFactoryViewTypes.MACROSELECTOR ) ); @@ -276,7 +273,7 @@ class ScriptSelectorPanel extends JPanel { tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { XBrowseNode xbn = getSelection(); - XPropertySet props = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet props = UnoRuntime.queryInterface( XPropertySet.class, xbn); if (xbn == null) { diff --git a/odk/examples/DevelopersGuide/Spreadsheet/ExampleDataPilotSource.java b/odk/examples/DevelopersGuide/Spreadsheet/ExampleDataPilotSource.java index b7299d16595b..c94f2056d656 100644 --- a/odk/examples/DevelopersGuide/Spreadsheet/ExampleDataPilotSource.java +++ b/odk/examples/DevelopersGuide/Spreadsheet/ExampleDataPilotSource.java @@ -577,10 +577,10 @@ class ExampleDimension implements return new ExamplePropertySetInfo( new com.sun.star.beans.Property[] { new com.sun.star.beans.Property( "Original", -1, new com.sun.star.uno.Type( com.sun.star.container.XNamed.class), - (short) com.sun.star.beans.PropertyAttribute.READONLY ), + com.sun.star.beans.PropertyAttribute.READONLY ), new com.sun.star.beans.Property( "IsDataLayoutDimension", -1, new com.sun.star.uno.Type( Boolean.class), - (short) com.sun.star.beans.PropertyAttribute.READONLY ), + com.sun.star.beans.PropertyAttribute.READONLY ), new com.sun.star.beans.Property( "Orientation", -1, new com.sun.star.uno.Type( com.sun.star.sheet.DataPilotFieldOrientation.class), (short) 0), diff --git a/odk/examples/DevelopersGuide/Spreadsheet/GeneralTableSample.java b/odk/examples/DevelopersGuide/Spreadsheet/GeneralTableSample.java index 30bd5c143aa1..4b1682af2c7e 100644 --- a/odk/examples/DevelopersGuide/Spreadsheet/GeneralTableSample.java +++ b/odk/examples/DevelopersGuide/Spreadsheet/GeneralTableSample.java @@ -99,15 +99,13 @@ public class GeneralTableSample extends SpreadsheetDocHelper // *** Insert a TEXT CELL using the XText interface *** xCell = xSheet.getCellByPosition( 0, 3 ); - com.sun.star.text.XText xCellText = (com.sun.star.text.XText) - UnoRuntime.queryInterface( com.sun.star.text.XText.class, xCell ); + com.sun.star.text.XText xCellText = UnoRuntime.queryInterface( com.sun.star.text.XText.class, xCell ); com.sun.star.text.XTextCursor xTextCursor = xCellText.createTextCursor(); xCellText.insertString( xTextCursor, aText, false ); // *** Change cell properties *** int nValue = bValid ? 0x00FF00 : 0xFF4040; - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); xPropSet.setPropertyValue( "CellBackColor", new Integer( nValue ) ); @@ -118,16 +116,14 @@ public class GeneralTableSample extends SpreadsheetDocHelper xCellRange = xSheet.getCellRangeByPosition( 2, 0, 3, 1 ); // Change properties of the range. - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); xPropSet.setPropertyValue( "CellBackColor", new Integer( 0x8080FF ) ); // Accessing a cell range over its name. xCellRange = xSheet.getCellRangeByName( "C4:D5" ); // Change properties of the range. - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); xPropSet.setPropertyValue( "CellBackColor", new Integer( 0xFFFF80 ) ); @@ -136,13 +132,11 @@ public class GeneralTableSample extends SpreadsheetDocHelper // Create a cursor using the XSpreadsheet method createCursorByRange() xCellRange = xSheet.getCellRangeByName( "A1" ); - com.sun.star.sheet.XSheetCellRange xSheetCellRange = (com.sun.star.sheet.XSheetCellRange) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCellRange.class, xCellRange ); + com.sun.star.sheet.XSheetCellRange xSheetCellRange = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCellRange.class, xCellRange ); com.sun.star.sheet.XSheetCellCursor xSheetCellCursor = xSheet.createCursorByRange( xSheetCellRange ); - com.sun.star.table.XCellCursor xCursor = (com.sun.star.table.XCellCursor) - UnoRuntime.queryInterface( com.sun.star.table.XCellCursor.class, xSheetCellCursor ); + com.sun.star.table.XCellCursor xCursor = UnoRuntime.queryInterface( com.sun.star.table.XCellCursor.class, xSheetCellCursor ); // Move to the last filled cell. xCursor.gotoEnd(); @@ -154,36 +148,30 @@ public class GeneralTableSample extends SpreadsheetDocHelper // *** Modifying COLUMNS and ROWS *** System.out.println( "*** Sample for services table.TableRows and table.TableColumns ***" ); - com.sun.star.table.XColumnRowRange xCRRange = (com.sun.star.table.XColumnRowRange) - UnoRuntime.queryInterface( com.sun.star.table.XColumnRowRange.class, xSheet ); + com.sun.star.table.XColumnRowRange xCRRange = UnoRuntime.queryInterface( com.sun.star.table.XColumnRowRange.class, xSheet ); com.sun.star.table.XTableColumns xColumns = xCRRange.getColumns(); com.sun.star.table.XTableRows xRows = xCRRange.getRows(); // Get column C by index (interface XIndexAccess). Object aColumnObj = xColumns.getByIndex( 2 ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aColumnObj ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aColumnObj ); xPropSet.setPropertyValue( "Width", new Integer( 5000 ) ); // Get the name of the column. - com.sun.star.container.XNamed xNamed = (com.sun.star.container.XNamed) - UnoRuntime.queryInterface( com.sun.star.container.XNamed.class, aColumnObj ); + com.sun.star.container.XNamed xNamed = UnoRuntime.queryInterface( com.sun.star.container.XNamed.class, aColumnObj ); aText = "The name of this column is " + xNamed.getName() + "."; xSheet.getCellByPosition( 2, 2 ).setFormula( aText ); // Get column D by name (interface XNameAccess). - com.sun.star.container.XNameAccess xColumnsName = (com.sun.star.container.XNameAccess) - UnoRuntime.queryInterface( com.sun.star.container.XNameAccess.class, xColumns ); + com.sun.star.container.XNameAccess xColumnsName = UnoRuntime.queryInterface( com.sun.star.container.XNameAccess.class, xColumns ); aColumnObj = xColumnsName.getByName( "D" ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aColumnObj ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aColumnObj ); xPropSet.setPropertyValue( "IsVisible", new Boolean( false ) ); // Get row 7 by index (interface XIndexAccess) Object aRowObj = xRows.getByIndex( 6 ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aRowObj ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aRowObj ); xPropSet.setPropertyValue( "Height", new Integer( 5000 ) ); xSheet.getCellByPosition( 2, 6 ).setFormula( "What a big cell." ); @@ -200,8 +188,8 @@ public class GeneralTableSample extends SpreadsheetDocHelper System.out.println( "*** Sample for service table.TableCharts ***" ); com.sun.star.table.XTableChartsSupplier xChartsSupp = - (com.sun.star.table.XTableChartsSupplier) UnoRuntime.queryInterface( - com.sun.star.table.XTableChartsSupplier.class, xSheet ); + UnoRuntime.queryInterface( + com.sun.star.table.XTableChartsSupplier.class, xSheet ); com.sun.star.table.XTableCharts xCharts = xChartsSupp.getCharts(); // The chart will base on the last cell series, initializing all values. @@ -218,8 +206,7 @@ public class GeneralTableSample extends SpreadsheetDocHelper // Get the chart by name. Object aChartObj = xCharts.getByName( aName ); - com.sun.star.table.XTableChart xChart = (com.sun.star.table.XTableChart) - UnoRuntime.queryInterface( com.sun.star.table.XTableChart.class, aChartObj ); + com.sun.star.table.XTableChart xChart = UnoRuntime.queryInterface( com.sun.star.table.XTableChart.class, aChartObj ); // Query the state of row and column headers. aText = "Chart has column headers: "; diff --git a/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetDocHelper.java b/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetDocHelper.java index d130ccfaf66c..58dbf4873d64 100644 --- a/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetDocHelper.java +++ b/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetDocHelper.java @@ -112,9 +112,9 @@ public class SpreadsheetDocHelper try { com.sun.star.container.XIndexAccess xSheetsIA = - (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface( - com.sun.star.container.XIndexAccess.class, xSheets ); - xSheet = (com.sun.star.sheet.XSpreadsheet) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( + com.sun.star.container.XIndexAccess.class, xSheets ); + xSheet = UnoRuntime.queryInterface( com.sun.star.sheet.XSpreadsheet.class, xSheetsIA.getByIndex(nIndex)); } catch (Exception ex) @@ -139,9 +139,8 @@ public class SpreadsheetDocHelper try { xSheets.insertNewByName( aName, nIndex ); - xSheet = (com.sun.star.sheet.XSpreadsheet) - UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, - xSheets.getByName( aName )); + xSheet = UnoRuntime.queryInterface(com.sun.star.sheet.XSpreadsheet.class, + xSheets.getByName( aName )); } catch (Exception ex) { @@ -197,16 +196,15 @@ public class SpreadsheetDocHelper // Set standard date format. com.sun.star.util.XNumberFormatsSupplier xFormatsSupplier = - (com.sun.star.util.XNumberFormatsSupplier) UnoRuntime.queryInterface( - com.sun.star.util.XNumberFormatsSupplier.class, getDocument() ); + UnoRuntime.queryInterface( + com.sun.star.util.XNumberFormatsSupplier.class, getDocument() ); com.sun.star.util.XNumberFormatTypes xFormatTypes = - (com.sun.star.util.XNumberFormatTypes) UnoRuntime.queryInterface( - com.sun.star.util.XNumberFormatTypes.class, xFormatsSupplier.getNumberFormats() ); + UnoRuntime.queryInterface( + com.sun.star.util.XNumberFormatTypes.class, xFormatsSupplier.getNumberFormats() ); int nFormat = xFormatTypes.getStandardFormat( com.sun.star.util.NumberFormat.DATE, new com.sun.star.lang.Locale() ); - com.sun.star.beans.XPropertySet xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); + com.sun.star.beans.XPropertySet xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); xPropSet.setPropertyValue( "NumberFormat", new Integer( nFormat ) ); } @@ -224,8 +222,7 @@ public class SpreadsheetDocHelper // draw border xCellRange = xSheet.getCellRangeByName( aRange ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); com.sun.star.table.BorderLine aLine = new com.sun.star.table.BorderLine(); aLine.Color = 0x99CCFF; aLine.InnerLineWidth = aLine.LineDistance = 0; @@ -237,20 +234,17 @@ public class SpreadsheetDocHelper xPropSet.setPropertyValue( "TableBorder", aBorder ); // draw headline - com.sun.star.sheet.XCellRangeAddressable xAddr = (com.sun.star.sheet.XCellRangeAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); + com.sun.star.sheet.XCellRangeAddressable xAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); com.sun.star.table.CellRangeAddress aAddr = xAddr.getRangeAddress(); xCellRange = xSheet.getCellRangeByPosition( aAddr.StartColumn, aAddr.StartRow, aAddr.EndColumn, aAddr.StartRow ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); xPropSet.setPropertyValue( "CellBackColor", new Integer( 0x99CCFF ) ); // write headline com.sun.star.table.XCell xCell = xCellRange.getCellByPosition( 0, 0 ); xCell.setFormula( aHeadline ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); xPropSet.setPropertyValue( "CharColor", new Integer( 0x003399 ) ); xPropSet.setPropertyValue( "CharWeight", new Float( com.sun.star.awt.FontWeight.BOLD ) ); } @@ -266,9 +260,8 @@ public class SpreadsheetDocHelper com.sun.star.sheet.XSpreadsheet xSheet, String aCell ) throws RuntimeException, Exception { - com.sun.star.sheet.XCellAddressable xAddr = (com.sun.star.sheet.XCellAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellAddressable.class, - xSheet.getCellRangeByName( aCell ).getCellByPosition( 0, 0 ) ); + com.sun.star.sheet.XCellAddressable xAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellAddressable.class, + xSheet.getCellRangeByName( aCell ).getCellByPosition( 0, 0 ) ); return xAddr.getCellAddress(); } @@ -279,9 +272,8 @@ public class SpreadsheetDocHelper public com.sun.star.table.CellRangeAddress createCellRangeAddress( com.sun.star.sheet.XSpreadsheet xSheet, String aRange ) { - com.sun.star.sheet.XCellRangeAddressable xAddr = (com.sun.star.sheet.XCellRangeAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, - xSheet.getCellRangeByName( aRange ) ); + com.sun.star.sheet.XCellRangeAddressable xAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, + xSheet.getCellRangeByName( aRange ) ); return xAddr.getRangeAddress(); } @@ -326,12 +318,10 @@ public class SpreadsheetDocHelper if (bWithSheet) { com.sun.star.sheet.XSpreadsheet xSheet = xCellRange.getSpreadsheet(); - com.sun.star.container.XNamed xNamed = (com.sun.star.container.XNamed) - UnoRuntime.queryInterface( com.sun.star.container.XNamed.class, xSheet ); + com.sun.star.container.XNamed xNamed = UnoRuntime.queryInterface( com.sun.star.container.XNamed.class, xSheet ); aStr += xNamed.getName() + "."; } - com.sun.star.sheet.XCellRangeAddressable xAddr = (com.sun.star.sheet.XCellRangeAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); + com.sun.star.sheet.XCellRangeAddressable xAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); aStr += getCellRangeAddressString( xAddr.getRangeAddress() ); return aStr; } @@ -349,8 +339,7 @@ public class SpreadsheetDocHelper if (nIndex > 0) aStr += " "; Object aRangeObj = xRangesIA.getByIndex( nIndex ); - com.sun.star.sheet.XSheetCellRange xCellRange = (com.sun.star.sheet.XSheetCellRange) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCellRange.class, aRangeObj ); + com.sun.star.sheet.XSheetCellRange xCellRange = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCellRange.class, aRangeObj ); aStr += getCellRangeAddressString( xCellRange, false ); } return aStr; @@ -382,17 +371,16 @@ public class SpreadsheetDocHelper private com.sun.star.sheet.XSpreadsheetDocument initDocument() throws RuntimeException, Exception { - XComponentLoader aLoader = (XComponentLoader) - UnoRuntime.queryInterface( - XComponentLoader.class, - mxRemoteServiceManager.createInstanceWithContext( - "com.sun.star.frame.Desktop", mxRemoteContext)); + XComponentLoader aLoader = UnoRuntime.queryInterface( + XComponentLoader.class, + mxRemoteServiceManager.createInstanceWithContext( + "com.sun.star.frame.Desktop", mxRemoteContext)); XComponent xComponent = aLoader.loadComponentFromURL( "private:factory/scalc", "_blank", 0, new com.sun.star.beans.PropertyValue[0] ); - return (com.sun.star.sheet.XSpreadsheetDocument)UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( com.sun.star.sheet.XSpreadsheetDocument.class, xComponent ); } diff --git a/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java b/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java index fcae70c91ec4..b818e76a60b9 100644 --- a/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java +++ b/odk/examples/DevelopersGuide/Spreadsheet/SpreadsheetSample.java @@ -214,8 +214,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Insert two text paragraphs into the cell. --- - com.sun.star.text.XText xText = (com.sun.star.text.XText) - UnoRuntime.queryInterface( com.sun.star.text.XText.class, xCell ); + com.sun.star.text.XText xText = UnoRuntime.queryInterface( com.sun.star.text.XText.class, xCell ); com.sun.star.text.XTextCursor xTextCursor = xText.createTextCursor(); xText.insertString( xTextCursor, "Text in first line.", false ); @@ -224,40 +223,36 @@ public class SpreadsheetSample extends SpreadsheetDocHelper xText.insertString( xTextCursor, "And a ", false ); // create a hyperlink - com.sun.star.lang.XMultiServiceFactory xServiceMan = (com.sun.star.lang.XMultiServiceFactory) - UnoRuntime.queryInterface( com.sun.star.lang.XMultiServiceFactory.class, getDocument() ); + com.sun.star.lang.XMultiServiceFactory xServiceMan = UnoRuntime.queryInterface( com.sun.star.lang.XMultiServiceFactory.class, getDocument() ); Object aHyperlinkObj = xServiceMan.createInstance( "com.sun.star.text.TextField.URL" ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aHyperlinkObj ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aHyperlinkObj ); xPropSet.setPropertyValue( "URL", "http://www.example.org" ); xPropSet.setPropertyValue( "Representation", "hyperlink" ); // ... and insert - com.sun.star.text.XTextContent xContent = (com.sun.star.text.XTextContent) - UnoRuntime.queryInterface( com.sun.star.text.XTextContent.class, aHyperlinkObj ); + com.sun.star.text.XTextContent xContent = UnoRuntime.queryInterface( com.sun.star.text.XTextContent.class, aHyperlinkObj ); xText.insertTextContent( xTextCursor, xContent, false ); // --- Query the separate paragraphs. --- com.sun.star.container.XEnumerationAccess xParaEA = - (com.sun.star.container.XEnumerationAccess) UnoRuntime.queryInterface( - com.sun.star.container.XEnumerationAccess.class, xCell ); + UnoRuntime.queryInterface( + com.sun.star.container.XEnumerationAccess.class, xCell ); com.sun.star.container.XEnumeration xParaEnum = xParaEA.createEnumeration(); // Go through the paragraphs while( xParaEnum.hasMoreElements() ) { Object aPortionObj = xParaEnum.nextElement(); com.sun.star.container.XEnumerationAccess xPortionEA = - (com.sun.star.container.XEnumerationAccess) UnoRuntime.queryInterface( - com.sun.star.container.XEnumerationAccess.class, aPortionObj ); + UnoRuntime.queryInterface( + com.sun.star.container.XEnumerationAccess.class, aPortionObj ); com.sun.star.container.XEnumeration xPortionEnum = xPortionEA.createEnumeration(); aText = ""; // Go through all text portions of a paragraph and construct string. Object nextElement; while( xPortionEnum.hasMoreElements() ) { - com.sun.star.text.XTextRange xRange = (com.sun.star.text.XTextRange) - UnoRuntime.queryInterface(com.sun.star.text.XTextRange.class, - xPortionEnum.nextElement()); + com.sun.star.text.XTextRange xRange = UnoRuntime.queryInterface(com.sun.star.text.XTextRange.class, + xPortionEnum.nextElement()); aText += xRange.getString(); } System.out.println( "Paragraph text: " + aText ); @@ -265,8 +260,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Change cell properties. --- - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCell ); // from styles.CharacterProperties xPropSet.setPropertyValue( "CharColor", new Integer( 0x003399 ) ); xPropSet.setPropertyValue( "CharHeight", new Float( 20.0 ) ); @@ -278,8 +272,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Get cell address. --- - com.sun.star.sheet.XCellAddressable xCellAddr = (com.sun.star.sheet.XCellAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellAddressable.class, xCell ); + com.sun.star.sheet.XCellAddressable xCellAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellAddressable.class, xCell ); com.sun.star.table.CellAddress aAddress = xCellAddr.getCellAddress(); aText = "Address of this cell: Column=" + aAddress.Column; aText += "; Row=" + aAddress.Row; @@ -289,13 +282,12 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Insert an annotation --- com.sun.star.sheet.XSheetAnnotationsSupplier xAnnotationsSupp = - (com.sun.star.sheet.XSheetAnnotationsSupplier) UnoRuntime.queryInterface( - com.sun.star.sheet.XSheetAnnotationsSupplier.class, xSheet ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XSheetAnnotationsSupplier.class, xSheet ); com.sun.star.sheet.XSheetAnnotations xAnnotations = xAnnotationsSupp.getAnnotations(); xAnnotations.insertNew( aAddress, "This is an annotation" ); - com.sun.star.sheet.XSheetAnnotationAnchor xAnnotAnchor = (com.sun.star.sheet.XSheetAnnotationAnchor) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetAnnotationAnchor.class, xCell ); + com.sun.star.sheet.XSheetAnnotationAnchor xAnnotAnchor = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetAnnotationAnchor.class, xCell ); com.sun.star.sheet.XSheetAnnotation xAnnotation = xAnnotAnchor.getAnnotation(); xAnnotation.setIsVisible( true ); } @@ -320,8 +312,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Change cell range properties. --- - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); // from com.sun.star.styles.CharacterProperties xPropSet.setPropertyValue( "CharColor", new Integer( 0x003399 ) ); xPropSet.setPropertyValue( "CharHeight", new Float( 20.0 ) ); @@ -333,8 +324,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Replace text in all cells. --- - com.sun.star.util.XReplaceable xReplace = (com.sun.star.util.XReplaceable) - UnoRuntime.queryInterface( com.sun.star.util.XReplaceable.class, xCellRange ); + com.sun.star.util.XReplaceable xReplace = UnoRuntime.queryInterface( com.sun.star.util.XReplaceable.class, xCellRange ); com.sun.star.util.XReplaceDescriptor xReplaceDesc = xReplace.createReplaceDescriptor(); xReplaceDesc.setSearchString( "cell" ); xReplaceDesc.setReplaceString( "text" ); @@ -347,8 +337,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Merge cells. --- xCellRange = xSheet.getCellRangeByName( "F3:G6" ); prepareRange( xSheet, "E1:H7", "XMergeable" ); - com.sun.star.util.XMergeable xMerge = (com.sun.star.util.XMergeable) - UnoRuntime.queryInterface( com.sun.star.util.XMergeable.class, xCellRange ); + com.sun.star.util.XMergeable xMerge = UnoRuntime.queryInterface( com.sun.star.util.XMergeable.class, xCellRange ); xMerge.merge( true ); @@ -373,17 +362,15 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Column properties. --- xCellRange = xSheet.getCellRangeByName( "B1" ); - com.sun.star.table.XColumnRowRange xColRowRange = (com.sun.star.table.XColumnRowRange) - UnoRuntime.queryInterface( com.sun.star.table.XColumnRowRange.class, xCellRange ); + com.sun.star.table.XColumnRowRange xColRowRange = UnoRuntime.queryInterface( com.sun.star.table.XColumnRowRange.class, xCellRange ); com.sun.star.table.XTableColumns xColumns = xColRowRange.getColumns(); Object aColumnObj = xColumns.getByIndex( 0 ); - xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aColumnObj ); xPropSet.setPropertyValue( "Width", new Integer( 6000 ) ); - com.sun.star.container.XNamed xNamed = (com.sun.star.container.XNamed) - UnoRuntime.queryInterface( com.sun.star.container.XNamed.class, aColumnObj ); + com.sun.star.container.XNamed xNamed = UnoRuntime.queryInterface( com.sun.star.container.XNamed.class, aColumnObj ); System.out.println( "The name of the wide column is " + xNamed.getName() + "." ); @@ -391,8 +378,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper prepareRange( xSheet, "A9:C30", "XCellRangeData" ); xCellRange = xSheet.getCellRangeByName( "A10:C30" ); - com.sun.star.sheet.XCellRangeData xData = (com.sun.star.sheet.XCellRangeData) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xCellRange ); + com.sun.star.sheet.XCellRangeData xData = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xCellRange ); Object[][] aValues = { { "Name", "Fruit", "Quantity" }, @@ -421,8 +407,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Get cell range address. --- - com.sun.star.sheet.XCellRangeAddressable xRangeAddr = (com.sun.star.sheet.XCellRangeAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); + com.sun.star.sheet.XCellRangeAddressable xRangeAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); aRangeAddress = xRangeAddr.getRangeAddress(); System.out.println( "Address of this range: Sheet=" + aRangeAddress.Sheet ); System.out.println( "Start column=" + aRangeAddress.StartColumn + "; Start row=" + aRangeAddress.StartRow ); @@ -431,8 +416,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Sheet operation. --- // uses the range filled with XCellRangeData - com.sun.star.sheet.XSheetOperation xSheetOp = (com.sun.star.sheet.XSheetOperation) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetOperation.class, xData ); + com.sun.star.sheet.XSheetOperation xSheetOp = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetOperation.class, xData ); double fResult = xSheetOp.computeFunction( com.sun.star.sheet.GeneralFunction.AVERAGE ); System.out.println( "Average value of the data table A10:C30: " + fResult ); @@ -483,8 +467,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Array formulas --- xCellRange = xSheet.getCellRangeByName( "E21:G23" ); prepareRange( xSheet, "E20:G23", "XArrayFormulaRange" ); - com.sun.star.sheet.XArrayFormulaRange xArrayFormula = (com.sun.star.sheet.XArrayFormulaRange) - UnoRuntime.queryInterface( com.sun.star.sheet.XArrayFormulaRange.class, xCellRange ); + com.sun.star.sheet.XArrayFormulaRange xArrayFormula = UnoRuntime.queryInterface( com.sun.star.sheet.XArrayFormulaRange.class, xCellRange ); // Insert a 3x3 unit matrix. xArrayFormula.setArrayFormula( "=A10:C12" ); System.out.println( "Array formula is: " + xArrayFormula.getArrayFormula() ); @@ -509,8 +492,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper com.sun.star.table.CellAddress aRowCell = createCellAddress( xSheet, "F26" ); xCellRange = xSheet.getCellRangeByName( "E26:J31" ); - com.sun.star.sheet.XMultipleOperation xMultOp = (com.sun.star.sheet.XMultipleOperation) - UnoRuntime.queryInterface( com.sun.star.sheet.XMultipleOperation.class, xCellRange ); + com.sun.star.sheet.XMultipleOperation xMultOp = UnoRuntime.queryInterface( com.sun.star.sheet.XMultipleOperation.class, xCellRange ); xMultOp.setTableOperation( aFormulaRange, com.sun.star.sheet.TableOperationMode.BOTH, aColCell, aRowCell ); @@ -519,16 +501,14 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // Row cell not needed xCellRange = xSheet.getCellRangeByName( "E34:H38" ); - xMultOp = (com.sun.star.sheet.XMultipleOperation) - UnoRuntime.queryInterface( com.sun.star.sheet.XMultipleOperation.class, xCellRange ); + xMultOp = UnoRuntime.queryInterface( com.sun.star.sheet.XMultipleOperation.class, xCellRange ); xMultOp.setTableOperation( aFormulaRange, com.sun.star.sheet.TableOperationMode.COLUMN, aColCell, aRowCell ); // --- Cell Ranges Query --- xCellRange = xSheet.getCellRangeByName( "A10:C30" ); - com.sun.star.sheet.XCellRangesQuery xRangesQuery = (com.sun.star.sheet.XCellRangesQuery) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangesQuery.class, xCellRange ); + com.sun.star.sheet.XCellRangesQuery xRangesQuery = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangesQuery.class, xCellRange ); com.sun.star.sheet.XSheetCellRanges xCellRanges = xRangesQuery.queryContentCells( (short)com.sun.star.sheet.CellFlags.STRING ); System.out.println( @@ -543,7 +523,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper private com.sun.star.sheet.XCellSeries getCellSeries( com.sun.star.sheet.XSpreadsheet xSheet, String aRange ) { - return (com.sun.star.sheet.XCellSeries) UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( com.sun.star.sheet.XCellSeries.class, xSheet.getCellRangeByName( aRange ) ); } @@ -556,12 +536,12 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // Create a new cell range container com.sun.star.lang.XMultiServiceFactory xDocFactory = - (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, getDocument() ); + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, getDocument() ); com.sun.star.sheet.XSheetCellRangeContainer xRangeCont = - (com.sun.star.sheet.XSheetCellRangeContainer) UnoRuntime.queryInterface( - com.sun.star.sheet.XSheetCellRangeContainer.class, - xDocFactory.createInstance( "com.sun.star.sheet.SheetCellRanges" ) ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XSheetCellRangeContainer.class, + xDocFactory.createInstance( "com.sun.star.sheet.SheetCellRanges" ) ); // --- Insert ranges --- @@ -577,8 +557,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper while( xEnum.hasMoreElements() ) { Object aCellObj = xEnum.nextElement(); - com.sun.star.sheet.XCellAddressable xAddr = (com.sun.star.sheet.XCellAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellAddressable.class, aCellObj ); + com.sun.star.sheet.XCellAddressable xAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellAddressable.class, aCellObj ); com.sun.star.table.CellAddress aAddr = xAddr.getCellAddress(); System.out.print( getCellAddressString( aAddr.Column, aAddr.Row ) + " " ); } @@ -623,21 +602,18 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Find the array formula using a cell cursor --- com.sun.star.table.XCellRange xRange = xSheet.getCellRangeByName( "F22" ); - com.sun.star.sheet.XSheetCellRange xCellRange = (com.sun.star.sheet.XSheetCellRange) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCellRange.class, xRange ); + com.sun.star.sheet.XSheetCellRange xCellRange = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCellRange.class, xRange ); com.sun.star.sheet.XSheetCellCursor xCursor = xSheet.createCursorByRange( xCellRange ); xCursor.collapseToCurrentArray(); - com.sun.star.sheet.XArrayFormulaRange xArray = (com.sun.star.sheet.XArrayFormulaRange) - UnoRuntime.queryInterface( com.sun.star.sheet.XArrayFormulaRange.class, xCursor ); + com.sun.star.sheet.XArrayFormulaRange xArray = UnoRuntime.queryInterface( com.sun.star.sheet.XArrayFormulaRange.class, xCursor ); System.out.println( "Array formula in " + getCellRangeAddressString( xCursor, false ) + " contains formula " + xArray.getArrayFormula() ); // --- Find the used area --- - com.sun.star.sheet.XUsedAreaCursor xUsedCursor = (com.sun.star.sheet.XUsedAreaCursor) - UnoRuntime.queryInterface( com.sun.star.sheet.XUsedAreaCursor.class, xCursor ); + com.sun.star.sheet.XUsedAreaCursor xUsedCursor = UnoRuntime.queryInterface( com.sun.star.sheet.XUsedAreaCursor.class, xCursor ); xUsedCursor.gotoStartOfUsedArea( false ); xUsedCursor.gotoEndOfUsedArea( true ); // xUsedCursor and xCursor are interfaces of the same object - @@ -660,23 +636,19 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Cell styles --- // get the cell style container - com.sun.star.style.XStyleFamiliesSupplier xFamiliesSupplier = (com.sun.star.style.XStyleFamiliesSupplier) - UnoRuntime.queryInterface( com.sun.star.style.XStyleFamiliesSupplier.class, getDocument() ); + com.sun.star.style.XStyleFamiliesSupplier xFamiliesSupplier = UnoRuntime.queryInterface( com.sun.star.style.XStyleFamiliesSupplier.class, getDocument() ); com.sun.star.container.XNameAccess xFamiliesNA = xFamiliesSupplier.getStyleFamilies(); Object aCellStylesObj = xFamiliesNA.getByName( "CellStyles" ); - com.sun.star.container.XNameContainer xCellStylesNA = (com.sun.star.container.XNameContainer) - UnoRuntime.queryInterface( com.sun.star.container.XNameContainer.class, aCellStylesObj ); + com.sun.star.container.XNameContainer xCellStylesNA = UnoRuntime.queryInterface( com.sun.star.container.XNameContainer.class, aCellStylesObj ); // create a new cell style - xDocServiceManager = (com.sun.star.lang.XMultiServiceFactory) - UnoRuntime.queryInterface( com.sun.star.lang.XMultiServiceFactory.class, getDocument() ); + xDocServiceManager = UnoRuntime.queryInterface( com.sun.star.lang.XMultiServiceFactory.class, getDocument() ); Object aCellStyle = xDocServiceManager.createInstance( "com.sun.star.style.CellStyle" ); String aStyleName = "MyNewCellStyle"; xCellStylesNA.insertByName( aStyleName, aCellStyle ); // modify properties of the new style - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aCellStyle ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aCellStyle ); xPropSet.setPropertyValue( "CellBackColor", new Integer( 0x888888 ) ); xPropSet.setPropertyValue( "IsCellBackgroundTransparent", new Boolean( false ) ); @@ -685,12 +657,12 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Query equal-formatted cell ranges --- // prepare example, use the new cell style xCellRange = xSheet.getCellRangeByName( "D2:F2" ); - xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); xPropSet.setPropertyValue( "CellStyle", aStyleName ); xCellRange = xSheet.getCellRangeByName( "A3:G3" ); - xPropSet = (com.sun.star.beans.XPropertySet) UnoRuntime.queryInterface( + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); xPropSet.setPropertyValue( "CellStyle", aStyleName ); @@ -698,22 +670,22 @@ public class SpreadsheetSample extends SpreadsheetDocHelper xCellRange = xSheet.getCellRangeByName( "A1:G3" ); System.out.println( "Service CellFormatRanges:" ); com.sun.star.sheet.XCellFormatRangesSupplier xFormatSupp = - (com.sun.star.sheet.XCellFormatRangesSupplier) UnoRuntime.queryInterface( - com.sun.star.sheet.XCellFormatRangesSupplier.class, xCellRange ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XCellFormatRangesSupplier.class, xCellRange ); xRangeIA = xFormatSupp.getCellFormatRanges(); System.out.println( getCellRangeListString( xRangeIA ) ); // Ranges sorted in SheetCellRanges containers System.out.println( "\nService UniqueCellFormatRanges:" ); com.sun.star.sheet.XUniqueCellFormatRangesSupplier xUniqueFormatSupp = - (com.sun.star.sheet.XUniqueCellFormatRangesSupplier) UnoRuntime.queryInterface( - com.sun.star.sheet.XUniqueCellFormatRangesSupplier.class, xCellRange ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XUniqueCellFormatRangesSupplier.class, xCellRange ); com.sun.star.container.XIndexAccess xRangesIA = xUniqueFormatSupp.getUniqueCellFormatRanges(); int nCount = xRangesIA.getCount(); for (int nIndex = 0; nIndex < nCount; ++nIndex) { Object aRangesObj = xRangesIA.getByIndex( nIndex ); - xRangeIA = (com.sun.star.container.XIndexAccess) UnoRuntime.queryInterface( + xRangeIA = UnoRuntime.queryInterface( com.sun.star.container.XIndexAccess.class, aRangesObj ); System.out.println( "Container " + (nIndex + 1) + ": " + getCellRangeListString( xRangeIA ) ); @@ -728,8 +700,8 @@ public class SpreadsheetSample extends SpreadsheetDocHelper Object aAutoFormatsObj = xServiceManager.createInstanceWithContext( "com.sun.star.sheet.TableAutoFormats", getContext()); com.sun.star.container.XNameContainer xAutoFormatsNA = - (com.sun.star.container.XNameContainer)UnoRuntime.queryInterface( - com.sun.star.container.XNameContainer.class, aAutoFormatsObj ); + UnoRuntime.queryInterface( + com.sun.star.container.XNameContainer.class, aAutoFormatsObj ); // create a new table auto format and insert into the container String aAutoFormatName = "Temp_Example"; @@ -749,8 +721,8 @@ public class SpreadsheetSample extends SpreadsheetDocHelper } // index access to the auto format fields com.sun.star.container.XIndexAccess xAutoFormatIA = - (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface( - com.sun.star.container.XIndexAccess.class, aAutoFormatObj ); + UnoRuntime.queryInterface( + com.sun.star.container.XIndexAccess.class, aAutoFormatObj ); // set properties of all auto format fields for (int nRow = 0; nRow < 4; ++nRow) @@ -772,17 +744,15 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // get the auto format field and apply properties Object aFieldObj = xAutoFormatIA.getByIndex( 4 * nRow + nColumn ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, aFieldObj ); + xPropSet = UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, aFieldObj ); xPropSet.setPropertyValue( "CellBackColor", new Integer( nColor ) ); } } // set the auto format to the spreadsheet xCellRange = xSheet.getCellRangeByName( "A5:H25" ); - com.sun.star.table.XAutoFormattable xAutoForm = (com.sun.star.table.XAutoFormattable) - UnoRuntime.queryInterface( com.sun.star.table.XAutoFormattable.class, xCellRange ); + com.sun.star.table.XAutoFormattable xAutoForm = UnoRuntime.queryInterface( com.sun.star.table.XAutoFormattable.class, xCellRange ); xAutoForm.autoFormat( aAutoFormatName ); // remove the auto format @@ -799,12 +769,11 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // get the conditional format object of the cell range xCellRange = xSheet.getCellRangeByName( "K21:K23" ); - xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); com.sun.star.sheet.XSheetConditionalEntries xEntries = - (com.sun.star.sheet.XSheetConditionalEntries) UnoRuntime.queryInterface( - com.sun.star.sheet.XSheetConditionalEntries.class, - xPropSet.getPropertyValue( "ConditionalFormat" )); + UnoRuntime.queryInterface( + com.sun.star.sheet.XSheetConditionalEntries.class, + xPropSet.getPropertyValue( "ConditionalFormat" )); // create a condition and apply it to the range com.sun.star.beans.PropertyValue[] aCondition = new com.sun.star.beans.PropertyValue[3]; @@ -841,16 +810,14 @@ public class SpreadsheetSample extends SpreadsheetDocHelper setFormula( xSheet, "A3", "=SUM(A2:B2)" ); setFormula( xSheet, "B3", "=FORMULA(A3)" ); - com.sun.star.sheet.XCellRangeMovement xMovement = (com.sun.star.sheet.XCellRangeMovement) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeMovement.class, xSheet ); + com.sun.star.sheet.XCellRangeMovement xMovement = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeMovement.class, xSheet ); com.sun.star.table.CellRangeAddress aSourceRange = createCellRangeAddress( xSheet, "A2:B3" ); com.sun.star.table.CellAddress aDestCell = createCellAddress( xSheet, "D2" ); xMovement.copyRange( aDestCell, aSourceRange ); // --- Print automatic column page breaks --- - com.sun.star.sheet.XSheetPageBreak xPageBreak = (com.sun.star.sheet.XSheetPageBreak) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetPageBreak.class, xSheet ); + com.sun.star.sheet.XSheetPageBreak xPageBreak = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetPageBreak.class, xSheet ); com.sun.star.sheet.TablePageBreakData[] aPageBreakArray = xPageBreak.getColumnPageBreaks(); System.out.print( "Automatic column page breaks:" ); @@ -861,8 +828,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Document properties --- - com.sun.star.beans.XPropertySet xPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, getDocument() ); + com.sun.star.beans.XPropertySet xPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, getDocument() ); AnyConverter aAnyConv = new AnyConverter(); String aText = "Value of property IsIterationEnabled: "; @@ -883,19 +849,16 @@ public class SpreadsheetSample extends SpreadsheetDocHelper setFormula( xSheet, "A6", "Insert values between 0.0 and 5.0 below:" ); com.sun.star.table.XCellRange xCellRange = xSheet.getCellRangeByName( "A7:C7" ); - com.sun.star.beans.XPropertySet xCellPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); + com.sun.star.beans.XPropertySet xCellPropSet = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xCellRange ); // validation properties - com.sun.star.beans.XPropertySet xValidPropSet = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, - xCellPropSet.getPropertyValue( "Validation" )); + com.sun.star.beans.XPropertySet xValidPropSet = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, + xCellPropSet.getPropertyValue( "Validation" )); xValidPropSet.setPropertyValue( "Type", com.sun.star.sheet.ValidationType.DECIMAL ); xValidPropSet.setPropertyValue( "ShowErrorMessage", new Boolean( true ) ); xValidPropSet.setPropertyValue( "ErrorMessage", "This is an invalid value!" ); xValidPropSet.setPropertyValue( "ErrorAlertStyle", com.sun.star.sheet.ValidationAlertStyle.STOP ); // condition - com.sun.star.sheet.XSheetCondition xCondition = (com.sun.star.sheet.XSheetCondition) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCondition.class, xValidPropSet ); + com.sun.star.sheet.XSheetCondition xCondition = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetCondition.class, xValidPropSet ); xCondition.setOperator( com.sun.star.sheet.ConditionOperator.BETWEEN ); xCondition.setFormula1( "0.0" ); xCondition.setFormula2( "5.0" ); @@ -945,20 +908,17 @@ public class SpreadsheetSample extends SpreadsheetDocHelper com.sun.star.table.XCellRange xCellRange = xSheet.getCellRangeByName( aRange ); // create the range address sequence - com.sun.star.sheet.XCellRangeAddressable xAddr = (com.sun.star.sheet.XCellRangeAddressable) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); + com.sun.star.sheet.XCellRangeAddressable xAddr = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeAddressable.class, xCellRange ); com.sun.star.table.CellRangeAddress[] aRangesSeq = new com.sun.star.table.CellRangeAddress[1]; aRangesSeq[0] = xAddr.getRangeAddress(); // create the scenario - com.sun.star.sheet.XScenariosSupplier xScenSupp = (com.sun.star.sheet.XScenariosSupplier) - UnoRuntime.queryInterface( com.sun.star.sheet.XScenariosSupplier.class, xSheet ); + com.sun.star.sheet.XScenariosSupplier xScenSupp = UnoRuntime.queryInterface( com.sun.star.sheet.XScenariosSupplier.class, xSheet ); com.sun.star.sheet.XScenarios xScenarios = xScenSupp.getScenarios(); xScenarios.addNewByName( aScenarioName, aRangesSeq, aScenarioComment ); // insert the values into the range - com.sun.star.sheet.XCellRangeData xData = (com.sun.star.sheet.XCellRangeData) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xCellRange ); + com.sun.star.sheet.XCellRangeData xData = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xCellRange ); xData.setDataArray( aValueArray ); } @@ -970,14 +930,12 @@ public class SpreadsheetSample extends SpreadsheetDocHelper String aScenarioName ) throws RuntimeException, Exception { // get the scenario set - com.sun.star.sheet.XScenariosSupplier xScenSupp = (com.sun.star.sheet.XScenariosSupplier) - UnoRuntime.queryInterface( com.sun.star.sheet.XScenariosSupplier.class, xSheet ); + com.sun.star.sheet.XScenariosSupplier xScenSupp = UnoRuntime.queryInterface( com.sun.star.sheet.XScenariosSupplier.class, xSheet ); com.sun.star.sheet.XScenarios xScenarios = xScenSupp.getScenarios(); // get the scenario and activate it Object aScenarioObj = xScenarios.getByName( aScenarioName ); - com.sun.star.sheet.XScenario xScenario = (com.sun.star.sheet.XScenario) - UnoRuntime.queryInterface( com.sun.star.sheet.XScenario.class, aScenarioObj ); + com.sun.star.sheet.XScenario xScenario = UnoRuntime.queryInterface( com.sun.star.sheet.XScenario.class, aScenarioObj ); xScenario.apply(); } @@ -998,11 +956,9 @@ public class SpreadsheetSample extends SpreadsheetDocHelper xSheet.getCellByPosition( 7, 43 ).setValue( 4 ); // insert a named range - com.sun.star.beans.XPropertySet xDocProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xDocument ); + com.sun.star.beans.XPropertySet xDocProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xDocument ); Object aRangesObj = xDocProp.getPropertyValue( "NamedRanges" ); - com.sun.star.sheet.XNamedRanges xNamedRanges = (com.sun.star.sheet.XNamedRanges) - UnoRuntime.queryInterface( com.sun.star.sheet.XNamedRanges.class, aRangesObj ); + com.sun.star.sheet.XNamedRanges xNamedRanges = UnoRuntime.queryInterface( com.sun.star.sheet.XNamedRanges.class, aRangesObj ); com.sun.star.table.CellAddress aRefPos = new com.sun.star.table.CellAddress(); aRefPos.Sheet = 0; aRefPos.Column = 6; @@ -1017,8 +973,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Label ranges --- prepareRange( xSheet, "G47:I50", "Label ranges" ); com.sun.star.table.XCellRange xRange = xSheet.getCellRangeByPosition( 6, 47, 7, 49 ); - com.sun.star.sheet.XCellRangeData xData = ( com.sun.star.sheet.XCellRangeData ) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xRange ); + com.sun.star.sheet.XCellRangeData xData = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xRange ); Object[][] aValues = { { "Apples", "Oranges" }, @@ -1029,8 +984,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // insert a column label range Object aLabelsObj = xDocProp.getPropertyValue( "ColumnLabelRanges" ); - com.sun.star.sheet.XLabelRanges xLabelRanges = (com.sun.star.sheet.XLabelRanges) - UnoRuntime.queryInterface( com.sun.star.sheet.XLabelRanges.class, aLabelsObj ); + com.sun.star.sheet.XLabelRanges xLabelRanges = UnoRuntime.queryInterface( com.sun.star.sheet.XLabelRanges.class, aLabelsObj ); com.sun.star.table.CellRangeAddress aLabelArea = new com.sun.star.table.CellRangeAddress(); aLabelArea.Sheet = 0; aLabelArea.StartColumn = 6; @@ -1060,10 +1014,10 @@ public class SpreadsheetSample extends SpreadsheetDocHelper { com.sun.star.lang.XMultiComponentFactory xServiceManager = getServiceManager(); com.sun.star.container.XNameAccess xContext = - (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface( - com.sun.star.container.XNameAccess.class, - xServiceManager.createInstanceWithContext( - "com.sun.star.sdb.DatabaseContext", getContext()) ); + UnoRuntime.queryInterface( + com.sun.star.container.XNameAccess.class, + xServiceManager.createInstanceWithContext( + "com.sun.star.sdb.DatabaseContext", getContext()) ); String[] aNames = xContext.getElementNames(); if ( aNames.length > 0 ) aDatabase = aNames[0]; @@ -1088,23 +1042,22 @@ public class SpreadsheetSample extends SpreadsheetDocHelper try { com.sun.star.lang.XMultiComponentFactory xServiceManager = getServiceManager(); - com.sun.star.container.XNameAccess xContext = (com.sun.star.container.XNameAccess) - UnoRuntime.queryInterface( com.sun.star.container.XNameAccess.class, - xServiceManager.createInstanceWithContext( - "com.sun.star.sdb.DatabaseContext", getContext()) ); + com.sun.star.container.XNameAccess xContext = UnoRuntime.queryInterface( com.sun.star.container.XNameAccess.class, + xServiceManager.createInstanceWithContext( + "com.sun.star.sdb.DatabaseContext", getContext()) ); com.sun.star.sdb.XCompletedConnection xSource = - (com.sun.star.sdb.XCompletedConnection)UnoRuntime.queryInterface( - com.sun.star.sdb.XCompletedConnection.class, - xContext.getByName( aDatabase ) ); + UnoRuntime.queryInterface( + com.sun.star.sdb.XCompletedConnection.class, + xContext.getByName( aDatabase ) ); com.sun.star.task.XInteractionHandler xHandler = - (com.sun.star.task.XInteractionHandler)UnoRuntime.queryInterface( - com.sun.star.task.XInteractionHandler.class, - xServiceManager.createInstanceWithContext( - "com.sun.star.task.InteractionHandler", getContext()) ); + UnoRuntime.queryInterface( + com.sun.star.task.XInteractionHandler.class, + xServiceManager.createInstanceWithContext( + "com.sun.star.task.InteractionHandler", getContext()) ); com.sun.star.sdbcx.XTablesSupplier xSupplier = - (com.sun.star.sdbcx.XTablesSupplier)UnoRuntime.queryInterface( - com.sun.star.sdbcx.XTablesSupplier.class, - xSource.connectWithCompletion( xHandler ) ); + UnoRuntime.queryInterface( + com.sun.star.sdbcx.XTablesSupplier.class, + xSource.connectWithCompletion( xHandler ) ); com.sun.star.container.XNameAccess xTables = xSupplier.getTables(); String[] aNames = xTables.getElementNames(); if ( aNames.length > 0 ) @@ -1128,8 +1081,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- put some example data into the sheet --- com.sun.star.table.XCellRange xRange = xSheet.getCellRangeByName( "B3:D24" ); - com.sun.star.sheet.XCellRangeData xData = ( com.sun.star.sheet.XCellRangeData ) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xRange ); + com.sun.star.sheet.XCellRangeData xData = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xRange ); Object[][] aValues = { { "Name", "Year", "Sales" }, @@ -1159,8 +1111,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- filter for second column >= 1998 --- - com.sun.star.sheet.XSheetFilterable xFilter = ( com.sun.star.sheet.XSheetFilterable ) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetFilterable.class, xRange ); + com.sun.star.sheet.XSheetFilterable xFilter = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetFilterable.class, xRange ); com.sun.star.sheet.XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor( true ); com.sun.star.sheet.TableFilterField[] aFilterFields = @@ -1171,24 +1122,21 @@ public class SpreadsheetSample extends SpreadsheetDocHelper aFilterFields[0].Operator = com.sun.star.sheet.FilterOperator.GREATER_EQUAL; aFilterFields[0].NumericValue = 1998; xFilterDesc.setFilterFields( aFilterFields ); - com.sun.star.beans.XPropertySet xFilterProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xFilterDesc ); + com.sun.star.beans.XPropertySet xFilterProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xFilterDesc ); xFilterProp.setPropertyValue( "ContainsHeader", new Boolean( true ) ); xFilter.filter( xFilterDesc ); // --- do the same filter as above, using criteria from a cell range --- com.sun.star.table.XCellRange xCritRange = xSheet.getCellRangeByName( "B27:B28" ); - com.sun.star.sheet.XCellRangeData xCritData = ( com.sun.star.sheet.XCellRangeData ) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xCritRange ); + com.sun.star.sheet.XCellRangeData xCritData = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeData.class, xCritRange ); Object[][] aCritValues = { { "Year" }, { ">= 1998" } }; xCritData.setDataArray( aCritValues ); - com.sun.star.sheet.XSheetFilterableEx xCriteria = ( com.sun.star.sheet.XSheetFilterableEx ) - UnoRuntime.queryInterface( com.sun.star.sheet.XSheetFilterableEx.class, xCritRange ); + com.sun.star.sheet.XSheetFilterableEx xCriteria = UnoRuntime.queryInterface( com.sun.star.sheet.XSheetFilterableEx.class, xCritRange ); xFilterDesc = xCriteria.createFilterDescriptorByObject( xFilter ); if ( xFilterDesc != null ) xFilter.filter( xFilterDesc ); @@ -1210,14 +1158,12 @@ public class SpreadsheetSample extends SpreadsheetDocHelper aSortDesc[1].Name = "ContainsHeader"; aSortDesc[1].Value = new Boolean( true ); - com.sun.star.util.XSortable xSort = ( com.sun.star.util.XSortable ) - UnoRuntime.queryInterface( com.sun.star.util.XSortable.class, xRange ); + com.sun.star.util.XSortable xSort = UnoRuntime.queryInterface( com.sun.star.util.XSortable.class, xRange ); xSort.sort( aSortDesc ); // --- insert subtotals --- - com.sun.star.sheet.XSubTotalCalculatable xSub = ( com.sun.star.sheet.XSubTotalCalculatable ) - UnoRuntime.queryInterface( com.sun.star.sheet.XSubTotalCalculatable.class, xRange ); + com.sun.star.sheet.XSubTotalCalculatable xSub = UnoRuntime.queryInterface( com.sun.star.sheet.XSubTotalCalculatable.class, xRange ); com.sun.star.sheet.XSubTotalDescriptor xSubDesc = xSub.createSubTotalDescriptor( true ); com.sun.star.sheet.SubTotalColumn[] aColumns = new com.sun.star.sheet.SubTotalColumn[1]; // calculate sum of third column @@ -1245,34 +1191,29 @@ public class SpreadsheetSample extends SpreadsheetDocHelper aImportDesc[2].Value = aTableName; com.sun.star.table.XCellRange xImportRange = xSheet.getCellRangeByName( "B35:B35" ); - com.sun.star.util.XImportable xImport = ( com.sun.star.util.XImportable ) - UnoRuntime.queryInterface( com.sun.star.util.XImportable.class, xImportRange ); + com.sun.star.util.XImportable xImport = UnoRuntime.queryInterface( com.sun.star.util.XImportable.class, xImportRange ); xImport.doImport( aImportDesc ); // --- use the temporary database range to find the imported data's size --- - com.sun.star.beans.XPropertySet xDocProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, getDocument() ); + com.sun.star.beans.XPropertySet xDocProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, getDocument() ); Object aRangesObj = xDocProp.getPropertyValue( "DatabaseRanges" ); com.sun.star.container.XNameAccess xRanges = - (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface( - com.sun.star.container.XNameAccess.class, aRangesObj ); + UnoRuntime.queryInterface( + com.sun.star.container.XNameAccess.class, aRangesObj ); String[] aNames = xRanges.getElementNames(); AnyConverter aAnyConv = new AnyConverter(); for ( int i=0; i<aNames.length; i++ ) { Object aRangeObj = xRanges.getByName( aNames[i] ); - com.sun.star.beans.XPropertySet xRangeProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aRangeObj ); + com.sun.star.beans.XPropertySet xRangeProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aRangeObj ); boolean bUser = aAnyConv.toBoolean(xRangeProp.getPropertyValue( "IsUserDefined" )); if ( !bUser ) { // this is the temporary database range - get the cell range and format it - com.sun.star.sheet.XCellRangeReferrer xRef = ( com.sun.star.sheet.XCellRangeReferrer ) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeReferrer.class, aRangeObj ); + com.sun.star.sheet.XCellRangeReferrer xRef = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeReferrer.class, aRangeObj ); com.sun.star.table.XCellRange xResultRange = xRef.getReferredCells(); - com.sun.star.beans.XPropertySet xResultProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xResultRange ); + com.sun.star.beans.XPropertySet xResultProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xResultRange ); xResultProp.setPropertyValue( "IsCellBackgroundTransparent", new Boolean( false ) ); xResultProp.setPropertyValue( "CellBackColor", new Integer( 0xFFFFCC ) ); } @@ -1292,8 +1233,7 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Create a new DataPilot table --- prepareRange( xSheet, "A38:C38", "Data Pilot" ); - com.sun.star.sheet.XDataPilotTablesSupplier xDPSupp = (com.sun.star.sheet.XDataPilotTablesSupplier) - UnoRuntime.queryInterface( com.sun.star.sheet.XDataPilotTablesSupplier.class, xSheet ); + com.sun.star.sheet.XDataPilotTablesSupplier xDPSupp = UnoRuntime.queryInterface( com.sun.star.sheet.XDataPilotTablesSupplier.class, xSheet ); com.sun.star.sheet.XDataPilotTables xDPTables = xDPSupp.getDataPilotTables(); com.sun.star.sheet.XDataPilotDescriptor xDPDesc = xDPTables.createDataPilotDescriptor(); // set source range (use data range from CellRange test) @@ -1305,18 +1245,15 @@ public class SpreadsheetSample extends SpreadsheetDocHelper com.sun.star.beans.XPropertySet xFieldProp; // use first column as column field aFieldObj = xFields.getByIndex(0); - xFieldProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); + xFieldProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); xFieldProp.setPropertyValue( "Orientation", com.sun.star.sheet.DataPilotFieldOrientation.COLUMN ); // use second column as row field aFieldObj = xFields.getByIndex(1); - xFieldProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); + xFieldProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); xFieldProp.setPropertyValue( "Orientation", com.sun.star.sheet.DataPilotFieldOrientation.ROW ); // use third column as data field, calculating the sum aFieldObj = xFields.getByIndex(2); - xFieldProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); + xFieldProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); xFieldProp.setPropertyValue( "Orientation", com.sun.star.sheet.DataPilotFieldOrientation.DATA ); xFieldProp.setPropertyValue( "Function", com.sun.star.sheet.GeneralFunction.SUM ); // select output position @@ -1326,13 +1263,11 @@ public class SpreadsheetSample extends SpreadsheetDocHelper // --- Modify the DataPilot table --- Object aDPTableObj = xDPTables.getByName( "DataPilotExample" ); - xDPDesc = (com.sun.star.sheet.XDataPilotDescriptor) - UnoRuntime.queryInterface( com.sun.star.sheet.XDataPilotDescriptor.class, aDPTableObj ); + xDPDesc = UnoRuntime.queryInterface( com.sun.star.sheet.XDataPilotDescriptor.class, aDPTableObj ); xFields = xDPDesc.getDataPilotFields(); // add a second data field from the third column, calculating the average aFieldObj = xFields.getByIndex(2); - xFieldProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); + xFieldProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, aFieldObj ); xFieldProp.setPropertyValue( "Orientation", com.sun.star.sheet.DataPilotFieldOrientation.DATA ); xFieldProp.setPropertyValue( "Function", com.sun.star.sheet.GeneralFunction.AVERAGE ); } @@ -1349,8 +1284,8 @@ public class SpreadsheetSample extends SpreadsheetDocHelper Object aFuncInst = xServiceManager.createInstanceWithContext( "com.sun.star.sheet.FunctionAccess", getContext()); com.sun.star.sheet.XFunctionAccess xFuncAcc = - (com.sun.star.sheet.XFunctionAccess)UnoRuntime.queryInterface( - com.sun.star.sheet.XFunctionAccess.class, aFuncInst ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XFunctionAccess.class, aFuncInst ); // put the data in a two-dimensional array double[][] aData = { { 1.0, 2.0, 3.0 } }; // construct the array of function arguments @@ -1366,8 +1301,8 @@ public class SpreadsheetSample extends SpreadsheetDocHelper Object aRecInst = xServiceManager.createInstanceWithContext( "com.sun.star.sheet.RecentFunctions", getContext()); com.sun.star.sheet.XRecentFunctions xRecFunc = - (com.sun.star.sheet.XRecentFunctions)UnoRuntime.queryInterface( - com.sun.star.sheet.XRecentFunctions.class, aRecInst ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XRecentFunctions.class, aRecInst ); int[] nRecentIds = xRecFunc.getRecentFunctionIds(); @@ -1375,8 +1310,8 @@ public class SpreadsheetSample extends SpreadsheetDocHelper Object aDescInst = xServiceManager.createInstanceWithContext( "com.sun.star.sheet.FunctionDescriptions", getContext()); com.sun.star.sheet.XFunctionDescriptions xFuncDesc = - (com.sun.star.sheet.XFunctionDescriptions)UnoRuntime.queryInterface( - com.sun.star.sheet.XFunctionDescriptions.class, aDescInst ); + UnoRuntime.queryInterface( + com.sun.star.sheet.XFunctionDescriptions.class, aDescInst ); System.out.print("Recently used functions: "); for (int nFunction=0; nFunction<nRecentIds.length; nFunction++) { @@ -1401,8 +1336,8 @@ public class SpreadsheetSample extends SpreadsheetDocHelper Object aSettings = xServiceManager.createInstanceWithContext( "com.sun.star.sheet.GlobalSheetSettings", getContext()); com.sun.star.beans.XPropertySet xPropSet = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, aSettings ); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, aSettings ); AnyConverter aAnyConv = new AnyConverter(); String[] aEntries = (String[]) aAnyConv.toObject(String[].class, diff --git a/odk/examples/DevelopersGuide/Spreadsheet/ViewSample.java b/odk/examples/DevelopersGuide/Spreadsheet/ViewSample.java index dd89ce017ead..8b4e8afaef10 100644 --- a/odk/examples/DevelopersGuide/Spreadsheet/ViewSample.java +++ b/odk/examples/DevelopersGuide/Spreadsheet/ViewSample.java @@ -72,42 +72,35 @@ public class ViewSample extends SpreadsheetDocHelper public void doSampleFunction() throws Exception { com.sun.star.sheet.XSpreadsheetDocument xDoc = getDocument(); - com.sun.star.frame.XModel xModel = (com.sun.star.frame.XModel) - UnoRuntime.queryInterface( com.sun.star.frame.XModel.class, xDoc); + com.sun.star.frame.XModel xModel = UnoRuntime.queryInterface( com.sun.star.frame.XModel.class, xDoc); com.sun.star.frame.XController xController = xModel.getCurrentController(); // --- Spreadsheet view --- // freeze the first column and first two rows - com.sun.star.sheet.XViewFreezable xFreeze = (com.sun.star.sheet.XViewFreezable) - UnoRuntime.queryInterface( com.sun.star.sheet.XViewFreezable.class, xController ); + com.sun.star.sheet.XViewFreezable xFreeze = UnoRuntime.queryInterface( com.sun.star.sheet.XViewFreezable.class, xController ); if ( null != xFreeze ) System.out.println( "got xFreeze" ); xFreeze.freezeAtPosition( 1, 2 ); // --- View pane --- // get the cell range shown in the second pane and assign a cell background to them - com.sun.star.container.XIndexAccess xIndex = (com.sun.star.container.XIndexAccess) - UnoRuntime.queryInterface( com.sun.star.container.XIndexAccess.class, xController ); + com.sun.star.container.XIndexAccess xIndex = UnoRuntime.queryInterface( com.sun.star.container.XIndexAccess.class, xController ); Object aPane = xIndex.getByIndex(1); - com.sun.star.sheet.XCellRangeReferrer xRefer = (com.sun.star.sheet.XCellRangeReferrer) - UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeReferrer.class, aPane ); + com.sun.star.sheet.XCellRangeReferrer xRefer = UnoRuntime.queryInterface( com.sun.star.sheet.XCellRangeReferrer.class, aPane ); com.sun.star.table.XCellRange xRange = xRefer.getReferredCells(); - com.sun.star.beans.XPropertySet xRangeProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xRange ); + com.sun.star.beans.XPropertySet xRangeProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xRange ); xRangeProp.setPropertyValue( "IsCellBackgroundTransparent", new Boolean( false ) ); xRangeProp.setPropertyValue( "CellBackColor", new Integer( 0xFFFFCC ) ); // --- View settings --- // change the view to display green grid lines - com.sun.star.beans.XPropertySet xProp = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xController ); + com.sun.star.beans.XPropertySet xProp = UnoRuntime.queryInterface( com.sun.star.beans.XPropertySet.class, xController ); xProp.setPropertyValue( "ShowGrid", new Boolean(true) ); xProp.setPropertyValue( "GridColor", new Integer(0x00CC00) ); // --- Range selection --- // let the user select a range and use it as the view's selection - com.sun.star.sheet.XRangeSelection xRngSel = (com.sun.star.sheet.XRangeSelection) - UnoRuntime.queryInterface( com.sun.star.sheet.XRangeSelection.class, xController ); + com.sun.star.sheet.XRangeSelection xRngSel = UnoRuntime.queryInterface( com.sun.star.sheet.XRangeSelection.class, xController ); ExampleRangeListener aListener = new ExampleRangeListener(); xRngSel.addRangeSelectionListener( aListener ); com.sun.star.beans.PropertyValue[] aArguments = new com.sun.star.beans.PropertyValue[2]; @@ -125,10 +118,8 @@ public class ViewSample extends SpreadsheetDocHelper xRngSel.removeRangeSelectionListener( aListener ); if ( aListener.aResult != null && aListener.aResult.length() != 0 ) { - com.sun.star.view.XSelectionSupplier xSel = (com.sun.star.view.XSelectionSupplier) - UnoRuntime.queryInterface( com.sun.star.view.XSelectionSupplier.class, xController ); - com.sun.star.sheet.XSpreadsheetView xView = (com.sun.star.sheet.XSpreadsheetView) - UnoRuntime.queryInterface( com.sun.star.sheet.XSpreadsheetView.class, xController ); + com.sun.star.view.XSelectionSupplier xSel = UnoRuntime.queryInterface( com.sun.star.view.XSelectionSupplier.class, xController ); + com.sun.star.sheet.XSpreadsheetView xView = UnoRuntime.queryInterface( com.sun.star.sheet.XSpreadsheetView.class, xController ); com.sun.star.sheet.XSpreadsheet xSheet = xView.getActiveSheet(); com.sun.star.table.XCellRange xResultRange = xSheet.getCellRangeByName( aListener.aResult ); xSel.select( xResultRange ); diff --git a/odk/examples/DevelopersGuide/Text/TextDocuments.java b/odk/examples/DevelopersGuide/Text/TextDocuments.java index 13e68967131b..4914251b07ca 100644 --- a/odk/examples/DevelopersGuide/Text/TextDocuments.java +++ b/odk/examples/DevelopersGuide/Text/TextDocuments.java @@ -186,11 +186,9 @@ public class TextDocuments { newDocComponentFromTemplate( sTemplateFileUrl.toString() ); // get XTextFieldsSupplier, XBookmarksSupplier interfaces - XTextFieldsSupplier xTextFieldsSupplier = (XTextFieldsSupplier) - UnoRuntime.queryInterface(XTextFieldsSupplier.class, - xTemplateComponent); - XBookmarksSupplier xBookmarksSupplier = (XBookmarksSupplier) - UnoRuntime.queryInterface(XBookmarksSupplier.class, xTemplateComponent); + XTextFieldsSupplier xTextFieldsSupplier = UnoRuntime.queryInterface(XTextFieldsSupplier.class, + xTemplateComponent); + XBookmarksSupplier xBookmarksSupplier = UnoRuntime.queryInterface(XBookmarksSupplier.class, xTemplateComponent); // access the TextFields and the TextFieldMasters collections XNameAccess xNamedFieldMasters = xTextFieldsSupplier.getTextFieldMasters(); @@ -207,14 +205,14 @@ public class TextDocuments { "com.sun.star.text.fieldmaster.User." + key); // query the XPropertySet interface, we need to set the Content property - XPropertySet xPropertySet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropertySet = UnoRuntime.queryInterface( XPropertySet.class, fieldMaster); // insert the column value into field master xPropertySet.setPropertyValue("Content", recipient.get(key)); } // afterwards we must refresh the textfields collection - XRefreshable xRefreshable = (XRefreshable)UnoRuntime.queryInterface( + XRefreshable xRefreshable = UnoRuntime.queryInterface( XRefreshable.class, xEnumeratedFields); xRefreshable.refresh(); @@ -225,7 +223,7 @@ public class TextDocuments { Object bookmark = xNamedBookmarks.getByName("Subscription"); // we need its XTextRange which is available from getAnchor(), // so query for XTextContent - XTextContent xBookmarkContent = (XTextContent)UnoRuntime.queryInterface( + XTextContent xBookmarkContent = UnoRuntime.queryInterface( XTextContent.class, bookmark); // get the anchor of the bookmark (its XTextRange) XTextRange xBookmarkRange = xBookmarkContent.getAnchor(); @@ -248,28 +246,28 @@ public class TextDocuments { Object desktop = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", mxRemoteContext); // query its XDesktop interface, we need the current component - XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface( + XDesktop xDesktop = UnoRuntime.queryInterface( XDesktop.class, desktop); // retrieve the current component and access the controller XComponent xCurrentComponent = xDesktop.getCurrentComponent(); - XModel xModel = (XModel)UnoRuntime.queryInterface(XModel.class, + XModel xModel = UnoRuntime.queryInterface(XModel.class, xCurrentComponent); XController xController = xModel.getCurrentController(); // the controller gives us the TextViewCursor XTextViewCursorSupplier xViewCursorSupplier = - (XTextViewCursorSupplier)UnoRuntime.queryInterface( - XTextViewCursorSupplier.class, xController); + 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( + XPropertySet xCursorPropertySet = UnoRuntime.queryInterface( XPropertySet.class, xViewCursor); // set the appropriate properties for character and paragraph style xCursorPropertySet.setPropertyValue("CharStyleName", "Quotation"); xCursorPropertySet.setPropertyValue("ParaStyleName", "Quotations"); // print the current page number - XPageCursor xPageCursor = (XPageCursor)UnoRuntime.queryInterface( + 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 @@ -284,8 +282,7 @@ public class TextDocuments { // or XDocumentInsertable, XSortable or XContentEnumerationAccess // and work with the properties of com.sun.star.text.TextCursor // in this case we just go to the end of the paragraph and add some text. - XParagraphCursor xParagraphCursor = (XParagraphCursor) - UnoRuntime.queryInterface(XParagraphCursor.class, xModelCursor); + XParagraphCursor xParagraphCursor = UnoRuntime.queryInterface(XParagraphCursor.class, xModelCursor); // goto the end of the paragraph xParagraphCursor.gotoEndOfParagraph(false); xParagraphCursor.setString(" ***** Fin de semana! ******"); @@ -299,7 +296,7 @@ public class TextDocuments { // create empty swriter document XComponent xEmptyWriterComponent = newDocComponent("swriter"); // query its XTextDocument interface to get the text - mxDoc = (XTextDocument)UnoRuntime.queryInterface( + mxDoc = UnoRuntime.queryInterface( XTextDocument.class, xEmptyWriterComponent); // get a reference to the body text of the document @@ -307,7 +304,7 @@ public class TextDocuments { // Get a reference to the document's property set. This contains document // information like the current word count - mxDocProps = (XPropertySet) UnoRuntime.queryInterface( + mxDocProps = UnoRuntime.queryInterface( XPropertySet.class, mxDoc ); // Simple text insertion example @@ -323,7 +320,7 @@ public class TextDocuments { // Access the text document's multi service factory, which we will need // for most of the following examples - mxDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( + mxDocFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, mxDoc ); // Examples of text fields, dependant text fields and field masters @@ -372,7 +369,7 @@ public class TextDocuments { // XDrawPageSupplier interface DrawPageExample (); - mxFactory = (XMultiServiceFactory)UnoRuntime.queryInterface( + mxFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, mxRemoteServiceManager); // This example demonstrates the use of the AutoTextContainer, // AutoTextGroup and AutoTextEntry services and shows how to create, @@ -386,8 +383,7 @@ public class TextDocuments { // retrieve the Desktop object, we need its XComponentLoader Object desktop = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", mxRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, desktop); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; java.io.File sourceFile = new java.io.File("PrintDemo.odt"); @@ -428,8 +424,7 @@ public class TextDocuments { mxRemoteServiceManager = this.getRemoteServiceManager(); Object desktop = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", mxRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, desktop); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; return xComponentLoader.loadComponentFromURL(loadUrl, "_blank", 0, loadProps); @@ -445,8 +440,7 @@ public class TextDocuments { // retrieve the Desktop object, we need its XComponentLoader Object desktop = mxRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", mxRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, desktop); + 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 @@ -466,7 +460,7 @@ public class TextDocuments { throws java.lang.Exception { - XStorable xStorable = (XStorable)UnoRuntime.queryInterface( + XStorable xStorable = UnoRuntime.queryInterface( XStorable.class, xDoc); PropertyValue[] storeProps = new PropertyValue[1]; storeProps[0] = new PropertyValue(); @@ -478,7 +472,7 @@ public class TextDocuments { } protected void printDocComponent(XComponent xDoc) throws java.lang.Exception { - XPrintable xPrintable = (XPrintable)UnoRuntime.queryInterface( + XPrintable xPrintable = UnoRuntime.queryInterface( XPrintable.class, xDoc); PropertyValue[] printerDesc = new PropertyValue[1]; printerDesc[0] = new PropertyValue(); @@ -538,12 +532,11 @@ public class TextDocuments { try { // First, get the XSentenceCursor interface of our text cursor - XSentenceCursor xSentenceCursor = (XSentenceCursor) - UnoRuntime.queryInterface(XSentenceCursor.class, mxDocCursor ); + XSentenceCursor xSentenceCursor = UnoRuntime.queryInterface(XSentenceCursor.class, mxDocCursor ); // Goto the next cursor, without selecting it xSentenceCursor.gotoNextSentence( false ); // Get the XWordCursor interface of our text cursor - XWordCursor xWordCursor = (XWordCursor) UnoRuntime.queryInterface( + XWordCursor xWordCursor = UnoRuntime.queryInterface( XWordCursor.class, mxDocCursor ); // Skip the first four words of this sentence and select the fifth xWordCursor.gotoNextWord( false ); @@ -558,7 +551,7 @@ public class TextDocuments { // Access the property set of the cursor, and set the currently // selected text (which is the string we just inserted) to be bold - XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xCursorProps = UnoRuntime.queryInterface( XPropertySet.class, mxDocCursor ); xCursorProps.setPropertyValue ( "CharWeight", new Float(com.sun.star.awt.FontWeight.BOLD) ); @@ -585,7 +578,7 @@ public class TextDocuments { { // Use the text document's factory to create a DateTime text field, // and access it's XTextField interface - XTextField xDateField = (XTextField) UnoRuntime.queryInterface ( + XTextField xDateField = UnoRuntime.queryInterface ( XTextField.class, mxDocFactory.createInstance ( "com.sun.star.text.TextField.DateTime" ) ); @@ -595,13 +588,13 @@ public class TextDocuments { // Use the text document's factory to create a user text field, // and access it's XDependentTextField interface XDependentTextField xUserField = - (XDependentTextField) UnoRuntime.queryInterface ( - XDependentTextField.class, mxDocFactory.createInstance ( - "com.sun.star.text.TextField.User" ) ); + UnoRuntime.queryInterface ( + XDependentTextField.class, mxDocFactory.createInstance ( + "com.sun.star.text.TextField.User" ) ); // Create a fieldmaster for our newly created User Text field, and // access it's XPropertySet interface - XPropertySet xMasterPropSet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xMasterPropSet = UnoRuntime.queryInterface( XPropertySet.class, mxDocFactory.createInstance ( "com.sun.star.text.fieldmaster.User" ) ); @@ -638,8 +631,7 @@ public class TextDocuments { // the text the service refers to. // Here, we access this interface - XEnumerationAccess xParaAccess = (XEnumerationAccess) - UnoRuntime.queryInterface(XEnumerationAccess.class, mxDocText ); + XEnumerationAccess xParaAccess = UnoRuntime.queryInterface(XEnumerationAccess.class, mxDocText ); // Call the XEnumerationAccess's only method to access the actual // Enumeration XEnumeration xParaEnum = xParaAccess.createEnumeration(); @@ -652,14 +644,14 @@ public class TextDocuments { // the element if it is a TextTable, if it doesn't support the // com.sun.star.text.TextTable service, then it is safe to assume // that it really is a paragraph - XServiceInfo xInfo = (XServiceInfo) UnoRuntime.queryInterface( + XServiceInfo xInfo = UnoRuntime.queryInterface( XServiceInfo.class, xParaEnum.nextElement() ); if ( !xInfo.supportsService ( "com.sun.star.text.TextTable" ) ) { // Access the paragraph's property set...the properties in this // property set are listed in: // com.sun.star.style.ParagraphProperties - XPropertySet xSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xSet = UnoRuntime.queryInterface( XPropertySet.class, xInfo ); // Set the justification to be center justified xSet.setPropertyValue ( "ParaAdjust", @@ -687,13 +679,13 @@ public class TextDocuments { XTextTable xTable) { // Access the XText interface of the cell referred to by sCellName - XText xCellText = (XText) UnoRuntime.queryInterface( + XText xCellText = 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 xCellCursorProps = UnoRuntime.queryInterface( XPropertySet.class, xCellCursor ); try @@ -717,7 +709,7 @@ public class TextDocuments { try { // Create a new table from the document's factory - XTextTable xTable = (XTextTable) UnoRuntime.queryInterface( + XTextTable xTable = UnoRuntime.queryInterface( XTextTable.class, mxDocFactory .createInstance( "com.sun.star.text.TextTable" ) ); @@ -731,7 +723,7 @@ public class TextDocuments { // 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 = UnoRuntime.queryInterface( XPropertySet.class, xRows.getByIndex ( 0 ) ); // If BackTransparant is false, then the background color is visible xRow.setPropertyValue( "BackTransparent", new Boolean(false)); @@ -739,7 +731,7 @@ public class TextDocuments { xRow.setPropertyValue( "BackColor", new Integer(6710932)); // Access the property set of the whole table - XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xTableProps = UnoRuntime.queryInterface( XPropertySet.class, xTable ); // We want visible background colors xTableProps.setPropertyValue( "BackTransparent", new Boolean(false)); @@ -786,14 +778,14 @@ public class TextDocuments { { // Use the document's factory to create a new text frame and // immediately access it's XTextFrame interface - XTextFrame xFrame = (XTextFrame) UnoRuntime.queryInterface ( + XTextFrame xFrame = 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); + XShape xShape = UnoRuntime.queryInterface(XShape.class, xFrame); // Access the XPropertySet interface of the TextFrame - XPropertySet xFrameProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xFrameProps = UnoRuntime.queryInterface( XPropertySet.class, xFrame ); // Set the size of the new Text Frame using the XShape's 'setSize' @@ -850,18 +842,17 @@ public class TextDocuments { mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // Position the cursor in the second paragraph - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor ); xParaCursor.gotoPreviousParagraph ( false ); // Get an XNameAccess interface to all auto text groups from the // document factory - XNameAccess xContainer = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess xContainer = 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 xTable = UnoRuntime.queryInterface( XTextTable.class, mxDocFactory .createInstance( "com.sun.star.text.TextTable" ) ); @@ -876,7 +867,7 @@ public class TextDocuments { xTable.initialize( aGroupNames.length+1,1); // Access the XPropertySet of the table - XPropertySet xTableProps = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xTableProps = UnoRuntime.queryInterface( XPropertySet.class, xTable ); // We want a visible background @@ -893,7 +884,7 @@ public class TextDocuments { XIndexAccess xRows = xTable.getRows(); // Get the first row in the table - XPropertySet xRow = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xRow = UnoRuntime.queryInterface( XPropertySet.class, xRows.getByIndex ( 0 ) ); // We want the background of the first row to be visible too @@ -916,7 +907,7 @@ public class TextDocuments { String sCellName = xTableCursor.getRangeName (); // Get the XText interface of the current cell - XText xCellText = (XText) UnoRuntime.queryInterface ( + XText xCellText = UnoRuntime.queryInterface ( XText.class, xTable.getCellByName ( sCellName ) ); // Set the cell contents of the current cell to be @@ -924,9 +915,8 @@ public class TextDocuments { xCellText.setString ( aGroupNames[i] ); // Access the autotext group with this name - XAutoTextGroup xGroup = (XAutoTextGroup) - UnoRuntime.queryInterface (XAutoTextGroup.class, - xContainer.getByName(aGroupNames[i])); + XAutoTextGroup xGroup = UnoRuntime.queryInterface (XAutoTextGroup.class, + xContainer.getByName(aGroupNames[i])); // Get the titles of each autotext block in this group String [] aBlockNames = xGroup.getTitles(); @@ -951,7 +941,7 @@ public class TextDocuments { for ( int j = 0 ; j < aBlockNames.length ; j ++ ) { // Get the XText interface of the current cell - xCellText = (XText) UnoRuntime.queryInterface ( + xCellText = UnoRuntime.queryInterface ( XText.class, xTable.getCellByName ( xTableCursor.getRangeName() ) ); @@ -984,7 +974,7 @@ public class TextDocuments { aGroupNames.length ); // Get the autotext group at this name - xGroup = ( XAutoTextGroup ) UnoRuntime.queryInterface ( + xGroup = UnoRuntime.queryInterface ( XAutoTextGroup.class, xContainer.getByName ( aGroupNames[ nRandom ] ) ); @@ -1003,10 +993,9 @@ public class TextDocuments { // XAutoTextEntry interface int nRandom = Math.abs ( maRandom.nextInt() % aBlockNames.length ); - XAutoTextEntry xEntry = ( XAutoTextEntry ) - UnoRuntime.queryInterface ( - XAutoTextEntry.class, xGroup.getByName ( - aBlockNames[ nRandom ] ) ); + XAutoTextEntry xEntry = UnoRuntime.queryInterface ( + XAutoTextEntry.class, xGroup.getByName ( + aBlockNames[ nRandom ] ) ); // insert the modified autotext block at the end of the document xEntry.applyTo ( mxDocCursor ); @@ -1014,7 +1003,7 @@ public class TextDocuments { String [] aBlockTitles = xGroup.getTitles(); // Get the XNamed interface of the autotext group - XNamed xGroupNamed = ( XNamed ) UnoRuntime.queryInterface ( + XNamed xGroupNamed = UnoRuntime.queryInterface ( XNamed.class, xGroup ); // Output the short cut and title of the random block @@ -1060,12 +1049,11 @@ public class TextDocuments { // Insert a new paragraph and position the cursor in it mxDocText.insertControlCharacter ( mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); xParaCursor.gotoPreviousParagraph ( false ); // Create a new ContentIndexMark and get it's XPropertySet interface - XPropertySet xEntry = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xEntry = UnoRuntime.queryInterface( XPropertySet.class, mxDocFactory.createInstance("com.sun.star.text.ContentIndexMark")); @@ -1077,7 +1065,7 @@ public class TextDocuments { xEntry.setPropertyValue ( "Level", new Short ( (short) 1 ) ); // Create a ContentIndex and access it's XPropertySet interface - XPropertySet xIndex = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xIndex = UnoRuntime.queryInterface( XPropertySet.class, mxDocFactory.createInstance ( "com.sun.star.text.ContentIndex" ) ); @@ -1086,9 +1074,9 @@ public class TextDocuments { // Access the XTextContent interfaces of both the Index and the // IndexMark - XTextContent xIndexContent = (XTextContent) UnoRuntime.queryInterface( + XTextContent xIndexContent = UnoRuntime.queryInterface( XTextContent.class, xIndex ); - XTextContent xEntryContent = (XTextContent) UnoRuntime.queryInterface( + XTextContent xEntryContent = UnoRuntime.queryInterface( XTextContent.class, xEntry ); // Insert both in the document @@ -1096,7 +1084,7 @@ public class TextDocuments { mxDocText.insertTextContent ( mxDocCursor, xIndexContent, false ); // Get the XDocumentIndex interface of the Index - XDocumentIndex xDocIndex = (XDocumentIndex) UnoRuntime.queryInterface( + XDocumentIndex xDocIndex = UnoRuntime.queryInterface( XDocumentIndex.class, xIndex ); // And call it's update method @@ -1123,33 +1111,31 @@ public class TextDocuments { mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // Get the Paragraph cursor - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = 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, + XNamed xRefMark = 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); + XTextTablesSupplier xTableSupplier = UnoRuntime.queryInterface(XTextTablesSupplier.class, mxDoc); // Get an XIndexAccess of TextTables - XIndexAccess xTables = (XIndexAccess)UnoRuntime.queryInterface( + XIndexAccess xTables = UnoRuntime.queryInterface( XIndexAccess.class, xTableSupplier.getTextTables()); // We've only inserted one table, so get the first one from index zero - XTextTable xTable = ( XTextTable ) UnoRuntime.queryInterface ( + XTextTable xTable = UnoRuntime.queryInterface ( XTextTable.class, xTables.getByIndex( 0 ) ); // Get the first cell from the table - XText xTableText = (XText) UnoRuntime.queryInterface( + XText xTableText = UnoRuntime.queryInterface( XText.class, xTable.getCellByName ( "A1" ) ); // Get a text cursor for the first cell @@ -1157,7 +1143,7 @@ public class TextDocuments { // Get the XTextContent interface of the reference mark so we can // insert it - XTextContent xContent = ( XTextContent ) UnoRuntime.queryInterface ( + XTextContent xContent = UnoRuntime.queryInterface ( XTextContent.class, xRefMark ); // Insert the reference mark into the first cell of the table @@ -1165,16 +1151,15 @@ public class TextDocuments { // 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( + XPropertySet xFieldProps = UnoRuntime.queryInterface( XPropertySet.class, mxDocFactory.createInstance ( "com.sun.star.text.TextField.GetReference" ) ); // Get the XReferenceMarksSupplier interface of the document - XReferenceMarksSupplier xRefSupplier = ( XReferenceMarksSupplier ) - UnoRuntime.queryInterface( XReferenceMarksSupplier.class, mxDoc ); + XReferenceMarksSupplier xRefSupplier = UnoRuntime.queryInterface( XReferenceMarksSupplier.class, mxDoc ); // Get an XNameAccess which refers to all inserted reference marks - XNameAccess xMarks = ( XNameAccess ) UnoRuntime.queryInterface ( + XNameAccess xMarks = UnoRuntime.queryInterface ( XNameAccess.class, xRefSupplier.getReferenceMarks() ); // Put the names of each reference mark into an array of strings @@ -1204,7 +1189,7 @@ public class TextDocuments { // Get the XTextContent interface of the GetReference text field - XTextContent xRefContent = (XTextContent) UnoRuntime.queryInterface( + XTextContent xRefContent = UnoRuntime.queryInterface( XTextContent.class, xFieldProps ); // Go to the end of the document @@ -1221,7 +1206,7 @@ public class TextDocuments { " contains the sum of some random numbers.", false ); // Refresh the document - XRefreshable xRefresh = (XRefreshable) UnoRuntime.queryInterface( + XRefreshable xRefresh = UnoRuntime.queryInterface( XRefreshable.class, mxDoc ); xRefresh.refresh(); } @@ -1241,7 +1226,7 @@ public class TextDocuments { { // Create a new footnote from the document factory and get it's // XFootnote interface - XFootnote xFootnote = (XFootnote) UnoRuntime.queryInterface( + XFootnote xFootnote = UnoRuntime.queryInterface( XFootnote.class, mxDocFactory.createInstance ( "com.sun.star.text.Footnote" ) ); @@ -1249,30 +1234,29 @@ public class TextDocuments { xFootnote.setLabel ( "Numbers" ); // Get the footnotes XTextContent interface so we can... - XTextContent xContent = ( XTextContent ) UnoRuntime.queryInterface ( + XTextContent xContent = 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 ); + XFootnotesSupplier xFootnoteSupplier = UnoRuntime.queryInterface(XFootnotesSupplier.class, mxDoc ); // Get an XIndexAccess interface to all footnotes - XIndexAccess xFootnotes = ( XIndexAccess ) UnoRuntime.queryInterface ( + XIndexAccess xFootnotes = UnoRuntime.queryInterface ( XIndexAccess.class, xFootnoteSupplier.getFootnotes() ); // Get the XFootnote interface to the first footnote inserted ('Numbers') - XFootnote xNumbers = ( XFootnote ) UnoRuntime.queryInterface ( + XFootnote xNumbers = UnoRuntime.queryInterface ( XFootnote.class, xFootnotes.getByIndex( 0 ) ); // Get the XSimpleText interface to the Footnote - XSimpleText xSimple = (XSimpleText ) UnoRuntime.queryInterface ( + XSimpleText xSimple = UnoRuntime.queryInterface ( XSimpleText.class, xNumbers ); // Create a text cursor for the foot note text - XTextRange xRange = (XTextRange ) UnoRuntime.queryInterface ( + XTextRange xRange = UnoRuntime.queryInterface ( XTextRange.class, xSimple.createTextCursor() ); // And insert the actual text of the footnote. @@ -1301,19 +1285,18 @@ public class TextDocuments { ControlCharacter.PARAGRAPH_BREAK, false); // Get the XParagraphCursor interface of our document cursor - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = 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 = UnoRuntime.queryInterface( XShape.class, mxDocFactory.createInstance ( "com.sun.star.drawing.RectangleShape" ) ); // Create an EllipseShape using the document factory - XShape xEllipse = (XShape) UnoRuntime.queryInterface( + XShape xEllipse = UnoRuntime.queryInterface( XShape.class, mxDocFactory.createInstance ( "com.sun.star.drawing.EllipseShape" ) ); @@ -1333,9 +1316,9 @@ public class TextDocuments { xRect.setPosition ( aPoint ); // Get the XPropertySet interfaces of both shapes - XPropertySet xRectProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xRectProps = UnoRuntime.queryInterface( XPropertySet.class, xRect ); - XPropertySet xEllipseProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xEllipseProps = UnoRuntime.queryInterface( XPropertySet.class, xEllipse ); // And set the AnchorTypes of both shapes to 'AT_PARAGRAPH' @@ -1345,11 +1328,10 @@ public class TextDocuments { TextContentAnchorType.AT_PARAGRAPH ); // Access the XDrawPageSupplier interface of the document - XDrawPageSupplier xDrawPageSupplier = (XDrawPageSupplier) - UnoRuntime.queryInterface (XDrawPageSupplier.class, mxDoc ); + XDrawPageSupplier xDrawPageSupplier = UnoRuntime.queryInterface (XDrawPageSupplier.class, mxDoc ); // Get the XShapes interface of the draw page - XShapes xShapes = ( XShapes ) UnoRuntime.queryInterface ( + XShapes xShapes = UnoRuntime.queryInterface ( XShapes.class, xDrawPageSupplier.getDrawPage () ); // Add both shapes @@ -1398,28 +1380,27 @@ public class TextDocuments { mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // Create a new style from the document's factory - XStyle xStyle = (XStyle) UnoRuntime.queryInterface( + 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 xStyleProps = 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); + XStyleFamiliesSupplier xSupplier = 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 = UnoRuntime.queryInterface ( XNameAccess.class, xSupplier.getStyleFamilies() ); // Access the 'ParagraphStyles' Family - XNameContainer xFamily = (XNameContainer ) UnoRuntime.queryInterface ( + XNameContainer xFamily = UnoRuntime.queryInterface ( XNameContainer.class, xFamilies.getByName ( "ParagraphStyles" ) ); @@ -1427,15 +1408,14 @@ public class TextDocuments { xFamily.insertByName ( "All-Singing All-Dancing Style", xStyle ); // Get the XParagraphCursor interface of the document cursor - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // 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 xCursorProps = UnoRuntime.queryInterface( XPropertySet.class, mxDocCursor ); // Set the style of the cursor selection to our newly created style @@ -1469,17 +1449,17 @@ public class TextDocuments { mxDocCursor.gotoEnd( false ); // Get the RelativeTextContentInsert interface of the document XRelativeTextContentInsert xRelative = - (XRelativeTextContentInsert ) UnoRuntime.queryInterface ( - XRelativeTextContentInsert.class, mxDocText ); + UnoRuntime.queryInterface ( + XRelativeTextContentInsert.class, mxDocText ); // Use the document's factory to create the NumberingRules service, // and get it's XIndexAccess interface - XIndexAccess xNum = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess xNum = UnoRuntime.queryInterface( XIndexAccess.class, mxDocFactory.createInstance( "com.sun.star.text.NumberingRules" ) ); // Also get the NumberingRule's XIndexReplace interface - XIndexReplace xReplace = (XIndexReplace) UnoRuntime.queryInterface( + XIndexReplace xReplace = UnoRuntime.queryInterface( XIndexReplace.class, xNum ); // Create an array of XPropertySets, one for each of the three @@ -1488,13 +1468,13 @@ public class TextDocuments { for ( int i = 0 ; i < 3 ; ++ i ) { // Create a new paragraph - XTextContent xNewPara = (XTextContent) UnoRuntime.queryInterface( + XTextContent xNewPara = 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] = UnoRuntime.queryInterface( XPropertySet.class, xNewPara ); // Insert the new paragraph into the document after the fish @@ -1535,8 +1515,7 @@ public class TextDocuments { } } // Get the XParagraphCursor interface of our text cursro - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // Go to the end of the document, then select the preceding paragraphs mxDocCursor.gotoEnd ( false ); xParaCursor.gotoPreviousParagraph ( false ); @@ -1544,7 +1523,7 @@ public class TextDocuments { xParaCursor.gotoPreviousParagraph ( true ); // Get the XPropertySet of the cursor's currently selected text - XPropertySet xCursorProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xCursorProps = UnoRuntime.queryInterface( XPropertySet.class, mxDocCursor ); // Set the updated Numbering rules to the cursor's property set @@ -1585,7 +1564,7 @@ public class TextDocuments { // Create a new TextSection from the document factory and access // it's XNamed interface - XNamed xChildNamed = (XNamed) UnoRuntime.queryInterface( + XNamed xChildNamed = UnoRuntime.queryInterface( XNamed.class, mxDocFactory.createInstance( "com.sun.star.text.TextSection" ) ); // Set the new sections name to 'Child_Section' @@ -1593,13 +1572,12 @@ public class TextDocuments { // Access the Child_Section's XTextContent interface and insert it // into the document - XTextContent xChildSection = (XTextContent) UnoRuntime.queryInterface( + XTextContent xChildSection = UnoRuntime.queryInterface( XTextContent.class, xChildNamed ); mxDocText.insertTextContent ( mxDocCursor, xChildSection, false ); // Access the XParagraphCursor interface of our text cursor - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor); + XParagraphCursor xParaCursor = UnoRuntime.queryInterface(XParagraphCursor.class, mxDocCursor); // Go back one paragraph (into Child_Section) xParaCursor.gotoPreviousParagraph ( false ); @@ -1617,14 +1595,14 @@ public class TextDocuments { mxDocCursor.gotoEnd ( true ); // Create another text section and access it's XNamed interface - XNamed xParentNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, + XNamed xParentNamed = 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 xParentSection = UnoRuntime.queryInterface( XTextContent.class, xParentNamed ); // ...and insert it into the document mxDocText.insertTextContent ( mxDocCursor, xParentSection, false ); @@ -1638,31 +1616,31 @@ public class TextDocuments { xParaCursor.gotoPreviousParagraph ( true ); // Create a new Text Section and access it's XNamed interface - XNamed xLinkNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, + XNamed xLinkNamed = 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 xLinkedSection = 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 = 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 xChildProps = 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 = UnoRuntime.queryInterface( XRefreshable.class, mxDoc ); xRefresh.refresh(); } @@ -1695,8 +1673,7 @@ public class TextDocuments { mxDocCursor, ControlCharacter.PARAGRAPH_BREAK, false ); // Get the XParagraphCursor interface of our text cursor - XParagraphCursor xParaCursor = (XParagraphCursor) - UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); + XParagraphCursor xParaCursor = UnoRuntime.queryInterface( XParagraphCursor.class, mxDocCursor ); // Jump back before all the text we just inserted xParaCursor.gotoPreviousParagraph ( false ); xParaCursor.gotoPreviousParagraph ( false ); @@ -1709,14 +1686,14 @@ public class TextDocuments { xParaCursor.gotoNextParagraph ( true ); // Create a new text section and get it's XNamed interface - XNamed xSectionNamed = (XNamed) UnoRuntime.queryInterface(XNamed.class, + XNamed xSectionNamed = UnoRuntime.queryInterface(XNamed.class, mxDocFactory.createInstance("com.sun.star.text.TextSection")); // Set the name of our new section (appropiately) to 'Fish' xSectionNamed.setName ( "Fish" ); // Create the TextColumns service and get it's XTextColumns interface - XTextColumns xColumns = (XTextColumns) UnoRuntime.queryInterface( + XTextColumns xColumns = UnoRuntime.queryInterface( XTextColumns.class, mxDocFactory.createInstance ( "com.sun.star.text.TextColumns" ) ); @@ -1733,26 +1710,25 @@ public class TextDocuments { xColumns.setColumns ( aSequence ); // Get the property set interface of our 'Fish' section - XPropertySet xSectionProps = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xSectionProps = 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( + mxFishSection = 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 ); + XRelativeTextContentInsert xRelative = UnoRuntime.queryInterface ( + XRelativeTextContentInsert.class, mxDocText ); // Create a new empty paragraph and get it's XTextContent interface - XTextContent xNewPara = (XTextContent) UnoRuntime.queryInterface( + XTextContent xNewPara = UnoRuntime.queryInterface( XTextContent.class, mxDocFactory.createInstance("com.sun.star.text.Paragraph")); diff --git a/odk/examples/java/ConverterServlet/ConverterServlet.java b/odk/examples/java/ConverterServlet/ConverterServlet.java index 526e9281ef01..2a3688c4ead9 100644 --- a/odk/examples/java/ConverterServlet/ConverterServlet.java +++ b/odk/examples/java/ConverterServlet/ConverterServlet.java @@ -228,9 +228,8 @@ public class ConverterServlet extends HttpServlet { "com.sun.star.bridge.UnoUrlResolver", xcomponentcontext ); // Create a new url resolver - XUnoUrlResolver xurlresolver = ( XUnoUrlResolver ) - UnoRuntime.queryInterface( XUnoUrlResolver.class, - objectUrlResolver ); + XUnoUrlResolver xurlresolver = UnoRuntime.queryInterface( XUnoUrlResolver.class, + objectUrlResolver ); // Resolves an object that is specified as follow: // uno:<connection description>;<protocol description>;<initial object name> @@ -239,29 +238,26 @@ public class ConverterServlet extends HttpServlet { ";urp;StarOffice.ServiceManager" ); // Create a service manager from the initial object - xmulticomponentfactory = ( XMultiComponentFactory ) - UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial ); + xmulticomponentfactory = UnoRuntime.queryInterface( XMultiComponentFactory.class, objectInitial ); // Query for the XPropertySet interface. - XPropertySet xpropertysetMultiComponentFactory = ( XPropertySet ) - UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory ); + XPropertySet xpropertysetMultiComponentFactory = UnoRuntime.queryInterface( XPropertySet.class, xmulticomponentfactory ); // Get the default context from the office server. Object objectDefaultContext = xpropertysetMultiComponentFactory.getPropertyValue( "DefaultContext" ); // Query for the interface XComponentContext. - xcomponentcontext = ( XComponentContext ) UnoRuntime.queryInterface( + xcomponentcontext = UnoRuntime.queryInterface( XComponentContext.class, objectDefaultContext ); /* A desktop environment contains tasks with one or more frames in which components can be loaded. Desktop is the environment for components which can instanciate within frames. */ - XComponentLoader xcomponentloader = ( XComponentLoader ) - UnoRuntime.queryInterface( XComponentLoader.class, - xmulticomponentfactory.createInstanceWithContext( - "com.sun.star.frame.Desktop", xcomponentcontext ) ); + XComponentLoader xcomponentloader = UnoRuntime.queryInterface( XComponentLoader.class, + xmulticomponentfactory.createInstanceWithContext( + "com.sun.star.frame.Desktop", xcomponentcontext ) ); // Preparing properties for loading the document PropertyValue propertyvalue[] = new PropertyValue[ 1 ]; @@ -277,8 +273,8 @@ public class ConverterServlet extends HttpServlet { // Getting an object that will offer a simple way to store a document to a URL. XStorable xstorable = - ( XStorable ) UnoRuntime.queryInterface( XStorable.class, - objectDocumentToStore ); + UnoRuntime.queryInterface( XStorable.class, + objectDocumentToStore ); // Preparing properties for converting the document propertyvalue = new PropertyValue[ 2 ]; @@ -302,7 +298,7 @@ public class ConverterServlet extends HttpServlet { // Storing and converting the document xstorable.storeAsURL( stringConvertedFile, propertyvalue ); - XCloseable xcloseable = (XCloseable)UnoRuntime.queryInterface( XCloseable.class,xstorable ); + XCloseable xcloseable = UnoRuntime.queryInterface( XCloseable.class,xstorable ); // Closing the converted document if ( xcloseable != null ) @@ -310,7 +306,7 @@ public class ConverterServlet extends HttpServlet { else { // If Xcloseable is not supported (older versions, // use dispose() for closing the document - XComponent xComponent = ( XComponent ) UnoRuntime.queryInterface( + XComponent xComponent = UnoRuntime.queryInterface( XComponent.class, xstorable ); xComponent.dispose(); } diff --git a/odk/examples/java/DocumentHandling/DocumentConverter.java b/odk/examples/java/DocumentHandling/DocumentConverter.java index b6bbdbe7d957..aeb6f022d2ca 100644 --- a/odk/examples/java/DocumentHandling/DocumentConverter.java +++ b/odk/examples/java/DocumentHandling/DocumentConverter.java @@ -112,8 +112,8 @@ public class DocumentConverter { // Getting an object that will offer a simple way to store // a document to a URL. com.sun.star.frame.XStorable xStorable = - (com.sun.star.frame.XStorable)UnoRuntime.queryInterface( - com.sun.star.frame.XStorable.class, oDocToStore ); + UnoRuntime.queryInterface( + com.sun.star.frame.XStorable.class, oDocToStore ); // Preparing properties for converting the document propertyValues = new com.sun.star.beans.PropertyValue[2]; @@ -138,15 +138,15 @@ public class DocumentConverter { // Closing the converted document. Use XCloseable.clsoe if the // interface is supported, otherwise use XComponent.dispose com.sun.star.util.XCloseable xCloseable = - (com.sun.star.util.XCloseable)UnoRuntime.queryInterface( - com.sun.star.util.XCloseable.class, xStorable); + UnoRuntime.queryInterface( + com.sun.star.util.XCloseable.class, xStorable); if ( xCloseable != null ) { xCloseable.close(false); } else { com.sun.star.lang.XComponent xComp = - (com.sun.star.lang.XComponent)UnoRuntime.queryInterface( - com.sun.star.lang.XComponent.class, xStorable); + UnoRuntime.queryInterface( + com.sun.star.lang.XComponent.class, xStorable); xComp.dispose(); } @@ -194,9 +194,8 @@ public class DocumentConverter { Object oDesktop = xMCF.createInstanceWithContext( "com.sun.star.frame.Desktop", xContext); - xCompLoader = (com.sun.star.frame.XComponentLoader) - UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, - oDesktop); + xCompLoader = UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, + oDesktop); // Getting the given starting directory File file = new File(args[0]); diff --git a/odk/examples/java/DocumentHandling/DocumentLoader.java b/odk/examples/java/DocumentHandling/DocumentLoader.java index 8185cbf6da5f..2f01046d21b4 100644 --- a/odk/examples/java/DocumentHandling/DocumentLoader.java +++ b/odk/examples/java/DocumentHandling/DocumentLoader.java @@ -63,9 +63,8 @@ public class DocumentLoader { "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, oDesktop); + UnoRuntime.queryInterface( + com.sun.star.frame.XComponentLoader.class, oDesktop); String sUrl = args[0]; if ( sUrl.indexOf("private:") != 0) { diff --git a/odk/examples/java/DocumentHandling/DocumentPrinter.java b/odk/examples/java/DocumentHandling/DocumentPrinter.java index e6a7a1430d4e..cc851123efc2 100644 --- a/odk/examples/java/DocumentHandling/DocumentPrinter.java +++ b/odk/examples/java/DocumentHandling/DocumentPrinter.java @@ -61,9 +61,8 @@ public class DocumentPrinter { "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, oDesktop); + UnoRuntime.queryInterface( + com.sun.star.frame.XComponentLoader.class, oDesktop); java.io.File sourceFile = new java.io.File(args[1]); StringBuffer sUrl = new StringBuffer("file:///"); @@ -76,8 +75,8 @@ public class DocumentPrinter { // Querying for the interface XPrintable on the loaded document com.sun.star.view.XPrintable xPrintable = - (com.sun.star.view.XPrintable)UnoRuntime.queryInterface( - com.sun.star.view.XPrintable.class, xComp); + UnoRuntime.queryInterface( + com.sun.star.view.XPrintable.class, xComp); // Setting the property "Name" for the favoured printer (name of // IP address) diff --git a/odk/examples/java/DocumentHandling/DocumentSaver.java b/odk/examples/java/DocumentHandling/DocumentSaver.java index f6f21ea48228..052b344a3d2e 100644 --- a/odk/examples/java/DocumentHandling/DocumentSaver.java +++ b/odk/examples/java/DocumentHandling/DocumentSaver.java @@ -71,9 +71,8 @@ public class DocumentSaver { "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, oDesktop); + UnoRuntime.queryInterface( + com.sun.star.frame.XComponentLoader.class, oDesktop); java.io.File sourceFile = new java.io.File(args[0]); StringBuffer sLoadUrl = new StringBuffer("file:///"); @@ -92,8 +91,8 @@ public class DocumentSaver { Object oDocToStore = xCompLoader.loadComponentFromURL( sLoadUrl.toString(), "_blank", 0, propertyValue ); com.sun.star.frame.XStorable xStorable = - (com.sun.star.frame.XStorable)UnoRuntime.queryInterface( - com.sun.star.frame.XStorable.class, oDocToStore ); + UnoRuntime.queryInterface( + com.sun.star.frame.XStorable.class, oDocToStore ); propertyValue = new com.sun.star.beans.PropertyValue[ 2 ]; propertyValue[0] = new com.sun.star.beans.PropertyValue(); @@ -107,17 +106,15 @@ public class DocumentSaver { System.out.println("\nDocument \"" + sLoadUrl + "\" saved under \"" + sSaveUrl + "\"\n"); - com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable) - UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, - oDocToStore ); + com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, + oDocToStore ); if (xCloseable != null ) { xCloseable.close(false); } else { - com.sun.star.lang.XComponent xComp = (com.sun.star.lang.XComponent) - UnoRuntime.queryInterface( - com.sun.star.lang.XComponent.class, oDocToStore ); + com.sun.star.lang.XComponent xComp = UnoRuntime.queryInterface( + com.sun.star.lang.XComponent.class, oDocToStore ); xComp.dispose(); } System.out.println("document closed!"); diff --git a/odk/examples/java/Drawing/SDraw.java b/odk/examples/java/Drawing/SDraw.java index dfb544e3db02..5f56dc25d541 100644 --- a/odk/examples/java/Drawing/SDraw.java +++ b/odk/examples/java/Drawing/SDraw.java @@ -92,13 +92,13 @@ public class SDraw { try { System.out.println( "getting Drawpage" ); com.sun.star.drawing.XDrawPagesSupplier xDPS = - (com.sun.star.drawing.XDrawPagesSupplier)UnoRuntime.queryInterface( - com.sun.star.drawing.XDrawPagesSupplier.class, xDrawDoc); + UnoRuntime.queryInterface( + com.sun.star.drawing.XDrawPagesSupplier.class, xDrawDoc); com.sun.star.drawing.XDrawPages xDPn = xDPS.getDrawPages(); com.sun.star.container.XIndexAccess xDPi = - (com.sun.star.container.XIndexAccess)UnoRuntime.queryInterface( - com.sun.star.container.XIndexAccess.class, xDPn); - xDrawPage = (com.sun.star.drawing.XDrawPage)UnoRuntime.queryInterface( + UnoRuntime.queryInterface( + com.sun.star.container.XIndexAccess.class, xDPn); + xDrawPage = UnoRuntime.queryInterface( com.sun.star.drawing.XDrawPage.class, xDPi.getByIndex(0)); } catch ( Exception e ) { System.err.println( "Couldn't create document"+ e ); @@ -109,9 +109,8 @@ public class SDraw { //put something on the drawpage System.out.println( "inserting some Shapes" ); - com.sun.star.drawing.XShapes xShapes = (com.sun.star.drawing.XShapes) - UnoRuntime.queryInterface( - com.sun.star.drawing.XShapes.class, xDrawPage); + com.sun.star.drawing.XShapes xShapes = UnoRuntime.queryInterface( + com.sun.star.drawing.XShapes.class, xDrawPage); xShapes.add(createShape(xDrawDoc,2000,1500,1000,1000,"Line",0)); xShapes.add(createShape(xDrawDoc,3000,4500,15000,1000,"Ellipse",16711680)); xShapes.add(createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle",6710932)); @@ -136,9 +135,8 @@ public class SDraw { 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/sdraw"; @@ -163,13 +161,13 @@ public class SDraw { //get MSF com.sun.star.lang.XMultiServiceFactory xDocMSF = - (com.sun.star.lang.XMultiServiceFactory) UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, xDocComp ); + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, xDocComp ); try { Object oInt = xDocMSF.createInstance("com.sun.star.drawing." +kind + "Shape"); - xShape = (com.sun.star.drawing.XShape)UnoRuntime.queryInterface( + xShape = UnoRuntime.queryInterface( com.sun.star.drawing.XShape.class, oInt); size.Height = height; size.Width = width; @@ -183,9 +181,8 @@ public class SDraw { e.printStackTrace(System.err); } - com.sun.star.beans.XPropertySet xSPS = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, xShape); + com.sun.star.beans.XPropertySet xSPS = UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xShape); try { xSPS.setPropertyValue("FillColor", new Integer(col)); @@ -203,8 +200,7 @@ public class SDraw { com.sun.star.awt.Size size = new com.sun.star.awt.Size(); com.sun.star.awt.Point position = new com.sun.star.awt.Point(); com.sun.star.drawing.XShape xShape = null; - com.sun.star.drawing.XShapes xShapes = (com.sun.star.drawing.XShapes) - UnoRuntime.queryInterface(com.sun.star.drawing.XShapes.class, xDP); + com.sun.star.drawing.XShapes xShapes = UnoRuntime.queryInterface(com.sun.star.drawing.XShapes.class, xDP); int height = 3000; int width = 3500; int x = 1900; @@ -216,13 +212,13 @@ public class SDraw { //get MSF com.sun.star.lang.XMultiServiceFactory xDocMSF = - (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, xDocComp ); + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, xDocComp ); for (int i=0; i<370; i=i+25) { try{ oInt = xDocMSF.createInstance("com.sun.star.drawing.EllipseShape"); - xShape = (com.sun.star.drawing.XShape)UnoRuntime.queryInterface( + xShape = UnoRuntime.queryInterface( com.sun.star.drawing.XShape.class, oInt); size.Height = height; size.Width = width; @@ -240,9 +236,8 @@ public class SDraw { b=b+8; - com.sun.star.beans.XPropertySet xSPS = (com.sun.star.beans.XPropertySet) - UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, - xShape); + com.sun.star.beans.XPropertySet xSPS = UnoRuntime.queryInterface(com.sun.star.beans.XPropertySet.class, + xShape); try { xSPS.setPropertyValue("FillColor", new Integer(getCol(r,g,b))); @@ -255,8 +250,8 @@ public class SDraw { } com.sun.star.drawing.XShapeGrouper xSGrouper = - (com.sun.star.drawing.XShapeGrouper)UnoRuntime.queryInterface( - com.sun.star.drawing.XShapeGrouper.class, xDP); + UnoRuntime.queryInterface( + com.sun.star.drawing.XShapeGrouper.class, xDP); xShape = xSGrouper.group(xShapes); diff --git a/odk/examples/java/NotesAccess/NotesAccess.java b/odk/examples/java/NotesAccess/NotesAccess.java index 63af5a66caf0..a8b221ee0ef5 100644 --- a/odk/examples/java/NotesAccess/NotesAccess.java +++ b/odk/examples/java/NotesAccess/NotesAccess.java @@ -111,14 +111,14 @@ public class NotesAccess implements Runnable { NotesAccess notesaccess = new NotesAccess(); // Allowing only local calls to the Domino classes. - thread = new NotesThread( ( Runnable ) notesaccess ); + thread = new NotesThread( notesaccess ); } else { // Extracting the host, user, and password. NotesAccess notesaccess = new NotesAccess(); // Allowing remote calls to the Domino classes. - thread = new Thread( ( Runnable ) notesaccess ); + thread = new Thread( notesaccess ); } // Starting the thread. @@ -147,10 +147,9 @@ public class NotesAccess implements Runnable { frames in which components can be loaded. Desktop is the environment for components which can instanciate within frames. */ - XComponentLoader xLoader = ( XComponentLoader ) - UnoRuntime.queryInterface(XComponentLoader.class, - xMCF.createInstanceWithContext( - "com.sun.star.frame.Desktop", xContext)); + XComponentLoader xLoader = UnoRuntime.queryInterface(XComponentLoader.class, + xMCF.createInstanceWithContext( + "com.sun.star.frame.Desktop", xContext)); // Load a Writer document, which will be automaticly displayed XComponent xComponent = xLoader.loadComponentFromURL( @@ -159,18 +158,18 @@ public class NotesAccess implements Runnable { // Querying for the interface XSpreadsheetDocument XSpreadsheetDocument xSpreadsheetDoc = - (XSpreadsheetDocument) UnoRuntime.queryInterface( - XSpreadsheetDocument.class, xComponent); + UnoRuntime.queryInterface( + XSpreadsheetDocument.class, xComponent); // Getting all sheets from the spreadsheet document. XSpreadsheets xSpreadsheets = xSpreadsheetDoc.getSheets() ; // Querying for the interface XIndexAccess. - XIndexAccess xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess xIndexAccess = UnoRuntime.queryInterface( XIndexAccess.class, xSpreadsheets); // Getting the first spreadsheet. - XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface( + XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface( XSpreadsheet.class, xIndexAccess.getByIndex(0)); Session session; diff --git a/odk/examples/java/Spreadsheet/CalcAddins.java b/odk/examples/java/Spreadsheet/CalcAddins.java index 0a417acae50e..d658a4f4fafa 100644 --- a/odk/examples/java/Spreadsheet/CalcAddins.java +++ b/odk/examples/java/Spreadsheet/CalcAddins.java @@ -100,14 +100,14 @@ public class CalcAddins { public int getMyFirstValue( com.sun.star.beans.XPropertySet xOptions ) { - return (int) 1; + return 1; } public int getMySecondValue( com.sun.star.beans.XPropertySet xOptions, int intDummy ) { - return( (int) ( 2 + intDummy ) ); + return( 2 + intDummy ); } diff --git a/odk/examples/java/Spreadsheet/ChartTypeChange.java b/odk/examples/java/Spreadsheet/ChartTypeChange.java index 7b14ab3716f9..98a143762cab 100644 --- a/odk/examples/java/Spreadsheet/ChartTypeChange.java +++ b/odk/examples/java/Spreadsheet/ChartTypeChange.java @@ -151,19 +151,17 @@ public class ChartTypeChange { */ public void changeChartType( String stringType, boolean booleanIs3D ) throws Exception { - XEmbeddedObjectSupplier xEmbeddedObjSupplier = (XEmbeddedObjectSupplier) - UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, xtablechart); + XEmbeddedObjectSupplier xEmbeddedObjSupplier = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, xtablechart); XInterface xInterface = xEmbeddedObjSupplier.getEmbeddedObject(); - XChartDocument xChartDoc = (XChartDocument)UnoRuntime.queryInterface( + XChartDocument xChartDoc = UnoRuntime.queryInterface( XChartDocument.class, xInterface); - XDiagram xDiagram = (XDiagram) xChartDoc.getDiagram(); - XMultiServiceFactory xMSF = (XMultiServiceFactory) - UnoRuntime.queryInterface( XMultiServiceFactory.class, xChartDoc ); + XDiagram xDiagram = xChartDoc.getDiagram(); + XMultiServiceFactory xMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xChartDoc ); Object object = xMSF.createInstance( stringType ); - xDiagram = (XDiagram) UnoRuntime.queryInterface(XDiagram.class, object); + xDiagram = UnoRuntime.queryInterface(XDiagram.class, object); - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xDiagram ); xPropSet.setPropertyValue( "Dim3D", new Boolean( booleanIs3D ) ); @@ -181,10 +179,9 @@ public class ChartTypeChange { frames in which components can be loaded. Desktop is the environment for components which can instanciate within frames. */ - XComponentLoader xComponentloader = (XComponentLoader) - UnoRuntime.queryInterface( XComponentLoader.class, - xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", - xCompContext ) ); + XComponentLoader xComponentloader = UnoRuntime.queryInterface( XComponentLoader.class, + xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", + xCompContext ) ); // Load a Writer document, which will be automaticly displayed XComponent xComponent = xComponentloader.loadComponentFromURL( @@ -192,24 +189,21 @@ public class ChartTypeChange { new PropertyValue[0] ); // Query for the interface XSpreadsheetDocument - XSpreadsheetDocument xSpreadSheetDocument = ( XSpreadsheetDocument ) - UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent ); + XSpreadsheetDocument xSpreadSheetDocument = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent ); XSpreadsheets xSpreadsheets = xSpreadSheetDocument.getSheets() ; - XIndexAccess xIndexAccess = (XIndexAccess) - UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets ); + XIndexAccess xIndexAccess = UnoRuntime.queryInterface(XIndexAccess.class, xSpreadsheets ); - XSpreadsheet xSpreadsheet = (XSpreadsheet) UnoRuntime.queryInterface( + XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface( XSpreadsheet.class, xIndexAccess.getByIndex(0)); - XTableChartsSupplier xTableChartsSupplier = ( XTableChartsSupplier ) - UnoRuntime.queryInterface( XTableChartsSupplier.class, xSpreadsheet ); + XTableChartsSupplier xTableChartsSupplier = UnoRuntime.queryInterface( XTableChartsSupplier.class, xSpreadsheet ); - xIndexAccess = (XIndexAccess) UnoRuntime.queryInterface( + xIndexAccess = UnoRuntime.queryInterface( XIndexAccess.class, xTableChartsSupplier.getCharts() ); - this.xtablechart = (XTableChart) UnoRuntime.queryInterface( + this.xtablechart = UnoRuntime.queryInterface( XTableChart.class, xIndexAccess.getByIndex( 0 ) ); } catch( Exception exception ) { @@ -227,11 +221,10 @@ public class ChartTypeChange { frames in which components can be loaded. Desktop is the environment for components which can instanciate within frames. */ - XComponentLoader xcomponentloader = ( XComponentLoader ) - UnoRuntime.queryInterface( XComponentLoader.class, - xMCF.createInstanceWithContext( - "com.sun.star.frame.Desktop", - xCompContext ) ); + XComponentLoader xcomponentloader = UnoRuntime.queryInterface( XComponentLoader.class, + xMCF.createInstanceWithContext( + "com.sun.star.frame.Desktop", + xCompContext ) ); // Create an empty calc document, which will be automaticly displayed XComponent xComponent = xcomponentloader.loadComponentFromURL( @@ -239,18 +232,17 @@ public class ChartTypeChange { new PropertyValue[0] ); // Query for the interface XSpreadsheetDocument - XSpreadsheetDocument xspreadsheetdocument = ( XSpreadsheetDocument ) - UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent ); + XSpreadsheetDocument xspreadsheetdocument = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent ); // Get all sheets of the spreadsheet document. XSpreadsheets xspreadsheets = xspreadsheetdocument.getSheets() ; // Get the index of the spreadsheet document. - XIndexAccess xindexaccess = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess xindexaccess = UnoRuntime.queryInterface( XIndexAccess.class, xspreadsheets ); // Get the first spreadsheet. - XSpreadsheet xspreadsheet = (XSpreadsheet) UnoRuntime.queryInterface( + XSpreadsheet xspreadsheet = UnoRuntime.queryInterface( XSpreadsheet.class, xindexaccess.getByIndex(0)); // The double array will written to the spreadsheet @@ -271,7 +263,7 @@ public class ChartTypeChange { rectangle.Height = 11000; // Get the cell range of the spreadsheet. - XCellRange xcellrange = ( XCellRange ) UnoRuntime.queryInterface( + XCellRange xcellrange = UnoRuntime.queryInterface( XCellRange.class, xspreadsheet ); // Create the Unicode of the character for the column name. @@ -291,7 +283,7 @@ public class ChartTypeChange { // Get the addressable cell range. XCellRangeAddressable xcellrangeaddressable = - ( XCellRangeAddressable ) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XCellRangeAddressable.class, xcellrangeChart ); // Get the cell range address. @@ -303,8 +295,7 @@ public class ChartTypeChange { cellrangeaddressChart[ 0 ] = cellrangeaddress; // Get the table charts supplier of the spreadsheet. - XTableChartsSupplier xtablechartssupplier = ( XTableChartsSupplier ) - UnoRuntime.queryInterface( XTableChartsSupplier.class, xspreadsheet ); + XTableChartsSupplier xtablechartssupplier = UnoRuntime.queryInterface( XTableChartsSupplier.class, xspreadsheet ); // Get all table charts of the spreadsheet. XTableCharts xtablecharts = xtablechartssupplier.getCharts(); @@ -314,9 +305,9 @@ public class ChartTypeChange { cellrangeaddressChart, true, true ); // Get the created table chart. - this.xtablechart = ( XTableChart ) UnoRuntime.queryInterface( - XTableChart.class, (( XNameAccess ) UnoRuntime.queryInterface( - XNameAccess.class, xtablecharts ) ).getByName( "Example" )); + this.xtablechart = UnoRuntime.queryInterface( + XTableChart.class, UnoRuntime.queryInterface( + XNameAccess.class, xtablecharts ).getByName( "Example" )); } catch( Exception exception ) { System.err.println( exception ); diff --git a/odk/examples/java/Spreadsheet/EuroAdaption.java b/odk/examples/java/Spreadsheet/EuroAdaption.java index 11727c2ea415..2f4f1d4f95e6 100644 --- a/odk/examples/java/Spreadsheet/EuroAdaption.java +++ b/odk/examples/java/Spreadsheet/EuroAdaption.java @@ -85,17 +85,17 @@ public class EuroAdaption { // create a sheet document XSpreadsheetDocument xSheetdocument = null; - xSheetdocument = ( XSpreadsheetDocument ) createSheetdocument( xDesktop ); + xSheetdocument = createSheetdocument( xDesktop ); System.out.println( "Create a new Spreadsheet" ); // get the collection of all sheets from the document XSpreadsheets xSheets = null; - xSheets = (XSpreadsheets) xSheetdocument.getSheets(); + xSheets = xSheetdocument.getSheets(); // the Action Interface provides methods to hide actions, // like inserting data, on a sheet, that increase the performance XActionLockable xActionInterface = null; - xActionInterface = (XActionLockable) UnoRuntime.queryInterface( + xActionInterface = UnoRuntime.queryInterface( XActionLockable.class, xSheetdocument ); // lock all actions @@ -104,11 +104,11 @@ public class EuroAdaption { com.sun.star.sheet.XSpreadsheet xSheet = null; try { // get via the index access the first sheet - XIndexAccess xElements = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess xElements = UnoRuntime.queryInterface( XIndexAccess.class, xSheets ); // specify the first sheet from the spreadsheet - xSheet = (XSpreadsheet) UnoRuntime.queryInterface( + xSheet = UnoRuntime.queryInterface( XSpreadsheet.class, xElements.getByIndex( 0 )); } catch( Exception e) { @@ -117,7 +117,7 @@ public class EuroAdaption { // get the interface to apply and create new numberformats XNumberFormatsSupplier xNumberFormatSupplier = null; - xNumberFormatSupplier = (XNumberFormatsSupplier) UnoRuntime.queryInterface( + xNumberFormatSupplier = UnoRuntime.queryInterface( XNumberFormatsSupplier.class, xSheetdocument ); XNumberFormats xNumberFormats = null; xNumberFormats = xNumberFormatSupplier.getNumberFormats(); @@ -154,14 +154,14 @@ public class EuroAdaption { // you have to use the FormatSupplier interface to get the // CellFormat enumeration XCellFormatRangesSupplier xCellFormatSupplier = - (XCellFormatRangesSupplier)UnoRuntime.queryInterface( - XCellFormatRangesSupplier.class, xSheet ); + UnoRuntime.queryInterface( + XCellFormatRangesSupplier.class, xSheet ); // getCellFormatRanges() has the interfaces for the enumeration XEnumerationAccess xEnumerationAccess = - (XEnumerationAccess)UnoRuntime.queryInterface( - XEnumerationAccess.class, - xCellFormatSupplier.getCellFormatRanges() ); + UnoRuntime.queryInterface( + XEnumerationAccess.class, + xCellFormatSupplier.getCellFormatRanges() ); XEnumeration xRanges = xEnumerationAccess.createEnumeration(); @@ -170,11 +170,11 @@ public class EuroAdaption { while( xRanges.hasMoreElements() ) { // the enumeration returns a cellrange - XCellRange xCellRange = (XCellRange) UnoRuntime.queryInterface( + XCellRange xCellRange = UnoRuntime.queryInterface( XCellRange.class, xRanges.nextElement()); // the PropertySet the get and set the properties from the cellrange - XPropertySet xCellProp = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCellProp = UnoRuntime.queryInterface( XPropertySet.class, xCellRange ); // getPropertyValue returns an Object, you have to cast it to @@ -183,8 +183,7 @@ public class EuroAdaption { int iNumberFormat = aAnyConv.toInt(oNumberObject); // get the properties from the cellrange numberformat - XPropertySet xFormat = (XPropertySet) - xNumberFormats.getByKey(iNumberFormat ); + XPropertySet xFormat = xNumberFormats.getByKey(iNumberFormat ); short fType = aAnyConv.toShort(xFormat.getPropertyValue("Type")); String sCurrencySymbol = aAnyConv.toString( @@ -221,9 +220,8 @@ public class EuroAdaption { // interate over all cells from the cellrange with an // content and use the DM/EUR factor - XCellRangesQuery xCellRangesQuery = (XCellRangesQuery) - UnoRuntime.queryInterface( - XCellRangesQuery.class, xCellRange ); + XCellRangesQuery xCellRangesQuery = UnoRuntime.queryInterface( + XCellRangesQuery.class, xCellRange ); XSheetCellRanges xSheetCellRanges = xCellRangesQuery.queryContentCells( @@ -236,9 +234,9 @@ public class EuroAdaption { xCellEnumerationAccess.createEnumeration(); while( xCellEnumeration.hasMoreElements() ) { - XCell xCell = (XCell) UnoRuntime.queryInterface( + XCell xCell = UnoRuntime.queryInterface( XCell.class, xCellEnumeration.nextElement()); - xCell.setValue( (double) xCell.getValue() / fFactor ); + xCell.setValue( xCell.getValue() / fFactor ); } } } @@ -299,7 +297,7 @@ public class EuroAdaption { 2, 1 + iCounter ); // get the ProperySet from the cell, to change the numberformat - XPropertySet xCellProp = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCellProp = UnoRuntime.queryInterface( XPropertySet.class, xCellRange ); xCellProp.setPropertyValue( "NumberFormat", new Integer(iNumberFormatKey) ); @@ -327,7 +325,7 @@ public class EuroAdaption { Object oDesktop = xMCF.createInstanceWithContext( "com.sun.star.frame.Desktop", xContext); - xDesktop = (XDesktop) UnoRuntime.queryInterface( + xDesktop = UnoRuntime.queryInterface( XDesktop.class, oDesktop); } else @@ -350,7 +348,7 @@ public class EuroAdaption { XComponent xComponent = null; xComponent = CreateNewDocument( xDesktop, "scalc" ); - aSheetDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface( + aSheetDocument = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComponent); } catch( Exception e) { @@ -370,7 +368,7 @@ public class EuroAdaption { PropertyValue xEmptyArgs[] = new PropertyValue[0]; try { - xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface( + xComponentLoader = UnoRuntime.queryInterface( XComponentLoader.class, xDesktop ); xComponent = xComponentLoader.loadComponentFromURL( diff --git a/odk/examples/java/Spreadsheet/SCalc.java b/odk/examples/java/Spreadsheet/SCalc.java index 66dc73fda7d3..dded8243fa7e 100644 --- a/odk/examples/java/Spreadsheet/SCalc.java +++ b/odk/examples/java/Spreadsheet/SCalc.java @@ -126,20 +126,17 @@ public class SCalc { //*************************************************************************** try { - XStyleFamiliesSupplier xSFS = (XStyleFamiliesSupplier) - UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, myDoc); - XNameAccess xSF = (XNameAccess) xSFS.getStyleFamilies(); - XNameAccess xCS = (XNameAccess) UnoRuntime.queryInterface( + XStyleFamiliesSupplier xSFS = UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, myDoc); + XNameAccess xSF = xSFS.getStyleFamilies(); + XNameAccess xCS = UnoRuntime.queryInterface( XNameAccess.class, xSF.getByName("CellStyles")); - XMultiServiceFactory oDocMSF = (XMultiServiceFactory) - UnoRuntime.queryInterface(XMultiServiceFactory.class, myDoc ); - XNameContainer oStyleFamilyNameContainer = (XNameContainer) - UnoRuntime.queryInterface( - XNameContainer.class, xCS); + XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface(XMultiServiceFactory.class, myDoc ); + XNameContainer oStyleFamilyNameContainer = UnoRuntime.queryInterface( + XNameContainer.class, xCS); XInterface oInt1 = (XInterface) oDocMSF.createInstance( "com.sun.star.style.CellStyle"); oStyleFamilyNameContainer.insertByName("My Style", oInt1); - XPropertySet oCPS1 = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet oCPS1 = UnoRuntime.queryInterface( XPropertySet.class, oInt1 ); oCPS1.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false)); oCPS1.setPropertyValue("CellBackColor",new Integer(6710932)); @@ -147,7 +144,7 @@ public class SCalc { XInterface oInt2 = (XInterface) oDocMSF.createInstance( "com.sun.star.style.CellStyle"); oStyleFamilyNameContainer.insertByName("My Style2", oInt2); - XPropertySet oCPS2 = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet oCPS2 = UnoRuntime.queryInterface( XPropertySet.class, oInt2 ); oCPS2.setPropertyValue("IsCellBackgroundTransparent", new Boolean(false)); oCPS2.setPropertyValue("CellBackColor",new Integer(13421823)); @@ -171,9 +168,9 @@ public class SCalc { try { System.out.println("Getting spreadsheet") ; XSpreadsheets xSheets = myDoc.getSheets() ; - XIndexAccess oIndexSheets = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess oIndexSheets = UnoRuntime.queryInterface( XIndexAccess.class, xSheets); - xSheet = (XSpreadsheet) UnoRuntime.queryInterface( + xSheet = UnoRuntime.queryInterface( XSpreadsheet.class, oIndexSheets.getByIndex(0)); } catch (Exception e) { @@ -280,16 +277,15 @@ public class SCalc { oRect.Width = 25000; oRect.Height = 11000; - XCellRange oRange = (XCellRange)UnoRuntime.queryInterface( + XCellRange oRange = UnoRuntime.queryInterface( XCellRange.class, xSheet); XCellRange myRange = oRange.getCellRangeByName("A1:N4"); - XCellRangeAddressable oRangeAddr = (XCellRangeAddressable) - UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange); + XCellRangeAddressable oRangeAddr = UnoRuntime.queryInterface(XCellRangeAddressable.class, myRange); CellRangeAddress myAddr = oRangeAddr.getRangeAddress(); CellRangeAddress[] oAddr = new CellRangeAddress[1]; oAddr[0] = myAddr; - XTableChartsSupplier oSupp = (XTableChartsSupplier)UnoRuntime.queryInterface( + XTableChartsSupplier oSupp = UnoRuntime.queryInterface( XTableChartsSupplier.class, xSheet); XTableChart oChart = null; @@ -302,22 +298,21 @@ public class SCalc { // get the diagramm and Change some of the properties try { - oChart = (XTableChart) (UnoRuntime.queryInterface( - XTableChart.class, ((XNameAccess)UnoRuntime.queryInterface( - XNameAccess.class, oCharts)).getByName("Example"))); - XEmbeddedObjectSupplier oEOS = (XEmbeddedObjectSupplier) - UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart); + oChart = (UnoRuntime.queryInterface( + XTableChart.class, UnoRuntime.queryInterface( + XNameAccess.class, oCharts).getByName("Example"))); + XEmbeddedObjectSupplier oEOS = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class, oChart); XInterface oInt = oEOS.getEmbeddedObject(); - XChartDocument xChart = (XChartDocument) UnoRuntime.queryInterface( + XChartDocument xChart = UnoRuntime.queryInterface( XChartDocument.class,oInt); - XDiagram oDiag = (XDiagram) xChart.getDiagram(); + XDiagram oDiag = xChart.getDiagram(); System.out.println("Change Diagramm to 3D"); - XPropertySet oCPS = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet oCPS = UnoRuntime.queryInterface( XPropertySet.class, oDiag ); oCPS.setPropertyValue("Dim3D", new Boolean(true)); System.out.println("Change the title"); Thread.sleep(200); - XPropertySet oTPS = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet oTPS = UnoRuntime.queryInterface( XPropertySet.class, xChart.getTitle() ); oTPS.setPropertyValue("String","The new title"); //oDiag.Dim3D(); @@ -347,14 +342,14 @@ public class SCalc { "com.sun.star.frame.Desktop", xContext ); // query the desktop object for the XComponentLoader - xCLoader = ( XComponentLoader ) UnoRuntime.queryInterface( + xCLoader = UnoRuntime.queryInterface( XComponentLoader.class, oDesktop ); PropertyValue [] szEmptyArgs = new PropertyValue [0]; String strDoc = "private:factory/scalc"; xComp = xCLoader.loadComponentFromURL(strDoc, "_blank", 0, szEmptyArgs ); - xSpreadSheetDoc = (XSpreadsheetDocument) UnoRuntime.queryInterface( + xSpreadSheetDoc = UnoRuntime.queryInterface( XSpreadsheetDocument.class, xComp); } catch(Exception e){ @@ -397,7 +392,7 @@ public class SCalc { ex.printStackTrace(System.err); } - XPropertySet xCPS = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xCPS = UnoRuntime.queryInterface( XPropertySet.class, xCR ); try { diff --git a/odk/examples/java/Storage/StorageFunctionality.java b/odk/examples/java/Storage/StorageFunctionality.java index a030d63a280b..29efd663653d 100644 --- a/odk/examples/java/Storage/StorageFunctionality.java +++ b/odk/examples/java/Storage/StorageFunctionality.java @@ -57,7 +57,7 @@ public class StorageFunctionality { try { Object oStorageFactory = xMSF.createInstance( "com.sun.star.embed.StorageFactory" ); - xStorageFactory = (XSingleServiceFactory)UnoRuntime.queryInterface( XSingleServiceFactory.class, + xStorageFactory = UnoRuntime.queryInterface( XSingleServiceFactory.class, oStorageFactory ); if ( xStorageFactory == null ) @@ -76,15 +76,15 @@ public class StorageFunctionality { final int nNumTests = 9; StorageTest pTests[] = new StorageTest[nNumTests]; - pTests[0] = (StorageTest) new Test01( xMSF, xStorageFactory ); - pTests[1] = (StorageTest) new Test02( xMSF, xStorageFactory ); - pTests[2] = (StorageTest) new Test03( xMSF, xStorageFactory ); - pTests[3] = (StorageTest) new Test04( xMSF, xStorageFactory ); - pTests[4] = (StorageTest) new Test05( xMSF, xStorageFactory ); - pTests[5] = (StorageTest) new Test06( xMSF, xStorageFactory ); - pTests[6] = (StorageTest) new Test07( xMSF, xStorageFactory ); - pTests[7] = (StorageTest) new Test08( xMSF, xStorageFactory ); - pTests[8] = (StorageTest) new Test09( xMSF, xStorageFactory ); + pTests[0] = new Test01( xMSF, xStorageFactory ); + pTests[1] = new Test02( xMSF, xStorageFactory ); + pTests[2] = new Test03( xMSF, xStorageFactory ); + pTests[3] = new Test04( xMSF, xStorageFactory ); + pTests[4] = new Test05( xMSF, xStorageFactory ); + pTests[5] = new Test06( xMSF, xStorageFactory ); + pTests[6] = new Test07( xMSF, xStorageFactory ); + pTests[7] = new Test08( xMSF, xStorageFactory ); + pTests[8] = new Test09( xMSF, xStorageFactory ); System.out.println( "\nstart testing\n" ); @@ -130,11 +130,11 @@ public class StorageFunctionality { // create a connector, so that it can contact the office Object oUrlResolver = xLocalServiceManager.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xComponentContext ); - XUnoUrlResolver xUrlResolver = (XUnoUrlResolver)UnoRuntime.queryInterface( + XUnoUrlResolver xUrlResolver = UnoRuntime.queryInterface( XUnoUrlResolver.class, oUrlResolver ); Object oInitialObject = xUrlResolver.resolve( sConnectStr ); - XNamingService xName = (XNamingService)UnoRuntime.queryInterface( + XNamingService xName = UnoRuntime.queryInterface( XNamingService.class, oInitialObject ); XMultiServiceFactory xMSF = null; @@ -142,8 +142,7 @@ public class StorageFunctionality { System.err.println( "got the remote naming service !" ); Object oMSF = xName.getRegisteredObject("StarOffice.ServiceManager" ); - xMSF = (XMultiServiceFactory) - UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF ); + xMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, oMSF ); } else System.out.println( "Error: Can't get XNamingService interface from url resolver!" ); diff --git a/odk/examples/java/Storage/Test01.java b/odk/examples/java/Storage/Test01.java index 4fc4cc625ef8..4abe4b25b83c 100644 --- a/odk/examples/java/Storage/Test01.java +++ b/odk/examples/java/Storage/Test01.java @@ -49,7 +49,7 @@ public class Test01 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -94,11 +94,11 @@ public class Test01 implements StorageTest { // create temporary storage based on a previously created temporary file Object pArgs[] = new Object[2]; - pArgs[0] = (Object) sTempFileURL; + pArgs[0] = sTempFileURL; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + XStorage xTempFileStorage = UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null ) { m_aTestHelper.Error( "Can't create storage based on temporary file!" ); @@ -121,7 +121,7 @@ public class Test01 implements StorageTest { // the temporary file must not be locked any more after storage disposing pArgs[1] = new Integer( ElementModes.READWRITE ); Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + XStorage xResultStorage = UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null ) { m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); diff --git a/odk/examples/java/Storage/Test02.java b/odk/examples/java/Storage/Test02.java index 9989a6a76bec..c78260b95bc1 100644 --- a/odk/examples/java/Storage/Test02.java +++ b/odk/examples/java/Storage/Test02.java @@ -49,11 +49,11 @@ public class Test02 implements StorageTest { // create storage based on the temporary stream Object pArgs[] = new Object[2]; - pArgs[0] = (Object) xTempFileStream; + pArgs[0] = xTempFileStream; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -121,10 +121,10 @@ public class Test02 implements StorageTest { // open input stream // since no mode is provided the result storage must be opened readonly Object pOneArg[] = new Object[1]; - pOneArg[0] = (Object) xTempInStream; + pOneArg[0] = xTempInStream; Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pOneArg ); - XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + XStorage xResultStorage = UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null ) { m_aTestHelper.Error( "Can't open storage based on input stream!" ); diff --git a/odk/examples/java/Storage/Test03.java b/odk/examples/java/Storage/Test03.java index 39e9c01ad7c1..fe9d8c05c499 100644 --- a/odk/examples/java/Storage/Test03.java +++ b/odk/examples/java/Storage/Test03.java @@ -43,7 +43,7 @@ public class Test03 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -118,7 +118,7 @@ public class Test03 implements StorageTest { return false; } - XNameAccess xRootNameAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xTempStorage ); + XNameAccess xRootNameAccess = UnoRuntime.queryInterface( XNameAccess.class, xTempStorage ); if ( xRootNameAccess == null ) { m_aTestHelper.Error( "Root storage doesn't support XNameAccess!" ); @@ -170,7 +170,7 @@ public class Test03 implements StorageTest { if ( !m_aTestHelper.checkStorageProperties( xResultSubStorage, "MediaType3", false, ElementModes.READ ) ) return false; - XNameAccess xChildAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage ); + XNameAccess xChildAccess = UnoRuntime.queryInterface( XNameAccess.class, xResultSubStorage ); if ( xChildAccess == null ) { m_aTestHelper.Error( "Child storage doesn't support XNameAccess!" ); @@ -199,7 +199,7 @@ public class Test03 implements StorageTest { try { Object oStorage = xAccess.getByName( sName ); - XStorage xResult = (XStorage) UnoRuntime.queryInterface( XStorage.class, oStorage ); + XStorage xResult = UnoRuntime.queryInterface( XStorage.class, oStorage ); if ( xResult != null ) return xResult; diff --git a/odk/examples/java/Storage/Test04.java b/odk/examples/java/Storage/Test04.java index cf3a6ec36b4f..9196b3870c23 100644 --- a/odk/examples/java/Storage/Test04.java +++ b/odk/examples/java/Storage/Test04.java @@ -50,7 +50,7 @@ public class Test04 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -114,11 +114,11 @@ public class Test04 implements StorageTest { // create temporary storage based on a previously created temporary file Object pArgs[] = new Object[2]; - pArgs[0] = (Object) sTempFileURL; + pArgs[0] = sTempFileURL; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + XStorage xTempFileStorage = UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null ) { m_aTestHelper.Error( "Can't create storage based on temporary file!" ); @@ -178,7 +178,7 @@ public class Test04 implements StorageTest { // the temporary file must not be locked any more after storage disposing pArgs[1] = new Integer( ElementModes.READWRITE ); Object oResStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xResStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResStorage ); + XStorage xResStorage = UnoRuntime.queryInterface( XStorage.class, oResStorage ); if ( xResStorage == null ) { m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); @@ -237,7 +237,7 @@ public class Test04 implements StorageTest { try { - XNameAccess xResAccess = (XNameAccess) UnoRuntime.queryInterface( XNameAccess.class, xResStorage ); + XNameAccess xResAccess = UnoRuntime.queryInterface( XNameAccess.class, xResStorage ); if ( xResAccess.hasByName( "SubStorage2" ) ) m_aTestHelper.Error( "SubStorage2 must be removed already!" ); } diff --git a/odk/examples/java/Storage/Test05.java b/odk/examples/java/Storage/Test05.java index d00ced1d3341..9a21b74e9482 100644 --- a/odk/examples/java/Storage/Test05.java +++ b/odk/examples/java/Storage/Test05.java @@ -50,11 +50,11 @@ public class Test05 implements StorageTest { // create temporary storage based on a previously created temporary file Object pArgs[] = new Object[2]; - pArgs[0] = (Object) sTempFileURL; + pArgs[0] = sTempFileURL; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + XStorage xTempFileStorage = UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null ) { m_aTestHelper.Error( "Can't create storage based on temporary file!" ); @@ -218,7 +218,7 @@ public class Test05 implements StorageTest { pArgs[1] = new Integer( ElementModes.READ ); Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + XStorage xResultStorage = UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null ) { m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); diff --git a/odk/examples/java/Storage/Test06.java b/odk/examples/java/Storage/Test06.java index 2b3d62820282..d3b1cb097fd6 100644 --- a/odk/examples/java/Storage/Test06.java +++ b/odk/examples/java/Storage/Test06.java @@ -42,7 +42,7 @@ public class Test06 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -192,7 +192,7 @@ public class Test06 implements StorageTest { // create new temporary storage based on arbitrary medium Object oTargetStorage = m_xStorageFactory.createInstance(); - XStorage xTargetStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTargetStorage ); + XStorage xTargetStorage = UnoRuntime.queryInterface( XStorage.class, oTargetStorage ); if ( xTargetStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); diff --git a/odk/examples/java/Storage/Test07.java b/odk/examples/java/Storage/Test07.java index 753bac8256a3..2e24b3c126b5 100644 --- a/odk/examples/java/Storage/Test07.java +++ b/odk/examples/java/Storage/Test07.java @@ -49,7 +49,7 @@ public class Test07 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -72,11 +72,11 @@ public class Test07 implements StorageTest { // create temporary storage based on a previously created temporary file Object pArgs[] = new Object[2]; - pArgs[0] = (Object) sTempFileURL; + pArgs[0] = sTempFileURL; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + XStorage xTempFileStorage = UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null ) { m_aTestHelper.Error( "Can't create storage based on temporary file!" ); @@ -99,7 +99,7 @@ public class Test07 implements StorageTest { // the temporary file must not be locked any more after storage disposing pArgs[1] = new Integer( ElementModes.READWRITE ); Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + XStorage xResultStorage = UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null ) { m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); @@ -107,7 +107,7 @@ public class Test07 implements StorageTest { } Object o2CopyStorage = m_xStorageFactory.createInstance(); - XStorage x2CopyStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, o2CopyStorage ); + XStorage x2CopyStorage = UnoRuntime.queryInterface( XStorage.class, o2CopyStorage ); if ( x2CopyStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); diff --git a/odk/examples/java/Storage/Test08.java b/odk/examples/java/Storage/Test08.java index 8b29d2cbe5aa..4aef187901cc 100644 --- a/odk/examples/java/Storage/Test08.java +++ b/odk/examples/java/Storage/Test08.java @@ -43,7 +43,7 @@ public class Test08 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -52,7 +52,7 @@ public class Test08 implements StorageTest { // set the global password for the root storage XEncryptionProtectedSource xTempStorageEncryption = - (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xTempStorage ); + UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xTempStorage ); if ( xTempStorageEncryption == null ) { @@ -127,11 +127,11 @@ public class Test08 implements StorageTest { // create temporary storage based on a previously created temporary file Object pArgs[] = new Object[2]; - pArgs[0] = (Object) sTempFileURL; + pArgs[0] = sTempFileURL; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + XStorage xTempFileStorage = UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null ) { m_aTestHelper.Error( "Can't create storage based on temporary file!" ); @@ -154,7 +154,7 @@ public class Test08 implements StorageTest { // the temporary file must not be locked any more after storage disposing pArgs[1] = new Integer( ElementModes.READ ); Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + XStorage xResultStorage = UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null ) { m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); @@ -179,7 +179,7 @@ public class Test08 implements StorageTest { // set the global password for the root storage XEncryptionProtectedSource xResultStorageEncryption = - (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xResultStorage ); + UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xResultStorage ); if ( xResultStorageEncryption == null ) { diff --git a/odk/examples/java/Storage/Test09.java b/odk/examples/java/Storage/Test09.java index 5e7bbe4f09ca..2c0fbac71950 100644 --- a/odk/examples/java/Storage/Test09.java +++ b/odk/examples/java/Storage/Test09.java @@ -43,7 +43,7 @@ public class Test09 implements StorageTest { // create temporary storage based on arbitrary medium // after such a storage is closed it is lost Object oTempStorage = m_xStorageFactory.createInstance(); - XStorage xTempStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oTempStorage ); + XStorage xTempStorage = UnoRuntime.queryInterface( XStorage.class, oTempStorage ); if ( xTempStorage == null ) { m_aTestHelper.Error( "Can't create temporary storage representation!" ); @@ -69,11 +69,11 @@ public class Test09 implements StorageTest { // create temporary storage based on a previously created temporary file Object pArgs[] = new Object[2]; - pArgs[0] = (Object) sTempFileURL; + pArgs[0] = sTempFileURL; pArgs[1] = new Integer( ElementModes.WRITE ); Object oTempFileStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xTempFileStorage = (XStorage)UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); + XStorage xTempFileStorage = UnoRuntime.queryInterface( XStorage.class, oTempFileStorage ); if ( xTempFileStorage == null ) { m_aTestHelper.Error( "Can't create storage based on temporary file!" ); @@ -106,7 +106,7 @@ public class Test09 implements StorageTest { // the temporary file must not be locked any more after storage disposing pArgs[1] = new Integer( ElementModes.READ ); Object oResultStorage = m_xStorageFactory.createInstanceWithArguments( pArgs ); - XStorage xResultStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oResultStorage ); + XStorage xResultStorage = UnoRuntime.queryInterface( XStorage.class, oResultStorage ); if ( xResultStorage == null ) { m_aTestHelper.Error( "Can't reopen storage based on temporary file!" ); diff --git a/odk/examples/java/Storage/TestHelper.java b/odk/examples/java/Storage/TestHelper.java index 935e0b4a9785..ac0c3b9c2d03 100644 --- a/odk/examples/java/Storage/TestHelper.java +++ b/odk/examples/java/Storage/TestHelper.java @@ -49,7 +49,7 @@ public class TestHelper { } // get XTrucate implementation from output stream - XTruncate xTruncate = (XTruncate) UnoRuntime.queryInterface( XTruncate.class, xOutput ); + XTruncate xTruncate = UnoRuntime.queryInterface( XTruncate.class, xOutput ); if ( xTruncate == null ) { Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" ); @@ -69,7 +69,7 @@ public class TestHelper { } // get access to the XPropertySet interface - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStream ); if ( xPropSet == null ) { Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); @@ -105,7 +105,7 @@ public class TestHelper { } // free the stream resources, garbage collector may remove the object too late - XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStream ); + XComponent xComponent = UnoRuntime.queryInterface( XComponent.class, xStream ); if ( xComponent == null ) { Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); @@ -128,7 +128,7 @@ public class TestHelper { try { Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) { Error( "Can't create substream '" + sStreamName + "'!" ); @@ -156,7 +156,7 @@ public class TestHelper { try { Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.WRITE, new String(pPass) ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) { Error( "Can't create substream '" + sStreamName + "'!" ); @@ -184,7 +184,7 @@ public class TestHelper { try { Object oSubStream = xStorage.openStreamElement( sStreamName, ElementModes.WRITE ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) { Error( "Can't create substream '" + sStreamName + "'!" ); @@ -198,7 +198,7 @@ public class TestHelper { } // get access to the XPropertySet interface - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xSubStream ); if ( xPropSet == null ) { Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" ); @@ -229,7 +229,7 @@ public class TestHelper { try { Object oSubStream = xStorage.openEncryptedStreamElement( sStreamName, ElementModes.WRITE, new String(pOldPass) ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) { Error( "Can't open substream '" + sStreamName + "'!" ); @@ -245,7 +245,7 @@ public class TestHelper { // change the password for the stream XEncryptionProtectedSource xStreamEncryption = - (XEncryptionProtectedSource) UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); + UnoRuntime.queryInterface( XEncryptionProtectedSource.class, xSubStream ); if ( xStreamEncryption == null ) { @@ -263,7 +263,7 @@ public class TestHelper { } // free the stream resources, garbage collector may remove the object too late - XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xSubStream ); + XComponent xComponent = UnoRuntime.queryInterface( XComponent.class, xSubStream ); if ( xComponent == null ) { Error( "Can't get XComponent implementation from substream '" + sStreamName + "'!" ); @@ -279,7 +279,7 @@ public class TestHelper { boolean bOk = false; // get access to the XPropertySet interface - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStorage ); if ( xPropSet != null ) { try @@ -323,7 +323,7 @@ public class TestHelper { boolean bOk = false; // get access to the XPropertySet interface - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStorage ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStorage ); if ( xPropSet != null ) { try @@ -421,7 +421,7 @@ public class TestHelper { boolean bOk = false; // get access to the XPropertySet interface - XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xStream ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStream ); if ( xPropSet != null ) { try @@ -467,7 +467,7 @@ public class TestHelper { try { Object oSubStream = xParentStorage.openStreamElement( sName, ElementModes.READ ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) { Error( "Can't open substream '" + sName + "'!" ); @@ -532,7 +532,7 @@ public class TestHelper { try { Object oSubStream = xParentStorage.openEncryptedStreamElement( sName, ElementModes.READ, new String(pPass) ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) { Error( "Can't open encrypted substream '" + sName + "'!" ); @@ -567,7 +567,7 @@ public class TestHelper { public boolean commitStorage( XStorage xStorage ) { // XTransactedObject must be supported by storages - XTransactedObject xTransact = (XTransactedObject) UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); + XTransactedObject xTransact = UnoRuntime.queryInterface( XTransactedObject.class, xStorage ); if ( xTransact == null ) { Error( "Storage doesn't implement transacted access!" ); @@ -590,7 +590,7 @@ public class TestHelper { public boolean disposeStorage( XStorage xStorage ) { // dispose the storage - XComponent xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xStorage ); + XComponent xComponent = UnoRuntime.queryInterface( XComponent.class, xStorage ); if ( xComponent == null ) { Error( "Can't retrieve XComponent implementation from storage!" ); @@ -664,7 +664,7 @@ public class TestHelper { try { Object oSubStorage = xStorage.openStorageElement( sName, nMode ); - XStorage xSubStorage = (XStorage) UnoRuntime.queryInterface( XStorage.class, oSubStorage ); + XStorage xSubStorage = UnoRuntime.queryInterface( XStorage.class, oSubStorage ); return xSubStorage; } catch( Exception e ) @@ -682,7 +682,7 @@ public class TestHelper { try { Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); - xTempFileStream = (XStream)UnoRuntime.queryInterface( XStream.class, oTempFile ); + xTempFileStream = UnoRuntime.queryInterface( XStream.class, oTempFile ); } catch( Exception e ) {} @@ -702,7 +702,7 @@ public class TestHelper { try { Object oTempFile = xMSF.createInstance( "com.sun.star.io.TempFile" ); - xTempFileProps = (XPropertySet)UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); + xTempFileProps = UnoRuntime.queryInterface( XPropertySet.class, oTempFile ); } catch( Exception e ) {} @@ -727,7 +727,7 @@ public class TestHelper { // close temporary file explicitly try { - XStream xStream = (XStream)UnoRuntime.queryInterface( XStream.class, xTempFileProps ); + XStream xStream = UnoRuntime.queryInterface( XStream.class, xTempFileProps ); if ( xStream != null ) { XOutputStream xOut = xStream.getOutputStream(); @@ -822,7 +822,7 @@ public class TestHelper { try { Object oSubStream = xStorage.openStreamElement( sStreamName, nMode ); - xSubStream = (XStream) UnoRuntime.queryInterface( XStream.class, oSubStream ); + xSubStream = UnoRuntime.queryInterface( XStream.class, oSubStream ); if ( xSubStream == null ) Error( "Can't create substream '" + sStreamName + "'!" ); } 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); |