Example usage for java.awt Component createImage

List of usage examples for java.awt Component createImage

Introduction

In this page you can find the example usage for java.awt Component createImage.

Prototype

public Image createImage(ImageProducer producer) 

Source Link

Document

Creates an image from the specified image producer.

Usage

From source file:util.ui.PictureAreaIcon.java

public void paintIcon(final Component c, Graphics g, int x, int y) {
    if (mScaledIcon == null) {
        return;//from w  ww . j  a  v  a 2  s .  c o m
    }

    y += 2;

    Color color = g.getColor();

    if (!colorsInEqualRange(c.getBackground(), c.getForeground()) && !mProgram.isExpired()) {
        g.setColor(c.getBackground());
        g.fillRect(x, y, getIconWidth(), getIconHeight() - 2);
    }

    g.setColor(color);
    g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 3);

    y += 3;
    x += 3;

    if (mIsGrayFilter && !mIsExpired && mProgram.isExpired()) {
        ImageFilter filter = new GrayFilter(true, 60);
        mScaledIcon
                .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter)));
        mIsExpired = true;
    }

    if (c.getForeground().getAlpha() != 255) {
        ImageFilter filter = new RGBImageFilter() {
            public int filterRGB(int x, int y, int rgb) {
                if ((rgb & 0xff000000) != 0) {
                    return (rgb & 0xffffff) | (c.getForeground().getAlpha() << 24);
                }
                return rgb;
            }
        };

        mScaledIcon
                .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter)));
    }

    mScaledIcon.paintIcon(c, g, x, y);

    /*
    if(!mProgram.isExpired()) {
      g.setColor(color);
    } else {
      g.setColor(color);
    }
    */
    mCopyrightText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight());
    if (mDescriptionLines > 0 && mDescriptionText != null) {
        mDescriptionText.paintIcon(null, g, x,
                y + mScaledIcon.getIconHeight() + mCopyrightText.getIconHeight() + 1);
    }
    g.setColor(color);
}