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