KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jasperreports > engine > fill > JRTemplateElement


1 /*
2  * ============================================================================
3  * GNU Lesser General Public License
4  * ============================================================================
5  *
6  * JasperReports - Free Java report-generating library.
7  * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * JasperSoft Corporation
24  * 303 Second Street, Suite 450 North
25  * San Francisco, CA 94107
26  * http://www.jaspersoft.com
27  */

28 package net.sf.jasperreports.engine.fill;
29
30 import java.awt.Color JavaDoc;
31 import java.io.Serializable JavaDoc;
32 import java.util.Random JavaDoc;
33
34 import net.sf.jasperreports.engine.JRConstants;
35 import net.sf.jasperreports.engine.JRDefaultStyleProvider;
36 import net.sf.jasperreports.engine.JRElement;
37 import net.sf.jasperreports.engine.JRStyle;
38 import net.sf.jasperreports.engine.JRStyleContainer;
39 import net.sf.jasperreports.engine.util.JRStyleResolver;
40
41
42 /**
43  * @author Teodor Danciu (teodord@users.sourceforge.net)
44  * @version $Id: JRTemplateElement.java 1471 2006-11-09 18:16:34 +0200 (Thu, 09 Nov 2006) lucianc $
45  */

46 public abstract class JRTemplateElement implements JRStyleContainer, Serializable JavaDoc
47 {
48
49
50     /**
51      *
52      */

53     private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
54     
55     private static final Random JavaDoc randomId = new Random JavaDoc();
56
57     /**
58      *
59      */

60     private String JavaDoc key;
61     private Byte JavaDoc mode = null;
62     private Color JavaDoc forecolor = null;
63     private Color JavaDoc backcolor = null;
64
65     protected JRDefaultStyleProvider defaultStyleProvider;
66     protected JRStyle parentStyle = null;
67
68     private final String JavaDoc id;
69     
70     /**
71      *
72      */

73     protected JRTemplateElement(JRDefaultStyleProvider defaultStyleProvider)
74     {
75         this.defaultStyleProvider = defaultStyleProvider;
76         id = createId();
77     }
78
79     /**
80      *
81      */

82     protected JRTemplateElement(JRElement element)
83     {
84         setElement(element);
85         id = createId();
86     }
87
88     protected JRTemplateElement(String JavaDoc id)
89     {
90         this.id = id;
91     }
92     
93     private String JavaDoc createId()
94     {
95         return System.identityHashCode(this) + "_" + System.currentTimeMillis() + "_" + randomId.nextInt();
96     }
97
98
99     /**
100      *
101      */

102     protected void setElement(JRElement element)
103     {
104         parentStyle = element.getStyle();
105         
106         setKey(element.getKey());
107         
108         mode = element.getOwnMode();
109         forecolor = element.getOwnForecolor();
110         backcolor = element.getOwnBackcolor();
111     }
112
113     /**
114      *
115      */

116     public JRDefaultStyleProvider getDefaultStyleProvider()
117     {
118         return defaultStyleProvider;
119     }
120
121     /**
122      *
123      */

124     public JRStyle getStyle()
125     {
126         return parentStyle;
127     }
128
129     /**
130      *
131      */

132     protected JRStyle getBaseStyle()
133     {
134         if (parentStyle != null)
135             return parentStyle;
136         if (defaultStyleProvider != null)
137             return defaultStyleProvider.getDefaultStyle();
138         return null;
139     }
140
141     /**
142      *
143      */

144     public byte getMode()
145     {
146         return JRStyleResolver.getMode(this, JRElement.MODE_OPAQUE);
147     }
148         
149     /**
150      *
151      */

152     public Byte JavaDoc getOwnMode()
153     {
154         return mode;
155     }
156     
157     /**
158      *
159      */

160     protected void setMode(byte mode)
161     {
162         this.mode = new Byte JavaDoc(mode);
163     }
164     
165     /**
166      *
167      */

168     protected void setMode(Byte JavaDoc mode)
169     {
170         this.mode = mode;
171     }
172     
173     /**
174      *
175      */

176     public Color JavaDoc getForecolor()
177     {
178         return JRStyleResolver.getForecolor(this);
179     }
180     
181     /**
182      *
183      */

184     public Color JavaDoc getOwnForecolor()
185     {
186         return this.forecolor;
187     }
188     
189     /**
190      *
191      */

192     protected void setForecolor(Color JavaDoc forecolor)
193     {
194         this.forecolor = forecolor;
195     }
196     
197     /**
198      *
199      */

200     public Color JavaDoc getBackcolor()
201     {
202         return JRStyleResolver.getBackcolor(this);
203     }
204     
205     /**
206      *
207      */

208     public Color JavaDoc getOwnBackcolor()
209     {
210         return this.backcolor;
211     }
212     
213     /**
214      *
215      */

216     protected void setBackcolor(Color JavaDoc backcolor)
217     {
218         this.backcolor = backcolor;
219     }
220     
221     /**
222      *
223      */

224     public String JavaDoc getId()
225     {
226         return id;
227     }
228
229     
230     public String JavaDoc getKey()
231     {
232         return key;
233     }
234
235     
236     public void setKey(String JavaDoc key)
237     {
238         this.key = key;
239     }
240 }
241
Popular Tags