001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * TextFieldReportElement.java
028: *
029: * Created on 24 maggio 2003, 10.22
030: *
031: */
032:
033: package it.businesslogic.ireport;
034:
035: import it.businesslogic.ireport.gui.MainFrame;
036:
037: /**
038: *
039: * @author Administrator
040: */
041: public class TextFieldReportElement extends
042: it.businesslogic.ireport.TextReportElement implements
043: HyperLinkableReportElement {
044:
045: public final static String PATTERN = "PATTERN";
046: public final static String DEFAULT_PATTERN = "";
047:
048: private String classExpression;
049:
050: private String group;
051:
052: private String evaluationTime;
053:
054: private boolean blankWhenNull;
055:
056: private boolean stretchWithOverflow;
057:
058: //private String pattern;
059:
060: private String anchorNameExpression = "";
061:
062: private String hyperlinkAnchorExpression = "";
063:
064: private String hyperlinkPageExpression = "";
065:
066: private String hyperlinkReferenceExpression = "";
067:
068: private String hyperlinkType = "None";
069:
070: private String tooltip = "";
071:
072: private int bookmarkLevel = 0;
073:
074: private java.util.List linkParameters = new java.util.ArrayList();
075:
076: static private java.util.List acceptedTextfieldClasses = null;
077: static {
078: acceptedTextfieldClasses = new java.util.ArrayList();
079:
080: acceptedTextfieldClasses.add("java.lang.Boolean");
081: acceptedTextfieldClasses.add("java.lang.Byte");
082: acceptedTextfieldClasses.add("java.util.Date");
083: acceptedTextfieldClasses.add("java.sql.Timestamp");
084: acceptedTextfieldClasses.add("java.sql.Time");
085: acceptedTextfieldClasses.add("java.lang.Double");
086: acceptedTextfieldClasses.add("java.lang.Float");
087: acceptedTextfieldClasses.add("java.lang.Integer");
088: acceptedTextfieldClasses.add("java.lang.Long");
089: acceptedTextfieldClasses.add("java.lang.Short");
090: acceptedTextfieldClasses.add("java.math.BigDecimal");
091: acceptedTextfieldClasses.add("java.lang.Number");
092: acceptedTextfieldClasses.add("java.lang.String");
093: }
094:
095: /** Creates a new instance of TextFieldReportElement */
096: public TextFieldReportElement(int x, int y, int width, int height) {
097: super (x, y, width, height);
098: this .setText("$F{Field}");
099: //this.pattern = "";
100: this .stretchWithOverflow = false;
101: this .blankWhenNull = false;
102: this .group = "";
103: this .evaluationTime = "Now";
104: this .classExpression = "java.lang.String";
105: this .hyperlinkType = "None";
106: this .anchorNameExpression = "";
107:
108: setKey("textField");
109: }
110:
111: /** Getter for property blankWhenNull.
112: * @return Value of property blankWhenNull.
113: *
114: */
115: public boolean isBlankWhenNull() {
116: return blankWhenNull;
117: }
118:
119: /** Setter for property blankWhenNull.
120: * @param blankWhenNull New value of property blankWhenNull.
121: *
122: */
123: public void setBlankWhenNull(boolean blankWhenNull) {
124: this .blankWhenNull = blankWhenNull;
125: }
126:
127: /** Getter for property classExpression.
128: * @return Value of property classExpression.
129: *
130: */
131: public java.lang.String getClassExpression() {
132: return classExpression;
133: }
134:
135: /** Setter for property classExpression.
136: * @param classExpression New value of property classExpression.
137: *
138: */
139: public void setClassExpression(java.lang.String classExpression) {
140: this .classExpression = classExpression;
141: }
142:
143: /** Setter for property classExpression.
144: * If newClass is not in
145: * java.lang.Boolean
146: * java.lang.Byte
147: * java.util.Date
148: * java.sql.Timestamp
149: * java.sql.Time
150: * java.lang.Double
151: * java.lang.Float
152: * java.lang.Integer
153: * java.lang.Long
154: * java.lang.Short
155: * java.math.BigDecimal
156: * java.lang.Number
157: * java.lang.String
158: * the method trys to find something of similar using getSuperClass
159: * it is used.
160: *
161: * In no solution is find, the type is set to java.lang.String an optionally is possible
162: * change the expression with something like ""+<exp>. This should be very rare...
163: * @param classExpression New value of property classExpression.
164: *
165: */
166: public void setMatchingClassExpression(
167: java.lang.String newClassName, boolean adjustExpression) {
168:
169: if (!acceptedTextfieldClasses.contains(newClassName)) {
170: try {
171: Class newClass = MainFrame.getMainInstance()
172: .getReportClassLoader().loadClass(newClassName);
173: setMatchingClassExpression(newClass, adjustExpression);
174: } catch (Exception ex) {
175: ex.printStackTrace();
176: }
177: } else {
178: setClassExpression(newClassName);
179: }
180: }
181:
182: private void setMatchingClassExpression(Class newClass,
183: boolean adjustExpression) {
184:
185: // try with the superclasss..
186: Class super Class = newClass.getSuperclass();
187:
188: if (super Class == null) {
189: this .classExpression = classExpression;
190: if (adjustExpression) {
191: this .setText("\"\"+" + getText());
192: }
193: } else {
194: setMatchingClassExpression(super Class.getName(),
195: adjustExpression);
196: }
197: }
198:
199: /** Getter for property evaluationTime.
200: * @return Value of property evaluationTime.
201: *
202: */
203: public java.lang.String getEvaluationTime() {
204: return evaluationTime;
205: }
206:
207: /** Setter for property evaluationTime.
208: * @param evaluationTime New value of property evaluationTime.
209: *
210: */
211: public void setEvaluationTime(java.lang.String evaluationTime) {
212: this .evaluationTime = evaluationTime;
213: }
214:
215: /** Getter for property group.
216: * @return Value of property group.
217: *
218: */
219: public java.lang.String getGroup() {
220: return group;
221: }
222:
223: /** Setter for property group.
224: * @param group New value of property group.
225: *
226: */
227: public void setGroup(java.lang.String group) {
228: this .group = group;
229: }
230:
231: /** Getter for property pattern.
232: * @return Value of property pattern.
233: *
234: */
235: public java.lang.String getPattern() {
236: if (getPropertyValue(PATTERN) == null) {
237: // Look for a fgcolor in the stylesheet...
238: if (getStyle() != null) {
239: return getStyle().getAttributeString(
240: getStyle().ATTRIBUTE_pattern, DEFAULT_PATTERN,
241: true);
242: }
243: }
244: return getStringValue(PATTERN, DEFAULT_PATTERN);
245: }
246:
247: /** Setter for property pattern.
248: * @param pattern New value of property pattern.
249: *
250: */
251: public void setPattern(java.lang.String pattern) {
252: setPropertyValue(PATTERN, pattern);
253: }
254:
255: /** Getter for property stretchWithOverflow.
256: * @return Value of property stretchWithOverflow.
257: *
258: */
259: public boolean isStretchWithOverflow() {
260: return stretchWithOverflow;
261: }
262:
263: /** Setter for property stretchWithOverflow.
264: * @param stretchWithOverflow New value of property stretchWithOverflow.
265: *
266: */
267: public void setStretchWithOverflow(boolean stretchWithOverflow) {
268: this .stretchWithOverflow = stretchWithOverflow;
269: }
270:
271: /** Getter for property anchorNameExpression.
272: * @return Value of property anchorNameExpression.
273: *
274: */
275: public java.lang.String getAnchorNameExpression() {
276: return anchorNameExpression;
277: }
278:
279: /** Setter for property anchorNameExpression.
280: * @param anchorNameExpression New value of property anchorNameExpression.
281: *
282: */
283: public void setAnchorNameExpression(
284: java.lang.String anchorNameExpression) {
285: this .anchorNameExpression = anchorNameExpression;
286: }
287:
288: /** Getter for property hyperlinkAnchorExpression.
289: * @return Value of property hyperlinkAnchorExpression.
290: *
291: */
292: public java.lang.String getHyperlinkAnchorExpression() {
293: return hyperlinkAnchorExpression;
294: }
295:
296: /** Setter for property hyperlinkAnchorExpression.
297: * @param hyperlinkAnchorExpression New value of property hyperlinkAnchorExpression.
298: *
299: */
300: public void setHyperlinkAnchorExpression(
301: java.lang.String hyperlinkAnchorExpression) {
302: this .hyperlinkAnchorExpression = hyperlinkAnchorExpression;
303: }
304:
305: /** Getter for property hyperlinkPageExpression.
306: * @return Value of property hyperlinkPageExpression.
307: *
308: */
309: public java.lang.String getHyperlinkPageExpression() {
310: return hyperlinkPageExpression;
311: }
312:
313: /** Setter for property hyperlinkPageExpression.
314: * @param hyperlinkPageExpression New value of property hyperlinkPageExpression.
315: *
316: */
317: public void setHyperlinkPageExpression(
318: java.lang.String hyperlinkPageExpression) {
319: this .hyperlinkPageExpression = hyperlinkPageExpression;
320: }
321:
322: /** Getter for property hyperlinkReferenceExpression.
323: * @return Value of property hyperlinkReferenceExpression.
324: *
325: */
326: public java.lang.String getHyperlinkReferenceExpression() {
327: return hyperlinkReferenceExpression;
328: }
329:
330: /** Setter for property hyperlinkReferenceExpression.
331: * @param hyperlinkReferenceExpression New value of property hyperlinkReferenceExpression.
332: *
333: */
334: public void setHyperlinkReferenceExpression(
335: java.lang.String hyperlinkReferenceExpression) {
336: this .hyperlinkReferenceExpression = hyperlinkReferenceExpression;
337: }
338:
339: /** Getter for property hyperlinkType.
340: * @return Value of property hyperlinkType.
341: *
342: */
343: public java.lang.String getHyperlinkType() {
344: return hyperlinkType;
345: }
346:
347: /** Setter for property hyperlinkType.
348: * @param hyperlinkType New value of property hyperlinkType.
349: *
350: */
351: public void setHyperlinkType(java.lang.String hyperlinkType) {
352: this .hyperlinkType = hyperlinkType;
353: }
354:
355: public ReportElement cloneMe() {
356: TextFieldReportElement newReportElement = new TextFieldReportElement(
357: position.x, position.y, width, height);
358: copyBaseReportElement(newReportElement, this );
359: return newReportElement;
360: }
361:
362: public void copyBaseReportElement(ReportElement destination,
363: ReportElement source) {
364: super .copyBaseReportElement(destination, source);
365:
366: if (destination instanceof TextFieldReportElement
367: && source instanceof TextFieldReportElement) {
368: destination.setPropertyValue(PATTERN, source
369: .getPropertyValue(PATTERN));
370: ((TextFieldReportElement) destination)
371: .setBlankWhenNull(((TextFieldReportElement) source)
372: .isBlankWhenNull());
373: ((TextFieldReportElement) destination)
374: .setClassExpression(new String(
375: ((TextFieldReportElement) source)
376: .getClassExpression()));
377: ((TextFieldReportElement) destination)
378: .setEvaluationTime(new String(
379: ((TextFieldReportElement) source)
380: .getEvaluationTime()));
381: ((TextFieldReportElement) destination).setGroup(new String(
382: ((TextFieldReportElement) source).getGroup()));
383: //((TextFieldReportElement)destination).setPattern(new String( ((TextFieldReportElement)source).getPattern() ));
384: ((TextFieldReportElement) destination)
385: .setStretchWithOverflow(((TextFieldReportElement) source)
386: .isStretchWithOverflow());
387:
388: ((HyperLinkableReportElement) destination)
389: .setAnchorNameExpression(new String(
390: ((HyperLinkableReportElement) source)
391: .getAnchorNameExpression()));
392: ((HyperLinkableReportElement) destination)
393: .setHyperlinkAnchorExpression(new String(
394: ((HyperLinkableReportElement) source)
395: .getHyperlinkAnchorExpression()));
396: ((HyperLinkableReportElement) destination)
397: .setHyperlinkPageExpression(new String(
398: ((HyperLinkableReportElement) source)
399: .getHyperlinkPageExpression()));
400: ((HyperLinkableReportElement) destination)
401: .setHyperlinkReferenceExpression(new String(
402: ((HyperLinkableReportElement) source)
403: .getHyperlinkReferenceExpression()));
404: ((HyperLinkableReportElement) destination)
405: .setHyperlinkType(new String(
406: ((HyperLinkableReportElement) source)
407: .getHyperlinkType()));
408: }
409: }
410:
411: protected String hyperlinkTarget = "Self";
412:
413: /** Getter for property hyperlinkTarget.
414: * @return Value of property hyperlinkTarget.
415: *
416: */
417: public java.lang.String getHyperlinkTarget() {
418: return hyperlinkTarget;
419: }
420:
421: /** Setter for property hyperlinkTarget.
422: * @param hyperlinkTarget New value of property hyperlinkTarget.
423: *
424: */
425: public void setHyperlinkTarget(java.lang.String hyperlinkTarget) {
426: this .hyperlinkTarget = hyperlinkTarget;
427: }
428:
429: public int getBookmarkLevel() {
430: return bookmarkLevel;
431: }
432:
433: public void setBookmarkLevel(int bookmarkLevel) {
434: this .bookmarkLevel = bookmarkLevel;
435: }
436:
437: public void setStyle(Style style) {
438:
439: super .setStyle(style);
440:
441: if (style != null) {
442: //this.setIsStyledText( style.getAttributeBoolean( style.ATTRIBUTE_isStyledText, isIsStyledText(), true));
443: this .setBlankWhenNull(style.getAttributeBoolean(
444: style.ATTRIBUTE_isBlankWhenNull, isBlankWhenNull(),
445: true));
446: //this.setPattern( style.getAttributeString( style.ATTRIBUTE_pattern, getPattern(), true));
447: }
448: }
449:
450: public java.util.List getLinkParameters() {
451: return linkParameters;
452: }
453:
454: public void setLinkParameters(java.util.List linkParameters) {
455: this .linkParameters = linkParameters;
456: }
457:
458: public String getTooltipExpression() {
459: return tooltip;
460: }
461:
462: public void setTooltipExpression(String s) {
463: tooltip = s;
464: }
465:
466: }
|