## com.bbn.openmap.image
Class AbstractImageFormatter

    java.lang.Object
      com.bbn.openmap.image.AbstractImageFormatter

All Implemented Interfaces:
  java.util.EventListener, ImageFormatter, java.beans.PropertyChangeListener, PropertyConsumer

Direct Known Subclasses:
  AcmeGifFormatter, ImageIOFormatter, PPMFormatter, SunJPEGFormatter

public abstract class AbstractImageFormatter
extends java.lang.Object
implements ImageFormatter, PropertyConsumer, java.beans.PropertyChangeListener

The abstract implementation of the ImageFormatter. The ImageFormatter deals with most of the image meanderings of Java, while letting you create an image in a specific format. The ImageFormatter's responsibility has grown slightly, since it now contains the BufferedImage that it will be formatting. Thisis to make things go smoother for different uses of the formatter - some image formats, for instance, really need to utilize a special implementation of a Graphics in order to create the data file they want. The new definition allows for that. Generally, however, you'll want to either hand the MapBean to the formatter to get the image bytes, or, as in the case of the ImageServer, get a Graphics from the formatter, paint the map into it, then retrieve the image bytes after that.

Field Summary
`protected java.awt.image.BufferedImage` `bufferedImage`
`protected Layer[]` `layers` Used when the layers from the MapBean are needed, in order to use the renderDataForProjection method.
`protected java.lang.String` `propertiesPrefix`

Fields inherited from interface com.bbn.openmap.PropertyConsumer
`EditorProperty, initPropertiesProperty, LabelEditorProperty, ScopedEditorProperty`

Constructor Summary
`AbstractImageFormatter()`

Method Summary
`abstract byte[]` `formatImage(java.awt.image.BufferedImage bi)` Convert a BufferedImage to a image file format...
`java.awt.image.BufferedImage` `getBufferedImage()` Return the BufferedImage contained within the formatter.
`java.awt.Graphics` `getGraphics(int width, int height)` Return the applicable Graphics to use to paint the layers into.
`java.awt.Graphics` `getGraphics(int width, int height, int imageType)` Return the applicable Graphics to use to paint the layers into.
`byte[]` `getImageBytes()` Return the image bytes of the formatted image.
`byte[]` `getImageFromMapBean(MapBean map)` Take a MapBean, and get the image bytes that represent the current state.
`byte[]` `getImageFromMapBean(MapBean map, int width, int height)` Take a MapBean, and get the image bytes that represent the current state.
`byte[]` `getImageFromMapBean(MapBean map, int width, int height, boolean scaleImage)` Take a MapBean, and get the image bytes that represent the current state.
`java.util.Properties` `getProperties(java.util.Properties props)` Part of the PropertyConsumer interface.
`java.util.Properties` `getPropertyInfo(java.util.Properties list)` Part of the PropertyConsumer interface.
`java.lang.String` `getPropertyPrefix()` Part of the PropertyConsumer interface.
`java.awt.image.BufferedImage` `getScaledBufferedImage(int scaledWidth, int scaledHeight)` Scale the internal BufferedImage to the pixel dimensions, and then return it.
`byte[]` `getScaledImageBytes(int scaledWidth, int scaledHeight)` Scale the internal BufferedImage, then return the image bytes of the formatted image.
`abstract ImageFormatter` `makeClone()` Create a new instance of the same type of formatter.
`void` `propertyChange(java.beans.PropertyChangeEvent pce)` Used when the layers from the MapBean are needed, in order to use the renderDataForProjection method.
`void` `setBufferedImage(java.awt.image.BufferedImage bi)` Return the BufferedImage contained within the formatter.
`void` `setProperties(java.util.Properties props)` Set the layers and image type in the properties.
`void` `setProperties(java.lang.String prefix, java.util.Properties props)` Set the properties of the image formatter.
`void` `setPropertyPrefix(java.lang.String prefix)` Part of the PropertyConsumer interface.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Methods inherited from interface com.bbn.openmap.image.ImageFormatter
`getContentType, getFormatLabel`

Field Detail

### bufferedImage

    protected java.awt.image.BufferedImage bufferedImage

### propertiesPrefix

    protected java.lang.String propertiesPrefix

### layers

    protected Layer[] layers

  Used when the layers from the MapBean are needed, in order to use the renderDataForProjection method.

Constructor Detail

### AbstractImageFormatter

    public AbstractImageFormatter()

Method Detail

### setProperties

    public void setProperties(java.lang.String prefix,
                              java.util.Properties props)

  Set the properties of the image formatter.

  Specified by:
    `setProperties` in interface `ImageFormatter`

### formatImage

    public abstract byte[] formatImage(java.awt.image.BufferedImage bi)

  Convert a BufferedImage to a image file format...

  Specified by:
    `formatImage` in interface `ImageFormatter`
  Parameters:
    `bi` - a BufferedImage..

### makeClone

    public abstract ImageFormatter makeClone()

  Create a new instance of the same type of formatter. If you are running in a multi-threaded environment, you'll need to provide a new instance of the formatter to each thread, since the image and graphics that are being drawn into for each thread are contained within.

  Specified by:
    `makeClone` in interface `ImageFormatter`
  Returns:
    a new instance of this type of formatter, with the same properties set.

### getImageFromMapBean

    public byte[] getImageFromMapBean(MapBean map)

  Take a MapBean, and get the image bytes that represent the current state.

  Specified by:
    `getImageFromMapBean` in interface `ImageFormatter`
  Parameters:
    `map` - the MapBean.
  Returns:
    byte[] representing an image of the map in it's current state.

### getImageFromMapBean

    public byte[] getImageFromMapBean(MapBean map,
                                      int width,
                                      int height)

  Take a MapBean, and get the image bytes that represent the current state.

  Parameters:
    `map` - the MapBean.
    `width` - the pixel width of the desired image.
    `height` - the pixel height of the desired image.
  Returns:
    byte[] representing an image of the map in it's current state.

### getImageFromMapBean

    public byte[] getImageFromMapBean(MapBean map,
                                      int width,
                                      int height,
                                      boolean scaleImage)

  Take a MapBean, and get the image bytes that represent the current state.

  Parameters:
    `map` - the MapBean.
    `width` - the pixel width of the desired image.
    `height` - the pixel height of the desired image.
    `scaleImage` - true to resize image based on scale
  Returns:
    byte[] representing an image of the map in it's current state.

### getGraphics

    public java.awt.Graphics getGraphics(int width,
                                         int height)

  Return the applicable Graphics to use to paint the layers into. If the internal BufferedImage hasn't been created yet, or has been set to null, then a new buffered Image is created, set to the size specified by the height and width. The ImageGenerator extends MapBean. Remember to dispose of the graphics object when you are done with it. Uses the default BufferedImage.TYPE_INT_RGB colormodel.

  Specified by:
    `getGraphics` in interface `ImageFormatter`
  Parameters:
    `width` - pixel width of Graphics.
    `height` - pixel height of Graphics.
  Returns:
    Graphics object to use.
  See Also:
    `BufferedImage`

### getGraphics

    public java.awt.Graphics getGraphics(int width,
                                         int height,
                                         int imageType)

  Return the applicable Graphics to use to paint the layers into. If the internal BufferedImage hasn't been created yet, or has been set to null, then a new buffered Image is created, set to the size specified by the height and width. The ImageGenerator extends MapBean. Remember to dispose of the graphics object when you are done with it. Lets you select the image type.

  Parameters:
    `width` - pixel width of Graphics.
    `height` - pixel height of Graphics.
    `imageType` - image type - see BufferedImage
  Returns:
    java.awt.Graphics object to use.
  See Also:
    `BufferedImage`

### getBufferedImage

    public java.awt.image.BufferedImage getBufferedImage()

  Return the BufferedImage contained within the formatter.

  Specified by:
    `getBufferedImage` in interface `ImageFormatter`
  Returns:
    the BufferedImage.

### setBufferedImage

    public void setBufferedImage(java.awt.image.BufferedImage bi)

  Return the BufferedImage contained within the formatter.

  Specified by:
    `setBufferedImage` in interface `ImageFormatter`
  Parameters:
    `bi` - the BufferedImage to use in this formatter.

### getScaledBufferedImage

    public java.awt.image.BufferedImage getScaledBufferedImage(int scaledWidth,
                                                               int scaledHeight)

  Scale the internal BufferedImage to the pixel dimensions, and then return it.

  Specified by:
    `getScaledBufferedImage` in interface `ImageFormatter`
  Parameters:
    `scaledWidth` - the desired pixel width of the image.
    `scaledHeight` - the desired pixel height of the image.
  Returns:
    the scaled BufferedImage.

### getImageBytes

    public byte[] getImageBytes()

  Return the image bytes of the formatted image.

  Specified by:
    `getImageBytes` in interface `ImageFormatter`
  Returns:
    byte[] representing the image.

### getScaledImageBytes

    public byte[] getScaledImageBytes(int scaledWidth,
                                      int scaledHeight)

  Scale the internal BufferedImage, then return the image bytes of the formatted image.

  Specified by:
    `getScaledImageBytes` in interface `ImageFormatter`
  Parameters:
    `scaledWidth` - the desired pixel width of the image.
    `scaledHeight` - the desired pixel height of the image.
  Returns:
    byte[] representing the image.

### setProperties

    public void setProperties(java.util.Properties props)

  Set the layers and image type in the properties.

  Specified by:
    `setProperties` in interface `PropertyConsumer`
  Parameters:
    `props` - a properties object that the PropertyConsumer can use to retrieve expected properties it can use for configuration.

### getProperties

    public java.util.Properties getProperties(java.util.Properties props)

  Part of the PropertyConsumer interface. Doesn't do anything yet.

  Specified by:
    `getProperties` in interface `PropertyConsumer`
  Parameters:
    `props` - a Properties object to load the PropertyConsumer properties into. If getList equals null, then a new Properties object should be created.
  Returns:
    Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

### getPropertyInfo

    public java.util.Properties getPropertyInfo(java.util.Properties list)

  Part of the PropertyConsumer interface.

  Specified by:
    `getPropertyInfo` in interface `PropertyConsumer`
  Parameters:
    `list` - a Properties object to load the PropertyConsumer properties into. If getList equals null, then a new Properties object should be created.
  Returns:
    Properties object containing PropertyConsumer property values. If getList was not null, this should equal getList. Otherwise, it should be the Properties object created by the PropertyConsumer.

### setPropertyPrefix

    public void setPropertyPrefix(java.lang.String prefix)

  Part of the PropertyConsumer interface. Set the Properties prefix to use to scope the relevant properties passed into the setProperties method.

  Specified by:
    `setPropertyPrefix` in interface `PropertyConsumer`
  Parameters:
    `prefix` - the prefix String.

### getPropertyPrefix

    public java.lang.String getPropertyPrefix()

  Part of the PropertyConsumer interface. Get the Properties prefix used to scope the relevant properties passed into the setProperties method.

  Specified by:
    `getPropertyPrefix` in interface `PropertyConsumer`
  Returns:
    the prefix string

### propertyChange

    public void propertyChange(java.beans.PropertyChangeEvent pce)

  Used when the layers from the MapBean are needed, in order to use the renderDataForProjection method. Sets the Layer[] by adding the formatter as a PropertyChangeListener to the MapBean. Remember to remove the formatter from the MapBean as a PropertyChangeListener.

  Specified by:
    `propertyChange` in interface `java.beans.PropertyChangeListener`

Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details