Package resources
Class ResourceManager
java.lang.Object
resources.ResourceManager
General resource management class that provides a convenient
way of accessing external resources used in Ghidra.
There is a known problem with Java's MediaTracker
that can cause deadlocks. The various
methods of this class that create ImageIcon
s will do so by loading image bytes directly,
as opposed to using the flawed constructor ImageIcon(Image)
.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic ImageIcon
Attempts to load an icon from the given path.static ImageIcon
static ImageIcon
getDisabledIcon
(Icon icon) Get the disabled rendering of the given icon.static ImageIcon
getDisabledIcon
(Icon icon, int brightnessPercent) Returns a disabled icon while allowing the caller to control the brightness of the icon returnedstatic ImageIcon
getDisabledIcon
(ImageIcon icon) Get the disabled rendering of the given imageIcon.static String
getIconName
(Icon icon) Get the name of this icon.static ImageIcon
getImageIcon
(Icon icon) Returns anImageIcon
for the given icon.static ImageIcon
getImageIconFromImage
(String imageName, Image image) Creates an image icon from the given image.Returns a list of all loaded icons.static URL
getResource
(String filename) Finds a resource with a given name.static InputStream
getResourceAsStream
(String filename) Finds a resource with a given name.static File
getResourceFile
(String filename) Locates a File resource by the given namegetResourceNames
(String dirName, String extension) Search the classpath for files in the <classpath entry>/dirName
location that have the given extension.getResources
(String dirName, String extension) Search the classpath for files in the <classpath entry>/dirName
location that have the given extension.static Icon
getScaledIcon
(Icon icon, int width, int height) Creates a scaled Icon from the given icon with scaling ofImage.SCALE_AREA_AVERAGING
.static ImageIcon
getScaledIcon
(Icon icon, int width, int height, int hints) Creates a scaled ImageIcon from the given icon.static ImageIcon
getScaledIcon
(ImageIcon icon, int width, int height) Creates a scaled ImageIcon from the given icon with scaling ofImage.SCALE_AREA_AVERAGING
static Icon
Load the icon specified by iconPath.static ImageIcon
Load the image specified by filename; returns the default bomb icon if problems occur trying to load the file.static ImageIcon
Load the image using the specified bytes.static ImageIcon
Load and scale the image specified by filename; returns null if problems occur trying to load the file.loadImages
(String... filenames) Load the images specified by filenames; substitutes the default bomb icon if problems occur trying to load an individual file.static ImageIcon
reloadImage
(String filename) A convenience method to force the image denoted byfilename
to be read from disk and to not use the cached version
-
Field Details
-
BOMB
- See Also:
-
BIG_BOMB
- See Also:
-
EXTERNAL_ICON_PREFIX
- See Also:
-
-
Constructor Details
-
ResourceManager
public ResourceManager()
-
-
Method Details
-
getResource
Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class.- Parameters:
filename
- "partially" qualified resource filename to get, e.g., "images/go-home.png" would look for the file named 'home.gif' in the 'images' subdirectory of the 'resources' package, following the search rules defined by your CLASSPATH and return an InputStream if found; null if it cannot load the resource.- Returns:
- the URL
-
getResourceAsStream
Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class.- Parameters:
filename
- "partially" qualified resource filename to get, e.g., "images/home.gif" would look for the file named 'home.gif' in the 'images' subdirectory of the 'resources' package, following the search rules defined by your CLASSPATH and return an InputStream if found; null if it cannot load the resource.- Returns:
- the input stream
-
getResourceFile
Locates a File resource by the given name- Parameters:
filename
- the filename- Returns:
- the File for the given resource; null if there is no such file
-
getResources
Search the classpath for files in the <classpath entry>/dirName
location that have the given extension. Innull
is passed for the extension, then all files found in the given dir names will be returned. In this way,null
is a wildcard.This method differs from
getResource(String)
in that this method finds multiple matches.- Parameters:
dirName
- the name of the sub-directory under which to searchextension
- the extension that matching files must possess- Returns:
- set of URLs in the given directory that end with the given extension
-
getResourceNames
Search the classpath for files in the <classpath entry>/dirName
location that have the given extension. Innull
is passed for the extension, then all files found in the given dir names will be returned. In this way,null
is a wildcard.The names returned from this method are relative and are meant to be used in a later callback to this class for methods such as
loadImage(String)
orgetResource(String)
.- Parameters:
dirName
- the name of the directory under which to searchextension
- the extension that matching files must possess- Returns:
- set of filenames in the given directory that end with the given extension
-
getScaledIcon
Creates a scaled ImageIcon from the given icon.- Parameters:
icon
- the icon to scalewidth
- the width of the new iconheight
- the height of the new iconhints
- scaling hints (seeImage.getScaledInstance(int, int, int)
- Returns:
- A new, scaled ImageIcon
-
getScaledIcon
Creates a scaled ImageIcon from the given icon with scaling ofImage.SCALE_AREA_AVERAGING
- Parameters:
icon
- the icon to scalewidth
- the width of the new iconheight
- the height of the new icon- Returns:
- A new, scaled ImageIcon
-
getScaledIcon
Creates a scaled Icon from the given icon with scaling ofImage.SCALE_AREA_AVERAGING
. If an EmptyIcon is passed, a new EmptyIcon is returned with the new dimensions.- Parameters:
icon
- the icon to scalewidth
- the width of the new iconheight
- the height of the new icon- Returns:
- A new, scaled ImageIcon
-
getDisabledIcon
Get the disabled rendering of the given icon.- Parameters:
icon
- The icon to disable.- Returns:
- disabled icon
-
getDisabledIcon
Get the disabled rendering of the given imageIcon.- Parameters:
icon
- The icon to disable.- Returns:
- disabled icon
-
getDisabledIcon
Returns a disabled icon while allowing the caller to control the brightness of the icon returned- Parameters:
icon
- The icon to disable.brightnessPercent
- The level of brightness (0-100, where 100 is the brightest).- Returns:
- a disabled version of the original icon.
-
getImageIconFromImage
Creates an image icon from the given image. This method will create anImageIcon
the "safe" way by avoiding the constructorImageIcon(Image)
, which can trigger problems with Java'sMediaTracker
.- Parameters:
imageName
- A textual description of the image; may be nullimage
- The image to use for creating an ImageIcon.- Returns:
- the new icon
-
getImageIcon
Returns anImageIcon
for the given icon. If the value is already an ImageIcon, then that object is returned; otherwise, an ImageIcon will be created the safe way.- Parameters:
icon
- The icon to convert- Returns:
- the new icon
-
getIconName
Get the name of this icon. The value is usually going to be the URL from which the icon was loaded- Parameters:
icon
- the icon for which the name is desired- Returns:
- the name
-
loadImage
Load the image using the specified bytes. The image icon will be cached using the image name. The bytes must have been read from an image file containing a supported image format, such as GIF, JPEG, or (as of 1.3) PNG.- Parameters:
imageName
- the name of the imageimageBytes
- the bytes of the image- Returns:
- the image icon stored in the bytes
-
loadImage
Load and scale the image specified by filename; returns null if problems occur trying to load the file.- Parameters:
filename
- name of file to load, e.g., "images/home.gif"width
- - the width to scale the image toheight
- - the height to scale the image to- Returns:
- the scaled image.
-
findIcon
Attempts to load an icon from the given path. Returns the icon or null if no icon was found from the given path. This differs fromloadImage(String)
in that loadImage will return the default Icon if one can't be found. Further, loadImage will cache even the default value, while findIcon only caches resolved icons.- Parameters:
path
- the icon to load, e.g., "images/home.gif"- Returns:
- the ImageIcon if it exists or null
-
loadIcon
Load the icon specified by iconPath. The iconPath can be either a path to a resource on the classpath or a relative or absolute path to an icon on the file system. If the iconPath is a path to a classpath resource, then it will be searched directly or also with an "images/" prepended to the path. For example, if there exists an icon "home.gif" on the classpath that was stored in the standard "images" resource directory, then it exists on the classpath as "images/home.gif". That icon will be found if the iconPath is either "images/home.gif" or just as "home.gif".- Parameters:
iconPath
- name of file to load, e.g., "images/home.gif"- Returns:
- an Icon from the given iconPath or null, if no such icon can be found
-
loadImage
Load the image specified by filename; returns the default bomb icon if problems occur trying to load the file.- Parameters:
iconPath
- name of file to load, e.g., "images/home.gif"- Returns:
- the image icon stored in the bytes
-
getLoadedIcons
Returns a list of all loaded icons.- Returns:
- a list of all loaded icons
-
loadImages
Load the images specified by filenames; substitutes the default bomb icon if problems occur trying to load an individual file.- Parameters:
filenames
- vararg list of string filenames (ie. "images/home.gif")- Returns:
- list of ImageIcons with each image, problem / missing images replaced with the default icon.
-
reloadImage
A convenience method to force the image denoted byfilename
to be read from disk and to not use the cached version- Parameters:
filename
- name of file to load, e.g., "images/home.gif"- Returns:
- the image icon stored in the bytes
- See Also:
-
getDefaultIcon
-
getToolImages
-