public abstract class AbstractIconRetriever extends Object implements IconRetriever
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"); } }
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 String |
retrieverPath
Path in the file system or network to the symbol repository.
|
Constructor and Description |
---|
AbstractIconRetriever(String retrieverPath)
Create a new retriever that will retrieve icons from the specified location.
|
Modifier and Type | Method and Description |
---|---|
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.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
createIcon
protected String retrieverPath
public AbstractIconRetriever(String retrieverPath)
retrieverPath
- URL to to the base symbol directory on the local file system or the network.protected BufferedImage drawImage(BufferedImage src, BufferedImage dest)
src
- Image to draw.dest
- Image to draw into.dest
BufferedImage.public boolean equals(Object o)
public String getRetrieverPath()
protected void multiply(BufferedImage image, Color color)
image
- Image to operate on.color
- Color to multiply by.replaceColor(java.awt.image.BufferedImage, java.awt.Color)
protected BufferedImage readImage(String path)
path
- Path to the icon resource, relative to this retriever's retrieval path.protected void replaceColor(BufferedImage image, 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)