Example usage for org.jfree.chart.entity EntityCollection addAll

List of usage examples for org.jfree.chart.entity EntityCollection addAll

Introduction

In this page you can find the example usage for org.jfree.chart.entity EntityCollection addAll.

Prototype

public void addAll(EntityCollection collection);

Source Link

Document

Adds the entities from another collection to this collection.

Usage

From source file:net.sourceforge.processdash.ui.web.CGIChartBase.java

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());

        // Next: most of our chart entities will not have URLs. URL values
        // don't inherit in the imagemap, so if we want the entire image
        // to have a single URL, we need to assign that URL to every
        // area in the chart.
        for (Iterator i = entities.iterator(); i.hasNext();) {
            ChartEntity ce = (ChartEntity) i.next();
            // check for no-op chart entity - these won't appear in the
            // 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);/*w w w . j  av a  2s .c o m*/
        }

        // 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 + '"');

    // imagemaps have hyperlink borders by default, even if we don't
    // have a URL we're pointing to.  Turn that border off.
    if (!StringUtils.hasValue(href) || parameters.containsKey("noBorder"))
        out.write(" border=\"0\"");

    // Our client might want to add attributes to the image tag. Look
    // through the query parameters we received for arbitrary attributes
    // 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();
}