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

The following examples show how to use java.awt.Color#getGreen() . These examples are extracted from open source projects. 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
private void drawObjectLocation(Graphics2D graphics, TileObject object, Color color)
{
	if (object == null)
	{
		return;
	}

	if (config.showClickBoxes())
	{
		Shape clickbox = object.getClickbox();
		if (clickbox != null)
		{
			Color clickBoxColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 20);

			graphics.setColor(color);
			graphics.draw(clickbox);
			graphics.setColor(clickBoxColor);
			graphics.fill(clickbox);
		}
	}
	else
	{
		OverlayUtil.renderTileOverlay(graphics, object, "", color);
	}
}
 
Example 2
/**
 * Sets the <code>Paint</code> attribute for the <code>Graphics2D</code> context. Calling this method with a
 * <code>null</code> <code>Paint</code> object does not have any effect on the current <code>Paint</code> attribute of
 * this <code>Graphics2D</code>.
 *
 * @param paint
 *          the <code>Paint</code> object to be used to generate color during the rendering process, or
 *          <code>null</code>
 * @see java.awt.Graphics#setColor
 * @see #getPaint
 * @see java.awt.GradientPaint
 * @see java.awt.TexturePaint
 */
public void setPaint( final Paint paint ) {
  if ( paint == null ) {
    return;
  }
  this.paint = paint;
  realPaint = paint;

  if ( ( composite instanceof AlphaComposite ) && ( paint instanceof Color ) ) {

    final AlphaComposite co = (AlphaComposite) composite;

    if ( co.getRule() == 3 ) {
      final Color c = (Color) paint;
      this.paint = new Color( c.getRed(), c.getGreen(), c.getBlue(), (int) ( (float) c.getAlpha() * alpha ) );
      realPaint = paint;
    }
  }
}
 
Example 3
/** Add a highlighted region based on the positions in an Info object. */
private void addHighlight(Highlighter h, Info info, Color c) {
    int start = info.start;
    int end = info.end;
    if (start == -1 && end == -1)
        return;
    if (start == -1)
        start = end;
    if (end == -1)
        end = start;
    try {
        h.addHighlight(info.start, info.end,
                new DefaultHighlighter.DefaultHighlightPainter(c));
        if (info.pos != -1) {
            Color c2 = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int)(.4f * 255)); // 40%
            h.addHighlight(info.pos, info.pos + 1,
                new DefaultHighlighter.DefaultHighlightPainter(c2));
        }
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
 
Example 4
protected int getBranchIndex(Color aColor, int aLevel) {
    if (aLevel > MAXLEVEL || aLevel < 0) {
        throw new IllegalArgumentException("Invalid octree node depth: " +
                                           aLevel);
    }

    int shift = MAXLEVEL - aLevel;
    int red_index = 0x1 & ((0xff & aColor.getRed()) >> shift);
    int green_index = 0x1 & ((0xff & aColor.getGreen()) >> shift);
    int blue_index = 0x1 & ((0xff & aColor.getBlue()) >> shift);
    int index = (red_index << 2) | (green_index << 1) | blue_index;
    return index;
}
 
Example 5
Source Project: ghidra   File: DecompilerClangTest.java    License: Apache License 2.0 5 votes vote down vote up
private String toString(Color c) {
	if (c == null) {
		return "Color{null}";
	}
	int r = c.getRed();
	int g = c.getGreen();
	int b = c.getBlue();
	int a = c.getAlpha();
	// "Color[r=" + r +",g=" + g  +",b=" + b + ",a="+ a + "]"
	// "Color[r=%s,g=%s,b=%s,a=%s]"
	String formatted = String.format("Color{%s, %s, %s, %s}", r, g, b, a);
	return formatted;
}
 
Example 6
public ColorMapper(Color from,
		Color to) {
	super(0, 4);

	this.from = new int[]{
		from.getRed(),
		from.getGreen(),
		from.getBlue(),
		from.getAlpha(),};
	this.to = new int[]{
		to.getRed(),
		to.getGreen(),
		to.getBlue(),
		to.getAlpha(),};
}
 
Example 7
/**
 * Returns a string representation of this <code>Color</code>. This method
 * is intended to be used only for debugging purposes. The content and
 * format of the returned string might vary between implementations. The
 * returned string might be empty but cannot be <code>null</code>.
 *
 * @return a String representation of this <code>Color</code>.
 */
@Override
public String toString() {
    Color src = UIManager.getColor(uiDefaultParentName);
    String s = "DerivedColor(color=" + getRed() + "," + getGreen() + "," + getBlue() +
            " parent=" + uiDefaultParentName +
            " offsets=" + getHueOffset() + "," + getSaturationOffset() + ","
            + getBrightnessOffset() + "," + getAlphaOffset();
    return src == null ? s : s + " pColor=" + src.getRed() + "," + src.getGreen() + "," + src.getBlue();
}
 
Example 8
/**
 * Convert a color to its hex representation.
 * 
 * @param color the color to convert.
 * @return the hex.
 */
public static String asHex( Color color ) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();

    String hex = String.format("#%02x%02x%02x", r, g, b);
    return hex;
}
 
Example 9
Source Project: SVNToolBox   File: SvnToolBoxAppState.java    License: Apache License 2.0 5 votes vote down vote up
public void setRegularDecorationColor(boolean enabled, Color color) {
    customRegularColor = enabled;
    if (enabled) {
        regularR = color.getRed();
        regularG = color.getGreen();
        regularB = color.getBlue();
    }
}
 
Example 10
Source Project: MyBox   File: ImageQuantization.java    License: Apache License 2.0 5 votes vote down vote up
public int colorIndex(Color color, int level) {
    // Take 1 bit from each averageColor channel
    // to return a 3-bit value ranging from 0 to 7.
    // Level 0 uses the highest bit, level 1 uses the second-highest bit, etc.
    int shift = (7 - level);
    return (((color.getRed() & Mask[level]) >> shift)
            | ((color.getGreen() & Mask[level]) << 1 >> shift)
            | ((color.getBlue() & Mask[level]) << 2 >> shift));
}
 
Example 11
private static int findLuminance(final Color color, final int brightness) {
  int lum =
      (int)
          (color.getRed() * LUMINANCE_RED
              + color.getGreen() * LUMINANCE_GREEN
              + color.getBlue() * LUMINANCE_BLUE);
  if (brightness > 0) {
    lum = (int) (lum * (100f - brightness) / 100f);
    lum = (int) (lum + (255f - (100f - brightness) * 255f / 100f));
  } else if (brightness < 0) {
    lum = (int) ((lum * (brightness + 100f)) / 100f);
  }
  return lum;
}
 
Example 12
Source Project: neodymium-library   File: ImageHelper.java    License: MIT License 5 votes vote down vote up
/**
 * Colors a certain pixel using getComplementaryColor. Works directly on imgOut.
 * 
 * @param image
 *            the original image for which certain pixels should be marked
 * @param x
 *            the x coordinate of the pixel to color
 * @param y
 *            the y coordinate of the pixel to color
 * @param c
 *            the color
 */
protected static void colorPixel(final BufferedImage image, final int x, final int y, final Color c)
{
    Color newColor;

    if (c == null)
    {
        final Color currentColor = new Color(image.getRGB(x, y));
        final double redLimit = 0.8;

        final int nonRedSum = currentColor.getGreen() + currentColor.getBlue();
        final double results = nonRedSum > 0 ? currentColor.getRed() / nonRedSum : 0;

        if (results > redLimit)
        {
            // red is strong in that one
            newColor = Color.GREEN;
        }
        else
        {
            newColor = Color.RED;
        }
    }
    else
    {
        newColor = c;
    }

    image.setRGB(x, y, newColor.getRGB());
}
 
Example 13
/**
 * Set the non-stroking color using an AWT color. Conversion uses the default sRGB color space.
 *
 * @param color The color to set.
 * @throws IOException If an IO error occurs while writing to the stream.
 */
public void setNonStrokingColor(Color color) throws IOException
{
    float[] components = new float[] {
            color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f };
    PDColor pdColor = new PDColor(components, PDDeviceRGB.INSTANCE);
    setNonStrokingColor(pdColor);
}
 
Example 14
public void drawTextAndDecorations(Label label,
                            Graphics2D g2d,
                            float x,
                            float y) {

    if (fgPaint == null && bgPaint == null && swapColors == false) {
        drawTextAndEmbellishments(label, g2d, x, y);
    }
    else {
        Paint savedPaint = g2d.getPaint();
        Paint foreground, background;

        if (swapColors) {
            background = fgPaint==null? savedPaint : fgPaint;
            if (bgPaint == null) {
                if (background instanceof Color) {
                    Color bg = (Color)background;
                    // 30/59/11 is standard weights, tweaked a bit
                    int brightness = 33 * bg.getRed()
                        + 53 * bg.getGreen()
                        + 14 * bg.getBlue();
                    foreground = brightness > 18500 ? Color.BLACK : Color.WHITE;
                } else {
                    foreground = Color.WHITE;
                }
            } else {
                foreground = bgPaint;
            }
        }
        else {
            foreground = fgPaint==null? savedPaint : fgPaint;
            background = bgPaint;
        }

        if (background != null) {

            Rectangle2D bgArea = label.getLogicalBounds();
            bgArea = new Rectangle2D.Float(x + (float)bgArea.getX(),
                                        y + (float)bgArea.getY(),
                                        (float)bgArea.getWidth(),
                                        (float)bgArea.getHeight());

            g2d.setPaint(background);
            g2d.fill(bgArea);
        }

        g2d.setPaint(foreground);
        drawTextAndEmbellishments(label, g2d, x, y);
        g2d.setPaint(savedPaint);
    }
}
 
Example 15
static BufferedImage replaceColor(BufferedImage image) {
    Map<Integer, Integer> colors = new HashMap<>();
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            int col = image.getRGB(x, y);
            if(!colors.containsKey(col)) {
                
                Color c = new Color( (col & 0x00ff0000) >> 16,
                                     (col & 0x0000ff00) >> 8,
                                     (col & 0x000000ff) >> 0);
                int newColor = col;
                /*
                int rgb = col & 0x00FFFFFF;
                String sColor = Integer.toHexString(rgb);
                if(sColor.startsWith("a") || sColor.startsWith("e") ||
                   sColor.startsWith("c") || sColor.startsWith("1") ||
                   sColor.startsWith("b8") || sColor.startsWith("76") ) {
                    newColor = (col & 0xff000000); 
                    newColor = newColor | ((col & 0x00ff0000) >> 24); 
                    newColor = newColor | ((col & 0x0000ff00) >> 0);
                    newColor = newColor | ((col & 0x000000ff) << 16);
                    
                    newColor = 0x00;
                }*/
                
                int fuzzy = 20;
                if( Math.abs(c.getRed() - c.getBlue()) < fuzzy &&
                    Math.abs(c.getRed() - c.getGreen()) < fuzzy &&
                    Math.abs(c.getBlue() - c.getGreen()) < fuzzy ) {
                    
                    newColor = (col & 0xff000000); 
                    newColor = newColor | ((Math.min(c.getRed() + 15, 255)) << 16); 
                    newColor = newColor | ((Math.min(c.getGreen() + 25, 255)) << 8);
                    newColor = newColor | ((Math.max(c.getBlue() - 30, 0)) << 0);
                    //newColor = 0x00;
                }
                
                
                fuzzy = 30;
                if( c.getRed() - c.getBlue() > fuzzy &&
                    c.getRed() - c.getGreen() > fuzzy) {
                    
                    newColor = (col & 0xff000000); 
                    newColor = newColor | ((Math.max(c.getRed() - 110, 0)) << 16); 
                    newColor = newColor | ((Math.min(c.getGreen() + 55, 255)) << 8);
                    newColor = newColor | ((Math.min(c.getBlue() + 20, 255)) << 0);
                    //newColor = 0x00;
                }
                
                
                fuzzy = 30;
                if( c.getGreen() - c.getRed() > 9 &&
                    c.getGreen() - c.getRed() < 25 &&
                    
                    c.getGreen() - c.getBlue() > 25 &&
                    c.getGreen() - c.getBlue() < 40 &&
                    
                    c.getRed() - c.getBlue() >= 15) {
                    
                    newColor = (col & 0xff000000); 
                    newColor = newColor | ((Math.max(c.getRed() - 40, 0)) << 16); 
                    newColor = newColor | ((Math.max(c.getGreen() - 55, 0)) << 8);
                    newColor = newColor | ((Math.max(c.getBlue() - 65, 0)) << 0);
                    //newColor = 0x00;
                }
                
                colors.put(col, newColor);
            }
        }
    }
    
    List<String> cStrs = new ArrayList<>();
    
    Set<String> ss = new HashSet<>();
    for(Integer color : colors.keySet()) {
        int rgb = color & 0x00FFFFFF;
        //cStrs.add(Integer.toHexString(rgb));
        ss.add(Integer.toHexString(rgb));
        //System.out.println(Integer.toHexString(rgb)); 
    //Integer.toString(color, 16));
    }
    
    cStrs.addAll(ss);
    Collections.sort(cStrs);
    
    for(String s : cStrs) {
        System.out.println(s + " : " + Integer.valueOf(s, 16));
    }
    
    return drawImage(colors, image);
}
 
Example 16
Source Project: littleluck   File: Utilities.java    License: Apache License 2.0 4 votes vote down vote up
public static Color deriveColorAlpha(Color base, int alpha) {
    return new Color(base.getRed(), base.getGreen(), base.getBlue(), alpha);
}
 
Example 17
public static Component loadArray(Object value) {
    Component comp = null;
    if (isViewableValue(value)) {
        Object[] arr;
        if (value instanceof Collection) {
            arr = ((Collection<?>) value).toArray();
        } else if (value instanceof Map) {
            arr = ((Map<?,?>) value).entrySet().toArray();
        } else if (value instanceof Object[]) {
            arr = (Object[]) value;
        } else {
            int length = Array.getLength(value);
            arr = new Object[length];
            for (int i = 0; i < length; i++) {
                arr[i] = Array.get(value, i);
            }
        }
        JEditorPane arrayEditor = new JEditorPane();
        arrayEditor.setContentType("text/html");
        arrayEditor.setEditable(false);
        Color evenRowColor = arrayEditor.getBackground();
        int red = evenRowColor.getRed();
        int green = evenRowColor.getGreen();
        int blue = evenRowColor.getBlue();
        String evenRowColorStr =
                "rgb(" + red + "," + green + "," + blue + ")";
        Color oddRowColor = new Color(
                red < 20 ? red + 20 : red - 20,
                green < 20 ? green + 20 : green - 20,
                blue < 20 ? blue + 20 : blue - 20);
        String oddRowColorStr =
                "rgb(" + oddRowColor.getRed() + "," +
                oddRowColor.getGreen() + "," +
                oddRowColor.getBlue() + ")";
        Color foreground = arrayEditor.getForeground();
        String textColor = String.format("%06x",
                                         foreground.getRGB() & 0xFFFFFF);
        StringBuilder sb = new StringBuilder();
        sb.append("<html><body text=#"+textColor+"><table width=\"100%\">");
        for (int i = 0; i < arr.length; i++) {
            if (i % 2 == 0) {
                sb.append("<tr style=\"background-color: " +
                        evenRowColorStr + "\"><td><pre>" +
                        (arr[i] == null ?
                            arr[i] : htmlize(arr[i].toString())) +
                        "</pre></td></tr>");
            } else {
                sb.append("<tr style=\"background-color: " +
                        oddRowColorStr + "\"><td><pre>" +
                        (arr[i] == null ?
                            arr[i] : htmlize(arr[i].toString())) +
                        "</pre></td></tr>");
            }
        }
        if (arr.length == 0) {
            sb.append("<tr style=\"background-color: " +
                    evenRowColorStr + "\"><td></td></tr>");
        }
        sb.append("</table></body></html>");
        arrayEditor.setText(sb.toString());
        JScrollPane scrollp = new JScrollPane(arrayEditor);
        comp = scrollp;
    }
    return comp;
}
 
Example 18
Source Project: netbeans   File: ColorEditor.java    License: Apache License 2.0 4 votes vote down vote up
SuperColor (String id, int palette, Color color) {
    super (color.getRed (), color.getGreen (), color.getBlue ());
    this.color = color;
    this.id = id;
    this.palette = palette;
}
 
Example 19
static int[] getRGBvals(Color c) {

        int rgbvals[] = new int[3];

        rgbvals[0] = c.getRed();
        rgbvals[1] = c.getGreen();
        rgbvals[2] = c.getBlue();

        return rgbvals;
    }
 
Example 20
Source Project: htmlunit   File: StringUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Formats the specified color.
 *
 * @param aColor the color to format
 * @return the specified color, formatted
 */
public static String formatColor(final Color aColor) {
    return "rgb(" + aColor.getRed() + ", " + aColor.getGreen() + ", " + aColor.getBlue() + ")";
}