| 1 | /******************************************************************************* | |
| 2 | * Copyhacked (H) 2012-2025. | |
| 3 | * This program and the accompanying materials | |
| 4 | * are made available under no term at all, use it like | |
| 5 | * you want, but share and discuss it | |
| 6 | * every time possible with every body. | |
| 7 | * | |
| 8 | * Contributors: | |
| 9 | * ron190 at ymail dot com - initial implementation | |
| 10 | ******************************************************************************/ | |
| 11 | package com.jsql.view.swing.tree; | |
| 12 | ||
| 13 | import com.jsql.util.LogLevelUtil; | |
| 14 | import org.apache.logging.log4j.LogManager; | |
| 15 | import org.apache.logging.log4j.Logger; | |
| 16 | ||
| 17 | import javax.imageio.ImageIO; | |
| 18 | import javax.swing.*; | |
| 19 | import java.awt.*; | |
| 20 | import java.awt.image.BufferedImage; | |
| 21 | import java.io.IOException; | |
| 22 | import java.util.Objects; | |
| 23 | ||
| 24 | /** | |
| 25 | * An icon composed of a main icon and another one displayed in the bottom right corner. | |
| 26 | */ | |
| 27 | public class ImageOverlap extends ImageIcon { | |
| 28 | | |
| 29 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 30 | ||
| 31 | /** | |
| 32 | * The path of icon displayed in the bottom right corner. | |
| 33 | */ | |
| 34 | private final String iconPathOverlap; | |
| 35 | ||
| 36 | /** | |
| 37 | * Create icon with tiny icon on top layer. | |
| 38 | * @param main Main icon to display | |
| 39 | * @param iconPathOverlap Secondary icon to display on top of main icon | |
| 40 | */ | |
| 41 | public ImageOverlap(ImageIcon main, String iconPathOverlap) { | |
| 42 | super(main.getImage()); | |
| 43 | this.iconPathOverlap = iconPathOverlap; | |
| 44 | } | |
| 45 | ||
| 46 | @Override | |
| 47 | public synchronized void paintIcon(Component c, Graphics g, int x, int y) { | |
| 48 |
1
1. paintIcon : removed call to javax/swing/ImageIcon::paintIcon → NO_COVERAGE |
super.paintIcon(c, g, x, y); |
| 49 | try { | |
| 50 | BufferedImage bufferedImage = ImageIO.read( | |
| 51 | Objects.requireNonNull(ImageOverlap.class.getClassLoader().getResource(this.iconPathOverlap)) | |
| 52 | ); | |
| 53 | | |
| 54 | g.drawImage( | |
| 55 | bufferedImage, | |
| 56 |
2
1. paintIcon : Replaced integer division with multiplication → NO_COVERAGE 2. paintIcon : Replaced integer subtraction with addition → NO_COVERAGE |
(this.getIconWidth() - bufferedImage.getWidth()) / 2, |
| 57 |
2
1. paintIcon : Replaced integer division with multiplication → NO_COVERAGE 2. paintIcon : Replaced integer subtraction with addition → NO_COVERAGE |
(this.getIconHeight() - bufferedImage.getHeight()) / 2, |
| 58 | null | |
| 59 | ); | |
| 60 | } catch (IOException e) { | |
| 61 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 62 | } | |
| 63 | } | |
| 64 | } | |
Mutations | ||
| 48 |
1.1 |
|
| 56 |
1.1 2.2 |
|
| 57 |
1.1 2.2 |