public abstract class AbstractIconRetriever extends java.lang.Object implements IconRetriever
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");
}
}
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;
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.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
retrieverPath
Path in the file system or network to the symbol repository.
|
Constructor and Description |
---|
AbstractIconRetriever(java.lang.String retrieverPath)
Create a new retriever that will retrieve icons from the specified location.
|
Modifier and Type | Method and Description |
---|---|
protected java.awt.image.BufferedImage |
drawImage(java.awt.image.BufferedImage src,
java.awt.image.BufferedImage dest)
Draw one image into another image.
|
boolean |
equals(java.lang.Object o)
Indicates whether or not this retriever is equal to another.
|
java.lang.String |
getRetrieverPath()
Indicates the file system or network path of the symbol directory..
|
int |
hashCode() |
protected void |
multiply(java.awt.image.BufferedImage image,
java.awt.Color color)
Multiply each pixel in an image by a color.
|
protected java.awt.image.BufferedImage |
readImage(java.lang.String path)
Load an image from a local or remote path.
|
protected void |
replaceColor(java.awt.image.BufferedImage image,
java.awt.Color color)
Replace the color of each pixel in an image.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
createIcon
protected java.lang.String retrieverPath
public AbstractIconRetriever(java.lang.String retrieverPath)
retrieverPath
- URL to to the base symbol directory on the local file system or the network.protected java.awt.image.BufferedImage drawImage(java.awt.image.BufferedImage src, java.awt.image.BufferedImage dest)
src
- Image to draw.dest
- Image to draw into.dest
BufferedImage.public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- Object to compare.true
if o
is an instance of AbstractIconRetriever and has the same retrieval path as this
retriever.public java.lang.String getRetrieverPath()
public int hashCode()
hashCode
in class java.lang.Object
protected void multiply(java.awt.image.BufferedImage image, java.awt.Color color)
image
- Image to operate on.color
- Color to multiply by.replaceColor(java.awt.image.BufferedImage, java.awt.Color)
protected java.awt.image.BufferedImage readImage(java.lang.String path)
path
- Path to the icon resource, relative to this retriever's retrieval path.protected void replaceColor(java.awt.image.BufferedImage image, java.awt.Color color)
multiply
, this method changes the color of all pixels.image
- Image to operate on.color
- Color to apply to to each pixel.multiply(java.awt.image.BufferedImage, java.awt.Color)