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