Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

In this page you can find the example usage for java.awt Color getRed.

Prototype

public int getRed() 

Source Link

Document

Returns the red component in the range 0-255 in the default sRGB space.

Usage

From source file:Main.java

/**
 * Create a darker color using a factor.
 *
 * @param color//from  w  w  w .  j a  va  2 s  . co  m
 * @param factor
 * @return darker color
 */
public static Color darker(final Color color, float factor) {
    return new Color(Math.max((int) (color.getRed() * factor), 0),
            Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0));
}

From source file:Main.java

/**
 * attach (append to child) RGB to the element, in the format <red>12</red> etc
 * @param rgb// w  w  w .ja v  a  2s  .c  o m
 * @param elem
 * @param doc
 */
public static void attachRGB(Color rgb, Element elem, Document doc) {
    int r = rgb.getRed();
    int g = rgb.getGreen();
    int b = rgb.getBlue();

    //create element
    Element red = doc.createElement(TAG_NAME_RED);
    Element green = doc.createElement(TAG_NAME_GREEN);
    Element blue = doc.createElement(TAG_NAME_BLUE);

    //fill the content
    red.appendChild(doc.createTextNode(Integer.toString(r)));
    green.appendChild(doc.createTextNode(Integer.toString(g)));
    blue.appendChild(doc.createTextNode(Integer.toString(b)));

    //structure the content
    elem.appendChild(red);
    elem.appendChild(green);
    elem.appendChild(blue);
}

From source file:Main.java

/**
 * Creates a new <code>Color</code> that is a darker version of this
 * <code>Color</code>. This method is the same implementation
 * java.awt.Color#darker is usind except it has a configurable factor.
 * The java.awt.Color default facotr is 0.7
 * @return  a new <code>Color</code> object that is 
 *                    a darker version of this <code>Color</code>.
 * @see        java.awt.Color#brighter/*from w  w  w .j a va  2s  . c om*/
 */
public static Color darkerColor(Color color, double factor) {
    return new Color(Math.max((int) (color.getRed() * factor), 0),
            Math.max((int) (color.getGreen() * factor), 0), Math.max((int) (color.getBlue() * factor), 0));
}

From source file:com.technofovea.packbsp.gui2.jung.DependencyVisualizer.java

static Color trans(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue(), 128);

}

From source file:Main.java

/**
 * Creates a new <code>Color</code> that is a brighter version of this
 * <code>Color</code>. This method is the same implementation
 * java.awt.Color#brighter is usind except it has a configurable factor.
 * The java.awt.Color default facotr is 0.7
 * @return     a new <code>Color</code> object that is  
 *                 a brighter version of this <code>Color</code>.
 * @see        java.awt.Color#darker/*w w  w  .  j a v  a2 s .  c om*/
 */
public static Color brighterColor(Color color, double factor) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();

    /* From 2D group:
     * 1. black.brighter() should return grey
     * 2. applying brighter to blue will always return blue, brighter
     * 3. non pure color (non zero rgb) will eventually return white
     */
    int i = (int) (1.0 / (1.0 - factor));
    if (r == 0 && g == 0 && b == 0) {
        return new Color(i, i, i);
    }
    if (r > 0 && r < i)
        r = i;
    if (g > 0 && g < i)
        g = i;
    if (b > 0 && b < i)
        b = i;

    return new Color(Math.min((int) (r / factor), 255), Math.min((int) (g / factor), 255),
            Math.min((int) (b / factor), 255));
}

From source file:Main.java

/**
 * Returns color copy./*from   w w w.j a v a  2  s.  co  m*/
 *
 * @param color
 *            color to copy
 * @return color copy
 */
public static Color copy(final Color color) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}

From source file:ColorUtil.java

public static Color copy(Color c) {
    return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
}

From source file:ColorUtils.java

/**
 * Serializes a color to its HTML markup (e.g. "#ff0000" for red)
 * // w ww .  j av a 2 s. c  o m
 * @param c The color to serialize
 * @return The HTML markup of the color
 */
public static String toHTML(Color c) {
    String ret = "#";
    String hex;
    hex = Integer.toHexString(c.getRed());
    if (hex.length() < 2)
        hex = "0" + hex;
    ret += hex;
    hex = Integer.toHexString(c.getGreen());
    if (hex.length() < 2)
        hex = "0" + hex;
    ret += hex;
    hex = Integer.toHexString(c.getBlue());
    if (hex.length() < 2)
        hex = "0" + hex;
    ret += hex;
    return ret;
}

From source file:Main.java

public static Color getGradientHsbColor(float ratio, Color minColor, Color maxColor) {
    float[] startHSB = Color.RGBtoHSB(minColor.getRed(), minColor.getGreen(), minColor.getBlue(), null);
    float[] endHSB = Color.RGBtoHSB(maxColor.getRed(), maxColor.getGreen(), maxColor.getBlue(), null);

    float brightness = (startHSB[2] + endHSB[2]) / 2;
    float saturation = (startHSB[1] + endHSB[1]) / 2;

    float hueMax = 0;
    float hueMin = 0;
    // if (startHSB[0] > endHSB[0]) {
    hueMax = startHSB[0];//from  w  w w . j  av  a2 s .co  m
    hueMin = endHSB[0];
    // } else {
    // hueMin = startHSB[0];
    // hueMax = endHSB[0];
    // }

    float hue = ((hueMax - hueMin) * (1.0F - ratio)) + hueMin;

    return Color.getHSBColor(hue, saturation, brightness);
}

From source file:ColorUtil.java

public static Color setAlpha(Color c, int alpha) {
    return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
}