Branch libreoffice-5-0-4
[LibreOffice.git] / odk / examples / DevelopersGuide / Drawing / DrawViewDemo.java
blob2377a711f9bb3788aaa0db28ceda8ea0b803aaa2
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * the BSD license.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *************************************************************************/
35 // __________ Imports __________
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.lang.XComponent;
40 import com.sun.star.beans.Property;
41 import com.sun.star.beans.PropertyValue;
42 import com.sun.star.beans.XPropertySet;
43 import com.sun.star.beans.XPropertySetInfo;
45 import com.sun.star.container.XIndexAccess;
47 import com.sun.star.document.XViewDataSupplier;
49 import com.sun.star.frame.XModel;
50 import com.sun.star.frame.XController;
54 // __________ Implementation __________
56 // text demo
58 public class DrawViewDemo
60 public static void main( String args[] )
62 if ( args.length < 1 )
64 System.out.println( "usage: DrawViewDemo SourceURL" );
65 System.exit(1);
68 XComponent xComponent = null;
69 try
71 // get the remote office context of a running office (a new office
72 // instance is started if necessary)
73 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
75 // suppress Presentation Autopilot when opening the document
76 // properties are the same as described for
77 // com.sun.star.document.MediaDescriptor
78 PropertyValue[] pPropValues = new PropertyValue[ 1 ];
79 pPropValues[ 0 ] = new PropertyValue();
80 pPropValues[ 0 ].Name = "Silent";
81 pPropValues[ 0 ].Value = Boolean.TRUE;
83 java.io.File sourceFile = new java.io.File(args[0]);
84 StringBuffer sUrl = new StringBuffer("file:///");
85 sUrl.append(sourceFile.getCanonicalPath().replace('\\', '/'));
87 xComponent = Helper.createDocument( xOfficeContext,
88 sUrl.toString(), "_blank", 0,
89 pPropValues );
90 XModel xModel =
91 UnoRuntime.queryInterface(
92 XModel.class, xComponent );
95 // print all available properties of first view
96 System.out.println("*** print all available properties of first view");
97 XViewDataSupplier xViewDataSupplier =
98 UnoRuntime.queryInterface(
99 XViewDataSupplier.class, xModel );
100 XIndexAccess xIndexAccess = xViewDataSupplier.getViewData();
101 if ( xIndexAccess.getCount() != 0 )
103 PropertyValue[] aPropSeq = (PropertyValue[])
104 xIndexAccess.getByIndex( 0 );
106 for( int i = 0; i < aPropSeq.length; i++ )
108 System.out.println( aPropSeq[ i ].Name + " = " +
109 aPropSeq[ i ].Value );
114 // print all properties that are supported by the controller
115 // and change into masterpage mode
116 System.out.println("*** print all properties that are supported by the controller");
117 XController xController = xModel.getCurrentController();
118 XPropertySet xPropSet =
119 UnoRuntime.queryInterface(
120 XPropertySet.class, xController );
121 XPropertySetInfo xPropSetInfo = xPropSet.getPropertySetInfo();
122 Property[] aPropSeq = xPropSetInfo.getProperties();
123 for( int i = 0; i < aPropSeq.length; i++ )
125 System.out.println( aPropSeq[ i ].Name );
127 System.out.println("*** change into masterpage mode");
128 xPropSet.setPropertyValue( "IsMasterPageMode", Boolean.TRUE );
131 catch( Exception ex )
133 System.out.println( ex.getMessage() );
134 ex.printStackTrace(System.err);
137 System.exit( 0 );