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.design;
029:
030: import java.io.IOException;
031: import java.io.ObjectInputStream;
032: import java.util.ArrayList;
033: import java.util.Iterator;
034: import java.util.List;
035:
036: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
037: import net.sf.jasperreports.engine.JRAnchor;
038: import net.sf.jasperreports.engine.JRChild;
039: import net.sf.jasperreports.engine.JRConstants;
040: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
041: import net.sf.jasperreports.engine.JRExpression;
042: import net.sf.jasperreports.engine.JRExpressionCollector;
043: import net.sf.jasperreports.engine.JRGroup;
044: import net.sf.jasperreports.engine.JRHyperlink;
045: import net.sf.jasperreports.engine.JRHyperlinkHelper;
046: import net.sf.jasperreports.engine.JRHyperlinkParameter;
047: import net.sf.jasperreports.engine.JRTextField;
048: import net.sf.jasperreports.engine.util.JRStyleResolver;
049: import net.sf.jasperreports.engine.xml.JRXmlWriter;
050:
051: //import java.text.Format;
052:
053: /**
054: * @author Teodor Danciu (teodord@users.sourceforge.net)
055: * @version $Id: JRDesignTextField.java 1364 2006-08-31 15:13:20Z lucianc $
056: */
057: public class JRDesignTextField extends JRDesignTextElement implements
058: JRTextField {
059:
060: /**
061: *
062: */
063: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
064:
065: /**
066: *
067: */
068: protected boolean isStretchWithOverflow = false;
069: protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW;
070: protected String pattern = null;
071: protected Boolean isBlankWhenNull = null;
072: protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
073: protected String linkType;
074: protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
075: private List hyperlinkParameters;
076:
077: /**
078: *
079: */
080: protected JRGroup evaluationGroup = null;
081: protected JRExpression expression = null;
082: protected JRExpression anchorNameExpression = null;
083: protected JRExpression hyperlinkReferenceExpression = null;
084: protected JRExpression hyperlinkAnchorExpression = null;
085: protected JRExpression hyperlinkPageExpression = null;
086: private JRExpression hyperlinkTooltipExpression;
087:
088: /**
089: * The bookmark level for the anchor associated with this field.
090: * @see JRAnchor#getBookmarkLevel()
091: */
092: protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
093:
094: /**
095: *
096: */
097: public JRDesignTextField() {
098: super (null);
099:
100: hyperlinkParameters = new ArrayList();
101: }
102:
103: /**
104: *
105: */
106: public JRDesignTextField(JRDefaultStyleProvider defaultStyleProvider) {
107: super (defaultStyleProvider);
108:
109: hyperlinkParameters = new ArrayList();
110: }
111:
112: /**
113: *
114: */
115: public boolean isStretchWithOverflow() {
116: return this .isStretchWithOverflow;
117: }
118:
119: /**
120: *
121: */
122: public byte getEvaluationTime() {
123: return this .evaluationTime;
124: }
125:
126: /**
127: *
128: */
129: public String getPattern() {
130: return JRStyleResolver.getPattern(this );
131: }
132:
133: public String getOwnPattern() {
134: return this .pattern;
135: }
136:
137: /**
138: *
139: */
140: public boolean isBlankWhenNull() {
141: return JRStyleResolver.isBlankWhenNull(this );
142: }
143:
144: /**
145: *
146: */
147: public Boolean isOwnBlankWhenNull() {
148: return isBlankWhenNull;
149: }
150:
151: /**
152: *
153: */
154: public byte getHyperlinkType() {
155: return JRHyperlinkHelper.getHyperlinkType(this );
156: }
157:
158: /**
159: *
160: */
161: public byte getHyperlinkTarget() {
162: return this .hyperlinkTarget;
163: }
164:
165: /**
166: *
167: */
168: public JRGroup getEvaluationGroup() {
169: return this .evaluationGroup;
170: }
171:
172: /**
173: *
174: */
175: public JRExpression getExpression() {
176: return this .expression;
177: }
178:
179: /**
180: *
181: */
182: public JRExpression getAnchorNameExpression() {
183: return this .anchorNameExpression;
184: }
185:
186: /**
187: *
188: */
189: public JRExpression getHyperlinkReferenceExpression() {
190: return this .hyperlinkReferenceExpression;
191: }
192:
193: /**
194: *
195: */
196: public JRExpression getHyperlinkAnchorExpression() {
197: return this .hyperlinkAnchorExpression;
198: }
199:
200: /**
201: *
202: */
203: public JRExpression getHyperlinkPageExpression() {
204: return this .hyperlinkPageExpression;
205: }
206:
207: /**
208: *
209: */
210: public void setStretchWithOverflow(boolean isStretch) {
211: this .isStretchWithOverflow = isStretch;
212: }
213:
214: /**
215: *
216: */
217: public void setEvaluationTime(byte evaluationTime) {
218: this .evaluationTime = evaluationTime;
219: }
220:
221: /**
222: *
223: */
224: public void setPattern(String pattern) {
225: this .pattern = pattern;
226: }
227:
228: /**
229: *
230: */
231: public void setBlankWhenNull(boolean isBlank) {
232: this .isBlankWhenNull = isBlank ? Boolean.TRUE : Boolean.FALSE;
233: }
234:
235: /**
236: *
237: */
238: public void setBlankWhenNull(Boolean isBlank) {
239: this .isBlankWhenNull = isBlank;
240: }
241:
242: /**
243: * Sets the link type as a built-in hyperlink type.
244: *
245: * @param hyperlinkType the built-in hyperlink type
246: * @see #getLinkType()
247: */
248: public void setHyperlinkType(byte hyperlinkType) {
249: setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
250: }
251:
252: /**
253: *
254: */
255: public void setHyperlinkTarget(byte hyperlinkTarget) {
256: this .hyperlinkTarget = hyperlinkTarget;
257: }
258:
259: /**
260: *
261: */
262: public void setEvaluationGroup(JRGroup evaluationGroup) {
263: this .evaluationGroup = evaluationGroup;
264: }
265:
266: /**
267: *
268: */
269: public void setExpression(JRExpression expression) {
270: this .expression = expression;
271: }
272:
273: /**
274: *
275: */
276: public void setAnchorNameExpression(
277: JRExpression anchorNameExpression) {
278: this .anchorNameExpression = anchorNameExpression;
279: }
280:
281: /**
282: *
283: */
284: public void setHyperlinkReferenceExpression(
285: JRExpression hyperlinkReferenceExpression) {
286: this .hyperlinkReferenceExpression = hyperlinkReferenceExpression;
287: }
288:
289: /**
290: *
291: */
292: public void setHyperlinkAnchorExpression(
293: JRExpression hyperlinkAnchorExpression) {
294: this .hyperlinkAnchorExpression = hyperlinkAnchorExpression;
295: }
296:
297: /**
298: *
299: */
300: public void setHyperlinkPageExpression(
301: JRExpression hyperlinkPageExpression) {
302: this .hyperlinkPageExpression = hyperlinkPageExpression;
303: }
304:
305: /**
306: *
307: */
308: public JRChild getCopy(JRAbstractObjectFactory factory) {
309: return factory.getTextField(this );
310: }
311:
312: /**
313: *
314: */
315: public void collectExpressions(JRExpressionCollector collector) {
316: collector.collect(this );
317: }
318:
319: /**
320: *
321: */
322: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
323: xmlWriter.writeTextField(this );
324: }
325:
326: public int getBookmarkLevel() {
327: return bookmarkLevel;
328: }
329:
330: /**
331: * Sets the boomark level for the anchor associated with this field.
332: *
333: * @param bookmarkLevel the bookmark level (starting from 1)
334: * or {@link JRAnchor#NO_BOOKMARK NO_BOOKMARK} if no bookmark should be created
335: */
336: public void setBookmarkLevel(int bookmarkLevel) {
337: this .bookmarkLevel = bookmarkLevel;
338: }
339:
340: public String getLinkType() {
341: return linkType;
342: }
343:
344: /**
345: * Sets the hyperlink type.
346: * <p>
347: * The type can be one of the built-in types
348: * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
349: * or can be an arbitrary type.
350: * </p>
351: * @param type the hyperlink type
352: */
353: public void setLinkType(String type) {
354: this .linkType = type;
355: }
356:
357: public JRHyperlinkParameter[] getHyperlinkParameters() {
358: JRHyperlinkParameter[] parameters;
359: if (hyperlinkParameters.isEmpty()) {
360: parameters = null;
361: } else {
362: parameters = new JRHyperlinkParameter[hyperlinkParameters
363: .size()];
364: hyperlinkParameters.toArray(parameters);
365: }
366: return parameters;
367: }
368:
369: /**
370: * Returns the list of custom hyperlink parameters.
371: *
372: * @return the list of custom hyperlink parameters
373: */
374: public List getHyperlinkParametersList() {
375: return hyperlinkParameters;
376: }
377:
378: /**
379: * Adds a custom hyperlink parameter.
380: *
381: * @param parameter the parameter to add
382: */
383: public void addHyperlinkParameter(JRHyperlinkParameter parameter) {
384: hyperlinkParameters.add(parameter);
385: }
386:
387: /**
388: * Removes a custom hyperlink parameter.
389: *
390: * @param parameter the parameter to remove
391: */
392: public void removeHyperlinkParameter(JRHyperlinkParameter parameter) {
393: hyperlinkParameters.remove(parameter);
394: }
395:
396: /**
397: * Removes a custom hyperlink parameter.
398: * <p>
399: * If multiple parameters having the specified name exist, all of them
400: * will be removed
401: * </p>
402: *
403: * @param parameterName the parameter name
404: */
405: public void removeHyperlinkParameter(String parameterName) {
406: for (Iterator it = hyperlinkParameters.iterator(); it.hasNext();) {
407: JRHyperlinkParameter parameter = (JRHyperlinkParameter) it
408: .next();
409: if (parameter.getName() != null
410: && parameter.getName().equals(parameterName)) {
411: it.remove();
412: }
413: }
414: }
415:
416: private void readObject(ObjectInputStream in) throws IOException,
417: ClassNotFoundException {
418: in.defaultReadObject();
419: normalizeLinkType();
420: }
421:
422: protected void normalizeLinkType() {
423: if (linkType == null) {
424: linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
425: }
426: hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
427: }
428:
429: public JRExpression getHyperlinkTooltipExpression() {
430: return hyperlinkTooltipExpression;
431: }
432:
433: /**
434: * Sets the expression which will be used to generate the hyperlink tooltip.
435: *
436: * @param hyperlinkTooltipExpression the expression which will be used to generate the hyperlink tooltip
437: * @see #getHyperlinkTooltipExpression()
438: */
439: public void setHyperlinkTooltipExpression(
440: JRExpression hyperlinkTooltipExpression) {
441: this.hyperlinkTooltipExpression = hyperlinkTooltipExpression;
442: }
443:
444: }
|