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.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * Method contributed by Alexej Suchov//from   w  ww.jav  a 2s. com
 *
 * @see Graphics2D#setComposite(Composite)
 */
@Override
public void setComposite(final Composite comp) {

    if (comp instanceof AlphaComposite) {

        final AlphaComposite composite = (AlphaComposite) comp;

        if (composite.getRule() == 3) {

            alpha = composite.getAlpha();
            this.composite = composite;

            if (realPaint != null && (realPaint instanceof Color)) {

                final Color c = (Color) realPaint;
                paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (c.getAlpha() * alpha));
            }
            return;
        }
    }

    this.composite = comp;
    alpha = 1.0F;

}

From source file:net.sf.jasperreports.engine.export.JRRtfExporter.java

/**
 * Return color index from header of the .rtf file. If a color is not
 * found is automatically added to the header of the rtf file. The
 * method is called first when the header of the .rtf file is constructed
 * and when a component needs a color for foreground or background
 * @param color Color for which the index is required.
 * @return index of the color from .rtf file header
 *//*w  w w. j a  va  2 s.  c  o m*/
private int getColorIndex(Color color) throws IOException {
    int colorNdx = colors.indexOf(color);
    if (colorNdx < 0) {
        colorNdx = colors.size();
        colors.add(color);
        colorWriter.write(
                "\\red" + color.getRed() + "\\green" + color.getGreen() + "\\blue" + color.getBlue() + ";");
    }
    return colorNdx;
}

From source file:userinterface.graph.Graph.java

/**
 * Allows graphs to be saved to the PRISM 'gra' file format.
 * //from w  ww  . j a  va 2s . co  m
 * @param file
 *            The file to save the graph to.
 * @throws GraphException
 *             If the file cannot be written.
 */
public void save(File file) throws PrismException {
    try {
        JFreeChart chart = getChart();
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.newDocument();

        Element chartFormat = doc.createElement("chartFormat");

        chartFormat.setAttribute("versionString", prism.Prism.getVersion());
        chartFormat.setAttribute("graphTitle", getTitle());

        Font titleFont = getTitleFont().f;
        chartFormat.setAttribute("titleFontName", titleFont.getName());
        chartFormat.setAttribute("titleFontSize", "" + titleFont.getSize());
        chartFormat.setAttribute("titleFontStyle", "" + titleFont.getStyle());

        Color titleFontColor = (Color) getTitleFont().c;
        chartFormat.setAttribute("titleFontColourR", "" + titleFontColor.getRed());
        chartFormat.setAttribute("titleFontColourG", "" + titleFontColor.getGreen());
        chartFormat.setAttribute("titleFontColourB", "" + titleFontColor.getBlue());

        chartFormat.setAttribute("legendVisible", isLegendVisible() ? "true" : "false");

        Font legendFont = getLegendFont().f;
        chartFormat.setAttribute("legendFontName", "" + legendFont.getName());
        chartFormat.setAttribute("legendFontSize", "" + legendFont.getSize());
        chartFormat.setAttribute("legendFontStyle", "" + legendFont.getStyle());

        Color legendFontColor = getLegendFont().c;

        chartFormat.setAttribute("legendFontColourR", "" + legendFontColor.getRed());
        chartFormat.setAttribute("legendFontColourG", "" + legendFontColor.getGreen());
        chartFormat.setAttribute("legendFontColourB", "" + legendFontColor.getBlue());

        switch (getLegendPosition()) {
        case LEFT:
            chartFormat.setAttribute("legendPosition", "left");
            break;
        case BOTTOM:
            chartFormat.setAttribute("legendPosition", "bottom");
            break;
        case TOP:
            chartFormat.setAttribute("legendPosition", "top");
            break;
        default:
            chartFormat.setAttribute("legendPosition", "right");
        }

        Element layout = doc.createElement("layout");
        chartFormat.appendChild(layout);

        Element xAxis = doc.createElement("axis");
        getXAxisSettings().save(xAxis);
        chartFormat.appendChild(xAxis);

        Element yAxis = doc.createElement("axis");
        getYAxisSettings().save(yAxis);
        chartFormat.appendChild(yAxis);

        synchronized (getSeriesLock()) {
            /* Make sure we preserve ordering. */
            for (int i = 0; i < seriesList.getSize(); i++) {
                SeriesKey key = seriesList.getKeyAt(i);

                Element series = doc.createElement("graph");
                SeriesSettings seriesSettings = getGraphSeries(key);
                seriesSettings.save(series);

                XYSeries seriesData = getXYSeries(key);

                for (int j = 0; j < seriesData.getItemCount(); j++) {
                    Element point = doc.createElement("point");

                    point.setAttribute("x", "" + seriesData.getX(j));
                    point.setAttribute("y", "" + seriesData.getY(j));

                    series.appendChild(point);
                }

                chartFormat.appendChild(series);
            }
        }

        doc.appendChild(chartFormat);

        // File writing 
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.setOutputProperty("doctype-system", "chartformat.dtd");
        t.setOutputProperty("indent", "yes");
        t.transform(new DOMSource(doc), new StreamResult(new FileOutputStream(file)));
    } catch (IOException e) {
        throw new PrismException(e.getMessage());
    } catch (DOMException e) {
        throw new PrismException("Problem saving graph: DOM Exception: " + e);
    } catch (ParserConfigurationException e) {
        throw new PrismException("Problem saving graph: Parser Exception: " + e);
    } catch (TransformerConfigurationException e) {
        throw new PrismException("Problem saving graph: Error in creating XML: " + e);
    } catch (TransformerException e) {
        throw new PrismException("Problem saving graph: Transformer Exception: " + e);
    } catch (SettingException e) {
        throw new PrismException(e.getMessage());
    }
}

From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java

/**
 * Set the stroking color, specified as RGB.
 * /* w w  w  . jav  a  2  s. c o m*/
 * @param color
 *            The color to set.
 * @throws IOException
 *             If an IO error occurs while writing to the stream.
 */
public void setStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java

/**
 * Set the non stroking color, specified as RGB.
 * //from   w  w w . j a  va  2 s  .  c  o  m
 * @param color
 *            The color to set.
 * @throws IOException
 *             If an IO error occurs while writing to the stream.
 */
public void setNonStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:lcmc.common.ui.ResourceGraph.java

/** Draws text on the vertex. */
private void drawVertexText(final Graphics2D g2d, final TextLayout textLayout, final double x, final double y,
        final Color color, final int alpha) {
    if (color != null) {
        g2d.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), alpha));
    }/*from   www .  j  a va  2s  .c om*/
    textLayout.draw(g2d, (float) x, (float) y);
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

private String serializeHighlightToString(Color cd) {
    if (cd != null) {
        int red = (cd.getRed() + 255) / 2;
        int green = (cd.getGreen() + 255) / 2;
        int blue = (cd.getBlue() + 255) / 2;

        String r = Integer.toHexString(red);
        if (red <= 0xF)
            r = "0" + r; //$NON-NLS-1$
        String g = Integer.toHexString(green);
        if (green <= 0xF)
            g = "0" + g; //$NON-NLS-1$
        String b = Integer.toHexString(blue);
        if (blue <= 0xF)
            b = "0" + b; //$NON-NLS-1$

        return "#" + r + g + b; //$NON-NLS-1$
    }//from   ww  w  . ja  va  2  s.  co  m

    return ""; //$NON-NLS-1$
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java

/**
 * Utility function to update a scatterplot line's data series.
 * @param data the datagraph data./*from w w  w.  j  a va2 s  . com*/
 * @param sheet the Excel sheet which contains corresponding data from the scatterplot data series.
 * @param seriesIdx the index of the data in the dategraph data.
 * @param series the XML object representing the series in the chart.
 */
private static void updateCTScatterSer(final DategraphData data, final XSSFSheet sheet, final int seriesIdx,
        final CTScatterSer series) {
    final String sheetName = sheet.getSheetName();

    // the series idx starts from 0
    final DategraphData.Row row = data.getRows().get(seriesIdx);
    final String title = row.getLabel();
    final Color color = Color.decode(row.getColor());

    series.getOrder().setVal(seriesIdx);
    series.getIdx().setVal(seriesIdx);

    final CTSolidColorFillProperties fill = series.getSpPr().getLn().getSolidFill();

    // We have to set any possible colour type, PowerPoint throws an error if there's multiple fills, and we don't
    //   know what colour type the user may have used in their template slide.
    if (fill.getSchemeClr() != null) {
        fill.unsetSchemeClr();
    }
    if (fill.getSrgbClr() != null) {
        fill.unsetSrgbClr();
    }
    if (fill.getHslClr() != null) {
        fill.unsetHslClr();
    }
    if (fill.getPrstClr() != null) {
        fill.unsetPrstClr();
    }
    if (fill.getScrgbClr() != null) {
        fill.unsetScrgbClr();
    }
    if (fill.getSysClr() != null) {
        fill.unsetSysClr();
    }

    final CTSRgbColor fillClr = fill.addNewSrgbClr();
    final byte[] colorBytes = { (byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue() };
    fillClr.setVal(colorBytes);

    final CTMarker marker = series.getMarker();

    if (marker != null) {
        final CTShapeProperties markerSpPr = marker.getSpPr();
        unsetSpPrFills(markerSpPr);
        markerSpPr.addNewSolidFill().addNewSrgbClr().setVal(colorBytes);

        final CTLineProperties markerLn = markerSpPr.getLn();
        if (markerLn != null) {
            unsetLineFills(markerLn);
            markerLn.addNewSolidFill().addNewSrgbClr().setVal(colorBytes);
        }
    }

    final CTStrRef strRef = series.getTx().getStrRef();
    strRef.getStrCache().getPtArray()[0].setV(title);

    strRef.setF(new CellReference(sheetName, 0, seriesIdx + 1, true, true).formatAsString());

    final long[] timestamps = data.getTimestamps();
    {
        final CTNumRef timestampCatNumRef = series.getXVal().getNumRef();
        timestampCatNumRef.setF(new AreaReference(new CellReference(sheetName, 1, 0, true, true),
                new CellReference(sheetName, 1 + timestamps.length, 0, true, true)).formatAsString());

        final CTNumData timeStampCatNumCache = timestampCatNumRef.getNumCache();
        timeStampCatNumCache.getPtCount().setVal(timestamps.length);
        timeStampCatNumCache.setPtArray(null);

        for (int ii = 0; ii < timestamps.length; ++ii) {
            final CTNumVal pt = timeStampCatNumCache.addNewPt();
            pt.setIdx(ii);
            pt.setV(sheet.getRow(1 + ii).getCell(0).getRawValue());
        }
    }

    {
        final double[] seriesData = row.getValues();

        final CTNumRef valuesNumRef = series.getYVal().getNumRef();
        valuesNumRef.setF(new AreaReference(new CellReference(sheetName, 1, seriesIdx + 1, true, true),
                new CellReference(sheetName, 1 + timestamps.length, seriesIdx + 1, true, true))
                        .formatAsString());

        final CTNumData valuesNumCache = valuesNumRef.getNumCache();
        valuesNumCache.getPtCount().setVal(timestamps.length);
        valuesNumCache.setPtArray(null);

        for (int ii = 0; ii < timestamps.length; ++ii) {
            final CTNumVal pt = valuesNumCache.addNewPt();
            pt.setIdx(ii);
            pt.setV(Double.toString(seriesData[ii]));
        }
    }
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

public void setXORMode(Color xorColor) {
    if ((color == null) || (xorColor == null))
        return;//from w w w  . j  av  a 2s.c  o  m

    int newColor = ((xorColor.getRed() << 16) + (xorColor.getGreen() << 8) + xorColor.getBlue())
            ^ ((color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());
    int r = newColor >> 16 & 0x0000FF;
    int g = (0x00FF00 & newColor) >> 8;
    int b = 0x0000FF & newColor;
    color = new Color(r, g, b);
}

From source file:org.eclipse.birt.chart.device.svg.SVGGraphics2D.java

/**
 * @returns the color definition in a string with the format: #RRGGBBAA:
 *          RRGGBB are the color components in hexa in the range 00..FF AA
 *          is the transparency value in hexa in the range 00..FF ex: Solid
 *          light gray : #777777/*from w ww.  jav  a 2 s  .  co  m*/
 */
protected String serializeToString(Color color) {

    String r = Integer.toHexString(color.getRed());
    if (color.getRed() <= 0xF)
        r = "0" + r; //$NON-NLS-1$
    String g = Integer.toHexString(color.getGreen());
    if (color.getGreen() <= 0xF)
        g = "0" + g; //$NON-NLS-1$
    String b = Integer.toHexString(color.getBlue());
    if (color.getBlue() <= 0xF)
        b = "0" + b; //$NON-NLS-1$

    String ret = "#" + r + g + b; //$NON-NLS-1$
    return ret;
}