| 1 | package com.rox.video; | |
| 2 | ||
| 3 | import javax.imageio.ImageIO; | |
| 4 | import java.awt.Graphics2D; | |
| 5 | import java.awt.Image; | |
| 6 | import java.awt.Window; | |
| 7 | import java.awt.image.BufferedImage; | |
| 8 | import java.io.IOException; | |
| 9 | import java.io.InputStream; | |
| 10 | import java.util.List; | |
| 11 | import java.util.function.Consumer; | |
| 12 | ||
| 13 | /** EmuRoxLab's icon - the scavenged NES, square - for every window's title bar, dock and Alt-Tab entry. */ | |
| 14 | public final class AppIcon { | |
| 15 | /** Sizes window managers commonly pick from: each picks the nearest rather than rescaling one. */ | |
| 16 | static final List<Integer> SIZES = List.of(16, 24, 32, 48, 64, 128, 256); | |
| 17 | private static final List<Image> IMAGES = images(readIcon("emuroxlab_icon.png")); | |
| 18 | ||
| 19 | private AppIcon(){ | |
| 20 | } | |
| 21 | ||
| 22 | /** Gives {@code window} the icon - and the dock too, where the platform has one (macOS). */ | |
| 23 | public static void applyTo(final Window window){ | |
| 24 |
1
1. applyTo : removed call to com/rox/video/AppIcon::applyTo → KILLED |
applyTo(window, IMAGES, DesktopPlatform.dockIcon()); |
| 25 | } | |
| 26 | ||
| 27 | /** @param dockIcon sets the dock's icon, or {@code null} where there's no dock to set */ | |
| 28 | static void applyTo(final Window window, final List<Image> images, final Consumer<Image> dockIcon){ | |
| 29 |
1
1. applyTo : negated conditional → KILLED |
if (images.isEmpty()){ |
| 30 | return; | |
| 31 | } | |
| 32 |
1
1. applyTo : removed call to java/awt/Window::setIconImages → KILLED |
window.setIconImages(images); |
| 33 |
1
1. applyTo : negated conditional → KILLED |
if (dockIcon != null){ |
| 34 |
2
1. applyTo : removed call to java/util/function/Consumer::accept → KILLED 2. applyTo : Replaced integer subtraction with addition → KILLED |
dockIcon.accept(images.get(images.size() - 1)); |
| 35 | } | |
| 36 | } | |
| 37 | ||
| 38 | /** {@code source} at each of {@link #SIZES}, area-averaged; none for {@code null}. */ | |
| 39 | static List<Image> images(final BufferedImage source){ | |
| 40 |
1
1. images : negated conditional → KILLED |
if (source == null){ |
| 41 | return List.of(); | |
| 42 | } | |
| 43 |
2
1. images : replaced return value with Collections.emptyList for com/rox/video/AppIcon::images → KILLED 2. lambda$images$0 : replaced return value with null for com/rox/video/AppIcon::lambda$images$0 → KILLED |
return SIZES.stream().<Image>map(size -> scaled(source, size)).toList(); |
| 44 | } | |
| 45 | ||
| 46 | private static BufferedImage scaled(final BufferedImage source, final int size){ | |
| 47 | final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); | |
| 48 | final Graphics2D g = image.createGraphics(); | |
| 49 | g.drawImage(source.getScaledInstance(size, size, Image.SCALE_AREA_AVERAGING), 0, 0, null); | |
| 50 |
1
1. scaled : removed call to java/awt/Graphics2D::dispose → SURVIVED |
g.dispose(); |
| 51 |
1
1. scaled : replaced return value with null for com/rox/video/AppIcon::scaled → KILLED |
return image; |
| 52 | } | |
| 53 | ||
| 54 | static BufferedImage readIcon(final String resource){ | |
| 55 | try (InputStream in = AppIcon.class.getResourceAsStream(resource)){ | |
| 56 |
2
1. readIcon : replaced return value with null for com/rox/video/AppIcon::readIcon → KILLED 2. readIcon : negated conditional → KILLED |
return in == null ? null : ImageIO.read(in); |
| 57 | } catch (IOException e){ | |
| 58 |
1
1. readIcon : removed call to java/io/PrintStream::println → SURVIVED |
System.err.println("Couldn't read " + resource + ": " + e.getMessage()); |
| 59 | return null; | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
Mutations | ||
| 24 |
1.1 |
|
| 29 |
1.1 |
|
| 32 |
1.1 |
|
| 33 |
1.1 |
|
| 34 |
1.1 2.2 |
|
| 40 |
1.1 |
|
| 43 |
1.1 2.2 |
|
| 50 |
1.1 |
|
| 51 |
1.1 |
|
| 56 |
1.1 2.2 |
|
| 58 |
1.1 |