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); } }
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(); }
@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(); }
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); } }
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(); }
@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); } }
protected void paintIndeterminate(Graphics g, JComponent c) { if (!(g instanceof Graphics2D)) { return; } Graphics2D g2D = (Graphics2D) g; Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - (b.right + b.left); int barRectHeight = progressBar.getHeight() - (b.top + b.bottom); Color colors[]; if (progressBar.getForeground() instanceof UIResource) { if (!Utilities.isActive(c)) { colors = BaseLookAndFeel.getTheme().getInActiveColors(); } else if (c.isEnabled()) { colors = BaseLookAndFeel.getTheme().getProgressBarColors(); } else { colors = BaseLookAndFeel.getTheme().getDisabledColors(); } } else { Color hiColor = ColorHelper.brighter(progressBar.getForeground(), 40); Color loColor = ColorHelper.darker(progressBar.getForeground(), 20); colors = ColorHelper.createColorArr(hiColor, loColor, 20); } Color cHi = ColorHelper.darker(colors[colors.length - 1], 5); Color cLo = ColorHelper.darker(colors[colors.length - 1], 10); // Paint the bouncing box. Rectangle box = getBox(null); if (box != null) { g2D.setColor(progressBar.getForeground()); Utilities.draw3DBorder(g, cHi, cLo, box.x + 1, box.y + 1, box.width - 2, box.height - 2); if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { Utilities.fillHorGradient(g, colors, box.x + 2, box.y + 2, box.width - 4, box.height - 4); } else { Utilities.fillVerGradient(g, colors, box.x + 2, box.y + 2, box.width - 4, box.height - 4); } // Deal with possible text painting if (progressBar.isStringPainted()) { Object savedRenderingHint = null; if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) { savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, BaseLookAndFeel.getTheme().getTextAntiAliasingHint()); } if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) { paintString(g2D, b.left, b.top, barRectWidth, barRectHeight, box.width, b); } else { paintString(g2D, b.left, b.top, barRectWidth, barRectHeight, box.height, b); } if (BaseLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } } } }
public static void drawRoundBorder(Graphics g, Color c, int x, int y, int w, int h, int r) { Graphics2D g2D = (Graphics2D) g; Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2D.setColor(c); g2D.drawRoundRect(x, y, w - 1, h - 1, r, r); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); }
public void paint(Graphics g) { if (g instanceof Graphics2D) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } super.paint(g); }
public Graphics2D getDisplayGfx() { Graphics2D gfx = (Graphics2D) img.getGraphics(); // make sure the gfx renders in high quality gfx.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); gfx.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); return gfx; }
public void paintChildren() { Graphics2D g = getGraphics(); Object anti = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); Object textAnti = g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); super.paintChildren(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, anti); g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, textAnti); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); int offset = 0; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString(ptmString.getIterator(), offset, 15); g2.dispose(); }
// 重画时清除屏幕 public void paint(Graphics g) { g.setColor(new Color(0, 0, 0)); g.fillRect(0, 0, getWidth(), getHeight()); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setColor(Color.WHITE); g.setFont(new Font("Default", 40, 40)); g.drawString(m_prompt, 220, 250); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); }
public void paintStroke(Graphics2D g, ButtonInfo info) { if (isStrokePainted(info.button)) { Paint strokeColor = fill.getStroke(info.button, info.fillBounds); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE); if (isStrokeAntialiased()) { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } g.setPaint(strokeColor); g.draw(info.stroke); } }
/** * Method description * * @param g */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) { ((Graphics2D) g) .setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } paintLegend(g); ((Graphics2D) g) .setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { AbstractButton button = (AbstractButton) c; Graphics2D g2D = (Graphics2D) g; Color frameColor = AbstractLookAndFeel.getTheme().getFrameColor(); if (!JTattooUtilities.isFrameActive(button)) { frameColor = ColorHelper.brighter(frameColor, 40); } if (AbstractLookAndFeel.getTheme().doDrawSquareButtons()) { g2D.setColor(Color.white); g2D.drawRect(x, y, w - 1, h - 1); if (button.getRootPane() != null && button.equals(button.getRootPane().getDefaultButton()) && !button.hasFocus()) { g2D.setColor(ColorHelper.darker(frameColor, 20)); g2D.drawRect(x, y, w - 1, h - 2); if (!button.getModel().isRollover()) { g2D.setColor(defaultColorHi); g2D.drawRect(x + 1, y + 1, w - 3, h - 4); g2D.setColor(defaultColorLo); g2D.drawRect(x + 2, y + 2, w - 5, h - 6); } } else { g2D.setColor(frameColor); g2D.drawRect(x, y, w - 2, h - 2); } } else { Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (button.getRootPane() != null && button.equals(button.getRootPane().getDefaultButton())) { if (!button.getModel().isRollover()) { g2D.setColor(defaultColorHi); g2D.drawRoundRect(x + 1, y + 1, w - 4, h - 2, 6, 6); g2D.setColor(defaultColorLo); g2D.drawRoundRect(x + 2, y + 2, w - 6, h - 6, 6, 6); } } g2D.setColor(Color.white); g2D.drawRoundRect(x, y, w - 1, h - 1, 6, 6); g2D.setColor(frameColor); g2D.drawRoundRect(x, y, w - 2, h - 2, 6, 6); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint); } }
protected void paintSafely(Graphics g) { 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()); } super.paintSafely(g); if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) { g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint); } }
private void _update(Graphics2D graphics2D, JComponent jComponent) { GFX ctx = new Java2DGFX(graphics2D); graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics2D.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics2D.setRenderingHint( RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); // graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, // RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB); ctx.setPaint(backgroundFill); ctx.fillRect(0, 0, jComponent.getWidth(), jComponent.getHeight()); // draw the scene root.draw(ctx); }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.white); g2.fillRect(0, 0, getWidth(), getHeight()); AffineTransform at = new AffineTransform(0.5, 0, 0, -0.5, 30, getHeight() * 3 / 4); g2.transform(at); g2.setColor(Color.black); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // System.out.println("Showing="+showing); if (showing != null) { showing.draw(g2); } }
/** * Internal utility method that creates a new icon. Called after the user selects a new color, or * when the size of the icon changes. */ private void updateIcon() { BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) image.getGraphics(); g2d.setColor(this.color); // turn antialiasing off g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); // we want fast rendering g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.fillRect(0, 0, iconWidth, iconHeight); ImageIcon imageIcon = new ImageIcon(image); this.setIcon(imageIcon); g2d.dispose(); }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); int pointSize = Math.max(Math.min(w, h) / 80, 4); double xInc = (double) (w - 2 * PAD) / (MAX_X - 1); double scale = (double) (h - 2 * PAD) / MAX_Y; // Draw abcissa. int tickInc = MAX_X / 10; for (int i = 0; i <= MAX_X; i += tickInc) { int x = PAD + (int) (i * xInc); int y = h - PAD; g.drawString(Integer.toString(i), x - 5, y + 20); g2.draw(new Line2D.Double(x, y - 5, x, y + 5)); } g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD)); AffineTransform orig = g2.getTransform(); g2.rotate(-Math.PI / 2); g2.setColor(Color.black); g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3); g2.setTransform(orig); // Draw ordinate. tickInc = (h - PAD) / 10; for (int i = tickInc; i < h - PAD; i += tickInc) { int x = PAD; int closest_10 = ((int) (i / scale) / 10) * 10; int y = h - PAD - (int) (closest_10 * scale); if (y < PAD) break; String tickMark = Integer.toString(closest_10); int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth(); g.drawString(tickMark, x - stringLen - 8, y + 5); g2.draw(new Line2D.Double(x - 5, y, x + 5, y)); } g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD)); g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40); for (int index = 0; index < plot_data.size(); index++) { int[] data = plot_data.get(index); // Mark data points. g2.setPaint(plot_colors.get(index)); for (int i = 0; i < data.length; i++) { double x = PAD + i * xInc; double y = h - PAD - scale * data[i]; g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize)); } g2.setFont(textFont); int stringHeight = (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight(); g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight); } }
/** paint the canvas into a image file of given width and height */ public void writeToImage(String s, int w, int h) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } boolean opq = true; if (theOpaque != null) opq = theOpaque; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(Color.white); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1)); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); doBuffer(g2, true, new Rectangle(0, 0, w, h)); try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
/** * Paints the icon. * * @param c the component on which it is painted * @param _g the graphics context * @param x the x coordinate of the icon * @param y the y coordinate of the icon */ public void paintIcon(Component c, Graphics _g, int x, int y) { Graphics2D g = (Graphics2D) _g; AffineTransform at = AffineTransform.getTranslateInstance(x + offsetX, y + offsetY); // save current graphics paint and clip Paint gPaint = g.getPaint(); Shape gClip = g.getClip(); // render shape(s) g.setPaint(color); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.clipRect(x, y, w, h); // paint shape, if any if (shape != null) { g.fill(at.createTransformedShape(shape)); } // paint decoration, if any if (decoration != null) { g.setPaint(decoColor); g.fill(at.createTransformedShape(decoration)); } // restore graphics paint and clip g.setPaint(gPaint); g.setClip(gClip); }
@Override protected void paintIcon(JComponent c, Graphics2D g, Rectangle viewRect, Rectangle iconRect) { int rad = JBUI.scale(4); // Paint the radio button final int x = iconRect.x + (rad - (rad % 2 == 1 ? 1 : 0)) / 2; final int y = iconRect.y + (rad - (rad % 2 == 1 ? 1 : 0)) / 2; final int w = iconRect.width - rad; final int h = iconRect.height - rad; final boolean enabled = c.isEnabled(); Color color = enabled ? Gray.x50 : Gray.xD3; g.translate(x, y); // setup AA for lines final GraphicsConfig config = GraphicsUtil.setupAAPainting(g); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); final boolean selected = ((AbstractButton) c).isSelected(); g.setPaint(color); g.drawOval(0, 0, w, h); if (selected) { g.setColor(color); g.fillOval(JBUI.scale(3), JBUI.scale(3), w - 2 * JBUI.scale(3), h - 2 * JBUI.scale(3)); } config.restore(); g.translate(-x, -y); }
private static Icon getThemeIcon(ColorScheme colorScheme, boolean square) { int iSize = SubstanceSizeUtils.getTitlePaneIconSize(); BufferedImage result = SubstanceCoreUtilities.getBlankImage(iSize, iSize); Graphics2D graphics = (Graphics2D) result.getGraphics().create(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Color color1 = (colorScheme == null) ? Color.red : colorScheme.getUltraDarkColor(); Color color2 = (colorScheme == null) ? Color.green : colorScheme.getMidColor(); Color color3 = (colorScheme == null) ? Color.blue : colorScheme.getExtraLightColor(); graphics.setColor(color1); if (square) graphics.fillRect(5, 2, 6, 6); else graphics.fillOval(5, 2, 6, 6); graphics.setColor(color1.darker()); if (square) graphics.drawRect(5, 2, 6, 6); else graphics.drawOval(5, 2, 6, 6); graphics.setColor(color2); if (square) graphics.fillRect(1, 9, 6, 6); else graphics.fillOval(1, 9, 6, 6); graphics.setColor(color2.darker()); if (square) graphics.drawRect(1, 9, 6, 6); else graphics.drawOval(1, 9, 6, 6); graphics.setColor(color3); if (square) graphics.fillRect(9, 9, 6, 6); else graphics.fillOval(9, 9, 6, 6); graphics.setColor(color3.darker()); if (square) graphics.drawRect(9, 9, 6, 6); else graphics.drawOval(9, 9, 6, 6); graphics.dispose(); return new ImageIcon(result); }
@Override public void paint(Graphics g) { super.paint(g); if (g instanceof Graphics2D) { Graphics2D g2d = (Graphics2D) g; if (blackOutEnabled) { // background g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); } else if (whiteOutEnabled) { // background g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); } else { // background g2d.setColor(backgroundColor); g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); // text if (font == null) font = GuiHelper.maxFontSize(frame.getWidth(), frame.getHeight(), fontName, timeFormat); if (textY == -1) textY = GuiHelper.getTextYForCenter(timeFormat, font, frame.getHeight()); g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setFont(font); g2d.setColor(textColor); g2d.drawString(timeToString(time), 0, textY); } } }
public void saveMapAs( final File selectedFile, FileExporter exporter, MapTransformer<COORD> transformer) throws IOException { exporter.setup(selectedFile, transformer.getWidth(), transformer.getHeight()); final Graphics2D g2 = exporter.getG2(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(MapPanel.BG_COLOR); g2.fillRect(0, 0, transformer.getWidth(), transformer.getHeight()); Rectangle bbox = transformer.getGarminBoundingBox(); int minLon = bbox.x; int maxLon = bbox.x + bbox.width; int minLat = bbox.y; int maxLat = bbox.y + bbox.height; int resolution = getResolution(minLon, maxLon, transformer.getWidth()); TransformedMapListener drawer = createMapDrawer(new MapConfig(), g2, exporter.getFontSize(), transformer); MapListener listener = new CoordinateConverterListener<COORD>( transformer, new ClippingMapListener(0, transformer.getWidth(), 0, transformer.getHeight(), drawer)); map.readMapForDrawing(minLon, maxLon, minLat, maxLat, resolution, ObjectKind.ALL, listener); exporter.finishSave(); }
@Override protected void paintComponent(Graphics g0) { Graphics2D g = (Graphics2D) g0; g.scale(scale, scale); g.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(Color.white); g.fillRect(0, 0, (int) labelWidth, (int) labelHeight); LabelArea area = new LabelArea(labelWidth, labelHeight, 0); g.setColor(Color.black); label.print(area, (Graphics2D) g.create()); }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); width = getWidth(); height = getHeight(); g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(width / 2, getHeight() / 2); drawGrid(g2); drawAxes(g2); g2.setColor(EMERALD); g2.setStroke(new BasicStroke(3)); System.out.println("REPAINTED " + countTest++ + " times by now..."); try { drawPlot(); } catch (ScriptException e) { e.printStackTrace(); } }