Changeset 571


Ignore:
Timestamp:
03/22/11 15:52:15 (2 years ago)
Author:
philsmart
Message:
 
Location:
raptor-web/trunk/src/main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • raptor-web/trunk/src/main/java/uk/ac/cardiff/raptorweb/engine/reports/GraphAndChartPDFReportGenerator.java

    r570 r571  
    105105    private JasperPrint constructReport(File reportTemplateXMLFile, WebSession session) throws IOException, JRException, ColumnBuilderException { 
    106106        log.info("Constructing Report Using DynamicJasper"); 
    107         // List source = new ArrayList(); 
    108         // BufferedImage image = ChartProcessor.extractBufferedImage(session.getGraphmodel().getCurrentJFreeGraph().getChart(), 
    109         // session.getGraphmodel().getChartOptions()); 
    110         // reportBean.setImage(image); 
    111         // ArrayList<String> values = new ArrayList(); 
    112         // values.add("One"); 
    113         // values.add("Two"); 
    114         // reportBean.setState(values); 
    115         // source.add(reportBean); 
    116         // 
    117         // DynamicReportBuilder drb = new DynamicReportBuilder(); 
    118         // drb.setTemplateFile(reportTemplateXMLFile.getCanonicalPath()); 
    119         // 
    120         // drb.addField("image", java.awt.image.BufferedImage.class.getName()); 
    121         // 
    122         // //session.getGraphmodel().getCurrentTableGraph().ge 
    123         // 
    124         // AbstractColumn columnState = ColumnBuilder.getNew().setColumnProperty("state",List.class.getName()).setTitle("State").setWidth(85).build(); 
    125         // drb.addColumn(columnState); 
    126         // DynamicReport dynamicReport = drb.build(); 
    127         // 
    128         // JRDataSource ds = new JRBeanCollectionDataSource(source); 
    129         // JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dynamicReport, new ClassicLayoutManager(), ds); 
    130         String[] columns = new String[session.getGraphmodel().getCurrentTableGraph().getTableSeries().size()+1]; 
    131         columns[0] = "Group";//always group 
    132         int headerCount=1; 
     107 
     108        // construct the table 
     109        String[] columns = new String[session.getGraphmodel().getCurrentTableGraph().getTableSeries().size() + 1]; 
     110        columns[0] = "Group";// always group 
     111        int headerCount = 1; 
    133112        for (TableSeries tseries : session.getGraphmodel().getCurrentTableGraph().getTableSeries()) { 
    134113            columns[headerCount++] = tseries.getSeriesLabel(); 
     
    137116        Object[][] data = new Object[maxNoRows(session.getGraphmodel().getCurrentTableGraph())][columns.length]; 
    138117 
    139  
    140  
    141         int rowCount=0; 
     118        int rowCount = 0; 
    142119        for (ManyRow mrow : session.getGraphmodel().getCurrentTableGraph().getRowsForView()) { 
    143             data[rowCount][0]=mrow.getGroupLabel(); 
    144             Iterator<?> it =mrow.getValues().iterator(); 
    145             headerCount=1; 
    146             while (it.hasNext()){ 
     120            data[rowCount][0] = mrow.getGroupLabel(); 
     121            Iterator<?> it = mrow.getValues().iterator(); 
     122            headerCount = 1; 
     123            while (it.hasNext()) { 
    147124                String value = it.next().toString(); 
    148125                data[rowCount][headerCount++] = value; 
     
    150127            rowCount++; 
    151128        } 
    152         log.debug("{}",Arrays.toString(data)); 
     129        log.debug("{}", Arrays.toString(data)); 
    153130 
    154131        DynamicTableModel model = new DynamicTableModel(); 
     
    156133        model.setData(data); 
    157134 
    158         BufferedImage image = ChartProcessor.extractBufferedImage(session.getGraphmodel().getCurrentJFreeGraph().getChart(),session.getGraphmodel().getChartOptions()); 
    159  
    160         //FastReportBuilder drb = new FastReportBuilder(); 
     135        // construct report and set the template 
    161136        DynamicReportBuilder drb = new DynamicReportBuilder(); 
    162137        drb.setTemplateFile(reportTemplateXMLFile.getCanonicalPath()); 
    163 //      drb.addField("image", java.awt.image.BufferedImage.class.getName()); 
    164  
    165         Style columDetail = new Style(); 
    166         columDetail.setBorder(Border.THIN); 
     138 
    167139        Style columDetailWhite = new Style(); 
    168140        columDetailWhite.setBorder(Border.THIN); 
    169141        columDetailWhite.setBackgroundColor(Color.WHITE); 
     142        columDetailWhite.setHorizontalAlign(HorizontalAlign.CENTER); 
    170143        Style columDetailWhiteBold = new Style(); 
    171144        columDetailWhiteBold.setBorder(Border.THIN); 
    172145        columDetailWhiteBold.setBackgroundColor(Color.WHITE); 
     146 
     147 
     148 
    173149        Style titleStyle = new Style(); 
    174         titleStyle.setFont(new Font(18, Font._FONT_VERDANA, true)); 
    175         Style numberStyle = new Style(); 
    176         numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT); 
    177         Style amountStyle = new Style(); 
    178         amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT); 
    179         amountStyle.setBackgroundColor(Color.cyan); 
    180         amountStyle.setTransparency(Transparency.OPAQUE); 
     150        titleStyle.setFont(new Font(12, Font._FONT_VERDANA, true)); 
     151        titleStyle.setHorizontalAlign(HorizontalAlign.CENTER); 
     152        titleStyle.setBorder(Border.THIN); 
    181153        Style oddRowStyle = new Style(); 
    182154        oddRowStyle.setBorder(Border.NO_BORDER); 
     
    188160        String[] headings = model.getColumnNames(); 
    189161        for (int i = 0; i < headings.length; i++) { 
    190             String key = headings[i]; 
    191             AbstractColumn column = ColumnBuilder.getNew().setColumnProperty(key, String.class.getName()).setTitle(key).setWidth(new Integer(100)).setStyle(columDetailWhite).build(); 
    192             drb.addColumn(column); 
    193  
    194         } 
    195         //drb.setTitle("Sample Report").setTitleStyle(titleStyle).setTitleHeight(new Integer(30)).setSubtitleHeight(new Integer(20)).setDetailHeight(new Integer(15)) 
    196         //      .setPrintBackgroundOnOddRows(true).setOddRowBackgroundStyle(oddRowStyle).setColumnsPerPage(new Integer(1)).setUseFullPageWidth(true).setColumnSpace(new Integer(5)); 
    197         drb.setPrintBackgroundOnOddRows(true).setOddRowBackgroundStyle(oddRowStyle).setColumnsPerPage(new Integer(1)).setUseFullPageWidth(true).setColumnSpace(new Integer(5)); 
    198          
    199 //      ArrayList beans = new ArrayList(); 
    200 //      SimpleRowBean a1 = new SimpleRowBean("header1","row1","VALUE1"); 
    201 //      SimpleRowBean a2 = new SimpleRowBean("header2","row1","VALUE2"); 
    202 //      SimpleRowBean a3 = new SimpleRowBean("header3","row1","VALUE3"); 
    203 //      beans.add(a1); 
    204 //      beans.add(a2); 
    205 //      beans.add(a3); 
    206 // 
    207 //      SimpleRowBean b1 = new SimpleRowBean("header1","row2","VALUE1"); 
    208 //      SimpleRowBean b2 = new SimpleRowBean("header2","row2","VALUE2"); 
    209 //      SimpleRowBean b3 = new SimpleRowBean("header3","row2","VALUE3"); 
    210 //      beans.add(b1); 
    211 //      beans.add(b2); 
    212 //      beans.add(b3); 
    213          
    214         reportBean.setImage(image); 
    215         //beans.add(reportBean); 
    216         //JRBeanCollectionDataSource ds = new JRBeanCollectionDataSource(beans); 
     162            if (i == 0) { 
     163                // group category 
     164                String key = headings[i]; 
     165                AbstractColumn column = ColumnBuilder.getNew().setColumnProperty(key, String.class.getName()).setTitle(key).setWidth(new Integer(100)).setStyle(columDetailWhiteBold).build(); 
     166                column.setHeaderStyle(titleStyle); 
     167                drb.addColumn(column); 
     168            } else { 
     169                String key = headings[i]; 
     170                AbstractColumn column = ColumnBuilder.getNew().setColumnProperty(key, String.class.getName()).setTitle(key).setWidth(new Integer(100)).setStyle(columDetailWhite).build(); 
     171                column.setHeaderStyle(titleStyle); 
     172                drb.addColumn(column); 
     173            } 
     174 
     175        } 
     176 
     177        drb.setPrintBackgroundOnOddRows(true); 
     178        drb.setOddRowBackgroundStyle(oddRowStyle); 
     179        drb.setColumnsPerPage(new Integer(1)); 
     180        drb.setUseFullPageWidth(true); 
     181        drb.setColumnSpace(new Integer(5)); 
     182        drb.setDetailHeight(new Integer(15)); 
     183 
     184        // add any additional parameters that are mapped to the template 
     185        BufferedImage image = ChartProcessor.extractBufferedImage(session.getGraphmodel().getCurrentJFreeGraph().getChart(), session.getGraphmodel().getChartOptions()); 
     186 
    217187        Map parameters = new HashMap(); 
    218188        parameters.put("image", image); 
    219         log.debug("Map: "+parameters); 
    220 //      JasperReport jasperReport = JasperCompileManager.compileReport(reportTemplateXMLFile.getCanonicalPath()); 
    221          
    222 //      JasperPrint jp = JasperFillManager.fillReport(jasperReport, parameters, ds); 
     189        parameters.put("subtitle", session.getGraphmodel().getSelectedStatisticalUnit().getStatisticalUnitInformation().getStatisticParameters().getPresentation().getGraphTitle()); 
     190        log.debug("Map: " + parameters); 
    223191 
    224192        DynamicReport dr = drb.build(); 
    225193        JRDataSource ds = new JRTableModelDataSource(model); 
    226         JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds,parameters); 
     194        JasperPrint jp = DynamicJasperHelper.generateJasperPrint(dr, new ClassicLayoutManager(), ds, parameters); 
    227195        return jp; 
    228196    } 
     
    234202    private int maxNoRows(RaptorTableChartModel currentTableGraph) { 
    235203        int maxRows = 0; 
    236          for (TableSeries tseries :currentTableGraph.getTableSeries()){ 
    237              if (tseries.getRows().size()>maxRows) 
    238                  maxRows=tseries.getRows().size(); 
    239          } 
    240          return maxRows; 
     204        for (TableSeries tseries : currentTableGraph.getTableSeries()) { 
     205            if (tseries.getRows().size() > maxRows) 
     206                maxRows = tseries.getRows().size(); 
     207        } 
     208        return maxRows; 
    241209    } 
    242210 
  • raptor-web/trunk/src/main/webapp/report-templates/generic-report.xml

    r570 r571  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="DataSourceReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50"> 
    3         <style name="Sans_Normal" isDefault="true" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/> 
    4         <style name="Sans_Bold" isDefault="false" fontName="DejaVu Sans" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/> 
    5         <style name="Sans_Italic" isDefault="false" fontName="DejaVu Sans" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/> 
    6         <parameter name="image" class="java.awt.Image"/> 
    7         <field name="description" class="java.lang.String"/> 
     3    <!--  This report is augmented with a table by DynamicJasper. DynamicJasper prohibits the use of the following 
     4    aspects of Jasper report templates: 
     5      The template must not have groups, DynamicJAsper will create them if necessary. 
     6           The detail band must be empty: DynamicJasper will work in the detail band, any previously existing element will be deleted. 
     7           One template per page size and orientation will be needed: This is because DJ knows how to arrange the element he creates, but not the existing ones. 
     8           The following options will be always overwritten by the dynamic report 
     9               number of columns 
     10               When-No-Data behavior 
     11               When-Resource-Missing behavior 
     12               Title start on new page flag (false by default) 
     13               Ignore Pagination flag (false by default) 
     14               Detail Band Split allowed flag (true by default) 
     15               Summary start on new page flag (false by default) 
     16     --> 
     17    <parameter name="image" class="java.awt.Image"/> 
    818 
    9          <title> 
    10  <!--  <band height="50"> 
    11       <staticText> 
    12         <reportElement x="0" y="0" width="180" height="15"/> 
    13         <textElement> 
    14                 <font fontName="DejaVu Sans" size="9"/> 
    15         </textElement> 
    16         <text><![CDATA[RaptorWeb Report]]></text> 
    17       </staticText>  
    18     </band>--> 
    19     <band height="600"> 
    20                         <staticText> 
    21                                 <reportElement x="0" y="10" width="311" height="20"/> 
    22                                 <textElement textAlignment="Center"> 
    23                                         <font fontName="DejaVu Sans" size="20"/> 
    24                                 </textElement> 
    25                                 <text><![CDATA[Report Title]]></text> 
    26                         </staticText> 
    27                         <image scaleImage="RetainShape" hAlign="Center" isUsingCache="true" isLazy="true"> 
    28                                 <reportElement x="0" y="30" width="500" height="500"/> 
    29                                 <imageExpression class="java.awt.Image"><![CDATA[$P{image}]]></imageExpression> 
    30                         </image> 
    31                 </band> 
    32         </title> 
    33         <pageHeader> 
    34     <band/> 
    35         </pageHeader> 
    36          
     19    <!--  The integration of a chart and table with dynamic Jasper requires the chart (or image) to be placed in the pages 
     20    Title area  --> 
     21    <title> 
     22    <band height="72"> 
     23            <frame> 
     24                <reportElement mode="Opaque" x="-20" y="-20" width="540" height="92" backcolor="#006699"/> 
     25                <staticText> 
     26                    <reportElement x="20" y="20" width="234" height="43" forecolor="#FFFFFF"/> 
     27                    <textElement> 
     28                        <font size="34" isBold="true"/> 
     29                    </textElement> 
     30                    <text><![CDATA[Report]]></text> 
     31                </staticText> 
     32                <textField> 
     33                    <reportElement x="70" y="43" width="465" height="20" forecolor="#FFFFFF"/> 
     34                    <textElement textAlignment="Right"> 
     35                        <font size="13" isBold="false"/> 
     36                    </textElement> 
     37                    <textFieldExpression><![CDATA[$P{subtitle}]]></textFieldExpression> 
     38                </textField> 
     39            </frame> 
     40            <image scaleImage="RetainShape" hAlign="Center" isUsingCache="true" isLazy="true"> 
     41                <reportElement x="0" y="100" width="500" height="500"/> 
     42                <imageExpression class="java.awt.Image"><![CDATA[$P{image}]]></imageExpression> 
     43            </image> 
     44        </band> 
     45     </title> 
     46 
     47 
    3748        <detail> 
    3849                <band> 
    39                         <staticText> 
    40         <reportElement x="0" y="0" width="40" height="15"/> 
    41         <textElement> 
    42             <font fontName="DejaVu Sans" size="8"/> 
    43         </textElement> 
    44         <text><![CDATA[Page:]]></text> 
    45       </staticText> 
     50            <!-- This band in the detail is where DynamicJasper will add the table, please leave --> 
    4651                </band> 
    47                  
     52 
    4853        </detail> 
    4954 
    50         <pageFooter> 
    51     <band height="15"> 
    52       <staticText> 
    53         <reportElement x="0" y="0" width="40" height="15"/> 
    54         <textElement> 
    55             <font fontName="DejaVu Sans" size="8"/> 
    56         </textElement> 
    57         <text><![CDATA[Page:]]></text> 
    58       </staticText> 
    59       <textField> 
    60         <reportElement x="40" y="0" width="100" height="15"/> 
    61         <textElement> 
    62                 <font fontName="DejaVu Sans" size="8"/> 
    63         </textElement> 
    64         <textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression> 
    65       </textField> 
    66     </band> 
    67   </pageFooter> 
     55    <pageFooter> 
     56        <band height="17"> 
     57            <textField> 
     58                <reportElement mode="Opaque" x="0" y="4" width="480" height="13" backcolor="#E6E6E6"/> 
     59                <textElement textAlignment="Right"> 
     60                    <font fontName="DejaVu Sans" size="8"/> 
     61                </textElement> 
     62                <textFieldExpression class="java.lang.String"><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression> 
     63            </textField> 
     64            <textField evaluationTime="Report"> 
     65                <reportElement mode="Opaque" x="480" y="4" width="40" height="13" backcolor="#E6E6E6"/> 
     66                <textElement> 
     67                    <font fontName="DejaVu Sans" size="8"/> 
     68                </textElement> 
     69                <textFieldExpression class="java.lang.String"><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression> 
     70            </textField> 
     71            <textField pattern="EEEEE dd MMMMM yyyy"> 
     72                <reportElement x="0" y="4" width="100" height="13"/> 
     73                <textElement> 
     74                    <font fontName="DejaVu Sans" size="8"/> 
     75                </textElement> 
     76                <textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression> 
     77            </textField> 
     78        </band> 
     79    </pageFooter> 
     80    <summary> 
     81        <band/> 
     82    </summary> 
    6883</jasperReport> 
Note: See TracChangeset for help on using the changeset viewer.