diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /odk/examples/DevelopersGuide/Drawing | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'odk/examples/DevelopersGuide/Drawing')
19 files changed, 3061 insertions, 0 deletions
diff --git a/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java b/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java new file mode 100644 index 000000000..6a5de2c7d --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/ChangeOrderDemo.java @@ -0,0 +1,113 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; + + + +// __________ Implementation __________ + +// ChangeOrderDemo + +public class ChangeOrderDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/sdraw", "_blank", 0, pPropValues ); + + // create two rectangles + XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + + XShape xShape1 = ShapeHelper.createShape( xDrawDoc, + new Point( 1000, 1000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.RectangleShape" ); + + XShape xShape2 = ShapeHelper.createShape( xDrawDoc, + new Point( 2000, 2000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.EllipseShape" ); + + xShapes.add( xShape1 ); + ShapeHelper.addPortion( xShape1, " this shape was inserted first", false ); + ShapeHelper.addPortion( xShape1, "by changing the ZOrder it lie now on top", true ); + xShapes.add( 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(); + + xPropSet1.setPropertyValue( "ZOrder", Integer.valueOf( nOrderOfShape2 ) ); + xPropSet2.setPropertyValue( "ZOrder", Integer.valueOf( nOrderOfShape1 ) ); + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java b/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java new file mode 100644 index 000000000..b2108db18 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/ControlAndSelectDemo.java @@ -0,0 +1,144 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; +import com.sun.star.awt.XControlModel; + +import com.sun.star.beans.PropertyValue; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XControlShape; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; + +import com.sun.star.frame.XModel; +import com.sun.star.frame.XController; + +import com.sun.star.view.XSelectionSupplier; + + +// __________ Implementation __________ + +/** ControlAndSelectDemo + + A (GroupBox) ControlShape will be created. + Finally the ControlShape will be inserted into a selection. +*/ + +public class ControlAndSelectDemo +{ + public static void main( String args[] ) + { + XComponent xComponent = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xComponent = Helper.createDocument( xOfficeContext, + "private:factory/sdraw", "_blank", 0, pPropValues ); + + XMultiServiceFactory xFactory = + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xComponent ); + + XDrawPagesSupplier xDrawPagesSupplier = + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); + XDrawPage xDrawPage = UnoRuntime.queryInterface( + XDrawPage.class, xDrawPages.getByIndex( 0 )); + XShapes xShapes = UnoRuntime.queryInterface(XShapes.class, + xDrawPage ); + + + // create and insert the ControlShape + Object xObj = xFactory.createInstance( + "com.sun.star.drawing.ControlShape" ); + 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 = UnoRuntime.queryInterface( + XControlModel.class, + xFactory.createInstance( "com.sun.star.form.component.GroupBox" ) ); + 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 = UnoRuntime.queryInterface( XModel.class, + xComponent ); + XController xController = xModel.getCurrentController(); + 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 = UnoRuntime.queryInterface( XShapes.class, + xOfficeContext.getServiceManager().createInstanceWithContext( + "com.sun.star.drawing.ShapeCollection", xOfficeContext ) ); + xSelection.add( xShape ); + xSelectionSupplier.select( xSelection ); + } + catch( java.lang.Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java b/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java new file mode 100644 index 000000000..7dcf1d71d --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/CustomShowDemo.java @@ -0,0 +1,169 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XSingleServiceFactory; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.container.XNamed; +import com.sun.star.container.XNameContainer; +import com.sun.star.container.XIndexContainer; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; + +import com.sun.star.presentation.XPresentation; +import com.sun.star.presentation.XPresentationSupplier; +import com.sun.star.presentation.XCustomPresentationSupplier; + + +// __________ Implementation __________ + +// presentation demo + +// This demo will demonstrate how to create a CustomShow + +// The first parameter describes the connection that is to use. If there is no parameter +// "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used. + + +public class CustomShowDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/simpress", "_blank", 0, pPropValues ); + + XDrawPagesSupplier xDrawPagesSupplier = + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xDrawDoc ); + XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); + + // take care that this document has ten pages + while ( xDrawPages.getCount() < 10 ) + xDrawPages.insertNewByIndex( 0 ); + + // assign a name to each page and also insert a text object including the name of the page + String aNameArray[] = { "Introduction", "page one", "page two", "page three", "page four", + "page five", "page six", "page seven", "page eight", "page nine" }; + int i; + for ( i = 0; i < 10; i++ ) + { + XDrawPage xDrawPage = UnoRuntime.queryInterface( + XDrawPage.class, xDrawPages.getByIndex( i )); + XNamed xPageName = UnoRuntime.queryInterface( + XNamed.class, xDrawPage ); + xPageName.setName( aNameArray[ i ] ); + + // now we will create and insert the text object + XShape xTextObj = ShapeHelper.createShape( xDrawDoc, new Point( 10000, 9000 ), + new Size( 10000, 5000 ), + "com.sun.star.drawing.TextShape" ); + 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 = 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 = UnoRuntime.queryInterface( XSingleServiceFactory.class, xNameContainer ); + + Object xObj; + XIndexContainer xContainer; + + /* instantiate an IndexContainer that will take + a list of draw pages for the first custom show */ + xObj = xFactory.createInstance(); + xContainer = UnoRuntime.queryInterface( XIndexContainer.class, xObj ); + for ( i = 5; i < 10; i++ ) + xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) ); + xNameContainer.insertByName( "ShortVersion", xContainer ); + + /* instantiate an IndexContainer that will take + a list of draw page for the second custom show */ + xObj = xFactory.createInstance(); + xContainer = UnoRuntime.queryInterface( XIndexContainer.class, xObj ); + for ( i = 1; i < 10; i++ ) + xContainer.insertByIndex( xContainer.getCount(), xDrawPages.getByIndex( i ) ); + xNameContainer.insertByName( "LongVersion", xContainer ); + + /* which custom show is to use + can been set in the presentation settings */ + + XPresentationSupplier xPresSupplier = UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); + XPresentation xPresentation = xPresSupplier.getPresentation(); + XPropertySet xPresPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); + xPresPropSet.setPropertyValue( "CustomShow", "ShortVersion" ); + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java b/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java new file mode 100644 index 000000000..111915366 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/DrawViewDemo.java @@ -0,0 +1,142 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.beans.Property; +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; + +import com.sun.star.container.XIndexAccess; + +import com.sun.star.document.XViewDataSupplier; + +import com.sun.star.frame.XModel; +import com.sun.star.frame.XController; + + + +// __________ Implementation __________ + +// text demo + +public class DrawViewDemo +{ + public static void main( String args[] ) + { + if ( args.length < 1 ) + { + System.out.println( "usage: DrawViewDemo SourceURL" ); + System.exit(1); + } + + XComponent xComponent = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + java.io.File sourceFile = new java.io.File(args[0]); + StringBuffer sUrl = new StringBuffer("file:///"); + sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); + + xComponent = Helper.createDocument( xOfficeContext, + sUrl.toString(), "_blank", 0, + pPropValues ); + XModel xModel = + UnoRuntime.queryInterface( + XModel.class, xComponent ); + + + // print all available properties of first view + System.out.println("*** print all available properties of first view"); + XViewDataSupplier xViewDataSupplier = + UnoRuntime.queryInterface( + XViewDataSupplier.class, xModel ); + XIndexAccess xIndexAccess = xViewDataSupplier.getViewData(); + if ( xIndexAccess.getCount() != 0 ) + { + PropertyValue[] aPropSeq = (PropertyValue[]) + xIndexAccess.getByIndex( 0 ); + + for( int i = 0; i < aPropSeq.length; i++ ) + { + System.out.println( aPropSeq[ i ].Name + " = " + + aPropSeq[ i ].Value ); + } + } + + + // print all properties that are supported by the controller + // and change into masterpage mode + System.out.println("*** print all properties that are supported by the controller"); + XController xController = xModel.getCurrentController(); + XPropertySet xPropSet = + UnoRuntime.queryInterface( + XPropertySet.class, xController ); + XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo(); + Property[] aPropSeq = xPropSetInfo.getProperties(); + for( int i = 0; i < aPropSeq.length; i++ ) + { + System.out.println( aPropSeq[ i ].Name ); + } + System.out.println("*** change into masterpage mode"); + xPropSet.setPropertyValue( "IsMasterPageMode", Boolean.TRUE ); + + } + catch( Exception ex ) + { + System.out.println( ex.getMessage() ); + ex.printStackTrace(System.err); + } + + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java b/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java new file mode 100644 index 000000000..f71197cf6 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/DrawingDemo.java @@ -0,0 +1,419 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.container.XNamed; + +import com.sun.star.drawing.PolygonFlags; +import com.sun.star.drawing.PolyPolygonBezierCoords; +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XShapeGrouper; +import com.sun.star.drawing.XDrawPage; + +import java.util.Random; + + +// __________ Implementation __________ + +// drawing demo + +// This drawing demo will create/load a document, and show how to +// handle pages and shapes using the Office API, + +// Calling this demo two parameter can be used. The first parameter +// describes if a document is to create or load: "draw" creates a +// draw document, "impress" creates an impress document, any other +// parameter is interpreted as URL and loads the corresponding +// document. ( example for a URL is: "file:///c:/test.odp" ) +// The second parameter is the connection that is to use. If no parameter +// is given a standard impress document is created by using following +// connection: "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager"; + +public class DrawingDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + String sURL; + if ( args.length == 0 ) + sURL = "impress"; + else + sURL = args[ 0 ]; + + if ( sURL.equals( "draw" ) ) + sURL = "private:factory/sdraw"; + else if ( sURL.equals( "impress" ) ) + sURL = "private:factory/simpress"; + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + sURL, "_blank", 0, pPropValues ); + } + catch( Exception ex ) + { + System.out.println( ex ); + System.exit( 0 ); + } + + + Demo_PageCreation( xDrawDoc, 10 ); + Demo_PageNaming( xDrawDoc, "this page is called: LastPage" ); + Demo_ShapeCreation( xDrawDoc ); + Demo_PolyPolygonBezier( xDrawDoc ); + Demo_Group1( xDrawDoc ); + Demo_Group2( xDrawDoc ); + System.exit( 0 ); + } + + // This method appends draw pages to the document, so that a + // minimum of n draw pages will be available. + // For each second draw page also a new master page is created. + public static void Demo_PageCreation( XComponent xDrawDoc, int n ) + { + try + { + // If the document has less than n draw pages, append them, + // a minimum of n draw pages will be available + int i, nDrawPages; + for ( nDrawPages = PageHelper.getDrawPageCount( xDrawDoc ); + nDrawPages < n; nDrawPages++ ) + PageHelper.insertNewDrawPageByIndex( xDrawDoc, nDrawPages ); + // Create a master page for each second drawpage + int nMasterPages; + for ( nMasterPages = PageHelper.getMasterPageCount( xDrawDoc ); + nMasterPages < ( ( nDrawPages + 1 ) / 2 ); nMasterPages++ ) + PageHelper.insertNewMasterPageByIndex( xDrawDoc, nMasterPages ); + + // Now connect master page 1 to draw page 1 and 2, + // master page 2 to draw page 3 and 4 and so on. + for ( i = 0; i < nDrawPages; i++ ) + { + XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, i ); + XDrawPage xMasterPage = PageHelper.getMasterPageByIndex( + xDrawDoc, i / 2 ); + PageHelper.setMasterPage( xDrawPage, xMasterPage ); + } + } + catch( Exception ex ) + { + System.out.println("Demo_PageCreation: I have a page creation problem"); + } + } + + // this method shows how to name a page, this is exemplary + // be done for the last draw page + public static void Demo_PageNaming( + XComponent xDrawDoc, String sLastPageName ) + { + try + { + XDrawPage xLastPage = PageHelper.getDrawPageByIndex( xDrawDoc, + PageHelper.getDrawPageCount( xDrawDoc ) - 1 ); + + // each drawpage is supporting an XNamed interface + XNamed xNamed = UnoRuntime.queryInterface( + XNamed.class, xLastPage ); + + // beware, the page must have a unique name + xNamed.setName( sLastPageName ); + } + catch( Exception ex ) + { + System.out.println( "Demo_PageNaming: can't set page name" ); + } + } + + // This method will add one rectangle shape into the lower left quarter of + // every page that is available, + public static void Demo_ShapeCreation( XComponent xDrawDoc ) + { + try + { + boolean bIsImpressDocument = PageHelper.isImpressDocument( xDrawDoc ); + + int nDrawingPages = PageHelper.getDrawPageCount( xDrawDoc ); + int nMasterPages = PageHelper.getMasterPageCount( xDrawDoc ); + int nGlobalPageCount = nDrawingPages + nMasterPages; + + if ( bIsImpressDocument ) + { + // in impress each draw page also has a notes page + nGlobalPageCount += nDrawingPages; + // for each drawing master is also a notes master available + nGlobalPageCount += nMasterPages; + // one handout is existing + nGlobalPageCount += 1; + } + + // create and fill a container with all draw pages + XDrawPage[] pPages = new XDrawPage[ nGlobalPageCount ]; + int i, nCurrentPageIndex = 0; + + // insert handout page + if ( bIsImpressDocument ) + pPages[ nCurrentPageIndex++ ] = PageHelper.getHandoutMasterPage( + xDrawDoc ); + + // inserting all master pages + for( i = 0; i < nMasterPages; i++ ) + { + XDrawPage xMasterPage = PageHelper.getMasterPageByIndex( + xDrawDoc, i ); + pPages[ nCurrentPageIndex++ ] = xMasterPage; + + // if the document is an impress, get the corresponding notes + // master page + if ( bIsImpressDocument ) + pPages[ nCurrentPageIndex++ ] = PageHelper.getNotesPage( + xMasterPage ); + } + for ( i = 0; i < nDrawingPages; i++ ) + { + XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, i ); + pPages[ nCurrentPageIndex++ ] = xDrawPage; + + // if the document is an impress, get the corresponding notes page + if ( bIsImpressDocument ) + pPages[ nCurrentPageIndex++ ] = PageHelper.getNotesPage( + xDrawPage ); + } + + // Now a complete list of pages is available in pPages. + // The following code will insert a rectangle into each page. + for ( i = 0; i < nGlobalPageCount; i++ ) + { + Size aPageSize = PageHelper.getPageSize( pPages[ i ] ); + int nHalfWidth = aPageSize.Width / 2; + int nHalfHeight = aPageSize.Height / 2; + + Random aRndGen = new Random(); + int nRndObjWidth = aRndGen.nextInt( nHalfWidth ); + int nRndObjHeight = aRndGen.nextInt( nHalfHeight ); + + int nRndObjPosX = aRndGen.nextInt( nHalfWidth - nRndObjWidth ); + int nRndObjPosY = aRndGen.nextInt( nHalfHeight - nRndObjHeight ) + + nHalfHeight; + + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, pPages[ i ] ); + ShapeHelper.createAndInsertShape( xDrawDoc, xShapes, + new Point( nRndObjPosX, nRndObjPosY ), + new Size( nRndObjWidth, nRndObjHeight ), + "com.sun.star.drawing.RectangleShape" ); + } + } + catch( Exception ex ) + { + System.out.println( "Demo_ShapeCreation:" + ex ); + } + } + + // This method will show how to create a PolyPolygonBezier that lies is in the + // topleft quarter of the page and positioned at the back + public static void Demo_PolyPolygonBezier( XComponent xDrawDoc ) + { + try + { + XShape xPolyPolygonBezier = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), + new Size( 0, 0 ), + "com.sun.star.drawing.ClosedBezierShape" ); + + // the fact that the shape must have been added to the page before + // it is possible to apply changes to the PropertySet, it is a good + // proceeding to add the shape as soon as possible + XDrawPage xDrawPage; + // if possible insert our new shape in the master page + if ( PageHelper.isImpressDocument( xDrawDoc ) ) + xDrawPage = PageHelper.getMasterPageByIndex( xDrawDoc, 0 ); + else + xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + xShapes.add( xPolyPolygonBezier ); + + XPropertySet xShapeProperties = UnoRuntime.queryInterface( XPropertySet.class, xPolyPolygonBezier ); + + // get pagesize + XPropertySet xPageProperties = UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); + int nPageWidth = ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue() / 2; + int nPageHeight = ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() / 2; + + PolyPolygonBezierCoords aCoords = new PolyPolygonBezierCoords(); + // allocating the outer sequence + int nPolygonCount = 50; + aCoords.Coordinates = new Point[ nPolygonCount ][ ]; + aCoords.Flags = new PolygonFlags[ nPolygonCount ][ ]; + int i, n, nY; + // fill the inner point sequence now + for ( nY = 0, i = 0; i < nPolygonCount; i++, nY += nPageHeight / nPolygonCount ) + { + // create a polygon using two normal and two control points + // allocating the inner sequence + int nPointCount = 8; + Point[] pPolyPoints = new Point[ nPointCount ]; + PolygonFlags[] pPolyFlags = new PolygonFlags[ nPointCount ]; + + for ( n = 0; n < nPointCount; n++ ) + pPolyPoints[ n ] = new Point(); + + pPolyPoints[ 0 ].X = 0; + pPolyPoints[ 0 ].Y = nY; + pPolyFlags[ 0 ] = PolygonFlags.NORMAL; + pPolyPoints[ 1 ].X = nPageWidth / 2; + pPolyPoints[ 1 ].Y = nPageHeight; + pPolyFlags[ 1 ] = PolygonFlags.CONTROL; + pPolyPoints[ 2 ].X = nPageWidth / 2; + pPolyPoints[ 2 ].Y = nPageHeight; + pPolyFlags[ 2 ] = PolygonFlags.CONTROL; + pPolyPoints[ 3 ].X = nPageWidth; + pPolyPoints[ 3 ].Y = nY; + pPolyFlags[ 3 ] = PolygonFlags.NORMAL; + + pPolyPoints[ 4 ].X = nPageWidth - 1000; + pPolyPoints[ 4 ].Y = nY; + pPolyFlags[ 4 ] = PolygonFlags.NORMAL; + pPolyPoints[ 5 ].X = nPageWidth / 2; + pPolyPoints[ 5 ].Y = nPageHeight / 2; + pPolyFlags[ 5 ] = PolygonFlags.CONTROL; + pPolyPoints[ 6 ].X = nPageWidth / 2; + pPolyPoints[ 6 ].Y = nPageHeight / 2; + pPolyFlags[ 6 ] = PolygonFlags.CONTROL; + pPolyPoints[ 7 ].X = 1000; + pPolyPoints[ 7 ].Y = nY; + pPolyFlags[ 7 ] = PolygonFlags.NORMAL; + + aCoords.Coordinates[ i ]= pPolyPoints; + aCoords.Flags[ i ] = pPolyFlags; + } + xShapeProperties.setPropertyValue( "PolyPolygonBezier", aCoords ); + + // move the shape to the back by changing the ZOrder + xShapeProperties.setPropertyValue( "ZOrder", Integer.valueOf( 1 ) ); + } + catch ( Exception ex ) + { + System.out.println( "Demo_PolyPolygonBezier:" + ex ); + } + } + + // This method will create a group containing two ellipses + // the shapes will be added into the top right corner of the first + // draw page + public static void Demo_Group1( XComponent xDrawDoc ) + { + try + { + XShape xGroup = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), + new Size( 0, 0 ), + "com.sun.star.drawing.GroupShape" ); + + // before it is possible to insert shapes, + // the group must have been added to the page + XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + xShapes.add( xGroup ); + + XShapes xShapesGroup = UnoRuntime.queryInterface( XShapes.class, xGroup ); + + Size aPageSize = PageHelper.getPageSize( xDrawPage ); + + int nWidth = 4000; + int nHeight = 2000; + int nPosX = ( aPageSize.Width * 3 ) / 4 - nWidth / 2; + int nPosY1 = 2000; + int nPosY2 = aPageSize.Height / 2 - ( nPosY1 + nHeight ); + XShape xRect1 = ShapeHelper.createShape( xDrawDoc, + new Point( nPosX, nPosY1 ), + new Size( nWidth, nHeight ), + "com.sun.star.drawing.EllipseShape" ); + XShape xRect2 = ShapeHelper.createShape( xDrawDoc, + new Point( nPosX, nPosY2 ), + new Size( nWidth, nHeight ), + "com.sun.star.drawing.EllipseShape" ); + + xShapesGroup.add( xRect1 ); + xShapesGroup.add( xRect2 ); + } + catch ( Exception ex ) + { + System.out.println( "Demo_Group1:" + ex ); + } + } + + // This method will group all available objects on the + // first page. + public static void Demo_Group2( XComponent xDrawDoc ) + { + try + { + XDrawPage xDrawPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapeGrouper xShapeGrouper = UnoRuntime.queryInterface( XShapeGrouper.class, xDrawPage ); + + XShapes xShapesPage = UnoRuntime.queryInterface( XShapes.class, xDrawPage ); + + xShapeGrouper.group( xShapesPage ); + } + catch ( Exception ex ) + { + System.out.println( "Demo_Group2:" + ex ); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java b/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java new file mode 100644 index 000000000..1f678b307 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/FillAndLineStyleDemo.java @@ -0,0 +1,132 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.drawing.LineDash; +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; + +import com.sun.star.awt.Gradient; +import com.sun.star.awt.GradientStyle; +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + + +// __________ Implementation __________ + +// FillStyle and LineStyle demo + +public class FillAndLineStyleDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/sdraw", "_blank", 0, pPropValues ); + + XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + + XShape xRectangle = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), + new Size( 15000, 12000 ), + "com.sun.star.drawing.RectangleShape" ); + + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + xShapes.add( 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 */ + xPropSet.setPropertyValue( "FillStyle", + com.sun.star.drawing.FillStyle.GRADIENT ); + Gradient aGradient = new Gradient(); + aGradient.Style = GradientStyle.LINEAR; + aGradient.StartColor = 0x00ff00; + aGradient.EndColor = 0xffff00; + aGradient.Angle = 450; + aGradient.Border = 0; + aGradient.XOffset = 0; + aGradient.YOffset = 0; + aGradient.StartIntensity = 100; + aGradient.EndIntensity = 100; + aGradient.StepCount = 10; + xPropSet.setPropertyValue( "FillGradient", aGradient ); + + /* create a blue line with dashes and dots */ + xPropSet.setPropertyValue( "LineStyle", + com.sun.star.drawing.LineStyle.DASH ); + LineDash aLineDash = new LineDash(); + aLineDash.Dots = 3; + aLineDash.DotLen = 150; + aLineDash.Dashes = 3; + aLineDash.DashLen = 300; + aLineDash.Distance = 150; + xPropSet.setPropertyValue( "LineDash", aLineDash ); + xPropSet.setPropertyValue( "LineColor", Integer.valueOf( 0x0000ff ) ); + xPropSet.setPropertyValue( "LineWidth", Integer.valueOf( 200 ) ); + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java b/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java new file mode 100644 index 000000000..f45ea385a --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/GluePointDemo.java @@ -0,0 +1,182 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.container.XIndexContainer; +import com.sun.star.container.XIdentifierContainer; + +import com.sun.star.drawing.Alignment; +import com.sun.star.drawing.EscapeDirection; +import com.sun.star.drawing.GluePoint2; +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XGluePointsSupplier; + + + +// __________ Implementation __________ + +// GluePointDemo + +public class GluePointDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/sdraw", "_blank", 0, pPropValues ); + + + XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + + // create two rectangles + XShape xShape1 = ShapeHelper.createShape( xDrawDoc, + new Point( 15000, 1000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.RectangleShape" ); + + XShape xShape2 = ShapeHelper.createShape( xDrawDoc, + new Point( 2000, 15000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.EllipseShape" ); + + // and a connector + XShape xConnector = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), + new Size( 0, 0 ), + "com.sun.star.drawing.ConnectorShape" ); + + xShapes.add( xShape1 ); + xShapes.add( xShape2 ); + xShapes.add( 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 +// Index value of 2 : the shape is connected at the bottom +// Index value of 3 : the shape is connected at the right + + int nStartIndex = 3; + int nEndIndex = 1; + + // the "StartPosition" or "EndPosition" property needs not to be set + // if there is a shape to connect + xConnectorPropSet.setPropertyValue( "StartShape", xShape1 ); + xConnectorPropSet.setPropertyValue( "StartGluePointIndex", + Integer.valueOf( nStartIndex ) ); + + xConnectorPropSet.setPropertyValue( "EndShape", xShape2 ); + xConnectorPropSet.setPropertyValue( "EndGluePointIndex", + Integer.valueOf( nEndIndex ) ); + + XGluePointsSupplier xGluePointsSupplier; + XIndexContainer xIndexContainer; + XIdentifierContainer xIdentifierContainer; + + GluePoint2 aGluePoint = new GluePoint2(); + aGluePoint.IsRelative = false; + aGluePoint.PositionAlignment = Alignment.CENTER; + aGluePoint.Escape = EscapeDirection.SMART; + aGluePoint.IsUserDefined = true; + aGluePoint.Position.X = 0; + aGluePoint.Position.Y = 0; + + // create and insert a glue point at shape1 + xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape1 ); + xIndexContainer = xGluePointsSupplier.getGluePoints(); + xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class, + xIndexContainer ); + int nIndexOfGluePoint1 = xIdentifierContainer.insert( aGluePoint ); + + // create and insert a glue point at shape2 + xGluePointsSupplier = UnoRuntime.queryInterface( XGluePointsSupplier.class, xShape2 ); + xIndexContainer = xGluePointsSupplier.getGluePoints(); + xIdentifierContainer = UnoRuntime.queryInterface( XIdentifierContainer.class, + xIndexContainer ); + int nIndexOfGluePoint2 = xIdentifierContainer.insert( aGluePoint ); + + // create and add a connector + XShape xConnector2 = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), + new Size( 0, 0 ), + "com.sun.star.drawing.ConnectorShape" ); + xShapes.add( xConnector2 ); + + XPropertySet xConnector2PropSet = UnoRuntime.queryInterface( XPropertySet.class, xConnector2 ); + + xConnector2PropSet.setPropertyValue( "StartShape", xShape1 ); + xConnector2PropSet.setPropertyValue( "StartGluePointIndex", + Integer.valueOf( nIndexOfGluePoint1 ) ); + + xConnector2PropSet.setPropertyValue( "EndShape", xShape2 ); + xConnector2PropSet.setPropertyValue( "EndGluePointIndex", + Integer.valueOf( nIndexOfGluePoint2 ) ); + + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java b/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java new file mode 100644 index 000000000..2b8ad77de --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/GraphicExportDemo.java @@ -0,0 +1,148 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.beans.PropertyValue; + +import com.sun.star.document.XExporter; +import com.sun.star.document.XFilter; + +import com.sun.star.drawing.XDrawPage; + +// __________ Implementation __________ + +// text demo + +public class GraphicExportDemo +{ + public static void main( String args[] ) + { + if ( args.length < 3 ) + { + System.out.println( "usage: GraphicExportDemo SourceURL DestinationURL PageIndexToExport" ); + System.exit(1); + } + + XComponent xComponent = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + java.io.File sourceFile = new java.io.File(args[0]); + StringBuffer sUrl = new StringBuffer("file:///"); + sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/')); + + xComponent = Helper.createDocument( xOfficeContext, + sUrl.toString(), "_blank", 0, + pPropValues ); + + Object GraphicExportFilter = + xOfficeContext.getServiceManager().createInstanceWithContext( + "com.sun.star.drawing.GraphicExportFilter", xOfficeContext); + XExporter xExporter = UnoRuntime.queryInterface( XExporter.class, GraphicExportFilter ); + + PropertyValue aProps[] = new PropertyValue[2]; + aProps[0] = new PropertyValue(); + aProps[0].Name = "MediaType"; + aProps[0].Value = "image/gif"; + + /* some graphics e.g. the Windows Metafile does not have a Media Type, + for this case + aProps[0].Name = "FilterName"; // it is possible to set a FilterName + aProps[0].Value = "WMF"; + */ + java.io.File destFile = new java.io.File(args[1]); + java.net.URL destUrl = destFile.toURI().toURL(); + + aProps[1] = new PropertyValue(); + aProps[1].Name = "URL"; + aProps[1].Value = destUrl.toString();//args[ 1 ]; + + int nPageIndex = Integer.parseInt( args[ 2 ] ); + if ( nPageIndex < PageHelper.getDrawPageCount( xComponent ) && + nPageIndex > 1 ) + { + XDrawPage xPage = PageHelper.getDrawPageByIndex( xComponent, + nPageIndex ); + XComponent xComp = UnoRuntime.queryInterface( XComponent.class, xPage ); + xExporter.setSourceDocument( xComp ); + XFilter xFilter = UnoRuntime.queryInterface( XFilter.class, xExporter ); + xFilter.filter( aProps ); + System.out.println( "*** graphics on page \"" + nPageIndex + + "\" from file \"" + args[0] + + "\" exported under the name \"" + + args[1] + "\" in the local directory" ); + } else + { + System.out.println( "page index not in range" ); + } + + + // close the document + com.sun.star.util.XCloseable xCloseable = UnoRuntime.queryInterface(com.sun.star.util.XCloseable.class, + xComponent); + + if (xCloseable != null ) + xCloseable.close(false); + else + xComponent.dispose(); + + System.out.println("*** document closed!"); + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/Helper.java b/odk/examples/DevelopersGuide/Drawing/Helper.java new file mode 100644 index 000000000..5e5c52d1f --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/Helper.java @@ -0,0 +1,89 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ 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 +{ + // __________ static helper methods __________ + + /** Connect to an office, if no office is running a new instance is started. + * A new connection is established and the service manager from the running + * office is returned. + */ + public static XComponentContext connect() + throws Exception + { + // get the remote office component context + XComponentContext xOfficeContext = + com.sun.star.comp.helper.Bootstrap.bootstrap(); + + // if connection fails an exception is thrown + System.out.println("Connected to a running office ..."); + + return xOfficeContext; + } + + /** creates and instantiates new document + */ + public static com.sun.star.lang.XComponent createDocument( + com.sun.star.uno.XComponentContext xOfficeContext, + String sURL, String sTargetFrame, int nSearchFlags, + com.sun.star.beans.PropertyValue[] aArgs ) + throws Exception + { + XComponentLoader aLoader = + UnoRuntime.queryInterface( + XComponentLoader.class, + xOfficeContext.getServiceManager().createInstanceWithContext( + "com.sun.star.frame.Desktop", xOfficeContext)); + + XComponent xComponent = + UnoRuntime.queryInterface( + XComponent.class, aLoader.loadComponentFromURL( + sURL, sTargetFrame, nSearchFlags, aArgs ) ); + + if ( xComponent == null ) + throw new Exception( "could not create document: " + sURL ); + return xComponent; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/LayerDemo.java b/odk/examples/DevelopersGuide/Drawing/LayerDemo.java new file mode 100644 index 000000000..4687cdc54 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/LayerDemo.java @@ -0,0 +1,152 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.container.XNameAccess; + +import com.sun.star.style.ParagraphAdjust; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XLayer; +import com.sun.star.drawing.XLayerManager; +import com.sun.star.drawing.XLayerSupplier; + + +// __________ Implementation __________ + +// LayerDemo + +public class LayerDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/sdraw", "_blank", 0, pPropValues ); + + + // create two rectangles + XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + + XShape xRect1 = ShapeHelper.createShape( xDrawDoc, + new Point( 1000, 1000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.RectangleShape" ); + + XShape xRect2 = ShapeHelper.createShape( xDrawDoc, + new Point( 1000, 7000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.RectangleShape" ); + + xShapes.add( xRect1 ); + xShapes.add( xRect2 ); + XPropertySet xTextProp = ShapeHelper.addPortion( xRect2, + "this shape is locked", + false ); + xTextProp.setPropertyValue( "ParaAdjust", ParagraphAdjust.CENTER ); + ShapeHelper.addPortion( xRect2, "and the shape above is not visible", + true ); + ShapeHelper.addPortion( xRect2, + "(switch to the layer view to gain access)", + true ); + + + // query for the XLayerManager + XLayerSupplier xLayerSupplier = UnoRuntime.queryInterface( + XLayerSupplier.class, xDrawDoc ); + XNameAccess xNameAccess = xLayerSupplier.getLayerManager(); + XLayerManager xLayerManager = UnoRuntime.queryInterface( + XLayerManager.class, xNameAccess ); + + // create a layer and set its properties + XPropertySet xLayerPropSet; + XLayer xNotVisibleAndEditable = xLayerManager.insertNewByIndex( + xLayerManager.getCount() ); + + xLayerPropSet = UnoRuntime.queryInterface( + XPropertySet.class, xNotVisibleAndEditable ); + xLayerPropSet.setPropertyValue( "Name", "NotVisibleAndEditable" ); + xLayerPropSet.setPropertyValue( "IsVisible", Boolean.FALSE ); + xLayerPropSet.setPropertyValue( "IsLocked", Boolean.TRUE ); + + // create a second layer + XLayer xNotEditable = xLayerManager.insertNewByIndex( + xLayerManager.getCount() ); + + xLayerPropSet = UnoRuntime.queryInterface( + XPropertySet.class, xNotEditable ); + xLayerPropSet.setPropertyValue( "Name", "NotEditable" ); + xLayerPropSet.setPropertyValue( "IsVisible", Boolean.TRUE ); + xLayerPropSet.setPropertyValue( "IsLocked", Boolean.TRUE ); + + // attach the layer to the rectangles + xLayerManager.attachShapeToLayer( xRect1, xNotVisibleAndEditable ); + xLayerManager.attachShapeToLayer( xRect2, xNotEditable ); + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/Makefile b/odk/examples/DevelopersGuide/Drawing/Makefile new file mode 100644 index 000000000..e5bbf1bf1 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/Makefile @@ -0,0 +1,174 @@ +#************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the Drawing examples of the Developers Guide. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk + +# Define non-platform/compiler specific settings +SAMPLE_NAME=DrawingExamples +SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME) +SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME) + +APP1_NAME=ChangeOrderDemo +APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar +APP2_NAME=ControlAndSelectDemo +APP2_JAR=$(SAMPLE_CLASS_OUT)/$(APP2_NAME).jar +APP3_NAME=CustomShowDemo +APP3_JAR=$(SAMPLE_CLASS_OUT)/$(APP3_NAME).jar +APP4_NAME=DrawingDemo +APP4_JAR=$(SAMPLE_CLASS_OUT)/$(APP4_NAME).jar +APP5_NAME=DrawViewDemo +APP5_JAR=$(SAMPLE_CLASS_OUT)/$(APP5_NAME).jar +APP6_NAME=FillAndLineStyleDemo +APP6_JAR=$(SAMPLE_CLASS_OUT)/$(APP6_NAME).jar +APP7_NAME=GluePointDemo +APP7_JAR=$(SAMPLE_CLASS_OUT)/$(APP7_NAME).jar +APP8_NAME=GraphicExportDemo +APP8_JAR=$(SAMPLE_CLASS_OUT)/$(APP8_NAME).jar +APP9_NAME=LayerDemo +APP9_JAR=$(SAMPLE_CLASS_OUT)/$(APP9_NAME).jar +APP10_NAME=ObjectTransformationDemo +APP10_JAR=$(SAMPLE_CLASS_OUT)/$(APP10_NAME).jar +APP11_NAME=Organigram +APP11_JAR=$(SAMPLE_CLASS_OUT)/$(APP11_NAME).jar +APP12_NAME=PresentationDemo +APP12_JAR=$(SAMPLE_CLASS_OUT)/$(APP12_NAME).jar +APP13_NAME=StyleDemo +APP13_JAR=$(SAMPLE_CLASS_OUT)/$(APP13_NAME).jar +APP14_NAME=TextDemo +APP14_JAR=$(SAMPLE_CLASS_OUT)/$(APP14_NAME).jar + +APP_JAVAFILES = \ + Helper.java \ + PageHelper.java \ + ShapeHelper.java + +APP_CLASSFILES = $(patsubst %.java,$(SAMPLE_CLASS_OUT)/%.class,$(APP_JAVAFILES)) +APP_CLASSNAMES = $(patsubst %.java,%.class,$(APP_JAVAFILES)) + +SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\ + $(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)) + + +# Targets +.PHONY: ALL +ALL : \ + DrawingExamples + +include $(SETTINGS)/stdtarget.mk + +$(APP_CLASSFILES) : $(APP_JAVAFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $(APP_JAVAFILES) + +$(SAMPLE_CLASS_OUT)/%.class : %.java $(APP_CLASSFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $< + +$(SAMPLE_CLASS_OUT)/%.mf : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo Main-Class: com.sun.star.lib.loader.Loader> $@ + $(ECHOLINE)>> $@ + @echo Name: com/sun/star/lib/loader/Loader.class>> $@ + @echo Application-Class: $*>> $@ + +$(SAMPLE_CLASS_OUT)/%.jar : $(SAMPLE_CLASS_OUT)/%.mf $(SAMPLE_CLASS_OUT)/%.class $(APP_CLASSFILES) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(@D)) + +cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class $(APP_CLASSNAMES) + +$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES) + +$(APP1_JAR) : $(SAMPLE_CLASS_OUT)/$(APP1_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP1_NAME).class +$(APP2_JAR) : $(SAMPLE_CLASS_OUT)/$(APP2_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP2_NAME).class +$(APP3_JAR) : $(SAMPLE_CLASS_OUT)/$(APP3_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP3_NAME).class +$(APP4_JAR) : $(SAMPLE_CLASS_OUT)/$(APP4_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP4_NAME).class +$(APP5_JAR) : $(SAMPLE_CLASS_OUT)/$(APP5_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP5_NAME).class +$(APP6_JAR) : $(SAMPLE_CLASS_OUT)/$(APP6_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP6_NAME).class +$(APP7_JAR) : $(SAMPLE_CLASS_OUT)/$(APP7_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP7_NAME).class +$(APP8_JAR) : $(SAMPLE_CLASS_OUT)/$(APP8_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP8_NAME).class +$(APP9_JAR) : $(SAMPLE_CLASS_OUT)/$(APP9_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP9_NAME).class +$(APP10_JAR) : $(SAMPLE_CLASS_OUT)/$(APP10_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP10_NAME).class +$(APP11_JAR) : $(SAMPLE_CLASS_OUT)/$(APP11_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP11_NAME).class +$(APP12_JAR) : $(SAMPLE_CLASS_OUT)/$(APP12_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP12_NAME).class +$(APP13_JAR) : $(SAMPLE_CLASS_OUT)/$(APP13_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP13_NAME).class +$(APP14_JAR) : $(SAMPLE_CLASS_OUT)/$(APP14_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP14_NAME).class + +DrawingExamples : $(APP1_JAR) $(APP2_JAR) $(APP3_JAR) $(APP4_JAR) $(APP5_JAR) $(APP6_JAR) $(APP7_JAR) $(APP8_JAR) $(APP9_JAR) $(APP10_JAR) $(APP11_JAR) $(APP12_JAR) $(APP13_JAR) $(APP14_JAR) + @echo -------------------------------------------------------------------------------- + @echo Please use one of the following commands to execute the examples! + @echo - + @echo $(MAKE) $(APP1_NAME).run + @echo $(MAKE) $(APP2_NAME).run + @echo $(MAKE) $(APP3_NAME).run + @echo $(MAKE) $(APP4_NAME).run + @echo $(MAKE) $(APP5_NAME).run + @echo $(MAKE) $(APP6_NAME).run + @echo $(MAKE) $(APP7_NAME).run + @echo $(MAKE) $(APP8_NAME).run + @echo $(MAKE) $(APP9_NAME).run + @echo $(MAKE) $(APP10_NAME).run + @echo $(MAKE) $(APP11_NAME).run + @echo $(MAKE) $(APP12_NAME).run + @echo $(MAKE) $(APP13_NAME).run + @echo $(MAKE) $(APP14_NAME).run + @echo -------- + @echo The $(APP5_NAME) and the $(APP8_NAME) needs parameters. Please use the + @echo following command to start the demo if you do not want the default parameters + @echo specified in the this makefile: + @echo --- $(APP5_NAME) --- + @echo java -Dcom.sun.star.lib.loader.unopath="$(QM)$(OFFICE_PROGRAM_PATH)$(QM)" -jar $(APP5_NAME).jar "$(QM)SourceUrl$(QM)" + @echo --- $(APP8_NAME) --- + @echo java -Dcom.sun.star.lib.loader.unopath="$(QM)$(OFFICE_PROGRAM_PATH)$(QM)" -jar $(APP8_NAME).jar "$(QM)SourceUrl$(QM)" "$(QM)DestinationUrl$(QM)" "$(QM)index$(QM)" + @echo -------------------------------------------------------------------------------- + +%.run: $(SAMPLE_CLASS_OUT)/%.jar + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< + +$(APP5_NAME).run: $(APP5_JAR) + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< SimplePresentation.odp + +$(APP8_NAME).run: $(APP8_JAR) + -$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/export) + $(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< SimplePresentation.odp "$(SAMPLE_GEN_OUT)/export/MyTestExport.gif" 2 + + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) + -$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT)) diff --git a/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java b/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java new file mode 100644 index 000000000..5bf81e577 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/ObjectTransformationDemo.java @@ -0,0 +1,131 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.HomogenMatrix3; + +import java.awt.geom.AffineTransform; + +// __________ Implementation __________ + +// ObjectTransformationDemo + +public class ObjectTransformationDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/simpress", "_blank", 0, pPropValues ); + + XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XPropertySet xPagePropSet= UnoRuntime.queryInterface( XPropertySet.class, xPage ); + + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + + + XShape xShape = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), new Size( 10000, 2500 ), + "com.sun.star.drawing.RectangleShape" ); + xShapes.add( xShape ); + + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); + + HomogenMatrix3 aHomogenMatrix3 = (HomogenMatrix3) + xPropSet.getPropertyValue( "Transformation" ); + + java.awt.geom.AffineTransform aOriginalMatrix = + new java.awt.geom.AffineTransform( + aHomogenMatrix3.Line1.Column1, aHomogenMatrix3.Line2.Column1, + aHomogenMatrix3.Line1.Column2, aHomogenMatrix3.Line2.Column2, + aHomogenMatrix3.Line1.Column3, aHomogenMatrix3.Line2.Column3 ); + + + AffineTransform aNewMatrix1 = new AffineTransform(); + aNewMatrix1.setToRotation( Math.PI /180 * 15 ); + aNewMatrix1.concatenate( aOriginalMatrix ); + + AffineTransform aNewMatrix2 = new AffineTransform(); + aNewMatrix2.setToTranslation( 2000, 2000 ); + aNewMatrix2.concatenate( aNewMatrix1 ); + + double aFlatMatrix[] = new double[ 6 ]; + aNewMatrix2.getMatrix( aFlatMatrix ); + aHomogenMatrix3.Line1.Column1 = aFlatMatrix[ 0 ]; + aHomogenMatrix3.Line2.Column1 = aFlatMatrix[ 1 ]; + aHomogenMatrix3.Line1.Column2 = aFlatMatrix[ 2 ]; + aHomogenMatrix3.Line2.Column2 = aFlatMatrix[ 3 ]; + aHomogenMatrix3.Line1.Column3 = aFlatMatrix[ 4 ]; + aHomogenMatrix3.Line2.Column3 = aFlatMatrix[ 5 ]; + xPropSet.setPropertyValue( "Transformation", aHomogenMatrix3 ); + + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/Organigram.java b/odk/examples/DevelopersGuide/Drawing/Organigram.java new file mode 100644 index 000000000..5a496086e --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/Organigram.java @@ -0,0 +1,176 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +import com.sun.star.beans.PropertyValue; +import com.sun.star.frame.XComponentLoader; + +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiComponentFactory; + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.uno.AnyConverter; +import com.sun.star.uno.XComponentContext; + + +public class Organigram { + + private XComponentContext xRemoteContext = null; + private XMultiComponentFactory xRemoteServiceManager = null; + + /** Creates a new instance of OpenQuery */ + public Organigram() { + } + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + Organigram organigram1 = new Organigram(); + try { + organigram1.drawOrganigram(); + } + catch (java.lang.Exception e){ + e.printStackTrace(); + } + finally { + System.exit(0); + } + } + public void drawOrganigram() throws java.lang.Exception { + // get the remote office component context + xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); + System.out.println("Connected to a running office ..."); + // get the remote service manager + xRemoteServiceManager = xRemoteContext.getServiceManager(); + + Object desktop = xRemoteServiceManager.createInstanceWithContext( + "com.sun.star.frame.Desktop", xRemoteContext); + XComponentLoader xComponentLoader = UnoRuntime.queryInterface(XComponentLoader.class, desktop); + + PropertyValue[] loadProps = new PropertyValue[0]; + XComponent xDrawComponent = xComponentLoader.loadComponentFromURL( + "private:factory/sdraw", "_blank", 0, loadProps); + + // get draw page by index + com.sun.star.drawing.XDrawPagesSupplier xDrawPagesSupplier = + 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 = UnoRuntime.queryInterface(com.sun.star.drawing.XDrawPage.class, + drawPage); + + com.sun.star.lang.XMultiServiceFactory xDocumentFactory = + UnoRuntime.queryInterface( + com.sun.star.lang.XMultiServiceFactory.class, xDrawComponent); + + com.sun.star.beans.XPropertySet xPageProps = + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, xDrawPage); + + int pageWidth = AnyConverter.toInt(xPageProps.getPropertyValue("Width")); + int pageHeight = AnyConverter.toInt(xPageProps.getPropertyValue("Height")); + int pageBorderTop = AnyConverter.toInt(xPageProps.getPropertyValue("BorderTop")); + int pageBorderLeft = AnyConverter.toInt(xPageProps.getPropertyValue("BorderLeft")); + int pageBorderRight = AnyConverter.toInt(xPageProps.getPropertyValue("BorderRight")); + int drawWidth = pageWidth - pageBorderLeft - pageBorderRight; + int horCenter = pageBorderLeft + drawWidth / 2; + + String[][] orgUnits = new String[2][4]; + orgUnits[0][0] = "Management"; + orgUnits[1][0] = "Production"; + orgUnits[1][1] = "Purchasing"; + orgUnits[1][2] = "IT Services"; + orgUnits[1][3] = "Sales"; + int[] levelCount = {1, 4}; + + int horSpace = 300; + int verSpace = 3000; + + int shapeWidth = (drawWidth - (levelCount[1] - 1) * horSpace) / levelCount[1]; + int shapeHeight = pageHeight / 20; + int shapeX = pageWidth / 2 - shapeWidth / 2; + int shapeY = pageBorderTop; + + int levelY; + int levelX; + + com.sun.star.drawing.XShape xStartShape = null; + + for (int level = 0; level <= 1; level++) { + levelY = pageBorderTop + 2000 + level * (shapeHeight + verSpace); + for (int i = levelCount[level] - 1; i > -1; i--) { + shapeX = horCenter - (levelCount[level] * shapeWidth + + (levelCount[level] - 1) * horSpace) / 2 + + i * shapeWidth + i * horSpace; + Object shape = xDocumentFactory.createInstance("com.sun.star.drawing.RectangleShape"); + 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 = UnoRuntime.queryInterface( + com.sun.star.text.XText.class, xShape); + + xText.setString(orgUnits[level][i]); + + // memorize the root shape + if (level == 0 && i == 0) + xStartShape = xShape; + + if (level == 1) { + Object connector = xDocumentFactory.createInstance("com.sun.star.drawing.ConnectorShape"); + com.sun.star.beans.XPropertySet xConnectorProps = + UnoRuntime.queryInterface( + com.sun.star.beans.XPropertySet.class, connector); + com.sun.star.drawing.XShape xConnector = + UnoRuntime.queryInterface( + com.sun.star.drawing.XShape.class, connector); + xDrawPage.add(xConnector); + xConnectorProps.setPropertyValue("StartShape", xStartShape); + xConnectorProps.setPropertyValue("EndShape", xShape); + xConnectorProps.setPropertyValue("StartGluePointIndex", + Integer.valueOf(2)); // 2 = bottom glue point + xConnectorProps.setPropertyValue("EndGluePointIndex", + Integer.valueOf(0)); // 0 = top glue point + } + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/PageHelper.java b/odk/examples/DevelopersGuide/Drawing/PageHelper.java new file mode 100644 index 000000000..9e8cfa295 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/PageHelper.java @@ -0,0 +1,199 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XServiceInfo; + +import com.sun.star.awt.Size; + +import com.sun.star.beans.XPropertySet; + +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; +import com.sun.star.drawing.XMasterPageTarget; +import com.sun.star.drawing.XMasterPagesSupplier; + +import com.sun.star.presentation.XPresentationPage; +import com.sun.star.presentation.XHandoutMasterSupplier; + + +public class PageHelper +{ + // __________ static helper methods __________ + + // __________ draw pages __________ + + /** get the page count for standard pages + */ + public static int getDrawPageCount( XComponent xComponent ) + { + XDrawPagesSupplier xDrawPagesSupplier = + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); + return xDrawPages.getCount(); + } + + /** get draw page by index + */ + public static XDrawPage getDrawPageByIndex( XComponent xComponent, int nIndex ) + throws com.sun.star.lang.IndexOutOfBoundsException, + com.sun.star.lang.WrappedTargetException + { + XDrawPagesSupplier xDrawPagesSupplier = + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); + return UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); + } + + /** creates and inserts a draw page into the giving position, + the method returns the new created page + */ + public static XDrawPage insertNewDrawPageByIndex( XComponent xComponent, int nIndex ) + throws Exception + { + XDrawPagesSupplier xDrawPagesSupplier = + UnoRuntime.queryInterface( + XDrawPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); + return xDrawPages.insertNewByIndex( nIndex ); + } + + + + /** get size of the given page + */ + public static Size getPageSize( XDrawPage xDrawPage ) + throws com.sun.star.beans.UnknownPropertyException, + com.sun.star.lang.WrappedTargetException + { + XPropertySet xPageProperties = UnoRuntime.queryInterface( XPropertySet.class, xDrawPage ); + return new Size( + ((Integer)xPageProperties.getPropertyValue( "Width" )).intValue(), + ((Integer)xPageProperties.getPropertyValue( "Height" )).intValue() ); + } + + // __________ master pages __________ + + /** get the page count for master pages + */ + public static int getMasterPageCount( XComponent xComponent ) + { + XMasterPagesSupplier xMasterPagesSupplier = + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); + return xDrawPages.getCount(); + } + + /** get master page by index + */ + public static XDrawPage getMasterPageByIndex( XComponent xComponent, int nIndex ) + throws com.sun.star.lang.IndexOutOfBoundsException, + com.sun.star.lang.WrappedTargetException + { + XMasterPagesSupplier xMasterPagesSupplier = + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); + return UnoRuntime.queryInterface(XDrawPage.class, xDrawPages.getByIndex( nIndex )); + } + + /** creates and inserts a new master page into the giving position, + the method returns the new created page + */ + public static XDrawPage insertNewMasterPageByIndex( XComponent xComponent, int nIndex ) + { + XMasterPagesSupplier xMasterPagesSupplier = + UnoRuntime.queryInterface( + XMasterPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xMasterPagesSupplier.getMasterPages(); + return xDrawPages.insertNewByIndex( nIndex ); + } + + + + + + /** sets given masterpage at the drawpage + */ + public static void setMasterPage( XDrawPage xDrawPage, XDrawPage xMasterPage ) + { + XMasterPageTarget xMasterPageTarget = + UnoRuntime.queryInterface( + XMasterPageTarget.class, xDrawPage ); + xMasterPageTarget.setMasterPage( xMasterPage ); + } + + // __________ presentation pages __________ + + /** test if a Presentation Document is supported. + This is important, because only presentation documents + have notes and handout pages + */ + public static boolean isImpressDocument( XComponent xComponent ) + { + XServiceInfo xInfo = UnoRuntime.queryInterface( + XServiceInfo.class, xComponent ); + return xInfo.supportsService( "com.sun.star.presentation.PresentationDocument" ); + } + + /** in impress documents each normal draw page has a corresponding notes page + */ + public static XDrawPage getNotesPage( XDrawPage xDrawPage ) + { + XPresentationPage aPresentationPage = + UnoRuntime.queryInterface( + XPresentationPage.class, xDrawPage ); + return aPresentationPage.getNotesPage(); + } + + /** in impress each documents has one handout page + */ + public static XDrawPage getHandoutMasterPage( XComponent xComponent ) + { + XHandoutMasterSupplier aHandoutMasterSupplier = + UnoRuntime.queryInterface( + XHandoutMasterSupplier.class, xComponent ); + return aHandoutMasterSupplier.getHandoutMasterPage(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java b/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java new file mode 100644 index 000000000..06b5bc4b1 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/PresentationDemo.java @@ -0,0 +1,232 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XServiceInfo; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.container.XNamed; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; + +import com.sun.star.presentation.XPresentation; +import com.sun.star.presentation.XPresentationSupplier; + + + +// __________ Implementation __________ + +// presentation demo + +// This demo will demonstrate how to create a presentation using the Office API + +// The first parameter describes the connection that is to use. If there is no parameter +// "uno:socket,host=localhost,port=2083;urp;StarOffice.ServiceManager" is used. + + +public class PresentationDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/simpress", "_blank", 0, pPropValues ); + + + XDrawPage xPage; + XShapes xShapes; + XPropertySet xShapePropSet; + + // create pages, so that three are available + while ( PageHelper.getDrawPageCount( xDrawDoc ) < 3 ) + PageHelper.insertNewDrawPageByIndex( xDrawDoc, 0 ); + + + // set the slide transition for the first page + xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + // set slide transition effect + setSlideTransition( xPage, + com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, + com.sun.star.presentation.AnimationSpeed.FAST, + 1, 0 ); // automatic object and slide transition + + // create a rectangle that is placed on the top left of the page + xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc, + xShapes,new Point( 1000, 1000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.RectangleShape" ); + xShapePropSet.setPropertyValue("Effect", + com.sun.star.presentation.AnimationEffect.WAVYLINE_FROM_BOTTOM ); + + /* the following three properties provokes that the shape is dimmed + to red + after the animation has been finished */ + xShapePropSet.setPropertyValue( "DimHide", Boolean.FALSE ); + xShapePropSet.setPropertyValue( "DimPrevious", Boolean.TRUE ); + xShapePropSet.setPropertyValue( "DimColor", Integer.valueOf( 0xff0000 ) ); + + + // set the slide transition for the second page + xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 1 ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + setSlideTransition( xPage, + com.sun.star.presentation.FadeEffect.FADE_FROM_RIGHT, + com.sun.star.presentation.AnimationSpeed.SLOW, + 1, 0 ); // automatic object and slide transition + + // create an ellipse that is placed on the bottom right of second page + xShapePropSet = ShapeHelper.createAndInsertShape( xDrawDoc, + xShapes, new Point( 21000, 15000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.EllipseShape" ); + xShapePropSet.setPropertyValue( + "Effect", com.sun.star.presentation.AnimationEffect.HIDE ); + + + // create two objects for the third page + // clicking the first object lets the presentation jump + // to page one by using ClickAction.FIRSTPAGE, + // the second object lets the presentation jump to page two + // by using a ClickAction.BOOKMARK; + xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 2 ); + xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + setSlideTransition( xPage, + com.sun.star.presentation.FadeEffect.ROLL_FROM_LEFT, + com.sun.star.presentation.AnimationSpeed.MEDIUM, + 2, 0 ); + XShape xShape = ShapeHelper.createShape( xDrawDoc, + new Point( 1000, 8000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.EllipseShape" ); + xShapes.add( xShape ); + ShapeHelper.addPortion( xShape, "click to go", false ); + ShapeHelper.addPortion( xShape, "to first page", true ); + 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.FIRSTPAGE ); + + + xShape = ShapeHelper.createShape( xDrawDoc, + new Point( 22000, 8000 ), new Size( 5000, 5000 ), + "com.sun.star.drawing.RectangleShape" ); + xShapes.add( xShape ); + ShapeHelper.addPortion( xShape, "click to go", false ); + ShapeHelper.addPortion( xShape, "to the second page", true ); + 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 = UnoRuntime.queryInterface( + XNamed.class, PageHelper.getDrawPageByIndex( xDrawDoc, 1 ) ); + xPageName.setName( "page two" ); + xShapePropSet.setPropertyValue( + "Bookmark", xPageName.getName() ); + + + /* start an endless presentation which is displayed in + full-screen mode and placed on top */ + + XPresentationSupplier xPresSupplier = UnoRuntime.queryInterface( XPresentationSupplier.class, xDrawDoc ); + XPresentation xPresentation = xPresSupplier.getPresentation(); + XPropertySet xPresPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPresentation ); + xPresPropSet.setPropertyValue( "IsEndless", Boolean.TRUE ); + xPresPropSet.setPropertyValue( "IsAlwaysOnTop", Boolean.TRUE ); + xPresPropSet.setPropertyValue( "Pause", Integer.valueOf( 0 ) ); + xPresentation.start(); + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } + + // this simple method applies the slide transition to a page + public static void setSlideTransition( XDrawPage xPage, + com.sun.star.presentation.FadeEffect eEffect, + com.sun.star.presentation.AnimationSpeed eSpeed, + int nChange, + int nDuration ) + { + // 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 = UnoRuntime.queryInterface( + XServiceInfo.class, xPage ); + if ( xInfo.supportsService( "com.sun.star.presentation.DrawPage" ) ) + { + try + { + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xPage ); + xPropSet.setPropertyValue( "Effect", eEffect ); + xPropSet.setPropertyValue( "Speed", eSpeed ); + xPropSet.setPropertyValue( "Change", Integer.valueOf( nChange ) ); + xPropSet.setPropertyValue( "Duration", Integer.valueOf( nDuration ) ); + } + catch( Exception ex ) + { + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java b/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java new file mode 100644 index 000000000..44b9b28a7 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/ShapeHelper.java @@ -0,0 +1,142 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; +import com.sun.star.lang.XMultiServiceFactory; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.XPropertySet; + +import com.sun.star.container.XEnumeration; +import com.sun.star.container.XEnumerationAccess; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; + +import com.sun.star.text.ControlCharacter; +import com.sun.star.text.XText; +import com.sun.star.text.XTextCursor; +import com.sun.star.text.XTextContent; +import com.sun.star.text.XTextRange; + + +public class ShapeHelper +{ + // __________ static helper methods __________ + + public static XPropertySet createAndInsertShape( XComponent xDrawDoc, + XShapes xShapes, Point aPos, Size aSize, String sShapeType ) + throws java.lang.Exception + { + XShape xShape = createShape( xDrawDoc, aPos, aSize, sShapeType ); + xShapes.add( xShape ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xShape ); + return xPropSet; + } + + /** create a Shape + */ + public static XShape createShape( XComponent xDrawDoc, + Point aPos, Size aSize, String sShapeType ) + throws java.lang.Exception + { + XShape xShape = null; + XMultiServiceFactory xFactory = + UnoRuntime.queryInterface( + XMultiServiceFactory.class, xDrawDoc ); + Object xObj = xFactory.createInstance( sShapeType ); + xShape = UnoRuntime.queryInterface( + XShape.class, xObj ); + xShape.setPosition( aPos ); + xShape.setSize( aSize ); + return xShape; + } + + /** + add text to a shape. the return value is the PropertySet + of the text range that has been added + */ + public static XPropertySet addPortion( XShape xShape, String sText, boolean bNewParagraph ) + throws com.sun.star.lang.IllegalArgumentException + { + XText xText = UnoRuntime.queryInterface( XText.class, xShape ); + + XTextCursor xTextCursor = xText.createTextCursor(); + xTextCursor.gotoEnd( false ); + if ( bNewParagraph == true ) + { + xText.insertControlCharacter( xTextCursor, ControlCharacter.PARAGRAPH_BREAK, false ); + xTextCursor.gotoEnd( false ); + } + XTextRange xTextRange = UnoRuntime.queryInterface( XTextRange.class, xTextCursor ); + xTextRange.setString( sText ); + xTextCursor.gotoEnd( true ); + XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextRange ); + return xPropSet; + } + + public static void setPropertyForLastParagraph( XShape xText, String sPropName, + Object aValue ) + throws com.sun.star.beans.UnknownPropertyException, + com.sun.star.beans.PropertyVetoException, + com.sun.star.lang.IllegalArgumentException, + com.sun.star.lang.WrappedTargetException, + com.sun.star.container.NoSuchElementException + { + XEnumerationAccess xEnumerationAccess = UnoRuntime.queryInterface( XEnumerationAccess.class, xText ); + if ( xEnumerationAccess.hasElements() ) + { + XEnumeration xEnumeration = xEnumerationAccess.createEnumeration(); + while( xEnumeration.hasMoreElements () ) + { + Object xObj = xEnumeration.nextElement(); + if ( xEnumeration.hasMoreElements() == false ) + { + XTextContent xTextContent = UnoRuntime.queryInterface( + XTextContent.class, xObj ); + XPropertySet xParaPropSet = UnoRuntime.queryInterface( XPropertySet.class, xTextContent ); + xParaPropSet.setPropertyValue( sPropName, aValue ); + } + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/SimplePresentation.odp b/odk/examples/DevelopersGuide/Drawing/SimplePresentation.odp Binary files differnew file mode 100644 index 000000000..3f40f7660 --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/SimplePresentation.odp diff --git a/odk/examples/DevelopersGuide/Drawing/StyleDemo.java b/odk/examples/DevelopersGuide/Drawing/StyleDemo.java new file mode 100644 index 000000000..3f9b083be --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/StyleDemo.java @@ -0,0 +1,164 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; +import com.sun.star.beans.XPropertySetInfo; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.XDrawPages; +import com.sun.star.drawing.XDrawPagesSupplier; + +import com.sun.star.frame.XModel; + + + +// __________ Implementation __________ + +// StyleDemo + +public class StyleDemo +{ + public static void main( String args[] ) + { + XComponent xComponent = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xComponent = Helper.createDocument( xOfficeContext, + "private:factory/simpress", "_blank", 0, pPropValues ); + + + + + /* The first part of this demo will set each "CharColor" Property + 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 = + UnoRuntime.queryInterface( + XModel.class, xComponent ); + com.sun.star.style.XStyleFamiliesSupplier xSFS = + UnoRuntime.queryInterface( + com.sun.star.style.XStyleFamiliesSupplier.class, xModel ); + + com.sun.star.container.XNameAccess xFamilies = xSFS.getStyleFamilies(); + + // the element should now contain at least two Styles. The first is + // "graphics" and the other one is the name of the Master page + String[] Families = xFamilies.getElementNames(); + for ( int i = 0; i < Families.length; i++ ) + { + // this is the family + System.out.println( "\n" + Families[ i ] ); + + // and now all available styles + Object aFamilyObj = xFamilies.getByName( Families[ i ] ); + com.sun.star.container.XNameAccess xStyles = + UnoRuntime.queryInterface( + 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 = 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 = UnoRuntime.queryInterface( XPropertySet.class, xStyle ); + XPropertySetInfo xStylePropSetInfo = + xStylePropSet.getPropertySetInfo(); + if ( xStylePropSetInfo.hasPropertyByName( "CharColor" ) ) + { + xStylePropSet.setPropertyValue( "CharColor", + Integer.valueOf( 0xff0000 ) ); + } + } + } + + + + /* now create a rectangle and apply the "title1" style of + the "graphics" family */ + + Object obj = xFamilies.getByName( "graphics" ); + 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 = UnoRuntime.queryInterface( com.sun.star.style.XStyle.class, obj ); + + XDrawPagesSupplier xDrawPagesSupplier = UnoRuntime.queryInterface( XDrawPagesSupplier.class, xComponent ); + XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages(); + XDrawPage xDrawPage = UnoRuntime.queryInterface( + XDrawPage.class, xDrawPages.getByIndex( 0 )); + 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 = UnoRuntime.queryInterface( XPropertySet.class, xShape ); + xPropSet.setPropertyValue( "Style", xTitle1Style ); + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/DevelopersGuide/Drawing/TextDemo.java b/odk/examples/DevelopersGuide/Drawing/TextDemo.java new file mode 100644 index 000000000..c03075c7d --- /dev/null +++ b/odk/examples/DevelopersGuide/Drawing/TextDemo.java @@ -0,0 +1,153 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * The Contents of this file are made available subject to the terms of + * the BSD license. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Sun Microsystems, Inc. nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *************************************************************************/ + +// __________ Imports __________ + +import com.sun.star.uno.UnoRuntime; +import com.sun.star.lang.XComponent; + +import com.sun.star.awt.Point; +import com.sun.star.awt.Size; + +import com.sun.star.beans.PropertyValue; +import com.sun.star.beans.XPropertySet; + +import com.sun.star.drawing.XShape; +import com.sun.star.drawing.XShapes; +import com.sun.star.drawing.XDrawPage; +import com.sun.star.drawing.TextFitToSizeType; + +import com.sun.star.style.LineSpacing; +import com.sun.star.style.LineSpacingMode; +import com.sun.star.style.ParagraphAdjust; + + + +// __________ Implementation __________ + +// text demo + +public class TextDemo +{ + public static void main( String args[] ) + { + XComponent xDrawDoc = null; + try + { + // get the remote office context of a running office (a new office + // instance is started if necessary) + com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect(); + + // suppress Presentation Autopilot when opening the document + // properties are the same as described for + // com.sun.star.document.MediaDescriptor + PropertyValue[] pPropValues = new PropertyValue[ 1 ]; + pPropValues[ 0 ] = new PropertyValue(); + pPropValues[ 0 ].Name = "Silent"; + pPropValues[ 0 ].Value = Boolean.TRUE; + + xDrawDoc = Helper.createDocument( xOfficeContext, + "private:factory/sdraw", "_blank", 0, pPropValues ); + + XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 ); + XShapes xShapes = UnoRuntime.queryInterface( XShapes.class, xPage ); + + + XShape xRectangle; + XPropertySet xTextPropSet, xShapePropSet; + LineSpacing aLineSpacing = new LineSpacing(); + aLineSpacing.Mode = LineSpacingMode.PROP; + + + + // first shape + xRectangle = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 0 ), + new Size( 15000, 7500 ), + "com.sun.star.drawing.RectangleShape" ); + xShapes.add( xRectangle ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + + + // first paragraph + xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion1", false ); + xTextPropSet.setPropertyValue( "CharColor", Integer.valueOf( 0xff0000 ) ); + xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion2", false ); + xTextPropSet.setPropertyValue( "CharColor", Integer.valueOf( 0x8080ff ) ); + aLineSpacing.Height = 100; + ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing", + aLineSpacing ); + + // second paragraph + xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion3", true ); + xTextPropSet.setPropertyValue( "CharColor", Integer.valueOf( 0xff ) ); + aLineSpacing.Height = 200; + ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing", + aLineSpacing ); + + + + // second shape + xRectangle = ShapeHelper.createShape( xDrawDoc, + new Point( 0, 10000 ), + new Size( 21000, 12500 ), + "com.sun.star.drawing.RectangleShape" ); + xShapes.add( xRectangle ); + xShapePropSet = UnoRuntime.queryInterface( XPropertySet.class, xRectangle ); + xShapePropSet.setPropertyValue( "TextFitToSize", + TextFitToSizeType.PROPORTIONAL ); + xShapePropSet.setPropertyValue( "TextLeftDistance", Integer.valueOf(2500)); + xShapePropSet.setPropertyValue( "TextRightDistance", Integer.valueOf(2500)); + xShapePropSet.setPropertyValue( "TextUpperDistance", Integer.valueOf(2500)); + xShapePropSet.setPropertyValue( "TextLowerDistance", Integer.valueOf(2500)); + xTextPropSet = ShapeHelper.addPortion( xRectangle, + "using TextFitToSize", false ); + xTextPropSet.setPropertyValue( "ParaAdjust", ParagraphAdjust.CENTER ); + xTextPropSet.setPropertyValue( "CharColor", Integer.valueOf(0xff00)); + xTextPropSet = ShapeHelper.addPortion(xRectangle, + "and a Border distance of 2,5 cm", + true ); + xTextPropSet.setPropertyValue( "CharColor", Integer.valueOf( 0xff0000 ) ); + + } + catch( Exception ex ) + { + System.out.println( ex ); + } + System.exit( 0 ); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |