private Graphics2D finishGroup(ReportGroup group, Graphics2D g, Point p) {

        //
        // Notify the report listeners that the current group has ended
        //
        ReportEvent event = new ReportEvent(ReportEvent.GROUP_FINISHED, state);
        event.setGroup(group);
        int expCount;
        ReportExpression exp;
        if (g != null) {
            PageState pageState = reportPages.get(pageIndex);
            expCount = pageState.getExpressionCount();
            for (int i=0; i<expCount; i++) {
                exp = pageState.getExpression(i);
                if (exp instanceof ReportListener)
                    ((ReportListener)exp).groupFinished(event);
            }
        } else {
            expCount = state.getExpressionCount();
            for (int i=0; i<expCount; i++) {
                exp = state.getExpression(i);
                if (exp instanceof ReportListener)
                    ((ReportListener)exp).groupFinished(event);
            }
        }

        //
        // Print the group footer
        //
        ReportBand band = group.getFooter();
        if (band.getElementCount() != 0) {
            Rectangle bandArea = band.getBounds();
            Rectangle footerArea = state.getPageFooter().getBounds();
            if (g == null) {
                if (p.y+bandArea.height+footerArea.height > printArea.y+printArea.height) {
                    finishPage(null);
                    startPage(null, p, false);
                }

                p.setLocation(p.x, p.y+bandArea.height);
                group.setValue(null);
            } else {
                if (p.y+bandArea.height+footerArea.height > printArea.y+printArea.height) {
                    finishPage(g);
                    g = null;
                } else {
                    band.format(g, p);
                    group.setValue(null);
                }
            }
        }

        return g;
    }