Hello Thorsten, On Monday 19 January 2009 11:12, Thorsten Behrens wrote: > Looks just fine to me, thx for chiming in
was this meant as in "to break suddenly and unwelcomely into a conversation, as to express agreement or voice an opinion"? ... next time I'll try to more polite... > > this is a no-go; API clients shouldn't worry about the implementation. > > You're right, please file an issue for the missing documentation. http://www.openoffice.org/issues/show_bug.cgi?id=98412 @John I attach a Java version of the OOo Basic code (yes, much more code :-( ) When I have more time and finish with http://api.openoffice.org/source/browse/api/examples/java/netbeans/ , I'll try something nicer and add it to it. Regards -- Ariel Constenla-Haile La Plata, Argentina "Aus der Kriegsschule des Lebens - Was mich nicht umbringt, macht mich härter." Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.
/* * AnimationDemo.java * * Created on 2009.01.20 - 09:53:51 * */ package org.openoffice.sdk.drawing; import com.sun.star.animations.XAnimateColor; import com.sun.star.animations.XAnimateMotion; import com.sun.star.animations.XAnimateSet; import com.sun.star.animations.XAnimateTransform; import com.sun.star.animations.XAnimationNode; import com.sun.star.animations.XAnimationNodeSupplier; import com.sun.star.animations.XAudio; import com.sun.star.animations.XCommand; import com.sun.star.animations.XIterateContainer; import com.sun.star.animations.XTimeContainer; import com.sun.star.animations.XTransitionFilter; import com.sun.star.awt.Point; import com.sun.star.awt.Size; import com.sun.star.beans.NamedValue; import com.sun.star.beans.PropertyValue; import com.sun.star.beans.XPropertySet; import com.sun.star.uno.XComponentContext; import com.sun.star.comp.helper.Bootstrap; import com.sun.star.drawing.XDrawPage; import com.sun.star.drawing.XDrawPages; import com.sun.star.drawing.XDrawPagesSupplier; import com.sun.star.drawing.XShape; import com.sun.star.drawing.XShapes; import com.sun.star.frame.FrameSearchFlag; import com.sun.star.frame.XComponentLoader; import com.sun.star.frame.XModel; import com.sun.star.lang.XComponent; import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.presentation.XPresentation; import com.sun.star.presentation.XPresentationSupplier; import com.sun.star.ucb.XSimpleFileAccess; import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.XInterface; /** * * @author ariel */ public class AnimationDemo { private XComponentContext m_xContext; /** Creates a new instance of AnimationDemo */ public AnimationDemo(XComponentContext xContext) { m_xContext = xContext; } public void runMotionPathDemo() { try { XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface( XDrawPagesSupplier.class, createNewDoc(m_xContext, "simpress")); XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); while (xDrawPages.getCount() < 1/*4*/) { xDrawPages.insertNewByIndex(0); } XDrawPage xDrawPage = getDrawPage(xDrawPages, 0); XPropertySet xPageProps = (XPropertySet) UnoRuntime.queryInterface( XPropertySet.class, xDrawPage); int nPageWidth, nPageHeight, nShape; nShape = 10000; nPageWidth = AnyConverter.toInt( xPageProps.getPropertyValue("Width")); nPageHeight = AnyConverter.toInt( xPageProps.getPropertyValue("Height")); XShape xShape = createAndInsertShape( xDrawPagesSupplier, xDrawPage, "Ellipse", new Point( nPageWidth / 2 - nShape / 2, nPageHeight / 2 - nShape / 2), new Size( nShape, nShape ) ); XAnimationNodeSupplier xNodeSupplier = (XAnimationNodeSupplier) UnoRuntime.queryInterface( XAnimationNodeSupplier.class, xDrawPage); XAnimationNode xRootNode = xNodeSupplier.getAnimationNode(); XTimeContainer xRootTimeContainer = (XTimeContainer) UnoRuntime.queryInterface( XTimeContainer.class, xRootNode); XTimeContainer xSeq = createSequenceTimeContainer(m_xContext); xRootTimeContainer.appendChild(xSeq); XTimeContainer xPar = createParallelTimeContainer(m_xContext); xSeq.appendChild(xPar); setUserData(xRootNode, com.sun.star.presentation.EffectNodeType.AFTER_PREVIOUS, com.sun.star.presentation.EffectPresetClass.MOTIONPATH, null); xPar.setAcceleration(0.05); xPar.setDecelerate(0.05); xPar.setFill(com.sun.star.animations.AnimationFill.HOLD); XAnimateMotion xMotion = createAnimateMotion(m_xContext); xPar.appendChild(xMotion); xMotion.setDuration(new Integer(2)); xMotion.setFill(com.sun.star.animations.AnimationFill.HOLD); xMotion.setTarget(xShape); xMotion.setPath("m -0.5 -0.5 0.5 1 0.5 -1"); XAudio xAudio = createAudioEffect( m_xContext, getRandomAudioURL(m_xContext), 1.0); // I have no idea what's expected under volume, // anyway: does setting the volume work? // at least the slideshow engine does not seem to take this into accout: // slideshow/source/inc/soundplayer.hxx // slideshow/source/engine/soundplayer.cxx // slideshow/source/engine/animationnodes/animationaudionode.cxx // ::com::sun::star::media::XPlayer has get/setVolumeDB() // if they work, would it possible to wrap it in the SoundPlayer? xPar.appendChild(xAudio); XPresentationSupplier xPresentationSupplier = (XPresentationSupplier) UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawPagesSupplier); XPresentation xPresentation = xPresentationSupplier.getPresentation(); bringWindowToFront(xDrawPagesSupplier); Thread.sleep(5000); xPresentation.start(); } catch (Exception e) { e.printStackTrace(); } } //************************************************************************* public static void setUserData( XAnimationNode xNode, short nEffectNodeType, short nEffectPresetClass, String sPresetID){ try { boolean bHasId = sPresetID != null && sPresetID.length() > 0; NamedValue[] aUserData = new NamedValue[bHasId ? 3 : 2]; aUserData[0] = new NamedValue( "node-type", Short.valueOf(nEffectNodeType)); aUserData[1] = new NamedValue( "preset-class", Short.valueOf(nEffectPresetClass)); if (bHasId) aUserData[2] = new NamedValue( "preset-id", sPresetID); xNode.setUserData(aUserData); } catch (Exception e) { e.printStackTrace(); } } public static XTimeContainer createParallelTimeContainer(XComponentContext xContext) { XTimeContainer xPar = null; try { xPar = (XTimeContainer) createUnoService( xContext, "com.sun.star.animations.ParallelTimeContainer", XTimeContainer.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xPar; } } public static XTimeContainer createSequenceTimeContainer(XComponentContext xContext) { XTimeContainer xSeq = null; try { xSeq = (XTimeContainer) createUnoService( xContext, "com.sun.star.animations.SequenceTimeContainer", XTimeContainer.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xSeq; } } public static XIterateContainer createIterateContainer(XComponentContext xContext) { XIterateContainer xIt = null; try { xIt = (XIterateContainer) createUnoService( xContext, "com.sun.star.animations.IterateContainer", XIterateContainer.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xIt; } } /*public static XAnimate createAnimate(XComponentContext xContext) { XAnimate xAnimate = null; try { xAnimate = (XAnimate) createUnoService( xContext, "com.sun.star.animations.Animate", XAnimate.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xAnimate; } }*/ public static XAnimateSet createAnimateSet(XComponentContext xContext) { XAnimateSet xSet = null; try { xSet = (XAnimateSet) createUnoService( xContext, "com.sun.star.animations.AnimateSet", XAnimateSet.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xSet; } } public static XAnimateColor createAnimateColor(XComponentContext xContext) { XAnimateColor xColor = null; try { xColor = (XAnimateColor) createUnoService( xContext, "com.sun.star.animations.AnimateColor", XAnimateColor.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xColor; } } public static XAnimateMotion createAnimateMotion(XComponentContext xContext) { XAnimateMotion xMotion = null; try { xMotion = (XAnimateMotion) createUnoService( xContext, "com.sun.star.animations.AnimateMotion", XAnimateMotion.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xMotion; } } public static XAnimateTransform createAnimateTransform(XComponentContext xContext) { XAnimateTransform xTransform = null; try { xTransform = (XAnimateTransform) createUnoService( xContext, "com.sun.star.animations.AnimateTransform", XAnimateTransform.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xTransform; } } public static XTransitionFilter createTransitionFilter(XComponentContext xContext) { XTransitionFilter xTransitionFilter = null; try { xTransitionFilter = (XTransitionFilter) createUnoService( xContext, "com.sun.star.animations.TransitionFilter", XTransitionFilter.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xTransitionFilter; } } public static XAudio createAudioEffect(XComponentContext xContext, String sURL, double dVolume) { XAudio xAudio = null; try { xAudio = (XAudio) createUnoService( xContext, "com.sun.star.animations.Audio", XAudio.class ); xAudio.setSource(sURL); xAudio.setVolume(dVolume); } catch (Exception e) { e.printStackTrace(); } finally { return xAudio; } } public static XCommand createAnimCommand(XComponentContext xContext) { XCommand xCommand = null; try { xCommand = (XCommand) createUnoService( xContext, "com.sun.star.animations.Command", XCommand.class ); } catch (Exception e) { e.printStackTrace(); } finally { return xCommand; } } public static XDrawPage getDrawPage(XDrawPages xDrawPages, int nIndex) { XDrawPage xDP = null; try { if ( nIndex < xDrawPages.getCount() ) xDP = (XDrawPage) UnoRuntime.queryInterface( XDrawPage.class, xDrawPages.getByIndex(nIndex)); } catch (Exception e) { e.printStackTrace(); } finally { return xDP; } } public static XShape createAndInsertShape( XInterface xDoc, XDrawPage xDrawPage, String sShapeType, Point aPosition, Size aSize ) { XShape xShape = null; try { xShape = createShape(xDoc, sShapeType, aPosition, aSize); XShapes xShapes = (XShapes) UnoRuntime.queryInterface( XShapes.class, xDrawPage); xShapes.add(xShape); } catch (Exception e) { e.printStackTrace(); } finally { return xShape; } } public static XShape createShape( XInterface xDoc, String sShapeType, Point aPosition, Size aSize ) { XShape xShape = null; try { XMultiServiceFactory xDocFactory = (XMultiServiceFactory) UnoRuntime.queryInterface( XMultiServiceFactory.class, xDoc); xShape = (XShape) UnoRuntime.queryInterface( XShape.class, xDocFactory.createInstance( "com.sun.star.drawing." + sShapeType + "Shape" ) ); xShape.setPosition(aPosition); xShape.setSize(aSize); } catch (Exception e) { e.printStackTrace(); } finally { return xShape; } } //************************************************************************* public static XComponent createNewDoc(XComponentContext xContext, String sType) { return createNewDoc(xContext, new PropertyValue[0], sType); } public static XComponent createNewDoc( XComponentContext xContext, PropertyValue[] aMediaDescriptor, String sType) { XComponent xComponent = null; try { XComponentLoader xDesktopLoader = (XComponentLoader) createUnoService( xContext, "com.sun.star.frame.Desktop", XComponentLoader.class ); xComponent = (XComponent) UnoRuntime.queryInterface( XComponent.class, xDesktopLoader.loadComponentFromURL( "private:factory/" + sType, "_default", FrameSearchFlag.ALL, aMediaDescriptor ) ); } catch (Exception ex) { ex.printStackTrace(); } return xComponent; } //************************************************************************* public static String getRandomAudioURL(XComponentContext xContext){ String sURL = null; try { String sGalleryPath = getShareGalleryURL(xContext); if (sGalleryPath != null && sGalleryPath.length() > 0) { XSimpleFileAccess xSFA = (XSimpleFileAccess) createUnoService( xContext, "com.sun.star.ucb.SimpleFileAccess", XSimpleFileAccess.class); String[] sFolder = xSFA.getFolderContents( sGalleryPath + "/sounds", false); int n = sFolder.length; if ( n > 0) { sURL = sFolder[ (int)(Math.random() * n) ]; } } } catch (Exception e) { e.printStackTrace(); } finally { return sURL; } } public static String getShareGalleryURL(XComponentContext xContext){ String sURL = null; try { XPropertySet xPathSettings = (XPropertySet) createUnoService( xContext, "com.sun.star.util.PathSettings", XPropertySet.class); String sGalleryPaths = AnyConverter.toString( xPathSettings.getPropertyValue("Gallery")); if (sGalleryPaths.contains(";")) { sURL = sGalleryPaths.split("\\;")[0]; } else sURL = sGalleryPaths; } catch (Exception e) { e.printStackTrace(); } finally { return sURL; } } //************************************************************************* public static Object createUnoService( XComponentContext xContext, String sServiceName){ Object oService = null; try { oService = xContext.getServiceManager().createInstanceWithContext( sServiceName, xContext); } catch (Exception e) { e.printStackTrace(); } return oService; } public static XInterface createUnoService( XComponentContext xContext, String sServiceName, Class xInterface){ XInterface xService = null; try { Object oInstance = createUnoService(xContext, sServiceName); if (oInstance != null) { xService = (XInterface) AnyConverter.toObject(xInterface, oInstance); } } catch (Exception e) { e.printStackTrace(); } return xService; } public static Object createUnoService( XComponentContext xContext, String sServiceName, Object[] aArguments){ Object oService = null; try { oService = xContext.getServiceManager().createInstanceWithArgumentsAndContext( sServiceName, aArguments, xContext); } catch (Exception e) { e.printStackTrace(); } return oService; } public static XInterface createUnoService( XComponentContext xContext, String sServiceName, Object[] aArguments, Class xInterface){ XInterface xService = null; try { Object oInstance = createUnoService(xContext, sServiceName, aArguments); if (oInstance != null) { xService = (XInterface) AnyConverter.toObject(xInterface, oInstance); } } catch (Exception e) { e.printStackTrace(); } return xService; } //************************************************************************* public static void bringWindowToFront(XInterface xIfce){ XModel xModel = (XModel) UnoRuntime.queryInterface(XModel.class, xIfce); if (xModel != null){ bringWindowToFront(xModel); } } public static void bringWindowToFront(XModel xModel){ com.sun.star.awt.XTopWindow xTopWindow = (com.sun.star.awt.XTopWindow) UnoRuntime.queryInterface( com.sun.star.awt.XTopWindow.class, xModel.getCurrentController().getFrame().getContainerWindow()); xTopWindow.toFront(); } //************************************************************************* /** * @param args the command line arguments */ public static void main(String[] args) { try { // get the remote office component context XComponentContext xContext = Bootstrap.bootstrap(); if (xContext == null) { System.err.println("ERROR: Could not bootstrap default Office."); } AnimationDemo demo = new AnimationDemo(xContext); demo.runMotionPathDemo(); } catch (java.lang.Exception e){ e.printStackTrace(); } finally { System.exit( 0 ); } } }
--------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org For additional commands, e-mail: dev-h...@api.openoffice.org