net.sf.jasperreports.engine.base.JRBasePrintImage Maven / Gradle / Ivy
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2013 Jaspersoft Corporation. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package net.sf.jasperreports.engine.base;
import java.awt.Color;
import java.io.IOException;
import java.io.ObjectInputStream;
import net.sf.jasperreports.engine.JRAnchor;
import net.sf.jasperreports.engine.JRConstants;
import net.sf.jasperreports.engine.JRDefaultStyleProvider;
import net.sf.jasperreports.engine.JRHyperlinkHelper;
import net.sf.jasperreports.engine.JRLineBox;
import net.sf.jasperreports.engine.JRPen;
import net.sf.jasperreports.engine.JRPrintHyperlinkParameter;
import net.sf.jasperreports.engine.JRPrintHyperlinkParameters;
import net.sf.jasperreports.engine.JRPrintImage;
import net.sf.jasperreports.engine.PrintElementVisitor;
import net.sf.jasperreports.engine.Renderable;
import net.sf.jasperreports.engine.RenderableUtil;
import net.sf.jasperreports.engine.type.HorizontalAlignEnum;
import net.sf.jasperreports.engine.type.HyperlinkTargetEnum;
import net.sf.jasperreports.engine.type.HyperlinkTypeEnum;
import net.sf.jasperreports.engine.type.ModeEnum;
import net.sf.jasperreports.engine.type.OnErrorTypeEnum;
import net.sf.jasperreports.engine.type.ScaleImageEnum;
import net.sf.jasperreports.engine.type.VerticalAlignEnum;
import net.sf.jasperreports.engine.util.JRBoxUtil;
import net.sf.jasperreports.engine.util.JRStyleResolver;
/**
* @author Teodor Danciu ([email protected])
* @version $Id: JRBasePrintImage.java 5878 2013-01-07 20:23:13Z teodord $
*/
public class JRBasePrintImage extends JRBasePrintGraphicElement implements JRPrintImage
{
/**
*
*/
private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
/**
*
*/
protected Renderable renderable;
protected ScaleImageEnum scaleImageValue;
protected Boolean isUsingCache = Boolean.TRUE;
protected HorizontalAlignEnum horizontalAlignmentValue;
protected VerticalAlignEnum verticalAlignmentValue;
protected boolean isLazy;
protected OnErrorTypeEnum onErrorTypeValue = OnErrorTypeEnum.ERROR;
protected JRLineBox lineBox;
protected String anchorName;
protected String linkType;
protected String linkTarget;
protected String hyperlinkReference;
protected String hyperlinkAnchor;
protected Integer hyperlinkPage;
protected String hyperlinkTooltip;
protected JRPrintHyperlinkParameters hyperlinkParameters;
/**
* The bookmark level for the anchor associated with this field.
* @see JRAnchor#getBookmarkLevel()
*/
protected int bookmarkLevel = JRAnchor.NO_BOOKMARK;
/**
*
*/
public JRBasePrintImage(JRDefaultStyleProvider defaultStyleProvider)
{
super(defaultStyleProvider);
lineBox = new JRBaseLineBox(this);
}
/**
*
*/
public ModeEnum getModeValue()
{
return JRStyleResolver.getMode(this, ModeEnum.TRANSPARENT);
}
/**
*
*/
public Renderable getRenderable()
{
return renderable;
}
/**
*
*/
public void setRenderable(Renderable renderable)
{
this.renderable = renderable;
}
/**
* @deprecated Replaced by {@link #getRenderable()}.
*/
public net.sf.jasperreports.engine.JRRenderable getRenderer()
{
return getRenderable();
}
/**
* @deprecated Replaced by {@link #setRenderable(Renderable)}.
*/
public void setRenderer(net.sf.jasperreports.engine.JRRenderable renderer)
{
setRenderable(RenderableUtil.getWrappingRenderable(renderer));
}
/**
*
*/
public ScaleImageEnum getScaleImageValue()
{
return JRStyleResolver.getScaleImageValue(this);
}
/**
*
*/
public ScaleImageEnum getOwnScaleImageValue()
{
return this.scaleImageValue;
}
/**
*
*/
public void setScaleImage(ScaleImageEnum scaleImageValue)
{
this.scaleImageValue = scaleImageValue;
}
/**
*
*/
public boolean isUsingCache()
{
return isUsingCache == null ? true : isUsingCache.booleanValue();
}
/**
*
*/
public void setUsingCache(boolean isUsingCache)
{
this.isUsingCache = (isUsingCache ? Boolean.TRUE : Boolean.FALSE);
}
/**
*
*/
public HorizontalAlignEnum getHorizontalAlignmentValue()
{
return JRStyleResolver.getHorizontalAlignmentValue(this);
}
/**
*
*/
public HorizontalAlignEnum getOwnHorizontalAlignmentValue()
{
return horizontalAlignmentValue;
}
/**
*
*/
public void setHorizontalAlignment(HorizontalAlignEnum horizontalAlignmentValue)
{
this.horizontalAlignmentValue = horizontalAlignmentValue;
}
/**
*
*/
public VerticalAlignEnum getVerticalAlignmentValue()
{
return JRStyleResolver.getVerticalAlignmentValue(this);
}
/**
*
*/
public VerticalAlignEnum getOwnVerticalAlignmentValue()
{
return verticalAlignmentValue;
}
/**
*
*/
public void setVerticalAlignment(VerticalAlignEnum verticalAlignmentValue)
{
this.verticalAlignmentValue = verticalAlignmentValue;
}
/**
*
*/
public boolean isLazy()
{
return isLazy;
}
/**
*
*/
public void setLazy(boolean isLazy)
{
this.isLazy = isLazy;
}
/**
*
*/
public OnErrorTypeEnum getOnErrorTypeValue()
{
return this.onErrorTypeValue;
}
/**
*
*/
public void setOnErrorType(OnErrorTypeEnum onErrorTypeValue)
{
this.onErrorTypeValue = onErrorTypeValue;
}
/**
*
*/
public JRLineBox getLineBox()
{
return lineBox;
}
/**
*
*/
public void copyBox(JRLineBox lineBox)
{
this.lineBox = lineBox.clone(this);
}
/**
*
*/
public Float getDefaultLineWidth()
{
return JRPen.LINE_WIDTH_0;
}
/**
*
*/
public String getAnchorName()
{
return anchorName;
}
/**
*
*/
public void setAnchorName(String anchorName)
{
this.anchorName = anchorName;
}
/**
*
*/
public HyperlinkTypeEnum getHyperlinkTypeValue()
{
return JRHyperlinkHelper.getHyperlinkTypeValue(getLinkType());
}
/**
*
*/
public void setHyperlinkType(HyperlinkTypeEnum hyperlinkType)
{
setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
}
/**
*
*/
public HyperlinkTargetEnum getHyperlinkTargetValue()
{
return JRHyperlinkHelper.getHyperlinkTargetValue(getLinkTarget());
}
/**
*
*/
public void setHyperlinkTarget(HyperlinkTargetEnum hyperlinkTarget)
{
setLinkTarget(JRHyperlinkHelper.getLinkTarget(hyperlinkTarget));
}
/**
*
*/
public String getHyperlinkReference()
{
return hyperlinkReference;
}
/**
*
*/
public void setHyperlinkReference(String hyperlinkReference)
{
this.hyperlinkReference = hyperlinkReference;
}
/**
*
*/
public String getHyperlinkAnchor()
{
return hyperlinkAnchor;
}
/**
*
*/
public void setHyperlinkAnchor(String hyperlinkAnchor)
{
this.hyperlinkAnchor = hyperlinkAnchor;
}
/**
*
*/
public Integer getHyperlinkPage()
{
return hyperlinkPage;
}
/**
*
*/
public void setHyperlinkPage(Integer hyperlinkPage)
{
this.hyperlinkPage = hyperlinkPage;
}
/**
*
*/
public void setHyperlinkPage(String hyperlinkPage)
{
this.hyperlinkPage = Integer.valueOf(hyperlinkPage);
}
public int getBookmarkLevel()
{
return bookmarkLevel;
}
public void setBookmarkLevel(int bookmarkLevel)
{
this.bookmarkLevel = bookmarkLevel;
}
public JRPrintHyperlinkParameters getHyperlinkParameters()
{
return hyperlinkParameters;
}
public void setHyperlinkParameters(JRPrintHyperlinkParameters hyperlinkParameters)
{
this.hyperlinkParameters = hyperlinkParameters;
}
/**
* Adds a custom hyperlink parameter.
*
* @param parameter the parameter to add
* @see #getHyperlinkParameters()
* @see JRPrintHyperlinkParameters#addParameter(JRPrintHyperlinkParameter)
*/
public void addHyperlinkParameter(JRPrintHyperlinkParameter parameter)
{
if (hyperlinkParameters == null)
{
hyperlinkParameters = new JRPrintHyperlinkParameters();
}
hyperlinkParameters.addParameter(parameter);
}
public String getLinkType()
{
return linkType;
}
public void setLinkType(String linkType)
{
this.linkType = linkType;
}
public String getLinkTarget()
{
return linkTarget;
}
public void setLinkTarget(String linkTarget)
{
this.linkTarget = linkTarget;
}
public String getHyperlinkTooltip()
{
return hyperlinkTooltip;
}
public void setHyperlinkTooltip(String hyperlinkTooltip)
{
this.hyperlinkTooltip = hyperlinkTooltip;
}
/*
* These fields are only for serialization backward compatibility.
*/
private int PSEUDO_SERIAL_VERSION_UID = JRConstants.PSEUDO_SERIAL_VERSION_UID; //NOPMD
/**
* @deprecated
*/
private Byte horizontalAlignment;
/**
* @deprecated
*/
private Byte verticalAlignment;
/**
* @deprecated
*/
private Byte border;
/**
* @deprecated
*/
private Byte topBorder;
/**
* @deprecated
*/
private Byte leftBorder;
/**
* @deprecated
*/
private Byte bottomBorder;
/**
* @deprecated
*/
private Byte rightBorder;
/**
* @deprecated
*/
private Color borderColor;
/**
* @deprecated
*/
private Color topBorderColor;
/**
* @deprecated
*/
private Color leftBorderColor;
/**
* @deprecated
*/
private Color bottomBorderColor;
/**
* @deprecated
*/
private Color rightBorderColor;
/**
* @deprecated
*/
private Integer padding;
/**
* @deprecated
*/
private Integer topPadding;
/**
* @deprecated
*/
private Integer leftPadding;
/**
* @deprecated
*/
private Integer bottomPadding;
/**
* @deprecated
*/
private Integer rightPadding;
/**
* @deprecated
*/
private byte hyperlinkType;
/**
* @deprecated
*/
private byte hyperlinkTarget;
/**
* @deprecated
*/
private Byte scaleImage;
/**
* @deprecated
*/
private byte onErrorType;
/**
* @deprecated
*/
private net.sf.jasperreports.engine.JRRenderable renderer;
@SuppressWarnings("deprecation")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
in.defaultReadObject();
if (PSEUDO_SERIAL_VERSION_UID < JRConstants.PSEUDO_SERIAL_VERSION_UID_3_7_2)
{
horizontalAlignmentValue = HorizontalAlignEnum.getByValue(horizontalAlignment);
verticalAlignmentValue = VerticalAlignEnum.getByValue(verticalAlignment);
scaleImageValue = ScaleImageEnum.getByValue(scaleImage);
onErrorTypeValue = OnErrorTypeEnum.getByValue(onErrorType);
horizontalAlignment = null;
verticalAlignment = null;
scaleImage = null;
}
if (lineBox == null)
{
lineBox = new JRBaseLineBox(this);
JRBoxUtil.setToBox(
border,
topBorder,
leftBorder,
bottomBorder,
rightBorder,
borderColor,
topBorderColor,
leftBorderColor,
bottomBorderColor,
rightBorderColor,
padding,
topPadding,
leftPadding,
bottomPadding,
rightPadding,
lineBox
);
border = null;
topBorder = null;
leftBorder = null;
bottomBorder = null;
rightBorder = null;
borderColor = null;
topBorderColor = null;
leftBorderColor = null;
bottomBorderColor = null;
rightBorderColor = null;
padding = null;
topPadding = null;
leftPadding = null;
bottomPadding = null;
rightPadding = null;
}
if (linkType == null)
{
linkType = JRHyperlinkHelper.getLinkType(HyperlinkTypeEnum.getByValue(hyperlinkType));
}
if (linkTarget == null)
{
linkTarget = JRHyperlinkHelper.getLinkTarget(HyperlinkTargetEnum.getByValue(hyperlinkTarget));
}
if (renderer != null && renderable == null)
{
if (renderer instanceof Renderable)
{
renderable = (Renderable)renderer;
}
else
{
renderable = RenderableUtil.getWrappingRenderable(renderer);
}
}
}
public void accept(PrintElementVisitor visitor, T arg)
{
visitor.visit(this, arg);
}
}