net.sf.jasperreports.engine.fill.JRTemplateImage 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.fill;
import java.awt.Color;
import java.io.IOException;
import java.io.ObjectInputStream;
import net.sf.jasperreports.engine.JRAlignment;
import net.sf.jasperreports.engine.JRChart;
import net.sf.jasperreports.engine.JRCommonImage;
import net.sf.jasperreports.engine.JRConstants;
import net.sf.jasperreports.engine.JRDefaultStyleProvider;
import net.sf.jasperreports.engine.JRHyperlinkHelper;
import net.sf.jasperreports.engine.JRImage;
import net.sf.jasperreports.engine.JRLineBox;
import net.sf.jasperreports.engine.JROrigin;
import net.sf.jasperreports.engine.JRPen;
import net.sf.jasperreports.engine.base.JRBaseLineBox;
import net.sf.jasperreports.engine.base.JRBasePen;
import net.sf.jasperreports.engine.type.FillEnum;
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;
import net.sf.jasperreports.engine.util.ObjectUtils;
/**
* Image information shared by multiple print image objects.
*
* @author Teodor Danciu ([email protected])
* @version $Id: JRTemplateImage.java 5878 2013-01-07 20:23:13Z teodord $
* @see JRTemplatePrintImage
*/
public class JRTemplateImage extends JRTemplateGraphicElement implements JRAlignment, JRCommonImage
{
/**
*
*/
private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID;
/**
*
*/
private ScaleImageEnum scaleImageValue;
private Boolean isUsingCache = Boolean.TRUE;
private HorizontalAlignEnum horizontalAlignmentValue;
private VerticalAlignEnum verticalAlignmentValue;
protected boolean isLazy;
protected OnErrorTypeEnum onErrorTypeValue = OnErrorTypeEnum.ERROR;
private String linkType;
private String linkTarget;
/**
*
*/
private JRLineBox lineBox;
/**
*
*/
protected JRTemplateImage(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider, JRImage image)
{
super(origin, defaultStyleProvider);
setImage(image);
}
/**
*
*/
protected JRTemplateImage(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider, JRChart chart)
{
super(origin, defaultStyleProvider);
setChart(chart);
}
/**
* Creates a template image.
*
* @param origin the origin of the elements that will use this template
* @param defaultStyleProvider the default style provider to use for
* this template
*/
public JRTemplateImage(JROrigin origin, JRDefaultStyleProvider defaultStyleProvider)
{
super(origin, defaultStyleProvider);
this.lineBox = new JRBaseLineBox(this);
this.linePen = new JRBasePen(this);
}
/**
*
*/
protected void setImage(JRImage image)
{
super.setGraphicElement(image);
lineBox = image.getLineBox().clone(this);
setScaleImage(image.getScaleImageValue());
setUsingCache(image.getUsingCache());
setHorizontalAlignment(image.getHorizontalAlignmentValue());
setVerticalAlignment(image.getVerticalAlignmentValue());
setLazy(image.isLazy());
setOnErrorType(image.getOnErrorTypeValue());
setLinkType(image.getLinkType());
setLinkTarget(image.getLinkTarget());
}
/**
*
*/
protected void setChart(JRChart chart)
{
super.setElement(chart);
linePen = new JRBasePen(this);
getLinePen().setLineWidth(0f);
setFill(FillEnum.SOLID);
copyLineBox(chart.getLineBox());
setLinkType(chart.getLinkType());
setLinkTarget(chart.getLinkTarget());
}
/**
* Copies box attributes.
*
* @param box the object to copy attributes from
*/
public void copyLineBox(JRLineBox box)
{
this.lineBox = box.clone(this);
}
/**
*
*/
public JRLineBox getLineBox()
{
return lineBox;
}
/**
*
*/
public ModeEnum getModeValue()
{
return JRStyleResolver.getMode(this, ModeEnum.TRANSPARENT);
}
/**
*
*/
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 void setUsingCache(Boolean isUsingCache)
{
this.isUsingCache = isUsingCache;
}
/**
*
*/
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;
}
/**
* Retrieves the hyperlink type for the element.
*
* The actual hyperlink type is determined by {@link #getLinkType() getLinkType()}.
* This method can is used to determine whether the hyperlink type is one of the
* built-in types or a custom type.
* When hyperlink is of custom type, {@link HyperlinkTypeEnum#CUSTOM CUSTOM} is returned.
*
* @return one of the hyperlink type constants
* @see #getLinkType()
*/
public HyperlinkTypeEnum getHyperlinkTypeValue()
{
return JRHyperlinkHelper.getHyperlinkTypeValue(getLinkType());
}
/**
* Sets the link type as a built-in hyperlink type.
*
* @param hyperlinkType the built-in hyperlink type
* @see #getLinkType()
*/
protected void setHyperlinkType(HyperlinkTypeEnum hyperlinkType)
{
setLinkType(JRHyperlinkHelper.getLinkType(hyperlinkType));
}
/**
*
*/
public HyperlinkTargetEnum getHyperlinkTargetValue()
{
return JRHyperlinkHelper.getHyperlinkTargetValue(getLinkTarget());
}
/**
*
*/
protected void setHyperlinkTarget(HyperlinkTargetEnum hyperlinkTarget)
{
setLinkTarget(JRHyperlinkHelper.getLinkTarget(hyperlinkTarget));
}
/**
* Returns the hyperlink target name.
*
* The target name can be one of the built-in names
* (Self, Blank, Top, Parent),
* or can be an arbitrary name.
*
* @return the hyperlink type
*/
public String getLinkTarget()
{
return linkTarget;
}
/**
* Sets the hyperlink target name.
*
* The target name can be one of the built-in names
* (Self, Blank, Top, Parent),
* or can be an arbitrary name.
*
* @param linkTarget the hyperlink target name
*/
public void setLinkTarget(String linkTarget)
{
this.linkTarget = linkTarget;
}
/**
* Returns the hyperlink type.
*
* The type can be one of the built-in types
* (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
* or can be an arbitrary type.
*
* @return the hyperlink type
*/
public String getLinkType()
{
return linkType;
}
/**
* Sets the hyperlink type.
*
* The type can be one of the built-in types
* (Reference, LocalAnchor, LocalPage, RemoteAnchor, RemotePage),
* or can be an arbitrary type.
*
* @param linkType the hyperlink type
*/
public void setLinkType(String linkType)
{
this.linkType = linkType;
}
/**
*
*/
public Float getDefaultLineWidth()
{
return JRPen.LINE_WIDTH_0;
}
/*
* 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;
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));
}
}
public int getHashCode()
{
ObjectUtils.HashCode hash = ObjectUtils.hash();
addGraphicHash(hash);
hash.add(scaleImageValue);
hash.add(isUsingCache);
hash.add(horizontalAlignmentValue);
hash.add(verticalAlignmentValue);
hash.add(isLazy);
hash.add(onErrorTypeValue);
hash.add(linkType);
hash.add(linkTarget);
hash.addIdentical(lineBox);
return hash.getHashCode();
}
public boolean isIdentical(Object object)
{
if (this == object)
{
return true;
}
if (!(object instanceof JRTemplateImage))
{
return false;
}
JRTemplateImage template = (JRTemplateImage) object;
return graphicIdentical(template)
&& ObjectUtils.equals(scaleImageValue, template.scaleImageValue)
&& ObjectUtils.equals(isUsingCache, template.isUsingCache)
&& ObjectUtils.equals(horizontalAlignmentValue, template.horizontalAlignmentValue)
&& ObjectUtils.equals(verticalAlignmentValue, template.verticalAlignmentValue)
&& ObjectUtils.equals(isLazy, template.isLazy)
&& ObjectUtils.equals(onErrorTypeValue, template.onErrorTypeValue)
&& ObjectUtils.equals(linkType, template.linkType)
&& ObjectUtils.equals(linkTarget, template.linkTarget)
&& ObjectUtils.identical(lineBox, template.lineBox);
}
}