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
30
31
32 private static final Logger LOGGER = LogManager.getRootLogger();
33
34
35
36
37 private final String iconPathOverlap;
38
39
40
41
42
43
44 public ImageOverlap(ImageIcon main, String iconPathOverlap) {
45 super(main.getImage());
46 this.iconPathOverlap = iconPathOverlap;
47 }
48
49 @Override
50 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
51 super.paintIcon(c, g, x, y);
52 try {
53 BufferedImage bufferedImage = ImageIO.read(
54 Objects.requireNonNull(ImageOverlap.class.getClassLoader().getResource(this.iconPathOverlap))
55 );
56
57 g.drawImage(
58 bufferedImage,
59 (this.getIconWidth() - bufferedImage.getWidth()) / 2,
60 (this.getIconHeight() - bufferedImage.getHeight()) / 2,
61 null
62 );
63 } catch (IOException e) {
64 LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
65 }
66 }
67 }