org.vizzini.ui.graphics
Class ImageCreator

java.lang.Object
  extended by org.vizzini.ui.graphics.ImageCreator

public class ImageCreator
extends Object

Provides a class which creates an image file from a JComponent.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Field Summary
static String DEFAULT_FILENAME
          The default image filename.
static float DEFAULT_JPEG_QUALITY
          The default JPEG quality setting.
static int DEFAULT_PNG_COMPRESSION
          The default PNG compression level.
static String JPG
          Encoding type JPEG.
static String PNG
          Encoding type PNG.
 
Constructor Summary
ImageCreator()
          Construct this object.
 
Method Summary
protected  BufferedImage createBufferedImage(JComponent component, int width, int height)
          Creates and returns a buffered image into which this has been drawn.
 String getBaseFilename()
          Return the base filename.
protected  BufferedImage getBufferedImage()
          Return the buffered image.
 JComponent getComponent()
          Return the contained component.
protected  String getDateString()
          Return a formatted date string representing now.
 String getEncodingType()
          Return the encoding type.
 String getFilePrefix()
          Return the file prefix.
 String getImageFilename()
          Return the image filename.
 Date getImageSaveDate()
          Return the last image save date.
 boolean isDateAppended()
          Return true if the date/time should be appended to the filename.
protected  void saveAsJPEG(File file, JComponent component, int width, int height, float quality)
          Saves the chart as a JPEG format image file.
protected  void saveAsPNG(File file, JComponent component, int width, int height, boolean encodeAlpha, int compression)
          Saves the chart as a PNG format image file.
 void saveImage()
          Save the image to a file.
 void setBaseFilename(String baseFilename)
          Set the base filename.
 void setComponent(JComponent component)
          Set the contained component.
 void setDateAppended(boolean dateAppended)
          Set the flag which indicates whether to append the date/time to the filename.
 void setEncodingType(String encodingType)
          Set the encoding type, one of ImageCreator.JPG or ImageCreator.PNG.
 void setFilePrefix(String filePrefix)
          Set the file prefix.
protected  void writeAsJPEG(OutputStream out, float quality, JComponent component, int width, int height)
          Writes the container to the output stream in JPEG format.
protected  void writeAsPNG(OutputStream out, JComponent component, int width, int height, boolean encodeAlpha, int compression)
          Writes the chart to the output stream in PNG format.
protected  void writeBufferedImageAsJPEG(OutputStream out, BufferedImage image, float quality)
          Writes the BufferedImage to the output stream in JPEG format.
protected  void writeBufferedImageAsPNG(OutputStream out, BufferedImage image, boolean encodeAlpha, int compression)
          Writes the BufferedImage to the output stream in PNG format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JPG

public static final String JPG
Encoding type JPEG.

See Also:
Constant Field Values

PNG

public static final String PNG
Encoding type PNG.

See Also:
Constant Field Values

DEFAULT_FILENAME

public static final String DEFAULT_FILENAME
The default image filename.

See Also:
Constant Field Values

DEFAULT_JPEG_QUALITY

public static final float DEFAULT_JPEG_QUALITY
The default JPEG quality setting.

See Also:
Constant Field Values

DEFAULT_PNG_COMPRESSION

public static final int DEFAULT_PNG_COMPRESSION
The default PNG compression level.

See Also:
Constant Field Values
Constructor Detail

ImageCreator

public ImageCreator()
Construct this object.

Since:
v0.3
Method Detail

getBaseFilename

public String getBaseFilename()
Return the base filename.

Since:
v0.3

getComponent

public JComponent getComponent()
Return the contained component.

Since:
v0.3

getEncodingType

public String getEncodingType()
Return the encoding type.

Since:
v0.3

getFilePrefix

public String getFilePrefix()
Return the file prefix.

Since:
v0.3

getImageFilename

public String getImageFilename()
Return the image filename.

Since:
v0.3

getImageSaveDate

public Date getImageSaveDate()
Return the last image save date.

Since:
v0.3

isDateAppended

public boolean isDateAppended()
Return true if the date/time should be appended to the filename.

Since:
v0.3

saveImage

public void saveImage()
               throws IOException
Save the image to a file.

Throws:
IOException
Since:
v0.3

setBaseFilename

public void setBaseFilename(String baseFilename)
Set the base filename.

Since:
v0.3

setComponent

public void setComponent(JComponent component)
Set the contained component.

Since:
v0.3

setDateAppended

public void setDateAppended(boolean dateAppended)
Set the flag which indicates whether to append the date/time to the filename.

Since:
v0.3

setEncodingType

public void setEncodingType(String encodingType)
Set the encoding type, one of ImageCreator.JPG or ImageCreator.PNG.

Since:
v0.3

setFilePrefix

public void setFilePrefix(String filePrefix)
Set the file prefix.

Since:
v0.3

createBufferedImage

protected BufferedImage createBufferedImage(JComponent component,
                                            int width,
                                            int height)
Creates and returns a buffered image into which this has been drawn.

Parameters:
component - Component.
width - Width.
height - Height.
Since:
v0.3

getBufferedImage

protected BufferedImage getBufferedImage()
Return the buffered image.

Since:
v0.3

getDateString

protected String getDateString()
Return a formatted date string representing now.

Since:
v0.3

saveAsJPEG

protected void saveAsJPEG(File file,
                          JComponent component,
                          int width,
                          int height,
                          float quality)
                   throws IOException
Saves the chart as a JPEG format image file.

Parameters:
file - The file name.
component - Component.
width - Image width.
height - Image height.
quality - The quality setting.
Throws:
IOException - if there are any I/O errors.
Since:
v0.3

saveAsPNG

protected void saveAsPNG(File file,
                         JComponent component,
                         int width,
                         int height,
                         boolean encodeAlpha,
                         int compression)
                  throws IOException
Saves the chart as a PNG format image file.

Parameters:
file - Output file.
component - Component whose image to save.
width - Image width.
height - Image height.
encodeAlpha - Flag indicating whether to encode the alpha channel.
compression - PNG compression level.
Throws:
IOException - if there are any I/O errors.
Since:
v0.3

writeAsJPEG

protected void writeAsJPEG(OutputStream out,
                           float quality,
                           JComponent component,
                           int width,
                           int height)
                    throws IOException
Writes the container to the output stream in JPEG format.

Parameters:
out - The output stream.
quality - The output quality (0.0f to 1.0f).
component - Component.
width - Image width.
height - Image height.
Throws:
IOException - if there are any I/O errors.
Since:
v0.3

writeAsPNG

protected void writeAsPNG(OutputStream out,
                          JComponent component,
                          int width,
                          int height,
                          boolean encodeAlpha,
                          int compression)
                   throws IOException
Writes the chart to the output stream in PNG format. This method allows you to pass in a ChartRenderingInfo object, to collect information about the chart dimensions/entities. You will need this info if you want to create an HTML image map.

Parameters:
out - the output stream.
component - Component.
width - the image width.
height - the image height.
encodeAlpha - encode alpha?
compression - the PNG compression level.
Throws:
IOException - if there are any I/O errors.
Since:
v0.3

writeBufferedImageAsJPEG

protected void writeBufferedImageAsJPEG(OutputStream out,
                                        BufferedImage image,
                                        float quality)
                                 throws IOException
Writes the BufferedImage to the output stream in JPEG format.

Parameters:
out - the output stream.
quality - the image quality (0.0f to 1.0f).
image - the buffered image to be written to the OutputStream
Throws:
IOException - if there are any I/O errors.
Since:
v0.3

writeBufferedImageAsPNG

protected void writeBufferedImageAsPNG(OutputStream out,
                                       BufferedImage image,
                                       boolean encodeAlpha,
                                       int compression)
                                throws IOException
Writes the BufferedImage to the output stream in PNG format.

Parameters:
out - The output stream.
image - The buffered image to be written to the OutputStream.
encodeAlpha - Encode alpha?
compression - The compression level.
Throws:
IOException - if there are any I/O errors.
Since:
v0.3


Copyright © 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02