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.polymap.core.data.image.ImageTransparencyProcessor.java

public static BufferedImage transparency(Image image, final Color markerColor) throws IOException {
    long start = System.currentTimeMillis();

    RGBImageFilter filter = new RGBImageFilter() {
        // the color we are looking for... Alpha bits are set to opaque
        public int markerRGB = markerColor.getRGB() | 0xFF000000;

        byte threshold = 25;

        double range = ((double) 0xFF) / (3 * threshold);

        public final int filterRGB(int x, int y, int rgb) {
            Color probe = new Color(rgb);
            //log.info( "probe=" + probe + ", marker=" + markerColor );

            // delta values
            int dRed = markerColor.getRed() - probe.getRed();
            int dGreen = markerColor.getGreen() - probe.getGreen();
            int dBlue = markerColor.getBlue() - probe.getBlue();
            //log.info( "    dRed=" + dRed + ", dGreen=" + dGreen );

            if (dRed >= 0 && dRed < threshold && dGreen >= 0 && dGreen < threshold && dBlue >= 0
                    && dBlue < threshold) {
                int alpha = (int) Math.round(range * (dRed + dGreen + dBlue));
                //log.info( "    -> alpha=" + alpha );

                return ((alpha << 24) | 0x00FFFFFF) & rgb;
            } else {
                // nothing to do
                return rgb;
            }//from w  ww . j  a v  a 2  s . com
        }
    };

    //        BufferedImage bimage = null;
    //        if (image instanceof BufferedImage) {
    //            bimage = (BufferedImage)image;
    //        }
    //        else {
    //            bimage = new BufferedImage(
    //                    image.getHeight( null ), image.getWidth( null ), BufferedImage.TYPE_INT_ARGB );
    //            Graphics g = bimage.getGraphics();
    //            g.drawImage( image, 0, 0, null );
    //            g.dispose();
    //        }

    ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
    Image result = Toolkit.getDefaultToolkit().createImage(ip);

    BufferedImage bresult = new BufferedImage(image.getHeight(null), image.getWidth(null),
            BufferedImage.TYPE_INT_ARGB);
    Graphics g = bresult.getGraphics();
    g.drawImage(result, 0, 0, null);
    g.dispose();

    //        // XXX this can surely be done any more clever
    //        int width = bimage.getWidth();
    //        int height = bimage.getHeight();
    //        for (int x=bimage.getMinX(); x<width; x++) {
    //            for (int y=bimage.getMinY(); y<height; y++) {
    //                int filtered = filter.filterRGB( x, y, bimage.getRGB( x, y ) );
    //                result.setRGB( x, y, filtered );
    //            }
    //        }

    log.debug("Transparency done. (" + (System.currentTimeMillis() - start) + "ms)");
    return bresult;
}

From source file:util.ui.UiUtilities.java

/**
 * Creates a text area that holds a help text.
 *
 * @param msg/*  w  ww .jav a  2s.c o  m*/
 *          The help text.
 * @return A text area containing the help text.
 */
public static JTextArea createHelpTextArea(String msg) {
    JTextArea descTA = new JTextArea(msg);
    descTA.setBorder(BorderFactory.createEmptyBorder());
    descTA.setFont(new JLabel().getFont());
    descTA.setEditable(false);
    descTA.setOpaque(false);
    descTA.setWrapStyleWord(true);
    descTA.setLineWrap(true);
    descTA.setFocusable(false);

    Color bg = new JPanel().getBackground();

    descTA.setBackground(new Color(bg.getRed(), bg.getGreen(), bg.getBlue()));

    return descTA;
}

From source file:org.wings.style.CSSStyleSheet.java

/**
 * Converts a type Color to a hex string
 * in the format "#RRGGBB"//from   ww w.j a v  a2s.  c o  m
 */
static String colorToHex(Color color) {
    String colorstr = "#";

    // Red
    String str = Integer.toHexString(color.getRed());
    if (str.length() > 2)
        str = str.substring(0, 2);
    if (str.length() < 2)
        colorstr += "0" + str;
    else
        colorstr += str;

    // Green
    str = Integer.toHexString(color.getGreen());
    if (str.length() > 2)
        str = str.substring(0, 2);
    if (str.length() < 2)
        colorstr += "0" + str;
    else
        colorstr += str;

    // Blue
    str = Integer.toHexString(color.getBlue());
    if (str.length() > 2)
        str = str.substring(0, 2);
    if (str.length() < 2)
        colorstr += "0" + str;
    else
        colorstr += str;

    return colorstr;
}

From source file:Main.java

public TranslucentJPanel(Color bgColor) {
    this.red = bgColor.getRed();
    this.green = bgColor.getGreen();
    this.blue = bgColor.getBlue();
}

From source file:util.ui.UiUtilities.java

/**
 * returns a color code as used in HTML, e.g. #FF0000 for pure red
 * @param color//from w  w  w. ja v a2s . c om
 * @return HTML color code
 */
public static String getHTMLColorCode(Color color) {
    return '#' + StringUtils.leftPad(Integer.toString(color.getRed(), 16), 2, '0')
            + StringUtils.leftPad(Integer.toString(color.getGreen(), 16), 2, '0')
            + StringUtils.leftPad(Integer.toString(color.getBlue(), 16), 2, '0');
}

From source file:com.github.nbyl.xfdcontrol.plugins.notification.blink1.Blink1ToolCommand.java

@VisibleForTesting
String mapColorToRgbArgument(Color color) {
    return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Color color = getBackground();
    String text = color.getRed() + "x" + color.getGreen() + "x" + color.getBlue();

    g.drawString(text, 20, 30);// ww  w  .j  a v a 2 s . co  m
}

From source file:nl.softwaredesign.exporter.ODTExportFormat.java

/**
 * @param toConvert color to convert/*from   w ww  .ja v a 2 s .  c  om*/
 * @return the six character hex string (rrggbb) for the color
 */
private static String rgbHexValue(Color toConvert) {
    StringBuilder result = new StringBuilder();

    result.append(Integer.toHexString(toConvert.getRed()));
    if (result.length() < 2) {
        result.insert(0, '0');
    }

    result.append(Integer.toHexString(toConvert.getGreen()));
    if (result.length() < 4) {
        result.insert(2, '0');
    }

    result.append(Integer.toHexString(toConvert.getBlue()));
    if (result.length() < 6) {
        result.insert(4, '0');
    }

    return result.toString();
}

From source file:lu.lippmann.cdb.graph.GraphUtil.java

/**
 * return if background of a node is dark or not
 * //w  ww .j ava 2  s  .  com
 * @param v
 * @return
 */
public static boolean isDarkNode(final CNode v) {
    final Color c = v.getColor();
    return ((c.getBlue() + c.getGreen() + c.getRed()) / 3 < 128);
}

From source file:org.apache.fop.util.ColorUtil.java

private static String toCIELabFunctionCall(ColorWithAlternatives color) {
    Color fallbackColor = getsRGBFallback(color);
    StringBuffer sb = new StringBuffer("cie-lab-color(");
    sb.append(fallbackColor.getRed()).append(',');
    sb.append(fallbackColor.getGreen()).append(',');
    sb.append(fallbackColor.getBlue());// w  w  w .  j  a  va 2  s.  c  o m
    CIELabColorSpace cs = (CIELabColorSpace) color.getColorSpace();
    float[] lab = cs.toNativeComponents(color.getColorComponents(null));
    for (int i = 0; i < 3; i++) {
        sb.append(',').append(lab[i]);
    }
    sb.append(')');
    return sb.toString();
}