diff options
Diffstat (limited to 'odk/examples/DevelopersGuide/Drawing')
17 files changed, 158 insertions, 224 deletions
diff --git a/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java b/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java index fd407358a00a..0518e327bba3 100644 --- a/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java @@ -77,8 +77,7 @@ public class ChangeOrderDemo // create two rectangles XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xShape1 = ShapeHelper.createShape( xDrawDoc, new Point( 1000, 1000 ), new Size( 5000, 5000 ), @@ -93,10 +92,8 @@ public class ChangeOrderDemo ShapeHelper.addPortion( xShape1, "by changing the ZOrder it lie now on top", true ); xShapes.add( xShape2 ); - XPropertySet xPropSet1 = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape1 ); - XPropertySet xPropSet2 = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape2 ); + XPropertySet xPropSet1 = UnoRuntime.queryInterface( XPropertySet.class, xShape1 ); + XPropertySet xPropSet2 = UnoRuntime.queryInterface( XPropertySet.class, xShape2 ); int nOrderOfShape1 = ((Integer)xPropSet1.getPropertyValue( "ZOrder" )).intValue(); int nOrderOfShape2 = ((Integer)xPropSet2.getPropertyValue( "ZOrder" )).intValue(); diff --git a/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java b/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java index 2af75e409c63..654c3b2feae1 100644 --- a/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java @@ -88,46 +88,45 @@ public class ControlAndSelectDemo "private:factory/sdraw", "_blank", 0, pPropValues ); XMultiServiceFactory xFactory = - (XMultiServiceFactory )UnoRuntime.queryInterface( - XMultiServiceFactory.class, xComponent ); + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xComponent ); XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface( + XDrawPage xDrawPage = UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex( 0 )); - XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, xDrawPage ); // create and insert the ControlShape Object xObj = xFactory.createInstance( "com.sun.star.drawing.ControlShape" ); - XShape xShape = (XShape)UnoRuntime.queryInterface( XShape.class, xObj ); + XShape xShape = UnoRuntime.queryInterface( XShape.class, xObj ); xShape.setPosition( new Point( 1000, 1000 ) ); xShape.setSize( new Size( 2000, 2000 ) ); xShapes.add( xShape ); // create and set the control - XControlModel xControlModel = (XControlModel)UnoRuntime.queryInterface( + XControlModel xControlModel = UnoRuntime.queryInterface( XControlModel.class, xFactory.createInstance( "com.sun.star.form.component.GroupBox" ) ); - XControlShape xControlShape = (XControlShape)UnoRuntime.queryInterface( + XControlShape xControlShape = UnoRuntime.queryInterface( XControlShape.class, xShape ); xControlShape.setControl( xControlModel ); // the following code will demonstrate how to // make a selection that contains our new created ControlShape - XModel xModel = (XModel)UnoRuntime.queryInterface( XModel.class, + XModel xModel = UnoRuntime.queryInterface( XModel.class, xComponent ); XController xController = xModel.getCurrentController(); - XSelectionSupplier xSelectionSupplier =(XSelectionSupplier) - UnoRuntime.queryInterface( XSelectionSupplier.class, xController ); + XSelectionSupplier xSelectionSupplier =UnoRuntime.queryInterface( XSelectionSupplier.class, xController ); // take care to use the global service factory only and not the one // that is provided by the component if you create the ShapeColletion - XShapes xSelection = (XShapes)UnoRuntime.queryInterface( XShapes.class, + XShapes xSelection = UnoRuntime.queryInterface( XShapes.class, xOfficeContext.getServiceManager().createInstanceWithContext( "com.sun.star.drawing.ShapeCollection", xOfficeContext ) ); xSelection.add( xShape ); diff --git a/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java b/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java index 88b09888eab3..322868efdd8d 100644 --- a/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java @@ -89,11 +89,11 @@ public class CustomShowDemo pPropValues[ 0 ].Value = new Boolean( true ); xDrawDoc = Helper.createDocument( xOfficeContext, - "private:factory/simpress", "_blank", 0, pPropValues ); + "private:factory/simpress", "_blank", 0, pPropValues ); XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xDrawDoc ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xDrawDoc ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); // take care that this document has ten pages @@ -106,9 +106,9 @@ public class CustomShowDemo int i; for ( i = 0; i < 10; i++ ) { - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface( + XDrawPage xDrawPage = UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex( i )); - XNamed xPageName = (XNamed)UnoRuntime.queryInterface( + XNamed xPageName = UnoRuntime.queryInterface( XNamed.class, xDrawPage ); xPageName.setName( aNameArray[ i ] ); @@ -116,22 +116,19 @@ public class CustomShowDemo XShape xTextObj = ShapeHelper.createShape( xDrawDoc, new Point( 10000, 9000 ), new Size( 10000, 5000 ), "com.sun.star.drawing.TextShape" ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapes.add( xTextObj ); ShapeHelper.addPortion( xTextObj, aNameArray[ i ], true ); } /* create two custom shows, one will play slide 6 to 10 and is named "ShortVersion" the other one will play slide 2 til 10 and is named "LongVersion" */ - XCustomPresentationSupplier xCustPresSupplier = (XCustomPresentationSupplier) - UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc ); + XCustomPresentationSupplier xCustPresSupplier = UnoRuntime.queryInterface( XCustomPresentationSupplier.class, xDrawDoc ); /* the following container is a container for further container which concludes the list of pages that are to play within a custom show */ XNameContainer xNameContainer = xCustPresSupplier.getCustomPresentations(); - XSingleServiceFactory xFactory = (XSingleServiceFactory) - UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer ); + XSingleServiceFactory xFactory = UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer ); Object xObj; XIndexContainer xContainer; @@ -139,7 +136,7 @@ public class CustomShowDemo /* instanciate an IndexContainer that will take a list of draw pages for the first custom show */ xObj = xFactory.createInstance(); - xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj ); + xContainer = UnoRuntime.queryInterface( XIndexContainer.class, xObj ); for ( i = 5; i < 10; i++ ) xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) ); xNameContainer.insertByName( "ShortVersion", xContainer ); @@ -147,7 +144,7 @@ public class CustomShowDemo /* instanciate an IndexContainer that will take a list of draw page for the second custom show */ xObj = xFactory.createInstance(); - xContainer = (XIndexContainer)UnoRuntime.queryInterface( XIndexContainer.class, xObj ); + xContainer = UnoRuntime.queryInterface( XIndexContainer.class, xObj ); for ( i = 1; i < 10; i++ ) xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) ); xNameContainer.insertByName( "LongVersion", xContainer ); @@ -155,11 +152,9 @@ public class CustomShowDemo /* which custom show is to use can been set in the presentation settings */ - XPresentationSupplier xPresSupplier = (XPresentationSupplier) - UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); + XPresentationSupplier xPresSupplier = UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); XPresentation xPresentation = xPresSupplier.getPresentation(); - XPropertySet xPresPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); + XPropertySet xPresPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); xPresPropSet.setPropertyValue( "CustomShow", "ShortVersion" ); } catch( Exception ex ) diff --git a/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java b/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java index 41780cfb6786..efea885c8693 100644 --- a/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java @@ -88,15 +88,15 @@ public class DrawViewDemo sUrl.toString(), "_blank", 0, pPropValues ); XModel xModel = - (XModel)UnoRuntime.queryInterface( - XModel.class, xComponent ); + UnoRuntime.queryInterface( + XModel.class, xComponent ); // print all available properties of first view System.out.println("*** print all available properties of first view"); XViewDataSupplier xViewDataSupplier = - (XViewDataSupplier)UnoRuntime.queryInterface( - XViewDataSupplier.class, xModel ); + UnoRuntime.queryInterface( + XViewDataSupplier.class, xModel ); XIndexAccess xIndexAccess = xViewDataSupplier.getViewData(); if ( xIndexAccess.getCount() != 0 ) { @@ -116,8 +116,8 @@ public class DrawViewDemo System.out.println("*** print all properties that are supported by the controller"); XController xController = xModel.getCurrentController(); XPropertySet xPropSet = - (XPropertySet)UnoRuntime.queryInterface( - XPropertySet.class, xController ); + UnoRuntime.queryInterface( + XPropertySet.class, xController ); XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo(); Property[] aPropSeq = xPropSetInfo.getProperties(); for( int i = 0; i < aPropSeq.length; i++ ) diff --git a/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java b/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java index 15cf5775b12b..28d91600500f 100644 --- a/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java @@ -166,7 +166,7 @@ public class DrawingDemo PageHelper.getDrawPageCount( xDrawDoc ) - 1 ); // each drawpage is supporting an XNamed interface - XNamed xNamed = (XNamed)UnoRuntime.queryInterface( + XNamed xNamed = UnoRuntime.queryInterface( XNamed.class, xLastPage ); // beware, the page must have an unique name @@ -249,8 +249,7 @@ public class DrawingDemo int nRndObjPosY = aRndGen.nextInt( nHalfHeight - nRndObjHeight ) + nHalfHeight; - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, pPages[ i ] ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, pPages[ i ] ); ShapeHelper.createAndInsertShape( xDrawDoc, xShapes, new Point( nRndObjPosX, nRndObjPosY ), new Size( nRndObjWidth, nRndObjHeight ), @@ -283,16 +282,13 @@ public class DrawingDemo xDrawPage = PageHelper.getMasterPageByIndex( xDrawDoc, 0 ); else xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapes.add( xPolyPolygonBezier ); - XPropertySet xShapeProperties = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPolyPolygonBezier ); + XPropertySet xShapeProperties = UnoRuntime.queryInterface( XPropertySet.class, xPolyPolygonBezier ); // get pagesize - XPropertySet xPageProperties = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); + XPropertySet xPageProperties = UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); int nPageWidth = ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue() / 2; int nPageHeight = ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() / 2; @@ -369,12 +365,10 @@ public class DrawingDemo // before it is possible to insert shapes, // the group must have been added to the page XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapes.add( xGroup ); - XShapes xShapesGroup = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xGroup ); + XShapes xShapesGroup = UnoRuntime.queryInterface( XShapes.class, xGroup ); Size aPageSize = PageHelper.getPageSize( xDrawPage ); @@ -408,11 +402,9 @@ public class DrawingDemo try { XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapeGrouper xShapeGrouper = (XShapeGrouper) - UnoRuntime.queryInterface( XShapeGrouper.class, xDrawPage ); + XShapeGrouper xShapeGrouper = UnoRuntime.queryInterface( XShapeGrouper.class, xDrawPage ); - XShapes xShapesPage = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + XShapes xShapesPage = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); xShapeGrouper.group( xShapesPage ); } diff --git a/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java b/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java index be32f589106b..472ae81c6340 100644 --- a/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java @@ -84,12 +84,10 @@ public class FillAndLineStyleDemo new Size( 15000, 12000 ), "com.sun.star.drawing.RectangleShape" ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); xShapes.add( xRectangle ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); /* apply a gradient fill style that goes from top left to bottom right and is changing its color from green to yellow */ diff --git a/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java b/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java index 4b9b08f07b9b..5f1a32e06493 100644 --- a/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java @@ -84,8 +84,7 @@ public class GluePointDemo XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); // create two rectangles XShape xShape1 = ShapeHelper.createShape( xDrawDoc, @@ -106,8 +105,7 @@ public class GluePointDemo xShapes.add( xShape2 ); xShapes.add( xConnector ); - XPropertySet xConnectorPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xConnector ); + XPropertySet xConnectorPropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector ); // Index value of 0 : the shape is connected at the top // Index value of 1 : the shape is connected at the left @@ -140,21 +138,17 @@ public class GluePointDemo aGluePoint.Position.Y = 0; // create and insert a glue point at shape1 - xGluePointsSupplier = (XGluePointsSupplier) - UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 ); + xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 ); xIndexContainer = xGluePointsSupplier.getGluePoints(); - xIdentifierContainer = (XIdentifierContainer) - UnoRuntime.queryInterface( XIdentifierContainer.class, - xIndexContainer ); + xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class, + xIndexContainer ); int nIndexOfGluePoint1 = xIdentifierContainer.insert( aGluePoint ); // create and insert a glue point at shape2 - xGluePointsSupplier = (XGluePointsSupplier) - UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 ); + xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 ); xIndexContainer = xGluePointsSupplier.getGluePoints(); - xIdentifierContainer = (XIdentifierContainer) - UnoRuntime.queryInterface( XIdentifierContainer.class, - xIndexContainer ); + xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class, + xIndexContainer ); int nIndexOfGluePoint2 = xIdentifierContainer.insert( aGluePoint ); // create and add a connector @@ -164,8 +158,7 @@ public class GluePointDemo "com.sun.star.drawing.ConnectorShape" ); xShapes.add( xConnector2 ); - XPropertySet xConnector2PropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xConnector2 ); + XPropertySet xConnector2PropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector2 ); xConnector2PropSet.setPropertyValue( "StartShape", xShape1 ); xConnector2PropSet.setPropertyValue( "StartGluePointIndex", diff --git a/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java b/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java index 25aa1b3ed771..dc93c75b28c2 100644 --- a/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java @@ -84,8 +84,7 @@ public class GraphicExportDemo Object GraphicExportFilter = xOfficeContext.getServiceManager().createInstanceWithContext( "com.sun.star.drawing.GraphicExportFilter", xOfficeContext); - XExporter xExporter = (XExporter) - UnoRuntime.queryInterface( XExporter.class, GraphicExportFilter ); + XExporter xExporter = UnoRuntime.queryInterface( XExporter.class, GraphicExportFilter ); PropertyValue aProps[] = new PropertyValue[2]; aProps[0] = new PropertyValue(); @@ -110,11 +109,9 @@ public class GraphicExportDemo { XDrawPage xPage = PageHelper.getDrawPageByIndex( xComponent, nPageIndex ); - XComponent xComp = (XComponent) - UnoRuntime.queryInterface( XComponent.class, xPage ); + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, xPage ); xExporter.setSourceDocument( xComp ); - XFilter xFilter = (XFilter) - UnoRuntime.queryInterface( XFilter.class, xExporter ); + XFilter xFilter = UnoRuntime.queryInterface( XFilter.class, xExporter ); xFilter.filter( aProps ); System.out.println( "*** graphics on page \"" + nPageIndex + "\" from file \"" + args[0] @@ -127,9 +124,8 @@ public class GraphicExportDemo // close the document - com.sun.star.util.XCloseable xCloseable = (com.sun.star.util.XCloseable) - UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, - xComponent); + com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, + xComponent); if (xCloseable != null ) xCloseable.close(false); diff --git a/odk/examples/DevelopersGuide/Drawing/Helper.java b/odk/examples/DevelopersGuide/Drawing/Helper.java index efd952ac0ce9..a232e9418be4 100644 --- a/odk/examples/DevelopersGuide/Drawing/Helper.java +++ b/odk/examples/DevelopersGuide/Drawing/Helper.java @@ -35,6 +35,9 @@ // __________ Imports __________ import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.XComponentContext; +import com.sun.star.lang.XComponent; +import com.sun.star.frame.XComponentLoader; public class Helper { @@ -44,11 +47,11 @@ public class Helper * A new connection is established and the service manger from the running * offic eis returned. */ - static public com.sun.star.uno.XComponentContext connect() + static public XComponentContext connect() throws Exception { // get the remote office component context - com.sun.star.uno.XComponentContext xOfficeContext = + XComponentContext xOfficeContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); // if connection fails an exception is thrown @@ -65,15 +68,15 @@ public class Helper com.sun.star.beans.PropertyValue[] aArgs ) throws Exception { - com.sun.star.lang.XComponent xComponent = null; - com.sun.star.frame.XComponentLoader aLoader = - (com.sun.star.frame.XComponentLoader)UnoRuntime.queryInterface( - com.sun.star.frame.XComponentLoader.class, - xOfficeContext.getServiceManager().createInstanceWithContext( - "com.sun.star.frame.Desktop", xOfficeContext)); + XComponentLoader aLoader = + UnoRuntime.queryInterface( + XComponentLoader.class, + xOfficeContext.getServiceManager().createInstanceWithContext( + "com.sun.star.frame.Desktop", xOfficeContext)); - xComponent = (com.sun.star.lang.XComponent)UnoRuntime.queryInterface( - com.sun.star.lang.XComponent.class, aLoader.loadComponentFromURL( + XComponent xComponent = + UnoRuntime.queryInterface( + XComponent.class, aLoader.loadComponentFromURL( sURL, sTargetFrame, nSearchFlags, aArgs ) ); if ( xComponent == null ) diff --git a/odk/examples/DevelopersGuide/Drawing/LayerDemo.java b/odk/examples/DevelopersGuide/Drawing/LayerDemo.java index eec7171d5525..cbf66354ba14 100644 --- a/odk/examples/DevelopersGuide/Drawing/LayerDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/LayerDemo.java @@ -84,8 +84,7 @@ public class LayerDemo // create two rectangles XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xRect1 = ShapeHelper.createShape( xDrawDoc, new Point( 1000, 1000 ), new Size( 5000, 5000 ), @@ -109,12 +108,10 @@ public class LayerDemo // query for the XLayerManager - XLayerSupplier xLayerSupplier = (XLayerSupplier) - (XLayerSupplier)UnoRuntime.queryInterface( + XLayerSupplier xLayerSupplier = UnoRuntime.queryInterface( XLayerSupplier.class, xDrawDoc ); XNameAccess xNameAccess = xLayerSupplier.getLayerManager(); - XLayerManager xLayerManager = (XLayerManager) - (XLayerManager)UnoRuntime.queryInterface( + XLayerManager xLayerManager = UnoRuntime.queryInterface( XLayerManager.class, xNameAccess ); // create a layer and set its properties @@ -122,8 +119,7 @@ public class LayerDemo XLayer xNotVisibleAndEditable = xLayerManager.insertNewByIndex( xLayerManager.getCount() ); - xLayerPropSet = (XPropertySet) - (XPropertySet)UnoRuntime.queryInterface( + xLayerPropSet = UnoRuntime.queryInterface( XPropertySet.class, xNotVisibleAndEditable ); xLayerPropSet.setPropertyValue( "Name", "NotVisibleAndEditable" ); xLayerPropSet.setPropertyValue( "IsVisible", new Boolean( false ) ); @@ -133,8 +129,7 @@ public class LayerDemo XLayer xNotEditable = xLayerManager.insertNewByIndex( xLayerManager.getCount() ); - xLayerPropSet = (XPropertySet) - (XPropertySet)UnoRuntime.queryInterface( + xLayerPropSet = UnoRuntime.queryInterface( XPropertySet.class, xNotEditable ); xLayerPropSet.setPropertyValue( "Name", "NotEditable" ); xLayerPropSet.setPropertyValue( "IsVisible", new Boolean( true ) ); diff --git a/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java b/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java index 4b09ea0ec72b..f45326a185b9 100644 --- a/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java @@ -77,11 +77,9 @@ public class ObjectTransformationDemo "private:factory/simpress", "_blank", 0, pPropValues ); XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XPropertySet xPagePropSet= (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPage ); + XPropertySet xPagePropSet= UnoRuntime.queryInterface( XPropertySet.class, xPage ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xShape = ShapeHelper.createShape( xDrawDoc, @@ -89,8 +87,7 @@ public class ObjectTransformationDemo "com.sun.star.drawing.RectangleShape" ); xShapes.add( xShape ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3) xPropSet.getPropertyValue( "Transformation" ); diff --git a/odk/examples/DevelopersGuide/Drawing/Organigram.java b/odk/examples/DevelopersGuide/Drawing/Organigram.java index 5b0bdf0f8b39..362f38a2e6f8 100644 --- a/odk/examples/DevelopersGuide/Drawing/Organigram.java +++ b/odk/examples/DevelopersGuide/Drawing/Organigram.java @@ -82,8 +82,7 @@ public class Organigram { Object desktop = xRemoteServiceManager.createInstanceWithContext( "com.sun.star.frame.Desktop", xRemoteContext); - XComponentLoader xComponentLoader = (XComponentLoader) - UnoRuntime.queryInterface(XComponentLoader.class, desktop); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); PropertyValue[] loadProps = new PropertyValue[0]; XComponent xDrawComponent = xComponentLoader.loadComponentFromURL( @@ -91,22 +90,21 @@ public class Organigram { // get draw page by index com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier = - (com.sun.star.drawing.XDrawPagesSupplier)UnoRuntime.queryInterface( - com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent ); + UnoRuntime.queryInterface( + com.sun.star.drawing.XDrawPagesSupplier.class, xDrawComponent ); com.sun.star.drawing.XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); Object drawPage = xDrawPages.getByIndex(0); - com.sun.star.drawing.XDrawPage xDrawPage = (com.sun.star.drawing.XDrawPage) - UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, - drawPage); + com.sun.star.drawing.XDrawPage xDrawPage = UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, + drawPage); com.sun.star.lang.XMultiServiceFactory xDocumentFactory = - (com.sun.star.lang.XMultiServiceFactory)UnoRuntime.queryInterface( - com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent); + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent); com.sun.star.beans.XPropertySet xPageProps = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, xDrawPage); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xDrawPage); int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width")); int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height")); @@ -144,15 +142,13 @@ public class Organigram { (levelCount[level] - 1) * horSpace) / 2 + i * shapeWidth + i * horSpace; Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape"); - com.sun.star.drawing.XShape xShape = (com.sun.star.drawing.XShape) - UnoRuntime.queryInterface( + com.sun.star.drawing.XShape xShape = UnoRuntime.queryInterface( com.sun.star.drawing.XShape.class, shape); xShape.setPosition(new com.sun.star.awt.Point(shapeX, levelY)); xShape.setSize(new com.sun.star.awt.Size(shapeWidth, shapeHeight)); xDrawPage.add(xShape); - com.sun.star.text.XText xText = (com.sun.star.text.XText) - UnoRuntime.queryInterface( + com.sun.star.text.XText xText = UnoRuntime.queryInterface( com.sun.star.text.XText.class, xShape); xText.setString(orgUnits[level][i]); @@ -164,11 +160,11 @@ public class Organigram { if (level == 1) { Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape"); com.sun.star.beans.XPropertySet xConnectorProps = - (com.sun.star.beans.XPropertySet)UnoRuntime.queryInterface( - com.sun.star.beans.XPropertySet.class, connector); + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, connector); com.sun.star.drawing.XShape xConnector = - (com.sun.star.drawing.XShape)UnoRuntime.queryInterface( - com.sun.star.drawing.XShape.class, connector); + UnoRuntime.queryInterface( + com.sun.star.drawing.XShape.class, connector); xDrawPage.add(xConnector); xConnectorProps.setPropertyValue("StartShape", xStartShape); xConnectorProps.setPropertyValue("EndShape", xShape); diff --git a/odk/examples/DevelopersGuide/Drawing/PageHelper.java b/odk/examples/DevelopersGuide/Drawing/PageHelper.java index c612afa4e61b..b6bb684453ed 100644 --- a/odk/examples/DevelopersGuide/Drawing/PageHelper.java +++ b/odk/examples/DevelopersGuide/Drawing/PageHelper.java @@ -63,8 +63,8 @@ public class PageHelper static public int getDrawPageCount( XComponent xComponent ) { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); return xDrawPages.getCount(); } @@ -76,10 +76,10 @@ public class PageHelper com.sun.star.lang.WrappedTargetException { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); - return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); + return UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); } /** creates and inserts a draw page into the giving position, @@ -89,8 +89,8 @@ public class PageHelper throws Exception { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); return xDrawPages.insertNewByIndex( nIndex ); } @@ -100,8 +100,8 @@ public class PageHelper static public void removeDrawPage( XComponent xComponent, XDrawPage xDrawPage ) { XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); xDrawPages.remove( xDrawPage ); } @@ -112,8 +112,7 @@ public class PageHelper throws com.sun.star.beans.UnknownPropertyException, com.sun.star.lang.WrappedTargetException { - XPropertySet xPageProperties = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); + XPropertySet xPageProperties = UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); return new Size( ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue(), ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() ); @@ -126,8 +125,8 @@ public class PageHelper static public int getMasterPageCount( XComponent xComponent ) { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); return xDrawPages.getCount(); } @@ -139,10 +138,10 @@ public class PageHelper com.sun.star.lang.WrappedTargetException { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); - return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); + return UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); } /** creates and inserts a new master page into the giving position, @@ -151,8 +150,8 @@ public class PageHelper static public XDrawPage insertNewMasterPageByIndex( XComponent xComponent, int nIndex ) { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); return xDrawPages.insertNewByIndex( nIndex ); } @@ -162,8 +161,8 @@ public class PageHelper static public void removeMasterPage( XComponent xComponent, XDrawPage xDrawPage ) { XMasterPagesSupplier xMasterPagesSupplier = - (XMasterPagesSupplier)UnoRuntime.queryInterface( - XMasterPagesSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); xDrawPages.remove( xDrawPage ); } @@ -173,8 +172,8 @@ public class PageHelper static public XDrawPage getMasterPage( XDrawPage xDrawPage ) { XMasterPageTarget xMasterPageTarget = - (XMasterPageTarget)UnoRuntime.queryInterface( - XMasterPageTarget.class, xDrawPage ); + UnoRuntime.queryInterface( + XMasterPageTarget.class, xDrawPage ); return xMasterPageTarget.getMasterPage(); } @@ -183,8 +182,8 @@ public class PageHelper static public void setMasterPage( XDrawPage xDrawPage, XDrawPage xMasterPage ) { XMasterPageTarget xMasterPageTarget = - (XMasterPageTarget)UnoRuntime.queryInterface( - XMasterPageTarget.class, xDrawPage ); + UnoRuntime.queryInterface( + XMasterPageTarget.class, xDrawPage ); xMasterPageTarget.setMasterPage( xMasterPage ); } @@ -196,7 +195,7 @@ public class PageHelper */ static public boolean isImpressDocument( XComponent xComponent ) { - XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo xInfo = UnoRuntime.queryInterface( XServiceInfo.class, xComponent ); return xInfo.supportsService( "com.sun.star.presentation.PresentationDocument" ); } @@ -206,8 +205,8 @@ public class PageHelper static public XDrawPage getNotesPage( XDrawPage xDrawPage ) { XPresentationPage aPresentationPage = - (XPresentationPage)UnoRuntime.queryInterface( - XPresentationPage.class, xDrawPage ); + UnoRuntime.queryInterface( + XPresentationPage.class, xDrawPage ); return aPresentationPage.getNotesPage(); } @@ -216,8 +215,8 @@ public class PageHelper static public XDrawPage getHandoutMasterPage( XComponent xComponent ) { XHandoutMasterSupplier aHandoutMasterSupplier = - (XHandoutMasterSupplier)UnoRuntime.queryInterface( - XHandoutMasterSupplier.class, xComponent ); + UnoRuntime.queryInterface( + XHandoutMasterSupplier.class, xComponent ); return aHandoutMasterSupplier.getHandoutMasterPage(); } } diff --git a/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java b/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java index 652d8b51a0e8..61e62d2cfadf 100644 --- a/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java @@ -99,8 +99,7 @@ public class PresentationDemo // set the slide transition for the first page xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); // set slide transition effect setSlideTransition( xPage, com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, @@ -124,8 +123,7 @@ public class PresentationDemo // set the slide transition for the second page xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 1 ); - xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); setSlideTransition( xPage, com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, com.sun.star.presentation.AnimationSpeed.SLOW, @@ -145,8 +143,7 @@ public class PresentationDemo // the second object lets the presentation jump to page two // by using a ClickAction.BOOKMARK; xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 2 ); - xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); setSlideTransition( xPage, com.sun.star.presentation.FadeEffect.ROLL_FROM_LEFT, com.sun.star.presentation.AnimationSpeed.MEDIUM, @@ -157,8 +154,7 @@ public class PresentationDemo xShapes.add( xShape ); ShapeHelper.addPortion( xShape, "click to go", false ); ShapeHelper.addPortion( xShape, "to first page", true ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); xShapePropSet.setPropertyValue("Effect", com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM ); xShapePropSet.setPropertyValue( @@ -171,15 +167,14 @@ public class PresentationDemo xShapes.add( xShape ); ShapeHelper.addPortion( xShape, "click to go", false ); ShapeHelper.addPortion( xShape, "to the second page", true ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); xShapePropSet.setPropertyValue("Effect", com.sun.star.presentation.AnimationEffect.FADE_FROM_BOTTOM ); xShapePropSet.setPropertyValue( "OnClick", com.sun.star.presentation.ClickAction.BOOKMARK ); // set the name of page two, and use it with the bookmark action - XNamed xPageName = (XNamed)UnoRuntime.queryInterface( + XNamed xPageName = UnoRuntime.queryInterface( XNamed.class, PageHelper.getDrawPageByIndex( xDrawDoc, 1 ) ); xPageName.setName( "page two" ); xShapePropSet.setPropertyValue( @@ -189,11 +184,9 @@ public class PresentationDemo /* start an endless presentation which is displayed in full-screen mode and placed on top */ - XPresentationSupplier xPresSupplier = (XPresentationSupplier) - UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); + XPresentationSupplier xPresSupplier = UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); XPresentation xPresentation = xPresSupplier.getPresentation(); - XPropertySet xPresPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); + XPropertySet xPresPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); xPresPropSet.setPropertyValue( "IsEndless", new Boolean( true ) ); xPresPropSet.setPropertyValue( "IsAlwaysOnTop", new Boolean( true ) ); xPresPropSet.setPropertyValue( "Pause", new Integer( 0 ) ); @@ -216,14 +209,13 @@ public class PresentationDemo // the following test is only sensible if you do not exactly know // what type of page xPage is, for this purpose it can been tested // if the com.sun.star.presentation.DrawPage service is supported - XServiceInfo xInfo = (XServiceInfo)UnoRuntime.queryInterface( + XServiceInfo xInfo = UnoRuntime.queryInterface( XServiceInfo.class, xPage ); if ( xInfo.supportsService( "com.sun.star.presentation.DrawPage" ) == true ) { try { - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xPage ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPage ); xPropSet.setPropertyValue( "Effect", eEffect ); xPropSet.setPropertyValue( "Speed", eSpeed ); xPropSet.setPropertyValue( "Change", new Integer( nChange ) ); diff --git a/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java b/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java index 7959b642fe0f..6f1d4aff680c 100644 --- a/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java +++ b/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java @@ -66,8 +66,7 @@ public class ShapeHelper { XShape xShape = createShape( xDrawDoc, aPos, aSize, sShapeType ); xShapes.add( xShape ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); return xPropSet; } @@ -79,10 +78,10 @@ public class ShapeHelper { XShape xShape = null; XMultiServiceFactory xFactory = - (XMultiServiceFactory )UnoRuntime.queryInterface( - XMultiServiceFactory.class, xDrawDoc ); + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xDrawDoc ); Object xObj = xFactory.createInstance( sShapeType ); - xShape = (XShape)UnoRuntime.queryInterface( + xShape = UnoRuntime.queryInterface( XShape.class, xObj ); xShape.setPosition( aPos ); xShape.setSize( aSize ); @@ -96,8 +95,7 @@ public class ShapeHelper public static XPropertySet addPortion( XShape xShape, String sText, boolean bNewParagraph ) throws com.sun.star.lang.IllegalArgumentException { - XText xText = (XText) - UnoRuntime.queryInterface( XText.class, xShape ); + XText xText = UnoRuntime.queryInterface( XText.class, xShape ); XTextCursor xTextCursor = xText.createTextCursor(); xTextCursor.gotoEnd( false ); @@ -106,12 +104,10 @@ public class ShapeHelper xText.insertControlCharacter( xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false ); xTextCursor.gotoEnd( false ); } - XTextRange xTextRange = (XTextRange) - UnoRuntime.queryInterface( XTextRange.class, xTextCursor ); + XTextRange xTextRange = UnoRuntime.queryInterface( XTextRange.class, xTextCursor ); xTextRange.setString( sText ); xTextCursor.gotoEnd( true ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xTextRange ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextRange ); return xPropSet; } @@ -123,8 +119,7 @@ public class ShapeHelper com.sun.star.lang.WrappedTargetException, com.sun.star.container.NoSuchElementException { - XEnumerationAccess xEnumerationAccess = (XEnumerationAccess) - UnoRuntime.queryInterface( XEnumerationAccess.class, xText ); + XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface( XEnumerationAccess.class, xText ); if ( xEnumerationAccess.hasElements() ) { XEnumeration xEnumeration = xEnumerationAccess.createEnumeration(); @@ -133,10 +128,9 @@ public class ShapeHelper Object xObj = xEnumeration.nextElement(); if ( xEnumeration.hasMoreElements() == false ) { - XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface( + XTextContent xTextContent = UnoRuntime.queryInterface( XTextContent.class, xObj ); - XPropertySet xParaPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xTextContent ); + XPropertySet xParaPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextContent ); xParaPropSet.setPropertyValue( sPropName, aValue ); } } diff --git a/odk/examples/DevelopersGuide/Drawing/StyleDemo.java b/odk/examples/DevelopersGuide/Drawing/StyleDemo.java index 6196ad1d0727..2fe07f62efbf 100644 --- a/odk/examples/DevelopersGuide/Drawing/StyleDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/StyleDemo.java @@ -89,12 +89,11 @@ public class StyleDemo that is available within the styles of the document to red. It will also print each family and style name to the standard output */ XModel xModel = - (XModel)UnoRuntime.queryInterface( - XModel.class, xComponent ); + UnoRuntime.queryInterface( + XModel.class, xComponent ); com.sun.star.style.XStyleFamiliesSupplier xSFS = - (com.sun.star.style.XStyleFamiliesSupplier) UnoRuntime.queryInterface( - com.sun.star.style.XStyleFamiliesSupplier.class, xModel ); + com.sun.star.style.XStyleFamiliesSupplier.class, xModel ); com.sun.star.container.XNameAccess xFamilies = xSFS.getStyleFamilies(); @@ -109,21 +108,18 @@ public class StyleDemo // and now all available styles Object aFamilyObj = xFamilies.getByName( Families[ i ] ); com.sun.star.container.XNameAccess xStyles = - (com.sun.star.container.XNameAccess) UnoRuntime.queryInterface( - com.sun.star.container.XNameAccess.class, aFamilyObj ); + com.sun.star.container.XNameAccess.class, aFamilyObj ); String[] Styles = xStyles.getElementNames(); for( int j = 0; j < Styles.length; j++ ) { System.out.println( " " + Styles[ j ] ); Object aStyleObj = xStyles.getByName( Styles[ j ] ); - com.sun.star.style.XStyle xStyle = (com.sun.star.style.XStyle) - UnoRuntime.queryInterface( + com.sun.star.style.XStyle xStyle = UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, aStyleObj ); // now we have the XStyle Interface and the CharColor for // all styles is exemplary be set to red. - XPropertySet xStylePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xStyle ); + XPropertySet xStylePropSet = UnoRuntime.queryInterface( XPropertySet.class, xStyle ); XPropertySetInfo xStylePropSetInfo = xStylePropSet.getPropertySetInfo(); if ( xStylePropSetInfo.hasPropertyByName( "CharColor" ) ) @@ -140,26 +136,21 @@ public class StyleDemo the "graphics" family */ Object obj = xFamilies.getByName( "graphics" ); - com.sun.star.container.XNameAccess xStyles = (XNameAccess) - UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, - obj ); + com.sun.star.container.XNameAccess xStyles = UnoRuntime.queryInterface(com.sun.star.container.XNameAccess.class, + obj ); obj = xStyles.getByName( "title1" ); - com.sun.star.style.XStyle xTitle1Style = (com.sun.star.style.XStyle) - UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, obj ); + com.sun.star.style.XStyle xTitle1Style = UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, obj ); - XDrawPagesSupplier xDrawPagesSupplier = - (XDrawPagesSupplier)UnoRuntime.queryInterface( - XDrawPagesSupplier.class, xComponent ); + XDrawPagesSupplier xDrawPagesSupplier = UnoRuntime.queryInterface( XDrawPagesSupplier.class, xComponent ); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); - XDrawPage xDrawPage = (XDrawPage)UnoRuntime.queryInterface( + XDrawPage xDrawPage = UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex( 0 )); - XShapes xShapes = (XShapes)UnoRuntime.queryInterface(XShapes.class, + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, xDrawPage ); XShape xShape = ShapeHelper.createShape( xComponent, new Point( 0, 0 ), new Size( 5000, 5000 ), "com.sun.star.drawing.RectangleShape" ); xShapes.add( xShape ); - XPropertySet xPropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); xPropSet.setPropertyValue( "Style", xTitle1Style ); } diff --git a/odk/examples/DevelopersGuide/Drawing/TextDemo.java b/odk/examples/DevelopersGuide/Drawing/TextDemo.java index 9d97b0aea29a..82b9abfc338d 100644 --- a/odk/examples/DevelopersGuide/Drawing/TextDemo.java +++ b/odk/examples/DevelopersGuide/Drawing/TextDemo.java @@ -81,8 +81,7 @@ public class TextDemo "private:factory/sdraw", "_blank", 0, pPropValues ); XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); - XShapes xShapes = (XShapes) - UnoRuntime.queryInterface( XShapes.class, xPage ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); XShape xRectangle; @@ -98,8 +97,7 @@ public class TextDemo new Size( 15000, 7500 ), "com.sun.star.drawing.RectangleShape" ); xShapes.add( xRectangle ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); // first paragraph @@ -126,8 +124,7 @@ public class TextDemo new Size( 21000, 12500 ), "com.sun.star.drawing.RectangleShape" ); xShapes.add( xRectangle ); - xShapePropSet = (XPropertySet) - UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); xShapePropSet.setPropertyValue( "TextFitToSize", TextFitToSizeType.PROPORTIONAL ); xShapePropSet.setPropertyValue( "TextLeftDistance", new Integer(2500)); |