From d62425cc27e04a3237cfec2ea2663b8b11284ec8 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 17 Apr 2013 13:54:28 +0200 Subject: [PATCH] Java cleanup, remove unnecessary casts Change-Id: Id12089bc7df16631737e6acaee0973fb91dd953f Reviewed-on: https://gerrit.libreoffice.org/3431 Reviewed-by: Fridrich Strba Tested-by: Fridrich Strba --- .../test/java_uno/acquire/TestAcquire.java | 12 ++-- bridges/test/testclient.java | 2 +- chart2/qa/TestCaseOldAPI.java | 70 +++++++++---------- .../star/sdbcx/comp/hsqldb/StorageAccess.java | 1 + dbaccess/qa/complex/dbaccess/PropertyBag.java | 2 +- dbaccess/qa/complex/dbaccess/UISettings.java | 6 +- .../extensionoptions/OptionsEventHandler.java | 20 +++--- .../integration/extensions/ConsoleWait.java | 2 +- .../qa/integration/extensions/Frame.java | 12 ++-- .../integration/extensions/MethodHandler.java | 4 +- .../extensions/ObjectInspector.java | 8 +-- .../extensions/ServicesHandler.java | 6 +- extensions/test/pgp/TestPGP.java | 6 +- forms/qa/integration/forms/CellBinding.java | 40 +++++------ .../integration/forms/ControlValidation.java | 2 +- .../qa/integration/forms/DocumentHelper.java | 36 +++++----- .../integration/forms/DocumentViewHelper.java | 12 ++-- forms/qa/integration/forms/FormComponent.java | 18 ++--- .../qa/integration/forms/FormControlTest.java | 26 +++---- forms/qa/integration/forms/FormLayer.java | 10 +-- forms/qa/integration/forms/ListSelection.java | 16 ++--- forms/qa/integration/forms/RadioButtons.java | 4 +- .../forms/SingleControlValidation.java | 6 +- .../forms/SpreadsheetDocument.java | 10 +-- .../qa/integration/forms/SpreadsheetView.java | 8 +-- .../forms/TableCellTextBinding.java | 2 +- forms/qa/integration/forms/ValueBinding.java | 6 +- .../qa/integration/forms/XMLFormSettings.java | 10 +-- .../complex/forms/tools/ResultSet.java | 4 +- forms/qa/org/openoffice/xforms/Model.java | 6 +- .../qa/org/openoffice/xforms/XMLDocument.java | 6 +- .../comp/Calc/NLPSolver/BaseNLPSolver.java | 30 ++++---- .../comp/Calc/NLPSolver/ResourceManager.java | 4 +- .../Calc/NLPSolver/dialogs/BaseDialog.java | 20 +++--- .../dialogs/EvolutionarySolverStatusUno.java | 2 +- .../dialogs/controls/BaseControl.java | 8 +-- .../NLPSolver/dialogs/controls/Button.java | 2 +- .../dialogs/controls/ProgressBar.java | 2 +- .../DevelopersGuide/Charts/CalcHelper.java | 54 +++++++------- .../DevelopersGuide/Charts/ChartHelper.java | 56 +++++++-------- .../DevelopersGuide/Charts/ChartInCalc.java | 42 +++++------ .../DevelopersGuide/Charts/ChartInDraw.java | 20 +++--- .../DevelopersGuide/Charts/ChartInWriter.java | 10 +-- .../DevelopersGuide/Charts/Helper.java | 11 ++- .../Charts/JavaSampleChartAddIn.java | 58 +++++++-------- .../Charts/ListenAtCalcRangeInDraw.java | 28 ++++---- .../Charts/SelectionChangeListener.java | 26 +++---- .../Components/Addons/JobsAddon/AsyncJob.java | 6 +- 48 files changed, 373 insertions(+), 379 deletions(-) diff --git a/bridges/test/java_uno/acquire/TestAcquire.java b/bridges/test/java_uno/acquire/TestAcquire.java index 33d3605e1827..0aa2b0f639e7 100644 --- a/bridges/test/java_uno/acquire/TestAcquire.java +++ b/bridges/test/java_uno/acquire/TestAcquire.java @@ -65,17 +65,17 @@ public final class TestAcquire { WaitUnreachable u; u = new WaitUnreachable(new XInterface() {}); - test.setInterfaceToInterface((XInterface) u.get()); + test.setInterfaceToInterface(u.get()); receive(test.getInterfaceFromInterface()); test.clearInterface(); u.waitUnreachable(); u = new WaitUnreachable(new XBase() {}); - test.setInterfaceToInterface((XBase) u.get()); + test.setInterfaceToInterface(u.get()); receive(test.getInterfaceFromInterface()); test.clearInterface(); u.waitUnreachable(); u = new WaitUnreachable(new XDerived() {}); - test.setInterfaceToInterface((XDerived) u.get()); + test.setInterfaceToInterface(u.get()); receive(test.getInterfaceFromInterface()); test.clearInterface(); u.waitUnreachable(); @@ -126,13 +126,13 @@ public final class TestAcquire { u.waitUnreachable(); u = new WaitUnreachable(new XInterface() {}); - receive(test.roundTripInterfaceToInterface((XInterface) u.get())); + receive(test.roundTripInterfaceToInterface(u.get())); u.waitUnreachable(); u = new WaitUnreachable(new XBase() {}); - receive(test.roundTripInterfaceToInterface((XBase) u.get())); + receive(test.roundTripInterfaceToInterface(u.get())); u.waitUnreachable(); u = new WaitUnreachable(new XDerived() {}); - receive(test.roundTripInterfaceToInterface((XDerived) u.get())); + receive(test.roundTripInterfaceToInterface(u.get())); u.waitUnreachable(); u = new WaitUnreachable(new XBase() {}); diff --git a/bridges/test/testclient.java b/bridges/test/testclient.java index 135030c5fa80..e52b70385845 100644 --- a/bridges/test/testclient.java +++ b/bridges/test/testclient.java @@ -117,7 +117,7 @@ public class testclient { System.out.println( "after connect" ); String rootOid = "OfficeDaemon.Factory"; - com.sun.star.uno.IBridge bridge = (IBridge ) UnoRuntime.getBridgeByName( + com.sun.star.uno.IBridge bridge = UnoRuntime.getBridgeByName( "java", null, "remote", diff --git a/chart2/qa/TestCaseOldAPI.java b/chart2/qa/TestCaseOldAPI.java index 5792f52483c3..be1f911be55b 100644 --- a/chart2/qa/TestCaseOldAPI.java +++ b/chart2/qa/TestCaseOldAPI.java @@ -113,7 +113,7 @@ public class TestCaseOldAPI extends ComplexTestCase { else mxChartModel = createChartModel(); - mxOldDoc = (XChartDocument) UnoRuntime.queryInterface( + mxOldDoc = UnoRuntime.queryInterface( XChartDocument.class, mxChartModel ); } @@ -121,7 +121,7 @@ public class TestCaseOldAPI extends ComplexTestCase { public void after() { - XCloseable xCloseable = (XCloseable) UnoRuntime.queryInterface( + XCloseable xCloseable = UnoRuntime.queryInterface( XCloseable.class, mxChartModel ); assure( "document is no XCloseable", xCloseable != null ); @@ -146,7 +146,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { try { - XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xDocProp = UnoRuntime.queryInterface( XPropertySet.class, mxOldDoc ); assure( "Chart Document is no XPropertySet", xDocProp != null ); xDocProp.setPropertyValue( "HasMainTitle", new Boolean( true )); @@ -154,7 +154,7 @@ public class TestCaseOldAPI extends ComplexTestCase { xDocProp.getPropertyValue( "HasMainTitle" ))); XShape xTitleShape = mxOldDoc.getTitle(); - XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xTitleProp = UnoRuntime.queryInterface( XPropertySet.class, xTitleShape ); // set property via old API @@ -196,7 +196,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { try { - XPropertySet xDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xDocProp = UnoRuntime.queryInterface( XPropertySet.class, mxOldDoc ); assure( "Chart Document is no XPropertySet", xDocProp != null ); xDocProp.setPropertyValue( "HasSubTitle", new Boolean( true )); @@ -204,7 +204,7 @@ public class TestCaseOldAPI extends ComplexTestCase { xDocProp.getPropertyValue( "HasSubTitle" ))); XShape xTitleShape = mxOldDoc.getSubTitle(); - XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xTitleProp = UnoRuntime.queryInterface( XPropertySet.class, xTitleShape ); // set Property via old API @@ -245,7 +245,7 @@ public class TestCaseOldAPI extends ComplexTestCase { XDiagram xDia = mxOldDoc.getDiagram(); if( xDia != null ) { - X3DDisplay xDisp = (X3DDisplay) UnoRuntime.queryInterface( + X3DDisplay xDisp = UnoRuntime.queryInterface( X3DDisplay.class, xDia ); assure( "X3DDisplay not supported", xDisp != null ); @@ -263,7 +263,7 @@ public class TestCaseOldAPI extends ComplexTestCase { "com.sun.star.chart.BarDiagram" )); // Diagram properties - xProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xDia ); + xProp = UnoRuntime.queryInterface( XPropertySet.class, xDia ); assure( "Diagram is no property set", xProp != null ); // y-axis @@ -295,7 +295,7 @@ public class TestCaseOldAPI extends ComplexTestCase { xProp.getPropertyValue( "HasSecondaryYAxis" )); assure( "Adding a second y-axis does not work", bNewSecYAxisValue == bSecondaryYAxis ); - XTwoAxisYSupplier xSecYAxisSuppl = (XTwoAxisYSupplier) UnoRuntime.queryInterface( + XTwoAxisYSupplier xSecYAxisSuppl = UnoRuntime.queryInterface( XTwoAxisYSupplier.class, xDia ); assure( "XTwoAxisYSupplier not implemented", xSecYAxisSuppl != null ); assure( "No second y-axis found", xSecYAxisSuppl.getSecondaryYAxis() != null ); @@ -303,7 +303,7 @@ public class TestCaseOldAPI extends ComplexTestCase { // move diagram { - XShape xDiagramShape = (XShape) UnoRuntime.queryInterface( + XShape xDiagramShape = UnoRuntime.queryInterface( XShape.class, xDia ); Point aOldPos = xDiagramShape.getPosition(); @@ -323,7 +323,7 @@ public class TestCaseOldAPI extends ComplexTestCase { // size diagram { - XShape xDiagramShape = (XShape) UnoRuntime.queryInterface( + XShape xDiagramShape = UnoRuntime.queryInterface( XShape.class, xDia ); Size aOldSize = xDiagramShape.getSize(); @@ -354,7 +354,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { try { - XAxisYSupplier xYAxisSuppl = (XAxisYSupplier) UnoRuntime.queryInterface( + XAxisYSupplier xYAxisSuppl = UnoRuntime.queryInterface( XAxisYSupplier.class, mxOldDoc.getDiagram() ); assure( "Diagram is no y-axis supplier", xYAxisSuppl != null ); @@ -452,7 +452,7 @@ public class TestCaseOldAPI extends ComplexTestCase { XShape xLegend = mxOldDoc.getLegend(); assure( "No Legend returned", xLegend != null ); - XPropertySet xLegendProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xLegendProp = UnoRuntime.queryInterface( XPropertySet.class, xLegend ); assure( "Legend is no property set", xLegendProp != null ); @@ -532,7 +532,7 @@ public class TestCaseOldAPI extends ComplexTestCase { public void testChartType() { - XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( + XMultiServiceFactory xFact = UnoRuntime.queryInterface( XMultiServiceFactory.class, mxOldDoc ); assure( "document is no factory", xFact != null ); @@ -553,13 +553,13 @@ public class TestCaseOldAPI extends ComplexTestCase { if( bServiceFound ) { - XDiagram xDia = (XDiagram) UnoRuntime.queryInterface( + XDiagram xDia = UnoRuntime.queryInterface( XDiagram.class, xFact.createInstance( aMyServiceName )); assure( aMyServiceName + " could not be created", xDia != null ); mxOldDoc.setDiagram( xDia ); - XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xDiaProp = UnoRuntime.queryInterface( XPropertySet.class, xDia ); assure( "Diagram is no XPropertySet", xDiaProp != null ); @@ -599,11 +599,11 @@ public class TestCaseOldAPI extends ComplexTestCase { public void testAggregation() { // query to new type - XChartDocument xDiaProv = (XChartDocument) UnoRuntime.queryInterface( + XChartDocument xDiaProv = UnoRuntime.queryInterface( XChartDocument.class, mxOldDoc ); assure( "query to new interface failed", xDiaProv != null ); - com.sun.star.chart.XChartDocument xDoc = (com.sun.star.chart.XChartDocument) UnoRuntime.queryInterface( + com.sun.star.chart.XChartDocument xDoc = UnoRuntime.queryInterface( com.sun.star.chart.XChartDocument.class, xDiaProv ); assure( "querying back to old interface failed", xDoc != null ); } @@ -616,7 +616,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { XDiagram xDia = mxOldDoc.getDiagram(); assure( "Invalid Diagram", xDia != null ); - XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( + XMultiServiceFactory xFact = UnoRuntime.queryInterface( XMultiServiceFactory.class, mxOldDoc ); assure( "document is no factory", xFact != null ); @@ -632,7 +632,7 @@ public class TestCaseOldAPI extends ComplexTestCase { // note: the FillGradient property is optional, however it was // supported in the old chart's API - XNameContainer xGradientTable = (XNameContainer) UnoRuntime.queryInterface( + XNameContainer xGradientTable = UnoRuntime.queryInterface( XNameContainer.class, xFact.createInstance( "com.sun.star.drawing.GradientTable" )); assure( "no gradient table", xGradientTable != null ); @@ -674,7 +674,7 @@ public class TestCaseOldAPI extends ComplexTestCase { // note: the FillHatch property is optional, however it was // supported in the old chart's API - XNameContainer xHatchTable = (XNameContainer) UnoRuntime.queryInterface( + XNameContainer xHatchTable = UnoRuntime.queryInterface( XNameContainer.class, xFact.createInstance( "com.sun.star.drawing.HatchTable" )); assure( "no hatch table", xHatchTable != null ); @@ -735,7 +735,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { try { - XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xDiaProp = UnoRuntime.queryInterface( XPropertySet.class, mxOldDoc.getDiagram() ); ChartDataRowSource eNewSource = ChartDataRowSource.ROWS; @@ -766,7 +766,7 @@ public class TestCaseOldAPI extends ComplexTestCase { XChartData xData = mxOldDoc.getData(); - XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface( + XChartDataArray xDataArray = UnoRuntime.queryInterface( XChartDataArray.class, xData ); assure( "document has no XChartDataArray", xDataArray != null ); @@ -791,18 +791,18 @@ public class TestCaseOldAPI extends ComplexTestCase { { setStockData_Type4(); - XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( + XMultiServiceFactory xFact = UnoRuntime.queryInterface( XMultiServiceFactory.class, mxOldDoc ); assure( "document is no factory", xFact != null ); String aMyServiceName = new String( "com.sun.star.chart.StockDiagram" ); - XDiagram xDia = (XDiagram) UnoRuntime.queryInterface( + XDiagram xDia = UnoRuntime.queryInterface( XDiagram.class, xFact.createInstance( aMyServiceName )); assure( aMyServiceName + " could not be created", xDia != null ); mxOldDoc.setDiagram( xDia ); - XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xDiaProp = UnoRuntime.queryInterface( XPropertySet.class, xDia ); assure( "Diagram is no XPropertySet", xDiaProp != null ); @@ -813,7 +813,7 @@ public class TestCaseOldAPI extends ComplexTestCase { assure( "Has UpDown", AnyConverter.toBoolean( xDiaProp.getPropertyValue( "UpDown" ))); // MinMaxLine - XStatisticDisplay xMinMaxProvider = (XStatisticDisplay) UnoRuntime.queryInterface( + XStatisticDisplay xMinMaxProvider = UnoRuntime.queryInterface( XStatisticDisplay.class, xDia ); assure( "Diagram is no XStatisticDisplay", xMinMaxProvider != null ); XPropertySet xMinMaxProp = xMinMaxProvider.getMinMaxLine(); @@ -837,7 +837,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { try { - XMultiServiceFactory xFact = (XMultiServiceFactory) UnoRuntime.queryInterface( + XMultiServiceFactory xFact = UnoRuntime.queryInterface( XMultiServiceFactory.class, mxOldDoc ); assure( "document is no factory", xFact != null ); @@ -873,7 +873,7 @@ public class TestCaseOldAPI extends ComplexTestCase { "First Row", "Second Row", "Third Row" }; - XPropertySet xDiaProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xDiaProp = UnoRuntime.queryInterface( XPropertySet.class, mxOldDoc.getDiagram() ); ChartDataRowSource eNewSource = ChartDataRowSource.ROWS; xDiaProp.setPropertyValue( "DataRowSource", eNewSource ); @@ -883,7 +883,7 @@ public class TestCaseOldAPI extends ComplexTestCase { xDiaProp.getPropertyValue( "DataRowSource" )) == eNewSource ); XChartData xData = mxOldDoc.getData(); - XChartDataArray xDataArray = (XChartDataArray) UnoRuntime.queryInterface( + XChartDataArray xDataArray = UnoRuntime.queryInterface( XChartDataArray.class, xData ); assure( "document has no XChartDataArray", xDataArray != null ); @@ -900,7 +900,7 @@ public class TestCaseOldAPI extends ComplexTestCase { // refetch data xData = mxOldDoc.getData(); - xDataArray = (XChartDataArray) UnoRuntime.queryInterface( + xDataArray = UnoRuntime.queryInterface( XChartDataArray.class, xData ); assure( "document has no XChartDataArray", xDataArray != null ); @@ -945,11 +945,11 @@ public class TestCaseOldAPI extends ComplexTestCase { XModel aResult = null; try { - XComponentLoader aLoader = (XComponentLoader) UnoRuntime.queryInterface( + XComponentLoader aLoader = UnoRuntime.queryInterface( XComponentLoader.class, ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.frame.Desktop" ) ); - aResult = (XModel) UnoRuntime.queryInterface( + aResult = UnoRuntime.queryInterface( XModel.class, aLoader.loadComponentFromURL( "private:factory/" + sDocType, "_blank", @@ -972,7 +972,7 @@ public class TestCaseOldAPI extends ComplexTestCase { XModel aResult = null; try { - aResult = (XModel) UnoRuntime.queryInterface( + aResult = UnoRuntime.queryInterface( XModel.class, ((XMultiServiceFactory)param.getMSF()).createInstance( "com.sun.star.comp.chart2.ChartModel" ) ); } @@ -991,7 +991,7 @@ public class TestCaseOldAPI extends ComplexTestCase { { XComponentContext xResult = null; - XPropertySet xProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet xProp = UnoRuntime.queryInterface( XPropertySet.class, xFact ); if( xProp != null ) try diff --git a/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java index 13afecfb9746..20a341201ca3 100644 --- a/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java +++ b/connectivity/com/sun/star/sdbcx/comp/hsqldb/StorageAccess.java @@ -97,6 +97,7 @@ public class StorageAccess implements org.hsqldb.lib.Storage { return readonly; } + @SuppressWarnings("cast") public long readLong() throws java.io.IOException { return (((long) readInt()) << 32) + (((long) readInt()) & 0xFFFFFFFFL); } diff --git a/dbaccess/qa/complex/dbaccess/PropertyBag.java b/dbaccess/qa/complex/dbaccess/PropertyBag.java index 02389a783665..83bbee891d6c 100644 --- a/dbaccess/qa/complex/dbaccess/PropertyBag.java +++ b/dbaccess/qa/complex/dbaccess/PropertyBag.java @@ -294,7 +294,7 @@ public class PropertyBag extends TestCase { "BoolValue", Boolean.TRUE }, { "StringValue", "" }, { "IntegerValue", Integer.valueOf( 3 ) }, - { "InterfaceValue", (XInterface)m_bag } + { "InterfaceValue", m_bag } }; for ( int i=0; i 0; i-- ) { aSheetsNC.removeByName( - ( (XNamed) UnoRuntime.queryInterface( - XNamed.class, aSheetsIA.getByIndex( i ) )).getName() ); + UnoRuntime.queryInterface( + XNamed.class, aSheetsIA.getByIndex( i ) ).getName() ); } - XNamed aFirstSheet = (XNamed) UnoRuntime.queryInterface( + XNamed aFirstSheet = UnoRuntime.queryInterface( XNamed.class, aSheetsIA.getByIndex( 0 )); diff --git a/odk/examples/DevelopersGuide/Charts/ChartHelper.java b/odk/examples/DevelopersGuide/Charts/ChartHelper.java index 8f01b52aa426..977983ecbce7 100644 --- a/odk/examples/DevelopersGuide/Charts/ChartHelper.java +++ b/odk/examples/DevelopersGuide/Charts/ChartHelper.java @@ -74,29 +74,27 @@ public class ChartHelper { XChartDocument aResult = null; - XMultiServiceFactory aFact = (XMultiServiceFactory) - UnoRuntime.queryInterface(XMultiServiceFactory.class, - maContainerDocument ); + XMultiServiceFactory aFact = UnoRuntime.queryInterface(XMultiServiceFactory.class, + maContainerDocument ); if( aFact != null ) { try { - XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface( + XTextContent xTextContent = UnoRuntime.queryInterface( XTextContent.class, aFact.createInstance("com.sun.star.text.TextEmbeddedObject")); if ( xTextContent != null ) { - XPropertySet xPropSet = (XPropertySet)UnoRuntime.queryInterface( + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextContent); Any aAny = new Any(String.class, msChartClassID); xPropSet.setPropertyValue("CLSID", aAny ); - XTextDocument xTextDoc = (XTextDocument) - UnoRuntime.queryInterface(XTextDocument.class, - maContainerDocument); + XTextDocument xTextDoc = UnoRuntime.queryInterface(XTextDocument.class, + maContainerDocument); XText xText = xTextDoc.getText(); XTextCursor xCursor = xText.createTextCursor(); @@ -104,7 +102,7 @@ public class ChartHelper xText.insertTextContent( xCursor, xTextContent, true ); // set size and position - XShape xShape = (XShape)UnoRuntime.queryInterface( + XShape xShape = UnoRuntime.queryInterface( XShape.class, xTextContent); xShape.setSize( aExtent ); @@ -120,18 +118,18 @@ public class ChartHelper xPropSet.setPropertyValue("HoriOrientPosition", aAny ); // retrieve the chart document as model of the OLE shape - aResult = (XChartDocument) UnoRuntime.queryInterface( + aResult = UnoRuntime.queryInterface( XChartDocument.class, xPropSet.getPropertyValue( "Model" )); // create a diagram via the factory and set this as // new diagram aResult.setDiagram( - (XDiagram) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XDiagram.class, - ((XMultiServiceFactory) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XMultiServiceFactory.class, - aResult )).createInstance(sChartServiceName ))); + aResult ).createInstance(sChartServiceName ))); } } catch( Exception ex) { @@ -153,16 +151,15 @@ public class ChartHelper XShapes aPage = null; // try interface for multiple pages in a document - XDrawPagesSupplier aSupplier = (XDrawPagesSupplier) - UnoRuntime.queryInterface(XDrawPagesSupplier.class, - maContainerDocument ); + XDrawPagesSupplier aSupplier = UnoRuntime.queryInterface(XDrawPagesSupplier.class, + maContainerDocument ); if( aSupplier != null ) { try { // get first page - aPage = (XShapes) UnoRuntime.queryInterface( + aPage = UnoRuntime.queryInterface( XShapes.class, aSupplier.getDrawPages().getByIndex( 0 ) ); } catch( Exception ex ) @@ -174,29 +171,27 @@ public class ChartHelper else { // try interface for single draw page (e.g. spreadsheet) - XDrawPageSupplier aOnePageSupplier = (XDrawPageSupplier) - UnoRuntime.queryInterface(XDrawPageSupplier.class, - maContainerDocument ); + XDrawPageSupplier aOnePageSupplier = UnoRuntime.queryInterface(XDrawPageSupplier.class, + maContainerDocument ); if( aOnePageSupplier != null ) { - aPage = (XShapes) UnoRuntime.queryInterface( + aPage = UnoRuntime.queryInterface( XShapes.class, aOnePageSupplier.getDrawPage()); } } if( aPage != null ) { - XMultiServiceFactory aFact = (XMultiServiceFactory) - UnoRuntime.queryInterface(XMultiServiceFactory.class, - maContainerDocument ); + XMultiServiceFactory aFact = UnoRuntime.queryInterface(XMultiServiceFactory.class, + maContainerDocument ); if( aFact != null ) { try { // create an OLE shape - XShape aShape = (XShape) UnoRuntime.queryInterface( + XShape aShape = UnoRuntime.queryInterface( XShape.class, aFact.createInstance( "com.sun.star.drawing.OLE2Shape" )); @@ -206,26 +201,25 @@ public class ChartHelper aShape.setSize( aExtent ); // make the OLE shape a chart - XPropertySet aShapeProp = (XPropertySet) - UnoRuntime.queryInterface(XPropertySet.class, aShape ); + XPropertySet aShapeProp = UnoRuntime.queryInterface(XPropertySet.class, aShape ); if( aShapeProp != null ) { // set the class id for charts aShapeProp.setPropertyValue( "CLSID", msChartClassID ); // retrieve the chart document as model of the OLE shape - aResult = (XChartDocument) UnoRuntime.queryInterface( + aResult = UnoRuntime.queryInterface( XChartDocument.class, aShapeProp.getPropertyValue( "Model" )); // create a diagram via the factory and set this as // new diagram aResult.setDiagram( - (XDiagram) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XDiagram.class, - ((XMultiServiceFactory) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XMultiServiceFactory.class, - aResult )).createInstance(sChartServiceName ))); + aResult ).createInstance(sChartServiceName ))); } } catch( Exception ex ) diff --git a/odk/examples/DevelopersGuide/Charts/ChartInCalc.java b/odk/examples/DevelopersGuide/Charts/ChartInCalc.java index f5e4b116ac7d..62042b95b5b7 100644 --- a/odk/examples/DevelopersGuide/Charts/ChartInCalc.java +++ b/odk/examples/DevelopersGuide/Charts/ChartInCalc.java @@ -80,8 +80,8 @@ public class ChartInCalc // insert a cell range with 4 columns and 24 rows filled with random numbers XCellRange aRange = aCalcHelper.insertRandomRange( 4, 24 ); - CellRangeAddress aRangeAddress = ((XCellRangeAddressable) UnoRuntime.queryInterface( - XCellRangeAddressable.class, aRange)).getRangeAddress(); + CellRangeAddress aRangeAddress = UnoRuntime.queryInterface( + XCellRangeAddressable.class, aRange).getRangeAddress(); // change view to sheet containing the chart aCalcHelper.raiseChartSheet(); @@ -150,7 +150,7 @@ public class ChartInCalc public void lockControllers() throws RuntimeException { - ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers(); + UnoRuntime.queryInterface( XModel.class, maChartDocument ).lockControllers(); } // ____________________ @@ -158,7 +158,7 @@ public class ChartInCalc public void unlockControllers() throws RuntimeException { - ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers(); + UnoRuntime.queryInterface( XModel.class, maChartDocument ).unlockControllers(); } // ____________________ @@ -167,7 +167,7 @@ public class ChartInCalc throws RuntimeException, UnknownPropertyException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException { - XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, maDiagram ); + XPropertySet aDiaProp = UnoRuntime.queryInterface( XPropertySet.class, maDiagram ); if( aDiaProp != null ) { @@ -237,7 +237,7 @@ public class ChartInCalc // determine the maximum value of the first series int nMaxIndex = 0; - XChartDataArray aDataArray = (XChartDataArray) UnoRuntime.queryInterface( + XChartDataArray aDataArray = UnoRuntime.queryInterface( XChartDataArray.class, maChartDocument.getData()); double aData[][] = aDataArray.getData(); @@ -293,8 +293,8 @@ public class ChartInCalc throws RuntimeException, UnknownPropertyException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException { - XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface( - X3DDisplay.class, maDiagram )).getWall(); + XPropertySet aWall = UnoRuntime.queryInterface( + X3DDisplay.class, maDiagram ).getWall(); // change background color of area aWall.setPropertyValue( "FillStyle", FillStyle.SOLID ); @@ -308,12 +308,12 @@ public class ChartInCalc com.sun.star.lang.IllegalArgumentException, WrappedTargetException { // change main title - XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aDocProp = UnoRuntime.queryInterface( XPropertySet.class, maChartDocument ); aDocProp.setPropertyValue( "HasMainTitle", new Boolean( true )); XShape aTitle = maChartDocument.getTitle(); - XPropertySet aTitleProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aTitle ); + XPropertySet aTitleProp = UnoRuntime.queryInterface( XPropertySet.class, aTitle ); // set new text if( aTitleProp != null ) @@ -323,9 +323,9 @@ public class ChartInCalc } // align title with y axis - XShape aAxis = (XShape) UnoRuntime.queryInterface( - XShape.class, ((XAxisYSupplier) UnoRuntime.queryInterface( - XAxisYSupplier.class, maDiagram )).getYAxis() ); + XShape aAxis = UnoRuntime.queryInterface( + XShape.class, UnoRuntime.queryInterface( + XAxisYSupplier.class, maDiagram ).getYAxis() ); if( aAxis != null && aTitle != null ) @@ -344,8 +344,8 @@ public class ChartInCalc MalformedNumberFormatException { // x axis - XPropertySet aAxisProp = ((XAxisXSupplier) UnoRuntime.queryInterface( - XAxisXSupplier.class, maDiagram )).getXAxis(); + XPropertySet aAxisProp = UnoRuntime.queryInterface( + XAxisXSupplier.class, maDiagram ).getXAxis(); if( aAxisProp != null ) { aAxisProp.setPropertyValue( "Max", new Integer( 24 )); @@ -353,12 +353,12 @@ public class ChartInCalc } // change number format for y axis - aAxisProp = ((XAxisYSupplier) UnoRuntime.queryInterface( - XAxisYSupplier.class, maDiagram )).getYAxis(); + aAxisProp = UnoRuntime.queryInterface( + XAxisYSupplier.class, maDiagram ).getYAxis(); // add a new custom number format and get the new key int nNewNumberFormat = 0; - XNumberFormatsSupplier aNumFmtSupp = (XNumberFormatsSupplier) UnoRuntime.queryInterface( + XNumberFormatsSupplier aNumFmtSupp = UnoRuntime.queryInterface( XNumberFormatsSupplier.class, maChartDocument ); if( aNumFmtSupp != null ) @@ -383,10 +383,10 @@ public class ChartInCalc com.sun.star.lang.IllegalArgumentException, WrappedTargetException { // y major grid - XPropertySet aGridProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aGridProp = UnoRuntime.queryInterface( XPropertySet.class, - ( (XAxisYSupplier) UnoRuntime.queryInterface( - XAxisYSupplier.class, maDiagram )).getYMainGrid()); + UnoRuntime.queryInterface( + XAxisYSupplier.class, maDiagram ).getYMainGrid()); if( aGridProp != null ) { diff --git a/odk/examples/DevelopersGuide/Charts/ChartInDraw.java b/odk/examples/DevelopersGuide/Charts/ChartInDraw.java index 362c1b731c32..f7fbb2cff263 100644 --- a/odk/examples/DevelopersGuide/Charts/ChartInDraw.java +++ b/odk/examples/DevelopersGuide/Charts/ChartInDraw.java @@ -121,7 +121,7 @@ public class ChartInDraw public void lockControllers() throws RuntimeException { - ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers(); + UnoRuntime.queryInterface( XModel.class, maChartDocument ).lockControllers(); } // ____________________ @@ -129,7 +129,7 @@ public class ChartInDraw public void unlockControllers() throws RuntimeException { - ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers(); + UnoRuntime.queryInterface( XModel.class, maChartDocument ).unlockControllers(); } // ____________________ @@ -154,8 +154,8 @@ public class ChartInDraw throws RuntimeException, UnknownPropertyException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException { - XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface( - X3DDisplay.class, maDiagram )).getWall(); + XPropertySet aWall = UnoRuntime.queryInterface( + X3DDisplay.class, maDiagram ).getWall(); // change background color of area aWall.setPropertyValue( "FillColor", new Integer( 0xcccccc )); @@ -169,12 +169,12 @@ public class ChartInDraw com.sun.star.lang.IllegalArgumentException, WrappedTargetException { // change main title - XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aDocProp = UnoRuntime.queryInterface( XPropertySet.class, maChartDocument ); aDocProp.setPropertyValue( "HasMainTitle", new Boolean( true )); XShape aTitle = maChartDocument.getTitle(); - XPropertySet aTitleProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aTitle ); + XPropertySet aTitleProp = UnoRuntime.queryInterface( XPropertySet.class, aTitle ); // set new text if( aTitleProp != null ) @@ -190,7 +190,7 @@ public class ChartInDraw com.sun.star.lang.IllegalArgumentException, WrappedTargetException { XShape aLegend = maChartDocument.getLegend(); - XPropertySet aLegendProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, aLegend ); + XPropertySet aLegendProp = UnoRuntime.queryInterface( XPropertySet.class, aLegend ); aLegendProp.setPropertyValue( "Alignment", ChartLegendPosition.LEFT ); aLegendProp.setPropertyValue( "FillStyle", FillStyle.SOLID ); @@ -204,7 +204,7 @@ public class ChartInDraw com.sun.star.lang.IllegalArgumentException, WrappedTargetException, com.sun.star.lang.IndexOutOfBoundsException { - XPropertySet aDiaProp = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, maDiagram ); + XPropertySet aDiaProp = UnoRuntime.queryInterface( XPropertySet.class, maDiagram ); Boolean aTrue = new Boolean( true ); aDiaProp.setPropertyValue( "Dim3D", aTrue ); @@ -213,8 +213,8 @@ public class ChartInDraw aDiaProp.setPropertyValue( "SolidType", new Integer( ChartSolidType.CYLINDER )); // change floor color to Magenta6 - XPropertySet aFloor = ((X3DDisplay) UnoRuntime.queryInterface( - X3DDisplay.class, maDiagram )).getFloor(); + XPropertySet aFloor = UnoRuntime.queryInterface( + X3DDisplay.class, maDiagram ).getFloor(); aFloor.setPropertyValue( "FillColor", new Integer( 0x6b2394 )); // apply changes to get a 3d scene diff --git a/odk/examples/DevelopersGuide/Charts/ChartInWriter.java b/odk/examples/DevelopersGuide/Charts/ChartInWriter.java index 30ff75a7e060..6506cb92f32e 100644 --- a/odk/examples/DevelopersGuide/Charts/ChartInWriter.java +++ b/odk/examples/DevelopersGuide/Charts/ChartInWriter.java @@ -73,7 +73,7 @@ public class ChartInWriter Helper aHelper = new Helper( args ); ChartHelper aChartHelper = new ChartHelper( - (XModel) UnoRuntime.queryInterface( XModel.class, + UnoRuntime.queryInterface( XModel.class, aHelper.createTextDocument())); // the unit for measures is 1/100th of a millimeter @@ -126,7 +126,7 @@ public class ChartInWriter public void lockControllers() throws RuntimeException { - ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).lockControllers(); + UnoRuntime.queryInterface( XModel.class, maChartDocument ).lockControllers(); } // ____________________ @@ -134,7 +134,7 @@ public class ChartInWriter public void unlockControllers() throws RuntimeException { - ((XModel) UnoRuntime.queryInterface( XModel.class, maChartDocument )).unlockControllers(); + UnoRuntime.queryInterface( XModel.class, maChartDocument ).unlockControllers(); } // ____________________ @@ -143,8 +143,8 @@ public class ChartInWriter throws RuntimeException, UnknownPropertyException, PropertyVetoException, com.sun.star.lang.IllegalArgumentException, WrappedTargetException { - XPropertySet aWall = ((X3DDisplay) UnoRuntime.queryInterface( - X3DDisplay.class, maDiagram )).getWall(); + XPropertySet aWall = UnoRuntime.queryInterface( + X3DDisplay.class, maDiagram ).getWall(); // change background color of area aWall.setPropertyValue( "FillColor", new Integer( 0xeecc99 )); diff --git a/odk/examples/DevelopersGuide/Charts/Helper.java b/odk/examples/DevelopersGuide/Charts/Helper.java index 6c7e2c316030..92ba8c476474 100644 --- a/odk/examples/DevelopersGuide/Charts/Helper.java +++ b/odk/examples/DevelopersGuide/Charts/Helper.java @@ -75,7 +75,7 @@ public class Helper public XSpreadsheetDocument createSpreadsheetDocument() { - return (XSpreadsheetDocument) UnoRuntime.queryInterface( + return UnoRuntime.queryInterface( XSpreadsheetDocument.class, createDocument( "scalc" )); } @@ -107,12 +107,11 @@ public class Helper XModel aResult = null; try { - XComponentLoader aLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, - maMCFactory.createInstanceWithContext("com.sun.star.frame.Desktop", - maContext) ); + XComponentLoader aLoader = UnoRuntime.queryInterface(XComponentLoader.class, + maMCFactory.createInstanceWithContext("com.sun.star.frame.Desktop", + maContext) ); - aResult = (XModel) UnoRuntime.queryInterface( + aResult = UnoRuntime.queryInterface( XModel.class, aLoader.loadComponentFromURL( "private:factory/" + sDocType, "_blank", diff --git a/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java b/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java index 3ddb9d814fd3..4a8b1ec46b12 100644 --- a/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java +++ b/odk/examples/DevelopersGuide/Charts/JavaSampleChartAddIn.java @@ -80,10 +80,10 @@ public class JavaSampleChartAddIn extends WeakBase implements { if( aArguments.length > 0 ) { - maChartDocument = (XChartDocument) UnoRuntime.queryInterface( + maChartDocument = UnoRuntime.queryInterface( XChartDocument.class, aArguments[ 0 ]); - XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aDocProp = UnoRuntime.queryInterface( XPropertySet.class, maChartDocument ); if( aDocProp != null ) { @@ -92,14 +92,14 @@ public class JavaSampleChartAddIn extends WeakBase implements } // get the draw page - XDrawPageSupplier aPageSupp = (XDrawPageSupplier) UnoRuntime.queryInterface( + XDrawPageSupplier aPageSupp = UnoRuntime.queryInterface( XDrawPageSupplier.class, maChartDocument ); if( aPageSupp != null ) - maDrawPage = (XDrawPage) UnoRuntime.queryInterface( + maDrawPage = UnoRuntime.queryInterface( XDrawPage.class, aPageSupp.getDrawPage() ); // get a factory for creating shapes - maShapeFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( + maShapeFactory = UnoRuntime.queryInterface( XMultiServiceFactory.class, maChartDocument ); } } @@ -112,13 +112,13 @@ public class JavaSampleChartAddIn extends WeakBase implements maTopLine == null ) { // try to recycle loaded shapes - XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aDocProp = UnoRuntime.queryInterface( XPropertySet.class, maChartDocument ); if( aDocProp != null ) { try { - XIndexAccess aShapesIA = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess aShapesIA = UnoRuntime.queryInterface( XIndexAccess.class, aDocProp.getPropertyValue( "AdditionalShapes" )); if( aShapesIA != null && aShapesIA.getCount() > 0 ) @@ -127,11 +127,11 @@ public class JavaSampleChartAddIn extends WeakBase implements String aName; for( int i = aShapesIA.getCount() - 1; i >= 0; --i ) { - aShape = (XShape) UnoRuntime.queryInterface( + aShape = UnoRuntime.queryInterface( XShape.class, aShapesIA.getByIndex( i )); if( aShape != null ) { - XPropertySet aProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aProp = UnoRuntime.queryInterface( XPropertySet.class, aShape ); aName = (String) aProp.getPropertyValue( "Name" ); @@ -159,12 +159,12 @@ public class JavaSampleChartAddIn extends WeakBase implements { if( maTopLine == null ) { - maTopLine = (XShape) UnoRuntime.queryInterface( + maTopLine = UnoRuntime.queryInterface( XShape.class, maShapeFactory.createInstance( "com.sun.star.drawing.LineShape" )); maDrawPage.add( maTopLine ); // make line red and thicker - XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aShapeProp = UnoRuntime.queryInterface( XPropertySet.class, maTopLine ); aShapeProp.setPropertyValue( "LineColor", new Integer( 0xe01010 )); @@ -182,12 +182,12 @@ public class JavaSampleChartAddIn extends WeakBase implements { if( maBottomLine == null ) { - maBottomLine = (XShape) UnoRuntime.queryInterface( + maBottomLine = UnoRuntime.queryInterface( XShape.class, maShapeFactory.createInstance( "com.sun.star.drawing.LineShape" )); maDrawPage.add( maBottomLine ); // make line green and thicker - XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aShapeProp = UnoRuntime.queryInterface( XPropertySet.class, maBottomLine ); aShapeProp.setPropertyValue( "LineColor", new Integer( 0x10e010 )); @@ -211,18 +211,18 @@ public class JavaSampleChartAddIn extends WeakBase implements // -------------- // get data - XChartDataArray aDataArray = (XChartDataArray) UnoRuntime.queryInterface( + XChartDataArray aDataArray = UnoRuntime.queryInterface( XChartDataArray.class, maChartDocument.getData()); double aData[][] = aDataArray.getData(); // get axes XDiagram aDiagram = maChartDocument.getDiagram(); - XShape aXAxis = (XShape) UnoRuntime.queryInterface( - XShape.class, ((XAxisXSupplier) UnoRuntime.queryInterface( - XAxisXSupplier.class, aDiagram )).getXAxis() ); - XShape aYAxis = (XShape) UnoRuntime.queryInterface( - XShape.class, ((XAxisYSupplier) UnoRuntime.queryInterface( - XAxisYSupplier.class, aDiagram )).getYAxis() ); + XShape aXAxis = UnoRuntime.queryInterface( + XShape.class, UnoRuntime.queryInterface( + XAxisXSupplier.class, aDiagram ).getXAxis() ); + XShape aYAxis = UnoRuntime.queryInterface( + XShape.class, UnoRuntime.queryInterface( + XAxisYSupplier.class, aDiagram ).getYAxis() ); // calculate points for hull final int nLength = aData.length; @@ -253,11 +253,11 @@ public class JavaSampleChartAddIn extends WeakBase implements // apply point sequences to lines try { - XPropertySet aShapeProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aShapeProp = UnoRuntime.queryInterface( XPropertySet.class, maTopLine ); aShapeProp.setPropertyValue( "PolyPolygon", aMaxPtSeq ); - aShapeProp = (XPropertySet) UnoRuntime.queryInterface( + aShapeProp = UnoRuntime.queryInterface( XPropertySet.class, maBottomLine ); aShapeProp.setPropertyValue( "PolyPolygon", aMinPtSeq ); } @@ -330,20 +330,20 @@ public class JavaSampleChartAddIn extends WeakBase implements // XShape : XDiagram public Size getSize() throws RuntimeException { - return ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).getSize(); + return UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram()).getSize(); } public void setSize( Size aSize ) throws RuntimeException, PropertyVetoException { - ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).setSize( aSize ); + UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram()).setSize( aSize ); } public Point getPosition() throws RuntimeException { - return ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).getPosition(); + return UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram()).getPosition(); } public void setPosition( Point aPos ) throws RuntimeException { - ((XShape) UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram())).setPosition( aPos ); + UnoRuntime.queryInterface( XShape.class, maChartDocument.getDiagram()).setPosition( aPos ); } // XShapeDescriptor : XShape : XDiagram @@ -370,7 +370,7 @@ public class JavaSampleChartAddIn extends WeakBase implements if( aAxis != null ) { - XPropertySet aAxisProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aAxisProp = UnoRuntime.queryInterface( XPropertySet.class, aAxis ); try @@ -386,13 +386,13 @@ public class JavaSampleChartAddIn extends WeakBase implements if( bVertical ) { nResult = aAxis.getPosition().Y + - (int)((double)(aAxis.getSize().Height) * + (int)((aAxis.getSize().Height) * (1.0 - (( fValue - fMin ) / fRange ))); } else { nResult = aAxis.getPosition().X + - (int)((double)(aAxis.getSize().Width) * + (int)((aAxis.getSize().Width) * (( fValue - fMin ) / fRange )); } } diff --git a/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java b/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java index 27cf351be271..266f07a9c728 100644 --- a/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java +++ b/odk/examples/DevelopersGuide/Charts/ListenAtCalcRangeInDraw.java @@ -95,7 +95,7 @@ public class ListenAtCalcRangeInDraw implements XChartDataChangeEventListener "com.sun.star.chart.XYDiagram" ); // attach the data coming from the cell range to the chart - maChartData = (XChartData) UnoRuntime.queryInterface( XChartData.class, aRange ); + maChartData = UnoRuntime.queryInterface( XChartData.class, aRange ); maChartDocument.attachData( maChartData ); } @@ -105,17 +105,17 @@ public class ListenAtCalcRangeInDraw implements XChartDataChangeEventListener { try { - ((XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, maChartDocument )).setPropertyValue( + UnoRuntime.queryInterface( + XPropertySet.class, maChartDocument ).setPropertyValue( "HasSubTitle", new Boolean( true )); // start listening for death of spreadsheet - ((XComponent) UnoRuntime.queryInterface( - XComponent.class, maSheetDoc )).addEventListener( this ); + UnoRuntime.queryInterface( + XComponent.class, maSheetDoc ).addEventListener( this ); // start listening for death of chart - ((XComponent) UnoRuntime.queryInterface( - XComponent.class, maChartDocument )).addEventListener( this ); + UnoRuntime.queryInterface( + XComponent.class, maChartDocument ).addEventListener( this ); //start listening for change of data maChartData.addChartDataChangeEventListener( this ); @@ -146,10 +146,10 @@ public class ListenAtCalcRangeInDraw implements XChartDataChangeEventListener maChartData.removeChartDataChangeEventListener( this ); // remove dispose listeners - ((XComponent) UnoRuntime.queryInterface( - XComponent.class, maSheetDoc )).removeEventListener( this ); - ((XComponent) UnoRuntime.queryInterface( - XComponent.class, maChartDocument )).removeEventListener( this ); + UnoRuntime.queryInterface( + XComponent.class, maSheetDoc ).removeEventListener( this ); + UnoRuntime.queryInterface( + XComponent.class, maChartDocument ).removeEventListener( this ); System.exit( 0 ); } @@ -164,12 +164,12 @@ public class ListenAtCalcRangeInDraw implements XChartDataChangeEventListener try { - XPropertySet aDocProp = (XPropertySet) UnoRuntime.queryInterface( + XPropertySet aDocProp = UnoRuntime.queryInterface( XPropertySet.class, maChartDocument ); aDocProp.setPropertyValue( "HasMainTitle", new Boolean( true )); - ((XPropertySet) UnoRuntime.queryInterface( - XPropertySet.class, maChartDocument.getSubTitle())).setPropertyValue( + UnoRuntime.queryInterface( + XPropertySet.class, maChartDocument.getSubTitle()).setPropertyValue( "String", aTitle ); maChartDocument.attachData( maChartData ); diff --git a/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java b/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java index 0f55fd1ddf00..5c10a0f55433 100644 --- a/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java +++ b/odk/examples/DevelopersGuide/Charts/SelectionChangeListener.java @@ -83,8 +83,8 @@ public class SelectionChangeListener implements XSelectionChangeListener { // insert a cell range with 4 columns and 12 rows filled with random numbers XCellRange aRange = aCalcHelper.insertRandomRange( 4, 12 ); - CellRangeAddress aRangeAddress = ((XCellRangeAddressable) UnoRuntime.queryInterface( - XCellRangeAddressable.class, aRange)).getRangeAddress(); + CellRangeAddress aRangeAddress = UnoRuntime.queryInterface( + XCellRangeAddressable.class, aRange).getRangeAddress(); // change view to sheet containing the chart aCalcHelper.raiseChartSheet(); @@ -113,10 +113,10 @@ public class SelectionChangeListener implements XSelectionChangeListener { while( bTrying ) { // start listening for selection changes - XSelectionSupplier aSelSupp = (XSelectionSupplier) UnoRuntime.queryInterface( + XSelectionSupplier aSelSupp = UnoRuntime.queryInterface( XSelectionSupplier.class, - (((XModel) UnoRuntime.queryInterface( - XModel.class, maChartDocument )).getCurrentController()) ); + (UnoRuntime.queryInterface( + XModel.class, maChartDocument ).getCurrentController()) ); if( aSelSupp != null ) { aSelSupp.addSelectionChangeListener( this ); System.out.println( "Successfully attached as selection change listener" ); @@ -124,7 +124,7 @@ public class SelectionChangeListener implements XSelectionChangeListener { } // start listening for death of Controller - XComponent aComp = (XComponent) UnoRuntime.queryInterface( XComponent.class, aSelSupp ); + XComponent aComp = UnoRuntime.queryInterface( XComponent.class, aSelSupp ); if( aComp != null ) { aComp.addEventListener( this ); System.out.println( "Successfully attached as dispose listener" ); @@ -144,13 +144,13 @@ public class SelectionChangeListener implements XSelectionChangeListener { System.out.println( "disposing called. detaching as listener" ); // stop listening for selection changes - XSelectionSupplier aCtrl = (XSelectionSupplier) UnoRuntime.queryInterface( + XSelectionSupplier aCtrl = UnoRuntime.queryInterface( XSelectionSupplier.class, aSourceObj ); if( aCtrl != null ) aCtrl.removeSelectionChangeListener( this ); // remove as dispose listener - XComponent aComp = (XComponent) UnoRuntime.queryInterface( XComponent.class, aSourceObj ); + XComponent aComp = UnoRuntime.queryInterface( XComponent.class, aSourceObj ); if( aComp != null ) aComp.removeEventListener( this ); @@ -162,7 +162,7 @@ public class SelectionChangeListener implements XSelectionChangeListener { // XSelectionChangeListener public void selectionChanged( EventObject aEvent ) { - XController aCtrl = (XController) UnoRuntime.queryInterface( XController.class, aEvent.Source ); + XController aCtrl = UnoRuntime.queryInterface( XController.class, aEvent.Source ); if( aCtrl != null ) { XMultiComponentFactory mMCF = maContext.getServiceManager(); @@ -195,18 +195,18 @@ public class SelectionChangeListener implements XSelectionChangeListener { Object oDesktop = mMCF.createInstanceWithContext("com.sun.star.frame.Desktop", maContext); Object oToolKit = mMCF.createInstanceWithContext("com.sun.star.awt.Toolkit", maContext); - aDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop); - aToolKit = (XInterface) UnoRuntime.queryInterface(XInterface.class, oToolKit); + aDesktop = UnoRuntime.queryInterface(XDesktop.class, oDesktop); + aToolKit = UnoRuntime.queryInterface(XInterface.class, oToolKit); } catch (Exception ex) { ex.printStackTrace(); } XWindow xWin = aDesktop.getCurrentFrame().getContainerWindow(); - XWindowPeer aWinPeer = (XWindowPeer) UnoRuntime.queryInterface(XWindowPeer.class, xWin); + XWindowPeer aWinPeer = UnoRuntime.queryInterface(XWindowPeer.class, xWin); Rectangle aRect = new Rectangle(); int button = com.sun.star.awt.MessageBoxButtons.BUTTONS_OK; - XMessageBoxFactory aMBF = (XMessageBoxFactory) UnoRuntime.queryInterface(XMessageBoxFactory.class, aToolKit); + XMessageBoxFactory aMBF = UnoRuntime.queryInterface(XMessageBoxFactory.class, aToolKit); XMessageBox xMB = aMBF.createMessageBox(aWinPeer, aRect, "infobox" , button, "Event-Notify", "Listener was called, selcetion has changed"); xMB.execute(); } diff --git a/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java b/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java index 260ac5597e9e..a0d5142563e1 100644 --- a/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java +++ b/odk/examples/DevelopersGuide/Components/Addons/JobsAddon/AsyncJob.java @@ -253,7 +253,7 @@ public class AsyncJob extends WeakBase implements XServiceInfo, XAsyncJob try { // get access to the office toolkit environment - com.sun.star.awt.XToolkit xKit = (com.sun.star.awt.XToolkit)UnoRuntime.queryInterface( + com.sun.star.awt.XToolkit xKit = UnoRuntime.queryInterface( com.sun.star.awt.XToolkit.class, m_xCmpCtx.getServiceManager().createInstanceWithContext("com.sun.star.awt.Toolkit", m_xCmpCtx)); @@ -267,13 +267,13 @@ public class AsyncJob extends WeakBase implements XServiceInfo, XAsyncJob com.sun.star.awt.WindowAttribute.CLOSEABLE; aDescriptor.Type = com.sun.star.awt.WindowClass.MODALTOP; aDescriptor.ParentIndex = 1; - aDescriptor.Parent = (com.sun.star.awt.XWindowPeer)UnoRuntime.queryInterface( + aDescriptor.Parent = UnoRuntime.queryInterface( com.sun.star.awt.XWindowPeer.class, xParent); // create the info box window com.sun.star.awt.XWindowPeer xPeer = xKit.createWindow(aDescriptor); - com.sun.star.awt.XMessageBox xInfoBox = (com.sun.star.awt.XMessageBox)UnoRuntime.queryInterface( + com.sun.star.awt.XMessageBox xInfoBox = UnoRuntime.queryInterface( com.sun.star.awt.XMessageBox.class, xPeer); if (xInfoBox == null)