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.io.IOException;
031: import java.io.ObjectInputStream;
032:
033: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
034: import net.sf.jasperreports.engine.JRAnchor;
035: import net.sf.jasperreports.engine.JRChild;
036: import net.sf.jasperreports.engine.JRConstants;
037: import net.sf.jasperreports.engine.JRExpression;
038: import net.sf.jasperreports.engine.JRExpressionCollector;
039: import net.sf.jasperreports.engine.JRGroup;
040: import net.sf.jasperreports.engine.JRHyperlink;
041: import net.sf.jasperreports.engine.JRHyperlinkHelper;
042: import net.sf.jasperreports.engine.JRHyperlinkParameter;
043: import net.sf.jasperreports.engine.JRTextField;
044: import net.sf.jasperreports.engine.util.JRStyleResolver;
045: import net.sf.jasperreports.engine.xml.JRXmlWriter;
046:
047: /**
048: * This class is used for representing a text field.
049: *
050: * @author Teodor Danciu (teodord@users.sourceforge.net)
051: * @version $Id: JRBaseTextField.java 1364 2006-08-31 15:13:20Z lucianc $
052: */
053: public class JRBaseTextField extends JRBaseTextElement implements
054: JRTextField {
055:
056: /**
057: *
058: */
059: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
060:
061: /**
062: *
063: */
064: protected boolean isStretchWithOverflow = false;
065: protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW;
066: protected String pattern;
067: protected Boolean isBlankWhenNull = null;
068: protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
069: protected String linkType;
070: protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
071: private JRHyperlinkParameter[] hyperlinkParameters;
072:
073: /**
074: *
075: */
076: protected JRGroup evaluationGroup = null;
077: protected JRExpression expression = null;
078: protected JRExpression anchorNameExpression = null;
079: protected JRExpression hyperlinkReferenceExpression = null;
080: protected JRExpression hyperlinkAnchorExpression = null;
081: protected JRExpression hyperlinkPageExpression = null;
082: private JRExpression hyperlinkTooltipExpression;
083:
084: /**
085: * The bookmark level for the anchor associated with this field.
086: * @see JRAnchor#getBookmarkLevel()
087: */
088: protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
089:
090: /**
091: * Initializes the text field properties.
092: */
093: protected JRBaseTextField(JRTextField textField,
094: JRBaseObjectFactory factory) {
095: super (textField, factory);
096:
097: isStretchWithOverflow = textField.isStretchWithOverflow();
098: evaluationTime = textField.getEvaluationTime();
099: pattern = textField.getOwnPattern();
100: isBlankWhenNull = textField.isOwnBlankWhenNull();
101: linkType = textField.getLinkType();
102: hyperlinkTarget = textField.getHyperlinkTarget();
103: hyperlinkParameters = JRBaseHyperlink.copyHyperlinkParameters(
104: textField, factory);
105:
106: evaluationGroup = factory.getGroup(textField
107: .getEvaluationGroup());
108: expression = factory.getExpression(textField.getExpression());
109: anchorNameExpression = factory.getExpression(textField
110: .getAnchorNameExpression());
111: hyperlinkReferenceExpression = factory.getExpression(textField
112: .getHyperlinkReferenceExpression());
113: hyperlinkAnchorExpression = factory.getExpression(textField
114: .getHyperlinkAnchorExpression());
115: hyperlinkPageExpression = factory.getExpression(textField
116: .getHyperlinkPageExpression());
117: hyperlinkTooltipExpression = factory.getExpression(textField
118: .getHyperlinkTooltipExpression());
119: bookmarkLevel = textField.getBookmarkLevel();
120: }
121:
122: /**
123: *
124: */
125: public boolean isStretchWithOverflow() {
126: return this .isStretchWithOverflow;
127: }
128:
129: /**
130: *
131: */
132: public void setStretchWithOverflow(boolean isStretchWithOverflow) {
133: this .isStretchWithOverflow = isStretchWithOverflow;
134: }
135:
136: /**
137: *
138: */
139: public byte getEvaluationTime() {
140: return this .evaluationTime;
141: }
142:
143: /**
144: *
145: */
146: public String getPattern() {
147: return JRStyleResolver.getPattern(this );
148: }
149:
150: public String getOwnPattern() {
151: return this .pattern;
152: }
153:
154: /**
155: *
156: */
157: public void setPattern(String pattern) {
158: this .pattern = pattern;
159: }
160:
161: /**
162: *
163: */
164: public boolean isBlankWhenNull() {
165: return JRStyleResolver.isBlankWhenNull(this );
166: }
167:
168: /**
169: *
170: */
171: public Boolean isOwnBlankWhenNull() {
172: return isBlankWhenNull;
173: }
174:
175: /**
176: *
177: */
178: public void setBlankWhenNull(Boolean isBlank) {
179: this .isBlankWhenNull = isBlank;
180: }
181:
182: /**
183: *
184: */
185: public void setBlankWhenNull(boolean isBlank) {
186: this .isBlankWhenNull = isBlank ? Boolean.TRUE : Boolean.FALSE;
187: }
188:
189: /**
190: *
191: */
192: public byte getHyperlinkType() {
193: return JRHyperlinkHelper.getHyperlinkType(this );
194: }
195:
196: /**
197: *
198: */
199: public byte getHyperlinkTarget() {
200: return this .hyperlinkTarget;
201: }
202:
203: /**
204: *
205: */
206: public JRGroup getEvaluationGroup() {
207: return this .evaluationGroup;
208: }
209:
210: /**
211: *
212: */
213: public JRExpression getExpression() {
214: return this .expression;
215: }
216:
217: /**
218: *
219: */
220: public JRExpression getAnchorNameExpression() {
221: return this .anchorNameExpression;
222: }
223:
224: /**
225: *
226: */
227: public JRExpression getHyperlinkReferenceExpression() {
228: return this .hyperlinkReferenceExpression;
229: }
230:
231: /**
232: *
233: */
234: public JRExpression getHyperlinkAnchorExpression() {
235: return this .hyperlinkAnchorExpression;
236: }
237:
238: /**
239: *
240: */
241: public JRExpression getHyperlinkPageExpression() {
242: return this .hyperlinkPageExpression;
243: }
244:
245: /**
246: *
247: */
248: public JRChild getCopy(JRAbstractObjectFactory factory) {
249: return factory.getTextField(this );
250: }
251:
252: /**
253: *
254: */
255: public void collectExpressions(JRExpressionCollector collector) {
256: collector.collect(this );
257: }
258:
259: /**
260: *
261: */
262: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
263: xmlWriter.writeTextField(this );
264: }
265:
266: public int getBookmarkLevel() {
267: return bookmarkLevel;
268: }
269:
270: public String getLinkType() {
271: return linkType;
272: }
273:
274: public JRHyperlinkParameter[] getHyperlinkParameters() {
275: return hyperlinkParameters;
276: }
277:
278: private void readObject(ObjectInputStream in) throws IOException,
279: ClassNotFoundException {
280: in.defaultReadObject();
281: normalizeLinkType();
282: }
283:
284: protected void normalizeLinkType() {
285: if (linkType == null) {
286: linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
287: }
288: hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
289: }
290:
291: public JRExpression getHyperlinkTooltipExpression() {
292: return hyperlinkTooltipExpression;
293: }
294:
295: }
|