Example usage for java.awt Color getBlue

List of usage examples for java.awt Color getBlue

Introduction

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

Prototype

public int getBlue() 

Source Link

Document

Returns the blue component in the range 0-255 in the default sRGB space.

Usage

From source file:org.pentaho.ui.xul.swt.tags.SwtGrid.java

public void setBgcolor(String bgcolor) {
    this.bgcolor = bgcolor;
    Color c = Color.decode(bgcolor);
    grid.setBackground(//from   w  w w . j av a2  s .c  o  m
            new org.eclipse.swt.graphics.Color(grid.getDisplay(), c.getRed(), c.getGreen(), c.getBlue()));
    grid.setBackgroundMode(SWT.INHERIT_DEFAULT);
}

From source file:baocaoxla.xuly_compare.java

public ChartPanel displayhistogram(BufferedImage image) {

    HistogramDataset dataset = new HistogramDataset();

    final int w = image.getWidth();
    final int h = image.getHeight();
    double[] r = new double[w * h];
    double[] g = new double[w * h];
    double[] b = new double[w * h];
    int dem = 0;/*from   w  ww  . j a  v  a 2 s . c  o  m*/
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            Color c = new Color(image.getRGB(j, i));
            r[dem] = c.getRed();
            g[dem] = c.getGreen();
            b[dem] = c.getBlue();
            dem++;
        }
    }
    //r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, 256);
    //r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", g, 256);
    // r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", b, 256);
    // chart
    JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel panel = new ChartPanel(chart);
    return panel;

}

From source file:org.apache.fop.util.ColorUtil.java

private static String toRGBFunctionCall(Color color) {
    StringBuffer sbuf = new StringBuffer();
    sbuf.append('#');
    String s = Integer.toHexString(color.getRed());
    if (s.length() == 1) {
        sbuf.append('0');
    }/* w  w  w. j a v a 2s  .c om*/
    sbuf.append(s);
    s = Integer.toHexString(color.getGreen());
    if (s.length() == 1) {
        sbuf.append('0');
    }
    sbuf.append(s);
    s = Integer.toHexString(color.getBlue());
    if (s.length() == 1) {
        sbuf.append('0');
    }
    sbuf.append(s);
    if (color.getAlpha() != 255) {
        s = Integer.toHexString(color.getAlpha());
        if (s.length() == 1) {
            sbuf.append('0');
        }
        sbuf.append(s);
    }
    return sbuf.toString();
}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the gridlines for the plot's primary range axis, if they are
 * visible./*from   w  w  w . ja v a  2  s  .c  o m*/
 *
 * @param g2  the graphics device.
 * @param area  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawRangeGridlines(Graphics2D g2, Rectangle2D area, List ticks) {

    // no renderer, no gridlines...
    if (getRenderer() == null) {
        return;
    }

    // draw the range grid lines, if any...
    if (isRangeGridlinesVisible() && this.yAxisStepSize > 0) {
        Stroke gridStroke = getRangeGridlineStroke();
        Paint gridPaint = getRangeGridlinePaint();
        ValueAxis axis = getRangeAxis();
        if (axis != null) {
            double lower = axis.getRange().getLowerBound();
            double upper = axis.getRange().getUpperBound();
            double y = lower;
            while (y <= upper) {
                Paint paint = gridPaint;
                if ((y == lower || y == upper) && gridPaint instanceof Color) {
                    Color c = (Color) gridPaint;
                    paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3);
                }
                getRenderer().drawRangeLine(g2, this, getRangeAxis(), area, y, paint, gridStroke);
                y += this.yAxisStepSize;
            }
        }
    }
}

From source file:TableRowColumnTest.java

public PlanetTableFrame() {
    setTitle("TableRowColumnTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    TableModel model = new DefaultTableModel(cells, columnNames) {
        public Class<?> getColumnClass(int c) {
            return cells[0][c].getClass();
        }//from ww w.java  2 s  .c o  m
    };

    table = new JTable(model);

    table.setRowHeight(100);
    table.getColumnModel().getColumn(COLOR_COLUMN).setMinWidth(250);
    table.getColumnModel().getColumn(IMAGE_COLUMN).setMinWidth(100);

    final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
    table.setRowSorter(sorter);
    sorter.setComparator(COLOR_COLUMN, new Comparator<Color>() {
        public int compare(Color c1, Color c2) {
            int d = c1.getBlue() - c2.getBlue();
            if (d != 0)
                return d;
            d = c1.getGreen() - c2.getGreen();
            if (d != 0)
                return d;
            return c1.getRed() - c2.getRed();
        }
    });
    sorter.setSortable(IMAGE_COLUMN, false);
    add(new JScrollPane(table), BorderLayout.CENTER);

    removedRowIndices = new HashSet<Integer>();
    removedColumns = new ArrayList<TableColumn>();

    final RowFilter<TableModel, Integer> filter = new RowFilter<TableModel, Integer>() {
        public boolean include(Entry<? extends TableModel, ? extends Integer> entry) {
            return !removedRowIndices.contains(entry.getIdentifier());
        }
    };

    // create menu

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu selectionMenu = new JMenu("Selection");
    menuBar.add(selectionMenu);

    rowsItem = new JCheckBoxMenuItem("Rows");
    columnsItem = new JCheckBoxMenuItem("Columns");
    cellsItem = new JCheckBoxMenuItem("Cells");

    rowsItem.setSelected(table.getRowSelectionAllowed());
    columnsItem.setSelected(table.getColumnSelectionAllowed());
    cellsItem.setSelected(table.getCellSelectionEnabled());

    rowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setRowSelectionAllowed(rowsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(rowsItem);

    columnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setColumnSelectionAllowed(columnsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(columnsItem);

    cellsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            table.clearSelection();
            table.setCellSelectionEnabled(cellsItem.isSelected());
            updateCheckboxMenuItems();
        }
    });
    selectionMenu.add(cellsItem);

    JMenu tableMenu = new JMenu("Edit");
    menuBar.add(tableMenu);

    JMenuItem hideColumnsItem = new JMenuItem("Hide Columns");
    hideColumnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedColumns();
            TableColumnModel columnModel = table.getColumnModel();

            // remove columns from view, starting at the last
            // index so that column numbers aren't affected

            for (int i = selected.length - 1; i >= 0; i--) {
                TableColumn column = columnModel.getColumn(selected[i]);
                table.removeColumn(column);

                // store removed columns for "show columns" command

                removedColumns.add(column);
            }
        }
    });
    tableMenu.add(hideColumnsItem);

    JMenuItem showColumnsItem = new JMenuItem("Show Columns");
    showColumnsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            // restore all removed columns
            for (TableColumn tc : removedColumns)
                table.addColumn(tc);
            removedColumns.clear();
        }
    });
    tableMenu.add(showColumnsItem);

    JMenuItem hideRowsItem = new JMenuItem("Hide Rows");
    hideRowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedRows();
            for (int i : selected)
                removedRowIndices.add(table.convertRowIndexToModel(i));
            sorter.setRowFilter(filter);
        }
    });
    tableMenu.add(hideRowsItem);

    JMenuItem showRowsItem = new JMenuItem("Show Rows");
    showRowsItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            removedRowIndices.clear();
            sorter.setRowFilter(filter);
        }
    });
    tableMenu.add(showRowsItem);

    JMenuItem printSelectionItem = new JMenuItem("Print Selection");
    printSelectionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int[] selected = table.getSelectedRows();
            System.out.println("Selected rows: " + Arrays.toString(selected));
            selected = table.getSelectedColumns();
            System.out.println("Selected columns: " + Arrays.toString(selected));
        }
    });
    tableMenu.add(printSelectionItem);
}

From source file:ColorBlocks.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Dimension d = getSize();// ww w . ja  va2  s . c o  m
    g2.translate(d.width / 2, d.height / 2);

    Color[] colors = { Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black, Color.red,
            Color.pink, Color.orange, Color.yellow, Color.green, Color.magenta, Color.cyan, Color.blue };

    float size = 25;
    float x = -size * colors.length / 2;
    float y = -size * 3 / 2;

    // Show all the predefined colors.
    for (int i = 0; i < colors.length; i++) {
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(colors[i]);
        g2.fill(r);
    }

    //a linear gradient.
    y += size;
    Color c1 = Color.yellow;
    Color c2 = Color.blue;
    for (int i = 0; i < colors.length; i++) {
        float ratio = (float) i / (float) colors.length;
        int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
        int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
        int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
        Color c = new Color(red, green, blue);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Show an alpha gradient.
    y += size;
    c1 = Color.red;
    for (int i = 0; i < colors.length; i++) {
        int alpha = (int) (255 * (float) i / (float) colors.length);
        Color c = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), alpha);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Draw a frame around the whole thing.
    y -= size * 2;
    Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length, size * 3);
    g2.setPaint(Color.black);
    g2.draw(frame);
}

From source file:org.geoserver.wms.wms_1_1_1.GetLegendGraphicTest.java

/**
 * Tests a dpi rescaled legend/*from w w w.  j av  a2  s .  c o  m*/
 */
@Test
public void testStatesLegendDpiRescaled() throws Exception {
    String base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=Population"
            + "&format=image/png&width=20&height=20&legend_options=dpi:180";
    BufferedImage image = getAsImage(base, "image/png");

    assertPixel(image, 20, 20, Color.RED);
    assertPixel(image, 20, 60, Color.GREEN);
    assertPixel(image, 20, 100, Color.BLUE);
    Color linePixel = getPixelColor(image, 20, 140);
    assertTrue(linePixel.getRed() < 10);
    assertTrue(linePixel.getGreen() < 10);
    assertTrue(linePixel.getBlue() < 10);
}

From source file:org.jfree.eastwood.GXYPlot.java

/**
 * Draws the gridlines for the plot, if they are visible.
 *
 * @param g2  the graphics device./*w ww .j av  a  2s. c o m*/
 * @param dataArea  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {

    // no renderer, no gridlines...
    if (getRenderer() == null) {
        return;
    }

    // draw the domain grid lines, if any...
    if (isDomainGridlinesVisible() && this.xAxisStepSize > 0) {
        Stroke gridStroke = getDomainGridlineStroke();
        Paint gridPaint = getDomainGridlinePaint();
        if ((gridStroke != null) && (gridPaint != null)) {
            ValueAxis axis = getDomainAxis();
            if (axis != null) {
                double lower = axis.getRange().getLowerBound();
                double upper = axis.getRange().getUpperBound();
                double x = lower;
                while (x <= upper) {
                    Paint paint = gridPaint;
                    if ((x == lower || x == upper) && gridPaint instanceof Color) {
                        Color c = (Color) gridPaint;
                        paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 3);
                    }
                    try {
                        setDomainGridlinePaint(paint);
                        getRenderer().drawDomainGridLine(g2, this, getDomainAxis(), dataArea, x);
                    } finally {
                        setDomainGridlinePaint(gridPaint);
                    }
                    x += this.xAxisStepSize;
                }
            }
        }
    }
}

From source file:org.geotools.renderer.chart.GeometryRenderer.java

void drawGeometry(Geometry g, Graphics2D g2, int series, int item, Rectangle2D dataArea, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis) {

    if (g instanceof GeometryCollection) {
        GeometryCollection gc = (GeometryCollection) g;
        for (int i = 0; i < gc.getNumGeometries(); i++) {
            drawGeometry(gc.getGeometryN(i), g2, series, item, dataArea, plot, domainAxis, rangeAxis);
        }//  w ww .  j  a  v a 2  s. com
    } else if (g instanceof Point) {
        drawCoordinate(((Point) g).getCoordinate(), g2, series, item, dataArea, plot, domainAxis, rangeAxis);
    } else if (g instanceof LineString) {
        g2.draw(new TranslatedLiteShape(g, dataArea, plot, domainAxis, rangeAxis));
    } else {

        if (fillPolygons) {
            Paint p = getSeriesPaint(series);
            if (p instanceof Color) {
                Color c = (Color) p;
                p = new Color(c.getRed() / 255f, c.getGreen() / 255f, c.getBlue() / 255f, polygonFillOpacity);
            }
            g2.setPaint(p);
            g2.fill(new TranslatedLiteShape(g, dataArea, plot, domainAxis, rangeAxis));

        }
        g2.setPaint(getSeriesPaint(series));
        g2.draw(new TranslatedLiteShape(g, dataArea, plot, domainAxis, rangeAxis));
    }
}

From source file:org.springframework.boot.ImageBanner.java

private int getLuminance(Color color, boolean inverse) {
    double luminance = 0.0;
    luminance += getLuminance(color.getRed(), inverse, RGB_WEIGHT[0]);
    luminance += getLuminance(color.getGreen(), inverse, RGB_WEIGHT[1]);
    luminance += getLuminance(color.getBlue(), inverse, RGB_WEIGHT[2]);
    return (int) Math.ceil((luminance / 0xFF) * 100);
}