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.reportbuilder.layout;
24 
25 import com.sun.star.awt.Rectangle;
26 import com.sun.star.report.XGroup;
27 import com.sun.star.report.XSection;
28 import com.sun.star.wizards.common.Resource;
29 import com.sun.star.wizards.report.IReportDefinitionReadAccess;
30 import com.sun.star.wizards.ui.UIConsts;
31 
32 /**
33  *
34  * @author ll93751
35  */
36 public class ColumnarTwoColumns extends ReportBuilderLayouter
37 {
38 
ColumnarTwoColumns(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource)39     public ColumnarTwoColumns(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource)
40     {
41         super(_xDefinitionAccess, _aResource);
42     }
43 
getName()44     public String getName()
45     {
46         return "ColumnarTwoColumnsLayoutOfData";
47     }
48 
getLocalizedName()49     public String getLocalizedName()
50     {
51         return getResource().getResText(UIConsts.RID_REPORT + 82);
52     }
53 
insertDetailFields()54     protected void insertDetailFields()
55     {
56         insertDetailFields(2);
57     }
58 
insertDetailFields(int _nColumns)59     protected void insertDetailFields(int _nColumns)
60     {
61         copyDetailProperties();
62 
63         if (_nColumns < 1)
64         {
65             return;
66         }
67         final String[] aFieldTitleNames = getFieldTitleNames();
68         if (aFieldTitleNames == null)
69         {
70             return;
71         }
72         final String[] aFieldNames = getFieldNames();
73         if (aFieldNames == null)
74         {
75             return;
76         }
77 //        int nGroups = getReportDefinition().getGroups().getCount();
78 
79         final XSection xSection = getReportDefinition().getDetail();
80 
81         Rectangle aRect = new Rectangle();
82 
83         final int nLabelWidth = getMaxLabelWidth(); // 3000;
84 
85         final int nUsablePageWidth = getPageWidth() - getLeftPageIndent() - getRightPageIndent() - getLeftGroupIndent(getCountOfGroups());
86         int i = 0;
87         int nRows = aFieldNames.length / _nColumns;
88         if ((aFieldNames.length % _nColumns) != 0)
89         {
90             ++nRows;
91         }
92         final int nWidth = (nUsablePageWidth - nLabelWidth * _nColumns) / _nColumns;
93         if (nWidth < 0)
94         {
95             // TODO: error message in logging
96             return;
97         }
98 
99         final SectionObject aSOLabel = getDesignTemplate().getDetailLabel();
100         aSOLabel.setFontToBold();
101         final SectionObject aSOTextField = getDesignTemplate().getDetailTextField();
102         int nMaxHeight = 0;
103         for (int x = 0; x < _nColumns; x++)
104         {
105             aRect.Y = 0;
106             for (int y = 0; y < nRows; y++)
107             {
108                 aRect.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups()) + x * (nWidth + nLabelWidth);
109                 if (i < aFieldNames.length)
110                 {
111                     final String sLabel = aFieldTitleNames[i];
112                     aRect = insertLabel(xSection, sLabel, aRect, nLabelWidth, aSOLabel);
113                     final String sFieldName = convertToFieldName(aFieldNames[i]);
114                     aRect = insertFormattedField(xSection, sFieldName, aRect, nWidth, aSOTextField);
115 
116                     aRect.Y += Math.max(aSOLabel.getHeight(LayoutConstants.LabelHeight), aRect.Height);
117                     ++i;
118                 }
119             }
120             nMaxHeight = Math.max(aRect.Y, nMaxHeight);
121         }
122         aRect.Y = Math.max(aSOLabel.getHeight(LayoutConstants.LabelHeight) * nRows, nMaxHeight);
123         aRect.Y += aSOLabel.getHeight(LayoutConstants.EmptyLineHeight); // one empty line
124         xSection.setHeight(aRect.Y);
125         doNotBreakInTable(xSection);
126     }
127 
insertDetailFieldTitles(int lastGroupPostion)128     protected void insertDetailFieldTitles(int lastGroupPostion)
129     {
130         // we won't extra field titles
131     }
132 }
133