Class SquareIcon

  • All Implemented Interfaces:
    ResizableIcon, java.io.Serializable, java.lang.Cloneable, javax.accessibility.Accessible, javax.swing.Icon

    @OpenApiAll
    public final class SquareIcon
    extends ResizableIconImageIcon
    An icon which fits another icon into a square of given size.
    See Also:
    Serialized Form
    • Field Summary

      • Fields inherited from class javax.swing.ImageIcon

        component, tracker
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ResizableIcon fit​(ResizableIcon icon, int size)
      Convert given icon to a scaled icon which fits to a square of given size.
      static ResizableIcon fitOrCenter​(ResizableIcon icon, int size)
      Convert given icon to a scaled icon which fits to a square of given size.
      int getIconHeight()  
      int getIconWidth()  
      java.lang.Double getScale()  
      static double getScale​(javax.swing.Icon icon, int size)
      Utility method to calculate a scale factor of given icon if it needs to be fit into a square of given size.
      static java.awt.Dimension getScaleSize​(javax.swing.Icon icon, int size)
      Utility method to calculate dimension of given icon if it needs to be fit into a square of given size.
      void paintIcon​(java.awt.Component c, java.awt.Graphics g, int x, int y)  
      void paintIcon​(java.awt.Component c, java.awt.Graphics g, int x, int y, int w, int h)
      Draw the icon in the given bounds.
      static ResizableIcon scale​(ResizableIcon icon, double scale)
      Convert given icon to a scaled icon with given scale(zoom) factor.
      • Methods inherited from class javax.swing.ImageIcon

        getAccessibleContext, getDescription, getImageLoadStatus, getImageObserver, loadImage, setDescription, setImageObserver, toString
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • fit

        public static ResizableIcon fit​(ResizableIcon icon,
                                        int size)
        Convert given icon to a scaled icon which fits to a square of given size. Wrapped icon is zoomed in if icon is smaller than square.
        Parameters:
        icon - icon
        size - square size
        Returns:
        scaled icon
      • fitOrCenter

        public static ResizableIcon fitOrCenter​(ResizableIcon icon,
                                                int size)
        Convert given icon to a scaled icon which fits to a square of given size. Wrapped icon is not zoomed in if icon is smaller than square. Icon is zoomed out if it is larger than square. Icon will be painted in the center of the square.
        Parameters:
        icon - icon
        size - square size
        Returns:
        scaled icon
      • scale

        public static ResizableIcon scale​(ResizableIcon icon,
                                          double scale)
        Convert given icon to a scaled icon with given scale(zoom) factor.
        Parameters:
        icon - icon
        scale - scale factor
        Returns:
        scaled icon
      • getScaleSize

        public static java.awt.Dimension getScaleSize​(javax.swing.Icon icon,
                                                      int size)
        Utility method to calculate dimension of given icon if it needs to be fit into a square of given size.
        Parameters:
        icon - icon
        size - square size
        Returns:
        dimensions of icon to fit into a square
      • getScale

        public static double getScale​(javax.swing.Icon icon,
                                      int size)
        Utility method to calculate a scale factor of given icon if it needs to be fit into a square of given size.
        Parameters:
        icon - icon
        size - square size
        Returns:
        scale factor of icon to fit into a square
      • paintIcon

        public void paintIcon​(@CheckForNull
                              java.awt.Component c,
                              java.awt.Graphics g,
                              int x,
                              int y,
                              int w,
                              int h)
        Description copied from interface: ResizableIcon
        Draw the icon in the given bounds. Icon implementations may use the Component argument to get properties useful for painting, e.g. the foreground or background color.
        Specified by:
        paintIcon in interface ResizableIcon
        Overrides:
        paintIcon in class ScalableImageIcon
        Parameters:
        c - the given component.
        g - the graphics to paint on.
        x - x coordinate.
        y - y coordinate.
        w - width to paint.
        h - height to paint.
      • paintIcon

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

        public int getIconWidth()
        Specified by:
        getIconWidth in interface javax.swing.Icon
        Overrides:
        getIconWidth in class ScalableImageIcon
      • getIconHeight

        public int getIconHeight()
        Specified by:
        getIconHeight in interface javax.swing.Icon
        Overrides:
        getIconHeight in class ScalableImageIcon
      • getScale

        public java.lang.Double getScale()
        Returns:
        icon scale factor