List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:net.java.sip.communicator.impl.osdependent.jdic.SystrayServiceJdicImpl.java
private BufferedImage createOverlayImage(String text) { int size = 16; BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); //background// w ww .jav a2s.c o m g.setPaint(new Color(0, 0, 0, 102)); g.fillRoundRect(0, 0, size, size, size, size); //filling int mainRadius = 14; g.setPaint(new Color(255, 98, 89)); g.fillRoundRect(size / 2 - mainRadius / 2, size / 2 - mainRadius / 2, mainRadius, mainRadius, size, size); //text Font font = g.getFont(); g.setFont(new Font(font.getName(), Font.BOLD, 9)); FontMetrics fontMetrics = g.getFontMetrics(); int textWidth = fontMetrics.stringWidth(text); g.setColor(Color.white); g.drawString(text, size / 2 - textWidth / 2, size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent()); return image; }
From source file:com.aurel.track.report.gantt.data.TrackGanttRenderer.java
/** Prints the specified labelstring. If neccessary it reduces the * font size that the label fits in the specified space. * 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 www .j a v a2 s. c o m*/ private void drawLabel(String s, Graphics2D g2, int _x, int _y, Font f, boolean alignRight, int space) { 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 { while (g2.getFontMetrics().stringWidth(s) > space - 4) { log.debug("Reducing Font size for label " + s); f = new Font(f.getName(), f.getStyle(), f.getSize() - 1); g2.setFont(f); } x = _x + 2; } g2.drawString(s, x, _y); }
From source file:net.sourceforge.processdash.ui.lib.chart.StandardDiscItemRenderer.java
protected void drawOutline(Graphics2D g2, Ellipse2D shape, Comparable key) { Paint outlinePaint = lookupOutlinePaint(key); Stroke outlineStroke = lookupOutlineStroke(key); if (outlinePaint != null && outlineStroke != null) { g2.setPaint(outlinePaint); g2.draw(shape);/*from w ww .ja v a 2s . c om*/ } }
From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java
private void drawSeriesLines(Graphics2D g2, Collection<Line2D> lines, int series, int item) { g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemStroke(series, item)); for (Line2D line : lines) { g2.draw(line);// w ww . j a v a 2 s .co m } }
From source file:HighlightedButton.java
/** * Creates a new instance of HighlightedButton *//*www .j a v a 2 s . c o m*/ public HighlightedButton(String label) { super(label); // Get the Graphics for the image Graphics2D g2d = highlight.createGraphics(); // Erase the image with a transparent background g2d.setComposite(AlphaComposite.Clear); g2d.fillRect(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE); g2d.setComposite(AlphaComposite.SrcOver); // Draw the highlight Point2D center = new Point2D.Float((float) HIGHLIGHT_SIZE / 2.0f, (float) HIGHLIGHT_SIZE / 2.0f); float radius = (float) HIGHLIGHT_SIZE / 2.0f; float[] dist = { 0.0f, .85f }; Color[] colors = { Color.white, new Color(255, 255, 255, 0) }; RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors); g2d.setPaint(paint); g2d.fillOval(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE); g2d.dispose(); }
From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java
private void drawDomainGridline(Graphics2D g2, CategoryPlot plot, Rectangle2D dataArea, double value) { Line2D line = null;/* w ww .j a va 2 s. c om*/ PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { line = new Line2D.Double(dataArea.getMinX(), value, dataArea.getMaxX(), value); } else if (orientation == PlotOrientation.VERTICAL) { line = new Line2D.Double(value, dataArea.getMinY(), value, dataArea.getMaxY()); } g2.setPaint(domainGridlinePaint); Stroke stroke = plot.getDomainGridlineStroke(); if (stroke == null) { stroke = CategoryPlot.DEFAULT_GRIDLINE_STROKE; } g2.setStroke(stroke); g2.draw(line); }
From source file:org.objectweb.proactive.extensions.timitspmd.util.charts.MatrixChart.java
private void buildFinalChart(String title, String subTitle, String filename, String xAxisLabel, String yAxisLabel, int width, int height) { this.buildMainChart(title, subTitle, xAxisLabel, yAxisLabel, filename); this.buildLegendChart(5); BufferedImage mainChartImage = this.mainChart.createBufferedImage(width, height); BufferedImage legendChartImage = this.legendChart.createBufferedImage(width / 6, height / 3); BufferedImage info = null;/*from w ww . ja v a 2 s .co m*/ try { info = ImageIO.read(MatrixChart.logoFile); } catch (IOException ex) { } BufferedImage total = new BufferedImage(width + (width / 6), height, BufferedImage.TYPE_INT_RGB); Graphics2D g = total.createGraphics(); g.drawImage(mainChartImage, 0, 0, null); g.drawImage(legendChartImage, width, height / 4, null); g.setPaint(Color.WHITE); g.fillRect(width, 0, width, height / 4); g.fillRect(width, (height / 4) + (height / 3), width, height); if (info != null) { // g.drawImage(info, (width+(width/6))-info.getWidth(),10, null); // // up-right g.drawImage(info, (width + (width / 6)) - info.getWidth(), height - info.getHeight(), null); // down-right } g.dispose(); try { javax.imageio.ImageIO.write(total, "png", XMLHelper.createFileWithDirs(filename)); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.jfree.experimental.chart.plot.dial.SimpleDialFrame.java
/** * Draws the frame. This method is called by the {@link DialPlot} class, * you shouldn't need to call it directly. * * @param g2 the graphics target (<code>null</code> not permitted). * @param plot the plot (<code>null</code> not permitted). * @param frame the frame (<code>null</code> not permitted). * @param view the view (<code>null</code> not permitted). *//* w w w . j av a 2s . com*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Shape window = getWindow(frame); Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, this.radius + 0.02); Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight()); Area area = new Area(e); Area area2 = new Area(window); area.subtract(area2); g2.setPaint(this.backgroundPaint); g2.fill(area); g2.setStroke(this.stroke); g2.setPaint(this.foregroundPaint); g2.draw(window); g2.draw(e); }
From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java
/** * Paints a single bar instance./*from w w w. j a v a 2s. 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. */ @Override public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column, final RectangularShape bar, final RectangleEdge base) { 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:org.jfree.demo.TextBlockPanel.java
/** * Paints the panel.//from ww w. ja va2 s. c o m * * @param g the graphics device. */ public void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; final Dimension size = getSize(); final Insets insets = getInsets(); final Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top, size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom); final double x = available.getX(); final double y = available.getY(); final float width = (float) available.getWidth(); final TextBlock block = TextUtilities.createTextBlock(this.text, this.font, Color.black, width, new G2TextMeasurer(g2)); g2.setPaint(Color.black); block.draw(g2, (float) x, (float) y, TextBlockAnchor.TOP_LEFT, 0.0f, 0.0f, 0.0); }