Example usage for java.awt Color getRGB

List of usage examples for java.awt Color getRGB

Introduction

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

Prototype

public int getRGB() 

Source Link

Document

Returns the RGB value representing the color in the default sRGB ColorModel .

Usage

From source file:SWTGraphics2D.java

/**
 * Internal method to convert a AWT color object into
 * a SWT color resource. If a corresponding SWT color
 * instance is already in the pool, it will be used
 * instead of creating a new one. This is used in
 * {@link #setColor()} for instance./*from w ww  .  j a v a  2s .c  o m*/
 *
 * @param awtColor The AWT color to convert.
 * @return A SWT color instance.
 */
private org.eclipse.swt.graphics.Color getSwtColorFromPool(Color awtColor) {
    org.eclipse.swt.graphics.Color swtColor = (org.eclipse.swt.graphics.Color)
    // we can't use the following valueOf() method, because it
    // won't compile with JDK1.4
    // this.colorsPool.get(Integer.valueOf(awtColor.getRGB()));
    this.colorsPool.get(new Integer(awtColor.getRGB()));
    if (swtColor == null) {
        swtColor = SWTUtils.toSwtColor(this.gc.getDevice(), awtColor);
        addToResourcePool(swtColor);
        // see comment above
        //this.colorsPool.put(Integer.valueOf(awtColor.getRGB()), swtColor);
        this.colorsPool.put(new Integer(awtColor.getRGB()), swtColor);
    }
    return swtColor;
}

From source file:edu.umn.cs.spatialHadoop.core.OGCESRIShape.java

@Override
public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) {
    OGCGeometry geom = this.geom;
    Color shape_color = g.getColor();
    if (geom instanceof OGCGeometryCollection) {
        OGCGeometryCollection geom_coll = (OGCGeometryCollection) geom;
        for (int i = 0; i < geom_coll.numGeometries(); i++) {
            OGCGeometry sub_geom = geom_coll.geometryN(i);
            // Recursive call to draw each geometry
            new OGCESRIShape(sub_geom).draw(g, fileMBR, imageWidth, imageHeight, scale);
        }/*from  w ww  .  j a va  2s .  c o  m*/
    } else if (geom.getEsriGeometry() instanceof MultiPath) {
        MultiPath path = (MultiPath) geom.getEsriGeometry();
        double sub_geom_alpha = path.calculateLength2D() * scale;
        int color_alpha = sub_geom_alpha > 1.0 ? 255 : (int) Math.round(sub_geom_alpha * 255);

        if (color_alpha == 0)
            return;

        int[] xpoints = new int[path.getPointCount()];
        int[] ypoints = new int[path.getPointCount()];

        for (int i = 0; i < path.getPointCount(); i++) {
            double px = path.getPoint(i).getX();
            double py = path.getPoint(i).getY();

            // Transform a point in the polygon to image coordinates
            xpoints[i] = (int) Math.round((px - fileMBR.x1) * imageWidth / fileMBR.getWidth());
            ypoints[i] = (int) Math.round((py - fileMBR.y1) * imageHeight / fileMBR.getHeight());
        }

        // Draw the polygon
        g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true));
        if (path instanceof Polygon)
            g.drawPolygon(xpoints, ypoints, path.getPointCount());
        else if (path instanceof Polyline)
            g.drawPolyline(xpoints, ypoints, path.getPointCount());
    }
}

From source file:tufts.vue.RichTextBox.java

public void overrideTextColor(Color c) {
    //System.out.println("OVERRIDE TEXT COLOR : " + c.toString());
    SimpleAttributeSet set = new SimpleAttributeSet();
    String colorString = "#" + Integer.toHexString(c.getRGB()).substring(2);
    com.lightdev.app.shtm.Util.styleSheet().addCSSAttribute(set, CSS.Attribute.COLOR, colorString);

    set.addAttribute(HTML.Attribute.COLOR, colorString);
    this.applyAttributesGlobally(set, true, false);
}

From source file:org.pentaho.chart.plugin.openflashchart.OpenFlashChartFactoryEngine.java

/**
* @deprecated/* w ww.j a va2s.  co  m*/
*/
private Chart createBasicChart(ChartDocument chartDocument) {
    String chartTitle = null;
    String cssFontStyleString = null;

    ChartElement rootElement = chartDocument.getRootElement();
    ChartElement plot = chartDocument.getPlotElement();

    final ChartElement[] children = rootElement.findChildrenByName(ChartElement.TAG_NAME_TITLE); //$NON-NLS-1$
    if (children != null && children.length > 0) {
        chartTitle = children[0].getText();
        cssFontStyleString = createCssFontStyleString(children[0]);
    }
    Chart chart = null;
    if ((chartTitle != null) && chartTitle.trim().length() > 0) {
        if (cssFontStyleString != null) {
            chart = new Chart(chartTitle, cssFontStyleString);
        } else {
            chart = new Chart(chartTitle);
        }
    } else {
        chart = new Chart();
    }

    Color chartBackgroundPaint = ColorFactory.getInstance().getColor(rootElement,
            BorderStyleKeys.BACKGROUND_COLOR);
    if (chartBackgroundPaint == null) {
        chartBackgroundPaint = Color.white;
    }
    chart.setBackgroundColour("#" + Integer.toHexString(0x00FFFFFF & chartBackgroundPaint.getRGB()));

    Color plotBackgroundColor = ColorFactory.getInstance().getColor(plot, BorderStyleKeys.BACKGROUND_COLOR);
    if (plotBackgroundColor != null) {
        chart.setInnerBackgroundColour("#" + Integer.toHexString(0x00FFFFFF & plotBackgroundColor.getRGB()));
    }
    return chart;
}

From source file:net.sf.jasperreports.engine.export.JRHtmlExporter.java

protected Color appendBackcolorStyle(JRExporterGridCell gridCell, StringBuffer styleBuffer) {
    Color cellBackcolor = gridCell.getCellBackcolor();
    if (cellBackcolor != null && (backcolor == null || cellBackcolor.getRGB() != backcolor.getRGB())) {
        styleBuffer.append("background-color: ");
        styleBuffer.append(JRColorUtil.getCssColor(cellBackcolor));
        styleBuffer.append("; ");

        return cellBackcolor;
    }//from w w  w  .  ja va  2s.c  o  m

    return null;
}

From source file:uk.bl.dpt.qa.gui.DissimilarGUIThread.java

/**
 * overlay heatmap on image/*from  w w w  . j a  va  2  s.  com*/
 */
private void internalOverlayHeatmap() {

    gRightImageSave = imageRight.getImage();

    if (!gHeatmapGenerated) {

        internalBeforeGUIThread();

        //threaded load so GUI doesn't hang
        Task<Integer> task = new Task<Integer>() {

            @Override
            protected Integer call() throws Exception {
                BufferedImage image = SwingFXUtils.fromFXImage(imageRight.getImage(), null);

                if (gHeatmap == null) {
                    //re-generate heatmap (must be on a re-load)
                    try {
                        gHeatmap = Imaging.getBufferedImage(gResults.get(gCurrentRecord).getHeatmapTemp());
                    } catch (IOException | ImageReadException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                for (int y = 0; y < image.getHeight(); y++) {
                    for (int x = 0; x < image.getWidth(); x++) {
                        int rgb = image.getRGB(x, y);

                        Color heatmapColor = new Color(gHeatmap.getRGB((x / DissimilarV2.SSIMWINDOWSIZE),
                                (y / DissimilarV2.SSIMWINDOWSIZE)));
                        int heatmapPixel = heatmapColor.getGreen();//&maxPixelValue;
                        if (heatmapColor.getGreen() != heatmapColor.getBlue()
                                && heatmapColor.getBlue() != heatmapColor.getRed()) {
                            gLogger.error("Heatmap error (should not happen)");
                        }

                        double factor = 1 - (((double) heatmapPixel / 255));

                        Color col = new Color(rgb);
                        int red = (int) (factor * col.getRed());
                        int green = (int) (factor * col.getGreen());
                        int blue = (int) (factor * col.getBlue());

                        if (red < 0)
                            red = 0;
                        if (green < 0)
                            green = 0;
                        if (blue < 0)
                            blue = 0;
                        col = new Color(red, green, blue);

                        image.setRGB(x, y, col.getRGB());
                    }
                }

                gHeatmapImage = SwingFXUtils.toFXImage(image, null);
                gHeatmapGenerated = true;

                Platform.runLater(new Runnable() {
                    //@Override
                    public void run() {
                        imageRight.setImage(gHeatmapImage);
                    }
                });

                internalAfterGUIThread();

                return 1;
            }

        };

        progressIndicator.progressProperty().bind(task.progressProperty());
        Thread loader = new Thread(task);
        loader.setDaemon(true);
        loader.start();

    } else {
        imageRight.setImage(gHeatmapImage);
    }

}

From source file:com.jcraft.weirdx.XPixmap.java

void setFgBg(Color f, Color b) {
    foreGround = f.getRGB() | 0xff000000;
    backGround = b.getRGB() | 0xff000000;
    if ((foreGround & 0x00ffffff) != 0 && (backGround & 0x00ffffff) == 0) {
        through = true;//from  w  ww.  j  a  v  a  2  s.  com
    } else {
        through = false;
    }
}

From source file:Trabalho.HistogramaHSB.java

public ChartPanel criaHistograma() throws IOException {

    //pega a imagem
    BufferedImage img = pegaImagem();
    //w pega a largura da imagem - h pega a altura da imagem
    int w = img.getWidth();
    int h = img.getHeight();
    //d calcula o tamanho da imagem
    int d = (w * h);
    //red, green e blue iro receber os tons de cor antigo da imagem - u vai receber o RGB da cor 
    int red, green, blue, u;
    //retorna rgb no mtodo
    float[] hsb;/*from w  ww .  j  a va2  s .c  o m*/
    int[] vetH = new int[256];
    int[] vetS = new int[256];
    int[] vetB = new int[256];
    float hue, sat, bri;
    //cAux e oldColor pegam os tons originais da imagem - newColor pega os tons aps o clculo
    Color oldColor;
    Color newColor;

    //for responsvel por substituir os tons antigos pelos novos; percorrem a imagem por largura e altura
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
            u = img.getRGB(i, j); //u vai receber o RGB da posio i, j
            oldColor = new Color(u); //oldColor  instanciado e recebe o valor de u
            //cada cor recebe o valor do tom original
            red = oldColor.getRed();
            green = oldColor.getGreen();
            blue = oldColor.getBlue();
            hsb = Color.RGBtoHSB(red, green, blue, null);
            hue = hsb[0];
            sat = hsb[1];
            bri = hsb[2];
            //                System.out.println("RGB [" + red + "," + green + "," + blue + "] converted to HSB [" + hue + "," + sat + "," + bri + "]");

            //                hue = hue * 360;
            //                int convH = Integer.valueOf(new Float(hue).intValue());
            //                vetH[convH]++;
            //
            //                sat = sat * 100;
            //                int convS = Integer.valueOf(new Float(sat).intValue());
            //                vetS[convS]++;
            //
            //                bri = bri * 100;
            //                int convB = Integer.valueOf(new Float(bri).intValue());
            //                vetB[convB]++;

            newColor = new Color(hue, sat, bri);
            //seta o RGB da imagem nas posies i, j pegando os valores da newColor
            img.setRGB(i, j, newColor.getRGB());
        }
    }

    File ouptut = new File("D:\\ProjetosNetBeans\\PDI\\src\\imagens\\5.jpeg");
    ImageIO.write(img, "png", ouptut);

    dataset = new HistogramDataset();
    //pega o RGB

    r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, 360);
    r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", r, 101);
    r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", r, 101);

    JFreeChart chart = ChartFactory.createHistogram("Histograma", "Pixels", "Y", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //Plota as cores
    XYPlot plot = (XYPlot) chart.getPlot();
    renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    //vermelho, verde, azul
    Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true),
            new Color(0x800000ff, true) };
    //desenhando o grfico
    plot.setDrawingSupplier(
            new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    return panel;
}

From source file:com.ricemap.spateDB.operations.Plot.java

public static <S extends Shape> void plotMapReduce(Path inFile, Path outFile, Shape shape, int width,
        int height, Color color, boolean showBorders, boolean showBlockCount, boolean showRecordCount,
        boolean background) throws IOException {
    JobConf job = new JobConf(Plot.class);
    job.setJobName("Plot");

    job.setMapperClass(PlotMap.class);
    ClusterStatus clusterStatus = new JobClient(job).getClusterStatus();
    job.setNumMapTasks(clusterStatus.getMaxMapTasks() * 5);
    job.setReducerClass(PlotReduce.class);
    job.setNumReduceTasks(Math.max(1, clusterStatus.getMaxReduceTasks()));
    job.setMapOutputKeyClass(Prism.class);
    SpatialSite.setShapeClass(job, shape.getClass());
    job.setMapOutputValueClass(shape.getClass());

    FileSystem inFs = inFile.getFileSystem(job);
    Prism fileMbr = FileMBR.fileMBRMapReduce(inFs, inFile, shape, false);
    FileStatus inFileStatus = inFs.getFileStatus(inFile);

    CellInfo[] cellInfos;/*w ww .  j  a v a  2  s  .c  o m*/
    GlobalIndex<Partition> gindex = SpatialSite.getGlobalIndex(inFs, inFile);
    if (gindex == null) {
        // A heap file. The map function should partition the file
        GridInfo gridInfo = new GridInfo(fileMbr.t1, fileMbr.x1, fileMbr.y1, fileMbr.t2, fileMbr.x2,
                fileMbr.y2);
        gridInfo.calculateCellDimensions(inFileStatus.getLen(), inFileStatus.getBlockSize());
        cellInfos = gridInfo.getAllCells();
        // Doesn't make sense to show any partition information in a heap file
        showBorders = showBlockCount = showRecordCount = false;
    } else {
        cellInfos = SpatialSite.cellsOf(inFs, inFile);
    }

    // Set cell information in the job configuration to be used by the mapper
    SpatialSite.setCells(job, cellInfos);

    // Adjust width and height to maintain aspect ratio
    if ((fileMbr.x2 - fileMbr.x1) / (fileMbr.y2 - fileMbr.y1) > (double) width / height) {
        // Fix width and change height
        height = (int) ((fileMbr.y2 - fileMbr.y1) * width / (fileMbr.x2 - fileMbr.x1));
    } else {
        width = (int) ((fileMbr.x2 - fileMbr.x1) * height / (fileMbr.y2 - fileMbr.y1));
    }
    LOG.info("Creating an image of size " + width + "x" + height);
    ImageOutputFormat.setFileMBR(job, fileMbr);
    ImageOutputFormat.setImageWidth(job, width);
    ImageOutputFormat.setImageHeight(job, height);
    job.setBoolean(ShowBorders, showBorders);
    job.setBoolean(ShowBlockCount, showBlockCount);
    job.setBoolean(ShowRecordCount, showRecordCount);
    job.setInt(StrokeColor, color.getRGB());

    // Set input and output
    job.setInputFormat(ShapeInputFormat.class);
    ShapeInputFormat.addInputPath(job, inFile);
    // Set output committer which will stitch images together after all reducers
    // finish
    job.setOutputCommitter(PlotOutputCommitter.class);

    job.setOutputFormat(ImageOutputFormat.class);
    TextOutputFormat.setOutputPath(job, outFile);

    if (background) {
        JobClient jc = new JobClient(job);
        lastSubmittedJob = jc.submitJob(job);
    } else {
        lastSubmittedJob = JobClient.runJob(job);
    }
}

From source file:net.sf.jasperreports.engine.export.JExcelApiExporter.java

protected Colour getWorkbookColour(Color awtColor, boolean isBackcolor) {
    if (isBackcolor && awtColor.getRGB() == Color.black.getRGB()) {
        return Colour.PALETTE_BLACK;
    }/*from   ww w . j  a  va 2  s .c o  m*/
    return getWorkbookColour(awtColor);
}