Search in sources :

Example 1 with BlockParams

use of org.jfree.chart.block.BlockParams in project SIMVA-SoS by SESoS.

the class XYTitleAnnotation method draw.

/**
 * Draws the annotation.  This method is called by the drawing code in the
 * {@link XYPlot} class, you don't normally need to call this method
 * directly.
 *
 * @param g2  the graphics device.
 * @param plot  the plot.
 * @param dataArea  the data area.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param rendererIndex  the renderer index.
 * @param info  if supplied, this info object will be populated with
 *              entity information.
 */
@Override
public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) {
    PlotOrientation orientation = plot.getOrientation();
    AxisLocation domainAxisLocation = plot.getDomainAxisLocation();
    AxisLocation rangeAxisLocation = plot.getRangeAxisLocation();
    RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation);
    RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation);
    Range xRange = domainAxis.getRange();
    Range yRange = rangeAxis.getRange();
    double anchorX, anchorY;
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        anchorX = xRange.getLowerBound() + (this.x * xRange.getLength());
        anchorY = yRange.getLowerBound() + (this.y * yRange.getLength());
    } else {
        anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge);
        anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge);
    }
    float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge);
    float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge);
    float xx = 0.0f;
    float yy = 0.0f;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = j2DY;
        yy = j2DX;
    } else if (orientation == PlotOrientation.VERTICAL) {
        xx = j2DX;
        yy = j2DY;
    }
    double maxW = dataArea.getWidth();
    double maxH = dataArea.getHeight();
    if (this.coordinateType == XYCoordinateType.RELATIVE) {
        if (this.maxWidth > 0.0) {
            maxW = maxW * this.maxWidth;
        }
        if (this.maxHeight > 0.0) {
            maxH = maxH * this.maxHeight;
        }
    }
    if (this.coordinateType == XYCoordinateType.DATA) {
        maxW = this.maxWidth;
        maxH = this.maxHeight;
    }
    RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH));
    Size2D size = this.title.arrange(g2, rc);
    Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height);
    Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor);
    xx = xx - (float) anchorPoint.getX();
    yy = yy - (float) anchorPoint.getY();
    titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight());
    BlockParams p = new BlockParams();
    if (info != null) {
        if (info.getOwner().getEntityCollection() != null) {
            p.setGenerateEntities(true);
        }
    }
    Object result = this.title.draw(g2, titleRect, p);
    if (info != null) {
        if (result instanceof EntityBlockResult) {
            EntityBlockResult ebr = (EntityBlockResult) result;
            info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection());
        }
        String toolTip = getToolTipText();
        String url = getURL();
        if (toolTip != null || url != null) {
            addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url);
        }
    }
}
Also used : AxisLocation(org.jfree.chart.axis.AxisLocation) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) Range(org.jfree.data.Range) BlockParams(org.jfree.chart.block.BlockParams) Size2D(org.jfree.ui.Size2D) Point2D(java.awt.geom.Point2D) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 2 with BlockParams

use of org.jfree.chart.block.BlockParams in project SIMVA-SoS by SESoS.

the class JFreeChartInfo method drawTitle.

/**
 * Draws a title.  The title should be drawn at the top, bottom, left or
 * right of the specified area, and the area should be updated to reflect
 * the amount of space used by the title.
 *
 * @param t  the title (<code>null</code> not permitted).
 * @param g2  the graphics device (<code>null</code> not permitted).
 * @param area  the chart area, excluding any existing titles
 *              (<code>null</code> not permitted).
 * @param entities  a flag that controls whether or not an entity
 *                  collection is returned for the title.
 *
 * @return An entity collection for the title (possibly <code>null</code>).
 */
protected EntityCollection drawTitle(Title t, Graphics2D g2, Rectangle2D area, boolean entities) {
    ParamChecks.nullNotPermitted(t, "t");
    ParamChecks.nullNotPermitted(area, "area");
    Rectangle2D titleArea;
    RectangleEdge position = t.getPosition();
    double ww = area.getWidth();
    if (ww <= 0.0) {
        return null;
    }
    double hh = area.getHeight();
    if (hh <= 0.0) {
        return null;
    }
    RectangleConstraint constraint = new RectangleConstraint(ww, new Range(0.0, ww), LengthConstraintType.RANGE, hh, new Range(0.0, hh), LengthConstraintType.RANGE);
    Object retValue = null;
    BlockParams p = new BlockParams();
    p.setGenerateEntities(entities);
    if (position == RectangleEdge.TOP) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.TOP);
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), Math.min(area.getY() + size.height, area.getMaxY()), area.getWidth(), Math.max(area.getHeight() - size.height, 0));
    } else if (position == RectangleEdge.BOTTOM) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, t.getHorizontalAlignment(), VerticalAlignment.BOTTOM);
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), area.getY(), area.getWidth(), area.getHeight() - size.height);
    } else if (position == RectangleEdge.RIGHT) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.RIGHT, t.getVerticalAlignment());
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX(), area.getY(), area.getWidth() - size.width, area.getHeight());
    } else if (position == RectangleEdge.LEFT) {
        Size2D size = t.arrange(g2, constraint);
        titleArea = createAlignedRectangle2D(size, area, HorizontalAlignment.LEFT, t.getVerticalAlignment());
        retValue = t.draw(g2, titleArea, p);
        area.setRect(area.getX() + size.width, area.getY(), area.getWidth() - size.width, area.getHeight());
    } else {
        throw new RuntimeException("Unrecognised title position.");
    }
    EntityCollection result = null;
    if (retValue instanceof EntityBlockResult) {
        EntityBlockResult ebr = (EntityBlockResult) retValue;
        result = ebr.getEntityCollection();
    }
    return result;
}
Also used : Size2D(org.jfree.ui.Size2D) EntityCollection(org.jfree.chart.entity.EntityCollection) Rectangle2D(java.awt.geom.Rectangle2D) EntityBlockResult(org.jfree.chart.block.EntityBlockResult) RectangleConstraint(org.jfree.chart.block.RectangleConstraint) Range(org.jfree.data.Range) RectangleEdge(org.jfree.ui.RectangleEdge) BlockParams(org.jfree.chart.block.BlockParams)

Aggregations

Rectangle2D (java.awt.geom.Rectangle2D)2 BlockParams (org.jfree.chart.block.BlockParams)2 EntityBlockResult (org.jfree.chart.block.EntityBlockResult)2 RectangleConstraint (org.jfree.chart.block.RectangleConstraint)2 Range (org.jfree.data.Range)2 RectangleEdge (org.jfree.ui.RectangleEdge)2 Size2D (org.jfree.ui.Size2D)2 Point2D (java.awt.geom.Point2D)1 AxisLocation (org.jfree.chart.axis.AxisLocation)1 EntityCollection (org.jfree.chart.entity.EntityCollection)1 PlotOrientation (org.jfree.chart.plot.PlotOrientation)1