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.awt.Color;
031: import java.io.IOException;
032: import java.io.ObjectInputStream;
033: import java.util.ArrayList;
034: import java.util.Iterator;
035: import java.util.List;
036:
037: import net.sf.jasperreports.engine.JRAbstractObjectFactory;
038: import net.sf.jasperreports.engine.JRAnchor;
039: import net.sf.jasperreports.engine.JRBox;
040: import net.sf.jasperreports.engine.JRChild;
041: import net.sf.jasperreports.engine.JRConstants;
042: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
043: import net.sf.jasperreports.engine.JRExpression;
044: import net.sf.jasperreports.engine.JRExpressionCollector;
045: import net.sf.jasperreports.engine.JRGroup;
046: import net.sf.jasperreports.engine.JRHyperlink;
047: import net.sf.jasperreports.engine.JRHyperlinkHelper;
048: import net.sf.jasperreports.engine.JRHyperlinkParameter;
049: import net.sf.jasperreports.engine.JRImage;
050: import net.sf.jasperreports.engine.util.JRStyleResolver;
051: import net.sf.jasperreports.engine.xml.JRXmlWriter;
052:
053: /**
054: * The actual implementation of a graphic element representing an image, used at design time.
055: * @author Teodor Danciu (teodord@users.sourceforge.net)
056: * @version $Id: JRDesignImage.java 1364 2006-08-31 15:13:20Z lucianc $
057: */
058: public class JRDesignImage extends JRDesignGraphicElement implements
059: JRImage {
060:
061: /**
062: *
063: */
064: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
065:
066: /**
067: *
068: */
069: protected Byte scaleImage;
070: protected Byte horizontalAlignment;
071: protected Byte verticalAlignment;
072: protected Boolean isUsingCache = null;
073: protected boolean isLazy = false;
074: protected byte onErrorType = ON_ERROR_TYPE_ERROR;
075: protected byte evaluationTime = JRExpression.EVALUATION_TIME_NOW;
076: protected byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
077: protected String linkType;
078: protected byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
079: private List hyperlinkParameters;
080:
081: /**
082: *
083: */
084: protected Byte border;
085: protected Byte topBorder = null;
086: protected Byte leftBorder = null;
087: protected Byte bottomBorder = null;
088: protected Byte rightBorder = null;
089: protected Color borderColor = null;
090: protected Color topBorderColor = null;
091: protected Color leftBorderColor = null;
092: protected Color bottomBorderColor = null;
093: protected Color rightBorderColor = null;
094: protected Integer padding;
095: protected Integer topPadding = null;
096: protected Integer leftPadding = null;
097: protected Integer bottomPadding = null;
098: protected Integer rightPadding = null;
099:
100: /**
101: *
102: */
103: // protected JRBox box = null;
104: /**
105: *
106: */
107: protected JRGroup evaluationGroup = null;
108: protected JRExpression expression = null;
109: protected JRExpression anchorNameExpression = null;
110: protected JRExpression hyperlinkReferenceExpression = null;
111: protected JRExpression hyperlinkAnchorExpression = null;
112: protected JRExpression hyperlinkPageExpression = null;
113: private JRExpression hyperlinkTooltipExpression;
114:
115: /**
116: * The bookmark level for the anchor associated with this image.
117: * @see JRAnchor#getBookmarkLevel()
118: */
119: protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
120:
121: /**
122: *
123: */
124: public JRDesignImage(JRDefaultStyleProvider defaultStyleProvider) {
125: super (defaultStyleProvider);
126:
127: hyperlinkParameters = new ArrayList();
128: }
129:
130: /**
131: *
132: */
133: public byte getPen() {
134: return JRStyleResolver.getPen(this , PEN_NONE);
135: }
136:
137: /**
138: *
139: */
140: public byte getMode() {
141: return JRStyleResolver.getMode(this , MODE_TRANSPARENT);
142: }
143:
144: /**
145: *
146: */
147: public byte getScaleImage() {
148: return JRStyleResolver.getScaleImage(this );
149: }
150:
151: public Byte getOwnScaleImage() {
152: return scaleImage;
153: }
154:
155: /**
156: *
157: */
158: public void setScaleImage(byte scaleImage) {
159: this .scaleImage = new Byte(scaleImage);
160: }
161:
162: /**
163: *
164: */
165: public void setScaleImage(Byte scaleImage) {
166: this .scaleImage = scaleImage;
167: }
168:
169: /**
170: *
171: */
172: public byte getHorizontalAlignment() {
173: return JRStyleResolver.getHorizontalAlignment(this );
174: }
175:
176: public Byte getOwnHorizontalAlignment() {
177: return horizontalAlignment;
178: }
179:
180: /**
181: *
182: */
183: public void setHorizontalAlignment(byte horizontalAlignment) {
184: this .horizontalAlignment = new Byte(horizontalAlignment);
185: }
186:
187: /**
188: *
189: */
190: public void setHorizontalAlignment(Byte horizontalAlignment) {
191: this .horizontalAlignment = horizontalAlignment;
192: }
193:
194: /**
195: *
196: */
197: public byte getVerticalAlignment() {
198: return JRStyleResolver.getVerticalAlignment(this );
199: }
200:
201: public Byte getOwnVerticalAlignment() {
202: return verticalAlignment;
203: }
204:
205: /**
206: *
207: */
208: public void setVerticalAlignment(byte verticalAlignment) {
209: this .verticalAlignment = new Byte(verticalAlignment);
210: }
211:
212: /**
213: *
214: */
215: public void setVerticalAlignment(Byte verticalAlignment) {
216: this .verticalAlignment = verticalAlignment;
217: }
218:
219: /**
220: *
221: */
222: public boolean isUsingCache() {
223: if (isUsingCache == null) {
224: if (getExpression() != null) {
225: return String.class.getName().equals(
226: getExpression().getValueClassName());
227: }
228: return true;
229: }
230: return isUsingCache.booleanValue();
231: }
232:
233: /**
234: *
235: */
236: public Boolean isOwnUsingCache() {
237: return isUsingCache;
238: }
239:
240: /**
241: *
242: */
243: public byte getEvaluationTime() {
244: return evaluationTime;
245: }
246:
247: /**
248: * @deprecated
249: */
250: public JRBox getBox() {
251: return this ;
252: }
253:
254: /**
255: *
256: */
257: public byte getHyperlinkType() {
258: return JRHyperlinkHelper.getHyperlinkType(this );
259: }
260:
261: /**
262: *
263: */
264: public byte getHyperlinkTarget() {
265: return hyperlinkTarget;
266: }
267:
268: /**
269: *
270: */
271: public JRGroup getEvaluationGroup() {
272: return evaluationGroup;
273: }
274:
275: /**
276: *
277: */
278: public JRExpression getExpression() {
279: return expression;
280: }
281:
282: /**
283: *
284: */
285: public JRExpression getAnchorNameExpression() {
286: return anchorNameExpression;
287: }
288:
289: /**
290: *
291: */
292: public JRExpression getHyperlinkReferenceExpression() {
293: return hyperlinkReferenceExpression;
294: }
295:
296: /**
297: *
298: */
299: public JRExpression getHyperlinkAnchorExpression() {
300: return hyperlinkAnchorExpression;
301: }
302:
303: /**
304: *
305: */
306: public JRExpression getHyperlinkPageExpression() {
307: return hyperlinkPageExpression;
308: }
309:
310: /**
311: *
312: */
313: public void setUsingCache(boolean isUsingCache) {
314: setUsingCache(isUsingCache ? Boolean.TRUE : Boolean.FALSE);
315: }
316:
317: /**
318: *
319: */
320: public void setUsingCache(Boolean isUsingCache) {
321: this .isUsingCache = isUsingCache;
322: }
323:
324: /**
325: *
326: */
327: public boolean isLazy() {
328: return isLazy;
329: }
330:
331: /**
332: *
333: */
334: public void setLazy(boolean isLazy) {
335: this .isLazy = isLazy;
336: }
337:
338: /**
339: *
340: */
341: public byte getOnErrorType() {
342: return onErrorType;
343: }
344:
345: /**
346: *
347: */
348: public void setOnErrorType(byte onErrorType) {
349: this .onErrorType = onErrorType;
350: }
351:
352: /**
353: * Sets the evaluation time for this image.
354: *
355: */
356: public void setEvaluationTime(byte evaluationTime) {
357: this .evaluationTime = evaluationTime;
358: }
359:
360: /**
361: * @deprecated
362: */
363: public void setBox(JRBox box) {
364: border = box.getOwnBorder();
365: topBorder = box.getOwnTopBorder();
366: leftBorder = box.getOwnLeftBorder();
367: bottomBorder = box.getOwnBottomBorder();
368: rightBorder = box.getOwnRightBorder();
369: borderColor = box.getOwnBorderColor();
370: topBorderColor = box.getOwnTopBorderColor();
371: leftBorderColor = box.getOwnLeftBorderColor();
372: bottomBorderColor = box.getOwnBottomBorderColor();
373: rightBorderColor = box.getOwnRightBorderColor();
374: padding = box.getOwnPadding();
375: topPadding = box.getOwnTopPadding();
376: leftPadding = box.getOwnLeftPadding();
377: bottomPadding = box.getOwnBottomPadding();
378: rightPadding = box.getOwnRightPadding();
379: }
380:
381: /**
382: * Sets the link type as a built-in hyperlink type.
383: *
384: * @param hyperlinkType the built-in hyperlink type
385: * @see #getLinkType()
386: */
387: public void setHyperlinkType(byte hyperlinkType) {
388: setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
389: }
390:
391: /**
392: *
393: */
394: public void setHyperlinkTarget(byte hyperlinkTarget) {
395: this .hyperlinkTarget = hyperlinkTarget;
396: }
397:
398: /**
399: *
400: */
401: public void setEvaluationGroup(JRGroup evaluationGroup) {
402: this .evaluationGroup = evaluationGroup;
403: }
404:
405: /**
406: *
407: */
408: public void setExpression(JRExpression expression) {
409: this .expression = expression;
410: }
411:
412: /**
413: *
414: */
415: public void setAnchorNameExpression(
416: JRExpression anchorNameExpression) {
417: this .anchorNameExpression = anchorNameExpression;
418: }
419:
420: /**
421: *
422: */
423: public void setHyperlinkReferenceExpression(
424: JRExpression hyperlinkReferenceExpression) {
425: this .hyperlinkReferenceExpression = hyperlinkReferenceExpression;
426: }
427:
428: /**
429: *
430: */
431: public void setHyperlinkAnchorExpression(
432: JRExpression hyperlinkAnchorExpression) {
433: this .hyperlinkAnchorExpression = hyperlinkAnchorExpression;
434: }
435:
436: /**
437: *
438: */
439: public void setHyperlinkPageExpression(
440: JRExpression hyperlinkPageExpression) {
441: this .hyperlinkPageExpression = hyperlinkPageExpression;
442: }
443:
444: /**
445: *
446: */
447: public JRChild getCopy(JRAbstractObjectFactory factory) {
448: return factory.getImage(this );
449: }
450:
451: /**
452: *
453: */
454: public void collectExpressions(JRExpressionCollector collector) {
455: collector.collect(this );
456: }
457:
458: /**
459: *
460: */
461: public void writeXml(JRXmlWriter xmlWriter) throws IOException {
462: xmlWriter.writeImage(this );
463: }
464:
465: public int getBookmarkLevel() {
466: return bookmarkLevel;
467: }
468:
469: /**
470: * Sets the boomark level for the anchor associated with this image.
471: *
472: * @param bookmarkLevel the bookmark level (starting from 1)
473: * or {@link JRAnchor#NO_BOOKMARK NO_BOOKMARK} if no bookmark should be created
474: */
475: public void setBookmarkLevel(int bookmarkLevel) {
476: this .bookmarkLevel = bookmarkLevel;
477: }
478:
479: /**
480: *
481: */
482: public byte getBorder() {
483: return JRStyleResolver.getBorder(this );
484: }
485:
486: public Byte getOwnBorder() {
487: return border;
488: }
489:
490: /**
491: *
492: */
493: public void setBorder(byte border) {
494: this .border = new Byte(border);
495: }
496:
497: /**
498: *
499: */
500: public Color getBorderColor() {
501: return JRStyleResolver.getBorderColor(this , getForecolor());
502: }
503:
504: public Color getOwnBorderColor() {
505: return borderColor;
506: }
507:
508: /**
509: *
510: */
511: public void setBorderColor(Color borderColor) {
512: this .borderColor = borderColor;
513: }
514:
515: /**
516: *
517: */
518: public int getPadding() {
519: return JRStyleResolver.getPadding(this );
520: }
521:
522: public Integer getOwnPadding() {
523: return padding;
524: }
525:
526: /**
527: *
528: */
529: public void setPadding(int padding) {
530: this .padding = new Integer(padding);
531: }
532:
533: /**
534: *
535: */
536: public byte getTopBorder() {
537: return JRStyleResolver.getTopBorder(this );
538: }
539:
540: /**
541: *
542: */
543: public Byte getOwnTopBorder() {
544: return topBorder;
545: }
546:
547: /**
548: *
549: */
550: public void setTopBorder(byte topBorder) {
551: this .topBorder = new Byte(topBorder);
552: }
553:
554: /**
555: *
556: */
557: public Color getTopBorderColor() {
558: return JRStyleResolver.getTopBorderColor(this , getForecolor());
559: }
560:
561: /**
562: *
563: */
564: public Color getOwnTopBorderColor() {
565: return topBorderColor;
566: }
567:
568: /**
569: *
570: */
571: public void setTopBorderColor(Color topBorderColor) {
572: this .topBorderColor = topBorderColor;
573: }
574:
575: /**
576: *
577: */
578: public int getTopPadding() {
579: return JRStyleResolver.getTopPadding(this );
580: }
581:
582: /**
583: *
584: */
585: public Integer getOwnTopPadding() {
586: return topPadding;
587: }
588:
589: /**
590: *
591: */
592: public void setTopPadding(int topPadding) {
593: this .topPadding = new Integer(topPadding);
594: }
595:
596: /**
597: *
598: */
599: public byte getLeftBorder() {
600: return JRStyleResolver.getLeftBorder(this );
601: }
602:
603: /**
604: *
605: */
606: public Byte getOwnLeftBorder() {
607: return leftBorder;
608: }
609:
610: /**
611: *
612: */
613: public void setLeftBorder(byte leftBorder) {
614: this .leftBorder = new Byte(leftBorder);
615: }
616:
617: /**
618: *
619: */
620: public Color getLeftBorderColor() {
621: return JRStyleResolver.getLeftBorderColor(this , getForecolor());
622: }
623:
624: /**
625: *
626: */
627: public Color getOwnLeftBorderColor() {
628: return leftBorderColor;
629: }
630:
631: /**
632: *
633: */
634: public void setLeftBorderColor(Color leftBorderColor) {
635: this .leftBorderColor = leftBorderColor;
636: }
637:
638: /**
639: *
640: */
641: public int getLeftPadding() {
642: return JRStyleResolver.getLeftPadding(this );
643: }
644:
645: /**
646: *
647: */
648: public Integer getOwnLeftPadding() {
649: return leftPadding;
650: }
651:
652: /**
653: *
654: */
655: public void setLeftPadding(int leftPadding) {
656: this .leftPadding = new Integer(leftPadding);
657: }
658:
659: /**
660: *
661: */
662: public byte getBottomBorder() {
663: return JRStyleResolver.getBottomBorder(this );
664: }
665:
666: /**
667: *
668: */
669: public Byte getOwnBottomBorder() {
670: return bottomBorder;
671: }
672:
673: /**
674: *
675: */
676: public void setBottomBorder(byte bottomBorder) {
677: this .bottomBorder = new Byte(bottomBorder);
678: }
679:
680: /**
681: *
682: */
683: public Color getBottomBorderColor() {
684: return JRStyleResolver.getBottomBorderColor(this ,
685: getForecolor());
686: }
687:
688: /**
689: *
690: */
691: public Color getOwnBottomBorderColor() {
692: return bottomBorderColor;
693: }
694:
695: /**
696: *
697: */
698: public void setBottomBorderColor(Color bottomBorderColor) {
699: this .bottomBorderColor = bottomBorderColor;
700: }
701:
702: /**
703: *
704: */
705: public int getBottomPadding() {
706: return JRStyleResolver.getBottomPadding(this );
707: }
708:
709: /**
710: *
711: */
712: public Integer getOwnBottomPadding() {
713: return bottomPadding;
714: }
715:
716: /**
717: *
718: */
719: public void setBottomPadding(int bottomPadding) {
720: this .bottomPadding = new Integer(bottomPadding);
721: }
722:
723: /**
724: *
725: */
726: public byte getRightBorder() {
727: return JRStyleResolver.getRightBorder(this );
728: }
729:
730: /**
731: *
732: */
733: public Byte getOwnRightBorder() {
734: return rightBorder;
735: }
736:
737: /**
738: *
739: */
740: public void setRightBorder(byte rightBorder) {
741: this .rightBorder = new Byte(rightBorder);
742: }
743:
744: /**
745: *
746: */
747: public Color getRightBorderColor() {
748: return JRStyleResolver
749: .getRightBorderColor(this , getForecolor());
750: }
751:
752: /**
753: *
754: */
755: public Color getOwnRightBorderColor() {
756: return rightBorderColor;
757: }
758:
759: /**
760: *
761: */
762: public void setRightBorderColor(Color rightBorderColor) {
763: this .rightBorderColor = rightBorderColor;
764: }
765:
766: /**
767: *
768: */
769: public int getRightPadding() {
770: return JRStyleResolver.getRightPadding(this );
771: }
772:
773: /**
774: *
775: */
776: public Integer getOwnRightPadding() {
777: return rightPadding;
778: }
779:
780: /**
781: *
782: */
783: public void setRightPadding(int rightPadding) {
784: this .rightPadding = new Integer(rightPadding);
785: }
786:
787: /**
788: *
789: */
790: public void setBorder(Byte border) {
791: this .border = border;
792: }
793:
794: /**
795: *
796: */
797: public void setPadding(Integer padding) {
798: this .padding = padding;
799: }
800:
801: /**
802: *
803: */
804: public void setTopBorder(Byte topBorder) {
805: this .topBorder = topBorder;
806: }
807:
808: /**
809: *
810: */
811: public void setTopPadding(Integer topPadding) {
812: this .topPadding = topPadding;
813: }
814:
815: /**
816: *
817: */
818: public void setLeftBorder(Byte leftBorder) {
819: this .leftBorder = leftBorder;
820: }
821:
822: /**
823: *
824: */
825: public void setLeftPadding(Integer leftPadding) {
826: this .leftPadding = leftPadding;
827: }
828:
829: /**
830: *
831: */
832: public void setBottomBorder(Byte bottomBorder) {
833: this .bottomBorder = bottomBorder;
834: }
835:
836: /**
837: *
838: */
839: public void setBottomPadding(Integer bottomPadding) {
840: this .bottomPadding = bottomPadding;
841: }
842:
843: /**
844: *
845: */
846: public void setRightBorder(Byte rightBorder) {
847: this .rightBorder = rightBorder;
848: }
849:
850: /**
851: *
852: */
853: public void setRightPadding(Integer rightPadding) {
854: this .rightPadding = rightPadding;
855: }
856:
857: public String getLinkType() {
858: return linkType;
859: }
860:
861: /**
862: * Sets the hyperlink type.
863: * <p>
864: * The type can be one of the built-in types
865: * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
866: * or can be an arbitrary type.
867: * </p>
868: * @param type the hyperlink type
869: */
870: public void setLinkType(String type) {
871: this .linkType = type;
872: }
873:
874: public JRHyperlinkParameter[] getHyperlinkParameters() {
875: JRHyperlinkParameter[] parameters;
876: if (hyperlinkParameters.isEmpty()) {
877: parameters = null;
878: } else {
879: parameters = new JRHyperlinkParameter[hyperlinkParameters
880: .size()];
881: hyperlinkParameters.toArray(parameters);
882: }
883: return parameters;
884: }
885:
886: /**
887: * Returns the list of custom hyperlink parameters.
888: *
889: * @return the list of custom hyperlink parameters
890: */
891: public List getHyperlinkParametersList() {
892: return hyperlinkParameters;
893: }
894:
895: /**
896: * Adds a custom hyperlink parameter.
897: *
898: * @param parameter the parameter to add
899: */
900: public void addHyperlinkParameter(JRHyperlinkParameter parameter) {
901: hyperlinkParameters.add(parameter);
902: }
903:
904: /**
905: * Removes a custom hyperlink parameter.
906: *
907: * @param parameter the parameter to remove
908: */
909: public void removeHyperlinkParameter(JRHyperlinkParameter parameter) {
910: hyperlinkParameters.remove(parameter);
911: }
912:
913: /**
914: * Removes a custom hyperlink parameter.
915: * <p>
916: * If multiple parameters having the specified name exist, all of them
917: * will be removed
918: * </p>
919: *
920: * @param parameterName the parameter name
921: */
922: public void removeHyperlinkParameter(String parameterName) {
923: for (Iterator it = hyperlinkParameters.iterator(); it.hasNext();) {
924: JRHyperlinkParameter parameter = (JRHyperlinkParameter) it
925: .next();
926: if (parameter.getName() != null
927: && parameter.getName().equals(parameterName)) {
928: it.remove();
929: }
930: }
931: }
932:
933: private void readObject(ObjectInputStream in) throws IOException,
934: ClassNotFoundException {
935: in.defaultReadObject();
936: normalizeLinkType();
937: }
938:
939: protected void normalizeLinkType() {
940: if (linkType == null) {
941: linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
942: }
943: hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
944: }
945:
946: public JRExpression getHyperlinkTooltipExpression() {
947: return hyperlinkTooltipExpression;
948: }
949:
950: /**
951: * Sets the expression which will be used to generate the hyperlink tooltip.
952: *
953: * @param hyperlinkTooltipExpression the expression which will be used to generate the hyperlink tooltip
954: * @see #getHyperlinkTooltipExpression()
955: */
956: public void setHyperlinkTooltipExpression(
957: JRExpression hyperlinkTooltipExpression) {
958: this.hyperlinkTooltipExpression = hyperlinkTooltipExpression;
959: }
960:
961: }
|