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.*;
31 
32 /**
33  *
34  * @author ll93751
35  */
36 public class InBlocksLabelsAbove extends ColumnarTwoColumns
37 {
38 
InBlocksLabelsAbove(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource)39     public InBlocksLabelsAbove(IReportDefinitionReadAccess _xDefinitionAccess, Resource _aResource)
40     {
41         super(_xDefinitionAccess, _aResource);
42     }
43 
getName()44     public String getName()
45     {
46         return "InBlocksLabelsAboveLayoutOfData";
47     }
48 
getLocalizedName()49     public String getLocalizedName()
50     {
51         return getResource().getResText(UIConsts.RID_REPORT + 85);
52     }
53 
insertDetailFields()54     protected void insertDetailFields()
55     {
56         copyDetailProperties();
57 
58         final String[] aFieldTitleNames = getFieldTitleNames();
59         if (aFieldTitleNames == null)
60         {
61             return;
62         }
63         final String[] aFieldNames = getFieldNames();
64         if (aFieldNames == null)
65         {
66             return;
67         }
68 //        int nGroups = getReportDefinition().getGroups().getCount();
69 
70         final XSection xSection = getReportDefinition().getDetail();
71 
72         Rectangle aRectLabels = new Rectangle();
73         Rectangle aRectFields = new Rectangle();
74 
75 
76         final int nUsablePageWidth = getPageWidth() - getLeftPageIndent() - getRightPageIndent() - getLeftGroupIndent(getCountOfGroups());
77 
78         int i = 0;
79         int nCount = aFieldTitleNames.length;
80         // int x = 0;
81         aRectLabels.Y = 0;
82         aRectLabels.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
83 
84         aRectFields.Y = LayoutConstants.LabelHeight;
85         aRectFields.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
86 
87         // first run only calculates the width.
88         int nDelta = 0;
89         int nFieldWidth = 3000;
90         while (nCount > 0)
91         {
92             // String sLabel = aFieldTitleNames[i];
93             // int nLabelWidth = 3000;
94             // String sFieldName = convertToFieldName(aFieldNames[i]);
95             aRectFields.X += nFieldWidth;
96             // aRectLabels.X += nFieldWidth;
97 
98             final int nNextX = aRectFields.X + nFieldWidth;
99             if (nNextX > (getPageWidth() - getRightPageIndent()))
100             {
101                 // all other values are not from interest.
102                 break;
103             }
104 
105             ++i;
106             --nCount;
107         }
108         final int nDeltaTotal = nUsablePageWidth - i * nFieldWidth;
109         nDelta = nDeltaTotal;
110         if (i > 0)
111         {
112             nDelta = nDeltaTotal / i;
113         }
114 
115         aRectLabels.Y = 0;
116         aRectLabels.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
117 
118         final SectionObject aSOLabel = getDesignTemplate().getDetailLabel();
119         aSOLabel.setFontToBold();
120         final SectionObject aSOTextField = getDesignTemplate().getDetailTextField();
121 
122         aRectFields.Y = aSOLabel.getHeight(LayoutConstants.LabelHeight);
123         aRectFields.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
124         i = 0;
125         nCount = aFieldTitleNames.length;
126         int nLastHeight = 0;
127         while (nCount > 0)
128         {
129             final String sLabel = aFieldTitleNames[i];
130             final int nLabelWidth = 3000 + nDelta;
131             aRectLabels = insertLabel(xSection, sLabel, aRectLabels, nLabelWidth, aSOLabel);
132             final String sFieldName = convertToFieldName(aFieldNames[i]);
133             nFieldWidth = 3000 + nDelta;
134             aRectFields = insertFormattedField(xSection, sFieldName, aRectFields, nFieldWidth, aSOTextField);
135             nLastHeight = Math.max(nLastHeight, aRectFields.Height);
136             int nNextX = aRectFields.X + nFieldWidth;
137             if (nNextX > (getPageWidth() - getRightPageIndent()) & nCount > 1)
138             {
139                 int nHeight = (aSOLabel.getHeight(LayoutConstants.LabelHeight) + Math.max(aSOTextField.getHeight(LayoutConstants.FormattedFieldHeight), nLastHeight));
140                 nLastHeight = 0;
141                 aRectLabels.Y += nHeight; // 2 * label height
142                 aRectLabels.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
143 
144                 aRectFields.Y += nHeight;
145                 aRectFields.X = getLeftPageIndent() + getLeftGroupIndent(getCountOfGroups());
146             }
147             ++i;
148             --nCount;
149         }
150         aRectFields.Y += Math.max(aSOTextField.getHeight(LayoutConstants.FormattedFieldHeight), nLastHeight);
151         aRectFields.Y += aSOTextField.getHeight(LayoutConstants.EmptyLineHeight); // one empty line
152         xSection.setHeight(aRectFields.Y);
153         doNotBreakInTable(xSection);
154     }
155 
insertDetailFieldTitles(int lastGroupPostion)156     protected void insertDetailFieldTitles(int lastGroupPostion)
157     {
158         // we won't extra field titles
159     }
160 }
161