Example usage for java.awt Color getGreen

List of usage examples for java.awt Color getGreen

Introduction

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

Prototype

public int getGreen() 

Source Link

Document

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

Usage

From source file:io.github.minecraftgui.models.network.packets.PacketSetAttribute.java

public PacketSetAttribute(Component component, Shape shape, State state, double percentage, long time,
        Color value) {
    this.component = component;
    this.shape = shape;
    this.state = state;
    this.percentage = percentage;
    this.time = time;
    this.value = new JSONObject().put(NetworkController.R, value.getRed())
            .put(NetworkController.G, value.getGreen()).put(NetworkController.B, value.getBlue())
            .put(NetworkController.A, value.getAlpha());
}

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

/**
 * Tests an custom legend graphic/* ww w. j a va  2 s  . c  o m*/
 */
@Test
public void testCustomLegend() throws Exception {
    String base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=custom"
            + "&format=image/png&width=22&height=22";

    BufferedImage image = getAsImage(base, "image/png");
    Resource resource = getResourceLoader().get("styles/legend.png");
    BufferedImage expected = ImageIO.read(resource.file());

    assertEquals(getPixelColor(expected, 10, 2).getRGB(), getPixelColor(image, 10, 2).getRGB());

    // test rescale
    base = "wms?service=WMS&version=1.1.1&request=GetLegendGraphic" + "&layer=sf:states&style=custom"
            + "&format=image/png&width=16&height=16";

    image = getAsImage(base, "image/png");

    Color expectedColor = getPixelColor(expected, 11, 11);
    Color actualColor = getPixelColor(image, 8, 8);
    assertEquals("red", expectedColor.getRed(), actualColor.getRed());
    assertEquals("green", expectedColor.getGreen(), actualColor.getGreen());
    assertEquals("blue", expectedColor.getBlue(), actualColor.getBlue());
    assertEquals("alpha", expectedColor.getAlpha(), actualColor.getAlpha());

}

From source file:io.github.minecraftgui.models.network.packets.PacketSetAttribute.java

public PacketSetAttribute(Component component, State state, Color value) {
    this.component = component;
    this.shape = component.getShape();
    this.state = state;
    this.percentage = 1;
    this.time = 0;
    this.value = new JSONObject().put(NetworkController.R, value.getRed())
            .put(NetworkController.G, value.getGreen()).put(NetworkController.B, value.getBlue())
            .put(NetworkController.A, value.getAlpha());
}

From source file:omeis.providers.re.HSBStrategy.java

/**
 * Retrieves the color for each active channels.
 * //from   ww w.  j  a  va2 s .  c  o m
 * @return the active channel color data.
 */
private List<int[]> getColors() {
    ChannelBinding[] channelBindings = renderer.getChannelBindings();
    List<int[]> colors = new ArrayList<int[]>();

    for (int w = 0; w < channelBindings.length; w++) {
        ChannelBinding cb = channelBindings[w];
        if (cb.getActive()) {
            int[] theNewColor = new int[] { cb.getRed(), cb.getGreen(), cb.getBlue(), cb.getAlpha() };
            colors.add(theNewColor);
        }
    }
    Map<byte[], Integer> overlays = renderer.getOverlays();
    if (overlays != null) {
        for (byte[] overlay : overlays.keySet()) {
            Integer packedColor = overlays.get(overlay);
            Color color = new Color(packedColor);
            colors.add(new int[] { color.getRed(), color.getBlue(), color.getGreen(), color.getAlpha() });
        }
    }
    return colors;
}

From source file:org.polymap.core.mapeditor.tooling.edit.VectorLayerStyler.java

/**
 * Calculates styles for {@link #hover} and {@link #select} intent based on the
 * {@link #standard} style. Override in order to change the standard behaviour.
 *//*from w  ww  .j  a  va 2 s. c o  m*/
protected void calculateHoverSelectStyle() {
    hover = Maps.newHashMap(standard);
    RGB rgb = (RGB) standard.get("strokeColor");

    // just brighter
    //        Color c = new Color( rgb.red, rgb.green, rgb.blue ).brighter().brighter().brighter();

    // gray
    //        int gray = (int)((0.299 * rgb.red) + (0.587 * rgb.green) + (0.114 * rgb.blue));
    //        Color c = new Color( gray, gray, gray ).brighter();

    HSLColor hsl = new HSLColor(new Color(rgb.red, rgb.green, rgb.blue));
    Color c = hsl.adjustShade(40).adjustSaturation(100).toRGB();

    // hover
    hover.put("strokeColor", new RGB(c.getRed(), c.getGreen(), c.getBlue()));
    hover.put("strokeDashstyle", "solid");
    Number strokeWidth = (Number) hover.get("strokeWidth");
    hover.put("strokeWidth", strokeWidth);
    hover.put("fillOpacity", 0.25);

    //        hsl = new HSLColor( new Color( rgb.red, rgb.green, rgb.blue ) );
    //        c = hsl.adjustHue( 180 ).adjustShade( 10 ).toRGB();

    // select
    select = Maps.newHashMap(standard);
    select.put("strokeColor", new RGB(c.getRed(), c.getGreen(), c.getBlue()));
    select.put("strokeDashstyle", "solid");
    strokeWidth = (Number) select.get("strokeWidth");
    select.put("strokeWidth", strokeWidth);
    select.put("fillOpacity", 0.20);
}

From source file:com.alkacon.opencms.survey.CmsFormReportingBean.java

/**
 * Returns a lazy initialized map that provides the color of the label for each background color used as a key in the Map.<p> 
 * /*from w  w  w .ja v a  2  s  .c  o  m*/
 * Dark background color returns white.<p>
 * Light background color returns black.<p>
 * 
 * @return a lazy initialized map
 */
public Map getTextColor() {

    if (m_color == null) {
        m_color = LazyMap.decorate(new HashMap(), new Transformer() {

            /**
             * @see org.apache.commons.collections.Transformer#transform(java.lang.Object)
             */
            public Object transform(Object input) {

                try {
                    // get the color from the given value
                    String value = String.valueOf(input);
                    Color color = Color.decode(value);

                    // look if its a dark color or a light
                    int dezColor = color.getBlue() + color.getGreen() + color.getRed();
                    if (dezColor < SEP_DARK_LIGHT) {
                        return "#FFF";
                    }

                } catch (Exception e) {
                    // NOOP
                }
                return "#000";
            }
        });
    }
    return m_color;
}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static float[][][] getImageDifference(BufferedImage image1, BufferedImage image2) {
    Color tmpColor1, tmpColor2;
    int width = image1.getWidth();
    int height = image1.getHeight();
    float[][][] outputMap = new float[3][width][height];
    for (int ii = 0; ii < width; ii++) {
        for (int jj = 0; jj < height; jj++) {
            tmpColor1 = new Color(image1.getRGB(ii, jj));
            tmpColor2 = new Color(image2.getRGB(ii, jj));
            outputMap[0][ii][jj] = (float) (tmpColor1.getRed() - tmpColor2.getRed())
                    * (tmpColor1.getRed() - tmpColor2.getRed());
            outputMap[1][ii][jj] = (float) (tmpColor1.getGreen() - tmpColor2.getGreen())
                    * (tmpColor1.getGreen() - tmpColor2.getGreen());
            outputMap[2][ii][jj] = (float) (tmpColor1.getBlue() - tmpColor2.getBlue())
                    * (tmpColor1.getBlue() - tmpColor2.getBlue());
        }/*from  w  w w  .  j  a v a2 s.  c  om*/
    }
    return outputMap;
}

From source file:app.springapp.ImageConverter.java

public int getBlockValue(int x1, int y1, int n, boolean flag) {

    BufferedImage im;//w  w  w . j a  va 2s . c o m
    if (flag) {
        im = new_image;

    } else {
        im = org_image;
    }

    int x2 = getX(x1, y1, n);
    int y2 = getY(x1, y1, n);

    int sum = 0;
    int i = x1, j = y1;

    while (i != x2 || j != y2) {

        int rgb = im.getRGB(i, j);
        Color c = new Color(rgb);
        sum += c.getRed() % 2;
        sum += c.getBlue() % 2;
        sum += c.getGreen() % 2;

        if (i + 1 < org_image.getWidth()) {
            i = i + 1;

        } else {
            j++;
            i = 0;
        }

    }

    int rgb = im.getRGB(x2, y2);
    Color c = new Color(rgb);
    sum += c.getRed() % 2;
    sum += c.getBlue() % 2;
    sum += c.getGreen() % 2;

    return sum;

}

From source file:gr.iti.mklab.reveal.forensics.maps.dwnoisevar.DWNoiseVarExtractor.java

public void getNoiseMap() throws IOException {

    BufferedImage img = inputImage;

    int imWidth, imHeight;
    if (img.getWidth() % 2 == 0) {
        imWidth = img.getWidth();/*w  ww .ja  v  a 2 s. co  m*/
    } else {
        imWidth = (img.getWidth() - 1);
    }
    if (img.getHeight() % 2 == 0) {
        imHeight = img.getHeight();
    } else {
        imHeight = (img.getHeight() - 1);
    }

    int columnFilterScale = (int) (Math.log(imHeight) / Math.log(2)) - 1;
    int rowFilterScale = (int) (Math.log(imWidth) / Math.log(2)) - 1;

    double[][] imgYAsArray = new double[imWidth][imHeight];
    double[][] filteredImgYAsArray = new double[imWidth][imHeight / 2];
    double[][] doubleFilteredImgYAsArray = new double[imWidth / 2][imHeight / 2];
    double[] imgColumn, imgRow;
    Color tmpcolor;
    double R, G, B;

    for (int ii = 0; ii < imWidth; ii++) {
        for (int jj = 0; jj < imHeight; jj++) {
            tmpcolor = new Color(img.getRGB(ii, jj));
            R = tmpcolor.getRed();
            G = tmpcolor.getGreen();
            B = tmpcolor.getBlue();
            imgYAsArray[ii][jj] = 0.2989 * R + 0.5870 * G + 0.1140 * B;
        }
    }

    double[] waveletColumn;
    RealMatrix rm = new Array2DRowRealMatrix(imgYAsArray);
    for (int ii = 0; ii < imWidth; ii++) {
        try {
            imgColumn = new double[imHeight];
            imgColumn = rm.getRow(ii);
            //Long startTime1 = System.currentTimeMillis();  
            waveletColumn = DWT.transform(imgColumn, Wavelet.Daubechies, 8, columnFilterScale,
                    DWT.Direction.forward);
            System.arraycopy(waveletColumn, imHeight / 2, filteredImgYAsArray[ii], 0, imHeight / 2);
        } catch (Exception ex) {
            Logger.getLogger(DWNoiseVarExtractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    double[] waveletRow;
    RealMatrix rm2 = new Array2DRowRealMatrix(filteredImgYAsArray);
    for (int jj = 0; jj < imHeight / 2; jj++) {
        try {
            imgRow = new double[imWidth];
            imgRow = rm2.getColumn(jj);
            waveletRow = DWT.transform(imgRow, Wavelet.Daubechies, 8, rowFilterScale, DWT.Direction.forward);
            for (int ii = 0; ii < imWidth / 2; ii++) {
                doubleFilteredImgYAsArray[ii][jj] = waveletRow[ii + imWidth / 2];
            }
        } catch (Exception ex) {
            Logger.getLogger(DWNoiseVarExtractor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    int blockSize = 8;
    double[][] blockNoiseVar = Util.blockNoiseVar(doubleFilteredImgYAsArray, blockSize);

    int medianFilterSize = 7;
    if (medianFilterSize > blockNoiseVar.length) {
        medianFilterSize = blockNoiseVar.length - 1;
    }
    if (medianFilterSize > blockNoiseVar[0].length) {
        medianFilterSize = blockNoiseVar[0].length - 1;
    }
    if (medianFilterSize < 5) {
        minNoiseValue = 0;
        maxNoiseValue = 0;
        noiseMap = new float[1][1];
        noiseMap[0][0] = 0;
        double[][] artificialOutput = new double[1][1];
        artificialOutput[0][0] = 0;
        BufferedImage outputImage = Util.visualizeWithJet(artificialOutput);
        displaySurface = outputImage;
        return;
    }

    float[][] outBlockMap = Util.medianFilterSingleChannelImage(blockNoiseVar, medianFilterSize);

    minNoiseValue = Util.minDouble2DArray(outBlockMap);
    maxNoiseValue = Util.maxDouble2DArray(outBlockMap);
    noiseMap = outBlockMap;
    double[][] normalizedMap = Util.normalizeIm(outBlockMap);
    BufferedImage outputImage = Util.visualizeWithJet(normalizedMap);
    // output
    displaySurface = outputImage;
}

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();
        }/*w ww  . j  a  v a2s  .  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);
}