01: package com.technoetic.xplanner.tags;
02:
03: import de.laures.cewolf.ChartImage;
04: import de.laures.cewolf.CewolfException;
05: import de.laures.cewolf.taglib.tags.ChartImgTag;
06: import de.laures.cewolf.util.RenderingException;
07:
08: import java.io.BufferedOutputStream;
09: import java.io.ByteArrayOutputStream;
10: import java.io.IOException;
11:
12: /**
13: * Created by IntelliJ IDEA.
14: * User: tkmower
15: * Date: Jun 11, 2004
16: * Time: 4:50:56 PM
17: */
18: public class CewolfProgressBarChartImage implements ChartImage {
19: private ProgressBarImage image;
20: private byte[] bytes;
21:
22: public CewolfProgressBarChartImage(ProgressBarImage image) {
23: this .image = image;
24: }
25:
26: public int getWidth() {
27: return image.getWidth();
28: }
29:
30: public int getHeight() {
31: return image.getHeight();
32: }
33:
34: public int getType() {
35: return IMG_TYPE_CHART;
36: }
37:
38: public byte[] getBytes() throws CewolfException {
39: if (bytes == null)
40: bytes = render();
41: return bytes;
42: }
43:
44: private byte[] render() throws RenderingException {
45: ByteArrayOutputStream baos = new ByteArrayOutputStream();
46: BufferedOutputStream bos = new BufferedOutputStream(baos);
47: try {
48: image.encodeJPEG(bos, 0.75f);
49: } catch (IOException e) {
50: throw new RenderingException(e);
51: }
52: return baos.toByteArray();
53: }
54:
55: public String getMimeType() {
56: return ChartImgTag.MIME_PNG;
57: }
58:
59: public int getSize() throws CewolfException {
60: return getBytes().length;
61: }
62: }
|