Example usage for java.awt Component getForeground

List of usage examples for java.awt Component getForeground

Introduction

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

Prototype

@Transient
public Color getForeground() 

Source Link

Document

Gets the foreground color of this component.

Usage

From source file:com.simiacryptus.util.Util.java

/**
 * To image buffered image./*from  w w w. jav  a  2  s.c  om*/
 *
 * @param component the component
 * @return the buffered image
 */
public static BufferedImage toImage(@javax.annotation.Nonnull final Component component) {
    try {
        com.simiacryptus.util.Util.layout(component);
        @javax.annotation.Nonnull
        final BufferedImage img = new BufferedImage(component.getWidth(), component.getHeight(),
                BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics2D g = img.createGraphics();
        g.setColor(component.getForeground());
        g.setFont(component.getFont());
        component.print(g);
        return img;
    } catch (@javax.annotation.Nonnull final Exception e) {
        return null;
    }
}

From source file:components.ArrowIcon.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c.isEnabled()) {
        g.setColor(c.getForeground());
    } else {/*from  ww  w  . j ava2 s. c o m*/
        g.setColor(Color.gray);
    }

    g.translate(x, y);
    g.fillPolygon(xPoints, yPoints, xPoints.length);
    g.translate(-x, -y); //Restore graphics object
}

From source file:CustomIconDemo.java

public void paintIcon(Component c, Graphics g, int x, int y) {
    if (c.isEnabled()) {
        g.setColor(c.getForeground());
    } else {/* w w w  . j  a v  a  2 s .  c  o m*/
        g.setColor(Color.gray);
    }

    g.translate(x, y);
    g.fillPolygon(xPoints, yPoints, xPoints.length);
    g.translate(-x, -y); // Restore graphics object
}

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 .  jav a2s.  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);
}