public class TextureAtlasElement extends java.lang.Object implements Disposable
TextureAtlas
.
TextureAtlasElement performs lazy retrieval and loading of its image source into its texture atlas. This loads the
image source and adds it to the atlas only when the load(gov.nasa.worldwind.render.DrawContext)
method is
called. If the image source is a BufferedImage
it is added to the atlas immediately when load
is
called. If the image source is a local file or a remote stream (URL), retrieval and loading is performed on a
separate thread from the EDT.Modifier and Type | Class and Description |
---|---|
protected static class |
TextureAtlasElement.RequestTask
RequestTask is an implementation of the Runnable interface who's
run method retrieves and loads this
element's image source. |
Modifier and Type | Field and Description |
---|---|
protected TextureAtlas |
atlas
Indicates the texture atlas this element belongs to.
|
protected java.awt.image.BufferedImage |
image
The BufferedImage created as the image source is read.
|
protected boolean |
imageInitializationFailed
Indicates that image initialization failed.
|
protected java.lang.Object |
imageSource
Indicates the original image source associated with this element.
|
protected java.beans.PropertyChangeListener |
listener
The object to notify when the image is eventually loaded in memory.
|
Constructor and Description |
---|
TextureAtlasElement(TextureAtlas atlas,
java.lang.Object imageSource)
Creates a new texture atlas element with the specified atlas and image source.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
addAtlasImage()
Adds this element's image source into its texture atlas.
|
protected java.lang.Runnable |
createRequestTask()
Returns an object that implements the Runnable interface, and who's
run method retrieves and loads
this element's image source. |
void |
dispose()
Removes this element's image from its texture atlas and disposes of this element's image resource.
|
boolean |
equals(java.lang.Object o)
Indicates whether another texture atlas element is equivalent to this one.
|
protected java.awt.image.BufferedImage |
getImage()
Indicates the image created as the image source is read.
|
java.lang.Object |
getImageSource()
Indicates the original image source associated with this element.
|
java.awt.Dimension |
getSize()
Returns the image dimensions associated with this texture atlas element.
|
TextureCoords |
getTexCoords()
Returns the OpenGL texture coordinates associated this texture atlas element.
|
TextureAtlas |
getTextureAtlas()
Indicates the texture atlas this element belongs to.
|
int |
hashCode()
Returns the hash code for this texture atlas element's image source.
|
protected boolean |
isBufferedImageSource()
Indicates whether this element's image source is a BufferedImage.
|
boolean |
isImageInitializationFailed()
Indicates whether this element's image failed to load.
|
boolean |
load(DrawContext dc)
Loads this element's image and adds it to the texture atlas.
|
protected boolean |
loadImage()
Loads this element's image source into its
image property. |
protected void |
notifyImageLoaded()
Notifies this texture atlas element's listener that image loading has completed.
|
protected java.awt.image.BufferedImage |
readImage(java.net.URL fileUrl)
Reads and returns the specified image URL as a BufferedImage.
|
protected boolean |
requestImage(DrawContext dc)
Requests that this element's image source be loaded into its texture atlas.
|
protected void |
setImage(java.awt.image.BufferedImage image)
Specifies the image created as the image source is read.
|
java.lang.String |
toString()
Returns the string representation of this texture atlas element's image source.
|
protected TextureAtlas atlas
protected volatile java.awt.image.BufferedImage image
null
once the image is loaded into the texture atlas. This field is volatile
in order
to synchronize atomic access among threads. This field is not used if the image source is
BufferedImage
.protected boolean imageInitializationFailed
true
. Initially
false
.protected java.lang.Object imageSource
protected java.beans.PropertyChangeListener listener
null
. This set to null
once
the image is loaded into the texture atlas.public TextureAtlasElement(TextureAtlas atlas, java.lang.Object imageSource)
atlas
- the texture atlas this element belongs to.imageSource
- a general image source. The source type may be one of the following: URL
InputStream
File
String
containing a valid URL description or a file or resource name available on the
classpath.java.lang.IllegalArgumentException
- if either the atlas or the image source is null
.protected boolean addAtlasImage()
image
property.true
if this element's image is successfully added to the texture atlas, and
false
otherwise.protected java.lang.Runnable createRequestTask()
run
method retrieves and loads
this element's image source.public void dispose()
dispose
in interface Disposable
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the object to test.true
if the specified object is a TextureAtlasElement and its image source is equivalent to
this element's image source, otherwise false
.protected java.awt.image.BufferedImage getImage()
setImage(java.awt.image.BufferedImage)
public java.lang.Object getImageSource()
public java.awt.Dimension getSize()
load
before
calling this method to ensure that the element is loaded into its texture atlas.null
if this texture
atlas element has not yet loaded or has failed to load.load(gov.nasa.worldwind.render.DrawContext)
public TextureCoords getTexCoords()
load
before calling this method to ensure that the element is loaded into its texture atlas.
The returned texture coordinates can change any time an element is added or removed from this element's texture
atlas, and therefore should not be cached unless the caller has explicit knowledge of when this element's texture
atlas has changed.null
if this
texture atlas element has not yet loaded or has failed to load.load(gov.nasa.worldwind.render.DrawContext)
public TextureAtlas getTextureAtlas()
public int hashCode()
hashCode
in class java.lang.Object
protected boolean isBufferedImageSource()
true
if this element's image source is a BufferedImage, and false
otherwise.public boolean isImageInitializationFailed()
true
.true
if this element's image failed to load, and false
otherwise.public boolean load(DrawContext dc)
dc
- the current draw context. Used to generate a repaint event when the image source retrieval completes.true
if this element's image is successfully loaded and added to the texture atlas,
otherwise false
.protected boolean loadImage()
image
property. If the image source is a remote resource,
this initiates a request for it and returns null
.true
if the image source has been loaded successfully, and false
otherwise.protected void notifyImageLoaded()
protected java.awt.image.BufferedImage readImage(java.net.URL fileUrl)
fileUrl
- the image URL to read.null
if the image could not be read.protected boolean requestImage(DrawContext dc)
true
. Otherwise, this
initiates the retrieval of this element's image source in a separate thread and returns false
. Once
the image source is retrieved, a subsequent invocation of this method loads it into the texture atlas and returns
true
.dc
- the current draw context. Used to generate a repaint event when the image source retrieval completes.true
if this element's image is loaded into the texture atlas, and false
otherwise.protected void setImage(java.awt.image.BufferedImage image)
volatile
in order to synchronize atomic access among threads.image
- this element's image.public java.lang.String toString()
toString
in class java.lang.Object