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 package util; 25 26 import com.sun.star.lang.XMultiServiceFactory; 27 import com.sun.star.uno.XInterface; 28 import com.sun.star.uno.UnoRuntime; 29 import com.sun.star.text.XTextFrame; 30 import com.sun.star.drawing.XShape; 31 import com.sun.star.awt.Size; 32 import com.sun.star.beans.XPropertySet; 33 /** 34 * the class FrameDsc 35 */ 36 public class FrameDsc extends InstDescr { 37 38 private Size size = null; 39 private int height = 2000; 40 private int width = 2000; 41 private String name = null; 42 private int autoheigth = 0; 43 private int anchorType = 0;// bound at paragraph 44 45 final String ifcName = "com.sun.star.text.XTextFrame"; 46 final String service = "com.sun.star.text.TextFrame"; 47 FrameDsc()48 public FrameDsc() { 49 initFrame(); 50 } 51 FrameDsc( int nHeight, int nWidth )52 public FrameDsc( int nHeight, int nWidth ) { 53 height = nHeight; 54 width = nWidth; 55 initFrame(); 56 } 57 FrameDsc( String FrameName, int nHeight, int nWidth )58 public FrameDsc( String FrameName, int nHeight, int nWidth ) { 59 name = FrameName; 60 height = nHeight; 61 width = nWidth; 62 initFrame(); 63 } getName()64 public String getName() { 65 return name; 66 } getIfcName()67 public String getIfcName() { 68 return ifcName; 69 } getService()70 public String getService() { 71 return service; 72 } 73 initFrame()74 private void initFrame() { 75 try { 76 ifcClass = Class.forName( ifcName ); 77 } 78 catch( ClassNotFoundException cnfE ) { 79 } 80 } createInstance( XMultiServiceFactory docMSF )81 public XInterface createInstance( XMultiServiceFactory docMSF ) { 82 Object SrvObj = null; 83 84 size = new Size(); 85 size.Height = height; 86 size.Width = width; 87 88 try { 89 SrvObj = docMSF.createInstance( service ); 90 } 91 catch( com.sun.star.uno.Exception cssuE ){ 92 } 93 XShape shape = (XShape)UnoRuntime.queryInterface( XShape.class, SrvObj ); 94 try { 95 shape.setSize(size); 96 } 97 catch( com.sun.star.beans.PropertyVetoException pvE ){ 98 } 99 100 XTextFrame TF = (XTextFrame)UnoRuntime.queryInterface( ifcClass, SrvObj ); 101 102 XPropertySet oPropSet = (XPropertySet) 103 UnoRuntime.queryInterface( XPropertySet.class, SrvObj ); 104 105 106 try { 107 oPropSet.setPropertyValue("AnchorType", new Integer(2)); 108 } 109 catch( com.sun.star.beans.UnknownPropertyException upE ){ 110 } 111 catch( com.sun.star.beans.PropertyVetoException pvE ){ 112 } 113 catch( com.sun.star.lang.IllegalArgumentException iaE ){ 114 } 115 catch( com.sun.star.lang.WrappedTargetException wtE ){ 116 } 117 118 119 120 return TF; 121 } 122 } 123