public class ImageFactory extends ManagedFactory
ImageIcon
).
Whenever possible, this factory will hand out references to shared instances. Use this if you
need many, many image objects while running your application and it is
acceptable for you to continously use a certain amount of memory for the cached object. If you
only use instances once then you should either install an object as usual (by calling
new
), or let this factory create a shared instance and flush the factory after
you're finished with the object. The garbage collector will then release memory on-the-fly
as the objects are no longer referenced so the overall memory footprint can be very small.
TODO: A special VFSImageFactory would also be nice since VFS loading might be quite slow.
Modifier and Type | Field and Description |
---|---|
static java.net.URL |
ERROR_ICON
Icon provided if images cannot be loaded.
|
protected static ImageFactory |
sharedInstance
Shared
ImageFactory instance. |
cacheObjectByID
Constructor and Description |
---|
ImageFactory()
Constructs an instance of this factory.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canRelease(java.lang.String id)
Checks whether a factory shared object can be released or not.
|
void |
cleanup(java.lang.String id)
Perform optional cleanup tasks like closing database connections or disposing dialogs.
|
static javax.swing.ImageIcon |
getIcon(java.lang.String id)
Convenience method to get a certain image from the shared instance of this factory.
|
static javax.swing.ImageIcon |
getIcon(java.lang.String id,
javax.swing.ImageIcon fallback)
Convenience method to get a certain image from the shared instance of this factory.
|
static ImageFactory |
getSharedInstance()
Provides the shared instance of the factory implementation.
|
java.lang.Object |
request(java.lang.String id)
Create the factory shared object, recycle if already existing.
|
getRegisteredObjects, hasSharedInstance, release, releaseByStrategy, releaseForced, set
protected static ImageFactory sharedInstance
ImageFactory
instance.public static final java.net.URL ERROR_ICON
public ImageFactory()
public static ImageFactory getSharedInstance()
public java.lang.Object request(java.lang.String id)
request
in class ManagedFactory
id
- The factory-unique identifier of the shared objectnull
if none could be createdpublic boolean canRelease(java.lang.String id)
canRelease
in class ManagedFactory
id
- The factory-unique identifier of the shared objectpublic void cleanup(java.lang.String id)
cleanup
in class ManagedFactory
id
- The factory-unique identifier of the shared objectpublic static javax.swing.ImageIcon getIcon(java.lang.String id)
id
- The factory-unique identifier of the shared objectpublic static javax.swing.ImageIcon getIcon(java.lang.String id, javax.swing.ImageIcon fallback)
id
- The factory-unique identifier of the shared objectfallback
- Returned if desired icon is not availableCopyright © 2005-2013 Leisenfels UG (haftungsbeschränkt). All rights reserved.