NASA World Wind

gov.nasa.worldwind.symbology
Class AbstractIconRetriever

java.lang.Object
  extended by gov.nasa.worldwind.symbology.AbstractIconRetriever
All Implemented Interfaces:
IconRetriever
Direct Known Subclasses:
MilStd1477IconRetriever, MilStd2525IconRetriever, MilStd2525ModifierRetriever, MilStd2525PointGraphicRetriever

public abstract class AbstractIconRetriever
extends Object
implements IconRetriever

Base class for icon retrievers. This class provides methods for loading and manipulating icons.

Icon retrieval

Each symbol in a symbology set must have a unique identifier. The IconRetriever's job is to create a BufferedImage to represent a symbol given the symbol identifier. Usually this means retrieving an image from the file system or the network, and optionally manipulating the symbol (for example, changing the color to represent a hostile or friendly entity).

Each instance of AbstractIconRetriever is configured with a retrieval path which specifies the location of a symbol repository on the file system or the network. readImage retrieves images relative to this base path. The retrieval path may be a file URL to a directory on the local file system (for example, file:///symbols/mil-std-2525). A URL to a network resource (http://myserver.com/milstd2525/), or a URL to a JAR or ZIP file (jar:file:milstd2525-symbols.zip!).

A simple icon retriever might use a symbol repository that is a simple directory of PNG files, where each file name matches a symbol identifier. Such an icon retriever could be implemented like this:

 class SimpleIconRetriever extends AbstractIconRetriever
 {
     public BufferedImage createIcon(String symbolId)
     {
         // Retrieves retrievalPath/symbolId.png
         return this.readImage(symbolId + ".png");
     }
 }
 

Composite icons

Complicated symbols may be made up of several different graphical elements. drawImage helps build a complex symbol from simple pieces. For example, if a symbol is composed of a frame and an icon, the icon retriever could load the frame and icon independently, draw the icon over the frame, and return the composite image:

 // Load the frame and icon as separate pieces.
 BufferedImage frame = this.readImage("path/to/frame.png");
 BufferedImage icon = this.readImage("path/to/icon.png");

 // Draw the icon on top of the frame. This call modifies the frame image.
 BufferedImage fullImage = this.drawImage(icon, frame);

 // Return the composite image.
 return fullImage;
 

Changing the color of an icon

multiply can change the color of an image by multiplying each pixel in the image by a color. The multiplication color will replace any white pixels and black pixels will be unaffected. For example, a symbol set in which hostile symbols are drawn in red and friendly symbols are drawn in green could be implemented by creating white icons, and then multiplying by either red or green when the retriever constructs the icon.


Field Summary
protected  String retrieverPath
          Path in the file system or network to the symbol repository.
 
Constructor Summary
AbstractIconRetriever(String retrieverPath)
          Create a new retriever that will retrieve icons from the specified location.
 
Method Summary
protected  BufferedImage drawImage(BufferedImage src, BufferedImage dest)
          Draw one image into another image.
 boolean equals(Object o)
          Indicates whether or not this retriever is equal to another.
 String getRetrieverPath()
          Indicates the file system or network path of the symbol directory..
 int hashCode()
          
protected  void multiply(BufferedImage image, Color color)
          Multiply each pixel in an image by a color.
protected  BufferedImage readImage(String path)
          Load an image from a local or remote path.
protected  void replaceColor(BufferedImage image, Color color)
          Replace the color of each pixel in an image.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.nasa.worldwind.symbology.IconRetriever
createIcon
 

Field Detail

retrieverPath

protected String retrieverPath
Path in the file system or network to the symbol repository.

Constructor Detail

AbstractIconRetriever

public AbstractIconRetriever(String retrieverPath)
Create a new retriever that will retrieve icons from the specified location. The retrieval path may be a file URL to a directory on the local file system (for example, file:///symbols/mil-std-2525). A URL to a network resource (http://myserver.com/milstd2525/), or a URL to a JAR or ZIP file (jar:file:milstd2525-symbols.zip!).

Parameters:
retrieverPath - URL to to the base symbol directory on the local file system or the network.
Method Detail

drawImage

protected BufferedImage drawImage(BufferedImage src,
                                  BufferedImage dest)
Draw one image into another image. The image is drawn at location (0, 0).

Parameters:
src - Image to draw.
dest - Image to draw into.
Returns:
dest BufferedImage.

equals

public boolean equals(Object o)
Indicates whether or not this retriever is equal to another.

Overrides:
equals in class Object
Parameters:
o - Object to compare.
Returns:
true if o is an instance of AbstractIconRetriever and has the same retrieval path as this retriever.

getRetrieverPath

public String getRetrieverPath()
Indicates the file system or network path of the symbol directory.. The retrieval path may be a file URL to a directory on the local file system (for example, file:///symbols/mil-std-2525). A URL to a network resource ( http://myserver.com/milstd2525/), or a URL to a JAR or ZIP file (jar:file:milstd2525-symbols.zip!).

Returns:
File system or network path to symbol repository.

hashCode

public int hashCode()

Overrides:
hashCode in class Object

multiply

protected void multiply(BufferedImage image,
                        Color color)
Multiply each pixel in an image by a color. White pixels are replaced by the multiplication color, black pixels are unaffected.

Parameters:
image - Image to operate on.
color - Color to multiply by.
See Also:
replaceColor(java.awt.image.BufferedImage, java.awt.Color)

readImage

protected BufferedImage readImage(String path)
Load an image from a local or remote path. The image path is interpreted relative to the retrieval path. For example, if the retrieval path is http://myserver.com/milstd2525/, calling readImage("icon.png") will attempt to retrieve an image from http://myserver.com/milstd2525/icon.png.

Parameters:
path - Path to the icon resource, relative to this retriever's retrieval path.
Returns:
The requested icon as a BufferedImage, or null if the icon cannot be loaded.

replaceColor

protected void replaceColor(BufferedImage image,
                            Color color)
Replace the color of each pixel in an image. This method retains the alpha channel of each pixel, but completely replaces the red, green, and blue components with the replacement color. Unlike multiply, this method changes the color of all pixels.

Parameters:
image - Image to operate on.
color - Color to apply to to each pixel.
See Also:
multiply(java.awt.image.BufferedImage, java.awt.Color)

NASA World Wind