Java Code Examples for java.awt.Color#getRGB()

The following examples show how to use java.awt.Color#getRGB() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultTreeCellRenderer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example 2
Source File: DefaultTreeCellRenderer.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example 3
Source File: ImageQuantization.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@Override
public Color operateColor(Color color) {
    if (color.getRGB() == 0) {
        return color;
    }
    int red, green, blue;

    int v = color.getRed();
    v = v - (v % redMod) + redOffset;
    red = Math.min(Math.max(v, 0), 255);

    v = color.getGreen();
    v = v - (v % greenMod) + greenOffset;
    green = Math.min(Math.max(v, 0), 255);

    v = color.getBlue();
    v = v - (v % blueMod) + blueOffset;
    blue = Math.min(Math.max(v, 0), 255);

    Color mappedColor = new Color(red, green, blue);
    countColor(mappedColor);
    return mappedColor;

}
 
Example 4
Source File: DefaultTreeCellRenderer.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void paintFocus(Graphics g, int x, int y, int w, int h, Color notColor) {
    Color       bsColor = getBorderSelectionColor();

    if (bsColor != null && (selected || !drawDashedFocusIndicator)) {
        g.setColor(bsColor);
        g.drawRect(x, y, w - 1, h - 1);
    }
    if (drawDashedFocusIndicator && notColor != null) {
        if (treeBGColor != notColor) {
            treeBGColor = notColor;
            focusBGColor = new Color(~notColor.getRGB());
        }
        g.setColor(focusBGColor);
        BasicGraphicsUtils.drawDashedRect(g, x, y, w, h);
    }
}
 
Example 5
Source File: CFadingColorGenerator.java    From binnavi with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the next color for a given object.
 *
 * @param object The object whose next color is determined.
 *
 * @return The next color of the object.
 */
public Color next(final T object) {
  if (!m_objects.containsKey(object)) {
    m_objects.put(object, Color.GREEN);

    return Color.GREEN;
  }

  final Color oldColor = m_objects.get(object);

  final int newLowest = Math.min((oldColor.getRGB() & 0xFF) + 0x40, 0xFF) & 0xFF;

  final int newMiddle = Math.min((oldColor.getRGB() & 0xFF0000) + 0x400000, 0xFF0000) & 0xFF0000;

  final Color newColor = new Color((oldColor.getRGB() & 0x00FF00) + newMiddle + newLowest);

  if (newColor == Color.WHITE) {
    m_objects.remove(object);
  } else {
    m_objects.put(object, newColor);
  }

  return newColor;
}
 
Example 6
Source File: ColorCustomizationTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void check(Color c) {
    SwingUtilities.updateComponentTreeUI(label);
    label.paint(g);
    if (label.getBackground().getRGB() != c.getRGB()) {
        System.err.println("Color mismatch!");
        System.err.println("   found: " + label.getBackground());
        System.err.println("   expected: " + c);
        throw new RuntimeException("Test failed");
    }
}
 
Example 7
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * DOCUMENT ME!
 *
 * @param  c DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private Color unwrap(Color c) {
    if (c instanceof UIResource) {
        return new Color(c.getRGB());
    }

    return c;
}
 
Example 8
Source File: BarcodeInter25.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/** Creates a <CODE>java.awt.Image</CODE>. This image only
 * contains the bars without any text.
 * @param foreground the color of the bars
 * @param background the color of the background
 * @return the image
 */    
public java.awt.Image createAwtImage(Color foreground, Color background) {
    int f = foreground.getRGB();
    int g = background.getRGB();
    Canvas canvas = new Canvas();

    String bCode = keepNumbers(code);
    if (generateChecksum)
        bCode += getChecksum(bCode);
    int len = bCode.length();
    int nn = (int)n;
    int fullWidth = len * (3 + 2 * nn) + (6 + nn );
    byte bars[] = getBarsInter25(bCode);
    boolean print = true;
    int ptr = 0;
    int height = (int)barHeight;
    int pix[] = new int[fullWidth * height];
    for (int k = 0; k < bars.length; ++k) {
        int w = (bars[k] == 0 ? 1 : nn);
        int c = g;
        if (print)
            c = f;
        print = !print;
        for (int j = 0; j < w; ++j)
            pix[ptr++] = c;
    }
    for (int k = fullWidth; k < pix.length; k += fullWidth) {
        System.arraycopy(pix, 0, pix, k, fullWidth); 
    }
    Image img = canvas.createImage(new MemoryImageSource(fullWidth, height, pix, 0, fullWidth));
    
    return img;
}
 
Example 9
Source File: ColorCustomizationTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
void check(Color c) {
    SwingUtilities.updateComponentTreeUI(label);
    label.paint(g);
    if (label.getBackground().getRGB() != c.getRGB()) {
        System.err.println("Color mismatch!");
        System.err.println("   found: " + label.getBackground());
        System.err.println("   expected: " + c);
        throw new RuntimeException("Test failed");
    }
}
 
Example 10
Source File: MarvinImage.java    From marvinproject with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Draws a rectangle in the image. It�s useful for debugging purposes.
 * @param x		rect�s start position in x-axis
 * @param y		rect�s start positioj in y-axis
 * @param w		rect�s width
 * @param h		rect�s height
 * @param c		rect�s color
 */
public void drawRect(int x, int y, int w, int h, Color c){
	int color = c.getRGB();
	for(int i=x; i<x+w; i++){
		setIntColor(i, y, color);
		setIntColor(i, y+(h-1), color);
	}
	
	for(int i=y; i<y+h; i++){
		setIntColor(x, i, color);
		setIntColor(x+(w-1), i, color);
	}
}
 
Example 11
Source File: MetaData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    Color color = (Color) oldInstance;
    Object[] args = new Object[] {color.getRGB()};
    return new Expression(color, ColorUIResource.class, "new", args);
}
 
Example 12
Source File: ImageUtil.java    From opentest with MIT License 4 votes vote down vote up
/**
 * Compare two images and return an image that shows the differences and the
 * similarity between them, as a percent.
 */
public static ImageCompareResult compare(BufferedImage templateImage, BufferedImage imageToCompare, Double maxPercentColorDistance, Color ignoredPixelsColor) {
    try {
        if (maxPercentColorDistance == null) {
            maxPercentColorDistance = 0.15;
        }

        BufferedImage diffImage = new BufferedImage(
                Math.min(templateImage.getWidth(), imageToCompare.getWidth()),
                Math.min(templateImage.getHeight(), imageToCompare.getHeight()),
                BufferedImage.TYPE_3BYTE_BGR);

        double maxColorDistance = Math.sqrt(
                Math.pow(255, 2)
                + Math.pow(255, 2)
                + Math.pow(255, 2));

        long diffPixelCount = 0;
        int red = Color.RED.getRGB();
        int gray = Color.LIGHT_GRAY.getRGB();
        int reallyLightGray = Color.decode("#FAFAFA").getRGB();

        for (int x = 0; x < diffImage.getWidth(); x++) {
            for (int y = 0; y < diffImage.getHeight(); y++) {
                int color1 = templateImage.getRGB(x, y);
                int red1 = (color1 >> 16) & 0x000000FF;
                int green1 = (color1 >> 8) & 0x000000FF;
                int blue1 = (color1) & 0x000000FF;
 
                int color2 = imageToCompare.getRGB(x, y);
                int red2 = (color2 >> 16) & 0x000000FF;
                int green2 = (color2 >> 8) & 0x000000FF;
                int blue2 = (color2) & 0x000000FF;
                
                if (ignoredPixelsColor != null) {
                    int ignoredColor = ignoredPixelsColor.getRGB();
                    if (color1 == ignoredColor || color2 == ignoredColor) {
                        diffImage.setRGB(x, y, reallyLightGray);
                        continue;
                    }
                }

                double colorDistance = Math.sqrt(
                        Math.pow(red1 - red2, 2)
                        + Math.pow(green1 - green2, 2)
                        + Math.pow(blue1 - blue2, 2));
                double percentDistance = colorDistance / maxColorDistance;

                // Make new color of the pixel either red or light gray,
                // depending on how different the actual screen capture was
                // from the reference image.
                if (percentDistance >= maxPercentColorDistance) {
                    diffPixelCount++;
                    diffImage.setRGB(x, y, red);
                } else if (percentDistance > 0.01) {
                    diffImage.setRGB(x, y, gray);
                } else {
                    diffImage.setRGB(x, y, reallyLightGray);
                }
            }
        }

        double similarity = 1 - ((double) diffPixelCount / (diffImage.getWidth() * diffImage.getHeight()));
        return new ImageCompareResult(diffImage, similarity, diffPixelCount);
    } catch (Exception exc) {
        throw new RuntimeException(exc);
    }
}
 
Example 13
Source File: ColorUIResource.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public ColorUIResource(Color c) {
    super(c.getRGB(), (c.getRGB() & 0xFF000000) != 0xFF000000);
}
 
Example 14
Source File: SynthTableUI.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private Color unwrap(Color c) {
    if (c instanceof UIResource) {
        return new Color(c.getRGB());
    }
    return c;
}
 
Example 15
Source File: SynthTableUI.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private Color unwrap(Color c) {
    if (c instanceof UIResource) {
        return new Color(c.getRGB());
    }
    return c;
}
 
Example 16
Source File: VirtualNetworkLayer.java    From amodeus with GNU General Public License v2.0 4 votes vote down vote up
private static Color halfAlpha(Color color) {
    int rgb = color.getRGB() & 0xffffff;
    int alpha = color.getAlpha() / 2;
    return new Color(rgb | (alpha << 24), true);
}
 
Example 17
Source File: ColorUIResource.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public ColorUIResource(Color c) {
    super(c.getRGB(), (c.getRGB() & 0xFF000000) != 0xFF000000);
}
 
Example 18
Source File: SynthTableUI.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private Color unwrap(Color c) {
    if (c instanceof UIResource) {
        return new Color(c.getRGB());
    }
    return c;
}
 
Example 19
Source File: ColorUIResource.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs a {@code ColorUIResource}.
 * @param c the color
 */
public ColorUIResource(Color c) {
    super(c.getRGB(), (c.getRGB() & 0xFF000000) != 0xFF000000);
}
 
Example 20
Source File: ColorUIResource.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Constructs a {@code ColorUIResource}.
 * @param c the color
 */
public ColorUIResource(Color c) {
    super(c.getRGB(), (c.getRGB() & 0xFF000000) != 0xFF000000);
}