[jboss-user] [JBoss Seam] - Re: Request for PDF p:element tag
dustismo
do-not-reply at jboss.com
Mon Apr 9 20:18:05 EDT 2007
Norman,
Many thanks for implementing this. Unfortunately it doesn't work for my purpose. I forgot that I needed access to the DocWriter in order to draw the graph onto the pdf. The element tag may end up being useful for other purposes though.
I extended ITextComponent to create a simple tag to renderer JFreeCharts. Possibly someone will find it useful.
| public class PdfGraph extends ITextComponent {
|
| JFreeChart graph = null;
| Element element = null;
| float height;
| float width;
|
| /**
| *
| */
| public PdfGraph() {
|
| }
|
| public void setValue(JFreeChart graph) {
| this.graph = graph;
| }
|
| /* (non-Javadoc)
| * @see org.jboss.seam.pdf.ui.ITextComponent#createITextObject(javax.faces.context.FacesContext)
| */
| @Override
| public void createITextObject(FacesContext context) {
| graph = (JFreeChart) valueBinding(context, "value", graph);
| height = (Float) valueBinding(context, "height", height);
| width = (Float) valueBinding(context, "width", width);
|
| UIDocument doc = (UIDocument)this.findITextParent(this, UIDocument.class);
| DocWriter writer = doc.getWriter();
|
| if (writer instanceof PdfWriter) {
| try {
| PdfContentByte cb = ((PdfWriter)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);
| this.graph.draw(g2d, r2d);
| g2d.dispose();
| this.element = new ImgTemplate(tp);
| } catch (Exception x) {
| x.printStackTrace();
| }
| }
| }
|
|
| /* (non-Javadoc)
| * @see org.jboss.seam.pdf.ui.ITextComponent#getITextObject()
| */
| @Override
| public Object getITextObject() {
| return element;
| }
|
| /* (non-Javadoc)
| * @see org.jboss.seam.pdf.ui.ITextComponent#handleAdd(java.lang.Object)
| */
| @Override
| public void handleAdd(Object arg0) {
| throw new RuntimeException("No children allowed");
| }
|
| /* (non-Javadoc)
| * @see org.jboss.seam.pdf.ui.ITextComponent#removeITextObject()
| */
| @Override
| public void removeITextObject() {
| element = null;
| }
|
| public float getHeight() {
| return this.height;
| }
|
| public void setHeight(float height) {
| this.height = height;
| }
|
| public float getWidth() {
| return this.width;
| }
|
| public void setWidth(float width) {
| this.width = width;
| }
|
| }
thanks,
Dustin
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4035837#4035837
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4035837
More information about the jboss-user
mailing list