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:org.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.StaticExcelColorSupport.java

public static short getNearestColor(final Color awtColor, final Map triplets) {
    if (awtColor == null) {
        throw new NullPointerException();
    }/*from   w  w  w  .ja  va 2s.c om*/

    if (triplets == null || triplets.isEmpty()) {
        logger.warn("Unable to get triplet hashtable");
        return HSSFColor.BLACK.index;
    }

    short color = HSSFColor.BLACK.index;
    double minDiff = Double.MAX_VALUE;

    // get the color without the alpha chanel
    final float[] hsb = Color.RGBtoHSB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue(), null);

    float[] excelHsb = null;
    final Iterator elements = triplets.values().iterator();
    while (elements.hasNext()) {
        final HSSFColor crtColor = (HSSFColor) elements.next();
        final short[] rgb = crtColor.getTriplet();
        excelHsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], excelHsb);

        final double weight = 3.0
                * (Math.min(Math.abs(excelHsb[0] - hsb[0]), Math.abs(excelHsb[0] - hsb[0] + 1)))
                + Math.abs(excelHsb[1] - hsb[1]) + Math.abs(excelHsb[2] - hsb[2]);

        if (weight < minDiff) {
            minDiff = weight;
            if (minDiff == 0) {
                // we found the color ...
                return crtColor.getIndex();
            }
            color = crtColor.getIndex();
        }
    }
    return color;
}

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

private static void attrFontColor(Color colorType, RtfAttributes rtfAttr) {
    // Cell background color
    if (colorType != null) {
        if (colorType.getAlpha() != 0 || colorType.getRed() != 0 || colorType.getGreen() != 0
                || colorType.getBlue() != 0) {
            rtfAttr.set(RtfText.ATTR_FONT_COLOR, convertFOPColorToRTF(colorType));
        }/*from   www . j av a  2  s .co  m*/
    }
}

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

private static VectorList colorVL(Color c) {
    final double[] color = new double[] { c.getRed() / 255., c.getGreen() / 255., c.getBlue() / 255.,
            c.getAlpha() / 255. };//from   w ww  .j a  v a 2s.  co  m

    return new VectorList() {
        @Override
        public int getNumVectors() {
            return 1;
        }

        @Override
        public int getNumComponentsPerVector() {
            return 4;
        }

        @Override
        public double componentAt(int vectorIndex, int componentIndex) {
            return color[componentIndex];
        }

        @Override
        public void setComponentAt(int vectorIndex, int componentIndex, double value) {
            throw new RuntimeException(
                    "Static palette created by Texture(Color c, TR tr) cannot be written to.");
        }
    };
}

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

public static Color getBestForegroundColor(Color background) {
    int backgroundBrightness = (background.getBlue() + background.getRed() * 2 + background.getGreen() * 3) / 6;
    return backgroundBrightness > 160 ? Color.BLACK : Color.WHITE;
}

From source file:com.netsteadfast.greenstep.util.SimpleUtils.java

public static int[] getColorRGB2(String color) throws Exception {
    if (StringUtils.isEmpty(color) || color.length() != 7) {
        return new int[] { 0, 0, 0 };
    }/*  ww w  .  j  av a2s.  com*/
    Color c = Color.decode(color);
    return new int[] { c.getRed(), c.getGreen(), c.getBlue() };
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithHeatMap.java

protected static void addValuesToPaintScale(LookupPaintScale paintScale, double lowerBound, double upperBound,
        Color lowColor, Color highColor) {
    int distinctValues = DISTINCT_PALETTE_VALUES;

    if (upperBound <= lowerBound)
        upperBound = lowerBound + .0001;
    double increment = (upperBound - lowerBound) / distinctValues;

    int redDiff = highColor.getRed() - lowColor.getRed();
    int greenDiff = highColor.getGreen() - lowColor.getGreen();
    int blueDiff = highColor.getBlue() - lowColor.getBlue();
    double redIncrement = (redDiff / distinctValues);
    double greenIncrement = (greenDiff / distinctValues);
    double blueIncrement = (blueDiff / distinctValues);

    _log.debug("Palette: ");

    for (int i = 0; i < distinctValues; i++) {
        int r = (int) (lowColor.getRed() + (i * redIncrement));
        int g = (int) (lowColor.getGreen() + (i * greenIncrement));
        int b = (int) (lowColor.getBlue() + (i * blueIncrement));
        Color incrementColor = new Color(r, g, b);
        double incrementStart = lowerBound + (i * increment);
        paintScale.add(incrementStart, incrementColor);
        _log.debug("\t" + incrementStart + "-" + (incrementStart + increment) + ": " + incrementColor);
    }/*w ww  . j  a va 2  s. co  m*/
}

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

private static float[] replaceColors(ImageConfiguration imageConfiguration, Color color,
        final float[] currentHsb) {
    float[] hsb;//from   w w w.j  a  v a 2s.c o m
    Optional<ReplaceConfiguration> config = imageConfiguration.getReplaceConfigurations().stream()
            .filter(rc -> rc.getFrom() != null && rc.getTo() != null && rc.getFrom().red == color.getRed()
                    && rc.getFrom().green == color.getGreen() && rc.getFrom().blue == color.getBlue())
            .findFirst();
    if (config.isPresent()) {
        hsb = config.get().getTo().getHSB();
        hsb[0] = degreeToPercent(hsb[0]);
    } else {
        hsb = currentHsb;
    }
    return hsb;
}

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);//from   w w  w  .  j  a v  a  2s .c om
    } 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:com.t_oster.visicut.misc.Helper.java

public static String toHtmlRGB(Color col) {
    String r = Integer.toHexString(col.getRed());
    String g = Integer.toHexString(col.getGreen());
    String b = Integer.toHexString(col.getBlue());
    return "#" + (r.length() == 1 ? "0" + r : r) + (g.length() == 1 ? "0" + g : g)
            + (b.length() == 1 ? "0" + b : b);
}

From source file:org.opensha.commons.geo.RegionUtils.java

private static String colorToHex(Color c) {
    StringBuffer sb = new StringBuffer();
    sb.append(toHex(c.getAlpha()));// ww  w .  j  av  a2s  .c om
    sb.append(toHex(c.getBlue()));
    sb.append(toHex(c.getGreen()));
    sb.append(toHex(c.getRed()));
    return sb.toString();
}