Source Code Cross Referenced for CubeJasperReportDefinition.java in  » Report » jmagallanes-1.0 » com » calipso » reportgenerator » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » jmagallanes 1.0 » com.calipso.reportgenerator.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.calipso.reportgenerator.common;
0002:
0003:        import javax.swing.table.TableModel;
0004:        import java.util.*;
0005:        import java.text.NumberFormat;
0006:        import java.text.DecimalFormat;
0007:
0008:        import net.sf.jasperreports.engine.design.*;
0009:        import net.sf.jasperreports.engine.design.JRDesignGroup;
0010:        import net.sf.jasperreports.engine.design.JRDesignBand;
0011:        import net.sf.jasperreports.engine.design.JRDesignStaticText;
0012:        import net.sf.jasperreports.engine.design.JRDesignReportFont;
0013:        import net.sf.jasperreports.engine.*;
0014:        import net.sf.jasperreports.engine.util.JRSaver;
0015:        import com.calipso.reportgenerator.common.*;
0016:
0017:        /**
0018:         * Construye una definición para los reportes dinamicos (Jasper)
0019:         */
0020:
0021:        public class CubeJasperReportDefinition implements  IJasperDefinition {
0022:
0023:            private Map fields;
0024:            private Map variables;
0025:            private TableModel data;
0026:            private String tittle;
0027:            private Vector dimensions;
0028:            private Vector metrics;
0029:            private Vector accuMetrics;
0030:            private Vector nonGroupingDimensions;
0031:            private int nonGroupingDimensionsCount;
0032:            private Vector dimensionsSizes;
0033:            private Vector metricsSizes;
0034:            private Vector accuMetricsSizes;
0035:            private Vector nonGroupingDimensionsSizes;
0036:            private Vector rowsTotalsSizes;
0037:            private int printAt;
0038:            private Vector metricsPosition = new Vector();
0039:            private Vector nonGroupingDimensionPosition = new Vector();
0040:            private Vector groupingDimensionPosition = new Vector();
0041:            private ReportResult reportResult;
0042:            private String numberFormatPattern;
0043:            private Vector metricsWidth;
0044:            private Vector accMetricsPosition;
0045:            private Vector accMetricsWidht;
0046:            private Vector columnIdentifiersPos;
0047:            private Vector rowsTotals;
0048:            private Vector rowsTotalsWidht;
0049:            private Vector rowsTotalsPosition;
0050:            private Map reportParams;
0051:
0052:            /**
0053:             * Inicializa una instancia de <coe>eJasperReportDefinition</code>
0054:             * @param reportResult
0055:             * @param data
0056:             * @param dimensionsCount
0057:             * @param metricsCount
0058:             * @param nonGroupingDimensionsCount
0059:             * @param accuMetricsCount
0060:             * @param tittle
0061:             */
0062:            public CubeJasperReportDefinition(ReportResult reportResult,
0063:                    TableModel data, int dimensionsCount, int metricsCount,
0064:                    int nonGroupingDimensionsCount, int accuMetricsCount,
0065:                    String tittle) throws InfoException {
0066:                this .data = data;
0067:                this .tittle = tittle;
0068:                this .reportResult = reportResult;
0069:                metricsWidth = new Vector();
0070:                accMetricsPosition = new Vector();
0071:                accMetricsWidht = new Vector();
0072:                rowsTotalsWidht = new Vector();
0073:                rowsTotalsPosition = new Vector();
0074:                this .nonGroupingDimensionsCount = nonGroupingDimensionsCount;
0075:                initializeVectors(dimensionsCount, metricsCount,
0076:                        nonGroupingDimensionsCount, accuMetricsCount);
0077:                reportParams = reportResult.getParamValues();
0078:                dimensionsSizes = calculateBestLenghts(dimensions);
0079:                metricsSizes = calculateBestLenghts(metrics);
0080:                accuMetricsSizes = calculateBestLenghts(this .accuMetrics);
0081:                nonGroupingDimensionsSizes = calculateBestLenghts(nonGroupingDimensions);
0082:                rowsTotalsSizes = calculateBestLenghts(rowsTotals);
0083:                initializeNumberFormatPattern();
0084:
0085:            }
0086:
0087:            private void initializeNumberFormatPattern() {
0088:                NumberFormat format = NumberFormat
0089:                        .getInstance(LanguageTraslator.getLocale());
0090:                numberFormatPattern = ((DecimalFormat) format).toPattern();
0091:            }
0092:
0093:            /**
0094:             * Retorna la definicion del reporte
0095:             * @return
0096:             * @throws net.sf.jasperreports.engine.JRException
0097:             */
0098:            public JasperDesign getJasperDefinition(boolean isLandscape)
0099:                    throws JRException {
0100:                JasperDesign jasperDesign = new JasperDesign();
0101:                if (isLandscape) {
0102:                    jasperDesign
0103:                            .setOrientation(JasperDesign.ORIENTATION_LANDSCAPE);
0104:                    jasperDesign
0105:                            .setPrintOrder(JasperDesign.PRINT_ORDER_VERTICAL);
0106:                    jasperDesign.setPageWidth(842);
0107:                    jasperDesign.setPageHeight(595);
0108:                } else {
0109:                    jasperDesign
0110:                            .setOrientation(JasperDesign.ORIENTATION_PORTRAIT);
0111:                    jasperDesign
0112:                            .setPrintOrder(JasperDesign.PRINT_ORDER_HORIZONTAL);
0113:                    jasperDesign.setPageWidth(595);
0114:                    jasperDesign.setPageHeight(842);
0115:                }
0116:                jasperDesign.setName("BasicReport");
0117:                addFields(jasperDesign);
0118:                addDetails(jasperDesign);
0119:                addGroups(jasperDesign);
0120:                addVariables(jasperDesign);
0121:                addTitle(jasperDesign);
0122:                addParams(jasperDesign);
0123:                //addPageHeader(jasperDesign);
0124:                return jasperDesign;
0125:            }
0126:
0127:            /**
0128:             * Agrega los parametros del reporte a la definicion del jasper para que puedan ser utilizados en la visualizacion.
0129:             * @param jasperDesign
0130:             * @throws JRException
0131:             */
0132:            private void addParams(JasperDesign jasperDesign)
0133:                    throws JRException {
0134:                for (Iterator iterator = reportParams.entrySet().iterator(); iterator
0135:                        .hasNext();) {
0136:                    Map.Entry param = (Map.Entry) iterator.next();
0137:                    JRDesignParameter parameter = new JRDesignParameter();
0138:                    parameter.setName(param.getKey().toString());
0139:                    parameter.setDescription(param.getKey().toString());
0140:                    Class paramClass = getClassFor(param);
0141:                    parameter.setValueClass(paramClass);
0142:                    jasperDesign.addParameter(parameter);
0143:                }
0144:            }
0145:
0146:            /**
0147:             * Obtiene la clase a la que pertenece el valor de un parametro dado.
0148:             * @param param
0149:             * @return
0150:             */
0151:            private Class getClassFor(Map.Entry param) {
0152:                Class result = java.lang.String.class;
0153:                Map map = new HashMap();
0154:                map.put(param.getKey(), param.getValue());
0155:                ReportMap.setParametersToSimpleType(map);
0156:                if (map.get(param.getKey()) != null) {
0157:                    result = map.get(param.getKey()).getClass();
0158:                }
0159:                return result;
0160:            }
0161:
0162:            /**
0163:             * Agrega los campos a la definicion
0164:             * @param jasperDesign
0165:             * @throws net.sf.jasperreports.engine.JRException
0166:             */
0167:            private void addFields(JasperDesign jasperDesign)
0168:                    throws JRException {
0169:                //Fields
0170:                String name;
0171:                if (dimensions.size() == 0) {
0172:                    dimensions.add("NONE");
0173:                    dimensionsSizes.add(new Integer(20));
0174:                }
0175:                for (int i = 0; i < dimensions.size(); i++) {
0176:                    JRDesignField field = new JRDesignField();
0177:                    name = dimensions.elementAt(i).toString();
0178:                    field.setName(name);
0179:                    if (reportResult.getDimensionFromName(name) != null) {
0180:                        field.setValueClass(ReportMap
0181:                                .getJavaLangType(reportResult
0182:                                        .getDimensionFromName(name)
0183:                                        .getDataType()));//java.lang.String.class);
0184:                    } else {
0185:                        field.setValueClass(java.lang.String.class);
0186:                    }
0187:                    jasperDesign.addField(field);
0188:                }
0189:                for (int i = 0; i < nonGroupingDimensions.size(); i++) {
0190:                    //if(i + 1 == nonGroupingDimensions.size()) {
0191:                    JRDesignField field = new JRDesignField();
0192:                    name = nonGroupingDimensions.elementAt(i).toString();
0193:                    field.setName(name);
0194:                    field.setValueClass(ReportMap.getJavaLangType(reportResult
0195:                            .getDimensionFromName(name).getDataType()));//java.lang.String.class);
0196:                    jasperDesign.addField(field);
0197:                    //}
0198:                }
0199:                for (int i = 0; i < metrics.size(); i++) {
0200:                    JRDesignField field = new JRDesignField();
0201:                    name = metrics.elementAt(i).toString();
0202:                    field.setName(name);
0203:                    field.setValueClass(java.lang.Float.class);
0204:                    jasperDesign.addField(field);
0205:                }
0206:                for (int i = 0; i < accuMetrics.size(); i++) {
0207:                    JRDesignField field = new JRDesignField();
0208:                    name = accuMetrics.elementAt(i).toString();
0209:                    field.setName(name);
0210:                    field.setValueClass(java.lang.Float.class);
0211:                    jasperDesign.addField(field);
0212:                }
0213:                for (int i = 0; i < rowsTotals.size(); i++) {
0214:                    JRDesignField field = new JRDesignField();
0215:                    name = rowsTotals.elementAt(i).toString();
0216:                    field.setName(name);
0217:                    field.setValueClass(java.lang.Float.class);
0218:                    jasperDesign.addField(field);
0219:                }
0220:
0221:            }
0222:
0223:            /**
0224:             * Agrega los grupos a la definicion
0225:             * @param jasperDesign
0226:             * @throws net.sf.jasperreports.engine.JRException
0227:             */
0228:            private void addGroups(JasperDesign jasperDesign)
0229:                    throws JRException {
0230:                //groups
0231:                JRDesignExpression expression;
0232:                JRDesignBand band;
0233:                JRDesignGroup group = null;
0234:                printAt = 0;
0235:                for (int j = 0; j < dimensions.size(); j++) {
0236:                    group = new JRDesignGroup();
0237:                    group
0238:                            .setName(dimensions.elementAt(j).toString()
0239:                                    + "_GROUP");
0240:                    group.setReprintHeaderOnEachPage(true);
0241:                    expression = new JRDesignExpression();
0242:                    if (reportResult.getDimensionFromName(dimensions.elementAt(
0243:                            j).toString()) != null) {
0244:                        expression.setValueClass(ReportMap
0245:                                .getJavaLangType(reportResult
0246:                                        .getDimensionFromName(
0247:                                                dimensions.elementAt(j)
0248:                                                        .toString())
0249:                                        .getDataType()));//java.lang.String.class);
0250:                    } else {
0251:                        expression.setValueClass(java.lang.String.class);
0252:                    }
0253:                    expression.setText("$F{" + dimensions.elementAt(j) + "}");
0254:                    group.setExpression(expression);
0255:
0256:                    if (j + 1 == dimensions.size()) {
0257:                        band = new JRDesignBand();
0258:                        band.setHeight(60);
0259:                    } else {
0260:                        band = new JRDesignBand();
0261:                        band.setHeight(20);
0262:                    }
0263:
0264:                    JRDesignStaticText text = new JRDesignStaticText();
0265:                    String caption = "";
0266:                    if (!dimensions.elementAt(j).toString().equalsIgnoreCase(
0267:                            "NONE")) {
0268:                        caption = reportResult.getReportSpec()
0269:                                .getDimensionFromName(
0270:                                        dimensions.elementAt(j).toString())
0271:                                .getCaption()
0272:                                + ":";
0273:                    }
0274:                    text.setX(0);
0275:                    text.setY(0);
0276:                    text.setWidth(getLenghtForCaption((new Integer(caption
0277:                            .length())).intValue()));
0278:                    text.setHeight(20);
0279:                    text.setText(caption);
0280:                    JRDesignReportFont bigFont = new JRDesignReportFont();
0281:                    bigFont.setFontSize(11);
0282:                    bigFont.setBold(true);
0283:                    bigFont.setItalic(true);
0284:                    text.setFont(bigFont);
0285:                    band.addElement(text);
0286:
0287:                    JRDesignTextField textField = new JRDesignTextField();
0288:                    textField.setX(getLenghtForCaption((new Integer(caption
0289:                            .length())).intValue()));
0290:                    textField.setY(0);
0291:                    if (data.getRowCount() == 1) {
0292:                        textField.setWidth(dimensions.elementAt(j).toString()
0293:                                .length() * 3);
0294:                    } else {
0295:                        textField
0296:                                .setWidth(getLenghtForCaption(((Integer) dimensionsSizes
0297:                                        .elementAt(j)).intValue()));
0298:                    }
0299:                    textField.setHeight(20);
0300:                    expression = new JRDesignExpression();
0301:                    if (reportResult.getDimensionFromName(dimensions.elementAt(
0302:                            j).toString()) != null) {
0303:                        expression.setValueClass(ReportMap
0304:                                .getJavaLangType(reportResult
0305:                                        .getDimensionFromName(
0306:                                                dimensions.elementAt(j)
0307:                                                        .toString())
0308:                                        .getDataType()));//java.lang.String.class);
0309:                    } else {
0310:                        expression.setValueClass(java.lang.String.class);
0311:                    }
0312:                    expression.setText("$F{" + dimensions.elementAt(j) + "}");
0313:                    textField.setExpression(expression);
0314:                    band.addElement(textField);
0315:
0316:                    if ((nonGroupingDimensions.size() >= 0)
0317:                            && (dimensions.size() == j + 1)) {
0318:
0319:                        //Empezamos estableciendo las descripciones de cada dimension que no agrupa
0320:                        //para cada conjunto de metricas. Es decir, los valores de la dimension que
0321:                        //estan ubicados en column.
0322:                        Vector vector = null;
0323:                        try {
0324:                            vector = reportResult.getReportTableModel()
0325:                                    .getOccurrences();
0326:                        } catch (InfoException e) {
0327:                            throw new JRException(e);
0328:                        }
0329:                        if (vector.size() > 0) {
0330:                            for (int i = 0; i < vector.size(); i++) {
0331:                                String s = (String) vector.elementAt(i);
0332:                                text = new JRDesignStaticText();
0333:                                text.setX(((Integer) columnIdentifiersPos
0334:                                        .elementAt(i)).intValue());
0335:                                text.setY(20);
0336:                                text.setWidth(getLenghtForCaption((new Integer(
0337:                                        s.length())).intValue()));
0338:                                text.setHeight(20);
0339:                                text.setText(s/* + ": "*/);
0340:                                band.addElement(text);
0341:                            }
0342:
0343:                            if (reportResult.getReportQuery().isVisibleTotals()) {
0344:                                text = new JRDesignStaticText();
0345:                                text.setX(((Integer) rowsTotalsPosition
0346:                                        .elementAt(0)).intValue());
0347:                                text.setY(20);
0348:                                text.setWidth(40);
0349:                                text.setHeight(20);
0350:                                text
0351:                                        .setText(LanguageTraslator
0352:                                                .traslate("358") /*+ ":"*/);
0353:                                band.addElement(text);
0354:                            }
0355:
0356:                            //Continuamos con los nombres de las dimensiones que no agrupan
0357:                            for (int i = 0; i < nonGroupingDimensions.size(); i++) {
0358:                                String s = (String) nonGroupingDimensions
0359:                                        .elementAt(i);
0360:                                caption = reportResult.getReportSpec()
0361:                                        .getDimensionFromName(s).getCaption();
0362:                                text = new JRDesignStaticText();
0363:                                text
0364:                                        .setX(((Integer) nonGroupingDimensionPosition
0365:                                                .elementAt(i)).intValue());
0366:                                text.setY(40);
0367:                                text.setWidth(getLenghtForCaption((new Integer(
0368:                                        s.length())).intValue()));
0369:                                text.setHeight(20);
0370:                                text.setText(caption/* + ": "*/);
0371:                                band.addElement(text);
0372:                            }
0373:                        }
0374:
0375:                        //Continuamos con las descripciones de las metricas
0376:                        ReportMetricSpec metricSpec = null;
0377:                        for (int i = 0; i < metrics.size(); i++) {
0378:                            /*String s = (String) metrics.elementAt(i);
0379:                            if (nonGroupingDimensions.size()>0) {
0380:                              String metricName;
0381:                              if(s.split("_").length > 1) {
0382:                                StringTokenizer tokenizer = new StringTokenizer(s, "_");
0383:                                tokenizer.nextToken();
0384:                                metricName = "";
0385:                                while (tokenizer.hasMoreTokens()){
0386:                                  metricName += (tokenizer.nextToken());
0387:                                  if(tokenizer.hasMoreTokens()){
0388:                                      metricName += "_";
0389:                                  }
0390:                                }
0391:                              }else{
0392:                                metricName = s;
0393:                              }
0394:                              metricSpec =  reportResult.getReportSpec().getMetricFromName(metricName);
0395:                            } else {
0396:                              metricSpec =  reportResult.getReportSpec().getMetricFromName(s);
0397:                            }*/
0398:                            String s = getMetricName((String) metrics
0399:                                    .elementAt(i));
0400:                            metricSpec = reportResult.getReportSpec()
0401:                                    .getMetricFromName(s);
0402:                            text = new JRDesignStaticText();
0403:                            text.setX(((Integer) metricsPosition.elementAt(i))
0404:                                    .intValue());
0405:                            text.setY(40);
0406:                            text.setWidth(getLenghtForCaption((new Integer(s
0407:                                    .length())).intValue()));
0408:                            text.setHeight(20);
0409:                            text.setText(metricSpec.getCaption() /*+ ": "*/);
0410:                            band.addElement(text);
0411:                        }
0412:
0413:                        for (int i = 0; i < rowsTotals.size(); i++) {
0414:                            String s = (String) rowsTotals.elementAt(i);
0415:                            StringTokenizer tokenizer = new StringTokenizer(s,
0416:                                    "_");
0417:                            tokenizer.nextToken();
0418:                            String metricName = "";
0419:                            while (tokenizer.hasMoreTokens()) {
0420:                                metricName += (tokenizer.nextToken());
0421:                                if (tokenizer.hasMoreTokens()) {
0422:                                    metricName += "_";
0423:                                }
0424:                            }
0425:                            metricSpec = reportResult
0426:                                    .getMetricFromName(metricName);
0427:                            text = new JRDesignStaticText();
0428:                            text.setX(((Integer) rowsTotalsPosition
0429:                                    .elementAt(i)).intValue());
0430:                            text.setY(40);
0431:                            text.setWidth(getLenghtForCaption((new Integer(s
0432:                                    .length())).intValue()));
0433:                            text.setHeight(20);
0434:                            text.setText(metricSpec.getCaption() /*+ ": "*/);
0435:                            band.addElement(text);
0436:
0437:                        }
0438:
0439:                    }
0440:                    if (dimensions.elementAt(j).toString().equalsIgnoreCase(
0441:                            "NONE")) {
0442:                        band = null;
0443:                    }
0444:                    group.setGroupHeader(band);
0445:
0446:                    /*if(j + 1 == dimensions.size()) {
0447:                      for(int i = 0 ; i < nonGroupingDimensions.size() ; i++) {
0448:                        int x = ((Integer) nonGroupingDimensionPosition.elementAt(i)).intValue();
0449:                        text = new JRDesignStaticText();
0450:                        text.setX(x);
0451:                        text.setY(20);
0452:                        //text.setWidth(((Integer) metricsWidth.elementAt(i)).intValue());
0453:                        int first = getLenghtForCaption(((Integer) nonGroupingDimensionsSizes.elementAt(i)).intValue());
0454:                        int second = getLenghtForCaption(nonGroupingDimensions.elementAt(i).toString().length());
0455:                        if(first >= second) {
0456:                          text.setWidth(getLenghtForCaption(first));
0457:                        } else {
0458:                          text.setWidth(getLenghtForCaption(second));
0459:                        }
0460:                        text.setHeight(20);
0461:                        text.setText(reportResult.getReportSpec().getDimensionFromName(nonGroupingDimensions.elementAt(i).toString()).getCaption());
0462:                        band.addElement(text);
0463:                      }
0464:
0465:                      for(int i = 0 ; i < metrics.size() ; i++) {
0466:                        int x = ((Integer) metricsPosition.elementAt(i)).intValue();
0467:                        text = new JRDesignStaticText();
0468:                        text.setX(x);
0469:                        text.setY(20);
0470:                        text.setWidth(((Integer) metricsWidth.elementAt(i)).intValue());
0471:                        text.setHeight(20);
0472:                        text.setText(reportResult.getReportSpec().getMetricFromName(metrics.elementAt(i).toString()).getCaption());
0473:                        band.addElement(text);
0474:                      }
0475:
0476:                      for(int i = 0 ; i < accMetricsPosition.size() ; i++) {
0477:                        int x = ((Integer) accMetricsPosition.elementAt(i)).intValue();
0478:                        text = new JRDesignStaticText();
0479:                        text.setX(x);
0480:                        text.setY(20);
0481:                        text.setWidth(((Integer) accMetricsWidht.elementAt(i)).intValue());
0482:                        text.setHeight(20);
0483:                        String metricName = getMetricName(accuMetrics.elementAt(i).toString());
0484:                        String metricCaption = reportResult.getReportSpec().getMetricFromName(metricName).getCaption();
0485:                        text.setText(metricCaption + " " + LanguageTraslator.traslate("315"));
0486:                        band.addElement(text);
0487:                      }
0488:                      group.setGroupHeader(band);
0489:                    }*/
0490:
0491:                    band = new JRDesignBand();
0492:                    band.setHeight(30);
0493:                    for (int i = 0; i < metrics.size(); i++) {
0494:                        band.setHeight(20);
0495:                        JRDesignStaticText staticText = new JRDesignStaticText();
0496:                        staticText.setX(0);
0497:                        staticText.setY(0);
0498:                        staticText.setWidth(60);
0499:                        staticText.setHeight(20);
0500:                        bigFont = new JRDesignReportFont();
0501:                        bigFont.setItalic(true);
0502:                        bigFont.setFontSize(11);
0503:                        staticText.setFont(bigFont);
0504:                        if (!dimensions.elementAt(j).toString()
0505:                                .equalsIgnoreCase("NONE")) {
0506:                            ReportDimensionSpec dimensionSpec = reportResult
0507:                                    .getReportSpec().getDimensionFromName(
0508:                                            dimensions.elementAt(j).toString());
0509:                            staticText.setText(dimensionSpec.getCaption());
0510:                        } else {
0511:                            staticText.setText("");
0512:                        }
0513:                        band.addElement(staticText);
0514:
0515:                        textField = new JRDesignTextField();
0516:                        textField.setX(((Integer) metricsPosition.elementAt(i))
0517:                                .intValue());
0518:                        textField.setY(0);
0519:                        if (data.getRowCount() == 1) {
0520:                            textField.setWidth(dimensions.elementAt(j)
0521:                                    .toString().length() * 3);
0522:                        } else {
0523:                            textField
0524:                                    .setWidth(getLenghtForCaption(((Integer) dimensionsSizes
0525:                                            .elementAt(j)).intValue()));
0526:                        }
0527:                        /*textField.setWidth(getLenghtForCaption(((Integer) dimensionsSizes.elementAt(j)).intValue()) + 20);*/
0528:                        textField.setHeight(20);
0529:                        expression = new JRDesignExpression();
0530:                        expression.setValueClass(java.lang.Float.class);
0531:                        expression.setText("$V{"
0532:                                + dimensions.elementAt(j).toString()
0533:                                + metrics.elementAt(i).toString() + "_SUM}");
0534:                        textField.setPattern(numberFormatPattern);
0535:                        textField.setExpression(expression);
0536:                        bigFont = new JRDesignReportFont();
0537:                        bigFont.setBold(true);
0538:                        bigFont.setItalic(true);
0539:                        textField.setFont(bigFont);
0540:                        band.addElement(textField);
0541:                        group.setGroupFooter(band);
0542:                    }
0543:
0544:                    for (int i = 0; i < rowsTotals.size(); i++) {
0545:                        band.setHeight(20);
0546:                        textField = new JRDesignTextField();
0547:                        textField.setX(((Integer) rowsTotalsPosition
0548:                                .elementAt(i)).intValue());
0549:                        textField.setY(0);
0550:                        if (data.getRowCount() == 1) {
0551:                            textField.setWidth(dimensions.elementAt(j)
0552:                                    .toString().length() * 3);
0553:                        } else {
0554:                            textField
0555:                                    .setWidth(getLenghtForCaption(((Integer) dimensionsSizes
0556:                                            .elementAt(j)).intValue()));
0557:                        }
0558:                        /*textField.setWidth(getLenghtForCaption(((Integer) dimensionsSizes.elementAt(j)).intValue()) + 20);*/
0559:                        textField.setHeight(20);
0560:                        expression = new JRDesignExpression();
0561:                        expression.setValueClass(java.lang.Float.class);
0562:                        expression.setText("$V{"
0563:                                + dimensions.elementAt(j).toString()
0564:                                + rowsTotals.elementAt(i).toString() + "_SUM}");
0565:                        textField.setPattern(numberFormatPattern);
0566:                        textField.setExpression(expression);
0567:                        bigFont = new JRDesignReportFont();
0568:                        bigFont.setBold(true);
0569:                        bigFont.setItalic(true);
0570:                        textField.setFont(bigFont);
0571:                        band.addElement(textField);
0572:                        group.setGroupFooter(band);
0573:                    }
0574:
0575:                    /*int atIndex = data.getColumnCount() - reportResult.getReportQuery().getMetrics().size();
0576:                    int element = 0;
0577:                    while(atIndex < data.getColumnCount()) {
0578:                      float total = 0;
0579:                      for(int i = 0 ; i < data.getRowCount() ; i++) {
0580:                        Float aFloat = (Float) data.getValueAt(i, atIndex);
0581:                        total += aFloat.floatValue();
0582:                      }
0583:
0584:                      text = new JRDesignStaticText();
0585:                      text.setX(((Integer)rowsTotalsPosition.elementAt(element)).intValue());
0586:                      text.setY(40);
0587:                      text.setWidth(getLenghtForCaption(((Integer) rowsTotalsSizes.elementAt(element++)).intValue()) + 20);
0588:                      text.setHeight(20);
0589:                      text.setText(String.valueOf(total));
0590:                      band.addElement(text);
0591:
0592:                      atIndex++;
0593:                    }*/
0594:
0595:                    groupingDimensionPosition.add(new Integer(printAt));
0596:                    printAt += 10;//getLenghtForCaption(((Integer)dimensionsSizes.elementAt(j)).intValue());
0597:
0598:                    jasperDesign.addGroup(group);
0599:                }
0600:            }
0601:
0602:            private String getMetricName(String s) {
0603:                if (nonGroupingDimensionsCount > 0) {
0604:                    StringTokenizer tokenizer = new StringTokenizer(s, "_");
0605:                    tokenizer.nextToken();
0606:                    String returnVal = "";
0607:                    while (tokenizer.hasMoreTokens()) {
0608:                        returnVal += tokenizer.nextToken() + "_";
0609:                    }
0610:                    if (!returnVal.equalsIgnoreCase("")) {
0611:                        return returnVal.substring(0, returnVal.length() - 1);
0612:                    }
0613:                }
0614:                return s;
0615:            }
0616:
0617:            /**
0618:             * Agrega las variables a la definicion
0619:             * @param jasperDesign
0620:             * @throws net.sf.jasperreports.engine.JRException
0621:             */
0622:            private void addVariables(JasperDesign jasperDesign)
0623:                    throws JRException {
0624:                //Variables
0625:                JRDesignExpression expression;
0626:                for (int j = 0; j < dimensions.size(); j++) {
0627:                    for (int i = 0; i < metrics.size(); i++) {
0628:                        JRDesignVariable jrVariable = new JRDesignVariable();
0629:                        jrVariable.setName(dimensions.elementAt(j).toString()
0630:                                + metrics.elementAt(i).toString() + "_SUM");
0631:                        jrVariable.setValueClass(java.lang.Float.class);
0632:                        jrVariable
0633:                                .setResetType(JRDesignVariable.RESET_TYPE_GROUP);
0634:                        jrVariable
0635:                                .setCalculation(JRDesignVariable.CALCULATION_SUM);
0636:                        jrVariable.setResetGroup((JRGroup) jasperDesign
0637:                                .getGroupsList().get(j));
0638:                        expression = new JRDesignExpression();
0639:                        expression.setValueClass(java.lang.Float.class);
0640:                        expression.setText("$F{"
0641:                                + metrics.elementAt(i).toString() + "}");
0642:                        jrVariable.setExpression(expression);
0643:                        jasperDesign.addVariable(jrVariable);
0644:                    }
0645:
0646:                    for (int i = 0; i < rowsTotals.size(); i++) {
0647:                        JRDesignVariable jrVariable = new JRDesignVariable();
0648:                        jrVariable.setName(dimensions.elementAt(j).toString()
0649:                                + rowsTotals.elementAt(i).toString() + "_SUM");
0650:                        jrVariable.setValueClass(java.lang.Float.class);
0651:                        jrVariable
0652:                                .setResetType(JRDesignVariable.RESET_TYPE_GROUP);
0653:                        jrVariable
0654:                                .setCalculation(JRDesignVariable.CALCULATION_SUM);
0655:                        jrVariable.setResetGroup((JRGroup) jasperDesign
0656:                                .getGroupsList().get(j));
0657:                        expression = new JRDesignExpression();
0658:                        expression.setValueClass(java.lang.Float.class);
0659:                        expression.setText("$F{"
0660:                                + rowsTotals.elementAt(i).toString() + "}");
0661:                        jrVariable.setExpression(expression);
0662:                        jasperDesign.addVariable(jrVariable);
0663:                    }
0664:                }
0665:            }
0666:
0667:            /**
0668:             * Agrega los detalles a la definicion
0669:             * @param jasperDesign
0670:             */
0671:            private void addDetails(JasperDesign jasperDesign)
0672:                    throws JRException {
0673:                //Details
0674:                //int printAt = calculateStartForItem();
0675:                int printAt;
0676:
0677:                if (nonGroupingDimensions.size() > 0) {
0678:                    printAt = 0;
0679:                } else {
0680:                    printAt = 75;
0681:                }
0682:                JRDesignBand band = new JRDesignBand();
0683:                band.setHeight(20);
0684:                JRDesignExpression expression;
0685:                /*for(int i = 0 ; i < nonGroupingDimensions.size() ; i++) {
0686:                  JRDesignTextField textField = new JRDesignTextField();
0687:                  textField.setX(printAt);
0688:                  textField.setY(0);
0689:                  textField.setWidth(getLenghtForCaption(((Integer) nonGroupingDimensionsSizes.elementAt(i)).intValue()));
0690:                  textField.setHeight(20);
0691:                  expression = new JRDesignExpression();
0692:                  expression.setValueClass(java.lang.String.class);
0693:                  expression.setText("$F{"+nonGroupingDimensions.elementAt(i)+"}");
0694:                  textField.setExpression(expression);
0695:                  band.addElement(textField);
0696:
0697:                  nonGroupingDimensionPosition.add(new Integer(printAt));
0698:
0699:                  int first = getLenghtForCaption(((Integer) nonGroupingDimensionsSizes.elementAt(i)).intValue());
0700:                  int second = getLenghtForCaption(nonGroupingDimensions.elementAt(i).toString().length());
0701:                  if(first >= second) {
0702:                    printAt += first;
0703:                  } else {
0704:                    printAt += second;
0705:                  }
0706:                  //printAt += getLenghtForCaption(((Integer) nonGroupingDimensionsSizes.elementAt(i)).intValue());
0707:
0708:                }*/
0709:
0710:                if (nonGroupingDimensions.size() > 0) {
0711:                    for (int i = 0; i < nonGroupingDimensions.size(); i++) {
0712:                        JRDesignTextField textField = new JRDesignTextField();
0713:                        textField.setX(printAt);
0714:                        textField.setY(0);
0715:                        textField
0716:                                .setWidth(getLenghtForCaption(((Integer) nonGroupingDimensionsSizes
0717:                                        .elementAt(i)).intValue()));
0718:                        textField.setHeight(20);
0719:                        expression = new JRDesignExpression();
0720:                        expression.setValueClass(ReportMap
0721:                                .getJavaLangType(reportResult
0722:                                        .getDimensionFromName(
0723:                                                nonGroupingDimensionsSizes
0724:                                                        .elementAt(i)
0725:                                                        .toString())
0726:                                        .getDataType()));//java.lang.String.class);
0727:                        expression.setText("$F{"
0728:                                + nonGroupingDimensions.elementAt(i) + "}");
0729:                        textField.setExpression(expression);
0730:                        band.addElement(textField);
0731:
0732:                        nonGroupingDimensionPosition.add(new Integer(printAt));
0733:
0734:                        int first = getLenghtForCaption(((Integer) nonGroupingDimensionsSizes
0735:                                .elementAt(i)).intValue());
0736:                        int second = getLenghtForCaption(nonGroupingDimensions
0737:                                .elementAt(i).toString().length());
0738:                        if (first >= second) {
0739:                            printAt += first;
0740:                        } else {
0741:                            printAt += second;
0742:                        }
0743:                        //printAt += getLenghtForCaption(((Integer) nonGroupingDimensionsSizes.elementAt(i)).intValue());
0744:
0745:                    }
0746:                }
0747:
0748:                Vector vector = null;
0749:                if (nonGroupingDimensions.size() >= 0) {
0750:                    try {
0751:                        vector = reportResult.getReportTableModel()
0752:                                .getOccurrences();
0753:                    } catch (InfoException e) {
0754:                        throw new JRException(e);
0755:                    }
0756:                    if (vector.size() > 0) {
0757:                        columnIdentifiersPos = new Vector();
0758:                    }
0759:                }
0760:
0761:                for (int i = 0, j = 0; i < metrics.size(); i++, j++) {
0762:                    JRDesignTextField textField = new JRDesignTextField();
0763:                    textField.setX(printAt);
0764:                    textField.setY(0);
0765:                    //textField.setWidth(getLenghtForCaption(((Integer) metricsSizes.elementAt(i)).intValue())+15);
0766:
0767:                    metricsWidth.add(new Integer(
0768:                            getLenghtForCaption((new Integer(metrics.elementAt(
0769:                                    i).toString().length())).intValue()) + 25));
0770:                    textField
0771:                            .setWidth(getLenghtForCaption((new Integer(metrics
0772:                                    .elementAt(i).toString().length()))
0773:                                    .intValue()) + 25);
0774:
0775:                    textField.setHeight(20);
0776:                    textField.setPattern(numberFormatPattern);
0777:                    expression = new JRDesignExpression();
0778:                    expression.setValueClass(java.lang.Float.class);
0779:                    expression.setText("$F{" + metrics.elementAt(i) + "}");
0780:                    textField.setExpression(expression);
0781:                    band.addElement(textField);
0782:                    metricsPosition.add(new Integer(printAt));
0783:
0784:                    if (nonGroupingDimensions.size() >= 0 && vector.size() > 0) {
0785:                        int cut = metrics.size() / vector.size();
0786:                        if (j == 0 || (j % cut == 0)) {
0787:                            columnIdentifiersPos.add(new Integer(printAt));
0788:                        }
0789:                    }
0790:                    if (data.getRowCount() == 1) {
0791:                        printAt += (metrics.elementAt(i).toString().length() + 40);
0792:                    } else {
0793:                        printAt += getLenghtForCaption(((Integer) metricsSizes
0794:                                .elementAt(i)).intValue()) + 25;
0795:                    }
0796:                }
0797:
0798:                for (int i = 0; i < accuMetrics.size(); i++) {
0799:                    JRDesignTextField textField = new JRDesignTextField();
0800:                    textField.setX(printAt + 25);
0801:                    textField.setY(0);
0802:
0803:                    //textField.setWidth(getLenghtForCaption(((Integer) accuMetricsSizes.elementAt(i)).intValue())+15);
0804:
0805:                    accMetricsWidht.add(new Integer(
0806:                            getLenghtForCaption((new Integer(accuMetrics
0807:                                    .elementAt(i).toString().length()))
0808:                                    .intValue()) + 25));
0809:                    textField.setWidth(getLenghtForCaption((new Integer(
0810:                            accuMetrics.elementAt(i).toString().length()))
0811:                            .intValue()) + 25);
0812:
0813:                    textField.setHeight(20);
0814:                    textField.setPattern(numberFormatPattern);
0815:                    expression = new JRDesignExpression();
0816:                    expression.setValueClass(java.lang.Float.class);
0817:                    expression.setText("$F{" + accuMetrics.elementAt(i) + "}");
0818:                    textField.setExpression(expression);
0819:                    band.addElement(textField);
0820:                    metricsPosition.add(new Integer(printAt + 25));
0821:                    accMetricsPosition.add(new Integer(printAt + 25));
0822:                    printAt += getLenghtForCaption(((Integer) accuMetricsSizes
0823:                            .elementAt(i)).intValue()) + 25;
0824:                }
0825:
0826:                for (int i = 0; i < rowsTotals.size(); i++) {
0827:                    JRDesignTextField textField = new JRDesignTextField();
0828:                    textField.setX(printAt);
0829:                    textField.setY(0);
0830:
0831:                    rowsTotalsWidht.add(new Integer(
0832:                            getLenghtForCaption((new Integer(rowsTotals
0833:                                    .elementAt(i).toString().length()))
0834:                                    .intValue()) + 25));
0835:                    textField.setWidth(getLenghtForCaption((new Integer(
0836:                            rowsTotals.elementAt(i).toString().length()))
0837:                            .intValue()) + 25);
0838:
0839:                    textField.setHeight(20);
0840:                    textField.setPattern(numberFormatPattern);
0841:                    expression = new JRDesignExpression();
0842:                    expression.setValueClass(java.lang.Float.class);
0843:                    expression.setText("$F{" + rowsTotals.elementAt(i) + "}");
0844:                    textField.setExpression(expression);
0845:                    JRDesignReportFont bigFont = new JRDesignReportFont();
0846:                    bigFont.setBold(true);
0847:                    bigFont.setItalic(true);
0848:                    textField.setFont(bigFont);
0849:                    band.addElement(textField);
0850:                    rowsTotalsPosition.add(new Integer(printAt));
0851:                    if (rowsTotalsSizes.size() > 0) {
0852:                        printAt += getLenghtForCaption(((Integer) rowsTotalsSizes
0853:                                .elementAt(i)).intValue()) + 25;
0854:                    }
0855:                }
0856:                if (rowsTotals.size() > 0) {
0857:                    if (((Integer) (rowsTotalsPosition.lastElement()))
0858:                            .intValue() > jasperDesign.getPageWidth()) {
0859:                        jasperDesign
0860:                                .setPageWidth(((Integer) (rowsTotalsPosition
0861:                                        .lastElement())).intValue() + 25);
0862:                    }
0863:                } else if (((Integer) (metricsPosition.lastElement()))
0864:                        .intValue() > jasperDesign.getPageWidth()) {
0865:                    jasperDesign.setPageWidth(((Integer) (metricsPosition
0866:                            .lastElement())).intValue() + 25);
0867:                }
0868:                jasperDesign.setDetail(band);
0869:            }
0870:
0871:            /**
0872:             * Agrega la cabecera de pagina a la definicion
0873:             * @param jasperDesign
0874:             */
0875:            /*private void addPageHeader(JasperDesign jasperDesign) {
0876:              int printAt = 45;
0877:              JRDesignBand band = new JRDesignBand();
0878:              for(int i = 0 ; i < dimensions.size() ; i++) {
0879:                String caption = reportResult.getReportSpec().getDimensionFromName(dimensions.elementAt(i).toString()).getCaption();
0880:                JRDesignStaticText text = new JRDesignStaticText();
0881:                text.setX(0);
0882:                text.setY(0);
0883:                text.setWidth(40);
0884:                text.setHeight(15);
0885:                text.setText(LanguageTraslator.traslate("308"));
0886:                band.addElement(text);
0887:                text = new JRDesignStaticText();
0888:                text.setX(printAt);
0889:                text.setY(0);
0890:                text.setWidth(getLenghtForCaptionHeader(caption.length()));
0891:                text.setHeight(15);
0892:                if(i == dimensions.size() - 1) {
0893:                  text.setText(caption);
0894:                } else {
0895:                  text.setText(caption + ",");
0896:                }
0897:                band.addElement(text);
0898:                printAt += getLenghtForCaptionHeader(caption.length());
0899:                JRDesignLine line = new JRDesignLine();
0900:                line = new JRDesignLine();
0901:                line.setX(0);
0902:                line.setY(16);
0903:                line.setWidth(515);
0904:                line.setHeight(0);
0905:                band.addElement(line);
0906:              }
0907:              printAt = 45;
0908:              for(int i = 0 ; i < nonGroupingDimensions.size() ; i++) {
0909:                String caption = reportResult.getReportSpec().getDimensionFromName(nonGroupingDimensions.elementAt(i).toString()).getCaption();
0910:                JRDesignStaticText text = new JRDesignStaticText();
0911:                text.setX(0);
0912:                text.setY(15);
0913:                text.setWidth(40);
0914:                text.setHeight(15);
0915:                text.setText(LanguageTraslator.traslate("309"));
0916:                band.addElement(text);
0917:                text = new JRDesignStaticText();
0918:                text.setX(printAt);
0919:                text.setY(15);
0920:                text.setWidth(getLenghtForCaptionHeader(caption.length()));
0921:                text.setHeight(15);
0922:                if(i == nonGroupingDimensions.size() - 1) {
0923:                  text.setText(caption);
0924:                } else {
0925:                  text.setText(caption + ",");
0926:                }
0927:                band.addElement(text);
0928:                printAt += getLenghtForCaptionHeader(caption.length());
0929:                JRDesignLine line = new JRDesignLine();
0930:                line = new JRDesignLine();
0931:                line.setX(0);
0932:                line.setY(31);
0933:                line.setWidth(515);
0934:                line.setHeight(0);
0935:                band.addElement(line);
0936:              }
0937:              printAt = 45;
0938:              for(int i = 0 ; i < metrics.size() ; i++) {
0939:                String caption = reportResult.getReportSpec().getMetricFromName(metrics.elementAt(i).toString()).getCaption();
0940:                JRDesignStaticText text = new JRDesignStaticText();
0941:                text.setX(0);
0942:                text.setY(30);
0943:                text.setWidth(40);
0944:                text.setHeight(15);
0945:                text.setText(LanguageTraslator.traslate("310"));
0946:                band.addElement(text);
0947:                text = new JRDesignStaticText();
0948:                text.setX(printAt);
0949:                text.setY(30);
0950:                text.setWidth(getLenghtForCaptionHeader(caption.length()));
0951:                text.setHeight(15);
0952:                if(accuMetrics.size() == 0) {
0953:                  if(i == metrics.size() - 1) {
0954:                    text.setText(caption);
0955:                  } else {
0956:                    text.setText(caption + ",");
0957:                  }
0958:                } else {
0959:                  text.setText(caption + ",");
0960:                }
0961:                band.addElement(text);
0962:                printAt += getLenghtForCaptionHeader(caption.length());
0963:                JRDesignLine line = new JRDesignLine();
0964:                line = new JRDesignLine();
0965:                line.setX(0);
0966:                line.setY(46);
0967:                line.setWidth(515);
0968:                line.setHeight(0);
0969:                band.addElement(line);
0970:              }
0971:              for(int i = 0 ; i < accuMetrics.size() ; i++) {
0972:                String caption = getAccMetricCaption(accuMetrics.elementAt(i).toString());
0973:                JRDesignStaticText text = new JRDesignStaticText();
0974:                text.setX(0);
0975:                text.setY(30);
0976:                text.setWidth(40);
0977:                text.setHeight(15);
0978:                text.setText(LanguageTraslator.traslate("310"));
0979:                band.addElement(text);
0980:                text = new JRDesignStaticText();
0981:                text.setX(printAt);
0982:                text.setY(30);
0983:                text.setWidth(getLenghtForCaptionHeader(caption.length()));
0984:                text.setHeight(15);
0985:                if(i == accuMetrics.size() - 1) {
0986:                  text.setText(caption);
0987:                } else {
0988:                  text.setText(caption + ",");
0989:                }
0990:                band.addElement(text);
0991:                printAt += getLenghtForCaptionHeader(caption.length());
0992:                JRDesignLine line = new JRDesignLine();
0993:                line = new JRDesignLine();
0994:                line.setX(0);
0995:                line.setY(46);
0996:                line.setWidth(515);
0997:                line.setHeight(0);
0998:                band.addElement(line);
0999:              }
1000:              jasperDesign.setPageHeader(band);
1001:            }*/
1002:
1003:            private void addPageHeader(JasperDesign jasperDesign) {
1004:
1005:                JRDesignBand band = new JRDesignBand();
1006:
1007:                String caption = getCaption(LanguageTraslator.traslate("308"),
1008:                        dimensions, new StringBuffer());
1009:                JRDesignStaticText text = new JRDesignStaticText();
1010:                text = new JRDesignStaticText();
1011:                text.setX(0);
1012:                text.setY(0);
1013:                text.setWidth(getLenghtForCaptionHeader(caption.length()));
1014:                text.setHeight(15);
1015:                text.setText(caption);
1016:                band.addElement(text);
1017:
1018:                caption = getCaption(LanguageTraslator.traslate("309"),
1019:                        nonGroupingDimensions, new StringBuffer());
1020:                text = new JRDesignStaticText();
1021:                text.setX(0);
1022:                text.setY(15);
1023:                text.setWidth(getLenghtForCaptionHeader(caption.length()));
1024:                text.setHeight(15);
1025:                text.setText(caption);
1026:                band.addElement(text);
1027:
1028:                StringBuffer sb = new StringBuffer();
1029:                StringBuffer buffer = new StringBuffer();
1030:                sb.append(getCaption(LanguageTraslator.traslate("310"),
1031:                        metrics, buffer));
1032:                sb.append(getCaption("", accuMetrics, buffer));
1033:                text = new JRDesignStaticText();
1034:                text.setX(0);
1035:                text.setY(30);
1036:                text
1037:                        .setWidth(getLenghtForCaptionHeader(sb.toString()
1038:                                .length()));
1039:                text.setHeight(15);
1040:                text.setText(sb.toString());
1041:                band.addElement(text);
1042:
1043:                jasperDesign.setPageHeader(band);
1044:            }
1045:
1046:            private String getCaption(String tittle, Vector vector,
1047:                    StringBuffer bufferString) {
1048:                StringBuffer buffer = new StringBuffer();
1049:                buffer.append(tittle);
1050:                if (vector == dimensions || vector == nonGroupingDimensions) {
1051:                    for (int i = 0; i < vector.size(); i++) {
1052:                        String caption = reportResult.getReportSpec()
1053:                                .getDimensionFromName(
1054:                                        vector.elementAt(i).toString())
1055:                                .getCaption();
1056:                        if (i == vector.size() - 1) {
1057:                            buffer.append(caption);
1058:                        } else {
1059:                            buffer.append(caption + ", ");
1060:                        }
1061:                    }
1062:                } else if (vector == metrics) {
1063:                    if (accuMetrics.size() == 0) {
1064:                        for (int i = 0; i < vector.size(); i++) {
1065:                            String caption = reportResult.getReportSpec()
1066:                                    .getMetricFromName(
1067:                                            metrics.elementAt(i).toString())
1068:                                    .getCaption();
1069:                            if (i == vector.size() - 1) {
1070:                                buffer.append(caption);
1071:                            } else {
1072:                                buffer.append(caption + ", ");
1073:                            }
1074:                        }
1075:                    } else {
1076:                        for (int i = 0; i < vector.size(); i++) {
1077:                            String caption = reportResult.getReportSpec()
1078:                                    .getMetricFromName(
1079:                                            metrics.elementAt(i).toString())
1080:                                    .getCaption();
1081:                            buffer.append(caption + ", ");
1082:                        }
1083:                    }
1084:                } else {
1085:                    Object[] accMetrics = reportResult.getReportSpec()
1086:                            .getAccumulableMetrics();
1087:                    for (int i = 0; i < accMetrics.length; i++) {
1088:                        ReportMetricSpec metric = (ReportMetricSpec) accMetrics[i];
1089:                        if (i == accMetrics.length - 1) {
1090:                            buffer.append(metric.getCaption() + " "
1091:                                    + LanguageTraslator.traslate("315"));
1092:                        } else {
1093:                            buffer.append(metric.getCaption() + " "
1094:                                    + LanguageTraslator.traslate("315") + ", ");
1095:                        }
1096:
1097:                    }
1098:                }
1099:                return buffer.toString();
1100:            }
1101:
1102:            /**
1103:             * Agrega el titulo al reporte.
1104:             * @param jasperDesign
1105:             */
1106:            private void addTitle(JasperDesign jasperDesign) throws JRException {
1107:                //Title
1108:                JRDesignTextField textField = new JRDesignTextField();
1109:                //JRDesignLine line = new JRDesignLine();
1110:                JRDesignBand band = new JRDesignBand();
1111:                band.setHeight(50);
1112:                JRDesignStaticText staticText = new JRDesignStaticText();
1113:                staticText.setX(0);
1114:                staticText.setY(10);
1115:                staticText.setWidth(515);
1116:                staticText.setHeight(30);
1117:                staticText
1118:                        .setHorizontalAlignment(JRAlignment.HORIZONTAL_ALIGN_CENTER);
1119:                JRDesignReportFont bigFont = new JRDesignReportFont();
1120:                bigFont.setName("Arial_Normal");
1121:                bigFont.setDefault(true);
1122:                bigFont.setFontName("Arial");
1123:                bigFont.setFontSize(16);
1124:                bigFont.setPdfFontName("Helvetica");
1125:                bigFont.setPdfEncoding("Cp1252");
1126:                bigFont.setPdfEmbedded(false);
1127:                jasperDesign.addFont(bigFont);
1128:                staticText.setFont(bigFont);
1129:                staticText.setText(tittle);
1130:                band.addElement(staticText);
1131:                /*line = new JRDesignLine();
1132:                	line.setX(0);
1133:                	line.setY(0);
1134:                	line.setWidth(515);
1135:                	line.setHeight(0);
1136:                	band.addElement(line);*/
1137:                jasperDesign.setTitle(band);
1138:
1139:                JRDesignBand emptyBand = new JRDesignBand();
1140:                emptyBand.setHeight(1);
1141:                jasperDesign.setPageHeader(emptyBand);
1142:                emptyBand = new JRDesignBand();
1143:                emptyBand.setHeight(1);
1144:                jasperDesign.setColumnHeader(emptyBand);
1145:                emptyBand = new JRDesignBand();
1146:                emptyBand.setHeight(1);
1147:                jasperDesign.setColumnFooter(emptyBand);
1148:
1149:                band = new JRDesignBand();
1150:                band.setHeight(15);
1151:                staticText = new JRDesignStaticText();
1152:                staticText.setX(0);
1153:                staticText.setY(0);
1154:                staticText.setWidth(40);
1155:                staticText.setHeight(15);
1156:                staticText.setText("Pagina: ");
1157:                band.addElement(staticText);
1158:                textField = new JRDesignTextField();
1159:                textField.setX(40);
1160:                textField.setY(0);
1161:                textField.setWidth(100);
1162:                textField.setHeight(15);
1163:                JRDesignExpression expression = new JRDesignExpression();
1164:                expression.setValueClass(java.lang.Integer.class);
1165:                expression.setText("$V{PAGE_NUMBER}");
1166:                textField.setExpression(expression);
1167:                band.addElement(textField);
1168:                jasperDesign.setPageFooter(band);
1169:
1170:                band = new JRDesignBand();
1171:                band.setHeight(20);
1172:                jasperDesign.setSummary(band);
1173:            }
1174:
1175:            /*  private void addColumnsHeader(JasperDesign jasperDesign) {
1176:             //columnHeader
1177:             JRDesignBand band = new JRDesignBand();
1178:             for(int i = 0 ; i < metrics.size() ; i++) {
1179:             band.setHeight(20);
1180:             JRDesignStaticText text = new JRDesignStaticText();
1181:             text.setX(((Integer)metricsPosition.elementAt(i)).intValue());
1182:             text.setY(0);
1183:             text.setWidth(40);
1184:             text.setHeight(20);
1185:             text.setText(reportResult.getReportSpec().getDimensionFromName(metrics.elementAt(i).toString()).getCaption());
1186:             band.addElement(text);
1187:             }
1188:             jasperDesign.setColumnHeader(band);
1189:             }
1190:
1191:             private void addColumnsFooter(JasperDesign jasperDesign) {
1192:             JRDesignBand band = new JRDesignBand();
1193:             JRDesignTextField textField;
1194:             String name;
1195:             band.setHeight(20);
1196:             JRDesignStaticText text = new JRDesignStaticText();
1197:             text.setX(40);
1198:             text.setY(0);
1199:             text.setWidth(40);
1200:             text.setHeight(20);
1201:             text.setText("Total");
1202:             band.addElement(text);
1203:
1204:             for(int i = 0 ; i < metrics.size() ; i++) {
1205:             textField = new JRDesignTextField();
1206:             textField.setX(((Integer)metricsPosition.elementAt(i)).intValue());
1207:             textField.setY(0);
1208:             textField.setWidth(100);
1209:             textField.setHeight(15);
1210:
1211:             JRDesignExpression expression = new JRDesignExpression();
1212:             expression.setValueClass(java.lang.Float.class);
1213:             name = metrics.elementAt(i).toString()+"_SUM";
1214:             expression.setText("$V{"+name+"}");
1215:             textField.setExpression(expression);
1216:             band.addElement(textField);
1217:
1218:             band.addElement(text);
1219:             }
1220:
1221:             jasperDesign.setColumnFooter(band);
1222:             }
1223:             */
1224:
1225:            /**
1226:             * Inicializa los vectores con la descripcion de las dimensiones
1227:             * que agrupan, las que no agrupan y las metricas.
1228:             * @param dimensionsCount
1229:             * @param metricsCount
1230:             * @param nonGroupingDimensionsCount
1231:             * @param accMetricsCount
1232:             */
1233:            private void initializeVectors(int dimensionsCount,
1234:                    int metricsCount, int nonGroupingDimensionsCount,
1235:                    int accMetricsCount) throws InfoException {
1236:                rowsTotals = new Vector();
1237:                dimensions = new Vector();
1238:                nonGroupingDimensions = new Vector();
1239:                metrics = new Vector();
1240:                accuMetrics = new Vector();
1241:                int i = 0;
1242:                if (nonGroupingDimensionsCount > 0) {
1243:                    for (; i < dimensionsCount; i++) {
1244:                        dimensions.add(data.getColumnName(i));
1245:                    }
1246:
1247:                    if (nonGroupingDimensionsCount > 1) {
1248:                        for (int z = 0; z < nonGroupingDimensionsCount - 1; i++, z++) {
1249:                            nonGroupingDimensions.add(data.getColumnName(i));
1250:                        }
1251:                    }
1252:
1253:                    Vector vector = reportResult.getReportTableModel()
1254:                            .getOccurrences();
1255:
1256:                    for (int j = 0; j < vector.size() * metricsCount; i++, j++) {
1257:                        metrics.add(data.getColumnName(i));
1258:                    }
1259:
1260:                    for (int j = 0; j < accMetricsCount; i++, j++) {
1261:                        accuMetrics.add(data.getColumnName(i));
1262:                    }
1263:
1264:                    if (reportResult.getReportQuery().isVisibleTotals()) {
1265:                        int startingPoint = data.getColumnCount()
1266:                                - metricsCount;
1267:                        for (int x = startingPoint; x < data.getColumnCount(); x++) {
1268:                            rowsTotals.add(data.getColumnName(x));
1269:                        }
1270:                    }
1271:
1272:                } else {
1273:                    for (; i < dimensionsCount; i++) {
1274:                        dimensions.add(data.getColumnName(i));
1275:                    }
1276:
1277:                    for (int j = 0; j < metricsCount; j++, i++) {
1278:                        metrics.add(data.getColumnName(i));
1279:                    }
1280:
1281:                    for (int z = 0; z < accMetricsCount; z++, i++) {
1282:                        accuMetrics.add(data.getColumnName(i));
1283:                    }
1284:
1285:                }
1286:            }
1287:
1288:            /**
1289:             * Determina un Vector con los anchos mas precisos.
1290:             * @param vector
1291:             * @return
1292:             */
1293:            private Vector calculateBestLenghts(Vector vector) {
1294:                Vector bestSizes = null;
1295:                Vector ColumnSizes;
1296:                if (data.getRowCount() != 0) {
1297:                    bestSizes = new Vector();
1298:                    for (int i = 0; i < vector.size(); i++) {
1299:                        ColumnSizes = new Vector();
1300:                        String columnName = "";
1301:                        ReportFieldSpec spec;
1302:                        if ((spec = reportResult.getDimensionFromName(vector
1303:                                .elementAt(i).toString())) != null) {
1304:                            columnName = spec.getCaption();
1305:                        } else if ((spec = reportResult
1306:                                .getMetricFromName(getMetricName(vector
1307:                                        .elementAt(i).toString()))) != null) {
1308:                            columnName = spec.getCaption();
1309:                        } else {
1310:                            columnName = "";
1311:                        }
1312:                        ColumnSizes.add(new Integer(columnName.length()));
1313:                        Object value = data.getValueAt(0,
1314:                                getColumnIndexFromName(vector.elementAt(i)
1315:                                        .toString()));
1316:                        if (value != null) {
1317:                            String current = value.toString();
1318:                            if (data.getRowCount() == 1) {
1319:                                ColumnSizes.add(new Integer(current.length()));
1320:                                break;
1321:                            } else {
1322:                                ColumnSizes.add(new Integer(current.length()));
1323:                                for (int j = 0; j < data.getRowCount(); j++) {
1324:                                    if (!current.equals(data.getValueAt(j, i)
1325:                                            .toString())) {
1326:                                        ColumnSizes
1327:                                                .add(new Integer(
1328:                                                        data
1329:                                                                .getValueAt(
1330:                                                                        j,
1331:                                                                        getColumnIndexFromName(vector
1332:                                                                                .elementAt(
1333:                                                                                        i)
1334:                                                                                .toString()))
1335:                                                                .toString()
1336:                                                                .length()));
1337:                                        current = data.getValueAt(j, i)
1338:                                                .toString();
1339:                                    }
1340:                                }
1341:                                bestSizes.add(getBestSize(ColumnSizes));
1342:                            }
1343:                        }
1344:                    }
1345:                }
1346:                return bestSizes;
1347:            }
1348:
1349:            /**
1350:             * Retorna un indice a partir de un nombre de columna.
1351:             * @param columnName
1352:             * @return
1353:             */
1354:            private int getColumnIndexFromName(String columnName) {
1355:                int index = 0;
1356:                for (int i = 0; i < data.getColumnCount(); i++) {
1357:                    if (data.getColumnName(i).equals(columnName)) {
1358:                        index = i;
1359:                        break;
1360:                    }
1361:                }
1362:                return index;
1363:            }
1364:
1365:            /**
1366:             * Retorna el ancho mas eficiente comparando los elementos
1367:             * del Vector
1368:             * @param ColumnSizes
1369:             * @return
1370:             */
1371:            private Integer getBestSize(Vector ColumnSizes) {
1372:                int compareTo = 0;
1373:                for (int i = 0; i < ColumnSizes.size(); i++) {
1374:                    if (((Integer) ColumnSizes.elementAt(i)).intValue() > compareTo) {
1375:                        compareTo = ((Integer) ColumnSizes.elementAt(i))
1376:                                .intValue();
1377:                    }
1378:                }
1379:                return new Integer(compareTo);
1380:            }
1381:
1382:            /**
1383:             * Determina el ancho para las descripciones
1384:             * de la cabecera
1385:             * @param chars
1386:             * @return
1387:             */
1388:            private int getLenghtForCaptionHeader(int chars) {
1389:                //return chars * 8 - chars;
1390:                Integer integer = new Integer(chars);
1391:                Double qsrt = new Double(Math.sqrt(integer.doubleValue()));
1392:                return chars * 7 - ((chars / 2) - 3 * qsrt.intValue());
1393:            }
1394:
1395:            /**
1396:             * Determina el comienzo donde se mostraran las
1397:             * metricas o dimensiones que no agrupan.
1398:             * @return
1399:             */
1400:            private int calculateStartForItem() {
1401:                int width = 0;
1402:                for (int i = 0; i < dimensionsSizes.size(); i++) {
1403:                    width += (((Integer) dimensionsSizes.elementAt(i))
1404:                            .intValue());
1405:                }
1406:
1407:                //return (width) + 100;
1408:                return 0;
1409:            }
1410:
1411:            /**
1412:             * Retorna un ancho preciso a partir de una
1413:             * determinada cantidad de caracteres
1414:             * @param chars
1415:             * @return
1416:             */
1417:            private int getLenghtForCaption(int chars) {
1418:                /*if(chars == 2 ) {
1419:                  return chars * 7;
1420:                }
1421:                Integer integer = new Integer(chars);
1422:                Double qsrt = new Double(Math.sqrt(integer.doubleValue()));
1423:                return chars * 8 - ((chars / 2) - 3 * qsrt.intValue());*/
1424:
1425:                return chars * 8;
1426:            }
1427:
1428:            /**
1429:             * Retorna los fields.
1430:             * @return
1431:             */
1432:            public Map getFields() {
1433:                if (fields == null) {
1434:                    fields = new HashMap();
1435:                }
1436:                return fields;
1437:            }
1438:
1439:            /**
1440:             * Retorna las variables
1441:             * @return
1442:             */
1443:            public Map getVariables() {
1444:                if (variables == null) {
1445:                    variables = new HashMap();
1446:                }
1447:                return variables;
1448:            }
1449:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.