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(ColorSpace cspace, float[] components, float alpha) 

Source Link

Document

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Usage

From source file:com.embedler.moon.jtxt2img.CoreHelper.java

public static Color hex2Rgb(String colorStr) {
    Validate.notBlank(colorStr, "Color string must not be null");
    String _color = StringUtils.rightPad(StringUtils.removeStart(colorStr, "#"), 6,
            colorStr.charAt(colorStr.length() - 1));
    return new Color(Integer.valueOf(_color.substring(0, 2), 16), Integer.valueOf(_color.substring(2, 4), 16),
            Integer.valueOf(_color.substring(4, 6), 16));
}

From source file:org.csml.tommo.sugar.heatmap.ColorPaintScale.java

@Override
public Color getPaint(double value) {
    value = validateValue(value);//from   w w w.j  ava 2 s .c  o  m
    double factor = (value - minValue) / (maxValue - minValue);
    return new Color(getRed(factor), getGreen(factor), getBlue(factor));
}

From source file:eu.delving.sip.base.ReportChartHelper.java

public static JPanel createPresenceChart(DataSet dataSet, String prefix, int[] presence, int totalRecords) {
    DefaultCategoryDataset data = new DefaultCategoryDataset();
    int index = 0;
    for (RecDef.Check check : RecDef.Check.values()) {
        data.addValue(presence[index], "Presence", check);
        index++;/*from  ww  w . j av  a2  s.  c  o m*/
    }
    JFreeChart chart = ChartFactory.createBarChart(
            String.format("Field presence in %s / %s", dataSet.getSpec(), prefix), "Field",
            String.format("Record count of %d records", totalRecords), data, PlotOrientation.VERTICAL, false,
            true, false);
    chart.addSubtitle(new TextTitle("Field Presence"));
    return finishBarChart(chart, new Color(218, 112, 214));
}

From source file:image.writer.ImageWriterExample1.java

/**
 * Paints a few things on a Graphics2D instance.
 * @param g2d the Graphics2D instance/* w  w  w. ja va 2 s.c  o  m*/
 * @param pageNum a page number
 */
protected void paintSome(Graphics2D g2d, int pageNum) {
    //Paint a bounding box
    g2d.drawRect(0, 0, 400, 200);

    //A few rectangles rotated and with different color
    Graphics2D copy = (Graphics2D) g2d.create();
    int c = 12;
    for (int i = 0; i < c; i++) {
        float f = ((i + 1) / (float) c);
        Color col = new Color(0.0f, 1 - f, 0.0f);
        copy.setColor(col);
        copy.fillRect(70, 90, 50, 50);
        copy.rotate(-2 * Math.PI / (double) c, 70, 90);
    }
    copy.dispose();

    //Some text
    copy = (Graphics2D) g2d.create();
    copy.rotate(-0.25);
    copy.setColor(Color.RED);
    copy.setFont(new Font("sans-serif", Font.PLAIN, 36));
    copy.drawString("Hello world!", 140, 140);
    copy.setColor(Color.RED.darker());
    copy.setFont(new Font("serif", Font.PLAIN, 36));
    copy.drawString("Hello world!", 140, 180);
    copy.dispose();

    //Try attributed text
    AttributedString aString = new AttributedString("This is attributed text.");
    aString.addAttribute(TextAttribute.FAMILY, "SansSerif");
    aString.addAttribute(TextAttribute.FAMILY, "Serif", 8, 18);
    aString.addAttribute(TextAttribute.FOREGROUND, Color.orange, 8, 18);
    g2d.drawString(aString.getIterator(), 250, 170);

    g2d.drawString("Page: " + pageNum, 250, 190);
}

From source file:java2d.ps.EPSColorsExample.java

/**
 * Creates an EPS file. The contents are painted using a Graphics2D
 * implementation that generates an EPS file.
 * /*  ww  w  . j  a v  a 2 s . co m*/
 * @param outputFile
 *            the target file
 * @throws IOException
 *             In case of an I/O error
 */
public static void generateEPSusingJava2D(final File outputFile) throws IOException {
    OutputStream out = new java.io.FileOutputStream(outputFile);
    out = new java.io.BufferedOutputStream(out);
    try {
        // Instantiate the EPSDocumentGraphics2D instance
        final EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
        g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

        // Set up the document size
        g2d.setupDocument(out, 400, 200); // 400pt x 200pt

        // Paint a bounding box
        g2d.drawRect(0, 0, 400, 200);

        g2d.setFont(new Font("sans-serif", Font.BOLD, 14));
        g2d.drawString("Color usage example:", 10, 20);
        g2d.setFont(new Font("sans-serif", Font.PLAIN, 12));
        g2d.drawString("RGB", 10, 84);
        g2d.drawString("CMYK", 60, 84);
        g2d.drawString("(Lab)", 110, 84);
        g2d.drawString("(Named)", 160, 84);

        // We're creating a few boxes all filled with some variant of the
        // "Postgelb" (postal yellow) color as used by Swiss Post.

        final Color colRGB = new Color(255, 204, 0);
        g2d.setColor(colRGB);
        g2d.fillRect(10, 30, 40, 40);

        // Just convert RGB to CMYK and use that
        final float[] compsRGB = colRGB.getColorComponents(null);
        final DeviceCMYKColorSpace cmykCS = ColorSpaces.getDeviceCMYKColorSpace();
        final float[] compsCMYK = cmykCS.fromRGB(compsRGB);
        final Color colCMYK = DeviceCMYKColorSpace.createCMYKColor(compsCMYK);
        g2d.setColor(colCMYK);
        g2d.fillRect(60, 30, 40, 40);

        // Try CIELab (not implemented, yet)
        final CIELabColorSpace d50 = ColorSpaces.getCIELabColorSpaceD50();
        final Color colLab = d50.toColor(83.25f, 16.45f, 96.89f, 1.0f);
        g2d.setColor(colLab);
        g2d.fillRect(110, 30, 40, 40);

        // Try named color (Separation, not implemented, yet)
        final float[] c1xyz = d50.toCIEXYZNative(83.25f, 16.45f, 96.89f);
        final NamedColorSpace postgelb = new NamedColorSpace("Postgelb", c1xyz);
        final Color colNamed = new Color(postgelb, new float[] { 1.0f }, 1.0f);
        g2d.setColor(colNamed);
        g2d.fillRect(160, 30, 40, 40);

        // Cleanup
        g2d.finish();
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:com.jtk.pengelolaanujian.view.dashboard.PiePanelVnv.java

private ChartPanel createChart(PieDataset data) {
    piechart = ChartFactory.createPieChart("Soal Vnv", data, true, true, false);
    PiePlot plot = (PiePlot) piechart.getPlot();
    plot.setSectionPaint("Belum Di VNV", new Color(135, 206, 250));
    plot.setSectionPaint("sudah Di VNV", new Color(205, 133, 63));
    plot.setNoDataMessage("Data Tidak Ada");
    plot.setExplodePercent("data", 0.1D);
    plot.setLabelBackgroundPaint(new Color(255, 228, 225));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator());

    // Key = 0 ----> section as String (Windows, Linux, Lainnya)
    // Key = 1 ----> section as value (300,200,100)
    // KEy - 2 ----> section as percentage (50%,33%,17 %) Muncul jika aplikasi telah di running
    plot.setSimpleLabels(true);//from  w w  w.j av a 2 s  . c om
    plot.setInteriorGap(0.0D);
    return new ChartPanel(piechart);
}

From source file:com.jmu.service.Patchca.PatchcaService.java

@PostConstruct
public void init() {
    cs.setColorFactory(new ColorFactory() {
        @Override/* www  .  ja va 2  s.c  om*/
        public Color getColor(int x) {
            int[] c = new int[3];
            int i = random.nextInt(c.length);
            for (int fi = 0; fi < c.length; fi++) {
                if (fi == i) {
                    c[fi] = random.nextInt(71);
                } else {
                    c[fi] = random.nextInt(256);
                }
            }
            return new Color(c[0], c[1], c[2]);
        }
    });

    cs.setFilterFactory(new CurvesRippleFilterFactory());

    // ??
    MyCustomBackgroundFactory backgroundFactory = new MyCustomBackgroundFactory();
    cs.setBackgroundFactory(backgroundFactory);

    // ??,?,o0
    RandomWordFactory wf = new RandomWordFactory();
    wf.setCharacters("abcdefghkmnpqstwxyz23456789ABCDEFGHGKLMNPQRSTUVWXYZ");
    wf.setMaxLength(4);
    wf.setMinLength(4);
    cs.setWordFactory(wf);

    // ??
    RandomFontFactory ff = new RandomFontFactory();
    ff.setMinSize(32);
    ff.setMaxSize(28);
    cs.setFontFactory(ff);

    // 
    ConfigurableFilterFactory filterFactory = new ConfigurableFilterFactory();
    List<BufferedImageOp> filters = new ArrayList<BufferedImageOp>();
    WobbleImageOp wobbleImageOp = new WobbleImageOp();
    wobbleImageOp.setEdgeMode(AbstractImageOp.EDGE_MIRROR);
    wobbleImageOp.setxAmplitude(2.0);
    wobbleImageOp.setyAmplitude(1.0);
    filters.add(wobbleImageOp);
    filterFactory.setFilters(filters);
    cs.setFilterFactory(filterFactory);

    // 
    BestFitTextRenderer textRenderer = new BestFitTextRenderer();
    textRenderer.setBottomMargin(3);
    textRenderer.setTopMargin(3);
    cs.setTextRenderer(textRenderer);
}

From source file:com.jtk.pengelolaanujian.view.dashboard.PiePanelUjian.java

private ChartPanel createChart(PieDataset data) {
    piechart = ChartFactory.createPieChart("Ujian Status", data, true, true, false);
    PiePlot plot = (PiePlot) piechart.getPlot();
    plot.setSectionPaint("Terlalui", new Color(60, 70, 5));
    plot.setSectionPaint("Belum", new Color(100, 20, 30));
    plot.setNoDataMessage("Data Tidak Ada");
    plot.setExplodePercent("data", 0.1D);
    plot.setLabelBackgroundPaint(new Color(255, 228, 225));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator());

    // Key = 0 ----> section as String (Windows, Linux, Lainnya)
    // Key = 1 ----> section as value (300,200,100)
    // KEy - 2 ----> section as percentage (50%,33%,17 %) Muncul jika aplikasi telah di running

    plot.setSimpleLabels(true);//from  ww w.j ava  2s  . c o m
    plot.setInteriorGap(0.0D);
    return new ChartPanel(piechart);
}

From source file:ScrollBarColorSelect.java

public void adjustmentValueChanged(AdjustmentEvent evt) {
    redLabel.setText("Red " + red.getValue());
    greenLabel.setText("Green " + green.getValue());
    blueLabel.setText("Blue " + blue.getValue());
    colorPanel.setBackground(new Color(red.getValue(), green.getValue(), blue.getValue()));

    colorPanel.repaint();/*from w  ww  . j a va 2 s . co m*/
}

From source file:com.jtk.pengelolaanujian.view.dashboard.PiePanelNilai.java

private ChartPanel createChart(PieDataset data) {
    piechart = ChartFactory.createPieChart("Nilai Upload", data, true, true, false);
    PiePlot plot = (PiePlot) piechart.getPlot();
    plot.setSectionPaint("Belum Di Print", new Color(60, 70, 5));
    plot.setSectionPaint("Sudah Di Print", new Color(100, 20, 30));
    plot.setNoDataMessage("Data Tidak Ada");
    plot.setExplodePercent("data", 0.1D);
    plot.setLabelBackgroundPaint(new Color(255, 228, 225));
    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({1})"));
    plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator());

    // Key = 0 ----> section as String (Windows, Linux, Lainnya)
    // Key = 1 ----> section as value (300,200,100)
    // KEy - 2 ----> section as percentage (50%,33%,17 %) Muncul jika aplikasi telah di running

    plot.setSimpleLabels(true);/*from  ww  w .  j a  v  a  2 s. c  om*/
    plot.setInteriorGap(0.0D);
    return new ChartPanel(piechart);
}