Author: dsvyatobatsko
Date: 2008-01-11 06:33:59 -0500 (Fri, 11 Jan 2008)
New Revision: 5294
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java
Log:
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java 2008-01-11
11:14:04 UTC (rev 5293)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/resource/AnimationResource.java 2008-01-11
11:33:59 UTC (rev 5294)
@@ -23,17 +23,10 @@
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
-import java.awt.image.RenderedImage;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Arrays;
-import javax.faces.FacesException;
-import javax.imageio.ImageIO;
-
-import org.ajax4jsf.Messages;
import org.ajax4jsf.resource.image.animatedgif.AnimatedGifEncoder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -68,35 +61,21 @@
private int currFrameIndex = 0;
public void send(ResourceContext context) throws IOException {
- ImageRenderer renderer = (ImageRenderer) getRenderer(null);
try {
- RenderedImage image = getImage(context);
- if (null != image) {
- renderer.sendImage(context, image);
-
- }
- } catch (Exception e) {
- throw new FacesException(Messages
- .getMessage(Messages.SEND_IMAGE_ERROR_2), e);
- }
- }
-
- protected RenderedImage getImage(ResourceContext context) {
- ImageRenderer renderer = (ImageRenderer) getRenderer(null);
- Dimension frameSize = getFrameSize(context);
- int numberOfFrames = getNumberOfFrames();
- BufferedImage frame = null;
- if (frameSize.getHeight() > 0.0 && frameSize.getWidth() > 0.0
- && numberOfFrames > 0) {
- AnimatedGifEncoder encoder = new AnimatedGifEncoder();
- FileOutputStream resultOutputStream;
- try {
- resultOutputStream = new FileOutputStream("result.gif");
- encoder.start(resultOutputStream);
+ DataOutputStream output = new DataOutputStream(context.getOutputStream());
+ Dimension frameSize = getFrameSize(context);
+ int numberOfFrames = getNumberOfFrames();
+ BufferedImage frame = null;
+ if (frameSize.getHeight() > 0.0 && frameSize.getWidth() > 0.0
+ && numberOfFrames > 0) {
+ AnimatedGifEncoder encoder = new AnimatedGifEncoder();
+ encoder.start(output);
encoder.setRepeat(getRepeat());
int[] delays = getFrameDelays();
+ ImageRenderer renderer = (ImageRenderer) getRenderer(null);
while (currFrameIndex < numberOfFrames) {
- frame = renderer.createImage(frameSize.width, frameSize.height);
+ frame = renderer.createImage(frameSize.width,
+ frameSize.height);
Graphics2D graphics = frame.createGraphics();
paint(context, graphics, currFrameIndex++);
graphics.dispose();
@@ -106,25 +85,13 @@
}
}
encoder.finish();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
- }
-
- BufferedImage retVal = null;
-
- try {
- retVal = ImageIO.read(new FileInputStream("result.gif"));
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ output.flush();
+ output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
-
- return retVal;
}
protected abstract void paint(ResourceContext context, Graphics2D graphics2D, int
frameIndex);
Show replies by date