1
2
3
4
5
6
7
8
9
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
26
27 public class ImageOverlap extends ImageIcon {
28
29 private static final Logger LOGGER = LogManager.getRootLogger();
30
31
32
33
34 private final String iconPathOverlap;
35
36
37
38
39
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 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 (this.getIconWidth() - bufferedImage.getWidth()) / 2,
57 (this.getIconHeight() - bufferedImage.getHeight()) / 2,
58 null
59 );
60 } catch (IOException e) {
61 LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
62 }
63 }
64 }