1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // __________ Imports __________
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
27cdf0e10cSrcweir import com.sun.star.lang.XComponent;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.awt.Point;
30cdf0e10cSrcweir import com.sun.star.awt.Size;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
33cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir import com.sun.star.drawing.XShape;
36cdf0e10cSrcweir import com.sun.star.drawing.XShapes;
37cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
38cdf0e10cSrcweir import com.sun.star.drawing.TextFitToSizeType;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir import com.sun.star.style.LineSpacing;
41cdf0e10cSrcweir import com.sun.star.style.LineSpacingMode;
42cdf0e10cSrcweir import com.sun.star.style.ParagraphAdjust;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir // __________ Implementation __________
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /** text demo
49cdf0e10cSrcweir     @author Sven Jacobi
50cdf0e10cSrcweir  */
51cdf0e10cSrcweir 
52cdf0e10cSrcweir public class TextDemo
53cdf0e10cSrcweir {
main( String args[] )54cdf0e10cSrcweir     public static void main( String args[] )
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir 		XComponent xDrawDoc = null;
57cdf0e10cSrcweir 		try
58cdf0e10cSrcweir 		{
59cdf0e10cSrcweir             // get the remote office context of a running office (a new office
60cdf0e10cSrcweir             // instance is started if necessary)
61cdf0e10cSrcweir 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 			// suppress Presentation Autopilot when opening the document
64cdf0e10cSrcweir 			// properties are the same as described for
65cdf0e10cSrcweir 			// com.sun.star.document.MediaDescriptor
66cdf0e10cSrcweir 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
67cdf0e10cSrcweir 			pPropValues[ 0 ] = new PropertyValue();
68cdf0e10cSrcweir 			pPropValues[ 0 ].Name = "Silent";
69cdf0e10cSrcweir 			pPropValues[ 0 ].Value = new Boolean( true );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 			xDrawDoc = Helper.createDocument( xOfficeContext,
72cdf0e10cSrcweir 				"private:factory/sdraw", "_blank", 0, pPropValues );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 			XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
75cdf0e10cSrcweir 			XShapes xShapes = (XShapes)
76cdf0e10cSrcweir 					UnoRuntime.queryInterface( XShapes.class, xPage );
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 			XShape		 xRectangle;
80cdf0e10cSrcweir 			XPropertySet xTextPropSet, xShapePropSet;
81cdf0e10cSrcweir 			LineSpacing  aLineSpacing = new LineSpacing();
82cdf0e10cSrcweir 			aLineSpacing.Mode = LineSpacingMode.PROP;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 			// first shape
87cdf0e10cSrcweir 			xRectangle = ShapeHelper.createShape( xDrawDoc,
88cdf0e10cSrcweir 				new Point( 0, 0 ),
89cdf0e10cSrcweir 					new Size( 15000, 7500 ),
90cdf0e10cSrcweir 						"com.sun.star.drawing.RectangleShape" );
91cdf0e10cSrcweir 			xShapes.add( xRectangle );
92cdf0e10cSrcweir 			xShapePropSet = (XPropertySet)
93cdf0e10cSrcweir 					UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 			// first paragraph
97cdf0e10cSrcweir 			xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion1", false );
98cdf0e10cSrcweir 			xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff0000 ) );
99cdf0e10cSrcweir 			xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion2", false );
100cdf0e10cSrcweir 			xTextPropSet.setPropertyValue( "CharColor", new Integer( 0x8080ff ) );
101cdf0e10cSrcweir 			aLineSpacing.Height = 100;
102cdf0e10cSrcweir 			ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing",
103cdf0e10cSrcweir                                                      aLineSpacing );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 			// second paragraph
106cdf0e10cSrcweir 			xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion3", true );
107cdf0e10cSrcweir 			xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff ) );
108cdf0e10cSrcweir 			aLineSpacing.Height = 200;
109cdf0e10cSrcweir 			ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing",
110cdf0e10cSrcweir                                                      aLineSpacing );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 			// second shape
115cdf0e10cSrcweir 			xRectangle = ShapeHelper.createShape( xDrawDoc,
116cdf0e10cSrcweir 				new Point( 0, 10000 ),
117cdf0e10cSrcweir 					new Size( 21000, 12500 ),
118cdf0e10cSrcweir 						"com.sun.star.drawing.RectangleShape" );
119cdf0e10cSrcweir 			xShapes.add( xRectangle );
120cdf0e10cSrcweir 			xShapePropSet = (XPropertySet)
121cdf0e10cSrcweir 					UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
122cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "TextFitToSize",
123cdf0e10cSrcweir                                             TextFitToSizeType.PROPORTIONAL );
124cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "TextLeftDistance",  new Integer(2500));
125cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "TextRightDistance", new Integer(2500));
126cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "TextUpperDistance", new Integer(2500));
127cdf0e10cSrcweir 			xShapePropSet.setPropertyValue( "TextLowerDistance", new Integer(2500));
128cdf0e10cSrcweir 			xTextPropSet = ShapeHelper.addPortion( xRectangle,
129cdf0e10cSrcweir                                                    "using TextFitToSize", false );
130cdf0e10cSrcweir 			xTextPropSet.setPropertyValue( "ParaAdjust", ParagraphAdjust.CENTER );
131cdf0e10cSrcweir 			xTextPropSet.setPropertyValue( "CharColor",  new Integer(0xff00));
132cdf0e10cSrcweir 			xTextPropSet = ShapeHelper.addPortion(xRectangle,
133cdf0e10cSrcweir                                                   "and a Border distance of 2,5 cm",
134cdf0e10cSrcweir                                                   true );
135cdf0e10cSrcweir 			xTextPropSet.setPropertyValue( "CharColor",  new Integer( 0xff0000 ) );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 		}
138cdf0e10cSrcweir 		catch( Exception ex )
139cdf0e10cSrcweir 		{
140cdf0e10cSrcweir             System.out.println( ex );
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 		System.exit( 0 );
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir }
145