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

The following examples show how to use java.awt.Color#getGreen() . 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: CheckAttributedTree.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** 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 2
Source File: HerbiboarOverlay.java    From plugins with GNU General Public License v3.0 6 votes vote down vote up
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 3
Source File: AbstractGraphics2D.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 4
Source File: DecompilerClangTest.java    From ghidra with 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 5
Source File: PDAbstractContentStream.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 6
Source File: ImageHelper.java    From neodymium-library with 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 7
Source File: ImageTransformer.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
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 8
Source File: ImageQuantization.java    From MyBox with 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 9
Source File: SvnToolBoxAppState.java    From SVNToolBox with 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 File: ColorUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 11
Source File: DerivedColor.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 12
Source File: FilterPanelSeparator.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
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 13
Source File: PaletteBuilder.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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 14
Source File: ImageColorReplacer.java    From seventh with GNU General Public License v2.0 4 votes vote down vote up
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 15
Source File: Utilities.java    From littleluck with 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 16
Source File: XArrayDataViewer.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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 17
Source File: Decoration.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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 18
Source File: ColorEditor.java    From netbeans with 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
Source File: XComponentPeer.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
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 File: StringUtils.java    From htmlunit with 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() + ")";
}