List of usage examples for java.awt Color getBlue
public int getBlue()
From source file:org.openstreetmap.josm.tools.Utils.java
/** * Returns the complementary color of {@code clr}. * @param clr the color to complement//from w w w.ja v a2 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) { /*/*from w w w.ja v a2 s . co m*/ 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:org.n52.server.io.render.DiagramRenderer.java
/** * Builds up a DesignDescriptionList which stores the information * about the style of each timeseries./*from w w w . ja v a2 s . c om*/ * * @param options * the options * @return the design description list */ private DesignDescriptionList buildUpDesignDescriptionList(DesignOptions options) { String domainAxisLabel; if (options.getLanguage() != null && options.getLanguage().equals("de")) { domainAxisLabel = "Zeit"; } else { // default => "en" domainAxisLabel = "Time"; } if (this.isOverview) { domainAxisLabel = null; } DesignDescriptionList designDescriptions = new DesignDescriptionList(domainAxisLabel); String observedPropertyWithGrid = options.getProperties().get(0).getPhenomenon(); for (TimeseriesProperties tsProperties : options.getProperties()) { Color c = JavaHelper.transformToColor(tsProperties.getHexColor()); String phenomenonId = tsProperties.getPhenomenon(); boolean drawGrid = observedPropertyWithGrid.equals(phenomenonId); designDescriptions.add(tsProperties, new Color(c.getRed(), c.getGreen(), c.getBlue(), (int) tsProperties.getOpacity() * 255 / 100), tsProperties.getLineStyle(), tsProperties.getLineWidth(), drawGrid); } return designDescriptions; }
From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java
@Override public JFreeChart createChart(DatasetMap datasets) { logger.debug("IN"); super.createChart(datasets); DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1"); DateAxis xAxis = new DateAxis(yLabel); xAxis.setLowerMargin(0.0);/*from w w w .ja v a 2 s . c om*/ xAxis.setUpperMargin(0.0); xAxis.setInverted(false); xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy")); if (dateAutoRange) { xAxis.setAutoRange(true); } else { DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter); xAxis.setTickUnit(unit); } if (dateMin != null && dateMax != null) { xAxis.setRange(dateMin, addDay(dateMax)); } else { xAxis.setRange(minDateFound, addDay(maxDateFound)); } // Calendar c=new GregorianCalendar(); // c.set(9 + 2000, Calendar.JANUARY, 1); // java.util.Date minima=c.getTime(); // Calendar c1=new GregorianCalendar(); // c1.set(9 + 2000, Calendar.FEBRUARY, 1); // java.util.Date massima=c1.getTime(); NumberAxis yAxis = new NumberAxis(xLabel); yAxis.setUpperMargin(0.0); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); yAxis.setRange(hourMin, hourMax); XYBlockRenderer renderer = new XYBlockRenderer(); renderer.setBlockWidth(BLOCK_HEIGHT); // one block for each minute! renderer.setBlockHeight(0.017); //renderer.setBlockWidth(1); renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT); // MyXYItemLabelGenerator my=new MyXYItemLabelGenerator(); // renderer.setItemLabelsVisible(null); // renderer.setSeriesItemLabelGenerator(0, my); // renderer.setSeriesItemLabelsVisible(0, true); // XYTextAnnotation annotation1 = new XYTextAnnotation( // "P_",1.2309372E12, 14.3); // XYTextAnnotation annotation2 = new XYTextAnnotation( // "P_",1.2308508E12, 16.3); for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) { String annotationCode = (String) iterator.next(); AnnotationBlock annotationBlock = annotations.get(annotationCode); XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(), annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition()); if (styleAnnotation != null) { xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize())); xyAnnotation.setPaint(styleAnnotation.getColor()); } else { xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8)); xyAnnotation.setPaint(Color.BLACK); } xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT); renderer.addAnnotation(xyAnnotation); } logger.debug("Annotation set"); LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color); String[] labels = new String[ranges.size() + 1]; labels[0] = ""; // ******************** SCALE **************************** for (Iterator iterator = ranges.iterator(); iterator.hasNext();) { RangeBlocks range = (RangeBlocks) iterator.next(); Integer index = patternRangeIndex.get(range.getPattern()); Color color = range.getColor(); if (color != null) { //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); Paint colorTransparent = null; if (addTransparency == true) { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50); } else { colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue()); } paintScale.add(index + 0.5, colorTransparent); } //String insertLabel=" "+range.getLabel(); String insertLabel = range.getLabel(); labels[index + 1] = insertLabel; } renderer.setPaintScale(paintScale); SymbolAxis scaleAxis = new SymbolAxis(null, labels); scaleAxis.setRange(0.5, ranges.size() + 0.5); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setMargin(new RectangleInsets(3, 10, 3, 10)); psl.setPosition(RectangleEdge.BOTTOM); psl.setAxisOffset(5.0); // ******************** END SCALE **************************** logger.debug("Scale Painted"); XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer); plot.setOrientation(PlotOrientation.HORIZONTAL); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5)); logger.debug("Plot set"); JFreeChart chart = new JFreeChart(name, plot); if (styleTitle != null) { TextTitle title = setStyleTitle(name, styleTitle); chart.setTitle(title); } chart.removeLegend(); chart.setBackgroundPaint(Color.white); chart.addSubtitle(psl); logger.debug("OUT"); return chart; }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void makeTransparent(BufferedImage img, Color trColor) { int w = img.getWidth(); int h = img.getHeight(); if (img.getType() != BufferedImage.TYPE_INT_ARGB) { return;/*w ww .j a v a2s . c om*/ } for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { if (img.getRaster().getSample(x, y, 0) == trColor.getRed() && img.getRaster().getSample(x, y, 1) == trColor.getGreen() && img.getRaster().getSample(x, y, 2) == trColor.getBlue()) { img.getRaster().setSample(x, y, 3, 0); } } } }
From source file:org.kurento.test.client.TestClient.java
public boolean compareColor(String videoTag, Color expectedColor) { @SuppressWarnings("unchecked") List<Long> realColor = (List<Long>) browserClient .executeScriptAndWaitOutput("return kurentoTest.colorInfo['" + videoTag + "'].currentColor;"); long red = realColor.get(0); long green = realColor.get(1); long blue = realColor.get(2); double distance = Math.sqrt((red - expectedColor.getRed()) * (red - expectedColor.getRed()) + (green - expectedColor.getGreen()) * (green - expectedColor.getGreen()) + (blue - expectedColor.getBlue()) * (blue - expectedColor.getBlue())); boolean out = distance <= browserClient.getColorDistance(); if (!out) {//from w ww . j a va 2 s. co m log.error("Difference in color comparision. Expected: {}, Real: {} (distance={})", expectedColor, realColor, distance); } return out; }
From source file:haven.Utils.java
public static Color preblend(Color c1, Color c2) { double a1 = c1.getAlpha() / 255.0; double a2 = c2.getAlpha() / 255.0; /* I can't help but feel that this should be possible to * express in some simpler form, but I can't see how. */ double ac = a1 + a2 - (a1 * a2); return (new Color((int) Math.round((((c2.getRed() * a2) - (c1.getRed() * a2)) / ac) + c1.getRed()), (int) Math.round((((c2.getGreen() * a2) - (c1.getGreen() * a2)) / ac) + c1.getGreen()), (int) Math.round((((c2.getBlue() * a2) - (c1.getBlue() * a2)) / ac) + c1.getBlue()), (int) Math.round(ac * 255))); }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
private void configureSolidAreaFill(Graphics2D g2, Paint itemPaint, SolidLineAreaFill solidLineAreaFill) { double transparency = solidLineAreaFill.getTransparency(); if (itemPaint instanceof Color) { Color itemColor = (Color) itemPaint; int alpha = transparency >= 0.0 && transparency <= 1.0 ? Math.round(255 * (float) transparency) : 255; g2.setPaint(new Color(itemColor.getRed(), itemColor.getGreen(), itemColor.getBlue(), alpha)); } else {//w w w.j a va 2 s . c o m g2.setPaint(itemPaint); } }
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 . ja va2 s. com*/ 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:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.AngularHistogramRenderer.java
@Override public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) { // compute the right color for the paint int length = GuiUtils.getAvailableColors().length; Color color = GuiUtils.getAvailableColors()[index % length]; // get all the data points int numPoints = dataset.getItemCount(seriesIndex); for (int i = 0; i < numPoints; i++) { double theta = dataset.getXValue(seriesIndex, i); // the angle at the center double radius = dataset.getYValue(seriesIndex, i); // the frequency Point p0 = plot.translateToJava2D(0, 0, plot.getAxis(), dataArea); Point p1 = plot.translateToJava2D(theta - binSize, radius, plot.getAxis(), dataArea); Point p2 = plot.translateToJava2D(theta + binSize, radius, plot.getAxis(), dataArea); Polygon poly = new Polygon(new int[] { p0.x, p1.x, p2.x }, new int[] { p0.y, p1.y, p2.y }, 3); g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175)); g2.fill(poly);// w w w. j a va2s . c o m } }