Update ooo320-m1
[ooovba.git] / odk / examples / DevelopersGuide / Drawing / TextDemo.java
blobc8afb3e1fa519326e7aa47e4e3122c0bd9b79a25
1 /*************************************************************************
3 * $RCSfile: TextDemo.java,v $
5 * $Revision: 1.5 $
7 * last change: $Author: rt $ $Date: 2005-01-31 16:25:38 $
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.awt.Point;
47 import com.sun.star.awt.Size;
49 import com.sun.star.beans.PropertyValue;
50 import com.sun.star.beans.XPropertySet;
52 import com.sun.star.drawing.XShape;
53 import com.sun.star.drawing.XShapes;
54 import com.sun.star.drawing.XDrawPage;
55 import com.sun.star.drawing.TextFitToSizeType;
57 import com.sun.star.style.LineSpacing;
58 import com.sun.star.style.LineSpacingMode;
59 import com.sun.star.style.ParagraphAdjust;
63 // __________ Implementation __________
65 /** text demo
66 @author Sven Jacobi
69 public class TextDemo
71 public static void main( String args[] )
73 XComponent xDrawDoc = null;
74 try
76 // get the remote office context of a running office (a new office
77 // instance is started if necessary)
78 com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
80 // suppress Presentation Autopilot when opening the document
81 // properties are the same as described for
82 // com.sun.star.document.MediaDescriptor
83 PropertyValue[] pPropValues = new PropertyValue[ 1 ];
84 pPropValues[ 0 ] = new PropertyValue();
85 pPropValues[ 0 ].Name = "Silent";
86 pPropValues[ 0 ].Value = new Boolean( true );
88 xDrawDoc = Helper.createDocument( xOfficeContext,
89 "private:factory/sdraw", "_blank", 0, pPropValues );
91 XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
92 XShapes xShapes = (XShapes)
93 UnoRuntime.queryInterface( XShapes.class, xPage );
96 XShape xRectangle;
97 XPropertySet xTextPropSet, xShapePropSet;
98 LineSpacing aLineSpacing = new LineSpacing();
99 aLineSpacing.Mode = LineSpacingMode.PROP;
103 // first shape
104 xRectangle = ShapeHelper.createShape( xDrawDoc,
105 new Point( 0, 0 ),
106 new Size( 15000, 7500 ),
107 "com.sun.star.drawing.RectangleShape" );
108 xShapes.add( xRectangle );
109 xShapePropSet = (XPropertySet)
110 UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
113 // first paragraph
114 xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion1", false );
115 xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff0000 ) );
116 xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion2", false );
117 xTextPropSet.setPropertyValue( "CharColor", new Integer( 0x8080ff ) );
118 aLineSpacing.Height = 100;
119 ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing",
120 aLineSpacing );
122 // second paragraph
123 xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion3", true );
124 xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff ) );
125 aLineSpacing.Height = 200;
126 ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing",
127 aLineSpacing );
131 // second shape
132 xRectangle = ShapeHelper.createShape( xDrawDoc,
133 new Point( 0, 10000 ),
134 new Size( 21000, 12500 ),
135 "com.sun.star.drawing.RectangleShape" );
136 xShapes.add( xRectangle );
137 xShapePropSet = (XPropertySet)
138 UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
139 xShapePropSet.setPropertyValue( "TextFitToSize",
140 TextFitToSizeType.PROPORTIONAL );
141 xShapePropSet.setPropertyValue( "TextLeftDistance", new Integer(2500));
142 xShapePropSet.setPropertyValue( "TextRightDistance", new Integer(2500));
143 xShapePropSet.setPropertyValue( "TextUpperDistance", new Integer(2500));
144 xShapePropSet.setPropertyValue( "TextLowerDistance", new Integer(2500));
145 xTextPropSet = ShapeHelper.addPortion( xRectangle,
146 "using TextFitToSize", false );
147 xTextPropSet.setPropertyValue( "ParaAdjust", ParagraphAdjust.CENTER );
148 xTextPropSet.setPropertyValue( "CharColor", new Integer(0xff00));
149 xTextPropSet = ShapeHelper.addPortion(xRectangle,
150 "and a Border distance of 2,5 cm",
151 true );
152 xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff0000 ) );
155 catch( Exception ex )
157 System.out.println( ex );
159 System.exit( 0 );