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.awt.Color;
031: import java.io.IOException;
032: import java.io.ObjectInputStream;
033:
034: import net.sf.jasperreports.engine.JRAlignment;
035: import net.sf.jasperreports.engine.JRBox;
036: import net.sf.jasperreports.engine.JRChart;
037: import net.sf.jasperreports.engine.JRConstants;
038: import net.sf.jasperreports.engine.JRDefaultStyleProvider;
039: import net.sf.jasperreports.engine.JRElement;
040: import net.sf.jasperreports.engine.JRGraphicElement;
041: import net.sf.jasperreports.engine.JRHyperlink;
042: import net.sf.jasperreports.engine.JRHyperlinkHelper;
043: import net.sf.jasperreports.engine.JRImage;
044: import net.sf.jasperreports.engine.util.JRStyleResolver;
045:
046: /**
047: * @author Teodor Danciu (teodord@users.sourceforge.net)
048: * @version $Id: JRTemplateImage.java 1729 2007-05-29 12:45:24Z teodord $
049: */
050: public class JRTemplateImage extends JRTemplateGraphicElement implements
051: JRAlignment, JRBox {
052:
053: /**
054: *
055: */
056: private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
057:
058: /**
059: *
060: */
061: private Byte scaleImage = null;
062: private Boolean isUsingCache = Boolean.TRUE;
063: private Byte horizontalAlignment = null;
064: private Byte verticalAlignment = null;
065: protected boolean isLazy = false;
066: private byte onErrorType = JRImage.ON_ERROR_TYPE_ERROR;
067: private byte hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
068: private String linkType;
069: private byte hyperlinkTarget = JRHyperlink.HYPERLINK_TARGET_SELF;
070: //private JRBox box = null;
071:
072: /**
073: *
074: */
075: protected Byte border;
076: protected Byte topBorder = null;
077: protected Byte leftBorder = null;
078: protected Byte bottomBorder = null;
079: protected Byte rightBorder = null;
080: protected Color borderColor = null;
081: protected Color topBorderColor = null;
082: protected Color leftBorderColor = null;
083: protected Color bottomBorderColor = null;
084: protected Color rightBorderColor = null;
085: protected Integer padding;
086: protected Integer topPadding = null;
087: protected Integer leftPadding = null;
088: protected Integer bottomPadding = null;
089: protected Integer rightPadding = null;
090:
091: /**
092: *
093: */
094: protected JRTemplateImage(
095: JRDefaultStyleProvider defaultStyleProvider, JRImage image) {
096: super (defaultStyleProvider);
097:
098: setImage(image);
099: }
100:
101: /**
102: *
103: */
104: protected JRTemplateImage(
105: JRDefaultStyleProvider defaultStyleProvider, JRChart chart) {
106: super (defaultStyleProvider);
107:
108: setChart(chart);
109: }
110:
111: /**
112: *
113: */
114: protected void setBox(JRBox box) {
115: border = box.getOwnBorder();
116: topBorder = box.getOwnTopBorder();
117: leftBorder = box.getOwnLeftBorder();
118: bottomBorder = box.getOwnBottomBorder();
119: rightBorder = box.getOwnRightBorder();
120: borderColor = box.getOwnBorderColor();
121: topBorderColor = box.getOwnTopBorderColor();
122: leftBorderColor = box.getOwnLeftBorderColor();
123: bottomBorderColor = box.getOwnBottomBorderColor();
124: rightBorderColor = box.getOwnRightBorderColor();
125: padding = box.getOwnPadding();
126: topPadding = box.getOwnTopPadding();
127: leftPadding = box.getOwnLeftPadding();
128: bottomPadding = box.getOwnBottomPadding();
129: rightPadding = box.getOwnRightPadding();
130: }
131:
132: /**
133: *
134: */
135: protected void setImage(JRImage image) {
136: super .setGraphicElement(image);
137:
138: setBox(image);
139:
140: setScaleImage(image.getScaleImage());
141: setUsingCache(image.isUsingCache());
142: setHorizontalAlignment(image.getHorizontalAlignment());
143: setVerticalAlignment(image.getVerticalAlignment());
144: setLazy(image.isLazy());
145: setOnErrorType(image.getOnErrorType());
146: setLinkType(image.getLinkType());
147: setHyperlinkTarget(image.getHyperlinkTarget());
148: }
149:
150: /**
151: *
152: */
153: protected void setChart(JRChart chart) {
154: super .setElement(chart);
155:
156: setPen(JRGraphicElement.PEN_NONE);
157: setFill(JRGraphicElement.FILL_SOLID);
158:
159: setBox(chart);
160:
161: setLinkType(chart.getLinkType());
162: setHyperlinkTarget(chart.getHyperlinkTarget());
163: }
164:
165: /**
166: *
167: */
168: public byte getMode() {
169: return JRStyleResolver
170: .getMode(this , JRElement.MODE_TRANSPARENT);
171: }
172:
173: /**
174: *
175: */
176: public byte getPen() {
177: return JRStyleResolver.getPen(this , JRGraphicElement.PEN_NONE);
178: }
179:
180: /**
181: *
182: */
183: public byte getScaleImage() {
184: return JRStyleResolver.getScaleImage(this );
185: }
186:
187: /**
188: *
189: */
190: public Byte getOwnScaleImage() {
191: return scaleImage;
192: }
193:
194: /**
195: *
196: */
197: protected void setScaleImage(byte scaleImage) {
198: this .scaleImage = new Byte(scaleImage);
199: }
200:
201: /**
202: *
203: */
204: protected void setScaleImage(Byte scaleImage) {
205: this .scaleImage = scaleImage;
206: }
207:
208: /**
209: *
210: */
211: public boolean isUsingCache() {
212: return isUsingCache == null ? true : isUsingCache
213: .booleanValue();
214: }
215:
216: /**
217: *
218: */
219: public void setUsingCache(boolean isUsingCache) {
220: this .isUsingCache = (isUsingCache ? Boolean.TRUE
221: : Boolean.FALSE);
222: }
223:
224: /**
225: *
226: */
227: public byte getHorizontalAlignment() {
228: return JRStyleResolver.getHorizontalAlignment(this );
229: }
230:
231: /**
232: *
233: */
234: public Byte getOwnHorizontalAlignment() {
235: return horizontalAlignment;
236: }
237:
238: /**
239: *
240: */
241: public void setHorizontalAlignment(byte horizontalAlignment) {
242: this .horizontalAlignment = new Byte(horizontalAlignment);
243: }
244:
245: /**
246: *
247: */
248: public void setHorizontalAlignment(Byte horizontalAlignment) {
249: this .horizontalAlignment = horizontalAlignment;
250: }
251:
252: /**
253: *
254: */
255: public byte getVerticalAlignment() {
256: return JRStyleResolver.getVerticalAlignment(this );
257: }
258:
259: /**
260: *
261: */
262: public Byte getOwnVerticalAlignment() {
263: return verticalAlignment;
264: }
265:
266: /**
267: *
268: */
269: public void setVerticalAlignment(byte verticalAlignment) {
270: this .verticalAlignment = new Byte(verticalAlignment);
271: }
272:
273: /**
274: *
275: */
276: public void setVerticalAlignment(Byte verticalAlignment) {
277: this .verticalAlignment = verticalAlignment;
278: }
279:
280: /**
281: *
282: */
283: public boolean isLazy() {
284: return isLazy;
285: }
286:
287: /**
288: *
289: */
290: public void setLazy(boolean isLazy) {
291: this .isLazy = isLazy;
292: }
293:
294: /**
295: *
296: */
297: public byte getOnErrorType() {
298: return onErrorType;
299: }
300:
301: /**
302: *
303: */
304: public void setOnErrorType(byte onErrorType) {
305: this .onErrorType = onErrorType;
306: }
307:
308: /**
309: * @deprecated
310: */
311: public JRBox getBox() {
312: return this ;
313: }
314:
315: /**
316: * Retrieves the hyperlink type for the element.
317: * <p>
318: * The actual hyperlink type is determined by {@link #getLinkType() getLinkType()}.
319: * This method can is used to determine whether the hyperlink type is one of the
320: * built-in types or a custom type.
321: * When hyperlink is of custom type, {@link JRHyperlink#HYPERLINK_TYPE_CUSTOM HYPERLINK_TYPE_CUSTOM} is returned.
322: * </p>
323: * @return one of the hyperlink type constants
324: * @see #getLinkType()
325: */
326: public byte getHyperlinkType() {
327: return JRHyperlinkHelper.getHyperlinkType(getLinkType());
328: }
329:
330: /**
331: * Sets the link type as a built-in hyperlink type.
332: *
333: * @param hyperlinkType the built-in hyperlink type
334: * @see #getLinkType()
335: */
336: protected void setHyperlinkType(byte hyperlinkType) {
337: setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
338: }
339:
340: /**
341: *
342: */
343: public byte getHyperlinkTarget() {
344: return hyperlinkTarget;
345: }
346:
347: /**
348: *
349: */
350: protected void setHyperlinkTarget(byte hyperlinkTarget) {
351: this .hyperlinkTarget = hyperlinkTarget;
352: }
353:
354: /**
355: *
356: */
357: public byte getBorder() {
358: return JRStyleResolver.getBorder(this );
359: }
360:
361: public Byte getOwnBorder() {
362: return border;
363: }
364:
365: /**
366: *
367: */
368: public void setBorder(byte border) {
369: this .border = new Byte(border);
370: }
371:
372: /**
373: *
374: */
375: public Color getBorderColor() {
376: return JRStyleResolver.getBorderColor(this , getForecolor());
377: }
378:
379: public Color getOwnBorderColor() {
380: return borderColor;
381: }
382:
383: /**
384: *
385: */
386: public void setBorderColor(Color borderColor) {
387: this .borderColor = borderColor;
388: }
389:
390: /**
391: *
392: */
393: public int getPadding() {
394: return JRStyleResolver.getPadding(this );
395: }
396:
397: public Integer getOwnPadding() {
398: return padding;
399: }
400:
401: /**
402: *
403: */
404: public void setPadding(int padding) {
405: this .padding = new Integer(padding);
406: }
407:
408: /**
409: *
410: */
411: public byte getTopBorder() {
412: return JRStyleResolver.getTopBorder(this );
413: }
414:
415: /**
416: *
417: */
418: public Byte getOwnTopBorder() {
419: return topBorder;
420: }
421:
422: /**
423: *
424: */
425: public void setTopBorder(byte topBorder) {
426: this .topBorder = new Byte(topBorder);
427: }
428:
429: /**
430: *
431: */
432: public Color getTopBorderColor() {
433: return JRStyleResolver.getTopBorderColor(this , getForecolor());
434: }
435:
436: /**
437: *
438: */
439: public Color getOwnTopBorderColor() {
440: return topBorderColor;
441: }
442:
443: /**
444: *
445: */
446: public void setTopBorderColor(Color topBorderColor) {
447: this .topBorderColor = topBorderColor;
448: }
449:
450: /**
451: *
452: */
453: public int getTopPadding() {
454: return JRStyleResolver.getTopPadding(this );
455: }
456:
457: /**
458: *
459: */
460: public Integer getOwnTopPadding() {
461: return topPadding;
462: }
463:
464: /**
465: *
466: */
467: public void setTopPadding(int topPadding) {
468: this .topPadding = new Integer(topPadding);
469: }
470:
471: /**
472: *
473: */
474: public byte getLeftBorder() {
475: return JRStyleResolver.getLeftBorder(this );
476: }
477:
478: /**
479: *
480: */
481: public Byte getOwnLeftBorder() {
482: return leftBorder;
483: }
484:
485: /**
486: *
487: */
488: public void setLeftBorder(byte leftBorder) {
489: this .leftBorder = new Byte(leftBorder);
490: }
491:
492: /**
493: *
494: */
495: public Color getLeftBorderColor() {
496: return JRStyleResolver.getLeftBorderColor(this , getForecolor());
497: }
498:
499: /**
500: *
501: */
502: public Color getOwnLeftBorderColor() {
503: return leftBorderColor;
504: }
505:
506: /**
507: *
508: */
509: public void setLeftBorderColor(Color leftBorderColor) {
510: this .leftBorderColor = leftBorderColor;
511: }
512:
513: /**
514: *
515: */
516: public int getLeftPadding() {
517: return JRStyleResolver.getLeftPadding(this );
518: }
519:
520: /**
521: *
522: */
523: public Integer getOwnLeftPadding() {
524: return leftPadding;
525: }
526:
527: /**
528: *
529: */
530: public void setLeftPadding(int leftPadding) {
531: this .leftPadding = new Integer(leftPadding);
532: }
533:
534: /**
535: *
536: */
537: public byte getBottomBorder() {
538: return JRStyleResolver.getBottomBorder(this );
539: }
540:
541: /**
542: *
543: */
544: public Byte getOwnBottomBorder() {
545: return bottomBorder;
546: }
547:
548: /**
549: *
550: */
551: public void setBottomBorder(byte bottomBorder) {
552: this .bottomBorder = new Byte(bottomBorder);
553: }
554:
555: /**
556: *
557: */
558: public Color getBottomBorderColor() {
559: return JRStyleResolver.getBottomBorderColor(this ,
560: getForecolor());
561: }
562:
563: /**
564: *
565: */
566: public Color getOwnBottomBorderColor() {
567: return bottomBorderColor;
568: }
569:
570: /**
571: *
572: */
573: public void setBottomBorderColor(Color bottomBorderColor) {
574: this .bottomBorderColor = bottomBorderColor;
575: }
576:
577: /**
578: *
579: */
580: public int getBottomPadding() {
581: return JRStyleResolver.getBottomPadding(this );
582: }
583:
584: /**
585: *
586: */
587: public Integer getOwnBottomPadding() {
588: return bottomPadding;
589: }
590:
591: /**
592: *
593: */
594: public void setBottomPadding(int bottomPadding) {
595: this .bottomPadding = new Integer(bottomPadding);
596: }
597:
598: /**
599: *
600: */
601: public byte getRightBorder() {
602: return JRStyleResolver.getRightBorder(this );
603: }
604:
605: /**
606: *
607: */
608: public Byte getOwnRightBorder() {
609: return rightBorder;
610: }
611:
612: /**
613: *
614: */
615: public void setRightBorder(byte rightBorder) {
616: this .rightBorder = new Byte(rightBorder);
617: }
618:
619: /**
620: *
621: */
622: public Color getRightBorderColor() {
623: return JRStyleResolver
624: .getRightBorderColor(this , getForecolor());
625: }
626:
627: /**
628: *
629: */
630: public Color getOwnRightBorderColor() {
631: return rightBorderColor;
632: }
633:
634: /**
635: *
636: */
637: public void setRightBorderColor(Color rightBorderColor) {
638: this .rightBorderColor = rightBorderColor;
639: }
640:
641: /**
642: *
643: */
644: public int getRightPadding() {
645: return JRStyleResolver.getRightPadding(this );
646: }
647:
648: /**
649: *
650: */
651: public Integer getOwnRightPadding() {
652: return rightPadding;
653: }
654:
655: /**
656: *
657: */
658: public void setRightPadding(int rightPadding) {
659: this .rightPadding = new Integer(rightPadding);
660: }
661:
662: /**
663: *
664: */
665: public void setBorder(Byte border) {
666: this .border = border;
667: }
668:
669: /**
670: *
671: */
672: public void setPadding(Integer padding) {
673: this .padding = padding;
674: }
675:
676: /**
677: *
678: */
679: public void setTopBorder(Byte topBorder) {
680: this .topBorder = topBorder;
681: }
682:
683: /**
684: *
685: */
686: public void setTopPadding(Integer topPadding) {
687: this .topPadding = topPadding;
688: }
689:
690: /**
691: *
692: */
693: public void setLeftBorder(Byte leftBorder) {
694: this .leftBorder = leftBorder;
695: }
696:
697: /**
698: *
699: */
700: public void setLeftPadding(Integer leftPadding) {
701: this .leftPadding = leftPadding;
702: }
703:
704: /**
705: *
706: */
707: public void setBottomBorder(Byte bottomBorder) {
708: this .bottomBorder = bottomBorder;
709: }
710:
711: /**
712: *
713: */
714: public void setBottomPadding(Integer bottomPadding) {
715: this .bottomPadding = bottomPadding;
716: }
717:
718: /**
719: *
720: */
721: public void setRightBorder(Byte rightBorder) {
722: this .rightBorder = rightBorder;
723: }
724:
725: /**
726: *
727: */
728: public void setRightPadding(Integer rightPadding) {
729: this .rightPadding = rightPadding;
730: }
731:
732: /**
733: * Returns the hyperlink type.
734: * <p>
735: * The type can be one of the built-in types
736: * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
737: * or can be an arbitrary type.
738: * </p>
739: * @return the hyperlink type
740: */
741: public String getLinkType() {
742: return linkType;
743: }
744:
745: /**
746: * Sets the hyperlink type.
747: * <p>
748: * The type can be one of the built-in types
749: * (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
750: * or can be an arbitrary type.
751: * </p>
752: * @param linkType the hyperlink type
753: */
754: public void setLinkType(String linkType) {
755: this .linkType = linkType;
756: }
757:
758: private void readObject(ObjectInputStream in) throws IOException,
759: ClassNotFoundException {
760: in.defaultReadObject();
761: normalizeLinkType();
762: }
763:
764: protected void normalizeLinkType() {
765: if (linkType == null) {
766: linkType = JRHyperlinkHelper.getLinkType(hyperlinkType);
767: }
768: hyperlinkType = JRHyperlink.HYPERLINK_TYPE_NULL;
769: }
770:
771: }
|