Example usage for java.awt Color getRed

List of usage examples for java.awt Color getRed

Introduction

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

Prototype

public int getRed() 

Source Link

Document

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

Usage

From source file:org.esa.s1tbx.ocean.worldwind.layers.Level2ProductLayer.java

public static AnalyticSurface.GridPointAttributes createColorGradientAttributes(final double value,
        double minValue, double maxValue, double minHue, double maxHue, boolean whiteZero) {
    final double hueFactor = WWMath.computeInterpolationFactor(value, minValue, maxValue);

    //double hue = WWMath.mixSmooth(hueFactor, minHue, maxHue);
    final double hue = WWMath.mix(hueFactor, minHue, maxHue);
    double sat = 1.0;
    if (whiteZero) {
        sat = Math.abs(WWMath.mixSmooth(hueFactor, -1, 1));
    }/*from  w  ww  .ja va 2 s.c  o m*/
    final Color color = Color.getHSBColor((float) hue, (float) sat, 1f);
    final double opacity = WWMath.computeInterpolationFactor(value, minValue,
            minValue + (maxValue - minValue) * 0.1);
    final Color rgbaColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (255 * opacity));

    return AnalyticSurface.createGridPointAttributes(value, rgbaColor);
}

From source file:bwem.example.MapPrinterExample.java

private boolean getZoneColorCppAlgorithmAnyOf(java.util.Map<Area, List<ChokePoint>> chokePointsByArea,
        java.util.Map<Integer, Color> mapZoneColor, Color color) {
    for (Area neighbor : chokePointsByArea.keySet()) {
        int neighborId = neighbor.getId().intValue();
        Color neighboringColor = mapZoneColor.get(neighborId);
        if (neighboringColor != null && (Math.abs(color.getRed() - neighboringColor.getRed())
                + Math.abs(color.getGreen() - neighboringColor.getGreen()) < 150)) {
            return true;
        }//from www  . j  a  v a2  s . com
    }
    return false;
}

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  . j  a  v  a  2 s .com
    };

    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:gov.redhawk.statistics.ui.views.StatisticsView.java

/**
 * This is a callback that will allow us to create the viewer and initialize it.
 *///ww w.j  av a 2  s .  c om
@Override
public void createPartControl(Composite comp) {

    parent = comp;
    parent.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(1).create());

    // Custom Action for the View's Menu
    CustomAction customAction = new CustomAction() {

        @Override
        public void run() {
            SettingsDialog dialog = new SettingsDialog(parent.getShell(), datalist.length, curIndex, numBars);
            dialog.create();
            if (dialog.open() == Window.OK) {
                numBars = dialog.getNumBars();
                curIndex = dialog.getSelectedIndex();
                refreshJob.schedule();
            }
        }
    };
    customAction.setText("Settings");
    getViewSite().getActionBars().getMenuManager().add(customAction);

    // creation of chart composite and selection of associated options
    Composite chartComposite = new Composite(parent, SWT.EMBEDDED);
    chartComposite.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());

    chart = ChartFactory.createXYBarChart(null, null, false, null, dataSet, PlotOrientation.VERTICAL, false,
            true, false);

    org.eclipse.swt.graphics.Color backgroundColor = chartComposite.getBackground();
    chart.setBackgroundPaint(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chart.getXYPlot().setBackgroundPaint(ChartColor.WHITE);

    Frame chartFrame = SWT_AWT.new_Frame(chartComposite);
    chartFrame.setBackground(
            new Color(backgroundColor.getRed(), backgroundColor.getGreen(), backgroundColor.getBlue()));
    chartFrame.setLayout(new GridLayout());

    ChartPanel jFreeChartPanel = new ChartPanel(chart);
    chartFrame.add(jFreeChartPanel);

    ClusteredXYBarRenderer renderer = new ClusteredXYBarRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    renderer.setMargin(0.05);
    renderer.setShadowVisible(false);
    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override
        public String generateLabel(XYDataset dataset, int series, int item) {
            return String.valueOf((int) (dataset.getYValue(series, item)));
        }
    });
    renderer.setBasePaint(new Color(139, 0, 0));
    renderer.setLegendItemLabelGenerator(new XYSeriesLabelGenerator() {

        @Override
        public String generateLabel(XYDataset ds, int i) {
            if (ds.getSeriesCount() == 2) {
                if (i == 0) {
                    return "Real";
                } else if (i == 1) {
                    return "Imaginary";
                } else {
                    return "Complex";
                }
            } else if (ds.getSeriesCount() > 1) {
                return "Dimension " + i;
            }

            return null;
        }
    });
    chart.getXYPlot().setRenderer(renderer);

    dataSet.addChangeListener(new DatasetChangeListener() {

        @Override
        public void datasetChanged(DatasetChangeEvent event) {
            chart.getPlot().datasetChanged(event);

        }
    });

    // creation of the statistics composite
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    section = toolkit.createSection(parent, Section.DESCRIPTION | Section.NO_TITLE | Section.CLIENT_INDENT);
    section.setBackground(parent.getBackground());
    section.setDescription("");
    section.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent

    // Composite for storing the data
    Composite composite = toolkit.createComposite(section, SWT.WRAP);
    composite.setBackground(parent.getBackground());
    composite.setLayout(GridLayoutFactory.fillDefaults().margins(10, 10).numColumns(4).create());
    composite.setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create()); // layout within parent
    toolkit.paintBordersFor(composite);
    section.setClient(composite);

    for (int j = 0; j < STAT_PROPS.length; j++) {
        Label label = new Label(composite, SWT.None);
        label.setText(STAT_PROPS[j] + ":");
        labels[j] = new Label(composite, SWT.None);
        labels[j].setLayoutData(GridDataFactory.fillDefaults().grab(true, false).create());
    }

}

From source file:pack1.test.java

@WebMethod(operationName = "convert")
public String convert(@WebParam(name = "encodedImageStr") String encodedImageStr,
        @WebParam(name = "fileName") String fileName, @WebParam(name = "AOR") String AOR,
        @WebParam(name = "val") int value) {
    System.out.println("Value" + value);
    FileOutputStream imageOutFile = null;
    try {//from   w w  w.j av  a 2 s.  c  o  m
        Connection con, con1;
        Statement stmtnew = null;
        area = Double.parseDouble(AOR);
        //int val=Integer.parseInt(value);
        System.out.println("connecting");
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        System.out.println("connected");
        con = DriverManager.getConnection("jdbc:odbc:test");
        System.out.println(" driver loaded in connection.jsp");
        stmtnew = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        // Decode String using Base64 Class
        byte[] imageByteArray = encodedImageStr.getBytes();
        // Write Image into File system - Make sure you update the path
        imageOutFile = new FileOutputStream(
                "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/cropped" + fileName);
        imageOutFile.write(imageByteArray);
        imageOutFile.close();
        System.out.println("Image Successfully Stored");
        FileInputStream leafPicPath = new FileInputStream(
                "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/cropped" + fileName);
        BufferedImage cat;
        int height, width;
        cat = ImageIO.read(leafPicPath);
        height = cat.getHeight();
        width = cat.getWidth();
        for (int w = 0; w < cat.getWidth(); w++) {

            for (int h = 0; h < cat.getHeight(); h++) {
                // BufferedImage.getRGB() saves the colour of the pixel as a single integer.
                // use Color(int) to grab the RGB values individually.

                Color color = new Color(cat.getRGB(w, h));

                // use the RGB values to get their average.

                int averageColor = ((color.getRed() + color.getGreen() + color.getBlue()) / 3);
                // create a new Color object using the average colour as the red, green and blue

                // colour values

                Color avg = new Color(averageColor, averageColor, averageColor);

                // set the pixel at that position to the new Color object using Color.getRGB().            

                cat.setRGB(w, h, avg.getRGB());

            }

        }
        String greyPicPath = "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/greyscale"
                + fileName;
        greyPicPath = greyPicPath.trim();
        File outputfile = new File(greyPicPath);
        ImageIO.write(cat, "jpg", outputfile);
        System.out.println("Image is successfully converted to grayscale");

        String binPicPath = "C:/Users/Kushagr Jolly/Documents/NetBeansProjects/webservice/IASRI/binary"
                + fileName;
        File f2 = new File(binPicPath);
        System.out.println("1");
        ImageProcessor ip;
        ImagePlus imp = new ImagePlus(greyPicPath);
        System.out.println("2");
        ip = imp.getProcessor();
        ip.invertLut();
        ip.autoThreshold();
        System.out.println("3");
        BufferedImage bf = ip.getBufferedImage();
        System.out.println("4");
        ImageIO.write(bf, "jpg", f2);
        System.out.println("Image is successfully converted to binary image");
        if (choice == 1) {
            String Inserted1 = "insert into test (PhyAOR) values ('" + area + "')";
            System.out.println("InsertedQuery" + Inserted1);
            stmtnew.executeUpdate(Inserted1);
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            String ID = "select MAX(id) as id from test";
            System.out.println("Query" + ID);
            rs = stmt.executeQuery(ID);
            while (rs.next()) {
                id = rs.getInt("id");
            }
            String Inserted2 = "update test set fileName0=? where id=?";
            PreparedStatement ps = con.prepareStatement(Inserted2);
            ps.setString(1, fileName);
            ps.setDouble(2, id);
            int rt = ps.executeUpdate();
            choice++;
        }
        System.out.println(choice);
        if (value == 1) {

            int count = countblackpixel(binPicPath);
            calculatepixA(count, area);
            //returnVal=value+"/"+count+"/"+OnepixArea;

        } else if (value == 2) {

            int flag = countblackpixel(binPicPath);
            // calculatepixA(flag, area);
            leafarea0(flag, area);
            //returnVal=value+"/"+flag+"/"+OnepixArea+"/"+leafArea0;
            //System.out.println(returnVal);
        } else if (value == 3) {
            String Inserted3 = "update test set fileName180=? where id=?";
            PreparedStatement ps1 = con.prepareStatement(Inserted3);
            ps1.setString(1, fileName);
            ps1.setDouble(2, id);
            int rt = ps1.executeUpdate();
            int black = countblackpixel(binPicPath);
            leafarea180(area, black);
            finalarea();
            Statement stmt = con.createStatement();
            ResultSet rs = null;
            String finalans = "select PhyAOR,onePixA,leafarea0,leafarea180,finalleafarea from test where id="
                    + id + "";
            rs = stmt.executeQuery(finalans);
            while (rs.next()) {
                returnVal = rs.getString("PhyAOR") + "/" + rs.getString("onePixA") + "/"
                        + rs.getString("leafarea0") + "/" + rs.getString("leafarea180") + "/"
                        + rs.getString("finalleafarea");
            }
            //returnVal=value+"/"+black+"/"+OnepixArea+"/"+leafArea180+"/"+Leaf_Area;
        } else if (value == 4) {
            finalarea();

        }
        imageOutFile.close();
    } catch (Exception ex) {
        Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
        System.out.println(ex);

    }
    return returnVal;

}

From source file:org.tros.logo.swing.LogoMenuBar.java

/**
 * Set up the tools menu.//from  w ww .ja  v  a  2 s  .  co m
 *
 * @return
 */
private JMenu setupToolsMenu() {
    JMenu toolsMenu = new JMenu(Localization.getLocalizedString("ToolsMenu"));

    toolsPenColorChooser = new JMenuItem(Localization.getLocalizedString("ToolsPenColorChooser"));
    toolsCanvasColorChooser = new JMenuItem(Localization.getLocalizedString("ToolsCanvasColorChooser"));

    toolsPenColorChooser.setMnemonic('P');
    toolsCanvasColorChooser.setMnemonic('C');

    toolsPenColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Color selected = JColorChooser.showDialog(parent, Localization.getLocalizedString("ColorChooser"),
                    null);
            if (selected != null) {
                int red = selected.getRed();
                int green = selected.getGreen();
                int blue = selected.getBlue();
                String hex = String.format("#%02x%02x%02x", red, green, blue);
                controller.insertCommand("pencolor" + " " + hex);
            }
        }
    });
    toolsCanvasColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Color selected = JColorChooser.showDialog(parent, Localization.getLocalizedString("ColorChooser"),
                    null);
            if (selected != null) {
                int red = selected.getRed();
                int green = selected.getGreen();
                int blue = selected.getBlue();
                String hex = String.format("#%02x%02x%02x", red, green, blue);
                controller.insertCommand("canvascolor" + " " + hex);
            }
        }
    });

    toolsMenu.add(toolsPenColorChooser);
    toolsMenu.add(toolsCanvasColorChooser);

    toolsMenu.setMnemonic('T');

    return (toolsMenu);
}

From source file:org.jls.toolbox.math.chart.XYBlockChart.java

/**
 * Permet de modifier l'chelle de couleur utilise par le graphique. Cela
 * va crer un gradient de couleur entre les deux couleurs spcifies, la
 * premire couleur correspondant aux valeurs les plus fortes de l'chelle
 * des donnes  reprsenter. Les bornes infrieure et suprieure permettent
 * de prciser l'tendue des donnes reprsentes par cette chelle de
 * couleur.//from w w  w .j  av a  2s.co  m
 * 
 * @param colorMin
 *            Couleur d'arrive du gradient reprsentant les plus faibles
 *            valeurs de l'chelle.
 * @param colorMax
 *            Couleur de dpart du gradient reprsentant les plus fortes
 *            valeurs de l'chelle.
 * @param lowerBound
 *            Borne infrieure de l'chelle des donnes reprsentes.
 * @param upperBound
 *            Bornes suprieure de l'chelle des donnes reprsentes.
 */
public void setColorGradient(Color colorMin, Color colorMax, double lowerBound, double upperBound) {
    LookupPaintScale scale = new LookupPaintScale(lowerBound, upperBound, Color.lightGray);
    double r1, r2, dr, g1, g2, dg, b1, b2, db;
    int nbVal = (int) (upperBound - lowerBound + 0.5);

    // Acquisition des composantes
    r1 = colorMax.getRed();
    g1 = colorMax.getGreen();
    b1 = colorMax.getBlue();
    r2 = colorMin.getRed();
    g2 = colorMin.getGreen();
    b2 = colorMin.getBlue();

    // Calcul du delta entre les composantes
    dr = (r2 - r1) / nbVal;
    dg = (g2 - g1) / nbVal;
    db = (b2 - b1) / nbVal;

    // Cration du gradient
    for (int i = 0; i < nbVal; i++) {
        scale.add(lowerBound + i, new Color((int) r2, (int) g2, (int) b2));
        r2 = r2 - dr;
        g2 = g2 - dg;
        b2 = b2 - db;
    }

    // Mise  jour du graphique
    this.renderer.setPaintScale(scale);
    this.scaleLegend.setScale(scale);

    // Du fait que la lgende n'est pas lie aux modifications de la courbe,
    // il faut rcrer la lgende  la main.
    this.chart.removeSubtitle(this.scaleLegend);
    createPaintScaleLegend(scale);
}

From source file:org.openhab.binding.diyonxbee.internal.DiyOnXBeeBinding.java

private String makeRGB(Color color) {
    final StringBuilder sb = new StringBuilder(12);
    sb.append("RGB");
    appendColor(sb, color.getRed());
    appendColor(sb, color.getGreen());/*w  w  w  . j  ava  2  s  .  co  m*/
    appendColor(sb, color.getBlue());
    return sb.toString();
}

From source file:haven.Utils.java

public static Color preblend(Color c1, Color c2) {
    double a1 = c1.getAlpha() / 255.0;
    double a2 = c2.getAlpha() / 255.0;
    /* I can't help but feel that this should be possible to
     * express in some simpler form, but I can't see how. */
    double ac = a1 + a2 - (a1 * a2);
    return (new Color((int) Math.round((((c2.getRed() * a2) - (c1.getRed() * a2)) / ac) + c1.getRed()),
            (int) Math.round((((c2.getGreen() * a2) - (c1.getGreen() * a2)) / ac) + c1.getGreen()),
            (int) Math.round((((c2.getBlue() * a2) - (c1.getBlue() * a2)) / ac) + c1.getBlue()),
            (int) Math.round(ac * 255)));
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private Object colorToHTML(Color color) {
    return "#" + String.format("%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
}