private void paintImage()

in modules/swing/src/main/java/common/javax/swing/plaf/synth/ImagePainter.java [197:379]


    private void paintImage(SynthContext context, Graphics g, int x, int y,
            int w, int h) {

        // affineTransform coefficients
        double a;
        double b;

        // destinationInsets - size of side and corner tiles. Defined to
        // simplify readability
        int insetsTop = destinationInsets.top;
        int insetsLeft = destinationInsets.left;
        int insetsRight = destinationInsets.right;
        int insetsBottom = destinationInsets.bottom;

        // Define tiling parameters
        int sourceWidth = imageWidth - imageInsetsLeft - imageInsetsRight;
        int destWidth = w - insetsLeft - insetsRight;
        int fullHorisontalPaintsNum = (int) Math.ceil(destWidth / sourceWidth);
        int sourceHeight = imageHeight - imageInsetsBottom - imageInsetsTop;
        int destHeight = h - insetsTop - insetsBottom;
        int fullVerticalPaintsNum = (int) Math.ceil(destHeight / sourceHeight);

        // Define synth parameters
        // JComponent c = context.getComponent();
        // Color color = context.getStyle()
        // .getColor(context, ColorType.BACKGROUND);
        JComponent c = null;
        Color color = Color.RED;

        if ((insetsTop > 0)) {

            if ((insetsLeft > 0) && (imageParts[0][0] != null)) {

                g.drawImage(imageParts[0][0], x, y, insetsLeft, insetsTop,
                        color, c);

            }

            if ((w > insetsLeft - insetsRight) && (imageParts[0][1] != null)
                    && (insetsLeft >= 0)) {

                if (stretch) {
                    g.drawImage(imageParts[0][1], x + insetsLeft, y, w
                            - insetsLeft - insetsRight, insetsTop, c);

                } else {

                    // Stretch the image horizontally
                    b = (double) (insetsTop) / (double) (imageInsetsTop);
                    BufferedImage result = new AffineTransformOp(
                            new AffineTransform(1, 0, 0, b, 0, 0),
                            AffineTransformOp.TYPE_BICUBIC).filter(
                            imageParts[0][1], null);

                    // Draw multiple number of images
                    for (int i = 0; i < fullHorisontalPaintsNum + 1; i++) {
                        g.drawImage(result, x + insetsLeft + i * sourceWidth,
                                y, color, c);
                    }

                }
            }

            if ((insetsRight > 0) && (imageParts[0][2] != null)
                    && (w >= insetsRight)) {

                g.drawImage(imageParts[0][2], x + w - insetsRight, y,
                        insetsRight, insetsTop, color, c);
            }
        }

        if ((insetsLeft > 0) && (imageParts[1][0] != null) && (insetsTop >= 0)
                && (h > insetsTop + insetsBottom)) {

            if (stretch) {

                g.drawImage(imageParts[1][0], x, y + insetsTop, insetsLeft, h
                        - insetsTop - insetsBottom, color, c);
            } else {

                // Stretch the image vertically
                a = (double) (insetsRight) / (double) (imageInsetsRight);
                BufferedImage result = new AffineTransformOp(
                        new AffineTransform(a, 0, 0, 1, 0, 0),
                        AffineTransformOp.TYPE_BICUBIC).filter(
                        imageParts[1][0], null);

                // draw multiple number of pictures
                for (int i = 0; i < fullVerticalPaintsNum + 1; i++) {
                    g.drawImage(result, x, y + i * sourceHeight + insetsTop,
                            color, c);
                }

            }
        }

        if (paintCenter && (imageParts[1][1] != null)
                && (w > insetsLeft + insetsRight)
                && (h > insetsBottom + insetsTop)) {

            g.drawImage(imageParts[1][1], x + insetsLeft, y + insetsTop, w
                    - insetsLeft - insetsRight, h - insetsTop - insetsBottom,
                    color, c);

        }

        if ((insetsRight > 0) && (imageParts[1][2] != null)
                && (h > insetsBottom + insetsTop) && (w >= insetsRight)
                && (insetsTop >= 0)) {

            if (stretch) {

                g.drawImage(imageParts[1][2], x + w - insetsRight, y
                        + insetsTop, insetsRight, h - insetsTop - insetsBottom,
                        color, c);
            } else {

                // Stretch the image vertically
                a = (double) (insetsRight) / (double) (imageInsetsRight);
                BufferedImage result = new AffineTransformOp(
                        new AffineTransform(a, 0, 0, 1, 0, 0),
                        AffineTransformOp.TYPE_BICUBIC).filter(
                        imageParts[1][2], null);

                // draw multiple number of pictures
                for (int i = 0; i < fullVerticalPaintsNum + 1; i++) {
                    g.drawImage(result, x + w - insetsRight, y + i
                            * sourceHeight + insetsTop, color, c);
                }

            }
        }

        if ((insetsBottom > 0)) {

            if ((insetsLeft >= 0) && (h >= insetsBottom)
                    && (w > insetsRight + insetsLeft)
                    && (imageParts[2][0] != null)) {

                g.drawImage(imageParts[2][0], x, y + h - insetsBottom,
                        insetsLeft, insetsBottom, color, c);

            }

            if ((imageParts[2][1] != null) && (imageInsetsBottom > 0)
                    && (w > insetsRight + insetsLeft) && (insetsBottom > 0)
                    && (insetsLeft >= 0) && (h >= insetsBottom)) {

                if (stretch) {

                    g.drawImage(imageParts[2][1], x + insetsLeft, y + h
                            - insetsBottom, w - insetsRight - insetsLeft,
                            insetsBottom, color, c);
                } else {

                    // Stretch the image horizontally
                    b = (double) (insetsBottom) / (double) (imageInsetsBottom);
                    BufferedImage result = new AffineTransformOp(
                            new AffineTransform(1, 0, 0, b, 0, 0),
                            AffineTransformOp.TYPE_BICUBIC).filter(
                            imageParts[2][1], null);

                    // draw multiple number of pictures
                    for (int i = 0; i < fullHorisontalPaintsNum + 1; i++) {
                        g.drawImage(result, x + insetsLeft + i * sourceWidth, y
                                + h - insetsBottom, color, c);
                    }

                }

            }

            if ((insetsRight > 0) && (imageParts[2][2] != null)
                    && (insetsBottom > 0) && (w >= insetsRight)
                    && (h >= insetsBottom) && (imageInsetsBottom > 0)) {

                g.drawImage(imageParts[2][2], x + w - insetsRight, y + h
                        - insetsBottom, insetsRight, insetsBottom, color, c);

            }
        }

    }