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