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/java/Spreadsheet | |
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/java/Spreadsheet')
-rw-r--r-- | odk/examples/java/Spreadsheet/CalcAddins.java | 4 | ||||
-rw-r--r-- | odk/examples/java/Spreadsheet/ChartTypeChange.java | 65 | ||||
-rw-r--r-- | odk/examples/java/Spreadsheet/EuroAdaption.java | 46 | ||||
-rw-r--r-- | odk/examples/java/Spreadsheet/SCalc.java | 53 |
4 files changed, 76 insertions, 92 deletions
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 { |