List of usage examples for java.awt Graphics2D setColor
public abstract void setColor(Color c);
From source file:org.pentaho.plugin.jfreereport.reportcharts.JFreeChartReportDrawable.java
public void draw(final Graphics2D graphics2D, final Rectangle2D bounds) { this.bounds = (Rectangle2D) bounds.clone(); if (chartRenderingInfo != null) { this.chartRenderingInfo.clear(); }//w w w . ja v a 2 s . c o m final Graphics2D g2 = (Graphics2D) graphics2D.create(); this.chart.draw(g2, bounds, chartRenderingInfo); g2.dispose(); if (chartRenderingInfo == null || debugRendering == false) { return; } graphics2D.setColor(Color.RED); final Rectangle2D dataArea = getDataAreaOffset(); final EntityCollection entityCollection = chartRenderingInfo.getEntityCollection(); for (int i = 0; i < entityCollection.getEntityCount(); i++) { final ChartEntity chartEntity = entityCollection.getEntity(i); if (chartEntity instanceof XYItemEntity || chartEntity instanceof CategoryItemEntity || chartEntity instanceof PieSectionEntity) { final Area a = new Area(chartEntity.getArea()); if (buggyDrawArea) { a.transform(AffineTransform.getTranslateInstance(dataArea.getX(), dataArea.getY())); } a.intersect(new Area(dataArea)); graphics2D.draw(a); } else { graphics2D.draw(chartEntity.getArea()); } } }
From source file:ImageOps.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Create a BufferedImage big enough to hold the Image loaded // in the constructor. Then copy that image into the new // BufferedImage object so that we can process it. BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_RGB); Graphics2D ig = bimage.createGraphics(); ig.drawImage(image, 0, 0, this); // copy the image // Set some default graphics attributes g.setFont(new Font("SansSerif", Font.BOLD, 12)); // 12pt bold text g.setColor(Color.green); // Draw in green g.translate(10, 10); // Set some margins // Loop through the filters for (int i = 0; i < filters.length; i++) { // If the filter is null, draw the original image, otherwise, // draw the image as processed by the filter if (filters[i] == null) g.drawImage(bimage, 0, 0, this); else/*from w w w.j av a2 s . com*/ g.drawImage(filters[i].filter(bimage, null), 0, 0, this); g.drawString(filterNames[i], 0, 205); // Label the image g.translate(137, 0); // Move over if (i % 4 == 3) g.translate(-137 * 4, 215); // Move down after 4 } }
From source file:org.tsho.dmc2.core.chart.ManifoldsRenderer.java
public void render(final Graphics2D g2, final Rectangle2D dataArea, final PlotRenderingInfo info) { byte myType = type; if ((myType & TYPE_UNSTABLE) != 0) { g2.setColor(Color.RED); if ((myType & TYPE_RIGHT) != 0) { renderManifold(false, true, g2, dataArea); if (state == STATE_STOPPED) { myType = 0;/*from ww w . java 2 s.c o m*/ } } if ((myType & TYPE_LEFT) != 0) { renderManifold(false, false, g2, dataArea); if (state == STATE_STOPPED) { myType = 0; } } } if ((myType & TYPE_STABLE) != 0) { g2.setColor(Color.BLUE); if ((myType & TYPE_RIGHT) != 0) { renderManifold(true, true, g2, dataArea); if (state == STATE_STOPPED) { myType = 0; } } if ((myType & TYPE_LEFT) != 0) { renderManifold(true, false, g2, dataArea); if (state == STATE_STOPPED) { myType = 0; } } } g2.setColor(Color.BLACK); plot(g2, dataArea, node, true); if (state != STATE_STOPPED) { state = STATE_FINISHED; } else { state = STATE_STOPPED; } }
From source file:com.joliciel.jochre.search.highlight.ImageSnippet.java
public BufferedImage getImage() { try {//from w ww. j av a 2 s. c o m BufferedImage originalImage = ImageIO.read(imageFile); BufferedImage imageSnippet = new BufferedImage(this.rectangle.getWidth(), this.rectangle.getHeight(), BufferedImage.TYPE_INT_ARGB); originalImage = originalImage.getSubimage(this.rectangle.getLeft(), this.rectangle.getTop(), this.rectangle.getWidth(), this.rectangle.getHeight()); Graphics2D graphics2D = imageSnippet.createGraphics(); graphics2D.drawImage(originalImage, 0, 0, this.rectangle.getWidth(), this.rectangle.getHeight(), null); int extra = 2; for (Rectangle rect : this.highlights) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setPaint(Color.BLACK); graphics2D.drawRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); graphics2D.setColor(new Color(255, 255, 0, 127)); graphics2D.fillRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); } return imageSnippet; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:net.team2xh.crt.gui.editor.EditorTextPane.java
/** * Paints the background, the margin background and the margin line. * * @param g/*from w w w.j a v a2 s.c o m*/ */ @Override public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; int m = marginSize; int w = getWidth(), h = getHeight(); // Background g2d.setPaint(Theme.getTheme().COLOR_02); g2d.fillRect(0, 0, m, h); // Margin background if (m < w) { g2d.setColor(Theme.getTheme().COLOR_01); g2d.fillRect(m, 0, w - m, h); } // Margin line g2d.setColor(Theme.getTheme().COLOR_04); g2d.drawLine(m, 0, m, h); // Draw the rest super.paintComponent(g); }
From source file:components.SizeDisplayer.java
protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(); //copy g Dimension minSize = getMinimumSize(); Dimension prefSize = getPreferredSize(); Dimension size = getSize();// w ww .ja v a 2 s. c om int prefX = 0, prefY = 0; //Set hints so text looks nice. g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); //Draw the maximum size rectangle if we're opaque. if (isOpaque()) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, size.width, size.height); } //Draw the icon. if (icon != null) { Composite oldComposite = g2d.getComposite(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f)); icon.paintIcon(this, g2d, (size.width - icon.getIconWidth()) / 2, (size.height - icon.getIconHeight()) / 2); g2d.setComposite(oldComposite); } //Draw the preferred size rectangle. prefX = (size.width - prefSize.width) / 2; prefY = (size.height - prefSize.height) / 2; g2d.setColor(Color.RED); g2d.drawRect(prefX, prefY, prefSize.width - 1, prefSize.height - 1); //Draw the minimum size rectangle. if (minSize.width != prefSize.width || minSize.height != prefSize.height) { int minX = (size.width - minSize.width) / 2; int minY = (size.height - minSize.height) / 2; g2d.setColor(Color.CYAN); g2d.drawRect(minX, minY, minSize.width - 1, minSize.height - 1); } //Draw the text. if (text != null) { Dimension textSize = getTextSize(g2d); g2d.setColor(getForeground()); g2d.drawString(text, (size.width - textSize.width) / 2, (size.height - textSize.height) / 2 + g2d.getFontMetrics().getAscent()); } g2d.dispose(); }
From source file:edworld.pdfreader4humans.PDFReader.java
private void draw(Component component, Graphics2D graphics, Color inkColor, Color backgroundColor, boolean showStructure, Map<String, Font> fonts) { for (Component child : component.getChildren()) draw(child, graphics, inkColor, backgroundColor, showStructure, fonts); if (component instanceof BoxComponent && showStructure) { graphics.setColor(boxColor(backgroundColor)); graphics.drawRect((int) component.getFromX(), (int) component.getFromY(), (int) component.getWidth(), (int) component.getHeight()); graphics.setColor(inkColor);/* w ww . j a v a 2 s . c o m*/ } else if (component instanceof GroupComponent && showStructure) { graphics.setColor(groupColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component instanceof MarginComponent && showStructure) { graphics.setColor(marginColor(backgroundColor)); graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); graphics.setColor(inkColor); } else if (component.getType().equals("line")) graphics.drawLine(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getToX()), Math.round(component.getToY())); else if (component.getType().equals("rect")) graphics.drawRect(Math.round(component.getFromX()), Math.round(component.getFromY()), Math.round(component.getWidth()), Math.round(component.getHeight())); else if (component instanceof TextComponent) { graphics.setFont(font((TextComponent) component, fonts)); graphics.drawString(((TextComponent) component).getText(), component.getFromX(), component.getToY()); } }
From source file:com.quinsoft.zeidon.objectbrowser.EntitySquare.java
private void paintCenteredText(Graphics2D graphics2, int y, String text, Color color) { Color prevColor = graphics2.getColor(); if (color != null) graphics2.setColor(color); FontMetrics fm = graphics2.getFontMetrics(); String lines[] = text.split("\n"); // Adjust y if there is more than one line. y -= (lines.length - 1) * fm.getHeight() / 2; for (String line : lines) { int lth = fm.stringWidth(line); int mid = size.width / 2; graphics2.drawString(line, mid - lth / 2, y); y += fm.getHeight();//from www .j ava2 s .c o m } if (color != null) graphics2.setColor(prevColor); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.ProfilesComparisonReportChartCanvas.java
protected void paintComponent(Graphics g) { // prepare graphic object Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // set clipping area if (is_printing) { g2d.translate(-draw_area.x, -draw_area.y); g2d.setClip(draw_area);//from w w w . j a v a 2 s. c om } //paint canvas background if (!is_printing) { g2d.setColor(getBackground()); g2d.fillRect(0, 0, getWidth(), getHeight()); } // paint white background on drawing area g2d.setColor(Color.white); g2d.fillRect(draw_area.x, draw_area.y, draw_area.width, draw_area.height); if (!is_printing) { g2d.setColor(Color.black); g2d.draw(draw_area); } // paint paintChart(g2d); // dispose graphic object g2d.dispose(); revalidate(); }
From source file:com.neophob.sematrix.generator.Textwriter.java
/** * create image./* www.j a v a 2s .c om*/ * * @param text the text */ public void createTextImage(String text) { //only load if needed if (StringUtils.equals(text, this.text)) { return; } this.text = text; BufferedImage img = new BufferedImage(TEXT_BUFFER_X_SIZE, internalBufferYSize, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = img.createGraphics(); FontRenderContext frc = g2.getFontRenderContext(); TextLayout layout = new TextLayout(text, font, frc); Rectangle2D rect = layout.getBounds(); int h = (int) (0.5f + rect.getHeight()); maxXPos = (int) (0.5f + rect.getWidth()) + 5; ypos = internalBufferYSize - (internalBufferYSize - h) / 2; img = new BufferedImage(maxXPos, internalBufferYSize, BufferedImage.TYPE_INT_RGB); g2 = img.createGraphics(); g2.setColor(color); g2.setFont(font); g2.setClip(0, 0, maxXPos, internalBufferYSize); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.drawString(text, xpos, ypos); DataBufferInt dbi = (DataBufferInt) img.getRaster().getDataBuffer(); textBuffer = dbi.getData(); g2.dispose(); wait = 0; xofs = 0; scrollRight = false; }