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