[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf/ui ...
Norman Richards
norman.richards at jboss.com
Thu Dec 20 23:51:46 EST 2007
User: nrichards
Date: 07/12/20 23:51:46
Modified: src/pdf/org/jboss/seam/pdf/ui UIDocument.java
Added: src/pdf/org/jboss/seam/pdf/ui UIGraphics2D.java
UISwingComponent.java
Log:
JBSEAM-2414
Revision Changes Path
1.28 +6 -1 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIDocument.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIDocument.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- UIDocument.java 20 Dec 2007 23:55:38 -0000 1.27
+++ UIDocument.java 21 Dec 2007 04:51:46 -0000 1.28
@@ -303,6 +303,11 @@
return writer;
}
+ public PdfTemplate createPdfTemplate(float width, float height) {
+ PdfWriter writer = (PdfWriter) getWriter();
+ return writer.getDirectContent().createTemplate(width, height);
+ }
+
private DocumentType documentTypeForName(String typeName) {
if (typeName != null) {
if (typeName.equalsIgnoreCase("pdf")) {
1.1 date: 2007/12/21 04:51:46; author: nrichards; state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIGraphics2D.java
Index: UIGraphics2D.java
===================================================================
package org.jboss.seam.pdf.ui;
import java.awt.Graphics2D;
import javax.faces.context.FacesContext;
import com.lowagie.text.BadElementException;
import com.lowagie.text.Image;
import com.lowagie.text.ImgTemplate;
import com.lowagie.text.pdf.PdfTemplate;
public abstract class UIGraphics2D
extends ITextComponent
{
private Image image = null;
private int height = 300;
private int width = 400;
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return (Integer) valueBinding("height", height);
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return (Integer) valueBinding("width", width);
}
@Override
public void createITextObject(FacesContext context) {
UIDocument doc = (UIDocument) findITextParent(getParent(), UIDocument.class);
if (doc != null) {
PdfTemplate tp = doc.createPdfTemplate(getWidth(), getHeight());
Graphics2D g2 = tp.createGraphics(getWidth(), getHeight());
render(g2);
g2.dispose();
try {
image = new ImgTemplate(tp);
} catch (BadElementException e) {
throw new RuntimeException(e);
}
}
}
public abstract void render(Graphics2D g2);
@Override
public void handleAdd(Object arg0) {
throw new RuntimeException("No children allowed");
}
@Override
public void removeITextObject() {
image = null;
}
@Override
public Object getITextObject() {
return image;
}
}
1.1 date: 2007/12/21 04:51:46; author: nrichards; state: Exp;jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UISwingComponent.java
Index: UISwingComponent.java
===================================================================
package org.jboss.seam.pdf.ui;
import java.awt.Component;
import java.awt.Graphics2D;
public class UISwingComponent extends UIGraphics2D {
private Component component;
public void setComponent(Component component) {
this.component = component;
}
public Component getComponent() {
return (Component) valueBinding("component", component);
}
@Override
public void render(Graphics2D g2) {
// don't use the component variable directly!
// we need to check for the valueBinding
Component component = getComponent();
if (component == null) {
throw new RuntimeException("Component was null");
}
System.out.println("component is " + component + " " +
component.getWidth() + "x" + component.getHeight());
// setSize() is very important. The default size
// for this component is zero, which means it will not display
// unless the size is set
component.setSize(getWidth(), getHeight());
System.out.println("component is " + component + " " +
component.getWidth() + "x" + component.getHeight());
component.paint(g2);
System.out.println("g2=" + g2);
}
}
More information about the jboss-cvs-commits
mailing list