1 /*
2  * JasperReports - Free Java Reporting Library.
3  * Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved.
4  * http://www.jaspersoft.com
5  *
6  * Unless you have purchased a commercial license agreement from Jaspersoft,
7  * the following license terms apply:
8  *
9  * This program is part of JasperReports.
10  *
11  * JasperReports is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * JasperReports is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * along with JasperReports. If not, see <http://www.gnu.org/licenses/>.
23  */

24 package net.sf.jasperreports.engine.base;
25
26 import java.awt.Color;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30
31 import net.sf.jasperreports.engine.JRChild;
32 import net.sf.jasperreports.engine.JRConstants;
33 import net.sf.jasperreports.engine.JRElement;
34 import net.sf.jasperreports.engine.JRExpressionCollector;
35 import net.sf.jasperreports.engine.JRFrame;
36 import net.sf.jasperreports.engine.JRLineBox;
37 import net.sf.jasperreports.engine.JRVisitor;
38 import net.sf.jasperreports.engine.type.BorderSplitType;
39 import net.sf.jasperreports.engine.type.ModeEnum;
40 import net.sf.jasperreports.engine.util.ElementsVisitorUtils;
41
42 /**
43  * Base read-only implementation of {@link net.sf.jasperreports.engine.JRFrame JRFrame}.
44  * 
45  * @author Lucian Chirita (lucianc@users.sourceforge.net)
46  */

47 public class JRBaseFrame extends JRBaseElement implements JRFrame
48 {
49     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
50     
51     protected List<JRChild> children;
52
53     protected JRLineBox lineBox;
54     
55     private BorderSplitType borderSplitType;
56
57
58     public JRBaseFrame(JRFrame frame, JRBaseObjectFactory factory)
59     {
60         super(frame, factory);
61
62         List<JRChild> frameChildren = frame.getChildren();
63         if (frameChildren != null)
64         {
65             children = new ArrayList<JRChild>(frameChildren.size());
66             for (Iterator<JRChild> it = frameChildren.iterator(); it.hasNext();)
67             {
68                 JRChild child = it.next();
69                 children.add((JRChild)factory.getVisitResult(child));
70             }
71         }
72         
73         lineBox = frame.getLineBox().clone(this);
74         this.borderSplitType = frame.getBorderSplitType();
75     }
76
77     @Override
78     public JRElement[] getElements()
79     {
80         return JRBaseElementGroup.getElements(children);
81     }
82
83     @Override
84     public void collectExpressions(JRExpressionCollector collector)
85     {
86         collector.collect(this);
87     }
88
89     @Override
90     public void visit(JRVisitor visitor)
91     {
92         visitor.visitFrame(this);
93         
94         if (ElementsVisitorUtils.visitDeepElements(visitor))
95         {
96             ElementsVisitorUtils.visitElements(visitor, children);
97         }
98     }
99     
100     @Override
101     public List<JRChild> getChildren()
102     {
103         return children;
104     }
105
106     @Override
107     public JRElement getElementByKey(String elementKey)
108     {
109         return JRBaseElementGroup.getElementByKey(getElements(), elementKey);
110     }
111     
112     @Override
113     public ModeEnum getModeValue()
114     {
115         return getStyleResolver().getMode(this, ModeEnum.TRANSPARENT);
116     }
117
118
119     @Override
120     public JRLineBox getLineBox()
121     {
122         return lineBox;
123     }
124
125     @Override
126     public Color getDefaultLineColor() 
127     {
128         return getForecolor();
129     }
130
131     @Override
132     public BorderSplitType getBorderSplitType()
133     {
134         return borderSplitType;
135     }
136
137     
138     @Override
139     public Object clone()
140     {
141         JRBaseFrame clone = (JRBaseFrame) super.clone();
142         
143         if (children != null)
144         {
145             clone.children = new ArrayList<JRChild>(children.size());
146             for(int i = 0; i < children.size(); i++)
147             {
148                 clone.children.add((JRChild)(children.get(i).clone(clone)));
149             }
150         }
151         
152         return clone;
153     }
154 }
155