001: /*
002: * ============================================================================
003: * GNU Lesser General Public License
004: * ============================================================================
005: *
006: * JasperReports - Free Java report-generating library.
007: * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
022: *
023: * JasperSoft Corporation
024: * 303 Second Street, Suite 450 North
025: * San Francisco, CA 94107
026: * http://www.jaspersoft.com
027: */
028: package net.sf.jasperreports.engine.fill;
029:
030: import java.awt.Color;
031: import java.io.Serializable;
032: import java.util.Random;
033:
034: import net.sf.jasperreports.engine.JRConstants;
035: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
036: import net.sf.jasperreports.engine.JRElement;
037: import net.sf.jasperreports.engine.JRStyle;
038: import net.sf.jasperreports.engine.JRStyleContainer;
039: import net.sf.jasperreports.engine.util.JRStyleResolver;
040:
041: /**
042: * @author Teodor Danciu (teodord@users.sourceforge.net)
043: * @version $Id: JRTemplateElement.java 1759 2007-06-20 16:47:34Z lucianc $
044: */
045: public abstract class JRTemplateElement implements JRStyleContainer,
046: Serializable {
047:
048: /**
049: *
050: */
051: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
052:
053: private static final Random randomId = new Random();
054:
055: /**
056: *
057: */
058: private String key;
059: private Byte mode = null;
060: private Color forecolor = null;
061: private Color backcolor = null;
062:
063: protected JRDefaultStyleProvider defaultStyleProvider;
064: protected JRStyle parentStyle = null;
065:
066: private final String id;
067:
068: /**
069: *
070: */
071: protected JRTemplateElement(
072: JRDefaultStyleProvider defaultStyleProvider) {
073: this .defaultStyleProvider = defaultStyleProvider;
074: id = createId();
075: }
076:
077: /**
078: *
079: */
080: protected JRTemplateElement(JRElement element) {
081: setElement(element);
082: id = createId();
083: }
084:
085: protected JRTemplateElement(String id) {
086: this .id = id;
087: }
088:
089: private String createId() {
090: return System.identityHashCode(this ) + "_"
091: + System.currentTimeMillis() + "_" + randomId.nextInt();
092: }
093:
094: /**
095: *
096: */
097: protected void setElement(JRElement element) {
098: parentStyle = element.getStyle();
099:
100: setKey(element.getKey());
101:
102: mode = element.getOwnMode();
103: forecolor = element.getOwnForecolor();
104: backcolor = element.getOwnBackcolor();
105: }
106:
107: /**
108: *
109: */
110: public JRDefaultStyleProvider getDefaultStyleProvider() {
111: return defaultStyleProvider;
112: }
113:
114: /**
115: *
116: */
117: public JRStyle getStyle() {
118: return parentStyle;
119: }
120:
121: /**
122: *
123: */
124: protected JRStyle getBaseStyle() {
125: if (parentStyle != null)
126: return parentStyle;
127: if (defaultStyleProvider != null)
128: return defaultStyleProvider.getDefaultStyle();
129: return null;
130: }
131:
132: /**
133: *
134: */
135: public byte getMode() {
136: return JRStyleResolver.getMode(this , JRElement.MODE_OPAQUE);
137: }
138:
139: /**
140: *
141: */
142: public Byte getOwnMode() {
143: return mode;
144: }
145:
146: /**
147: *
148: */
149: protected void setMode(byte mode) {
150: this .mode = new Byte(mode);
151: }
152:
153: /**
154: *
155: */
156: protected void setMode(Byte mode) {
157: this .mode = mode;
158: }
159:
160: /**
161: *
162: */
163: public Color getForecolor() {
164: return JRStyleResolver.getForecolor(this );
165: }
166:
167: /**
168: *
169: */
170: public Color getOwnForecolor() {
171: return this .forecolor;
172: }
173:
174: /**
175: *
176: */
177: protected void setForecolor(Color forecolor) {
178: this .forecolor = forecolor;
179: }
180:
181: /**
182: *
183: */
184: public Color getBackcolor() {
185: return JRStyleResolver.getBackcolor(this );
186: }
187:
188: /**
189: *
190: */
191: public Color getOwnBackcolor() {
192: return this .backcolor;
193: }
194:
195: /**
196: *
197: */
198: protected void setBackcolor(Color backcolor) {
199: this .backcolor = backcolor;
200: }
201:
202: /**
203: *
204: */
205: public String getId() {
206: return id;
207: }
208:
209: public String getKey() {
210: return key;
211: }
212:
213: public void setKey(String key) {
214: this .key = key;
215: }
216:
217: /**
218: * Returns null as external style references are not allowed for print objects.
219: */
220: public String getStyleNameReference() {
221: return null;
222: }
223: }
|