List of usage examples for java.awt Color BLACK
Color BLACK
To view the source code for java.awt Color BLACK.
Click Source Link
From source file:GetApplets.java
private void createGUI() { JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10))); setContentPane(contentPane);/*from www .j av a 2s . c o m*/ JButton b = new JButton("Click to call getApplets()"); b.addActionListener(this); add(b, BorderLayout.PAGE_START); textArea = new JTextArea(5, 40); textArea.setEditable(false); JScrollPane scroller = new JScrollPane(textArea); add(scroller, BorderLayout.CENTER); }
From source file:ChartPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); if (values == null || values.length == 0) return;/*w w w . j a va 2 s . co m*/ double minValue = 0; double maxValue = 0; for (int i = 0; i < values.length; i++) { if (minValue > values[i]) minValue = values[i]; if (maxValue < values[i]) maxValue = values[i]; } Dimension d = getSize(); int clientWidth = d.width; int clientHeight = d.height; int barWidth = clientWidth / values.length; Font titleFont = new Font("SansSerif", Font.BOLD, 20); FontMetrics titleFontMetrics = g.getFontMetrics(titleFont); Font labelFont = new Font("SansSerif", Font.PLAIN, 10); FontMetrics labelFontMetrics = g.getFontMetrics(labelFont); int titleWidth = titleFontMetrics.stringWidth(title); int y = titleFontMetrics.getAscent(); int x = (clientWidth - titleWidth) / 2; g.setFont(titleFont); g.drawString(title, x, y); int top = titleFontMetrics.getHeight(); int bottom = labelFontMetrics.getHeight(); if (maxValue == minValue) return; double scale = (clientHeight - top - bottom) / (maxValue - minValue); y = clientHeight - labelFontMetrics.getDescent(); g.setFont(labelFont); for (int i = 0; i < values.length; i++) { int valueX = i * barWidth + 1; int valueY = top; int height = (int) (values[i] * scale); if (values[i] >= 0) valueY += (int) ((maxValue - values[i]) * scale); else { valueY += (int) (maxValue * scale); height = -height; } g.setColor(Color.red); g.fillRect(valueX, valueY, barWidth - 2, height); g.setColor(Color.black); g.drawRect(valueX, valueY, barWidth - 2, height); int labelWidth = labelFontMetrics.stringWidth(names[i]); x = i * barWidth + (barWidth - labelWidth) / 2; g.drawString(names[i], x, y); } }
From source file:cn.z.Ocr5.java
public static BufferedImage removeBackgroud(File picFile) throws Exception { BufferedImage img = ImageIO.read(picFile); final int width = img.getWidth(); final int height = img.getHeight(); // int blackThreshold = 300; // img.getMinX() img.getMinY() for (int x = img.getMinX(); x < width; x++) { for (int y = img.getMinY(); y < height; y++) { Color color = new Color(img.getRGB(x, y)); if ((color.getBlue() < 120) || ((color.getRed() + color.getGreen() + color.getBlue()) < 50)) { // img.setRGB(x, y, Color.WHITE.getRGB()); } else if ((color.getRed() + color.getGreen() + color.getBlue()) < 400) { img.setRGB(x, y, Color.BLACK.getRGB()); }/*from ww w . j av a2 s . c om*/ int nearly = 0; int vertical = 0; int horizontal = 0; if (x > 0) { Color leftColor = new Color(img.getRGB(x - 1, y)); if ((leftColor.getRed() + leftColor.getGreen() + leftColor.getBlue()) < 400) { nearly++; horizontal++; } } if (x < width - 1) { Color rightColor = new Color(img.getRGB(x + 1, y)); if ((rightColor.getRed() + rightColor.getGreen() + rightColor.getBlue()) < 400) { nearly++; horizontal++; } } if (y > 0) { Color topColor = new Color(img.getRGB(x, y - 1)); if ((topColor.getRed() + topColor.getGreen() + topColor.getBlue()) < 400) { nearly++; vertical++; } } if (y < height - 1) { Color bottomColor = new Color(img.getRGB(x, y + 1)); if ((bottomColor.getRed() + bottomColor.getGreen() + bottomColor.getBlue()) < 400) { nearly++; vertical++; } } if (x > 0 && y > 0) { Color leftTopColor = new Color(img.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(img.getRGB(x + 1, y + 1)); if ((rightBottomColor.getRed() + rightBottomColor.getGreen() + rightBottomColor.getBlue()) < 400) { nearly++; } } if (x < width - 1 && y > 0) { Color rightTopColor = new Color(img.getRGB(x + 1, y - 1)); if ((rightTopColor.getRed() + rightTopColor.getGreen() + rightTopColor.getBlue()) < 400) { nearly++; } } if (x > 0 && y < height - 1) { Color leftBottomColor = new Color(img.getRGB(x - 1, y + 1)); if ((leftBottomColor.getRed() + leftBottomColor.getGreen() + leftBottomColor.getBlue()) < 400) { nearly++; } } if (nearly < 2) { img.setRGB(x, y, Color.WHITE.getRGB()); } /* if (horizontal < 1 && vertical > 0) { img.setRGB(x, y, Color.WHITE.getRGB()); } if (horizontal > 0 && vertical < 1) { img.setRGB(x, y, Color.WHITE.getRGB()); } */ /* if (isWhite(img.getRGB(x, y), whiteThreshold) == 1) { img.setRGB(x, y, Color.WHITE.getRGB()); } else { img.setRGB(x, y, Color.BLACK.getRGB()); } if (getColorBright(img.getRGB(x, y)) < 100) { int count = isBlack(img.getRGB(x - 1, y), blackThreshold) + isBlack(img.getRGB(x + 1, y), blackThreshold) + isBlack(img.getRGB(x, y - 1), blackThreshold) + isBlack(img.getRGB(x, y + 1), blackThreshold) + isBlack(img.getRGB(x + 1, y + 1), blackThreshold) + isBlack(img.getRGB(x - 1, y - 1), blackThreshold) + isBlack(img.getRGB(x + 1, y -1 ), blackThreshold) + isBlack(img.getRGB(x - 1, y + 1), blackThreshold); System.out.println(count); if (count < 2) { img.setRGB(x, y, Color.WHITE.getRGB()); } // img.setRGB(x, y, Color.WHITE.getRGB()); } */ // if(getColorBright(img.getRGB(x, y)) > 600) { // img.setRGB(x, y, Color.WHITE.getRGB()); // } else { // /* // // ?Graphics2D // Graphics2D g2d = img.createGraphics(); // // ? // // 1.0f? 0-1.0???? // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 1.0f)); // // // g2d.setColor(new Color(255,0,0)); // g2d.setStroke(new BasicStroke(1)); // // g2d.draw // // // // ? ? // g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); // g2d.dispose(); // */ // // img.setRGB(x, y, Color.BLACK.getRGB()); // /* // System.out.println(getColorBright(img.getRGB(x, y)) + ":"); // System.out.println(getColorBright(img.getRGB(x + 1, y)) + "-" + getColorBright(img.getRGB(x + 1, y + 1)) + "-" + getColorBright(img.getRGB(x, y + 1))); // System.out.println(getColorBright(img.getRGB(x - 1, y)) + "-" + getColorBright(img.getRGB(x - 1, y - 1)) + "-" + getColorBright(img.getRGB(x, y - 1))); // System.out.println(getColorBright(img.getRGB(x - 1, y + 1)) + "-" + getColorBright(img.getRGB(x + 1, y - 1))); // */ // // /* // int i = 0; // i = ((x < width - 1) && getColorBright(img.getRGB(x + 1, y)) < 30)? i + 1 : i; // i = ((x < width - 1) && (y < height - 1) && getColorBright(img.getRGB(x + 1, y + 1)) < 30)? i + 1 : i; // i = ((y < height - 1) && getColorBright(img.getRGB(x, y + 1)) < 30)? i + 1 : i; // i = ((x > 0) && getColorBright(img.getRGB(x - 1, y)) < 30)? i + 1 : i; // i = ((x > 0) && (y > 0) && getColorBright(img.getRGB(x - 1, y - 1)) < 30)? i + 1 : i; // i = ((y > 0) && getColorBright(img.getRGB(x, y - 1)) < 30)? i + 1 : i; // i = ((x < width - 1) && (y > 0) && getColorBright(img.getRGB(x + 1, y - 1)) < 30)? i + 1 : i; // i = ((x > 0) && (y < height - 1) && getColorBright(img.getRGB(x - 1, y + 1)) < 30)? i + 1 : i; // // if(i > 1) { // img.setRGB(x, y, Color.BLACK.getRGB()); // } else { // img.setRGB(x, y, Color.WHITE.getRGB()); // } // */ // } /* int i = 0; i = (getColorBright(img.getRGB(x + 1, y)) == 0)? i + 1 : i; i = (getColorBright(img.getRGB(x + 1, y + 1)) == 0)? i + 1 : i; i = (getColorBright(img.getRGB(x, y + 1)) == 0)? i + 1 : i; i = (getColorBright(img.getRGB(x - 1, y)) == 0)? i + 1 : i; i = (getColorBright(img.getRGB(x - 1, y - 1)) == 0)? i + 1 : i; i = (getColorBright(img.getRGB(x, y - 1)) == 0)? i + 1 : i; System.out.println(getColorBright(img.getRGB(x, y)) + ":"); System.out.println(getColorBright(img.getRGB(x + 1, y)) + "-" + getColorBright(img.getRGB(x + 1, y + 1)) + "-" + getColorBright(img.getRGB(x, y + 1))); System.out.println(getColorBright(img.getRGB(x - 1, y)) + "-" + getColorBright(img.getRGB(x - 1, y - 1)) + "-" + getColorBright(img.getRGB(x, y - 1))); System.out.println(getColorBright(img.getRGB(x - 1, y + 1)) + "-" + getColorBright(img.getRGB(x + 1, y - 1))); if(getColorBright(img.getRGB(x, y)) == 0 && i < 3) { img.setRGB(x, y, Color.WHITE.getRGB()); } */ /* // ?for???? // ??object Object data = img.getRaster().getDataElements(x, y, null); int red = img.getColorModel().getRed(data); int blue = img.getColorModel().getBlue(data); int green = img.getColorModel().getGreen(data); System.out.println((red + blue + green) + "-" + getColorBright(img.getRGB(x, y))); red = (red * 3 + green * 6 + blue * 1)/10; green = red; blue = green; // r?g?b?rgbbufferedImage????rgbrgb8388608?255*255*255?16777216 int rgb = (red * 256 + green) * 256 + blue; if(rgb > 8388608) { rgb = rgb - 16777216; } // rgb img.setRGB(x, y, rgb); */ } } // img = img.getSubimage(1, 1, img.getWidth() - 2, img.getHeight() - 2); return img; }
From source file:com.compomics.pepshell.view.statistics.JFreeChartPanel.java
private static void setupPlot(XYPlot xYPlot) { // set background to white and grid color to black xYPlot.setBackgroundPaint(Color.white); xYPlot.setRangeGridlinePaint(Color.black); // hide the border of the sorrounding box xYPlot.setOutlinePaint(Color.white); // get domanin and range axes ValueAxis domainAxis = xYPlot.getDomainAxis(); ValueAxis rangeAxis = xYPlot.getRangeAxis(); // set label paint for axes to black domainAxis.setLabelPaint(Color.black); rangeAxis.setLabelPaint(Color.black); // set font for labels, both on domain and range axes domainAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12)); rangeAxis.setLabelFont(new Font("Tahoma", Font.BOLD, 12)); }
From source file:net.sf.jasperreports.chartthemes.provider.LineBorderProvider.java
@Override public BlockFrame getBlockFrame() { RectangleInsets borderInsets = insets == null ? new RectangleInsets(1.0, 1.0, 1.0, 1.0) : insets; Stroke borderStroke = lineStroke == null ? new BasicStroke(1.0f) : lineStroke; Paint borderPaint = paint == null ? null : paint.getPaint(); if (borderPaint == null) { borderPaint = Color.BLACK; }//from ww w .j ava 2s. c o m return new LineBorder(borderPaint, borderStroke, borderInsets); }
From source file:com.joliciel.jochre.graphics.VectorizerImpl.java
public BufferedImage drawArrayLists(JochreImage jochreImage) { long startTime = (new Date()).getTime(); BufferedImage vectorizedImage = new BufferedImage(jochreImage.getWidth(), jochreImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = vectorizedImage.createGraphics(); graphics2D.setStroke(new BasicStroke(1)); graphics2D.setPaint(Color.BLACK); for (Paragraph paragraph : jochreImage.getParagraphs()) { for (RowOfShapes row : paragraph.getRows()) { for (GroupOfShapes group : row.getGroups()) { for (Shape shape : group.getShapes()) { List<LineSegment> lines = this.vectorize(shape); for (LineSegment line : lines) graphics2D.drawLine(shape.getLeft() + line.getStartX(), shape.getTop() + line.getStartY(), shape.getLeft() + line.getEndX(), shape.getTop() + line.getEndY()); }//from www . ja v a 2s .com } } } if (LOG.isDebugEnabled()) { long endTime = (new Date()).getTime(); long diff = endTime - startTime; LOG.debug("Time elapsed: " + ((double) diff / 1000)); } return vectorizedImage; }
From source file:irille.pub.verify.RandomImageServlet.java
/** * ???,,?16,// www.ja v a2 s . c o m * @param num ?? * @param out ? * @throws IOException */ protected static void render(String num, boolean gif, OutputStream out) throws IOException { if (num.getBytes().length > 4) throw new IllegalArgumentException("The length of param num cannot exceed 4."); int width = 50; int height = 18; BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = (Graphics2D) bi.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); Font mFont = new Font("Tahoma", Font.BOLD | Font.ITALIC, 16); g.setFont(mFont); g.setColor(Color.BLACK); g.drawString(num, 2, 15); if (gif) { AnimatedGifEncoder e = new AnimatedGifEncoder(); e.setTransparent(Color.WHITE); e.start(out); e.setDelay(0); e.addFrame(bi); e.finish(); } else { ImageIO.write(bi, "png", out); } }
From source file:org.nbheaven.sqe.codedefects.dashboard.controlcenter.panels.Statistics.java
private static JFreeChart createOverviewPanel(DefaultCategoryDataset dataSet) { JFreeChart overview = org.jfree.chart.ChartFactory.createStackedBarChart(null, null, "CodeDefects", dataSet, PlotOrientation.HORIZONTAL, false, true, false); overview.setBorderVisible(false);/*from w ww. ja va 2 s .co m*/ overview.setBackgroundPaint(Color.WHITE); overview.setAntiAlias(true); overview.setNotify(true); CategoryPlot overviewPlot = overview.getCategoryPlot(); overviewPlot.setRangeGridlinePaint(Color.BLACK); overviewPlot.setDomainGridlinePaint(Color.BLACK); overviewPlot.setBackgroundPaint(Color.WHITE); overviewPlot.setForegroundAlpha(0.7f); overviewPlot.setRangeAxisLocation(AxisLocation.getOpposite(overviewPlot.getRangeAxisLocation())); CategoryAxis domainAxis = overviewPlot.getDomainAxis(); domainAxis.setVisible(true); LogarithmicAxis rangeAxis = new LogarithmicAxis("CodeDefects"); rangeAxis.setLabel(null); rangeAxis.setStrictValuesFlag(false); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); overviewPlot.setRangeAxis(rangeAxis); CategoryItemRenderer categoryItemRenderer = new StackedBarRenderer(); //3D(); // categoryItemRenderers[0].setPaint(Color.RED); categoryItemRenderer.setSeriesPaint(0, Color.RED); categoryItemRenderer.setSeriesPaint(1, Color.ORANGE); categoryItemRenderer.setSeriesPaint(2, Color.YELLOW); categoryItemRenderer.setBaseItemLabelsVisible(true); overviewPlot.setRenderer(categoryItemRenderer); return overview; }
From source file:com.griddynamics.jagger.diagnostics.visualization.GraphVisualizationHelper.java
public static <V, E> Image renderGraph(Graph<V, E> graph, int width, int height, GraphLayout graphLayout, final ColorTheme colorTheme, final Map<V, Paint> customNodeColors) { Layout<V, E> layout;/*from ww w .j av a2 s .com*/ switch (graphLayout) { case CIRCLE: layout = new CircleLayout<V, E>(graph); break; case ISOM: layout = new ISOMLayout<V, E>(graph); break; case FR: layout = new FRLayout<V, E>(graph); break; case KK: layout = new KKLayout<V, E>(graph); break; default: throw new RuntimeException("Unknown Graph Layout : [" + graphLayout + "]"); } layout.setSize(new Dimension((int) (width * (1 - IMAGE_HORIZONTAL_MARGIN)), (int) (height * (1 - IMAGE_VERTICAL_MARGIN)))); VisualizationImageServer<V, E> server = new VisualizationImageServer<V, E>(displacementLayout(layout, (int) (width * IMAGE_HORIZONTAL_MARGIN / 2), (int) (height * IMAGE_VERTICAL_MARGIN / 2)), new Dimension(width, height)); final Color edgeColor; switch (colorTheme) { case LIGHT: server.setBackground(Color.WHITE); edgeColor = Color.BLACK; break; case DARK: server.setBackground(Color.BLACK); edgeColor = Color.LIGHT_GRAY; break; default: throw new RuntimeException("Unknown Color Theme : [" + colorTheme + "]"); } Transformer<V, Paint> vertexPaint = new Transformer<V, Paint>() { public Paint transform(V v) { Paint paint = customNodeColors.get(v); if (paint == null) { paint = Color.LIGHT_GRAY; } return paint; } }; Transformer<V, Paint> vertexBorderPaint = new Transformer<V, Paint>() { public Paint transform(V v) { return Color.DARK_GRAY; } }; Transformer<E, Paint> edgePaint = new Transformer<E, Paint>() { public Paint transform(E e) { return edgeColor; } }; server.getRenderContext().setVertexFillPaintTransformer(vertexPaint); server.getRenderContext().setEdgeDrawPaintTransformer(edgePaint); server.getRenderContext().setArrowDrawPaintTransformer(edgePaint); server.getRenderContext().setArrowFillPaintTransformer(edgePaint); server.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>()); server.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<E>()); server.getRenderContext().setVertexDrawPaintTransformer(vertexBorderPaint); server.getRenderContext().setVertexLabelTransformer(new ChainedTransformer<V, String>( new Transformer[] { new ToStringLabeller<V>(), new Transformer<String, String>() { public String transform(String input) { return "<html><center><p>" + formatLabel(input, MAX_LABEL_LENGTH); } } })); VertexLabelAsShapeRenderer<V, E> vlasr = new VertexLabelAsShapeRenderer<V, E>(server.getRenderContext()); server.getRenderContext().setVertexShapeTransformer(vlasr); server.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); return server.getImage(new Point(0, 0), new Dimension(width, height)); }
From source file:MonteCarloWindowLogic.java
static void drawPointsOnChart(JPanel panelWhenInside, ArrayList<Point2D> convexHull, ArrayList<Point2D> hits, ArrayList<Point2D> miss) { panelWhenInside.removeAll();//from w w w.j av a 2 s.c o m panelWhenInside.setLayout(new java.awt.BorderLayout()); XYSeries seriersHits = new XYSeries("Hits"); convertArrayListToXYSeries(seriersHits, hits); XYSeries seriersMiss = new XYSeries("Miss"); convertArrayListToXYSeries(seriersMiss, miss); //TODO refactor this, to handling hits, miss and than convex hull int pairsNumber = 0; if (convexHull != null) pairsNumber = convexHull.size() - 1; XYSeries covnexHullDivideOnPiars[] = new XYSeries[pairsNumber]; for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { covnexHullDivideOnPiars[i] = new XYSeries("Convex hull pair " + i); } if (convexHull != null) { divideOnPairsAndConvertConvexHullIntoSeries(covnexHullDivideOnPiars, convexHull); } // Add the seriersAllPoints to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(seriersHits); dataset.addSeries(seriersMiss); for (int i = 0; i < covnexHullDivideOnPiars.length; i++) { dataset.addSeries(covnexHullDivideOnPiars[i]); } // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart(null, // Title null, // x-axis Label null, // y-axis Label dataset, // Dataset PlotOrientation.VERTICAL, // Plot Orientation false, // Show Legend false, // Use tooltips false // Configure chart to generate URLs? ); final XYPlot plot = chart.getXYPlot(); ChartPanel chartPanel = new ChartPanel(chart); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesLinesVisible(0, false); renderer.setSeriesShape(0, ShapeUtilities.createDiamond(3)); renderer.setSeriesPaint(1, Color.RED); renderer.setSeriesLinesVisible(1, false); renderer.setSeriesShape(1, ShapeUtilities.createDiamond(3)); for (int i = 2; i <= covnexHullDivideOnPiars.length + 1; i++) { renderer.setSeriesPaint(i, Color.black); renderer.setSeriesLinesVisible(i, true); renderer.setSeriesStroke(i, new BasicStroke(1.0f)); } plot.setRenderer(renderer); panelWhenInside.add(chartPanel, BorderLayout.CENTER); panelWhenInside.validate(); }