[jboss-cvs] jboss-seam/src/pdf/org/jboss/seam/pdf/ui ...
Norman Richards
norman.richards at jboss.com
Tue May 15 22:42:29 EDT 2007
User: nrichards
Date: 07/05/15 22:42:29
Modified: src/pdf/org/jboss/seam/pdf/ui ITextComponent.java
UIBarCode.java
Log:
add barcode jpeg generation
Revision Changes Path
1.15 +7 -4 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/ITextComponent.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ITextComponent.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/ITextComponent.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- ITextComponent.java 3 May 2007 02:33:12 -0000 1.14
+++ ITextComponent.java 16 May 2007 02:42:29 -0000 1.15
@@ -107,10 +107,13 @@
if (parent != null) {
parent.add(obj);
} else {
- throw new RuntimeException("Couldn't find ITextComponent parent for component " +
- this.getClass().getName());
+ noITextParentFound();
+ }
}
+ public void noITextParentFound() {
+ throw new RuntimeException("Couldn't find ITextComponent parent for component " +
+ this.getClass().getName());
}
public Object processFacet(String facetName) {
1.2 +84 -53 jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIBarCode.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UIBarCode.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/pdf/org/jboss/seam/pdf/ui/UIBarCode.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- UIBarCode.java 14 May 2007 18:27:56 -0000 1.1
+++ UIBarCode.java 16 May 2007 02:42:29 -0000 1.2
@@ -1,9 +1,22 @@
package org.jboss.seam.pdf.ui;
import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.image.BufferedImage;
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.imageio.ImageIO;
+import org.jboss.seam.core.Manager;
+import org.jboss.seam.core.Image.Type;
import org.jboss.seam.pdf.ui.ITextComponent;
+import org.jboss.seam.ui.graphicImage.GraphicImageResource;
+import org.jboss.seam.ui.graphicImage.GraphicImageStore;
+import org.jboss.seam.ui.graphicImage.GraphicImageStore.ImageWrapper;
import com.lowagie.text.Image;
import com.lowagie.text.pdf.*;
@@ -29,117 +42,93 @@
private Float minBarWidth;
private Float barMultiplier;
-
-
- public String getCode()
- {
+ public String getCode() {
return code;
}
- public void setCode(String code)
- {
+ public void setCode(String code) {
this.code = code;
}
- public String getType()
- {
+ public String getType() {
return type;
}
- public void setType(String type)
- {
+ public void setType(String type) {
this.type = type;
}
- public Float getRotDegrees()
- {
+ public Float getRotDegrees(){
return rotDegrees;
}
- public void setRotDegrees(Float rotDegrees)
- {
+ public void setRotDegrees(Float rotDegrees) {
this.rotDegrees = rotDegrees;
}
- public Float getXpos()
- {
+ public Float getXpos() {
return xpos;
}
- public void setXpos(Float xpos)
- {
+ public void setXpos(Float xpos) {
this.xpos = xpos;
}
- public Float getYpos()
- {
+ public Float getYpos() {
return ypos;
}
- public void setYpos(Float ypos)
- {
+ public void setYpos(Float ypos) {
this.ypos = ypos;
}
- public String getAltText()
- {
+ public String getAltText() {
return altText;
}
- public void setAltText(String altText)
- {
+ public void setAltText(String altText) {
this.altText = altText;
}
- public Float getBarHeight()
- {
+ public Float getBarHeight() {
return barHeight;
}
- public void setBarHeight(Float barHeight)
- {
+ public void setBarHeight(Float barHeight) {
this.barHeight = barHeight;
}
- public Float getBarMultiplier()
- {
+ public Float getBarMultiplier() {
return barMultiplier;
}
- public void setBarMultiplier(Float barMultiplier)
- {
+ public void setBarMultiplier(Float barMultiplier) {
this.barMultiplier = barMultiplier;
}
- public Float getMinBarWidth()
- {
+ public Float getMinBarWidth() {
return minBarWidth;
}
- public void setMinBarWidth(Float minBarWidth)
- {
+ public void setMinBarWidth(Float minBarWidth) {
this.minBarWidth = minBarWidth;
}
- public Float getTextSize()
- {
+ public Float getTextSize() {
return textSize;
}
- public void setTextSize(Float textSize)
- {
+ public void setTextSize(Float textSize) {
this.textSize = textSize;
}
@Override
- public Object getITextObject()
- {
+ public Object getITextObject() {
return image;
}
@Override
- public void createITextObject(FacesContext context)
- {
+ public void createITextObject(FacesContext context) {
type = (String) valueBinding(context, "type", type);
if (type != null) {
if (type.equalsIgnoreCase("code128")) {
@@ -182,8 +171,7 @@
}
minBarWidth = (Float) valueBinding(context, "minBarWidth", minBarWidth);
- if (minBarWidth != null)
- {
+ if (minBarWidth != null) {
barcode.setX(minBarWidth);
}
@@ -206,14 +194,57 @@
}
@Override
- public void removeITextObject()
- {
+ public void removeITextObject() {
image = null;
}
@Override
- public void handleAdd(Object other)
- {
+ public void handleAdd(Object other) {
throw new RuntimeException("can't add " + other.getClass().getName() + " to barcode");
}
+
+
+
+
+ public static byte[] imageToByteArray(java.awt.Image image)
+ throws IOException
+ {
+ BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
+ image.getHeight(null),
+ BufferedImage.TYPE_INT_RGB);
+ Graphics gc = bufferedImage.createGraphics();
+ gc.drawImage(image, 0, 0, null);
+
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ ImageIO.write(bufferedImage, "jpeg", stream);
+
+ return stream.toByteArray();
+ }
+
+ @Override
+ public void noITextParentFound() {
+ try {
+ FacesContext context = FacesContext.getCurrentInstance();
+ ResponseWriter response = context.getResponseWriter();
+ response.startElement("img", null);
+ GraphicImageStore store = GraphicImageStore.instance();
+
+
+ byte[] imageData = imageToByteArray(barcode.createAwtImage(Color.BLACK, Color.WHITE));
+
+
+ String key = store.put(new ImageWrapper(imageData, Type.IMAGE_JPEG));
+ String url = context.getExternalContext().getRequestContextPath() +
+ GraphicImageResource.GRAPHIC_IMAGE_RESOURCE_PATH + "/" + key + Type.IMAGE_JPEG.getExtension();
+
+ response.writeAttribute("src", url, null);
+
+ response.endElement("img");
+
+ Manager.instance().beforeRedirect();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
More information about the jboss-cvs-commits
mailing list