Package jmri.jmrit.catalog
Class NamedIcon
- java.lang.Object
-
- javax.swing.ImageIcon
-
- jmri.jmrit.catalog.NamedIcon
-
- All Implemented Interfaces:
java.io.Serializable,javax.accessibility.Accessible,javax.swing.Icon
public class NamedIcon extends javax.swing.ImageIcon
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:
PositionableLabelXml, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intHORIZONTALFLIP(package private) intmRotationValid values are 0 - no rotation 1 - 90 degrees counter-clockwise 2 - 180 degrees counter-clockwise 3 - 270 degrees counter-clockwisestatic intNOFLIPstatic intVERTICALFLIP
-
Constructor Summary
Constructors Constructor Description NamedIcon(java.awt.Image im)Create a named icon from an Image.NamedIcon(java.lang.String pUrl, java.lang.String pName)Create a named icon that includes an image to be loaded from a URL.NamedIcon(java.lang.String pUrl, java.lang.String pName, jmri.jmrit.catalog.NamedIcon.GIFMetadataImages pGifState)Create a named icon that includes an image to be loaded from a URL.NamedIcon(java.net.URL pUrl, java.lang.String pName)Create a named icon that includes an image to be loaded from a URL.NamedIcon(NamedIcon pOld)Create a NamedIcon that is a complete copy of an existing NamedIconNamedIcon(NamedIcon pOld, java.awt.Component comp)Create a NamedIcon that is really a complete copy of an existing NamedIcon
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.awt.ImagecreateRotatedImage(java.awt.Image pImage, java.awt.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 2019voidflip(int flip, java.awt.Component comp)intgetDegrees()static NamedIcongetIconByName(java.lang.String path)Find the NamedIcon corresponding to a file path.java.lang.StringgetName()Return the human-readable name of this icon.intgetRotation()Get the number of 90-degree rotations needed to properly display this icon.doublegetScale()java.lang.StringgetURL()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(int degree, java.awt.Component comp)Rotate from anchor point (upper left corner) and shift into place.voidscale(double scale, java.awt.Component comp)Scale as a percentage.voidsetLoad(int d, double s, java.awt.Component comp)voidsetName(java.lang.String name)Set the human-readable name for this icon.voidsetRotation(int pRotation, java.awt.Component comp)Set the number of 90-degree rotations needed to properly display this icon.voidsetURL(java.lang.String url)Set URL of original icon image.voidtransformImage(int w, int h, java.awt.geom.AffineTransform t, java.awt.Component comp)
-
-
-
Field Detail
-
mRotation
int mRotation
Valid values are- 0 - no rotation
- 1 - 90 degrees counter-clockwise
- 2 - 180 degrees counter-clockwise
- 3 - 270 degrees counter-clockwise
-
NOFLIP
public static final int NOFLIP
- See Also:
- Constant Field Values
-
HORIZONTALFLIP
public static final int HORIZONTALFLIP
- See Also:
- Constant Field Values
-
VERTICALFLIP
public static final int VERTICALFLIP
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
NamedIcon
public NamedIcon(NamedIcon pOld)
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
public NamedIcon(NamedIcon pOld, java.awt.Component comp)
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
public NamedIcon(java.lang.String pUrl, java.lang.String pName)
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(java.lang.String pUrl, java.lang.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
public NamedIcon(java.net.URL pUrl, java.lang.String pName)
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
public NamedIcon(java.awt.Image im)
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 Detail
-
getIconByName
public static NamedIcon getIconByName(java.lang.String path)
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
@CheckForNull public java.lang.String getName()
Return the human-readable name of this icon.- Returns:
- the name or null if not set
-
setName
public void setName(@CheckForNull java.lang.String name)
Set the human-readable name for this icon.- Parameters:
name- the new name, can be null
-
getURL
@CheckForNull public java.lang.String getURL()
Get the URL of this icon.- Returns:
- the path to this icon in JMRI portable format or null if not set
-
setURL
public void setURL(@CheckForNull java.lang.String url)
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
public int 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
public void setRotation(int pRotation, java.awt.Component comp)
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
public java.awt.Image createRotatedImage(java.awt.Image pImage, java.awt.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 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
public int getDegrees()
-
getScale
public double getScale()
-
setLoad
public void setLoad(int d, double s, java.awt.Component comp)
-
transformImage
public void transformImage(int w, int h, java.awt.geom.AffineTransform t, java.awt.Component comp)
-
scale
public void scale(double scale, java.awt.Component comp)
Scale as a percentage.- Parameters:
scale- the scale to set the imagecomp- the containing component
-
rotate
public void rotate(int degree, java.awt.Component comp)
Rotate from anchor point (upper left corner) and shift into place.- Parameters:
degree- the distance to rotatecomp- containing component
-
reduceTo
public double reduceTo(int width, int height, double limit)
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
public void flip(int flip, java.awt.Component comp)
-
-