Class VectorIcon

  • All Implemented Interfaces:
    javax.swing.Icon

    public class VectorIcon
    extends java.lang.Object
    implements javax.swing.Icon
    An icon that is drawn from a VectorImage.
    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Summary

      Constructors 
      Constructor Description
      VectorIcon​(VectorImage vectorImage, int iconWidth, int iconHeight, boolean fitToSize)  
      VectorIcon​(java.net.URL imageURL)  
      VectorIcon​(java.net.URL imageURL, int iconWidth, int iconHeight)  
      VectorIcon​(java.net.URL imageURL, int iconWidth, int iconHeight, boolean fitToSize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      VectorIcon derive​(int newWidth, int newHeight)
      Returns a new vector icon for the same image as this icon, but with a different icon size.
      int getIconHeight()
      Returns the height of this icon.
      int getIconWidth()
      Returns the width of this icon.
      VectorImage getImage()
      Returns the vector image painted by this icon.
      boolean isImageFittingEnabled()
      Returns true if the image's aspect ratio will be maintained by fitting it within the icon width and height.
      void paintIcon​(java.awt.Component c, java.awt.Graphics g, int x, int y)  
      void setIconHeight​(int height)
      Sets the height of this icon.
      void setIconWidth​(int width)
      Sets the width of this icon.
      void setImageFittingEnabled​(boolean fit)
      Sets whether the image's aspect ratio will be maintained by fitting it within the icon width and height.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • VectorIcon

        public VectorIcon​(java.net.URL imageURL)
      • VectorIcon

        public VectorIcon​(java.net.URL imageURL,
                          int iconWidth,
                          int iconHeight)
      • VectorIcon

        public VectorIcon​(java.net.URL imageURL,
                          int iconWidth,
                          int iconHeight,
                          boolean fitToSize)
      • VectorIcon

        public VectorIcon​(VectorImage vectorImage,
                          int iconWidth,
                          int iconHeight,
                          boolean fitToSize)
    • Method Detail

      • paintIcon

        public void paintIcon​(java.awt.Component c,
                              java.awt.Graphics g,
                              int x,
                              int y)
        Specified by:
        paintIcon in interface javax.swing.Icon
      • getIconWidth

        public final int getIconWidth()
        Returns the width of this icon. This is the width occupied by the icon in an interface layout.
        Specified by:
        getIconWidth in interface javax.swing.Icon
        Returns:
        the width of the icon
        See Also:
        setIconWidth(int)
      • setIconWidth

        public final void setIconWidth​(int width)
        Sets the width of this icon. This is the width occupied by the icon in an interface layout.
        Parameters:
        width - the new icon width
        See Also:
        getIconWidth()
      • getIconHeight

        public final int getIconHeight()
        Returns the height of this icon. This is the height occupied by the icon in an interface layout.
        Specified by:
        getIconHeight in interface javax.swing.Icon
        Returns:
        the height of the icon
        See Also:
        setIconHeight(int)
      • setIconHeight

        public final void setIconHeight​(int height)
        Sets the height of this icon. This is the height occupied by the icon in an interface layout.
        Parameters:
        height - the new icon width
        See Also:
        getIconHeight()
      • isImageFittingEnabled

        public final boolean isImageFittingEnabled()
        Returns true if the image's aspect ratio will be maintained by fitting it within the icon width and height.
        Returns:
        true if the painted area will pad one dimension, if necessary, to maintain the original image's aspect ratio
        See Also:
        setImageFittingEnabled(boolean)
      • setImageFittingEnabled

        public final void setImageFittingEnabled​(boolean fit)
        Sets whether the image's aspect ratio will be maintained by fitting it within the icon width and height.
        Parameters:
        fit - if true the painted area will be padded in one dimension, if necessary, to maintain the original image's aspect ratio
        See Also:
        setImageFittingEnabled(boolean)
      • getImage

        public final VectorImage getImage()
        Returns the vector image painted by this icon.
        Returns:
        the vector image used to create the icon
      • derive

        public final VectorIcon derive​(int newWidth,
                                       int newHeight)
        Returns a new vector icon for the same image as this icon, but with a different icon size. A new icon is always returned, even if the new size is equal to this icon's size.
        Parameters:
        newWidth - the new icon width
        newHeight - the new icon height
        Returns:
        an icon identical to this icon, except for having the newly specified icon dimensions
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object