001 /* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 025 * in the United States and other countries.] 026 * 027 * ------------------- 028 * ChartUtilities.java 029 * ------------------- 030 * (C) Copyright 2001-2007, by Object Refinery Limited and Contributors. 031 * 032 * Original Author: David Gilbert (for Object Refinery Limited); 033 * Contributor(s): Wolfgang Irler; 034 * Richard Atkinson; 035 * Xavier Poinsard; 036 * 037 * Changes 038 * ------- 039 * 11-Dec-2001 : Version 1. The JPEG method comes from Wolfgang Irler's 040 * JFreeChartServletDemo class (DG); 041 * 23-Jan-2002 : Changed saveChartAsXXX() methods to pass IOExceptions back to 042 * caller (DG); 043 * 26-Jun-2002 : Added image map methods (DG); 044 * 05-Aug-2002 : Added writeBufferedImage methods 045 * Modified writeImageMap method to support flexible image 046 * maps (RA); 047 * 26-Aug-2002 : Added saveChartAsJPEG and writeChartAsJPEG methods with info 048 * objects (RA); 049 * 05-Sep-2002 : Added writeImageMap() method to support OverLIB 050 * - http://www.bosrup.com/web/overlib (RA); 051 * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG); 052 * 17-Oct-2002 : Exposed JPEG quality setting and PNG compression level as 053 * parameters (DG); 054 * 25-Oct-2002 : Fixed writeChartAsJPEG() empty method bug (DG); 055 * 13-Mar-2003 : Updated writeImageMap method as suggested by Xavier Poinsard 056 * (see Feature Request 688079) (DG); 057 * 12-Aug-2003 : Added support for custom image maps using 058 * ToolTipTagFragmentGenerator and URLTagFragmentGenerator (RA); 059 * 02-Sep-2003 : Separated PNG encoding from writing chart to an 060 * OutputStream (RA); 061 * 04-Dec-2003 : Chart draw() method modified to include anchor point (DG); 062 * 20-Feb-2004 : Edited Javadocs and added argument checking (DG); 063 * 05-Apr-2004 : Fixed problem with buffered image type (DG); 064 * 01-Aug-2004 : Modified to use EncoderUtil for all image encoding (RA); 065 * 02-Aug-2004 : Delegated image map related functionality to ImageMapUtil (RA); 066 * 13-Jan-2005 : Renamed ImageMapUtil --> ImageMapUtilities, removed method 067 * writeImageMap(PrintWriter, String, ChartRenderingInfo) which 068 * exists in ImageMapUtilities (DG); 069 * ------------- JFREECHART 1.0.x --------------------------------------------- 070 * 06-Feb-2006 : API doc update (DG); 071 * 19-Mar-2007 : Use try-finally to close output stream in saveChartAsXXX() 072 * methods (DG); 073 * 074 */ 075 076 package org.jfree.chart; 077 078 import java.awt.Graphics2D; 079 import java.awt.geom.AffineTransform; 080 import java.awt.geom.Rectangle2D; 081 import java.awt.image.BufferedImage; 082 import java.io.BufferedOutputStream; 083 import java.io.File; 084 import java.io.FileOutputStream; 085 import java.io.IOException; 086 import java.io.OutputStream; 087 import java.io.PrintWriter; 088 089 import org.jfree.chart.encoders.EncoderUtil; 090 import org.jfree.chart.encoders.ImageFormat; 091 import org.jfree.chart.imagemap.ImageMapUtilities; 092 import org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator; 093 import org.jfree.chart.imagemap.StandardToolTipTagFragmentGenerator; 094 import org.jfree.chart.imagemap.StandardURLTagFragmentGenerator; 095 import org.jfree.chart.imagemap.ToolTipTagFragmentGenerator; 096 import org.jfree.chart.imagemap.URLTagFragmentGenerator; 097 098 /** 099 * A collection of utility methods for JFreeChart. Includes methods for 100 * converting charts to image formats (PNG and JPEG) plus creating simple HTML 101 * image maps. 102 * 103 * @see ImageMapUtilities 104 */ 105 public abstract class ChartUtilities { 106 107 /** 108 * Writes a chart to an output stream in PNG format. 109 * 110 * @param out the output stream (<code>null</code> not permitted). 111 * @param chart the chart (<code>null</code> not permitted). 112 * @param width the image width. 113 * @param height the image height. 114 * 115 * @throws IOException if there are any I/O errors. 116 */ 117 public static void writeChartAsPNG(OutputStream out, JFreeChart chart, 118 int width, int height) throws IOException { 119 120 // defer argument checking... 121 writeChartAsPNG(out, chart, width, height, null); 122 123 } 124 125 /** 126 * Writes a chart to an output stream in PNG format. 127 * 128 * @param out the output stream (<code>null</code> not permitted). 129 * @param chart the chart (<code>null</code> not permitted). 130 * @param width the image width. 131 * @param height the image height. 132 * @param encodeAlpha encode alpha? 133 * @param compression the compression level (0-9). 134 * 135 * @throws IOException if there are any I/O errors. 136 */ 137 public static void writeChartAsPNG(OutputStream out, JFreeChart chart, 138 int width, int height, boolean encodeAlpha, int compression) 139 throws IOException { 140 141 // defer argument checking... 142 ChartUtilities.writeChartAsPNG(out, chart, width, height, null, 143 encodeAlpha, compression); 144 145 } 146 147 /** 148 * Writes a chart to an output stream in PNG format. This method allows 149 * you to pass in a {@link ChartRenderingInfo} object, to collect 150 * information about the chart dimensions/entities. You will need this 151 * info if you want to create an HTML image map. 152 * 153 * @param out the output stream (<code>null</code> not permitted). 154 * @param chart the chart (<code>null</code> not permitted). 155 * @param width the image width. 156 * @param height the image height. 157 * @param info the chart rendering info (<code>null</code> permitted). 158 * 159 * @throws IOException if there are any I/O errors. 160 */ 161 public static void writeChartAsPNG(OutputStream out, JFreeChart chart, 162 int width, int height, ChartRenderingInfo info) 163 throws IOException { 164 165 if (chart == null) { 166 throw new IllegalArgumentException("Null 'chart' argument."); 167 } 168 BufferedImage bufferedImage 169 = chart.createBufferedImage(width, height, info); 170 EncoderUtil.writeBufferedImage(bufferedImage, ImageFormat.PNG, out); 171 } 172 173 /** 174 * Writes a chart to an output stream in PNG format. This method allows 175 * you to pass in a {@link ChartRenderingInfo} object, to collect 176 * information about the chart dimensions/entities. You will need this 177 * info if you want to create an HTML image map. 178 * 179 * @param out the output stream (<code>null</code> not permitted). 180 * @param chart the chart (<code>null</code> not permitted). 181 * @param width the image width. 182 * @param height the image height. 183 * @param info carries back chart rendering info (<code>null</code> 184 * permitted). 185 * @param encodeAlpha encode alpha? 186 * @param compression the PNG compression level (0-9). 187 * 188 * @throws IOException if there are any I/O errors. 189 */ 190 public static void writeChartAsPNG(OutputStream out, JFreeChart chart, 191 int width, int height, ChartRenderingInfo info, 192 boolean encodeAlpha, int compression) throws IOException { 193 194 if (out == null) { 195 throw new IllegalArgumentException("Null 'out' argument."); 196 } 197 if (chart == null) { 198 throw new IllegalArgumentException("Null 'chart' argument."); 199 } 200 BufferedImage chartImage = chart.createBufferedImage(width, height, 201 BufferedImage.TYPE_INT_ARGB, info); 202 ChartUtilities.writeBufferedImageAsPNG(out, chartImage, encodeAlpha, 203 compression); 204 205 } 206 207 /** 208 * Writes a scaled version of a chart to an output stream in PNG format. 209 * 210 * @param out the output stream (<code>null</code> not permitted). 211 * @param chart the chart (<code>null</code> not permitted). 212 * @param width the unscaled chart width. 213 * @param height the unscaled chart height. 214 * @param widthScaleFactor the horizontal scale factor. 215 * @param heightScaleFactor the vertical scale factor. 216 * 217 * @throws IOException if there are any I/O problems. 218 */ 219 public static void writeScaledChartAsPNG(OutputStream out, 220 JFreeChart chart, int width, int height, int widthScaleFactor, 221 int heightScaleFactor) throws IOException { 222 223 if (out == null) { 224 throw new IllegalArgumentException("Null 'out' argument."); 225 } 226 if (chart == null) { 227 throw new IllegalArgumentException("Null 'chart' argument."); 228 } 229 230 double desiredWidth = width * widthScaleFactor; 231 double desiredHeight = height * heightScaleFactor; 232 double defaultWidth = width; 233 double defaultHeight = height; 234 boolean scale = false; 235 236 // get desired width and height from somewhere then... 237 if ((widthScaleFactor != 1) || (heightScaleFactor != 1)) { 238 scale = true; 239 } 240 241 double scaleX = desiredWidth / defaultWidth; 242 double scaleY = desiredHeight / defaultHeight; 243 244 BufferedImage image = new BufferedImage((int) desiredWidth, 245 (int) desiredHeight, BufferedImage.TYPE_INT_ARGB); 246 Graphics2D g2 = image.createGraphics(); 247 248 if (scale) { 249 AffineTransform saved = g2.getTransform(); 250 g2.transform(AffineTransform.getScaleInstance(scaleX, scaleY)); 251 chart.draw(g2, new Rectangle2D.Double(0, 0, defaultWidth, 252 defaultHeight), null, null); 253 g2.setTransform(saved); 254 g2.dispose(); 255 } 256 else { 257 chart.draw(g2, new Rectangle2D.Double(0, 0, defaultWidth, 258 defaultHeight), null, null); 259 } 260 out.write(encodeAsPNG(image)); 261 262 } 263 264 /** 265 * Saves a chart to the specified file in PNG format. 266 * 267 * @param file the file name (<code>null</code> not permitted). 268 * @param chart the chart (<code>null</code> not permitted). 269 * @param width the image width. 270 * @param height the image height. 271 * 272 * @throws IOException if there are any I/O errors. 273 */ 274 public static void saveChartAsPNG(File file, JFreeChart chart, 275 int width, int height) throws IOException { 276 277 // defer argument checking... 278 saveChartAsPNG(file, chart, width, height, null); 279 280 } 281 282 /** 283 * Saves a chart to a file in PNG format. This method allows you to pass 284 * in a {@link ChartRenderingInfo} object, to collect information about the 285 * chart dimensions/entities. You will need this info if you want to 286 * create an HTML image map. 287 * 288 * @param file the file (<code>null</code> not permitted). 289 * @param chart the chart (<code>null</code> not permitted). 290 * @param width the image width. 291 * @param height the image height. 292 * @param info the chart rendering info (<code>null</code> permitted). 293 * 294 * @throws IOException if there are any I/O errors. 295 */ 296 public static void saveChartAsPNG(File file, JFreeChart chart, 297 int width, int height, ChartRenderingInfo info) 298 throws IOException { 299 300 if (file == null) { 301 throw new IllegalArgumentException("Null 'file' argument."); 302 } 303 OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 304 try { 305 ChartUtilities.writeChartAsPNG(out, chart, width, height, info); 306 } 307 finally { 308 out.close(); 309 } 310 } 311 312 /** 313 * Saves a chart to a file in PNG format. This method allows you to pass 314 * in a {@link ChartRenderingInfo} object, to collect information about the 315 * chart dimensions/entities. You will need this info if you want to 316 * create an HTML image map. 317 * 318 * @param file the file (<code>null</code> not permitted). 319 * @param chart the chart (<code>null</code> not permitted). 320 * @param width the image width. 321 * @param height the image height. 322 * @param info the chart rendering info (<code>null</code> permitted). 323 * @param encodeAlpha encode alpha? 324 * @param compression the PNG compression level (0-9). 325 * 326 * @throws IOException if there are any I/O errors. 327 */ 328 public static void saveChartAsPNG(File file, JFreeChart chart, 329 int width, int height, ChartRenderingInfo info, boolean encodeAlpha, 330 int compression) throws IOException { 331 332 if (file == null) { 333 throw new IllegalArgumentException("Null 'file' argument."); 334 } 335 if (chart == null) { 336 throw new IllegalArgumentException("Null 'chart' argument."); 337 } 338 339 OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 340 try { 341 writeChartAsPNG(out, chart, width, height, info, encodeAlpha, 342 compression); 343 } 344 finally { 345 out.close(); 346 } 347 348 } 349 350 /** 351 * Writes a chart to an output stream in JPEG format. Please note that 352 * JPEG is a poor format for chart images, use PNG if possible. 353 * 354 * @param out the output stream (<code>null</code> not permitted). 355 * @param chart the chart (<code>null</code> not permitted). 356 * @param width the image width. 357 * @param height the image height. 358 * 359 * @throws IOException if there are any I/O errors. 360 */ 361 public static void writeChartAsJPEG(OutputStream out, 362 JFreeChart chart, int width, int height) throws IOException { 363 364 // defer argument checking... 365 writeChartAsJPEG(out, chart, width, height, null); 366 367 } 368 369 /** 370 * Writes a chart to an output stream in JPEG format. Please note that 371 * JPEG is a poor format for chart images, use PNG if possible. 372 * 373 * @param out the output stream (<code>null</code> not permitted). 374 * @param quality the quality setting. 375 * @param chart the chart (<code>null</code> not permitted). 376 * @param width the image width. 377 * @param height the image height. 378 * 379 * @throws IOException if there are any I/O errors. 380 */ 381 public static void writeChartAsJPEG(OutputStream out, float quality, 382 JFreeChart chart, int width, int height) throws IOException { 383 384 // defer argument checking... 385 ChartUtilities.writeChartAsJPEG(out, quality, chart, width, height, 386 null); 387 388 } 389 390 /** 391 * Writes a chart to an output stream in JPEG format. This method allows 392 * you to pass in a {@link ChartRenderingInfo} object, to collect 393 * information about the chart dimensions/entities. You will need this 394 * info if you want to create an HTML image map. 395 * 396 * @param out the output stream (<code>null</code> not permitted). 397 * @param chart the chart (<code>null</code> not permitted). 398 * @param width the image width. 399 * @param height the image height. 400 * @param info the chart rendering info (<code>null</code> permitted). 401 * 402 * @throws IOException if there are any I/O errors. 403 */ 404 public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, 405 int width, int height, ChartRenderingInfo info) 406 throws IOException { 407 408 if (chart == null) { 409 throw new IllegalArgumentException("Null 'chart' argument."); 410 } 411 BufferedImage image = chart.createBufferedImage(width, height, info); 412 EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out); 413 414 } 415 416 /** 417 * Writes a chart to an output stream in JPEG format. This method allows 418 * you to pass in a {@link ChartRenderingInfo} object, to collect 419 * information about the chart dimensions/entities. You will need this 420 * info if you want to create an HTML image map. 421 * 422 * @param out the output stream (<code>null</code> not permitted). 423 * @param quality the output quality (0.0f to 1.0f). 424 * @param chart the chart (<code>null</code> not permitted). 425 * @param width the image width. 426 * @param height the image height. 427 * @param info the chart rendering info (<code>null</code> permitted). 428 * 429 * @throws IOException if there are any I/O errors. 430 */ 431 public static void writeChartAsJPEG(OutputStream out, float quality, 432 JFreeChart chart, int width, int height, ChartRenderingInfo info) 433 throws IOException { 434 435 if (chart == null) { 436 throw new IllegalArgumentException("Null 'chart' argument."); 437 } 438 BufferedImage image = chart.createBufferedImage(width, height, info); 439 EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, quality); 440 441 } 442 443 /** 444 * Saves a chart to a file in JPEG format. 445 * 446 * @param file the file (<code>null</code> not permitted). 447 * @param chart the chart (<code>null</code> not permitted). 448 * @param width the image width. 449 * @param height the image height. 450 * 451 * @throws IOException if there are any I/O errors. 452 */ 453 public static void saveChartAsJPEG(File file, JFreeChart chart, 454 int width, int height) throws IOException { 455 456 // defer argument checking... 457 saveChartAsJPEG(file, chart, width, height, null); 458 459 } 460 461 /** 462 * Saves a chart to a file in JPEG format. 463 * 464 * @param file the file (<code>null</code> not permitted). 465 * @param quality the JPEG quality setting. 466 * @param chart the chart (<code>null</code> not permitted). 467 * @param width the image width. 468 * @param height the image height. 469 * 470 * @throws IOException if there are any I/O errors. 471 */ 472 public static void saveChartAsJPEG(File file, float quality, 473 JFreeChart chart, int width, int height) throws IOException { 474 475 // defer argument checking... 476 saveChartAsJPEG(file, quality, chart, width, height, null); 477 478 } 479 480 /** 481 * Saves a chart to a file in JPEG format. This method allows you to pass 482 * in a {@link ChartRenderingInfo} object, to collect information about the 483 * chart dimensions/entities. You will need this info if you want to 484 * create an HTML image map. 485 * 486 * @param file the file name (<code>null</code> not permitted). 487 * @param chart the chart (<code>null</code> not permitted). 488 * @param width the image width. 489 * @param height the image height. 490 * @param info the chart rendering info (<code>null</code> permitted). 491 * 492 * @throws IOException if there are any I/O errors. 493 */ 494 public static void saveChartAsJPEG(File file, JFreeChart chart, 495 int width, int height, ChartRenderingInfo info) throws IOException { 496 497 if (file == null) { 498 throw new IllegalArgumentException("Null 'file' argument."); 499 } 500 if (chart == null) { 501 throw new IllegalArgumentException("Null 'chart' argument."); 502 } 503 OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 504 try { 505 writeChartAsJPEG(out, chart, width, height, info); 506 } 507 finally { 508 out.close(); 509 } 510 511 } 512 513 /** 514 * Saves a chart to a file in JPEG format. This method allows you to pass 515 * in a {@link ChartRenderingInfo} object, to collect information about the 516 * chart dimensions/entities. You will need this info if you want to 517 * create an HTML image map. 518 * 519 * @param file the file name (<code>null</code> not permitted). 520 * @param quality the quality setting. 521 * @param chart the chart (<code>null</code> not permitted). 522 * @param width the image width. 523 * @param height the image height. 524 * @param info the chart rendering info (<code>null</code> permitted). 525 * 526 * @throws IOException if there are any I/O errors. 527 */ 528 public static void saveChartAsJPEG(File file, float quality, 529 JFreeChart chart, int width, int height, 530 ChartRenderingInfo info) throws IOException { 531 532 if (file == null) { 533 throw new IllegalArgumentException("Null 'file' argument."); 534 } 535 if (chart == null) { 536 throw new IllegalArgumentException("Null 'chart' argument."); 537 } 538 539 OutputStream out = new BufferedOutputStream(new FileOutputStream( 540 file)); 541 try { 542 writeChartAsJPEG(out, quality, chart, width, height, info); 543 } 544 finally { 545 out.close(); 546 } 547 548 } 549 550 /** 551 * Writes a {@link BufferedImage} to an output stream in JPEG format. 552 * 553 * @param out the output stream (<code>null</code> not permitted). 554 * @param image the image (<code>null</code> not permitted). 555 * 556 * @throws IOException if there are any I/O errors. 557 */ 558 public static void writeBufferedImageAsJPEG(OutputStream out, 559 BufferedImage image) throws IOException { 560 561 // defer argument checking... 562 writeBufferedImageAsJPEG(out, 0.75f, image); 563 564 } 565 566 /** 567 * Writes a {@link BufferedImage} to an output stream in JPEG format. 568 * 569 * @param out the output stream (<code>null</code> not permitted). 570 * @param quality the image quality (0.0f to 1.0f). 571 * @param image the image (<code>null</code> not permitted). 572 * 573 * @throws IOException if there are any I/O errors. 574 */ 575 public static void writeBufferedImageAsJPEG(OutputStream out, float quality, 576 BufferedImage image) throws IOException { 577 578 EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, quality); 579 580 } 581 582 /** 583 * Writes a {@link BufferedImage} to an output stream in PNG format. 584 * 585 * @param out the output stream (<code>null</code> not permitted). 586 * @param image the image (<code>null</code> not permitted). 587 * 588 * @throws IOException if there are any I/O errors. 589 */ 590 public static void writeBufferedImageAsPNG(OutputStream out, 591 BufferedImage image) throws IOException { 592 593 EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, out); 594 595 } 596 597 /** 598 * Writes a {@link BufferedImage} to an output stream in PNG format. 599 * 600 * @param out the output stream (<code>null</code> not permitted). 601 * @param image the image (<code>null</code> not permitted). 602 * @param encodeAlpha encode alpha? 603 * @param compression the compression level (0-9). 604 * 605 * @throws IOException if there are any I/O errors. 606 */ 607 public static void writeBufferedImageAsPNG(OutputStream out, 608 BufferedImage image, boolean encodeAlpha, int compression) 609 throws IOException { 610 611 EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, out, 612 compression, encodeAlpha); 613 } 614 615 /** 616 * Encodes a {@link BufferedImage} to PNG format. 617 * 618 * @param image the image (<code>null</code> not permitted). 619 * 620 * @return A byte array in PNG format. 621 * 622 * @throws IOException if there is an I/O problem. 623 */ 624 public static byte[] encodeAsPNG(BufferedImage image) throws IOException { 625 return EncoderUtil.encode(image, ImageFormat.PNG); 626 } 627 628 /** 629 * Encodes a {@link BufferedImage} to PNG format. 630 * 631 * @param image the image (<code>null</code> not permitted). 632 * @param encodeAlpha encode alpha? 633 * @param compression the PNG compression level (0-9). 634 * 635 * @return The byte array in PNG format. 636 * 637 * @throws IOException if there is an I/O problem. 638 */ 639 public static byte[] encodeAsPNG(BufferedImage image, boolean encodeAlpha, 640 int compression) 641 throws IOException { 642 return EncoderUtil.encode(image, ImageFormat.PNG, compression, 643 encodeAlpha); 644 } 645 646 /** 647 * Writes an image map to an output stream. 648 * 649 * @param writer the writer (<code>null</code> not permitted). 650 * @param name the map name (<code>null</code> not permitted). 651 * @param info the chart rendering info (<code>null</code> not permitted). 652 * @param useOverLibForToolTips whether to use OverLIB for tooltips 653 * (http://www.bosrup.com/web/overlib/). 654 * 655 * @throws IOException if there are any I/O errors. 656 */ 657 public static void writeImageMap(PrintWriter writer, 658 String name, 659 ChartRenderingInfo info, 660 boolean useOverLibForToolTips) 661 throws IOException { 662 663 ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null; 664 if (useOverLibForToolTips) { 665 toolTipTagFragmentGenerator 666 = new OverLIBToolTipTagFragmentGenerator(); 667 } 668 else { 669 toolTipTagFragmentGenerator 670 = new StandardToolTipTagFragmentGenerator(); 671 } 672 ImageMapUtilities.writeImageMap(writer, name, info, 673 toolTipTagFragmentGenerator, 674 new StandardURLTagFragmentGenerator()); 675 676 } 677 678 /** 679 * Writes an image map to the specified writer. 680 * 681 * @param writer the writer (<code>null</code> not permitted). 682 * @param name the map name (<code>null</code> not permitted). 683 * @param info the chart rendering info (<code>null</code> not permitted). 684 * @param toolTipTagFragmentGenerator a generator for the HTML fragment 685 * that will contain the tooltip text (<code>null</code> not permitted 686 * if <code>info</code> contains tooltip information). 687 * @param urlTagFragmentGenerator a generator for the HTML fragment that 688 * will contain the URL reference (<code>null</code> not permitted if 689 * <code>info</code> contains URLs). 690 * 691 * @throws IOException if there are any I/O errors. 692 */ 693 public static void writeImageMap(PrintWriter writer, String name, 694 ChartRenderingInfo info, 695 ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, 696 URLTagFragmentGenerator urlTagFragmentGenerator) 697 throws IOException { 698 699 writer.println(ImageMapUtilities.getImageMap(name, info, 700 toolTipTagFragmentGenerator, urlTagFragmentGenerator)); 701 } 702 703 /** 704 * Creates an HTML image map. This method maps to 705 * {@link ImageMapUtilities#getImageMap(String, ChartRenderingInfo, 706 * ToolTipTagFragmentGenerator, URLTagFragmentGenerator)}, using default 707 * generators. 708 * 709 * @param name the map name (<code>null</code> not permitted). 710 * @param info the chart rendering info (<code>null</code> not permitted). 711 * 712 * @return The map tag. 713 */ 714 public static String getImageMap(String name, ChartRenderingInfo info) { 715 return ImageMapUtilities.getImageMap(name, info, 716 new StandardToolTipTagFragmentGenerator(), 717 new StandardURLTagFragmentGenerator()); 718 } 719 720 /** 721 * Creates an HTML image map. This method maps directly to 722 * {@link ImageMapUtilities#getImageMap(String, ChartRenderingInfo, 723 * ToolTipTagFragmentGenerator, URLTagFragmentGenerator)}. 724 * 725 * @param name the map name (<code>null</code> not permitted). 726 * @param info the chart rendering info (<code>null</code> not permitted). 727 * @param toolTipTagFragmentGenerator a generator for the HTML fragment 728 * that will contain the tooltip text (<code>null</code> not permitted 729 * if <code>info</code> contains tooltip information). 730 * @param urlTagFragmentGenerator a generator for the HTML fragment that 731 * will contain the URL reference (<code>null</code> not permitted if 732 * <code>info</code> contains URLs). 733 * 734 * @return The map tag. 735 */ 736 public static String getImageMap(String name, ChartRenderingInfo info, 737 ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, 738 URLTagFragmentGenerator urlTagFragmentGenerator) { 739 740 return ImageMapUtilities.getImageMap(name, info, 741 toolTipTagFragmentGenerator, urlTagFragmentGenerator); 742 743 } 744 745 }