1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 // __________ Imports __________
36 
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.lang.XComponent;
39 
40 import com.sun.star.awt.Point;
41 import com.sun.star.awt.Size;
42 
43 import com.sun.star.beans.PropertyValue;
44 import com.sun.star.beans.XPropertySet;
45 
46 import com.sun.star.drawing.XShape;
47 import com.sun.star.drawing.XShapes;
48 import com.sun.star.drawing.XDrawPage;
49 import com.sun.star.drawing.TextFitToSizeType;
50 
51 import com.sun.star.style.LineSpacing;
52 import com.sun.star.style.LineSpacingMode;
53 import com.sun.star.style.ParagraphAdjust;
54 
55 
56 
57 // __________ Implementation __________
58 
59 /** text demo
60     @author Sven Jacobi
61  */
62 
63 public class TextDemo
64 {
65     public static void main( String args[] )
66     {
67 		XComponent xDrawDoc = null;
68 		try
69 		{
70             // get the remote office context of a running office (a new office
71             // instance is started if necessary)
72 			com.sun.star.uno.XComponentContext xOfficeContext = Helper.connect();
73 
74 			// suppress Presentation Autopilot when opening the document
75 			// properties are the same as described for
76 			// com.sun.star.document.MediaDescriptor
77 			PropertyValue[] pPropValues = new PropertyValue[ 1 ];
78 			pPropValues[ 0 ] = new PropertyValue();
79 			pPropValues[ 0 ].Name = "Silent";
80 			pPropValues[ 0 ].Value = new Boolean( true );
81 
82 			xDrawDoc = Helper.createDocument( xOfficeContext,
83 				"private:factory/sdraw", "_blank", 0, pPropValues );
84 
85 			XDrawPage xPage = PageHelper.getDrawPageByIndex( xDrawDoc, 0 );
86 			XShapes xShapes = (XShapes)
87 					UnoRuntime.queryInterface( XShapes.class, xPage );
88 
89 
90 			XShape		 xRectangle;
91 			XPropertySet xTextPropSet, xShapePropSet;
92 			LineSpacing  aLineSpacing = new LineSpacing();
93 			aLineSpacing.Mode = LineSpacingMode.PROP;
94 
95 
96 
97 			// first shape
98 			xRectangle = ShapeHelper.createShape( xDrawDoc,
99 				new Point( 0, 0 ),
100 					new Size( 15000, 7500 ),
101 						"com.sun.star.drawing.RectangleShape" );
102 			xShapes.add( xRectangle );
103 			xShapePropSet = (XPropertySet)
104 					UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
105 
106 
107 			// first paragraph
108 			xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion1", false );
109 			xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff0000 ) );
110 			xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion2", false );
111 			xTextPropSet.setPropertyValue( "CharColor", new Integer( 0x8080ff ) );
112 			aLineSpacing.Height = 100;
113 			ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing",
114                                                      aLineSpacing );
115 
116 			// second paragraph
117 			xTextPropSet = ShapeHelper.addPortion( xRectangle, "Portion3", true );
118 			xTextPropSet.setPropertyValue( "CharColor", new Integer( 0xff ) );
119 			aLineSpacing.Height = 200;
120 			ShapeHelper.setPropertyForLastParagraph( xRectangle, "ParaLineSpacing",
121                                                      aLineSpacing );
122 
123 
124 
125 			// second shape
126 			xRectangle = ShapeHelper.createShape( xDrawDoc,
127 				new Point( 0, 10000 ),
128 					new Size( 21000, 12500 ),
129 						"com.sun.star.drawing.RectangleShape" );
130 			xShapes.add( xRectangle );
131 			xShapePropSet = (XPropertySet)
132 					UnoRuntime.queryInterface( XPropertySet.class, xRectangle );
133 			xShapePropSet.setPropertyValue( "TextFitToSize",
134                                             TextFitToSizeType.PROPORTIONAL );
135 			xShapePropSet.setPropertyValue( "TextLeftDistance",  new Integer(2500));
136 			xShapePropSet.setPropertyValue( "TextRightDistance", new Integer(2500));
137 			xShapePropSet.setPropertyValue( "TextUpperDistance", new Integer(2500));
138 			xShapePropSet.setPropertyValue( "TextLowerDistance", new Integer(2500));
139 			xTextPropSet = ShapeHelper.addPortion( xRectangle,
140                                                    "using TextFitToSize", false );
141 			xTextPropSet.setPropertyValue( "ParaAdjust", ParagraphAdjust.CENTER );
142 			xTextPropSet.setPropertyValue( "CharColor",  new Integer(0xff00));
143 			xTextPropSet = ShapeHelper.addPortion(xRectangle,
144                                                   "and a Border distance of 2,5 cm",
145                                                   true );
146 			xTextPropSet.setPropertyValue( "CharColor",  new Integer( 0xff0000 ) );
147 
148 		}
149 		catch( Exception ex )
150 		{
151             System.out.println( ex );
152 		}
153 		System.exit( 0 );
154     }
155 }
156