Class AbstractIconRetriever
- java.lang.Object
-
- gov.nasa.worldwind.symbology.AbstractIconRetriever
-
- All Implemented Interfaces:
IconRetriever
- Direct Known Subclasses:
MilStd1477IconRetriever
,MilStd2525IconRetriever
,MilStd2525ModifierRetriever
,MilStd2525PointGraphicRetriever
public abstract class AbstractIconRetriever extends java.lang.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
Fields Modifier and Type Field Description protected java.lang.String
retrieverPath
Path in the file system or network to the symbol repository.
-
Constructor Summary
Constructors Constructor Description AbstractIconRetriever(java.lang.String retrieverPath)
Create a new retriever that will retrieve icons from the specified location.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.symbology.IconRetriever
createIcon
-
-
-
-
Constructor Detail
-
AbstractIconRetriever
public AbstractIconRetriever(java.lang.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
-
getRetrieverPath
public java.lang.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.
-
equals
public boolean equals(java.lang.Object o)
Indicates whether or not this retriever is equal to another.- Overrides:
equals
in classjava.lang.Object
- Parameters:
o
- Object to compare.- Returns:
true
ifo
is an instance of AbstractIconRetriever and has the same retrieval path as this retriever.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
readImage
protected java.awt.image.BufferedImage readImage(java.lang.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.
-
drawImage
protected java.awt.image.BufferedImage drawImage(java.awt.image.BufferedImage src, java.awt.image.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.
-
multiply
protected void multiply(java.awt.image.BufferedImage image, java.awt.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)
-
replaceColor
protected void replaceColor(java.awt.image.BufferedImage image, java.awt.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. Unlikemultiply
, 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)
-
-