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.io.IOException;
031:
032: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
033: import net.sf.jasperreports.engine.JRChild;
034: import net.sf.jasperreports.engine.JRException;
035: import net.sf.jasperreports.engine.JRExpressionCollector;
036: import net.sf.jasperreports.engine.JRPrintElement;
037: import net.sf.jasperreports.engine.JRPrintText;
038: import net.sf.jasperreports.engine.JRStaticText;
039: import net.sf.jasperreports.engine.JRStyle;
040: import net.sf.jasperreports.engine.xml.JRXmlWriter;
041:
042: /**
043: * @author Teodor Danciu (teodord@users.sourceforge.net)
044: * @version $Id: JRFillStaticText.java 1357 2006-08-10 09:36:24Z lucianc $
045: */
046: public class JRFillStaticText extends JRFillTextElement implements
047: JRStaticText {
048:
049: /**
050: *
051: */
052: protected JRFillStaticText(JRBaseFiller filler,
053: JRStaticText staticText, JRFillObjectFactory factory) {
054: super (filler, staticText, factory);
055:
056: //setRawText(JRStringUtil.treatNewLineChars(staticText.getText()));
057: String text = staticText.getText();
058: if (text == null) {
059: text = "";
060: }
061: setRawText(text);
062: }
063:
064: protected JRFillStaticText(JRFillStaticText staticText,
065: JRFillCloneFactory factory) {
066: super (staticText, factory);
067:
068: // setRawText(JRStringUtil.treatNewLineChars(staticText.getText()));
069: String text = staticText.getText();
070: if (text == null) {
071: text = "";
072: }
073: setRawText(text);
074: }
075:
076: /**
077: *
078: */
079: public void setText(String text) {
080: }
081:
082: /**
083: *
084: */
085: protected JRTemplateText getJRTemplateText() {
086: JRStyle style = getStyle();
087: JRTemplateText template = (JRTemplateText) getTemplate(style);
088: if (template == null) {
089: template = new JRTemplateText(filler.getJasperPrint()
090: .getDefaultStyleProvider(), this );
091: registerTemplate(style, template);
092: }
093: return template;
094: }
095:
096: /**
097: *
098: */
099: protected void evaluate(byte evaluation) throws JRException {
100: reset();
101:
102: evaluatePrintWhenExpression(evaluation);
103:
104: setTextStart(0);
105: setTextEnd(0);
106:
107: setValueRepeating(true);
108: }
109:
110: /**
111: *
112: */
113: protected boolean prepare(int availableStretchHeight,
114: boolean isOverflow) throws JRException {
115: boolean willOverflow = false;
116:
117: super .prepare(availableStretchHeight, isOverflow);
118:
119: if (!isToPrint()) {
120: return willOverflow;
121: }
122:
123: boolean isToPrint = true;
124: boolean isReprinted = false;
125:
126: if (isOverflow && isAlreadyPrinted()
127: && !isPrintWhenDetailOverflows()) {
128: isToPrint = false;
129: }
130:
131: if (isToPrint && isPrintWhenExpressionNull()
132: && !isPrintRepeatedValues()) {
133: if ((!isPrintInFirstWholeBand() || !getBand()
134: .isFirstWholeOnPageColumn())
135: && (getPrintWhenGroupChanges() == null || !getBand()
136: .isNewGroup(getPrintWhenGroupChanges()))
137: && (!isOverflow || !isPrintWhenDetailOverflows())) {
138: isToPrint = false;
139: }
140: }
141:
142: if (isToPrint
143: && availableStretchHeight < getRelativeY() - getY()
144: - getBandBottomY()) {
145: isToPrint = false;
146: willOverflow = true;
147: }
148:
149: if (isToPrint
150: && isOverflow
151: &&
152: //(isAlreadyPrinted() || !isPrintRepeatedValues())
153: (isPrintWhenDetailOverflows() && (isAlreadyPrinted() || (!isAlreadyPrinted() && !isPrintRepeatedValues())))) {
154: isReprinted = true;
155: }
156:
157: setTextStart(0);
158: setTextEnd(0);
159:
160: if (isToPrint) {
161: chopTextElement(0);
162: }
163:
164: setToPrint(isToPrint);
165: setReprinted(isReprinted);
166:
167: return willOverflow;
168: }
169:
170: /**
171: *
172: */
173: protected JRPrintElement fill() {
174: JRPrintText text = null;
175:
176: text = new JRTemplatePrintText(getJRTemplateText());
177: text.setX(getX());
178: text.setY(getRelativeY());
179: text.setWidth(getWidth());
180: if (getRotation() == ROTATION_NONE) {
181: text.setHeight(getStretchHeight());
182: } else {
183: text.setHeight(getHeight());
184: }
185: text.setRunDirection(getRunDirection());
186: text.setLineSpacingFactor(getLineSpacingFactor());
187: text.setLeadingOffset(getLeadingOffset());
188: text.setTextHeight(getTextHeight());
189:
190: //text.setText(getRawText());
191: text.setText(textChopper.chop(this , getTextStart(),
192: getTextEnd()));
193:
194: return text;
195: }
196:
197: /**
198: *
199: */
200: public JRChild getCopy(JRAbstractObjectFactory factory) {
201: return factory.getStaticText(this );
202: }
203:
204: /**
205: *
206: */
207: public void collectExpressions(JRExpressionCollector collector) {
208: collector.collect(this );
209: }
210:
211: /**
212: *
213: */
214: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
215: xmlWriter.writeStaticText(this );
216: }
217:
218: protected void resolveElement(JRPrintElement element,
219: byte evaluation) {
220: // nothing
221: }
222:
223: public JRCloneable createClone(JRFillCloneFactory factory) {
224: return new JRFillStaticText(this, factory);
225: }
226:
227: }
|