jmri.jmrit.catalog
Class NamedIcon

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

Author:
Bob Jacobsen Copyright 2002, 2008, Pete Cressman Copyright: Copyright (c) 2009, 2010
See Also:
PositionableLabelXml, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
 
Field Summary
 
Fields inherited from class javax.swing.ImageIcon
component, tracker
 
Constructor Summary
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
 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 deg, 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 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
 

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
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


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 deg,
                   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'



Copyright © 1997 - 2011 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