/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.lowagie.geoforge.text.pdf;
import com.lowagie.text.Chunk;
import com.lowagie.text.LwgImage;
import com.lowagie.text.LwgPhrase;
import com.lowagie.text.pdf.DefaultFontMapper;
import com.lowagie.text.pdf.LwgPdfPCell;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.LwgPdfPTable;
import com.lowagie.text.pdf.PdfTemplate;
import com.lowagie.text.pdf.PdfWriter;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.io.FileOutputStream;
import org.jfree.chart.JFreeChart;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrPdfPCell extends LwgPdfPCell
{
public GfrPdfPCell(LwgPdfPCell cell)
{
super(cell);
}
public GfrPdfPCell(LwgPdfPTable table, LwgPdfPCell style)
{
super(table, style);
}
public GfrPdfPCell(LwgPdfPTable table)
{
super(table);
}
public GfrPdfPCell(LwgImage image, boolean fit)
{
super(image, fit);
}
public GfrPdfPCell(LwgImage image)
{
super(image);
}
public GfrPdfPCell(LwgPhrase phrase)
{
super(phrase);
}
public GfrPdfPCell(LwgPhrase phrase, int horizontalAlignment)
{
this(phrase);
super.setHorizontalAlignment(horizontalAlignment);
}
public GfrPdfPCell(
LwgPhrase phrase,
int horizontalAlignment,
int intRowSpan)
{
this(
phrase,
horizontalAlignment);
super.setHorizontalAlignment(horizontalAlignment);
}
public GfrPdfPCell()
{
super();
}
public void setChart(
JFreeChart chart,
PdfWriter writer,
float fltX,
float fltY,
float fltWidth,
float fltHeight)
{
int width = (int)(fltWidth);
int height = (int)(fltHeight);
// step 4
PdfContentByte cb = writer.getDirectContent();
PdfTemplate tp = cb.createTemplate(width, height);
Graphics2D g2d = tp.createGraphics(width, height, new DefaultFontMapper());
Rectangle2D r2d = new Rectangle2D.Double(0, 0, width, height);
chart.draw(g2d, r2d);
g2d.dispose();
tp.sanityCheck();
cb.addTemplate(tp, fltX, fltY);
cb.sanityCheck();
}
}