All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.elegantchaos.beans.asset.Asset

java.lang.Object
   |
   +----com.elegantchaos.beans.asset.Asset

public abstract class Asset
extends java.lang.Object
implements java.io.Serializable, java.io.ObjectInputValidation
Asset is the abstract class that all asset types inherit from

"User" objects can register an interest in assets, and then request them to load. When an asset is loaded, all registered users get notified, and sent the asset data to use. This potentially allows a number of client objects to share the asset data, avoiding unnecessary duplication of resources.

When user objects are permanently finished with an asset, they can unregister themselves. Assets can be set to automatically unload when all users have unregistered, or they can stay loaded until explicitly requested to unload.

The Asset class provides the capability (as yet unimplemented) for an "asset manager" of some sort which manages the unloading of assets in order to manage application memory effectively. The Asset manager can request that an asset be unloaded. When this happens, all registered users of the asset will receive an assetUnloading(kRequested) event, which gives them the chance to veto the unload (they do this by throwing an exception). The Asset manager will then send an assetUnloading(kFinished) event to indicate that the asset has indeed been unloaded. The Asset manager can also deliver this event without negotiation, in a situation where the asset has unexpectedly become unavailable.

Objects that use listeners are encouraged to fully support assetUnloading requests by not vetoing them unless doing so is absolutely necessary. In any event, assetUnloaded events should be handled so that the object can cope gracefully with it's asset becoming unavailable.


Constructor Index

 o Asset(String)
default constructor which just stores the asset location and calls initialize()

Method Index

 o addAssetListener(AssetListener)
call to register interest in this asset
 o getData()
return the asset data for the asset
 o getFileSize()
return file size of this asset
 o getLocation()
the current url for the asset
 o getPreview()
return preview image for this asset
 o getSize()
return size of this asset
 o isAudible()
can this asset be heard?
 o isCached()
will the asset be cached in ram?
 o isLoaded()
has the asset been loaded?
 o isPreloaded()
 o isVisual()
can this asset be drawn?
 o removeAssetListener(AssetListener)
call to unregister interest in this asset
 o requestLoad(AssetListener)
this method should be called by an asset listener to request an asset to load - the listener should have already registered themselves by calling addAssetListener()

if the asset is already loaded, the calling listener is immedietly sent an assetLoaded(kFinished) event - otherwise the load is requested, and appropriate events are sent to indicate the result

the idea here is to make sure that any user object only receives the load event once, but still inform all objects that need to know as soon as the load occurs.

 o requestUnload(AssetListener)
this method should be called to request an asset to unload

if the asset is already unloaded, the calling listener is immedietly sent an assetUnloaded(kFinished) event - otherwise the routine first asks all registered listeners whether they mind the asset unloading, and only completes the unload if they all agree

 o setCached(boolean)
set whether the asset should be cached in ram
 o setLocation(String)
change the url for the asset
 o setPreloaded(boolean)
 o validateObject()
we do our initialisation here, after loading of this class and any subclasses has taken place

Constructors

 o Asset
 public Asset(java.lang.String url)
default constructor which just stores the asset location and calls initialize()

Methods

 o validateObject
 public void validateObject() throws java.io.InvalidObjectException
we do our initialisation here, after loading of this class and any subclasses has taken place

 o isCached
 public boolean isCached()
will the asset be cached in ram?

 o setCached
 public void setCached(boolean b)
set whether the asset should be cached in ram

 o isPreloaded
 public boolean isPreloaded()
 o setPreloaded
 public void setPreloaded(boolean b)
 o isLoaded
 public boolean isLoaded()
has the asset been loaded?

 o getLocation
 public java.lang.String getLocation()
the current url for the asset

 o setLocation
 public void setLocation(java.lang.String url)
change the url for the asset

 o getData
 public java.lang.Object getData()
return the asset data for the asset

 o isVisual
 public boolean isVisual()
can this asset be drawn?

 o isAudible
 public boolean isAudible()
can this asset be heard?

 o getSize
 public java.awt.Dimension getSize()
return size of this asset

 o getFileSize
 public int getFileSize()
return file size of this asset

 o getPreview
 public javax.swing.ImageIcon getPreview()
return preview image for this asset

 o requestLoad
 public void requestLoad(com.elegantchaos.beans.asset.AssetListener al)
this method should be called by an asset listener to request an asset to load - the listener should have already registered themselves by calling addAssetListener()

if the asset is already loaded, the calling listener is immedietly sent an assetLoaded(kFinished) event - otherwise the load is requested, and appropriate events are sent to indicate the result

the idea here is to make sure that any user object only receives the load event once, but still inform all objects that need to know as soon as the load occurs. As a result, client objects should be prepared to receive the load object before they have requested loading.

 o requestUnload
 public void requestUnload(com.elegantchaos.beans.asset.AssetListener al)
this method should be called to request an asset to unload

if the asset is already unloaded, the calling listener is immedietly sent an assetUnloaded(kFinished) event - otherwise the routine first asks all registered listeners whether they mind the asset unloading, and only completes the unload if they all agree

 o addAssetListener
 public synchronized void addAssetListener(com.elegantchaos.beans.asset.AssetListener al)
call to register interest in this asset

 o removeAssetListener
 public synchronized void removeAssetListener(com.elegantchaos.beans.asset.AssetListener al)
call to unregister interest in this asset


All Packages  Class Hierarchy  This Package  Previous  Next  Index