1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
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 about 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 | /** | |
30 | * Log4j logger sent to view. | |
31 | */ | |
32 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
33 | ||
34 | /** | |
35 | * The path of icon displayed in the bottom right corner. | |
36 | */ | |
37 | private final String iconPathOverlap; | |
38 | ||
39 | /** | |
40 | * Create icon with tiny icon on top layer. | |
41 | * @param main Main icon to display | |
42 | * @param iconPathOverlap Secondary icon to display on top of main icon | |
43 | */ | |
44 | public ImageOverlap(String main, String iconPathOverlap) { | |
45 | | |
46 | super(Objects.requireNonNull(ImageOverlap.class.getClassLoader().getResource(main))); | |
47 | this.iconPathOverlap = iconPathOverlap; | |
48 | } | |
49 | ||
50 | @Override | |
51 | public synchronized void paintIcon(Component c, Graphics g, int x, int y) { | |
52 | | |
53 |
1
1. paintIcon : removed call to javax/swing/ImageIcon::paintIcon → NO_COVERAGE |
super.paintIcon(c, g, x, y); |
54 | | |
55 | try { | |
56 | BufferedImage bufferedImage = ImageIO.read( | |
57 | Objects.requireNonNull(ImageOverlap.class.getClassLoader().getResource(this.iconPathOverlap)) | |
58 | ); | |
59 | | |
60 | g.drawImage( | |
61 | bufferedImage, | |
62 |
2
1. paintIcon : Replaced integer division with multiplication → NO_COVERAGE 2. paintIcon : Replaced integer subtraction with addition → NO_COVERAGE |
(this.getIconWidth() - bufferedImage.getWidth()) / 2, |
63 |
2
1. paintIcon : Replaced integer division with multiplication → NO_COVERAGE 2. paintIcon : Replaced integer subtraction with addition → NO_COVERAGE |
(this.getIconHeight() - bufferedImage.getHeight()) / 2, |
64 | null | |
65 | ); | |
66 | } catch (IOException e) { | |
67 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
68 | } | |
69 | } | |
70 | } | |
Mutations | ||
53 |
1.1 |
|
62 |
1.1 2.2 |
|
63 |
1.1 2.2 |