/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.itext.text.pdf;
import com.lowagie.text.DocumentException;
import com.lowagie.text.LwgImage;
import com.lowagie.text.pdf.LwgPdfPCell;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import org.geoforge.java.lang.number.GfrUtilFloat;
/**
*
* @author user
*/
public class GfrHeader extends GfrPdfPTable
{
private LwgPdfPCell _cellLogo_ = null;
protected LwgPdfPCell _cellText = null;
protected float _fltHeight = GfrUtilFloat.NDV;
protected float _fltWidthImage_ = GfrUtilFloat.NDV;
protected float _fltHeightImage_ = GfrUtilFloat.NDV;
private float _fltWidth_ = GfrUtilFloat.NDV;
public GfrHeader(
ImageIcon iin,
int size,
float fltWidth,
float fltHeight) throws Exception
{
super(size);
this._fltWidth_ = fltWidth;
this._fltHeight = fltHeight;
if (iin != null)
{
LwgImage img = LwgImage.getInstance(
iin.getImage(),
null,
false);
/*
* There is a bug with iin.getIconHeight()/Width :
* when creating new ImageIcon(strPath); there is something note updated
* related to image = Toolkit.getDefaultToolkit().getImage(filename);
* that provides the old image even if the image has been changed.
*
* Taking the width/height from Lowagie images solves the problem.
*/
this._fltWidthImage_ = img.getWidth();
this._fltHeightImage_ = img.getHeight();//iin.getIconHeight();
this._cellLogo_ = new LwgPdfPCell(
img,//force BW
true// fit to cell
);
}
else
this._cellLogo_ = new LwgPdfPCell();
}
@Override
public boolean init()
{
if (!super.init())
return false;
super.setWidthPercentage(100);
super.getDefaultCell().setBorderWidth(0);
super.getDefaultCell().setPadding(5);
this._cellLogo_.setFixedHeight(this._fltHeight);
super.add(this._cellLogo_);
float fltRelativeWithLogo = GfrUtilFloat.NDV;
if (_fltHeightImage_ != GfrUtilFloat.NDV && _fltWidthImage_ != GfrUtilFloat.NDV)
{
float fltScale = _fltHeight / _fltHeightImage_;
float fltWidthLogo = _fltWidthImage_ * fltScale;
fltRelativeWithLogo = fltWidthLogo / _fltWidth_;
}
else
{
fltRelativeWithLogo = 0.3f;
}
//Keek at leats 60% width for text if logo has a huge width
if (fltRelativeWithLogo > 0.4)
{
fltRelativeWithLogo = 0.4f;
}
float[] fltsRelativeWiths =
{
fltRelativeWithLogo,
1f - fltRelativeWithLogo
};
try
{
super.setWidths(fltsRelativeWiths);
}
catch (DocumentException ex)
{
Logger.getLogger(GfrHeader.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
}
@Override
public void destroy()
{
super.destroy();
}
}