iReport Ultimate Guide - Nimsoft Library
iReport Ultimate Guide - Nimsoft Library iReport Ultimate Guide - Nimsoft Library
iReport Ultimate GuideCode Example 11-7Sample personalized data sourceimport net.sf.jasperreports.engine.*;import java.io.*;public class JRFileSystemDataSource implements JRDataSource{File[] files = null;int index = -1;public JRFileSystemDataSource(String path){File dir = new File(path);if (dir.exists() && dir.isDirectory()){files = dir.listFiles();}}public JRFileSystemDataSource(){this(".");204
Data Sources and Query ExecutersCode Example 11-7Sample personalized data source, continued}public boolean next() throws JRException{index++;if (files != null && index < files.length){return true;}return false;}}public Object getFieldValue(JRField jrField) throws JRException{File f = files[index];if (f == null) return null;if (jrField.getName().equals("FILENAME")){return f.getName();}else if (jrField.getName().equals("IS_DIRECTORY")){return new Boolean(f.isDirectory());}else if (jrField.getName().equals("SIZE")){return new Long(f.length());}// Field not found...return null;}The getFieldValue method will return the requested file information. Your implementation does not use the informationregarding the return type expected by the caller of the method, but it assumes that the name has to be returned as a string, theflag IS_DIRECTORY as a Boolean object, and the file size as a Long object.In the next section, you will learn how to use your personalized data source in iReport and test it.11.6.12 Using a Personalized JRDataSource with iReportiReport provides support for almost all the data sources provided by UR, such as JRXmlDataSource,JRBeanArrayDataSource, and JRBeanCollectionDataSource.To use your personalized data sources, a special connection is provided. It is useful for employing whatever JRDataSourceyou want to use through some kind of factory class that provides an instance of that JRDataSource implementation. Thefactory is just a simple Java class useful to test your data source and to fill a report in iReport. The idea is the same as what youhave seen for the JavaBeans set data source—it is necessary to write a Java class that creates the data source through a static205
- Page 153 and 154: SubreportsFigure 10-3Subreport elem
- Page 155 and 156: SubreportsFigure 10-4Subreport Para
- Page 157 and 158: SubreportsFigure 10-7Just a list of
- Page 159 and 160: SubreportsFigure 10-11 Subreport Wi
- Page 161 and 162: SubreportsFigure 10-14 The final re
- Page 163 and 164: Subreports3. Click the Add button t
- Page 165 and 166: Subreports10.4 Using the Subreport
- Page 167 and 168: SubreportsFigure 10-21 Subreport co
- Page 169 and 170: SubreportsFigure 10-23 Setting Subr
- Page 171 and 172: Data Sources and Query ExecutersCHA
- Page 173 and 174: Data Sources and Query Executers•
- Page 175 and 176: Data Sources and Query ExecutersFig
- Page 177 and 178: Data Sources and Query ExecutersFig
- Page 179 and 180: Data Sources and Query ExecutersFig
- Page 181 and 182: Data Sources and Query ExecutersFig
- Page 183 and 184: Data Sources and Query ExecutersFig
- Page 185 and 186: Data Sources and Query ExecutersFig
- Page 187 and 188: Data Sources and Query Executers•
- Page 189 and 190: Data Sources and Query ExecutersAft
- Page 191 and 192: Data Sources and Query ExecutersIns
- Page 193 and 194: Data Sources and Query Executerspub
- Page 195 and 196: Data Sources and Query ExecutersFig
- Page 197 and 198: Data Sources and Query ExecutersFig
- Page 199 and 200: Data Sources and Query Executersbe
- Page 201 and 202: Data Sources and Query ExecutersFig
- Page 203: Data Sources and Query ExecutersWhe
- Page 207 and 208: Data Sources and Query ExecutersPre
- Page 209 and 210: Data Sources and Query ExecutersFig
- Page 211 and 212: Data Sources and Query Executersspe
- Page 213 and 214: Data Sources and Query Executers•
- Page 215 and 216: Data Sources and Query Executersof
- Page 217 and 218: Data Sources and Query ExecutersThi
- Page 219 and 220: Data Sources and Query ExecutersCod
- Page 221 and 222: Data Sources and Query ExecutersIf
- Page 223 and 224: ChartsCHAPTER 12 CHARTSUR provides
- Page 225 and 226: ChartsFigure 12-3Chart selection wi
- Page 227 and 228: ChartsFigure 12-6Dataset configurat
- Page 229 and 230: settings). These four fields have t
- Page 231 and 232: ChartsFigure 12-10 Chart Theme Desi
- Page 233 and 234: ChartsFigure 12-12 Example chart th
- Page 235 and 236: Run your report. iReport should dis
- Page 237 and 238: Charts1. First create a report.Figu
- Page 239 and 240: Charts4. Right-click on the chart a
- Page 241 and 242: Flash ChartsCHAPTER 13 FLASH CHARTS
- Page 243 and 244: Flash ChartsThe layout properties f
- Page 245 and 246: Flash ChartsThe following figure sh
- Page 247 and 248: Flash ChartsTable 13-2Entity IDs of
- Page 249 and 250: Flash ChartsTable 13-3Entity expres
- Page 251 and 252: Flash ChartsFigure 13-10 Specifying
- Page 253 and 254: Flash ChartsFigure 13-12 Bar chart
Data Sources and Query ExecutersCode Example 11-7Sample personalized data source, continued}public boolean next() throws JRException{index++;if (files != null && index < files.length){return true;}return false;}}public Object getFieldValue(JRField jrField) throws JRException{File f = files[index];if (f == null) return null;if (jrField.getName().equals("FILENAME")){return f.getName();}else if (jrField.getName().equals("IS_DIRECTORY")){return new Boolean(f.isDirectory());}else if (jrField.getName().equals("SIZE")){return new Long(f.length());}// Field not found...return null;}The getFieldValue method will return the requested file information. Your implementation does not use the informationregarding the return type expected by the caller of the method, but it assumes that the name has to be returned as a string, theflag IS_DIRECTORY as a Boolean object, and the file size as a Long object.In the next section, you will learn how to use your personalized data source in <strong>iReport</strong> and test it.11.6.12 Using a Personalized JRDataSource with <strong>iReport</strong><strong>iReport</strong> provides support for almost all the data sources provided by UR, such as JRXmlDataSource,JRBeanArrayDataSource, and JRBeanCollectionDataSource.To use your personalized data sources, a special connection is provided. It is useful for employing whatever JRDataSourceyou want to use through some kind of factory class that provides an instance of that JRDataSource implementation. Thefactory is just a simple Java class useful to test your data source and to fill a report in <strong>iReport</strong>. The idea is the same as what youhave seen for the JavaBeans set data source—it is necessary to write a Java class that creates the data source through a static205