franta-hg@1
|
1 |
/* ================================================================
|
franta-hg@1
|
2 |
* Cewolf : Chart enabling Web Objects Framework
|
franta-hg@1
|
3 |
* ================================================================
|
franta-hg@1
|
4 |
*
|
franta-hg@1
|
5 |
* Project Info: http://cewolf.sourceforge.net
|
franta-hg@1
|
6 |
* Project Lead: Guido Laures (guido@laures.de);
|
franta-hg@1
|
7 |
*
|
franta-hg@1
|
8 |
* (C) Copyright 2002, by Guido Laures
|
franta-hg@1
|
9 |
*
|
franta-hg@1
|
10 |
* This library is free software; you can redistribute it and/or modify it under the terms
|
franta-hg@1
|
11 |
* of the GNU Lesser General Public License as published by the Free Software Foundation;
|
franta-hg@1
|
12 |
* either version 2.1 of the License, or (at your option) any later version.
|
franta-hg@1
|
13 |
*
|
franta-hg@1
|
14 |
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
franta-hg@1
|
15 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
franta-hg@1
|
16 |
* See the GNU Lesser General Public License for more details.
|
franta-hg@1
|
17 |
*
|
franta-hg@1
|
18 |
* You should have received a copy of the GNU Lesser General Public License along with this
|
franta-hg@1
|
19 |
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
franta-hg@1
|
20 |
* Boston, MA 02111-1307, USA.
|
franta-hg@1
|
21 |
*/
|
franta-hg@1
|
22 |
|
franta-hg@1
|
23 |
package de.laures.cewolf.taglib;
|
franta-hg@1
|
24 |
|
franta-hg@1
|
25 |
import java.io.Serializable;
|
franta-hg@1
|
26 |
import java.util.Calendar;
|
franta-hg@1
|
27 |
import java.util.Date;
|
franta-hg@1
|
28 |
import java.util.GregorianCalendar;
|
franta-hg@1
|
29 |
|
franta-hg@1
|
30 |
import org.apache.commons.logging.Log;
|
franta-hg@1
|
31 |
import org.apache.commons.logging.LogFactory;
|
franta-hg@1
|
32 |
|
franta-hg@1
|
33 |
import de.laures.cewolf.CewolfException;
|
franta-hg@1
|
34 |
import de.laures.cewolf.ChartHolder;
|
franta-hg@1
|
35 |
import de.laures.cewolf.ChartImage;
|
franta-hg@1
|
36 |
import de.laures.cewolf.ChartValidationException;
|
franta-hg@1
|
37 |
import de.laures.cewolf.DatasetProduceException;
|
franta-hg@1
|
38 |
import de.laures.cewolf.PostProcessingException;
|
franta-hg@1
|
39 |
import de.laures.cewolf.event.ChartImageRenderListener;
|
franta-hg@1
|
40 |
import de.laures.cewolf.util.RenderedImage;
|
franta-hg@1
|
41 |
import de.laures.cewolf.util.Renderer;
|
franta-hg@1
|
42 |
|
franta-hg@1
|
43 |
/**
|
franta-hg@1
|
44 |
* Serializable implementaton of a ChartImage.
|
franta-hg@1
|
45 |
* @author glaures
|
franta-hg@1
|
46 |
* @see de.laures.cewolf.ChartImage
|
franta-hg@1
|
47 |
*/
|
franta-hg@1
|
48 |
public class ChartImageDefinition implements ChartImage, ChartHolder, Serializable {
|
franta-hg@1
|
49 |
|
franta-hg@1
|
50 |
private static final Log log = LogFactory.getLog(ChartImageDefinition.class);
|
franta-hg@1
|
51 |
|
franta-hg@1
|
52 |
private final ChartHolder chartHolder;
|
franta-hg@1
|
53 |
private final int height;
|
franta-hg@1
|
54 |
private final int width;
|
franta-hg@1
|
55 |
private final int type;
|
franta-hg@1
|
56 |
private final String mimeType;
|
franta-hg@1
|
57 |
transient private final Date timeoutTime;
|
franta-hg@1
|
58 |
|
franta-hg@1
|
59 |
private RenderedImage renderedImage;
|
franta-hg@1
|
60 |
|
franta-hg@1
|
61 |
/**
|
franta-hg@1
|
62 |
* Constructor for ChartImage
|
franta-hg@1
|
63 |
*/
|
franta-hg@1
|
64 |
public ChartImageDefinition(ChartHolder ch, int width, int height, int type, String mimeType, int timeout) {
|
franta-hg@1
|
65 |
if(width <= 0 || height <= 0){
|
franta-hg@1
|
66 |
throw new IllegalArgumentException("ChartImage with height or width <= 0 is illegal");
|
franta-hg@1
|
67 |
}
|
franta-hg@1
|
68 |
this.chartHolder = ch;
|
franta-hg@1
|
69 |
this.width = width;
|
franta-hg@1
|
70 |
this.height = height;
|
franta-hg@1
|
71 |
this.type = type;
|
franta-hg@1
|
72 |
this.mimeType = mimeType;
|
franta-hg@1
|
73 |
Calendar cal = new GregorianCalendar();
|
franta-hg@1
|
74 |
cal.add(Calendar.SECOND,timeout);
|
franta-hg@1
|
75 |
this.timeoutTime = cal.getTime();
|
franta-hg@1
|
76 |
}
|
franta-hg@1
|
77 |
|
franta-hg@1
|
78 |
/**
|
franta-hg@1
|
79 |
* Returns the height.
|
franta-hg@1
|
80 |
* @return int
|
franta-hg@1
|
81 |
*/
|
franta-hg@1
|
82 |
public int getHeight() {
|
franta-hg@1
|
83 |
return height;
|
franta-hg@1
|
84 |
}
|
franta-hg@1
|
85 |
|
franta-hg@1
|
86 |
/**
|
franta-hg@1
|
87 |
* Returns the width.
|
franta-hg@1
|
88 |
* @return int
|
franta-hg@1
|
89 |
*/
|
franta-hg@1
|
90 |
public int getWidth() {
|
franta-hg@1
|
91 |
return width;
|
franta-hg@1
|
92 |
}
|
franta-hg@1
|
93 |
|
franta-hg@1
|
94 |
public int getType() {
|
franta-hg@1
|
95 |
return type;
|
franta-hg@1
|
96 |
}
|
franta-hg@1
|
97 |
|
franta-hg@1
|
98 |
public Object getChart() throws DatasetProduceException, ChartValidationException, PostProcessingException {
|
franta-hg@1
|
99 |
return chartHolder.getChart();
|
franta-hg@1
|
100 |
}
|
franta-hg@1
|
101 |
|
franta-hg@1
|
102 |
public Object getDataset() throws DatasetProduceException {
|
franta-hg@1
|
103 |
return chartHolder.getDataset();
|
franta-hg@1
|
104 |
}
|
franta-hg@1
|
105 |
|
franta-hg@1
|
106 |
/**
|
franta-hg@1
|
107 |
* Returns the mimeType.
|
franta-hg@1
|
108 |
* @return String
|
franta-hg@1
|
109 |
*/
|
franta-hg@1
|
110 |
public String getMimeType() {
|
franta-hg@1
|
111 |
return mimeType;
|
franta-hg@1
|
112 |
}
|
franta-hg@1
|
113 |
|
franta-hg@1
|
114 |
/**
|
franta-hg@1
|
115 |
* @see java.lang.Object#finalize()
|
franta-hg@1
|
116 |
*/
|
franta-hg@1
|
117 |
protected void finalize() throws Throwable {
|
franta-hg@1
|
118 |
super.finalize();
|
franta-hg@1
|
119 |
log.debug(this + " finalized.");
|
franta-hg@1
|
120 |
}
|
franta-hg@1
|
121 |
|
franta-hg@1
|
122 |
/**
|
franta-hg@1
|
123 |
* @see de.laures.cewolf.ChartImage#getRenderingInfo()
|
franta-hg@1
|
124 |
*/
|
franta-hg@1
|
125 |
public Object getRenderingInfo() throws CewolfException {
|
franta-hg@1
|
126 |
ensureRendered();
|
franta-hg@1
|
127 |
return renderedImage.renderingInfo;
|
franta-hg@1
|
128 |
}
|
franta-hg@1
|
129 |
|
franta-hg@1
|
130 |
public byte[] getBytes() throws CewolfException{
|
franta-hg@1
|
131 |
ensureRendered();
|
franta-hg@1
|
132 |
return renderedImage.data;
|
franta-hg@1
|
133 |
}
|
franta-hg@1
|
134 |
|
franta-hg@1
|
135 |
private void ensureRendered() throws CewolfException{
|
franta-hg@1
|
136 |
if(renderedImage == null){
|
franta-hg@1
|
137 |
renderedImage = Renderer.render(this, chartHolder.getChart());
|
franta-hg@1
|
138 |
onImageRendered(renderedImage);
|
franta-hg@1
|
139 |
}
|
franta-hg@1
|
140 |
}
|
franta-hg@1
|
141 |
|
franta-hg@1
|
142 |
/**
|
franta-hg@1
|
143 |
* @see de.laures.cewolf.ChartImage#getSize()
|
franta-hg@1
|
144 |
*/
|
franta-hg@1
|
145 |
public int getSize() throws CewolfException {
|
franta-hg@1
|
146 |
ensureRendered();
|
franta-hg@1
|
147 |
return renderedImage.data.length;
|
franta-hg@1
|
148 |
}
|
franta-hg@1
|
149 |
|
franta-hg@1
|
150 |
/* (non-Javadoc)
|
franta-hg@1
|
151 |
* @see de.laures.cewolf.ChartImage#getTimeoutTime()
|
franta-hg@1
|
152 |
*/
|
franta-hg@1
|
153 |
public Date getTimeoutTime() {
|
franta-hg@1
|
154 |
return timeoutTime;
|
franta-hg@1
|
155 |
}
|
franta-hg@1
|
156 |
|
franta-hg@1
|
157 |
/**
|
franta-hg@1
|
158 |
* Implemented onImageRendered method.
|
franta-hg@1
|
159 |
* @see de.laures.cewolf.ChartHolder#onImageRendered(de.laures.cewolf.util.RenderedImage).
|
franta-hg@1
|
160 |
* @param renderedImage The image
|
franta-hg@1
|
161 |
*/
|
franta-hg@1
|
162 |
private void onImageRendered(RenderedImage renderedImage) {
|
franta-hg@1
|
163 |
if (chartHolder instanceof ChartImageRenderListener) {
|
franta-hg@1
|
164 |
// delegate to chartHolder if it's interested...
|
franta-hg@1
|
165 |
((ChartImageRenderListener) chartHolder).onImageRendered(renderedImage);
|
franta-hg@1
|
166 |
}
|
franta-hg@1
|
167 |
}
|
franta-hg@1
|
168 |
|
franta-hg@1
|
169 |
}
|