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