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.form;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.awt.XListBox;
26cdf0e10cSrcweir import com.sun.star.awt.XRadioButton;
27cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
28cdf0e10cSrcweir import com.sun.star.container.XNameAccess;
29cdf0e10cSrcweir import com.sun.star.lang.EventObject;
30cdf0e10cSrcweir import com.sun.star.lang.IllegalArgumentException;
31cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
32cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
33cdf0e10cSrcweir import com.sun.star.uno.Exception;
34cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
35cdf0e10cSrcweir import com.sun.star.uno.XInterface;
36cdf0e10cSrcweir import com.sun.star.wizards.common.Configuration;
37cdf0e10cSrcweir import com.sun.star.wizards.common.Desktop;
38cdf0e10cSrcweir import com.sun.star.wizards.common.FileAccess;
39cdf0e10cSrcweir import com.sun.star.wizards.common.Helper;
40cdf0e10cSrcweir import com.sun.star.wizards.common.JavaTools;
41cdf0e10cSrcweir import com.sun.star.wizards.common.NoValidPathException;
42cdf0e10cSrcweir import com.sun.star.wizards.common.PropertyNames;
43cdf0e10cSrcweir import com.sun.star.wizards.document.Control;
44cdf0e10cSrcweir import com.sun.star.wizards.document.DatabaseControl;
45cdf0e10cSrcweir import com.sun.star.wizards.document.GridControl;
46cdf0e10cSrcweir import com.sun.star.wizards.document.TimeStampControl;
47cdf0e10cSrcweir import com.sun.star.wizards.text.TextStyleHandler;
48cdf0e10cSrcweir import com.sun.star.wizards.ui.*;
49cdf0e10cSrcweir import com.sun.star.wizards.ui.UIConsts;
50cdf0e10cSrcweir import java.util.ArrayList;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // TODO: Style Templates fuer OOo?
53cdf0e10cSrcweir 
54cdf0e10cSrcweir public class StyleApplier
55cdf0e10cSrcweir {
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     private WizardDialog CurUnoDialog;
58cdf0e10cSrcweir     private XPropertySet xPageStylePropertySet;
59cdf0e10cSrcweir     private XMultiServiceFactory xMSF;
60cdf0e10cSrcweir     private short curtabindex;
61cdf0e10cSrcweir     private XRadioButton optNoBorder;
62cdf0e10cSrcweir     private XRadioButton opt3DLook;
63cdf0e10cSrcweir     private XRadioButton optFlat;
64cdf0e10cSrcweir     private XListBox lstStyles;
65cdf0e10cSrcweir     private Desktop.OfficePathRetriever curofficepath;//  String[][] sLayoutFiles;
66cdf0e10cSrcweir     private FormDocument curFormDocument;
67cdf0e10cSrcweir     private short iOldLayoutPos;
68cdf0e10cSrcweir     private int SOLAYOUTLST = 0;
69cdf0e10cSrcweir     private static final String SCHANGELAYOUT = "changeLayout";
70cdf0e10cSrcweir     private static final String SCHANGEBORDERTYPE = "changeBorderLayouts";
71cdf0e10cSrcweir     private String[] StyleNames;
72cdf0e10cSrcweir     private String[] StyleNodeNames;
73cdf0e10cSrcweir     private String[] FileNames;
74cdf0e10cSrcweir     // private String StylesPath;
75cdf0e10cSrcweir     private final static int SOBACKGROUNDCOLOR = 0;
76cdf0e10cSrcweir     private final static int SODBTEXTCOLOR = 1;
77cdf0e10cSrcweir     private final static int SOLABELTEXTCOLOR = 2;
78cdf0e10cSrcweir //  final static int SODBCONTROLBACKGROUNDCOLOR = 3;
79cdf0e10cSrcweir     private final static int SOLABELBACKGROUNDCOLOR = 4;
80cdf0e10cSrcweir     private final static int SOBORDERCOLOR = 5;
81cdf0e10cSrcweir     private Short IBorderValue = new Short((short) 1);
82cdf0e10cSrcweir 
StyleApplier(WizardDialog _CurUnoDialog, FormDocument _curFormDocument)83cdf0e10cSrcweir     public StyleApplier(WizardDialog _CurUnoDialog, FormDocument _curFormDocument) throws NoValidPathException
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir //        try
86cdf0e10cSrcweir //        {
87cdf0e10cSrcweir             this.curFormDocument = _curFormDocument;
88cdf0e10cSrcweir             xMSF = curFormDocument.xMSF;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             TextStyleHandler oTextStyleHandler = new TextStyleHandler(xMSF, curFormDocument.xTextDocument);
91cdf0e10cSrcweir             xPageStylePropertySet = oTextStyleHandler.getStyleByName("PageStyles", "Standard");
92cdf0e10cSrcweir             this.CurUnoDialog = _CurUnoDialog;
93cdf0e10cSrcweir             curtabindex = (short) (FormWizard.SOSTYLE_PAGE * 100);
94cdf0e10cSrcweir             Integer IStyleStep = new Integer(FormWizard.SOSTYLE_PAGE);
95cdf0e10cSrcweir             String sPageStyles = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 86);
96cdf0e10cSrcweir             String sNoBorder = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 29);
97cdf0e10cSrcweir             String s3DLook = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 30);
98cdf0e10cSrcweir             String sFlat = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 31);
99cdf0e10cSrcweir             String sFieldBorder = CurUnoDialog.m_oResource.getResText(UIConsts.RID_FORM + 28);
100cdf0e10cSrcweir //            XInterface xUcbInterface = (XInterface) _curFormDocument.xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess");
101cdf0e10cSrcweir             setStyles();
102cdf0e10cSrcweir             short[] SelLayoutPos;
103cdf0e10cSrcweir             SelLayoutPos = new short[]
104cdf0e10cSrcweir                     {
105cdf0e10cSrcweir                         0
106cdf0e10cSrcweir                     };
107cdf0e10cSrcweir 
108cdf0e10cSrcweir             CurUnoDialog.insertLabel("lblStyles",
109cdf0e10cSrcweir                     new String[]
110cdf0e10cSrcweir                     {
111cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
112cdf0e10cSrcweir                     },
113cdf0e10cSrcweir                     new Object[]
114cdf0e10cSrcweir                     {
115cdf0e10cSrcweir                         UIConsts.INTEGERS[8], sPageStyles, 92, 25, IStyleStep, new Short(curtabindex++), 90
116cdf0e10cSrcweir                     });
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             lstStyles = CurUnoDialog.insertListBox("lstStyles", null, SCHANGELAYOUT, this,
119cdf0e10cSrcweir                     new String[]
120cdf0e10cSrcweir                     {
121cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.SELECTED_ITEMS, PropertyNames.PROPERTY_STEP, PropertyNames.STRING_ITEM_LIST, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
122cdf0e10cSrcweir                     },
123cdf0e10cSrcweir                     new Object[]
124cdf0e10cSrcweir                     {
125cdf0e10cSrcweir                         143, "HID:WIZARDS_HID_DLGFORM_LSTSTYLES", 92, 35, SelLayoutPos, IStyleStep, this.StyleNames, new Short(curtabindex++), 90
126cdf0e10cSrcweir                     });
127cdf0e10cSrcweir 
128cdf0e10cSrcweir             optNoBorder = CurUnoDialog.insertRadioButton("otpNoBorder", SCHANGEBORDERTYPE, this,
129cdf0e10cSrcweir                     new String[]
130cdf0e10cSrcweir                     {
131cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tag", PropertyNames.PROPERTY_WIDTH
132cdf0e10cSrcweir                     },
133cdf0e10cSrcweir                     new Object[]
134cdf0e10cSrcweir                     {
135cdf0e10cSrcweir                         UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMDNOBORDER", sNoBorder, 196, 39, IStyleStep, new Short(curtabindex++), "0", 93
136cdf0e10cSrcweir                     });
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             opt3DLook = CurUnoDialog.insertRadioButton("otp3DLook", SCHANGEBORDERTYPE, this,
139cdf0e10cSrcweir                     new String[]
140cdf0e10cSrcweir                     {
141cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STATE, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tag", PropertyNames.PROPERTY_WIDTH
142cdf0e10cSrcweir                     },
143cdf0e10cSrcweir                     new Object[]
144cdf0e10cSrcweir                     {
145cdf0e10cSrcweir                         UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMD3DBORDER", s3DLook, 196, 53, new Short((short) 1), IStyleStep, new Short(curtabindex++), "1", 93
146cdf0e10cSrcweir                     });
147cdf0e10cSrcweir 
148cdf0e10cSrcweir             optFlat = CurUnoDialog.insertRadioButton("otpFlat", SCHANGEBORDERTYPE, this,
149cdf0e10cSrcweir                     new String[]
150cdf0e10cSrcweir                     {
151cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_HELPURL, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, "Tag", PropertyNames.PROPERTY_WIDTH
152cdf0e10cSrcweir                     },
153cdf0e10cSrcweir                     new Object[]
154cdf0e10cSrcweir                     {
155cdf0e10cSrcweir                         UIConsts.INTEGERS[10], "HID:WIZARDS_HID_DLGFORM_CMDSIMPLEBORDER", sFlat, 196, 67, IStyleStep, new Short(curtabindex++), "2", 93
156cdf0e10cSrcweir                     });
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             CurUnoDialog.insertFixedLine("lnFieldBorder",
159cdf0e10cSrcweir                     new String[]
160cdf0e10cSrcweir                     {
161cdf0e10cSrcweir                         PropertyNames.PROPERTY_HEIGHT, PropertyNames.PROPERTY_LABEL, PropertyNames.PROPERTY_POSITION_X, PropertyNames.PROPERTY_POSITION_Y, PropertyNames.PROPERTY_STEP, PropertyNames.PROPERTY_TABINDEX, PropertyNames.PROPERTY_WIDTH
162cdf0e10cSrcweir                     },
163cdf0e10cSrcweir                     new Object[]
164cdf0e10cSrcweir                     {
165cdf0e10cSrcweir                         UIConsts.INTEGERS[8], sFieldBorder, 192, 25, IStyleStep, new Short(curtabindex++), 98
166cdf0e10cSrcweir                     });
167cdf0e10cSrcweir //        }
168cdf0e10cSrcweir //        catch (Exception e)
169cdf0e10cSrcweir //        {
170cdf0e10cSrcweir //            e.printStackTrace(System.out);
171cdf0e10cSrcweir //        }
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     /*  public void initialize(short _iStyleindex){
175cdf0e10cSrcweir     if (_iStyleindex < lstStyles.getItemCount()){
176cdf0e10cSrcweir     Helper.setUnoPropertyValue(UnoDialog.getModel(lstStyles), PropertyNames.SELECTED_ITEMS, new short[]{_iStyleindex});
177cdf0e10cSrcweir     applyStyle(true, false);
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir      */
setStyles()181cdf0e10cSrcweir     private void setStyles()
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         try
184cdf0e10cSrcweir         {
185cdf0e10cSrcweir             Object oRootNode = Configuration.getConfigurationRoot(xMSF, "org.openoffice.Office.FormWizard/FormWizard/Styles", false);
186cdf0e10cSrcweir             XNameAccess xNameAccess = UnoRuntime.queryInterface(XNameAccess.class, oRootNode);
187cdf0e10cSrcweir             StyleNodeNames = xNameAccess.getElementNames();
188cdf0e10cSrcweir             StyleNames = new String[StyleNodeNames.length];
189cdf0e10cSrcweir             FileNames = new String[StyleNodeNames.length];
190cdf0e10cSrcweir             for (int i = 0; i < StyleNodeNames.length; i++)
191cdf0e10cSrcweir             {
192cdf0e10cSrcweir                 Object oStyleNode = xNameAccess.getByName(StyleNodeNames[i]);
193cdf0e10cSrcweir                 StyleNames[i] = (String) Helper.getUnoPropertyValue(oStyleNode, PropertyNames.PROPERTY_NAME);
194cdf0e10cSrcweir                 FileNames[i] = (String) Helper.getUnoPropertyValue(oStyleNode, "CssHref");
195cdf0e10cSrcweir             }
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir         catch (Exception e)
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir             e.printStackTrace(System.out);
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir     }
202cdf0e10cSrcweir 
getStyleIndex()203cdf0e10cSrcweir     private short getStyleIndex()
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         try
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             short[] SelFields = (short[]) AnyConverter.toArray(Helper.getUnoPropertyValue(UnoDialog.getModel(lstStyles), PropertyNames.SELECTED_ITEMS));
208cdf0e10cSrcweir             if (SelFields != null)
209cdf0e10cSrcweir             {
210cdf0e10cSrcweir                 return SelFields[0];
211cdf0e10cSrcweir             }
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir         catch (IllegalArgumentException e)
214cdf0e10cSrcweir         {
215cdf0e10cSrcweir             e.printStackTrace(System.out);
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir         return (short) -1;
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
applyStyle(boolean _bmodifyBackground, boolean _bapplyalways)220cdf0e10cSrcweir     public void applyStyle(boolean _bmodifyBackground, boolean _bapplyalways)
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir         short iStyle = getStyleIndex();
223cdf0e10cSrcweir         if ((iStyle != iOldLayoutPos) || _bapplyalways)
224cdf0e10cSrcweir         {
225cdf0e10cSrcweir             if (iStyle > -1)
226cdf0e10cSrcweir             {
227cdf0e10cSrcweir                 iOldLayoutPos = iStyle;
228cdf0e10cSrcweir                 String sFileName = FileNames[iStyle]; //Style =  lstStyles.getSelectedItem();
229cdf0e10cSrcweir                 int[] iStyles = getStyleColors(sFileName);
230cdf0e10cSrcweir                 applyDBControlProperties(iStyles);
231cdf0e10cSrcweir             }
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir     }
234cdf0e10cSrcweir 
changeLayout()235cdf0e10cSrcweir     public void changeLayout()
236cdf0e10cSrcweir     {
237cdf0e10cSrcweir         short iPos = lstStyles.getSelectedItemPos();
238cdf0e10cSrcweir         if (iPos != iOldLayoutPos)
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             iOldLayoutPos = iPos;
241cdf0e10cSrcweir             String sFileName = FileNames[iPos]; //Style =  lstStyles.getSelectedItem();
242cdf0e10cSrcweir             int[] iStyles = getStyleColors(sFileName);
243cdf0e10cSrcweir             applyDBControlProperties(iStyles);
244cdf0e10cSrcweir         }
245cdf0e10cSrcweir         curFormDocument.unlockallControllers();
246cdf0e10cSrcweir     }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     /*  public void changeLayout(){
249cdf0e10cSrcweir     /       curFormDocument.xTextDocument.lockControllers();
250cdf0e10cSrcweir     applyStyle(true, false);
251cdf0e10cSrcweir     curFormDocument.unlockallControllers();
252cdf0e10cSrcweir     }
253cdf0e10cSrcweir      */
getBorderType()254cdf0e10cSrcweir     public Short getBorderType()
255cdf0e10cSrcweir     {
256cdf0e10cSrcweir         return IBorderValue;
257cdf0e10cSrcweir     }
258cdf0e10cSrcweir 
changeBorderLayouts()259cdf0e10cSrcweir     public void changeBorderLayouts()
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         try
262cdf0e10cSrcweir         {
263cdf0e10cSrcweir             curFormDocument.xTextDocument.lockControllers();
264cdf0e10cSrcweir 
265cdf0e10cSrcweir             if (optNoBorder.getState())
266cdf0e10cSrcweir             {
267cdf0e10cSrcweir                 IBorderValue = new Short((short) 0);
268cdf0e10cSrcweir             }
269cdf0e10cSrcweir             else if (opt3DLook.getState())
270cdf0e10cSrcweir             {
271cdf0e10cSrcweir                 IBorderValue = new Short((short) 1);
272cdf0e10cSrcweir             }
273cdf0e10cSrcweir             else
274cdf0e10cSrcweir             {
275cdf0e10cSrcweir                 IBorderValue = new Short((short) 2);
276cdf0e10cSrcweir             }
277cdf0e10cSrcweir             for (int m = 0; m < curFormDocument.oControlForms.size(); m++)
278cdf0e10cSrcweir             {
279cdf0e10cSrcweir                 FormDocument.ControlForm curControlForm = ((FormDocument.ControlForm) curFormDocument.oControlForms.get(m));
280cdf0e10cSrcweir                 if (curControlForm.getArrangemode() == FormWizard.AS_GRID)
281cdf0e10cSrcweir                 {
282cdf0e10cSrcweir                     GridControl oGridControl = curControlForm.getGridControl();
283cdf0e10cSrcweir                     oGridControl.xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, IBorderValue);
284cdf0e10cSrcweir                 }
285cdf0e10cSrcweir                 else
286cdf0e10cSrcweir                 {
287cdf0e10cSrcweir                     DatabaseControl[] DBControls = curControlForm.getDatabaseControls();
288cdf0e10cSrcweir                     for (int n = 0; n < DBControls.length; n++)
289cdf0e10cSrcweir                     {
290cdf0e10cSrcweir                         if (DBControls[n].xServiceInfo.supportsService("com.sun.star.drawing.ShapeCollection"))
291cdf0e10cSrcweir                         {
292cdf0e10cSrcweir                             TimeStampControl oTimeStampControl = (TimeStampControl) DBControls[n];
293cdf0e10cSrcweir                             for (int i = 0; i < 2; i++)
294cdf0e10cSrcweir                             {
295cdf0e10cSrcweir                                 XPropertySet xPropertySet = oTimeStampControl.getControlofGroupShapeByIndex(i);
296cdf0e10cSrcweir                                 if (xPropertySet.getPropertySetInfo().hasPropertyByName(PropertyNames.PROPERTY_BORDER))
297cdf0e10cSrcweir                                 {
298cdf0e10cSrcweir                                     xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, IBorderValue);
299cdf0e10cSrcweir                                 }
300cdf0e10cSrcweir                             }
301cdf0e10cSrcweir                         }
302cdf0e10cSrcweir                         else
303cdf0e10cSrcweir                         {
304cdf0e10cSrcweir                             if (DBControls[n].xPropertySet.getPropertySetInfo().hasPropertyByName(PropertyNames.PROPERTY_BORDER))
305cdf0e10cSrcweir                             {
306cdf0e10cSrcweir                                 DBControls[n].xPropertySet.setPropertyValue(PropertyNames.PROPERTY_BORDER, IBorderValue);
307cdf0e10cSrcweir                             }
308cdf0e10cSrcweir                         }
309cdf0e10cSrcweir                     }
310cdf0e10cSrcweir                 }
311cdf0e10cSrcweir             }
312cdf0e10cSrcweir         }
313cdf0e10cSrcweir         catch (Exception e)
314cdf0e10cSrcweir         {
315cdf0e10cSrcweir             e.printStackTrace(System.out);
316cdf0e10cSrcweir         }
317cdf0e10cSrcweir         curFormDocument.unlockallControllers();
318cdf0e10cSrcweir     }
319cdf0e10cSrcweir 
disposing(EventObject eventObject)320cdf0e10cSrcweir     public void disposing(EventObject eventObject)
321cdf0e10cSrcweir     {
322cdf0e10cSrcweir     }
323cdf0e10cSrcweir 
getStyleColor(String[] _sDataList, String _sHeader, String _sPropertyDescription)324cdf0e10cSrcweir     private int getStyleColor(String[] _sDataList, String _sHeader, String _sPropertyDescription)
325cdf0e10cSrcweir     {
326cdf0e10cSrcweir         int iColor = -1;
327cdf0e10cSrcweir         int index = JavaTools.FieldInList(_sDataList, _sHeader);
328cdf0e10cSrcweir         if (index > -1)
329cdf0e10cSrcweir         {
330cdf0e10cSrcweir             String sPropName = PropertyNames.EMPTY_STRING;
331cdf0e10cSrcweir             int iStyleColor;
332cdf0e10cSrcweir             while (((sPropName.indexOf("}") < 0) && (index < _sDataList.length - 1)))
333cdf0e10cSrcweir             {
334cdf0e10cSrcweir                 String scurline = _sDataList[index++];
335cdf0e10cSrcweir                 if ((scurline.indexOf(_sPropertyDescription)) > 0)
336cdf0e10cSrcweir                 {
337cdf0e10cSrcweir                     if (scurline.indexOf(":") > 0)
338cdf0e10cSrcweir                     {
339cdf0e10cSrcweir                         String[] sPropList = JavaTools.ArrayoutofString(scurline, ":");
340cdf0e10cSrcweir                         String sPropValue = sPropList[1];
341cdf0e10cSrcweir                         sPropValue = sPropValue.trim();
342cdf0e10cSrcweir                         if (sPropValue.indexOf("#") > -1)
343cdf0e10cSrcweir                         {
344cdf0e10cSrcweir                             sPropValue = JavaTools.replaceSubString(sPropValue, PropertyNames.EMPTY_STRING, PropertyNames.SEMI_COLON);
345cdf0e10cSrcweir                             sPropValue = JavaTools.replaceSubString(sPropValue, PropertyNames.EMPTY_STRING, PropertyNames.SPACE);
346cdf0e10cSrcweir                             return Integer.decode(sPropValue).intValue();
347cdf0e10cSrcweir                         }
348cdf0e10cSrcweir                     }
349cdf0e10cSrcweir                 }
350cdf0e10cSrcweir             }
351cdf0e10cSrcweir         }
352cdf0e10cSrcweir         return -1;
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir 
getMSF()355cdf0e10cSrcweir     private XMultiServiceFactory getMSF()
356cdf0e10cSrcweir     {
357cdf0e10cSrcweir         return xMSF;
358cdf0e10cSrcweir     }
359cdf0e10cSrcweir 
getStylePaths()360cdf0e10cSrcweir     private ArrayList<String> getStylePaths()
361cdf0e10cSrcweir     {
362cdf0e10cSrcweir         ArrayList<String> aStylePaths = new ArrayList<String>();
363cdf0e10cSrcweir         try
364cdf0e10cSrcweir         {
365cdf0e10cSrcweir             // TODO: check different languages in header layouts
366cdf0e10cSrcweir             aStylePaths = FileAccess.getOfficePaths(getMSF(), "Config", PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING);
367cdf0e10cSrcweir             FileAccess.combinePaths(getMSF(), aStylePaths, "/wizard/form/styles");
368cdf0e10cSrcweir 
369cdf0e10cSrcweir             String[][] LayoutFiles = FileAccess.getFolderTitles(getMSF(), null, aStylePaths, ".css");
370cdf0e10cSrcweir 
371cdf0e10cSrcweir         }
372cdf0e10cSrcweir         catch (com.sun.star.wizards.common.NoValidPathException e)
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir             // if there are problems, don't show anything is a little bit hard.
375cdf0e10cSrcweir             aStylePaths.add("default");
376cdf0e10cSrcweir         }
377cdf0e10cSrcweir         return aStylePaths;
378cdf0e10cSrcweir     }
379cdf0e10cSrcweir 
getStylePath()380cdf0e10cSrcweir     private String getStylePath()
381cdf0e10cSrcweir         {
382cdf0e10cSrcweir // TODO: umstellen auf mehrere Pfade
383cdf0e10cSrcweir             String StylesPath = PropertyNames.EMPTY_STRING;
384cdf0e10cSrcweir             try
385cdf0e10cSrcweir             {
386cdf0e10cSrcweir                 StylesPath = FileAccess.getOfficePath(xMSF, "Config", PropertyNames.EMPTY_STRING, PropertyNames.EMPTY_STRING);
387cdf0e10cSrcweir                 StylesPath = FileAccess.combinePaths(xMSF, StylesPath, "/wizard/form/styles");
388cdf0e10cSrcweir             }
389cdf0e10cSrcweir             catch (NoValidPathException e)
390cdf0e10cSrcweir             {
391cdf0e10cSrcweir             }
392cdf0e10cSrcweir             return StylesPath;
393cdf0e10cSrcweir         }
394cdf0e10cSrcweir 
getStyleColors(String _filename)395cdf0e10cSrcweir     private int[] getStyleColors(String _filename)
396cdf0e10cSrcweir     {
397cdf0e10cSrcweir         String sFilePath = getStylePath() + "/" + _filename;
398cdf0e10cSrcweir         int[] oStylePropList = new int[6];
399cdf0e10cSrcweir         String[] sData = FileAccess.getDataFromTextFile(xMSF, sFilePath);
400cdf0e10cSrcweir         oStylePropList[SOBACKGROUNDCOLOR] = getStyleColor(sData, ".toctitle {", "background-color:");
401cdf0e10cSrcweir         oStylePropList[SODBTEXTCOLOR] = getStyleColor(sData, ".doctitle {", "color:");
402cdf0e10cSrcweir         oStylePropList[SOLABELTEXTCOLOR] = getStyleColor(sData, ".toctitle {", "color:");
403cdf0e10cSrcweir //      oStylePropList[SODBCONTROLBACKGROUNDCOLOR] = getStyleColor(sData, "body {", "background-color:");
404cdf0e10cSrcweir //      oStylePropList[SOLABELBACKGROUNDCOLOR] = getStyleColor(sData, ".toctitle {", "background-color:");
405cdf0e10cSrcweir         oStylePropList[SOBORDERCOLOR] = getStyleColor(sData, ".tcolor {", "border-color:");
406cdf0e10cSrcweir         return oStylePropList;
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
setDBControlColors(XPropertySet xPropertySet, int[] _iStyleColors)409cdf0e10cSrcweir     private void setDBControlColors(XPropertySet xPropertySet, int[] _iStyleColors)
410cdf0e10cSrcweir     {
411cdf0e10cSrcweir         try
412cdf0e10cSrcweir         {
413cdf0e10cSrcweir             if (xPropertySet.getPropertySetInfo().hasPropertyByName("TextColor"))
414cdf0e10cSrcweir             {
415cdf0e10cSrcweir                 if (_iStyleColors[SODBTEXTCOLOR] > -1)
416cdf0e10cSrcweir                 {
417cdf0e10cSrcweir                     xPropertySet.setPropertyValue("TextColor", Integer.decode("#00000"));
418cdf0e10cSrcweir                 }
419cdf0e10cSrcweir             }
420cdf0e10cSrcweir             if (xPropertySet.getPropertySetInfo().hasPropertyByName("BackgroundColor"))
421cdf0e10cSrcweir             {
422cdf0e10cSrcweir                 xPropertySet.setPropertyValue("BackgroundColor", Integer.decode("#DDDDDD"));
423cdf0e10cSrcweir             }
424cdf0e10cSrcweir         }
425cdf0e10cSrcweir         catch (Exception e)
426cdf0e10cSrcweir         {
427cdf0e10cSrcweir             e.printStackTrace(System.out);
428cdf0e10cSrcweir         }
429cdf0e10cSrcweir     }
430cdf0e10cSrcweir 
applyDBControlProperties(int[] _iStyleColors)431cdf0e10cSrcweir     public void applyDBControlProperties(int[] _iStyleColors)
432cdf0e10cSrcweir     {
433cdf0e10cSrcweir         try
434cdf0e10cSrcweir         {
435cdf0e10cSrcweir             for (int m = 0; m < curFormDocument.oControlForms.size(); m++)
436cdf0e10cSrcweir             {
437cdf0e10cSrcweir                 FormDocument.ControlForm curControlForm = ((FormDocument.ControlForm) curFormDocument.oControlForms.get(m));
438cdf0e10cSrcweir                 if (curControlForm.getArrangemode() == FormWizard.AS_GRID)
439cdf0e10cSrcweir                 {
440cdf0e10cSrcweir                     if (_iStyleColors[SOLABELTEXTCOLOR] > -1)
441cdf0e10cSrcweir                     {
442cdf0e10cSrcweir                         curControlForm.oGridControl.xPropertySet.setPropertyValue("TextColor", new Integer(_iStyleColors[SODBTEXTCOLOR]));
443cdf0e10cSrcweir                     }
444cdf0e10cSrcweir                     curControlForm.oGridControl.xPropertySet.setPropertyValue("BackgroundColor", Integer.decode("#DDDDDD"));
445cdf0e10cSrcweir                 }
446cdf0e10cSrcweir                 else
447cdf0e10cSrcweir                 {
448cdf0e10cSrcweir                     DatabaseControl[] DBControls = curControlForm.getDatabaseControls();
449cdf0e10cSrcweir                     for (int n = 0; n < DBControls.length; n++)
450cdf0e10cSrcweir                     {
451cdf0e10cSrcweir                         if (_iStyleColors[SODBTEXTCOLOR] > -1)
452cdf0e10cSrcweir                         {
453cdf0e10cSrcweir                             DatabaseControl aDBControl = DBControls[n];
454cdf0e10cSrcweir                             if (aDBControl != null)
455cdf0e10cSrcweir                             {
456cdf0e10cSrcweir                                 if (aDBControl.xServiceInfo.supportsService("com.sun.star.drawing.ShapeCollection"))
457cdf0e10cSrcweir                             {
458cdf0e10cSrcweir                                     TimeStampControl oTimeStampControl = (TimeStampControl) aDBControl;
459cdf0e10cSrcweir                                 for (int i = 0; i < 2; i++)
460cdf0e10cSrcweir                                 {
461cdf0e10cSrcweir                                     XPropertySet xPropertySet = oTimeStampControl.getControlofGroupShapeByIndex(i);
462cdf0e10cSrcweir                                     setDBControlColors(xPropertySet, _iStyleColors);
463cdf0e10cSrcweir                                 }
464cdf0e10cSrcweir                             }
465cdf0e10cSrcweir                             else
466cdf0e10cSrcweir                             {
467cdf0e10cSrcweir                                     setDBControlColors(aDBControl.xPropertySet, _iStyleColors);
468cdf0e10cSrcweir                                 }
469cdf0e10cSrcweir                             }
470cdf0e10cSrcweir                         }
471cdf0e10cSrcweir                     }
472cdf0e10cSrcweir                     Control[] LabelControls = curControlForm.getLabelControls();
473cdf0e10cSrcweir                     for (int n = 0; n < LabelControls.length; n++)
474cdf0e10cSrcweir                     {
475cdf0e10cSrcweir                         if (_iStyleColors[SOLABELTEXTCOLOR] > -1)
476cdf0e10cSrcweir                         {
477cdf0e10cSrcweir                             LabelControls[n].xPropertySet.setPropertyValue("TextColor", new Integer(_iStyleColors[SOLABELTEXTCOLOR]));
478cdf0e10cSrcweir //                  if (_iStyleColors[SOCONTROLBACKGROUNDCOLOR] > -1)
479cdf0e10cSrcweir //                      LabelControls[n].xPropertySet.setPropertyValue("BackgroundColor", new Integer(_iStyleColors[SOCONTROLBACKGROUNDCOLOR]));
480cdf0e10cSrcweir                         }
481cdf0e10cSrcweir                     }
482cdf0e10cSrcweir                 }
483cdf0e10cSrcweir             }
484cdf0e10cSrcweir             xPageStylePropertySet.setPropertyValue("BackColor", new Integer(_iStyleColors[SOBACKGROUNDCOLOR]));
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir         catch (Exception e)
487cdf0e10cSrcweir         {
488cdf0e10cSrcweir             e.printStackTrace(System.out);
489cdf0e10cSrcweir         }
490cdf0e10cSrcweir     }
491cdf0e10cSrcweir }
492