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:smlm.util.SRutil.java

public static Color getGradientColor(Color ini, Color fin, int numberOfSteps, int step) {
    if (numberOfSteps == 0)
        return ini;
    if (step % numberOfSteps == 0)
        return ini;
    if (step % numberOfSteps == numberOfSteps - 1)
        return fin;
    else {//from   ww  w .j  a  v  a  2s. c  o m
        float[] hsbini = Color.RGBtoHSB(ini.getRed(), ini.getGreen(), ini.getBlue(), null);
        float[] hsbfin = Color.RGBtoHSB(fin.getRed(), fin.getGreen(), fin.getBlue(), null);
        float h = ((numberOfSteps - step % numberOfSteps) * hsbini[0] + (step % numberOfSteps) * hsbfin[0])
                / numberOfSteps;
        float s = ((numberOfSteps - step % numberOfSteps) * hsbini[1] + (step % numberOfSteps) * hsbfin[1])
                / numberOfSteps;
        float b = ((numberOfSteps - step % numberOfSteps) * hsbini[2] + (step % numberOfSteps) * hsbfin[2])
                / numberOfSteps;
        return Color.getHSBColor(h, s, b);
    }
}

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

/**
 * overlay heatmap on image//  w ww  .j  av  a2 s. c o  m
 */
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:net.sf.jasperreports.engine.export.JRPdfExporter.java

/**
 *
 *///from   ww w .java 2s .com
private static void preparePen(PdfContentByte pdfContentByte, JRPen pen, int lineCap) {
    float lineWidth = pen.getLineWidth();

    if (lineWidth <= 0) {
        return;
    }

    pdfContentByte.setLineWidth(lineWidth);
    pdfContentByte.setLineCap(lineCap);

    Color color = pen.getLineColor();
    pdfContentByte.setRGBColorStroke(color.getRed(), color.getGreen(), color.getBlue());

    switch (pen.getLineStyleValue()) {
    case DOUBLE: {
        pdfContentByte.setLineWidth(lineWidth / 3);
        pdfContentByte.setLineDash(0f);
        break;
    }
    case DOTTED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(lineWidth, lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(0, 2 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case DASHED: {
        switch (lineCap) {
        case PdfContentByte.LINE_CAP_BUTT: {
            pdfContentByte.setLineDash(5 * lineWidth, 3 * lineWidth, 0f);
            break;
        }
        case PdfContentByte.LINE_CAP_PROJECTING_SQUARE: {
            pdfContentByte.setLineDash(4 * lineWidth, 4 * lineWidth, 0f);
            break;
        }
        }
        break;
    }
    case SOLID:
    default: {
        pdfContentByte.setLineDash(0f);
        break;
    }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * Method contributed by Alexej Suchov/*w w w.  jav a2  s . c  o m*/
 *
 * @see Graphics2D#setPaint(Paint)
 */
@Override
public void setPaint(final Paint paint) {
    if (paint == null) {
        return;
    }
    this.paint = paint;
    realPaint = paint;

    if ((composite instanceof AlphaComposite) && (paint instanceof Color)) {

        final AlphaComposite co = (AlphaComposite) composite;

        if (co.getRule() == 3) {
            final Color c = (Color) paint;
            this.paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (c.getAlpha() * alpha));
            realPaint = paint;
        }
    }

}

From source file:com.mgmtp.perfload.loadprofiles.ui.AppFrame.java

private void updateGraph() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    Collection<Stairs> loadProfileEnities = transform(
            filter(loadProfilesController.getTreeItems(), new IsStairsPredicate()),
            new LoadProfileEntityToStairsFunction());
    GraphPointsCalculator calc = new GraphPointsCalculator();
    Map<String, Set<Point>> pointsMap = calc.calculatePoints(loadProfileEnities);

    for (Entry<String, Set<Point>> entry : pointsMap.entrySet()) {
        final XYSeries series = new XYSeries(entry.getKey());
        for (Point point : entry.getValue()) {
            series.add(point.getX(), point.getY());
        }/*w  w  w.j a v a2s .c  o m*/
        dataset.addSeries(series);
    }

    String name = txtName.getText();
    chart = ChartFactory.createXYLineChart(name, "t (min)", "Executions (1/h)", dataset,
            PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = chart.getXYPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    plot.setRenderer(renderer);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    double maxX = 0;

    for (OneTime oneTime : getOneTimes()) {
        String key = oneTime.operation.getName();
        XYSeries series;
        try {
            // We need the series in order to retrieve paint and stroke
            series = dataset.getSeries(key);
        } catch (UnknownKeyException ex) {
            series = new XYSeries(key);
            dataset.addSeries(series);
        }

        int index = dataset.getSeriesIndex(key);
        BasicStroke stroke = (BasicStroke) renderer.lookupSeriesStroke(index);
        stroke = new BasicStroke(stroke.getLineWidth() + 1f, stroke.getEndCap(), stroke.getLineJoin(),
                stroke.getMiterLimit(), stroke.getDashArray(), stroke.getDashPhase());
        Color paint = (Color) renderer.lookupSeriesPaint(index);
        paint = new Color(paint.getRed(), paint.getGreen(), paint.getBlue(), 160);

        double height = rangeAxis.getUpperBound() * .05; // five percent of range
        double width = domainAxis.getUpperBound() * .01; // one percent of range
        double center = oneTime.t0;
        double left = center - width / 2;
        double right = center + width / 2;

        // We only add annotations for one times, but nothing to the series
        plot.addAnnotation(new XYPolygonAnnotation(new double[] { left, 0d, center, height, right, 0d }, stroke,
                paint, paint));

        maxX = max(maxX, right);
    }

    for (Marker marker : getMarkers()) {
        IntervalMarker im = new IntervalMarker(marker.left, marker.right);
        im.setLabel(marker.name);
        im.setLabelFont(new Font(getFont().getName(), getFont().getStyle(), getFont().getSize() + 1));
        im.setLabelAnchor(RectangleAnchor.TOP);
        im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d));
        im.setLabelPaint(Color.BLACK);
        im.setAlpha(.3f);
        im.setPaint(Color.WHITE);
        im.setOutlinePaint(Color.BLACK);
        im.setOutlineStroke(new BasicStroke(1.0f));
        plot.addDomainMarker(im, Layer.BACKGROUND);

        maxX = max(maxX, marker.right);
    }

    if (domainAxis.getUpperBound() < maxX) {
        domainAxis.setUpperBound(maxX * 1.05);
    }
    chartPanel.setChart(chart);
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * Method contributed by Alexej Suchov//  w ww.j a  va  2s  . c  o  m
 *
 * @see Graphics2D#setComposite(Composite)
 */
@Override
public void setComposite(final Composite comp) {

    if (comp instanceof AlphaComposite) {

        final AlphaComposite composite = (AlphaComposite) comp;

        if (composite.getRule() == 3) {

            alpha = composite.getAlpha();
            this.composite = composite;

            if (realPaint != null && (realPaint instanceof Color)) {

                final Color c = (Color) realPaint;
                paint = new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) (c.getAlpha() * alpha));
            }
            return;
        }
    }

    this.composite = comp;
    alpha = 1.0F;

}

From source file:savant.view.tracks.BAMTrackRenderer.java

private Shape renderRead(Graphics2D g2, GraphPaneAdapter gp, BAMIntervalRecord rec, int level, Range range,
        double readHeight) {

    SAMRecord samRec = rec.getSAMRecord();
    boolean reverseStrand = samRec.getReadNegativeStrandFlag();

    ColourScheme cs = (ColourScheme) instructions.get(DrawingInstruction.COLOUR_SCHEME);
    Color readColor = cs.getColor(reverseStrand ? ColourKey.REVERSE_STRAND : ColourKey.FORWARD_STRAND);

    Color override = rec.getColor();
    if (override != null) {
        readColor = override;// w  ww .  java2  s.c  o  m
    }
    if ((Boolean) instructions.get(DrawingInstruction.MAPPING_QUALITY)) {
        int alpha = getConstrainedAlpha(samRec.getMappingQuality());
        readColor = new Color(readColor.getRed(), readColor.getGreen(), readColor.getBlue(), alpha);
    }

    // cutoffs to determine when not to draw
    double leftMostX = gp.transformXPos(range.getFrom());
    double rightMostX = gp.transformXPos(range.getTo() + 1);

    //y = gp.transformYPos(0) - (level + 1)*unitHeight;
    double x = gp.transformXPos(rec.getInterval().getStart());
    double y = gp.transformYPos(0) - (level + 1) * readHeight - gp.getOffset();
    double w = rec.getInterval().getLength() * gp.getUnitWidth();

    // cut off x and w so no drawing happens off-screen
    double x2;
    if (rightMostX < x + w) {
        x2 = rightMostX;
    } else {
        x2 = x + w;
    }
    if (leftMostX > x) {
        x = leftMostX;
    }
    w = x2 - x;

    Shape pointyBar = getPointyBar(reverseStrand, x, y, w, readHeight);

    // Only fill in the read if we're not going to slam bases on top of it.
    boolean baseQuality = (Boolean) instructions.get(DrawingInstruction.BASE_QUALITY);
    if (lastMode != DrawingMode.SEQUENCE && !baseQuality) {
        g2.setColor(readColor);
        g2.fill(pointyBar);
    }

    // Render individual bases/mismatches as appropriate for the current mode.
    if (lastMode != DrawingMode.STANDARD || baseQuality) {
        renderBases(g2, gp, samRec, level, refSeq, range, readHeight);
    }

    // Draw outline, if there's room
    if (pointyBar.getBounds().getHeight() >= 4.0) {
        g2.setColor(cs.getColor(ColourKey.INTERVAL_LINE));
        g2.draw(pointyBar);
    }
    return pointyBar;

}

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

/**
 * Return color index from header of the .rtf file. If a color is not
 * found is automatically added to the header of the rtf file. The
 * method is called first when the header of the .rtf file is constructed
 * and when a component needs a color for foreground or background
 * @param color Color for which the index is required.
 * @return index of the color from .rtf file header
 *//*from   w w w.ja va2  s .c  o  m*/
private int getColorIndex(Color color) throws IOException {
    int colorNdx = colors.indexOf(color);
    if (colorNdx < 0) {
        colorNdx = colors.size();
        colors.add(color);
        colorWriter.write(
                "\\red" + color.getRed() + "\\green" + color.getGreen() + "\\blue" + color.getBlue() + ";");
    }
    return colorNdx;
}

From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java

/**
 * Set the stroking color, specified as RGB.
 * //ww w .jav a 2  s  .com
 * @param color
 *            The color to set.
 * @throws IOException
 *             If an IO error occurs while writing to the stream.
 */
public void setStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}

From source file:fi.nls.oskari.printout.printing.PDPageContentStream.java

/**
 * Set the non stroking color, specified as RGB.
 * //from  w  ww . j av a2s  .c om
 * @param color
 *            The color to set.
 * @throws IOException
 *             If an IO error occurs while writing to the stream.
 */
public void setNonStrokingColor(Color color) throws IOException {
    ColorSpace colorSpace = color.getColorSpace();
    if (colorSpace.getType() == ColorSpace.TYPE_RGB) {
        setNonStrokingColor(color.getRed(), color.getGreen(), color.getBlue());
    } else if (colorSpace.getType() == ColorSpace.TYPE_GRAY) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0]);
    } else if (colorSpace.getType() == ColorSpace.TYPE_CMYK) {
        color.getColorComponents(colorComponents);
        setNonStrokingColor(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]);
    } else {
        throw new IOException("Error: unknown colorspace:" + colorSpace);
    }
}