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.beans.XPropertySet;
29 import com.sun.star.wizards.common.*;
30 import com.sun.star.wizards.db.FieldColumn;
31 import com.sun.star.wizards.ui.*;
32 import com.sun.star.sdbc.*;
33 import com.sun.star.uno.Exception;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.container.XNameContainer;
36 import com.sun.star.drawing.XControlShape;
37 import com.sun.star.drawing.XShape;
38 import com.sun.star.drawing.XShapes;
39 
40 public class TimeStampControl extends DatabaseControl
41 {
42 
43     DatabaseControl oDateControl;
44     DatabaseControl oTimeControl;
45 //  XShape xGroupShape;
46     Resource oResource;
47     private String sDateAppendix; // = GetResText(RID_FORM + 4)
48     private String sTimeAppendix; // = GetResText(RID_FORM + 5)
49     XShapes xGroupShapes = null;
50     double nreldatewidth;
51     double nreltimewidth;
52     int nTimeWidth;
53     int nDBWidth;
54     int nDateWidth;
55     XShape xShapeGroup;
56 
TimeStampControl(Resource _oResource, FormHandler _oFormHandler, XNameContainer _xFormName, String _curFieldName, Point _aPoint)57     public TimeStampControl(Resource _oResource, FormHandler _oFormHandler, XNameContainer _xFormName, String _curFieldName, Point _aPoint)
58     {
59         super(_oFormHandler, "com.sun.star.drawing.ShapeCollection", _aPoint);
60         oResource = _oResource;
61 //      xGroupShape = xShape;
62         oDateControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.DATE, aPoint);
63         int nDBHeight = oDateControl.getControlHeight();
64         nDateWidth = oDateControl.getPreferredWidth();
65         oDateControl.setSize(new Size(nDateWidth, nDBHeight));
66         Point aTimePoint = new Point(aPoint.X + 10 + nDateWidth, aPoint.Y);
67         oTimeControl = new DatabaseControl(oFormHandler, _xFormName, _curFieldName, DataType.TIME, aTimePoint);
68         nTimeWidth = oTimeControl.getPreferredWidth();
69         oTimeControl.setSize(new Size(nTimeWidth, nDBHeight));
70         nDBWidth = nDateWidth + nTimeWidth + 10;
71         xShapes.add(oDateControl.xShape);
72         xShapes.add(oTimeControl.xShape);
73         xShapeGroup = _oFormHandler.xShapeGrouper.group(xShapes);
74         xShapeGroup = UnoRuntime.queryInterface(XShape.class, xShapeGroup);
75         nreldatewidth = 1.0 / ((double) getSize().Width / (double) nDateWidth);
76         nreltimewidth = 1.0 - nreldatewidth;
77     }
78 
getControlofGroupShapeByIndex(int _i)79     public XPropertySet getControlofGroupShapeByIndex(int _i)
80     {
81         try
82         {
83             if (_i < xShapes.getCount())
84             {
85                 Object oControl = xShapes.getByIndex(_i);
86                 XControlShape xControlShape = UnoRuntime.queryInterface(XControlShape.class, oControl);
87                 return UnoRuntime.queryInterface(XPropertySet.class, xControlShape.getControl());
88             }
89         }
90         catch (Exception e)
91         {
92             e.printStackTrace(System.out);
93         }
94         return null;
95     }
96 
TimeStampControl(Resource _oResource, GridControl _oGridControl, FieldColumn _curfieldcolumn)97     public TimeStampControl(Resource _oResource, GridControl _oGridControl, FieldColumn _curfieldcolumn)
98     {
99         super(_oGridControl, _curfieldcolumn);
100         oResource = _oResource;
101         sDateAppendix = oResource.getResText(UIConsts.RID_FORM + 88);
102         sTimeAppendix = oResource.getResText(UIConsts.RID_FORM + 89);
103         oDateControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.DATE, _curfieldcolumn.getFieldTitle() + PropertyNames.SPACE + sDateAppendix);
104         oTimeControl = new DatabaseControl(_oGridControl, _curfieldcolumn, DataType.TIME, _curfieldcolumn.getFieldTitle() + PropertyNames.SPACE + sTimeAppendix);
105     }
106 
setPropertyValue(String _sPropertyName, Object _aPropertyValue)107     public void setPropertyValue(String _sPropertyName, Object _aPropertyValue) throws Exception
108     {
109         oDateControl.setPropertyValue(_sPropertyName, _aPropertyValue);
110         oTimeControl.setPropertyValue(_sPropertyName, _aPropertyValue);
111     }
112 
getPreferredWidth()113     public int getPreferredWidth()
114     {
115         return nDBWidth;
116     }
117 
setSize(Size _aSize)118     public void setSize(Size _aSize)
119     {
120         try
121         {
122             int ndatewidth = (int) (nreldatewidth * (double) _aSize.Width);
123             int ntimewidth = (int) (nreltimewidth * (double) _aSize.Width);
124             oDateControl.xShape.setSize(new Size(ndatewidth, _aSize.Height));
125             oTimeControl.xShape.setSize(new Size(ntimewidth, _aSize.Height));
126         }
127         catch (PropertyVetoException e)
128         {
129             e.printStackTrace(System.out);
130         }
131     }
132 
getSize()133     public Size getSize()
134     {
135         int ncontrolwidth = oDateControl.xShape.getSize().Width + oTimeControl.xShape.getSize().Width;
136         return new Size(ncontrolwidth, oDateControl.xShape.getSize().Height);
137     }
138 
getPosition()139     public Point getPosition()
140     {
141         return xShapeGroup.getPosition();
142     }
143 
setPosition(Point _aPoint)144     public void setPosition(Point _aPoint)
145     {
146         // --> TESTING
147         Point aBeforePt = xShapeGroup.getPosition();
148         // <--
149         xShapeGroup.setPosition(_aPoint);
150 //      oDateControl.xShape.setPosition(_aPoint);
151 //      Point atimepoint = new Point(oDateControl.xShape.getPosition().X + oDateControl.xShape.getSize().Width, oDateControl.xShape.getPosition().Y );
152 //      oTimeControl.xShape.setPosition(atimepoint);
153         // --> TESTING
154         Point aAfterPt = xShapeGroup.getPosition();
155     // <--
156     }
157 
getControlType()158     public int getControlType()
159     {
160         return FormHandler.SODATETIMECONTROL;
161     }
162 }
163 
164 
165 
166 
167 
168