1 30 31 package it.businesslogic.ireport; 32 33 import it.businesslogic.ireport.crosstab.CrosstabCell; 34 import it.businesslogic.ireport.util.*; 35 36 import java.awt.*; 37 import java.awt.geom.*; 38 import java.awt.image.*; 39 40 import java.util.Iterator ; 41 import java.util.Vector ; 42 43 44 public class ReportElement extends IReportHashMapBean 45 { 46 47 static int id_gen = 1; 48 49 private int elementID = 0; 50 51 54 public static final String BGCOLOR = "BGCOLOR"; 55 public static final String FGCOLOR = "FGCOLOR"; 56 public static final String MODE = "MODE"; public static final String REMOVE_LINE_WHEN_BLANK = "REMOVE_LINE_WHEN_BLANK"; 58 public static final String PRINT_REPEATED_VALUES = "PRINT_REPEATED_VALUES"; 59 public static final String PRINT_IN_FIRST_WHOLE_BAND = "DEFAULT_PRINT_IN_FIRST_WHOLE_BAND"; 60 public static final String PRINT_WHEN_DETAIL_OVERFLOW = "PRINT_WHEN_DETAIL_OVERFLOW"; 61 public static final String POSITION_TYPE = "POSITION_TYPE"; 62 63 67 public static final Color DEFAULT_BGCOLOR = Color.WHITE; 68 public static final Color DEFAULT_FGCOLOR = Color.BLACK; 69 public static final boolean DEFAULT_REMOVE_LINE_WHEN_BLANK = false; 70 public static final boolean DEFAULT_PRINT_REPEATED_VALUES = true; 71 public static final boolean DEFAULT_PRINT_IN_FIRST_WHOLE_BAND = false; 72 public static final boolean DEFAULT_PRINT_WHEN_DETAIL_OVERFLOW = false; 73 public static final String DEFAULT_POSITION_TYPE = "FixRelativeToTop"; 74 75 78 public String transparentDefault = "Opaque"; 79 80 81 public String name; 82 public Point position; 83 84 87 private Point relativePosition; 88 public int width; 89 public int height; 90 Rectangle bounds; 91 public static BufferedImage hached = null; 92 public Band band; 93 private CrosstabCell cell; 94 95 public String printWhenExpression = ""; 96 102 public static Color lightcolor; 103 104 public String printWhenGroupChanges = ""; 105 double zoom_factor = 1.0; 106 107 protected String stretchType; 108 private String elementGroup = ""; 109 public Vector intersections = new Vector (); 110 111 private Style style = null; 112 113 private ReportElement parentElement = null; 114 115 123 public ReportElement(int x, int y, int width, int height) 124 { 125 126 if (hached == null) 127 { 128 hached = Misc.loadBufferedImageFromResources(new java.awt.Panel (), 129 "it/businesslogic/ireport/icons/layout/hached.gif"); 130 } 131 132 this.position = new Point(x, y); 133 this.setRelativePosition(new Point(x, y)); 134 this.width = Math.abs(width); 135 this.height = Math.abs(height); 136 137 bounds = new Rectangle(position.x, position.y, width, height); 138 name = "element-" + id_gen; 139 setElementID(id_gen); 140 id_gen++; 141 this.hached = hached; 142 143 if (lightcolor == null) 144 { 145 lightcolor = Color.LIGHT_GRAY; 146 } 147 148 stretchType = "NoStretch"; 149 } 150 151 159 public void drawObject(Graphics2D g, double zoom_factor, 160 int x_shift_origin, int y_shift_origin) 161 { 162 position.x -= 10; 163 position.y -= 10; 164 x_shift_origin -= 10; 165 y_shift_origin -= 10; 166 167 this.zoom_factor = zoom_factor; 168 169 g.fillRect(getZoomedDim(position.x) - x_shift_origin, 171 getZoomedDim(position.y) - y_shift_origin, 172 getZoomedDim(width), getZoomedDim(height)); 173 174 position.x += 10; 176 position.y += 10; 177 x_shift_origin += 10; 178 y_shift_origin += 10; 179 180 drawGraphicsElement(g, "2Point", zoom_factor, x_shift_origin, 181 y_shift_origin); 182 drawBorder(g, zoom_factor, x_shift_origin, y_shift_origin); 183 } 184 185 194 public void drawGraphicsElement(Graphics2D g, String pen, 195 double zoom_factor, int x_shift_origin, 196 int y_shift_origin) 197 { 198 drawGraphicsElement(g, pen, zoom_factor, x_shift_origin, 199 y_shift_origin, 0); 200 } 201 202 212 public void drawGraphicsElement(Graphics2D g, String pen, 213 double zoom_factor, int x_shift_origin, 214 int y_shift_origin, int radius) 215 { 216 217 int correction = (zoom_factor <= 1 && 218 (pen.equals("Thin") || pen.equals("1Point") || 219 pen.equals("Dotted"))) 220 ? -1 221 : 0; 222 int xy_correction = (zoom_factor <= 1 && pen.equals("Dotted")) 223 ? 1 224 : 0; 225 226 Stroke stroke = getPenStroke(pen, zoom_factor); 227 g.setColor(this.getFgcolor()); 228 229 this.zoom_factor = zoom_factor; 230 231 if (stroke == null || pen.equalsIgnoreCase("None")) 232 { 233 234 return; 235 } 236 237 position.x -= 10; 238 position.y -= 10; 239 x_shift_origin -= 10; 240 y_shift_origin -= 10; 241 242 Stroke oldStroke = g.getStroke(); 243 g.setStroke(stroke); 244 245 if (radius != 0) 246 { 247 g.drawRoundRect( 248 getZoomedDim(position.x) - x_shift_origin + 249 xy_correction, 250 getZoomedDim(position.y) - y_shift_origin + 251 xy_correction, getZoomedDim(width) + correction, 252 getZoomedDim(height) + correction, getZoomedDim(radius), getZoomedDim(radius)); 253 } 254 else 255 { 256 g.drawRect(getZoomedDim(position.x) - x_shift_origin + 257 xy_correction, 258 getZoomedDim(position.y) - y_shift_origin + 259 xy_correction, getZoomedDim(width) + correction, 260 getZoomedDim(height) + correction); 261 } 262 263 position.x += 10; 264 position.y += 10; 265 266 g.setStroke(oldStroke); 267 } 268 269 277 public void drawBorder(Graphics2D g, double zoom_factor, 278 int x_shift_origin, int y_shift_origin) 279 { 280 drawBorder(g, zoom_factor, x_shift_origin, y_shift_origin, null); 281 } 282 283 292 public void drawBorder(Graphics2D g, double zoom_factor, 293 int x_shift_origin, int y_shift_origin, Box box) 294 { 295 this.zoom_factor = zoom_factor; 296 297 int correction = (zoom_factor <= 1) 298 ? -1 299 : 0; 300 301 position.x -= 10; 302 position.y -= 10; 303 x_shift_origin -= 10; 304 y_shift_origin -= 10; 305 306 Stroke oldStroke = g.getStroke(); 307 308 if (box == null || !insideBand()) 309 { 310 311 if (insideBand()) 312 { 313 g.setColor(lightcolor); 314 } 315 else 316 { 317 g.setColor(Color.RED); 318 } 319 320 g.drawRect(getZoomedDim(position.x) - x_shift_origin, 321 getZoomedDim(position.y) - y_shift_origin, 322 getZoomedDim(width) + correction, 323 getZoomedDim(height) + correction); 324 } 325 else 326 { 327 328 boolean insideBand = insideBand(); 330 int ax = getZoomedDim(position.x) - x_shift_origin; 331 int ay = getZoomedDim(position.y) - y_shift_origin; 332 int bx = ax + getZoomedDim(width) + correction; 333 int by = ay + getZoomedDim(height) + correction; 334 335 Stroke newBoxStroke = null; 336 337 if (box.getLeftBorderColor() != null) 338 { 339 g.setColor(box.getLeftBorderColor()); 340 } 341 else 342 { 343 g.setColor(lightcolor); 344 } 345 346 if ((newBoxStroke = getPenStroke(box.getLeftBorder(), zoom_factor)) != null) 347 { 348 g.setStroke(newBoxStroke); 349 g.drawLine(ax, ay, ax, by); 350 } 351 352 if (box.getTopBorderColor() != null) 354 { 355 g.setColor(box.getTopBorderColor()); 356 } 357 else 358 { 359 g.setColor(lightcolor); 360 } 361 362 if ((newBoxStroke = getPenStroke(box.getTopBorder(), zoom_factor)) != null) 363 { 364 g.setStroke(newBoxStroke); 365 g.drawLine(ax, ay, bx, ay); 366 } 367 368 if (box.getRightBorderColor() != null) 369 { 370 g.setColor(box.getRightBorderColor()); 371 } 372 else 373 { 374 g.setColor(lightcolor); 375 } 376 377 if ((newBoxStroke = getPenStroke(box.getRightBorder(), zoom_factor)) != null) 378 { 379 g.setStroke(newBoxStroke); 380 g.drawLine(bx, ay, bx, by); 381 } 382 383 if (box.getBottomBorderColor() != null) 384 { 385 g.setColor(box.getBottomBorderColor()); 386 } 387 else 388 { 389 g.setColor(lightcolor); 390 } 391 392 if ((newBoxStroke = getPenStroke(box.getBottomBorder(), 393 zoom_factor)) != null) 394 { 395 g.setStroke(newBoxStroke); 396 g.drawLine(ax, by, bx, by); 397 } 398 399 g.setStroke(oldStroke); 400 } 401 402 position.x += 10; 403 position.y += 10; 404 x_shift_origin += 10; 405 y_shift_origin += 10; 406 } 407 408 417 public void drawCorona(Graphics2D g, double zoom_factor, 418 int x_shift_origin, int y_shift_origin, 419 boolean selected) 420 { 421 this.zoom_factor = zoom_factor; 422 423 position.x -= 10; 425 position.y -= 10; 426 x_shift_origin -= 10; 427 y_shift_origin -= 10; 428 429 Rectangle2D r = new Rectangle2D.Double( 430 getZoomedDim(position.x) - 5 - 431 x_shift_origin, 432 getZoomedDim(position.y) - 5 - 433 y_shift_origin, getZoomedDim(width) + 10, 434 getZoomedDim(height) + 10); 435 436 Rectangle2D r2 = new Rectangle2D.Double( 437 getZoomedDim(position.x) - x_shift_origin, 438 getZoomedDim(position.y) - y_shift_origin, 439 getZoomedDim(width), getZoomedDim(height)); 440 java.awt.geom.Area area = new Area(r); 441 area.exclusiveOr(new Area(r2)); 442 443 if (hached == null) 444 { 445 g.fill(area); 446 } 447 else 448 { 449 g.setPaint(new java.awt.TexturePaint (hached, 450 new Rectangle2D.Double(0, 0, 451 2, 2))); 452 g.fill(area); 453 } 454 455 g.setPaint(Color.BLUE); 457 458 if (!selected) 459 { 460 g.setPaint(Color.GRAY); 461 } 462 463 if (intersectsElements()) 465 { 466 467 if (enclosesOtherElement()) 468 { 469 g.setPaint(Color.PINK); 470 } 471 else 472 { 473 g.setPaint(Color.GREEN); 474 } 475 476 } 477 478 if (!insideBand()) 479 { 480 g.setPaint(Color.RED); 481 } 482 483 g.fillRect(getZoomedDim(position.x) - 5 - x_shift_origin, 484 getZoomedDim(position.y) - 5 - y_shift_origin, 5, 5); 485 g.fillRect(getZoomedDim(position.x + width) - x_shift_origin, 486 getZoomedDim(position.y) - 5 - y_shift_origin, 5, 5); 487 g.fillRect(getZoomedDim(position.x + width) - x_shift_origin, 488 getZoomedDim(position.y + height) - y_shift_origin, 5, 5); 489 g.fillRect(getZoomedDim(position.x) - 5 - x_shift_origin, 490 getZoomedDim(position.y + height) - y_shift_origin, 5, 5); 491 492 g.fillRect(getZoomedDim(position.x + (width / 2)) - 2 - 493 x_shift_origin, 494 getZoomedDim(position.y) - 5 - y_shift_origin, 5, 5); 495 g.fillRect(getZoomedDim(position.x + (width / 2)) - 2 - 496 x_shift_origin, 497 getZoomedDim(position.y + height) - y_shift_origin, 5, 5); 498 g.fillRect(getZoomedDim(position.x) - 5 - x_shift_origin, 499 getZoomedDim(position.y + (height / 2)) - 2 - 500 y_shift_origin, 5, 5); 501 g.fillRect(getZoomedDim(position.x + width) - x_shift_origin, 502 getZoomedDim(position.y + (height / 2)) - 2 - 503 y_shift_origin, 5, 5); 504 505 position.x += 10; 506 position.y += 10; 507 } 508 509 514 public boolean enclosesOtherElement() 515 { 516 517 for (Iterator i = intersections.iterator(); i.hasNext();) 518 { 519 520 ReportElement e = (ReportElement) i.next(); 521 522 if (bounds.contains(e.bounds)) 523 { 524 525 return true; 526 } 527 } 528 529 return false; 530 } 531 532 537 public boolean intersectsElements() 538 { 539 540 int oldHeight = 0; 541 boolean result = false; 542 543 Iterator i = null; 548 if (band == null && cell == null) return false; 549 if (band != null) i = band.getParent().getElements().iterator(); 550 else i = cell.getParent().getElements().iterator(); 551 for (;i.hasNext();) 552 { 553 554 ReportElement e = (ReportElement) i.next(); 555 556 if (!this.equals(e)) 558 { 559 oldHeight = e.height; 560 561 if (e.height == 0) 564 { 565 e.height = 10; 566 } 567 568 if (e.bounds.intersects(bounds)) 569 { 570 571 this.intersections.add(e); 573 result = true; 574 } 575 576 e.height = oldHeight; 577 } 578 } 579 580 return result; 581 } 582 583 589 public boolean intersects(Point p) 590 { 591 592 Rectangle r = new Rectangle(bounds); 593 594 if (height == 0) 595 { 596 r.height = 10; 597 r.y -= 5; 598 } 599 600 if (width == 0) 601 { 602 r.width = 10; 603 r.x -= 5; 604 } 605 606 return r.intersects(p.x, p.y, 1, 1); 607 } 608 609 614 public boolean insideBandReal() 615 { 616 position.x -= 10; 617 position.y -= 10; 618 619 boolean result = insideBand(); 620 621 position.x += 10; 622 position.y += 10; 623 624 return result; 625 } 626 627 632 public boolean insideBand() 633 { 634 635 if (band == null) 636 { 637 if (cell != null) 638 { 639 return cell.getBounds().contains( new Rectangle(getPosition().x,getPosition().y,width,height) ); 640 } 641 return false; 642 } 643 644 int yband = band.getBandYLocation(); 645 646 if (position.y - yband < 0) 648 { 649 650 return false; 651 } 652 653 if (position.x - band.getParent().getLeftMargin() < 0) 655 { 656 657 return false; 658 } 659 660 if (position.y - yband + height > band.getHeight()) 662 { 663 664 return false; 665 } 666 667 if (position.x - band.getParent().getLeftMargin() + width > band.getUsableWidth()) 669 { 670 671 return false; 672 } 673 674 return true; 675 } 676 677 683 public boolean intersects(Rectangle r2) 684 { 685 686 Rectangle r = new Rectangle(bounds); 687 688 if (height == 0) 689 { 690 r.height = 10; 691 r.y -= 5; 692 } 693 694 if (width == 0) 695 { 696 r.width = 10; 697 r.x -= 5; 698 } 699 700 return r.intersects(r2); 701 } 702 703 708 public void setPosition(Point p) 709 { 710 711 if (p == null) 712 { 713 714 return; 715 } 716 717 if (p.x == position.x && p.y == position.y) 718 { 719 720 return; 721 } 722 723 position.x = p.x; 724 position.y = p.y; 725 bounds = new Rectangle(position.x, position.y, width, height); 726 } 727 728 735 public Point trasform(Point delta, int type) 736 { 737 738 if (delta == null) 739 { 740 741 return null; 742 } 743 744 Point result = new Point(delta); 745 int old_x = 0; 746 int old_y = 0; 747 748 if (type == TransformationType.TRANSFORMATION_MOVE) 749 { 750 position.x += delta.x; 751 position.y += delta.y; 752 } 753 else if (type == TransformationType.TRANSFORMATION_RESIZE_E) 754 { 755 old_x = width; 756 width += delta.x; 757 758 if (width < 0) 759 { 760 width = 0; 761 } 762 763 result.x = width - old_x; 764 } 765 else if (type == TransformationType.TRANSFORMATION_RESIZE_W) 766 { 767 old_x = width; 768 769 int d = Math.min(delta.x, width); 770 width -= d; 771 position.x += d; 772 result.x = d; 773 } 774 else if (type == TransformationType.TRANSFORMATION_RESIZE_N) 775 { 776 777 int d = Math.min(delta.y, height); 778 height -= d; 779 position.y += d; 780 result.y = d; 781 } 782 else if (type == TransformationType.TRANSFORMATION_RESIZE_S) 783 { 784 old_y = height; 785 height += delta.y; 786 787 if (height < 0) 788 { 789 height = 0; 790 } 791 792 result.y = height - old_y; 793 } 794 else if (type == TransformationType.TRANSFORMATION_RESIZE_SE) 795 { 796 old_y = height; 797 old_x = width; 798 height += delta.y; 799 800 if (height < 0) 801 { 802 height = 0; 803 } 804 805 width += delta.x; 806 807 if (width < 0) 808 { 809 width = 0; 810 } 811 812 result.x = width - old_x; 813 result.y = height - old_y; 814 } 815 else if (type == TransformationType.TRANSFORMATION_RESIZE_SW) 816 { 817 old_y = height; 818 height += delta.y; 819 820 if (height < 0) 821 { 822 height = 0; 823 } 824 825 int d = Math.min(delta.x, width); 826 width -= d; 827 position.x += d; 828 result.x = d; 829 result.y = height - old_y; 830 } 831 else if (type == TransformationType.TRANSFORMATION_RESIZE_NE) 832 { 833 old_x = width; 834 835 int d = Math.min(delta.y, height); 836 height -= d; 837 position.y += d; 838 width += delta.x; 839 840 if (width < 0) 841 { 842 width = 0; 843 } 844 845 result.x = width - old_x; 846 result.y = d; 847 } 848 else if (type == TransformationType.TRANSFORMATION_RESIZE_NW) 849 { 850 851 int d = Math.min(delta.y, height); 852 height -= d; 853 position.y += d; 854 result.y = d; 855 d = Math.min(delta.x, width); 856 width -= d; 857 position.x += d; 858 result.x = d; 859 } 860 861 bounds = new Rectangle(position.x, position.y, width, height); 862 863 if (getCell() != null && type != TransformationType.TRANSFORMATION_RESIZE_SE) 864 { 865 setRelativePosition( new Point(getPosition().x - getCell().getLeft()- 10, getPosition().y - getCell().getTop()- 10)); 866 } 867 868 return result; 869 } 870 871 876 public void adjustBand() 877 { 878 if (band == null) return; 879 position.x -= 10; 880 position.y -= 10; 881 882 for (Iterator i = band.getParent().getBands().iterator(); i.hasNext();) 883 { 884 885 Band b = (Band) i.next(); 886 887 if (position.y - band.getParent().getBandYLocation(b) >= 0) 888 { 889 890 if (position.y - band.getParent().getBandYLocation(b) + 891 height <= b.getHeight()) 892 { 893 894 band = b; 896 897 break; 898 } 899 } 900 } 901 902 position.x += 10; 903 position.y += 10; 904 } 905 906 907 public void adjustCell(Vector cells) 908 { 909 if (getCell().getType() == CrosstabCell.NODATA_CELL) return; 910 for (int i=0; i<cells.size(); ++i) 911 { 912 CrosstabCell tmpCell = (CrosstabCell)cells.elementAt(i); 913 if (tmpCell.getType() == CrosstabCell.NODATA_CELL) continue; 914 if ( tmpCell.getBounds().contains( new Point(getPosition().x-10,getPosition().y-10) ) ) 915 { 916 this.setCell( tmpCell ); 917 setRelativePosition(new Point( getPosition().x - getCell().getLeft() - 10, getPosition().y - getCell().getTop() - 10 )); 918 return; 919 } 920 } 921 } 922 923 924 929 public void updateRelativePosition() 930 { 931 if (getCell() == null) return; 932 setRelativePosition(new Point( getPosition().x - getCell().getLeft() - 10, getPosition().y - getCell().getTop() - 10 )); 933 } 934 935 936 940 941 944 public void updateBounds() 945 { 946 bounds = new Rectangle(position.x, position.y, width, height); 947 } 948 949 950 957 public Point trasformTest(Point delta, int type) 958 { 959 960 if (delta == null) 961 { 962 963 return null; 964 } 965 966 Point result = new Point(delta); 967 int old_x = 0; 968 int old_y = 0; 969 970 if (type == TransformationType.TRANSFORMATION_MOVE) 971 { 972 } 973 else if (type == TransformationType.TRANSFORMATION_RESIZE_E) 974 { 975 old_x = width; 976 old_x += delta.x; 977 978 if (old_x < 0) 979 { 980 old_x = 0; 981 } 982 983 result.x = old_x - width; 984 } 985 else if (type == TransformationType.TRANSFORMATION_RESIZE_W) 986 { 987 result.x = Math.min(delta.x, width); 988 } 989 else if (type == TransformationType.TRANSFORMATION_RESIZE_N) 990 { 991 result.y = Math.min(delta.y, height); 992 } 993 else if (type == TransformationType.TRANSFORMATION_RESIZE_S) 994 { 995 old_y = height; 996 old_y += delta.y; 997 998 if (old_y < 0) 999 { 1000 old_y = 0; 1001 } 1002 1003 result.y = old_y - height; 1004 } 1005 else if (type == TransformationType.TRANSFORMATION_RESIZE_SE) 1006 { 1007 old_y = height; 1008 old_x = width; 1009 old_y += delta.y; 1010 1011 if (old_y < 0) 1012 { 1013 old_y = 0; 1014 } 1015 1016 old_x += delta.x; 1017 1018 if (old_x < 0) 1019 { 1020 old_x = 0; 1021 } 1022 1023 result.x = old_x - width; 1024 result.y = old_y - height; 1025 } 1026 else if (type == TransformationType.TRANSFORMATION_RESIZE_SW) 1027 { 1028 old_y = height; 1029 old_y += delta.y; 1030 1031 if (old_y < 0) 1032 { 1033 old_y = 0; 1034 } 1035 1036 result.x = Math.min(delta.x, width); 1037 result.y = old_y - height; 1038 } 1039 else if (type == TransformationType.TRANSFORMATION_RESIZE_NE) 1040 { 1041 old_x = width; 1042 result.y = Math.min(delta.y, height); 1043 old_x += delta.x; 1044 1045 if (old_x < 0) 1046 { 1047 old_x = 0; 1048 } 1049 1050 result.x = old_x - width; 1051 } 1052 else if (type == TransformationType.TRANSFORMATION_RESIZE_NW) 1053 { 1054 result.y = Math.min(delta.y, height); 1055 result.x = Math.min(delta.x, width); 1056 } 1057 1058 return result; 1059 } 1060 1061 1066 public String toString() 1067 { 1068 if (band == null) return ""+name; 1069 else 1070 { 1071 if (getParentElement() == null) 1072 { 1073 return name + " [" + 1074 (position.x - band.getParent().getRightMargin() - 10) + "," + 1075 (position.y - band.getBandYLocation() - 10) + "]"; 1076 } 1077 else 1078 { 1079 return name + " [" + 1080 (position.x - getParentElement().getPosition().x) + "," + 1081 (position.y - getParentElement().getPosition().y) + "]"; 1082 } 1083 } 1084 } 1085 1086 1092 public int getZoomedDim(int dim) 1093 { 1094 1095 if (zoom_factor == 1.0) 1096 { 1097 1098 return dim; 1099 } 1100 1101 return (int) ((double) dim * zoom_factor); 1104 1105 } 1107 1108 1114 public double getZoomedDim(double dim) 1115 { 1116 1117 if (zoom_factor == 1.0) 1118 { 1119 1120 return dim; 1121 } 1122 1123 return ((double) dim * zoom_factor); 1126 1127 } 1129 1130 1136 public int getLogicalDim(int dim) 1137 { 1138 1139 if (zoom_factor == 1.0) 1140 { 1141 1142 return dim; 1143 } 1144 1145 return (int) ((double) dim / zoom_factor); 1149 1150 } 1152 1153 1158 public ReportElement cloneMe() 1159 { 1160 1161 ReportElement newReportElement = new ReportElement(position.x, 1162 position.y, width, 1163 height); 1164 newReportElement.name = new String (name); 1165 newReportElement.band = band; 1166 newReportElement.cell = cell; 1167 newReportElement.parentElement = parentElement; 1168 1169 copyElementPropertiesTo(newReportElement); 1170 1171 return newReportElement; 1172 } 1173 1174 1179 public void copyElementPropertiesTo(ReportElement newReportElement) 1180 { 1181 newReportElement.printWhenExpression = printWhenExpression; 1182 1183 newReportElement.setPropertyValue(POSITION_TYPE, this.getPropertyValue(POSITION_TYPE)); 1184 newReportElement.setPropertyValue(REMOVE_LINE_WHEN_BLANK, this.getPropertyValue(REMOVE_LINE_WHEN_BLANK)); 1185 newReportElement.setPropertyValue(PRINT_REPEATED_VALUES, this.getPropertyValue(PRINT_REPEATED_VALUES) ); 1186 newReportElement.setPropertyValue(PRINT_IN_FIRST_WHOLE_BAND, this.getPropertyValue(PRINT_IN_FIRST_WHOLE_BAND)); 1187 newReportElement.setPropertyValue(PRINT_WHEN_DETAIL_OVERFLOW, this.getPropertyValue(PRINT_WHEN_DETAIL_OVERFLOW)); 1188 } 1189 1190 1198 public static String string_replace(String s1, String s2, String s3) 1199 { 1200 1201 String string = ""; 1202 string = ""; 1203 1204 if (s2 == null || s3 == null || s2.length() == 0) 1205 { 1206 1207 return s3; 1208 } 1209 1210 int pos_i = 0; int pos_f = 0; 1213 int len = s2.length(); 1214 1215 while ((pos_f = s3.indexOf(s2, pos_i)) >= 0) 1216 { 1217 string += s3.substring(pos_i, pos_f) + s1; 1218 1219 pos_f = pos_i = pos_f + len; 1221 1222 } 1223 1224 string += s3.substring(pos_i); 1225 1226 return string; 1227 } 1228 1229 1236 public static Stroke getPenStroke(String pen, double zoom_factor) 1237 { 1238 1239 if (pen == null || pen.equals("None")) 1240 { 1241 1242 return null; 1243 } 1244 1245 if (pen.equals("Dotted")) 1246 { 1247 1248 return (Stroke) new BasicStroke((float) (1f * zoom_factor), 1249 BasicStroke.CAP_BUTT, 1250 BasicStroke.JOIN_BEVEL, 0f, 1251 new float[] { 5f, 3f }, 0f); 1252 } 1253 else if (pen.equals("2Point")) 1254 { 1255 1256 return (Stroke) new BasicStroke((float) (2f * zoom_factor)); 1257 } 1258 else if (pen.equals("3Point")) 1259 { 1260 1261 return (Stroke) new BasicStroke((float) (3f * zoom_factor)); 1262 } 1263 else if (pen.equals("4Point")) 1264 { 1265 1266 return (Stroke) new BasicStroke((float) (4f * zoom_factor)); 1267 } 1268 else if (pen.equals("Thin")) 1269 { 1270 1271 return (Stroke) new BasicStroke((float) (1f * zoom_factor)); 1272 } 1273 else { 1275 1276 return (Stroke) new BasicStroke((float) (1f * zoom_factor)); 1277 } 1278 } 1279 1280 1285 public int getWidth() 1286 { 1287 1288 return width; 1289 } 1290 1291 1296 public void setWidth(int width) 1297 { 1298 this.width = width; 1299 updateBounds(); 1300 } 1301 1302 1307 public int getHeight() 1308 { 1309 1310 return height; 1311 } 1312 1313 1318 public void setHeight(int height) 1319 { 1320 this.height = height; 1321 updateBounds(); 1322 } 1323 1324 1329 public java.awt.Point getPosition() 1330 { 1331 1332 return position; 1333 } 1334 1335 1340 public it.businesslogic.ireport.Band getBand() 1341 { 1342 1343 return band; 1344 } 1345 1346 1351 public void setBand(it.businesslogic.ireport.Band band) 1352 { 1353 this.band = band; 1354 } 1355 1356 1361 public java.lang.String getTransparent() 1362 { 1363 1364 if (getStringValue(MODE, null ) == null) 1365 { 1366 if (getStyle() != null) 1368 { 1369 return getStyle().getAttributeString( getStyle().ATTRIBUTE_mode, transparentDefault , true); 1370 } 1371 } 1372 return getStringValue(MODE, transparentDefault ); 1373 } 1374 1375 1380 public void setTransparent(java.lang.String transparent) 1381 { 1382 setPropertyValue(MODE,transparent); 1383 } 1384 1385 1390 public java.lang.String getPositionType() 1391 { 1392 1393 return getStringValue(POSITION_TYPE,DEFAULT_POSITION_TYPE); 1394 } 1395 1396 1401 public void setPositionType(java.lang.String positionType) 1402 { 1403 setPropertyValue(POSITION_TYPE,positionType); 1404 } 1405 1406 1411 public boolean isIsPrintInFirstWholeBand() 1412 { 1413 1414 return getBooleanValue(PRINT_IN_FIRST_WHOLE_BAND, DEFAULT_PRINT_IN_FIRST_WHOLE_BAND ); 1415 } 1416 1417 1423 public void setIsPrintInFirstWholeBand(boolean isPrintInFirstWholeBand) 1424 { 1425 setPropertyValue(PRINT_IN_FIRST_WHOLE_BAND, ""+isPrintInFirstWholeBand ); 1426 } 1427 1428 1433 public java.lang.String getPrintWhenExpression() 1434 { 1435 1436 return printWhenExpression; 1437 } 1438 1439 1444 public void setPrintWhenExpression(java.lang.String printWhenExpression) 1445 { 1446 this.printWhenExpression = printWhenExpression; 1447 } 1448 1449 1454 public boolean isIsPrintRepeatedValues() 1455 { 1456 1457 return getBooleanValue(PRINT_REPEATED_VALUES, DEFAULT_PRINT_REPEATED_VALUES ); 1458 } 1459 1460 1466 public void setIsPrintRepeatedValues(boolean isPrintRepeatedValues) 1467 { 1468 setPropertyValue(PRINT_REPEATED_VALUES, ""+isPrintRepeatedValues ); 1469 } 1470 1471 1476 public java.awt.Color getFgcolor() 1477 { 1478 if (getColorValue(FGCOLOR, null ) == null) 1479 { 1480 if (getStyle() != null) 1482 { 1483 return getStyle().getAttributeColor( getStyle().ATTRIBUTE_forecolor, DEFAULT_FGCOLOR, true); 1484 } 1485 } 1486 return getColorValue(FGCOLOR, DEFAULT_FGCOLOR ); 1487 } 1488 1489 1494 public void setFgcolor(java.awt.Color fgcolor) 1495 { 1496 setPropertyValue(FGCOLOR,fgcolor); 1497 } 1498 1499 1504 public java.awt.Color getBgcolor() 1505 { 1506 1507 if (getColorValue(BGCOLOR, null ) == null) 1508 { 1509 if (getStyle() != null) 1511 { 1512 return getStyle().getAttributeColor( getStyle().ATTRIBUTE_backcolor, DEFAULT_BGCOLOR, true); 1513 } 1514 } 1515 return getColorValue(BGCOLOR, DEFAULT_BGCOLOR ); 1516 } 1517 1518 1523 public void setBgcolor(java.awt.Color bgcolor) 1524 { 1525 setPropertyValue(BGCOLOR,bgcolor); 1526 } 1527 1528 1533 public boolean isIsRemoveLineWhenBlank() 1534 { 1535 1536 return getBooleanValue(REMOVE_LINE_WHEN_BLANK, DEFAULT_REMOVE_LINE_WHEN_BLANK ); 1537 } 1538 1539 1545 public void setIsRemoveLineWhenBlank(boolean isRemoveLineWhenBlank) 1546 { 1547 setPropertyValue(REMOVE_LINE_WHEN_BLANK, ""+isRemoveLineWhenBlank ); 1548 } 1549 1550 1555 public java.lang.String getPrintWhenGroupChanges() 1556 { 1557 1558 return printWhenGroupChanges; 1559 } 1560 1561 1567 public void setPrintWhenGroupChanges(java.lang.String printWhenGroupChanges) 1568 { 1569 this.printWhenGroupChanges = printWhenGroupChanges; 1570 } 1571 1572 1577 public java.lang.String getName() 1578 { 1579 1580 return name; 1581 } 1582 1583 1588 public void setName(java.lang.String name) 1589 { 1590 this.name = name; 1591 } 1592 1593 1598 public boolean isIsPrintWhenDetailOverflows() 1599 { 1600 1601 return getBooleanValue(PRINT_WHEN_DETAIL_OVERFLOW, DEFAULT_PRINT_WHEN_DETAIL_OVERFLOW ); 1602 } 1603 1604 1610 public void setIsPrintWhenDetailOverflows(boolean isPrintWhenDetailOverflows) 1611 { 1612 setPropertyValue(PRINT_WHEN_DETAIL_OVERFLOW, ""+isPrintWhenDetailOverflows ); 1613 } 1614 1615 1621 public void copyBaseReportElement(ReportElement destination, 1622 ReportElement source) 1623 { 1624 1625 destination.setName(new String (source.getName())); 1627 1628 destination.setPropertyValue(FGCOLOR, this.getPropertyValue(FGCOLOR)); 1629 destination.setPropertyValue(BGCOLOR, this.getPropertyValue(BGCOLOR)); 1630 1631 destination.setBand(source.getBand()); 1632 destination.setCell(source.getCell()); 1633 destination.setPositionType(new String (source.getPositionType())); 1634 1635 destination.setPropertyValue(REMOVE_LINE_WHEN_BLANK, this.getPropertyValue(REMOVE_LINE_WHEN_BLANK)); 1636 destination.setPropertyValue(PRINT_REPEATED_VALUES, this.getPropertyValue(PRINT_REPEATED_VALUES) ); 1637 destination.setPropertyValue(PRINT_IN_FIRST_WHOLE_BAND, this.getPropertyValue(PRINT_IN_FIRST_WHOLE_BAND)); 1638 destination.setPropertyValue(PRINT_WHEN_DETAIL_OVERFLOW, this.getPropertyValue(PRINT_WHEN_DETAIL_OVERFLOW)); 1639 destination.setPropertyValue(MODE, this.getPropertyValue(MODE)); 1640 destination.setStretchType( source.getStretchType()); 1641 1642 destination.setStyle( this.getStyle() ); 1643 1644 destination.setPrintWhenExpression(new String (source.getPrintWhenExpression())); 1645 destination.setPrintWhenGroupChanges(new String (source.getPrintWhenGroupChanges())); 1646 1647 } 1648 1649 1654 public java.lang.String getKey() 1655 { 1656 1657 return name; 1658 } 1659 1660 1665 public void setKey(java.lang.String key) 1666 { 1667 this.name = key; 1668 } 1669 1670 1675 public java.lang.String getStretchType() 1676 { 1677 1678 return stretchType; 1679 } 1680 1681 1686 public void setStretchType(java.lang.String stretchType) 1687 { 1688 this.stretchType = stretchType; 1689 } 1690 1691 1696 public java.awt.Rectangle getBounds() 1697 { 1698 1699 return bounds; 1700 } 1701 1702 1707 public void setBounds(java.awt.Rectangle bounds) 1708 { 1709 this.position.x = bounds.x; 1710 this.position.y = bounds.y; 1711 this.width = bounds.width; 1712 this.height = bounds.height; 1713 this.updateBounds(); 1714 } 1715 1716 1721 public void addToGroup(String groupname) 1722 { 1723 1724 if (getElementGroup() == null || getElementGroup().equals("")) 1725 { 1726 setElementGroup(getElementGroup() + groupname); 1727 } 1728 else 1729 { 1730 setElementGroup(groupname + "." + getElementGroup()); 1731 } 1732 } 1733 1734 1739 public void removeFromGroup(String groupname) 1740 { 1741 1742 if (getElementGroup() == null || getElementGroup().equals("")) 1743 { 1744 1745 return; 1746 } 1747 1748 if (getElementGroup().startsWith(groupname)) 1749 { 1750 setElementGroup(getElementGroup().substring(groupname.length())); 1751 1752 if (getElementGroup().startsWith(".")) 1753 { 1754 setElementGroup(getElementGroup().substring(1)); 1755 } 1756 } 1757 } 1758 1759 1762 public void removeFromAllGroups() 1763 { 1764 setElementGroup(""); 1765 } 1766 1767 public String getElementGroup() { 1768 return elementGroup; 1769 } 1770 1771 public void setElementGroup(String elementGroup) { 1772 this.elementGroup = elementGroup; 1773 } 1774 1775 public ReportElement getParentElement() { 1776 return parentElement; 1777 } 1778 1779 public void setParentElement(ReportElement parentElement) { 1780 this.parentElement = parentElement; 1781 } 1782 1783 public int getElementID() { 1784 return elementID; 1785 } 1786 1787 public void setElementID(int elementID) { 1788 this.elementID = elementID; 1789 } 1790 1791 public Style getStyle() { 1792 return style; 1793 } 1794 1795 public void setStyle(Style style) { 1796 this.style = style; 1797 if (style != null) 1798 { 1799 } 1803 } 1804 1805 public CrosstabCell getCell() { 1806 return cell; 1807 } 1808 1809 public void setCell(CrosstabCell cell) { 1810 this.cell = cell; 1811 } 1812 1813 public Point getRelativePosition() { 1814 return relativePosition; 1815 } 1816 1817 public void setRelativePosition(Point relativePosition) { 1818 this.relativePosition = relativePosition; 1819 } 1820 1821} 1822 | Popular Tags |