afreechart/src/main/java/org/afree/chart/AFreeChart.java
/**
     * 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 canvas
     *            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>).
     */
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 (null not permitted).
@param canvas
the graphics device (null not permitted).
@param area
the chart area, excluding any existing titles (
null 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 null).
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 ( null not permitted ) . @param canvas the graphics device ( null not permitted ) . @param area the chart area excluding any existing titles ( null 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 null ) .
protected EntityCollection drawTitle(Title t, Canvas canvas, RectShape area,
            boolean entities) {
        if (t == null) {
            throw new IllegalArgumentException("Null 't' argument.");
        }
        if (area == null) {
            throw new IllegalArgumentException("Null 'area' argument.");
        }
        RectShape titleArea = new RectShape();
        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(canvas, constraint);
            titleArea = createAlignedRectShape(size, area, t
                    .getHorizontalAlignment(), VerticalAlignment.TOP);
            retValue = t.draw(canvas, 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(canvas, constraint);
            titleArea = createAlignedRectShape(size, area, t
                    .getHorizontalAlignment(), VerticalAlignment.BOTTOM);
            retValue = t.draw(canvas, titleArea, p);
            area.setRect(area.getX(), area.getY(), area.getWidth(), area
                    .getHeight()
                    - size.height);
        } else if (position == RectangleEdge.RIGHT) {
            Size2D size = t.arrange(canvas, constraint);
            titleArea = createAlignedRectShape(size, area,
                    HorizontalAlignment.RIGHT, t.getVerticalAlignment());
            retValue = t.draw(canvas, titleArea, p);
            area.setRect(area.getX(), area.getY(),
                    area.getWidth() - size.width, area.getHeight());
        }
        else if (position == RectangleEdge.LEFT) {
            Size2D size = t.arrange(canvas, constraint);
            titleArea = createAlignedRectShape(size, area,
                    HorizontalAlignment.LEFT, t.getVerticalAlignment());
            retValue = t.draw(canvas, 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;
    }
protected EntityCollection drawTitle ( Title t , Canvas canvas , RectShape area , boolean entities ) { if ( t == null ) { throw new IllegalArgumentException ( "Null 't' argument." ) ; } if ( area == null ) { throw new IllegalArgumentException ( "Null 'area' argument." ) ; } RectShape titleArea = new RectShape ( ) ; 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 ( canvas , constraint ) ; titleArea = createAlignedRectShape ( size , area , t . getHorizontalAlignment ( ) , VerticalAlignment . TOP ) ; retValue = t . draw ( canvas , 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 ( canvas , constraint ) ; titleArea = createAlignedRectShape ( size , area , t . getHorizontalAlignment ( ) , VerticalAlignment . BOTTOM ) ; retValue = t . draw ( canvas , titleArea , p ) ; area . setRect ( area . getX ( ) , area . getY ( ) , area . getWidth ( ) , area . getHeight ( ) - size . height ) ; } else if ( position == RectangleEdge . RIGHT ) { Size2D size = t . arrange ( canvas , constraint ) ; titleArea = createAlignedRectShape ( size , area , HorizontalAlignment . RIGHT , t . getVerticalAlignment ( ) ) ; retValue = t . draw ( canvas , titleArea , p ) ; area . setRect ( area . getX ( ) , area . getY ( ) , area . getWidth ( ) - size . width , area . getHeight ( ) ) ; } else if ( position == RectangleEdge . LEFT ) { Size2D size = t . arrange ( canvas , constraint ) ; titleArea = createAlignedRectShape ( size , area , HorizontalAlignment . LEFT , t . getVerticalAlignment ( ) ) ; retValue = t . draw ( canvas , 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 ; }
Draws a title.
Draws a title .