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:at.gv.egiz.pdfas.common.utils.ImageUtils.java

public static BufferedImage convertRGBAToIndexed(BufferedImage src) {
    BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED);
    Graphics g = dest.getGraphics();
    g.setColor(new Color(231, 20, 189));
    g.fillRect(0, 0, dest.getWidth(), dest.getHeight()); // fill with a
    // hideous color
    // and make it
    // transparent
    dest = makeTransparent(dest, 0, 0);// w  w w . j a v  a  2s . c om
    dest.createGraphics().drawImage(src, 0, 0, null);
    return dest;
}

From source file:ar.com.fdvs.dj.test.StylesReport2Test.java

public DynamicReport buildReport() throws Exception {

    //      Style detailStyle = new Style();
    Style detailStyle = new StyleBuilder(false).setTransparency(Transparency.OPAQUE)
            .setBackgroundColor(new Color(200, 200, 230)).build();

    Style headerStyle = new Style();
    headerStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
    headerStyle.getFont().setItalic(true);
    headerStyle.setBorderTop(Border.PEN_2_POINT);
    headerStyle.setBorderBottom(Border.THIN);
    headerStyle.setBackgroundColor(Color.blue);
    headerStyle.setTransparency(Transparency.OPAQUE);
    headerStyle.setTextColor(Color.white);
    headerStyle.setHorizontalAlign(HorizontalAlign.CENTER);
    headerStyle.setVerticalAlign(VerticalAlign.MIDDLE);
    headerStyle.setRotation(Rotation.LEFT);

    Style titleStyle = new Style();
    titleStyle.setFont(new Font(10, Font._FONT_VERDANA, true));
    Style numberStyle = new Style();
    numberStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    Style amountStyle = new Style();
    amountStyle.setHorizontalAlign(HorizontalAlign.RIGHT);
    amountStyle.setBackgroundColor(Color.cyan);
    amountStyle.setTransparency(Transparency.OPAQUE);
    amountStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
    amountStyle.getFont().setUnderline(true);
    amountStyle.setPaddingBottom(new Integer(5));
    Style oddRowStyle = new Style();
    oddRowStyle.setBorder(Border.NO_BORDER);
    Color veryLightGrey = new Color(230, 230, 230);
    oddRowStyle.setBackgroundColor(veryLightGrey);
    oddRowStyle.setTransparency(Transparency.OPAQUE);

    Style variableStyle = new Style();
    BeanUtils.copyProperties(variableStyle, amountStyle);
    variableStyle.setFont(Font.ARIAL_MEDIUM_BOLD);
    variableStyle.setBackgroundColor(Color.PINK);

    Style variableStyle2 = new Style();
    BeanUtils.copyProperties(variableStyle2, amountStyle);
    variableStyle2.setFont(Font.ARIAL_MEDIUM_BOLD);
    variableStyle2.setBackgroundColor(Color.ORANGE);

    DynamicReportBuilder drb = new DynamicReportBuilder();
    Integer margin = new Integer(20);

    drb.setTitle("November 2006 sales report") //defines the title of the report
            .setSubtitle("The items in this report correspond "
                    + "to the main products: DVDs, Books, Foods and Magazines")
            .setTitleStyle(titleStyle).setTitleHeight(new Integer(30))
            .setDefaultStyles(null, null, null, detailStyle).setSubtitleHeight(new Integer(20))
            .setDetailHeight(new Integer(15))
            //         .setLeftMargin(margin)
            //         .setRightMargin(margin)
            //         .setTopMargin(margin)
            //         .setBottomMargin(margin)
            .setPrintBackgroundOnOddRows(true).setOddRowBackgroundStyle(oddRowStyle)
            .setColumnsPerPage(new Integer(1)).setColumnSpace(new Integer(5));

    AbstractColumn columnState = ColumnBuilder.getNew().setColumnProperty("state", String.class.getName())
            .setTitle("State").setWidth(new Integer(85)).setStyle(detailStyle).setHeaderStyle(headerStyle)
            .build();/* w w  w. j  av  a 2  s.c  o  m*/

    AbstractColumn columnBranch = ColumnBuilder.getNew().setColumnProperty("branch", String.class.getName())
            .setTitle("Branch").setWidth(new Integer(85)).setStyle(detailStyle).setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnaProductLine = ColumnBuilder.getNew()
            .setColumnProperty("productLine", String.class.getName()).setTitle("Product Line")
            .setWidth(new Integer(85)).setStyle(detailStyle).setHeaderStyle(headerStyle).build();

    AbstractColumn columnaItem = ColumnBuilder.getNew().setColumnProperty("item", String.class.getName())
            .setTitle("item").setWidth(new Integer(85)).setStyle(detailStyle).setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnCode = ColumnBuilder.getNew().setColumnProperty("id", Long.class.getName())
            .setTitle("ID").setWidth(new Integer(40)).setStyle(numberStyle).setHeaderStyle(headerStyle).build();

    AbstractColumn columnaCantidad = ColumnBuilder.getNew().setColumnProperty("quantity", Long.class.getName())
            .setTitle("Quantity").setWidth(new Integer(80)).setStyle(numberStyle).setHeaderStyle(headerStyle)
            .build();

    AbstractColumn columnAmount = ColumnBuilder.getNew().setColumnProperty("amount", Float.class.getName())
            .setTitle("Amount").setWidth(new Integer(90)).setPattern("$ 0.00").setStyle(amountStyle)
            .setHeaderStyle(headerStyle).build();

    drb.addColumn(columnState);
    drb.addColumn(columnaItem);
    drb.addColumn(columnBranch);
    drb.addColumn(columnaProductLine);
    drb.addColumn(columnCode);
    drb.addColumn(columnaCantidad);
    drb.addColumn(columnAmount);

    DJGroup group = new GroupBuilder().setCriteriaColumn((PropertyColumn) columnState)
            .addFooterVariable(columnAmount, DJCalculation.SUM, variableStyle).build();
    drb.addGroup(group);

    DJGroup group2 = new GroupBuilder().setCriteriaColumn((PropertyColumn) columnaItem)
            .addFooterVariable(columnAmount, DJCalculation.SUM).build();
    drb.addGroup(group2);

    group2.setDefaulFooterVariableStyle(variableStyle2);

    drb.setUseFullPageWidth(true);

    DynamicReport dr = drb.build();
    //      saveXML(dr,"dynamicReport");
    return dr;
}

From source file:monitordispositivos.RecibirVotos.java

public void actualizarConteo() {
    /*//from w ww  .j  ava2  s .  c o m
    * Porcentaje
    */
    votos = votos + 1;
    lblvotos_totales.setText("" + votos);
    porcentaje = (votos * 100) / poblacion;
    if (porcentaje >= 100.0 || (porcentaje % 1) == 0)
        decimales = new DecimalFormat("0");
    else
        decimales = new DecimalFormat("0.00");
    lblporcentaje.setText("" + decimales.format(porcentaje) + "%");

    // Fuente de Datos
    data = new DefaultPieDataset();
    data.setValue("SI", votos);
    data.setValue("NO", poblacion - votos);
    // Creando el Grafico
    chart = ChartFactory.createPieChart("", data, false, false, false);
    chart.setBackgroundPaint(Color.white);

    plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setLabelGenerator(null);
    plot.setOutlineVisible(false);
    plot.setSectionPaint("SI", new Color(0, 204, 0));
    plot.setSectionPaint("NO", new Color(218, 24, 24));

    // Crear el Panel del Grafico con ChartPanel
    chartPanel = new ChartPanel(chart);
    chartPanel.setEnabled(false);
    pnlgrafica.setLayout(new java.awt.BorderLayout());
    pnlgrafica.removeAll();
    pnlgrafica.add(chartPanel, BorderLayout.CENTER);
    pnlgrafica.validate();
}

From source file:org.jfree.expdemo.SelectionDemo6Pie.java

private static JFreeChart createChart(final PieDataset dataset, DatasetSelectionExtension ext) {
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", // chart title
            dataset, // dataset
            true, // include legend
            true, false);/*from  w ww.  jav a 2 s  .  c  o  m*/

    final PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionPaint("One", new Color(160, 160, 255));
    plot.setSectionPaint("Two", new Color(128, 128, 255 - 32));
    plot.setSectionPaint("Three", new Color(96, 96, 255 - 64));
    plot.setSectionPaint("Four", new Color(64, 64, 255 - 96));
    plot.setSectionPaint("Five", new Color(32, 32, 255 - 128));
    plot.setSectionPaint("Six", new Color(0, 0, 255 - 144));

    plot.setNoDataMessage("No data available");

    plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} ({2} percent)"));
    plot.setLabelBackgroundPaint(new Color(220, 220, 220));

    plot.setLegendLabelToolTipGenerator(new StandardPieSectionLabelGenerator("Tooltip for legend item {0}"));
    plot.setSimpleLabels(true);
    plot.setInteriorGap(0.1);

    //pie plots done use abstract renderers need to react to selection on our own
    final PieCursor cursor = new PieCursor();

    ext.addSelectionChangeListener(new SelectionChangeListener() {
        public void selectionChanged(SelectionChangeEvent event) {
            for (int i = 0; i < dataset.getItemCount(); i++) {
                cursor.setPosition(dataset.getKey(i));
                if (event.getSelectionExtension().isSelected(cursor)) {
                    plot.setExplodePercent(cursor.key, 0.15);
                } else {
                    plot.setExplodePercent(cursor.key, 0.0);
                }
            }
        }
    });

    return chart;
}

From source file:edu.stanford.epadd.launcher.Splash.java

void setSplashText(String text) {
    if (splash == null)
        return;//from  w w w  .j  a  v  a  2 s  .  c  o m

    // clear the previous text
    g.setColor(new Color(1, 117, 188)); // #0175bc
    g.fillRect(300, 175, ((int) splash.getBounds().getWidth()) - 300, 40); // x=300 is where the logo starts, so we left-align to it. width is usually 795
    g.setPaintMode();

    // write the new text
    g.setColor(Color.WHITE); // #0175bc
    g.drawString(text, 300, 200);
    //      g.setFont(new Font("Serif", Font.PLAIN, 12));
    splash.update();
}

From source file:org.jax.maanova.plot.PlotUtil.java

/**
 * Create a simple monochrome XY renderer which can be used for scatter plots
 * @return  the renderer//  w  w w. j  a  va2  s.  c  om
 */
public static XYLineAndShapeRenderer createMonochromeScatterPlotRenderer() {
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    renderer.setAutoPopulateSeriesShape(false);
    renderer.setAutoPopulateSeriesOutlinePaint(false);
    renderer.setAutoPopulateSeriesOutlineStroke(false);
    renderer.setAutoPopulateSeriesPaint(false);

    renderer.setBaseShape(new Ellipse2D.Float(-PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS / 2F,
            -PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS / 2F, PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS,
            PlotUtil.SCATTER_PLOT_DOT_SIZE_PIXELS));

    renderer.setUseOutlinePaint(true);
    renderer.setBaseOutlinePaint(Color.BLACK);
    renderer.setBaseOutlineStroke(new BasicStroke(0.25F));

    renderer.clearSeriesPaints(false);
    renderer.setBasePaint(new Color(0x55, 0x55, 0xFF)); // blue

    return renderer;
}

From source file:edu.scripps.fl.curves.plot.CurvePlotDrawingSupplier.java

private static Color toGreyScale(Color c) {
    int rgb = (int) (((double) c.getRed() * 0.299) + ((double) c.getGreen() * 0.587)
            + ((double) c.getBlue() * 0.114));
    if (rgb > 255)
        rgb = 255;/*from   www. j  av  a 2  s .c o  m*/
    return new Color(rgb, rgb, rgb);
}

From source file:org.jfree.graphics2d.demo.SVGPieChartDemo1.java

/**
 * Creates a chart./*from w ww .  j  ava2s .c o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // chart title
            dataset);
    chart.removeLegend();

    // set a custom background for the chart
    chart.setBackgroundPainter(new GradientPainter(new Color(20, 20, 20), RectangleAnchor.TOP_LEFT,
            Color.DARK_GRAY, RectangleAnchor.BOTTOM_RIGHT));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPainter(null);
    plot.setInteriorGap(0.04);
    plot.setBorderPainter(null);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:LayeredPaneDemo4.java

public MDIPane() {
    addComponentListener(this);
    setOpaque(true);

    // default background color
    setBackground(new Color(244, 232, 152));
}

From source file:openqcm.ChartDynamicData.java

public ChartDynamicData() {

    // add primary axis frequency
    TimeSeries seriesFrequency = new TimeSeries("Frequency (Hz)");
    datasetFrequency = new TimeSeriesCollection(seriesFrequency);
    rangeAxisF = new NumberAxis("Frequency (Hz)");
    XYItemRenderer renderer = new StandardXYItemRenderer();
    renderer.setSeriesPaint(0, new Color(0, 142, 192));
    rangeAxisF.setAutoRangeIncludesZero(false);
    rangeAxisF.setAutoRange(true);//from  w  ww  .ja  v a  2 s. co  m
    rangeAxisF.setAutoRangeMinimumSize(50);

    plot.setDataset(0, datasetFrequency);
    plot.setRangeAxis(0, rangeAxisF);
    plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
    plot.setRenderer(0, renderer);
    plot.mapDatasetToRangeAxis(0, 0);

    // add secondary axis temperature
    TimeSeries seriesTemperature = new TimeSeries("Temperature (C)");
    datasetTemperature = new TimeSeriesCollection(seriesTemperature);
    plot.setDataset(1, datasetTemperature);
    NumberAxis rangeAxisT = new NumberAxis("Temperature (C)");
    rangeAxisT.setAutoRangeIncludesZero(false);
    rangeAxisT.setAutoRange(true);
    rangeAxisT.setAutoRangeMinimumSize(5);
    plot.setRangeAxis(1, rangeAxisT);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    // custom renderer for dinamically changing temperaure
    rendererT.setSeriesPaint(0, new Color(255, 128, 0));
    plot.setRenderer(1, rendererT);

    plot.mapDatasetToRangeAxis(1, 1);
    plotComb.add(plot);
    plotComb.setBackgroundPaint(Color.white);
    plotComb.setDomainGridlinePaint(Color.white);
    plotComb.setRangeGridlinePaint(Color.white);
    // enable panning for both axis
    plotComb.setRangePannable(true);
    plotComb.setDomainPannable(true);

    // set time axis properties
    // format time axis as hh:mm:ss
    SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
    DateAxis axis = (DateAxis) plotComb.getDomainAxis();
    axis.setDateFormatOverride(format);
    // default auto range
    domainAxis.setAutoRange(true);

    // init the JFreeChart
    JFreeChart chart = new JFreeChart(plotComb);
    chart.setBorderPaint(Color.lightGray);
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(Color.white);

    // set legend properties
    LegendTitle legend = chart.getLegend();
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemFont(new Font("Dialog", Font.PLAIN, 9));

    // constructor for org.jfree.chart.ChartPanel
    // ChartPanel(JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
    ChartPanel chartPanel = new ChartPanel(chart, false, true, true, true, true);
    // enable mouse wheel support for the chart panel
    chartPanel.setMouseWheelEnabled(true);

    this.setLayout(new BorderLayout());
    // add real time chart to the frame
    this.add(chartPanel);
    this.validate();
}