protected void calcSize() {
        if (image != null) {
            imgWidth = image.getWidth(null);
            imgHeight = image.getHeight(null);

            if (getWidth() != 0 && getHeight() != 0) {
                int w = getWidth() - imgWidth;
                int h = getHeight() - imgHeight;

                if (w < 0 || h < 0) {
                    if (h < w) {
                        imgWidth = imgWidth * getHeight() / imgHeight;
                        imgHeight = getHeight();
                    } else {
                        imgHeight = imgHeight * getWidth() / imgWidth;
                        imgWidth = getWidth();
                    }
                }
            }
        } else {
            imgWidth = 0;
            imgHeight = 0;
        }
    }