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.csa.rstb.dat.toolviews.HaAlphaPlotPanel.java

private void initColorModels() {
    for (int j = 0; j <= 1; j++) {
        final int palSize = 256;
        final byte[] r = new byte[palSize];
        final byte[] g = new byte[palSize];
        final byte[] b = new byte[palSize];
        final byte[] a = new byte[palSize];
        r[0] = (byte) backgroundColor.getRed();
        g[0] = (byte) backgroundColor.getGreen();
        b[0] = (byte) backgroundColor.getBlue();
        a[0] = (byte) backgroundColor.getAlpha();

        final Palette pal = new Palette("Rainbow", new Color[] { Color.black, Color.blue, Color.cyan,
                Color.green, Color.yellow, Color.orange, Color.red });
        for (int i = 1; i < 256; ++i) {
            float value = i / 255f;
            if (j == 0)
                value = (255 - i) / 255f;
            Color c = pal.lookupColor(value);
            r[i] = (byte) c.getRed();
            g[i] = (byte) c.getGreen();
            b[i] = (byte) c.getBlue();
            a[i] = (byte) 255;
        }//from   w w w. j  ava 2 s .  c  o  m

        if (j == 0) {
            toggledColorModel = new IndexColorModel(8, palSize, r, g, b, a);
        } else {
            untoggledColorModel = new IndexColorModel(8, palSize, r, g, b, a);
        }
    }
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private void configureGradientAreaFill(Graphics2D g2, XYPlot plot, PlotRenderingInfo info, Paint itemPaint,
        GradientLineAreaFill gradientLineAreaFill) {
    final Rectangle2D plotArea = info.getPlotArea();
    double plotWidth = plotArea.getWidth();
    double plotHeight = plotArea.getHeight();
    Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency();
    Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency();

    if (itemPaint instanceof Color) {
        Color itemColor = (Color) itemPaint;
        int red = itemColor.getRed();
        int green = itemColor.getGreen();
        int blue = itemColor.getBlue();
        int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0)
                ? Math.round(255 * mainColorTransparency.floatValue())
                : 150;/*from  w ww.  jav a2s .  co m*/
        int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0)
                ? Math.round(255 * bgColorTransparency.floatValue())
                : 128;

        Color mainColor = new Color(red, green, blue, mainColorAlpha);
        Paint bgColor = getBackgroundPaint();
        if (bgColor == null) {
            bgColor = plot.getBackgroundPaint();
        }
        Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor);

        Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor);
        g2.setPaint(areaPaint);
    } else {
        g2.setPaint(itemPaint);
    }
}

From source file:statechum.analysis.learning.Visualiser.java

private static PluggableRenderer labelEdges(Graph graph, PluggableRenderer render,
        final LayoutOptions graphLayoutOptions) {
    final EdgeColour paintChooser = new EdgeColour(graph);
    EdgeStringer stringer = new EdgeStringer() {

        @SuppressWarnings("unchecked")
        @Override//  www  .j  a va2  s  .com
        public String getLabel(ArchetypeEdge e) {
            String result = "";

            if (e.containsUserDatumKey(JUConstants.LABEL)) {
                StringBuffer text = new StringBuffer();
                text.append("<html>");
                boolean first = true;
                //final String blowupAttribute = Math.abs(graphLayoutOptions.scaleText - 1)<Configuration.fpAccuracy?" ":
                //   " style=\"font-size:"+Math.round(graphLayoutOptions.scaleText*100.)+"%\"";
                String color = "black";
                if (e.containsUserDatumKey(JUConstants.DIFF)) {
                    Color rgb = (Color) e.getUserDatum(JUConstants.DIFF);
                    color = "rgb(" + rgb.getRed() + "," + rgb.getGreen() + "," + rgb.getBlue() + ")";
                }
                for (Label lbl : abstractLabels((Set<Label>) e.getUserDatum(JUConstants.LABEL),
                        graphLayoutOptions.componentsToPick)) {
                    if (!first) {// choose separator
                        text.append("<br>");// default layout is vertical
                    } else
                        first = false;

                    if (!(lbl instanceof ErlangLabel)) {
                        text.append("<font color=" + color + ">");
                        text.append(lbl.toString());
                    } else {
                        ErlangLabel l = (ErlangLabel) lbl;
                        text.append("<font color=blue>");
                        text.append(l.callName);
                        text.append("</font>,&nbsp;");
                        text.append("<font color=" + color + ">");
                        text.append(l.input);
                        text.append("</font>");
                        if (l.expectedOutput != null) {
                            text.append(",&nbsp;<font color=black>");
                            text.append(l.expectedOutput);
                            text.append("</font>");
                        }
                    }
                }
                text.append("</html>");
                result = text.toString();
            }

            return result;
        }
    };
    render.setEdgeArrowFunction(
            new DirectionalEdgeArrowFunction((int) Math.round(10. * graphLayoutOptions.scaleLines),
                    (int) Math.round(5. * graphLayoutOptions.scaleLines), 4));
    render.setEdgeStringer(stringer);
    render.setEdgeStrokeFunction(new ConstantEdgeStrokeFunction((float) graphLayoutOptions.scaleLines));
    render.setEdgePaintFunction(new AbstractEdgePaintFunction() {

        @Override
        public Paint getDrawPaint(Edge e) {
            Color result = paintChooser.getPickedColour(e, graphLayoutOptions);
            return result != null ? result : Color.BLACK;
        }
    });
    return render;
}

From source file:com.kurento.kmf.test.client.BrowserClient.java

public boolean colorSimilarTo(Color expectedColor) {
    String[] realColor = driver.findElement(By.id("color")).getAttribute("value").split(",");
    int red = Integer.parseInt(realColor[0]);
    int green = Integer.parseInt(realColor[1]);
    int blue = Integer.parseInt(realColor[2]);

    double distance = Math.sqrt((red - expectedColor.getRed()) * (red - expectedColor.getRed())
            + (green - expectedColor.getGreen()) * (green - expectedColor.getGreen())
            + (blue - expectedColor.getBlue()) * (blue - expectedColor.getBlue()));

    log.info("Color comparision: real {}, expected {}, distance {}", realColor, expectedColor, distance);

    return distance <= getMaxDistance();
}

From source file:userinterface.graph.SeriesSettings.java

public void save(Element series) throws SettingException {
    series.setAttribute("seriesHeading", getSeriesHeading());
    series.setAttribute("lineWidth", "" + getLineWidth());

    Color seriesColor = getSeriesColour();
    series.setAttribute("seriesColourR", "" + seriesColor.getRed());
    series.setAttribute("seriesColourG", "" + seriesColor.getGreen());
    series.setAttribute("seriesColourB", "" + seriesColor.getBlue());

    series.setAttribute("showPoints", showPoints() ? "true" : "false");
    series.setAttribute("showLines", showLines() ? "true" : "false");

    int lineStyle = getLineStyle();

    switch (lineStyle) {
    case (DASHED):
        series.setAttribute("lineStyle", "dashed");
        break;//from   w w w.  j a v  a2  s.co m
    case (DOT_DASHED):
        series.setAttribute("lineStyle", "dotDashed");
        break;
    default:
        series.setAttribute("lineStyle", "normal");
    }

    int seriesShape = getSeriesShape();

    switch (seriesShape) {
    case (CIRCLE):
        series.setAttribute("seriesShape", "circle");
        break;
    case (SQUARE):
        series.setAttribute("seriesShape", "square");
        break;
    case (TRIANGLE):
        series.setAttribute("seriesShape", "triangle");
        break;
    case (RECTANGLE_H):
        series.setAttribute("seriesShape", "rectangle_h");
        break;
    case (RECTANGLE_V):
        series.setAttribute("seriesShape", "rectangle_v");
        break;
    default:
        series.setAttribute("seriesShape", "none");
    }
}

From source file:org.jfree.eastwood.ChartEngine.java

private static Color interpolatedColor(Color c1, Color c2, int index, int range) {
    if (index == 0) {
        return c1;
    }/*from  ww w.  jav a 2s. co  m*/
    if (index == range) {
        return c2;
    }
    double fraction = (index + 0.0) / range;
    int r1 = c1.getRed();
    int g1 = c1.getGreen();
    int b1 = c1.getBlue();
    int r2 = c2.getRed();
    int g2 = c2.getGreen();
    int b2 = c2.getBlue();
    return new Color((int) (r1 + fraction * (r2 - r1)), (int) (g1 + fraction * (g2 - g1)),
            (int) (b1 + fraction * (b2 - b1)));
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java

/**
 * Utility function to create a semi-transparent variant of a given colour.
 * @param color the original colour.//w w w  .j  av  a  2s. c  o  m
 * @param a alpha, as a value from 0 (transparent) to 255 (opaque).
 * @return colour with transparency set.
 */
private static Color transparentColor(final Color color, final int a) {
    return new Color(color.getRed(), color.getGreen(), color.getBlue(), a);
}

From source file:org.openstreetmap.josm.tools.Utils.java

/**
 * Returns the complementary color of {@code clr}.
 * @param clr the color to complement/*from   w ww.j  av  a 2 s .  c o m*/
 * @return the complementary color of {@code clr}
 */
public static Color complement(Color clr) {
    return new Color(255 - clr.getRed(), 255 - clr.getGreen(), 255 - clr.getBlue(), clr.getAlpha());
}

From source file:net.cloudkit.relaxation.VerifyImage.java

public void clearNoise(BufferedImage image) {
    /*/*  w  ww  .j av a 2  s  .com*/
    int w = image.getWidth();
    int h = image.getHeight();
            
    int p1;
    int p2;
    for (p1 = 0; p1 < w; ++p1) {
    for (p2 = 0; p2 < h; ++p2) {
        if (p1 == 0 || p2 == 0 || p1 == w - 1 || p2 == h - 1) {
            image.setRGB(p1, p2, Color.WHITE.getRGB());
        }
    }
    }
            
    for (int x = 0; x < w; ++x) {
    for (int y = 0; y < h; ++y) {
        p1 = x == 0 ? 255 : getRed(image.getRGB(x - 1, y));
        p2 = x == w - 1 ? 255 : getRed(image.getRGB(x + 1, y));
        int p3 = y == 0 ? 255 : getRed(image.getRGB(x, y - 1));
        int p4 = y == h - 1 ? 255 : getRed(image.getRGB(x, y + 1));
        int p5 = x != 0 && y != 0 ? getRed(image.getRGB(x - 1, y - 1)) : 255;
        int p6 = x != w - 1 && y != 0 ? getRed(image.getRGB(x + 1, y - 1)) : 255;
        int p7 = x != 0 && y != h - 1 ? getRed(image.getRGB(x - 1, y + 1)) : 255;
        int p8 = x != w - 1 && y != h - 1 ? getRed(image.getRGB(x + 1, y + 1)) : 255;
        if (p1 == 255 && p1 == p2 && p2 == p3 && p3 == p4 && p4 == p5 && p5 == p6 && p7 == p8) {
            image.setRGB(x, y, Color.WHITE.getRGB());
        }
    }
    }
    */

    final int width = image.getWidth();
    final int height = image.getHeight();

    // int blackThreshold = 300;

    // img.getMinX() img.getMinY()
    for (int x = image.getMinX(); x < width; x++) {
        for (int y = image.getMinY(); y < height; y++) {

            //                Color color = new Color(image.getRGB(x, y));
            //                if((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { //
            //                    image.setRGB(x, y, Color.WHITE.getRGB());
            //                } else if((color.getRed() + color.getGreen() + color.getBlue()) < 400) {
            //                    image.setRGB(x, y, Color.BLACK.getRGB());
            //                }

            int nearly = 0;
            int vertical = 0;
            int horizontal = 0;

            if (x > 0) {
                Color leftColor = new Color(image.getRGB(x - 1, y));
                if ((leftColor.getRed() + leftColor.getGreen() + leftColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (x < width - 1) {
                Color rightColor = new Color(image.getRGB(x + 1, y));
                if ((rightColor.getRed() + rightColor.getGreen() + rightColor.getBlue()) < 400) {
                    nearly++;
                    horizontal++;
                }
            }
            if (y > 0) {
                Color topColor = new Color(image.getRGB(x, y - 1));
                if ((topColor.getRed() + topColor.getGreen() + topColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }
            if (y < height - 1) {
                Color bottomColor = new Color(image.getRGB(x, y + 1));
                if ((bottomColor.getRed() + bottomColor.getGreen() + bottomColor.getBlue()) < 400) {
                    nearly++;
                    vertical++;
                }
            }

            if (x > 0 && y > 0) {
                Color leftTopColor = new Color(image.getRGB(x - 1, y - 1));
                if ((leftTopColor.getRed() + leftTopColor.getGreen() + leftTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y < height - 1) {
                Color rightBottomColor = new Color(image.getRGB(x + 1, y + 1));
                if ((rightBottomColor.getRed() + rightBottomColor.getGreen()
                        + rightBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x < width - 1 && y > 0) {
                Color rightTopColor = new Color(image.getRGB(x + 1, y - 1));
                if ((rightTopColor.getRed() + rightTopColor.getGreen() + rightTopColor.getBlue()) < 400) {
                    nearly++;
                }
            }
            if (x > 0 && y < height - 1) {
                Color leftBottomColor = new Color(image.getRGB(x - 1, y + 1));
                if ((leftBottomColor.getRed() + leftBottomColor.getGreen() + leftBottomColor.getBlue()) < 400) {
                    nearly++;
                }
            }

            if (nearly < 2) {
                image.setRGB(x, y, Color.WHITE.getRGB());
            }

        }
    }
}

From source file:net.sf.maltcms.chromaui.chromatogram2Dviewer.ui.panel.Chromatogram2DViewerPanel.java

@Override
public void setPaintScale(PaintScale ps) {
    Logger.getLogger(getClass().getName()).info("Set paint scale called on HeatmapPanel");
    GradientPaintScale sps = (GradientPaintScale) ps;
    if (this.ps != null) {
        double lb = this.ps.getLowerBound();
        double ub = this.ps.getUpperBound();
        sps.setLowerBound(lb);//  w  w  w.  ja v  a  2s.c o  m
        sps.setUpperBound(ub);
        //this.jSlider1.setValue(0);
    }
    this.alpha = (int) sps.getAlpha();
    this.beta = (int) sps.getBeta();
    this.ps = sps;
    Color c = (Color) sps.getPaint(this.ps.getUpperBound());
    selectionFill = new Color(c.getRed(), c.getBlue(), c.getGreen(), 192);
    selectionOutline = new Color(c.getRed(), c.getBlue(), c.getGreen()).darker();
    this.jSlider1.setMaximum(100);
    this.jSlider1.setMinimum(0);
    handleSliderChange();
}