1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package com.sun.star.wizards.document;
28 
29 import com.sun.star.awt.Point;
30 import com.sun.star.awt.Size;
31 import com.sun.star.beans.PropertyVetoException;
32 import com.sun.star.beans.XPropertySet;
33 import com.sun.star.wizards.common.*;
34 import com.sun.star.wizards.db.FieldColumn;
35 import com.sun.star.wizards.ui.*;
36 import com.sun.star.sdbc.*;
37 import com.sun.star.uno.Exception;
38 import com.sun.star.uno.UnoRuntime;
39 import com.sun.star.container.XNameContainer;
40 import com.sun.star.drawing.XControlShape;
41 import com.sun.star.drawing.XShape;
42 import com.sun.star.drawing.XShapes;
43 
44 public class TimeStampControl extends DatabaseControl
45 {
46 
47     DatabaseControl oDateControl;
48     DatabaseControl oTimeControl;
49 //  XShape xGroupShape;
50     Resource oResource;
51     private String sDateAppendix; // = GetResText(RID_FORM + 4)
52     private String sTimeAppendix; // = GetResText(RID_FORM + 5)
53     XShapes xGroupShapes = null;
54     double nreldatewidth;
55     double nreltimewidth;
56     int nTimeWidth;
57     int nDBWidth;
58     int nDateWidth;
59     XShape xShapeGroup;
60 
61     public TimeStampControl(Resource _oResource, FormHandler _oFormHandler, XNameContainer _xFormName, String _curFieldName, Point _aPoint)
62     {
63         super(_oFormHandler, "com.sun.star.drawing.ShapeCollection", _aPoint);
64         oResource = _oResource;
65 //      xGroupShape = xShape;
66         oDateControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.DATE, aPoint);
67         int nDBHeight = oDateControl.getControlHeight();
68         nDateWidth = oDateControl.getPreferredWidth();
69         oDateControl.setSize(new Size(nDateWidth, nDBHeight));
70         Point aTimePoint = new Point(aPoint.X + 10 + nDateWidth, aPoint.Y);
71         oTimeControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.TIME, aTimePoint);
72         nTimeWidth = oTimeControl.getPreferredWidth();
73         oTimeControl.setSize(new Size(nTimeWidth, nDBHeight));
74         nDBWidth = nDateWidth + nTimeWidth + 10;
75         xShapes.add(oDateControl.xShape);
76         xShapes.add(oTimeControl.xShape);
77         xShapeGroup = _oFormHandler.xShapeGrouper.group(xShapes);
78         xShapeGroup = UnoRuntime.queryInterface(XShape.class, xShapeGroup);
79         nreldatewidth = 1.0 / ((double) getSize().Width / (double) nDateWidth);
80         nreltimewidth = 1.0 - nreldatewidth;
81     }
82 
83     public XPropertySet getControlofGroupShapeByIndex(int _i)
84     {
85         try
86         {
87             if (_i < xShapes.getCount())
88             {
89                 Object oControl = xShapes.getByIndex(_i);
90                 XControlShape xControlShape = UnoRuntime.queryInterface(XControlShape.class, oControl);
91                 return UnoRuntime.queryInterface(XPropertySet.class, xControlShape.getControl());
92             }
93         }
94         catch (Exception e)
95         {
96             e.printStackTrace(System.out);
97         }
98         return null;
99     }
100 
101     public TimeStampControl(Resource _oResource, GridControl _oGridControl, FieldColumn _curfieldcolumn)
102     {
103         super(_oGridControl, _curfieldcolumn);
104         oResource = _oResource;
105         sDateAppendix = oResource.getResText(UIConsts.RID_FORM + 88);
106         sTimeAppendix = oResource.getResText(UIConsts.RID_FORM + 89);
107         oDateControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.DATE, _curfieldcolumn.getFieldTitle() + PropertyNames.SPACE + sDateAppendix);
108         oTimeControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.TIME, _curfieldcolumn.getFieldTitle() + PropertyNames.SPACE + sTimeAppendix);
109     }
110 
111     public void setPropertyValue(String _sPropertyName, Object _aPropertyValue) throws Exception
112     {
113         oDateControl.setPropertyValue(_sPropertyName, _aPropertyValue);
114         oTimeControl.setPropertyValue(_sPropertyName, _aPropertyValue);
115     }
116 
117     public int getPreferredWidth()
118     {
119         return nDBWidth;
120     }
121 
122     public void setSize(Size _aSize)
123     {
124         try
125         {
126             int ndatewidth = (int) (nreldatewidth * (double) _aSize.Width);
127             int ntimewidth = (int) (nreltimewidth * (double) _aSize.Width);
128             oDateControl.xShape.setSize(new Size(ndatewidth, _aSize.Height));
129             oTimeControl.xShape.setSize(new Size(ntimewidth, _aSize.Height));
130         }
131         catch (PropertyVetoException e)
132         {
133             e.printStackTrace(System.out);
134         }
135     }
136 
137     public Size getSize()
138     {
139         int ncontrolwidth = oDateControl.xShape.getSize().Width + oTimeControl.xShape.getSize().Width;
140         return new Size(ncontrolwidth, oDateControl.xShape.getSize().Height);
141     }
142 
143     public Point getPosition()
144     {
145         return xShapeGroup.getPosition();
146     }
147 
148     public void setPosition(Point _aPoint)
149     {
150         // --> TESTING
151         Point aBeforePt = xShapeGroup.getPosition();
152         // <--
153         xShapeGroup.setPosition(_aPoint);
154 //      oDateControl.xShape.setPosition(_aPoint);
155 //      Point atimepoint = new Point(oDateControl.xShape.getPosition().X + oDateControl.xShape.getSize().Width, oDateControl.xShape.getPosition().Y );
156 //      oTimeControl.xShape.setPosition(atimepoint);
157         // --> TESTING
158         Point aAfterPt = xShapeGroup.getPosition();
159     // <--
160     }
161 
162     public int getControlType()
163     {
164         return FormHandler.SODATETIMECONTROL;
165     }
166 }
167 
168 
169 
170 
171 
172