use of org.jfree.chart.imagemap.StandardURLTagFragmentGenerator in project processdash by dtuma.
the class CGIChartBase method writeImageHtml.
private void writeImageHtml(int width, int height, int imgID, ChartRenderingInfo info) throws IOException {
String tooltip = getParameter("tooltip");
if (!StringUtils.hasValue(tooltip))
tooltip = resources.getHTML("More_Detail_Here_Instruction");
String href = getParameter("href");
if (StringUtils.hasValue(href)) {
// create a copy of the entity collection, and place an entity for
// the entire chart at the beginning of the list. This will
// make it appear last in the image map (which is important,
// because browsers process the image map areas in the order that
// they appear; having the entire chart area listed first would
// obscure all of the other image map areas).
EntityCollection entities = new StandardEntityCollection();
entities.add(new ChartEntity(info.getChartArea(), tooltip, href));
if (info.getEntityCollection() != null)
entities.addAll(info.getEntityCollection());
// area in the chart.
for (Iterator i = entities.iterator(); i.hasNext(); ) {
ChartEntity ce = (ChartEntity) i.next();
// image map anyway, so they don't need to be adjusted
if (ce.getToolTipText() == null && ce.getURLText() == null)
continue;
// for other entities, add a tooltip and a URL as needed.
if (!StringUtils.hasValue(ce.getToolTipText()))
ce.setToolTipText(tooltip);
if (!StringUtils.hasValue(ce.getURLText()))
ce.setURLText(href);
}
// install our modified version of the entity collection into
// the chart info object, so it will be used when generating
// the image map later.
info.setEntityCollection(entities);
}
// write the image tag
out.write("<img width=\"" + width + "\" height=\"" + height + "\" src=\"/reports/pngCache?id=" + imgID + "\" usemap=\"#IMG" + imgID + '"');
// have a URL we're pointing to. Turn that border off.
if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
out.write(" border=\"0\"");
// starting with the prefix "img", and copy them into the tag.
for (Iterator i = parameters.entrySet().iterator(); i.hasNext(); ) {
Map.Entry e = (Map.Entry) i.next();
String attrName = (String) e.getKey();
if (attrName.startsWith("img") && !attrName.endsWith("_ALL")) {
out.write(" " + attrName.substring(3) + "=\"");
out.write(HTMLUtils.escapeEntities(e.getValue().toString()));
out.write('"');
}
}
out.write(">");
// finally, write the image map. Note that we have to strip line
// break characters from the resulting HTML, otherwise firefox seems
// to decide that the <map> tag actually takes up space on the page
String imageMapHtml = ImageMapUtilities.getImageMap("IMG" + imgID, info, getToolTipGenerator(tooltip), new StandardURLTagFragmentGenerator());
for (int i = 0; i < imageMapHtml.length(); i++) {
char c = imageMapHtml.charAt(i);
if (c != '\r' && c != '\n')
out.write(c);
}
out.flush();
}
Aggregations