private static double getIconRatio(BufferedImage originalImage,
            BufferedImage icon)
    {
        double ratio=1;

        if (originalImage.getWidth()>icon.getWidth())
        {
            ratio=(double)(icon.getWidth())/originalImage.getWidth();
        }
        else
        {
            ratio=icon.getWidth()/originalImage.getWidth();
        }
        if (originalImage.getHeight()>icon.getHeight())
        {
            double r2=(double)(icon.getHeight())/originalImage.getHeight();

            if (r2<ratio)
            {
                ratio=r2;
            }
        }
        else
        {
            double r2=icon.getHeight()/originalImage.getHeight();

            if (r2<ratio)
            {
                ratio=r2;
            }
        }

        return ratio;
    }