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:motordrivertxrx.View.MainView.java

/**
 * Creates new form MainView//w ww . ja  va2  s . co m
 */
public MainView() {
    initComponents();

    this.dataset1 = new DefaultValueDataset(10.0);
    this.dataset2 = new DefaultValueDataset(50.0);

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    plot.setDataset(0, this.dataset1);
    plot.setDataset(1, this.dataset2);
    SimpleDialFrame dialFrame = new SimpleDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.DARK_GRAY);
    plot.setDialFrame(dialFrame);
    /*
    GradientPaint gp = new GradientPaint(new Point(), 
        new Color(255, 255, 255), new Point(), 
        new Color(170, 170, 220));
    */
    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), Color.ORANGE);

    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setBackground(db);

    DialTextAnnotation annotation1 = new DialTextAnnotation("Velocidad");
    annotation1.setFont(new Font("Dialog", Font.BOLD, 14));
    annotation1.setRadius(0.7);

    plot.addLayer(annotation1);

    DialValueIndicator dvi = new DialValueIndicator(0, "c");
    dvi.setFont(new Font("Dialog", Font.PLAIN, 10));
    dvi.setOutlinePaint(Color.darkGray);
    dvi.setRadius(0.60);
    dvi.setAngle(-103.0);
    plot.addLayer(dvi);

    DialValueIndicator dvi2 = new DialValueIndicator(1, "c");
    dvi2.setFont(new Font("Dialog", Font.PLAIN, 10));
    dvi2.setOutlinePaint(Color.red);
    dvi2.setRadius(0.60);
    dvi2.setAngle(-77.0);
    plot.addLayer(dvi2);

    StandardDialScale scale = new StandardDialScale(0, 127, -120, -300);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14));
    plot.addScale(0, scale);

    StandardDialScale scale2 = new StandardDialScale(0, 100, -120, -300);
    scale2.setTickRadius(0.50);
    scale2.setTickLabelOffset(0.15);
    scale2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    scale2.setMajorTickPaint(Color.red);
    plot.addScale(1, scale2);
    plot.mapDatasetToScale(1, 1);

    DialPointer needle2 = new DialPointer.Pin(1);
    needle2.setRadius(0.55);
    plot.addLayer(needle2);

    DialPointer needle = new DialPointer.Pointer(0);
    plot.addLayer(needle);

    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart1 = new JFreeChart(plot);
    chart1.setTitle("Velocidad motor");
    ChartPanel cp1 = new ChartPanel(chart1);
    cp1.setPreferredSize(new Dimension(400, 400));

    /*JPanel sliderPanel = new JPanel(new GridLayout(2, 2));
    sliderPanel.add(new JLabel("Outer Needle:"));
    sliderPanel.add(new JLabel("Inner Needle:"));
    this.slider1 = new JSlider(-40, 60);
    this.slider1.setMajorTickSpacing(20);
    this.slider1.setPaintTicks(true);
    this.slider1.setPaintLabels(true);
    this.slider1.addChangeListener(this);
    sliderPanel.add(this.slider1);
    sliderPanel.add(this.slider1);
    this.slider2 = new JSlider(0, 100);
    this.slider2.setMajorTickSpacing(20);
    this.slider2.setPaintTicks(true);
    this.slider2.setPaintLabels(true);
    this.slider2.addChangeListener(this);
    sliderPanel.add(this.slider2);*/

    velocimetroPanel.add(cp1);

}

From source file:org.jfree.chart.demo.selection.SelectionDemo6Pie.java

private static JFreeChart createChart(final PieDataset dataset,
        DatasetSelectionExtension<PieCursor<String>> ext) {
    JFreeChart chart = ChartFactory.createPieChart("Pie Chart Demo 2", dataset);

    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);// ww  w  .  j  a v  a2  s  . co m
    plot.setInteriorGap(0.1);

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

    ext.addChangeListener(new SelectionChangeListener<PieCursor<String>>() {
        public void selectionChanged(SelectionChangeEvent<PieCursor<String>> event) {
            for (int i = 0; i < dataset.getItemCount(); i++) {
                cursor.setPosition((String) 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:spec.reporter.Utils.java

public static void createBmResultGraph(BenchmarkRecord record) {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String iterName = "";
    double max = 0;
    double min = Long.MAX_VALUE;
    for (int i = 0; i < record.iterRecords.size(); i++) {
        BenchmarkRecord.IterationRecord iterRecord = (BenchmarkRecord.IterationRecord) record.iterRecords
                .get(i);// ww  w. ja v a 2s .c o m
        String shortName = iterRecord.iterName.replaceFirst("ation", "");
        if (iterRecord.score > max) {
            max = iterRecord.score;
            iterName = shortName;
        }

        if (iterRecord.score < min) {
            min = iterRecord.score;
        }

        dataset.addValue(iterRecord.score, " ", shortName);
    }

    JFreeChart chart = ChartFactory.createLineChart("  ", "iterations", Constants.WORKLOAD_METRIC, dataset,
            PlotOrientation.VERTICAL, false, true, false);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(new Color(201, 222, 254));
    plot.setRangeGridlinePaint(Color.WHITE);
    if (record.isValidRun() && min != Long.MAX_VALUE) {
        plot.getRangeAxis().setRange(min - 10, max + 10);
    } else {
        plot.getRangeAxis().setRange(0, max + 10);
    }
    ValueMarker vm = new ValueMarker(record.maxScore);
    vm.setLabel(Utils.df.format(record.maxScore));
    vm.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    vm.setLabelTextAnchor(TextAnchor.HALF_ASCENT_LEFT);

    plot.addRangeMarker(vm);
    CategoryMarker marker = new CategoryMarker(iterName);
    marker.setDrawAsLine(true);
    marker.setPaint(vm.getPaint());
    plot.addDomainMarker(marker);
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setFillPaint(Color.WHITE);
    renderer.setSeriesPaint(0, Color.BLUE.darker());

    try {
        ChartUtilities.saveChartAsJPEG(new File(Utils.getFullImageName(record.name + "_results")), chart, 300,
                200);
    } catch (Exception e) {
        System.out.println("Problems...");
    }
}

From source file:Gui.Graficos.java

private void init(String titulo, String tituloX, String tituloY) {

    panel = new JPanel();
    panel.setBackground(Color.WHITE);

    getContentPane().add(panel);/*from w w  w  .jav  a 2  s .c  o  m*/

    // Creando el Grafico

    JFreeChart chart = ChartFactory.createBarChart3D(titulo, tituloX, tituloY, dataset,
            PlotOrientation.VERTICAL, true, true, false);

    chart.setBackgroundPaint(new Color(225, 255, 228));
    chart.getTitle().setPaint(Color.black);
    CategoryPlot p = chart.getCategoryPlot();
    p.setRangeGridlinePaint(Color.red);

    // Mostrar Grafico

    ChartPanel chartPanel = new ChartPanel(chart);
    panel.add(chartPanel);

    // panel.setLayout(new VerticalLayout());

    panel.add(btAceptar);

    //panel.
    panel.setLayout(null);

    chartPanel.setBounds(100, 10, 1100, 600);
    btAceptar.setBounds(1065, 620, 130, 30);

}

From source file:PaintUtils.java

/** Uses translucent shades of white and black to draw highlights
 * and shadows around a rectangle, and then frames the rectangle
 * with a shade of gray (120).//from   w  ww.j  ava 2 s . c om
 * <P>This should be called to add a finishing touch on top of
 * existing graphics.
 * @param g the graphics to paint to.
 * @param r the rectangle to paint.
 */
public static void drawBevel(Graphics g, Rectangle r) {
    drawColors(blacks, g, r.x, r.y + r.height, r.x + r.width, r.y + r.height, SwingConstants.SOUTH);
    drawColors(blacks, g, r.x + r.width, r.y, r.x + r.width, r.y + r.height, SwingConstants.EAST);

    drawColors(whites, g, r.x, r.y, r.x + r.width, r.y, SwingConstants.NORTH);
    drawColors(whites, g, r.x, r.y, r.x, r.y + r.height, SwingConstants.WEST);

    g.setColor(new Color(120, 120, 120));
    g.drawRect(r.x, r.y, r.width, r.height);
}

From source file:net.sf.webphotos.tools.Thumbnail.java

/**
 * Busca no arquivo de configurao, classe
 * {@link net.sf.webphotos.util.Config Config}, os tamnahos dos 4 thumbs e
 * seta esses valores nas variveis desta classe. Testa se o usurio setou
 * valores de marca d'gua e texto para o thumb4, caso afirmativo, busca os
 * valores necessrios no arquivo de configurao.
 *//*  ww w .  ja  v  a2s.  c  o m*/
private static void inicializar() {

    // le as configuraes do usurio
    Configuration c = Util.getConfig();

    // tamanhos de thumbnails
    t1 = c.getInt("thumbnail1");
    t2 = c.getInt("thumbnail2");
    t3 = c.getInt("thumbnail3");
    t4 = c.getInt("thumbnail4");

    // usuario setou marca d'agua para thumbnail 4 ?
    // TODO: melhorar teste para captao destes parametros
    try {
        marcadagua = c.getString("marcadagua");
        mdPosicao = c.getInt("marcadagua.posicao");
        mdMargem = c.getInt("marcadagua.margem");
        mdTransparencia = c.getInt("marcadagua.transparencia");
    } catch (Exception ex) {
        ex.printStackTrace(Util.err);
    }

    // usurio setou texto para o thumbnail 4 ?
    try {
        texto = c.getString("texto");
        txPosicao = c.getInt("texto.posicao");
        txMargem = c.getInt("texto.margem");
        txTamanho = c.getInt("texto.tamanho");
        txEstilo = c.getInt("texto.estilo");
        txFamilia = c.getString("texto.familia");

        String[] aux = c.getStringArray("texto.corFrente");
        txCorFrente = new Color(Integer.parseInt(aux[0]), Integer.parseInt(aux[1]), Integer.parseInt(aux[2]));
        aux = c.getStringArray("texto.corFundo");
        txCorFundo = new Color(Integer.parseInt(aux[0]), Integer.parseInt(aux[1]), Integer.parseInt(aux[2]));
    } catch (Exception ex) {
        ex.printStackTrace(Util.err);
    }

}

From source file:Classes_Home.CriarGrafico.java

public void criargrafico(JPanel jPanel3) {
        String pcs[] = { "'HP'", "'IBM'", "'LENOVO'", "'POSITIVO'", "'NACIONAL'" };
        for (int i = 0; i <= 4; i++) {
            String query = "SELECT * FROM `cpu` WHERE marca = " + pcs[i];

            try {
                st = connection.createStatement();
                rs = st.executeQuery(query);
                if (rs.last()) {
                    int aux = rs.getRow();
                    vetorParaGrafico[i] = aux;
                }/*w  w w  .j ava 2s  . c o  m*/
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.setValue(vetorParaGrafico[0], "Quantidade", "HP");
        dataset.setValue(vetorParaGrafico[1], "Quantidade", "IBM");
        dataset.setValue(vetorParaGrafico[2], "Quantidade", "LENOVO");
        dataset.setValue(vetorParaGrafico[3], "Quantidade", "POSITIVO");
        dataset.setValue(vetorParaGrafico[4], "Quantidade", "NACIONAL");

        JFreeChart chart = ChartFactory.createBarChart3D(null, null, "Quantidade", dataset,
                PlotOrientation.VERTICAL, false, true, false);
        CategoryPlot p = chart.getCategoryPlot();
        CategoryItemRenderer renderer = p.getRenderer();
        renderer.setSeriesPaint(0, new Color(80, 151, 204));
        p.setRangeGridlinePaint(Color.BLACK);
        ChartPanel panel = new ChartPanel(chart);
        panel.setDomainZoomable(true);
        panel.setVisible(true);
        jPanel3.setLayout(new BorderLayout());
        jPanel3.add(panel, BorderLayout.CENTER);
        jPanel3.revalidate();
        jPanel3.repaint();
        System.gc();
    }

From source file:edu.asu.mgb.gui.AggregateTransformer.java

@Override
public Transformer<State, Paint> getVertexPaintTransformer() {
    return new Transformer<State, Paint>() {
        @Override//from  w w w  . j a v  a 2  s  .c o  m
        public Paint transform(State state) {
            float ratio;
            float intensity = state.getNormalizedIntensity();
            if (intensity == Problem.INITIAL) {
                // Initial position
                return Color.BLUE;
            } else if (intensity == Problem.CORRECT) {
                ratio = state.getCorrectRatio();
                return new Color(1 - ratio, 1, 1 - ratio);
            } else if (intensity == Problem.INCORRECT) {
                ratio = state.getWrongRatio();
                return new Color(1, 1 - ratio, 1 - ratio);
            } else {
                return Color.WHITE;
            }
        }
    };
}

From source file:de.uniol.ui.tsv.ui.StepChartDialog.java

protected JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createXYStepChartFast(title, xTitle, yTitle, xy, PlotOrientation.VERTICAL,
            true, false, false);/*  w  ww.  j  a  v a  2 s  .  c om*/

    chart.setBackgroundPaint(Color.white);
    chart.getLegend().setBackgroundPaint(new Color(224, 224, 224));

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(224, 224, 224));
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setRenderer(new XYStepRendererFast(null, null));

    XYItemRenderer xyr = plot.getRenderer();
    //      xyr.setBaseToolTipGenerator(new XYToolTipGenerator() {
    //         public String generateToolTip(XYDataset dataset, int series,
    //               int item) {
    //            return nf.format(dataset.getXValue(series, item))
    //                  + tooltipRangeUnits + ", "
    //                  + nf2.format(dataset.getYValue(series, item))
    //                  + tooltipValueUnits;
    //         }
    //      });

    for (int i : seriesStrokes.keySet()) {
        xyr.setSeriesStroke(i, seriesStrokes.get(i));
    }
    for (int i : seriesColors.keySet()) {
        xyr.setSeriesPaint(i, seriesColors.get(i));
    }

    DateAxis da = new DateAxis(xTitle);
    if (useRelativeHourFormat) {
        da.setDateFormatOverride(new RelativeHourFormat());
    }
    da.setLowerMargin(0.03);
    plot.setDomainAxis(da);

    ValueAxis yaxis = plot.getRangeAxis();
    yaxis.setRange(new Range(minRange, maxRange));

    return chart;
}

From source file:edu.purdue.cc.bionet.util.Spectrum.java

public Paint getPaint(float value) throws IllegalArgumentException {
    if (!this.inRange(value)) {
        if (this.outOfRangePaint != null) {
            return this.outOfRangePaint;
        } else {//w  w  w .  j  a va 2  s.co  m
            throw new IllegalArgumentException(String.format(
                    "%f is not a valid value for this %s. The value must be between %f and %f (inclusive).",
                    value, this.getClass().getName(), this.range.getMin(), this.range.getMax()));
        }
    }
    value = this.normalize(value);
    return new Color(this.getRed(value), this.getGreen(value), this.getBlue(value));
}