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 package com.sun.star.wizards.document;
24 
25 import com.sun.star.awt.Point;
26 import com.sun.star.awt.Size;
27 import com.sun.star.beans.PropertyVetoException;
28 import com.sun.star.drawing.XControlShape;
29 import com.sun.star.drawing.XShape;
30 import com.sun.star.drawing.XShapes;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.lang.XServiceInfo;
33 import com.sun.star.text.TextContentAnchorType;
34 import com.sun.star.uno.Exception;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.wizards.common.Helper;
37 
38 /**
39  * @author Administrator
40  *
41  * To change the template for this generated type comment go to
42  * Window>Preferences>Java>Code Generation>Code and Comments
43  */
44 public class Shape
45 {
46 
47     public XShape xShape;
48     protected FormHandler oFormHandler;
49     public XServiceInfo xServiceInfo;
50     protected Point aPoint;
51     protected Size aSize;
52     protected XControlShape xControlShape;
53     public XMultiServiceFactory xMSF;
54     public XShapes xShapes;
55 
Shape(FormHandler _oFormHandler, Point _aPoint, Size _aSize)56     public Shape(FormHandler _oFormHandler, Point _aPoint, Size _aSize)
57     {
58         this.aPoint = _aPoint;
59         this.aSize = _aSize;
60         this.oFormHandler = _oFormHandler;
61         createShape("com.sun.star.drawing.ControlShape");
62     }
63 
Shape(FormHandler _oFormHandler, String _sServiceName, Point _aPoint, Size _aSize)64     public Shape(FormHandler _oFormHandler, String _sServiceName, Point _aPoint, Size _aSize)
65     {
66         try
67         {
68             this.aPoint = _aPoint;
69             this.aSize = _aSize;
70             this.oFormHandler = _oFormHandler;
71             Object oShape = oFormHandler.xMSF.createInstance(_sServiceName);
72             xShapes = UnoRuntime.queryInterface(XShapes.class, oShape);
73             xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, oShape);
74         }
75         catch (Exception e)
76         {
77             e.printStackTrace();
78         }
79     }
80 
Shape()81     public Shape()
82     {
83     }
84 
createShape(String sServiceName)85     private void createShape(String sServiceName)
86     {
87         try
88         {
89             xMSF = oFormHandler.xMSFDoc;
90             Object oShape = xMSF.createInstance(sServiceName);
91             xShape = UnoRuntime.queryInterface(XShape.class, oShape);
92             xShape.setPosition(aPoint);
93             if (aSize != null)
94             {
95                 xShape.setSize(aSize);
96             }
97             else
98             {
99                 xShape.setSize(new Size(1000, 100));
100             }
101             Helper.setUnoPropertyValue(xShape, "AnchorType", TextContentAnchorType.AT_PARAGRAPH);
102             xServiceInfo = UnoRuntime.queryInterface(XServiceInfo.class, xShape);
103             xControlShape = UnoRuntime.queryInterface(XControlShape.class, xShape);
104 
105         }
106         catch (Exception e)
107         {
108             e.printStackTrace(System.out);
109         }
110     }
111 
getSize()112     public Size getSize()
113     {
114         return xShape.getSize();
115     }
116 
setSize(Size _aSize)117     public void setSize(Size _aSize)
118     {
119         try
120         {
121             xShape.setSize(_aSize);
122         }
123         catch (PropertyVetoException e)
124         {
125             e.printStackTrace(System.out);
126         }
127     }
128 
getPosition()129     public Point getPosition()
130     {
131         return xShape.getPosition();
132     }
133 
setPosition(Point _aPoint)134     public void setPosition(Point _aPoint)
135     {
136         xShape.setPosition(_aPoint);
137     }
138 }
139