jmri.jmrit.catalog
Class NamedIcon

Show UML class diagram
java.lang.Object
  extended by javax.swing.ImageIcon
      extended by jmri.jmrit.catalog.NamedIcon
All Implemented Interfaces:
Serializable, Accessible, Icon

public class NamedIcon
extends ImageIcon

Extend an ImageIcon to remember the name from which it was created and provide rotation & scaling services.

We store both a "URL" for finding the file this was made from (so we can load this later), plus a shorter "name" for display.

These can be persisted by storing their name and rotation

See Also:
PositionableLabelXml, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
 
Field Summary
static int HORIZONTALFLIP
           
(package private) static org.slf4j.Logger log
           
(package private)  int mRotation
          Valid values are 0 - no rotation 1 - 90 degrees counter-clockwise 2 - 180 degrees counter-clockwise 3 - 270 degrees counter-clockwise
static int NOFLIP
           
static int VERTICALFLIP
           
 
Fields inherited from class javax.swing.ImageIcon
component, tracker
 
Constructor Summary
NamedIcon(Image im)
           
NamedIcon(NamedIcon pOld)
          Create a NamedIcon that is a complete copy of an existing NamedIcon
NamedIcon(NamedIcon pOld, Component comp)
          Create a NamedIcon that is really a complete copy of an existing NamedIcon
NamedIcon(String pUrl, String pName)
          Create a named icon that includes an image to be loaded from a URL.
NamedIcon(URL pUrl, String pName)
          Create a named icon that includes an image to be loaded from a URL.
 
Method Summary
 Image createRotatedImage(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
 void flip(int flip, Component comp)
           
 int getDegrees()
           
static NamedIcon getIconByName(String pName)
          Find the NamedIcon corresponding to a name.
 String getName()
          Return the human-readable name of this icon
 int getRotation()
          Return the 0-3 number of 90-degree rotations needed to properly display this icon
 double getScale()
           
 String getURL()
          Return the URL of this icon
 double reduceTo(int width, int height, double limit)
          If necessary, reduce this image to within 'width' x 'height' dimensions.
 void rotate(int degree, Component comp)
          Rotate from anchor point (upper left corner) and shift into place
 void scale(double scale, Component comp)
          Scale as a percentage public void scale(int s, Component comp) { //log.info("scale= "+s+", "+getDescription()); if (s<1) { return; } scale(s/100.0, comp); }
 void setLoad(int d, double s, Component comp)
           
 void setName(String name)
          Actually it is mName that is the URL that loads the icon!
 void setRotation(int pRotation, Component comp)
          Set the 0-3 number of 90-degree rotations needed to properly display this icon
 void setURL(String url)
          Set URL of original icon image
 void transformImage(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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mRotation

int mRotation
Valid values are


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

log

static org.slf4j.Logger log
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,
                 Component comp)
Create a NamedIcon that is really a complete copy of an existing NamedIcon

Parameters:
pOld - Object to copy

NamedIcon

public NamedIcon(String pUrl,
                 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 load
pName - Human-readable name for the icon

NamedIcon

public NamedIcon(URL pUrl,
                 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 load
pName - Human-readable name for the icon

NamedIcon

public NamedIcon(Image im)
Method Detail

getIconByName

public static NamedIcon getIconByName(String pName)
Find the NamedIcon corresponding to a name. Understands the standard portable filename prefixes.

Parameters:
pName - The name string, possibly starting with file: or resource:
Returns:
the desired icon with this same pName as its name.

getName

public String getName()
Return the human-readable name of this icon


setName

public void setName(String name)
Actually it is mName that is the URL that loads the icon!


getURL

public String getURL()
Return the URL of this icon


setURL

public void setURL(String url)
Set URL of original icon image


getRotation

public int getRotation()
Return the 0-3 number of 90-degree rotations needed to properly display this icon


setRotation

public void setRotation(int pRotation,
                        Component comp)
Set the 0-3 number of 90-degree rotations needed to properly display this icon


createRotatedImage

public Image createRotatedImage(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

Parameters:
pImage - Image to transform
pComponent - Component containing the image, needed to obtain a MediaTracker to process the image consistently with display
pRotation - 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,
                    Component comp)

transformImage

public void transformImage(int w,
                           int h,
                           AffineTransform t,
                           Component comp)

scale

public void scale(double scale,
                  Component comp)
Scale as a percentage public void scale(int s, Component comp) { //log.info("scale= "+s+", "+getDescription()); if (s<1) { return; } scale(s/100.0, comp); }


rotate

public void rotate(int degree,
                   Component comp)
Rotate from anchor point (upper left corner) and shift into place


reduceTo

public double reduceTo(int width,
                       int height,
                       double limit)
If necessary, reduce this image to within 'width' x 'height' dimensions. limit the reduction by 'limit'


flip

public void flip(int flip,
                 Component comp)


Copyright © 1997-2013 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads