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:org.apache.fop.render.pcl.PCLGenerator.java

/**
 * Generates a user-defined pattern for a dithering pattern matching the grayscale value
 * of the color given.//from   w  ww. ja  v  a2s.c o  m
 * @param col the color to create the pattern for
 * @param patternID the pattern ID to use
 * @param ditherMatrixSize the size of the Bayer dither matrix to use (4 or 8 supported)
 * @throws IOException In case of an I/O error
 */
public void defineGrayscalePattern(Color col, int patternID, int ditherMatrixSize) throws IOException {
    ByteArrayOutputStream baout = new ByteArrayOutputStream();
    DataOutputStream data = new DataOutputStream(baout);
    data.writeByte(0); //Format
    data.writeByte(0); //Continuation
    data.writeByte(1); //Pixel Encoding
    data.writeByte(0); //Reserved
    data.writeShort(8); //Width in Pixels
    data.writeShort(8); //Height in Pixels
    //data.writeShort(600); //X Resolution (didn't manage to get that to work)
    //data.writeShort(600); //Y Resolution
    int gray255 = convertToGray(col.getRed(), col.getGreen(), col.getBlue());

    byte[] pattern;
    if (ditherMatrixSize == 8) {
        pattern = DitherUtil.getBayerDither(DitherUtil.DITHER_MATRIX_8X8, gray255, false);
    } else {
        //Since a 4x4 pattern did not work, the 4x4 pattern is applied 4 times to an
        //8x8 pattern. Maybe this could be changed to use an 8x8 bayer dither pattern
        //instead of the 4x4 one.
        pattern = DitherUtil.getBayerDither(DitherUtil.DITHER_MATRIX_4X4, gray255, true);
    }
    data.write(pattern);
    if ((baout.size() % 2) > 0) {
        baout.write(0);
    }
    writeCommand("*c" + patternID + "G");
    writeCommand("*c" + baout.size() + "W");
    baout.writeTo(this.out);
    writeCommand("*c4Q"); //temporary pattern
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Converts the passed color./*  w w w  .  j a  v  a2  s.c  o m*/
 * 
 * @param c The color to handle.
 * @return See above.
 */
public static int convertColor(Color c) {
    int alpha = c.getAlpha();
    if (alpha == 0)
        alpha = 255;
    return ((alpha & 0xFF) << 24) | ((c.getRed() & 0xFF) << 16) | ((c.getGreen() & 0xFF) << 8)
            | ((c.getBlue() & 0xFF) << 0);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Returns <code>true</code> if the passed colors are the same, 
 * <code>false</code> otherwise.
 * //  w ww .j a  v a 2 s. co m
 * @param c1 One of the colors to check.
 * @param c2 One of the colors to check.
 * @param alpha Pass <code>true</code> to take into account the 
 *             alpha component, <code>false</code> otherwise.
 * @return See above.
 */
public static boolean isSameColors(Color c1, Color c2, boolean alpha) {
    if (c1 == null || c2 == null)
        return false;
    if (c1.getRed() != c2.getRed())
        return false;
    if (c1.getGreen() != c2.getGreen())
        return false;
    if (c1.getBlue() != c2.getBlue())
        return false;
    if (alpha) {
        if (c1.getAlpha() != c2.getAlpha())
            return false;
    }
    return true;
}

From source file:monitor.processing.OLD.SoccerField.java

public void drawTree(BaseNode n, RealVector v) {

    Color c = Color.WHITE;

    if (n instanceof TransformNode) {
        v = ((TransformNode) n).getTrasformMatrix().operate(v);

        c = Color.ORANGE;/*from   ww w  .  j  av a2 s  .  c om*/
    } else if (n instanceof StaticMesh) {
        StaticMesh sm = (StaticMesh) n;

        if (sm.isTransparent()) {
            c = Color.BLUE;
        } else if (sm.isVisible()) {
            //                System.out.println(n.getInfo());
            //                System.out.println(v);
            c = Color.RED;
            if (sm.getModel().contains("naohead") || sm.getModel().contains("naobody")) {
                c = Color.PINK;
            }
        } else {
            c = Color.CYAN;
        }

    } else if (n instanceof StaticMeshNode) {
        StaticMeshNode smn = (StaticMeshNode) n;

        if (smn.isTransparent()) {
            c = Color.GREEN;
            //                cameraSceneX = (float)v.getEntry(0);
            //                cameraSceneY = (float)v.getEntry(1);
            //                cameraSceneZ = (float)v.getEntry(2);
        } else if (smn.isVisible()) {
            c = Color.YELLOW;
        } else {
            c = Color.MAGENTA;
        }

    }

    pushMatrix();
    fill(100);

    //        c = Color.getHSBColor(n.getAddress()*0.05f, 1, 1);
    stroke(c.getRed(), c.getGreen(), c.getBlue());
    translate((float) (scale * v.getEntry(0)), (float) (-scale * v.getEntry(1)),
            (float) (scale * v.getEntry(2)));
    box(5);
    popMatrix();

    for (int a = n.getChildren().size() - 1; a >= 0; a--) {
        drawTree(((ArrayList<BaseNode>) n.getChildren()).get(a), v);
    }

}

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

/**
 * overlay heatmap on image//w  ww  .j ava2s.co 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: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  .java2s  .  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:net.sf.jasperreports.engine.export.JRPdfExporter.java

/**
 *
 */// w  ww  . j a  v  a2  s .co  m
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//from   w  w  w .ja v  a  2 s. com
 *
 * @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());
        }//www  .  ja  v  a 2 s  . c  om
        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: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 w w  .j  ava 2  s.co  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;

}