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.base;
029:
030: import java.awt.Color;
031: import java.io.Serializable;
032:
033: import net.sf.jasperreports.engine.JRConstants;
034: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
035: import net.sf.jasperreports.engine.JRElement;
036: import net.sf.jasperreports.engine.JRElementGroup;
037: import net.sf.jasperreports.engine.JRExpression;
038: import net.sf.jasperreports.engine.JRGroup;
039: import net.sf.jasperreports.engine.JRStyle;
040: import net.sf.jasperreports.engine.util.JRStyleResolver;
041:
042: /**
043: * This class provides a skeleton implementation for a report element. It mostly provides internal variables, representing
044: * the most common element properties, and their getter/setter methods. It also has a constructor for initializing
045: * these properties.
046: * @author Teodor Danciu (teodord@users.sourceforge.net)
047: * @version $Id: JRBaseElement.java 1759 2007-06-20 16:47:34Z lucianc $
048: */
049: public abstract class JRBaseElement implements JRElement, Serializable {
050:
051: /**
052: *
053: */
054: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
055:
056: /**
057: *
058: */
059: protected String key = null;
060: protected byte positionType;
061: protected byte stretchType;
062: protected boolean isPrintRepeatedValues = true;
063: protected Byte mode;
064: protected int x = 0;
065: protected int y = 0;
066: protected int width = 0;
067: protected int height = 0;
068: protected boolean isRemoveLineWhenBlank = false;
069: protected boolean isPrintInFirstWholeBand = false;
070: protected boolean isPrintWhenDetailOverflows = false;
071: protected Color forecolor = null;
072: protected Color backcolor = null;
073:
074: /**
075: *
076: */
077: protected JRExpression printWhenExpression = null;
078: protected JRGroup printWhenGroupChanges = null;
079: protected JRElementGroup elementGroup = null;
080:
081: protected JRDefaultStyleProvider defaultStyleProvider;
082: protected JRStyle parentStyle;
083: protected String parentStyleNameReference;
084:
085: /**
086: *
087: */
088: protected JRBaseElement(JRDefaultStyleProvider defaultStyleProvider) {
089: this .defaultStyleProvider = defaultStyleProvider;
090: }
091:
092: /**
093: * Initializes basic properties of the element.
094: * @param element an element whose properties are copied to this element. Usually it is a
095: * {@link net.sf.jasperreports.engine.design.JRDesignElement} that must be transformed into an
096: * <tt>JRBaseElement</tt> at compile time.
097: * @param factory a factory used in the compile process
098: */
099: protected JRBaseElement(JRElement element,
100: JRBaseObjectFactory factory) {
101: factory.put(element, this );
102:
103: defaultStyleProvider = factory.getDefaultStyleProvider();
104:
105: parentStyle = factory.getStyle(element.getStyle());
106: parentStyleNameReference = element.getStyleNameReference();
107:
108: key = element.getKey();
109: positionType = element.getPositionType();
110: stretchType = element.getStretchType();
111: isPrintRepeatedValues = element.isPrintRepeatedValues();
112: mode = element.getOwnMode();
113: x = element.getX();
114: y = element.getY();
115: width = element.getWidth();
116: height = element.getHeight();
117: isRemoveLineWhenBlank = element.isRemoveLineWhenBlank();
118: isPrintInFirstWholeBand = element.isPrintInFirstWholeBand();
119: isPrintWhenDetailOverflows = element
120: .isPrintWhenDetailOverflows();
121: forecolor = element.getOwnForecolor();
122: backcolor = element.getOwnBackcolor();
123:
124: printWhenExpression = factory.getExpression(element
125: .getPrintWhenExpression());
126: printWhenGroupChanges = factory.getGroup(element
127: .getPrintWhenGroupChanges());
128: elementGroup = factory.getElementGroup(element
129: .getElementGroup());
130: }
131:
132: /**
133: *
134: */
135: public JRDefaultStyleProvider getDefaultStyleProvider() {
136: return defaultStyleProvider;
137: }
138:
139: /**
140: *
141: */
142: protected JRStyle getBaseStyle() {
143: if (parentStyle != null)
144: return parentStyle;
145: if (defaultStyleProvider != null)
146: return defaultStyleProvider.getDefaultStyle();
147: return null;
148: }
149:
150: /**
151: *
152: */
153: public String getKey() {
154: return this .key;
155: }
156:
157: /**
158: *
159: */
160: public byte getPositionType() {
161: return positionType;
162: }
163:
164: /**
165: *
166: */
167: public void setPositionType(byte positionType) {
168: this .positionType = positionType;
169: }
170:
171: /**
172: *
173: */
174: public byte getStretchType() {
175: return stretchType;
176: }
177:
178: /**
179: *
180: */
181: public void setStretchType(byte stretchType) {
182: this .stretchType = stretchType;
183: }
184:
185: /**
186: *
187: */
188: public boolean isPrintRepeatedValues() {
189: return this .isPrintRepeatedValues;
190: }
191:
192: /**
193: *
194: */
195: public void setPrintRepeatedValues(boolean isPrintRepeatedValues) {
196: this .isPrintRepeatedValues = isPrintRepeatedValues;
197: }
198:
199: /**
200: *
201: */
202: public byte getMode() {
203: return JRStyleResolver.getMode(this , MODE_OPAQUE);
204: }
205:
206: /**
207: *
208: */
209: public Byte getOwnMode() {
210: return mode;
211: }
212:
213: /**
214: *
215: */
216: public void setMode(byte mode) {
217: this .mode = new Byte(mode);
218: }
219:
220: /**
221: *
222: */
223: public void setMode(Byte mode) {
224: this .mode = mode;
225: }
226:
227: /**
228: *
229: */
230: public int getX() {
231: return this .x;
232: }
233:
234: /**
235: *
236: */
237: public void setX(int x) {
238: this .x = x;
239: }
240:
241: /**
242: *
243: */
244: public int getY() {
245: return this .y;
246: }
247:
248: /**
249: *
250: */
251: public int getWidth() {
252: return this .width;
253: }
254:
255: /**
256: *
257: */
258: public void setWidth(int width) {
259: this .width = width;
260: }
261:
262: /**
263: *
264: */
265: public int getHeight() {
266: return this .height;
267: }
268:
269: /**
270: *
271: */
272: public boolean isRemoveLineWhenBlank() {
273: return this .isRemoveLineWhenBlank;
274: }
275:
276: /**
277: *
278: */
279: public void setRemoveLineWhenBlank(boolean isRemoveLine) {
280: this .isRemoveLineWhenBlank = isRemoveLine;
281: }
282:
283: /**
284: *
285: */
286: public boolean isPrintInFirstWholeBand() {
287: return this .isPrintInFirstWholeBand;
288: }
289:
290: /**
291: *
292: */
293: public void setPrintInFirstWholeBand(boolean isPrint) {
294: this .isPrintInFirstWholeBand = isPrint;
295: }
296:
297: /**
298: *
299: */
300: public boolean isPrintWhenDetailOverflows() {
301: return this .isPrintWhenDetailOverflows;
302: }
303:
304: /**
305: *
306: */
307: public void setPrintWhenDetailOverflows(boolean isPrint) {
308: this .isPrintWhenDetailOverflows = isPrint;
309: }
310:
311: /**
312: *
313: */
314: public Color getForecolor() {
315: return JRStyleResolver.getForecolor(this );
316: }
317:
318: /**
319: *
320: */
321: public Color getOwnForecolor() {
322: return forecolor;
323: }
324:
325: /**
326: *
327: */
328: public void setForecolor(Color forecolor) {
329: this .forecolor = forecolor;
330: }
331:
332: /**
333: *
334: */
335: public Color getBackcolor() {
336: return JRStyleResolver.getBackcolor(this );
337: }
338:
339: /**
340: *
341: */
342: public Color getOwnBackcolor() {
343: return backcolor;
344: }
345:
346: /**
347: *
348: */
349: public void setBackcolor(Color backcolor) {
350: this .backcolor = backcolor;
351: }
352:
353: /**
354: *
355: */
356: public JRExpression getPrintWhenExpression() {
357: return this .printWhenExpression;
358: }
359:
360: /**
361: *
362: */
363: public JRGroup getPrintWhenGroupChanges() {
364: return this .printWhenGroupChanges;
365: }
366:
367: /**
368: *
369: */
370: public JRElementGroup getElementGroup() {
371: return this .elementGroup;
372: }
373:
374: public JRStyle getStyle() {
375: return parentStyle;
376: }
377:
378: public String getStyleNameReference() {
379: return parentStyleNameReference;
380: }
381: }
|