Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

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

Prototype

public int getGreen() 

Source Link

Document

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

Usage

From source file:org.jtrfp.trcl.core.Texture.java

public static ByteBuffer indexed2RGBA8888(ByteBuffer indexedPixels, Color[] palette) {
    Color color;
    ByteBuffer buf = ByteBuffer.allocateDirect(indexedPixels.capacity() * 4);
    final int cap = indexedPixels.capacity();
    for (int i = 0; i < cap; i++) {
        color = palette[(indexedPixels.get() & 0xFF)];
        buf.put((byte) color.getRed());
        buf.put((byte) color.getGreen());
        buf.put((byte) color.getBlue());
        buf.put((byte) color.getAlpha());
    } // end for(i)
    buf.clear();// Rewind
    return buf;/*  w ww  . j  av  a 2s .c o m*/
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchicalClusterer.java

private static Color mixColors(Color c1, double w1, Color c2, double w2) {

    if (w1 == 0.0) {
        return c2;
    }//  w  w w  . j ava 2 s  .  c om

    if (w2 == 0.0) {
        return c1;
    }

    double wa1 = FastMath.abs(w1);
    double wa2 = FastMath.abs(w2);

    double total = wa1 + wa2;

    double t1 = wa1 / total;
    double t2 = wa2 / total;

    if (t1 < 0.1) {
        t1 = 0.1;
        t2 = 0.8;
    }

    if (t2 < 0.1) {
        t1 = 0.8;
        t2 = 0.1;
    }

    int red = (int) (t1 * (double) c1.getRed() + t2 * (double) c2.getRed());
    int green = (int) (t1 * (double) c1.getGreen() + t2 * (double) c2.getGreen());
    int blue = (int) (t1 * (double) c1.getBlue() + t2 * (double) c2.getBlue());

    return new Color(red, green, blue);
}

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

public static boolean isMarker(Color x) {

    int brightness = (int) (0.2126 * x.getRed() + 0.7152 * x.getGreen() + 0.0722 * x.getBlue());

    if (brightness < brightThreshold)
        return true;
    else/*from  w  w  w .j a  va 2s .  c o m*/
        return false;

}

From source file:mx.itesm.web2mexadl.cluster.ClusterAnalyzer.java

/**
 * Generate a random color, to identify Clusters. Based on:
 * http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate
 * -an-aesthetically-pleasing-color-palette
 * /*from   w ww  .ja v  a2  s  .  c  o  m*/
 * @return
 */
private static Color getRandomColor() {
    int red;
    int blue;
    int green;
    Random random;
    Color mixColor;
    Color returnValue;

    // Base color (white)
    mixColor = new Color(255, 255, 255);
    random = new Random();
    red = random.nextInt(256);
    green = random.nextInt(256);
    blue = random.nextInt(256);

    // Mix new color with base one
    red = (red + mixColor.getRed()) / 2;
    green = (green + mixColor.getGreen()) / 2;
    blue = (blue + mixColor.getBlue()) / 2;

    returnValue = new Color(red, green, blue);
    return returnValue;
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Convert a color object to a hex string
 **///from   ww w .  ja va2  s  .co  m
public static String colorToHex(Color colorCode) {
    int r = colorCode.getRed();
    int g = colorCode.getGreen();
    int b = colorCode.getBlue();

    return toHex(r) + toHex(g) + toHex(b);
}

From source file:it.units.malelab.ege.util.DUMapper.java

private static void modifyMap(String fileName, float bins) throws IOException {
    Color[][] colorMap = new Color[3][];
    colorMap[0] = new Color[] { fromCode("000000"), fromCode("b36600"), fromCode("f3b300") };
    colorMap[1] = new Color[] { fromCode("376387"), fromCode("b3b3b3"), fromCode("f3e6b3") };
    colorMap[2] = new Color[] { fromCode("509dc2"), fromCode("b4d3e1"), fromCode("f3f3f3") };
    BufferedImage inImage = ImageIO.read(new File(fileName));
    BufferedImage outRGDImage = new BufferedImage(inImage.getWidth(), inImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    BufferedImage outCMImage = new BufferedImage(inImage.getWidth(), inImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    for (int x = 0; x < inImage.getWidth(); x++) {
        for (int y = 0; y < inImage.getHeight(); y++) {
            Color inColor = new Color(inImage.getRGB(x, y));
            Color outColor = new Color(
                    Math.min((float) Math.floor((float) inColor.getRed() / 255f * bins) / (bins - 1), 1f),
                    Math.min((float) Math.floor((float) inColor.getGreen() / 255f * bins) / (bins - 1), 1f), 0);
            outRGDImage.setRGB(x, y, outColor.getRGB());
            int cmRIndex = (int) Math.min((int) Math.floor((float) inColor.getRed() / 255f * 3), 2);
            int cmGIndex = (int) Math.min((int) Math.floor((float) inColor.getGreen() / 255f * 3), 2);
            outColor = colorMap[cmRIndex][cmGIndex];
            outCMImage.setRGB(x, y, outColor.getRGB());
        }/*www  . ja va  2  s .  c om*/
    }
    ImageIO.write(outRGDImage, "PNG",
            new File(fileName.replace(".png", String.format(".rgbdisc%d.png", (int) bins))));
    ImageIO.write(outCMImage, "PNG", new File(fileName.replace(".png", ".cm.png")));
}

From source file:org.ut.biolab.medsavant.shared.util.MiscUtils.java

/**
 * Blend two colours, in the given proportions. Resulting alpha is always
 * 1.0./*from w w  w. ja  va  2 s  .  c  o  m*/
 *
 * @param col1 the first colour
 * @param col2 the second colour
 * @param weight1 the weight given to col1 (from 0.0-1.0)
 */
public static Color blend(Color col1, Color col2, float weight1) {

    float weight2 = (1.0F - weight1) / 255;
    weight1 /= 255;

    // This constructor expects values from 0.0F to 1.0F, so weights have to be scaled appropriately.
    return new Color(col1.getRed() * weight1 + col2.getRed() * weight2,
            col1.getGreen() * weight1 + col2.getGreen() * weight2,
            col1.getBlue() * weight1 + col2.getBlue() * weight2);
}

From source file:org.nuclos.client.common.Utils.java

public static String colorToHexString(Color c) {
    char[] buf = new char[7];
    buf[0] = '#';
    String s = Integer.toHexString(c.getRed());
    if (s.length() == 1) {
        buf[1] = '0';
        buf[2] = s.charAt(0);// www. j a v  a2s.co m
    } else {
        buf[1] = s.charAt(0);
        buf[2] = s.charAt(1);
    }
    s = Integer.toHexString(c.getGreen());
    if (s.length() == 1) {
        buf[3] = '0';
        buf[4] = s.charAt(0);
    } else {
        buf[3] = s.charAt(0);
        buf[4] = s.charAt(1);
    }
    s = Integer.toHexString(c.getBlue());
    if (s.length() == 1) {
        buf[5] = '0';
        buf[6] = s.charAt(0);
    } else {
        buf[5] = s.charAt(0);
        buf[6] = s.charAt(1);
    }
    return String.valueOf(buf);
}

From source file:org.apache.fop.render.rtf.TextAttributesConverter.java

/**
 * Reads background-color from bl and writes it to rtfAttr.
 *
 * @param bpb the CommonBorderPaddingBackground from which the properties are read
 * @param rtfAttr the RtfAttributes object the attributes are written to
 *///from  w ww.  j a va 2  s  .co m
private static void attrBackgroundColor(CommonBorderPaddingBackground bpb, RtfAttributes rtfAttr) {
    Color fopValue = bpb.backgroundColor;
    int rtfColor = 0;
    /* FOP uses a default background color of "transparent", which is
       actually a transparent black, which is generally not suitable as a
       default here. Changing FOP's default to "white" causes problems in
       PDF output, so we will look for the default here & change it to
       "auto". */
    if ((fopValue == null) || ((fopValue.getRed() == 0) && (fopValue.getGreen() == 0)
            && (fopValue.getBlue() == 0) && (fopValue.getAlpha() == 0))) {
        return;
    } else {
        rtfColor = convertFOPColorToRTF(fopValue);
    }

    rtfAttr.set(RtfText.ATTR_BACKGROUND_COLOR, rtfColor);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartRendererFactory.java

private static void configureXYDifferenceRenderer(FormattedXYDifferenceRenderer renderer,
        ValueSource valueSource, PlotConfiguration plotConfiguration) {
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.SHAPE);

    int seriesCount = 1;// valueSource.getSeriesDataForAllGroupCells().groupCellCount();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
        // configure linestyle
        if (seriesFormat.getLineStyle() == LineStyle.NONE) {
        } else {/* www  .j a v a 2s. c  o  m*/
            renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
        }

        // configure series shape if necessary
        if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
            if (seriesFormat.getItemShape() != ItemShape.NONE) {
                renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
            } else {
            }
        }

        // configure series color if necessary
        if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
            Color itemColor = seriesFormat.getItemColor();
            Color halfTransparentPaint = DataStructureUtils.setColorAlpha(itemColor, itemColor.getAlpha() / 2);

            renderer.setSeriesPaint(0, halfTransparentPaint);
            renderer.setSeriesFillPaint(0, halfTransparentPaint);
            renderer.setPositivePaint(halfTransparentPaint);
            renderer.setNegativePaint(new Color(255 - itemColor.getRed(), 255 - itemColor.getGreen(),
                    255 - itemColor.getBlue(), itemColor.getAlpha() / 2));
        }
        renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
    }
}