001package jmri.util.davidflanagan; 002 003import java.awt.Component; 004import java.awt.Graphics; 005import java.awt.Image; 006 007import javax.swing.Icon; 008 009public class RetinaIcon implements Icon { 010 private final Image image; 011 private final double retinaScale; 012 013 public RetinaIcon(Image image, double retinaScale) { 014 this.image = image; 015 this.retinaScale = retinaScale; 016 } 017 018 @Override 019 public void paintIcon(Component c, Graphics g, int x, int y) { 020 // Draw the larger image into the smaller space 021 g.drawImage(image, x, y, (int)(image.getWidth(null) / retinaScale), (int)(image.getHeight(null) / retinaScale), c); 022 } 023 024 @Override 025 public int getIconWidth() { return (int)(image.getWidth(null) / retinaScale); } 026 027 @Override 028 public int getIconHeight() { return (int)(image.getHeight(null) / retinaScale); } 029}