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:PaintUtils.java

/** Paints 3 different strokes around a shape to indicate focus.
 * The widest stroke is the most transparent, so this achieves a nice
 * "glow" effect./*from   w w  w  .ja  v  a2  s  .  com*/
 * <P>The catch is that you have to render this underneath the shape,
 * and the shape should be filled completely.
 * 
 * @param g the graphics to paint to
 * @param shape the shape to outline
 * @param biggestStroke the widest stroke to use.
 */
public static void paintFocus(Graphics2D g, Shape shape, int biggestStroke) {
    Color focusColor = getFocusRingColor();
    Color[] focusArray = new Color[] {
            new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 255),
            new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 170),
            new Color(focusColor.getRed(), focusColor.getGreen(), focusColor.getBlue(), 110) };
    g.setStroke(new BasicStroke(biggestStroke));
    g.setColor(focusArray[2]);
    g.draw(shape);
    g.setStroke(new BasicStroke(biggestStroke - 1));
    g.setColor(focusArray[1]);
    g.draw(shape);
    g.setStroke(new BasicStroke(biggestStroke - 2));
    g.setColor(focusArray[0]);
    g.draw(shape);
    g.setStroke(new BasicStroke(1));
}

From source file:net.sf.maltcms.chromaui.charts.ChartCustomizer.java

/**
 *
 * @param color/*from w  w  w. j a va 2  s .  c om*/
 * @param alpha
 * @return
 */
public static Color withAlpha(Color color, float alpha) {
    Color ca = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (alpha * 255.0f));
    return ca;
}

From source file:com.github.fritaly.graphml4j.Utils.java

/**
 * Encodes the given color into an hexadecimal string like "#RRGGBBAA" or
 * "#RRGGBB" (whether the transparency is set to 0).
 *
 * @param color//from ww  w.j  a  v  a 2  s  .  c om
 *            a color to encode. Can't be null.
 * @return a string representing the encoded color.
 */
static String encode(Color color) {
    Validate.notNull(color, "The given color is null");

    if (color.getAlpha() == 255) {
        return String.format("#%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue());
    } else {
        return String.format("#%02X%02X%02X%02X", color.getRed(), color.getGreen(), color.getBlue(),
                color.getAlpha());
    }
}

From source file:Main.java

/**
 * Write a {@link Color} value into XML output.
 *
 * @param value/*  w w  w  . jav  a  2 s  . c  o m*/
 * value to write
 *
 * @return
 * XML string
 *
 * @throws IllegalArgumentException
 * if a validation error occured
 */
public static String printColor(Color value) {
    if (value == null) {
        throw new IllegalArgumentException("The provided color is invalid!");
    }

    String r = Integer.toHexString(value.getRed()).trim();
    if (r.length() == 1)
        r = "0" + r;
    String g = Integer.toHexString(value.getGreen()).trim();
    if (g.length() == 1)
        g = "0" + g;
    String b = Integer.toHexString(value.getBlue()).trim();
    if (b.length() == 1)
        b = "0" + b;
    return "#" + r + g + b;
}

From source file:chiliad.parser.pdf.model.MToken.java

public static String colorToRgba(Color c) {
    return "rgba(" + c.getRed() + "," + c.getGreen() + "," + c.getBlue() + "," + c.getAlpha() / 255 + ")";
}

From source file:org.polymap.rhei.batik.engine.svg.Svg2PngTask.java

static RGB getTypedRGB(String rgbStr) {
    if (rgbStr == null) {
        return null;
    }//www .j  a  v  a 2 s.c o m
    if (rgbStr.startsWith("#")) {
        rgbStr = rgbStr.substring(1);
    }
    if (!rgbStr.startsWith("0x")) {
        rgbStr = "0x" + rgbStr;
    }
    Color color = Color.decode(rgbStr);
    return new RGB(color.getRed(), color.getGreen(), color.getBlue());
}

From source file:ColorUtilities.java

public static Color blend(Color c0, Color c1) {
    double totalAlpha = c0.getAlpha() + c1.getAlpha();
    double weight0 = c0.getAlpha() / totalAlpha;
    double weight1 = c1.getAlpha() / totalAlpha;

    double r = weight0 * c0.getRed() + weight1 * c1.getRed();
    double g = weight0 * c0.getGreen() + weight1 * c1.getGreen();
    double b = weight0 * c0.getBlue() + weight1 * c1.getBlue();
    double a = Math.max(c0.getAlpha(), c1.getAlpha());

    return new Color((int) r, (int) g, (int) b, (int) a);
}

From source file:ch.fork.AdHocRailway.ui.utils.ImageTools.java

public static Image TransformColorToTransparency(BufferedImage image, Color c1, Color c2) {
    // Primitive test, just an example
    final int r1 = c1.getRed();
    final int g1 = c1.getGreen();
    final int b1 = c1.getBlue();
    final int r2 = c2.getRed();
    final int g2 = c2.getGreen();
    final int b2 = c2.getBlue();
    ImageFilter filter = new RGBImageFilter() {
        public final int filterRGB(int x, int y, int rgb) {
            int r = (rgb & 0xFF0000) >> 16;
            int g = (rgb & 0xFF00) >> 8;
            int b = rgb & 0xFF;
            if (r >= r1 && r <= r2 && g >= g1 && g <= g2 && b >= b1 && b <= b2) {
                // Set fully transparent but keep color
                return rgb & 0xFFFFFF;
            }/*from   w  ww.j  ava2s . co m*/
            return rgb;
        }
    };

    ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
    return Toolkit.getDefaultToolkit().createImage(ip);
}

From source file:ColorUtil.java

/**
 * Check if a color is more dark than light. Useful if an entity of
 * this color is to be labeled: Use white label on a "dark" color and
 * black label on a "light" color./*  w w w  . ja v  a 2 s.  c o  m*/
 *
 * @param color  Color to check.
 * @return       True if this is a "dark" color, false otherwise.
 */
public static boolean isDark(Color color) {
    float r = color.getRed() / 255.0f;
    float g = color.getGreen() / 255.0f;
    float b = color.getBlue() / 255.0f;

    return isDark(r, g, b);
}

From source file:ColorUtil.java

/**
 * Return the hex name of a specified color.
 * //w w w. j  av a2 s. co m
 * @param color  Color to get hex name of.
 * @return       Hex name of color: "rrggbb".
 */
public static String getHexName(Color color) {
    int r = color.getRed();
    int g = color.getGreen();
    int b = color.getBlue();

    String rHex = Integer.toString(r, 16);
    String gHex = Integer.toString(g, 16);
    String bHex = Integer.toString(b, 16);

    return (rHex.length() == 2 ? "" + rHex : "0" + rHex) + (gHex.length() == 2 ? "" + gHex : "0" + gHex)
            + (bHex.length() == 2 ? "" + bHex : "0" + bHex);
}