Example usage for org.jfree.chart.block EntityBlockParams getGenerateEntities

List of usage examples for org.jfree.chart.block EntityBlockParams getGenerateEntities

Introduction

In this page you can find the example usage for org.jfree.chart.block EntityBlockParams getGenerateEntities.

Prototype

public boolean getGenerateEntities();

Source Link

Document

Returns a flag that controls whether or not the block should return entities for the items it draws.

Usage

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.legend.ColoredBlockContainer.java

/**
 * Disclaimer: this is a "works for me" implementation, and probably only works as long as the
 * items are arranged horizontally in exactly one line, since it brutally enforces the items to
 * be aligned vertically centered./*from   w  w w .j  a v  a 2s  .  c  o  m*/
 */
@Override
public Object draw(Graphics2D g2, Rectangle2D area, Object params) {
    area = drawFill(g2, area);

    // check if we need to collect chart entities from the container
    EntityBlockParams ebp = null;
    StandardEntityCollection sec = null;
    if (params instanceof EntityBlockParams) {
        ebp = (EntityBlockParams) params;
        if (ebp.getGenerateEntities()) {
            sec = new StandardEntityCollection();
        }
    }
    Rectangle2D contentArea = (Rectangle2D) area.clone();
    contentArea = trimMargin(contentArea);
    drawBorder(g2, contentArea);
    contentArea = trimBorder(contentArea);
    contentArea = trimPadding(contentArea);
    Iterator iterator = getBlocks().iterator();
    while (iterator.hasNext()) {
        Block block = (Block) iterator.next();
        Rectangle2D bounds = block.getBounds();

        // enforce vertically centered alignment
        double y = area.getY() + (area.getHeight() - bounds.getHeight()) / 2.0;

        Rectangle2D drawArea = new Rectangle2D.Double(bounds.getX() + area.getX(), y, bounds.getWidth(),
                bounds.getHeight());
        Object r = block.draw(g2, drawArea, params);
        if (sec != null) {
            if (r instanceof EntityBlockResult) {
                EntityBlockResult ebr = (EntityBlockResult) r;
                EntityCollection ec = ebr.getEntityCollection();
                sec.addAll(ec);
            }
        }
    }
    BlockResult result = null;
    if (sec != null) {
        result = new BlockResult();
        result.setEntityCollection(sec);
    }
    return result;
}