1 2 package com.calipso.xmleditor; 3 4 import net.sf.jasperreports.engine.*; 5 import net.sf.jasperreports.engine.design.JasperDesign; 6 import net.sf.jasperreports.engine.base.JRBaseReport; 7 8 import javax.swing.*; 9 import java.awt.*; 10 import java.util.*; 11 12 public abstract class RW { 13 14 17 public final static String IMAGE_EXPRESSION_TYPES[] = { 18 "java.lang.String", "java.io.File", "java.net.URL", 19 "java.io.InputStream", "java.awt.Image"}; 20 21 24 public final static String WHEN_NO_DATA[] = { 25 "NoPages", "BlankPage", "AllSectionsNoDetail"}; 26 27 30 public final static String SCALE_TYPES[] = { 31 "Retain shape", "Fill frame", "Clip"}; 32 33 36 public final static String STRETCH_TYPES[] = { 37 "None", "Band height", "Tallest object"}; 38 39 42 public final static String PEN_TYPES[] = { 43 "None", "1 pt", "2 pt", "4 pt", "Dotted"}; 44 45 48 public final static String EVAL_TIMES[] = { 49 "Now", "Report", "Page", "Column", "Group"}; 50 51 54 public final static String ALIGNMENTS[] = { 55 "Left", "Center", "Right", "Justified"}; 56 57 60 public final static String HORIZONTAL_ALIGNMENTS[] = { 61 "Left", "Center", "Right"}; 62 63 66 public final static String VERTICAL_ALIGNMENTS[] = { 67 "Top", "Middle", "Bottom"}; 68 71 public final static String LINE_SPACINGS[] = { 72 "Single", "1_1_2", "Double"}; 73 74 77 public final static String VALUE_TYPES[] = { 78 "String", 79 "Double", 80 "Date", 81 "Integer", 82 "Timestamp", 83 "Boolean", 84 "Byte", 85 "Float", 86 "InputStream", 87 "Long", 88 "Short", 89 }; 90 91 94 public final static String CALC_TYPES[] = { 95 "Nothing", "Count", "Sum", "Average", "Lowest", 96 "Highest", "StandardDeviation", "Variance", "System"}; 97 98 101 public final static String RESET_TYPES[] = { 102 "None", "Report", "Page", "Column", "Group" 103 }; 104 105 108 public final static String HYPERLINK_TYPES[] = { 109 "None", "LocalAnchor", "LocalPage", "Reference", 110 "RemoteAnchor", "RemotePage" 111 }; 112 113 private static Map typesMap = null; 114 115 121 public static String getResetTypeName( JRVariable var ) { 122 return getResetTypeName( var.getResetType() ); 123 } 124 125 private static void loadTypesMap() { 126 typesMap = new HashMap(); 127 typesMap.put( "String", java.lang.String .class ); 128 typesMap.put( "Boolean", java.lang.Boolean .class ); 129 typesMap.put( "Byte", java.lang.Byte .class ); 130 typesMap.put( "Date", java.util.Date .class ); 131 typesMap.put( "Timestamp", java.sql.Timestamp .class ); 132 typesMap.put( "Double", java.lang.Double .class ); 133 typesMap.put( "Float", java.lang.Float .class ); 134 typesMap.put( "Integer", java.lang.Integer .class ); 135 typesMap.put( "InputStream", java.io.InputStream .class ); 136 typesMap.put( "Long", java.lang.Long .class ); 137 typesMap.put( "Short", java.lang.Short .class ); 138 } 139 140 public static Class getValueClass( String typeName ) { 141 if( typesMap == null ) { 142 loadTypesMap(); 143 } 144 return (Class )typesMap.get( typeName ); 145 } 146 147 public static String getTypeName( Class cls ) { 148 String clsName = cls.getName(); 149 int ix = clsName.lastIndexOf( "." ); 150 if( ix>=0 ) { 151 clsName = clsName.substring( ix + 1 ); 152 } 153 return clsName; 154 } 155 156 162 public static String getScaleTypeName( int i ) { 163 164 String penStr = "Clip"; 165 switch ( i ) { 166 case JRImage.SCALE_IMAGE_FILL_FRAME: 167 penStr = "Fill frame"; 168 break; 169 case JRImage.SCALE_IMAGE_RETAIN_SHAPE: 170 penStr = "Retain shape"; 171 break; 172 } 173 return penStr; 174 } 175 176 182 public static byte getScaleType( String s ) { 183 if( "Fill frame".equals( s ) ) { 184 return JRImage.SCALE_IMAGE_FILL_FRAME; 185 } 186 else if( "Retain shape".equals( s ) ) { 187 return JRImage.SCALE_IMAGE_RETAIN_SHAPE; 188 } 189 return JRImage.SCALE_IMAGE_CLIP; 190 } 191 192 198 public static String getStretchTypeName( int i ) { 199 200 String penStr = "None"; 201 switch ( i ) { 202 case JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_BAND_HEIGHT: 203 penStr = "Band height"; 204 break; 205 case JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT: 206 penStr = "Tallest object"; 207 break; 208 } 209 return penStr; 210 } 211 212 218 public static byte getStretchType( String s ) { 219 if( "Band height".equals( s ) ) { 220 return JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_BAND_HEIGHT; 221 } 222 else if( "Tallest object".equals( s ) ) { 223 return JRGraphicElement.STRETCH_TYPE_RELATIVE_TO_TALLEST_OBJECT; 224 } 225 return JRGraphicElement.STRETCH_TYPE_NO_STRETCH; 226 } 227 228 234 public static String getPenTypeName( int i ) { 235 236 String penStr = "None"; 237 switch ( i ) { 238 case JRGraphicElement.PEN_1_POINT: 239 penStr = "1 pt"; 240 break; 241 case JRGraphicElement.PEN_2_POINT: 242 penStr = "2 pt"; 243 break; 244 case JRGraphicElement.PEN_4_POINT: 245 penStr = "4 pt"; 246 break; 247 case JRGraphicElement.PEN_DOTTED: 248 penStr = "Dotted"; 249 break; 250 } 251 return penStr; 252 } 253 254 260 public static byte getPenType( String s ) { 261 if( "1 pt".equals( s ) ) { 262 return JRGraphicElement.PEN_1_POINT; 263 } 264 else if( "2 pt".equals( s ) ) { 265 return JRGraphicElement.PEN_2_POINT; 266 } 267 else if( "4 pt".equals( s ) ) { 268 return JRGraphicElement.PEN_4_POINT; 269 } 270 else if( "Dotted".equals( s ) ) { 271 return JRGraphicElement.PEN_DOTTED; 272 } 273 return JRGraphicElement.PEN_NONE; 274 } 275 276 282 public static String getResetTypeName( int i ) { 283 284 String resetStr = "None"; 285 switch ( i ) { 286 case JRVariable.RESET_TYPE_COLUMN: 287 resetStr = "Column"; 288 break; 289 case JRVariable.RESET_TYPE_GROUP: 290 resetStr = "Group"; 291 break; 292 case JRVariable.RESET_TYPE_NONE: 293 resetStr = "None"; 294 break; 295 case JRVariable.RESET_TYPE_PAGE: 296 resetStr = "Page"; 297 break; 298 case JRVariable.RESET_TYPE_REPORT: 299 resetStr = "Report"; 300 break; 301 } 302 return resetStr; 303 } 304 305 311 public static String getCalculationName( JRVariable var ) { 312 return getCalculationName( var.getCalculation() ); 313 } 314 315 321 public static String getEvaluationTimeName( int i ) { 322 323 switch ( i ) { 324 case JRExpression.EVALUATION_TIME_COLUMN: 325 return "Column"; 326 case JRExpression.EVALUATION_TIME_GROUP: 327 return "Group"; 328 case JRExpression.EVALUATION_TIME_PAGE: 329 return "Page"; 330 case JRExpression.EVALUATION_TIME_REPORT: 331 return "Report"; 332 } 333 return "Now"; 334 } 335 336 342 public static byte getEvaluationTime( String s ) { 343 344 if( "Column".equals( s ) ) { 345 return JRExpression.EVALUATION_TIME_COLUMN; 346 } 347 else if( "Report".equals( s ) ) { 348 return JRExpression.EVALUATION_TIME_REPORT; 349 } 350 else if( "Page".equals( s ) ) { 351 return JRExpression.EVALUATION_TIME_PAGE; 352 } 353 else if( "Group".equals( s ) ) { 354 return JRExpression.EVALUATION_TIME_GROUP; 355 } 356 return JRExpression.EVALUATION_TIME_NOW; 357 } 358 359 365 public static String getCalculationName( int i ) { 366 367 String calcName = "Nothing"; 368 switch ( i ) { 369 case JRVariable.CALCULATION_AVERAGE: 370 calcName = "Average"; 371 break; 372 case JRVariable.CALCULATION_COUNT: 373 calcName = "Count"; 374 break; 375 case JRVariable.CALCULATION_HIGHEST: 376 calcName = "Highest"; 377 break; 378 case JRVariable.CALCULATION_LOWEST: 379 calcName = "Lowest"; 380 break; 381 case JRVariable.CALCULATION_NOTHING: 382 calcName = "Nothing"; 383 break; 384 case JRVariable.CALCULATION_STANDARD_DEVIATION: 385 calcName = "StandardDeviation"; 386 break; 387 case JRVariable.CALCULATION_SUM: 388 calcName = "Sum"; 389 break; 390 case JRVariable.CALCULATION_SYSTEM: 391 calcName = "System"; 392 break; 393 case JRVariable.CALCULATION_VARIANCE: 394 calcName = "Variance"; 395 break; 396 default: 397 calcName = "Nothing"; 398 } 399 return calcName; 400 } 401 402 408 public static byte getCalculationType( String str ) { 409 410 if( "Count".equals( str ) ) { 411 return JRVariable.CALCULATION_COUNT; 412 } 413 else if( "Sum".equals( str ) ) { 414 return JRVariable.CALCULATION_SUM; 415 } 416 else if( "Average".equals( str ) ) { 417 return JRVariable.CALCULATION_AVERAGE; 418 } 419 else if( "Lowest".equals( str ) ) { 420 return JRVariable.CALCULATION_LOWEST; 421 } 422 else if( "Highest".equals( str ) ) { 423 return JRVariable.CALCULATION_HIGHEST; 424 } 425 else if( "StandardDeviation".equals( str ) ) { 426 return JRVariable.CALCULATION_STANDARD_DEVIATION; 427 } 428 else if( "Variance".equals( str ) ) { 429 return JRVariable.CALCULATION_VARIANCE; 430 } 431 else if( "System".equals( str ) ) { 432 return JRVariable.CALCULATION_SYSTEM; 433 } 434 return JRVariable.CALCULATION_NOTHING; 435 } 436 437 443 public static byte getResetType( String str ) { 444 445 if( "Report".equals( str ) ) { 446 return JRVariable.RESET_TYPE_REPORT; 447 } 448 else if( "Page".equals( str ) ) { 449 return JRVariable.RESET_TYPE_PAGE; 450 } 451 else if( "Column".equals( str ) ) { 452 return JRVariable.RESET_TYPE_COLUMN; 453 } 454 else if( "Group".equals( str ) ) { 455 return JRVariable.RESET_TYPE_GROUP; 456 } 457 return JRVariable.RESET_TYPE_NONE; 458 } 459 460 public static String getHyperlinkTypeName( int aType ) { 461 if( aType == JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR ) { 462 return "LocalAnchor"; 463 } 464 else if( aType == JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE ) { 465 return "LocalPage"; 466 } 467 else if( aType == JRHyperlink.HYPERLINK_TYPE_REFERENCE ) { 468 return "Reference"; 469 } 470 else if( aType == JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR ) { 471 return "RemoteAnchor"; 472 } 473 else if( aType == JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE ) { 474 return "RemotePage"; 475 } 476 return "None"; 477 } 478 479 public static byte getHyperlinkType( String str ) { 480 if( "LocalAnchor".equals( str ) ) { 481 return JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR; 482 } 483 else if( "LocalPage".equals( str ) ) { 484 return JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE; 485 } 486 else if( "Reference".equals( str ) ) { 487 return JRHyperlink.HYPERLINK_TYPE_REFERENCE; 488 } 489 else if( "RemoteAnchor".equals( str ) ) { 490 return JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR; 491 } 492 else if( "RemotePage".equals( str ) ) { 493 return JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE; 494 } 495 return JRHyperlink.HYPERLINK_TYPE_NONE; 496 } 497 498 504 public static String getExpressionText( JRExpression exp ) { 505 506 StringBuffer expressionTxt = new StringBuffer (); 507 if( exp == null ) { 508 return ""; 509 } 510 JRExpressionChunk chunks[] = exp.getChunks(); 511 for( int i = 0; chunks != null && i < chunks.length; i++ ) { 512 JRExpressionChunk chunk = chunks[i]; 513 switch ( chunk.getType() ) { 514 case JRExpressionChunk.TYPE_FIELD: 515 expressionTxt.append( "$F{" + chunk.getText() + "}" ); 516 break; 517 case JRExpressionChunk.TYPE_VARIABLE: 518 expressionTxt.append( "$V{" + chunk.getText() + "}" ); 519 break; 520 case JRExpressionChunk.TYPE_PARAMETER: 521 expressionTxt.append( "$P{" + chunk.getText() + "}" ); 522 break; 523 default: 524 expressionTxt.append( chunk.getText() ); 525 } 526 } 527 return expressionTxt.toString(); 528 } 529 530 536 public static Vector getGroupNames( JRBaseReport report ) { 537 Vector v = new Vector( report.getGroups().length ); 538 JRGroup grps[] = report.getGroups(); 539 for( int i = 0; i < grps.length; i++ ) { 540 JRGroup group = grps[i]; 541 v.add( group.getName() ); 542 } 543 return v; 544 } 545 546 552 public static String getAlignmentName( int i ) { 553 554 switch ( i ) { 555 case JRTextElement.TEXT_ALIGN_CENTER: 556 return "Center"; 557 case JRTextElement.TEXT_ALIGN_RIGHT: 558 return "Right"; 559 case JRTextElement.TEXT_ALIGN_JUSTIFIED: 560 return "Justified"; 561 default: 562 return "Left"; 563 } 564 } 565 566 public static byte getHorizontalAlignment( String s ) { 567 568 if( "Center".equals( s ) ) { 569 return JRAlignment.HORIZONTAL_ALIGN_CENTER; 570 } 571 else if( "Right".equals( s ) ) { 572 return JRAlignment.HORIZONTAL_ALIGN_RIGHT; 573 } 574 return JRAlignment.HORIZONTAL_ALIGN_LEFT; 575 } 576 577 public static String getHorizontalAlignmentName( byte b ) { 578 if( JRAlignment.HORIZONTAL_ALIGN_CENTER == b ) { 579 return "Center"; 580 } 581 else if( JRAlignment.HORIZONTAL_ALIGN_RIGHT == b ) { 582 return "Right"; 583 } 584 return "Left"; 585 } 586 587 public static byte getVerticalAlignment( String s ) { 588 589 if( "Middle".equals( s ) ) { 590 return JRAlignment.VERTICAL_ALIGN_MIDDLE; 591 } 592 else if( "Bottome".equals( s ) ) { 593 return JRAlignment.VERTICAL_ALIGN_BOTTOM; 594 } 595 return JRAlignment.VERTICAL_ALIGN_TOP; 596 } 597 598 public static String getVerticalAlignmentName( byte b ) { 599 if( JRAlignment.VERTICAL_ALIGN_MIDDLE == b ) { 600 return "Middle"; 601 } 602 else if( JRAlignment.VERTICAL_ALIGN_BOTTOM == b ) { 603 return "Bottom"; 604 } 605 return "Top"; 606 } 607 608 614 public static byte getAlignment( String s ) { 615 616 if( "Center".equals( s ) ) { 617 return JRTextElement.TEXT_ALIGN_CENTER; 618 } 619 else if( "Right".equals( s ) ) { 620 return JRTextElement.TEXT_ALIGN_RIGHT; 621 } 622 else if( "Justified".equals( s ) ) { 623 return JRTextElement.TEXT_ALIGN_JUSTIFIED; 624 } 625 return JRTextElement.TEXT_ALIGN_LEFT; 626 } 627 628 public static String getWhenNoDataName( int i ) { 629 switch ( i ) { 630 case JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE: 631 return "BlankPage"; 632 case JRReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL: 633 return "AllSectionsNoDetail"; 634 } 635 return "NoPages"; 636 } 637 638 public static byte getWhenNoData( String s ) { 639 640 if( "BlankPage".equals( s ) ) { 641 return JRReport.WHEN_NO_DATA_TYPE_BLANK_PAGE; 642 } 643 else if( "AllSectionsNoDetail".equals( s ) ) { 644 return JRReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL; 645 } 646 return JRReport.WHEN_NO_DATA_TYPE_NO_PAGES; 647 } 648 649 655 public static String getLineSpacingName( int i ) { 656 657 switch ( i ) { 658 case JRTextElement.LINE_SPACING_SINGLE: 659 return "Single"; 660 case JRTextElement.LINE_SPACING_DOUBLE: 661 return "Double"; 662 case JRTextElement.LINE_SPACING_1_1_2: 663 return "1_1_2"; 664 } 665 return "Single"; 666 } 667 668 674 public static byte getLineSpacing( String s ) { 675 676 if( "Single".equals( s ) ) { 677 return JRTextElement.LINE_SPACING_SINGLE; 678 } 679 else if( "Double".equals( s ) ) { 680 return JRTextElement.LINE_SPACING_DOUBLE; 681 } 682 else if( "1_1_2".equals( s ) ) { 683 return JRTextElement.LINE_SPACING_1_1_2; 684 } 685 return JRTextElement.LINE_SPACING_SINGLE; 686 } 687 688 694 public static String getJdbcTypeClass( int t ) { 695 String cls = "java.lang.String"; 696 switch ( t ) { 697 case java.sql.Types.TINYINT: 698 case java.sql.Types.BIT: 699 cls = "java.lang.Byte"; 700 break; 701 case java.sql.Types.SMALLINT: 702 cls = "java.lang.Short"; 703 break; 704 case java.sql.Types.INTEGER: 705 cls = "java.lang.Integer"; 706 break; 707 case java.sql.Types.REAL: 708 case java.sql.Types.DOUBLE: 709 case java.sql.Types.NUMERIC: 710 case java.sql.Types.DECIMAL: 711 cls = "java.lang.Double"; 712 break; 713 case java.sql.Types.CHAR: 714 case java.sql.Types.VARCHAR: 715 cls = "java.lang.String"; 716 break; 717 case java.sql.Types.BOOLEAN: 718 cls = "java.lang.Boolean"; 719 break; 720 case java.sql.Types.BIGINT: 721 cls = "java.lang.Long"; 722 break; 723 case java.sql.Types.DATE: 724 case java.sql.Types.TIME: 725 cls = "java.util.Date"; 726 break; 727 case java.sql.Types.TIMESTAMP: 728 cls = "java.sql.Timestamp"; 729 break; 730 } 731 return cls; 732 } 733 734 741 public static JRReportFont searchReportFont( String name, JasperDesign design ) { 742 if( design == null ) { 743 return null; 744 } 745 JRReportFont[] allReportf = design.getFonts(); 746 for( int i = 0; i < allReportf.length; i++ ) { 747 if( allReportf[i].getName().equals( name ) ) { 748 return allReportf[i]; 749 } 750 } 751 return null; 752 } 753 } 754 755 | Popular Tags |