1*a1b4a26bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*a1b4a26bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*a1b4a26bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*a1b4a26bSAndrew Rist * distributed with this work for additional information 6*a1b4a26bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*a1b4a26bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*a1b4a26bSAndrew Rist * "License"); you may not use this file except in compliance 9*a1b4a26bSAndrew Rist * with the License. You may obtain a copy of the License at 10*a1b4a26bSAndrew Rist * 11*a1b4a26bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*a1b4a26bSAndrew Rist * 13*a1b4a26bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*a1b4a26bSAndrew Rist * software distributed under the License is distributed on an 15*a1b4a26bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*a1b4a26bSAndrew Rist * KIND, either express or implied. See the License for the 17*a1b4a26bSAndrew Rist * specific language governing permissions and limitations 18*a1b4a26bSAndrew Rist * under the License. 19*a1b4a26bSAndrew Rist * 20*a1b4a26bSAndrew Rist *************************************************************/ 21*a1b4a26bSAndrew Rist 22*a1b4a26bSAndrew Rist 23cdf0e10cSrcweir package com.sun.star.wizards.document; 24cdf0e10cSrcweir 25cdf0e10cSrcweir import com.sun.star.awt.Point; 26cdf0e10cSrcweir import com.sun.star.awt.Size; 27cdf0e10cSrcweir import com.sun.star.beans.PropertyVetoException; 28cdf0e10cSrcweir import com.sun.star.drawing.XControlShape; 29cdf0e10cSrcweir import com.sun.star.drawing.XShape; 30cdf0e10cSrcweir import com.sun.star.drawing.XShapes; 31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 32cdf0e10cSrcweir import com.sun.star.lang.XServiceInfo; 33cdf0e10cSrcweir import com.sun.star.text.TextContentAnchorType; 34cdf0e10cSrcweir import com.sun.star.uno.Exception; 35cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 36cdf0e10cSrcweir import com.sun.star.wizards.common.Helper; 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** 39cdf0e10cSrcweir * @author Administrator 40cdf0e10cSrcweir * 41cdf0e10cSrcweir * To change the template for this generated type comment go to 42cdf0e10cSrcweir * Window>Preferences>Java>Code Generation>Code and Comments 43cdf0e10cSrcweir */ 44cdf0e10cSrcweir public class Shape 45cdf0e10cSrcweir { 46cdf0e10cSrcweir 47cdf0e10cSrcweir public XShape xShape; 48cdf0e10cSrcweir protected FormHandler oFormHandler; 49cdf0e10cSrcweir public XServiceInfo xServiceInfo; 50cdf0e10cSrcweir protected Point aPoint; 51cdf0e10cSrcweir protected Size aSize; 52cdf0e10cSrcweir protected XControlShape xControlShape; 53cdf0e10cSrcweir public XMultiServiceFactory xMSF; 54cdf0e10cSrcweir public XShapes xShapes; 55cdf0e10cSrcweir Shape(FormHandler _oFormHandler, Point _aPoint, Size _aSize)56cdf0e10cSrcweir public Shape(FormHandler _oFormHandler, Point _aPoint, Size _aSize) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir this.aPoint = _aPoint; 59cdf0e10cSrcweir this.aSize = _aSize; 60cdf0e10cSrcweir this.oFormHandler = _oFormHandler; 61cdf0e10cSrcweir createShape("com.sun.star.drawing.ControlShape"); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir Shape(FormHandler _oFormHandler, String _sServiceName, Point _aPoint, Size _aSize)64cdf0e10cSrcweir public Shape(FormHandler _oFormHandler, String _sServiceName, Point _aPoint, Size _aSize) 65cdf0e10cSrcweir { 66cdf0e10cSrcweir try 67cdf0e10cSrcweir { 68cdf0e10cSrcweir this.aPoint = _aPoint; 69cdf0e10cSrcweir this.aSize = _aSize; 70cdf0e10cSrcweir this.oFormHandler = _oFormHandler; 71cdf0e10cSrcweir Object oShape = oFormHandler.xMSF.createInstance(_sServiceName); 72cdf0e10cSrcweir xShapes = UnoRuntime.queryInterface(XShapes.class, oShape); 73cdf0e10cSrcweir xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, oShape); 74cdf0e10cSrcweir } 75cdf0e10cSrcweir catch (Exception e) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir e.printStackTrace(); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir Shape()81cdf0e10cSrcweir public Shape() 82cdf0e10cSrcweir { 83cdf0e10cSrcweir } 84cdf0e10cSrcweir createShape(String sServiceName)85cdf0e10cSrcweir private void createShape(String sServiceName) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir try 88cdf0e10cSrcweir { 89cdf0e10cSrcweir xMSF = oFormHandler.xMSFDoc; 90cdf0e10cSrcweir Object oShape = xMSF.createInstance(sServiceName); 91cdf0e10cSrcweir xShape = UnoRuntime.queryInterface(XShape.class, oShape); 92cdf0e10cSrcweir xShape.setPosition(aPoint); 93cdf0e10cSrcweir if (aSize != null) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir xShape.setSize(aSize); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir else 98cdf0e10cSrcweir { 99cdf0e10cSrcweir xShape.setSize(new Size(1000, 100)); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir Helper.setUnoPropertyValue(xShape, "AnchorType", TextContentAnchorType.AT_PARAGRAPH); 102cdf0e10cSrcweir xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, xShape); 103cdf0e10cSrcweir xControlShape = UnoRuntime.queryInterface(XControlShape.class, xShape); 104cdf0e10cSrcweir 105cdf0e10cSrcweir } 106cdf0e10cSrcweir catch (Exception e) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir e.printStackTrace(System.out); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir } 111cdf0e10cSrcweir getSize()112cdf0e10cSrcweir public Size getSize() 113cdf0e10cSrcweir { 114cdf0e10cSrcweir return xShape.getSize(); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir setSize(Size _aSize)117cdf0e10cSrcweir public void setSize(Size _aSize) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir try 120cdf0e10cSrcweir { 121cdf0e10cSrcweir xShape.setSize(_aSize); 122cdf0e10cSrcweir } 123cdf0e10cSrcweir catch (PropertyVetoException e) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir e.printStackTrace(System.out); 126cdf0e10cSrcweir } 127cdf0e10cSrcweir } 128cdf0e10cSrcweir getPosition()129cdf0e10cSrcweir public Point getPosition() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir return xShape.getPosition(); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir setPosition(Point _aPoint)134cdf0e10cSrcweir public void setPosition(Point _aPoint) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir xShape.setPosition(_aPoint); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139