- All Superinterfaces:
NamedResource
- All Known Implementing Classes:
GeneralSampleImage
,Kimia1070
,Kimia216
,Kimia99
,KimiaCollage
Interface to be implemented by named image resources. This indicates (for testing) that the associated resource can
be opened as an image (by ImageJ). Extends interface NamedResource
by adding method getImagePlus()
,
which returns an ImagePlus
instance. By default, image files are assumed to reside in a directory at the same
level and with exactly the same name as the defining enum class itself. E.g., in a standard Maven-setup this is:
.../java/ .../bar/MyImageResource.java = enum class implementing 'ImageResource' .../resource/.../bar/MyImageResource/image1.png = associated image files .../resource/.../bar/MyImageResource/image2.tif .../resource/.../bar/MyImageResource/...
For example, given a named resource MyImages.image1
, this can be used simply in the form
ImagePlus im = MyImages.image1.getImage(); im.show();
By default, resource file names are derived automatically from the enum item's name (by method autoName()
).
If some other behavior is needed, method getFileName()
should be overridden.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default icon size (maximum width or height).The set of image file extensions supported inautoName()
.Fields inherited from interface imagingbook.core.resource.NamedResource
RelativeDirectorySuffix
-
Method Summary
Modifier and TypeMethodDescriptiondefault String
autoName()
Derives and returns a filename for this resource item to be used in parameterless enum constructors.default String
Returns the file name for the associated resource (to be implemented by concrete classes).default ImagePlus
Returns an icon for thisImageResource
with the default icon size.default ImagePlus
getImageIcon
(int iconSize) Returns an icon for thisImageResource
with the specified size.default ImagePlus
Opens end returns aImagePlus
instance for thisImageResource
.static String[]
getResourceFileNames
(Class<? extends ImageResource> clazz) Returns the names of the actual files contained in the associated resource directory of the specified class, which must implement theImageResource
interface.Methods inherited from interface imagingbook.core.resource.NamedResource
getRelativeDirectory, getRelativePath, getStream, getURL, isInsideJar
-
Field Details
-
ValidImageExtensions
The set of image file extensions supported inautoName()
. -
DefaultIconSize
The default icon size (maximum width or height).- See Also:
-
IconMap
-
-
Method Details
-
getImagePlus
Opens end returns aImagePlus
instance for thisImageResource
.- Returns:
- a
ImagePlus
instance
-
getFileName
Description copied from interface:NamedResource
Returns the file name for the associated resource (to be implemented by concrete classes).- Specified by:
getFileName
in interfaceNamedResource
- Returns:
- the name of the resource file
-
autoName
Derives and returns a filename for this resource item to be used in parameterless enum constructors. By default the file name is identical to the name of the enum constant supplemented with a ".png" extension. No separate file name needs to be supplied. A different file extension may be specified by having the enum name end with an underscore followed by a valid image file extension, that is, "png", "tif", "tiff", "jpg", "jpeg" or "gif". In this case, the last underscore of the enum name is replaced by a '.' character to form the file name. (Note that '.' is no legal character in a Java identifier, thus cannot be used for the enum name directly.) If the last underscore in a item's name is not followed by a valid extension, the default case is assumed ("png").
Examples:
enum DummyNamedResource implements ImageResource { a, // file "a.png" A_png, // file "A.png" foo_tif, // file "foo.tif" foo_tiff, // file "foo.tiff" The_File_jpg, // file "The_File.jpg" The_File_jpeg, // file "The_File.jpeg" _Some____File_bla; // file "_Some____File_bla.png" }
- Returns:
- the image filename derived from the enum item's name
-
getResourceFileNames
Returns the names of the actual files contained in the associated resource directory of the specified class, which must implement theImageResource
interface. This can be used to check if a given named resource has a matching file in a case-sensitive way.- Parameters:
clazz
- the resource class- Returns:
- an array of strings
-
getImageIcon
Returns an icon for thisImageResource
with the default icon size. All icons are cached, i.e., are only created once when first requested for a particular size.- Returns:
- an
ImagePlus
instance containing the icon image - See Also:
-
getImageIcon
Returns an icon for thisImageResource
with the specified size. All icons are cached, i.e., are only created once when first requested for a particular size.- Parameters:
iconSize
-- Returns:
- an
ImagePlus
instance containing the icon image - See Also:
-