List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2D; g2D = (Graphics2D) g;/*w ww . ja v a 2 s .c o m*/ g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); FontRenderContext frc = g2D.getFontRenderContext(); Font font1 = new Font("Courier", Font.BOLD, 24); String str1 = new String("Java"); TextLayout tl = new TextLayout(str1, font1, frc); g2D.setColor(Color.gray); tl.draw(g2D, 50, 150); }
From source file:krasa.cpu.CpuUsagePanel.java
/** * it will probably be better synchronized, not sure *//*from www . ja v a 2 s . c om*/ private synchronized void draw(Graphics g, Image bufferedImage) { UIUtil.drawImage(g, bufferedImage, 0, 0, null); if (UIUtil.isJreHiDPI((Graphics2D) g) && !UIUtil.isUnderDarcula()) { Graphics2D g2 = (Graphics2D) g.create(0, 0, getWidth(), getHeight()); float s = JBUI.sysScale(g2); g2.scale(1 / s, 1 / s); g2.setColor(UIUtil.isUnderIntelliJLaF() ? Gray.xC9 : Gray.x91); g2.drawLine(0, 0, (int) (s * getWidth()), 0); g2.scale(1, 1); g2.dispose(); } }
From source file:ImageOps.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); int w = getSize().width; int h = getSize().height; g2.setColor(Color.black); float[][] data = { { 0.1f, 0.1f, 0.1f, // low-pass filter 0.1f, 0.2f, 0.1f, 0.1f, 0.1f, 0.1f }, SHARPEN3x3_3 }; String theDesc[] = { "Convolve LowPass", "Convolve Sharpen", "LookupOp", "RescaleOp" }; for (int i = 0; i < bi.length; i++) { int iw = bi[i].getWidth(this); int ih = bi[i].getHeight(this); int x = 0, y = 0; AffineTransform at = new AffineTransform(); at.scale((w - 14) / 2.0 / iw, (h - 34) / 2.0 / ih); BufferedImageOp biop = null; BufferedImage bimg = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); switch (i) { case 0://from w w w . j a va 2 s.c o m case 1: x = i == 0 ? 5 : w / 2 + 3; y = 15; Kernel kernel = new Kernel(3, 3, data[i]); ConvolveOp cop = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); cop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); break; case 2: x = 5; y = h / 2 + 15; byte chlut[] = new byte[256]; for (int j = 0; j < 200; j++) chlut[j] = (byte) (256 - j); ByteLookupTable blut = new ByteLookupTable(0, chlut); LookupOp lop = new LookupOp(blut, null); lop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); break; case 3: x = w / 2 + 3; y = h / 2 + 15; RescaleOp rop = new RescaleOp(1.1f, 20.0f, null); rop.filter(bi[i], bimg); biop = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); } g2.drawImage(bimg, biop, x, y); TextLayout tl = new TextLayout(theDesc[i], g2.getFont(), g2.getFontRenderContext()); tl.draw(g2, (float) x, (float) y - 4); } }
From source file:org.n52.oxf.render.sos.ProportionalCircleMapRenderer.java
/** * renders one frame of the animation.//from w ww . j a va 2 s . co m */ private Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures, ObservationSeriesCollection obsValues) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex]; // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); // draw time-string into map: g.setColor(Color.BLACK); g.drawString(currentTimePos.toString(), 20, 20); for (OXFFeature dotFeature : selectedFeatures) { // // draw the points into the image at the georeferenced position of the corresponding feature: // Point pRealWorld = (Point) dotFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); ObservedValueTuple tuple = obsValues.getTuple(dotFeature, currentTimePos); // if there wasn't a tuple for the current time position go backwards through the sortedTimeArray and take the most recent one: int j = currentTimeIndex - 1; while (tuple == null && j >= 0) { tuple = obsValues.getTuple(dotFeature, sortedTimeArray[j]); j--; } // if a tuple was found -> draw the dot: if (tuple != null) { int dotSize = computeDotSize((Double) tuple.getValue(0), (Double) obsValues.getMinimum(0), (Double) obsValues.getMaximum(0)); g.setColor(POINT_INNER_COLOR); g.fillOval(pScreen.x - (dotSize / 2), pScreen.y - (dotSize / 2), dotSize, dotSize); } // otherwise draw "no data available" else { g.setColor(Color.BLACK); // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } } return image; }
From source file:gsn.vsensor.DemoVSensor.java
public void dataAvailable(String inputStreamName, StreamElement data) { if (inputStreamName.equalsIgnoreCase("SSTREAM")) { String action = (String) data.getData("STATUS"); /**/* w w w. j a v a 2 s .co m*/ * */ String moteId = (String) data.getData("ID"); if (moteId.toLowerCase().indexOf("mica") < 0) return; if (action.toLowerCase().indexOf("add") >= 0) counter++; if (action.toLowerCase().indexOf("remove") >= 0) counter--; } if (inputStreamName.equalsIgnoreCase("CSTREAM")) { BufferedImage bufferedImage = null; outputStream.reset(); byte[] rawData = (byte[]) data.getData("IMAGE"); input = new ByteArrayInputStream(rawData); try { bufferedImage = ImageIO.read(input); } catch (IOException e) { logger.error(e.getMessage(), e); } Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics(); int size = 30; int locX = 0; int locY = 0; if (counter < 0) counter = 0; switch (counter) { case 0: graphics.setColor(Color.RED); break; case 1: graphics.setColor(Color.ORANGE); break; case 2: graphics.setColor(Color.YELLOW); break; case 3: graphics.setColor(Color.GREEN); break; default: logger.warn( new StringBuilder().append("Shouldn't happen.>").append(counter).append("<").toString()); } graphics.fillOval(locX, locY, size, size); try { ImageIO.write(bufferedImage, "jpeg", outputStream); outputStream.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } StreamElement outputSE = new StreamElement(OUTPUT_FIELDS, OUTPUT_TYPES, new Serializable[] { outputStream.toByteArray() }, data.getTimeStamp()); dataProduced(outputSE); } logger.info( new StringBuilder().append("Data received under the name: ").append(inputStreamName).toString()); }
From source file:com.bwc.ora.models.Lrp.java
@Override public void drawOverlay(BufferedImage baseImg) { Graphics2D graphics = baseImg.createGraphics(); graphics.setColor(Color.green); graphics.draw(this); // System.out.println("Drawing selection on OCT..."); }
From source file:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java
/** * {@inheritDoc}/* w w w . ja v a 2 s . com*/ */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; if (!released && source != null) { final PiePlot plot = ((PiePlot) getChart().getPlot()); final Comparable<?> key = plot.getDataset().getKey(source.getSectionIndex()); final Color color = (Color) plot.getSectionPaint(key); g2d.translate(tx, ty); g2d.setColor(color); g2d.fill(source.getArea()); } }
From source file:RadialGradientApp.java
@Override protected void paintComponent(Graphics g) { setFont(getFont().deriveFont(70.f).deriveFont(Font.BOLD)); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Retains the previous state Paint oldPaint = g2.getPaint(); // Fills the circle with solid blue color g2.setColor(new Color(0x0153CC)); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds shadows at the top Paint p;/*from w w w . j av a2s . co m*/ p = new GradientPaint(0, 0, new Color(0.0f, 0.0f, 0.0f, 0.4f), 0, getHeight(), new Color(0.0f, 0.0f, 0.0f, 0.0f)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds highlights at the bottom p = new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 0.0f), 0, getHeight(), new Color(1.0f, 1.0f, 1.0f, 0.4f)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Creates dark edges for 3D effect p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 2.0f, new float[] { 0.0f, 1.0f }, new Color[] { new Color(6, 76, 160, 127), new Color(0.0f, 0.0f, 0.0f, 0.8f) }); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds oval inner highlight at the bottom p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() * 1.5), getWidth() / 2.3f, new Point2D.Double(getWidth() / 2.0, getHeight() * 1.75 + 6), new float[] { 0.0f, 0.8f }, new Color[] { new Color(64, 142, 203, 255), new Color(64, 142, 203, 0) }, RadialGradientPaint.CycleMethod.NO_CYCLE, RadialGradientPaint.ColorSpaceType.SRGB, AffineTransform.getScaleInstance(1.0, 0.5)); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Adds oval specular highlight at the top left p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 1.4f, new Point2D.Double(45.0, 25.0), new float[] { 0.0f, 0.5f }, new Color[] { new Color(1.0f, 1.0f, 1.0f, 0.4f), new Color(1.0f, 1.0f, 1.0f, 0.0f) }, RadialGradientPaint.CycleMethod.NO_CYCLE); g2.setPaint(p); g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1); // Restores the previous state g2.setPaint(oldPaint); // Draws the logo // FontRenderContext context = g2.getFontRenderContext(); // TextLayout layout = new TextLayout("R", getFont(), context); // Rectangle2D bounds = layout.getBounds(); // // float x = (getWidth() - (float) bounds.getWidth()) / 2.0f; // float y = (getHeight() + (float) bounds.getHeight()) / 2.0f; // // g2.setColor(Color.WHITE); // layout.draw(g2, x, y); // // Area shadow = new Area(layout.getOutline(null)); // shadow.subtract(new Area(layout.getOutline(AffineTransform.getTranslateInstance(1.0, 1.0)))); // g2.setColor(Color.BLACK); // g2.translate(x, y); // g2.fill(shadow); // g2.translate(-x, -y); }
From source file:com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.java
private void cleanImage(BufferedImage image, List<Rectangle> areasToBeCleaned) { Graphics2D graphics = image.createGraphics(); graphics.setColor(CLEANED_AREA_FILL_COLOR); // A rectangle in the areasToBeCleaned list is treated to be in standard [0, 1]x[0,1] image space // (y varies from bottom to top and x from left to right), so we should scale the rectangle and also // invert and shear the y axe for (Rectangle rect : areasToBeCleaned) { int scaledBottomY = (int) Math.ceil(rect.getBottom() * image.getHeight()); int scaledTopY = (int) Math.floor(rect.getTop() * image.getHeight()); int x = (int) Math.ceil(rect.getLeft() * image.getWidth()); int y = scaledTopY * -1 + image.getHeight(); int width = (int) Math.floor(rect.getRight() * image.getWidth()) - x; int height = scaledTopY - scaledBottomY; graphics.fillRect(x, y, width, height); }//from ww w . j av a 2 s . co m graphics.dispose(); }
From source file:org.n52.oxf.render.sos.AnimatedMapBarChartRenderer.java
protected Image renderFrame(ITimePosition[] sortedTimeArray, int currentTimeIndex, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> featuresWithCharts, ObservationSeriesCollection tupleFinder) { ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH);// w w w . j av a2s .c o m g.setColor(Color.BLACK); ITimePosition currentTimePos = sortedTimeArray[currentTimeIndex]; for (OXFFeature chartFeature : featuresWithCharts) { // // create Plot for each "chart feature" and add it to the cache: // if (!chartCache.contains(currentTimePos, chartFeature)) { // if there is a data tuple for the current time position -> create a new plot if (tupleFinder.getTuple(chartFeature, currentTimePos) != null) { CategoryPlot plot = drawChart4FOI(chartFeature.getID(), currentTimePos.toString(), tupleFinder.getTuple(chartFeature, currentTimePos)); chartCache.add(currentTimePos, chartFeature, plot); } } CategoryPlot plot = (CategoryPlot) chartCache.get(currentTimePos, chartFeature); // if there wasn't a plot for the current time position go backwards through the sortedTimeArray and take the most recent one: int j = currentTimeIndex - 1; while (plot == null && j >= 0) { plot = (CategoryPlot) chartCache.get(sortedTimeArray[j], chartFeature); j--; } // // draw the plots into the image at the georeferenced position of the corresponding chartFeature: // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); // if an appropriate plot was found -> draw it if (plot != null) { for (int i = 0; i < observedProperties.length; i++) { plot.getRangeAxis(i).setRange((Double) tupleFinder.getMinimum(i) - 5, (Double) tupleFinder.getMaximum(i)); if (i > 0) { plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); } } plot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT + 10, pScreen.y + Y_SHIFT, CHART_WIDTH + observedProperties.length * CHART_WIDTH_MULTIPLICATOR, CHART_HEIGHT), null, null, null); } // otherwise draw "no data available" else { g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); } return image; }