List of usage examples for java.awt Color getRed
public int getRed()
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; }/* w w w . j a va 2 s . c om*/ } }; // 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: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 {//from w w w.java2s . com 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:nl.softwaredesign.exporter.ODTExportFormat.java
/** * @param toConvert color to convert//from w w w .j a v a 2s.c o m * @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:util.ui.UiUtilities.java
/** * returns a color code as used in HTML, e.g. #FF0000 for pure red * @param color//from www .java 2 s . co m * @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:util.ui.UiUtilities.java
/** * Creates a text area that holds a help text. * * @param msg//w ww .ja v a 2 s . com * 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:Main.java
public TranslucentJPanel(Color bgColor) { this.red = bgColor.getRed(); this.green = bgColor.getGreen(); this.blue = bgColor.getBlue(); }
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());//from ww w .j av a 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(); }
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);// w ww . jav a 2s . c o m }
From source file:org.apache.fop.util.ColorUtil.java
private static String toRGBFunctionCall(Color color) { StringBuffer sbuf = new StringBuffer(); sbuf.append('#'); String s = Integer.toHexString(color.getRed()); if (s.length() == 1) { sbuf.append('0'); }/*w w w. ja v a2 s .c o m*/ sbuf.append(s); s = Integer.toHexString(color.getGreen()); if (s.length() == 1) { sbuf.append('0'); } sbuf.append(s); s = Integer.toHexString(color.getBlue()); if (s.length() == 1) { sbuf.append('0'); } sbuf.append(s); if (color.getAlpha() != 255) { s = Integer.toHexString(color.getAlpha()); if (s.length() == 1) { sbuf.append('0'); } sbuf.append(s); } return sbuf.toString(); }