Example usage for org.jfree.chart.entity ChartEntity getURLText

List of usage examples for org.jfree.chart.entity ChartEntity getURLText

Introduction

In this page you can find the example usage for org.jfree.chart.entity ChartEntity getURLText.

Prototype

public String getURLText() 

Source Link

Document

Returns the URL text for the entity.

Usage

From source file:org.openfaces.component.chart.impl.helpers.MapRenderUtilities.java

public static String getImageMapExt(Chart chart, String name, ChartRenderingInfo info,
        ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
        URLTagFragmentGenerator urlTagFragmentGenerator) {
    StringBuilder sb = new StringBuilder();
    sb.append("<map id=\"").append(name).append("\" name=\"").append(name).append("\">");
    sb.append(StringUtils.getLineSeparator());

    // the following is needed for displaying tooltips under IE (doesn't display tooltips if there's no area with href)
    String fakeArea = "<area shape=\"rect\" coords=\"0,0,0,0\" href=\"fake.jsp\" alt=\"\" title=\"\" />";
    sb.append(fakeArea);/* ww  w  .  ja va 2  s . c o  m*/
    sb.append(StringUtils.getLineSeparator());

    EntityCollection entities = info.getEntityCollection();
    if (entities != null) {
        int count = entities.getEntityCount();
        ChartView view = chart.getChartView();

        for (int i = count - 1; i >= 0; i--) {
            ChartEntity entity = entities.getEntity(i);

            if (entity.getToolTipText() == null && entity.getURLText() == null
                    && getOnClick(chart, chart.getChartView(), entity) == null && !viewHasAction(view)
                    && !viewHasPopup(view) && chart.getChartSelection() == null)
                continue;

            String area;
            if (i == 0) {
                area = getTitleImageMapAreaTag(chart, new StandardToolTipTagFragmentGenerator(),
                        new StandardURLTagFragmentGenerator(), entity);
            } else {
                if (entity instanceof PieSectionEntity) {
                    area = getImageMapAreaTag(chart, view, toolTipTagFragmentGenerator, urlTagFragmentGenerator,
                            entity, i);
                } else if (entity instanceof CategoryItemEntity) {
                    area = getImageMapAreaTag(chart, view, toolTipTagFragmentGenerator, urlTagFragmentGenerator,
                            entity, i);
                } else if (entity instanceof XYItemEntity) {
                    area = getImageMapAreaTag(chart, view, toolTipTagFragmentGenerator, urlTagFragmentGenerator,
                            entity, i);
                } else {
                    area = "";
                }
            }

            if (area.length() > 0) {
                sb.append(area);
                sb.append(StringUtils.getLineSeparator());
            }
        }

    }

    sb.append("</map>");
    return sb.toString();
}

From source file:org.openfaces.component.chart.impl.helpers.MapRenderUtilities.java

private static String getImageMapAreaTag(Chart chart, ChartView view,
        ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
        URLTagFragmentGenerator urlTagFragmentGenerator, ChartEntity entity, int entityIndex) {
    StringBuilder tag = new StringBuilder();
    boolean hasURL = entity.getURLText() != null && !entity.getURLText().equals("");
    boolean hasAction = viewHasAction(view);
    boolean hasPopup = viewHasPopup(view);
    boolean hasToolTip = entity.getToolTipText() != null && !entity.getToolTipText().equals("");
    boolean hasSelection = chart.getChartSelection() != null;

    String onClick = getOnClick(chart, view, entity);
    String onMouseOut = getOnMouseOut(chart, view, entity);
    String onMouseOver = getOnMouseOver(chart, view, entity);

    boolean hasCustomOnMouseOver = onMouseOver != null && !onMouseOver.equals("");
    boolean hasCustomOnMouseOut = onMouseOut != null && !onMouseOut.equals("");
    boolean hasCustomClick = onClick != null && !onClick.equals("");

    if (hasURL || hasToolTip || hasAction || hasPopup || hasCustomClick || hasSelection) {
        final FacesContext context = FacesContext.getCurrentInstance();
        tag.append("<area");

        if (hasAction || hasCustomClick || hasSelection) {
            if (hasSelection && chart.getChartMenu() != null && Environment.isChrome()) {
                tag.append(" oncontextmenu=\"");
                tag.append("O$('").append(chart.getClientId(context))
                        .append("')._areaContextMenuClick(event, '")
                        .append(chart.getChartMenu().getClientId(context)).append("');");
                tag.append("\"");
            }/*from  w ww .  j av a  2 s.  c  o m*/
            tag.append(" onclick=\"O$('").append(chart.getClientId(context)).append("')._clickItem(event, '")
                    .append(entityIndex).append("'");
            tag.append(",");
            if (hasCustomClick) {
                tag.append("function(event){").append(onClick).append("}");
            } else {
                tag.append("null");
            }
            tag.append(",").append(hasAction);
            tag.append(",").append(hasSelection);

            tag.append(")\"");
        }

        if (hasCustomOnMouseOver || hasPopup) {
            StringBuilder mouseOverBuilder = new StringBuilder();
            if (hasPopup) {
                final Integer oldEntityIndex = chart.getEntityIndex();
                chart.setEntityIndex(entityIndex);
                mouseOverBuilder.append("O$.ChartPopup._show(event,");
                mouseOverBuilder.append("'");
                mouseOverBuilder.append(chart.getChartView().getChartPopup().getClientId(context));
                mouseOverBuilder.append("',");
                mouseOverBuilder.append("'");
                mouseOverBuilder.append(entityIndex);
                mouseOverBuilder.append("'");
                chart.setEntityIndex(oldEntityIndex);

                if (hasCustomOnMouseOver) {
                    mouseOverBuilder.append(", function(){");
                    mouseOverBuilder.append(onMouseOver);
                    mouseOverBuilder.append("}");
                }
            } else {
                mouseOverBuilder.append(onMouseOver);
            }
            mouseOverBuilder.append(");");

            tag.append(" onmouseover=\"").append(mouseOverBuilder.toString()).append("\"");
        }

        if (hasCustomOnMouseOut) {
            tag.append(" onmouseout=\"").append(onMouseOut).append("\"");
        }

        tag.append(" shape=\"").append(entity.getShapeType()).append("\"" + " coords=\"")
                .append(entity.getShapeCoords()).append("\"");

        if (hasToolTip)
            tag.append(toolTipTagFragmentGenerator.generateToolTipFragment(entity.getToolTipText()));

        if (hasURL && !hasAction)
            tag.append(urlTagFragmentGenerator.generateURLFragment(entity.getURLText()));

        if (!hasToolTip)
            tag.append(" alt=\"\"");

        tag.append("/>");
    }
    return tag.toString();
}

From source file:org.openfaces.component.chart.impl.helpers.MapRenderUtilities.java

private static String getTitleImageMapAreaTag(Chart chart,
        ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
        URLTagFragmentGenerator urlTagFragmentGenerator, ChartEntity entity) {
    StringBuilder tag = new StringBuilder();
    ChartTitle title = chart.getTitle();
    if (title == null)
        return "";
    boolean hasURL = entity.getURLText() != null && !entity.getURLText().equals("");
    boolean hasAction = title.getActionExpression() != null || title.getActionListeners().length > 0;
    boolean hasToolTip = title.getTooltip() != null && !title.getTooltip().equals("");

    if (!hasURL && !hasToolTip && !hasAction)
        return "";

    String fieldId = chart.getClientId(FacesContext.getCurrentInstance()) + ACTION_FIELD_SUFFIX;

    tag.append("<area");

    if (hasAction)
        tag.append(" onclick=\"O$.setValue('").append(fieldId).append("','title'); O$.submitById('")
                .append(fieldId).append("');\"");

    tag.append(" shape=\"").append(entity.getShapeType()).append("\"" + " coords=\"")
            .append(entity.getShapeCoords()).append("\"");

    if (hasToolTip) {
        String toolTipText = entity.getToolTipText();
        if (toolTipText != null)
            tag.append(toolTipTagFragmentGenerator.generateToolTipFragment(toolTipText));
    }/*from w w w . j a v a2  s.  com*/

    if (hasURL && !hasAction)
        tag.append(urlTagFragmentGenerator.generateURLFragment(entity.getURLText()));

    if (!hasToolTip)
        tag.append(" alt=\"\"");

    tag.append("/>");
    return tag.toString();
}

From source file:gov.nih.nci.caintegrator.ui.graphing.util.ImageMapUtil.java

/**
 * Get a collection of entities with the area shape equal to the bounding rectangle
 * for the shape of original entity. This is necessary because the Javascript for the sample 
 * selection lasso can only handle rect objects.
 * @param entities/*from   w  ww  .j  av  a  2  s .c  o  m*/
 * @return a collection of entities containing the bounding rectangles of the original entities
 */
private static Collection<ChartEntity> getBoundingEntities(Collection entities) {
    ChartEntity entity;
    ChartEntity boundingEntity;
    Shape shape;
    Rectangle2D boundingRect;
    Collection<ChartEntity> boundingEntities = new ArrayList<ChartEntity>();
    for (Iterator i = entities.iterator(); i.hasNext();) {
        entity = (ChartEntity) i.next();
        shape = entity.getArea();
        boundingRect = shape.getBounds2D();
        boundingEntity = new ChartEntity(boundingRect, entity.getToolTipText(), entity.getURLText());
        boundingEntities.add(boundingEntity);
    }
    return boundingEntities;
}

From source file:gda.plots.SimpleLegendEntity.java

/**
 * Creates a SimpleLegendEntity by creating a new ChartEntity from an existing one and adding an SimpleXYSeries.
 * //from  w w  w.  j a  v  a 2 s.c o  m
 * @param ce
 * @param sxys
 */
public SimpleLegendEntity(ChartEntity ce, SimpleXYSeries sxys) {
    super(ce.getArea(), ce.getToolTipText(), ce.getURLText());
    this.sxys = sxys;
}

From source file:com.manydesigns.portofino.pageactions.chart.jfreechart.JFreeChartInstance.java

public void toXhtml(@NotNull XhtmlBuffer xb) {
    xb.openElement("img");
    xb.addAttribute("src", chartUrl);
    xb.addAttribute("alt", alt);
    xb.addAttribute("usemap", "#" + mapId);
    xb.addAttribute("style", "border: none;");
    xb.addAttribute("class", "img-responsive");
    xb.closeElement("img");

    xb.openElement("map");
    xb.addAttribute("id", mapId);
    xb.addAttribute("name", mapId);
    Iterator iter = renderingInfo.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity ce = (ChartEntity) iter.next();
        String shapeType = ce.getShapeType();
        String shapeCoords = ce.getShapeCoords();
        String tooltipText = ce.getToolTipText();
        String urltext = ce.getURLText();

        if (urltext == null)
            continue;

        xb.openElement("area");
        xb.addAttribute("shape", shapeType);
        xb.addAttribute("coords", shapeCoords);
        xb.addAttribute("title", tooltipText);
        xb.addAttribute("alt", tooltipText);
        xb.addAttribute("href", urltext);
        xb.closeElement("area");
    }//w  w  w .j  av a  2 s  .  co m
    xb.closeElement("map");
}

From source file:com.manydesigns.portofino.pageactions.chart.JFreeChartInstance.java

public void toXhtml(@NotNull XhtmlBuffer xb) {
    xb.openElement("img");
    xb.addAttribute("src", chartUrl);
    xb.addAttribute("alt", alt);
    xb.addAttribute("usemap", "#" + mapId);
    xb.addAttribute("style", "border: none;");
    xb.closeElement("img");

    xb.openElement("map");
    xb.addAttribute("id", mapId);
    xb.addAttribute("name", mapId);
    Iterator iter = renderingInfo.getEntityCollection().iterator();
    while (iter.hasNext()) {
        ChartEntity ce = (ChartEntity) iter.next();
        String shapeType = ce.getShapeType();
        String shapeCoords = ce.getShapeCoords();
        String tooltipText = ce.getToolTipText();
        String urltext = ce.getURLText();

        if (urltext == null)
            continue;

        xb.openElement("area");
        xb.addAttribute("shape", shapeType);
        xb.addAttribute("coords", shapeCoords);
        xb.addAttribute("title", tooltipText);
        xb.addAttribute("alt", tooltipText);
        xb.addAttribute("href", urltext);
        //hongliangpan add
        xb.addAttribute("target", "_BLANK");
        // xb.addAttribute("onclick",
        // "window.open(this.href, '_blank', 'scrollbars=0,resizable=0;width=300');return false");

        xb.closeElement("area");
    }//from  ww  w  . j  a va 2 s .  c o m
    xb.closeElement("map");
}

From source file:de.laures.cewolf.taglib.tags.ChartMapTag.java

private String generateLink(Dataset dataset, ChartEntity ce) {
    String link = null;//www  .  j a v  a  2s  . c  o  m
    if (useJFreeChartLinkGenerator) {
        link = ce.getURLText();
    } else if (linkGenerator instanceof CategoryItemLinkGenerator
            || linkGenerator instanceof XYItemLinkGenerator
            || linkGenerator instanceof PieSectionLinkGenerator) {
        if (linkGenerator instanceof CategoryItemLinkGenerator) {
            if (ce instanceof CategoryItemEntity) {
                CategoryItemEntity catEnt = (CategoryItemEntity) ce;
                link = ((CategoryItemLinkGenerator) linkGenerator).generateLink(dataset, catEnt.getSeries(),
                        catEnt.getCategory());
            }
        }
        if (linkGenerator instanceof XYItemLinkGenerator) {
            if (ce instanceof XYItemEntity) {
                XYItemEntity xyEnt = (XYItemEntity) ce;
                link = ((XYItemLinkGenerator) linkGenerator).generateLink(dataset, xyEnt.getSeriesIndex(),
                        xyEnt.getItem());
            } else {
                // Note; there is a simple ChartEntity also passed since Jfreechart 1.0rc1, that is ignored
                LOG.debug("Link entity skipped, not XYItemEntity.class:" + ce);
            }
        }
        if (linkGenerator instanceof PieSectionLinkGenerator) {
            if (ce instanceof PieSectionEntity) {
                PieSectionEntity pieEnt = (PieSectionEntity) ce;
                link = ((PieSectionLinkGenerator) linkGenerator).generateLink(dataset, pieEnt.getSectionKey());
            }
        }
    }
    return link;
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java

/**
 * Returns an optional image-map for the entry.
 *
 * @param bounds the bounds for which the image map is computed.
 * @return the computed image-map or null if there is no image-map available.
 *///w ww  .  j  a  v a  2  s . c o  m
public ImageMap getImageMap(final Rectangle2D bounds) {
    if (chartRenderingInfo == null) {
        return null;
    }
    final Rectangle2D dataArea = getDataAreaOffset();
    final Rectangle2D otherArea = new Rectangle2D.Double();

    if ((ObjectUtilities.equal(bounds, this.bounds)) == false) {
        final BufferedImage image = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
        final Graphics2D graphics = image.createGraphics();
        draw(graphics, bounds);
        graphics.dispose();
    }

    final ImageMap map = new ImageMap();
    final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection();
    final int count = entityCollection.getEntityCount();
    for (int i = 0; i < count; i++) {
        final ChartEntity chartEntity = entityCollection.getEntity(i);
        final Shape area = chartEntity.getArea();
        final String hrefValue = chartEntity.getURLText();
        final String tooltipValue = chartEntity.getToolTipText();
        if (StringUtils.isEmpty(tooltipValue) == false || StringUtils.isEmpty(hrefValue) == false) {
            final AbstractImageMapEntry entry;
            if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity
                    || chartEntity instanceof PieSectionEntity) {
                entry = createMapEntry(area, dataArea);
            } else {
                entry = createMapEntry(area, otherArea);
            }
            if (entry == null) {
                continue;
            }
            if (StringUtils.isEmpty(hrefValue) == false) {
                entry.setAttribute(LibXmlInfo.XHTML_NAMESPACE, "href", hrefValue);
            } else {
                entry.setAttribute(LibXmlInfo.XHTML_NAMESPACE, "href", "#");
            }
            if (StringUtils.isEmpty(tooltipValue) == false) {
                entry.setAttribute(LibXmlInfo.XHTML_NAMESPACE, "title", tooltipValue);
            }
            map.addMapEntry(entry);
        }
    }

    return map;
}

From source file:org.orbeon.oxf.processor.JFreeChartProcessor.java

public ProcessorOutput createOutput(String name) {
    return new ProcessorOutputImpl(JFreeChartProcessor.this, name) {
        public void readImpl(PipelineContext context, XMLReceiver xmlReceiver) {
            JFreeChartSerializer.ChartConfig chartConfig = readChartConfig(context);
            ChartInfo info = createChart(context, chartConfig);
            try {
                xmlReceiver.startDocument();
                xmlReceiver.startElement("", "chart-info", "chart-info", new AttributesImpl());

                xmlReceiver.startElement("", "file", "file", new AttributesImpl());
                xmlReceiver.characters(info.file.toCharArray(), 0, info.file.length());
                xmlReceiver.endElement("", "file", "file");

                if (chartConfig.getMap() != null) {
                    AttributesImpl atts = new AttributesImpl();

                    atts.addAttribute("", "name", "name", "CDATA", chartConfig.getMap());
                    xmlReceiver.startElement("", "map", "map", atts);

                    EntityCollection entities = info.getInfo().getEntityCollection();

                    Iterator iterator = entities.iterator();
                    while (iterator.hasNext()) {
                        ChartEntity entity = (ChartEntity) iterator.next();
                        AttributesImpl attr = new AttributesImpl();
                        attr.addAttribute("", "shape", "shape", "CDATA", entity.getShapeType());
                        attr.addAttribute("", "coords", "coords", "CDATA", entity.getShapeCoords());

                        if (entity.getURLText() != null && !entity.getURLText().equals("")) {
                            attr.addAttribute("", "href", "href", "CDATA", entity.getURLText());
                        }/*from w w w .j  a v  a  2  s  . c om*/
                        if (entity.getToolTipText() != null && !entity.getToolTipText().equals("")) {
                            attr.addAttribute("", "title", "title", "CDATA", entity.getToolTipText());

                        }
                        xmlReceiver.startElement("", "area", "area", attr);
                        xmlReceiver.endElement("", "area", "area");
                    }

                    xmlReceiver.endElement("", "map", "map");
                }
                xmlReceiver.endElement("", "chart-info", "chart-info");
                xmlReceiver.endDocument();

            } catch (SAXException e) {
                throw new OXFException(e);
            }
        }
    };
}