1 package com.calipso.reportgenerator.common; 2 3 import javax.swing.table.TableModel ; 4 import java.util.*; 5 import java.text.NumberFormat ; 6 import java.text.DecimalFormat ; 7 8 import net.sf.jasperreports.engine.design.*; 9 import net.sf.jasperreports.engine.design.JRDesignGroup; 10 import net.sf.jasperreports.engine.design.JRDesignBand; 11 import net.sf.jasperreports.engine.design.JRDesignStaticText; 12 import net.sf.jasperreports.engine.*; 13 import com.calipso.reportgenerator.common.LanguageTraslator; 14 import com.calipso.reportgenerator.common.ReportResult; 15 import com.calipso.reportgenerator.common.ReportMetricSpec; 16 import com.calipso.reportgenerator.common.IJasperDefinition; 17 18 21 22 public class StaticJasperReportDefinition implements IJasperDefinition { 23 24 private Map fields; 25 private Map variables; 26 private TableModel data; 27 private String tittle; 28 private Vector dimensions; 29 private Vector metrics; 30 private Vector accuMetrics; 31 private Vector nonGroupingDimensions; 32 private Vector dimensionsSizes; 33 private Vector metricsSizes; 34 private Vector accuMetricsSizes; 35 private Vector nonGroupingDimensionsSizes; 36 private int printAt; 37 private Vector metricsPosition = new Vector(); 38 private Vector nonGroupingDimensionPosition = new Vector(); 39 private Vector groupingDimensionPosition = new Vector(); 40 private ReportResult reportResult; 41 private String numberFormatPattern; 42 private Vector metricsWidth; 43 private Vector accMetricsPosition; 44 private Vector accMetricsWidht; 45 private Map reportParams; 46 47 57 public StaticJasperReportDefinition(ReportResult reportResult, TableModel data, int dimensionsCount, int metricsCount, int nonGroupingDimensionsCount, int accuMetricsCount, String tittle) { 58 this.data = data; 59 this.tittle = tittle; 60 this.reportResult = reportResult; 61 metricsWidth = new Vector(); 62 accMetricsPosition = new Vector(); 63 accMetricsWidht = new Vector(); 64 initializeVectors(dimensionsCount, metricsCount, nonGroupingDimensionsCount, accuMetricsCount); 65 reportParams = reportResult.getParamValues(); 66 dimensionsSizes = calculateBestLenghts(dimensions); 67 metricsSizes = calculateBestLenghts(metrics); 68 accuMetricsSizes = calculateBestLenghts(this.accuMetrics); 69 nonGroupingDimensionsSizes = calculateBestLenghts(nonGroupingDimensions); 70 initializeNumberFormatPattern(); 71 } 72 73 private void initializeNumberFormatPattern() { 74 NumberFormat format = NumberFormat.getInstance(LanguageTraslator.getLocale()); 75 numberFormatPattern = ((DecimalFormat )format).toPattern(); 76 } 77 78 83 public JasperDesign getJasperDefinition(boolean isLandscape) throws JRException { 84 JasperDesign jasperDesign = new JasperDesign(); 85 if(isLandscape) { 86 jasperDesign.setOrientation(JasperDesign.ORIENTATION_LANDSCAPE); 87 jasperDesign.setPrintOrder(JasperDesign.PRINT_ORDER_VERTICAL); 88 jasperDesign.setPageWidth(842); 89 jasperDesign.setPageHeight(595); 90 } else { 91 jasperDesign.setOrientation(JasperDesign.ORIENTATION_PORTRAIT); 92 jasperDesign.setPrintOrder(JasperDesign.PRINT_ORDER_HORIZONTAL); 93 jasperDesign.setPageWidth(595); 94 jasperDesign.setPageHeight(842); 95 } 96 jasperDesign.setName("BasicReport"); 97 addFields(jasperDesign); 98 addDetails(jasperDesign); 99 addGroups(jasperDesign); 100 addVariables(jasperDesign); 101 addTitle(jasperDesign); 102 addParams(jasperDesign); 103 return jasperDesign; 105 } 106 107 112 private void addParams(JasperDesign jasperDesign) throws JRException { 113 for (Iterator iterator = reportParams.entrySet().iterator(); iterator.hasNext();) { 114 Map.Entry param = (Map.Entry) iterator.next(); 115 JRDesignParameter parameter = new JRDesignParameter(); 116 parameter.setName(param.getKey().toString()); 117 parameter.setDescription(param.getKey().toString()); 118 Class paramClass = getClassFor(param); 119 parameter.setValueClass(paramClass); 120 jasperDesign.addParameter(parameter); 121 } 122 } 123 124 129 private Class getClassFor(Map.Entry param) { 130 Class result = java.lang.String .class; 131 Map map = new HashMap(); 132 map.put(param.getKey(), param.getValue()); 133 ReportMap.setParametersToSimpleType(map); 134 if(map.get(param.getKey())!=null){ 135 result = map.get(param.getKey()).getClass(); 136 } 137 return result; 138 } 139 140 145 private void addFields(JasperDesign jasperDesign) throws JRException { 146 String name; 148 for(int i = 0 ; i < dimensions.size() ; i++) { 149 JRDesignField field = new JRDesignField(); 150 name = dimensions.elementAt(i).toString(); 151 field.setName(name); 152 field.setValueClass(java.lang.String .class); 153 jasperDesign.addField(field); 154 } 155 for(int i = 0 ; i < nonGroupingDimensions.size() ; i++) { 156 JRDesignField field = new JRDesignField(); 157 name = nonGroupingDimensions.elementAt(i).toString(); 158 field.setName(name); 159 field.setValueClass(java.lang.String .class); 160 jasperDesign.addField(field); 161 } 162 for(int i = 0 ; i < metrics.size() ; i++) { 163 JRDesignField field = new JRDesignField(); 164 name = metrics.elementAt(i).toString(); 165 field.setName(name); 166 field.setValueClass(java.lang.Float .class); 167 jasperDesign.addField(field); 168 } 169 for(int i = 0 ; i < accuMetrics.size() ; i++) { 170 JRDesignField field = new JRDesignField(); 171 name = accuMetrics.elementAt(i).toString(); 172 field.setName(name); 173 field.setValueClass(java.lang.Float .class); 174 jasperDesign.addField(field); 175 } 176 } 177 178 183 private void addGroups(JasperDesign jasperDesign) throws JRException { 184 JRDesignExpression expression; 186 JRDesignBand band; 187 JRDesignGroup group = null; 188 printAt = 0; 189 if(dimensions.size()==0){ 190 if (jasperDesign.getFields().length==0){ 191 dimensions.add(""); 192 } else{ 193 dimensions.add(jasperDesign.getFields()[0].getName()); 194 } 195 dimensionsSizes.add(new Integer (4)); 196 } 197 for(int j = 0 ; j < dimensions.size() ; j++) { 198 group = new JRDesignGroup(); 199 group.setName(dimensions.elementAt(j).toString()+"_GROUP"); 200 group.setReprintHeaderOnEachPage(true); 201 202 expression = new JRDesignExpression(); 203 expression.setValueClass(java.lang.String .class); 204 expression.setText("$F{"+dimensions.elementAt(j)+"}"); 205 group.setExpression(expression); 206 207 if(j + 1 == dimensions.size()) { 208 band = new JRDesignBand(); 209 band.setHeight(60); 210 } else { 211 band = new JRDesignBand(); 212 band.setHeight(20); 213 } 214 215 216 JRDesignStaticText text = new JRDesignStaticText(); 217 String caption = ""; 218 if(dimensions.elementAt(j)!=""){ 219 caption = reportResult.getReportSpec().getDimensionFromName(dimensions.elementAt(j).toString()).getCaption() + ":"; 220 } 221 text.setX(printAt); 222 text.setY(0); 223 text.setWidth(getLenghtForCaption((new Integer (caption.length())).intValue())); 224 text.setHeight(20); 225 text.setText(caption); 226 band.addElement(text); 227 228 JRDesignTextField textField = new JRDesignTextField(); 229 textField.setX(printAt + getLenghtForCaption((new Integer (caption.length())).intValue()) - 5); 230 textField.setY(0); 231 textField.setWidth(getLenghtForCaption(((Integer ) dimensionsSizes.elementAt(j)).intValue())); 232 textField.setHeight(20); 233 expression = new JRDesignExpression(); 234 expression.setValueClass(java.lang.String .class); 235 expression.setText("$F{"+dimensions.elementAt(j)+"}"); 236 textField.setExpression(expression); 237 band.addElement(textField); 238 group.setGroupHeader(band); 239 240 if(j + 1 == dimensions.size()) { 241 for(int i = 0 ; i < nonGroupingDimensions.size() ; i++) { 242 int x = ((Integer ) nonGroupingDimensionPosition.elementAt(i)).intValue(); 243 text = new JRDesignStaticText(); 244 text.setX(x); 245 text.setY(20); 246 int first = getLenghtForCaption(((Integer ) nonGroupingDimensionsSizes.elementAt(i)).intValue()); 248 int second = getLenghtForCaption(nonGroupingDimensions.elementAt(i).toString().length()); 249 if(first >= second) { 250 text.setWidth(getLenghtForCaption(first)); 251 } else { 252 text.setWidth(getLenghtForCaption(second)); 253 } 254 text.setHeight(20); 255 text.setText(reportResult.getReportSpec().getDimensionFromName(nonGroupingDimensions.elementAt(i).toString()).getCaption()); 256 band.addElement(text); 257 } 258 259 for(int i = 0 ; i < metrics.size() ; i++) { 260 int x = ((Integer ) metricsPosition.elementAt(i)).intValue(); 261 text = new JRDesignStaticText(); 262 text.setX(x); 263 text.setY(20); 264 text.setWidth(((Integer ) metricsWidth.elementAt(i)).intValue()); 265 text.setHeight(20); 266 text.setText(reportResult.getReportSpec().getMetricFromName(metrics.elementAt(i).toString()).getCaption()); 267 band.addElement(text); 268 } 269 270 for(int i = 0 ; i < accMetricsPosition.size() ; i++) { 271 int x = ((Integer ) accMetricsPosition.elementAt(i)).intValue(); 272 text = new JRDesignStaticText(); 273 text.setX(x); 274 text.setY(20); 275 text.setWidth(((Integer ) accMetricsWidht.elementAt(i)).intValue()); 276 text.setHeight(20); 277 String metricName = getMetricName(accuMetrics.elementAt(i).toString()); 278 String metricCaption = reportResult.getReportSpec().getMetricFromName(metricName).getCaption(); 279 text.setText(metricCaption + " " + LanguageTraslator.traslate("315")); 280 band.addElement(text); 281 } 282 group.setGroupHeader(band); 283 } 284 285 286 band = new JRDesignBand(); 287 band.setHeight(30); 288 text = new JRDesignStaticText(); 289 text.setX(printAt); 290 text.setY(0); 291 text.setWidth(40); 292 text.setHeight(20); 293 text.setText(LanguageTraslator.traslate("358")); 294 band.addElement(text); 295 for(int i = 0 ; i < metrics.size() ; i++) { 296 band.setHeight(20); 297 textField = new JRDesignTextField(); 298 textField.setX(((Integer )metricsPosition.elementAt(i)).intValue()); 299 textField.setY(0); 300 textField.setWidth(getLenghtForCaption(((Integer ) dimensionsSizes.elementAt(j)).intValue()) + 20); 301 textField.setHeight(20); 302 expression = new JRDesignExpression(); 303 expression.setValueClass(java.lang.Float .class); 304 expression.setText("$V{"+dimensions.elementAt(j).toString() + metrics.elementAt(i).toString()+"_SUM}"); 305 textField.setPattern(numberFormatPattern); 306 textField.setExpression(expression); 307 band.addElement(textField); 308 group.setGroupFooter(band); 309 } 310 groupingDimensionPosition.add(new Integer (printAt)); 311 printAt += 10; 313 jasperDesign.addGroup(group); 314 } 315 } 316 317 private String getMetricName(String s) { 318 StringTokenizer tokenizer = new StringTokenizer(s, "_"); 319 String returnVal = tokenizer.nextToken(); 320 return returnVal; 321 } 322 323 328 private void addVariables(JasperDesign jasperDesign) throws JRException { 329 JRDesignExpression expression; 331 for(int j = 0 ; j < dimensions.size() ; j++) { 332 for(int i = 0 ; i < metrics.size() ; i++) { 333 JRDesignVariable jrVariable = new JRDesignVariable(); 334 jrVariable.setName(dimensions.elementAt(j).toString()+ metrics.elementAt(i).toString()+"_SUM"); 335 jrVariable.setValueClass(java.lang.Float .class); 336 jrVariable.setResetType(JRDesignVariable.RESET_TYPE_GROUP); 337 jrVariable.setCalculation(JRDesignVariable.CALCULATION_SUM); 338 jrVariable.setResetGroup((JRGroup)jasperDesign.getGroupsList().get(j)); 339 expression = new JRDesignExpression(); 340 expression.setValueClass(java.lang.Float .class); 341 expression.setText("$F{"+metrics.elementAt(i).toString()+"}"); 342 jrVariable.setExpression(expression); 343 jasperDesign.addVariable(jrVariable); 344 } 345 } 346 } 347 348 352 private void addDetails(JasperDesign jasperDesign) { 353 int printAt = calculateStartForItem(); 355 JRDesignBand band = new JRDesignBand(); 356 band.setHeight(20); 357 JRDesignExpression expression; 358 for(int i = 0 ; i < nonGroupingDimensions.size() ; i++) { 359 JRDesignTextField textField = new JRDesignTextField(); 360 textField.setX(printAt); 361 textField.setY(0); 362 textField.setWidth(getLenghtForCaption(((Integer ) nonGroupingDimensionsSizes.elementAt(i)).intValue())); 363 textField.setHeight(20); 364 expression = new JRDesignExpression(); 365 expression.setValueClass(java.lang.String .class); 366 expression.setText("$F{"+nonGroupingDimensions.elementAt(i)+"}"); 367 textField.setExpression(expression); 368 band.addElement(textField); 369 370 nonGroupingDimensionPosition.add(new Integer (printAt)); 371 372 int first = getLenghtForCaption(((Integer ) nonGroupingDimensionsSizes.elementAt(i)).intValue()); 373 int second = getLenghtForCaption(nonGroupingDimensions.elementAt(i).toString().length()); 374 if(first >= second) { 375 printAt += first; 376 } else { 377 printAt += second; 378 } 379 381 } 382 for(int i = 0 ; i < metrics.size() ; i++) { 383 JRDesignTextField textField = new JRDesignTextField(); 384 textField.setX(printAt + 25); 385 textField.setY(0); 386 388 metricsWidth.add(new Integer (getLenghtForCaption((new Integer (metrics.elementAt(i).toString().length())).intValue())+25)); 389 textField.setWidth(getLenghtForCaption((new Integer (metrics.elementAt(i).toString().length())).intValue())+25); 390 391 textField.setHeight(20); 392 textField.setPattern(numberFormatPattern); 393 expression = new JRDesignExpression(); 394 expression.setValueClass(java.lang.Float .class); 395 expression.setText("$F{"+metrics.elementAt(i)+"}"); 396 textField.setExpression(expression); 397 band.addElement(textField); 398 metricsPosition.add(new Integer (printAt + 25)); 399 printAt += getLenghtForCaption(((Integer ) metricsSizes.elementAt(i)).intValue()) + 25 ; 400 } 401 402 for(int i = 0 ; i < accuMetrics.size() ; i++) { 403 JRDesignTextField textField = new JRDesignTextField(); 404 textField.setX(printAt + 25); 405 textField.setY(0); 406 407 409 accMetricsWidht.add(new Integer (getLenghtForCaption((new Integer (accuMetrics.elementAt(i).toString().length())).intValue())+25)); 410 textField.setWidth(getLenghtForCaption((new Integer (accuMetrics.elementAt(i).toString().length())).intValue())+25); 411 412 textField.setHeight(20); 413 textField.setPattern(numberFormatPattern); 414 expression = new JRDesignExpression(); 415 expression.setValueClass(java.lang.Float .class); 416 expression.setText("$F{"+accuMetrics.elementAt(i)+"}"); 417 textField.setExpression(expression); 418 band.addElement(textField); 419 metricsPosition.add(new Integer (printAt + 25)); 420 accMetricsPosition.add(new Integer (printAt + 25)); 421 printAt += getLenghtForCaption(((Integer ) accuMetricsSizes.elementAt(i)).intValue()) + 25 ; 422 } 423 424 jasperDesign.setDetail(band); 425 } 426 427 431 558 559 private void addPageHeader(JasperDesign jasperDesign) { 560 561 JRDesignBand band = new JRDesignBand(); 562 563 String caption = getCaption(LanguageTraslator.traslate("308"), dimensions, new StringBuffer ()); 564 JRDesignStaticText text = new JRDesignStaticText(); 565 text = new JRDesignStaticText(); 566 text.setX(0); 567 text.setY(0); 568 text.setWidth(getLenghtForCaptionHeader(caption.length())); 569 text.setHeight(15); 570 text.setText(caption); 571 band.addElement(text); 572 573 caption = getCaption(LanguageTraslator.traslate("309"), nonGroupingDimensions, new StringBuffer ()); 574 text = new JRDesignStaticText(); 575 text.setX(0); 576 text.setY(15); 577 text.setWidth(getLenghtForCaptionHeader(caption.length())); 578 text.setHeight(15); 579 text.setText(caption); 580 band.addElement(text); 581 582 StringBuffer sb = new StringBuffer (); 583 StringBuffer buffer = new StringBuffer (); 584 sb.append(getCaption(LanguageTraslator.traslate("310"), metrics, buffer)); 585 sb.append(getCaption("", accuMetrics, buffer)); 586 text = new JRDesignStaticText(); 587 text.setX(0); 588 text.setY(30); 589 text.setWidth(getLenghtForCaptionHeader(sb.toString().length())); 590 text.setHeight(15); 591 text.setText(sb.toString()); 592 band.addElement(text); 593 594 jasperDesign.setPageHeader(band); 595 } 596 597 private String getCaption(String tittle, Vector vector, StringBuffer bufferString) { 598 StringBuffer buffer = new StringBuffer (); 599 buffer.append(tittle); 600 if(vector == dimensions || vector == nonGroupingDimensions) { 601 for(int i = 0 ; i < vector.size() ; i++){ 602 String caption = reportResult.getReportSpec().getDimensionFromName(vector.elementAt(i).toString()).getCaption(); 603 if(i == vector.size() - 1) { 604 buffer.append(caption); 605 } else { 606 buffer.append(caption + ", "); 607 } 608 } 609 } else if(vector == metrics) { 610 if(accuMetrics.size() == 0) { 611 for(int i = 0 ; i < vector.size() ; i++) { 612 String caption = reportResult.getReportSpec().getMetricFromName(metrics.elementAt(i).toString()).getCaption(); 613 if(i == vector.size() - 1) { 614 buffer.append(caption); 615 } else { 616 buffer.append(caption + ", "); 617 } 618 } 619 } else { 620 for(int i = 0 ; i < vector.size() ; i++) { 621 String caption = reportResult.getReportSpec().getMetricFromName(metrics.elementAt(i).toString()).getCaption(); 622 buffer.append(caption + ", "); 623 } 624 } 625 } else { 626 Object [] accMetrics = reportResult.getReportSpec().getAccumulableMetrics(); 627 for(int i = 0 ; i < accMetrics.length ; i++) { 628 ReportMetricSpec metric = (ReportMetricSpec) accMetrics[i]; 629 if(i == accMetrics.length - 1) { 630 buffer.append(metric.getCaption() + " " + LanguageTraslator.traslate("315")); 631 } else { 632 buffer.append(metric.getCaption() + " " + LanguageTraslator.traslate("315") + ", ") ; 633 } 634 635 } 636 } 637 return buffer.toString(); 638 } 639 640 644 private void addTitle(JasperDesign jasperDesign) throws JRException{ 645 JRDesignTextField textField = new JRDesignTextField(); 647 JRDesignBand band = new JRDesignBand(); 649 band.setHeight(50); 650 JRDesignStaticText staticText = new JRDesignStaticText(); 651 staticText.setX(0); 652 staticText.setY(10); 653 staticText.setWidth(515); 654 staticText.setHeight(30); 655 staticText.setTextAlignment(JRTextElement.TEXT_ALIGN_CENTER); 656 JRDesignReportFont bigFont = new JRDesignReportFont(); 657 bigFont.setName("Arial_Normal"); 658 bigFont.setDefault(true); 659 bigFont.setFontName("Arial"); 660 bigFont.setSize(16); 661 bigFont.setPdfFontName("Helvetica"); 662 bigFont.setPdfEncoding("Cp1252"); 663 bigFont.setPdfEmbedded(false); 664 jasperDesign.addFont(bigFont); 665 staticText.setFont(bigFont); 666 staticText.setText(tittle); 667 band.addElement(staticText); 668 674 jasperDesign.setTitle(band); 675 676 JRDesignBand emptyBand = new JRDesignBand(); 677 emptyBand.setHeight(1); 678 jasperDesign.setPageHeader(emptyBand); 679 emptyBand = new JRDesignBand(); 680 emptyBand.setHeight(1); 681 jasperDesign.setColumnHeader(emptyBand); 682 emptyBand = new JRDesignBand(); 683 emptyBand.setHeight(1); 684 jasperDesign.setColumnFooter(emptyBand); 685 686 band = new JRDesignBand(); 687 band.setHeight(15); 688 staticText = new JRDesignStaticText(); 689 staticText.setX(0); 690 staticText.setY(0); 691 staticText.setWidth(40); 692 staticText.setHeight(15); 693 staticText.setText("Pagina: "); 694 band.addElement(staticText); 695 textField = new JRDesignTextField(); 696 textField.setX(40); 697 textField.setY(0); 698 textField.setWidth(100); 699 textField.setHeight(15); 700 JRDesignExpression expression = new JRDesignExpression(); 701 expression.setValueClass(java.lang.Integer .class); 702 expression.setText("$V{PAGE_NUMBER}"); 703 textField.setExpression(expression); 704 band.addElement(textField); 705 jasperDesign.setPageFooter(band); 706 707 band = new JRDesignBand(); 708 band.setHeight(20); 709 jasperDesign.setSummary(band); 710 } 711 712 761 762 770 private void initializeVectors(int dimensionsCount, int metricsCount, int nonGroupingDimensionsCount, int accMetricsCount) { 771 dimensions = new Vector(); 772 nonGroupingDimensions = new Vector(); 773 metrics = new Vector(); 774 accuMetrics = new Vector(); 775 int i = 0; 776 for (; i < dimensionsCount; i++) { 777 dimensions.add(data.getColumnName(i)); 778 } 779 for (int z = 0; z < nonGroupingDimensionsCount; i++, z++) { 780 nonGroupingDimensions.add(data.getColumnName(i)); 781 } 782 for (int j = 0; j < metricsCount; i++, j++) { 783 metrics.add(data.getColumnName(i)); 784 } 785 for (int j = 0; j < accMetricsCount; i++, j++) { 786 accuMetrics.add(data.getColumnName(i)); 787 } 788 } 789 790 795 private Vector calculateBestLenghts(Vector vector) { 796 Vector bestSizes = null; 797 Vector ColumnSizes; 798 if (data.getRowCount() != 0) { 799 bestSizes = new Vector(); 800 for (int i = 0; i < vector.size(); i++) { 801 ColumnSizes = new Vector(); 802 String current = data.getValueAt(0, getColumnIndexFromName(vector.elementAt(i).toString())).toString(); 803 if (data.getRowCount() == 1) { 804 ColumnSizes.add(new Integer (current.length())); 805 break; 806 } 807 else { 808 ColumnSizes.add(new Integer (current.length())); 809 for (int j = 0; j < data.getRowCount(); j++) { 810 if (!current.equals(data.getValueAt(j, i).toString())) { 811 ColumnSizes.add(new Integer (data.getValueAt(j, getColumnIndexFromName(vector.elementAt(i).toString())).toString().length())); 812 current = data.getValueAt(j, i).toString(); 813 } 814 } 815 bestSizes.add(getBestSize(ColumnSizes)); 816 } 817 } 818 } 819 return bestSizes; 820 } 821 822 827 private int getColumnIndexFromName(String columnName) { 828 int index = 0; 829 for (int i = 0; i < data.getColumnCount(); i++) { 830 if (data.getColumnName(i).equals(columnName)) { 831 index = i; 832 break; 833 } 834 } 835 return index; 836 } 837 838 844 private Integer getBestSize(Vector ColumnSizes) { 845 int compareTo = 0; 846 for (int i = 0; i < ColumnSizes.size(); i++) { 847 if (((Integer ) ColumnSizes.elementAt(i)).intValue() > compareTo) { 848 compareTo = ((Integer ) ColumnSizes.elementAt(i)).intValue(); 849 } 850 } 851 return new Integer (compareTo); 852 } 853 854 860 private int getLenghtForCaptionHeader(int chars){ 861 Integer integer = new Integer (chars); 863 Double qsrt = new Double (Math.sqrt(integer.doubleValue())); 864 return chars * 7 - ((chars / 2) - 3 * qsrt.intValue()); 865 } 866 867 872 private int calculateStartForItem() { 873 int width = 0 ; 874 for(int i = 0 ; i < dimensionsSizes.size() ; i++){ 875 width += (((Integer )dimensionsSizes.elementAt(i)).intValue()); 876 } 877 878 return 0; 880 } 881 882 888 private int getLenghtForCaption(int chars) { 889 if(chars == 2 ) { 890 return chars * 7; 891 } 892 Integer integer = new Integer (chars); 893 Double qsrt = new Double (Math.sqrt(integer.doubleValue())); 894 return chars * 8 - ((chars / 2) - 3 * qsrt.intValue()); 895 } 896 897 901 public Map getFields() { 902 if (fields == null){ 903 fields = new HashMap(); 904 } 905 return fields; 906 } 907 908 912 public Map getVariables() { 913 if (variables == null ){ 914 variables = new HashMap(); 915 } 916 return variables; 917 } 918 } | Popular Tags |