List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawThickLine2DPaint(Graphics2D g2d, double x1, double y1, double x2, double y2, int width, Color c, double xObj, double yObj, float alpha) throws Exception { g2d.setPaint(c); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); Line2D line = new Line2D.Double(x1, y1, x2, y2); g2d.draw(line);//www .j a va2s . c om }
From source file:org.openmeetings.app.data.record.BatikMethods.java
public void drawThickLine2D(Graphics2D g2d, double x1, double y1, double x2, double y2, int width, Color c, double xObj, double yObj, float alpha) throws Exception { g2d.setPaint(c); int[] rules = new int[8]; //all possible Compositing Rules: rules[0] = AlphaComposite.SRC_OVER; rules[1] = AlphaComposite.DST_OVER; rules[2] = AlphaComposite.CLEAR; rules[3] = AlphaComposite.SRC; rules[4] = AlphaComposite.SRC_IN; rules[5] = AlphaComposite.DST_IN; rules[6] = AlphaComposite.SRC_OUT; rules[7] = AlphaComposite.DST_OUT; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, alpha)); g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL)); Line2D line = new Line2D.Double(x1 + xObj, y1 + yObj, x2 + xObj, y2 + yObj); g2d.draw(line);/*from www . ja v a 2s . c o m*/ }
From source file:figs.treeVisualization.gui.PhyloDateAxis.java
/** * Draws an axis line at the current cursor position and edge. * /* w w w . j ava 2 s. c om*/ * This always uses RectangleEdge.RIGHT, so the cursor is the x position. * * @param g2 the graphics device. * @param cursor the cursor position. * @param dataArea the data area. * @param edge the edge. * * Original method is in <code>org.jfree.chart.axis.ValueAxis</code> */ protected void drawAxisLine(Graphics2D g2, double cursor, Rectangle2D dataArea) { if (!isAxisLineVisible()) { // originally in drawTickMarksAndLabels return; } Line2D axisLine = new Line2D.Double(cursor, dataArea.getY(), cursor, dataArea.getHeight()); g2.setPaint(getAxisLinePaint()); g2.setStroke(getAxisLineStroke()); g2.draw(axisLine); }
From source file:org.geotools.renderer.chart.GeometryRenderer.java
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo plotInfo, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { GeometryDataset gd = (GeometryDataset) dataset; Geometry g = gd.getGeometries().get(series); g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemStroke(series, item)); if (pass == 0) { drawGeometry(g, g2, series, item, dataArea, plot, domainAxis, rangeAxis); }// www. j ava2 s . com if (pass == 1 && renderCoordinates) { // second pass to render coordinates if (g instanceof Point || g instanceof MultiPoint) { //already rendered in pass 0 return; } for (Coordinate c : g.getCoordinates()) { drawCoordinate(c, g2, series, item, dataArea, plot, domainAxis, rangeAxis); } } }
From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderArea(Graphics2D g2, Rectangle2D dataArea) { CoreStatusEvent statusEv = new CoreStatusEvent(this); g2.setPaint(paint); final double parHStep, parVStep; double parHLower = domainAxis.getRange().getLowerBound(); double parHUpper = domainAxis.getRange().getUpperBound(); double parVLower = rangeAxis.getRange().getLowerBound(); double parVUpper = rangeAxis.getRange().getUpperBound(); parHStep = Math.abs(parHUpper - parHLower) / dataArea.getWidth(); parVStep = Math.abs(parVUpper - parVLower) / dataArea.getHeight(); final BufferedImage image = new BufferedImage((int) dataArea.getWidth(), (int) dataArea.getHeight(), BufferedImage.TYPE_INT_RGB); WritableRaster raster = image.getRaster(); DataBufferInt dataBuffer = (DataBufferInt) raster.getDataBuffer(); int[] data = dataBuffer.getData(); final double parHStart = parHLower + parHStep / 2; final double parVStart = parVUpper - parVStep / 2; for (int i = 0; i < (int) dataArea.getWidth(); i++) { for (int j = 0; j < (int) dataArea.getHeight(); j++) { parameters.put(firstParLabel, parHStart + i * parHStep); parameters.put(secondParLabel, parVStart - j * parVStep); double[] result; int color; try { result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); } catch (ModelException e) { String mess = "Exception while:\n" + dumpVariableDoubles(parameters) + dumpVariableDoubles(initialPoint); throw new ModelException(mess, e); }//from ww w . j a va 2s . c o m if (result == null) { System.out.println("i: " + i + " j: " + j); System.out.println("par1: " + parHStart + i * parHStep); System.out.println("par2: " + parVStart + j * parVStep); g2.drawImage(image, null, (int) dataArea.getX() + 1, (int) dataArea.getY() + 1); statusEv.setStatusString("exception"); statusEv.setType(CoreStatusEvent.STRING); notifyCoreStatusListeners(statusEv); return false; } // both zero if (Math.abs(result[0]) < epsilon && Math.abs(result[1]) < epsilon) { color = Color.black.getRGB(); } // one zero one positive else if (Math.abs(result[0]) < epsilon && result[1] > 0 || Math.abs(result[1]) < epsilon && result[0] > 0) { color = Color.red.getRGB(); } // one zero one negative else if (Math.abs(result[0]) < epsilon && result[1] < 0 || Math.abs(result[1]) < epsilon && result[0] < 0) { color = Color.blue.getRGB(); } // one positive one negative else if (result[0] < 0 && result[1] > 0 || result[1] < 0 && result[0] > 0) { color = Color.green.getRGB(); } // both positive else if (result[0] > 0 && result[1] > 0) { color = Color.orange.getRGB(); } // both negative else if (result[0] < 0 && result[1] < 0) { color = Color.pink.getRGB(); } else { // impossible color = Color.yellow.getRGB(); } data[i + j * (int) dataArea.getWidth()] = color; if (stopped == true) { return false; } if (j == (int) dataArea.getHeight() - 1) { g2.drawImage(image, null, (int) dataArea.getX() + 1, (int) dataArea.getY() + 1); statusEv.setPercent(0); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); } } } return true; }
From source file:TextureWithBufferedImage.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Rectangle2D rec1, rec2, rec3, rec4, rec5; rec1 = new Rectangle2D.Float(25, 25, 75, 150); rec2 = new Rectangle2D.Float(125, 25, 10, 75); rec3 = new Rectangle2D.Float(75, 125, 125, 75); rec4 = new Rectangle2D.Float(25, 15, 12, 75); rec5 = new Rectangle2D.Float(15, 50, 15, 15); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1); g2D.setComposite(ac);/*from ww w . j ava2 s . c o m*/ g2D.setStroke(new BasicStroke(5.0f)); g2D.draw(rec1); GradientPaint gp = new GradientPaint(125f, 25f, Color.yellow, 225f, 100f, Color.blue); g2D.setPaint(gp); g2D.fill(rec2); BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi.createGraphics(); big.setColor(Color.magenta); big.fillRect(0, 0, 5, 5); big.setColor(Color.black); big.drawLine(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); TexturePaint tp = new TexturePaint(bi, r); g2D.setPaint(tp); g2D.fill(rec3); g2D.setColor(Color.green); g2D.fill(rec4); g2D.setColor(Color.red); g2D.fill(rec5); }
From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java
/** Prints the specified labelstring. * The x coordinate specifies the startposition. * The y coordinate specifies the lower startposition of the label. * If alignRight is true, this method subtracts the length of the * labelstring and 3 pixels from the x coordinate. * Otherwise it adds 3 pixels to the x coordinate. *///from w ww .j av a 2s. com private void drawLabel(String s, Graphics2D g2, int _x, int _y, Font f, boolean alignRight) { g2.setPaint(Color.black); g2.setFont(f); int x = 0; if (alignRight) { // subtract the length neede to print the label from the x coordinate x = _x - g2.getFontMetrics().stringWidth(s) - 3; } else { x = _x + 3; } // correct the very first and very last point in the diagram. if (startLabels > x) { startLabels = x; } if (stopLabels < x + g2.getFontMetrics().stringWidth(s)) { stopLabels = x + g2.getFontMetrics().stringWidth(s); } g2.drawString(s, x, _y); }
From source file:org.kuali.mobility.people.service.PeopleServiceImpl.java
@Override public BufferedImage generateObfuscatedImage(String text) { int width = 250; int height = 25; BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = bufferedImage.createGraphics(); Font font = new Font("Arial", Font.PLAIN, 14); g2d.setFont(font);//from ww w. j a v a 2 s . co m RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHints(rh); Paint bg = new Color(255, 255, 255); g2d.setPaint(bg); g2d.fillRect(0, 0, width, height); int x = 0; int y = height - 7; Paint textPaint = new Color(0, 0, 0); g2d.setPaint(textPaint); g2d.drawString(text, x, y); g2d.dispose(); return bufferedImage; }
From source file:com.rapidminer.gui.plotter.charts.RapidXYBarPainter.java
@Override public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar, RectangleEdge base) {/*w w w .j ava 2 s.c o m*/ Paint itemPaint = renderer.getItemPaint(row, column); Color c0 = null; if (itemPaint instanceof Color) { c0 = (Color) itemPaint; } else { c0 = SwingTools.DARK_BLUE; } // as a special case, if the bar color has alpha == 0, we draw // nothing. if (c0.getAlpha() == 0) { return; } g2.setPaint(c0); g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight())); // draw the outline... if (renderer.isDrawBarOutline()) { Stroke stroke = renderer.getItemOutlineStroke(row, column); Paint paint = renderer.getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } }
From source file:ColorBlocks.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();//from www .j a v a 2 s . c o m g2.translate(d.width / 2, d.height / 2); Color[] colors = { Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black, Color.red, Color.pink, Color.orange, Color.yellow, Color.green, Color.magenta, Color.cyan, Color.blue }; float size = 25; float x = -size * colors.length / 2; float y = -size * 3 / 2; // Show all the predefined colors. for (int i = 0; i < colors.length; i++) { Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size); g2.setPaint(colors[i]); g2.fill(r); } //a linear gradient. y += size; Color c1 = Color.yellow; Color c2 = Color.blue; for (int i = 0; i < colors.length; i++) { float ratio = (float) i / (float) colors.length; int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio)); int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio)); int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio)); Color c = new Color(red, green, blue); Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size); g2.setPaint(c); g2.fill(r); } // Show an alpha gradient. y += size; c1 = Color.red; for (int i = 0; i < colors.length; i++) { int alpha = (int) (255 * (float) i / (float) colors.length); Color c = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), alpha); Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size); g2.setPaint(c); g2.fill(r); } // Draw a frame around the whole thing. y -= size * 2; Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length, size * 3); g2.setPaint(Color.black); g2.draw(frame); }