List of usage examples for java.awt Color getAlpha
public int getAlpha()
From source file:org.kalypso.commons.java.util.StringUtilities.java
/** * Converts a Color into a String./*from w w w.j av a 2 s. com*/ * <p> * String will have same format as specified in {@link StringUtilities#stringToColor(String)} * * @param c * @throws IllegalArgumentException * if color is null */ public static String colorToString(final Color c) { if (c == null) throw new IllegalArgumentException( Messages.getString("org.kalypso.commons.java.util.StringUtilities.1")); //$NON-NLS-1$ final StringBuffer buf = new StringBuffer(); buf.append(c.getRed()).append(";").append(c.getGreen()).append(";").append(c.getBlue()); //$NON-NLS-1$ //$NON-NLS-2$ // alpha component is optional if (c.getAlpha() != 255) buf.append(";").append(c.getAlpha()); //$NON-NLS-1$ return buf.toString(); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
protected static final LookupPaintScale createLUT(final int ncol, final float vmin, final float vmax, final Color start, final Color end) { final float[][] colors = new float[][] { { start.getRed() / 255f, start.getGreen() / 255f, start.getBlue() / 255f, start.getAlpha() / 255f }, { end.getRed() / 255f, end.getGreen() / 255f, end.getBlue() / 255f, end.getAlpha() / 255f } }; final float[] limits = new float[] { 0, 1 }; final LookupPaintScale lut = new LookupPaintScale(vmin, vmax, start); float val; float r, g, b, a; for (int j = 0; j < ncol; j++) { val = j / (ncol - 0.99f); final int i = 0; r = colors[i][0] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][0] - colors[i][0]); g = colors[i][1] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][1] - colors[i][1]); b = colors[i][2] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][2] - colors[i][2]); a = colors[i][3] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][3] - colors[i][3]); lut.add(val * (vmax - vmin) + vmin, new Color(r, g, b, a)); }// w w w. j ava 2s.c om return lut; }
From source file:ColorUtil.java
/** * Make a color darker./*from w ww . j av a 2s.c om*/ * * @param color Color to make darker. * @param fraction Darkness fraction. * @return Darker color. */ public static Color darker(Color color, double fraction) { int red = (int) Math.round(color.getRed() * (1.0 - fraction)); int green = (int) Math.round(color.getGreen() * (1.0 - fraction)); int blue = (int) Math.round(color.getBlue() * (1.0 - fraction)); if (red < 0) red = 0; else if (red > 255) red = 255; if (green < 0) green = 0; else if (green > 255) green = 255; if (blue < 0) blue = 0; else if (blue > 255) blue = 255; int alpha = color.getAlpha(); return new Color(red, green, blue, alpha); }
From source file:ColorUtil.java
/** * Make a color lighter./*w w w . j av a 2 s . c om*/ * * @param color Color to make lighter. * @param fraction Darkness fraction. * @return Lighter color. */ public static Color lighter(Color color, double fraction) { int red = (int) Math.round(color.getRed() * (1.0 + fraction)); int green = (int) Math.round(color.getGreen() * (1.0 + fraction)); int blue = (int) Math.round(color.getBlue() * (1.0 + fraction)); if (red < 0) red = 0; else if (red > 255) red = 255; if (green < 0) green = 0; else if (green > 255) green = 255; if (blue < 0) blue = 0; else if (blue > 255) blue = 255; int alpha = color.getAlpha(); return new Color(red, green, blue, alpha); }
From source file:msi.gama.outputs.layers.charts.ChartJFreeChartOutputHeatmap.java
protected static final LookupPaintScale createLUT(final int ncol, final float vmin, final float vmax, final Color start, final Color med, final Color end) { final float[][] colors = new float[][] { { start.getRed() / 255f, start.getGreen() / 255f, start.getBlue() / 255f, start.getAlpha() / 255f }, { med.getRed() / 255f, med.getGreen() / 255f, med.getBlue() / 255f, med.getAlpha() / 255f }, { end.getRed() / 255f, end.getGreen() / 255f, end.getBlue() / 255f, end.getAlpha() / 255f } }; final float[] limits = new float[] { 0, 0.5f, 1 }; final LookupPaintScale lut = new LookupPaintScale(vmin, vmax, med); float val; float r, g, b, a; for (int j = 0; j < ncol; j++) { val = j / (ncol - 0.99f); int i = 0; for (i = 0; i < limits.length; i++) { if (val < limits[i]) { break; }//from ww w . j a va 2 s.c om } i = i - 1; r = colors[i][0] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][0] - colors[i][0]); g = colors[i][1] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][1] - colors[i][1]); b = colors[i][2] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][2] - colors[i][2]); a = colors[i][3] + (val - limits[i]) / (limits[i + 1] - limits[i]) * (colors[i + 1][3] - colors[i][3]); lut.add(val * (vmax - vmin) + vmin, new Color(r, g, b, a)); } return lut; }
From source file:de.bund.bfr.knime.gis.views.canvas.CanvasUtils.java
public static Paint mixColors(Color backgroundColor, List<Color> colors, List<Double> alphas, boolean checkedInsteadOfStriped) { double rb = backgroundColor.getRed() / 255.0; double gb = backgroundColor.getGreen() / 255.0; double bb = backgroundColor.getBlue() / 255.0; double ab = backgroundColor.getAlpha() / 255.0; List<Color> cs = new ArrayList<>(); for (int i = 0; i < colors.size(); i++) { double alpha = alphas.get(i); if (alpha > 0.0) { double r = colors.get(i).getRed() / 255.0 * alpha + rb * (1 - alpha); double g = colors.get(i).getGreen() / 255.0 * alpha + gb * (1 - alpha); double b = colors.get(i).getBlue() / 255.0 * alpha + bb * (1 - alpha); double a = colors.get(i).getAlpha() / 255.0 * alpha + ab * (1 - alpha); cs.add(new Color((float) r, (float) g, (float) b, (float) a)); }/*from w w w .j a v a 2s .c om*/ } if (cs.isEmpty()) { return backgroundColor; } else if (cs.size() == 1) { return cs.get(0); } BufferedImage img; int size = cs.size() * (checkedInsteadOfStriped ? EDGE_TEXTURE_SIZE : NODE_TEXTURE_SIZE); if (checkedInsteadOfStriped) { img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { img.setRGB(x, y, cs.get((x / EDGE_TEXTURE_SIZE + y / EDGE_TEXTURE_SIZE) % cs.size()).getRGB()); } } } else { img = new BufferedImage(size, 1, BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < size; x++) { img.setRGB(x, 0, cs.get(x / NODE_TEXTURE_SIZE).getRGB()); } } return new TexturePaint(img, new Rectangle(img.getWidth(), img.getHeight())); }
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;//from ww w. j a va 2s. co m }
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 www .j a v a 2 s .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:org.openfaces.component.chart.impl.renderers.GradientXYBarPainterAdapter.java
@Override public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base, boolean pegShadow) { // handle a special case - if the bar colour has alpha == 0, it is // invisible so we shouldn't draw any shadow Paint itemPaint = renderer.getItemPaint(row, column); if (itemPaint instanceof Color) { Color c = (Color) itemPaint; if (c.getAlpha() == 0) { return; }// w w w . j a va 2 s. co m } RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(), renderer.getShadowYOffset(), base, pegShadow); if (renderer instanceof XYBarRendererAdapter) { g2.setPaint(((XYBarRendererAdapter) renderer).getShadowPaint()); } g2.fill(shadow); }
From source file:org.openfaces.component.chart.impl.renderers.StandardXYBarPainterAdapter.java
/** * Paints a single bar instance./*from ww w. j a v a2s.c o m*/ * * @param g2 the graphics target. * @param renderer the renderer. * @param row the row index. * @param column the column index. * @param bar the bar * @param base indicates which side of the rectangle is the base of the * bar. * @param pegShadow peg the shadow to the base of the bar? */ public void paintBarShadow(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base, boolean pegShadow) { // handle a special case - if the bar colour has alpha == 0, it is // invisible so we shouldn't draw any shadow Paint itemPaint = renderer.getItemPaint(row, column); if (itemPaint instanceof Color) { Color c = (Color) itemPaint; if (c.getAlpha() == 0) { return; } } RectangularShape shadow = createShadow(bar, renderer.getShadowXOffset(), renderer.getShadowYOffset(), base, pegShadow); if (renderer instanceof XYBarRendererAdapter) { g2.setPaint(((XYBarRendererAdapter) renderer).getShadowPaint()); } g2.fill(shadow); }