Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

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

Prototype

public Color(int rgb) 

Source Link

Document

Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

Usage

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    this.setBackground(new Color(rnd.nextInt() & mask));
    this.icon.update(count += rnd.nextInt(8));
    this.parent.repaint();
}

From source file:ColorSchemaGenerator.java

/**
 * Create the schema color.//from  w w w  . ja v  a2  s .  c om
 * 
 * @param base
 * @param i (a color between 0 and 3)
 * @param schemaName
 * @return
 */
public static Color createColor(Color base, int i, String schemaName) {

    i = Math.abs(i %= 3);
    if (schemaName == null)
        schemaName = SCHEMA_SOFT;
    float[] schema = schemas.get(schemaName);

    float[] components = Color.RGBtoHSB(base.getRed(), base.getGreen(), base.getBlue(), null);

    components[1] = (schema[i * 2] < 0) ? -schema[i * 2] * components[1] : schema[i * 2];
    if (components[1] > 1)
        components[1] = 1.0f;
    if (components[1] < 0)
        components[1] = 0;

    components[2] = (schema[i * 2 + 1] < 0) ? -schema[i * 2 + 1] * components[2] : schema[i * 2 + 1];
    if (components[2] > 1)
        components[2] = 1.0f;
    if (components[2] < 0)
        components[2] = 0;

    return new Color(Color.HSBtoRGB(components[0], components[1], components[2]));
}

From source file:ColorScribble.java

protected Color getColorParameter(String name) {
    String value = this.getParameter(name);
    try {/*from  w w w .  j av a  2  s.  com*/
        return new Color(Integer.parseInt(value, 16));
    } catch (Exception e) {
        return null;
    }
}

From source file:net.d53dev.dslfy.web.service.GifService.java

public BufferedImage convertRGBAToGIF(BufferedImage src, int transColor) {
    BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = dst.getGraphics();
    g.setColor(new Color(transColor));
    g.fillRect(0, 0, dst.getWidth(), dst.getHeight());
    {//  w w  w . j  a v  a  2s.  c o m
        IndexColorModel indexedModel = (IndexColorModel) dst.getColorModel();
        WritableRaster raster = dst.getRaster();
        int sample = raster.getSample(0, 0, 0);
        int size = indexedModel.getMapSize();
        byte[] rr = new byte[size];
        byte[] gg = new byte[size];
        byte[] bb = new byte[size];
        indexedModel.getReds(rr);
        indexedModel.getGreens(gg);
        indexedModel.getBlues(bb);
        IndexColorModel newModel = new IndexColorModel(8, size, rr, gg, bb, sample);
        dst = new BufferedImage(newModel, raster, dst.isAlphaPremultiplied(), null);
    }
    dst.createGraphics().drawImage(src, 0, 0, null);
    return dst;
}

From source file:imageprocessingproject.ImageHistogram.java

public static BufferedImage autoContrastImage(BufferedImage image) {
    createContrastLUT(image);//  www. j  av a  2  s .  c om

    int height = image.getHeight();
    int width = image.getWidth();
    int r, g, b;
    Color c;

    BufferedImage tempImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {
            c = new Color(image.getRGB(i, j));
            r = (int) (255 * contrast_lut[c.getRed()]);
            g = (int) (255 * contrast_lut[c.getGreen()]);
            b = (int) (255 * contrast_lut[c.getBlue()]);
            tempImage.setRGB(i, j, new Color(r, g, b, c.getAlpha()).getRGB());
        }
    }

    return tempImage;
}

From source file:br.prof.salesfilho.oci.image.ImageProcessor.java

public double[] getRed() {
    int[] colors = new int[this.image.getWidth() * this.image.getHeight()];
    this.image.getRGB(0, 0, this.image.getWidth(), this.image.getHeight(), colors, 0, this.image.getWidth());

    double[] red = new double[colors.length];

    for (int i = 0; i < colors.length; i++) {
        Color color = new Color(colors[i]);
        int rgb = color.getRGB();
        int r = (rgb >> 16) & 0xFF;
        red[i] = (double) r;
    }//  w  ww .j a v  a 2 s.  co  m
    return red;
}

From source file:com.clank.launcher.swing.MessageLog.java

public MessageLog(int numLines, boolean colorEnabled) {
    this.numLines = numLines;
    this.colorEnabled = colorEnabled;

    this.highlightedAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(highlightedAttributes, new Color(0xFF7F00));

    this.errorAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(errorAttributes, new Color(0xFF0000));
    this.infoAttributes = new SimpleAttributeSet();
    this.debugAttributes = new SimpleAttributeSet();

    setLayout(new BorderLayout());

    initComponents();/*from   w w  w . j a v a 2 s.c o m*/
}

From source file:ColorFactory.java

private ColorFactory() {
    Map colorMap = this.colorMap;
    synchronized (this) {
        colorMap.put("transparent", TRANSPARENT);
        //http://www.w3schools.com/css/css_colornames.asp
        colorMap.put("aliceblue", new Color(0xf0f8ff));
        colorMap.put("antiquewhite", new Color(0xfaebd7));
        colorMap.put("aqua", new Color(0x00ffff));
        colorMap.put("aquamarine", new Color(0x7fffd4));
        colorMap.put("azure", new Color(0xf0ffff));
        colorMap.put("beige", new Color(0xf5f5dc));
        colorMap.put("bisque", new Color(0xffe4c4));
        colorMap.put("black", new Color(0x000000));
        colorMap.put("blanchedalmond", new Color(0xffebcd));
        colorMap.put("blue", new Color(0x0000ff));
        colorMap.put("blueviolet", new Color(0x8a2be2));
        colorMap.put("brown", new Color(0xa52a2a));
        colorMap.put("burlywood", new Color(0xdeb887));
        colorMap.put("cadetblue", new Color(0x5f9ea0));
        colorMap.put("chartreuse", new Color(0x7fff00));
        colorMap.put("chocolate", new Color(0xd2691e));
        colorMap.put("coral", new Color(0xff7f50));
        colorMap.put("cornflowerblue", new Color(0x6495ed));
        colorMap.put("cornsilk", new Color(0xfff8dc));
        colorMap.put("crimson", new Color(0xdc143c));
        colorMap.put("cyan", new Color(0x00ffff));
        colorMap.put("darkblue", new Color(0x00008b));
        colorMap.put("darkcyan", new Color(0x008b8b));
        colorMap.put("darkgoldenrod", new Color(0xb8860b));
        colorMap.put("darkgray", new Color(0xa9a9a9));
        colorMap.put("darkgrey", new Color(0xa9a9a9));
        colorMap.put("darkgreen", new Color(0x006400));
        colorMap.put("darkkhaki", new Color(0xbdb76b));
        colorMap.put("darkmagenta", new Color(0x8b008b));
        colorMap.put("darkolivegreen", new Color(0x556b2f));
        colorMap.put("darkorange", new Color(0xff8c00));
        colorMap.put("darkorchid", new Color(0x9932cc));
        colorMap.put("darkred", new Color(0x8b0000));
        colorMap.put("darksalmon", new Color(0xe9967a));
        colorMap.put("darkseagreen", new Color(0x8fbc8f));
        colorMap.put("darkslateblue", new Color(0x483d8b));
        colorMap.put("darkslategray", new Color(0x2f4f4f));
        colorMap.put("darkslategrey", new Color(0x2f4f4f));
        colorMap.put("darkturquoise", new Color(0x00ced1));
        colorMap.put("darkviolet", new Color(0x9400d3));
        colorMap.put("deeppink", new Color(0xff1493));
        colorMap.put("deepskyblue", new Color(0x00bfff));
        colorMap.put("dimgray", new Color(0x696969));
        colorMap.put("dimgrey", new Color(0x696969));
        colorMap.put("dodgerblue", new Color(0x1e90ff));
        colorMap.put("firebrick", new Color(0xb22222));
        colorMap.put("floralwhite", new Color(0xfffaf0));
        colorMap.put("forestgreen", new Color(0x228b22));
        colorMap.put("fuchsia", new Color(0xff00ff));
        colorMap.put("gainsboro", new Color(0xdcdcdc));
        colorMap.put("ghostwhite", new Color(0xf8f8ff));
        colorMap.put("gold", new Color(0xffd700));
        colorMap.put("goldenrod", new Color(0xdaa520));
        colorMap.put("gray", new Color(0x808080));
        colorMap.put("grey", new Color(0x808080));
        colorMap.put("green", new Color(0x008000));
        colorMap.put("greenyellow", new Color(0xadff2f));
        colorMap.put("honeydew", new Color(0xf0fff0));
        colorMap.put("hotpink", new Color(0xff69b4));
        colorMap.put("indianred", new Color(0xcd5c5c));
        colorMap.put("indigo", new Color(0x4b0082));
        colorMap.put("ivory", new Color(0xfffff0));
        colorMap.put("khaki", new Color(0xf0e68c));
        colorMap.put("lavender", new Color(0xe6e6fa));
        colorMap.put("lavenderblush", new Color(0xfff0f5));
        colorMap.put("lawngreen", new Color(0x7cfc00));
        colorMap.put("lemonchiffon", new Color(0xfffacd));
        colorMap.put("lightblue", new Color(0xadd8e6));
        colorMap.put("lightcoral", new Color(0xf08080));
        colorMap.put("lightcyan", new Color(0xe0ffff));
        colorMap.put("lightgoldenrodyellow", new Color(0xfafad2));
        colorMap.put("lightgray", new Color(0xd3d3d3));
        colorMap.put("lightgrey", new Color(0xd3d3d3));
        colorMap.put("lightgreen", new Color(0x90ee90));
        colorMap.put("lightpink", new Color(0xffb6c1));
        colorMap.put("lightsalmon", new Color(0xffa07a));
        colorMap.put("lightseagreen", new Color(0x20b2aa));
        colorMap.put("lightskyblue", new Color(0x87cefa));
        colorMap.put("lightslategray", new Color(0x778899));
        colorMap.put("lightslategrey", new Color(0x778899));
        colorMap.put("lightsteelblue", new Color(0xb0c4de));
        colorMap.put("lightyellow", new Color(0xffffe0));
        colorMap.put("lime", new Color(0x00ff00));
        colorMap.put("limegreen", new Color(0x32cd32));
        colorMap.put("linen", new Color(0xfaf0e6));
        colorMap.put("magenta", new Color(0xff00ff));
        colorMap.put("maroon", new Color(0x800000));
        colorMap.put("mediumaquamarine", new Color(0x66cdaa));
        colorMap.put("mediumblue", new Color(0x0000cd));
        colorMap.put("mediumorchid", new Color(0xba55d3));
        colorMap.put("mediumpurple", new Color(0x9370d8));
        colorMap.put("mediumseagreen", new Color(0x3cb371));
        colorMap.put("mediumslateblue", new Color(0x7b68ee));
        colorMap.put("mediumspringgreen", new Color(0x00fa9a));
        colorMap.put("mediumturquoise", new Color(0x48d1cc));
        colorMap.put("mediumvioletred", new Color(0xc71585));
        colorMap.put("midnightblue", new Color(0x191970));
        colorMap.put("mintcream", new Color(0xf5fffa));
        colorMap.put("mistyrose", new Color(0xffe4e1));
        colorMap.put("moccasin", new Color(0xffe4b5));
        colorMap.put("navajowhite", new Color(0xffdead));
        colorMap.put("navy", new Color(0x000080));
        colorMap.put("oldlace", new Color(0xfdf5e6));
        colorMap.put("olive", new Color(0x808000));
        colorMap.put("olivedrab", new Color(0x6b8e23));
        colorMap.put("orange", new Color(0xffa500));
        colorMap.put("orangered", new Color(0xff4500));
        colorMap.put("orchid", new Color(0xda70d6));
        colorMap.put("palegoldenrod", new Color(0xeee8aa));
        colorMap.put("palegreen", new Color(0x98fb98));
        colorMap.put("paleturquoise", new Color(0xafeeee));
        colorMap.put("palevioletred", new Color(0xd87093));
        colorMap.put("papayawhip", new Color(0xffefd5));
        colorMap.put("peachpuff", new Color(0xffdab9));
        colorMap.put("peru", new Color(0xcd853f));
        colorMap.put("pink", new Color(0xffc0cb));
        colorMap.put("plum", new Color(0xdda0dd));
        colorMap.put("powderblue", new Color(0xb0e0e6));
        colorMap.put("purple", new Color(0x800080));
        colorMap.put("red", new Color(0xff0000));
        colorMap.put("rosybrown", new Color(0xbc8f8f));
        colorMap.put("royalblue", new Color(0x4169e1));
        colorMap.put("saddlebrown", new Color(0x8b4513));
        colorMap.put("salmon", new Color(0xfa8072));
        colorMap.put("sandybrown", new Color(0xf4a460));
        colorMap.put("seagreen", new Color(0x2e8b57));
        colorMap.put("seashell", new Color(0xfff5ee));
        colorMap.put("sienna", new Color(0xa0522d));
        colorMap.put("silver", new Color(0xc0c0c0));
        colorMap.put("skyblue", new Color(0x87ceeb));
        colorMap.put("slateblue", new Color(0x6a5acd));
        colorMap.put("slategray", new Color(0x708090));
        colorMap.put("slategrey", new Color(0x708090));
        colorMap.put("snow", new Color(0xfffafa));
        colorMap.put("springgreen", new Color(0x00ff7f));
        colorMap.put("steelblue", new Color(0x4682b4));
        colorMap.put("tan", new Color(0xd2b48c));
        colorMap.put("teal", new Color(0x008080));
        colorMap.put("thistle", new Color(0xd8bfd8));
        colorMap.put("tomato", new Color(0xff6347));
        colorMap.put("turquoise", new Color(0x40e0d0));
        colorMap.put("violet", new Color(0xee82ee));
        colorMap.put("wheat", new Color(0xf5deb3));
        colorMap.put("white", new Color(0xffffff));
        colorMap.put("whitesmoke", new Color(0xf5f5f5));
        colorMap.put("yellow", new Color(0xffff00));
        colorMap.put("yellowgreen", new Color(0x9acd32));
    }//from  w  w  w  . j a va  2 s .c o m
}

From source file:main.java.whiteSocket.Area.java

public static void getLightBounds() throws IOException {
    /*// w  w w  .  j a  v  a2 s. c o  m
     * sets ax, ay, bx, by, cx, cy, dx, dy
     * */

    //      ArrayList<Area> _1 = new ArrayList<Area>();

    System.out.println("getLightBounds() ...");

    hasBeenHit = new boolean[Bloop.sketch.getHeight()][Bloop.sketch.getWidth()];

    Color pxColor = null;
    Border b1 = null;
    Border b2 = null;
    Border b3 = null;
    Border b4 = null;

    here1: for (int row = 0; row < Bloop.sketch.getHeight() / 2; row++) {
        for (int col = 0; col < Bloop.sketch.getWidth() / 2; col++) {
            /*
             * QUAD #1 - UL
             */
            int xIN = col;
            int yIN = row;

            pxColor = new Color(Bloop.sketch.getRGB(xIN, yIN));
            if (Bloop.isMarker(pxColor) && !hasBeenHit[yIN][xIN]) {
                b1 = new Border(xIN, yIN);
                break here1;
            }
        }
    }

    here2: for (int row = 0; row < Bloop.sketch.getHeight() / 2; row++) {
        for (int col = Bloop.sketch.getWidth() - 1; col > Bloop.sketch.getWidth() / 2; col--) {
            /*
             * QUAD #2 - UR
             */
            int xIN = col;
            int yIN = row;

            pxColor = new Color(Bloop.sketch.getRGB(xIN, yIN));
            if (Bloop.isMarker(pxColor) && !hasBeenHit[yIN][xIN]) {
                b2 = new Border(xIN, yIN);
                break here2;
            }
        }
    }

    here3: for (int row = Bloop.sketch.getHeight() - 1; row > Bloop.sketch.getHeight() / 2; row--) {
        for (int col = 0; col < Bloop.sketch.getWidth() / 2; col++) {
            /*
             * QUAD #3 - LL
             */
            int xIN = col;
            int yIN = row;

            pxColor = new Color(Bloop.sketch.getRGB(xIN, yIN));
            if (Bloop.isMarker(pxColor) && !hasBeenHit[yIN][xIN]) {
                b3 = new Border(xIN, yIN);
                break here3;
            }
        }
    }

    here4: for (int row = Bloop.sketch.getHeight() - 1; row > Bloop.sketch.getHeight() / 2; row--) {
        for (int col = Bloop.sketch.getWidth() - 1; col > Bloop.sketch.getWidth() / 2; col--) {
            /*
             * QUAD #4 - LR
             */
            int xIN = col;
            int yIN = row;

            pxColor = new Color(Bloop.sketch.getRGB(xIN, yIN));
            if (Bloop.isMarker(pxColor) && !hasBeenHit[yIN][xIN]) {
                b4 = new Border(xIN, yIN);
                break here4;
            }
        }
    }

    Stretch.ax = b1.xMax + 1;
    Stretch.ay = b1.yMax + 1;
    Stretch.cx = b2.xMin - 1;
    Stretch.cy = b2.yMax + 1;
    Stretch.dx = b3.xMax + 1;
    Stretch.dy = b3.yMin - 1;
    Stretch.bx = b4.xMin - 1;
    Stretch.by = b4.yMin - 1;

    Bloop.topSlope = ((double) Stretch.cy - (double) Stretch.ay) / ((double) Stretch.cx - (double) Stretch.ax);
    Bloop.bottomSlope = ((double) Stretch.dy - (double) Stretch.by)
            / ((double) Stretch.dx - (double) Stretch.bx);
    Bloop.leftSlope = ((double) Stretch.dy - (double) Stretch.ay) / ((double) Stretch.dx - (double) Stretch.ax);
    Bloop.rightSlope = ((double) Stretch.cy - (double) Stretch.by)
            / ((double) Stretch.cx - (double) Stretch.bx);

    //      printBorderValues();      
    //      printImgBool(hasBeenHit, "corners");

}

From source file:net.sourceforge.subsonic.controller.AbstractChartController.java

private Color getColor(String code, HttpServletRequest request) {
    Theme theme = RequestContextUtils.getTheme(request);
    Locale locale = RequestContextUtils.getLocale(request);
    String colorHex = theme.getMessageSource().getMessage(code, new Object[0], locale);
    return new Color(Integer.parseInt(colorHex, 16));
}