diff options
author | Noel Grandin <noel@peralex.com> | 2013-04-17 13:54:28 +0200 |
---|---|---|
committer | Fridrich Strba <fridrich@documentfoundation.org> | 2013-04-19 07:51:41 +0000 |
commit | d62425cc27e04a3237cfec2ea2663b8b11284ec8 (patch) | |
tree | bc96f74a3460377c4d368ba2d3cbd56b2e8baa89 /odk/examples | |
parent | a79d43dcd7989ee927de1b8c69ebc2981cc7166e (diff) |
Java cleanup, remove unnecessary casts
Change-Id: Id12089bc7df16631737e6acaee0973fb91dd953f
Reviewed-on: https://gerrit.libreoffice.org/3431
Reviewed-by: Fridrich Strba <fridrich@documentfoundation.org>
Tested-by: Fridrich Strba <fridrich@documentfoundation.org>
Diffstat (limited to 'odk/examples')
10 files changed, 152 insertions, 159 deletions
diff --git a/odk/examples/DevelopersGuide/Charts/CalcHelper.java b/odk/examples/DevelopersGuide/Charts/CalcHelper.java index ec0bea5f6306..ade201ccd297 100644 --- a/odk/examples/DevelopersGuide/Charts/CalcHelper.java +++ b/odk/examples/DevelopersGuide/Charts/CalcHelper.java @@ -74,13 +74,13 @@ public class CalcHelper public XSpreadsheet getChartSheet() throws RuntimeException { - XNameAccess aSheetsNA = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess aSheetsNA = UnoRuntime.queryInterface( XNameAccess.class, maSpreadSheetDoc.getSheets() ); XSpreadsheet aSheet = null; try { - aSheet = (XSpreadsheet) UnoRuntime.queryInterface( + aSheet = UnoRuntime.queryInterface( XSpreadsheet.class, aSheetsNA.getByName( msChartSheetName ) ); } catch( NoSuchElementException ex ) @@ -97,7 +97,7 @@ public class CalcHelper public XSpreadsheet getDataSheet() throws RuntimeException { - XNameAccess aSheetsNA = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess aSheetsNA = UnoRuntime.queryInterface( XNameAccess.class, maSpreadSheetDoc.getSheets() ); XSpreadsheet aSheet = null; @@ -105,7 +105,7 @@ public class CalcHelper { try { - aSheet = (XSpreadsheet) UnoRuntime.queryInterface( + aSheet = UnoRuntime.queryInterface( XSpreadsheet.class, aSheetsNA.getByName( msDataSheetName ) ); } catch( NoSuchElementException ex ) @@ -141,7 +141,7 @@ public class CalcHelper // get the sheet to insert the chart try { - aSheet = (XTableChartsSupplier) UnoRuntime.queryInterface( + aSheet = UnoRuntime.queryInterface( XTableChartsSupplier.class, getChartSheet() ); } catch( Exception ex ) @@ -151,7 +151,7 @@ public class CalcHelper } XTableCharts aChartCollection = aSheet.getCharts(); - XNameAccess aChartCollectionNA = (XNameAccess) UnoRuntime.queryInterface( + XNameAccess aChartCollectionNA = UnoRuntime.queryInterface( XNameAccess.class, aChartCollection ); if( aChartCollectionNA != null && @@ -168,23 +168,23 @@ public class CalcHelper try { - XTableChart aTableChart = (XTableChart) UnoRuntime.queryInterface( + XTableChart aTableChart = UnoRuntime.queryInterface( XTableChart.class, aChartCollectionNA.getByName( sChartName )); // the table chart is an embedded object which contains the chart document - aResult = (XChartDocument) UnoRuntime.queryInterface( + aResult = UnoRuntime.queryInterface( XChartDocument.class, - ((XEmbeddedObjectSupplier) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XEmbeddedObjectSupplier.class, - aTableChart )).getEmbeddedObject()); + aTableChart ).getEmbeddedObject()); // 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( NoSuchElementException ex ) { @@ -210,7 +210,7 @@ public class CalcHelper try { XSpreadsheet aSheet = getDataSheet(); - XCellRange aSheetRange = (XCellRange) UnoRuntime.queryInterface( XCellRange.class, aSheet ); + XCellRange aSheetRange = UnoRuntime.queryInterface( XCellRange.class, aSheet ); aRange = aSheetRange.getCellRangeByPosition( 0, 0, @@ -239,7 +239,7 @@ public class CalcHelper if( 0 == nCol ) { // x values: ascending numbers - fValue = (double)nRow + aGenerator.nextDouble(); + fValue = nRow + aGenerator.nextDouble(); } else { @@ -273,7 +273,7 @@ public class CalcHelper try { XSpreadsheet aSheet = getDataSheet(); - XCellRange aSheetRange = (XCellRange) UnoRuntime.queryInterface( XCellRange.class, aSheet ); + XCellRange aSheetRange = UnoRuntime.queryInterface( XCellRange.class, aSheet ); aRange = aSheetRange.getCellRangeByPosition( 0, 0, @@ -281,14 +281,14 @@ public class CalcHelper int nCol, nRow; double fValue; - double fFactor = 2.0 * java.lang.Math.PI / (double)(nRowCount - 1); + double fFactor = 2.0 * java.lang.Math.PI / (nRowCount - 1); String aFormula; // set variable factor for cos formula int nFactorCol = nColumnCount + 2; (aSheet.getCellByPosition( nFactorCol - 1, 0 )).setValue( 0.2 ); - XText xCellText = (XText) UnoRuntime.queryInterface( XText.class, aSheet.getCellByPosition( nFactorCol - 1, 1 ) ); + XText xCellText = UnoRuntime.queryInterface( XText.class, aSheet.getCellByPosition( nFactorCol - 1, 1 ) ); xCellText.setString( "Change the factor above and\nwatch the changes in the chart" ); for( nCol = 0; nCol < nColumnCount; nCol++ ) @@ -298,7 +298,7 @@ public class CalcHelper if( 0 == nCol ) { // x values: ascending numbers - fValue = (double)nRow * fFactor; + fValue = nRow * fFactor; (aSheet.getCellByPosition( nCol, nRow )).setValue( fValue ); } else @@ -329,11 +329,11 @@ public class CalcHelper */ public void raiseChartSheet() { - ((XSpreadsheetView) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XSpreadsheetView.class, - ((XModel) UnoRuntime.queryInterface( + UnoRuntime.queryInterface( XModel.class, - maSpreadSheetDoc )).getCurrentController()) ).setActiveSheet( getChartSheet() ); + maSpreadSheetDoc ).getCurrentController()).setActiveSheet( getChartSheet() ); } @@ -354,9 +354,9 @@ public class CalcHelper if( maSpreadSheetDoc != null ) { XSpreadsheets aSheets = maSpreadSheetDoc.getSheets(); - XNameContainer aSheetsNC = (XNameContainer) UnoRuntime.queryInterface( + XNameContainer aSheetsNC = UnoRuntime.queryInterface( XNameContainer.class, aSheets ); - XIndexAccess aSheetsIA = (XIndexAccess) UnoRuntime.queryInterface( + XIndexAccess aSheetsIA = UnoRuntime.queryInterface( XIndexAccess.class, aSheets ); if( aSheets != null && @@ -369,11 +369,11 @@ public class CalcHelper for( int i = aSheetsIA.getCount() - 1; 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) |