KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > ChartUtilities


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * -------------------
27  * ChartUtilities.java
28  * -------------------
29  * (C) Copyright 2001-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): Wolfgang Irler;
33  * Richard Atkinson;
34  * Xavier Poinsard;
35  *
36  * $Id: ChartUtilities.java,v 1.4 2005/03/28 19:38:39 mungady Exp $
37  *
38  * Changes
39  * -------
40  * 11-Dec-2001 : Version 1. The JPEG method comes from Wolfgang Irler's
41  * JFreeChartServletDemo class (DG);
42  * 23-Jan-2002 : Changed saveChartAsXXX() methods to pass IOExceptions back to
43  * caller (DG);
44  * 26-Jun-2002 : Added image map methods (DG);
45  * 05-Aug-2002 : Added writeBufferedImage methods
46  * Modified writeImageMap method to support flexible image
47  * maps (RA);
48  * 26-Aug-2002 : Added saveChartAsJPEG and writeChartAsJPEG methods with info
49  * objects (RA);
50  * 05-Sep-2002 : Added writeImageMap() method to support OverLIB
51  * - http://www.bosrup.com/web/overlib (RA);
52  * 26-Sep-2002 : Fixed errors reported by Checkstyle (DG);
53  * 17-Oct-2002 : Exposed JPEG quality setting and PNG compression level as
54  * parameters (DG);
55  * 25-Oct-2002 : Fixed writeChartAsJPEG() empty method bug (DG);
56  * 13-Mar-2003 : Updated writeImageMap method as suggested by Xavier Poinsard
57  * (see Feature Request 688079) (DG);
58  * 12-Aug-2003 : Added support for custom image maps using
59  * ToolTipTagFragmentGenerator and URLTagFragmentGenerator (RA);
60  * 02-Sep-2003 : Separated PNG encoding from writing chart to an
61  * OutputStream (RA);
62  * 04-Dec-2003 : Chart draw() method modified to include anchor point (DG);
63  * 20-Feb-2004 : Edited Javadocs and added argument checking (DG);
64  * 05-Apr-2004 : Fixed problem with buffered image type (DG);
65  * 01-Aug-2004 : Modified to use EncoderUtil for all image encoding (RA);
66  * 02-Aug-2004 : Delegated image map related functionality to ImageMapUtil (RA);
67  * 13-Jan-2005 : Renamed ImageMapUtil --> ImageMapUtilities, removed method
68  * writeImageMap(PrintWriter, String, ChartRenderingInfo) which
69  * exists in ImageMapUtilities (DG);
70  *
71  */

72
73 package org.jfree.chart;
74
75 import java.awt.Graphics2D JavaDoc;
76 import java.awt.geom.AffineTransform JavaDoc;
77 import java.awt.geom.Rectangle2D JavaDoc;
78 import java.awt.image.BufferedImage JavaDoc;
79 import java.io.BufferedOutputStream JavaDoc;
80 import java.io.File JavaDoc;
81 import java.io.FileOutputStream JavaDoc;
82 import java.io.IOException JavaDoc;
83 import java.io.OutputStream JavaDoc;
84 import java.io.PrintWriter JavaDoc;
85
86 import org.jfree.chart.imagemap.ImageMapUtilities;
87 import org.jfree.chart.imagemap.OverLIBToolTipTagFragmentGenerator;
88 import org.jfree.chart.imagemap.StandardToolTipTagFragmentGenerator;
89 import org.jfree.chart.imagemap.StandardURLTagFragmentGenerator;
90 import org.jfree.chart.imagemap.ToolTipTagFragmentGenerator;
91 import org.jfree.chart.imagemap.URLTagFragmentGenerator;
92
93 import org.jfree.chart.encoders.EncoderUtil;
94 import org.jfree.chart.encoders.ImageFormat;
95
96 /**
97  * A collection of utility methods for JFreeChart. Includes methods for
98  * converting charts to image formats (PNG and JPEG) plus creating simple HTML
99  * image maps.
100  */

101 public abstract class ChartUtilities {
102
103     /**
104      * Writes a chart to an output stream in PNG format.
105      *
106      * @param out the output stream (<code>null</code> not permitted).
107      * @param chart the chart (<code>null</code> not permitted).
108      * @param width the image width.
109      * @param height the image height.
110      *
111      * @throws IOException if there are any I/O errors.
112      */

113     public static void writeChartAsPNG(OutputStream JavaDoc out,
114                                        JFreeChart chart,
115                                        int width,
116                                        int height) throws IOException JavaDoc {
117
118         // defer argument checking...
119
writeChartAsPNG(out, chart, width, height, null);
120
121     }
122
123     /**
124      * Writes a chart to an output stream in PNG format.
125      *
126      * @param out the output stream (<code>null</code> not permitted).
127      * @param chart the chart (<code>null</code> not permitted).
128      * @param width the image width.
129      * @param height the image height.
130      * @param encodeAlpha encode alpha?
131      * @param compression the compression level (0-9).
132      *
133      * @throws IOException if there are any I/O errors.
134      */

135     public static void writeChartAsPNG(OutputStream JavaDoc out,
136                                        JFreeChart chart,
137                                        int width,
138                                        int height,
139                                        boolean encodeAlpha,
140                                        int compression) throws IOException JavaDoc {
141
142         // defer argument checking...
143
ChartUtilities.writeChartAsPNG(
144             out, chart, width, height, null, encodeAlpha, compression
145         );
146
147     }
148
149     /**
150      * Writes a chart to an output stream in PNG format. This method allows
151      * you to pass in a {@link ChartRenderingInfo} object, to collect
152      * information about the chart dimensions/entities. You will need this
153      * info if you want to create an HTML image map.
154      *
155      * @param out the output stream (<code>null</code> not permitted).
156      * @param chart the chart (<code>null</code> not permitted).
157      * @param width the image width.
158      * @param height the image height.
159      * @param info the chart rendering info (<code>null</code> permitted).
160      *
161      * @throws IOException if there are any I/O errors.
162      */

163     public static void writeChartAsPNG(OutputStream JavaDoc out,
164                                        JFreeChart chart,
165                                        int width,
166                                        int height,
167                                        ChartRenderingInfo info)
168         throws IOException JavaDoc {
169
170         if (chart == null) {
171             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
172         }
173         BufferedImage JavaDoc bufferedImage
174             = chart.createBufferedImage(width, height, info);
175         EncoderUtil.writeBufferedImage(bufferedImage, ImageFormat.PNG, out);
176     }
177
178     /**
179      * Writes a chart to an output stream in PNG format. This method allows
180      * you to pass in a {@link ChartRenderingInfo} object, to collect
181      * information about the chart dimensions/entities. You will need this
182      * info if you want to create an HTML image map.
183      *
184      * @param out the output stream (<code>null</code> not permitted).
185      * @param chart the chart (<code>null</code> not permitted).
186      * @param width the image width.
187      * @param height the image height.
188      * @param info carries back chart rendering info (<code>null</code>
189      * permitted).
190      * @param encodeAlpha encode alpha?
191      * @param compression the PNG compression level (0-9).
192      *
193      * @throws IOException if there are any I/O errors.
194      */

195     public static void writeChartAsPNG(OutputStream JavaDoc out,
196                                        JFreeChart chart,
197                                        int width, int height,
198                                        ChartRenderingInfo info,
199                                        boolean encodeAlpha,
200                                        int compression) throws IOException JavaDoc {
201
202         if (out == null) {
203             throw new IllegalArgumentException JavaDoc("Null 'out' argument.");
204         }
205         if (chart == null) {
206             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
207         }
208         BufferedImage JavaDoc chartImage = chart.createBufferedImage(
209             width, height, BufferedImage.TYPE_INT_ARGB, info
210         );
211         ChartUtilities.writeBufferedImageAsPNG(
212             out, chartImage, encodeAlpha, compression
213         );
214
215     }
216
217     /**
218      * Writes a scaled version of a chart to an output stream in PNG format.
219      *
220      * @param out the output stream (<code>null</code> not permitted).
221      * @param chart the chart (<code>null</code> not permitted).
222      * @param width the unscaled chart width.
223      * @param height the unscaled chart height.
224      * @param widthScaleFactor the horizontal scale factor.
225      * @param heightScaleFactor the vertical scale factor.
226      *
227      * @throws IOException if there are any I/O problems.
228      */

229     public static void writeScaledChartAsPNG(OutputStream JavaDoc out,
230                                              JFreeChart chart,
231                                              int width,
232                                              int height,
233                                              int widthScaleFactor,
234                                              int heightScaleFactor)
235         throws IOException JavaDoc {
236
237         if (out == null) {
238             throw new IllegalArgumentException JavaDoc("Null 'out' argument.");
239         }
240         if (chart == null) {
241             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
242         }
243
244         double desiredWidth = width * widthScaleFactor;
245         double desiredHeight = height * heightScaleFactor;
246         double defaultWidth = width;
247         double defaultHeight = height;
248         boolean scale = false;
249
250         // get desired width and height from somewhere then...
251
if ((widthScaleFactor != 1) || (heightScaleFactor != 1)) {
252             scale = true;
253         }
254
255         double scaleX = desiredWidth / defaultWidth;
256         double scaleY = desiredHeight / defaultHeight;
257
258         BufferedImage JavaDoc image = new BufferedImage JavaDoc(
259             (int) desiredWidth, (int) desiredHeight, BufferedImage.TYPE_INT_ARGB
260         );
261         Graphics2D JavaDoc g2 = image.createGraphics();
262
263         if (scale) {
264             AffineTransform JavaDoc saved = g2.getTransform();
265             g2.transform(AffineTransform.getScaleInstance(scaleX, scaleY));
266             chart.draw(
267                 g2, new Rectangle2D.Double JavaDoc(0, 0, defaultWidth, defaultHeight),
268                 null, null
269             );
270             g2.setTransform(saved);
271             g2.dispose();
272         }
273         else {
274             chart.draw(
275                 g2, new Rectangle2D.Double JavaDoc(0, 0, defaultWidth, defaultHeight),
276                 null, null
277             );
278         }
279         out.write(encodeAsPNG(image));
280
281     }
282
283     /**
284      * Saves a chart to the specified file in PNG format.
285      *
286      * @param file the file name (<code>null</code> not permitted).
287      * @param chart the chart (<code>null</code> not permitted).
288      * @param width the image width.
289      * @param height the image height.
290      *
291      * @throws IOException if there are any I/O errors.
292      */

293     public static void saveChartAsPNG(File JavaDoc file,
294                                       JFreeChart chart,
295                                       int width,
296                                       int height) throws IOException JavaDoc {
297
298         // defer argument checking...
299
saveChartAsPNG(file, chart, width, height, null);
300
301     }
302
303     /**
304      * Saves a chart to a file in PNG format. This method allows you to pass
305      * in a {@link ChartRenderingInfo} object, to collect information about the
306      * chart dimensions/entities. You will need this info if you want to
307      * create an HTML image map.
308      *
309      * @param file the file (<code>null</code> not permitted).
310      * @param chart the chart (<code>null</code> not permitted).
311      * @param width the image width.
312      * @param height the image height.
313      * @param info the chart rendering info (<code>null</code> permitted).
314      *
315      * @throws IOException if there are any I/O errors.
316      */

317     public static void saveChartAsPNG(File JavaDoc file,
318                                       JFreeChart chart,
319                                       int width,
320                                       int height,
321                                       ChartRenderingInfo info)
322         throws IOException JavaDoc {
323
324         if (file == null) {
325             throw new IllegalArgumentException JavaDoc("Null 'file' argument.");
326         }
327         OutputStream JavaDoc out = new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(file));
328         ChartUtilities.writeChartAsPNG(out, chart, width, height, info);
329         out.close();
330     }
331
332     /**
333      * Saves a chart to a file in PNG format. This method allows you to pass
334      * in a {@link ChartRenderingInfo} object, to collect information about the
335      * chart dimensions/entities. You will need this info if you want to
336      * create an HTML image map.
337      *
338      * @param file the file (<code>null</code> not permitted).
339      * @param chart the chart (<code>null</code> not permitted).
340      * @param width the image width.
341      * @param height the image height.
342      * @param info the chart rendering info (<code>null</code> permitted).
343      * @param encodeAlpha encode alpha?
344      * @param compression the PNG compression level (0-9).
345      *
346      * @throws IOException if there are any I/O errors.
347      */

348     public static void saveChartAsPNG(File JavaDoc file,
349                                       JFreeChart chart,
350                                       int width,
351                                       int height,
352                                       ChartRenderingInfo info,
353                                       boolean encodeAlpha,
354                                       int compression) throws IOException JavaDoc {
355
356         if (file == null) {
357             throw new IllegalArgumentException JavaDoc("Null 'file' argument.");
358         }
359         if (chart == null) {
360             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
361         }
362
363         OutputStream JavaDoc out = new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(file));
364         writeChartAsPNG(
365             out, chart, width, height, info, encodeAlpha, compression
366         );
367         out.close();
368
369     }
370
371     /**
372      * Writes a chart to an output stream in JPEG format. Please note that
373      * JPEG is a poor format for chart images, use PNG if possible.
374      *
375      * @param out the output stream (<code>null</code> not permitted).
376      * @param chart the chart (<code>null</code> not permitted).
377      * @param width the image width.
378      * @param height the image height.
379      *
380      * @throws IOException if there are any I/O errors.
381      */

382     public static void writeChartAsJPEG(OutputStream JavaDoc out,
383                                         JFreeChart chart,
384                                         int width,
385                                         int height) throws IOException JavaDoc {
386
387         // defer argument checking...
388
writeChartAsJPEG(out, chart, width, height, null);
389
390     }
391
392     /**
393      * Writes a chart to an output stream in JPEG format. Please note that
394      * JPEG is a poor format for chart images, use PNG if possible.
395      *
396      * @param out the output stream (<code>null</code> not permitted).
397      * @param quality the quality setting.
398      * @param chart the chart (<code>null</code> not permitted).
399      * @param width the image width.
400      * @param height the image height.
401      *
402      * @throws IOException if there are any I/O errors.
403      */

404     public static void writeChartAsJPEG(OutputStream JavaDoc out,
405                                         float quality,
406                                         JFreeChart chart,
407                                         int width,
408                                         int height) throws IOException JavaDoc {
409
410         // defer argument checking...
411
ChartUtilities.writeChartAsJPEG(
412             out, quality, chart, width, height, null
413         );
414
415     }
416
417     /**
418      * Writes a chart to an output stream in JPEG format. This method allows
419      * you to pass in a {@link ChartRenderingInfo} object, to collect
420      * information about the chart dimensions/entities. You will need this
421      * info if you want to create an HTML image map.
422      *
423      * @param out the output stream (<code>null</code> not permitted).
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 JavaDoc out,
432                                         JFreeChart chart,
433                                         int width,
434                                         int height,
435                                         ChartRenderingInfo info)
436         throws IOException JavaDoc {
437
438         if (chart == null) {
439             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
440         }
441         BufferedImage JavaDoc image = chart.createBufferedImage(width, height, info);
442         EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out);
443
444     }
445
446     /**
447      * Writes a chart to an output stream in JPEG format. This method allows
448      * you to pass in a {@link ChartRenderingInfo} object, to collect
449      * information about the chart dimensions/entities. You will need this
450      * info if you want to create an HTML image map.
451      *
452      * @param out the output stream (<code>null</code> not permitted).
453      * @param quality the output quality (0.0f to 1.0f).
454      * @param chart the chart (<code>null</code> not permitted).
455      * @param width the image width.
456      * @param height the image height.
457      * @param info the chart rendering info (<code>null</code> permitted).
458      *
459      * @throws IOException if there are any I/O errors.
460      */

461     public static void writeChartAsJPEG(OutputStream JavaDoc out,
462                                         float quality,
463                                         JFreeChart chart,
464                                         int width,
465                                         int height,
466                                         ChartRenderingInfo info)
467         throws IOException JavaDoc {
468
469         if (chart == null) {
470             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
471         }
472         BufferedImage JavaDoc image = chart.createBufferedImage(width, height, info);
473         EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, quality);
474
475     }
476
477     /**
478      * Saves a chart to a file in JPEG format.
479      *
480      * @param file the file (<code>null</code> not permitted).
481      * @param chart the chart (<code>null</code> not permitted).
482      * @param width the image width.
483      * @param height the image height.
484      *
485      * @throws IOException if there are any I/O errors.
486      */

487     public static void saveChartAsJPEG(File JavaDoc file,
488                                        JFreeChart chart,
489                                        int width,
490                                        int height) throws IOException JavaDoc {
491
492         // defer argument checking...
493
saveChartAsJPEG(file, chart, width, height, null);
494
495     }
496
497     /**
498      * Saves a chart to a file in JPEG format.
499      *
500      * @param file the file (<code>null</code> not permitted).
501      * @param quality the JPEG quality setting.
502      * @param chart the chart (<code>null</code> not permitted).
503      * @param width the image width.
504      * @param height the image height.
505      *
506      * @throws IOException if there are any I/O errors.
507      */

508     public static void saveChartAsJPEG(File JavaDoc file,
509                                        float quality,
510                                        JFreeChart chart,
511                                        int width,
512                                        int height) throws IOException JavaDoc {
513
514         // defer argument checking...
515
saveChartAsJPEG(file, quality, chart, width, height, null);
516
517     }
518
519     /**
520      * Saves a chart to a file in JPEG format. This method allows you to pass
521      * in a {@link ChartRenderingInfo} object, to collect information about the
522      * chart dimensions/entities. You will need this info if you want to
523      * create an HTML image map.
524      *
525      * @param file the file name (<code>null</code> not permitted).
526      * @param chart the chart (<code>null</code> not permitted).
527      * @param width the image width.
528      * @param height the image height.
529      * @param info the chart rendering info (<code>null</code> permitted).
530      *
531      * @throws IOException if there are any I/O errors.
532      */

533     public static void saveChartAsJPEG(File JavaDoc file,
534                                        JFreeChart chart,
535                                        int width,
536                                        int height,
537                                        ChartRenderingInfo info)
538         throws IOException JavaDoc {
539
540         if (file == null) {
541             throw new IllegalArgumentException JavaDoc("Null 'file' argument.");
542         }
543         if (chart == null) {
544             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
545         }
546         OutputStream JavaDoc out = new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(file));
547         writeChartAsJPEG(out, chart, width, height, info);
548         out.close();
549
550     }
551
552     /**
553      * Saves a chart to a file in JPEG format. This method allows you to pass
554      * in a {@link ChartRenderingInfo} object, to collect information about the
555      * chart dimensions/entities. You will need this info if you want to
556      * create an HTML image map.
557      *
558      * @param file the file name (<code>null</code> not permitted).
559      * @param quality the quality setting.
560      * @param chart the chart (<code>null</code> not permitted).
561      * @param width the image width.
562      * @param height the image height.
563      * @param info the chart rendering info (<code>null</code> permitted).
564      *
565      * @throws IOException if there are any I/O errors.
566      */

567     public static void saveChartAsJPEG(File JavaDoc file,
568                                        float quality,
569                                        JFreeChart chart,
570                                        int width,
571                                        int height,
572                                        ChartRenderingInfo info)
573         throws IOException JavaDoc {
574
575         if (file == null) {
576             throw new IllegalArgumentException JavaDoc("Null 'file' argument.");
577         }
578         if (chart == null) {
579             throw new IllegalArgumentException JavaDoc("Null 'chart' argument.");
580         }
581         OutputStream JavaDoc out = new BufferedOutputStream JavaDoc(new FileOutputStream JavaDoc(file));
582         writeChartAsJPEG(out, quality, chart, width, height, info);
583         out.close();
584
585     }
586
587     /**
588      * Writes a {@link BufferedImage} to an output stream in JPEG format.
589      *
590      * @param out the output stream (<code>null</code> not permitted).
591      * @param image the image (<code>null</code> not permitted).
592      *
593      * @throws IOException if there are any I/O errors.
594      */

595     public static void writeBufferedImageAsJPEG(OutputStream JavaDoc out,
596                                                 BufferedImage JavaDoc image)
597         throws IOException JavaDoc {
598
599         // defer argument checking...
600
writeBufferedImageAsJPEG(out, 0.75f, image);
601
602     }
603
604     /**
605      * Writes a {@link BufferedImage} to an output stream in JPEG format.
606      *
607      * @param out the output stream (<code>null</code> not permitted).
608      * @param quality the image quality (0.0f to 1.0f).
609      * @param image the image (<code>null</code> not permitted).
610      *
611      * @throws IOException if there are any I/O errors.
612      */

613     public static void writeBufferedImageAsJPEG(OutputStream JavaDoc out, float quality,
614                                                 BufferedImage JavaDoc image)
615         throws IOException JavaDoc {
616
617         EncoderUtil.writeBufferedImage(image, ImageFormat.JPEG, out, quality);
618
619     }
620
621     /**
622      * Writes a {@link BufferedImage} to an output stream in PNG format.
623      *
624      * @param out the output stream (<code>null</code> not permitted).
625      * @param image the image (<code>null</code> not permitted).
626      *
627      * @throws IOException if there are any I/O errors.
628      */

629     public static void writeBufferedImageAsPNG(OutputStream JavaDoc out,
630                                                BufferedImage JavaDoc image)
631         throws IOException JavaDoc {
632
633         EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, out);
634
635     }
636
637     /**
638      * Writes a {@link BufferedImage} to an output stream in PNG format.
639      *
640      * @param out the output stream (<code>null</code> not permitted).
641      * @param image the image (<code>null</code> not permitted).
642      * @param encodeAlpha encode alpha?
643      * @param compression the compression level (0-9).
644      *
645      * @throws IOException if there are any I/O errors.
646      */

647     public static void writeBufferedImageAsPNG(OutputStream JavaDoc out,
648                                                BufferedImage JavaDoc image,
649                                                boolean encodeAlpha,
650                                                int compression)
651         throws IOException JavaDoc {
652
653         EncoderUtil.writeBufferedImage(
654             image, ImageFormat.PNG, out, compression, encodeAlpha
655         );
656     }
657
658     /**
659      * Encodes a {@link BufferedImage} to PNG format.
660      *
661      * @param image the image (<code>null</code> not permitted).
662      *
663      * @return A byte array in PNG format.
664      *
665      * @throws IOException if there is an I/O problem.
666      */

667     public static byte[] encodeAsPNG(BufferedImage JavaDoc image) throws IOException JavaDoc {
668         return EncoderUtil.encode(image, ImageFormat.PNG);
669     }
670
671     /**
672      * Encodes a {@link BufferedImage} to PNG format.
673      *
674      * @param image the image (<code>null</code> not permitted).
675      * @param encodeAlpha encode alpha?
676      * @param compression the PNG compression level (0-9).
677      *
678      * @return The byte array in PNG format.
679      *
680      * @throws IOException if there is an I/O problem.
681      */

682     public static byte[] encodeAsPNG(BufferedImage JavaDoc image, boolean encodeAlpha,
683                                      int compression)
684         throws IOException JavaDoc {
685         return EncoderUtil.encode(
686             image, ImageFormat.PNG, compression, encodeAlpha
687         );
688     }
689
690     /**
691      * Writes an image map to an output stream.
692      *
693      * @param writer the writer (<code>null</code> not permitted).
694      * @param name the map name (<code>null</code> not permitted).
695      * @param info the chart rendering info (<code>null</code> not permitted).
696      * @param useOverLibForToolTips whether to use OverLIB for tooltips
697      * (http://www.bosrup.com/web/overlib/).
698      *
699      * @throws IOException if there are any I/O errors.
700      */

701     public static void writeImageMap(PrintWriter JavaDoc writer,
702                                      String JavaDoc name,
703                                      ChartRenderingInfo info,
704                                      boolean useOverLibForToolTips)
705         throws IOException JavaDoc {
706
707         ToolTipTagFragmentGenerator toolTipTagFragmentGenerator = null;
708         if (useOverLibForToolTips) {
709             toolTipTagFragmentGenerator
710                 = new OverLIBToolTipTagFragmentGenerator();
711         }
712         else {
713             toolTipTagFragmentGenerator
714                 = new StandardToolTipTagFragmentGenerator();
715         }
716         ImageMapUtilities.writeImageMap(
717             writer, name, info, toolTipTagFragmentGenerator,
718             new StandardURLTagFragmentGenerator()
719         );
720
721     }
722
723     /**
724      * Writes an image map to an output stream.
725      *
726      * @param writer the writer (<code>null</code> not permitted).
727      * @param name the map name (<code>null</code> not permitted).
728      * @param info the chart rendering info (<code>null</code> not permitted).
729      * @param toolTipTagFragmentGenerator the tool tip generator.
730      * @param urlTagFragmentGenerator the url generator.
731      *
732      * @throws IOException if there are any I/O errors.
733      */

734     public static void writeImageMap(PrintWriter JavaDoc writer, String JavaDoc name,
735             ChartRenderingInfo info,
736             ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
737             URLTagFragmentGenerator urlTagFragmentGenerator)
738             throws IOException JavaDoc {
739
740         writer.println(
741             ImageMapUtilities.getImageMap(
742                 name, info, toolTipTagFragmentGenerator, urlTagFragmentGenerator
743             )
744         );
745     }
746
747     /**
748      * Creates an HTML image map.
749      *
750      * @param name the map name (<code>null</code> not permitted).
751      * @param info the chart rendering info (<code>null</code> not permitted).
752      *
753      * @return The map tag.
754      */

755     public static String JavaDoc getImageMap(String JavaDoc name, ChartRenderingInfo info) {
756         return ImageMapUtilities.getImageMap(
757             name,
758             info,
759             new StandardToolTipTagFragmentGenerator(),
760             new StandardURLTagFragmentGenerator()
761         );
762     }
763
764     /**
765      * Creates an HTML image map.
766      *
767      * @param name the map name (<code>null</code> not permitted).
768      * @param info the chart rendering info (<code>null</code> not permitted).
769      * @param toolTipTagFragmentGenerator the tool tip generator.
770      * @param urlTagFragmentGenerator the url generator.
771      *
772      * @return The map tag.
773      */

774     public static String JavaDoc getImageMap(String JavaDoc name,
775                      ChartRenderingInfo info,
776                      ToolTipTagFragmentGenerator toolTipTagFragmentGenerator,
777                      URLTagFragmentGenerator urlTagFragmentGenerator) {
778
779         return ImageMapUtilities.getImageMap(
780             name, info, toolTipTagFragmentGenerator, urlTagFragmentGenerator
781         );
782         
783     }
784
785 }
786
Popular Tags