private void paintToImage( final BufferedImage img, final int x, final int y, final int width, final int height) { // clear the prior image Graphics2D imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.Clear); imgG.setColor(Color.black); imgG.fillRect(0, 0, width + blur * 2, height + blur * 2); final int adjX = (int) (x + blur + offsetX + (insets.left * distance)); final int adjY = (int) (y + blur + offsetY + (insets.top * distance)); final int adjW = (int) (width - (insets.left + insets.right) * distance); final int adjH = (int) (height - (insets.top + insets.bottom) * distance); // let the delegate paint whatever they want to be blurred imgG.setComposite(AlphaComposite.DstAtop); if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); // blur the prior image back into the same pixels imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.DstAtop); imgG.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); imgG.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); imgG.drawImage(img, blurOp, 0, 0); if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); }
/** * Creates an BufferedImage of the passed slide. * * @param tmpslide slide to copied to a BufferedImage. * @param dimension Dimension, the dimension of the slide * @param tmpimgWidth int, width which the slide will be scaled to. * @param tmpImgHeight int, height which the slide will be scaled to. * @return BufferedImage, the image scaled image copy of the slide. */ private BufferedImage slideToImage(Slide tmpslide, Dimension dimension) { BufferedImage img = new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_RGB); // create the graphic "painter" Graphics2D graphics = img.createGraphics(); graphics.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); graphics.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setPaint(Color.white); // creates a square graphics.fill(new Rectangle2D.Float(0, 0, dimension.width, dimension.height)); // render image in the square tmpslide.draw(graphics); return img; }
@Override public void paint(Graphics g) { super.paint(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int v = value; boolean is_ng = false; if (v > 999) v = 999; if (v < 0) { v *= -1; is_ng = true; if (v > 99) v = 99; } for (int i = 2, p = 1; i >= 0; i--, v /= 10) { BufferedImage r = GameResource.sevenSegmentDigits[v % 10]; g2.drawImage(r, i * 15 + 5, 5, 15, 30, this); } if (is_ng) { BufferedImage r = GameResource.sevenSegmentDigits[10]; g2.drawImage(r, 0 * 15 + 5, 5, 15, 30, this); } }
public void paint(Graphics g) { Graphics2D gc = (Graphics2D) g; // for antialiasing text gc.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); gc.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gc.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); Dimension d = getSize(); // System.out.println(d.width + "x" + d.height); // System.out.println(d.width + "," + d.height); int w = d.width - 1; int h = d.height - 1; float brightness = (float) Settings.brightness.getDouble(); gc.setColor(Color.black); gc.fillRect(0, 0, getWidth(), getHeight()); gc.setColor(new Color(brightness, brightness, brightness)); if (mouseInside) gc.drawRoundRect(0, 0, w, h, 8, 8); else gc.drawRect(0, 0, w, h); FontMetrics fm = gc.getFontMetrics(); Rectangle2D sb = fm.getStringBounds(text, gc); double x = (d.width - sb.getWidth()) / 2; double y = (d.height + sb.getHeight()) / 2 - fm.getDescent(); gc.drawString(text, (int) Math.round(x), (int) Math.round(y)); }
BufferedImage drawText(boolean doGV) { int w = 400; int h = 50; BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setColor(Color.white); g.fillRect(0, 0, w, h); g.setColor(Color.black); Font f = helvFont.deriveFont(Font.PLAIN, 40); g.setFont(f); int x = 5; int y = h - 10; if (doGV) { FontRenderContext frc = new FontRenderContext(null, true, true); GlyphVector gv = f.createGlyphVector(frc, codes); g.drawGlyphVector(gv, 5, y); } else { g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); g.drawString(str, x, y); } return bi; }
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { final Graphics2D g2d = (Graphics2D) g; final Insets ins = getBorderInsets(c); final int yOff = (ins.top + ins.bottom) / 4; final boolean square = DarculaButtonUI.isSquare(c); int offset = JBUI.scale(square ? 1 : getOffset()); if (c.hasFocus()) { DarculaUIUtil.paintFocusRing(g2d, offset, yOff, width - 2 * offset, height - 2 * yOff); } else { final GraphicsConfig config = new GraphicsConfig(g); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT); g2d.setPaint( UIUtil.getGradientPaint( width / 2, y + yOff + 1, Gray._80.withAlpha(90), width / 2, height - 2 * yOff, Gray._90.withAlpha(90))); // g.drawRoundRect(x + offset + 1, y + yOff + 1, width - 2 * offset, height - 2*yOff, 5, 5); ((Graphics2D) g).setPaint(Gray._100.withAlpha(180)); g.drawRoundRect( x + offset, y + yOff, width - 2 * offset, height - 2 * yOff, JBUI.scale(square ? 3 : 5), JBUI.scale(square ? 3 : 5)); config.restore(); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); int width = getWidth(); int height = getHeight(); // rendering hints g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // formatter DecimalFormat format = new DecimalFormat("##.#%"); // text to display String percentage = (value == null || Double.parseDouble(value.toString()) == -1) ? "" : format.format(Double.parseDouble(value.toString())); // paint text g2.setColor(Color.black); g2.setFont(g2.getFont().deriveFont(Font.BOLD)); FontMetrics fontMetrics = g2.getFontMetrics(); int textWidth = fontMetrics.stringWidth(percentage); int xPos = (width - textWidth) / 2; int yPos = height / 2 + fontMetrics.getDescent() + 2; g2.drawString(percentage, xPos, yPos); g2.dispose(); }
/** Creates and initializes a splash screen based on image shown by vm while starting. */ private void createSplashscreen() { // Create splash screen only when not yet happened. if (splash != null) { splashGraphics = splash.createGraphics(); if (splashGraphics != null) { final Color splashscreenColor = new Color(85, 85, 85); final int versionX = 38; final int versionY = 126; final float versionFontSize = 18; final String versionString = RunUI.class.getPackage().getSpecificationVersion(); splashGraphics.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); splashGraphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); splashGraphics.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); splashGraphics.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); splashGraphics.setColor(splashscreenColor); splashGraphics.setFont(FontFactory.createSplashscreenFont().deriveFont(versionFontSize)); splashGraphics.setPaintMode(); splashGraphics.drawString("Version " + versionString, versionX, versionY); splash.update(); splashGraphics.setFont(FontFactory.createSplashscreenFont()); } } }
/** * Updates a Graphics according to this context * * @param g Graphics to be updated */ public void updateGraphics(Graphics2D g) { g.setFont(font); g.setColor(color); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); }
public @Override void paint(Graphics g) { if (!indicatorLabel.getFont().equals(chartFrame.getChartProperties().getFont())) indicatorLabel.setFont(chartFrame.getChartProperties().getFont()); if (!indicatorLabel.getForeground().equals(chartFrame.getChartProperties().getFontColor())) indicatorLabel.setForeground(chartFrame.getChartProperties().getFontColor()); if (!indicatorLabel.getText().equals(indicator.getLabel())) indicatorLabel.setText(indicator.getLabel()); Rectangle oldClip = g.getClipBounds(); Rectangle newClip = getBounds(); g.setClip(newClip); Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g2.setPaintMode(); if (mouseOver) { g2.setColor(backColor); RoundRectangle2D roundRectangle = new RoundRectangle2D.Double(getX(), getY(), getWidth(), getHeight(), 10, 10); g2.fill(roundRectangle); } super.paint(g); g2.dispose(); g.setClip(oldClip); }
public static void setupAntialiasing(final Graphics g) { if (DEFAULT_ALIASING) return; Graphics2D g2d = (Graphics2D) g; UISettings uiSettings = getInstance(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); if (uiSettings == null || uiSettings.ANTIALIASING_IN_EDITOR) { Toolkit tk = Toolkit.getDefaultToolkit(); //noinspection HardCodedStringLiteral Map map = (Map) tk.getDesktopProperty("awt.font.desktophints"); if (map != null) { if (isRemoteDesktopConnected()) { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); } else { g2d.addRenderingHints(map); } } else { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } } else { g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } }
public void paintComponent(Graphics g) { Color controle = UIManager.getColor("control"); int width = getWidth() - 6; int height = getHeight() - 6; Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, width, height, 12, 12); drawShadow(g2, rect); Paint pinceau = g2.getPaint(); if (!mouseOver) { g2.setPaint(new GradientPaint(this.icon.getIconWidth(), 0, Color.white, width, 0, controle)); } else { g2.setColor(Color.white); } g2.translate(2, 2); if (mousePressed) { g2.translate(1, 1); } g2.fill(rect); g2.setPaint(pinceau); g2.translate(-2, -2); }
// <editor-fold defaultstate="collapsed" desc="Visualization"> @Override protected void paintComponent(Graphics g) { final Graphics2D G2 = (Graphics2D) g.create(); G2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); G2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); G2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); G2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // Translate the coordinate system related to insets G2.translate(getFramelessOffset().getX(), getFramelessOffset().getY()); // Draw combined background image G2.drawImage(bImage, 0, 0, null); // Draw the symbol image if (on) { G2.drawImage(symbolOnImage, 0, 0, null); } else { G2.drawImage(symbolOffImage, 0, 0, null); } // Draw combined foreground image G2.drawImage(fImage, 0, 0, null); if (!isEnabled()) { G2.drawImage(disabledImage, 0, 0, null); } // Translate the coordinate system back to original G2.translate(-getInnerBounds().x, -getInnerBounds().y); G2.dispose(); }
public static void antialias(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); }
/** * Creates buffered image from path of width. * * @param path * @param width * @return * @throws IOException */ private BufferedImage getScaledBufferedImage(String path, int width) { BufferedImage bi; Image tmp = null; try { // loads image from path and scales it to desired size tmp = getScaledImage(path, width); } catch (IOException ex) { // should never happen, all hwComponentType default icons are in .jar as a resource } // create new buffered image to paint on bi = new BufferedImage(tmp.getWidth(null), tmp.getHeight(null), BufferedImage.TYPE_INT_ARGB); // create graphics and set hints Graphics2D graphics2D = bi.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // draw image graphics2D.drawImage(tmp, 0, 0, null); graphics2D.dispose(); return bi; }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Add antialiasing to smooth the lines of the cube g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2.translate(getWidth() / 2, getHeight() / 2); // Center the frame // g2.fillOval(-2, -2, 4, 4); //Draw the (0, 0) for reference for (int i = 0; i < adjacency.getNbRows(); i++) { for (int j = 0; j < adjacency.getNbColumns(); j++) { if (adjacency.getEntry(i, j) == 1) { /*if(calcPoints[i].getEntry(3, 1) > 0.05 || calcPoints[j].getEntry(3, 1) > 0.05) g2.setColor(Color.RED); else*/ g2.setColor(Color.BLACK); g2.drawLine( (int) (calcPoints[i].getEntry(0, 0) * FACTOR), (int) (calcPoints[i].getEntry(1, 0) * FACTOR), (int) (calcPoints[j].getEntry(0, 0) * FACTOR), (int) (calcPoints[j].getEntry(1, 0) * FACTOR)); } } } }
@Override public BufferedImage makeIcon( final int width, final int height, final Path2D iconShape, final boolean allowAlpha) { final BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final Graphics2D g = result.createGraphics(); g.setStroke(new BasicStroke(0.05f)); final Color c; if (allowAlpha) { c = new Color( this.color.getRed(), this.color.getGreen(), this.color.getBlue(), this.color.getAlpha()); } else { c = new Color(this.color.getRGB()); } if (iconShape != null) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); g.setColor(c); final Shape path = makeTransformedPathForSize(width, height, iconShape); g.fill(path); } else { g.setColor(c); g.fillRect(0, 0, width, height); } g.dispose(); return result; }
@Override public void paint(Graphics2D graphics, Dimension dimensions) { final Color SHADOW_COLOR = new Color(0.0f, 0.0f, 0.0f, 0.65f); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE); // graphics.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, // RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); // graphics.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, // RenderingHints.VALUE_COLOR_RENDER_QUALITY); graphics.setRenderingHint( RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); // graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_ON); final int imageWidth = (int) dimensions.getWidth(); final int imageHeight = (int) dimensions.getHeight(); final GeneralPath pointerShape; pointerShape = new GeneralPath(); pointerShape.setWindingRule(Path2D.WIND_EVEN_ODD); pointerShape.moveTo(0.5 * imageWidth, 0.16822429906542055 * imageHeight); pointerShape.lineTo(0.48598130841121495 * imageWidth, 0.5 * imageHeight); pointerShape.lineTo(0.5 * imageWidth, 0.5046728971962616 * imageHeight); pointerShape.lineTo(0.5093457943925234 * imageWidth, 0.5 * imageHeight); pointerShape.lineTo(0.5 * imageWidth, 0.16822429906542055 * imageHeight); pointerShape.closePath(); graphics.setColor(SHADOW_COLOR); graphics.fill(pointerShape); graphics.dispose(); }
public BufferedImage generateImageFromDna( List<Gene> dna, GAParameters parameters, double multiplier) { // long timestamp = System.currentTimeMillis(); BufferedImage image = new BufferedImage( (int) (parameters.getTargetImage().getWidth() * multiplier), (int) (parameters.getTargetImage().getHeight() * multiplier), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED); drawBlackBackground(graphics, parameters, multiplier); for (Gene gene : dna) { int[] x = new int[gene.getPoints().size()]; int[] y = new int[gene.getPoints().size()]; for (int i = 0; i < gene.getPoints().size(); i++) { x[i] = (int) (gene.getPoints().get(i).getX() * multiplier); y[i] = (int) (gene.getPoints().get(i).getY() * multiplier); } Polygon p = new Polygon(x, y, gene.getPoints().size()); graphics.setColor(gene.getColor()); graphics.fillPolygon(p); } // System.out.println("rendering took : " + (System.currentTimeMillis() - timestamp)); return image; }
public int getBitmapFontRAMUsage() { BufferedImage image = new BufferedImage(50, 50, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) image.getGraphics(); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g2d.setRenderingHint( RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, bitmapAntialiasing); g2d.setFont(java.awt.Font.decode(lookupFont)); FontMetrics metrics = g2d.getFontMetrics(); FontRenderContext context = g2d.getFontRenderContext(); int baseline = (int) Math.ceil(metrics.getMaxAscent()); int[] offsets = new int[bitmapCharset.length()]; int[] widths = new int[offsets.length]; int currentOffset = 0; for (int iter = 0; iter < bitmapCharset.length(); iter++) { offsets[iter] = currentOffset; String currentChar = bitmapCharset.substring(iter, iter + 1); g2d.drawString(currentChar, currentOffset, baseline); Rectangle2D rect = g2d.getFont().getStringBounds(currentChar, context); widths[iter] = (int) Math.ceil(rect.getWidth()); // max advance works but it makes a HUGE image in terms of width which // occupies more ram if (g2d.getFont().isItalic()) { currentOffset += metrics.getMaxAdvance(); } else { currentOffset += widths[iter] + 1; } } g2d.dispose(); return currentOffset * getHeight() * 4; }
public static void drawStringUnderlineCharAt( JComponent c, Graphics g, String text, int underlinedIndex, int x, int y) { Graphics2D g2D = (Graphics2D) g; Object savedRenderingHint = null; if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, AbstractLookAndFeel.getTheme().getTextAntiAliasingHint()); } if (getJavaVersion() >= 1.6) { try { Class swingUtilities2Class = Class.forName("sun.swing.SwingUtilities2"); Class classParams[] = { JComponent.class, Graphics.class, String.class, Integer.TYPE, Integer.TYPE, Integer.TYPE }; Method m = swingUtilities2Class.getMethod("drawStringUnderlineCharAt", classParams); Object methodParams[] = { c, g, text, new Integer(underlinedIndex), new Integer(x), new Integer(y) }; m.invoke(null, methodParams); } catch (Exception ex) { BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y); } } else if (getJavaVersion() >= 1.4) { BasicGraphicsUtils.drawStringUnderlineCharAt(g, text, underlinedIndex, x, y); } else { BasicGraphicsUtils.drawString(g, text, underlinedIndex, x, y); } if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } }
@Override public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); super.paintComponent(g2); }
@Override public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D) g; AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); initShape(b); // ContentArea g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (model.isArmed()) { g2.setColor(ac); g2.fill(shape); } else if (b.isRolloverEnabled() && model.isRollover()) { paintFocusAndRollover(g2, c, rc); } else if (b.hasFocus()) { paintFocusAndRollover(g2, c, fc); } else { g2.setColor(c.getBackground()); g2.fill(shape); } // Border g2.setPaint(c.getForeground()); g2.draw(shape); g2.setColor(c.getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); super.paint(g2, c); }
public static void drawLabel( Graphics2D g2, FontMetrics f, Pixel highest, String label, Color edgeColor, Color bgColor, Color textColor) { int lineHeight = 20; int padding = 3; Rectangle2D r = f.getStringBounds(label, g2); int halfStringWidth = (int) (r.getWidth() / 2); int halfStringHeight = (int) (r.getHeight() / 2); int stringWidth = halfStringWidth * 2; int stringHeight = halfStringHeight * 2; g2.setColor(bgColor); g2.fillRect( highest.x - halfStringWidth - padding, highest.y - lineHeight - stringHeight - padding - padding, stringWidth + padding + padding, stringHeight + padding + padding); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(textColor); g2.drawString(label, highest.x - halfStringWidth, highest.y - lineHeight - halfStringHeight); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2.setColor(edgeColor); g2.drawRect( highest.x - halfStringWidth - padding, highest.y - lineHeight - stringHeight - padding - padding, stringWidth + padding + padding, stringHeight + padding + padding); g2.drawLine(highest.x, highest.y, highest.x, highest.y - lineHeight); }
/** * Renders the given range in the model as normal unselected text. This is implemented to paint * colors based upon the token-to-color translations. * * @param g the graphics context * @param x the starting X coordinate * @param y the starting Y coordinate * @param start the beginning position in the model * @param end the ending position in the model * @returns the location of the end of the range * @exception BadLocationException if the range is invalid */ @Override protected int drawUnselectedText(Graphics g, int x, int y, int start, int end) throws BadLocationException { DocumentImpl doc = (DocumentImpl) getDocument(); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); int mark = start; Segment text = new Segment(); for (Token token : doc.getTokensInRange(start, end)) { int endPosition = Math.min(token.getEndOffset(), end); token.accept(gd.setGraphics(g2)); doc.getText(mark, endPosition - mark, text); x = Utilities.drawTabbedText(text, x, y, g, this, mark); mark = endPosition; } // tokens may not reach to the end of the area we want rendered // so this will make up the remaining space if (end != mark) { doc.getText(mark, end - mark, text); x = Utilities.drawTabbedText(text, x, y, g, this, mark); } g2.setFont(g2.getFont().deriveFont(Font.PLAIN)); return x; }
public void exportReportToGraphics2D() throws JRException { grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // grx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); grx.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); grx.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); AffineTransform atrans = new AffineTransform(); atrans.translate(globalOffsetX, globalOffsetY); atrans.scale(zoom, zoom); grx.transform(atrans); java.util.List pages = jasperPrint.getPages(); if (pages != null) { Shape oldClipShape = grx.getClip(); grx.clip(new Rectangle(0, 0, jasperPrint.getPageWidth(), jasperPrint.getPageHeight())); try { JRPrintPage page = (JRPrintPage) pages.get(startPageIndex); exportPage(page); } finally { grx.setClip(oldClipShape); } } }
public void paintComponent(Graphics g) { super.paintComponent(g); int centerX = getWidth() / 2; int centerY = getHeight() / 2; Graphics2D g2d = (Graphics2D) g.create(); g2d.translate(centerX, centerY); // Set Graphics2D transform origin to center of panel g2d.setColor(fgColor); bar.setFrame(-barWidth / 2, -barHeight / 2 + barHeight * barPosition, barWidth, barHeight); g2d.fill(bar); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (Spike spike : spikes) { if (spike != null) { double opacity = 255; if (spike.getDirection() == 0) { opacity = getWidth() * 0.5 - 70 - spike.getPosition().getX(); } else { opacity = spike.getPosition().getX() + getWidth() * 0.5 - 70; } g2d.setColor(new Color(0, 0, 0, (int) clamp(opacity * 10, 0, 255))); g2d.fill(spike); } } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); g2d.setColor(Color.BLACK); g2d.draw(barCross); g2d.setStroke(new BasicStroke(2)); g2d.draw(barFrame); g2d.dispose(); }
private void createImages() { int w = 16; int h = getPreferredSize().height; setTarget(new Rectangle(2, 0, 20, 18)); Graphics2D g2; open = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); g2 = open.createGraphics(); g2.setPaint(getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillRect(0, 0, w, h); int[] x = {2, w / 2, 14}; int[] y = {4, 13, 4}; Polygon p = new Polygon(x, y, 3); g2.setPaint(new Color(204, 204, 204)); g2.fill(p); g2.draw(p); g2.dispose(); closed = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); g2 = closed.createGraphics(); g2.setPaint(getBackground()); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillRect(0, 0, w, h); x = new int[] {3, 13, 3}; y = new int[] {4, h / 2, 16}; p = new Polygon(x, y, 3); g2.setPaint(new Color(102, 102, 102)); g2.fill(p); g2.draw(p); g2.dispose(); }
private BufferedImage getFontImage(char ch) { // Create a temporary image to extract the character's size BufferedImage tempfontImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB); Graphics2D g = (Graphics2D) tempfontImage.getGraphics(); if (antiAlias == true) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } g.setFont(font); fontMetrics = g.getFontMetrics(); int charwidth = fontMetrics.charWidth(ch) + 8; if (charwidth <= 0) { charwidth = 7; } int charheight = fontMetrics.getHeight() + 3; if (charheight <= 0) { charheight = fontSize; } // Create another image holding the character we are creating BufferedImage fontImage; fontImage = new BufferedImage(charwidth, charheight, BufferedImage.TYPE_INT_ARGB); Graphics2D gt = (Graphics2D) fontImage.getGraphics(); if (antiAlias == true) { gt.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } gt.setFont(font); gt.setColor(Color.WHITE); int charx = 3; int chary = 1; gt.drawString(String.valueOf(ch), (charx), (chary) + fontMetrics.getAscent()); return fontImage; }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (!loadingDone && faderTimer == null) { return; } Insets insets = getInsets(); int x = insets.left; int y = insets.top; int width = getWidth() - insets.left - insets.right; int height = getHeight() - insets.top - insets.bottom; Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Composite oldComposite = g2.getComposite(); if (damaged) { drawableAvatars = sortAvatarsByDepth(x, y, width, height); damaged = false; } drawAvatars(g2, drawableAvatars); if (drawableAvatars.length > 0) { drawAvatarName(g2); } g2.setComposite(oldComposite); }