public class LazyFileIcon extends ImageIcon
ImageIcon
which lazily loads the file icon.
This type of image can be used to lazily load a file icon. This can be useful if files reside on a slow network drive which could impact the GUI performance if loading would be performed OnEDT.
To use this icon, simply create it via LazyFileIcon(File, ImageObserver)
and
use it like any other ImageIcon. Correct size and obviously the paintIcon-Method will only be
available after successful loading.
After successful loading, the passed ImageObserver
will be notified to update the icon.
Note
This class contains an internal cache to store Icons for specific file suffixes. In consequence,
a file type (based on suffix) only has 1 possible icon.
Consider the following situation / example:
Internally, this class remembers the processed error files for which no icon could be retrieved. This is to prevent loops when fetching icons for non-existent files. Entries for a specific suffix will be removed if possible as soon as at least one file with that suffix has been processed successfully.
Usage
See LazyFileIcon(File, ImageObserver)
ImageIcon.AccessibleImageIcon
Constructor and Description |
---|
LazyFileIcon(File file,
ImageObserver imageObserver)
Creates a new
LazyFileIcon for the given file. |
Modifier and Type | Method and Description |
---|---|
int |
getIconHeight()
As long as the icon is not yet fully loaded, this will return 0.
|
int |
getIconWidth()
As long as the icon is not yet fully loaded, this will return 0.
|
void |
paintIcon(Component component,
Graphics graphics,
int x,
int y) |
getAccessibleContext, getDescription, getImage, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImage, setImageObserver, toString
public LazyFileIcon(File file, ImageObserver imageObserver)
LazyFileIcon
for the given file. This will first check if an icon for the
file's suffix has already been loaded and uses that if present.
If no cached entry is present, the loading will be queued - as soon as loading is finished,
ImageObserver.imageUpdate(java.awt.Image, int, int, int, int, int)
will be called on
the passed ImageObserver
which updates the visual appearance to the loaded icon.
If multiple requests for the same suffix arrive, the ImageObservers for that type will be collected in a list and will be notified when the loading operation succeeds.
file
- the file to obtain an icon forimageObserver
- the ImageObserver
to be notified when deferred loading completespublic int getIconWidth()
getIconWidth
in interface Icon
getIconWidth
in class ImageIcon
public int getIconHeight()
getIconHeight
in interface Icon
getIconHeight
in class ImageIcon
Copyright © 2024 levigo holding gmbh. All rights reserved.