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:org.jtrfp.trcl.core.Texture.java

public static ByteBuffer indexed2RGBA8888(ByteBuffer indexedPixels, Color[] palette) {
    Color color;
    ByteBuffer buf = ByteBuffer.allocateDirect(indexedPixels.capacity() * 4);
    final int cap = indexedPixels.capacity();
    for (int i = 0; i < cap; i++) {
        color = palette[(indexedPixels.get() & 0xFF)];
        buf.put((byte) color.getRed());
        buf.put((byte) color.getGreen());
        buf.put((byte) color.getBlue());
        buf.put((byte) color.getAlpha());
    } // end for(i)
    buf.clear();// Rewind
    return buf;// www .j  av  a  2 s .  c  o  m
}

From source file:com.limegroup.gnutella.gui.GUIUtils.java

/**
 * Convert a color object to a hex string
 **///from   w w w  . j ava2  s .  co  m
public static String colorToHex(Color colorCode) {
    int r = colorCode.getRed();
    int g = colorCode.getGreen();
    int b = colorCode.getBlue();

    return toHex(r) + toHex(g) + toHex(b);
}

From source file:mx.itesm.web2mexadl.cluster.ClusterAnalyzer.java

/**
 * Generate a random color, to identify Clusters. Based on:
 * http://stackoverflow.com/questions/43044/algorithm-to-randomly-generate
 * -an-aesthetically-pleasing-color-palette
 * //from ww  w .  jav  a2  s  .  co  m
 * @return
 */
private static Color getRandomColor() {
    int red;
    int blue;
    int green;
    Random random;
    Color mixColor;
    Color returnValue;

    // Base color (white)
    mixColor = new Color(255, 255, 255);
    random = new Random();
    red = random.nextInt(256);
    green = random.nextInt(256);
    blue = random.nextInt(256);

    // Mix new color with base one
    red = (red + mixColor.getRed()) / 2;
    green = (green + mixColor.getGreen()) / 2;
    blue = (blue + mixColor.getBlue()) / 2;

    returnValue = new Color(red, green, blue);
    return returnValue;
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchicalClusterer.java

private static Color mixColors(Color c1, double w1, Color c2, double w2) {

    if (w1 == 0.0) {
        return c2;
    }/*from   w  w  w .j  a va2 s .  c om*/

    if (w2 == 0.0) {
        return c1;
    }

    double wa1 = FastMath.abs(w1);
    double wa2 = FastMath.abs(w2);

    double total = wa1 + wa2;

    double t1 = wa1 / total;
    double t2 = wa2 / total;

    if (t1 < 0.1) {
        t1 = 0.1;
        t2 = 0.8;
    }

    if (t2 < 0.1) {
        t1 = 0.8;
        t2 = 0.1;
    }

    int red = (int) (t1 * (double) c1.getRed() + t2 * (double) c2.getRed());
    int green = (int) (t1 * (double) c1.getGreen() + t2 * (double) c2.getGreen());
    int blue = (int) (t1 * (double) c1.getBlue() + t2 * (double) c2.getBlue());

    return new Color(red, green, blue);
}

From source file:org.ut.biolab.medsavant.shared.util.MiscUtils.java

/**
 * Blend two colours, in the given proportions. Resulting alpha is always
 * 1.0.//from   ww  w  .  jav a2  s  . com
 *
 * @param col1 the first colour
 * @param col2 the second colour
 * @param weight1 the weight given to col1 (from 0.0-1.0)
 */
public static Color blend(Color col1, Color col2, float weight1) {

    float weight2 = (1.0F - weight1) / 255;
    weight1 /= 255;

    // This constructor expects values from 0.0F to 1.0F, so weights have to be scaled appropriately.
    return new Color(col1.getRed() * weight1 + col2.getRed() * weight2,
            col1.getGreen() * weight1 + col2.getGreen() * weight2,
            col1.getBlue() * weight1 + col2.getBlue() * weight2);
}

From source file:Main.java

public static String displayPropertiesToCSS(Font font, Color fg) {
    StringBuffer rule = new StringBuffer("body {");
    if (font != null) {
        rule.append(" font-family: ");
        rule.append(font.getFamily());//  ww  w  .  j a  v  a 2s  .  com
        rule.append(" ; ");
        rule.append(" font-size: ");
        rule.append(font.getSize());
        rule.append("pt ;");
        if (font.isBold()) {
            rule.append(" font-weight: 700 ; ");
        }
        if (font.isItalic()) {
            rule.append(" font-style: italic ; ");
        }
    }
    if (fg != null) {
        rule.append(" color: #");
        if (fg.getRed() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getRed()));
        if (fg.getGreen() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getGreen()));
        if (fg.getBlue() < 16) {
            rule.append('0');
        }
        rule.append(Integer.toHexString(fg.getBlue()));
        rule.append(" ; ");
    }
    rule.append(" }");
    return rule.toString();
}

From source file:org.apache.fop.render.rtf.TextAttributesConverter.java

/**
 * Reads background-color from bl and writes it to rtfAttr.
 *
 * @param bpb the CommonBorderPaddingBackground from which the properties are read
 * @param rtfAttr the RtfAttributes object the attributes are written to
 *///from  w  w w.  jav a 2s  . c o  m
private static void attrBackgroundColor(CommonBorderPaddingBackground bpb, RtfAttributes rtfAttr) {
    Color fopValue = bpb.backgroundColor;
    int rtfColor = 0;
    /* FOP uses a default background color of "transparent", which is
       actually a transparent black, which is generally not suitable as a
       default here. Changing FOP's default to "white" causes problems in
       PDF output, so we will look for the default here & change it to
       "auto". */
    if ((fopValue == null) || ((fopValue.getRed() == 0) && (fopValue.getGreen() == 0)
            && (fopValue.getBlue() == 0) && (fopValue.getAlpha() == 0))) {
        return;
    } else {
        rtfColor = convertFOPColorToRTF(fopValue);
    }

    rtfAttr.set(RtfText.ATTR_BACKGROUND_COLOR, rtfColor);
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.ChartRendererFactory.java

private static void configureXYDifferenceRenderer(FormattedXYDifferenceRenderer renderer,
        ValueSource valueSource, PlotConfiguration plotConfiguration) {
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    SeriesFormat seriesFormat = valueSource.getSeriesFormat();
    DimensionConfig domainConfig = valueSource.getDomainConfig();
    DimensionConfig colorDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.COLOR);
    DimensionConfig shapeDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.SHAPE);

    int seriesCount = 1;// valueSource.getSeriesDataForAllGroupCells().groupCellCount();

    // Loop all series and set series format.
    // Format based on dimension configs will be set later on in initFormatDelegate().
    for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) {
        // configure linestyle
        if (seriesFormat.getLineStyle() == LineStyle.NONE) {
        } else {//w ww .ja va2s.c  o  m
            renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false);
        }

        // configure series shape if necessary
        if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) {
            if (seriesFormat.getItemShape() != ItemShape.NONE) {
                renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape());
            } else {
            }
        }

        // configure series color if necessary
        if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) {
            Color itemColor = seriesFormat.getItemColor();
            Color halfTransparentPaint = DataStructureUtils.setColorAlpha(itemColor, itemColor.getAlpha() / 2);

            renderer.setSeriesPaint(0, halfTransparentPaint);
            renderer.setSeriesFillPaint(0, halfTransparentPaint);
            renderer.setPositivePaint(halfTransparentPaint);
            renderer.setNegativePaint(new Color(255 - itemColor.getRed(), 255 - itemColor.getGreen(),
                    255 - itemColor.getBlue(), itemColor.getAlpha() / 2));
        }
        renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT);
    }
}

From source file:util.ui.UiUtilities.java

/**
 * Creates a text area that holds a help text.
 *
 * @param msg/*  w w  w .  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.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  www. jav a2s. c  o  m
        }
    };

    //        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;
}