Example usage for java.awt Color decode

List of usage examples for java.awt Color decode

Introduction

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

Prototype

public static Color decode(String nm) throws NumberFormatException 

Source Link

Document

Converts a String to an integer and returns the specified opaque Color .

Usage

From source file:org.owasp.benchmark.score.report.ScatterScores.java

private JFreeChart display(String title, int height, int width, List<Report> toolResults) {
    JFrame f = new JFrame(title);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries series = new XYSeries("Scores");
    for (int i = 0; i < toolResults.size(); i++) {
        Report toolReport = toolResults.get(i);
        OverallResults overallResults = toolReport.getOverallResults();
        series.add(overallResults.getFalsePositiveRate() * 100, overallResults.getTruePositiveRate() * 100);
    }/*from  ww w  .j  a  va2 s.com*/
    dataset.addSeries(series);

    chart = ChartFactory.createScatterPlot(title, "False Positive Rate", "True Positive Rate", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    String fontName = "Arial";
    DecimalFormat pctFormat = new DecimalFormat("0'%'");

    theme = (StandardChartTheme) org.jfree.chart.StandardChartTheme.createJFreeTheme();
    theme.setExtraLargeFont(new Font(fontName, Font.PLAIN, 24)); // title
    theme.setLargeFont(new Font(fontName, Font.PLAIN, 20)); // axis-title
    theme.setRegularFont(new Font(fontName, Font.PLAIN, 16));
    theme.setSmallFont(new Font(fontName, Font.PLAIN, 12));
    theme.setRangeGridlinePaint(Color.decode("#C0C0C0"));
    theme.setPlotBackgroundPaint(Color.white);
    theme.setChartBackgroundPaint(Color.white);
    theme.setGridBandPaint(Color.red);
    theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0));
    theme.setBarPainter(new StandardBarPainter());
    theme.setAxisLabelPaint(Color.decode("#666666"));
    theme.apply(chart);

    XYPlot xyplot = chart.getXYPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    NumberAxis domainAxis = (NumberAxis) xyplot.getDomainAxis();

    xyplot.setOutlineVisible(true);

    rangeAxis.setRange(-5, 109.99);
    rangeAxis.setNumberFormatOverride(pctFormat);
    rangeAxis.setTickLabelPaint(Color.decode("#666666"));
    rangeAxis.setMinorTickCount(5);
    rangeAxis.setTickUnit(new NumberTickUnit(10));
    rangeAxis.setAxisLineVisible(true);
    rangeAxis.setMinorTickMarksVisible(true);
    rangeAxis.setTickMarksVisible(true);
    rangeAxis.setLowerMargin(10);
    rangeAxis.setUpperMargin(10);
    xyplot.setRangeGridlineStroke(new BasicStroke());
    xyplot.setRangeGridlinePaint(Color.lightGray);
    xyplot.setRangeMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setRangeMinorGridlinesVisible(true);

    domainAxis.setRange(-5, 105);
    domainAxis.setNumberFormatOverride(pctFormat);
    domainAxis.setTickLabelPaint(Color.decode("#666666"));
    domainAxis.setMinorTickCount(5);
    domainAxis.setTickUnit(new NumberTickUnit(10));
    domainAxis.setAxisLineVisible(true);
    domainAxis.setTickMarksVisible(true);
    domainAxis.setMinorTickMarksVisible(true);
    domainAxis.setLowerMargin(10);
    domainAxis.setUpperMargin(10);
    xyplot.setDomainGridlineStroke(new BasicStroke());
    xyplot.setDomainGridlinePaint(Color.lightGray);
    xyplot.setDomainMinorGridlinePaint(Color.decode("#DDDDDD"));
    xyplot.setDomainMinorGridlinesVisible(true);

    chart.setTextAntiAlias(true);
    chart.setAntiAlias(true);
    chart.removeLegend();
    chart.setPadding(new RectangleInsets(20, 20, 20, 20));
    xyplot.getRenderer().setSeriesPaint(0, Color.decode("#4572a7"));

    //        // setup item labels
    //        XYItemRenderer renderer = xyplot.getRenderer();
    //        Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 7.0f, 7.0f);
    //        for ( int i = 0; i < dataset.getSeriesCount(); i++ ) {
    //            renderer.setSeriesShape(i, circle);
    //            renderer.setSeriesPaint(i, Color.blue);
    //            String label = ""+((String)dataset.getSeries(i).getKey());
    //            int idx = label.indexOf( ':');
    //            label = label.substring( 0, idx );
    //            StandardXYItemLabelGenerator generator = new StandardXYItemLabelGenerator(label); 
    //            renderer.setSeriesItemLabelGenerator(i, generator); 
    //            renderer.setSeriesItemLabelsVisible(i, true);
    //            ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER );
    //            renderer.setSeriesPositiveItemLabelPosition(i, position);
    //        }

    makeDataLabels(toolResults, xyplot);
    makeLegend(toolResults, 57, 48, dataset, xyplot);

    Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 6, 3 },
            0);
    for (XYDataItem item : (List<XYDataItem>) series.getItems()) {
        double x = item.getX().doubleValue();
        double y = item.getY().doubleValue();
        double z = (x + y) / 2;
        XYLineAnnotation score = new XYLineAnnotation(x, y, z, z, dashed, Color.blue);
        xyplot.addAnnotation(score);
    }

    //        // put legend inside plot
    //        LegendTitle lt = new LegendTitle(xyplot);
    //        lt.setItemFont(theme.getSmallFont());
    //        lt.setPosition(RectangleEdge.RIGHT);
    //        lt.setItemFont(theme.getSmallFont());
    //        XYTitleAnnotation ta = new XYTitleAnnotation(.7, .55, lt, RectangleAnchor.TOP_LEFT);
    //        ta.setMaxWidth(0.48);
    //        xyplot.addAnnotation(ta);

    // draw guessing line
    XYLineAnnotation guessing = new XYLineAnnotation(-5, -5, 105, 105, dashed, Color.red);
    xyplot.addAnnotation(guessing);

    XYPointerAnnotation worse = makePointer(75, 5, "Worse than guessing", TextAnchor.TOP_CENTER, 90);
    xyplot.addAnnotation(worse);

    XYPointerAnnotation better = makePointer(25, 100, "Better than guessing", TextAnchor.BOTTOM_CENTER, 270);
    xyplot.addAnnotation(better);

    XYTextAnnotation stroketext = new XYTextAnnotation("                     Random Guess", 88, 107);
    stroketext.setTextAnchor(TextAnchor.CENTER_RIGHT);
    stroketext.setBackgroundPaint(Color.white);
    stroketext.setPaint(Color.red);
    stroketext.setFont(theme.getRegularFont());
    xyplot.addAnnotation(stroketext);

    XYLineAnnotation strokekey = new XYLineAnnotation(58, 107, 68, 107, dashed, Color.red);
    xyplot.setBackgroundPaint(Color.white);
    xyplot.addAnnotation(strokekey);

    ChartPanel cp = new ChartPanel(chart, height, width, 400, 400, 1200, 1200, false, false, false, false,
            false, false);
    f.add(cp);
    f.pack();
    f.setLocationRelativeTo(null);
    //      f.setVisible(true);
    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.linecharts.LineChart.java

public JFreeChart createChart() {

    logger.debug("IN");
    CategoryPlot plot = new CategoryPlot();

    NumberAxis rangeAxis = new NumberAxis("Kpi Values");
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    Color colorLabel = Color.decode("#000000");
    rangeAxis.setLabelPaint(colorLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    rangeAxis.setTickLabelPaint(colorLabel);
    plot.setRangeAxis(rangeAxis);/*w w  w  .  j a  v a  2s . c om*/

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setLabelPaint(colorLabel);
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setTickLabelPaint(colorLabel);
    plot.setDomainAxis(domainAxis);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    //I create a line renderer 
    MyStandardCategoryItemLabelGenerator generator = null;

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
    lineRenderer.setShapesFilled(true);
    lineRenderer.setBaseItemLabelGenerator(generator);
    lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12));
    lineRenderer.setBaseItemLabelPaint(colorLabel);
    lineRenderer.setBaseItemLabelsVisible(true);

    DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line");

    for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
        String serName = (String) iterator.next();
        String labelName = "";
        int index = -1;
        index = datasetLine.getRowIndex(serName);

        Color color = Color.decode("#990200");
        lineRenderer.setSeriesPaint(index, color);
    }

    plot.setDataset(0, datasetLine);
    plot.setRenderer(0, lineRenderer);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    logger.debug("Chart created");
    TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.setTitle(title);
    TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle);
    TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle2);
    chart.removeLegend();

    chart.setBackgroundPaint(Color.white);
    logger.debug("OUT");
    return chart;
}

From source file:com.netsteadfast.greenstep.action.CommonBarChartAction.java

private void setPlotColor(CategoryPlot plot, List<String> names, List<String> colors) throws Exception {
    Paint[] paints = new Paint[colors.size()];
    for (int ix = 0; ix < names.size(); ix++) {
        paints[ix] = Color.decode(colors.get(ix));
    }//  w w  w. j  a v  a 2s . co  m
    CategoryItemRenderer renderer = new CustomRenderer(paints);
    plot.setRenderer(renderer);
}

From source file:org.zaproxy.zap.extension.viewstate.HttpPanelViewStateView.java

private JPanel getContainerPanel() {
    if (container == null) {
        container = new JPanel();
        container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
        JScrollPane cScroll = new JScrollPane();
        cScroll.setName(CAPTION_NAME);/*from ww w  . j a va 2s  .co m*/
        cScroll.setViewportView(getHexTableBody());
        // Outer scroll size constraints
        container.setPreferredSize(new Dimension(0, 100));
        // Setup text field for ViewState info
        vsInfoTxt = new JFormattedTextField();
        vsInfoTxt.setEditable(false);
        vsInfoTxt.setBackground(Color.decode("#D6D9DF"));
        vsInfoTxt.setFont(FontUtils.getFont("Courier", Font.BOLD));
        // Add to container
        container.add(cScroll);
        container.add(vsInfoTxt);
    }
    return container;
}

From source file:org.geopublishing.atlasStyler.swing.PolygonSymbolEditGUI.java

/**
 * This method initializes jComboBox/*  w w w  .j  av  a 2  s .c  om*/
 * 
 * @return javax.swing.JComboBox
 */
private ColorButton getJButtonFillColor() {
    if (jButtonFillColor == null) {
        jButtonFillColor = new ColorButton();

        jButtonFillColor.setAction(new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {

                Fill fill = symbolizer.getFill();

                Color color = null;
                if (fill != null && fill.getColor() != null) {
                    String substring = fill.getColor().toString();
                    color = Color.decode(substring);
                }
                // Color newColor = JColorChooser.showDialog(
                // PolygonSymbolEditGUI.this, "Choose fill color",
                // color); // i8nAC
                Color newColor = AVSwingUtil.showColorChooser(PolygonSymbolEditGUI.this,
                        AtlasStylerVector.R("Fill.ColorChooserDialog.Title"), color);

                if (newColor != null && newColor != color) {
                    String rgb = Integer.toHexString(newColor.getRGB());
                    rgb = "#" + rgb.substring(2, rgb.length());
                    fill.setColor(ASUtil.ff2.literal(rgb));

                    PolygonSymbolEditGUI.this.firePropertyChange(PROPERTY_UPDATED, null, null);

                    jButtonFillColor.setColor(newColor);

                }

            }

        });

        Fill f = symbolizer.getFill();
        if (f != null) {
            jButtonFillColor.setColor(StylingUtil.getColorFromExpression(f.getColor()));
        } else {
            jButtonFillColor.setColor((Color) null);
            jPanelFill.setEnabled(false);
        }
    }
    return jButtonFillColor;
}

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

static RGB getTypedRGB(String rgbStr) {
    if (rgbStr == null) {
        return null;
    }// w  ww .  jav  a 2s.  c  o m
    if (rgbStr.startsWith("#")) {
        rgbStr = rgbStr.substring(1);
    }
    if (!rgbStr.startsWith("0x")) {
        rgbStr = "0x" + rgbStr;
    }
    Color color = Color.decode(rgbStr);
    return new RGB(color.getRed(), color.getGreen(), color.getBlue());
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.targetcharts.SparkLine.java

@Override
public void configureChart(SourceBean content) {
    logger.debug("IN");
    super.configureChart(content);
    if (confParameters.get(AVG_COLOR) != null
            && !(((String) confParameters.get(AVG_COLOR)).equalsIgnoreCase(""))) {
        String avg_color = (String) confParameters.get(AVG_COLOR);
        Color color = Color.GRAY;
        try {/*from   ww  w .  jav  a 2  s.  c  o  m*/
            color = Color.decode(avg_color);
            if (color != null) {
                colorAverage = color;
            }
        } catch (NumberFormatException e) {
            logger.error("Error in average line color, put default GREY", e);
        }
    }
    logger.debug("OUT");
}

From source file:org.cerberus.refactor.LineChart.java

public BufferedImage bi(TimeSeriesCollection timeseriescollection, String xname, String name, int count) {

    BufferedImage bi = null;// w ww.j av a2  s. c o  m
    boolean fc = false;
    XYDataset xydataset = timeseriescollection;

    JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(name, xname, name, xydataset, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainCrosshairVisible(true);
    xyplot.setRangeCrosshairVisible(false);
    XYItemRenderer xyitemrenderer = xyplot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        Shape point = ShapeUtilities.createDiagonalCross(1, 1);
        String[] seriesColors = { "#FF0000", "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01" };
        String[] seriesColors2 = { "#D7D6F6", "#0F07F3", "#EEFFBD", "#75C53E", "#FED7BA", "#FE6F01" };
        XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
        xylineandshaperenderer.setBaseShapesVisible(true);
        xylineandshaperenderer.setBaseShapesFilled(true);
        for (int a = 0; a < count; a++) {
            xylineandshaperenderer.setSeriesShape(a, point);
            xyitemrenderer.setSeriesStroke(a, new BasicStroke(1.0F));
            //TODO check this - fc is always false
            if (fc) {
                xylineandshaperenderer.setSeriesPaint(a, Color.decode(seriesColors[count - a - 1]));
            } else {
                xylineandshaperenderer.setSeriesPaint(a, Color.decode(seriesColors2[count - a - 1]));
            }
        }

    }
    DateAxis dateaxis = (DateAxis) xyplot.getDomainAxis();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("hh:mm"));

    bi = jfreechart.createBufferedImage(500, 270);

    return bi;

}

From source file:com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D.java

/**
 * Sets the "fillStyle" property./*from ww w  . j a  va2s.c  om*/
 * @param fillStyle the "fillStyle" property
 */
@JsxSetter
public void setFillStyle(String fillStyle) {
    fillStyle = fillStyle.replaceAll("\\s", "");
    Color color = null;
    if (fillStyle.startsWith("rgb(")) {
        final String[] colors = fillStyle.substring(4, fillStyle.length() - 1).split(",");
        color = new Color(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]),
                Integer.parseInt(colors[2]));
    } else if (fillStyle.startsWith("rgba(")) {
        final String[] colors = fillStyle.substring(5, fillStyle.length() - 1).split(",");
        color = new Color(Integer.parseInt(colors[0]), Integer.parseInt(colors[1]), Integer.parseInt(colors[2]),
                (int) (Float.parseFloat(colors[3]) * 255));
    } else if (fillStyle.startsWith("#")) {
        color = Color.decode(fillStyle);
    } else {
        try {
            final Field f = Color.class.getField(fillStyle);
            color = (Color) f.get(null);
        } catch (final Exception e) {
            LOG.info("Can not find color '" + fillStyle + '\'');
            color = Color.black;
        }
    }
    graphics2D_.setColor(color);
}

From source file:it.eng.spagobi.engines.kpi.bo.charttypes.trendcharts.LineChart.java

public JFreeChart createChart() {

    logger.debug("IN");
    CategoryPlot plot = new CategoryPlot();
    IMessageBuilder msgBuilder = MessageBuilderFactory.getMessageBuilder();
    String rangeAxisName = msgBuilder.getMessage("sbi.kpi.rangeAxisName");
    NumberAxis rangeAxis = new NumberAxis(rangeAxisName);
    rangeAxis.setLabelFont(new Font("Arial", Font.PLAIN, 12));
    Color colorLabel = Color.decode("#000000");
    rangeAxis.setLabelPaint(colorLabel);
    rangeAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    rangeAxis.setTickLabelPaint(colorLabel);
    plot.setRangeAxis(rangeAxis);/*  w  w w .  j a  va  2 s .c  o m*/

    CategoryAxis domainAxis = new CategoryAxis();
    domainAxis.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setLabelPaint(colorLabel);
    domainAxis.setTickLabelFont(new Font("Arial", Font.PLAIN, 10));
    domainAxis.setTickLabelPaint(colorLabel);
    plot.setDomainAxis(domainAxis);

    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeGridlinesVisible(true);
    plot.setDomainGridlinesVisible(true);

    //I create a line renderer 
    MyStandardCategoryItemLabelGenerator generator = null;

    LineAndShapeRenderer lineRenderer = new LineAndShapeRenderer();
    lineRenderer.setShapesFilled(true);
    lineRenderer.setBaseItemLabelGenerator(generator);
    lineRenderer.setBaseItemLabelFont(new Font("Arial", Font.PLAIN, 12));
    lineRenderer.setBaseItemLabelPaint(colorLabel);
    lineRenderer.setBaseItemLabelsVisible(true);

    DefaultCategoryDataset datasetLine = (DefaultCategoryDataset) datasetMap.getDatasets().get("line");

    for (Iterator iterator = datasetLine.getRowKeys().iterator(); iterator.hasNext();) {
        String serName = (String) iterator.next();
        String labelName = "";
        int index = -1;
        index = datasetLine.getRowIndex(serName);

        Color color = Color.decode("#990200");
        lineRenderer.setSeriesPaint(index, color);
    }

    plot.setDataset(0, datasetLine);
    plot.setRenderer(0, lineRenderer);

    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    JFreeChart chart = new JFreeChart(plot);
    logger.debug("Chart created");
    TextTitle title = new TextTitle(name, new Font("Arial", Font.BOLD, 16), Color.decode("#990200"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.setTitle(title);
    TextTitle subTitle = new TextTitle(subName, new Font("Arial", Font.PLAIN, 12), Color.decode("#000000"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle);
    TextTitle subTitle2 = new TextTitle(subName, new Font("Arial", Font.PLAIN, 8), Color.decode("#FFFFFF"),
            RectangleEdge.TOP, HorizontalAlignment.CENTER, VerticalAlignment.TOP, RectangleInsets.ZERO_INSETS);
    chart.addSubtitle(subTitle2);
    chart.removeLegend();

    chart.setBackgroundPaint(Color.white);
    logger.debug("OUT");
    return chart;
}