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:com.igormaznitsa.jhexed.swing.editor.ui.Utils.java

public static Color getListBackground(final boolean selected) {
    if (selected) {
        if (isUnderNimbusLookAndFeel()) {
            return UIManager.getColor("List[Selected].textBackground"); // Nimbus
        }//from w ww .j a  v a 2 s.c o  m
        return UIManager.getColor("List.selectionBackground");
    } else {
        if (isUnderNimbusLookAndFeel()) {
            final Color color = UIManager.getColor("List.background");
            //noinspection UseJBColor
            return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
        }
        // Under GTK+ L&F "Table.background" often has main panel color, which looks ugly
        return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("List.background");
    }
}

From source file:org.nuxeo.theme.presets.PhotoshopPaletteParser.java

public static Map<String, String> parse(byte[] bytes) {
    Map<String, String> entries = new LinkedHashMap<String, String>();
    ByteArrayInputStream is = new ByteArrayInputStream(bytes);
    DataInputStream dis = new DataInputStream(is);

    char[] words = new char[bytes.length];
    int size = 0;
    while (true) {
        try {//w w w .j  av  a 2s. co  m
            words[size] = dis.readChar();
            size++;
        } catch (Exception e) {
            break;
        }
    }

    try {
        is.close();
        dis.close();
    } catch (IOException e) {
        log.error(e, e);
    }

    int offset = 1;
    int version = words[0] & 0xffff;
    int nc = words[1] & 0xffff;

    // get version 2 if it exists
    if (version == 1 && size > nc * 5 + 2) {
        offset += nc * 5 + 2;
        version = words[offset - 1] & 0xffff;
        nc = words[offset] & 0xffff;
    }

    if (version == 1) {
        log.debug("Found ACO v1 color file (Photoshop < 7.0)");
    } else if (version == 2) {
        log.debug("Found ACO v2 color file (Photoshop >= 7.0)");
    } else {
        log.error("Unknown ACO file version: " + version);
        return entries;
    }

    log.debug("Found " + nc + " colors.");

    int counter = 1;
    for (int j = 0; j < nc; j++) {
        String value = null;
        int colorSpace = words[offset + 1] & 0xff;
        int w = words[offset + 2] & 0xffff;
        int x = words[offset + 3] & 0xffff;
        int y = words[offset + 4] & 0xffff;
        int z = words[offset + 5] & 0xffff;

        if (colorSpace == RGB) {
            value = rgbToHex(w / 256, x / 256, y / 256);

        } else if (colorSpace == HSB) {
            float hue = w / 65535F; // [0.0-1.0]
            float saturation = x / 65535F; // [0.0-1.0]
            float brightness = y / 65535F; // [0.0-1.0]
            Color color = Color.getHSBColor(hue, saturation, brightness);
            value = rgbToHex(color.getRed(), color.getGreen(), color.getBlue());

        } else if (colorSpace == CMYK) {
            float cyan = 1F - w / 65535F; // [0.0-1.0]
            float magenta = 1F - x / 65535F; // [0.0-1.0]
            float yellow = 1F - y / 65535F; // [0.0-1.0]
            float black = 1F - z / 65535F; // [0.0-1.0]
            // TODO: do the conversion to RGB. An ICC profile is required.
            log.warn("Unsupported color space: CMYK");

        } else if (colorSpace == GRAYSCALE) {
            int gray = (int) (w * 256F / 10000F); // [0-256]
            value = rgbToHex(gray, gray, gray);

        } else if (colorSpace == LAB) {
            float l = w / 100F;
            float a = x / 100F;
            float b = y / 100F;
            // TODO: do the conversion to RGB. An ICC profile is required.
            log.warn("Unsupported color space: CIE Lab");

        } else if (colorSpace == WIDE_CMYK) {
            float cyan = w / 10000F; // [0.0-1.0]
            float magenta = x / 10000F; // [0.0-1.0]
            float yellow = y / 10000F; // [0.0-1.0]
            float black = z / 10000F; // [0.0-1.0]
            // TODO: do the conversion to RGB. An ICC profile is required.
            log.warn("Unsupported color space: Wide CMYK");

        } else {
            log.warn("Unknown color space: " + colorSpace);
        }

        String name = "";
        if (version == 1) {
            name = String.format("Color %s", counter);
        }

        else if (version == 2) {
            int len = (words[offset + 7] & 0xffff) - 1;
            name = String.copyValueOf(words, offset + 8, len);
            offset += len + 3;

            String n = name;
            int c = 2;
            while (entries.containsKey(n)) {
                n = String.format("%s %s", name, c);
                c++;
            }
            name = n;
        }

        if (value != null) {
            entries.put(name, value);
        }

        offset += 5;
        counter++;
    }

    return entries;
}

From source file:com.teambrmodding.neotech.client.models.ModelItemFluidStorage.java

/**
 * Change standard color into color MC wants for vertex data
 * @param input The input//from   w ww. ja va  2s  .  c  o m
 * @return The correct color to add to the vertex data
 */
public static int fixColorForMC(int input) {
    // ABGR, MC is reverse for some reason
    Color outputColor = new Color(input);
    int a = outputColor.getAlpha();
    int r = outputColor.getRed();
    int g = outputColor.getGreen();
    int b = outputColor.getBlue();

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

From source file:savant.view.tracks.VariantTrackRenderer.java

/**
 * If we're homozygotic, accumulate a rectangle for this variant.  If we're heterozygotic, accumulate a triangle for each parent.
 * @param vars array of one or two variant types
 * @param accumulator a colour accumulator
 * @param rect bounding box used for rendering both zygotes
 *//*  w  ww  .  j  a va 2  s .com*/
public static void accumulateZygoteShapes(VariantType[] vars, ColourAccumulator accumulator, Rectangle2D rect) {
    ColourScheme scheme = accumulator.getScheme();
    if (vars != null) {
        if (vars.length == 1) {
            accumulator.addShape(scheme.getVariantColor(vars[0]), rect);
        } else {
            Color color0 = scheme.getVariantColor(vars[0]);
            Color color1 = scheme.getVariantColor(vars[1]);
            Color blend;
            if (color0 == null) {
                blend = new Color(color1.getRed(), color1.getGreen(), color1.getBlue(), 128);
            } else if (color1 == null) {
                blend = new Color(color0.getRed(), color0.getGreen(), color0.getBlue(), 128);
            } else {
                blend = new Color((color0.getRed() + color1.getRed()) / 2,
                        (color0.getGreen() + color1.getGreen()) / 2, (color0.getBlue() + color1.getBlue()) / 2);
            }
            accumulator.addShape(blend, rect);
        }
    }
}

From source file:ColorSchemaGenerator.java

/**
 * Create the schema color./*  w w  w  .  java 2  s.  com*/
 * 
 * @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:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileChartFactory.java

public static JFreeChart createDiveProfileChartPanel(DiveProfile diveProfile, Locale locale,
        LengthUnit lengthUnit) {//from   w  w  w. ja  va 2 s  .c om
    XYSeries depthSerie = new XYSeries(SERIE_DEPTH);
    XYSeriesCollection depthCollection = new XYSeriesCollection();
    depthCollection.addSeries(depthSerie);

    JFreeChart chart = ChartFactory.createXYAreaChart(null, getDomainLegend(locale),
            getRangeLegend(locale, lengthUnit), depthCollection, PlotOrientation.VERTICAL, false, true, false);
    XYPlot xyp = chart.getXYPlot();

    Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f,
            UIAgent.getInstance().getColorWaterSurface(), false);
    xyp.setBackgroundPaint(p);
    xyp.setDomainGridlinePaint(UIAgent.getInstance().getColorWaterGrid());
    xyp.setRangeGridlinePaint(UIAgent.getInstance().getColorWaterGrid());
    ((NumberAxis) xyp.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat());

    XYAreaRenderer renderer0 = new XYAreaRenderer();
    renderer0.setOutline(true);
    renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorWaterBottom());

    Color baseColor = UIAgent.getInstance().getColorBaseBackground();
    renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50));
    xyp.setRenderer(0, renderer0);

    int i = 1;

    XYSeriesCollection decoEntriesCollection = new XYSeriesCollection();
    XYSeries decoEntriesSerie = new XYSeries(SERIE_DECO_ENTRY);
    decoEntriesCollection.addSeries(decoEntriesSerie);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorDecoEntries());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_ENTRY]);
    xyp.setDataset(i, decoEntriesCollection);
    xyp.setRenderer(i, renderer2);

    i++;
    XYSeriesCollection ascentTooFastCollection = new XYSeriesCollection();
    XYSeries ascentTooFastSerie = new XYSeries(SERIE_WARNING_ASCENT_TOO_FAST);
    ascentTooFastCollection.addSeries(ascentTooFastSerie);
    renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningAscentTooFast());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_ASCENT_TOO_FAST_WARNING]);
    xyp.setDataset(i, ascentTooFastCollection);
    xyp.setRenderer(i, renderer2);

    i++;
    XYSeriesCollection decoWarningCollection = new XYSeriesCollection();
    XYSeries decoWarningSerie = new XYSeries(SERIE_DECO_STOP);
    decoWarningCollection.addSeries(decoWarningSerie);
    renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningDecoCeiling());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_WARNING]);
    xyp.setDataset(i, decoWarningCollection);
    xyp.setRenderer(i, renderer2);

    i++;
    XYSeriesCollection remainBottomTimeCollection = new XYSeriesCollection();
    XYSeries remainBottomTimeSerie = new XYSeries(SERIE_REMAINING_BOTTOM_TIME);
    remainBottomTimeCollection.addSeries(remainBottomTimeSerie);
    renderer2 = new XYLineAndShapeRenderer();
    renderer2.setSeriesLinesVisible(0, false);
    renderer2.setAutoPopulateSeriesShape(false);
    renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningRemainingBottomTime());
    renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_REMAINING_BOTTOM_TIME_WARNING]);
    xyp.setDataset(i, remainBottomTimeCollection);
    xyp.setRenderer(i, renderer2);

    Map<Double, Double> depthEntries = diveProfile.getDepthEntries();
    Set<Double> ascentWarning = diveProfile.getAscentWarnings();
    Set<Double> decoWarnings = diveProfile.getDecoCeilingWarnings();
    Set<Double> remainBottomTime = diveProfile.getRemainingBottomTimeWarnings();
    Set<Double> decoEntryTime = diveProfile.getDecoEntries();

    if (depthEntries.size() > 0 && depthEntries.get(0d) == null) {
        depthEntries.put(0d, 0d);
    }

    for (Double seconds : depthEntries.keySet()) {
        double d = UnitsAgent.getInstance().convertLengthFromModel(depthEntries.get(seconds), lengthUnit);
        depthSerie.add(seconds, Double.valueOf(d));
    }

    if (null != ascentWarning) {
        for (Double seconds : ascentWarning) {
            ascentTooFastSerie.add(seconds, depthEntries.get(seconds));
        }
    }

    if (null != decoWarnings) {
        for (Double seconds : decoWarnings) {
            decoWarningSerie.add(seconds, depthEntries.get(seconds));
        }
    }

    if (null != remainBottomTime) {
        for (Double seconds : remainBottomTime) {
            remainBottomTimeSerie.add(seconds, depthEntries.get(seconds));
        }
    }

    if (null != decoEntryTime) {
        for (Double seconds : decoEntryTime) {
            decoEntriesSerie.add(seconds, depthEntries.get(seconds));
        }
    }
    return chart;
}

From source file:ImageProcessing.ImageProcessing.java

public static void processGrayscale(BufferedImage image) {
    //Converts a color image to a Grayscale image.
    for (int i = 0; i < image.getHeight(); i++) {
        for (int j = 0; j < image.getWidth(); j++) {
            int rgb = image.getRGB(j, i);
            Color currentPixel = new Color(rgb, true);
            //Find the average from all the color components for the given pixel.
            int grayLevel = (currentPixel.getRed() + currentPixel.getGreen() + currentPixel.getBlue()) / 3;

            int gray = (grayLevel << 16) + (grayLevel << 8) + grayLevel;
            image.setRGB(j, i, gray);//w w w  . j  av  a  2s.c om
        }
    }
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.Utils.java

public static String color2html(final Color c, final boolean alpha) {
    final String ac = Integer.toHexString(c.getAlpha()).toUpperCase(Locale.ENGLISH);
    final String rc = Integer.toHexString(c.getRed()).toUpperCase(Locale.ENGLISH);
    final String gc = Integer.toHexString(c.getGreen()).toUpperCase(Locale.ENGLISH);
    final String bc = Integer.toHexString(c.getBlue()).toUpperCase(Locale.ENGLISH);

    final StringBuilder result = new StringBuilder(7);
    result.append('#');
    if (alpha) {/*from w  w w . j a  v a  2 s .  c om*/
        if (ac.length() == 1) {
            result.append('0');
        }
        result.append(ac);
    }
    if (rc.length() == 1) {
        result.append('0');
    }
    result.append(rc);
    if (gc.length() == 1) {
        result.append('0');
    }
    result.append(gc);
    if (bc.length() == 1) {
        result.append('0');
    }
    result.append(bc);

    return result.toString();
}

From source file:org.opensha.commons.util.XMLUtils.java

/**
 * Convenience method for writing a java 'Color' object to XML with the given
 * element name/*from   www  .j a va 2 s . c om*/
 * 
 * @param parent
 * @param color
 * @param elName
 */
public static void colorToXML(Element parent, Color color, String elName) {
    Element el = parent.addElement(elName);
    el.addAttribute("r", color.getRed() + "");
    el.addAttribute("g", color.getGreen() + "");
    el.addAttribute("b", color.getBlue() + "");
    el.addAttribute("a", color.getAlpha() + "");
}

From source file:se.ngm.ditaaeps.EpsRenderer.java

public static boolean isColorDark(Color color) {
    int brightness = Math.max(color.getRed(), color.getGreen());
    brightness = Math.max(color.getBlue(), brightness);
    if (brightness < 200) {
        if (DEBUG)
            System.out.println("Color " + color + " is dark");
        return true;
    }//from   w w  w.j  a  v  a 2  s .  c  om
    if (DEBUG)
        System.out.println("Color " + color + " is not dark");
    return false;
}