1 28 29 30 34 35 package net.sf.jasperreports.engine; 36 37 import java.io.Serializable ; 38 import java.util.ArrayList ; 39 import java.util.Collection ; 40 import java.util.HashMap ; 41 import java.util.Iterator ; 42 import java.util.List ; 43 import java.util.Map ; 44 45 46 58 public class JasperPrint implements Serializable 59 { 60 61 64 private static class DefaultStyleProvider implements JRDefaultStyleProvider, Serializable 65 { 66 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 67 68 private JRReportFont defaultFont; 69 private JRStyle defaultStyle; 70 71 DefaultStyleProvider(JRReportFont font, JRStyle style) 72 { 73 this.defaultFont = font; 74 this.defaultStyle = style; 75 } 76 77 public JRReportFont getDefaultFont() 78 { 79 return defaultFont; 80 } 81 82 void setDefaultFont(JRReportFont font) 83 { 84 this.defaultFont = font; 85 } 86 87 public JRStyle getDefaultStyle() 88 { 89 return defaultStyle; 90 } 91 92 void setDefaultStyle(JRStyle style) 93 { 94 this.defaultStyle = style; 95 } 96 } 97 98 99 102 private static final long serialVersionUID = JRConstants.SERIAL_VERSION_UID; 103 104 107 private String name = null; 108 private int pageWidth = 0; 109 private int pageHeight = 0; 110 private byte orientation = JRReport.ORIENTATION_PORTRAIT; 111 112 private Map fontsMap = new HashMap (); 113 private List fontsList = new ArrayList (); 114 private Map stylesMap = new HashMap (); 115 private List stylesList = new ArrayList (); 116 117 private List pages = new ArrayList (); 118 119 private transient Map anchorIndexes = null; 120 private DefaultStyleProvider defaultStyleProvider = null; 121 122 private String formatFactoryClass; 123 private String localeCode; 124 private String timeZoneId; 125 126 127 130 public JasperPrint() 131 { 132 defaultStyleProvider = new DefaultStyleProvider(null, null); 133 } 134 135 138 public String getName() 139 { 140 return name; 141 } 142 143 148 public void setName(String name) 149 { 150 this.name = name; 151 } 152 153 156 public int getPageWidth() 157 { 158 return pageWidth; 159 } 160 161 166 public void setPageWidth(int pageWidth) 167 { 168 this.pageWidth = pageWidth; 169 } 170 171 174 public int getPageHeight() 175 { 176 return pageHeight; 177 } 178 179 184 public void setPageHeight(int pageHeight) 185 { 186 this.pageHeight = pageHeight; 187 } 188 189 190 195 public byte getOrientation() 196 { 197 return orientation; 198 } 199 200 205 public void setOrientation(byte orientation) 206 { 207 this.orientation = orientation; 208 } 209 210 213 public JRReportFont getDefaultFont() 214 { 215 return defaultStyleProvider.getDefaultFont(); 216 } 217 218 221 public void setDefaultFont(JRReportFont font) 222 { 223 defaultStyleProvider.setDefaultFont(font); 224 } 225 226 230 public JRDefaultFontProvider getDefaultFontProvider() 231 { 232 return defaultStyleProvider; 233 } 234 235 239 public JRReportFont[] getFonts() 240 { 241 JRReportFont[] fontsArray = new JRReportFont[fontsList.size()]; 242 243 fontsList.toArray(fontsArray); 244 245 return fontsArray; 246 } 247 248 252 public List getFontsList() 253 { 254 return fontsList; 255 } 256 257 261 public Map getFontsMap() 262 { 263 return fontsMap; 264 } 265 266 270 public synchronized void addFont(JRReportFont reportFont) throws JRException 271 { 272 addFont(reportFont, false); 273 } 274 275 279 public synchronized void addFont(JRReportFont reportFont, boolean isIgnoreDuplicate) throws JRException 280 { 281 if (fontsMap.containsKey(reportFont.getName())) 282 { 283 if (!isIgnoreDuplicate) 284 { 285 throw new JRException("Duplicate declaration of report font : " + reportFont.getName()); 286 } 287 } 288 else 289 { 290 fontsList.add(reportFont); 291 fontsMap.put(reportFont.getName(), reportFont); 292 293 if (reportFont.isDefault()) 294 { 295 setDefaultFont(reportFont); 296 } 297 } 298 } 299 300 303 public synchronized JRReportFont removeFont(String fontName) 304 { 305 return removeFont( 306 (JRReportFont)fontsMap.get(fontName) 307 ); 308 } 309 310 313 public synchronized JRReportFont removeFont(JRReportFont reportFont) 314 { 315 if (reportFont != null) 316 { 317 if (reportFont.isDefault()) 318 { 319 setDefaultFont(null); 320 } 321 322 fontsList.remove(reportFont); 323 fontsMap.remove(reportFont.getName()); 324 } 325 326 return reportFont; 327 } 328 329 332 public JRStyle getDefaultStyle() 333 { 334 return defaultStyleProvider.getDefaultStyle(); 335 } 336 337 340 public synchronized void setDefaultStyle(JRStyle style) 341 { 342 defaultStyleProvider.setDefaultStyle(style); 343 } 344 345 349 public JRDefaultStyleProvider getDefaultStyleProvider() 350 { 351 return defaultStyleProvider; 352 } 353 354 357 public JRStyle[] getStyles() 358 { 359 JRStyle[] stylesArray = new JRStyle[stylesList.size()]; 360 361 stylesList.toArray(stylesArray); 362 363 return stylesArray; 364 } 365 366 369 public List getStylesList() 370 { 371 return stylesList; 372 } 373 374 377 public Map getStylesMap() 378 { 379 return stylesMap; 380 } 381 382 385 public synchronized void addStyle(JRStyle style) throws JRException 386 { 387 addStyle(style, false); 388 } 389 390 393 public synchronized void addStyle(JRStyle style, boolean isIgnoreDuplicate) throws JRException 394 { 395 if (stylesMap.containsKey(style.getName())) 396 { 397 if (!isIgnoreDuplicate) 398 { 399 throw new JRException("Duplicate declaration of report style : " + style.getName()); 400 } 401 } 402 else 403 { 404 stylesList.add(style); 405 stylesMap.put(style.getName(), style); 406 407 if (style.isDefault()) 408 { 409 setDefaultStyle(style); 410 } 411 } 412 } 413 414 417 public synchronized JRStyle removeStyle(String styleName) 418 { 419 return removeStyle( 420 (JRStyle)stylesMap.get(styleName) 421 ); 422 } 423 424 427 public synchronized JRStyle removeStyle(JRStyle style) 428 { 429 if (style != null) 430 { 431 if (style.isDefault()) 432 { 433 setDefaultStyle(null); 434 } 435 436 stylesList.remove(style); 437 stylesMap.remove(style.getName()); 438 } 439 440 return style; 441 } 442 443 446 public List getPages() 447 { 448 return pages; 449 } 450 451 454 public synchronized void addPage(JRPrintPage page) 455 { 456 anchorIndexes = null; 457 pages.add(page); 458 } 459 460 463 public synchronized void addPage(int index, JRPrintPage page) 464 { 465 anchorIndexes = null; 466 pages.add(index, page); 467 } 468 469 472 public synchronized JRPrintPage removePage(int index) 473 { 474 anchorIndexes = null; 475 return (JRPrintPage)pages.remove(index); 476 } 477 478 481 public synchronized Map getAnchorIndexes() 482 { 483 if (anchorIndexes == null) 484 { 485 anchorIndexes = new HashMap (); 486 487 int i = 0; 488 for(Iterator itp = pages.iterator(); itp.hasNext(); i++) 489 { 490 JRPrintPage page = (JRPrintPage)itp.next(); 491 Collection elements = page.getElements(); 492 collectAnchors(elements, i, 0, 0); 493 } 494 } 495 496 return anchorIndexes; 497 } 498 499 protected void collectAnchors(Collection elements, int pageIndex, int offsetX, int offsetY) 500 { 501 if (elements != null && elements.size() > 0) 502 { 503 JRPrintElement element = null; 504 for(Iterator it = elements.iterator(); it.hasNext();) 505 { 506 element = (JRPrintElement)it.next(); 507 if (element instanceof JRPrintAnchor) 508 { 509 anchorIndexes.put( 510 ((JRPrintAnchor)element).getAnchorName(), 511 new JRPrintAnchorIndex(pageIndex, element, offsetX, offsetY) 512 ); 513 } 514 515 if (element instanceof JRPrintFrame) 516 { 517 JRPrintFrame frame = (JRPrintFrame) element; 518 collectAnchors(frame.getElements(), pageIndex, offsetX + frame.getX(), offsetY + frame.getY()); 519 } 520 } 521 } 522 } 523 524 525 529 public String getFormatFactoryClass() 530 { 531 return formatFactoryClass; 532 } 533 534 535 539 public void setFormatFactoryClass(String formatFactoryClass) 540 { 541 this.formatFactoryClass = formatFactoryClass; 542 } 543 544 545 558 public String getLocaleCode() 559 { 560 return localeCode; 561 } 562 563 564 572 public void setLocaleCode(String localeCode) 573 { 574 this.localeCode = localeCode; 575 } 576 577 578 591 public String getTimeZoneId() 592 { 593 return timeZoneId; 594 } 595 596 597 605 public void setTimeZoneId(String timeZoneId) 606 { 607 this.timeZoneId = timeZoneId; 608 } 609 610 611 } 612 | Popular Tags |