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