Java 类net.sf.jasperreports.engine.JRChild 实例源码

项目:jasperreports    文件:JRBaseFrame.java   
public JRBaseFrame(JRFrame frame, JRBaseObjectFactory factory)
{
    super(frame, factory);

    List<JRChild> frameChildren = frame.getChildren();
    if (frameChildren != null)
    {
        children = new ArrayList<JRChild>(frameChildren.size());
        for (Iterator<JRChild> it = frameChildren.iterator(); it.hasNext();)
        {
            JRChild child = it.next();
            children.add((JRChild)factory.getVisitResult(child));
        }
    }

    lineBox = frame.getLineBox().clone(this);
    this.borderSplitType = frame.getBorderSplitType();
}
项目:jasperreports    文件:FrameConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter, JRElement element)
{
    JRBasePrintFrame printFrame = new JRBasePrintFrame(reportConverter.getDefaultStyleProvider());
    JRFrame frame = (JRFrame)element; 

    copyElement(reportConverter, frame, printFrame);

    printFrame.copyBox(frame.getLineBox());

    List<JRChild> children = frame.getChildren();
    if (children != null && children.size() > 0)
    {
        ConvertVisitor convertVisitor = new ConvertVisitor(reportConverter, printFrame);
        for(int i = 0; i < children.size(); i++)
        {
            children.get(i).visit(convertVisitor);
        }
    }

    return printFrame;
}
项目:jasperreports    文件:JRApiWriter.java   
/**
 * Writes the contents (child elements) of an element container.
 * 
 * @param elementContainer the element container
 */
public void writeChildElements( JRElementGroup elementContainer, String parentName)
{
    List<JRChild> children = elementContainer.getChildren();
    if (children != null && children.size() > 0)
    {
        for(int i = 0; i < children.size(); i++)
        {
            String childName = parentName + "_" + i;
            apiWriterVisitor.setName(childName);
            children.get(i).visit(apiWriterVisitor);
            if(children.get(i) instanceof JRElementGroup && !(children.get(i) instanceof JRElement))
            {
                write( parentName +".addElementGroup(" + childName + ");\n\n");

            }
            else if (!(children.get(i) instanceof JRComponentElement))//FIXME component
            {
                write( parentName +".addElement(" + childName + ");\n\n");
            }
        }
    }
}
项目:jasperreports    文件:JRFillElementGroup.java   
protected JRFillElementGroup(JRFillElementGroup elementGrp, JRFillCloneFactory factory)
{
    factory.put(elementGrp, this);

    List<JRChild> list = elementGrp.getChildren();
    if (list != null)
    {
        for (int i = 0; i < list.size(); i++)
        {
            JRFillCloneable child = (JRFillCloneable) list.get(i);
            JRFillCloneable clone = child.createClone(factory);
            children.add((JRChild)clone);
        }
    }

    getElements();

    elementGroup = (JRFillElementGroup) factory.getClone((JRFillElementGroup) elementGrp.getElementGroup());
}
项目:jasperreports    文件:JRFillCrosstab.java   
private int findRowGroupColumHeaderElementIndex(int rowGroupIndex, List<JRChild> cellElements)
{
    String rowGropIndexStr = Integer.toString(rowGroupIndex);
    int colHeaderTextIndex = -1;
    for (ListIterator<JRChild> elemIt = cellElements.listIterator(cellElements.size()); elemIt.hasPrevious();)
    {
        JRChild child = elemIt.previous();
        if (child instanceof JRTextElement)
        {
            JRFillTextElement textElement = (JRFillTextElement) child;
            JRElement parentElement = textElement.getParent();
            String prop = parentElement.hasProperties() 
                    ? parentElement.getPropertiesMap().getProperty(PROPERTY_ROW_GROUP_COLUMN_HEADER) : null;
            if (prop != null && prop.equals(rowGropIndexStr))
            {
                // found it
                colHeaderTextIndex = elemIt.nextIndex();
                break;
            }
        }
    }
    return colHeaderTextIndex;
}
项目:jasperreports    文件:TableUtil.java   
/**
 * 
 */
public static <T extends JRElement> T getCellElement(Class<T> type, Cell cell, boolean oneElementPerCell) 
{
    List<JRChild> detailElements = cell == null ? null : cell.getChildren();

    if (detailElements == null || (detailElements != null && oneElementPerCell && detailElements.size() != 1)) 
    {
        return null;
    }

    for (JRChild detailElement: detailElements) 
    {
        if (type.isInstance(detailElement) ) 
        {
            @SuppressWarnings("unchecked")
            T de = (T) detailElement;
            return de;
        }
    }

    return null;
}
项目:jasperreports    文件:TableReport.java   
protected JRExpression getColumnHeaderLabelExpression(Cell header)
{
    List<JRChild> detailElements = header == null ? null : header.getChildren();
    // only consider cells with a single text fields
    if (detailElements == null || detailElements.size() != 1)
    {
        return null;
    }

    JRChild detailElement = detailElements.get(0);
    if (detailElement instanceof JRTextField)
    {
        return ((JRTextField) detailElement).getExpression();
    }

    if (detailElement instanceof JRStaticText)
    {
        return builtinEvaluatorFactory.createConstantExpression(((JRStaticText)detailElement).getText());
    }

    return null;
}
项目:PDFReporter-Studio    文件:ListSizePropertyDescriptor.java   
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {

    for (APropertyNode node : section.getElements()){
        if (node instanceof MList){
            MList list = (MList)node;
            StandardListComponent listComponent = (StandardListComponent)list.getValue().getComponent();
            int cellWidth = 100;
            int cellHeight = 30;
            for(JRChild child : listComponent.getContents().getChildren()){
                if (child instanceof JRElement){
                    JRElement jrChild = (JRElement)child;
                    int rightBound = jrChild.getX()+jrChild.getWidth();
                    int downBound  = jrChild.getY()+jrChild.getHeight();
                    cellWidth = Math.max(cellWidth, rightBound);
                    cellHeight = Math.max(cellHeight, downBound);
                }
            }
            section.changePropertyOn(MList.PREFIX + DesignListContents.PROPERTY_HEIGHT, cellHeight, list);
            section.changePropertyOn(MList.PREFIX + DesignListContents.PROPERTY_WIDTH, cellWidth, list);    
        }
    }
    section.refresh();
}
项目:PDFReporter-Studio    文件:VErrorPreview.java   
private List<JRDesignElement> getNotReferencedStyles(JRChild[] childs, HashSet<String> styles) {
    List<JRDesignElement> result = new ArrayList<JRDesignElement>();
    for (JRChild child : childs) {
        if (child instanceof JRDesignElement) {
            String styleName = getElementStyle((JRDesignElement) child);
            if (styleName != null && styles.contains(styleName)) {
                result.add((JRDesignElement) child);
            }
        }
        if (child instanceof JRElementGroup) {
            JRElementGroup group = (JRElementGroup) child;
            List<JRDesignElement> value = getNotReferencedStyles(group.getElements(), styles);
            result.addAll(value);
        }
    }
    return result;
}
项目:jasperreports    文件:JRBaseElementGroup.java   
/**
 *
 */
public static JRElement[] getElements(List<JRChild> children)
{
    JRElement[] elements = null;

    if (children != null)
    {
        List<JRElement> allElements = new ArrayList<JRElement>();
        Object child = null;
        JRElement[] childElementArray = null;
        for(int i = 0; i < children.size(); i++)
        {
            child = children.get(i);
            if (child instanceof JRElement)
            {
                allElements.add((JRElement)child);
            }
            else if (child instanceof JRElementGroup)
            {
                childElementArray = ((JRElementGroup)child).getElements();
                if (childElementArray != null)
                {
                    allElements.addAll( Arrays.asList(childElementArray) );
                }
            }
        }

        elements = new JRElement[allElements.size()];
        allElements.toArray(elements);
    }

    return elements;
}
项目:jasperreports    文件:ConvertVisitor.java   
@Override
public void visitElementGroup(JRElementGroup elementGroup)
{
    List<JRChild> children = elementGroup.getChildren();
    if (children != null && children.size() > 0)
    {
        for(int i = 0; i < children.size(); i++)
        {
            children.get(i).visit(this);
        }
    }
}
项目:jasperreports    文件:JRXmlWriter.java   
/**
 * Writes the contents (child elements) of an element container.
 * 
 * @param elementContainer the element container
 */
public void writeChildElements(JRElementGroup elementContainer)
{
    List<JRChild> children = elementContainer.getChildren();
    if (children != null && children.size() > 0)
    {
        for(int i = 0; i < children.size(); i++)
        {
            children.get(i).visit(xmlWriterVisitor);
        }
    }
}
项目:jasperreports    文件:JRDesignFrame.java   
/**
 * Creates a new frame object.
 * 
 * @param defaultStyleProvider default style provider instance
 */
public JRDesignFrame(JRDefaultStyleProvider defaultStyleProvider)
{
    super(defaultStyleProvider);

    children = new ArrayList<JRChild>();

    lineBox = new JRBaseLineBox(this);
}
项目:jasperreports    文件:TableReport.java   
@Override
protected boolean isEmpty(Cell cell)
{
    if (super.isEmpty(cell))
    {
        return true;
    }

    // also threat zero height cells as empty.
    // FIXME only doing this for the detail cells to minimize impact, it should apply to all cells
    List<JRChild> children = cell.getChildren();
    return cell.getHeight() == 0 && (children == null || children.isEmpty());
}
项目:jasperreports    文件:TableReport.java   
protected void addIconLabelComponent(Column column, JRDesignFrame frame, String suffix)
{
    List<JRChild> children = frame.getChildren();
    if (children.size() > 0)
    {
        JRBaseTextElement headerTextElement = (JRBaseTextElement)children.get(0);
        if (headerTextElement != null) 
        {
            JRComponentElement componentElement = 
                IconLabelComponentUtil.getInstance(fillContext.getFiller().getJasperReportsContext()).createIconLabelComponentElement(headerTextElement);
            IconLabelComponent iconLabelComponent = (IconLabelComponent)componentElement.getComponent();

            JRDesignTextField labelTextField = (JRDesignTextField)iconLabelComponent.getLabelTextField();
            if (headerTextElement instanceof JRTextField) 
            {
                labelTextField.setExpression(((JRTextField) headerTextElement).getExpression());
            }
            else if (headerTextElement instanceof JRStaticText) 
            {
                labelTextField.setExpression(builtinEvaluatorFactory.createConstantExpression(((JRStaticText)headerTextElement).getText()));
            }

            JRDesignTextField iconTextField = (JRDesignTextField)iconLabelComponent.getIconTextField();
            iconTextField.setExpression(builtinEvaluatorFactory.createConstantExpression(suffix));

            componentElement.getPropertiesMap().setProperty(MatcherExporterFilter.PROPERTY_MATCHER_EXPORT_FILTER_KEY, TABLE_HEADER_ICON_LABEL_MATCHER_EXPORT_KEY);

            JRBaseElement element = (JRBaseElement)frame.getChildren().get(0);
            element.getPropertiesMap().setProperty(MatcherExporterFilter.PROPERTY_MATCHER_EXPORT_FILTER_KEY, TABLE_HEADER_LABEL_MATCHER_EXPORT_KEY);

            //frame.getChildren().remove(0);
            frame.getChildren().add(componentElement);
        }
    }
}
项目:PDFReporter-Studio    文件:TableTemplateEngine.java   
/**
 * Search the template table inside a JasperDesign, looking in the children of the summary band
 * 
 * @param jd the jasperdesign that contains the sample table
 * @return a JRDesignComponentElement that contains a StandardTable, or null if it isn't found
 */
private static JRDesignComponentElement getTable(JasperDesign jd){
    if (jd.getSummary() == null) return null;
    for(JRChild child : jd.getSummary().getChildren()){
        if (child instanceof JRDesignComponentElement){
            JRDesignComponentElement component = (JRDesignComponentElement)child;
            if (component.getComponent() instanceof StandardTable) return component;
        }
    }
    //No table found, create a default one
    return null;
}
项目:PDFReporter-Studio    文件:TableTemplateEngine.java   
private void addSectionElementsToList(Cell section, List<JRDesignElement> currentList){
    if (section != null){
        for(JRChild child : section.getChildren()){
            if (child instanceof JRDesignElement) currentList.add((JRDesignElement)child);
        }
    }
}
项目:PDFReporter-Studio    文件:JasperReportCompiler.java   
private JRDesignElement getElementFromTable(JRChild[] childs, StandardTable table){ 
    for(JRChild child : childs){
        if (child instanceof JRDesignComponentElement && ((JRDesignComponentElement)child).getComponent() == table) return (JRDesignElement)child;
        if (child instanceof JRElementGroup) {
            JRElementGroup group = (JRElementGroup)child;
            JRDesignElement value = getElementFromTable(group.getElements(), table);
            if (value != null) return value;
        }
    }
    return null;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Create a detail section in a {@link JasperReport}. Checks the {@link JasperReport} fields for a
 * {@link Detail} annotation and processes that {@link Detail} field.
 */
protected JRBand createDetailForSummary(final ReportInfo report) throws Exception {
    final JRDesignBand retval = new JRDesignBand();

    int maxHeight = DETAIL_HEIGHT;
    LOG.debug("Summary: Initial height is "+ DETAIL_HEIGHT);

    retval.setHeight(CELL_HEIGHT + 5);

    LOG.debug("Summary: Detail band has height of "+ maxHeight);
    int y = 0;

    LOG.info("Summary: Adding fields for detail");
    final Field summaryField = getFieldWithAnnotation(report, Summary.class);
    if (isCrosstab(summaryField)) {
        // If the summary has a crosstab, then we want to use the Summary section for rendering the crosstab.
        final Collection<JRChild> elements = processFields(report, Summary.class, Crosstab.class);
        for (final JRChild element : elements) {
            final JRDesignCrosstab crosstab = (JRDesignCrosstab) element;

            LOG.debug("Adding crosstab to summary "+ crosstab+ " with height "+ crosstab.getHeight());
            crosstab.setY(y);
            retval.addElement(crosstab);
            y += crosstab.getHeight() + PAGEHEADER_HEIGHT;
            retval.setHeight(y);
        }
    }
    else {
        // No crosstab, so use the detail
        final JRDesignTextField nameField = normal("$F{name}").toTextField();
        addDesignElementTo(retval, nameField, (CELL_WIDTH * 3 + 5) * 0, 0, CELL_WIDTH * 3, CELL_HEIGHT);

        final JRDesignTextField amountField = normal("$F{amount}").toTextField(java.math.BigDecimal.class);
        addDesignElementTo(retval, amountField, (CELL_WIDTH * 3 + 5) * 1, 0, CELL_WIDTH * 3, CELL_HEIGHT);
    }

    return retval;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Create {@link JRDesignElement} instances used in a {@link JasperReport} based on fields in a {@link ReportInfo} instance.
 * This method tries to be smart about what fields in the {@link ReportInfo} are to be used and how they
 * are used in the input.
 *
 * @param report {@link ReportInfo} instance to process fields on
 * @param annotations is a filter on what fields by the {@link Annotation} they might have.
 * @return {@link Collection} of {@link JRDesignElement} instances that are part of the {@link ReportInfo}
 * @throws Exception because there are a lot of I/O and Reflection actions performed that can
 * potentially cause problems.
 */
protected Collection<JRChild> processFields(final ReportInfo report, final Class ... annotations) throws Exception {
    final Collection<JRChild> retval = new ArrayList<JRChild>();

    for (final Field field : report.getClass().getDeclaredFields()) {
        boolean valid = true;
        valid &= hasAnnotations(field, annotations) && !hasAnnotations(field, Summary.class, SubReport.class);

        if (valid) {
            retval.add(createElementForField(report, field));
        }
    }

    return retval;
}
项目:jasperreports    文件:JRBaseElementGroup.java   
@Override
public List<JRChild> getChildren()
{
    return this.children;
}
项目:jasperreports    文件:JRBaseFrame.java   
@Override
public List<JRChild> getChildren()
{
    return children;
}
项目:jasperreports    文件:CrosstabConverter.java   
/**
     * 
     */
    private JRPrintFrame getCrosstabCellFrame(
        ReportConverter reportConverter,
        JRCellContents cell, 
        int x, 
        int y, 
        boolean left, 
        boolean right, 
        boolean top
        )
    {
        JRBasePrintFrame frame = new JRBasePrintFrame(cell.getDefaultStyleProvider());
        //frame.setUUID(cell.getUUID());
        frame.setX(x);
        frame.setY(y);
        frame.setWidth(cell.getWidth());
        frame.setHeight(cell.getHeight());

        frame.setMode(cell.getModeValue());
        frame.setBackcolor(cell.getBackcolor());
        frame.setStyle(reportConverter.resolveStyle(cell));

        JRLineBox box = cell.getLineBox();
        if (box != null)
        {
            frame.copyBox(box);

            boolean copyLeft = left && box.getLeftPen().getLineWidth().floatValue() <= 0f && box.getRightPen().getLineWidth().floatValue() > 0f;
            boolean copyRight = right && box.getRightPen().getLineWidth().floatValue() <= 0f && box.getLeftPen().getLineWidth().floatValue() > 0f;
            boolean copyTop = top && box.getTopPen().getLineWidth().floatValue() <= 0f && box.getBottomPen().getLineWidth().floatValue() > 0f;

            if (copyLeft)
            {
                ((JRBaseLineBox)frame.getLineBox()).copyLeftPen(box.getRightPen());
            }

            if (copyRight)
            {
                ((JRBaseLineBox)frame.getLineBox()).copyRightPen(box.getLeftPen());
            }

            if (copyTop)
            {
                ((JRBaseLineBox)frame.getLineBox()).copyTopPen(box.getBottomPen());
            }
        }

//      List children = cell.getChildren();
//      if (children != null)
//      {
//          for (Iterator it = children.iterator(); it.hasNext();)
//          {
//              JRChild child = (JRChild) it.next();
//              if (child instanceof JRElement)
//              {
//                  frame.addElement((JRElement) child);
//              }
//              else if (child instanceof JRElementGroup)
//              {
//                  frame.addElementGroup((JRElementGroup) child);
//              }
//          }
//      }
        List<JRChild> children = cell.getChildren();
        if (children != null && children.size() > 0)
        {
            ConvertVisitor convertVisitor = new ConvertVisitor(reportConverter, frame);
            for(int i = 0; i < children.size(); i++)
            {
                children.get(i).visit(convertVisitor);
            }
        }

        return frame;
    }
项目:jasperreports    文件:JRElementsVisitor.java   
protected void visitElements(List<JRChild> elements)
{
    ElementsVisitorUtils.visitElements(this, elements);
}
项目:jasperreports    文件:JRDesignFrame.java   
@Override
public List<JRChild> getChildren()
{
    return children;
}
项目:jasperreports    文件:JRFillElementGroup.java   
@Override
public List<JRChild> getChildren()
{
    return this.children;
}
项目:jasperreports    文件:JRFillFrame.java   
@Override
public List<JRChild> getChildren()
{
    return frameContainer.getChildren();
}
项目:jasperreports    文件:ListDesignConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter,
        JRComponentElement element)
{
    ListComponent list = (ListComponent) element.getComponent();
    if (list == null || list.getContents() == null)
    {
        return null;
    }

    JRBasePrintFrame frame = new JRBasePrintFrame(
            reportConverter.getDefaultStyleProvider());
    reportConverter.copyBaseAttributes(element, frame);

    ListContents contents = list.getContents();
    if (contents.getHeight() > 0)
    {
        JRBasePrintFrame contentsFrame = new JRBasePrintFrame(
                reportConverter.getDefaultStyleProvider());
        contentsFrame.setUUID(element.getUUID());
        contentsFrame.setX(0);
        contentsFrame.setY(0);
        contentsFrame.setWidth(element.getWidth());         
        contentsFrame.setHeight(contents.getHeight());
        contentsFrame.setMode(ModeEnum.TRANSPARENT);

        List<JRChild> children = contents.getChildren();
        if (children != null)
        {
            ConvertVisitor contentsVisitor = new ConvertVisitor(reportConverter, 
                    contentsFrame);
            for (Iterator<JRChild> it = children.iterator(); it
                    .hasNext();)
            {
                JRChild child = it.next();
                child.visit(contentsVisitor);
            }
        }

        frame.addElement(contentsFrame);

        /*
        Integer width = contents.getWidth();
        int contentsWidth = width == null ? element.getWidth() 
                : width.intValue();

        if (contents.getHeight() < element.getHeight() 
                || contentsWidth < element.getWidth())
        {
            // add a grey rectangle to highlight the contents height
            JRBasePrintImage image = new JRBasePrintImage(
                    reportConverter.getDefaultStyleProvider());
            image.setX(0);
            image.setWidth(element.getWidth());
            image.setY(0);
            image.setHeight(element.getHeight());
            image.setMode(ModeEnum.TRANSPARENT);

            // clip out the list contents area
            Area clip = new Area(new Rectangle(
                    0, 0, element.getWidth(), element.getHeight()));
            clip.subtract(new Area(new Rectangle(
                    0, 0, contentsWidth, contents.getHeight())));

            image.setRenderer(new UnusedSpaceImageRenderer(clip));
            frame.addElement(image);
        }
        */
    }

    return frame;
}
项目:jasperreports    文件:TableDesignConverter.java   
@Override
public JRPrintElement convert(ReportConverter reportConverter,
        JRComponentElement element)
{
    TableComponent table = (TableComponent) element.getComponent();
    if (table == null)// || list.getContents() == null)
    {
        return null;
    }

    JRBasePrintFrame frame = new JRBasePrintFrame(
            reportConverter.getDefaultStyleProvider());
    reportConverter.copyBaseAttributes(element, frame);

    TableUtil tableManager = 
        new TableUtil(
            table, 
            reportConverter.getReport()
            );

    Map<Cell, Rectangle> cellBounds = tableManager.getCellBounds();

    for (Map.Entry<Cell, Rectangle> pair : cellBounds.entrySet()) 
    {
        Cell cell = pair.getKey();
        Rectangle rectangle = pair.getValue(); 

        JRBasePrintFrame cellFrame = 
            new JRBasePrintFrame(
                reportConverter.getDefaultStyleProvider()
                );
        cellFrame.setX((int)rectangle.getX());
        cellFrame.setY((int)rectangle.getY());
        cellFrame.setWidth((int)rectangle.getWidth());          
        cellFrame.setHeight((int)rectangle.getHeight());
        cellFrame.setStyle(reportConverter.resolveStyle(cell));

        if (cell.getLineBox() != null)
        {
            cellFrame.copyBox(cell.getLineBox());
        }

        List<JRChild> children = cell.getChildren();
        if (children != null && children.size() > 0)
        {
            ConvertVisitor convertVisitor = new ConvertVisitor(reportConverter, cellFrame);
            for(int i = 0; i < children.size(); i++)
            {
                (children.get(i)).visit(convertVisitor);
            }
        }

        frame.addElement(cellFrame);
    }

    return frame;
}
项目:jasperreports    文件:TableReport.java   
protected void addSummaryGroup(List<FillColumn> fillColumns)
{
    JRDesignGroup summaryGroup = new JRDesignGroup();
    summaryGroup.setName(SUMMARY_GROUP_NAME);//TODO check for uniqueness

    JRDesignBand groupFooter = new JRDesignBand();
    groupFooter.setSplitType(SplitTypeEnum.PREVENT);
    groupFooter.setHeight(pageFooter.getHeight());

    // we need to put everything in a frame so that we can tell the frame
    // not to print when there are no detail bands on the current page
    // 
    // we can't do that directly to the band since its print when expression
    // is evaluated too soon
    JRDesignFrame footerFrame = new JRDesignFrame();
    UUID uuid = DigestUtils.instance().deriveUUID(
            fillContext.getComponentElement().getUUID(), 
            BandTypeEnum.GROUP_FOOTER + "-" + SUMMARY_GROUP_NAME);
    footerFrame.setUUID(uuid);
    footerFrame.setX(0);
    footerFrame.setY(0);
    footerFrame.setWidth(computeTableWidth(fillColumns));
    footerFrame.setHeight(pageFooter.getHeight());
    footerFrame.getLineBox().setPadding(0);
    footerFrame.getLineBox().getPen().setLineWidth(0f);
    footerFrame.setRemoveLineWhenBlank(true);

    JRDesignExpression footerPrintWhen = builtinEvaluatorFactory.createExpression(new SummaryGroupFooterPrintWhenEvaluator());
    footerFrame.setPrintWhenExpression(footerPrintWhen);

    // clone the contents of the page footer in the frame
    List<JRChild> footerElements = pageFooter.getChildren();
    for (Iterator<JRChild> iterator = footerElements.iterator(); iterator
            .hasNext();)
    {
        JRChild child = iterator.next();
        JRChild childClone = (JRChild) child.clone(footerFrame);
        if (childClone instanceof JRElement)
        {
            footerFrame.addElement((JRElement) childClone);
        }
        else if (childClone instanceof JRElementGroup)
        {
            footerFrame.addElementGroup((JRElementGroup) childClone);
        }
        else
        {
            throw 
                new JRRuntimeException(
                    EXCEPTION_MESSAGE_KEY_UNKNOWN_CHILD_TYPE,  
                    new Object[]{childClone.getClass().getName()} 
                    );
        }
    }

    groupFooter.addElement(footerFrame);
    ((JRDesignSection) summaryGroup.getGroupFooterSection()).addBand(groupFooter);

    mainDataset.addScriptlet(TABLE_SCRIPTLET_NAME, TableReportScriptlet.class);
    mainDataset.addFirstGroup(summaryGroup);
}
项目:PDFReporter-Studio    文件:TableTemplateEngine.java   
/**
 * Initialize the fields needed to build the style of the report
 */
@Override
protected void processTemplate(JasperDesign jd, List<Object> fields, List<Object> groupFields) {
    //Initialize the styles list
    stylesList = buildStylesList(jd);
    JRDesignComponentElement tableComponent = getTable(jd);
    summaryHeight = jd.getSummary().getHeight();
    /**
     * If the template table is found it will be used to create the style of the real table and of its 
     * content
     */
    if (tableComponent != null){
        StandardTable table = (StandardTable)tableComponent.getComponent();

        tableWidth = tableComponent.getWidth();
        templateGroupWidth = tableComponent.getWidth();
        tableHeight = tableComponent.getHeight();
        columnWidth = table.getColumns().get(0).getWidth();
        tableX = tableComponent.getX();
        tableY = tableComponent.getY();

        generateTableContentList(table);

        if (table.getColumns().size()>0){
            StandardColumn col = getStandadColumn(table.getColumns().get(0));
            boolean tableHeader = col.getTableHeader() != null;
            boolean tableFooter = col.getTableFooter() != null;
            boolean columnHeader = col.getColumnHeader() != null;
            boolean columnFooter = col.getColumnFooter() != null;
            boolean groupHeader = col.getGroupHeaders() != null && col.getGroupHeaders().size()>0; 
            boolean groupFooter = col.getGroupFooters() != null && col.getGroupFooters().size()>0; 
            sections = new TableSections(tableHeader, tableFooter, columnHeader, columnFooter, groupHeader, groupFooter);
            if (tableHeader) sections.setTableHeaderHeight(col.getTableHeader().getHeight());
            if (tableFooter) sections.setTableFooterHeight(col.getTableFooter().getHeight());
            if (columnHeader) sections.setColumnHeaderHeight(col.getColumnHeader().getHeight());
            if (columnFooter) sections.setColumnFooterHeight(col.getColumnFooter().getHeight());
            if (groupHeader) sections.setGroupHeaderHeight(col.getGroupHeaders().get(0).getCell().getHeight());
            if (groupFooter) sections.setGroupHeaderHeight(col.getGroupFooters().get(0).getCell().getHeight());
            sections.setDetailHeight(col.getDetailCell().getHeight());
        }
        removeElement(jd.getSummary(), tableComponent);
    } else {
        //If the table is not found try to build the template with some default values
        JRDesignStaticText colHeaderLabel = DefaultTemplateEngine.findStaticTextElement(jd.getColumnHeader(), "Label"); //$NON-NLS-1$
        JRDesignTextField cellField = DefaultTemplateEngine.findTextFieldElement(jd.getDetailSection().getBands()[0], "Field"); //$NON-NLS-1$
        tableHeaderContent = new ArrayList<JRDesignElement>();
        tableFooterContent = new ArrayList<JRDesignElement>();
        colFooterContent = new ArrayList<JRDesignElement>();
        colHeaderContent = new ArrayList<JRDesignElement>();
        detailContent = new ArrayList<JRDesignElement>();
        tableGroupField = new ArrayList<List<JRDesignElement>>();
        List<JRDesignElement> fakeGroupPlaceHolder = new ArrayList<JRDesignElement>();
        JRDesignTextField groupElement = new MTextField().createJRElement(jd);
        groupElement.setExpression(ExprUtil.setValues(new JRDesignExpression(), "$F{Group1}", "java.Lang.Object"));
        fakeGroupPlaceHolder.add(groupElement);
        tableGroupField.add(fakeGroupPlaceHolder);

        if (colHeaderLabel != null) colHeaderContent.add(colHeaderLabel);
        if (cellField != null) detailContent.add(cellField);

        tableWidth = jd.getPageWidth()-jd.getLeftMargin()-jd.getRightMargin();

        if (jd.getSummary() == null){
            //I need to create the summary where place the table
            jd.setSummary(MBand.createJRBand());
            ((JRDesignBand)jd.getSummary()).setHeight(jd.getDetailSection().getBands()[0].getHeight());
        }
        tableHeight = jd.getSummary().getHeight();
        tableX = 0;
        tableY = 0;
        sections = new TableSections(false, false, true, true, false, false);
        JRDesignElementGroup summaryBand = (JRDesignElementGroup)jd.getSummary();
        for(JRChild child : summaryBand.getChildren())
            summaryBand.removeElement((JRDesignElement)child);
    }

    removeUnwantedBand(jd);
    jd.removeDataset("tableDataset"); //$NON-NLS-1$
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Determines what to do with a {@link Field} in a {@link ReportInfo} instance by the annotations on that
 * {@link Field} and creates a {@link JRDesignElement} from it.
 *
 *
 * @param param
 * @param field
 * @return {@link JRDesignElement} instance
 * @throws Exception
 */
protected JRChild createElementForField(final ReportInfo report, final Field field) throws Exception {
    LOG.info("Processing field "+ field.getName());
    if (isSubreport(field)) {
        LOG.debug("Creating a report element from field "+ field.getName());
        return createSubreport(report, field);
    }

    if (isCrosstab(field)) {
        LOG.debug("Creating a crosstab from field "+ field.getName());
        final JRDesignCrosstab crosstab       = createCrosstab(report, field);
        final JRDesignCrosstabDataset dataset = new JRDesignCrosstabDataset();
        final JRDesignDatasetRun dsRun        = new JRDesignDatasetRun();
        final JRDesignExpression dsExpression = new JRDesignExpression();
        final String getterName               = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1);
        dsExpression.setText("$P{report}." + getterName + "()");
        dsExpression.setValueClass(JRDataSource.class);
        dsRun.setDatasetName(initialCaps(field.getName()));
        dsRun.setDataSourceExpression(dsExpression);
        dataset.setDatasetRun(dsRun);
        dataset.setDataPreSorted(true);
        crosstab.setDataset(dataset);

        return crosstab;
    }

    if (isSummary(field)) {
        LOG.debug("Building Summary JRDesignBand");
        final JRDesignBand summary = new JRDesignBand();
        final Class dataClass = findDataClassFor(report);

        final JRDesignStaticText header = h3("Summary").toStaticText();
        addDesignElementTo(summary, header, 0, 0, CT_HEADER_WIDTH, PAGEHEADER_HEIGHT);

        int fieldIdx = 0;
        for (final Field dataField : dataClass.getDeclaredFields()) {
            final JRDesignStaticText headerField = h5(dataField.getName()).toStaticText();
            addDesignElementTo(summary, headerField, (CELL_WIDTH * 3 + 5) * fieldIdx, PAGEHEADER_HEIGHT, CELL_WIDTH * 2, CELL_HEIGHT);

            final JRDesignTextField textElement = normal("$F{" + dataField.getName() + "}").toTextField(dataField.getType());
            LOG.debug("Adding summary field "+ dataField.getName()+ " at ("+ (CELL_WIDTH + 5) * fieldIdx+ "+ 0");
            addDesignElementTo(summary, textElement, (CELL_WIDTH * 3 + 5) * fieldIdx, PAGEHEADER_HEIGHT + CELL_HEIGHT, CELL_WIDTH * 3, CELL_HEIGHT);
            fieldIdx++;
        }
        summary.setHeight(SUMMARY_HEIGHT);
        return summary;
    }

    return null;
}
项目:kfs    文件:TravelReportFactoryServiceImpl.java   
/**
 * Overloaded version of {@link #processFields(ReportInfo, Class ...)}.
 *
 * @param report {@link ReportInfo} instance to process fields on
 * @return {@link Collection} of {@link JRDesignElement} instances that are part of the {@link ReportInfo}
 * @throws Exception because there are a lot of I/O and Reflection actions performed that can
 * potentially cause problems.
 */
protected Collection<JRChild> processFields(final ReportInfo report) throws Exception {
    return processFields(report, new Class[] {});
}