Class IconStore


  • public class IconStore
    extends java.lang.Object
    Manages client icons. Images are cached where appropriate. A size may be supplied so that all icons returned by this object's methods are of a given standard size. Also provides some icon utility methods.
    Since:
    17 Nov 2008
    Author:
    Mark Taylor
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  IconStore.SizedIcon
      Icon implementation which looks like an existing one, but is resized down if necessary.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private javax.swing.Icon defaultIcon_  
      private static java.util.logging.Logger logger_  
      private static java.util.Map urlIconMap_  
    • Constructor Summary

      Constructors 
      Constructor Description
      IconStore​(javax.swing.Icon defaultIcon)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.Icon createEmptyIcon​(int size)
      Returns an icon with no content but a given size.
      static javax.swing.Icon createMinimalIcon​(int size)
      Returns an icon which indicates a shape but doesn't look like much.
      (package private) static javax.swing.Icon createResourceIcon​(java.lang.String fileName)
      Constructs an icon given a file name in the images directory.
      javax.swing.Icon getIcon​(java.lang.String url)
      Returns the icon supplied by the graphic file at a given URL.
      javax.swing.Icon getIcon​(Client client)
      Returns the icon associated with a given client.
      private static javax.swing.Icon readIcon​(java.lang.String url, int waitSecs)
      Reads an icon from a URL, with a maximum wait time.
      static javax.swing.Icon scaleIcon​(javax.swing.Icon icon, int fixDim, double maxAspect, boolean fixVertical)
      Icon implementation which is rescaled to so that one dimension (either width or height) has a fixed value.
      static javax.swing.Icon sizeIcon​(javax.swing.Icon icon, int size)
      Return an icon based on an existing one, but drawn to an exact size.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • defaultIcon_

        private final javax.swing.Icon defaultIcon_
      • urlIconMap_

        private static final java.util.Map urlIconMap_
      • logger_

        private static final java.util.logging.Logger logger_
    • Constructor Detail

      • IconStore

        public IconStore​(javax.swing.Icon defaultIcon)
        Constructor.
        Parameters:
        defaultIcon - icon returned if no client icon is available
    • Method Detail

      • getIcon

        public javax.swing.Icon getIcon​(java.lang.String url)
        Returns the icon supplied by the graphic file at a given URL. Icons are cached, so that repeated invocations with the same url are not expensive.
        Parameters:
        url - URL of image
        Returns:
        image icon, resized if appropriate
      • getIcon

        public javax.swing.Icon getIcon​(Client client)
        Returns the icon associated with a given client. This is either the icon described in its metadata or the default icon if there isn't one.
        Parameters:
        client - client whose icon is required
        Returns:
        associated icon, resized if appropriate
      • createEmptyIcon

        public static javax.swing.Icon createEmptyIcon​(int size)
        Returns an icon with no content but a given size.
        Parameters:
        size - edge size in pixels
        Returns:
        emtpy square icon
      • createMinimalIcon

        public static javax.swing.Icon createMinimalIcon​(int size)
        Returns an icon which indicates a shape but doesn't look like much. Currently it's a kind of open square.
        Parameters:
        size - dimension in pixels
        Returns:
        minimal icon
      • createResourceIcon

        static javax.swing.Icon createResourceIcon​(java.lang.String fileName)
        Constructs an icon given a file name in the images directory.
        Parameters:
        fileName - file name omitting directory
        Returns:
        icon
      • sizeIcon

        public static javax.swing.Icon sizeIcon​(javax.swing.Icon icon,
                                                int size)
        Return an icon based on an existing one, but drawn to an exact size.
        Parameters:
        icon - original icon, or null for blank
        size - number of horizontal and vertical pixels in output
        Returns:
        resized version of icon
      • scaleIcon

        public static javax.swing.Icon scaleIcon​(javax.swing.Icon icon,
                                                 int fixDim,
                                                 double maxAspect,
                                                 boolean fixVertical)
        Icon implementation which is rescaled to so that one dimension (either width or height) has a fixed value.
        Parameters:
        icon - input icon
        fixDim - the fixed dimension in pixels
        maxAspect - maximum aspect ratio (>= 1)
        fixVertical - true to fix height, false to fix width
      • readIcon

        private static javax.swing.Icon readIcon​(java.lang.String url,
                                                 int waitSecs)
                                          throws java.io.IOException
        Reads an icon from a URL, with a maximum wait time. If the timeout is exceeded, an exception will be thrown.
        Parameters:
        url - icon URL
        waitSecs - maximum time in seconds to wait
        Returns:
        icon from url
        Throws:
        java.io.IOException - if timeout has been exceeded