Package jmri.jmrit.catalog
Class NamedIcon
java.lang.Object
javax.swing.ImageIcon
jmri.jmrit.catalog.NamedIcon
- All Implemented Interfaces:
Serializable,Accessible,Icon
Extend an ImageIcon to remember the name from which it was created and
provide rotation and scaling services.
We store both a "URL" for finding the file this was made from (so we can load this later), plus a shorter (localized) "name" for display in GUI.
These can be persisted by storing their name and rotation.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int(package private) intValid values are 0 - no rotation 1 - 90 degrees counter-clockwise 2 - 180 degrees counter-clockwise 3 - 270 degrees counter-clockwisestatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionCreate a named icon from an Image.Create a named icon that includes an image to be loaded from a URL.Create a named icon that includes an image to be loaded from a URL.Create a named icon that includes an image to be loaded from a URL.Create a NamedIcon that is a complete copy of an existing NamedIconCreate a NamedIcon that is really a complete copy of an existing NamedIcon -
Method Summary
Modifier and TypeMethodDescriptioncreateRotatedImage(Image pImage, Component pComponent, int pRotation) The following was based on a text-rotating applet from David Risner, available at http://www.risner.org/java/rotate_text.html Page unavailable as at April 2019voidintstatic NamedIcongetIconByName(String path) Find the NamedIcon corresponding to a file path.getName()Return the human-readable name of this icon.intGet the number of 90-degree rotations needed to properly display this icon.doublegetScale()getURL()Get the URL of this icon.doublereduceTo(int width, int height, double limit) Reduce this image size to within the given dimensions, with a limit on the reduction in size.voidRotate from anchor point (upper left corner) and shift into place.voidScale as a percentage.voidvoidSet the human-readable name for this icon.voidsetRotation(int pRotation, Component comp) Set the number of 90-degree rotations needed to properly display this icon.voidSet URL of original icon image.voidtransformImage(int w, int h, AffineTransform t, Component comp) Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getIconHeight, getIconWidth, getImage, getImageLoadStatus, getImageObserver, loadImage, paintIcon, setDescription, setImage, setImageObserver, toString
-
Field Details
-
mRotation
int mRotationValid values are- 0 - no rotation
- 1 - 90 degrees counter-clockwise
- 2 - 180 degrees counter-clockwise
- 3 - 270 degrees counter-clockwise
-
NOFLIP
- See Also:
-
HORIZONTALFLIP
- See Also:
-
VERTICALFLIP
- See Also:
-
-
Constructor Details
-
NamedIcon
Create a NamedIcon that is a complete copy of an existing NamedIcon- Parameters:
pOld- Object to copy i.e. copy of the original icon, but NOT a complete copy of pOld (no transformations done)
-
NamedIcon
Create a NamedIcon that is really a complete copy of an existing NamedIcon- Parameters:
pOld- Object to copycomp- the container the new icon is embedded in
-
NamedIcon
Create a named icon that includes an image to be loaded from a URL.The default access form is "file:", so a bare pathname to an icon file will also work for the URL argument.
- Parameters:
pUrl- URL of image file to loadpName- Human-readable name for the icon
-
NamedIcon
public NamedIcon(String pUrl, String pName, jmri.jmrit.catalog.NamedIcon.GIFMetadataImages pGifState) Create a named icon that includes an image to be loaded from a URL.The default access form is "file:", so a bare pathname to an icon file will also work for the URL argument.
- Parameters:
pUrl- URL of image file to loadpName- Human-readable name for the iconpGifState- Breakdown of GIF Image metadata and frames
-
NamedIcon
Create a named icon that includes an image to be loaded from a URL.- Parameters:
pUrl- String-form URL of image file to loadpName- Human-readable name for the icon
-
NamedIcon
Create a named icon from an Image. N.B. NamedIcon's create using this constructor can NOT be animated GIFs- Parameters:
im- Image to use
-
-
Method Details
-
getIconByName
Find the NamedIcon corresponding to a file path. Understands the standard portable filename prefixes.- Parameters:
path- The path to the file, either absolute or portable- Returns:
- the desired icon with this same name as its path
-
getName
Return the human-readable name of this icon.- Returns:
- the name or null if not set
-
setName
Set the human-readable name for this icon.- Parameters:
name- the new name, can be null
-
getURL
Get the URL of this icon.- Returns:
- the path to this icon in JMRI portable format or null if not set
-
setURL
Set URL of original icon image. Setting this after initial construction does not change the icon.- Parameters:
url- the URL associated with this icon
-
getRotation
Get the number of 90-degree rotations needed to properly display this icon.- Returns:
- 0 (no rotation), 1 (rotated 90 degrees), 2 (180 degrees), or 3 (270 degrees)
-
setRotation
Set the number of 90-degree rotations needed to properly display this icon.- Parameters:
pRotation- 0 (no rotation), 1 (rotated 90 degrees), 2 (180 degrees), or 3 (270 degrees)comp- the component containing this icon
-
createRotatedImage
The following was based on a text-rotating applet from David Risner, available at http://www.risner.org/java/rotate_text.html Page unavailable as at April 2019- Parameters:
pImage- Image to transformpComponent- Component containing the image, needed to obtain a MediaTracker to process the image consistently with displaypRotation- 0-3 number of 90-degree rotations needed- Returns:
- new Image object containing the rotated input image
-
getDegrees
-
getScale
-
setLoad
-
transformImage
-
scale
Scale as a percentage.- Parameters:
scale- the scale to set the imagecomp- the containing component
-
rotate
Rotate from anchor point (upper left corner) and shift into place.- Parameters:
degree- the distance to rotatecomp- containing component
-
reduceTo
Reduce this image size to within the given dimensions, with a limit on the reduction in size.- Parameters:
width- new widthheight- new heightlimit- limit on the reduction in size- Returns:
- the scale by which this image was resized
-
flip
-